@@ -2399,15 +2399,6 @@ static unsigned int GetBlockScriptFlags(const CBlockIndex& block_index, const Ch
23992399}
24002400
24012401
2402- static SteadyClock::duration time_check{};
2403- static SteadyClock::duration time_forks{};
2404- static SteadyClock::duration time_connect{};
2405- static SteadyClock::duration time_verify{};
2406- static SteadyClock::duration time_undo{};
2407- static SteadyClock::duration time_index{};
2408- static SteadyClock::duration time_total{};
2409- static int64_t num_blocks_total = 0 ;
2410-
24112402/* * Apply the effects of this block (with given index) on the UTXO set represented by coins.
24122403 * Validity checks that depend on the UTXO set are also done; ConnectBlock()
24132404 * can fail if those validity checks fail (among other reasons). */
@@ -2452,7 +2443,7 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
24522443 uint256 hashPrevBlock = pindex->pprev == nullptr ? uint256 () : pindex->pprev ->GetBlockHash ();
24532444 assert (hashPrevBlock == view.GetBestBlock ());
24542445
2455- num_blocks_total++;
2446+ m_chainman. num_blocks_total ++;
24562447
24572448 // Special case for the genesis block, skipping connection of its transactions
24582449 // (its coinbase is unspendable)
@@ -2494,11 +2485,11 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
24942485 }
24952486
24962487 const auto time_1{SteadyClock::now ()};
2497- time_check += time_1 - time_start;
2488+ m_chainman. time_check += time_1 - time_start;
24982489 LogPrint (BCLog::BENCH, " - Sanity checks: %.2fms [%.2fs (%.2fms/blk)]\n " ,
24992490 Ticks<MillisecondsDouble>(time_1 - time_start),
2500- Ticks<SecondsDouble>(time_check),
2501- Ticks<MillisecondsDouble>(time_check) / num_blocks_total);
2491+ Ticks<SecondsDouble>(m_chainman. time_check ),
2492+ Ticks<MillisecondsDouble>(m_chainman. time_check ) / m_chainman. num_blocks_total );
25022493
25032494 // Do not allow blocks that contain transactions which 'overwrite' older transactions,
25042495 // unless those are already completely spent.
@@ -2596,11 +2587,11 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
25962587 unsigned int flags{GetBlockScriptFlags (*pindex, m_chainman)};
25972588
25982589 const auto time_2{SteadyClock::now ()};
2599- time_forks += time_2 - time_1;
2590+ m_chainman. time_forks += time_2 - time_1;
26002591 LogPrint (BCLog::BENCH, " - Fork checks: %.2fms [%.2fs (%.2fms/blk)]\n " ,
26012592 Ticks<MillisecondsDouble>(time_2 - time_1),
2602- Ticks<SecondsDouble>(time_forks),
2603- Ticks<MillisecondsDouble>(time_forks) / num_blocks_total);
2593+ Ticks<SecondsDouble>(m_chainman. time_forks ),
2594+ Ticks<MillisecondsDouble>(m_chainman. time_forks ) / m_chainman. num_blocks_total );
26042595
26052596 CBlockUndo blockundo;
26062597
@@ -2687,12 +2678,12 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
26872678 UpdateCoins (tx, view, i == 0 ? undoDummy : blockundo.vtxundo .back (), pindex->nHeight );
26882679 }
26892680 const auto time_3{SteadyClock::now ()};
2690- time_connect += time_3 - time_2;
2681+ m_chainman. time_connect += time_3 - time_2;
26912682 LogPrint (BCLog::BENCH, " - Connect %u transactions: %.2fms (%.3fms/tx, %.3fms/txin) [%.2fs (%.2fms/blk)]\n " , (unsigned )block.vtx .size (),
26922683 Ticks<MillisecondsDouble>(time_3 - time_2), Ticks<MillisecondsDouble>(time_3 - time_2) / block.vtx .size (),
26932684 nInputs <= 1 ? 0 : Ticks<MillisecondsDouble>(time_3 - time_2) / (nInputs - 1 ),
2694- Ticks<SecondsDouble>(time_connect),
2695- Ticks<MillisecondsDouble>(time_connect) / num_blocks_total);
2685+ Ticks<SecondsDouble>(m_chainman. time_connect ),
2686+ Ticks<MillisecondsDouble>(m_chainman. time_connect ) / m_chainman. num_blocks_total );
26962687
26972688 CAmount blockReward = nFees + GetBlockSubsidy (pindex->nHeight , params.GetConsensus ());
26982689 if (block.vtx [0 ]->GetValueOut () > blockReward) {
@@ -2705,12 +2696,12 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
27052696 return state.Invalid (BlockValidationResult::BLOCK_CONSENSUS, " block-validation-failed" );
27062697 }
27072698 const auto time_4{SteadyClock::now ()};
2708- time_verify += time_4 - time_2;
2699+ m_chainman. time_verify += time_4 - time_2;
27092700 LogPrint (BCLog::BENCH, " - Verify %u txins: %.2fms (%.3fms/txin) [%.2fs (%.2fms/blk)]\n " , nInputs - 1 ,
27102701 Ticks<MillisecondsDouble>(time_4 - time_2),
27112702 nInputs <= 1 ? 0 : Ticks<MillisecondsDouble>(time_4 - time_2) / (nInputs - 1 ),
2712- Ticks<SecondsDouble>(time_verify),
2713- Ticks<MillisecondsDouble>(time_verify) / num_blocks_total);
2703+ Ticks<SecondsDouble>(m_chainman. time_verify ),
2704+ Ticks<MillisecondsDouble>(m_chainman. time_verify ) / m_chainman. num_blocks_total );
27142705
27152706 if (fJustCheck )
27162707 return true ;
@@ -2720,11 +2711,11 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
27202711 }
27212712
27222713 const auto time_5{SteadyClock::now ()};
2723- time_undo += time_5 - time_4;
2714+ m_chainman. time_undo += time_5 - time_4;
27242715 LogPrint (BCLog::BENCH, " - Write undo data: %.2fms [%.2fs (%.2fms/blk)]\n " ,
27252716 Ticks<MillisecondsDouble>(time_5 - time_4),
2726- Ticks<SecondsDouble>(time_undo),
2727- Ticks<MillisecondsDouble>(time_undo) / num_blocks_total);
2717+ Ticks<SecondsDouble>(m_chainman. time_undo ),
2718+ Ticks<MillisecondsDouble>(m_chainman. time_undo ) / m_chainman. num_blocks_total );
27282719
27292720 if (!pindex->IsValid (BLOCK_VALID_SCRIPTS)) {
27302721 pindex->RaiseValidity (BLOCK_VALID_SCRIPTS);
@@ -2735,11 +2726,11 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
27352726 view.SetBestBlock (pindex->GetBlockHash ());
27362727
27372728 const auto time_6{SteadyClock::now ()};
2738- time_index += time_6 - time_5;
2729+ m_chainman. time_index += time_6 - time_5;
27392730 LogPrint (BCLog::BENCH, " - Index writing: %.2fms [%.2fs (%.2fms/blk)]\n " ,
27402731 Ticks<MillisecondsDouble>(time_6 - time_5),
2741- Ticks<SecondsDouble>(time_index),
2742- Ticks<MillisecondsDouble>(time_index) / num_blocks_total);
2732+ Ticks<SecondsDouble>(m_chainman. time_index ),
2733+ Ticks<MillisecondsDouble>(m_chainman. time_index ) / m_chainman. num_blocks_total );
27432734
27442735 TRACE6 (validation, block_connected,
27452736 block_hash.data (),
@@ -3097,11 +3088,6 @@ bool Chainstate::DisconnectTip(BlockValidationState& state, DisconnectedBlockTra
30973088 return true ;
30983089}
30993090
3100- static SteadyClock::duration time_connect_total{};
3101- static SteadyClock::duration time_flush{};
3102- static SteadyClock::duration time_chainstate{};
3103- static SteadyClock::duration time_post_connect{};
3104-
31053091struct PerBlockConnectTrace {
31063092 CBlockIndex* pindex = nullptr ;
31073093 std::shared_ptr<const CBlock> pblock;
@@ -3188,31 +3174,31 @@ bool Chainstate::ConnectTip(BlockValidationState& state, CBlockIndex* pindexNew,
31883174 return false ;
31893175 }
31903176 time_3 = SteadyClock::now ();
3191- time_connect_total += time_3 - time_2;
3192- assert (num_blocks_total > 0 );
3177+ m_chainman. time_connect_total += time_3 - time_2;
3178+ assert (m_chainman. num_blocks_total > 0 );
31933179 LogPrint (BCLog::BENCH, " - Connect total: %.2fms [%.2fs (%.2fms/blk)]\n " ,
31943180 Ticks<MillisecondsDouble>(time_3 - time_2),
3195- Ticks<SecondsDouble>(time_connect_total),
3196- Ticks<MillisecondsDouble>(time_connect_total) / num_blocks_total);
3181+ Ticks<SecondsDouble>(m_chainman. time_connect_total ),
3182+ Ticks<MillisecondsDouble>(m_chainman. time_connect_total ) / m_chainman. num_blocks_total );
31973183 bool flushed = view.Flush ();
31983184 assert (flushed);
31993185 }
32003186 const auto time_4{SteadyClock::now ()};
3201- time_flush += time_4 - time_3;
3187+ m_chainman. time_flush += time_4 - time_3;
32023188 LogPrint (BCLog::BENCH, " - Flush: %.2fms [%.2fs (%.2fms/blk)]\n " ,
32033189 Ticks<MillisecondsDouble>(time_4 - time_3),
3204- Ticks<SecondsDouble>(time_flush),
3205- Ticks<MillisecondsDouble>(time_flush) / num_blocks_total);
3190+ Ticks<SecondsDouble>(m_chainman. time_flush ),
3191+ Ticks<MillisecondsDouble>(m_chainman. time_flush ) / m_chainman. num_blocks_total );
32063192 // Write the chain state to disk, if necessary.
32073193 if (!FlushStateToDisk (state, FlushStateMode::IF_NEEDED)) {
32083194 return false ;
32093195 }
32103196 const auto time_5{SteadyClock::now ()};
3211- time_chainstate += time_5 - time_4;
3197+ m_chainman. time_chainstate += time_5 - time_4;
32123198 LogPrint (BCLog::BENCH, " - Writing chainstate: %.2fms [%.2fs (%.2fms/blk)]\n " ,
32133199 Ticks<MillisecondsDouble>(time_5 - time_4),
3214- Ticks<SecondsDouble>(time_chainstate),
3215- Ticks<MillisecondsDouble>(time_chainstate) / num_blocks_total);
3200+ Ticks<SecondsDouble>(m_chainman. time_chainstate ),
3201+ Ticks<MillisecondsDouble>(m_chainman. time_chainstate ) / m_chainman. num_blocks_total );
32163202 // Remove conflicting transactions from the mempool.;
32173203 if (m_mempool) {
32183204 m_mempool->removeForBlock (blockConnecting.vtx , pindexNew->nHeight );
@@ -3223,16 +3209,16 @@ bool Chainstate::ConnectTip(BlockValidationState& state, CBlockIndex* pindexNew,
32233209 UpdateTip (pindexNew);
32243210
32253211 const auto time_6{SteadyClock::now ()};
3226- time_post_connect += time_6 - time_5;
3227- time_total += time_6 - time_1;
3212+ m_chainman. time_post_connect += time_6 - time_5;
3213+ m_chainman. time_total += time_6 - time_1;
32283214 LogPrint (BCLog::BENCH, " - Connect postprocess: %.2fms [%.2fs (%.2fms/blk)]\n " ,
32293215 Ticks<MillisecondsDouble>(time_6 - time_5),
3230- Ticks<SecondsDouble>(time_post_connect),
3231- Ticks<MillisecondsDouble>(time_post_connect) / num_blocks_total);
3216+ Ticks<SecondsDouble>(m_chainman. time_post_connect ),
3217+ Ticks<MillisecondsDouble>(m_chainman. time_post_connect ) / m_chainman. num_blocks_total );
32323218 LogPrint (BCLog::BENCH, " - Connect block: %.2fms [%.2fs (%.2fms/blk)]\n " ,
32333219 Ticks<MillisecondsDouble>(time_6 - time_1),
3234- Ticks<SecondsDouble>(time_total),
3235- Ticks<MillisecondsDouble>(time_total) / num_blocks_total);
3220+ Ticks<SecondsDouble>(m_chainman. time_total ),
3221+ Ticks<MillisecondsDouble>(m_chainman. time_total ) / m_chainman. num_blocks_total );
32363222
32373223 // If we are the background validation chainstate, check to see if we are done
32383224 // validating the snapshot (i.e. our tip has reached the snapshot's base block).
@@ -3423,16 +3409,15 @@ static bool NotifyHeaderTip(ChainstateManager& chainman) LOCKS_EXCLUDED(cs_main)
34233409{
34243410 bool fNotify = false ;
34253411 bool fInitialBlockDownload = false ;
3426- static CBlockIndex* pindexHeaderOld = nullptr ;
34273412 CBlockIndex* pindexHeader = nullptr ;
34283413 {
34293414 LOCK (cs_main);
34303415 pindexHeader = chainman.m_best_header ;
34313416
3432- if (pindexHeader != pindexHeaderOld ) {
3417+ if (pindexHeader != chainman. m_last_notified_header ) {
34333418 fNotify = true ;
34343419 fInitialBlockDownload = chainman.IsInitialBlockDownload ();
3435- pindexHeaderOld = pindexHeader;
3420+ chainman. m_last_notified_header = pindexHeader;
34363421 }
34373422 }
34383423 // Send block tip changed notifications without cs_main
0 commit comments