Skip to content

Commit

Permalink
fix: ignore triggers from the past when voting (dashpay#5798)
Browse files Browse the repository at this point in the history
## 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)_
  • Loading branch information
UdjinM6 authored and knst committed Jan 10, 2024
1 parent 4ebdaf6 commit acd3ce7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/governance/governance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,11 @@ void CGovernanceManager::VoteGovernanceTriggers(const std::optional<const CGover
const auto activeTriggers = triggerman.GetActiveTriggers();
for (const auto& trigger : activeTriggers) {
const uint256 trigger_hash = trigger->GetGovernanceObject(*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());
Expand Down
23 changes: 22 additions & 1 deletion test/functional/feature_governance.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,13 +303,34 @@ def sync_gov(node):
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()
Expand Down

0 comments on commit acd3ce7

Please sign in to comment.