diff --git a/src/governance/classes.cpp b/src/governance/classes.cpp index 949f1e02b1b1c..5b452e4da109a 100644 --- a/src/governance/classes.cpp +++ b/src/governance/classes.cpp @@ -127,7 +127,7 @@ bool CGovernanceTriggerManager::AddNewTrigger(uint256 nHash) mapTrigger.insert(std::make_pair(nHash, pSuperblock)); - return true; + return !pSuperblock->IsExpired(*governance); } /** @@ -724,6 +724,14 @@ bool CSuperblock::IsExpired(const CGovernanceManager& governanceManager) const return true; } + if (Params().NetworkIDString() != CBaseChainParams::MAIN) { + // NOTE: this can happen on testnet/devnets due to reorgs, should never happen on mainnet + if (governanceManager.GetCachedBlockHeight() + Params().GetConsensus().nSuperblockCycle * 2 < nBlockHeight) { + LogPrint(BCLog::GOBJECT, "CSuperblock::IsExpired -- Trigger is too far into the future\n"); + return true; + } + } + return false; } diff --git a/src/governance/governance.cpp b/src/governance/governance.cpp index 12efb5b7b2d98..0c4952309b07d 100644 --- a/src/governance/governance.cpp +++ b/src/governance/governance.cpp @@ -1203,8 +1203,8 @@ int CGovernanceManager::RequestGovernanceObjectVotes(Span vNodesCopy, CC if (mapObjects.empty()) return -2; - for (const auto& objPair : mapObjects) { - uint256 nHash = objPair.first; + for (const auto& [nHash, govobj] : mapObjects) { + if (govobj.IsSetCachedDelete()) continue; if (mapAskedRecently.count(nHash)) { auto it = mapAskedRecently[nHash].begin(); while (it != mapAskedRecently[nHash].end()) { @@ -1217,7 +1217,7 @@ int CGovernanceManager::RequestGovernanceObjectVotes(Span vNodesCopy, CC if (mapAskedRecently[nHash].size() >= nPeersPerHashMax) continue; } - if (objPair.second.GetObjectType() == GovernanceObject::TRIGGER) { + if (govobj.GetObjectType() == GovernanceObject::TRIGGER) { vTriggerObjHashes.push_back(nHash); } else { vOtherObjHashes.push_back(nHash);