Skip to content

Commit

Permalink
Move cs_main lock from CMasternode::UpdateLastPaid to CMasternodeMan
Browse files Browse the repository at this point in the history
Ensure correct locking order to fix deadlock.
  • Loading branch information
codablock committed Sep 5, 2018
1 parent dc7292a commit 19fbf8a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/masternode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,14 +347,15 @@ std::string CMasternode::GetStatus() const

void CMasternode::UpdateLastPaid(const CBlockIndex *pindex, int nMaxBlocksToScanBack)
{
AssertLockHeld(cs_main);

if(!pindex) return;

if (deterministicMNManager->IsDeterministicMNsSporkActive(pindex->nHeight)) {
auto dmn = deterministicMNManager->GetListForBlock(pindex->GetBlockHash()).GetMN(outpoint.hash);
if (!dmn || dmn->pdmnState->nLastPaidHeight == -1) {
LogPrint("masternode", "CMasternode::UpdateLastPaidBlock -- searching for block with payment to %s -- not found\n", outpoint.ToStringShort());
} else {
LOCK(cs_main);
nBlockLastPaid = (int)dmn->pdmnState->nLastPaidHeight;
nTimeLastPaid = chainActive[nBlockLastPaid]->nTime;
LogPrint("masternode", "CMasternode::UpdateLastPaidBlock -- searching for block with payment to %s -- found new %d\n", outpoint.ToStringShort(), nBlockLastPaid);
Expand Down
2 changes: 1 addition & 1 deletion src/masternodeman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1817,7 +1817,7 @@ bool CMasternodeMan::CheckMnbAndUpdateMasternodeList(CNode* pfrom, CMasternodeBr

void CMasternodeMan::UpdateLastPaid(const CBlockIndex* pindex)
{
LOCK(cs);
LOCK2(cs_main, cs);

if(fLiteMode || !masternodeSync.IsWinnersListSynced() || mapMasternodes.empty()) return;

Expand Down

0 comments on commit 19fbf8a

Please sign in to comment.