From a6320865c46b2af0ec89c830c868e7aeec96d187 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Thu, 25 Jul 2024 12:31:44 +0300 Subject: [PATCH] fix: avoid voting for the same trigger multiple times --- src/governance/governance.cpp | 39 ++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/src/governance/governance.cpp b/src/governance/governance.cpp index 89336190ed..208cb7e5bd 100644 --- a/src/governance/governance.cpp +++ b/src/governance/governance.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -743,21 +744,36 @@ 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()); @@ -768,6 +784,19 @@ 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, "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