Skip to content

Commit 9402ce7

Browse files
committed
refactor: limit usage of fDisableGovernance, use IsValid() instead
CGovernanceManager::IsValid() returns true only if its db is successfully initialized. If we attempt to initialize it and fail, init logic will report to us that it failed. If we don't attempt to initialize it at all, it will remain false. Since fDisableGovernance is the same as not initializing it at all and the other case where IsValid() is false is dealt with in init, we can use IsValid() to infer if governance is enabled.
1 parent 106f6bd commit 9402ce7

File tree

5 files changed

+10
-9
lines changed

5 files changed

+10
-9
lines changed

src/dsnotificationinterface.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ void CDSNotificationInterface::UpdatedBlockTip(const CBlockIndex *pindexNew, con
9999
m_llmq_ctx->qdkgsman->UpdatedBlockTip(pindexNew, fInitialDownload);
100100
m_llmq_ctx->ehfSignalsHandler->UpdatedBlockTip(pindexNew, /* is_masternode = */ m_mn_activeman != nullptr);
101101

102-
if (!fDisableGovernance) m_govman.UpdatedBlockTip(pindexNew, m_connman, m_peerman, m_mn_activeman);
102+
if (m_govman.IsValid()) {
103+
m_govman.UpdatedBlockTip(pindexNew, m_connman, m_peerman, m_mn_activeman);
104+
}
103105
}
104106

105107
void CDSNotificationInterface::TransactionAddedToMempool(const CTransactionRef& ptx, int64_t nAcceptTime)

src/governance/governance.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ bool CGovernanceManager::SerializeVoteForHash(const uint256& nHash, CDataStream&
121121

122122
PeerMsgRet CGovernanceManager::ProcessMessage(CNode& peer, CConnman& connman, PeerManager& peerman, std::string_view msg_type, CDataStream& vRecv)
123123
{
124-
if (fDisableGovernance) return {};
124+
if (!IsValid()) return {};
125125
if (m_mn_sync == nullptr || !m_mn_sync->IsBlockchainSynced()) return {};
126126

127127
const auto tip_mn_list = Assert(m_dmnman)->GetListAtChainTip();
@@ -565,7 +565,7 @@ struct sortProposalsByVotes {
565565

566566
std::optional<const CSuperblock> CGovernanceManager::CreateSuperblockCandidate(int nHeight) const
567567
{
568-
if (fDisableGovernance) return std::nullopt;
568+
if (!IsValid()) return std::nullopt;
569569
if (m_mn_sync == nullptr || !m_mn_sync->IsSynced()) return std::nullopt;
570570
if (nHeight % Params().GetConsensus().nSuperblockCycle < Params().GetConsensus().nSuperblockCycle - Params().GetConsensus().nSuperblockMaturityWindow) return std::nullopt;
571571
if (HasAlreadyVotedFundingTrigger()) return std::nullopt;
@@ -793,7 +793,7 @@ void CGovernanceManager::ResetVotedFundingTrigger()
793793

794794
void CGovernanceManager::DoMaintenance(CConnman& connman)
795795
{
796-
if (fDisableGovernance) return;
796+
if (!IsValid()) return;
797797
if (m_mn_sync == nullptr || !m_mn_sync->IsSynced()) return;
798798
if (ShutdownRequested()) return;
799799

src/init.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2312,7 +2312,7 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc
23122312
node.scheduler->scheduleEvery(std::bind(&CMasternodeUtils::DoMaintenance, std::ref(*node.connman), std::ref(*node.dmnman), std::ref(*node.mn_sync), std::ref(*node.cj_ctx)), std::chrono::minutes{1});
23132313
node.scheduler->scheduleEvery(std::bind(&CDeterministicMNManager::DoMaintenance, std::ref(*node.dmnman)), std::chrono::seconds{10});
23142314

2315-
if (!fDisableGovernance) {
2315+
if (node.govman->IsValid()) {
23162316
node.scheduler->scheduleEvery(std::bind(&CGovernanceManager::DoMaintenance, std::ref(*node.govman), std::ref(*node.connman)), std::chrono::minutes{5});
23172317
}
23182318

src/masternode/payments.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include <script/standard.h>
1919
#include <tinyformat.h>
2020
#include <util/ranges.h>
21-
#include <util/system.h>
2221
#include <validation.h>
2322

2423
#include <cassert>
@@ -223,7 +222,7 @@ bool CMNPaymentsProcessor::IsBlockValueValid(const CBlock& block, const int nBlo
223222
return false;
224223
}
225224

226-
if(!m_mn_sync.IsSynced() || fDisableGovernance) {
225+
if (!m_mn_sync.IsSynced() || !m_govman.IsValid()) {
227226
LogPrint(BCLog::MNPAYMENTS, "CMNPaymentsProcessor::%s -- WARNING! Not enough data, checked superblock max bounds only\n", __func__);
228227
// not enough data for full checks but at least we know that the superblock limits were honored.
229228
// We rely on the network to have followed the correct chain in this case
@@ -280,7 +279,7 @@ bool CMNPaymentsProcessor::IsBlockPayeeValid(const CTransaction& txNew, const CB
280279
return false;
281280
}
282281

283-
if (!m_mn_sync.IsSynced() || fDisableGovernance) {
282+
if (!m_mn_sync.IsSynced() || !m_govman.IsValid()) {
284283
// governance data is either incomplete or non-existent
285284
LogPrint(BCLog::MNPAYMENTS, "CMNPaymentsProcessor::%s -- WARNING! Not enough data, skipping superblock payee checks\n", __func__);
286285
return true; // not an error

src/masternode/sync.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ void CMasternodeSync::ProcessTick()
220220
// GOVOBJ : SYNC GOVERNANCE ITEMS FROM OUR PEERS
221221

222222
if(nCurrentAsset == MASTERNODE_SYNC_GOVERNANCE) {
223-
if (fDisableGovernance) {
223+
if (!m_govman.IsValid()) {
224224
SwitchToNextAsset();
225225
connman.ReleaseNodeVector(vNodesCopy);
226226
return;

0 commit comments

Comments
 (0)