From acd3ce7783cf9ab2feb68594a26c5795eeb9d805 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Sun, 7 Jan 2024 04:27:26 +0300 Subject: [PATCH] fix: ignore triggers from the past when voting (#5798) ## Issue being fixed or feature implemented we should not vote on triggers from the past ## What was done? ## How Has This Been Tested? n/a ## 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)_ --- src/governance/governance.cpp | 5 +++++ test/functional/feature_governance.py | 23 ++++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/governance/governance.cpp b/src/governance/governance.cpp index 25dff9e48e..def0bc1b5b 100644 --- a/src/governance/governance.cpp +++ b/src/governance/governance.cpp @@ -738,6 +738,11 @@ void CGovernanceManager::VoteGovernanceTriggers(const std::optionalGetGovernanceObject(*this)->GetHash(); + if (trigger->GetBlockHeight() <= nCachedBlockHeight) { + // ignore triggers from the past + LogPrint(BCLog::GOBJECT, "CGovernanceManager::%s Not voting NO-FUNDING for outdated trigger:%s\n", __func__, trigger_hash.ToString()); + continue; + } if (trigger_hash == votedFundingYesTriggerHash) { // Skip actual trigger LogPrint(BCLog::GOBJECT, "CGovernanceManager::%s Not voting NO-FUNDING for trigger:%s, we voted yes for it already\n", __func__, trigger_hash.ToString()); diff --git a/test/functional/feature_governance.py b/test/functional/feature_governance.py index 3b076aa960..0169896694 100755 --- a/test/functional/feature_governance.py +++ b/test/functional/feature_governance.py @@ -303,13 +303,34 @@ class DashGovernanceTest (DashTestFramework): self.check_superblockbudget(True) self.check_superblock() + # Move a few block past the recent superblock height and make sure we have no new votes + for _ in range(5): + with self.nodes[1].assert_debug_log("", [f"Voting NO-FUNDING for trigger:{winning_trigger_hash} success"]): + self.nodes[0].generate(1) + self.bump_mocktime(1) + self.sync_blocks() + # Votes on both triggers should NOT change + assert_equal(self.nodes[0].gobject("list", "valid", "triggers")[winning_trigger_hash]['NoCount'], 1) + assert_equal(self.nodes[0].gobject("list", "valid", "triggers")[isolated_trigger_hash]['NoCount'], self.mn_count - 1) + + block_count = self.nodes[0].getblockcount() + n = sb_cycle - block_count % sb_cycle + + # Move remaining n blocks until the next Superblock + for i in range(n): + self.nodes[0].generate(1) + self.bump_mocktime(1) + self.sync_blocks() + assert_equal(self.nodes[0].getblockcount(), 260) + assert_equal(self.nodes[0].getblockchaininfo()["softforks"]["v20"]["bip9"]["status"], "active") + # Mine and check a couple more superblocks for i in range(2): for _ in range(20): self.nodes[0].generate(1) self.bump_mocktime(1) self.sync_blocks() - assert_equal(self.nodes[0].getblockcount(), 240 + (i + 1) * 20) + assert_equal(self.nodes[0].getblockcount(), 260 + (i + 1) * 20) assert_equal(self.nodes[0].getblockchaininfo()["softforks"]["v20"]["bip9"]["status"], "active") self.check_superblockbudget(True) self.check_superblock()