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
This commit is contained in:
Tim Flynn 2017-04-03 16:06:33 -04:00 committed by UdjinM6
parent 17a36de02d
commit d7fbaf907f
2 changed files with 16 additions and 3 deletions

View File

@ -188,7 +188,9 @@ bool CGovernanceObject::ProcessVote(CNode* pfrom,
return false; return false;
} }
voteInstance = vote_instance_t(vote.GetOutcome(), nVoteTimeUpdate, vote.GetTimestamp()); voteInstance = vote_instance_t(vote.GetOutcome(), nVoteTimeUpdate, vote.GetTimestamp());
fileVotes.AddVote(vote); if(!fileVotes.HasVote(vote.GetHash())) {
fileVotes.AddVote(vote);
}
fDirtyCache = true; fDirtyCache = true;
return true; return true;
} }

View File

@ -58,6 +58,7 @@ void CGovernanceObjectVoteFile::RemoveVotesFromMasternode(const CTxIn& vinMaster
vote_l_it it = listVotes.begin(); vote_l_it it = listVotes.begin();
while(it != listVotes.end()) { while(it != listVotes.end()) {
if(it->GetVinMasternode() == vinMasternode) { if(it->GetVinMasternode() == vinMasternode) {
--nMemoryVotes;
mapVoteIndex.erase(it->GetHash()); mapVoteIndex.erase(it->GetHash());
listVotes.erase(it++); listVotes.erase(it++);
} }
@ -78,8 +79,18 @@ CGovernanceObjectVoteFile& CGovernanceObjectVoteFile::operator=(const CGovernanc
void CGovernanceObjectVoteFile::RebuildIndex() void CGovernanceObjectVoteFile::RebuildIndex()
{ {
mapVoteIndex.clear(); 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; 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++);
}
} }
} }