Only track last seen time instead of first and last seen time (#3165)

This avoids timeouts on parts of the network
This commit is contained in:
Alexander Block 2019-10-23 09:55:06 +02:00
parent ad720eef19
commit 9b49bfda81
2 changed files with 6 additions and 16 deletions

View File

@ -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<uint256, StaticSaltedHasher> 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);
}
}

View File

@ -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<CSigShare> sigShares;
// stores time of first and last receivedSigShare. Used to detect timeouts
std::unordered_map<uint256, std::pair<int64_t, int64_t>, StaticSaltedHasher> timeSeenForSessions;
// stores time of last receivedSigShare. Used to detect timeouts
std::unordered_map<uint256, int64_t, StaticSaltedHasher> timeSeenForSessions;
std::unordered_map<NodeId, CSigSharesNodeState> nodeStates;
SigShareMap<std::pair<NodeId, int64_t>> sigSharesRequested;