mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 12:02:48 +01:00
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:
parent
17a36de02d
commit
d7fbaf907f
@ -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());
|
||||||
|
if(!fileVotes.HasVote(vote.GetHash())) {
|
||||||
fileVotes.AddVote(vote);
|
fileVotes.AddVote(vote);
|
||||||
|
}
|
||||||
fDirtyCache = true;
|
fDirtyCache = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -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++);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user