Move cs_main lock from CMasternode::UpdateLastPaid to CMasternodeMan

Ensure correct locking order to fix deadlock.
This commit is contained in:
Alexander Block 2018-03-09 21:19:44 +01:00
parent dc7292afa9
commit 19fbf8ab76
2 changed files with 3 additions and 2 deletions

View File

@ -347,6 +347,8 @@ std::string CMasternode::GetStatus() const
void CMasternode::UpdateLastPaid(const CBlockIndex *pindex, int nMaxBlocksToScanBack) void CMasternode::UpdateLastPaid(const CBlockIndex *pindex, int nMaxBlocksToScanBack)
{ {
AssertLockHeld(cs_main);
if(!pindex) return; if(!pindex) return;
if (deterministicMNManager->IsDeterministicMNsSporkActive(pindex->nHeight)) { if (deterministicMNManager->IsDeterministicMNsSporkActive(pindex->nHeight)) {
@ -354,7 +356,6 @@ void CMasternode::UpdateLastPaid(const CBlockIndex *pindex, int nMaxBlocksToScan
if (!dmn || dmn->pdmnState->nLastPaidHeight == -1) { if (!dmn || dmn->pdmnState->nLastPaidHeight == -1) {
LogPrint("masternode", "CMasternode::UpdateLastPaidBlock -- searching for block with payment to %s -- not found\n", outpoint.ToStringShort()); LogPrint("masternode", "CMasternode::UpdateLastPaidBlock -- searching for block with payment to %s -- not found\n", outpoint.ToStringShort());
} else { } else {
LOCK(cs_main);
nBlockLastPaid = (int)dmn->pdmnState->nLastPaidHeight; nBlockLastPaid = (int)dmn->pdmnState->nLastPaidHeight;
nTimeLastPaid = chainActive[nBlockLastPaid]->nTime; nTimeLastPaid = chainActive[nBlockLastPaid]->nTime;
LogPrint("masternode", "CMasternode::UpdateLastPaidBlock -- searching for block with payment to %s -- found new %d\n", outpoint.ToStringShort(), nBlockLastPaid); LogPrint("masternode", "CMasternode::UpdateLastPaidBlock -- searching for block with payment to %s -- found new %d\n", outpoint.ToStringShort(), nBlockLastPaid);

View File

@ -1817,7 +1817,7 @@ bool CMasternodeMan::CheckMnbAndUpdateMasternodeList(CNode* pfrom, CMasternodeBr
void CMasternodeMan::UpdateLastPaid(const CBlockIndex* pindex) void CMasternodeMan::UpdateLastPaid(const CBlockIndex* pindex)
{ {
LOCK(cs); LOCK2(cs_main, cs);
if(fLiteMode || !masternodeSync.IsWinnersListSynced() || mapMasternodes.empty()) return; if(fLiteMode || !masternodeSync.IsWinnersListSynced() || mapMasternodes.empty()) return;