From 86dc99f10d50e24d83d3b15611e921cf4fcb35be Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Mon, 5 Jun 2023 03:26:23 +0700 Subject: [PATCH] refactor: using reference instead reference to unique_ptr with object (#5381) ## Issue being fixed or feature implemented Many objects created and functions called by passing `const std::unique_ptr& obj` instead directly passing `Obj& obj` In some cases it is indeed needed, but in most cases it is just extra complexity that is better to avoid. Motivation: - providing reference to object instead `unique_ptr` is giving warranty that there's no `nullptr` and no need to keep it in mind - value inside unique_ptr by reference can be changed externally and instead `nullptr` it can turn to real object later (or in opposite) - code is shorter but cleaner Based on that this refactoring is useful as it reduces mental load when reading or writing code. `std::unique` should be used ONLY for owning object, but not for passing it everywhere. ## What was done? Replaced most of usages `std::unique_ptr& obj` to `Obj& obj`. Btw, in several cases implementation assumes that object can be nullptr and replacement to reference is not possible. Even using raw pointer is not possible, because the empty std::unique_ptr can be initialized later somewhere in code. For example, in `src/init.cpp` there's called `PeerManager::make` and pass unique_ptr to the `node.llmq_ctx` that would be initialized way later. That is out of scope this PR. List of cases, where reference to `std::unique_ptr` stayed as they are: - `std::unique_ptr& llmq_ctx` in `PeerManagerImpl`, `PeerManager` and `CDSNotificationInterface` - `std::unique_ptr& dmnman` in `CDSNotificationInterface` Also `CChainState` have 3 references to `unique_ptr` that can't be replaced too: - `std::unique_ptr& m_clhandler;` - `std::unique_ptr& m_isman;` - `std::unique_ptr& m_quorum_block_processor;` ## How Has This Been Tested? Run unit/functional tests. ## Breaking Changes No breaking changes, all of these changes - are internal APIs for Dash Core developers only. ## Checklist: - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [x] I have added or updated relevant unit/integration/functional/e2e tests - [x] I have made corresponding changes to the documentation - [x] I have assigned this pull request to a milestone --------- Co-authored-by: UdjinM6 --- src/coinjoin/client.cpp | 20 +++++----- src/coinjoin/client.h | 12 +++--- src/coinjoin/coinjoin.cpp | 8 ++-- src/coinjoin/coinjoin.h | 4 +- src/coinjoin/server.cpp | 4 +- src/coinjoin/server.h | 4 +- src/dsnotificationinterface.cpp | 16 ++++---- src/dsnotificationinterface.h | 12 +++--- src/init.cpp | 10 +++-- src/llmq/chainlocks.cpp | 8 ++-- src/llmq/chainlocks.h | 4 +- src/llmq/context.cpp | 4 +- src/llmq/instantsend.cpp | 8 ++-- src/llmq/instantsend.h | 4 +- src/net_processing.cpp | 8 ++-- src/net_processing.h | 2 +- src/test/util/setup_common.cpp | 6 +-- src/test/validation_chainstate_tests.cpp | 2 +- .../validation_chainstatemanager_tests.cpp | 12 +++--- src/test/validation_flush_tests.cpp | 2 +- src/validation.cpp | 40 +++++++++---------- src/validation.h | 24 +++++------ src/wallet/wallet.cpp | 6 ++- 23 files changed, 111 insertions(+), 109 deletions(-) diff --git a/src/coinjoin/client.cpp b/src/coinjoin/client.cpp index 890dbdef26..d538b277ed 100644 --- a/src/coinjoin/client.cpp +++ b/src/coinjoin/client.cpp @@ -35,7 +35,7 @@ void CCoinJoinClientQueueManager::ProcessMessage(const CNode& peer, PeerManager& { if (fMasternodeMode) return; if (!CCoinJoinClientOptions::IsEnabled()) return; - if (!m_mn_sync->IsBlockchainSynced()) return; + if (!m_mn_sync.IsBlockchainSynced()) return; if (!CheckDiskSpace(GetDataDir())) { LogPrint(BCLog::COINJOIN, "CCoinJoinClientQueueManager::ProcessMessage -- Not enough disk space, disabling CoinJoin.\n"); @@ -134,7 +134,7 @@ void CCoinJoinClientManager::ProcessMessage(CNode& peer, PeerManager& peerman, C { if (fMasternodeMode) return; if (!CCoinJoinClientOptions::IsEnabled()) return; - if (!m_mn_sync->IsBlockchainSynced()) return; + if (!m_mn_sync.IsBlockchainSynced()) return; if (!CheckDiskSpace(GetDataDir())) { ResetPool(); @@ -158,7 +158,7 @@ void CCoinJoinClientSession::ProcessMessage(CNode& peer, PeerManager& peerman, C { if (fMasternodeMode) return; if (!CCoinJoinClientOptions::IsEnabled()) return; - if (!m_mn_sync->IsBlockchainSynced()) return; + if (!m_mn_sync.IsBlockchainSynced()) return; if (msg_type == NetMsgType::DSSTATUSUPDATE) { if (!mixingMasternode) return; @@ -289,7 +289,7 @@ bilingual_str CCoinJoinClientSession::GetStatus(bool fWaitForBlock) const nStatusMessageProgress += 10; std::string strSuffix; - if (fWaitForBlock || !m_mn_sync->IsBlockchainSynced()) { + if (fWaitForBlock || !m_mn_sync.IsBlockchainSynced()) { return strAutoDenomResult; } @@ -691,7 +691,7 @@ void CCoinJoinClientManager::UpdatedSuccessBlock() bool CCoinJoinClientManager::WaitForAnotherBlock() const { - if (!m_mn_sync->IsBlockchainSynced()) return true; + if (!m_mn_sync.IsBlockchainSynced()) return true; if (CCoinJoinClientOptions::IsMultiSessionEnabled()) return false; @@ -773,7 +773,7 @@ bool CCoinJoinClientSession::DoAutomaticDenominating(CConnman& connman, CBlockPo if (fMasternodeMode) return false; // no client-side mixing on masternodes if (nState != POOL_STATE_IDLE) return false; - if (!m_mn_sync->IsBlockchainSynced()) { + if (!m_mn_sync.IsBlockchainSynced()) { strAutoDenomResult = _("Can't mix while sync in progress."); return false; } @@ -953,7 +953,7 @@ bool CCoinJoinClientManager::DoAutomaticDenominating(CConnman& connman, CBlockPo if (fMasternodeMode) return false; // no client-side mixing on masternodes if (!CCoinJoinClientOptions::IsEnabled() || !IsMixing()) return false; - if (!m_mn_sync->IsBlockchainSynced()) { + if (!m_mn_sync.IsBlockchainSynced()) { strAutoDenomResult = _("Can't mix while sync in progress."); return false; } @@ -1819,10 +1819,9 @@ void CCoinJoinClientManager::UpdatedBlockTip(const CBlockIndex* pindex) void CCoinJoinClientQueueManager::DoMaintenance() { if (!CCoinJoinClientOptions::IsEnabled()) return; - if (m_mn_sync == nullptr) return; if (fMasternodeMode) return; // no client-side mixing on masternodes - if (!m_mn_sync->IsBlockchainSynced() || ShutdownRequested()) return; + if (!m_mn_sync.IsBlockchainSynced() || ShutdownRequested()) return; CheckQueue(); } @@ -1830,10 +1829,9 @@ void CCoinJoinClientQueueManager::DoMaintenance() void CCoinJoinClientManager::DoMaintenance(CConnman& connman, CBlockPolicyEstimator& fee_estimator, CTxMemPool& mempool) { if (!CCoinJoinClientOptions::IsEnabled()) return; - if (m_mn_sync == nullptr) return; if (fMasternodeMode) return; // no client-side mixing on masternodes - if (!m_mn_sync->IsBlockchainSynced() || ShutdownRequested()) return; + if (!m_mn_sync.IsBlockchainSynced() || ShutdownRequested()) return; static int nTick = 0; static int nDoAutoNextRun = nTick + COINJOIN_AUTO_TIMEOUT_MIN; diff --git a/src/coinjoin/client.h b/src/coinjoin/client.h index 455e1a4aca..cd5e28317d 100644 --- a/src/coinjoin/client.h +++ b/src/coinjoin/client.h @@ -74,7 +74,7 @@ public: class CCoinJoinClientSession : public CCoinJoinBaseSession { private: - const std::unique_ptr& m_mn_sync; + const CMasternodeSync& m_mn_sync; std::vector vecOutPointLocked; @@ -124,7 +124,7 @@ private: void SetNull() EXCLUSIVE_LOCKS_REQUIRED(cs_coinjoin); public: - explicit CCoinJoinClientSession(CWallet& pwallet, const std::unique_ptr& mn_sync) : + explicit CCoinJoinClientSession(CWallet& pwallet, const CMasternodeSync& mn_sync) : m_mn_sync(mn_sync), mixingWallet(pwallet) { } @@ -158,10 +158,10 @@ class CCoinJoinClientQueueManager : public CCoinJoinBaseManager { private: CConnman& connman; - const std::unique_ptr& m_mn_sync; + const CMasternodeSync& m_mn_sync; public: - explicit CCoinJoinClientQueueManager(CConnman& _connman, const std::unique_ptr& mn_sync) : + explicit CCoinJoinClientQueueManager(CConnman& _connman, const CMasternodeSync& mn_sync) : connman(_connman), m_mn_sync(mn_sync) {}; void ProcessMessage(const CNode& peer, PeerManager& peerman, std::string_view msg_type, CDataStream& vRecv) LOCKS_EXCLUDED(cs_vecqueue); @@ -177,7 +177,7 @@ private: // Keep track of the used Masternodes std::vector vecMasternodesUsed; - const std::unique_ptr& m_mn_sync; + const CMasternodeSync& m_mn_sync; mutable Mutex cs_deqsessions; // TODO: or map ?? @@ -207,7 +207,7 @@ public: CCoinJoinClientManager(CCoinJoinClientManager const&) = delete; CCoinJoinClientManager& operator=(CCoinJoinClientManager const&) = delete; - explicit CCoinJoinClientManager(CWallet& wallet, const std::unique_ptr& mn_sync) : + explicit CCoinJoinClientManager(CWallet& wallet, const CMasternodeSync& mn_sync) : m_mn_sync(mn_sync), mixingWallet(wallet) {} void ProcessMessage(CNode& peer, PeerManager& peerman, CConnman& connman, const CTxMemPool& mempool, std::string_view msg_type, CDataStream& vRecv) LOCKS_EXCLUDED(cs_deqsessions); diff --git a/src/coinjoin/coinjoin.cpp b/src/coinjoin/coinjoin.cpp index 237dfaeb24..9c2489b45a 100644 --- a/src/coinjoin/coinjoin.cpp +++ b/src/coinjoin/coinjoin.cpp @@ -457,16 +457,16 @@ void CCoinJoin::CheckDSTXes(const CBlockIndex* pindex, const llmq::CChainLocksHa LogPrint(BCLog::COINJOIN, "CCoinJoin::CheckDSTXes -- mapDSTX.size()=%llu\n", mapDSTX.size()); } -void CCoinJoin::UpdatedBlockTip(const CBlockIndex* pindex, const llmq::CChainLocksHandler& clhandler, const std::unique_ptr& mn_sync) +void CCoinJoin::UpdatedBlockTip(const CBlockIndex* pindex, const llmq::CChainLocksHandler& clhandler, const CMasternodeSync& mn_sync) { - if (pindex && mn_sync->IsBlockchainSynced()) { + if (pindex && mn_sync.IsBlockchainSynced()) { CheckDSTXes(pindex, clhandler); } } -void CCoinJoin::NotifyChainLock(const CBlockIndex* pindex, const llmq::CChainLocksHandler& clhandler, const std::unique_ptr& mn_sync) +void CCoinJoin::NotifyChainLock(const CBlockIndex* pindex, const llmq::CChainLocksHandler& clhandler, const CMasternodeSync& mn_sync) { - if (pindex && mn_sync->IsBlockchainSynced()) { + if (pindex && mn_sync.IsBlockchainSynced()) { CheckDSTXes(pindex, clhandler); } } diff --git a/src/coinjoin/coinjoin.h b/src/coinjoin/coinjoin.h index 538e7011fa..9aa02ffcf3 100644 --- a/src/coinjoin/coinjoin.h +++ b/src/coinjoin/coinjoin.h @@ -502,8 +502,8 @@ public: static void AddDSTX(const CCoinJoinBroadcastTx& dstx) LOCKS_EXCLUDED(cs_mapdstx); static CCoinJoinBroadcastTx GetDSTX(const uint256& hash) LOCKS_EXCLUDED(cs_mapdstx); - static void UpdatedBlockTip(const CBlockIndex* pindex, const llmq::CChainLocksHandler& clhandler, const std::unique_ptr& mn_sync); - static void NotifyChainLock(const CBlockIndex* pindex, const llmq::CChainLocksHandler& clhandler, const std::unique_ptr& mn_sync); + static void UpdatedBlockTip(const CBlockIndex* pindex, const llmq::CChainLocksHandler& clhandler, const CMasternodeSync& mn_sync); + static void NotifyChainLock(const CBlockIndex* pindex, const llmq::CChainLocksHandler& clhandler, const CMasternodeSync& mn_sync); static void TransactionAddedToMempool(const CTransactionRef& tx) LOCKS_EXCLUDED(cs_mapdstx); static void BlockConnected(const std::shared_ptr& pblock, const CBlockIndex* pindex) LOCKS_EXCLUDED(cs_mapdstx); diff --git a/src/coinjoin/server.cpp b/src/coinjoin/server.cpp index bbd97bb91f..6b94fdea35 100644 --- a/src/coinjoin/server.cpp +++ b/src/coinjoin/server.cpp @@ -29,7 +29,7 @@ constexpr static CAmount DEFAULT_MAX_RAW_TX_FEE{COIN / 10}; void CCoinJoinServer::ProcessMessage(CNode& peer, PeerManager& peerman, std::string_view msg_type, CDataStream& vRecv) { if (!fMasternodeMode) return; - if (!m_mn_sync->IsBlockchainSynced()) return; + if (!m_mn_sync.IsBlockchainSynced()) return; if (msg_type == NetMsgType::DSACCEPT) { ProcessDSACCEPT(peer, vRecv); @@ -889,7 +889,7 @@ void CCoinJoinServer::SetState(PoolState nStateNew) void CCoinJoinServer::DoMaintenance() const { if (!fMasternodeMode) return; // only run on masternodes - if (m_mn_sync == nullptr || !m_mn_sync->IsBlockchainSynced()) return; + if (!m_mn_sync.IsBlockchainSynced()) return; if (ShutdownRequested()) return; if (!coinJoinServer) return; diff --git a/src/coinjoin/server.h b/src/coinjoin/server.h index 6d05a95e7b..183cd3f32e 100644 --- a/src/coinjoin/server.h +++ b/src/coinjoin/server.h @@ -24,7 +24,7 @@ class CCoinJoinServer : public CCoinJoinBaseSession, public CCoinJoinBaseManager private: CTxMemPool& mempool; CConnman& connman; - const std::unique_ptr& m_mn_sync; + const CMasternodeSync& m_mn_sync; // Mixing uses collateral transactions to trust parties entering the pool // to behave honestly. If they don't it takes their money. @@ -79,7 +79,7 @@ private: void SetNull() EXCLUSIVE_LOCKS_REQUIRED(cs_coinjoin); public: - explicit CCoinJoinServer(CTxMemPool& mempool, CConnman& _connman, const std::unique_ptr& mn_sync) : + explicit CCoinJoinServer(CTxMemPool& mempool, CConnman& _connman, const CMasternodeSync& mn_sync) : mempool(mempool), connman(_connman), m_mn_sync(mn_sync), diff --git a/src/dsnotificationinterface.cpp b/src/dsnotificationinterface.cpp index f3e427d7e2..5e1d16635b 100644 --- a/src/dsnotificationinterface.cpp +++ b/src/dsnotificationinterface.cpp @@ -22,8 +22,8 @@ #include CDSNotificationInterface::CDSNotificationInterface(CConnman& _connman, - std::unique_ptr& _mn_sync, std::unique_ptr& _dmnman, - std::unique_ptr& _govman, std::unique_ptr& _llmq_ctx + CMasternodeSync& _mn_sync, const std::unique_ptr& _dmnman, + CGovernanceManager& _govman, const std::unique_ptr& _llmq_ctx ) : connman(_connman), m_mn_sync(_mn_sync), dmnman(_dmnman), govman(_govman), llmq_ctx(_llmq_ctx) {} void CDSNotificationInterface::InitializeCurrentBlockTip() @@ -35,14 +35,12 @@ void CDSNotificationInterface::InitializeCurrentBlockTip() void CDSNotificationInterface::AcceptedBlockHeader(const CBlockIndex *pindexNew) { llmq_ctx->clhandler->AcceptedBlockHeader(pindexNew); - if (m_mn_sync != nullptr) { - m_mn_sync->AcceptedBlockHeader(pindexNew); - } + m_mn_sync.AcceptedBlockHeader(pindexNew); } void CDSNotificationInterface::NotifyHeaderTip(const CBlockIndex *pindexNew, bool fInitialDownload) { - m_mn_sync->NotifyHeaderTip(pindexNew, fInitialDownload); + m_mn_sync.NotifyHeaderTip(pindexNew, fInitialDownload); } void CDSNotificationInterface::SynchronousUpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload) @@ -58,7 +56,7 @@ void CDSNotificationInterface::UpdatedBlockTip(const CBlockIndex *pindexNew, con if (pindexNew == pindexFork) // blocks were disconnected without any new ones return; - m_mn_sync->UpdatedBlockTip(pindexNew, fInitialDownload); + m_mn_sync.UpdatedBlockTip(pindexNew, fInitialDownload); // Update global DIP0001 activation status fDIP0001ActiveAtTip = pindexNew->nHeight >= Params().GetConsensus().DIP0001Height; @@ -79,7 +77,7 @@ void CDSNotificationInterface::UpdatedBlockTip(const CBlockIndex *pindexNew, con llmq_ctx->qman->UpdatedBlockTip(pindexNew, fInitialDownload); llmq_ctx->qdkgsman->UpdatedBlockTip(pindexNew, fInitialDownload); - if (!fDisableGovernance) govman->UpdatedBlockTip(pindexNew, connman); + if (!fDisableGovernance) govman.UpdatedBlockTip(pindexNew, connman); } void CDSNotificationInterface::TransactionAddedToMempool(const CTransactionRef& ptx, int64_t nAcceptTime) @@ -119,7 +117,7 @@ void CDSNotificationInterface::BlockDisconnected(const std::shared_ptrUpdateCachesAndClean(); + govman.UpdateCachesAndClean(); } void CDSNotificationInterface::NotifyChainLock(const CBlockIndex* pindex, const std::shared_ptr& clsig) diff --git a/src/dsnotificationinterface.h b/src/dsnotificationinterface.h index 36dc795f3d..b01bbdac9f 100644 --- a/src/dsnotificationinterface.h +++ b/src/dsnotificationinterface.h @@ -17,8 +17,8 @@ class CDSNotificationInterface : public CValidationInterface { public: explicit CDSNotificationInterface(CConnman& _connman, - std::unique_ptr& _mn_sync, std::unique_ptr& _dmnman, - std::unique_ptr& _govman, std::unique_ptr& _llmq_ctx); + CMasternodeSync& _mn_sync, const std::unique_ptr& _dmnman, + CGovernanceManager& _govman, const std::unique_ptr& _llmq_ctx); virtual ~CDSNotificationInterface() = default; // a small helper to initialize current block height in sub-modules on startup @@ -40,11 +40,11 @@ protected: private: CConnman& connman; - std::unique_ptr& m_mn_sync; - std::unique_ptr& dmnman; - std::unique_ptr& govman; + CMasternodeSync& m_mn_sync; + const std::unique_ptr& dmnman; + CGovernanceManager& govman; - std::unique_ptr& llmq_ctx; + const std::unique_ptr& llmq_ctx; }; #endif // BITCOIN_DSNOTIFICATIONINTERFACE_H diff --git a/src/init.cpp b/src/init.cpp index 417934c26e..7080a40789 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1945,8 +1945,10 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc } #endif + assert(masternodeSync != nullptr); + assert(governance != nullptr); pdsNotificationInterface = new CDSNotificationInterface( - *node.connman, ::masternodeSync, ::deterministicMNManager, ::governance, node.llmq_ctx + *node.connman, *::masternodeSync, ::deterministicMNManager, *::governance, node.llmq_ctx ); RegisterValidationInterface(pdsNotificationInterface); @@ -2021,7 +2023,7 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc LOCK(cs_main); node.evodb.reset(); node.evodb = std::make_unique(nEvoDbCache, false, fReset || fReindexChainState); - chainman.InitializeChainstate(llmq::chainLocksHandler, llmq::quorumInstantSendManager, llmq::quorumBlockProcessor, node.evodb, *Assert(node.mempool)); + chainman.InitializeChainstate(llmq::chainLocksHandler, llmq::quorumInstantSendManager, llmq::quorumBlockProcessor, *node.evodb, *Assert(node.mempool)); chainman.m_total_coinstip_cache = nCoinCacheUsage; chainman.m_total_coinsdb_cache = nCoinDBCache; @@ -2318,10 +2320,10 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc // ********************************************************* Step 10a: Setup CoinJoin - ::coinJoinServer = std::make_unique(*node.mempool, *node.connman, ::masternodeSync); + ::coinJoinServer = std::make_unique(*node.mempool, *node.connman, *::masternodeSync); #ifdef ENABLE_WALLET if (!ignores_incoming_txs) { - ::coinJoinClientQueueManager = std::make_unique(*node.connman, ::masternodeSync); + ::coinJoinClientQueueManager = std::make_unique(*node.connman, *::masternodeSync); } #endif // ENABLE_WALLET diff --git a/src/llmq/chainlocks.cpp b/src/llmq/chainlocks.cpp index e42e3677b4..89a162a524 100644 --- a/src/llmq/chainlocks.cpp +++ b/src/llmq/chainlocks.cpp @@ -25,7 +25,7 @@ std::unique_ptr chainLocksHandler; CChainLocksHandler::CChainLocksHandler(CTxMemPool& _mempool, CConnman& _connman, CSporkManager& sporkManager, CSigningManager& _sigman, CSigSharesManager& _shareman, CQuorumManager& _qman, - const std::unique_ptr& mn_sync, + CMasternodeSync& mn_sync, const std::unique_ptr& peerman) : connman(_connman), mempool(_mempool), @@ -241,7 +241,7 @@ void CChainLocksHandler::TrySignChainTip() return; } - if (!m_mn_sync->IsBlockchainSynced()) { + if (!m_mn_sync.IsBlockchainSynced()) { return; } @@ -361,7 +361,7 @@ void CChainLocksHandler::TransactionAddedToMempool(const CTransactionRef& tx, in void CChainLocksHandler::BlockConnected(const std::shared_ptr& pblock, const CBlockIndex* pindex) { - if (!m_mn_sync->IsBlockchainSynced()) { + if (!m_mn_sync.IsBlockchainSynced()) { return; } @@ -628,7 +628,7 @@ bool CChainLocksHandler::InternalHasConflictingChainLock(int nHeight, const uint void CChainLocksHandler::Cleanup() { - if (!m_mn_sync->IsBlockchainSynced()) { + if (!m_mn_sync.IsBlockchainSynced()) { return; } diff --git a/src/llmq/chainlocks.h b/src/llmq/chainlocks.h index 7f9422a78b..b52493f172 100644 --- a/src/llmq/chainlocks.h +++ b/src/llmq/chainlocks.h @@ -49,7 +49,7 @@ private: CSigSharesManager& shareman; CQuorumManager& qman; - const std::unique_ptr& m_mn_sync; + CMasternodeSync& m_mn_sync; const std::unique_ptr& m_peerman; std::unique_ptr scheduler; @@ -86,7 +86,7 @@ private: public: explicit CChainLocksHandler(CTxMemPool& _mempool, CConnman& _connman, CSporkManager& sporkManager, CSigningManager& _sigman, CSigSharesManager& _shareman, CQuorumManager& _qman, - const std::unique_ptr& mn_sync, + CMasternodeSync& mn_sync, const std::unique_ptr& peerman); ~CChainLocksHandler(); diff --git a/src/llmq/context.cpp b/src/llmq/context.cpp index f2fc033f79..6470afc1a8 100644 --- a/src/llmq/context.cpp +++ b/src/llmq/context.cpp @@ -49,8 +49,8 @@ void LLMQContext::Create(CEvoDB& evo_db, CTxMemPool& mempool, CConnman& connman, llmq::quorumManager = std::make_unique(evo_db, connman, *bls_worker, *llmq::quorumBlockProcessor, *qdkgsman, ::masternodeSync, peerman); sigman = std::make_unique(connman, *llmq::quorumManager, peerman, unit_tests, wipe); shareman = std::make_unique(connman, *llmq::quorumManager, *sigman, peerman); - llmq::chainLocksHandler = std::make_unique(mempool, connman, sporkman, *sigman, *shareman, *llmq::quorumManager, ::masternodeSync, peerman); - llmq::quorumInstantSendManager = std::make_unique(mempool, connman, sporkman, *llmq::quorumManager, *sigman, *shareman, *llmq::chainLocksHandler, ::masternodeSync, peerman, unit_tests, wipe); + llmq::chainLocksHandler = std::make_unique(mempool, connman, sporkman, *sigman, *shareman, *llmq::quorumManager, *::masternodeSync, peerman); + llmq::quorumInstantSendManager = std::make_unique(mempool, connman, sporkman, *llmq::quorumManager, *sigman, *shareman, *llmq::chainLocksHandler, *::masternodeSync, peerman, unit_tests, wipe); // NOTE: we use this only to wipe the old db, do NOT use it for anything else // TODO: remove it in some future version diff --git a/src/llmq/instantsend.cpp b/src/llmq/instantsend.cpp index e10d0a318c..c745b63244 100644 --- a/src/llmq/instantsend.cpp +++ b/src/llmq/instantsend.cpp @@ -480,7 +480,7 @@ void CInstantSendManager::Stop() void CInstantSendManager::ProcessTx(const CTransaction& tx, bool fRetroactive, const Consensus::Params& params) { - if (!fMasternodeMode || !IsInstantSendEnabled() || !m_mn_sync->IsBlockchainSynced()) { + if (!fMasternodeMode || !IsInstantSendEnabled() || !m_mn_sync.IsBlockchainSynced()) { return; } @@ -1138,7 +1138,7 @@ void CInstantSendManager::ProcessInstantSendLock(NodeId from, const uint256& has void CInstantSendManager::TransactionAddedToMempool(const CTransactionRef& tx) { - if (!IsInstantSendEnabled() || !m_mn_sync->IsBlockchainSynced() || tx->vin.empty()) { + if (!IsInstantSendEnabled() || !m_mn_sync.IsBlockchainSynced() || tx->vin.empty()) { return; } @@ -1191,7 +1191,7 @@ void CInstantSendManager::BlockConnected(const std::shared_ptr& pb return; } - if (m_mn_sync->IsBlockchainSynced()) { + if (m_mn_sync.IsBlockchainSynced()) { for (const auto& tx : pblock->vtx) { if (tx->IsCoinBase() || tx->vin.empty()) { // coinbase and TXs with no inputs can't be locked @@ -1738,7 +1738,7 @@ bool CInstantSendManager::IsInstantSendMempoolSigningEnabled() const bool CInstantSendManager::RejectConflictingBlocks() const { - if (m_mn_sync == nullptr || !m_mn_sync->IsBlockchainSynced()) { + if (!m_mn_sync.IsBlockchainSynced()) { return false; } if (!spork_manager.IsSporkActive(SPORK_3_INSTANTSEND_BLOCK_FILTERING)) { diff --git a/src/llmq/instantsend.h b/src/llmq/instantsend.h index dda6e535c4..01640b15d3 100644 --- a/src/llmq/instantsend.h +++ b/src/llmq/instantsend.h @@ -211,7 +211,7 @@ private: CSigSharesManager& shareman; CChainLocksHandler& clhandler; - const std::unique_ptr& m_mn_sync; + const CMasternodeSync& m_mn_sync; const std::unique_ptr& m_peerman; std::atomic fUpgradedDB{false}; @@ -262,7 +262,7 @@ private: public: explicit CInstantSendManager(CTxMemPool& _mempool, CConnman& _connman, CSporkManager& sporkManager, CQuorumManager& _qman, CSigningManager& _sigman, CSigSharesManager& _shareman, - CChainLocksHandler& _clhandler, const std::unique_ptr& mn_sync, + CChainLocksHandler& _clhandler, CMasternodeSync& mn_sync, const std::unique_ptr& peerman, bool unitTests, bool fWipe) : db(unitTests, fWipe), connman(_connman), mempool(_mempool), spork_manager(sporkManager), qman(_qman), sigman(_sigman), shareman(_shareman), clhandler(_clhandler), m_mn_sync(mn_sync), m_peerman(peerman) diff --git a/src/net_processing.cpp b/src/net_processing.cpp index d396f0a578..0b1d7c5f13 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -216,7 +216,7 @@ class PeerManagerImpl final : public PeerManager public: PeerManagerImpl(const CChainParams& chainparams, CConnman& connman, CAddrMan& addrman, BanMan* banman, CScheduler &scheduler, ChainstateManager& chainman, - CTxMemPool& pool, std::unique_ptr& llmq_ctx, bool ignore_incoming_txs); + CTxMemPool& pool, const std::unique_ptr& llmq_ctx, bool ignore_incoming_txs); /** Overridden from CValidationInterface. */ void BlockConnected(const std::shared_ptr& pblock, const CBlockIndex* pindexConnected) override; @@ -305,7 +305,7 @@ private: CAddrMan& m_addrman; ChainstateManager& m_chainman; CTxMemPool& m_mempool; - std::unique_ptr& m_llmq_ctx; + const std::unique_ptr& m_llmq_ctx; /** The height of the best chain */ std::atomic m_best_height{-1}; @@ -1463,14 +1463,14 @@ static bool BlockRequestAllowed(const CBlockIndex* pindex, const Consensus::Para std::unique_ptr PeerManager::make(const CChainParams& chainparams, CConnman& connman, CAddrMan& addrman, BanMan* banman, CScheduler &scheduler, ChainstateManager& chainman, CTxMemPool& pool, - std::unique_ptr& llmq_ctx, bool ignore_incoming_txs) + const std::unique_ptr& llmq_ctx, bool ignore_incoming_txs) { return std::make_unique(chainparams, connman, addrman, banman, scheduler, chainman, pool, llmq_ctx, ignore_incoming_txs); } PeerManagerImpl::PeerManagerImpl(const CChainParams& chainparams, CConnman& connman, CAddrMan& addrman, BanMan* banman, CScheduler &scheduler, ChainstateManager& chainman, CTxMemPool& pool, - std::unique_ptr& llmq_ctx, bool ignore_incoming_txs) + const std::unique_ptr& llmq_ctx, bool ignore_incoming_txs) : m_chainparams(chainparams), m_connman(connman), m_addrman(addrman), diff --git a/src/net_processing.h b/src/net_processing.h index d404095edc..0f9bde911e 100644 --- a/src/net_processing.h +++ b/src/net_processing.h @@ -37,7 +37,7 @@ class PeerManager : public CValidationInterface, public NetEventsInterface public: static std::unique_ptr make(const CChainParams& chainparams, CConnman& connman, CAddrMan& addrman, BanMan* banman, CScheduler &scheduler, ChainstateManager& chainman, - CTxMemPool& pool, std::unique_ptr& llmq_ctx, bool ignore_incoming_txs); + CTxMemPool& pool, const std::unique_ptr& llmq_ctx, bool ignore_incoming_txs); virtual ~PeerManager() { } /** Get statistics from node state */ diff --git a/src/test/util/setup_common.cpp b/src/test/util/setup_common.cpp index e831be0fa1..8d9a33932e 100644 --- a/src/test/util/setup_common.cpp +++ b/src/test/util/setup_common.cpp @@ -180,9 +180,9 @@ ChainTestingSetup::ChainTestingSetup(const std::string& chainName, const std::ve ::sporkManager = std::make_unique(); ::governance = std::make_unique(); ::masternodeSync = std::make_unique(*m_node.connman); - ::coinJoinServer = std::make_unique(*m_node.mempool, *m_node.connman, ::masternodeSync); + ::coinJoinServer = std::make_unique(*m_node.mempool, *m_node.connman, *::masternodeSync); #ifdef ENABLE_WALLET - ::coinJoinClientQueueManager = std::make_unique(*m_node.connman, ::masternodeSync); + ::coinJoinClientQueueManager = std::make_unique(*m_node.connman, *::masternodeSync); #endif // ENABLE_WALLET deterministicMNManager.reset(new CDeterministicMNManager(*m_node.evodb, *m_node.connman)); @@ -231,7 +231,7 @@ TestingSetup::TestingSetup(const std::string& chainName, const std::vectorInitializeChainstate(llmq::chainLocksHandler, llmq::quorumInstantSendManager, llmq::quorumBlockProcessor, m_node.evodb, *m_node.mempool); + m_node.chainman->InitializeChainstate(llmq::chainLocksHandler, llmq::quorumInstantSendManager, llmq::quorumBlockProcessor, *m_node.evodb, *m_node.mempool); ::ChainstateActive().InitCoinsDB( /* cache_size_bytes */ 1 << 23, /* in_memory */ true, /* should_wipe */ false); assert(!::ChainstateActive().CanFlushToDisk()); diff --git a/src/test/validation_chainstate_tests.cpp b/src/test/validation_chainstate_tests.cpp index 5d83f22bda..e6eb56ef83 100644 --- a/src/test/validation_chainstate_tests.cpp +++ b/src/test/validation_chainstate_tests.cpp @@ -40,7 +40,7 @@ BOOST_AUTO_TEST_CASE(validation_chainstate_resize_caches) return outp; }; - CChainState& c1 = *WITH_LOCK(cs_main, return &manager.InitializeChainstate(llmq::chainLocksHandler, llmq::quorumInstantSendManager, llmq::quorumBlockProcessor, m_node.evodb, mempool)); + CChainState& c1 = *WITH_LOCK(cs_main, return &manager.InitializeChainstate(llmq::chainLocksHandler, llmq::quorumInstantSendManager, llmq::quorumBlockProcessor, *m_node.evodb, mempool)); c1.InitCoinsDB( /* cache_size_bytes */ 1 << 23, /* in_memory */ true, /* should_wipe */ false); WITH_LOCK(::cs_main, c1.InitCoinsCache(1 << 23)); diff --git a/src/test/validation_chainstatemanager_tests.cpp b/src/test/validation_chainstatemanager_tests.cpp index 22b97d9e5e..aecc027de3 100644 --- a/src/test/validation_chainstatemanager_tests.cpp +++ b/src/test/validation_chainstatemanager_tests.cpp @@ -28,13 +28,14 @@ BOOST_FIXTURE_TEST_SUITE(validation_chainstatemanager_tests, ChainTestingSetup) BOOST_AUTO_TEST_CASE(chainstatemanager) { ChainstateManager& manager = *m_node.chainman; - CTxMemPool &mempool = *m_node.mempool; + CTxMemPool& mempool = *m_node.mempool; + CEvoDB& evodb = *m_node.evodb; std::vector chainstates; const CChainParams& chainparams = Params(); // Create a legacy (IBD) chainstate. // - CChainState& c1 = *WITH_LOCK(::cs_main, return &manager.InitializeChainstate(llmq::chainLocksHandler, llmq::quorumInstantSendManager, llmq::quorumBlockProcessor, m_node.evodb, mempool)); + CChainState& c1 = *WITH_LOCK(::cs_main, return &manager.InitializeChainstate(llmq::chainLocksHandler, llmq::quorumInstantSendManager, llmq::quorumBlockProcessor, evodb, mempool)); chainstates.push_back(&c1); c1.InitCoinsDB( /* cache_size_bytes */ 1 << 23, /* in_memory */ true, /* should_wipe */ false); @@ -60,7 +61,7 @@ BOOST_AUTO_TEST_CASE(chainstatemanager) // Create a snapshot-based chainstate. // - CChainState& c2 = *WITH_LOCK(::cs_main, return &manager.InitializeChainstate(llmq::chainLocksHandler, llmq::quorumInstantSendManager, llmq::quorumBlockProcessor, m_node.evodb, mempool, GetRandHash())); + CChainState& c2 = *WITH_LOCK(::cs_main, return &manager.InitializeChainstate(llmq::chainLocksHandler, llmq::quorumInstantSendManager, llmq::quorumBlockProcessor, evodb, mempool, GetRandHash())); chainstates.push_back(&c2); c2.InitCoinsDB( /* cache_size_bytes */ 1 << 23, /* in_memory */ true, /* should_wipe */ false); @@ -111,6 +112,7 @@ BOOST_AUTO_TEST_CASE(chainstatemanager_rebalance_caches) { ChainstateManager& manager = *m_node.chainman; CTxMemPool& mempool = *m_node.mempool; + CEvoDB& evodb = *m_node.evodb; size_t max_cache = 10000; manager.m_total_coinsdb_cache = max_cache; manager.m_total_coinstip_cache = max_cache; @@ -119,7 +121,7 @@ BOOST_AUTO_TEST_CASE(chainstatemanager_rebalance_caches) // Create a legacy (IBD) chainstate. // - CChainState& c1 = *WITH_LOCK(cs_main, return &manager.InitializeChainstate(llmq::chainLocksHandler, llmq::quorumInstantSendManager, llmq::quorumBlockProcessor, m_node.evodb, mempool)); + CChainState& c1 = *WITH_LOCK(cs_main, return &manager.InitializeChainstate(llmq::chainLocksHandler, llmq::quorumInstantSendManager, llmq::quorumBlockProcessor, evodb, mempool)); chainstates.push_back(&c1); c1.InitCoinsDB( /* cache_size_bytes */ 1 << 23, /* in_memory */ true, /* should_wipe */ false); @@ -137,7 +139,7 @@ BOOST_AUTO_TEST_CASE(chainstatemanager_rebalance_caches) // Create a snapshot-based chainstate. // - CChainState& c2 = *WITH_LOCK(cs_main, return &manager.InitializeChainstate(llmq::chainLocksHandler, llmq::quorumInstantSendManager, llmq::quorumBlockProcessor, m_node.evodb, mempool, GetRandHash())); + CChainState& c2 = *WITH_LOCK(cs_main, return &manager.InitializeChainstate(llmq::chainLocksHandler, llmq::quorumInstantSendManager, llmq::quorumBlockProcessor, evodb, mempool, GetRandHash())); chainstates.push_back(&c2); c2.InitCoinsDB( /* cache_size_bytes */ 1 << 23, /* in_memory */ true, /* should_wipe */ false); diff --git a/src/test/validation_flush_tests.cpp b/src/test/validation_flush_tests.cpp index 53c267cb8a..482d4f2ff2 100644 --- a/src/test/validation_flush_tests.cpp +++ b/src/test/validation_flush_tests.cpp @@ -24,7 +24,7 @@ BOOST_AUTO_TEST_CASE(getcoinscachesizestate) { CTxMemPool mempool; BlockManager blockman{}; - CChainState chainstate(blockman, llmq::chainLocksHandler, llmq::quorumInstantSendManager, llmq::quorumBlockProcessor, m_node.evodb, mempool); + CChainState chainstate(blockman, llmq::chainLocksHandler, llmq::quorumInstantSendManager, llmq::quorumBlockProcessor, *m_node.evodb, mempool); chainstate.InitCoinsDB(/*cache_size_bytes*/ 1 << 10, /*in_memory*/ true, /*should_wipe*/ false); WITH_LOCK(::cs_main, chainstate.InitCoinsCache(1 << 10)); CTxMemPool tx_pool{}; diff --git a/src/validation.cpp b/src/validation.cpp index ef35a8e9f7..1979e09f94 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -1296,10 +1296,10 @@ void CoinsViews::InitCache() } CChainState::CChainState(BlockManager& blockman, - std::unique_ptr& clhandler, - std::unique_ptr& isman, - std::unique_ptr& quorum_block_processor, - std::unique_ptr& evoDb, + const std::unique_ptr& clhandler, + const std::unique_ptr& isman, + const std::unique_ptr& quorum_block_processor, + CEvoDB& evoDb, CTxMemPool& mempool, uint256 from_snapshot_blockhash) : m_mempool(mempool), @@ -1730,7 +1730,7 @@ DisconnectResult CChainState::DisconnectBlock(const CBlock& block, const CBlockI assert(m_quorum_block_processor); bool fDIP0003Active = pindex->nHeight >= Params().GetConsensus().DIP0003Height; - if (fDIP0003Active && !m_evoDb->VerifyBestBlock(pindex->GetBlockHash())) { + if (fDIP0003Active && !m_evoDb.VerifyBestBlock(pindex->GetBlockHash())) { // Nodes that upgraded after DIP3 activation will have to reindex to ensure evodb consistency AbortNode("Found EvoDB inconsistency, you must reindex to continue"); return DISCONNECT_FAILED; @@ -1891,7 +1891,7 @@ DisconnectResult CChainState::DisconnectBlock(const CBlock& block, const CBlockI // move best block pointer to prevout block view.SetBestBlock(pindex->pprev->GetBlockHash()); - m_evoDb->WriteBestBlock(pindex->pprev->GetBlockHash()); + m_evoDb.WriteBestBlock(pindex->pprev->GetBlockHash()); boost::posix_time::ptime finish = boost::posix_time::microsec_clock::local_time(); boost::posix_time::time_duration diff = finish - start; @@ -2126,7 +2126,7 @@ bool CChainState::ConnectBlock(const CBlock& block, BlockValidationState& state, if (pindex->pprev) { bool fDIP0003Active = pindex->nHeight >= chainparams.GetConsensus().DIP0003Height; - if (fDIP0003Active && !m_evoDb->VerifyBestBlock(pindex->pprev->GetBlockHash())) { + if (fDIP0003Active && !m_evoDb.VerifyBestBlock(pindex->pprev->GetBlockHash())) { // Nodes that upgraded after DIP3 activation will have to reindex to ensure evodb consistency return AbortNode(state, "Found EvoDB inconsistency, you must reindex to continue"); } @@ -2521,7 +2521,7 @@ bool CChainState::ConnectBlock(const CBlock& block, BlockValidationState& state, int64_t nTime6 = GetTimeMicros(); nTimeIndex += nTime6 - nTime5; LogPrint(BCLog::BENCHMARK, " - Index writing: %.2fms [%.2fs (%.2fms/blk)]\n", MILLI * (nTime6 - nTime5), nTimeIndex * MICRO, nTimeIndex * MILLI / nBlocksTotal); - m_evoDb->WriteBestBlock(pindex->GetBlockHash()); + m_evoDb.WriteBestBlock(pindex->GetBlockHash()); int64_t nTime7 = GetTimeMicros(); nTimeCallbacks += nTime7 - nTime6; LogPrint(BCLog::BENCHMARK, " - Callbacks: %.2fms [%.2fs (%.2fms/blk)]\n", MILLI * (nTime7 - nTime6), nTimeCallbacks * MICRO, nTimeCallbacks * MILLI / nBlocksTotal); @@ -2624,7 +2624,7 @@ bool CChainState::FlushStateToDisk( // The cache is over the limit, we have to write now. bool fCacheCritical = mode == FlushStateMode::IF_NEEDED && cache_state >= CoinsCacheSizeState::CRITICAL; // The evodb cache is too large - bool fEvoDbCacheCritical = mode == FlushStateMode::IF_NEEDED && m_evoDb != nullptr && m_evoDb->GetMemoryUsage() >= (64 << 20); + bool fEvoDbCacheCritical = mode == FlushStateMode::IF_NEEDED && m_evoDb.GetMemoryUsage() >= (64 << 20); // It's been a while since we wrote the block index to disk. Do this frequently, so we don't need to redownload after a crash. bool fPeriodicWrite = mode == FlushStateMode::PERIODIC && nNow > nLastWrite + DATABASE_WRITE_INTERVAL; // It's been very long since we flushed the cache. Do this infrequently, to optimize cache usage. @@ -2689,7 +2689,7 @@ bool CChainState::FlushStateToDisk( // Flush the chainstate (which may refer to block index entries). if (!CoinsTip().Flush()) return AbortNode(state, "Failed to write to coin database"); - if (!m_evoDb->CommitRootTransaction()) { + if (!m_evoDb.CommitRootTransaction()) { return AbortNode(state, "Failed to commit EvoDB"); } nLastFlush = nNow; @@ -2818,7 +2818,7 @@ bool CChainState::DisconnectTip(BlockValidationState& state, const CChainParams& // Apply the block atomically to the chain state. int64_t nStart = GetTimeMicros(); { - auto dbTx = m_evoDb->BeginTransaction(); + auto dbTx = m_evoDb.BeginTransaction(); CCoinsViewCache view(&CoinsTip()); assert(view.GetBestBlock() == pindexDelete->GetBlockHash()); @@ -2848,7 +2848,7 @@ bool CChainState::DisconnectTip(BlockValidationState& state, const CChainParams& m_chain.SetTip(pindexDelete->pprev); - UpdateTip(m_mempool, pindexDelete->pprev, chainparams, *this, *m_evoDb); + UpdateTip(m_mempool, pindexDelete->pprev, chainparams, *this, m_evoDb); // Let wallets know transactions went from 1-confirmed to // 0-confirmed or conflicted: GetMainSignals().BlockDisconnected(pblock, pindexDelete); @@ -2931,7 +2931,7 @@ bool CChainState::ConnectTip(BlockValidationState& state, const CChainParams& ch int64_t nTime3; LogPrint(BCLog::BENCHMARK, " - Load block from disk: %.2fms [%.2fs]\n", (nTime2 - nTime1) * MILLI, nTimeReadFromDisk * MICRO); { - auto dbTx = m_evoDb->BeginTransaction(); + auto dbTx = m_evoDb.BeginTransaction(); CCoinsViewCache view(&CoinsTip()); bool rv = ConnectBlock(blockConnecting, state, pindexNew, view, chainparams); @@ -2960,7 +2960,7 @@ bool CChainState::ConnectTip(BlockValidationState& state, const CChainParams& ch disconnectpool.removeForBlock(blockConnecting.vtx); // Update m_chain & related variables. m_chain.SetTip(pindexNew); - UpdateTip(m_mempool, pindexNew, chainparams, *this, *m_evoDb); + UpdateTip(m_mempool, pindexNew, chainparams, *this, m_evoDb); int64_t nTime6 = GetTimeMicros(); nTimePostConnect += nTime6 - nTime5; nTimeTotal += nTime6 - nTime1; LogPrint(BCLog::BENCHMARK, " - Connect postprocess: %.2fms [%.2fs (%.2fms/blk)]\n", (nTime6 - nTime5) * MILLI, nTimePostConnect * MICRO, nTimePostConnect * MILLI / nBlocksTotal); @@ -4939,7 +4939,7 @@ bool CChainState::ReplayBlocks(const CChainParams& params) assert(pindexFork != nullptr); } - auto dbTx = m_evoDb->BeginTransaction(); + auto dbTx = m_evoDb.BeginTransaction(); // Rollback along the old branch. while (pindexOld != pindexFork) { @@ -4974,7 +4974,7 @@ bool CChainState::ReplayBlocks(const CChainParams& params) } cache.SetBestBlock(pindexNew->GetBlockHash()); - m_evoDb->WriteBestBlock(pindexNew->GetBlockHash()); + m_evoDb.WriteBestBlock(pindexNew->GetBlockHash()); bool flushed = cache.Flush(); assert(flushed); dbTx->Commit(); @@ -5658,10 +5658,10 @@ std::vector ChainstateManager::GetAll() return out; } -CChainState& ChainstateManager::InitializeChainstate(std::unique_ptr& clhandler, - std::unique_ptr& isman, - std::unique_ptr& quorum_block_processor, - std::unique_ptr& evoDb, +CChainState& ChainstateManager::InitializeChainstate(const std::unique_ptr& clhandler, + const std::unique_ptr& isman, + const std::unique_ptr& quorum_block_processor, + CEvoDB& evoDb, CTxMemPool& mempool, const uint256& snapshot_blockhash) { diff --git a/src/validation.h b/src/validation.h index 7e9b234abc..2b740979bd 100644 --- a/src/validation.h +++ b/src/validation.h @@ -574,10 +574,10 @@ private: std::unique_ptr m_coins_views; //! Dash - std::unique_ptr& m_clhandler; - std::unique_ptr& m_isman; - std::unique_ptr& m_quorum_block_processor; - std::unique_ptr& m_evoDb; + const std::unique_ptr& m_clhandler; + const std::unique_ptr& m_isman; + const std::unique_ptr& m_quorum_block_processor; + CEvoDB& m_evoDb; public: //! Reference to a BlockManager instance which itself is shared across all @@ -585,10 +585,10 @@ public: BlockManager& m_blockman; explicit CChainState(BlockManager& blockman, - std::unique_ptr& clhandler, - std::unique_ptr& isman, - std::unique_ptr& quorum_block_processor, - std::unique_ptr& evoDb, + const std::unique_ptr& clhandler, + const std::unique_ptr& isman, + const std::unique_ptr& quorum_block_processor, + CEvoDB& evoDb, CTxMemPool& mempool, uint256 from_snapshot_blockhash = uint256()); @@ -909,10 +909,10 @@ public: // constructor //! @param[in] snapshot_blockhash If given, signify that this chainstate //! is based on a snapshot. - CChainState& InitializeChainstate(std::unique_ptr& clhandler, - std::unique_ptr& isman, - std::unique_ptr& quorum_block_processor, - std::unique_ptr& evoDb, + CChainState& InitializeChainstate(const std::unique_ptr& clhandler, + const std::unique_ptr& isman, + const std::unique_ptr& quorum_block_processor, + CEvoDB& evoDb, CTxMemPool& mempool, const uint256& snapshot_blockhash = uint256()) EXCLUSIVE_LOCKS_REQUIRED(::cs_main); diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 668488ae99..922fde44c1 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -118,7 +118,8 @@ bool AddWallet(const std::shared_ptr& wallet) vpwallets.push_back(wallet); } wallet->ConnectScriptPubKeyManNotifiers(); - coinJoinClientManagers.emplace(std::make_pair(wallet->GetName(), std::make_shared(*wallet, ::masternodeSync))); + assert(::masternodeSync != nullptr); + coinJoinClientManagers.emplace(std::make_pair(wallet->GetName(), std::make_shared(*wallet, *::masternodeSync))); g_wallet_init_interface.InitCoinJoinSettings(); return true; } @@ -4793,7 +4794,8 @@ std::shared_ptr CWallet::Create(interfaces::Chain& chain, const std::st walletInstance->database->IncrementUpdateCounter(); } - coinJoinClientManagers.emplace(std::make_pair(walletInstance->GetName(), std::make_shared(*walletInstance, ::masternodeSync))); + assert(::masternodeSync != nullptr); + coinJoinClientManagers.emplace(std::make_pair(walletInstance->GetName(), std::make_shared(*walletInstance, *::masternodeSync))); { LOCK(cs_wallets);