diff --git a/chia/full_node/full_node.py b/chia/full_node/full_node.py index 3396bfe341c4..8f5266c149c2 100644 --- a/chia/full_node/full_node.py +++ b/chia/full_node/full_node.py @@ -620,6 +620,7 @@ async def short_sync_batch(self, peer: WSChiaConnection, start_height: uint32, t fork_hash = self.constants.GENESIS_CHALLENGE assert fork_hash fork_info = ForkInfo(start_height - 1, start_height - 1, fork_hash) + blockchain = AugmentedBlockchain(self.blockchain) for height in range(start_height, target_height, batch_size): end_height = min(target_height, height + batch_size) request = RequestBlocks(uint32(height), uint32(end_height), True) @@ -638,7 +639,7 @@ async def short_sync_batch(self, peer: WSChiaConnection, start_height: uint32, t ) vs = ValidationState(ssi, diff, None) success, state_change_summary = await self.add_block_batch( - response.blocks, peer_info, fork_info, vs + response.blocks, peer_info, fork_info, vs, blockchain ) if not success: raise ValueError(f"Error short batch syncing, failed to validate blocks {height}-{end_height}") @@ -1478,13 +1479,13 @@ async def add_block_batch( peer_info: PeerInfo, fork_info: ForkInfo, vs: ValidationState, # in-out parameter + blockchain: AugmentedBlockchain, wp_summaries: Optional[list[SubEpochSummary]] = None, ) -> tuple[bool, Optional[StateChangeSummary]]: # Precondition: All blocks must be contiguous blocks, index i+1 must be the parent of index i # Returns a bool for success, as well as a StateChangeSummary if the peak was advanced pre_validate_start = time.monotonic() - blockchain = AugmentedBlockchain(self.blockchain) blocks_to_validate = await self.skip_blocks(blockchain, all_blocks, fork_info, vs) if len(blocks_to_validate) == 0: @@ -1547,7 +1548,7 @@ async def skip_blocks( # we have already validated this block once, no need to do it again. # however, if this block is not part of the main chain, we need to # update the fork context with its additions and removals - if blockchain.height_to_hash(block.height) == header_hash: + if self.blockchain.height_to_hash(block.height) == header_hash: # we're on the main chain, just fast-forward the fork height fork_info.reset(block.height, header_hash) else: @@ -1628,6 +1629,8 @@ async def add_prevalidated_blocks( vs.ssi = cc_sub_slot.new_sub_slot_iters assert cc_sub_slot.new_difficulty is not None vs.difficulty = cc_sub_slot.new_difficulty + if expected_sub_slot_iters != vs.ssi: + self.log.info(f"block {block.height} fails") assert expected_sub_slot_iters == vs.ssi assert expected_difficulty == vs.difficulty result, error, state_change_summary = await self.blockchain.add_block( diff --git a/chia/simulator/add_blocks_in_batches.py b/chia/simulator/add_blocks_in_batches.py index dc0a1910060b..319bd3c02f97 100644 --- a/chia/simulator/add_blocks_in_batches.py +++ b/chia/simulator/add_blocks_in_batches.py @@ -8,6 +8,7 @@ from chia.types.full_block import FullBlock from chia.types.peer_info import PeerInfo from chia.types.validation_state import ValidationState +from chia.util.augmented_chain import AugmentedBlockchain from chia.util.batches import to_batches from chia.util.ints import uint32 @@ -34,14 +35,14 @@ async def add_blocks_in_batches( fork_info = ForkInfo(fork_height, blocks[0].height - 1, peak_hash) vs = ValidationState(ssi, diff, None) - + blockchain = AugmentedBlockchain(full_node.blockchain) for block_batch in to_batches(blocks, 64): b = block_batch.entries[0] if (b.height % 128) == 0: print(f"main chain: {b.height:4} weight: {b.weight}") # vs is updated by the call to add_block_batch() success, state_change_summary = await full_node.add_block_batch( - block_batch.entries, PeerInfo("0.0.0.0", 0), fork_info, vs + block_batch.entries, PeerInfo("0.0.0.0", 0), fork_info, vs, blockchain ) assert success is True if state_change_summary is not None: diff --git a/chia/util/augmented_chain.py b/chia/util/augmented_chain.py index 45f6a32c3edf..104fae86a1e1 100644 --- a/chia/util/augmented_chain.py +++ b/chia/util/augmented_chain.py @@ -81,7 +81,7 @@ async def get_block_record_from_db(self, header_hash: bytes32) -> Optional[Block def add_block_record(self, block_record: BlockRecord) -> None: self._underlying.add_block_record(block_record) - + self._height_to_hash[block_record.height] = block_record.header_hash # now that we're adding the block to the underlying blockchain, we don't # need to keep the extra block around anymore hh = block_record.header_hash