diff --git a/src/evo/chainhelper.cpp b/src/evo/chainhelper.cpp index fe6bfdf192..519983b846 100644 --- a/src/evo/chainhelper.cpp +++ b/src/evo/chainhelper.cpp @@ -10,9 +10,10 @@ CChainstateHelper::CChainstateHelper(CCreditPoolManager& cpoolman, CDeterministicMNManager& dmnman, CMNHFManager& mnhfman, CGovernanceManager& govman, llmq::CQuorumBlockProcessor& qblockman, const Consensus::Params& consensus_params, - const CMasternodeSync& mn_sync, const CSporkManager& sporkman, const llmq::CChainLocksHandler& clhandler) + 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)}, - special_tx{std::make_unique(cpoolman, dmnman, mnhfman, qblockman, consensus_params, clhandler)} + special_tx{std::make_unique(cpoolman, dmnman, mnhfman, qblockman, consensus_params, clhandler, qman)} {} CChainstateHelper::~CChainstateHelper() = default; diff --git a/src/evo/chainhelper.h b/src/evo/chainhelper.h index 06dded2af3..4e687b3f28 100644 --- a/src/evo/chainhelper.h +++ b/src/evo/chainhelper.h @@ -20,6 +20,7 @@ namespace Consensus { struct Params; } namespace llmq { class CChainLocksHandler; class CQuorumBlockProcessor; +class CQuorumManager; } class CChainstateHelper @@ -27,7 +28,8 @@ class CChainstateHelper public: explicit CChainstateHelper(CCreditPoolManager& cpoolman, CDeterministicMNManager& dmnman, CMNHFManager& mnhfman, CGovernanceManager& govman, llmq::CQuorumBlockProcessor& qblockman, const Consensus::Params& consensus_params, - const CMasternodeSync& mn_sync, const CSporkManager& sporkman, const llmq::CChainLocksHandler& clhandler); + const CMasternodeSync& mn_sync, const CSporkManager& sporkman, const llmq::CChainLocksHandler& clhandler, + const llmq::CQuorumManager& qman); ~CChainstateHelper(); CChainstateHelper() = delete; diff --git a/src/evo/mnhftx.cpp b/src/evo/mnhftx.cpp index 003f753e1e..b63b4efd7a 100644 --- a/src/evo/mnhftx.cpp +++ b/src/evo/mnhftx.cpp @@ -84,14 +84,14 @@ CMNHFManager::Signals CMNHFManager::GetSignalsStage(const CBlockIndex* const pin return signals; } -bool MNHFTx::Verify(const uint256& quorumHash, const uint256& requestId, const uint256& msgHash, TxValidationState& state) const +bool MNHFTx::Verify(const llmq::CQuorumManager& qman, const uint256& quorumHash, const uint256& requestId, const uint256& msgHash, TxValidationState& state) const { if (versionBit >= VERSIONBITS_NUM_BITS) { return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-mnhf-nbit-out-of-bounds"); } const Consensus::LLMQType& llmqType = Params().GetConsensus().llmqTypeMnhf; - const auto quorum = llmq::quorumManager->GetQuorum(llmqType, quorumHash); + const auto quorum = qman.GetQuorum(llmqType, quorumHash); const uint256 signHash = llmq::BuildSignHash(llmqType, quorum->qc->quorumHash, requestId, msgHash); if (!sig.VerifyInsecure(quorum->qc->quorumPublicKey, signHash)) { @@ -101,7 +101,7 @@ bool MNHFTx::Verify(const uint256& quorumHash, const uint256& requestId, const u return true; } -bool CheckMNHFTx(const CTransaction& tx, const CBlockIndex* pindexPrev, TxValidationState& state) +bool CheckMNHFTx(const llmq::CQuorumManager& qman, const CTransaction& tx, const CBlockIndex* pindexPrev, TxValidationState& state) { if (!tx.IsSpecialTxVersion() || tx.nType != TRANSACTION_MNHF_SIGNAL) { return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-mnhf-type"); @@ -134,7 +134,7 @@ bool CheckMNHFTx(const CTransaction& tx, const CBlockIndex* pindexPrev, TxValida uint256 msgHash = tx_copy.GetHash(); - if (!mnhfTx.signal.Verify(mnhfTx.signal.quorumHash, mnhfTx.GetRequestId(), msgHash, state)) { + if (!mnhfTx.signal.Verify(qman, mnhfTx.signal.quorumHash, mnhfTx.GetRequestId(), msgHash, state)) { // set up inside Verify return false; } @@ -160,7 +160,7 @@ std::optional extractEHFSignal(const CTransaction& tx) return opt_mnhfTx->signal.versionBit; } -static bool extractSignals(const CBlock& block, const CBlockIndex* const pindex, std::vector& new_signals, BlockValidationState& state) +static bool extractSignals(const llmq::CQuorumManager& qman, const CBlock& block, const CBlockIndex* const pindex, std::vector& new_signals, BlockValidationState& state) { // we skip the coinbase for (size_t i = 1; i < block.vtx.size(); ++i) { @@ -172,7 +172,7 @@ static bool extractSignals(const CBlock& block, const CBlockIndex* const pindex, } TxValidationState tx_state; - if (!CheckMNHFTx(tx, pindex, tx_state)) { + if (!CheckMNHFTx(qman, tx, pindex, tx_state)) { return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, tx_state.GetRejectReason(), tx_state.GetDebugMessage()); } @@ -194,7 +194,7 @@ std::optional CMNHFManager::ProcessBlock(const CBlock& bl { try { std::vector new_signals; - if (!extractSignals(block, pindex, new_signals, state)) { + if (!extractSignals(*Assert(llmq::quorumManager), block, pindex, new_signals, state)) { // state is set inside extractSignals return std::nullopt; } @@ -246,7 +246,7 @@ bool CMNHFManager::UndoBlock(const CBlock& block, const CBlockIndex* const pinde { std::vector excluded_signals; BlockValidationState state; - if (!extractSignals(block, pindex, excluded_signals, state)) { + if (!extractSignals(*Assert(llmq::quorumManager), block, pindex, excluded_signals, state)) { LogPrintf("CMNHFManager::%s: failed to extract signals\n", __func__); return false; } diff --git a/src/evo/mnhftx.h b/src/evo/mnhftx.h index 63d8f07cca..cb045b267b 100644 --- a/src/evo/mnhftx.h +++ b/src/evo/mnhftx.h @@ -22,6 +22,9 @@ class CBlock; class CBlockIndex; class CEvoDB; class TxValidationState; +namespace llmq { +class CQuorumManager; +} // mnhf signal special transaction class MNHFTx @@ -32,7 +35,8 @@ public: CBLSSignature sig{}; MNHFTx() = default; - bool Verify(const uint256& quorumHash, const uint256& requestId, const uint256& msgHash, TxValidationState& state) const; + bool Verify(const llmq::CQuorumManager& qman, const uint256& quorumHash, const uint256& requestId, const uint256& msgHash, + TxValidationState& state) const; SERIALIZE_METHODS(MNHFTx, obj) { @@ -148,6 +152,6 @@ private: }; std::optional extractEHFSignal(const CTransaction& tx); -bool CheckMNHFTx(const CTransaction& tx, const CBlockIndex* pindexPrev, TxValidationState& state); +bool CheckMNHFTx(const llmq::CQuorumManager& qman, const CTransaction& tx, const CBlockIndex* pindexPrev, TxValidationState& state); #endif // BITCOIN_EVO_MNHFTX_H diff --git a/src/evo/specialtxman.cpp b/src/evo/specialtxman.cpp index 8e71a0e68a..debaa0abbc 100644 --- a/src/evo/specialtxman.cpp +++ b/src/evo/specialtxman.cpp @@ -18,7 +18,8 @@ #include #include -static bool CheckSpecialTxInner(CDeterministicMNManager& dmnman, const CTransaction& tx, const CBlockIndex* pindexPrev, const CCoinsViewCache& view, const std::optional& indexes, bool check_sigs, TxValidationState& state) +static bool CheckSpecialTxInner(CDeterministicMNManager& dmnman, const llmq::CQuorumManager& qman, const CTransaction& tx, const CBlockIndex* pindexPrev, + const CCoinsViewCache& view, const std::optional& indexes, bool check_sigs, TxValidationState& state) { AssertLockHeld(cs_main); @@ -48,7 +49,7 @@ static bool CheckSpecialTxInner(CDeterministicMNManager& dmnman, const CTransact if (!DeploymentActiveAfter(pindexPrev, consensusParams, Consensus::DEPLOYMENT_V20)) { return state.Invalid(TxValidationResult::TX_CONSENSUS, "mnhf-before-v20"); } - return CheckMNHFTx(tx, pindexPrev, state); + return CheckMNHFTx(qman, tx, pindexPrev, state); case TRANSACTION_ASSET_LOCK: if (!DeploymentActiveAfter(pindexPrev, consensusParams, Consensus::DEPLOYMENT_V20)) { return state.Invalid(TxValidationResult::TX_CONSENSUS, "assetlocks-before-v20"); @@ -75,7 +76,7 @@ static bool CheckSpecialTxInner(CDeterministicMNManager& dmnman, const CTransact bool CSpecialTxProcessor::CheckSpecialTx(const CTransaction& tx, const CBlockIndex* pindexPrev, const CCoinsViewCache& view, bool check_sigs, TxValidationState& state) { AssertLockHeld(cs_main); - return CheckSpecialTxInner(m_dmnman, tx, pindexPrev, view, std::nullopt, check_sigs, state); + return CheckSpecialTxInner(m_dmnman, m_qman, tx, pindexPrev, view, std::nullopt, check_sigs, state); } [[nodiscard]] bool CSpecialTxProcessor::ProcessSpecialTx(const CTransaction& tx, const CBlockIndex* pindex, TxValidationState& state) @@ -154,7 +155,7 @@ bool CSpecialTxProcessor::ProcessSpecialTxsInBlock(const CBlock& block, const CB TxValidationState tx_state; // At this moment CheckSpecialTx() and ProcessSpecialTx() may fail by 2 possible ways: // consensus failures and "TX_BAD_SPECIAL" - if (!CheckSpecialTxInner(m_dmnman, *ptr_tx, pindex->pprev, view, creditPool.indexes, fCheckCbTxMerkleRoots, tx_state)) { + if (!CheckSpecialTxInner(m_dmnman, m_qman, *ptr_tx, pindex->pprev, view, creditPool.indexes, fCheckCbTxMerkleRoots, tx_state)) { assert(tx_state.GetResult() == TxValidationResult::TX_CONSENSUS || tx_state.GetResult() == TxValidationResult::TX_BAD_SPECIAL); return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, tx_state.GetRejectReason(), strprintf("Special Transaction check failed (tx hash %s) %s", ptr_tx->GetHash().ToString(), tx_state.GetDebugMessage())); diff --git a/src/evo/specialtxman.h b/src/evo/specialtxman.h index f8464fc64e..cddc978961 100644 --- a/src/evo/specialtxman.h +++ b/src/evo/specialtxman.h @@ -24,6 +24,7 @@ struct MNListUpdates; namespace Consensus { struct Params; } namespace llmq { class CQuorumBlockProcessor; +class CQuorumManager; class CChainLocksHandler; } // namespace llmq @@ -38,6 +39,7 @@ private: llmq::CQuorumBlockProcessor& m_qblockman; const Consensus::Params& m_consensus_params; const llmq::CChainLocksHandler& m_clhandler; + const llmq::CQuorumManager& m_qman; private: [[nodiscard]] bool ProcessSpecialTx(const CTransaction& tx, const CBlockIndex* pindex, TxValidationState& state); @@ -45,8 +47,9 @@ private: public: explicit CSpecialTxProcessor(CCreditPoolManager& cpoolman, CDeterministicMNManager& dmnman, CMNHFManager& mnhfman, llmq::CQuorumBlockProcessor& qblockman, - const Consensus::Params& consensus_params, const llmq::CChainLocksHandler& clhandler) : - m_cpoolman(cpoolman), m_dmnman{dmnman}, m_mnhfman{mnhfman}, m_qblockman{qblockman}, m_consensus_params{consensus_params}, m_clhandler{clhandler} {} + const Consensus::Params& consensus_params, const llmq::CChainLocksHandler& clhandler, const llmq::CQuorumManager& qman) : + m_cpoolman(cpoolman), m_dmnman{dmnman}, m_mnhfman{mnhfman}, m_qblockman{qblockman}, m_consensus_params{consensus_params}, m_clhandler{clhandler}, + m_qman{qman} {} bool CheckSpecialTx(const CTransaction& tx, const CBlockIndex* pindexPrev, const CCoinsViewCache& view, bool check_sigs, TxValidationState& state) EXCLUSIVE_LOCKS_REQUIRED(cs_main); diff --git a/src/init.cpp b/src/init.cpp index 3a83d70086..461b9397e3 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1978,7 +1978,7 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc node.chain_helper.reset(); node.chain_helper = std::make_unique(*node.cpoolman, *node.dmnman, *node.mnhf_manager, *node.govman, *(node.llmq_ctx->quorum_block_processor), - chainparams.GetConsensus(), *node.mn_sync, *node.sporkman, *(node.llmq_ctx->clhandler)); + chainparams.GetConsensus(), *node.mn_sync, *node.sporkman, *(node.llmq_ctx->clhandler), *(node.llmq_ctx->qman)); if (fReset) { pblocktree->WriteReindexing(true); diff --git a/src/test/util/setup_common.cpp b/src/test/util/setup_common.cpp index dfb0068932..6b22c8b5e7 100644 --- a/src/test/util/setup_common.cpp +++ b/src/test/util/setup_common.cpp @@ -120,7 +120,7 @@ void DashTestSetup(NodeContext& node, const CChainParams& chainparams) node.llmq_ctx = std::make_unique(chainstate, *node.connman, *node.dmnman, *node.evodb, *node.mn_metaman, *node.mnhf_manager, *node.sporkman, *node.mempool, /* mn_activeman = */ nullptr, *node.mn_sync, node.peerman, /* unit_tests = */ true, /* wipe = */ false); node.chain_helper = std::make_unique(*node.cpoolman, *node.dmnman, *node.mnhf_manager, *node.govman, *(node.llmq_ctx->quorum_block_processor), - chainparams.GetConsensus(), *node.mn_sync, *node.sporkman, *(node.llmq_ctx->clhandler)); + chainparams.GetConsensus(), *node.mn_sync, *node.sporkman, *(node.llmq_ctx->clhandler), *(node.llmq_ctx->qman)); } void DashTestSetupClose(NodeContext& node)