From 21cc12c62ab3f964cfb0ea2172ba53ed8b9f4b5d Mon Sep 17 00:00:00 2001 From: Kittywhiskers Van Gogh <63189531+kwvg@users.noreply.github.com> Date: Wed, 26 Jun 2024 11:04:54 +0000 Subject: [PATCH] refactor: drop usage of chainstate globals in governance logic --- src/evo/chainhelper.cpp | 4 ++-- src/evo/chainhelper.h | 3 ++- src/governance/classes.cpp | 12 ++++++------ src/governance/classes.h | 14 +++++++------- src/governance/governance.cpp | 19 ++++++++++--------- src/governance/governance.h | 3 ++- src/governance/object.cpp | 20 ++++++++++---------- src/governance/object.h | 9 +++++---- src/init.cpp | 4 ++-- src/masternode/payments.cpp | 6 +++--- src/masternode/payments.h | 9 ++++++--- src/node/interfaces.cpp | 4 ++-- src/rpc/governance.cpp | 26 ++++++++++++++++---------- src/test/util/setup_common.cpp | 4 ++-- 14 files changed, 75 insertions(+), 62 deletions(-) diff --git a/src/evo/chainhelper.cpp b/src/evo/chainhelper.cpp index 519983b84697d..4063fbd0f5755 100644 --- a/src/evo/chainhelper.cpp +++ b/src/evo/chainhelper.cpp @@ -9,10 +9,10 @@ #include CChainstateHelper::CChainstateHelper(CCreditPoolManager& cpoolman, CDeterministicMNManager& dmnman, CMNHFManager& mnhfman, CGovernanceManager& govman, - llmq::CQuorumBlockProcessor& qblockman, const Consensus::Params& consensus_params, + llmq::CQuorumBlockProcessor& qblockman, const ChainstateManager& chainman, const Consensus::Params& consensus_params, const CMasternodeSync& mn_sync, const CSporkManager& sporkman, const llmq::CChainLocksHandler& clhandler, const llmq::CQuorumManager& qman) - : mn_payments{std::make_unique(dmnman, govman, consensus_params, mn_sync, sporkman)}, + : mn_payments{std::make_unique(dmnman, govman, chainman, consensus_params, mn_sync, sporkman)}, special_tx{std::make_unique(cpoolman, dmnman, mnhfman, qblockman, consensus_params, clhandler, qman)} {} diff --git a/src/evo/chainhelper.h b/src/evo/chainhelper.h index 4e687b3f28079..73db5b3427e6a 100644 --- a/src/evo/chainhelper.h +++ b/src/evo/chainhelper.h @@ -9,6 +9,7 @@ class CCreditPoolManager; class CDeterministicMNManager; +class ChainstateManager; class CMNHFManager; class CMNPaymentsProcessor; class CMasternodeSync; @@ -27,7 +28,7 @@ class CChainstateHelper { public: explicit CChainstateHelper(CCreditPoolManager& cpoolman, CDeterministicMNManager& dmnman, CMNHFManager& mnhfman, CGovernanceManager& govman, - llmq::CQuorumBlockProcessor& qblockman, const Consensus::Params& consensus_params, + llmq::CQuorumBlockProcessor& qblockman, const ChainstateManager& chainman, const Consensus::Params& consensus_params, const CMasternodeSync& mn_sync, const CSporkManager& sporkman, const llmq::CChainLocksHandler& clhandler, const llmq::CQuorumManager& qman); ~CChainstateHelper(); diff --git a/src/governance/classes.cpp b/src/governance/classes.cpp index 4c132f065a035..163abde1b6b5d 100644 --- a/src/governance/classes.cpp +++ b/src/governance/classes.cpp @@ -362,14 +362,14 @@ bool CSuperblockManager::GetSuperblockPayments(CGovernanceManager& govman, const return true; } -bool CSuperblockManager::IsValid(CGovernanceManager& govman, const CDeterministicMNList& tip_mn_list, const CTransaction& txNew, int nBlockHeight, CAmount blockReward) +bool CSuperblockManager::IsValid(CGovernanceManager& govman, const CChain& active_chain, const CDeterministicMNList& tip_mn_list, const CTransaction& txNew, int nBlockHeight, CAmount blockReward) { // GET BEST SUPERBLOCK, SHOULD MATCH LOCK(govman.cs); CSuperblock_sptr pSuperblock; if (CSuperblockManager::GetBestSuperblock(govman, tip_mn_list, pSuperblock, nBlockHeight)) { - return pSuperblock->IsValid(govman, txNew, nBlockHeight, blockReward); + return pSuperblock->IsValid(govman, active_chain, txNew, nBlockHeight, blockReward); } return false; @@ -482,7 +482,7 @@ void CSuperblock::GetNearestSuperblocksHeights(int nBlockHeight, int& nLastSuper } } -CAmount CSuperblock::GetPaymentsLimit(int nBlockHeight) +CAmount CSuperblock::GetPaymentsLimit(const CChain& active_chain, int nBlockHeight) { const Consensus::Params& consensusParams = Params().GetConsensus(); @@ -490,7 +490,7 @@ CAmount CSuperblock::GetPaymentsLimit(int nBlockHeight) return 0; } - const CBlockIndex* pindex = ::ChainActive().Tip(); + const CBlockIndex* pindex = active_chain.Tip(); if (pindex->nHeight > nBlockHeight) pindex = pindex->GetAncestor(nBlockHeight); const auto v20_state = g_versionbitscache.State(pindex, consensusParams, Consensus::DEPLOYMENT_V20); @@ -612,7 +612,7 @@ CAmount CSuperblock::GetPaymentsTotalAmount() * - Does this transaction match the superblock? */ -bool CSuperblock::IsValid(CGovernanceManager& govman, const CTransaction& txNew, int nBlockHeight, CAmount blockReward) +bool CSuperblock::IsValid(CGovernanceManager& govman, const CChain& active_chain, const CTransaction& txNew, int nBlockHeight, CAmount blockReward) { // TODO : LOCK(cs); // No reason for a lock here now since this method only accesses data @@ -646,7 +646,7 @@ bool CSuperblock::IsValid(CGovernanceManager& govman, const CTransaction& txNew, // payments should not exceed limit CAmount nPaymentsTotalAmount = GetPaymentsTotalAmount(); - CAmount nPaymentsLimit = GetPaymentsLimit(nBlockHeight); + CAmount nPaymentsLimit = GetPaymentsLimit(active_chain, nBlockHeight); if (nPaymentsTotalAmount > nPaymentsLimit) { LogPrintf("CSuperblock::IsValid -- ERROR: Block invalid, payments limit exceeded: payments %lld, limit %lld\n", nPaymentsTotalAmount, nPaymentsLimit); return false; diff --git a/src/governance/classes.h b/src/governance/classes.h index da85d98dc245b..7ff8eff2e4f8b 100644 --- a/src/governance/classes.h +++ b/src/governance/classes.h @@ -10,12 +10,12 @@ #include