Skip to content

Commit b92bedf

Browse files
committed
Improve exceptions
1 parent 3d72405 commit b92bedf

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

chia/full_node/block_store.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
from chia.util.errors import Err
1919
from chia.util.lru_cache import LRUCache
2020

21+
22+
class UnsupportedDatabaseVersionError(Exception):
23+
"""Raised when a method is called with an unsupported database version."""
24+
25+
2126
log = logging.getLogger(__name__)
2227

2328

@@ -478,7 +483,7 @@ async def get_block_bytes_in_range(
478483
"""
479484

480485
if self.db_wrapper.db_version != 2:
481-
raise NotImplementedError("get_block_bytes_in_range requires DB version 2")
486+
raise UnsupportedDatabaseVersionError("get_block_bytes_in_range requires DB version 2")
482487
async with self.db_wrapper.reader_no_transaction() as conn:
483488
async with conn.execute(
484489
"SELECT block FROM full_blocks WHERE height >= ? AND height <= ? AND in_main_chain=1",

chia/full_node/full_node_api.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
from chia.consensus.get_block_generator import get_block_generator
4242
from chia.consensus.pot_iterations import calculate_ip_iters, calculate_iterations_quality, calculate_sp_iters
4343
from chia.consensus.signage_point import SignagePoint
44+
from chia.full_node.block_store import UnsupportedDatabaseVersionError
4445
from chia.full_node.coin_store import CoinStore
4546
from chia.full_node.fee_estimator_interface import FeeEstimatorInterface
4647
from chia.full_node.full_block_utils import get_height_and_tx_status_from_block, header_block_from_block
@@ -1457,7 +1458,9 @@ async def request_block_headers(self, request: wallet_protocol.RequestBlockHeade
14571458
blocks_bytes = await self.full_node.block_store.get_block_bytes_in_range(
14581459
request.start_height, request.end_height
14591460
)
1460-
except NotImplementedError:
1461+
except ValueError:
1462+
return make_msg(ProtocolMessageTypes.reject_block_headers, reject)
1463+
except UnsupportedDatabaseVersionError:
14611464
# The underlying block store may not support this optimized call
14621465
# (e.g. v1 DB). In this case, we fall back to the legacy approach
14631466
height_to_hash = self.full_node.blockchain.height_to_hash
@@ -1469,8 +1472,6 @@ async def request_block_headers(self, request: wallet_protocol.RequestBlockHeade
14691472
header_hashes.append(header_hash)
14701473

14711474
blocks_bytes = await self.full_node.block_store.get_block_bytes_by_hash(header_hashes)
1472-
except ValueError:
1473-
return make_msg(ProtocolMessageTypes.reject_block_headers, reject)
14741475
if len(blocks_bytes) != (request.end_height - request.start_height + 1): # +1 because interval is inclusive
14751476
return make_msg(ProtocolMessageTypes.reject_block_headers, reject)
14761477
return_filter = request.return_filter

0 commit comments

Comments
 (0)