Skip to content

Commit

Permalink
fix: update blocks.tip.* stats in ConnectTip/DisconnectTip inst…
Browse files Browse the repository at this point in the history
…ead of `ConnectBlock`
  • Loading branch information
UdjinM6 authored and PastaPastaPasta committed Sep 10, 2024
1 parent 63241c2 commit 2f26f78
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2283,11 +2283,6 @@ bool CChainState::ConnectBlock(const CBlock& block, BlockValidationState& state,
LogPrint(BCLog::BENCHMARK, " - Callbacks: %.2fms [%.2fs (%.2fms/blk)]\n", MILLI * (nTime8 - nTime5), nTimeCallbacks * MICRO, nTimeCallbacks * MILLI / nBlocksTotal);

statsClient.timing("ConnectBlock_ms", (nTime8 - nTimeStart) / 1000, 1.0f);
statsClient.gauge("blocks.tip.SizeBytes", ::GetSerializeSize(block, PROTOCOL_VERSION), 1.0f);
statsClient.gauge("blocks.tip.Height", m_chain.Height() + 1, 1.0f); // without the +1, the "tip.Height" doesn't match rpc calls like `getblockcount`
statsClient.gauge("blocks.tip.Version", block.nVersion, 1.0f);
statsClient.gauge("blocks.tip.NumTransactions", block.vtx.size(), 1.0f);
statsClient.gauge("blocks.tip.SigOps", nSigOps, 1.0f);

return true;
}
Expand Down Expand Up @@ -2579,6 +2574,8 @@ bool CChainState::DisconnectTip(BlockValidationState& state, DisconnectedBlockTr
AssertLockHeld(cs_main);
if (m_mempool) AssertLockHeld(m_mempool->cs);

int64_t nTime1 = GetTimeMicros();

CBlockIndex *pindexDelete = m_chain.Tip();
assert(pindexDelete);
// Read block from disk.
Expand Down Expand Up @@ -2625,6 +2622,19 @@ bool CChainState::DisconnectTip(BlockValidationState& state, DisconnectedBlockTr
// Let wallets know transactions went from 1-confirmed to
// 0-confirmed or conflicted:
GetMainSignals().BlockDisconnected(pblock, pindexDelete);

int64_t nTime2 = GetTimeMicros();

unsigned int nSigOps = 0;
for (const auto& tx : block.vtx) {
nSigOps += GetLegacySigOpCount(*tx);
}
statsClient.timing("DisconnectTip_ms", (nTime2 - nTime1) / 1000, 1.0f);
statsClient.gauge("blocks.tip.SizeBytes", ::GetSerializeSize(block, PROTOCOL_VERSION), 1.0f);
statsClient.gauge("blocks.tip.Height", m_chain.Height(), 1.0f);
statsClient.gauge("blocks.tip.Version", block.nVersion, 1.0f);
statsClient.gauge("blocks.tip.NumTransactions", block.vtx.size(), 1.0f);
statsClient.gauge("blocks.tip.SigOps", nSigOps, 1.0f);
return true;
}

Expand Down Expand Up @@ -2743,7 +2753,16 @@ bool CChainState::ConnectTip(BlockValidationState& state, CBlockIndex* pindexNew
LogPrint(BCLog::BENCHMARK, " - Connect postprocess: %.2fms [%.2fs (%.2fms/blk)]\n", (nTime6 - nTime5) * MILLI, nTimePostConnect * MICRO, nTimePostConnect * MILLI / nBlocksTotal);
LogPrint(BCLog::BENCHMARK, "- Connect block: %.2fms [%.2fs (%.2fms/blk)]\n", (nTime6 - nTime1) * MILLI, nTimeTotal * MICRO, nTimeTotal * MILLI / nBlocksTotal);

unsigned int nSigOps = 0;
for (const auto& tx : blockConnecting.vtx) {
nSigOps += GetLegacySigOpCount(*tx);
}
statsClient.timing("ConnectTip_ms", (nTime6 - nTime1) / 1000, 1.0f);
statsClient.gauge("blocks.tip.SizeBytes", ::GetSerializeSize(blockConnecting, PROTOCOL_VERSION), 1.0f);
statsClient.gauge("blocks.tip.Height", m_chain.Height(), 1.0f);
statsClient.gauge("blocks.tip.Version", blockConnecting.nVersion, 1.0f);
statsClient.gauge("blocks.tip.NumTransactions", blockConnecting.vtx.size(), 1.0f);
statsClient.gauge("blocks.tip.SigOps", nSigOps, 1.0f);

connectTrace.BlockConnected(pindexNew, std::move(pthisBlock));
return true;
Expand Down

0 comments on commit 2f26f78

Please sign in to comment.