fix: update blocks.tip.* stats in ConnectTip/DisconnectTip instead of ConnectBlock

This commit is contained in:
UdjinM6 2024-09-05 23:48:40 +03:00 committed by pasta
parent 508bade8c3
commit 3e5242283c
No known key found for this signature in database
GPG Key ID: E2F3D7916E722D38

View File

@ -2623,6 +2623,8 @@ bool CChainState::DisconnectTip(BlockValidationState& state, DisconnectedBlockTr
AssertLockHeld(cs_main); AssertLockHeld(cs_main);
if (m_mempool) AssertLockHeld(m_mempool->cs); if (m_mempool) AssertLockHeld(m_mempool->cs);
int64_t nTime1 = GetTimeMicros();
CBlockIndex *pindexDelete = m_chain.Tip(); CBlockIndex *pindexDelete = m_chain.Tip();
assert(pindexDelete); assert(pindexDelete);
// Read block from disk. // Read block from disk.
@ -2681,6 +2683,19 @@ bool CChainState::DisconnectTip(BlockValidationState& state, DisconnectedBlockTr
// Let wallets know transactions went from 1-confirmed to // Let wallets know transactions went from 1-confirmed to
// 0-confirmed or conflicted: // 0-confirmed or conflicted:
GetMainSignals().BlockDisconnected(pblock, pindexDelete); 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; return true;
} }
@ -2799,7 +2814,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 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); 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);
}
::g_stats_client->timing("ConnectTip_ms", (nTime6 - nTime1) / 1000, 1.0f); ::g_stats_client->timing("ConnectTip_ms", (nTime6 - nTime1) / 1000, 1.0f);
::g_stats_client->gauge("blocks.tip.SizeBytes", ::GetSerializeSize(blockConnecting, PROTOCOL_VERSION), 1.0f);
::g_stats_client->gauge("blocks.tip.Height", m_chain.Height(), 1.0f);
::g_stats_client->gauge("blocks.tip.Version", blockConnecting.nVersion, 1.0f);
::g_stats_client->gauge("blocks.tip.NumTransactions", blockConnecting.vtx.size(), 1.0f);
::g_stats_client->gauge("blocks.tip.SigOps", nSigOps, 1.0f);
connectTrace.BlockConnected(pindexNew, std::move(pthisBlock)); connectTrace.BlockConnected(pindexNew, std::move(pthisBlock));
return true; return true;