Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop all kind of invalid votes from all types of gobjects #2812

Merged
merged 2 commits into from
Mar 30, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
UdjinM6 marked this conversation as resolved.
Show resolved Hide resolved
std::set<uint256> RemoveInvalidProposalVotes(const COutPoint& mnOutpoint);
std::set<uint256> RemoveInvalidVotes(const COutPoint& mnOutpoint);

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

std::set<uint256> CGovernanceObjectVoteFile::RemoveInvalidProposalVotes(const COutPoint& outpointMasternode)
std::set<uint256> CGovernanceObjectVoteFile::RemoveInvalidVotes(const COutPoint& outpointMasternode, bool fProposal)
{
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) {
bool useVotingKey = fProposal && (it->GetSignal() == VOTE_SIGNAL_FUNDING);
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 fProposal);

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) {
UdjinM6 marked this conversation as resolved.
Show resolved Hide resolved
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