From d7fbaf907f944672a840be7157b2a80dfcd929bc Mon Sep 17 00:00:00 2001 From: Tim Flynn Date: Mon, 3 Apr 2017 16:06:33 -0400 Subject: [PATCH] V0.12.1.x multiple vote fix (#1425) * Avoid adding the same vote multiple times to the vote file * Cleanup multiple votes in vote file --- src/governance-object.cpp | 4 +++- src/governance-votedb.cpp | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/governance-object.cpp b/src/governance-object.cpp index b33d96bd31..1b9c631606 100644 --- a/src/governance-object.cpp +++ b/src/governance-object.cpp @@ -188,7 +188,9 @@ bool CGovernanceObject::ProcessVote(CNode* pfrom, return false; } voteInstance = vote_instance_t(vote.GetOutcome(), nVoteTimeUpdate, vote.GetTimestamp()); - fileVotes.AddVote(vote); + if(!fileVotes.HasVote(vote.GetHash())) { + fileVotes.AddVote(vote); + } fDirtyCache = true; return true; } diff --git a/src/governance-votedb.cpp b/src/governance-votedb.cpp index ed62c43faa..0a817f9668 100644 --- a/src/governance-votedb.cpp +++ b/src/governance-votedb.cpp @@ -58,6 +58,7 @@ void CGovernanceObjectVoteFile::RemoveVotesFromMasternode(const CTxIn& vinMaster vote_l_it it = listVotes.begin(); while(it != listVotes.end()) { if(it->GetVinMasternode() == vinMasternode) { + --nMemoryVotes; mapVoteIndex.erase(it->GetHash()); listVotes.erase(it++); } @@ -78,8 +79,18 @@ CGovernanceObjectVoteFile& CGovernanceObjectVoteFile::operator=(const CGovernanc void CGovernanceObjectVoteFile::RebuildIndex() { mapVoteIndex.clear(); - for(vote_l_it it = listVotes.begin(); it != listVotes.end(); ++it) { + nMemoryVotes = 0; + vote_l_it it = listVotes.begin(); + while(it != listVotes.end()) { CGovernanceVote& vote = *it; - mapVoteIndex[vote.GetHash()] = it; + uint256 nHash = vote.GetHash(); + if(mapVoteIndex.find(nHash) == mapVoteIndex.end()) { + mapVoteIndex[nHash] = it; + ++nMemoryVotes; + ++it; + } + else { + listVotes.erase(it++); + } } }