From 9b49bfda81fdf1126ebc8a6b714c28ec5650c3ab Mon Sep 17 00:00:00 2001 From: Alexander Block Date: Wed, 23 Oct 2019 09:55:06 +0200 Subject: [PATCH] Only track last seen time instead of first and last seen time (#3165) This avoids timeouts on parts of the network --- src/llmq/quorums_signing_shares.cpp | 17 ++++------------- src/llmq/quorums_signing_shares.h | 5 ++--- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/src/llmq/quorums_signing_shares.cpp b/src/llmq/quorums_signing_shares.cpp index a2d4687fd8..b5f7284605 100644 --- a/src/llmq/quorums_signing_shares.cpp +++ b/src/llmq/quorums_signing_shares.cpp @@ -676,18 +676,10 @@ void CSigSharesManager::ProcessSigShare(NodeId nodeId, const CSigShare& sigShare if (!sigShares.Add(sigShare.GetKey(), sigShare)) { return; } - sigSharesToAnnounce.Add(sigShare.GetKey(), true); - auto it = timeSeenForSessions.find(sigShare.GetSignHash()); - if (it == timeSeenForSessions.end()) { - auto t = GetTimeMillis(); - // insert first-seen and last-seen time - timeSeenForSessions.emplace(sigShare.GetSignHash(), std::make_pair(t, t)); - } else { - // update last-seen time - it->second.second = GetTimeMillis(); - } + // Update the time we've seen the last sigShare + timeSeenForSessions[sigShare.GetSignHash()] = GetTimeMillis(); if (!quorumNodes.empty()) { // don't announce and wait for other nodes to request this share and directly send it to them @@ -1215,10 +1207,9 @@ void CSigSharesManager::Cleanup() std::unordered_set timeoutSessions; for (auto& p : timeSeenForSessions) { auto& signHash = p.first; - int64_t firstSeenTime = p.second.first; - int64_t lastSeenTime = p.second.second; + int64_t lastSeenTime = p.second; - if (now - firstSeenTime >= SESSION_TOTAL_TIMEOUT || now - lastSeenTime >= SESSION_NEW_SHARES_TIMEOUT) { + if (now - lastSeenTime >= SESSION_NEW_SHARES_TIMEOUT) { timeoutSessions.emplace(signHash); } } diff --git a/src/llmq/quorums_signing_shares.h b/src/llmq/quorums_signing_shares.h index f355ca4a81..654f88268f 100644 --- a/src/llmq/quorums_signing_shares.h +++ b/src/llmq/quorums_signing_shares.h @@ -330,7 +330,6 @@ public: class CSigSharesManager : public CRecoveredSigsListener { static const int64_t SESSION_NEW_SHARES_TIMEOUT = 60 * 1000; - static const int64_t SESSION_TOTAL_TIMEOUT = 5 * 60 * 1000; static const int64_t SIG_SHARE_REQUEST_TIMEOUT = 5 * 1000; // we try to keep total message size below 10k @@ -348,8 +347,8 @@ private: SigShareMap sigShares; - // stores time of first and last receivedSigShare. Used to detect timeouts - std::unordered_map, StaticSaltedHasher> timeSeenForSessions; + // stores time of last receivedSigShare. Used to detect timeouts + std::unordered_map timeSeenForSessions; std::unordered_map nodeStates; SigShareMap> sigSharesRequested;