Skip to content

Commit 315bc4e

Browse files
committed
mindiffs
1 parent cb2c7cc commit 315bc4e

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

chia/full_node/block_store.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -199,30 +199,6 @@ def transaction(self) -> AbstractAsyncContextManager[Any]:
199199
def get_block_from_cache(self, header_hash: bytes32) -> Optional[FullBlock]:
200200
return self.block_cache.get(header_hash)
201201

202-
async def get_block_records_close_to_peak(
203-
self, blocks_n: int
204-
) -> tuple[dict[bytes32, BlockRecord], Optional[bytes32]]:
205-
"""
206-
Returns a dictionary with all blocks that have height >= peak height - blocks_n, as well as the
207-
peak header hash. Only blocks that are part of the main chain/current peak are included.
208-
"""
209-
210-
peak = await self.get_peak()
211-
if peak is None:
212-
return {}, None
213-
214-
ret: dict[bytes32, BlockRecord] = {}
215-
async with self.db_wrapper.reader_no_transaction() as conn:
216-
async with conn.execute(
217-
"SELECT header_hash, block_record FROM full_blocks WHERE height >= ? AND in_main_chain=1",
218-
(peak[1] - blocks_n,),
219-
) as cursor:
220-
for row in await cursor.fetchall():
221-
header_hash = bytes32(row[0])
222-
ret[header_hash] = BlockRecord.from_bytes(row[1])
223-
224-
return ret, peak[0]
225-
226202
def rollback_cache_block(self, header_hash: bytes32) -> None:
227203
try:
228204
self.block_cache.remove(header_hash)
@@ -527,6 +503,30 @@ async def get_peak(self) -> Optional[tuple[bytes32, uint32]]:
527503
return None
528504
return bytes32(peak_row[0]), uint32(peak_height[0])
529505

506+
async def get_block_records_close_to_peak(
507+
self, blocks_n: int
508+
) -> tuple[dict[bytes32, BlockRecord], Optional[bytes32]]:
509+
"""
510+
Returns a dictionary with all blocks that have height >= peak height - blocks_n, as well as the
511+
peak header hash. Only blocks that are part of the main chain/current peak are included.
512+
"""
513+
514+
peak = await self.get_peak()
515+
if peak is None:
516+
return {}, None
517+
518+
ret: dict[bytes32, BlockRecord] = {}
519+
async with self.db_wrapper.reader_no_transaction() as conn:
520+
async with conn.execute(
521+
"SELECT header_hash, block_record FROM full_blocks WHERE height >= ? AND in_main_chain=1",
522+
(peak[1] - blocks_n,),
523+
) as cursor:
524+
for row in await cursor.fetchall():
525+
header_hash = bytes32(row[0])
526+
ret[header_hash] = BlockRecord.from_bytes(row[1])
527+
528+
return ret, peak[0]
529+
530530
async def set_peak(self, header_hash: bytes32) -> None:
531531
# We need to be in a sqlite transaction here.
532532
# Note: we do not commit this to the database yet, as we need to also change the coin store

0 commit comments

Comments
 (0)