Skip to content

Commit 3e732a9

Browse files
authored
fix: expire triggers that are too far into the future (#5646)
## Issue being fixed or feature implemented `gobject count all` before: >Governance Objects: 1195 (Proposals: 9, Triggers: 1186, Other: 0; Erased: 1), Votes: 135064 after (in 10-ish minutes after gov sync is done): >Governance Objects: 11 (Proposals: 9, Triggers: 2, Other: 0; Erased: 1), Votes: 702 I _think_ it happens when a node can't follow the right chain for some reason but it keeps receiving triggers and votes from other nodes which means triggers never expire on such node. This wouldn't be a problem for us if we wouldn't reorg testnet/devnets from time to time. Once we reorg the stuck node happily spams us with all the triggers it saved in the meantime. ## What was done? 2 sb cycles into the future should be enough for all legit triggers, drop the ones that have their height even higher ## How Has This Been Tested? run a node, check rpc ## Breaking Changes n/a ## Checklist: - [x] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have added or updated relevant unit/integration/functional/e2e tests - [ ] I have made corresponding changes to the documentation - [x] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_
1 parent 297b50a commit 3e732a9

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/governance/classes.cpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ bool CGovernanceTriggerManager::AddNewTrigger(uint256 nHash)
127127

128128
mapTrigger.insert(std::make_pair(nHash, pSuperblock));
129129

130-
return true;
130+
return !pSuperblock->IsExpired(*governance);
131131
}
132132

133133
/**
@@ -724,6 +724,14 @@ bool CSuperblock::IsExpired(const CGovernanceManager& governanceManager) const
724724
return true;
725725
}
726726

727+
if (Params().NetworkIDString() != CBaseChainParams::MAIN) {
728+
// NOTE: this can happen on testnet/devnets due to reorgs, should never happen on mainnet
729+
if (governanceManager.GetCachedBlockHeight() + Params().GetConsensus().nSuperblockCycle * 2 < nBlockHeight) {
730+
LogPrint(BCLog::GOBJECT, "CSuperblock::IsExpired -- Trigger is too far into the future\n");
731+
return true;
732+
}
733+
}
734+
727735
return false;
728736
}
729737

src/governance/governance.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1203,8 +1203,8 @@ int CGovernanceManager::RequestGovernanceObjectVotes(Span<CNode*> vNodesCopy, CC
12031203

12041204
if (mapObjects.empty()) return -2;
12051205

1206-
for (const auto& objPair : mapObjects) {
1207-
uint256 nHash = objPair.first;
1206+
for (const auto& [nHash, govobj] : mapObjects) {
1207+
if (govobj.IsSetCachedDelete()) continue;
12081208
if (mapAskedRecently.count(nHash)) {
12091209
auto it = mapAskedRecently[nHash].begin();
12101210
while (it != mapAskedRecently[nHash].end()) {
@@ -1217,7 +1217,7 @@ int CGovernanceManager::RequestGovernanceObjectVotes(Span<CNode*> vNodesCopy, CC
12171217
if (mapAskedRecently[nHash].size() >= nPeersPerHashMax) continue;
12181218
}
12191219

1220-
if (objPair.second.GetObjectType() == GovernanceObject::TRIGGER) {
1220+
if (govobj.GetObjectType() == GovernanceObject::TRIGGER) {
12211221
vTriggerObjHashes.push_back(nHash);
12221222
} else {
12231223
vOtherObjHashes.push_back(nHash);

0 commit comments

Comments
 (0)