mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 03:52:49 +01:00
fix: avoid voting for the same trigger multiple times
This commit is contained in:
parent
e3a5afd6a6
commit
a6320865c4
@ -23,6 +23,7 @@
|
||||
#include <protocol.h>
|
||||
#include <shutdown.h>
|
||||
#include <spork.h>
|
||||
#include <util/ranges.h>
|
||||
#include <util/time.h>
|
||||
#include <validation.h>
|
||||
|
||||
@ -743,21 +744,36 @@ void CGovernanceManager::VoteGovernanceTriggers(const std::optional<const CGover
|
||||
if (trigger_opt.has_value()) {
|
||||
// We should never vote "yes" on another trigger or the same trigger twice
|
||||
assert(!votedFundingYesTriggerHash.has_value());
|
||||
// Vote YES-FUNDING for the trigger we like
|
||||
// Vote YES-FUNDING for the trigger we like, unless we already did
|
||||
const uint256 gov_sb_hash = trigger_opt.value().GetHash();
|
||||
if (!VoteFundingTrigger(gov_sb_hash, VOTE_OUTCOME_YES, connman, peerman, mn_activeman)) {
|
||||
if (vote_rec_t voteRecord; trigger_opt.value().GetCurrentMNVotes(mn_activeman.GetOutPoint(), voteRecord)) {
|
||||
const auto& strFunc = __func__;
|
||||
ranges::any_of(voteRecord.mapInstances, [&](const auto& voteInstancePair){
|
||||
if (voteInstancePair.first == VOTE_SIGNAL_FUNDING) {
|
||||
if (voteInstancePair.second.eOutcome == VOTE_OUTCOME_YES) {
|
||||
votedFundingYesTriggerHash = gov_sb_hash;
|
||||
}
|
||||
LogPrint(BCLog::GOBJECT, "CGovernanceManager::%s Not voting YES-FUNDING for trigger:%s, we voted %s for it already\n",
|
||||
strFunc, gov_sb_hash.ToString(), CGovernanceVoting::ConvertOutcomeToString(voteInstancePair.second.eOutcome));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
} else if (VoteFundingTrigger(gov_sb_hash, VOTE_OUTCOME_YES, connman, peerman, mn_activeman)) {
|
||||
LogPrint(BCLog::GOBJECT, "CGovernanceManager::%s Voting YES-FUNDING for new trigger:%s success\n", __func__, gov_sb_hash.ToString());
|
||||
votedFundingYesTriggerHash = gov_sb_hash;
|
||||
} else {
|
||||
LogPrint(BCLog::GOBJECT, "CGovernanceManager::%s Voting YES-FUNDING for new trigger:%s failed\n", __func__, gov_sb_hash.ToString());
|
||||
// this should never happen, bail out
|
||||
return;
|
||||
}
|
||||
LogPrint(BCLog::GOBJECT, "CGovernanceManager::%s Voting YES-FUNDING for new trigger:%s success\n", __func__, gov_sb_hash.ToString());
|
||||
votedFundingYesTriggerHash = gov_sb_hash;
|
||||
}
|
||||
|
||||
// Vote NO-FUNDING for the rest of the active triggers
|
||||
const auto activeTriggers = GetActiveTriggers();
|
||||
for (const auto& trigger : activeTriggers) {
|
||||
const uint256 trigger_hash = trigger->GetGovernanceObject(*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::optional<const CGover
|
||||
LogPrint(BCLog::GOBJECT, "CGovernanceManager::%s Not voting NO-FUNDING for trigger:%s, we voted yes for it already\n", __func__, trigger_hash.ToString());
|
||||
continue;
|
||||
}
|
||||
if (vote_rec_t voteRecord; govobj->GetCurrentMNVotes(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
|
||||
|
Loading…
Reference in New Issue
Block a user