From 08dc178711e1570f5de6b93a81c14ad42a2b3c1d Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Thu, 6 Dec 2018 10:06:21 +0300 Subject: [PATCH] Drop pre-DIP3 votes from current votes per MN per object (#2524) --- src/governance-object.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/governance-object.cpp b/src/governance-object.cpp index 67ef9a769..4d05a1f2b 100644 --- a/src/governance-object.cpp +++ b/src/governance-object.cpp @@ -795,6 +795,7 @@ std::vector CGovernanceObject::RemoveOldVotes(unsigned int nMinTime) { LOCK(cs); + // Drop pre-DIP3 votes from vote db auto removed = fileVotes.RemoveOldVotes(nMinTime); if (!removed.empty()) { @@ -806,5 +807,24 @@ std::vector CGovernanceObject::RemoveOldVotes(unsigned int nMinTime) fDirtyCache = true; } + // Same for current votes per MN for this specific object + auto itMnPair = mapCurrentMNVotes.begin(); + while (itMnPair != mapCurrentMNVotes.end()) { + auto& miRef = itMnPair->second.mapInstances; + auto itVotePair = miRef.begin(); + while (itVotePair != miRef.end()) { + if (itVotePair->second.nTime < nMinTime) { + miRef.erase(itVotePair++); + } else { + ++itVotePair; + } + } + if (miRef.empty()) { + mapCurrentMNVotes.erase(itMnPair++); + } else { + ++itMnPair; + } + } + return removed; }