Skip to content

Commit dd9342f

Browse files
committed
Deal with .db_wrapper
1 parent 44cb633 commit dd9342f

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

chia/consensus/blockchain.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from chia.consensus.block_body_validation import ForkInfo, validate_block_body
2828
from chia.consensus.block_header_validation import validate_unfinished_header_block
2929
from chia.consensus.block_height_map import BlockHeightMap
30+
from chia.consensus.block_store_protocol import BlockStoreProtocol
3031
from chia.consensus.coin_store_protocol import CoinStoreProtocol
3132
from chia.consensus.cost_calculator import NPCResult
3233
from chia.consensus.difficulty_adjustment import get_next_sub_slot_iters_and_difficulty
@@ -35,7 +36,6 @@
3536
from chia.consensus.generator_tools import get_block_header
3637
from chia.consensus.get_block_generator import get_block_generator
3738
from chia.consensus.multiprocess_validation import PreValidationResult
38-
from chia.full_node.block_store import BlockStore
3939
from chia.types.blockchain_format.coin import Coin
4040
from chia.types.blockchain_format.vdf import VDFInfo
4141
from chia.types.coin_record import CoinRecord
@@ -104,7 +104,7 @@ class Blockchain:
104104
# Unspent Store
105105
coin_store: CoinStoreProtocol
106106
# Store
107-
block_store: BlockStore
107+
block_store: BlockStoreProtocol
108108
# Used to verify blocks in parallel
109109
pool: Executor
110110
# Set holding seen compact proofs, in order to avoid duplicates.
@@ -122,7 +122,7 @@ class Blockchain:
122122
@staticmethod
123123
async def create(
124124
coin_store: CoinStoreProtocol,
125-
block_store: BlockStore,
125+
block_store: BlockStoreProtocol,
126126
height_map: BlockHeightMap,
127127
consensus_constants: ConsensusConstants,
128128
reserved_cores: int,

chia/full_node/block_store.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from chia_rs.sized_bytes import bytes32
1212
from chia_rs.sized_ints import uint32
1313

14-
from chia.consensus.block_store_protocol import BlockStoreProtocol
1514
from chia.full_node.full_block_utils import GeneratorBlockInfo, block_info_from_block, generator_from_block
1615
from chia.util.db_wrapper import DBWrapper2, execute_fetchone
1716
from chia.util.errors import Err
@@ -469,7 +468,8 @@ async def get_block_bytes_in_range(
469468
No orphan blocks.
470469
"""
471470

472-
assert self.db_wrapper.db_version == 2
471+
if self.db_wrapper.db_version != 2:
472+
raise NotImplementedError("get_block_bytes_in_range requires DB version 2")
473473
async with self.db_wrapper.reader_no_transaction() as conn:
474474
async with conn.execute(
475475
"SELECT block FROM full_blocks WHERE height >= ? AND height <= ? AND in_main_chain=1",

chia/full_node/full_node_api.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,15 +1452,13 @@ async def request_block_headers(self, request: wallet_protocol.RequestBlockHeade
14521452

14531453
if request.end_height < request.start_height or request.end_height - request.start_height > 128:
14541454
return make_msg(ProtocolMessageTypes.reject_block_headers, reject)
1455-
if self.full_node.block_store.db_wrapper.db_version == 2:
1456-
try:
1457-
blocks_bytes = await self.full_node.block_store.get_block_bytes_in_range(
1458-
request.start_height, request.end_height
1459-
)
1460-
except ValueError:
1461-
return make_msg(ProtocolMessageTypes.reject_block_headers, reject)
1462-
1463-
else:
1455+
try:
1456+
blocks_bytes = await self.full_node.block_store.get_block_bytes_in_range(
1457+
request.start_height, request.end_height
1458+
)
1459+
except NotImplementedError:
1460+
# The underlying block store may not support this optimized call
1461+
# (e.g. v1 DB). In this case, we fall back to the legacy approach
14641462
height_to_hash = self.full_node.blockchain.height_to_hash
14651463
header_hashes: list[bytes32] = []
14661464
for i in range(request.start_height, request.end_height + 1):
@@ -1470,6 +1468,8 @@ async def request_block_headers(self, request: wallet_protocol.RequestBlockHeade
14701468
header_hashes.append(header_hash)
14711469

14721470
blocks_bytes = await self.full_node.block_store.get_block_bytes_by_hash(header_hashes)
1471+
except ValueError:
1472+
return make_msg(ProtocolMessageTypes.reject_block_headers, reject)
14731473
if len(blocks_bytes) != (request.end_height - request.start_height + 1): # +1 because interval is inclusive
14741474
return make_msg(ProtocolMessageTypes.reject_block_headers, reject)
14751475
return_filter = request.return_filter

0 commit comments

Comments
 (0)