Skip to content

Commit

Permalink
Drop all kind of invalid votes from all types of gobjects
Browse files Browse the repository at this point in the history
Currently we only do so for proposal "funding" votes which looks incomplete.
  • Loading branch information
UdjinM6 committed Mar 28, 2019
1 parent 8987a6c commit d9cbb8c
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 17 deletions.
10 changes: 3 additions & 7 deletions src/governance-object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,21 +229,17 @@ void CGovernanceObject::ClearMasternodeVotes()
}
}

std::set<uint256> CGovernanceObject::RemoveInvalidProposalVotes(const COutPoint& mnOutpoint)
std::set<uint256> CGovernanceObject::RemoveInvalidVotes(const COutPoint& mnOutpoint)
{
LOCK(cs);

if (nObjectType != GOVERNANCE_OBJECT_PROPOSAL) {
return {};
}

auto it = mapCurrentMNVotes.find(mnOutpoint);
if (it == mapCurrentMNVotes.end()) {
// don't even try as we don't have any votes from this MN
return {};
}

auto removedVotes = fileVotes.RemoveInvalidProposalVotes(mnOutpoint);
auto removedVotes = fileVotes.RemoveInvalidVotes(mnOutpoint, nObjectType == GOVERNANCE_OBJECT_PROPOSAL);
if (removedVotes.empty()) {
return {};
}
Expand All @@ -267,7 +263,7 @@ std::set<uint256> CGovernanceObject::RemoveInvalidProposalVotes(const COutPoint&
for (auto& h : removedVotes) {
removedStr += strprintf(" %s\n", h.ToString());
}
LogPrintf("CGovernanceObject::%s -- Removed %d invalid votes for %s from MN %s:\n%s\n", __func__, removedVotes.size(), nParentHash.ToString(), mnOutpoint.ToString(), removedStr);
LogPrintf("CGovernanceObject::%s -- Removed %d invalid votes for %s from MN %s:\n%s", __func__, removedVotes.size(), nParentHash.ToString(), mnOutpoint.ToString(), removedStr);
fDirtyCache = true;
}

Expand Down
2 changes: 1 addition & 1 deletion src/governance-object.h
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ class CGovernanceObject

// Revalidate all votes from this MN and delete them if validation fails
// This is the case for DIP3 MNs that change voting keys. Returns deleted vote hashes
std::set<uint256> RemoveInvalidProposalVotes(const COutPoint& mnOutpoint);
std::set<uint256> RemoveInvalidVotes(const COutPoint& mnOutpoint);

void CheckOrphanVotes(CConnman& connman);
};
Expand Down
6 changes: 3 additions & 3 deletions src/governance-votedb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ void CGovernanceObjectVoteFile::RemoveVotesFromMasternode(const COutPoint& outpo
}
}

std::set<uint256> CGovernanceObjectVoteFile::RemoveInvalidProposalVotes(const COutPoint& outpointMasternode)
std::set<uint256> CGovernanceObjectVoteFile::RemoveInvalidVotes(const COutPoint& outpointMasternode, bool useVotingKey)
{
std::set<uint256> removedVotes;

vote_l_it it = listVotes.begin();
while (it != listVotes.end()) {
if (it->GetSignal() == VOTE_SIGNAL_FUNDING && it->GetMasternodeOutpoint() == outpointMasternode) {
if (!it->IsValid(true)) {
if (it->GetMasternodeOutpoint() == outpointMasternode) {
if (!it->IsValid(useVotingKey)) {
removedVotes.emplace(it->GetHash());
--nMemoryVotes;
mapVoteIndex.erase(it->GetHash());
Expand Down
2 changes: 1 addition & 1 deletion src/governance-votedb.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class CGovernanceObjectVoteFile
std::vector<CGovernanceVote> GetVotes() const;

void RemoveVotesFromMasternode(const COutPoint& outpointMasternode);
std::set<uint256> RemoveInvalidProposalVotes(const COutPoint& outpointMasternode);
std::set<uint256> RemoveInvalidVotes(const COutPoint& outpointMasternode, bool useVotingKey);

ADD_SERIALIZE_METHODS;

Expand Down
11 changes: 7 additions & 4 deletions src/governance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ void CGovernanceManager::DoMaintenance(CConnman& connman)
if (fLiteMode || !masternodeSync.IsSynced() || ShutdownRequested()) return;

if (deterministicMNManager->IsDIP3Enforced()) {
RemoveInvalidProposalVotes();
RemoveInvalidVotes();
}

// CHECK OBJECTS WE'VE ASKED FOR, REMOVE OLD ENTRIES
Expand Down Expand Up @@ -1286,7 +1286,7 @@ void CGovernanceManager::UpdatedBlockTip(const CBlockIndex* pindex, CConnman& co
LogPrint("gobject", "CGovernanceManager::UpdatedBlockTip -- nCachedBlockHeight: %d\n", nCachedBlockHeight);

if (deterministicMNManager->IsDIP3Enforced(pindex->nHeight)) {
RemoveInvalidProposalVotes();
RemoveInvalidVotes();
}

CheckPostponedObjects(connman);
Expand Down Expand Up @@ -1341,7 +1341,7 @@ void CGovernanceManager::CleanOrphanObjects()
}
}

void CGovernanceManager::RemoveInvalidProposalVotes()
void CGovernanceManager::RemoveInvalidVotes()
{
auto curMNList = deterministicMNManager->GetListAtChainTip();
auto diff = lastMNListForVotingKeys.BuildDiff(curMNList);
Expand All @@ -1354,6 +1354,9 @@ void CGovernanceManager::RemoveInvalidProposalVotes()
if (p.second->keyIDVoting != oldDmn->pdmnState->keyIDVoting) {
changedKeyMNs.emplace_back(oldDmn->collateralOutpoint);
}
if (p.second->pubKeyOperator != oldDmn->pdmnState->pubKeyOperator) {
changedKeyMNs.emplace_back(oldDmn->collateralOutpoint);
}
}
for (const auto& proTxHash : diff.removedMns) {
auto oldDmn = lastMNListForVotingKeys.GetMN(proTxHash);
Expand All @@ -1362,7 +1365,7 @@ void CGovernanceManager::RemoveInvalidProposalVotes()

for (const auto& outpoint : changedKeyMNs) {
for (auto& p : mapObjects) {
auto removed = p.second.RemoveInvalidProposalVotes(outpoint);
auto removed = p.second.RemoveInvalidVotes(outpoint);
if (removed.empty()) {
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion src/governance.h
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ class CGovernanceManager

void CleanOrphanObjects();

void RemoveInvalidProposalVotes();
void RemoveInvalidVotes();

};

Expand Down

0 comments on commit d9cbb8c

Please sign in to comment.