Skip to content

Commit

Permalink
Various fixes for RemoveInvalidVotes() (#2845)
Browse files Browse the repository at this point in the history
* Fix crash in RemoveInvalidVotes()

Caused by lock not being held while accessing lastMNListForVotingKeys when RemoveInvalidVotes() is called from DoMaintenance() and UpdatedBlockTip() at the same time.

* No need to call RemoveInvalidVotes() from DoMaintenance()

MN list only changes on new blocks and we already call RemoveInvalidVotes() from UpdatedBlockTip()

* No need to call RemoveInvalidVotes() until we are fully synced
  • Loading branch information
UdjinM6 committed Apr 8, 2019
1 parent b5bc7c9 commit 1ba8694
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/governance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -557,10 +557,6 @@ void CGovernanceManager::DoMaintenance(CConnman& connman)
{
if (fLiteMode || !masternodeSync.IsSynced() || ShutdownRequested()) return;

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

// CHECK OBJECTS WE'VE ASKED FOR, REMOVE OLD ENTRIES

CleanOrphanObjects();
Expand Down Expand Up @@ -1330,11 +1326,15 @@ void CGovernanceManager::CleanOrphanObjects()

void CGovernanceManager::RemoveInvalidVotes()
{
auto curMNList = deterministicMNManager->GetListAtChainTip();
auto diff = lastMNListForVotingKeys.BuildDiff(curMNList);
if (!masternodeSync.IsSynced()) {
return;
}

LOCK(cs);

auto curMNList = deterministicMNManager->GetListAtChainTip();
auto diff = lastMNListForVotingKeys.BuildDiff(curMNList);

std::vector<COutPoint> changedKeyMNs;
for (const auto& p : diff.updatedMNs) {
auto oldDmn = lastMNListForVotingKeys.GetMN(p.first);
Expand Down

0 comments on commit 1ba8694

Please sign in to comment.