@@ -2399,15 +2399,6 @@ static unsigned int GetBlockScriptFlags(const CBlockIndex& block_index, const Ch
2399
2399
}
2400
2400
2401
2401
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
-
2411
2402
/* * Apply the effects of this block (with given index) on the UTXO set represented by coins.
2412
2403
* Validity checks that depend on the UTXO set are also done; ConnectBlock()
2413
2404
* can fail if those validity checks fail (among other reasons). */
@@ -2452,7 +2443,7 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
2452
2443
uint256 hashPrevBlock = pindex->pprev == nullptr ? uint256 () : pindex->pprev ->GetBlockHash ();
2453
2444
assert (hashPrevBlock == view.GetBestBlock ());
2454
2445
2455
- num_blocks_total++;
2446
+ m_chainman. num_blocks_total ++;
2456
2447
2457
2448
// Special case for the genesis block, skipping connection of its transactions
2458
2449
// (its coinbase is unspendable)
@@ -2494,11 +2485,11 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
2494
2485
}
2495
2486
2496
2487
const auto time_1{SteadyClock::now ()};
2497
- time_check += time_1 - time_start;
2488
+ m_chainman. time_check += time_1 - time_start;
2498
2489
LogPrint (BCLog::BENCH, " - Sanity checks: %.2fms [%.2fs (%.2fms/blk)]\n " ,
2499
2490
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 );
2502
2493
2503
2494
// Do not allow blocks that contain transactions which 'overwrite' older transactions,
2504
2495
// unless those are already completely spent.
@@ -2596,11 +2587,11 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
2596
2587
unsigned int flags{GetBlockScriptFlags (*pindex, m_chainman)};
2597
2588
2598
2589
const auto time_2{SteadyClock::now ()};
2599
- time_forks += time_2 - time_1;
2590
+ m_chainman. time_forks += time_2 - time_1;
2600
2591
LogPrint (BCLog::BENCH, " - Fork checks: %.2fms [%.2fs (%.2fms/blk)]\n " ,
2601
2592
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 );
2604
2595
2605
2596
CBlockUndo blockundo;
2606
2597
@@ -2687,12 +2678,12 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
2687
2678
UpdateCoins (tx, view, i == 0 ? undoDummy : blockundo.vtxundo .back (), pindex->nHeight );
2688
2679
}
2689
2680
const auto time_3{SteadyClock::now ()};
2690
- time_connect += time_3 - time_2;
2681
+ m_chainman. time_connect += time_3 - time_2;
2691
2682
LogPrint (BCLog::BENCH, " - Connect %u transactions: %.2fms (%.3fms/tx, %.3fms/txin) [%.2fs (%.2fms/blk)]\n " , (unsigned )block.vtx .size (),
2692
2683
Ticks<MillisecondsDouble>(time_3 - time_2), Ticks<MillisecondsDouble>(time_3 - time_2) / block.vtx .size (),
2693
2684
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 );
2696
2687
2697
2688
CAmount blockReward = nFees + GetBlockSubsidy (pindex->nHeight , params.GetConsensus ());
2698
2689
if (block.vtx [0 ]->GetValueOut () > blockReward) {
@@ -2705,12 +2696,12 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
2705
2696
return state.Invalid (BlockValidationResult::BLOCK_CONSENSUS, " block-validation-failed" );
2706
2697
}
2707
2698
const auto time_4{SteadyClock::now ()};
2708
- time_verify += time_4 - time_2;
2699
+ m_chainman. time_verify += time_4 - time_2;
2709
2700
LogPrint (BCLog::BENCH, " - Verify %u txins: %.2fms (%.3fms/txin) [%.2fs (%.2fms/blk)]\n " , nInputs - 1 ,
2710
2701
Ticks<MillisecondsDouble>(time_4 - time_2),
2711
2702
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 );
2714
2705
2715
2706
if (fJustCheck )
2716
2707
return true ;
@@ -2720,11 +2711,11 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
2720
2711
}
2721
2712
2722
2713
const auto time_5{SteadyClock::now ()};
2723
- time_undo += time_5 - time_4;
2714
+ m_chainman. time_undo += time_5 - time_4;
2724
2715
LogPrint (BCLog::BENCH, " - Write undo data: %.2fms [%.2fs (%.2fms/blk)]\n " ,
2725
2716
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 );
2728
2719
2729
2720
if (!pindex->IsValid (BLOCK_VALID_SCRIPTS)) {
2730
2721
pindex->RaiseValidity (BLOCK_VALID_SCRIPTS);
@@ -2735,11 +2726,11 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
2735
2726
view.SetBestBlock (pindex->GetBlockHash ());
2736
2727
2737
2728
const auto time_6{SteadyClock::now ()};
2738
- time_index += time_6 - time_5;
2729
+ m_chainman. time_index += time_6 - time_5;
2739
2730
LogPrint (BCLog::BENCH, " - Index writing: %.2fms [%.2fs (%.2fms/blk)]\n " ,
2740
2731
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 );
2743
2734
2744
2735
TRACE6 (validation, block_connected,
2745
2736
block_hash.data (),
@@ -3097,11 +3088,6 @@ bool Chainstate::DisconnectTip(BlockValidationState& state, DisconnectedBlockTra
3097
3088
return true ;
3098
3089
}
3099
3090
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
-
3105
3091
struct PerBlockConnectTrace {
3106
3092
CBlockIndex* pindex = nullptr ;
3107
3093
std::shared_ptr<const CBlock> pblock;
@@ -3188,31 +3174,31 @@ bool Chainstate::ConnectTip(BlockValidationState& state, CBlockIndex* pindexNew,
3188
3174
return false ;
3189
3175
}
3190
3176
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 );
3193
3179
LogPrint (BCLog::BENCH, " - Connect total: %.2fms [%.2fs (%.2fms/blk)]\n " ,
3194
3180
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 );
3197
3183
bool flushed = view.Flush ();
3198
3184
assert (flushed);
3199
3185
}
3200
3186
const auto time_4{SteadyClock::now ()};
3201
- time_flush += time_4 - time_3;
3187
+ m_chainman. time_flush += time_4 - time_3;
3202
3188
LogPrint (BCLog::BENCH, " - Flush: %.2fms [%.2fs (%.2fms/blk)]\n " ,
3203
3189
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 );
3206
3192
// Write the chain state to disk, if necessary.
3207
3193
if (!FlushStateToDisk (state, FlushStateMode::IF_NEEDED)) {
3208
3194
return false ;
3209
3195
}
3210
3196
const auto time_5{SteadyClock::now ()};
3211
- time_chainstate += time_5 - time_4;
3197
+ m_chainman. time_chainstate += time_5 - time_4;
3212
3198
LogPrint (BCLog::BENCH, " - Writing chainstate: %.2fms [%.2fs (%.2fms/blk)]\n " ,
3213
3199
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 );
3216
3202
// Remove conflicting transactions from the mempool.;
3217
3203
if (m_mempool) {
3218
3204
m_mempool->removeForBlock (blockConnecting.vtx , pindexNew->nHeight );
@@ -3223,16 +3209,16 @@ bool Chainstate::ConnectTip(BlockValidationState& state, CBlockIndex* pindexNew,
3223
3209
UpdateTip (pindexNew);
3224
3210
3225
3211
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;
3228
3214
LogPrint (BCLog::BENCH, " - Connect postprocess: %.2fms [%.2fs (%.2fms/blk)]\n " ,
3229
3215
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 );
3232
3218
LogPrint (BCLog::BENCH, " - Connect block: %.2fms [%.2fs (%.2fms/blk)]\n " ,
3233
3219
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 );
3236
3222
3237
3223
// If we are the background validation chainstate, check to see if we are done
3238
3224
// 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)
3423
3409
{
3424
3410
bool fNotify = false ;
3425
3411
bool fInitialBlockDownload = false ;
3426
- static CBlockIndex* pindexHeaderOld = nullptr ;
3427
3412
CBlockIndex* pindexHeader = nullptr ;
3428
3413
{
3429
3414
LOCK (cs_main);
3430
3415
pindexHeader = chainman.m_best_header ;
3431
3416
3432
- if (pindexHeader != pindexHeaderOld ) {
3417
+ if (pindexHeader != chainman. m_last_notified_header ) {
3433
3418
fNotify = true ;
3434
3419
fInitialBlockDownload = chainman.IsInitialBlockDownload ();
3435
- pindexHeaderOld = pindexHeader;
3420
+ chainman. m_last_notified_header = pindexHeader;
3436
3421
}
3437
3422
}
3438
3423
// Send block tip changed notifications without cs_main
0 commit comments