From 1ba8694cd748ee4f4cef15aec6c5503b95647eae Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Mon, 8 Apr 2019 08:38:13 +0300 Subject: [PATCH] Various fixes for RemoveInvalidVotes() (#2845) * 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 --- src/governance.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/governance.cpp b/src/governance.cpp index 7017231a6f372..5ce8ac5ee48e9 100644 --- a/src/governance.cpp +++ b/src/governance.cpp @@ -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(); @@ -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 changedKeyMNs; for (const auto& p : diff.updatedMNs) { auto oldDmn = lastMNListForVotingKeys.GetMN(p.first);