Skip to content

Commit d5dbbdb

Browse files
feat: also log the islock time, and erase the received at time; conditional on either stats or logger being active
1 parent 38d7892 commit d5dbbdb

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

src/llmq/instantsend.cpp

+21-11
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,10 @@ PeerMsgRet CInstantSendManager::ProcessMessage(const CNode& pfrom, PeerManager&
742742
return {};
743743
}
744744

745+
bool ShouldReportISLockTiming() {
746+
return g_stats_client->active() || LogAcceptDebug(BCLog::INSTANTSEND);
747+
}
748+
745749
PeerMsgRet CInstantSendManager::ProcessMessageInstantSendLock(const CNode& pfrom, PeerManager& peerman,
746750
const llmq::CInstantSendLockPtr& islock)
747751
{
@@ -775,16 +779,22 @@ PeerMsgRet CInstantSendManager::ProcessMessageInstantSendLock(const CNode& pfrom
775779
LogPrint(BCLog::INSTANTSEND, "CInstantSendManager::%s -- txid=%s, islock=%s: received islock, peer=%d\n", __func__,
776780
islock->txid.ToString(), hash.ToString(), pfrom.GetId());
777781

778-
auto time_diff = [&] () -> int64_t {
779-
LOCK(cs_timingsTxSeen);
780-
if (auto it = timingsTxSeen.find(islock->txid); it != timingsTxSeen.end()) {
781-
// This is the normal case where we received the TX before the islock
782-
return GetTimeMillis() - it->second;
783-
}
784-
// 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.
785-
return 0;
786-
}();
787-
::g_stats_client->timing("islock_ms", time_diff);
782+
if (ShouldReportISLockTiming()) {
783+
auto time_diff = [&] () -> int64_t {
784+
LOCK(cs_timingsTxSeen);
785+
if (auto it = timingsTxSeen.find(islock->txid); it != timingsTxSeen.end()) {
786+
// This is the normal case where we received the TX before the islock
787+
auto diff = GetTimeMillis() - it->second;
788+
timingsTxSeen.erase(it);
789+
return diff;
790+
}
791+
// 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.
792+
return 0;
793+
}();
794+
::g_stats_client->timing("islock_ms", time_diff);
795+
LogPrint(BCLog::INSTANTSEND, "CInstantSendManager::%s -- txid=%s, islock took %dms\n", __func__,
796+
islock->txid.ToString(), time_diff);
797+
}
788798

789799
LOCK(cs_pendingLocks);
790800
pendingInstantSendLocks.emplace(hash, std::make_pair(pfrom.GetId(), islock));
@@ -1180,7 +1190,7 @@ void CInstantSendManager::AddNonLockedTx(const CTransactionRef& tx, const CBlock
11801190
}
11811191
}
11821192

1183-
{
1193+
if (ShouldReportISLockTiming()) {
11841194
LOCK(cs_timingsTxSeen);
11851195
// Only insert the time the first time we see the tx, as we sometimes try to resign
11861196
if (auto it = timingsTxSeen.find(tx->GetHash()); it == timingsTxSeen.end()) {

0 commit comments

Comments
 (0)