Skip to content

Commit af01054

Browse files
committed
Masternode: locking internal cs for lastPing set.
1 parent b82c0e6 commit af01054

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

src/activemasternode.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,13 +209,18 @@ bool CActiveMasternode::SendMasternodePing(std::string& errorMessage)
209209
return false;
210210
}
211211

212-
pmn->lastPing = mnp;
212+
// SetLastPing locks the masternode cs, be careful with the lock order.
213+
pmn->SetLastPing(mnp);
213214
mnodeman.mapSeenMasternodePing.emplace(mnp.GetHash(), mnp);
214215

215216
//mnodeman.mapSeenMasternodeBroadcast.lastPing is probably outdated, so we'll update it
216217
CMasternodeBroadcast mnb(*pmn);
217218
uint256 hash = mnb.GetHash();
218-
if (mnodeman.mapSeenMasternodeBroadcast.count(hash)) mnodeman.mapSeenMasternodeBroadcast[hash].lastPing = mnp;
219+
if (mnodeman.mapSeenMasternodeBroadcast.count(hash)) {
220+
// SetLastPing locks the masternode cs, be careful with the lock order.
221+
// TODO: check why are we double setting the last ping here..
222+
mnodeman.mapSeenMasternodeBroadcast[hash].SetLastPing(mnp);
223+
}
219224

220225
mnp.Relay();
221226
return true;

src/masternode.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,8 @@ bool CMasternodePing::CheckAndUpdate(int& nDos, bool fRequireEnabled, bool fChec
727727
return false;
728728
}
729729

730-
pmn->lastPing = *this;
730+
// SetLastPing locks masternode cs. Be careful with the lock ordering.
731+
pmn->SetLastPing(*this);
731732

732733
//mnodeman.mapSeenMasternodeBroadcast.lastPing is probably outdated, so we'll update it
733734
CMasternodeBroadcast mnb(*pmn);

src/masternode.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ class CMasternode : public CSignedMessage
147147
const CTxIn GetVin() const override { return vin; };
148148
const CPubKey GetPublicKey(std::string& strErrorRet) const override { return pubKeyCollateralAddress; }
149149

150+
void SetLastPing(const CMasternodePing& _lastPing) { WITH_LOCK(cs, lastPing = _lastPing;); }
151+
150152
void swap(CMasternode& first, CMasternode& second) // nothrow
151153
{
152154
CSignedMessage::swap(first, second);

0 commit comments

Comments
 (0)