Skip to content

Commit caebb0c

Browse files
committed
merge bitcoin#24216: improve connect bench logging
1 parent 4e28b54 commit caebb0c

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

src/validation.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2116,6 +2116,7 @@ static unsigned int GetBlockScriptFlags(const CBlockIndex* pindex, const Consens
21162116
static int64_t nTimeCheck = 0;
21172117
static int64_t nTimeForks = 0;
21182118
static int64_t nTimeVerify = 0;
2119+
static int64_t nTimeUndo = 0;
21192120
static int64_t nTimeISFilter = 0;
21202121
static int64_t nTimeSubsidy = 0;
21212122
static int64_t nTimeValueValid = 0;
@@ -2526,17 +2527,20 @@ bool CChainState::ConnectBlock(const CBlock& block, BlockValidationState& state,
25262527
if (fJustCheck)
25272528
return true;
25282529

2530+
int64_t nTime6 = GetTimeMicros();
2531+
25292532
if (!m_blockman.WriteUndoDataForBlock(blockundo, state, pindex, m_params)) {
25302533
return false;
25312534
}
25322535

2536+
int64_t nTime7 = GetTimeMicros(); nTimeUndo += nTime7 - nTime6;
2537+
LogPrint(BCLog::BENCHMARK, " - Write undo data: %.2fms [%.2fs (%.2fms/blk)]\n", MILLI * (nTime7 - nTime6), nTimeUndo * MICRO, nTimeUndo * MILLI / nBlocksTotal);
2538+
25332539
if (!pindex->IsValid(BLOCK_VALID_SCRIPTS)) {
25342540
pindex->RaiseValidity(BLOCK_VALID_SCRIPTS);
25352541
m_blockman.m_dirty_blockindex.insert(pindex);
25362542
}
25372543

2538-
int64_t nTime6 = GetTimeMicros();
2539-
25402544
if (fAddressIndex) {
25412545
if (!m_blockman.m_block_tree_db->WriteAddressIndex(addressIndex)) {
25422546
return AbortNode(state, "Failed to write address index");
@@ -2555,8 +2559,8 @@ bool CChainState::ConnectBlock(const CBlock& block, BlockValidationState& state,
25552559
if (!m_blockman.m_block_tree_db->WriteTimestampIndex(CTimestampIndexKey(pindex->nTime, pindex->GetBlockHash())))
25562560
return AbortNode(state, "Failed to write timestamp index");
25572561

2558-
int64_t nTime7 = GetTimeMicros(); nTimeIndexWrite += nTime7 - nTime6;
2559-
LogPrint(BCLog::BENCHMARK, " - Index writing: %.2fms [%.2fs (%.2fms/blk)]\n", MILLI * (nTime7 - nTime6), nTimeIndexWrite * MICRO, nTimeIndexWrite * MILLI / nBlocksTotal);
2562+
int64_t nTime8 = GetTimeMicros(); nTimeIndexWrite += nTime8 - nTime7;
2563+
LogPrint(BCLog::BENCHMARK, " - Index writing: %.2fms [%.2fs (%.2fms/blk)]\n", MILLI * (nTime8 - nTime7), nTimeIndexWrite * MICRO, nTimeIndexWrite * MILLI / nBlocksTotal);
25602564

25612565
// add this block to the view's block chain
25622566
view.SetBestBlock(pindex->GetBlockHash());
@@ -2568,15 +2572,15 @@ bool CChainState::ConnectBlock(const CBlock& block, BlockValidationState& state,
25682572
uiInterface.NotifyMasternodeListChanged(mnlu.new_list, pindex);
25692573
}
25702574

2571-
::g_stats_client->timing("ConnectBlock_ms", (nTime7 - nTimeStart) / 1000, 1.0f);
2575+
::g_stats_client->timing("ConnectBlock_ms", (nTime8 - nTimeStart) / 1000, 1.0f);
25722576

25732577
TRACE6(validation, block_connected,
25742578
block_hash.data(),
25752579
pindex->nHeight,
25762580
block.vtx.size(),
25772581
nInputs,
25782582
nSigOps,
2579-
nTime7 - nTimeStart // in microseconds (µs)
2583+
nTime8 - nTimeStart // in microseconds (µs)
25802584
);
25812585

25822586
return true;
@@ -2963,7 +2967,7 @@ bool CChainState::DisconnectTip(BlockValidationState& state, DisconnectedBlockTr
29632967
return true;
29642968
}
29652969

2966-
static int64_t nTimeReadFromDisk = 0;
2970+
static int64_t nTimeReadFromDiskTotal = 0;
29672971
static int64_t nTimeConnectTotal = 0;
29682972
static int64_t nTimeFlush = 0;
29692973
static int64_t nTimeChainState = 0;
@@ -3031,13 +3035,14 @@ bool CChainState::ConnectTip(BlockValidationState& state, CBlockIndex* pindexNew
30313035
}
30323036
pthisBlock = pblockNew;
30333037
} else {
3038+
LogPrint(BCLog::BENCHMARK, " - Using cached block\n");
30343039
pthisBlock = pblock;
30353040
}
30363041
const CBlock& blockConnecting = *pthisBlock;
30373042
// Apply the block atomically to the chain state.
3038-
int64_t nTime2 = GetTimeMicros(); nTimeReadFromDisk += nTime2 - nTime1;
3043+
int64_t nTime2 = GetTimeMicros(); nTimeReadFromDiskTotal += nTime2 - nTime1;
30393044
int64_t nTime3;
3040-
LogPrint(BCLog::BENCHMARK, " - Load block from disk: %.2fms [%.2fs]\n", (nTime2 - nTime1) * MILLI, nTimeReadFromDisk * MICRO);
3045+
LogPrint(BCLog::BENCHMARK, " - Load block from disk: %.2fms [%.2fs (%.2fms/blk)]\n", (nTime2 - nTime1) * MILLI, nTimeReadFromDiskTotal * MICRO, nTimeReadFromDiskTotal * MILLI / nBlocksTotal);
30413046
{
30423047
auto dbTx = m_evoDb.BeginTransaction();
30433048

0 commit comments

Comments
 (0)