diff --git a/src/governance/governance.cpp b/src/governance/governance.cpp index defdfd6f64..00a130e7d1 100644 --- a/src/governance/governance.cpp +++ b/src/governance/governance.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -736,21 +737,47 @@ void CGovernanceManager::VoteGovernanceTriggers(const std::optionalGetGovernanceObject(*this)->GetHash(); + const auto govobj = trigger->GetGovernanceObject(*this); + const uint256 trigger_hash = govobj->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()); @@ -761,6 +788,22 @@ void CGovernanceManager::VoteGovernanceTriggers(const std::optionalGetCurrentMNVotes(mn_activeman.GetOutPoint(), voteRecord)) { + const auto& strFunc = __func__; + if (ranges::any_of(voteRecord.mapInstances, [&](const auto& voteInstancePair) { + if (voteInstancePair.first == VOTE_SIGNAL_FUNDING) { + LogPrint(BCLog::GOBJECT, /* Continued */ + "CGovernanceManager::%s " + "Not voting NO-FUNDING for trigger:%s, we voted %s for it already\n", + strFunc, trigger_hash.ToString(), + CGovernanceVoting::ConvertOutcomeToString(voteInstancePair.second.eOutcome)); + return true; + } + return false; + })) { + continue; + } + } if (!VoteFundingTrigger(trigger_hash, VOTE_OUTCOME_NO, connman, peerman, mn_activeman)) { LogPrint(BCLog::GOBJECT, "CGovernanceManager::%s Voting NO-FUNDING for trigger:%s failed\n", __func__, trigger_hash.ToString()); // failing here is ok-ish diff --git a/test/functional/feature_governance.py b/test/functional/feature_governance.py index e98cf6ba1b..9ec599dc96 100755 --- a/test/functional/feature_governance.py +++ b/test/functional/feature_governance.py @@ -11,6 +11,8 @@ from test_framework.test_framework import DashTestFramework from test_framework.governance import have_trigger_for_height, prepare_object from test_framework.util import assert_equal, satoshi_round, set_node_times, wait_until_helper +GOVERNANCE_UPDATE_MIN = 60 * 60 # src/governance/object.h + class DashGovernanceTest (DashTestFramework): def set_test_params(self): self.v20_start_time = 1417713500 + 80 @@ -283,6 +285,23 @@ class DashGovernanceTest (DashTestFramework): self.wait_until(lambda: self.nodes[0].gobject("list", "valid", "triggers")[winning_trigger_hash]['NoCount'] == 1, timeout=5) self.wait_until(lambda: self.nodes[0].gobject("list", "valid", "triggers")[isolated_trigger_hash]['NoCount'] == self.mn_count - 1, timeout=5) + # Remember vote count + before = self.nodes[1].gobject("count")["votes"] + + # Bump mocktime to let MNs vote again + self.bump_mocktime(GOVERNANCE_UPDATE_MIN + 1) + + # Move another block inside the Superblock maturity window + with self.nodes[1].assert_debug_log(["CGovernanceManager::VoteGovernanceTriggers"]): + self.nodes[0].generate(1) + self.bump_mocktime(1) + self.sync_blocks() + + # Vote count should not change even though MNs are allowed to vote again + assert_equal(before, self.nodes[1].gobject("count")["votes"]) + # Revert mocktime back to avoid issues in tests below + self.bump_mocktime(GOVERNANCE_UPDATE_MIN * -1) + block_count = self.nodes[0].getblockcount() n = sb_cycle - block_count % sb_cycle