From 3e5242283c2ccc172102724dffd0ed11a7ca0cee Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Thu, 5 Sep 2024 23:48:40 +0300 Subject: [PATCH] fix: update `blocks.tip.*` stats in `ConnectTip`/`DisconnectTip` instead of `ConnectBlock` --- src/validation.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/validation.cpp b/src/validation.cpp index 97eb0a7ce6..cdba67dfae 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -2623,6 +2623,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. @@ -2681,6 +2683,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; } @@ -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 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->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)); return true;