stats: make statsClient a std::unique_ptr, denote as global variable

This step is needed so we can simplify construction in an upcoming
commit
This commit is contained in:
Kittywhiskers Van Gogh 2024-09-02 11:56:07 +00:00
parent 8c106bb9ce
commit f81951dd00
No known key found for this signature in database
GPG Key ID: 30CD0C065E5C4AAD
8 changed files with 81 additions and 72 deletions

View File

@ -289,6 +289,7 @@ void PrepareShutdown(NodeContext& node)
node.banman.reset(); node.banman.reset();
node.addrman.reset(); node.addrman.reset();
node.netgroupman.reset(); node.netgroupman.reset();
::statsClient.reset();
if (node.mempool && node.mempool->IsLoaded() && node.args->GetBoolArg("-persistmempool", DEFAULT_PERSIST_MEMPOOL)) { if (node.mempool && node.mempool->IsLoaded() && node.args->GetBoolArg("-persistmempool", DEFAULT_PERSIST_MEMPOOL)) {
DumpMempool(*node.mempool); DumpMempool(*node.mempool);
@ -839,12 +840,12 @@ static void PeriodicStats(ArgsManager& args, ChainstateManager& chainman, const
CCoinsStats stats{CoinStatsHashType::NONE}; CCoinsStats stats{CoinStatsHashType::NONE};
chainman.ActiveChainstate().ForceFlushStateToDisk(); chainman.ActiveChainstate().ForceFlushStateToDisk();
if (WITH_LOCK(cs_main, return GetUTXOStats(&chainman.ActiveChainstate().CoinsDB(), std::ref(chainman.m_blockman), stats, RpcInterruptionPoint, chainman.ActiveChain().Tip()))) { if (WITH_LOCK(cs_main, return GetUTXOStats(&chainman.ActiveChainstate().CoinsDB(), std::ref(chainman.m_blockman), stats, RpcInterruptionPoint, chainman.ActiveChain().Tip()))) {
statsClient.gauge("utxoset.tx", stats.nTransactions, 1.0f); ::statsClient->gauge("utxoset.tx", stats.nTransactions, 1.0f);
statsClient.gauge("utxoset.txOutputs", stats.nTransactionOutputs, 1.0f); ::statsClient->gauge("utxoset.txOutputs", stats.nTransactionOutputs, 1.0f);
statsClient.gauge("utxoset.dbSizeBytes", stats.nDiskSize, 1.0f); ::statsClient->gauge("utxoset.dbSizeBytes", stats.nDiskSize, 1.0f);
statsClient.gauge("utxoset.blockHeight", stats.nHeight, 1.0f); ::statsClient->gauge("utxoset.blockHeight", stats.nHeight, 1.0f);
if (stats.total_amount.has_value()) { if (stats.total_amount.has_value()) {
statsClient.gauge("utxoset.totalAmount", (double)stats.total_amount.value() / (double)COIN, 1.0f); ::statsClient->gauge("utxoset.totalAmount", (double)stats.total_amount.value() / (double)COIN, 1.0f);
} }
} else { } else {
// something went wrong // something went wrong
@ -866,22 +867,22 @@ static void PeriodicStats(ArgsManager& args, ChainstateManager& chainman, const
int64_t timeDiff = maxTime - minTime; int64_t timeDiff = maxTime - minTime;
double nNetworkHashPS = workDiff.getdouble() / timeDiff; double nNetworkHashPS = workDiff.getdouble() / timeDiff;
statsClient.gaugeDouble("network.hashesPerSecond", nNetworkHashPS); ::statsClient->gaugeDouble("network.hashesPerSecond", nNetworkHashPS);
statsClient.gaugeDouble("network.terahashesPerSecond", nNetworkHashPS / 1e12); ::statsClient->gaugeDouble("network.terahashesPerSecond", nNetworkHashPS / 1e12);
statsClient.gaugeDouble("network.petahashesPerSecond", nNetworkHashPS / 1e15); ::statsClient->gaugeDouble("network.petahashesPerSecond", nNetworkHashPS / 1e15);
statsClient.gaugeDouble("network.exahashesPerSecond", nNetworkHashPS / 1e18); ::statsClient->gaugeDouble("network.exahashesPerSecond", nNetworkHashPS / 1e18);
// No need for cs_main, we never use null tip here // No need for cs_main, we never use null tip here
statsClient.gaugeDouble("network.difficulty", (double)GetDifficulty(tip)); ::statsClient->gaugeDouble("network.difficulty", (double)GetDifficulty(tip));
statsClient.gauge("transactions.txCacheSize", WITH_LOCK(cs_main, return chainman.ActiveChainstate().CoinsTip().GetCacheSize()), 1.0f); ::statsClient->gauge("transactions.txCacheSize", WITH_LOCK(cs_main, return chainman.ActiveChainstate().CoinsTip().GetCacheSize()), 1.0f);
statsClient.gauge("transactions.totalTransactions", tip->nChainTx, 1.0f); ::statsClient->gauge("transactions.totalTransactions", tip->nChainTx, 1.0f);
{ {
LOCK(mempool.cs); LOCK(mempool.cs);
statsClient.gauge("transactions.mempool.totalTransactions", mempool.size(), 1.0f); ::statsClient->gauge("transactions.mempool.totalTransactions", mempool.size(), 1.0f);
statsClient.gauge("transactions.mempool.totalTxBytes", (int64_t) mempool.GetTotalTxSize(), 1.0f); ::statsClient->gauge("transactions.mempool.totalTxBytes", (int64_t) mempool.GetTotalTxSize(), 1.0f);
statsClient.gauge("transactions.mempool.memoryUsageBytes", (int64_t) mempool.DynamicMemoryUsage(), 1.0f); ::statsClient->gauge("transactions.mempool.memoryUsageBytes", (int64_t) mempool.DynamicMemoryUsage(), 1.0f);
statsClient.gauge("transactions.mempool.minFeePerKb", mempool.GetMinFee(args.GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000).GetFeePerK(), 1.0f); ::statsClient->gauge("transactions.mempool.minFeePerKb", mempool.GetMinFee(args.GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000).GetFeePerK(), 1.0f);
} }
} }
@ -1524,6 +1525,11 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
fDiscover = args.GetBoolArg("-discover", true); fDiscover = args.GetBoolArg("-discover", true);
const bool ignores_incoming_txs{args.GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY)}; const bool ignores_incoming_txs{args.GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY)};
// We need to initialize statsClient early as currently, statsClient is called
// regardless of whether transmitting stats are desirable or not and if
// statsClient isn't present when that attempt is made, the client will crash.
::statsClient = std::make_unique<statsd::StatsdClient>();
{ {
// Read asmap file if configured // Read asmap file if configured

View File

@ -623,7 +623,7 @@ CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCo
/*inbound_onion=*/false, /*inbound_onion=*/false,
std::move(i2p_transient_session)); std::move(i2p_transient_session));
pnode->AddRef(); pnode->AddRef();
statsClient.inc("peers.connect", 1.0f); ::statsClient->inc("peers.connect", 1.0f);
// We're making a new connection, harvest entropy from the time (and our peer count) // We're making a new connection, harvest entropy from the time (and our peer count)
RandAddEvent((uint32_t)id); RandAddEvent((uint32_t)id);
@ -666,7 +666,7 @@ void CNode::CloseSocketDisconnect(CConnman* connman)
m_sock.reset(); m_sock.reset();
m_i2p_sam_session.reset(); m_i2p_sam_session.reset();
statsClient.inc("peers.disconnect", 1.0f); ::statsClient->inc("peers.disconnect", 1.0f);
} }
void CConnman::AddWhitelistPermissionFlags(NetPermissionFlags& flags, const CNetAddr &addr) const { void CConnman::AddWhitelistPermissionFlags(NetPermissionFlags& flags, const CNetAddr &addr) const {
@ -817,7 +817,7 @@ bool CNode::ReceiveMsgBytes(Span<const uint8_t> msg_bytes, bool& complete)
} }
assert(i != mapRecvBytesPerMsgType.end()); assert(i != mapRecvBytesPerMsgType.end());
i->second += msg.m_raw_message_size; i->second += msg.m_raw_message_size;
statsClient.count("bandwidth.message." + std::string(msg.m_type) + ".bytesReceived", msg.m_raw_message_size, 1.0f); ::statsClient->count("bandwidth.message." + std::string(msg.m_type) + ".bytesReceived", msg.m_raw_message_size, 1.0f);
// push the message to the process queue, // push the message to the process queue,
vRecvMsg.push_back(std::move(msg)); vRecvMsg.push_back(std::move(msg));
@ -1741,20 +1741,20 @@ void CConnman::CalculateNumConnectionsChangedStats()
torNodes++; torNodes++;
const auto last_ping_time = count_microseconds(pnode->m_last_ping_time); const auto last_ping_time = count_microseconds(pnode->m_last_ping_time);
if (last_ping_time > 0) if (last_ping_time > 0)
statsClient.timing("peers.ping_us", last_ping_time, 1.0f); ::statsClient->timing("peers.ping_us", last_ping_time, 1.0f);
} }
for (const std::string &msg : getAllNetMessageTypes()) { for (const std::string &msg : getAllNetMessageTypes()) {
statsClient.gauge("bandwidth.message." + msg + ".totalBytesReceived", mapRecvBytesMsgStats[msg], 1.0f); ::statsClient->gauge("bandwidth.message." + msg + ".totalBytesReceived", mapRecvBytesMsgStats[msg], 1.0f);
statsClient.gauge("bandwidth.message." + msg + ".totalBytesSent", mapSentBytesMsgStats[msg], 1.0f); ::statsClient->gauge("bandwidth.message." + msg + ".totalBytesSent", mapSentBytesMsgStats[msg], 1.0f);
} }
statsClient.gauge("peers.totalConnections", nPrevNodeCount, 1.0f); ::statsClient->gauge("peers.totalConnections", nPrevNodeCount, 1.0f);
statsClient.gauge("peers.spvNodeConnections", spvNodes, 1.0f); ::statsClient->gauge("peers.spvNodeConnections", spvNodes, 1.0f);
statsClient.gauge("peers.fullNodeConnections", fullNodes, 1.0f); ::statsClient->gauge("peers.fullNodeConnections", fullNodes, 1.0f);
statsClient.gauge("peers.inboundConnections", inboundNodes, 1.0f); ::statsClient->gauge("peers.inboundConnections", inboundNodes, 1.0f);
statsClient.gauge("peers.outboundConnections", outboundNodes, 1.0f); ::statsClient->gauge("peers.outboundConnections", outboundNodes, 1.0f);
statsClient.gauge("peers.ipv4Connections", ipv4Nodes, 1.0f); ::statsClient->gauge("peers.ipv4Connections", ipv4Nodes, 1.0f);
statsClient.gauge("peers.ipv6Connections", ipv6Nodes, 1.0f); ::statsClient->gauge("peers.ipv6Connections", ipv6Nodes, 1.0f);
statsClient.gauge("peers.torConnections", torNodes, 1.0f); ::statsClient->gauge("peers.torConnections", torNodes, 1.0f);
} }
bool CConnman::ShouldRunInactivityChecks(const CNode& node, std::chrono::seconds now) const bool CConnman::ShouldRunInactivityChecks(const CNode& node, std::chrono::seconds now) const
@ -4124,8 +4124,8 @@ bool CConnman::DisconnectNode(NodeId id)
void CConnman::RecordBytesRecv(uint64_t bytes) void CConnman::RecordBytesRecv(uint64_t bytes)
{ {
nTotalBytesRecv += bytes; nTotalBytesRecv += bytes;
statsClient.count("bandwidth.bytesReceived", bytes, 0.1f); ::statsClient->count("bandwidth.bytesReceived", bytes, 0.1f);
statsClient.gauge("bandwidth.totalBytesReceived", nTotalBytesRecv, 0.01f); ::statsClient->gauge("bandwidth.totalBytesReceived", nTotalBytesRecv, 0.01f);
} }
void CConnman::RecordBytesSent(uint64_t bytes) void CConnman::RecordBytesSent(uint64_t bytes)
@ -4134,8 +4134,8 @@ void CConnman::RecordBytesSent(uint64_t bytes)
LOCK(m_total_bytes_sent_mutex); LOCK(m_total_bytes_sent_mutex);
nTotalBytesSent += bytes; nTotalBytesSent += bytes;
statsClient.count("bandwidth.bytesSent", bytes, 0.01f); ::statsClient->count("bandwidth.bytesSent", bytes, 0.01f);
statsClient.gauge("bandwidth.totalBytesSent", nTotalBytesSent, 0.01f); ::statsClient->gauge("bandwidth.totalBytesSent", nTotalBytesSent, 0.01f);
const auto now = GetTime<std::chrono::seconds>(); const auto now = GetTime<std::chrono::seconds>();
if (nMaxOutboundCycleStartTime + MAX_UPLOAD_TIMEFRAME < now) if (nMaxOutboundCycleStartTime + MAX_UPLOAD_TIMEFRAME < now)
@ -4291,8 +4291,8 @@ void CConnman::PushMessage(CNode* pnode, CSerializedNetMsg&& msg)
msg.data.data() msg.data.data()
); );
statsClient.count(strprintf("bandwidth.message.%s.bytesSent", msg.m_type), nMessageSize, 1.0f); ::statsClient->count(strprintf("bandwidth.message.%s.bytesSent", msg.m_type), nMessageSize, 1.0f);
statsClient.inc(strprintf("message.sent.%s", msg.m_type), 1.0f); ::statsClient->inc(strprintf("message.sent.%s", msg.m_type), 1.0f);
{ {
LOCK(pnode->cs_vSend); LOCK(pnode->cs_vSend);

View File

@ -1688,9 +1688,9 @@ void PeerManagerImpl::Misbehaving(const NodeId pnode, const int howmuch, const s
if (score_now >= DISCOURAGEMENT_THRESHOLD && score_before < DISCOURAGEMENT_THRESHOLD) { if (score_now >= DISCOURAGEMENT_THRESHOLD && score_before < DISCOURAGEMENT_THRESHOLD) {
warning = " DISCOURAGE THRESHOLD EXCEEDED"; warning = " DISCOURAGE THRESHOLD EXCEEDED";
peer->m_should_discourage = true; peer->m_should_discourage = true;
statsClient.inc("misbehavior.banned", 1.0f); ::statsClient->inc("misbehavior.banned", 1.0f);
} else { } else {
statsClient.count("misbehavior.amount", howmuch, 1.0); ::statsClient->count("misbehavior.amount", howmuch, 1.0);
} }
LogPrint(BCLog::NET, "Misbehaving: peer=%d (%d -> %d)%s%s\n", LogPrint(BCLog::NET, "Misbehaving: peer=%d (%d -> %d)%s%s\n",
@ -3260,7 +3260,7 @@ void PeerManagerImpl::ProcessMessage(
AssertLockHeld(g_msgproc_mutex); AssertLockHeld(g_msgproc_mutex);
LogPrint(BCLog::NET, "received: %s (%u bytes) peer=%d\n", SanitizeString(msg_type), vRecv.size(), pfrom.GetId()); LogPrint(BCLog::NET, "received: %s (%u bytes) peer=%d\n", SanitizeString(msg_type), vRecv.size(), pfrom.GetId());
statsClient.inc("message.received." + SanitizeString(msg_type), 1.0f); ::statsClient->inc("message.received." + SanitizeString(msg_type), 1.0f);
const bool is_masternode = m_mn_activeman != nullptr; const bool is_masternode = m_mn_activeman != nullptr;
@ -3759,7 +3759,7 @@ void PeerManagerImpl::ProcessMessage(
if (inv.IsMsgBlk()) { if (inv.IsMsgBlk()) {
const bool fAlreadyHave = AlreadyHaveBlock(inv.hash); const bool fAlreadyHave = AlreadyHaveBlock(inv.hash);
LogPrint(BCLog::NET, "got inv: %s %s peer=%d\n", inv.ToString(), fAlreadyHave ? "have" : "new", pfrom.GetId()); LogPrint(BCLog::NET, "got inv: %s %s peer=%d\n", inv.ToString(), fAlreadyHave ? "have" : "new", pfrom.GetId());
statsClient.inc(strprintf("message.received.inv_%s", inv.GetCommand()), 1.0f); ::statsClient->inc(strprintf("message.received.inv_%s", inv.GetCommand()), 1.0f);
UpdateBlockAvailability(pfrom.GetId(), inv.hash); UpdateBlockAvailability(pfrom.GetId(), inv.hash);
if (!fAlreadyHave && !fImporting && !fReindex && !mapBlocksInFlight.count(inv.hash)) { if (!fAlreadyHave && !fImporting && !fReindex && !mapBlocksInFlight.count(inv.hash)) {
@ -3774,7 +3774,7 @@ void PeerManagerImpl::ProcessMessage(
} else { } else {
const bool fAlreadyHave = AlreadyHave(inv); const bool fAlreadyHave = AlreadyHave(inv);
LogPrint(BCLog::NET, "got inv: %s %s peer=%d\n", inv.ToString(), fAlreadyHave ? "have" : "new", pfrom.GetId()); LogPrint(BCLog::NET, "got inv: %s %s peer=%d\n", inv.ToString(), fAlreadyHave ? "have" : "new", pfrom.GetId());
statsClient.inc(strprintf("message.received.inv_%s", inv.GetCommand()), 1.0f); ::statsClient->inc(strprintf("message.received.inv_%s", inv.GetCommand()), 1.0f);
static std::set<int> allowWhileInIBDObjs = { static std::set<int> allowWhileInIBDObjs = {
MSG_SPORK MSG_SPORK

View File

@ -38,7 +38,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <cmath> #include <cmath>
#include <cstdio> #include <cstdio>
statsd::StatsdClient statsClient; std::unique_ptr<statsd::StatsdClient> statsClient;
namespace statsd { namespace statsd {

View File

@ -66,6 +66,6 @@ class StatsdClient {
} // namespace statsd } // namespace statsd
extern statsd::StatsdClient statsClient; extern std::unique_ptr<statsd::StatsdClient> statsClient;
#endif // BITCOIN_STATSD_CLIENT_H #endif // BITCOIN_STATSD_CLIENT_H

View File

@ -39,6 +39,7 @@
#include <scheduler.h> #include <scheduler.h>
#include <script/sigcache.h> #include <script/sigcache.h>
#include <spork.h> #include <spork.h>
#include <statsd_client.h>
#include <streams.h> #include <streams.h>
#include <test/util/index.h> #include <test/util/index.h>
#include <txdb.h> #include <txdb.h>
@ -182,6 +183,7 @@ BasicTestingSetup::BasicTestingSetup(const std::string& chainName, const std::ve
SetupNetworking(); SetupNetworking();
InitSignatureCache(); InitSignatureCache();
InitScriptExecutionCache(); InitScriptExecutionCache();
::statsClient = std::make_unique<statsd::StatsdClient>();
m_node.chain = interfaces::MakeChain(m_node); m_node.chain = interfaces::MakeChain(m_node);
m_node.netgroupman = std::make_unique<NetGroupManager>(/*asmap=*/std::vector<bool>()); m_node.netgroupman = std::make_unique<NetGroupManager>(/*asmap=*/std::vector<bool>());
@ -217,6 +219,7 @@ BasicTestingSetup::~BasicTestingSetup()
m_node.connman.reset(); m_node.connman.reset();
m_node.addrman.reset(); m_node.addrman.reset();
m_node.netgroupman.reset(); m_node.netgroupman.reset();
::statsClient.reset();
LogInstance().DisconnectTestLogger(); LogInstance().DisconnectTestLogger();
fs::remove_all(m_path_root); fs::remove_all(m_path_root);

View File

@ -51,8 +51,8 @@ bool TxOrphanage::AddTx(const CTransactionRef& tx, NodeId peer)
LogPrint(BCLog::MEMPOOL, "stored orphan tx %s (mapsz %u outsz %u)\n", hash.ToString(), LogPrint(BCLog::MEMPOOL, "stored orphan tx %s (mapsz %u outsz %u)\n", hash.ToString(),
m_orphans.size(), m_outpoint_to_orphan_it.size()); m_orphans.size(), m_outpoint_to_orphan_it.size());
statsClient.inc("transactions.orphans.add", 1.0f); ::statsClient->inc("transactions.orphans.add", 1.0f);
statsClient.gauge("transactions.orphans", m_orphans.size()); ::statsClient->gauge("transactions.orphans", m_orphans.size());
return true; return true;
} }
@ -87,8 +87,8 @@ int TxOrphanage::EraseTx(const uint256& txid)
assert(m_orphan_tx_size >= it->second.nTxSize); assert(m_orphan_tx_size >= it->second.nTxSize);
m_orphan_tx_size -= it->second.nTxSize; m_orphan_tx_size -= it->second.nTxSize;
m_orphans.erase(it); m_orphans.erase(it);
statsClient.inc("transactions.orphans.remove", 1.0f); ::statsClient->inc("transactions.orphans.remove", 1.0f);
statsClient.gauge("transactions.orphans", m_orphans.size()); ::statsClient->gauge("transactions.orphans", m_orphans.size());
return 1; return 1;
} }

View File

@ -612,7 +612,7 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws)
// is it already in the memory pool? // is it already in the memory pool?
if (m_pool.exists(hash)) { if (m_pool.exists(hash)) {
statsClient.inc("transactions.duplicate", 1.0f); ::statsClient->inc("transactions.duplicate", 1.0f);
return state.Invalid(TxValidationResult::TX_CONFLICT, "txn-already-in-mempool"); return state.Invalid(TxValidationResult::TX_CONFLICT, "txn-already-in-mempool");
} }
@ -838,11 +838,11 @@ bool MemPoolAccept::Finalize(const ATMPArgs& args, Workspace& ws)
CAmount nValueOut = tx.GetValueOut(); CAmount nValueOut = tx.GetValueOut();
unsigned int nSigOps = GetTransactionSigOpCount(tx, m_view, STANDARD_SCRIPT_VERIFY_FLAGS); unsigned int nSigOps = GetTransactionSigOpCount(tx, m_view, STANDARD_SCRIPT_VERIFY_FLAGS);
statsClient.count("transactions.sizeBytes", entry->GetTxSize(), 1.0f); ::statsClient->count("transactions.sizeBytes", entry->GetTxSize(), 1.0f);
statsClient.count("transactions.fees", nModifiedFees, 1.0f); ::statsClient->count("transactions.fees", nModifiedFees, 1.0f);
statsClient.count("transactions.inputValue", nValueOut - nModifiedFees, 1.0f); ::statsClient->count("transactions.inputValue", nValueOut - nModifiedFees, 1.0f);
statsClient.count("transactions.outputValue", nValueOut, 1.0f); ::statsClient->count("transactions.outputValue", nValueOut, 1.0f);
statsClient.count("transactions.sigOps", nSigOps, 1.0f); ::statsClient->count("transactions.sigOps", nSigOps, 1.0f);
// Add memory address index // Add memory address index
if (fAddressIndex) { if (fAddressIndex) {
@ -895,10 +895,10 @@ MempoolAcceptResult MemPoolAccept::AcceptSingleTransaction(const CTransactionRef
const CTransaction& tx = *ptx; const CTransaction& tx = *ptx;
auto finish = Now<SteadyMilliseconds>(); auto finish = Now<SteadyMilliseconds>();
auto diff = finish - start; auto diff = finish - start;
statsClient.timing("AcceptToMemoryPool_ms", count_milliseconds(diff), 1.0f); ::statsClient->timing("AcceptToMemoryPool_ms", count_milliseconds(diff), 1.0f);
statsClient.inc("transactions.accepted", 1.0f); ::statsClient->inc("transactions.accepted", 1.0f);
statsClient.count("transactions.inputs", tx.vin.size(), 1.0f); ::statsClient->count("transactions.inputs", tx.vin.size(), 1.0f);
statsClient.count("transactions.outputs", tx.vout.size(), 1.0f); ::statsClient->count("transactions.outputs", tx.vout.size(), 1.0f);
return MempoolAcceptResult::Success(ws.m_base_fees); return MempoolAcceptResult::Success(ws.m_base_fees);
} }
@ -1319,7 +1319,7 @@ void CChainState::InvalidChainFound(CBlockIndex* pindexNew)
{ {
AssertLockHeld(cs_main); AssertLockHeld(cs_main);
statsClient.inc("warnings.InvalidChainFound", 1.0f); ::statsClient->inc("warnings.InvalidChainFound", 1.0f);
if (!m_chainman.m_best_invalid || pindexNew->nChainWork > m_chainman.m_best_invalid->nChainWork) { if (!m_chainman.m_best_invalid || pindexNew->nChainWork > m_chainman.m_best_invalid->nChainWork) {
m_chainman.m_best_invalid = pindexNew; m_chainman.m_best_invalid = pindexNew;
@ -1343,7 +1343,7 @@ void CChainState::ConflictingChainFound(CBlockIndex* pindexNew)
{ {
AssertLockHeld(cs_main); AssertLockHeld(cs_main);
statsClient.inc("warnings.ConflictingChainFound", 1.0f); ::statsClient->inc("warnings.ConflictingChainFound", 1.0f);
LogPrintf("%s: conflicting block=%s height=%d log2_work=%f date=%s\n", __func__, LogPrintf("%s: conflicting block=%s height=%d log2_work=%f date=%s\n", __func__,
pindexNew->GetBlockHash().ToString(), pindexNew->nHeight, pindexNew->GetBlockHash().ToString(), pindexNew->nHeight,
@ -1362,7 +1362,7 @@ void CChainState::InvalidBlockFound(CBlockIndex *pindex, const BlockValidationSt
{ {
AssertLockHeld(cs_main); AssertLockHeld(cs_main);
statsClient.inc("warnings.InvalidBlockFound", 1.0f); ::statsClient->inc("warnings.InvalidBlockFound", 1.0f);
if (state.GetResult() != BlockValidationResult::BLOCK_MUTATED) { if (state.GetResult() != BlockValidationResult::BLOCK_MUTATED) {
pindex->nStatus |= BLOCK_FAILED_VALID; pindex->nStatus |= BLOCK_FAILED_VALID;
m_chainman.m_failed_blocks.insert(pindex); m_chainman.m_failed_blocks.insert(pindex);
@ -1526,7 +1526,7 @@ bool CheckInputScripts(const CTransaction& tx, TxValidationState &state, const C
auto finish = Now<SteadyMilliseconds>(); auto finish = Now<SteadyMilliseconds>();
auto diff = finish - start; auto diff = finish - start;
statsClient.timing("CheckInputScripts_ms", count_milliseconds(diff), 1.0f); ::statsClient->timing("CheckInputScripts_ms", count_milliseconds(diff), 1.0f);
return true; return true;
} }
@ -1729,7 +1729,7 @@ DisconnectResult CChainState::DisconnectBlock(const CBlock& block, const CBlockI
auto finish = Now<SteadyMilliseconds>(); auto finish = Now<SteadyMilliseconds>();
auto diff = finish - start; auto diff = finish - start;
statsClient.timing("DisconnectBlock_ms", count_milliseconds(diff), 1.0f); ::statsClient->timing("DisconnectBlock_ms", count_milliseconds(diff), 1.0f);
return fClean ? DISCONNECT_OK : DISCONNECT_UNCLEAN; return fClean ? DISCONNECT_OK : DISCONNECT_UNCLEAN;
} }
@ -2296,12 +2296,12 @@ bool CChainState::ConnectBlock(const CBlock& block, BlockValidationState& state,
int64_t nTime8 = GetTimeMicros(); nTimeCallbacks += nTime8 - nTime5; int64_t nTime8 = GetTimeMicros(); nTimeCallbacks += nTime8 - nTime5;
LogPrint(BCLog::BENCHMARK, " - Callbacks: %.2fms [%.2fs (%.2fms/blk)]\n", MILLI * (nTime8 - nTime5), nTimeCallbacks * MICRO, nTimeCallbacks * MILLI / nBlocksTotal); 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->timing("ConnectBlock_ms", (nTime8 - nTimeStart) / 1000, 1.0f);
statsClient.gauge("blocks.tip.SizeBytes", ::GetSerializeSize(block, PROTOCOL_VERSION), 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.Height", m_chain.Height(), 1.0f);
statsClient.gauge("blocks.tip.Version", block.nVersion, 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.NumTransactions", block.vtx.size(), 1.0f);
statsClient.gauge("blocks.tip.SigOps", nSigOps, 1.0f); ::statsClient->gauge("blocks.tip.SigOps", nSigOps, 1.0f);
TRACE6(validation, block_connected, TRACE6(validation, block_connected,
block.GetHash().data(), block.GetHash().data(),
@ -2772,7 +2772,7 @@ 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);
statsClient.timing("ConnectTip_ms", (nTime6 - nTime1) / 1000, 1.0f); ::statsClient->timing("ConnectTip_ms", (nTime6 - nTime1) / 1000, 1.0f);
connectTrace.BlockConnected(pindexNew, std::move(pthisBlock)); connectTrace.BlockConnected(pindexNew, std::move(pthisBlock));
return true; return true;
@ -3084,7 +3084,7 @@ bool CChainState::ActivateBestChain(BlockValidationState& state, std::shared_ptr
auto finish = Now<SteadyMilliseconds>(); auto finish = Now<SteadyMilliseconds>();
auto diff = finish - start; auto diff = finish - start;
statsClient.timing("ActivateBestChain_ms", count_milliseconds(diff), 1.0f); ::statsClient->timing("ActivateBestChain_ms", count_milliseconds(diff), 1.0f);
// Write changes periodically to disk, after relay. // Write changes periodically to disk, after relay.
if (!FlushStateToDisk(state, FlushStateMode::PERIODIC)) { if (!FlushStateToDisk(state, FlushStateMode::PERIODIC)) {
@ -3572,7 +3572,7 @@ bool CheckBlock(const CBlock& block, BlockValidationState& state, const Consensu
auto finish = Now<SteadyMicroseconds>(); auto finish = Now<SteadyMicroseconds>();
auto diff = finish - start; auto diff = finish - start;
statsClient.timing("CheckBlock_us", count_microseconds(diff), 1.0f); ::statsClient->timing("CheckBlock_us", count_microseconds(diff), 1.0f);
return true; return true;
} }
@ -3943,7 +3943,7 @@ bool CChainState::AcceptBlock(const std::shared_ptr<const CBlock>& pblock, Block
auto finish = Now<SteadyMicroseconds>(); auto finish = Now<SteadyMicroseconds>();
auto diff = finish - start; auto diff = finish - start;
statsClient.timing("AcceptBlock_us", count_microseconds(diff), 1.0f); ::statsClient->timing("AcceptBlock_us", count_microseconds(diff), 1.0f);
return true; return true;
} }