Skip to content

Commit fe1d84e

Browse files
committed
[Validation] Verify MN pings with cached block hashes
removes cs_main lock to access chainActive in CMasternodePing::CheckAndUpdate
1 parent 14d3c32 commit fe1d84e

File tree

1 file changed

+4
-16
lines changed

1 file changed

+4
-16
lines changed

src/masternode.cpp

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -720,25 +720,13 @@ bool CMasternodePing::CheckAndUpdate(int& nDos, bool fRequireEnabled, bool fChec
720720
return false;
721721
}
722722

723-
// Check if the ping block hash exists in disk
724-
BlockMap::iterator mi = mapBlockIndex.find(blockHash);
725-
if (mi == mapBlockIndex.end() || !(*mi).second) {
726-
LogPrint(BCLog::MNPING,"%s: ping block not in disk. Masternode %s block hash %s\n", __func__, vin.prevout.hash.ToString(), blockHash.ToString());
723+
// Check if the ping block hash exists and it's within 24 blocks from the tip
724+
if (!mnodeman.IsWithinDepth(blockHash, 2 * MNPING_DEPTH)) {
725+
LogPrint(BCLog::MNPING,"%s: Masternode %s block hash %s is too old or has an invalid block hash\n",
726+
__func__, vin.prevout.hash.ToString(), blockHash.ToString());
727727
return false;
728728
}
729729

730-
// Verify ping block hash in main chain and in the [ tip > x > tip - 24 ] range.
731-
{
732-
LOCK(cs_main);
733-
if (!chainActive.Contains((*mi).second) || (chainActive.Height() - (*mi).second->nHeight > 24)) {
734-
LogPrint(BCLog::MNPING,"%s: Masternode %s block hash %s is too old or has an invalid block hash\n",
735-
__func__, vin.prevout.hash.ToString(), blockHash.ToString());
736-
// Do nothing here (no Masternode update, no mnping relay)
737-
// Let this node to be visible but fail to accept mnping
738-
return false;
739-
}
740-
}
741-
742730
pmn->lastPing = *this;
743731

744732
//mnodeman.mapSeenMasternodeBroadcast.lastPing is probably outdated, so we'll update it

0 commit comments

Comments
 (0)