Skip to content

Commit

Permalink
remove unused get_block_records() function (Chia-Network#5016)
Browse files Browse the repository at this point in the history
* remove unused get_block_records() function

it's only used by one test. It's also a dangerous function since the whole chain may become very large, and may not fit in memory

* fixup tests

* fixup test
  • Loading branch information
arvidn authored May 24, 2021
1 parent c1f54cb commit 2ddc48d
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 26 deletions.
20 changes: 0 additions & 20 deletions chia/full_node/block_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,26 +232,6 @@ async def get_block_record(self, header_hash: bytes32) -> Optional[BlockRecord]:
return BlockRecord.from_bytes(row[0])
return None

async def get_block_records(
self,
) -> Tuple[Dict[bytes32, BlockRecord], Optional[bytes32]]:
"""
Returns a dictionary with all blocks, as well as the header hash of the peak,
if present.
"""
cursor = await self.db.execute("SELECT * from block_records")
rows = await cursor.fetchall()
await cursor.close()
ret: Dict[bytes32, BlockRecord] = {}
peak: Optional[bytes32] = None
for row in rows:
header_hash = bytes.fromhex(row[0])
ret[header_hash] = BlockRecord.from_bytes(row[3])
if row[5]:
assert peak is None # Sanity check, only one peak
peak = header_hash
return ret, peak

async def get_block_records_in_range(
self,
start: int,
Expand Down
7 changes: 2 additions & 5 deletions tests/core/full_node/test_block_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,8 @@ async def test_block_store(self):
assert len(await store.get_full_blocks_at([100])) == 0

# Get blocks
block_record_records = await store.get_block_records()
assert len(block_record_records[0]) == len(blocks)

# Peak is correct
assert block_record_records[1] == blocks[-1].header_hash
block_record_records = await store.get_block_records_in_range(0, 0xFFFFFFFF)
assert len(block_record_records) == len(blocks)

except Exception:
await connection.close()
Expand Down
3 changes: 2 additions & 1 deletion tests/weight_proof/test_weight_proof.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,8 @@ async def test_weight_proof_extend_multiple_ses(self, default_1000_blocks):
async def test_weight_proof_from_database(self):
connection = await aiosqlite.connect("path to db")
block_store: BlockStore = await BlockStore.create(connection)
blocks, peak = await block_store.get_block_records()
blocks = await block_store.get_block_records_in_range(0, 0xFFFFFFFF)
peak = len(blocks) - 1
peak_height = blocks[peak].height
headers = await block_store.get_header_blocks_in_range(0, peak_height)
sub_height_to_hash = {}
Expand Down

0 comments on commit 2ddc48d

Please sign in to comment.