Drop pre-DIP3 votes from current votes per MN per object (#2524)

This commit is contained in:
UdjinM6 2018-12-06 10:06:21 +03:00 committed by Alexander Block
parent 7037f7c999
commit 08dc178711

View File

@ -795,6 +795,7 @@ std::vector<uint256> CGovernanceObject::RemoveOldVotes(unsigned int nMinTime)
{ {
LOCK(cs); LOCK(cs);
// Drop pre-DIP3 votes from vote db
auto removed = fileVotes.RemoveOldVotes(nMinTime); auto removed = fileVotes.RemoveOldVotes(nMinTime);
if (!removed.empty()) { if (!removed.empty()) {
@ -806,5 +807,24 @@ std::vector<uint256> CGovernanceObject::RemoveOldVotes(unsigned int nMinTime)
fDirtyCache = true; 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; return removed;
} }