From 4f144a6092440138865a90a715f239691b7846d6 Mon Sep 17 00:00:00 2001 From: almogdepaz Date: Tue, 14 Jan 2025 13:16:45 +0200 Subject: [PATCH] use try_block_record --- chia/consensus/difficulty_adjustment.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/chia/consensus/difficulty_adjustment.py b/chia/consensus/difficulty_adjustment.py index 63a85d27fb04..5fda123735c4 100644 --- a/chia/consensus/difficulty_adjustment.py +++ b/chia/consensus/difficulty_adjustment.py @@ -224,11 +224,10 @@ def _get_next_sub_slot_iters( if next_height < constants.EPOCH_BLOCKS: return uint64(constants.SUB_SLOT_ITERS_STARTING) - if not blocks.contains_block(prev_header_hash): + prev_b = blocks.try_block_record(prev_header_hash) + if prev_b is None: raise ValueError(f"Header hash {prev_header_hash} not in blocks") - prev_b: BlockRecord = blocks.block_record(prev_header_hash) - # If we are in the same epoch, return same ssi if not skip_epoch_check: _, can_finish_epoch = can_finish_sub_and_full_epoch( @@ -304,11 +303,10 @@ def _get_next_difficulty( # We are in the first epoch return uint64(constants.DIFFICULTY_STARTING) - if not blocks.contains_block(prev_header_hash): + prev_b = blocks.try_block_record(prev_header_hash) + if prev_b is None: raise ValueError(f"Header hash {prev_header_hash} not in blocks") - prev_b: BlockRecord = blocks.block_record(prev_header_hash) - # If we are in the same slot as previous block, return same difficulty if not skip_epoch_check: _, can_finish_epoch = can_finish_sub_and_full_epoch(