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++); + } } }