From 0073b66aaac1ffe91cb33171e8d91e58d3aeafe5 Mon Sep 17 00:00:00 2001 From: Kittywhiskers Van Gogh <63189531+kwvg@users.noreply.github.com> Date: Sat, 5 Oct 2024 05:02:51 +0000 Subject: [PATCH] refactor: migrate some Dash code to use `ChainstateManager::ProcessTransaction` --- src/coinjoin/client.cpp | 14 +++++++------- src/coinjoin/client.h | 17 +++++++++-------- src/coinjoin/coinjoin.cpp | 14 +++++++------- src/coinjoin/coinjoin.h | 6 +++--- src/coinjoin/context.cpp | 6 +++--- src/coinjoin/context.h | 4 ++-- src/coinjoin/server.cpp | 14 +++++++------- src/coinjoin/server.h | 8 ++++---- src/init.cpp | 4 ++-- src/llmq/context.cpp | 19 +++++++++++-------- src/llmq/context.h | 4 ++-- src/llmq/ehf_signals.cpp | 14 ++++++-------- src/llmq/ehf_signals.h | 10 ++++------ src/rpc/coinjoin.cpp | 4 ++-- src/test/util/setup_common.cpp | 4 ++-- 15 files changed, 71 insertions(+), 71 deletions(-) diff --git a/src/coinjoin/client.cpp b/src/coinjoin/client.cpp index 86dce7a10b..c2ed7c0a20 100644 --- a/src/coinjoin/client.cpp +++ b/src/coinjoin/client.cpp @@ -793,7 +793,7 @@ bool CCoinJoinClientManager::CheckAutomaticBackup() // // Passively run mixing in the background to mix funds based on the given configuration. // -bool CCoinJoinClientSession::DoAutomaticDenominating(CChainState& active_chainstate, CConnman& connman, CTxMemPool& mempool, bool fDryRun) +bool CCoinJoinClientSession::DoAutomaticDenominating(ChainstateManager& chainman, CConnman& connman, const CTxMemPool& mempool, bool fDryRun) { if (m_is_masternode) return false; // no client-side mixing on masternodes if (nState != POOL_STATE_IDLE) return false; @@ -946,7 +946,7 @@ bool CCoinJoinClientSession::DoAutomaticDenominating(CChainState& active_chainst return false; } } else { - if (!CoinJoin::IsCollateralValid(active_chainstate, mempool, CTransaction(txMyCollateral))) { + if (!CoinJoin::IsCollateralValid(chainman, mempool, CTransaction(txMyCollateral))) { WalletCJLogPrint(m_wallet, "CCoinJoinClientSession::DoAutomaticDenominating -- invalid collateral, recreating...\n"); if (!CreateCollateralTransaction(txMyCollateral, strReason)) { WalletCJLogPrint(m_wallet, "CCoinJoinClientSession::DoAutomaticDenominating -- create collateral error: %s\n", strReason); @@ -973,7 +973,7 @@ bool CCoinJoinClientSession::DoAutomaticDenominating(CChainState& active_chainst return false; } -bool CCoinJoinClientManager::DoAutomaticDenominating(CChainState& active_chainstate, CConnman& connman, CTxMemPool& mempool, bool fDryRun) +bool CCoinJoinClientManager::DoAutomaticDenominating(ChainstateManager& chainman, CConnman& connman, const CTxMemPool& mempool, bool fDryRun) { if (m_is_masternode) return false; // no client-side mixing on masternodes if (!CCoinJoinClientOptions::IsEnabled() || !IsMixing()) return false; @@ -1016,7 +1016,7 @@ bool CCoinJoinClientManager::DoAutomaticDenominating(CChainState& active_chainst return false; } - fResult &= session.DoAutomaticDenominating(active_chainstate, connman, mempool, fDryRun); + fResult &= session.DoAutomaticDenominating(chainman, connman, mempool, fDryRun); } return fResult; @@ -1864,7 +1864,7 @@ void CCoinJoinClientQueueManager::DoMaintenance() CheckQueue(); } -void CCoinJoinClientManager::DoMaintenance(CChainState& active_chainstate, CConnman& connman, CTxMemPool& mempool) +void CCoinJoinClientManager::DoMaintenance(ChainstateManager& chainman, CConnman& connman, const CTxMemPool& mempool) { if (!CCoinJoinClientOptions::IsEnabled()) return; if (m_is_masternode) return; // no client-side mixing on masternodes @@ -1878,7 +1878,7 @@ void CCoinJoinClientManager::DoMaintenance(CChainState& active_chainstate, CConn CheckTimeout(); ProcessPendingDsaRequest(connman); if (nDoAutoNextRun == nTick) { - DoAutomaticDenominating(active_chainstate, connman, mempool); + DoAutomaticDenominating(chainman, connman, mempool); nDoAutoNextRun = nTick + COINJOIN_AUTO_TIMEOUT_MIN + GetRandInt(COINJOIN_AUTO_TIMEOUT_MAX - COINJOIN_AUTO_TIMEOUT_MIN); } } @@ -1930,7 +1930,7 @@ void CoinJoinWalletManager::DoMaintenance() { LOCK(cs_wallet_manager_map); for (auto& [_, clientman] : m_wallet_manager_map) { - clientman->DoMaintenance(m_chainstate, m_connman, m_mempool); + clientman->DoMaintenance(m_chainman, m_connman, m_mempool); } } diff --git a/src/coinjoin/client.h b/src/coinjoin/client.h index 5a615a6ce9..2002f566d1 100644 --- a/src/coinjoin/client.h +++ b/src/coinjoin/client.h @@ -22,9 +22,10 @@ class CCoinJoinClientQueueManager; class CConnman; class CDeterministicMN; class CDeterministicMNManager; -class CNode; +class ChainstateManager; class CMasternodeMetaMan; class CMasternodeSync; +class CNode; class CoinJoinWalletManager; class CTxMemPool; @@ -74,9 +75,9 @@ public: using wallet_name_cjman_map = std::map>; public: - CoinJoinWalletManager(CChainState& chainstate, CConnman& connman, CDeterministicMNManager& dmnman, CMasternodeMetaMan& mn_metaman, CTxMemPool& mempool, + CoinJoinWalletManager(ChainstateManager& chainman, CConnman& connman, CDeterministicMNManager& dmnman, CMasternodeMetaMan& mn_metaman, const CTxMemPool& mempool, const CMasternodeSync& mn_sync, const std::unique_ptr& queueman, bool is_masternode) - : m_chainstate(chainstate), m_connman(connman), m_dmnman(dmnman), m_mn_metaman(mn_metaman), m_mempool(mempool), m_mn_sync(mn_sync), + : m_chainman(chainman), m_connman(connman), m_dmnman(dmnman), m_mn_metaman(mn_metaman), m_mempool(mempool), m_mn_sync(mn_sync), m_queueman(queueman), m_is_masternode{is_masternode} {} @@ -112,11 +113,11 @@ public: }; private: - CChainState& m_chainstate; + ChainstateManager& m_chainman; CConnman& m_connman; CDeterministicMNManager& m_dmnman; CMasternodeMetaMan& m_mn_metaman; - CTxMemPool& m_mempool; + const CTxMemPool& m_mempool; const CMasternodeSync& m_mn_sync; const std::unique_ptr& m_queueman; @@ -202,7 +203,7 @@ public: bool GetMixingMasternodeInfo(CDeterministicMNCPtr& ret) const; /// Passively run mixing in the background according to the configuration in settings - bool DoAutomaticDenominating(CChainState& active_chainstate, CConnman& connman, CTxMemPool& mempool, bool fDryRun = false) EXCLUSIVE_LOCKS_REQUIRED(!cs_coinjoin); + bool DoAutomaticDenominating(ChainstateManager& chainman, CConnman& connman, const CTxMemPool& mempool, bool fDryRun = false) EXCLUSIVE_LOCKS_REQUIRED(!cs_coinjoin); /// As a client, submit part of a future mixing transaction to a Masternode to start the process bool SubmitDenominate(CConnman& connman); @@ -310,7 +311,7 @@ public: bool GetMixingMasternodesInfo(std::vector& vecDmnsRet) const EXCLUSIVE_LOCKS_REQUIRED(!cs_deqsessions); /// Passively run mixing in the background according to the configuration in settings - bool DoAutomaticDenominating(CChainState& active_chainstate, CConnman& connman, CTxMemPool& mempool, bool fDryRun = false) EXCLUSIVE_LOCKS_REQUIRED(!cs_deqsessions); + bool DoAutomaticDenominating(ChainstateManager& chainman, CConnman& connman, const CTxMemPool& mempool, bool fDryRun = false) EXCLUSIVE_LOCKS_REQUIRED(!cs_deqsessions); bool TrySubmitDenominate(const CService& mnAddr, CConnman& connman) EXCLUSIVE_LOCKS_REQUIRED(!cs_deqsessions); bool MarkAlreadyJoinedQueueAsTried(CCoinJoinQueue& dsq) const EXCLUSIVE_LOCKS_REQUIRED(!cs_deqsessions); @@ -326,7 +327,7 @@ public: void UpdatedBlockTip(const CBlockIndex* pindex); - void DoMaintenance(CChainState& active_chainstate, CConnman& connman, CTxMemPool& mempool) EXCLUSIVE_LOCKS_REQUIRED(!cs_deqsessions); + void DoMaintenance(ChainstateManager& chainman, CConnman& connman, const CTxMemPool& mempool) EXCLUSIVE_LOCKS_REQUIRED(!cs_deqsessions); void GetJsonInfo(UniValue& obj) const EXCLUSIVE_LOCKS_REQUIRED(!cs_deqsessions); }; diff --git a/src/coinjoin/coinjoin.cpp b/src/coinjoin/coinjoin.cpp index c081df9286..bc6a65e994 100644 --- a/src/coinjoin/coinjoin.cpp +++ b/src/coinjoin/coinjoin.cpp @@ -308,10 +308,10 @@ bool CCoinJoinBaseSession::IsValidInOuts(CChainState& active_chainstate, const C // Responsibility for checking fee sanity is moved from the mempool to the client (BroadcastTransaction) // but CoinJoin still requires ATMP with fee sanity checks so we need to implement them separately -bool ATMPIfSaneFee(CChainState& active_chainstate, CTxMemPool& pool, const CTransactionRef &tx, bool test_accept) { +bool ATMPIfSaneFee(ChainstateManager& chainman, const CTransactionRef &tx, bool test_accept) { AssertLockHeld(cs_main); - const MempoolAcceptResult result = AcceptToMemoryPool(active_chainstate, pool, tx, /* bypass_limits */ false, /* test_accept */ true); + const MempoolAcceptResult result = chainman.ProcessTransaction(tx, /*test_accept=*/true); if (result.m_result_type != MempoolAcceptResult::ResultType::VALID) { /* Fetch fee and fast-fail if ATMP fails regardless */ return false; @@ -322,11 +322,11 @@ bool ATMPIfSaneFee(CChainState& active_chainstate, CTxMemPool& pool, const CTran /* Don't re-run ATMP if only doing test run */ return true; } - return AcceptToMemoryPool(active_chainstate, pool, tx, /* bypass_limits */ false, test_accept).m_result_type == MempoolAcceptResult::ResultType::VALID; + return chainman.ProcessTransaction(tx, test_accept).m_result_type == MempoolAcceptResult::ResultType::VALID; } // check to make sure the collateral provided by the client is valid -bool CoinJoin::IsCollateralValid(CChainState& active_chainstate, CTxMemPool& mempool, const CTransaction& txCollateral) +bool CoinJoin::IsCollateralValid(ChainstateManager& chainman, const CTxMemPool& mempool, const CTransaction& txCollateral) { if (txCollateral.vout.empty()) return false; if (txCollateral.nLockTime != 0) return false; @@ -352,7 +352,7 @@ bool CoinJoin::IsCollateralValid(CChainState& active_chainstate, CTxMemPool& mem return false; } nValueIn += mempoolTx->vout[txin.prevout.n].nValue; - } else if (GetUTXOCoin(active_chainstate, txin.prevout, coin)) { + } else if (GetUTXOCoin(chainman.ActiveChainstate(), txin.prevout, coin)) { nValueIn += coin.out.nValue; } else { LogPrint(BCLog::COINJOIN, "CoinJoin::IsCollateralValid -- Unknown inputs in collateral transaction, txCollateral=%s", txCollateral.ToString()); /* Continued */ @@ -370,8 +370,8 @@ bool CoinJoin::IsCollateralValid(CChainState& active_chainstate, CTxMemPool& mem { LOCK(cs_main); - if (!ATMPIfSaneFee(active_chainstate, mempool, MakeTransactionRef(txCollateral), /*test_accept=*/true)) { - LogPrint(BCLog::COINJOIN, "CoinJoin::IsCollateralValid -- didn't pass AcceptToMemoryPool()\n"); + if (!ATMPIfSaneFee(chainman, MakeTransactionRef(txCollateral), /*test_accept=*/true)) { + LogPrint(BCLog::COINJOIN, "CoinJoin::IsCollateralValid -- didn't pass ATMPIfSaneFee()\n"); return false; } } diff --git a/src/coinjoin/coinjoin.h b/src/coinjoin/coinjoin.h index 8bbab7a4e5..1e36f24207 100644 --- a/src/coinjoin/coinjoin.h +++ b/src/coinjoin/coinjoin.h @@ -27,6 +27,7 @@ class CChainState; class CConnman; class CBLSPublicKey; class CBlockIndex; +class ChainstateManager; class CMasternodeSync; class CTxMemPool; class TxValidationState; @@ -368,7 +369,7 @@ namespace CoinJoin constexpr CAmount GetMaxPoolAmount() { return COINJOIN_ENTRY_MAX_SIZE * vecStandardDenominations.front(); } /// If the collateral is valid given by a client - bool IsCollateralValid(CChainState& active_chainstate, CTxMemPool& mempool, const CTransaction& txCollateral); + bool IsCollateralValid(ChainstateManager& chainman, const CTxMemPool& mempool, const CTransaction& txCollateral); } @@ -402,7 +403,6 @@ private: }; -bool ATMPIfSaneFee(CChainState& active_chainstate, CTxMemPool& pool, - const CTransactionRef &tx, bool test_accept = false) EXCLUSIVE_LOCKS_REQUIRED(cs_main); +bool ATMPIfSaneFee(ChainstateManager& chainman, const CTransactionRef &tx, bool test_accept = false) EXCLUSIVE_LOCKS_REQUIRED(cs_main); #endif // BITCOIN_COINJOIN_COINJOIN_H diff --git a/src/coinjoin/context.cpp b/src/coinjoin/context.cpp index 6e3beb7980..c4aa025804 100644 --- a/src/coinjoin/context.cpp +++ b/src/coinjoin/context.cpp @@ -9,20 +9,20 @@ #endif // ENABLE_WALLET #include -CJContext::CJContext(CChainState& chainstate, CConnman& connman, CDeterministicMNManager& dmnman, +CJContext::CJContext(ChainstateManager& chainman, CConnman& connman, CDeterministicMNManager& dmnman, CMasternodeMetaMan& mn_metaman, CTxMemPool& mempool, const CActiveMasternodeManager* const mn_activeman, const CMasternodeSync& mn_sync, std::unique_ptr& peerman, bool relay_txes) : dstxman{std::make_unique()}, #ifdef ENABLE_WALLET - walletman{std::make_unique(chainstate, connman, dmnman, mn_metaman, mempool, mn_sync, + walletman{std::make_unique(chainman, connman, dmnman, mn_metaman, mempool, mn_sync, queueman, /* is_masternode = */ mn_activeman != nullptr)}, queueman{relay_txes ? std::make_unique(connman, peerman, *walletman, dmnman, mn_metaman, mn_sync, /* is_masternode = */ mn_activeman != nullptr) : nullptr}, #endif // ENABLE_WALLET - server{std::make_unique(chainstate, connman, dmnman, *dstxman, mn_metaman, mempool, mn_activeman, + server{std::make_unique(chainman, connman, dmnman, *dstxman, mn_metaman, mempool, mn_activeman, mn_sync, peerman)} {} diff --git a/src/coinjoin/context.h b/src/coinjoin/context.h index 08cb67801b..b4e8c6a47f 100644 --- a/src/coinjoin/context.h +++ b/src/coinjoin/context.h @@ -13,11 +13,11 @@ class CActiveMasternodeManager; class CBlockPolicyEstimator; -class CChainState; class CCoinJoinServer; class CConnman; class CDeterministicMNManager; class CDSTXManager; +class ChainstateManager; class CMasternodeMetaMan; class CMasternodeSync; class CTxMemPool; @@ -31,7 +31,7 @@ class CoinJoinWalletManager; struct CJContext { CJContext() = delete; CJContext(const CJContext&) = delete; - CJContext(CChainState& chainstate, CConnman& connman, CDeterministicMNManager& dmnman, + CJContext(ChainstateManager& chainman, CConnman& connman, CDeterministicMNManager& dmnman, CMasternodeMetaMan& mn_metaman, CTxMemPool& mempool, const CActiveMasternodeManager* const mn_activeman, const CMasternodeSync& mn_sync, std::unique_ptr& peerman, bool relay_txes); ~CJContext(); diff --git a/src/coinjoin/server.cpp b/src/coinjoin/server.cpp index 0f34255321..856cf5fc7e 100644 --- a/src/coinjoin/server.cpp +++ b/src/coinjoin/server.cpp @@ -331,8 +331,8 @@ void CCoinJoinServer::CommitFinalTransaction() // See if the transaction is valid TRY_LOCK(cs_main, lockMain); mempool.PrioritiseTransaction(hashTx, 0.1 * COIN); - if (!lockMain || !ATMPIfSaneFee(m_chainstate, mempool, finalTransaction)) { - LogPrint(BCLog::COINJOIN, "CCoinJoinServer::CommitFinalTransaction -- AcceptToMemoryPool() error: Transaction not valid\n"); + if (!lockMain || !ATMPIfSaneFee(m_chainman, finalTransaction)) { + LogPrint(BCLog::COINJOIN, "CCoinJoinServer::CommitFinalTransaction -- ATMPIfSaneFee() error: Transaction not valid\n"); WITH_LOCK(cs_coinjoin, SetNull()); // not much we can do in this case, just notify clients RelayCompletedTransaction(ERR_INVALID_TX); @@ -463,8 +463,8 @@ void CCoinJoinServer::ChargeRandomFees() const void CCoinJoinServer::ConsumeCollateral(const CTransactionRef& txref) const { LOCK(cs_main); - if (!ATMPIfSaneFee(m_chainstate, mempool, txref, false /* bypass_limits */)) { - LogPrint(BCLog::COINJOIN, "%s -- AcceptToMemoryPool failed\n", __func__); + if (!ATMPIfSaneFee(m_chainman, txref)) { + LogPrint(BCLog::COINJOIN, "%s -- ATMPIfSaneFee failed\n", __func__); } else { Assert(m_peerman)->RelayTransaction(txref->GetHash()); LogPrint(BCLog::COINJOIN, "%s -- Collateral was consumed\n", __func__); @@ -582,7 +582,7 @@ bool CCoinJoinServer::AddEntry(const CCoinJoinEntry& entry, PoolMessage& nMessag return false; } - if (!CoinJoin::IsCollateralValid(m_chainstate, mempool, *entry.txCollateral)) { + if (!CoinJoin::IsCollateralValid(m_chainman, mempool, *entry.txCollateral)) { LogPrint(BCLog::COINJOIN, "CCoinJoinServer::%s -- ERROR: collateral not valid!\n", __func__); nMessageIDRet = ERR_INVALID_COLLATERAL; return false; @@ -616,7 +616,7 @@ bool CCoinJoinServer::AddEntry(const CCoinJoinEntry& entry, PoolMessage& nMessag } bool fConsumeCollateral{false}; - if (!IsValidInOuts(m_chainstate, mempool, vin, entry.vecTxOut, nMessageIDRet, &fConsumeCollateral)) { + if (!IsValidInOuts(m_chainman.ActiveChainstate(), mempool, vin, entry.vecTxOut, nMessageIDRet, &fConsumeCollateral)) { LogPrint(BCLog::COINJOIN, "CCoinJoinServer::%s -- ERROR! IsValidInOuts() failed: %s\n", __func__, CoinJoin::GetMessageByID(nMessageIDRet).translated); if (fConsumeCollateral) { ConsumeCollateral(entry.txCollateral); @@ -693,7 +693,7 @@ bool CCoinJoinServer::IsAcceptableDSA(const CCoinJoinAccept& dsa, PoolMessage& n } // check collateral - if (!fUnitTest && !CoinJoin::IsCollateralValid(m_chainstate, mempool, CTransaction(dsa.txCollateral))) { + if (!fUnitTest && !CoinJoin::IsCollateralValid(m_chainman, mempool, CTransaction(dsa.txCollateral))) { LogPrint(BCLog::COINJOIN, "CCoinJoinServer::%s -- collateral not valid!\n", __func__); nMessageIDRet = ERR_INVALID_COLLATERAL; return false; diff --git a/src/coinjoin/server.h b/src/coinjoin/server.h index 5f528a2bfb..43530ff601 100644 --- a/src/coinjoin/server.h +++ b/src/coinjoin/server.h @@ -10,11 +10,11 @@ #include class CActiveMasternodeManager; -class CChainState; class CCoinJoinServer; class CDataStream; class CDeterministicMNManager; class CDSTXManager; +class ChainstateManager; class CMasternodeMetaMan; class CNode; class CTxMemPool; @@ -27,7 +27,7 @@ class UniValue; class CCoinJoinServer : public CCoinJoinBaseSession, public CCoinJoinBaseManager { private: - CChainState& m_chainstate; + ChainstateManager& m_chainman; CConnman& connman; CDeterministicMNManager& m_dmnman; CDSTXManager& m_dstxman; @@ -90,11 +90,11 @@ private: void SetNull() override EXCLUSIVE_LOCKS_REQUIRED(cs_coinjoin); public: - explicit CCoinJoinServer(CChainState& chainstate, CConnman& _connman, CDeterministicMNManager& dmnman, + explicit CCoinJoinServer(ChainstateManager& chainman, CConnman& _connman, CDeterministicMNManager& dmnman, CDSTXManager& dstxman, CMasternodeMetaMan& mn_metaman, CTxMemPool& mempool, const CActiveMasternodeManager* const mn_activeman, const CMasternodeSync& mn_sync, std::unique_ptr& peerman) : - m_chainstate(chainstate), + m_chainman(chainman), connman(_connman), m_dmnman(dmnman), m_dstxman(dstxman), diff --git a/src/init.cpp b/src/init.cpp index 86429fe62b..d974c39be2 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1891,7 +1891,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info) node.llmq_ctx->Stop(); } node.llmq_ctx.reset(); - node.llmq_ctx = std::make_unique(chainman.ActiveChainstate(), *node.connman, *node.dmnman, *node.evodb, *node.mn_metaman, *node.mnhf_manager, *node.sporkman, + node.llmq_ctx = std::make_unique(chainman, *node.connman, *node.dmnman, *node.evodb, *node.mn_metaman, *node.mnhf_manager, *node.sporkman, *node.mempool, node.mn_activeman.get(), *node.mn_sync, node.peerman, /* unit_tests = */ false, /* wipe = */ fReset || fReindexChainState); // Enable CMNHFManager::{Process, Undo}Block node.mnhf_manager->ConnectManagers(node.chainman.get(), node.llmq_ctx->qman.get()); @@ -2153,7 +2153,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info) // ********************************************************* Step 7c: Setup CoinJoin - node.cj_ctx = std::make_unique(chainman.ActiveChainstate(), *node.connman, *node.dmnman, *node.mn_metaman, *node.mempool, + node.cj_ctx = std::make_unique(chainman, *node.connman, *node.dmnman, *node.mn_metaman, *node.mempool, node.mn_activeman.get(), *node.mn_sync, node.peerman, !ignores_incoming_txs); #ifdef ENABLE_WALLET diff --git a/src/llmq/context.cpp b/src/llmq/context.cpp index 2c6c11446e..30e3d45187 100644 --- a/src/llmq/context.cpp +++ b/src/llmq/context.cpp @@ -5,6 +5,7 @@ #include #include +#include #include #include @@ -17,7 +18,7 @@ #include #include -LLMQContext::LLMQContext(CChainState& chainstate, CConnman& connman, CDeterministicMNManager& dmnman, CEvoDB& evo_db, +LLMQContext::LLMQContext(ChainstateManager& chainman, CConnman& connman, CDeterministicMNManager& dmnman, CEvoDB& evo_db, CMasternodeMetaMan& mn_metaman, CMNHFManager& mnhfman, CSporkManager& sporkman, CTxMemPool& mempool, const CActiveMasternodeManager* const mn_activeman, const CMasternodeSync& mn_sync, const std::unique_ptr& peerman, bool unit_tests, @@ -25,28 +26,30 @@ LLMQContext::LLMQContext(CChainState& chainstate, CConnman& connman, CDeterminis is_masternode{mn_activeman != nullptr}, bls_worker{std::make_shared()}, dkg_debugman{std::make_unique()}, - quorum_block_processor{std::make_unique(chainstate, dmnman, evo_db)}, - qdkgsman{std::make_unique(*bls_worker, chainstate, connman, dmnman, *dkg_debugman, + quorum_block_processor{std::make_unique(chainman.ActiveChainstate(), dmnman, evo_db)}, + qdkgsman{std::make_unique(*bls_worker, chainman.ActiveChainstate(), connman, dmnman, *dkg_debugman, mn_metaman, *quorum_block_processor, mn_activeman, sporkman, peerman, unit_tests, wipe)}, - qman{std::make_unique(*bls_worker, chainstate, connman, dmnman, *qdkgsman, evo_db, + qman{std::make_unique(*bls_worker, chainman.ActiveChainstate(), connman, dmnman, *qdkgsman, evo_db, *quorum_block_processor, mn_activeman, mn_sync, sporkman, unit_tests, wipe)}, - sigman{std::make_unique(connman, mn_activeman, chainstate, *qman, peerman, unit_tests, wipe)}, + sigman{std::make_unique(connman, mn_activeman, chainman.ActiveChainstate(), *qman, peerman, unit_tests, wipe)}, shareman{std::make_unique(connman, *sigman, mn_activeman, *qman, sporkman, peerman)}, clhandler{[&]() -> llmq::CChainLocksHandler* const { assert(llmq::chainLocksHandler == nullptr); - llmq::chainLocksHandler = std::make_unique(chainstate, *qman, *sigman, *shareman, + llmq::chainLocksHandler = std::make_unique(chainman.ActiveChainstate(), *qman, *sigman, *shareman, sporkman, mempool, mn_sync, is_masternode); return llmq::chainLocksHandler.get(); }()}, isman{[&]() -> llmq::CInstantSendManager* const { assert(llmq::quorumInstantSendManager == nullptr); - llmq::quorumInstantSendManager = std::make_unique(*llmq::chainLocksHandler, chainstate, connman, *qman, *sigman, *shareman, sporkman, mempool, mn_sync, peerman, is_masternode, unit_tests, wipe); + llmq::quorumInstantSendManager = std::make_unique( + *llmq::chainLocksHandler, chainman.ActiveChainstate(), connman, *qman, *sigman, *shareman, sporkman, + mempool, mn_sync, peerman, is_masternode, unit_tests, wipe); return llmq::quorumInstantSendManager.get(); }()}, ehfSignalsHandler{ - std::make_unique(chainstate, mnhfman, *sigman, *shareman, mempool, *qman)} + std::make_unique(chainman, mnhfman, *sigman, *shareman, *qman)} { } diff --git a/src/llmq/context.h b/src/llmq/context.h index 7d41111c4a..a42d748621 100644 --- a/src/llmq/context.h +++ b/src/llmq/context.h @@ -9,8 +9,8 @@ class CActiveMasternodeManager; class CBLSWorker; -class CChainState; class CConnman; +class ChainstateManager; class CDeterministicMNManager; class CDBWrapper; class CEvoDB; @@ -40,7 +40,7 @@ private: public: LLMQContext() = delete; LLMQContext(const LLMQContext&) = delete; - LLMQContext(CChainState& chainstate, CConnman& connman, CDeterministicMNManager& dmnman, CEvoDB& evo_db, + LLMQContext(ChainstateManager& chainman, CConnman& connman, CDeterministicMNManager& dmnman, CEvoDB& evo_db, CMasternodeMetaMan& mn_metaman, CMNHFManager& mnhfman, CSporkManager& sporkman, CTxMemPool& mempool, const CActiveMasternodeManager* const mn_activeman, const CMasternodeSync& mn_sync, const std::unique_ptr& peerman, bool unit_tests, bool wipe); diff --git a/src/llmq/ehf_signals.cpp b/src/llmq/ehf_signals.cpp index 3ea7bf8677..c5388e46dd 100644 --- a/src/llmq/ehf_signals.cpp +++ b/src/llmq/ehf_signals.cpp @@ -15,19 +15,17 @@ #include #include // g_txindex #include -#include #include namespace llmq { -CEHFSignalsHandler::CEHFSignalsHandler(CChainState& chainstate, CMNHFManager& mnhfman, CSigningManager& sigman, - CSigSharesManager& shareman, CTxMemPool& mempool, const CQuorumManager& qman) : - chainstate(chainstate), +CEHFSignalsHandler::CEHFSignalsHandler(ChainstateManager& chainman, CMNHFManager& mnhfman, CSigningManager& sigman, + CSigSharesManager& shareman, const CQuorumManager& qman) : + m_chainman(chainman), mnhfman(mnhfman), sigman(sigman), shareman(shareman), - mempool(mempool), qman(qman) { sigman.RegisterRecoveredSigsListener(this); @@ -77,7 +75,7 @@ void CEHFSignalsHandler::trySignEHFSignal(int bit, const CBlockIndex* const pind return; } - const auto quorum = llmq::SelectQuorumForSigning(llmq_params_opt.value(), chainstate.m_chain, qman, requestId); + const auto quorum = llmq::SelectQuorumForSigning(llmq_params_opt.value(), m_chainman.ActiveChain(), qman, requestId); if (!quorum) { LogPrintf("CEHFSignalsHandler::trySignEHFSignal no quorum for id=%s\n", requestId.ToString()); return; @@ -103,7 +101,7 @@ MessageProcessingResult CEHFSignalsHandler::HandleNewRecoveredSig(const CRecover } MessageProcessingResult ret; - const auto ehfSignals = mnhfman.GetSignalsStage(WITH_LOCK(cs_main, return chainstate.m_chain.Tip())); + const auto ehfSignals = mnhfman.GetSignalsStage(WITH_LOCK(cs_main, return m_chainman.ActiveTip())); MNHFTxPayload mnhfPayload; for (const auto& deployment : Params().GetConsensus().vDeployments) { // skip deployments that do not use dip0023 or that have already been mined @@ -126,7 +124,7 @@ MessageProcessingResult CEHFSignalsHandler::HandleNewRecoveredSig(const CRecover CTransactionRef tx_to_sent = MakeTransactionRef(std::move(tx)); LogPrintf("CEHFSignalsHandler::HandleNewRecoveredSig Special EHF TX is created hash=%s\n", tx_to_sent->GetHash().ToString()); LOCK(cs_main); - const MempoolAcceptResult result = AcceptToMemoryPool(chainstate, mempool, tx_to_sent, /* bypass_limits */ false); + const MempoolAcceptResult result = m_chainman.ProcessTransaction(tx_to_sent); if (result.m_result_type == MempoolAcceptResult::ResultType::VALID) { ret.m_transactions.push_back(tx_to_sent->GetHash()); } else { diff --git a/src/llmq/ehf_signals.h b/src/llmq/ehf_signals.h index 41f888d48d..7798180e77 100644 --- a/src/llmq/ehf_signals.h +++ b/src/llmq/ehf_signals.h @@ -10,9 +10,8 @@ #include class CBlockIndex; -class CChainState; +class ChainstateManager; class CMNHFManager; -class CTxMemPool; namespace llmq { @@ -23,11 +22,10 @@ class CSigningManager; class CEHFSignalsHandler : public CRecoveredSigsListener { private: - CChainState& chainstate; + ChainstateManager& m_chainman; CMNHFManager& mnhfman; CSigningManager& sigman; CSigSharesManager& shareman; - CTxMemPool& mempool; const CQuorumManager& qman; /** @@ -36,8 +34,8 @@ private: mutable Mutex cs; std::set ids GUARDED_BY(cs); public: - explicit CEHFSignalsHandler(CChainState& chainstate, CMNHFManager& mnhfman, CSigningManager& sigman, - CSigSharesManager& shareman, CTxMemPool& mempool, const CQuorumManager& qman); + explicit CEHFSignalsHandler(ChainstateManager& chainman, CMNHFManager& mnhfman, CSigningManager& sigman, + CSigSharesManager& shareman, const CQuorumManager& qman); ~CEHFSignalsHandler(); diff --git a/src/rpc/coinjoin.cpp b/src/rpc/coinjoin.cpp index 68210881a7..ccaaa840ec 100644 --- a/src/rpc/coinjoin.cpp +++ b/src/rpc/coinjoin.cpp @@ -134,10 +134,10 @@ static RPCHelpMan coinjoin_start() throw JSONRPCError(RPC_INTERNAL_ERROR, "Mixing has been started already."); } - const ChainstateManager& chainman = EnsureChainman(node); + ChainstateManager& chainman = EnsureChainman(node); CTxMemPool& mempool = EnsureMemPool(node); CConnman& connman = EnsureConnman(node); - bool result = cj_clientman->DoAutomaticDenominating(chainman.ActiveChainstate(), connman, mempool); + bool result = cj_clientman->DoAutomaticDenominating(chainman, connman, mempool); return "Mixing " + (result ? "started successfully" : ("start failed: " + cj_clientman->GetStatuses().original + ", will retry")); }, }; diff --git a/src/test/util/setup_common.cpp b/src/test/util/setup_common.cpp index 30b1f4adbe..9f917bd7ea 100644 --- a/src/test/util/setup_common.cpp +++ b/src/test/util/setup_common.cpp @@ -110,12 +110,12 @@ void DashTestSetup(NodeContext& node, const CChainParams& chainparams) node.dmnman = std::make_unique(chainstate, *node.connman, *node.evodb); node.mempool->ConnectManagers(node.dmnman.get()); - node.cj_ctx = std::make_unique(chainstate, *node.connman, *node.dmnman, *node.mn_metaman, *node.mempool, + node.cj_ctx = std::make_unique(*node.chainman, *node.connman, *node.dmnman, *node.mn_metaman, *node.mempool, /* mn_activeman = */ nullptr, *node.mn_sync, node.peerman, /* relay_txes = */ true); #ifdef ENABLE_WALLET node.coinjoin_loader = interfaces::MakeCoinJoinLoader(*node.cj_ctx->walletman); #endif // ENABLE_WALLET - node.llmq_ctx = std::make_unique(chainstate, *node.connman, *node.dmnman, *node.evodb, *node.mn_metaman, *node.mnhf_manager, *node.sporkman, *node.mempool, + node.llmq_ctx = std::make_unique(*node.chainman, *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); Assert(node.mnhf_manager)->ConnectManagers(node.chainman.get(), node.llmq_ctx->qman.get()); node.chain_helper = std::make_unique(*node.cpoolman, *node.dmnman, *node.mnhf_manager, *node.govman, *(node.llmq_ctx->quorum_block_processor), *node.chainman,