From 9edfe23f76036e1a7c6dc2f9a4b1a4ec7cb7ca5d Mon Sep 17 00:00:00 2001 From: arvidn Date: Tue, 17 Oct 2023 22:04:23 +0200 Subject: [PATCH] log when entering the slow-path of validating orphaned blocks. Ideally, we don't get here --- chia/consensus/blockchain.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/chia/consensus/blockchain.py b/chia/consensus/blockchain.py index 871fd1f0fe9b..e63046362e90 100644 --- a/chia/consensus/blockchain.py +++ b/chia/consensus/blockchain.py @@ -5,6 +5,7 @@ import enum import logging import multiprocessing +import time import traceback from concurrent.futures import Executor from concurrent.futures.process import ProcessPoolExecutor @@ -353,14 +354,27 @@ async def add_block( fork_height = block.height - len(fork_chain) - 1 fork_info = ForkInfo(fork_height, fork_height, fork_hash) + log.warning( + f"slow path in block validation. Building coin set for fork ({fork_height}, {block.height})" + ) + # now run all the blocks of the fork to compute the additions # and removals. They are recorded in the fork_info object + counter = 0 + start = time.monotonic() for height in range(fork_info.fork_height + 1, block.height): fork_block: Optional[FullBlock] = await self.block_store.get_full_block(fork_chain[uint32(height)]) assert fork_block is not None assert fork_block.height - 1 == fork_info.peak_height assert fork_block.height == 0 or fork_block.prev_header_hash == fork_info.peak_hash await self.run_single_block(fork_block, fork_info) + counter += 1 + end = time.monotonic() + log.info( + f"executed {counter} block generators in {end - start:2f} s. " + f"{len(fork_info.additions_since_fork)} additions, " + f"{len(fork_info.removals_since_fork)} removals" + ) else: temporary_fork_info = False