From 63abf4e08dad050d74d2783b02f22e069e7db462 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Mon, 9 Dec 2024 14:48:13 +0100 Subject: [PATCH] optimize add_blocks_in_batches() by adding all blocks in a single batch (avoiding the pipeline stall every 64 blocks) --- chia/simulator/add_blocks_in_batches.py | 35 ++++++++++--------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/chia/simulator/add_blocks_in_batches.py b/chia/simulator/add_blocks_in_batches.py index e72904cba590..9e5979044176 100644 --- a/chia/simulator/add_blocks_in_batches.py +++ b/chia/simulator/add_blocks_in_batches.py @@ -9,7 +9,6 @@ from chia.types.full_block import FullBlock from chia.types.peer_info import PeerInfo from chia.types.validation_state import ValidationState -from chia.util.batches import to_batches from chia.util.ints import uint32 @@ -34,24 +33,18 @@ async def add_blocks_in_batches( vs = ValidationState(ssi, diff, None) - 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, err = await full_node.add_block_batch( - block_batch.entries, - PeerInfo("0.0.0.0", 0), - fork_info, - vs, - ) - assert err is None - assert success is True - if state_change_summary is not None: - peak_fb: Optional[FullBlock] = await full_node.blockchain.get_full_peak() - assert peak_fb is not None - ppp_result: PeakPostProcessingResult = await full_node.peak_post_processing( - peak_fb, state_change_summary, None - ) - await full_node.peak_post_processing_2(peak_fb, None, state_change_summary, ppp_result) + # vs is updated by the call to add_block_batch() + success, state_change_summary, err = await full_node.add_block_batch( + blocks, + PeerInfo("0.0.0.0", 0), + fork_info, + vs, + ) + assert err is None + assert success is True + if state_change_summary is not None: + peak_fb: Optional[FullBlock] = await full_node.blockchain.get_full_peak() + assert peak_fb is not None + ppp_result: PeakPostProcessingResult = await full_node.peak_post_processing(peak_fb, state_change_summary, None) + await full_node.peak_post_processing_2(peak_fb, None, state_change_summary, ppp_result) await full_node._finish_sync(uint32(max(0, fork_height)))