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
This commit is contained in:
UdjinM6 2019-04-08 08:38:13 +03:00 committed by GitHub
parent b5bc7c9dac
commit 1ba8694cd7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -557,10 +557,6 @@ void CGovernanceManager::DoMaintenance(CConnman& connman)
{ {
if (fLiteMode || !masternodeSync.IsSynced() || ShutdownRequested()) return; if (fLiteMode || !masternodeSync.IsSynced() || ShutdownRequested()) return;
if (deterministicMNManager->IsDIP3Enforced()) {
RemoveInvalidVotes();
}
// CHECK OBJECTS WE'VE ASKED FOR, REMOVE OLD ENTRIES // CHECK OBJECTS WE'VE ASKED FOR, REMOVE OLD ENTRIES
CleanOrphanObjects(); CleanOrphanObjects();
@ -1330,11 +1326,15 @@ void CGovernanceManager::CleanOrphanObjects()
void CGovernanceManager::RemoveInvalidVotes() void CGovernanceManager::RemoveInvalidVotes()
{ {
auto curMNList = deterministicMNManager->GetListAtChainTip(); if (!masternodeSync.IsSynced()) {
auto diff = lastMNListForVotingKeys.BuildDiff(curMNList); return;
}
LOCK(cs); LOCK(cs);
auto curMNList = deterministicMNManager->GetListAtChainTip();
auto diff = lastMNListForVotingKeys.BuildDiff(curMNList);
std::vector<COutPoint> changedKeyMNs; std::vector<COutPoint> changedKeyMNs;
for (const auto& p : diff.updatedMNs) { for (const auto& p : diff.updatedMNs) {
auto oldDmn = lastMNListForVotingKeys.GetMN(p.first); auto oldDmn = lastMNListForVotingKeys.GetMN(p.first);