Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add transactions.mempool.lockedTransactions and chainlocks.blockHeight stats #6237

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/evo/deterministicmns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <univalue.h>
#include <messagesigner.h>
#include <uint256.h>
#include <statsd_client.h>

#include <optional>
#include <memory>
Expand Down Expand Up @@ -641,6 +642,15 @@ bool CDeterministicMNManager::ProcessBlock(const CBlock& block, gsl::not_null<co
updatesRet = {newList, oldList, diff};
}

statsClient.gauge("masternodes.count", newList.GetAllMNsCount());
statsClient.gauge("masternodes.weighted_count", newList.GetValidWeightedMNsCount());
statsClient.gauge("masternodes.enabled", newList.GetValidMNsCount());
statsClient.gauge("masternodes.weighted_enabled", newList.GetValidWeightedMNsCount());
statsClient.gauge("masternodes.evo.count", newList.GetAllEvoCount());
statsClient.gauge("masternodes.evo.enabled", newList.GetValidEvoCount());
statsClient.gauge("masternodes.mn.count", newList.GetAllMNsCount() - newList.GetAllEvoCount());
statsClient.gauge("masternodes.mn.enabled", newList.GetValidMNsCount() - newList.GetValidEvoCount());

if (nHeight == consensusParams.DIP0003EnforcementHeight) {
if (!consensusParams.DIP0003EnforcementHash.IsNull() && consensusParams.DIP0003EnforcementHash != pindex->GetBlockHash()) {
LogPrintf("CDeterministicMNManager::%s -- DIP3 enforcement block has wrong hash: hash=%s, expected=%s, nHeight=%d\n", __func__,
Expand Down
5 changes: 3 additions & 2 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ static void StartupNotify(const ArgsManager& args)
}
#endif

static void PeriodicStats(ArgsManager& args, ChainstateManager& chainman, const CTxMemPool& mempool)
static void PeriodicStats(ArgsManager& args, ChainstateManager& chainman, const CTxMemPool& mempool, const llmq::CInstantSendManager& isman)
{
assert(args.GetBoolArg("-statsenabled", DEFAULT_STATSD_ENABLE));
CCoinsStats stats{CoinStatsHashType::NONE};
Expand Down Expand Up @@ -882,6 +882,7 @@ static void PeriodicStats(ArgsManager& args, ChainstateManager& chainman, const
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.lockedTransactions", isman.GetInstantSendLockCount(), 1.0f);
}

static bool AppInitServers(NodeContext& node)
Expand Down Expand Up @@ -2241,7 +2242,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)

if (args.GetBoolArg("-statsenabled", DEFAULT_STATSD_ENABLE)) {
int nStatsPeriod = std::min(std::max((int)args.GetArg("-statsperiod", DEFAULT_STATSD_PERIOD), MIN_STATSD_PERIOD), MAX_STATSD_PERIOD);
node.scheduler->scheduleEvery(std::bind(&PeriodicStats, std::ref(*node.args), std::ref(chainman), std::cref(*node.mempool)), std::chrono::seconds{nStatsPeriod});
node.scheduler->scheduleEvery(std::bind(&PeriodicStats, std::ref(*node.args), std::ref(chainman), std::cref(*node.mempool), std::cref(*node.llmq_ctx->isman)), std::chrono::seconds{nStatsPeriod});
}

// ********************************************************* Step 11: import blocks
Expand Down
2 changes: 2 additions & 0 deletions src/llmq/chainlocks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <node/ui_interface.h>
#include <scheduler.h>
#include <spork.h>
#include <statsd_client.h>
#include <txmempool.h>
#include <util/thread.h>
#include <util/time.h>
Expand Down Expand Up @@ -519,6 +520,7 @@ void CChainLocksHandler::EnforceBestChainLock()

GetMainSignals().NotifyChainLock(currentBestChainLockBlockIndex, clsig);
uiInterface.NotifyChainLock(clsig->getBlockHash().ToString(), clsig->getHeight());
statsClient.gauge("chainlocks.blockHeight", clsig->getHeight(), 1.0f);
}

void CChainLocksHandler::HandleNewRecoveredSig(const llmq::CRecoveredSig& recoveredSig)
Expand Down
21 changes: 21 additions & 0 deletions src/llmq/instantsend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <util/ranges.h>
#include <util/thread.h>
#include <validation.h>
#include <statsd_client.h>

#include <cxxtimer.hpp>

Expand Down Expand Up @@ -790,6 +791,17 @@ PeerMsgRet CInstantSendManager::ProcessMessageInstantSendLock(const CNode& pfrom
LogPrint(BCLog::INSTANTSEND, "CInstantSendManager::%s -- txid=%s, islock=%s: received islock, peer=%d\n", __func__,
islock->txid.ToString(), hash.ToString(), pfrom.GetId());

auto time_diff = [&] () -> int64_t {
LOCK(cs_timingsTxSeen);
if (auto it = timingsTxSeen.find(islock->txid); it != timingsTxSeen.end()) {
// This is the normal case where we received the TX before the islock
return GetTimeMillis() - it->second;
}
// But if we received the islock and don't know when we got the tx, then say 0, to indicate we received the islock first.
return 0;
}();
statsClient.timing("islock_ms", time_diff);
Comment on lines +794 to +803
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any concerns about doing this here? kinda concerned about potential performance implications doing this in this thread. Any thoughts?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be ok imo


LOCK(cs_pendingLocks);
pendingInstantSendLocks.emplace(hash, std::make_pair(pfrom.GetId(), islock));
return {};
Expand Down Expand Up @@ -1179,6 +1191,15 @@ void CInstantSendManager::AddNonLockedTx(const CTransactionRef& tx, const CBlock
++it;
}
}

{
LOCK(cs_timingsTxSeen);
// Only insert the time the first time we see the tx, as we sometimes try to resign
if (auto it = timingsTxSeen.find(tx->GetHash()); it == timingsTxSeen.end()) {
timingsTxSeen[tx->GetHash()] = GetTimeMillis();
}
}

LogPrint(BCLog::INSTANTSEND, "CInstantSendManager::%s -- txid=%s, pindexMined=%s\n", __func__,
tx->GetHash().ToString(), pindexMined ? pindexMined->GetBlockHash().ToString() : "");
}
Expand Down
3 changes: 3 additions & 0 deletions src/llmq/instantsend.h
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,9 @@ class CInstantSendManager : public CRecoveredSigsListener
mutable Mutex cs_pendingRetry;
std::unordered_set<uint256, StaticSaltedHasher> pendingRetryTxs GUARDED_BY(cs_pendingRetry);

mutable Mutex cs_timingsTxSeen;
std::unordered_map<uint256, int64_t, StaticSaltedHasher> timingsTxSeen GUARDED_BY(cs_timingsTxSeen);

public:
explicit CInstantSendManager(CChainLocksHandler& _clhandler, CChainState& chainstate, CConnman& _connman,
CQuorumManager& _qman, CSigningManager& _sigman, CSigSharesManager& _shareman,
Expand Down
2 changes: 1 addition & 1 deletion src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2284,7 +2284,7 @@ bool CChainState::ConnectBlock(const CBlock& block, BlockValidationState& state,

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.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`
PastaPastaPasta marked this conversation as resolved.
Show resolved Hide resolved
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);
Expand Down
Loading