Skip to content

Commit de804ae

Browse files
committed
ruff
1 parent ae77f25 commit de804ae

File tree

2 files changed

+5
-45
lines changed

2 files changed

+5
-45
lines changed

chia/consensus/block_store_protocol.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ async def is_fully_compactified(self, header_hash: bytes32) -> Optional[bool]: .
4242
async def replace_proof(self, header_hash: bytes32, block: FullBlock) -> None: ...
4343
async def count_compactified_blocks(self) -> int: ...
4444
async def count_uncompactified_blocks(self) -> int: ...
45-
async def get_block_records_close_to_peak(self, blocks_n: int) -> tuple[dict[bytes32, BlockRecord], Optional[bytes32]]: ...
45+
async def get_block_records_close_to_peak(
46+
self, blocks_n: int
47+
) -> tuple[dict[bytes32, BlockRecord], Optional[bytes32]]: ...
4648
def get_host_parameter_limit(self) -> int: ...
4749
async def get_prev_hash(self, header_hash: bytes32) -> bytes32: ...
48-
def transaction(self) -> AbstractAsyncContextManager[None]: ...
50+
def transaction(self) -> AbstractAsyncContextManager[None]: ...

chia/full_node/block_store.py

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import dataclasses
44
import logging
55
import sqlite3
6+
from contextlib import AbstractAsyncContextManager
67
from typing import Optional
78

89
import typing_extensions
@@ -396,25 +397,6 @@ async def get_block_records_by_hash(self, header_hashes: list[bytes32]) -> list[
396397
ret.append(all_blocks[hh])
397398
return ret
398399

399-
async def get_prev_hash(self, header_hash: bytes32) -> bytes32:
400-
"""
401-
Returns the header hash preceeding the input header hash.
402-
Throws an exception if the block is not present
403-
"""
404-
cached = self.block_cache.get(header_hash)
405-
if cached is not None:
406-
return cached.prev_header_hash
407-
408-
async with self.db_wrapper.reader_no_transaction() as conn:
409-
async with conn.execute(
410-
"SELECT prev_hash FROM full_blocks WHERE header_hash=?",
411-
(header_hash,),
412-
) as cursor:
413-
row = await cursor.fetchone()
414-
if row is None:
415-
raise KeyError("missing block in chain")
416-
return bytes32(row[0])
417-
418400
async def get_block_bytes_by_hash(self, header_hashes: list[bytes32]) -> list[bytes]:
419401
"""
420402
Returns a list of Full Blocks block blobs, ordered by the same order in which header_hashes are passed in.
@@ -545,30 +527,6 @@ async def get_peak(self) -> Optional[tuple[bytes32, uint32]]:
545527
return None
546528
return bytes32(peak_row[0]), uint32(peak_height[0])
547529

548-
async def get_block_records_close_to_peak(
549-
self, blocks_n: int
550-
) -> tuple[dict[bytes32, BlockRecord], Optional[bytes32]]:
551-
"""
552-
Returns a dictionary with all blocks that have height >= peak height - blocks_n, as well as the
553-
peak header hash. Only blocks that are part of the main chain/current peak are included.
554-
"""
555-
556-
peak = await self.get_peak()
557-
if peak is None:
558-
return {}, None
559-
560-
ret: dict[bytes32, BlockRecord] = {}
561-
async with self.db_wrapper.reader_no_transaction() as conn:
562-
async with conn.execute(
563-
"SELECT header_hash, block_record FROM full_blocks WHERE height >= ? AND in_main_chain=1",
564-
(peak[1] - blocks_n,),
565-
) as cursor:
566-
for row in await cursor.fetchall():
567-
header_hash = bytes32(row[0])
568-
ret[header_hash] = BlockRecord.from_bytes(row[1])
569-
570-
return ret, peak[0]
571-
572530
async def set_peak(self, header_hash: bytes32) -> None:
573531
# We need to be in a sqlite transaction here.
574532
# Note: we do not commit this to the database yet, as we need to also change the coin store

0 commit comments

Comments
 (0)