diff --git a/src/bench/coin_selection.cpp b/src/bench/coin_selection.cpp index ec61a3f134bd..a51c4b96e276 100644 --- a/src/bench/coin_selection.cpp +++ b/src/bench/coin_selection.cpp @@ -11,6 +11,17 @@ #include +using node::NodeContext; +using wallet::CHANGE_LOWER; +using wallet::CoinEligibilityFilter; +using wallet::CoinSelectionParams; +using wallet::COutput; +using wallet::CreateDummyWalletDatabase; +using wallet::CWallet; +using wallet::CWalletTx; +using wallet::OutputGroup; +using wallet::TxStateInactive; + static void addCoin(const CAmount& nValue, const CWallet& wallet, std::vector>& wtxs) { static int nextLockTime = 0; diff --git a/src/bench/load_external.cpp b/src/bench/load_external.cpp index 6bc359a408a8..68d7895f49b4 100644 --- a/src/bench/load_external.cpp +++ b/src/bench/load_external.cpp @@ -40,7 +40,7 @@ static void LoadExternalBlockFile(benchmark::Bench& bench) // "wb+" is "binary, O_RDWR | O_CREAT | O_TRUNC". FILE* file{fsbridge::fopen(blkfile, "wb+")}; // Make the test block file about 128 MB in length. - for (size_t i = 0; i < MAX_BLOCKFILE_SIZE / ss.size(); ++i) { + for (size_t i = 0; i < node::MAX_BLOCKFILE_SIZE / ss.size(); ++i) { if (fwrite(ss.data(), 1, ss.size(), file) != ss.size()) { throw std::runtime_error("write to test file failed\n"); } diff --git a/src/bench/wallet_balance.cpp b/src/bench/wallet_balance.cpp index dbc522615991..004a4c5aa665 100644 --- a/src/bench/wallet_balance.cpp +++ b/src/bench/wallet_balance.cpp @@ -14,6 +14,11 @@ #include +using wallet::CreateMockWalletDatabase; +using wallet::CWallet; +using wallet::DBErrors; +using wallet::WALLET_FLAG_DESCRIPTORS; + static void WalletBalance(benchmark::Bench& bench, const bool set_dirty, const bool add_mine, const uint32_t epoch_iters) { const auto test_setup = MakeNoLogFileContext(); diff --git a/src/bitcoin-wallet.cpp b/src/bitcoin-wallet.cpp index 832273514b0c..45f494b348b7 100644 --- a/src/bitcoin-wallet.cpp +++ b/src/bitcoin-wallet.cpp @@ -112,7 +112,7 @@ MAIN_FUNCTION } ECC_Start(); - if (!WalletTool::ExecuteWalletToolFunc(args, command->command)) { + if (!wallet::WalletTool::ExecuteWalletToolFunc(args, command->command)) { return EXIT_FAILURE; } ECC_Stop(); diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp index f3cc180d4fdd..4706c8457833 100644 --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -31,6 +31,8 @@ #include #include +using node::NodeContext; + const std::function G_TRANSLATION_FUN = nullptr; UrlDecodeFn* const URL_DECODE = urlDecode; diff --git a/src/chain.cpp b/src/chain.cpp index ae5307d90ed5..2480047d024f 100644 --- a/src/chain.cpp +++ b/src/chain.cpp @@ -4,9 +4,15 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include +#include #include +std::string CBlockFileInfo::ToString() const +{ + return strprintf("CBlockFileInfo(blocks=%u, size=%u, heights=%u...%u, time=%s...%s)", nBlocks, nSize, nHeightFirst, nHeightLast, FormatISO8601Date(nTimeFirst), FormatISO8601Date(nTimeLast)); +} + std::string CBlockIndex::ToString() const { return strprintf("CBlockIndex(pprev=%p, nHeight=%d, merkle=%s, hashBlock=%s)", diff --git a/src/coinjoin/client.cpp b/src/coinjoin/client.cpp index d7fdb87a3911..025823f9b9bd 100644 --- a/src/coinjoin/client.cpp +++ b/src/coinjoin/client.cpp @@ -33,6 +33,13 @@ #include #include +using wallet::CCoinControl; +using wallet::CompactTallyItem; +using wallet::COutput; +using wallet::CoinType; +using wallet::CWallet; +using wallet::ReserveDestination; + PeerMsgRet CCoinJoinClientQueueManager::ProcessMessage(const CNode& peer, CConnman& connman, PeerManager& peerman, std::string_view msg_type, CDataStream& vRecv) { @@ -54,7 +61,7 @@ PeerMsgRet CCoinJoinClientQueueManager::ProcessDSQueue(const CNode& peer, CConnm vRecv >> dsq; { - LOCK(cs_main); + LOCK(::cs_main); peerman.EraseObjectRequest(peer.GetId(), CInv(MSG_DSQ, dsq.GetHash())); } diff --git a/src/coinjoin/client.h b/src/coinjoin/client.h index 9fd50133de44..bdeaccc7d9db 100644 --- a/src/coinjoin/client.h +++ b/src/coinjoin/client.h @@ -96,7 +96,7 @@ class CoinJoinWalletManager { } } - void Add(const std::shared_ptr& wallet); + void Add(const std::shared_ptr& wallet); void DoMaintenance(CConnman& connman); void Remove(const std::string& name); @@ -138,7 +138,7 @@ class CoinJoinWalletManager { class CCoinJoinClientSession : public CCoinJoinBaseSession { private: - const std::shared_ptr m_wallet; + const std::shared_ptr m_wallet; CCoinJoinClientManager& m_clientman; CDeterministicMNManager& m_dmnman; CMasternodeMetaMan& m_mn_metaman; @@ -162,12 +162,12 @@ class CCoinJoinClientSession : public CCoinJoinBaseSession /// Create denominations bool CreateDenominated(CAmount nBalanceToDenominate); - bool CreateDenominated(CAmount nBalanceToDenominate, const CompactTallyItem& tallyItem, bool fCreateMixingCollaterals) + bool CreateDenominated(CAmount nBalanceToDenominate, const wallet::CompactTallyItem& tallyItem, bool fCreateMixingCollaterals) EXCLUSIVE_LOCKS_REQUIRED(m_wallet->cs_wallet); /// Split up large inputs or make fee sized inputs bool MakeCollateralAmounts(); - bool MakeCollateralAmounts(const CompactTallyItem& tallyItem, bool fTryDenominated) + bool MakeCollateralAmounts(const wallet::CompactTallyItem& tallyItem, bool fTryDenominated) EXCLUSIVE_LOCKS_REQUIRED(m_wallet->cs_wallet); bool CreateCollateralTransaction(CMutableTransaction& txCollateral, std::string& strReason) @@ -200,7 +200,7 @@ class CCoinJoinClientSession : public CCoinJoinBaseSession void SetNull() override EXCLUSIVE_LOCKS_REQUIRED(cs_coinjoin); public: - explicit CCoinJoinClientSession(const std::shared_ptr& wallet, CCoinJoinClientManager& clientman, + explicit CCoinJoinClientSession(const std::shared_ptr& wallet, CCoinJoinClientManager& clientman, CDeterministicMNManager& dmnman, CMasternodeMetaMan& mn_metaman, const CMasternodeSync& mn_sync, const llmq::CInstantSendManager& isman, const std::unique_ptr& queueman, bool is_masternode); @@ -263,7 +263,7 @@ class CCoinJoinClientQueueManager : public CCoinJoinBaseManager class CCoinJoinClientManager { private: - const std::shared_ptr m_wallet; + const std::shared_ptr m_wallet; CDeterministicMNManager& m_dmnman; CMasternodeMetaMan& m_mn_metaman; const CMasternodeSync& m_mn_sync; @@ -302,7 +302,7 @@ class CCoinJoinClientManager CCoinJoinClientManager(CCoinJoinClientManager const&) = delete; CCoinJoinClientManager& operator=(CCoinJoinClientManager const&) = delete; - explicit CCoinJoinClientManager(const std::shared_ptr& wallet, CDeterministicMNManager& dmnman, + explicit CCoinJoinClientManager(const std::shared_ptr& wallet, CDeterministicMNManager& dmnman, CMasternodeMetaMan& mn_metaman, const CMasternodeSync& mn_sync, const llmq::CInstantSendManager& isman, const std::unique_ptr& queueman, bool is_masternode) : diff --git a/src/coinjoin/coinjoin.cpp b/src/coinjoin/coinjoin.cpp index 2e226296b930..fafdf4528755 100644 --- a/src/coinjoin/coinjoin.cpp +++ b/src/coinjoin/coinjoin.cpp @@ -257,7 +257,7 @@ bool CCoinJoinBaseSession::IsValidInOuts(CChainState& active_chainstate, const l nFees -= txout.nValue; } - CCoinsViewMemPool viewMemPool(WITH_LOCK(cs_main, return &active_chainstate.CoinsTip()), mempool); + CCoinsViewMemPool viewMemPool(WITH_LOCK(::cs_main, return &active_chainstate.CoinsTip()), mempool); for (const auto& txin : vin) { LogPrint(BCLog::COINJOIN, "CCoinJoinBaseSession::%s -- txin=%s\n", __func__, txin.ToString()); @@ -299,7 +299,7 @@ bool CCoinJoinBaseSession::IsValidInOuts(CChainState& active_chainstate, const l // but CoinJoin still requires ATMP with fee sanity checks so we need to implement them separately bool ATMPIfSaneFee(ChainstateManager& chainman, const CTransactionRef& tx, bool test_accept) { - AssertLockHeld(cs_main); + AssertLockHeld(::cs_main); const MempoolAcceptResult result = chainman.ProcessTransaction(tx, /*test_accept=*/true); if (result.m_result_type != MempoolAcceptResult::ResultType::VALID) { @@ -360,7 +360,7 @@ bool CoinJoin::IsCollateralValid(ChainstateManager& chainman, const llmq::CInsta LogPrint(BCLog::COINJOIN, "CoinJoin::IsCollateralValid -- %s", txCollateral.ToString()); /* Continued */ { - LOCK(cs_main); + LOCK(::cs_main); 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 f9cd1de64bc8..5eac1470be35 100644 --- a/src/coinjoin/coinjoin.h +++ b/src/coinjoin/coinjoin.h @@ -404,6 +404,6 @@ class CDSTXManager }; bool ATMPIfSaneFee(ChainstateManager& chainman, const CTransactionRef& tx, bool test_accept = false) - EXCLUSIVE_LOCKS_REQUIRED(cs_main); + EXCLUSIVE_LOCKS_REQUIRED(::cs_main); #endif // BITCOIN_COINJOIN_COINJOIN_H diff --git a/src/coinjoin/interfaces.cpp b/src/coinjoin/interfaces.cpp index acb9565974e0..a434d023a801 100644 --- a/src/coinjoin/interfaces.cpp +++ b/src/coinjoin/interfaces.cpp @@ -17,6 +17,9 @@ #include #include +using node::NodeContext; +using wallet::CWallet; + namespace coinjoin { namespace { diff --git a/src/coinjoin/server.cpp b/src/coinjoin/server.cpp index f5fef56e5f76..01a8266916ee 100644 --- a/src/coinjoin/server.cpp +++ b/src/coinjoin/server.cpp @@ -119,7 +119,7 @@ PeerMsgRet CCoinJoinServer::ProcessDSQUEUE(const CNode& peer, CDataStream& vRecv vRecv >> dsq; { - LOCK(cs_main); + LOCK(::cs_main); Assert(m_peerman)->EraseObjectRequest(peer.GetId(), CInv(MSG_DSQ, dsq.GetHash())); } @@ -327,7 +327,7 @@ void CCoinJoinServer::CommitFinalTransaction() { // See if the transaction is valid - TRY_LOCK(cs_main, lockMain); + TRY_LOCK(::cs_main, lockMain); mempool.PrioritiseTransaction(hashTx, 0.1 * COIN); if (!lockMain || !ATMPIfSaneFee(m_chainman, finalTransaction)) { LogPrint(BCLog::COINJOIN, "CCoinJoinServer::CommitFinalTransaction -- ATMPIfSaneFee() error: Transaction not valid\n"); @@ -460,7 +460,7 @@ void CCoinJoinServer::ChargeRandomFees() const void CCoinJoinServer::ConsumeCollateral(const CTransactionRef& txref) const { - LOCK(cs_main); + LOCK(::cs_main); if (!ATMPIfSaneFee(m_chainman, txref)) { LogPrint(BCLog::COINJOIN, "%s -- ATMPIfSaneFee failed\n", __func__); } else { diff --git a/src/coinjoin/util.cpp b/src/coinjoin/util.cpp index 2537a1cedcb9..18415e23b14a 100644 --- a/src/coinjoin/util.cpp +++ b/src/coinjoin/util.cpp @@ -14,6 +14,13 @@ #include +using wallet::CompactTallyItem; +using wallet::CRecipient; +using wallet::CWallet; +using wallet::FEATURE_COMPRPUBKEY; +using wallet::GetDiscardRate; +using wallet::WalletBatch; + inline unsigned int GetSizeOfCompactSizeDiff(uint64_t nSizePrev, uint64_t nSizeNew) { assert(nSizePrev <= nSizeNew); @@ -273,7 +280,7 @@ bool CTransactionBuilder::Commit(bilingual_str& strResult) CTransactionRef tx; { - LOCK2(m_wallet.cs_wallet, cs_main); + LOCK2(m_wallet.cs_wallet, ::cs_main); FeeCalculation fee_calc_out; if (!CreateTransaction(m_wallet, vecSend, tx, nFeeRet, nChangePosRet, strResult, coinControl, fee_calc_out)) { return false; @@ -312,7 +319,7 @@ bool CTransactionBuilder::Commit(bilingual_str& strResult) } { - LOCK2(m_wallet.cs_wallet, cs_main); + LOCK2(m_wallet.cs_wallet, ::cs_main); m_wallet.CommitTransaction(tx, {}, {}); } diff --git a/src/coinjoin/util.h b/src/coinjoin/util.h index 5b0d060b456f..c76209175d41 100644 --- a/src/coinjoin/util.h +++ b/src/coinjoin/util.h @@ -13,11 +13,11 @@ struct bilingual_str; class CKeyHolder { private: - ReserveDestination reserveDestination; + wallet::ReserveDestination reserveDestination; CTxDestination dest; public: - explicit CKeyHolder(CWallet* pwalletIn); + explicit CKeyHolder(wallet::CWallet* pwalletIn); CKeyHolder(CKeyHolder&&) = delete; CKeyHolder& operator=(CKeyHolder&&) = delete; void KeepKey(); @@ -33,7 +33,7 @@ class CKeyHolderStorage std::vector > storage GUARDED_BY(cs_storage); public: - CScript AddKey(CWallet* pwalletIn) EXCLUSIVE_LOCKS_REQUIRED(!cs_storage); + CScript AddKey(wallet::CWallet* pwalletIn) EXCLUSIVE_LOCKS_REQUIRED(!cs_storage); void KeepAll() EXCLUSIVE_LOCKS_REQUIRED(!cs_storage); void ReturnAll() EXCLUSIVE_LOCKS_REQUIRED(!cs_storage); }; @@ -47,14 +47,14 @@ class CTransactionBuilderOutput /// Used for amount updates CTransactionBuilder* pTxBuilder{nullptr}; /// Reserve key where the amount of this output will end up - ReserveDestination dest; + wallet::ReserveDestination dest; /// Amount this output will receive CAmount nAmount{0}; /// ScriptPubKey of this output CScript script; public: - CTransactionBuilderOutput(CTransactionBuilder* pTxBuilderIn, CWallet& wallet, CAmount nAmountIn); + CTransactionBuilderOutput(CTransactionBuilder* pTxBuilderIn, wallet::CWallet& wallet, CAmount nAmountIn); CTransactionBuilderOutput(CTransactionBuilderOutput&&) = delete; CTransactionBuilderOutput& operator=(CTransactionBuilderOutput&&) = delete; /// Get the scriptPubKey of this output @@ -77,15 +77,15 @@ class CTransactionBuilderOutput class CTransactionBuilder { /// Wallet the transaction will be build for - CWallet& m_wallet; + wallet::CWallet& m_wallet; /// See CTransactionBuilder() for initialization - CCoinControl coinControl; + wallet::CCoinControl coinControl; /// Dummy since we anyway use tallyItem's destination as change destination in coincontrol. /// Its a member just to make sure ReturnKey can be called in destructor just in case it gets generated/kept /// somewhere in CWallet code. - ReserveDestination dummyReserveDestination; + wallet::ReserveDestination dummyReserveDestination; /// Contains all utxos available to generate this transactions. They are all from the same address. - CompactTallyItem tallyItem; + wallet::CompactTallyItem tallyItem; /// Contains the number of bytes required for a transaction with only the inputs of tallyItems, no outputs int nBytesBase{0}; /// Contains the number of bytes required to add one output @@ -100,7 +100,7 @@ class CTransactionBuilder friend class CTransactionBuilderOutput; public: - CTransactionBuilder(CWallet& wallet, const CompactTallyItem& tallyItemIn); + CTransactionBuilder(wallet::CWallet& wallet, const wallet::CompactTallyItem& tallyItemIn); ~CTransactionBuilder(); /// Check it would be possible to add a single output with the amount nAmount. Returns true if its possible and false if not. bool CouldAddOutput(CAmount nAmountOutput) const EXCLUSIVE_LOCKS_REQUIRED(!cs_outputs); diff --git a/src/context.h b/src/context.h index 39da4ec9a832..b88aee7e29b0 100644 --- a/src/context.h +++ b/src/context.h @@ -13,13 +13,17 @@ class ChainstateManager; class CTxMemPool; class CBlockPolicyEstimator; struct LLMQContext; +namespace node { struct NodeContext; +} // namespace node +namespace wallet { struct WalletContext; +} // namespace wallet using CoreContext = std::variant, - std::reference_wrapper, - std::reference_wrapper, + std::reference_wrapper, + std::reference_wrapper, std::reference_wrapper, std::reference_wrapper, std::reference_wrapper, diff --git a/src/dummywallet.cpp b/src/dummywallet.cpp index 2cadbb003b21..b37c7c364cd2 100644 --- a/src/dummywallet.cpp +++ b/src/dummywallet.cpp @@ -7,8 +7,6 @@ #include class ArgsManager; -class CWallet; - namespace interfaces { class Chain; class Handler; @@ -17,8 +15,14 @@ class WalletClient; class WalletLoader; namespace CoinJoin { class Loader; -} // namespcae CoinJoin -} +} // namespace CoinJoin +} // namespace interfaces +namespace node { +class NodeContext; +} // namespace node +namespace wallet { +class CWallet; +} // namespace wallet class DummyWalletInit : public WalletInitInterface { public: @@ -26,7 +30,7 @@ class DummyWalletInit : public WalletInitInterface { bool HasWalletSupport() const override {return false;} void AddWalletOptions(ArgsManager& argsman) const override; bool ParameterInteraction() const override {return true;} - void Construct(NodeContext& node) const override {LogPrintf("No wallet support compiled in!\n");} + void Construct(node::NodeContext& node) const override {LogPrintf("No wallet support compiled in!\n");} // Dash Specific WalletInitInterface InitCoinJoinSettings void AutoLockMasternodeCollaterals(interfaces::WalletLoader& wallet_loader) const override {} @@ -82,17 +86,17 @@ const WalletInitInterface& g_wallet_init_interface = DummyWalletInit(); namespace interfaces { -std::unique_ptr MakeCoinJoinLoader(NodeContext& node) +std::unique_ptr MakeCoinJoinLoader(node::NodeContext& node) { throw std::logic_error("Wallet function called in non-wallet build."); } -std::unique_ptr MakeWallet(const std::shared_ptr& wallet) +std::unique_ptr MakeWallet(const std::shared_ptr& wallet) { throw std::logic_error("Wallet function called in non-wallet build."); } -std::unique_ptr MakeWalletLoader(Chain& chain, ArgsManager& args, NodeContext& node_context, +std::unique_ptr MakeWalletLoader(Chain& chain, ArgsManager& args, node::NodeContext& node_context, interfaces::CoinJoin::Loader& coinjoin_loader) { throw std::logic_error("Wallet function called in non-wallet build."); diff --git a/src/evo/assetlocktx.cpp b/src/evo/assetlocktx.cpp index d64eb126ffa5..61878c447018 100644 --- a/src/evo/assetlocktx.cpp +++ b/src/evo/assetlocktx.cpp @@ -20,6 +20,8 @@ #include +using node::BlockManager; + /** * Common code for Asset Lock and Asset Unlock */ @@ -184,7 +186,7 @@ bool CheckAssetUnlockTx(const BlockManager& blockman, const llmq::CQuorumManager return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-assetunlock-duplicated-index"); } - if (LOCK(cs_main); blockman.LookupBlockIndex(assetUnlockTx.getQuorumHash()) == nullptr) { + if (LOCK(::cs_main); blockman.LookupBlockIndex(assetUnlockTx.getQuorumHash()) == nullptr) { return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-assetunlock-quorum-hash"); } diff --git a/src/evo/assetlocktx.h b/src/evo/assetlocktx.h index 0af346be0a20..2fc44643fa8f 100644 --- a/src/evo/assetlocktx.h +++ b/src/evo/assetlocktx.h @@ -14,13 +14,15 @@ #include -class BlockManager; class CBlockIndex; class CRangesSet; class TxValidationState; namespace llmq { class CQuorumManager; } // namespace llmq +namespace node { +class BlockManager; +} // namespace node class CAssetLockPayload { @@ -150,8 +152,8 @@ class CAssetUnlockPayload }; bool CheckAssetLockTx(const CTransaction& tx, TxValidationState& state); -bool CheckAssetUnlockTx(const BlockManager& blockman, const llmq::CQuorumManager& qman, const CTransaction& tx, gsl::not_null pindexPrev, const std::optional& indexes, TxValidationState& state); -bool CheckAssetLockUnlockTx(const BlockManager& blockman, const llmq::CQuorumManager& qman, const CTransaction& tx, gsl::not_null pindexPrev, const std::optional& indexes, TxValidationState& state); +bool CheckAssetUnlockTx(const node::BlockManager& blockman, const llmq::CQuorumManager& qman, const CTransaction& tx, gsl::not_null pindexPrev, const std::optional& indexes, TxValidationState& state); +bool CheckAssetLockUnlockTx(const node::BlockManager& blockman, const llmq::CQuorumManager& qman, const CTransaction& tx, gsl::not_null pindexPrev, const std::optional& indexes, TxValidationState& state); bool GetAssetUnlockFee(const CTransaction& tx, CAmount& txfee, TxValidationState& state); #endif // BITCOIN_EVO_ASSETLOCKTX_H diff --git a/src/evo/cbtx.cpp b/src/evo/cbtx.cpp index d562877db9bf..9eb014a814b7 100644 --- a/src/evo/cbtx.cpp +++ b/src/evo/cbtx.cpp @@ -18,6 +18,7 @@ #include #include +using node::ReadBlockFromDisk; bool CheckCbTx(const CCbTx& cbTx, const CBlockIndex* pindexPrev, TxValidationState& state) { diff --git a/src/evo/chainhelper.cpp b/src/evo/chainhelper.cpp index ca19f850c8e3..d946785ea1b5 100644 --- a/src/evo/chainhelper.cpp +++ b/src/evo/chainhelper.cpp @@ -13,6 +13,8 @@ #include #include +using node::GetTransaction; + CChainstateHelper::CChainstateHelper(CCreditPoolManager& cpoolman, CDeterministicMNManager& dmnman, CMNHFManager& mnhfman, CGovernanceManager& govman, llmq::CInstantSendManager& isman, llmq::CQuorumBlockProcessor& qblockman, llmq::CQuorumSnapshotManager& qsnapman, diff --git a/src/evo/creditpool.cpp b/src/evo/creditpool.cpp index ea5adf412f63..639aa1b1d5de 100644 --- a/src/evo/creditpool.cpp +++ b/src/evo/creditpool.cpp @@ -22,6 +22,9 @@ #include #include +using node::BlockManager; +using node::ReadBlockFromDisk; + // Forward declaration to prevent a new circular dependencies through masternode/payments.h CAmount PlatformShare(const CAmount masternodeReward); diff --git a/src/evo/creditpool.h b/src/evo/creditpool.h index 46572f4b39ed..bc6c7e8fc3ae 100644 --- a/src/evo/creditpool.h +++ b/src/evo/creditpool.h @@ -20,7 +20,6 @@ #include #include -class BlockManager; class CBlock; class CBlockIndex; class BlockValidationState; @@ -32,6 +31,9 @@ struct Params; namespace llmq { class CQuorumManager; } // namespace llmq +namespace node { +class BlockManager; +} // namespace node struct CCreditPool { CAmount locked{0}; @@ -86,7 +88,7 @@ class CCreditPoolDiff { * to change amount of credit pool * @return true if transaction can be included in this block */ - bool ProcessLockUnlockTransaction(const BlockManager& blockman, const llmq::CQuorumManager& qman, const CTransaction& tx, TxValidationState& state); + bool ProcessLockUnlockTransaction(const node::BlockManager& blockman, const llmq::CQuorumManager& qman, const CTransaction& tx, TxValidationState& state); /** * this function returns total amount of credits for the next block @@ -139,7 +141,7 @@ class CCreditPoolManager const Consensus::Params& consensusParams); }; -std::optional GetCreditPoolDiffForBlock(CCreditPoolManager& cpoolman, const BlockManager& blockman, const llmq::CQuorumManager& qman, +std::optional GetCreditPoolDiffForBlock(CCreditPoolManager& cpoolman, const node::BlockManager& blockman, const llmq::CQuorumManager& qman, const CBlock& block, const CBlockIndex* pindexPrev, const Consensus::Params& consensusParams, const CAmount blockSubsidy, BlockValidationState& state); diff --git a/src/evo/deterministicmns.cpp b/src/evo/deterministicmns.cpp index 897723c7950e..38192ca25539 100644 --- a/src/evo/deterministicmns.cpp +++ b/src/evo/deterministicmns.cpp @@ -588,7 +588,7 @@ bool CDeterministicMNManager::ProcessBlock(const CBlock& block, gsl::not_null& updatesRet) { - AssertLockHeld(cs_main); + AssertLockHeld(::cs_main); const auto& consensusParams = Params().GetConsensus(); if (!DeploymentActiveAt(*pindex, consensusParams, Consensus::DEPLOYMENT_DIP0003)) { diff --git a/src/evo/deterministicmns.h b/src/evo/deterministicmns.h index b2ed24c8b064..5b0c246a0242 100644 --- a/src/evo/deterministicmns.h +++ b/src/evo/deterministicmns.h @@ -582,7 +582,7 @@ class CDeterministicMNManager bool ProcessBlock(const CBlock& block, gsl::not_null pindex, BlockValidationState& state, const CCoinsViewCache& view, llmq::CQuorumSnapshotManager& qsnapman, const CDeterministicMNList& newList, std::optional& updatesRet) - EXCLUSIVE_LOCKS_REQUIRED(!cs, cs_main); + EXCLUSIVE_LOCKS_REQUIRED(!cs, ::cs_main); bool UndoBlock(gsl::not_null pindex, std::optional& updatesRet) EXCLUSIVE_LOCKS_REQUIRED(!cs); void UpdatedBlockTip(gsl::not_null pindex) EXCLUSIVE_LOCKS_REQUIRED(!cs); diff --git a/src/evo/mnhftx.cpp b/src/evo/mnhftx.cpp index 618a5a640a8f..c1c1e76df740 100644 --- a/src/evo/mnhftx.cpp +++ b/src/evo/mnhftx.cpp @@ -22,6 +22,8 @@ #include #include +using node::ReadBlockFromDisk; + static const std::string MNEHF_REQUESTID_PREFIX = "mnhf"; static const std::string DB_SIGNALS = "mnhf_s"; static const std::string DB_SIGNALS_v2 = "mnhf_s2"; diff --git a/src/evo/mnhftx.h b/src/evo/mnhftx.h index b59cd75dcf1e..8de6ef6c5d59 100644 --- a/src/evo/mnhftx.h +++ b/src/evo/mnhftx.h @@ -146,7 +146,7 @@ class CMNHFManager : public AbstractEHFManager */ void DisconnectManagers() { m_chainman = nullptr; m_qman = nullptr; }; - bool ForceSignalDBUpdate() EXCLUSIVE_LOCKS_REQUIRED(cs_main); + bool ForceSignalDBUpdate() EXCLUSIVE_LOCKS_REQUIRED(::cs_main); private: void AddToCache(const Signals& signals, const CBlockIndex* const pindex); diff --git a/src/evo/simplifiedmns.cpp b/src/evo/simplifiedmns.cpp index 979c8e175bc7..1812f7c811df 100644 --- a/src/evo/simplifiedmns.cpp +++ b/src/evo/simplifiedmns.cpp @@ -27,6 +27,8 @@ #include #include +using node::ReadBlockFromDisk; + CSimplifiedMNListEntry::CSimplifiedMNListEntry(const CDeterministicMN& dmn) : proRegTxHash(dmn.proTxHash), confirmedHash(dmn.pdmnState->confirmedHash), @@ -335,7 +337,7 @@ bool BuildSimplifiedMNListDiff(CDeterministicMNManager& dmnman, const Chainstate const llmq::CQuorumManager& qman, const uint256& baseBlockHash, const uint256& blockHash, CSimplifiedMNListDiff& mnListDiffRet, std::string& errorRet, bool extended) { - AssertLockHeld(cs_main); + AssertLockHeld(::cs_main); mnListDiffRet = CSimplifiedMNListDiff(); const CBlockIndex* baseBlockIndex = chainman.ActiveChain().Genesis(); diff --git a/src/evo/specialtxman.cpp b/src/evo/specialtxman.cpp index 8f7de17ab5e5..f4de428ffb1a 100644 --- a/src/evo/specialtxman.cpp +++ b/src/evo/specialtxman.cpp @@ -27,7 +27,7 @@ static bool CheckSpecialTxInner(CDeterministicMNManager& dmnman, llmq::CQuorumSn const std::optional& indexes, bool check_sigs, TxValidationState& state) EXCLUSIVE_LOCKS_REQUIRED(::cs_main) { - AssertLockHeld(cs_main); + AssertLockHeld(::cs_main); if (!tx.HasExtraPayloadField()) return true; @@ -76,7 +76,7 @@ static bool CheckSpecialTxInner(CDeterministicMNManager& dmnman, llmq::CQuorumSn bool CSpecialTxProcessor::CheckSpecialTx(const CTransaction& tx, const CBlockIndex* pindexPrev, const CCoinsViewCache& view, bool check_sigs, TxValidationState& state) { - AssertLockHeld(cs_main); + AssertLockHeld(::cs_main); return CheckSpecialTxInner(m_dmnman, m_qsnapman, m_chainman, m_qman, tx, pindexPrev, view, std::nullopt, check_sigs, state); } @@ -84,7 +84,7 @@ bool CSpecialTxProcessor::CheckSpecialTx(const CTransaction& tx, const CBlockInd bool CSpecialTxProcessor::ProcessSpecialTxsInBlock(const CBlock& block, const CBlockIndex* pindex, const CCoinsViewCache& view, bool fJustCheck, bool fCheckCbTxMerkleRoots, BlockValidationState& state, std::optional& updatesRet) { - AssertLockHeld(cs_main); + AssertLockHeld(::cs_main); try { static int64_t nTimeLoop = 0; @@ -242,7 +242,7 @@ bool CSpecialTxProcessor::ProcessSpecialTxsInBlock(const CBlock& block, const CB bool CSpecialTxProcessor::UndoSpecialTxsInBlock(const CBlock& block, const CBlockIndex* pindex, std::optional& updatesRet) { - AssertLockHeld(cs_main); + AssertLockHeld(::cs_main); auto bls_legacy_scheme = bls::bls_legacy_scheme.load(); @@ -277,7 +277,7 @@ bool CSpecialTxProcessor::UndoSpecialTxsInBlock(const CBlock& block, const CBloc bool CSpecialTxProcessor::CheckCreditPoolDiffForBlock(const CBlock& block, const CBlockIndex* pindex, const CCbTx& cbTx, BlockValidationState& state) { - AssertLockHeld(cs_main); + AssertLockHeld(::cs_main); if (!DeploymentActiveAt(*pindex, m_consensus_params, Consensus::DEPLOYMENT_DIP0008)) return true; if (!DeploymentActiveAt(*pindex, m_consensus_params, Consensus::DEPLOYMENT_V20)) return true; diff --git a/src/evo/specialtxman.h b/src/evo/specialtxman.h index ef1dd819701d..ac497f667432 100644 --- a/src/evo/specialtxman.h +++ b/src/evo/specialtxman.h @@ -64,16 +64,16 @@ class CSpecialTxProcessor } bool CheckSpecialTx(const CTransaction& tx, const CBlockIndex* pindexPrev, const CCoinsViewCache& view, bool check_sigs, TxValidationState& state) - EXCLUSIVE_LOCKS_REQUIRED(cs_main); + EXCLUSIVE_LOCKS_REQUIRED(::cs_main); bool ProcessSpecialTxsInBlock(const CBlock& block, const CBlockIndex* pindex, const CCoinsViewCache& view, bool fJustCheck, bool fCheckCbTxMerkleRoots, BlockValidationState& state, std::optional& updatesRet) - EXCLUSIVE_LOCKS_REQUIRED(cs_main); + EXCLUSIVE_LOCKS_REQUIRED(::cs_main); bool UndoSpecialTxsInBlock(const CBlock& block, const CBlockIndex* pindex, std::optional& updatesRet) - EXCLUSIVE_LOCKS_REQUIRED(cs_main); + EXCLUSIVE_LOCKS_REQUIRED(::cs_main); private: bool CheckCreditPoolDiffForBlock(const CBlock& block, const CBlockIndex* pindex, const CCbTx& cbTx, - BlockValidationState& state) EXCLUSIVE_LOCKS_REQUIRED(cs_main); + BlockValidationState& state) EXCLUSIVE_LOCKS_REQUIRED(::cs_main); }; #endif // BITCOIN_EVO_SPECIALTXMAN_H diff --git a/src/governance/governance.cpp b/src/governance/governance.cpp index 279d3b587a99..8d87a235cb37 100644 --- a/src/governance/governance.cpp +++ b/src/governance/governance.cpp @@ -194,7 +194,7 @@ PeerMsgRet CGovernanceManager::ProcessMessage(CNode& peer, CConnman& connman, Pe return {}; } - LOCK2(cs_main, cs); + LOCK2(::cs_main, cs); if (mapObjects.count(nHash) || mapPostponedObjects.count(nHash) || mapErasedGovernanceObjects.count(nHash)) { // TODO - print error code? what if it's GOVOBJ_ERROR_IMMATURE? @@ -312,7 +312,7 @@ void CGovernanceManager::AddGovernanceObject(CGovernanceObject& govobj, PeerMana govobj.UpdateSentinelVariables(tip_mn_list); //this sets local vars in object - LOCK2(cs_main, cs); + LOCK2(::cs_main, cs); std::string strError; // MAKE SURE THIS OBJECT IS OK @@ -374,7 +374,7 @@ void CGovernanceManager::CheckAndRemove() const auto tip_mn_list = Assert(m_dmnman)->GetListAtChainTip(); - LOCK2(cs_main, cs); + LOCK2(::cs_main, cs); for (const uint256& nHash : vecDirtyHashes) { auto it = mapObjects.find(nHash); @@ -701,7 +701,7 @@ std::optional CGovernanceManager::CreateGovernanceTrigg if (!sb_opt.has_value()) return std::nullopt; //TODO: Check if nHashParentIn, nRevision and nCollateralHashIn are correct - LOCK2(cs_main, cs); + LOCK2(::cs_main, cs); // Check if identical trigger (equal DataHash()) is already created (signed by other masternode) CGovernanceObject gov_sb(uint256(), 1, GetAdjustedTime(), uint256(), sb_opt.value().GetHexStrData()); @@ -748,7 +748,7 @@ void CGovernanceManager::VoteGovernanceTriggers(const std::optional& if (!pnode->CanRelay() || (fMasternodeMode && pnode->IsInboundConn())) continue; // stop early to prevent setAskFor overflow { - LOCK(cs_main); + LOCK(::cs_main); size_t nProjectedSize = peerman.GetRequestedObjectCount(pnode->GetId()) + nProjectedVotes; if (nProjectedSize > MAX_INV_SZ) continue; // to early to ask the same node diff --git a/src/governance/object.cpp b/src/governance/object.cpp index 7776fd09fb7c..53c2db8a9761 100644 --- a/src/governance/object.cpp +++ b/src/governance/object.cpp @@ -361,7 +361,7 @@ UniValue CGovernanceObject::ToJson() const void CGovernanceObject::UpdateLocalValidity(const CDeterministicMNList& tip_mn_list, const ChainstateManager& chainman) { - AssertLockHeld(cs_main); + AssertLockHeld(::cs_main); // THIS DOES NOT CHECK COLLATERAL, THIS IS CHECKED UPON ORIGINAL ARRIVAL fCachedLocalValidity = IsValidLocally(tip_mn_list, chainman, strLocalValidityError, false); } @@ -376,7 +376,7 @@ bool CGovernanceObject::IsValidLocally(const CDeterministicMNList& tip_mn_list, bool CGovernanceObject::IsValidLocally(const CDeterministicMNList& tip_mn_list, const ChainstateManager& chainman, std::string& strError, bool& fMissingConfirmations, bool fCheckCollateral) const { - AssertLockHeld(cs_main); + AssertLockHeld(::cs_main); fMissingConfirmations = false; @@ -447,7 +447,7 @@ CAmount CGovernanceObject::GetMinCollateralFee() const bool CGovernanceObject::IsCollateralValid(const ChainstateManager& chainman, std::string& strError, bool& fMissingConfirmations) const { - AssertLockHeld(cs_main); + AssertLockHeld(::cs_main); strError = ""; fMissingConfirmations = false; @@ -505,7 +505,7 @@ bool CGovernanceObject::IsCollateralValid(const ChainstateManager& chainman, std // GET CONFIRMATIONS FOR TRANSACTION - AssertLockHeld(cs_main); + AssertLockHeld(::cs_main); int nConfirmationsIn = 0; if (nBlockHash != uint256()) { const CBlockIndex* pindex = chainman.m_blockman.LookupBlockIndex(nBlockHash); diff --git a/src/governance/object.h b/src/governance/object.h index 8ced4950f939..66324a75d62b 100644 --- a/src/governance/object.h +++ b/src/governance/object.h @@ -228,15 +228,15 @@ class CGovernanceObject // CORE OBJECT FUNCTIONS - bool IsValidLocally(const CDeterministicMNList& tip_mn_list, const ChainstateManager& chainman, std::string& strError, bool fCheckCollateral) const EXCLUSIVE_LOCKS_REQUIRED(cs_main); + bool IsValidLocally(const CDeterministicMNList& tip_mn_list, const ChainstateManager& chainman, std::string& strError, bool fCheckCollateral) const EXCLUSIVE_LOCKS_REQUIRED(::cs_main); - bool IsValidLocally(const CDeterministicMNList& tip_mn_list, const ChainstateManager& chainman, std::string& strError, bool& fMissingConfirmations, bool fCheckCollateral) const EXCLUSIVE_LOCKS_REQUIRED(cs_main); + bool IsValidLocally(const CDeterministicMNList& tip_mn_list, const ChainstateManager& chainman, std::string& strError, bool& fMissingConfirmations, bool fCheckCollateral) const EXCLUSIVE_LOCKS_REQUIRED(::cs_main); /// Check the collateral transaction for the budget proposal/finalized budget - bool IsCollateralValid(const ChainstateManager& chainman, std::string& strError, bool& fMissingConfirmations) const EXCLUSIVE_LOCKS_REQUIRED(cs_main); + bool IsCollateralValid(const ChainstateManager& chainman, std::string& strError, bool& fMissingConfirmations) const EXCLUSIVE_LOCKS_REQUIRED(::cs_main); void UpdateLocalValidity(const CDeterministicMNList& tip_mn_list, const ChainstateManager& chainman) - EXCLUSIVE_LOCKS_REQUIRED(cs_main); + EXCLUSIVE_LOCKS_REQUIRED(::cs_main); void UpdateSentinelVariables(const CDeterministicMNList& tip_mn_list); diff --git a/src/index/base.cpp b/src/index/base.cpp index d596ba40025d..eab169708dae 100644 --- a/src/index/base.cpp +++ b/src/index/base.cpp @@ -13,6 +13,10 @@ #include #include +using node::PruneLockInfo; +using node::ReadBlockFromDisk; +using node::fPruneMode; + constexpr uint8_t DB_BEST_BLOCK{'B'}; constexpr auto SYNC_LOG_INTERVAL{30s}; diff --git a/src/index/blockfilterindex.cpp b/src/index/blockfilterindex.cpp index 5af98dae49bd..f21b8afe4b43 100644 --- a/src/index/blockfilterindex.cpp +++ b/src/index/blockfilterindex.cpp @@ -10,6 +10,8 @@ #include #include +using node::UndoReadFromDisk; + /* The index database stores three items for each block: the disk location of the encoded filter, * its dSHA256 hash, and the header. Those belonging to blocks on the active chain are indexed by * height, and those belonging to blocks that have been reorganized out of the active chain are diff --git a/src/index/coinstatsindex.cpp b/src/index/coinstatsindex.cpp index b93f760ef889..457590ec9c3f 100644 --- a/src/index/coinstatsindex.cpp +++ b/src/index/coinstatsindex.cpp @@ -13,6 +13,12 @@ #include #include +using node::CCoinsStats; +using node::GetBogoSize; +using node::ReadBlockFromDisk; +using node::TxOutSer; +using node::UndoReadFromDisk; + static constexpr uint8_t DB_BLOCK_HASH{'s'}; static constexpr uint8_t DB_BLOCK_HEIGHT{'t'}; static constexpr uint8_t DB_MUHASH{'M'}; diff --git a/src/index/coinstatsindex.h b/src/index/coinstatsindex.h index e93c2316a439..0eb42b1ca35d 100644 --- a/src/index/coinstatsindex.h +++ b/src/index/coinstatsindex.h @@ -56,7 +56,7 @@ class CoinStatsIndex final : public BaseIndex explicit CoinStatsIndex(size_t n_cache_size, bool f_memory = false, bool f_wipe = false); // Look up stats for a specific block using CBlockIndex - bool LookUpStats(const CBlockIndex* block_index, CCoinsStats& coins_stats) const; + bool LookUpStats(const CBlockIndex* block_index, node::CCoinsStats& coins_stats) const; }; /// The global UTXO set hash object. diff --git a/src/index/txindex.cpp b/src/index/txindex.cpp index 637e4d9565bd..75e8bea7033f 100644 --- a/src/index/txindex.cpp +++ b/src/index/txindex.cpp @@ -9,6 +9,8 @@ #include #include +using node::OpenBlockFile; + constexpr uint8_t DB_TXINDEX{'t'}; std::unique_ptr g_txindex; diff --git a/src/init.cpp b/src/init.cpp index c2d83174f052..f942e0f93ef4 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -134,6 +134,32 @@ #include #endif +using node::CacheSizes; +using node::CalculateCacheSizes; +using node::CCoinsStats; +using node::CoinStatsHashType; +using node::ChainstateLoadingError; +using node::ChainstateLoadVerifyError; +using node::DashChainstateSetupClose; +using node::DEFAULT_ADDRESSINDEX; +using node::DEFAULT_PRINTPRIORITY; +using node::DEFAULT_SPENTINDEX; +using node::DEFAULT_STOPAFTERBLOCKIMPORT; +using node::DEFAULT_TIMESTAMPINDEX; +using node::LoadChainstate; +using node::NodeContext; +using node::ThreadImport; +using node::VerifyLoadedChainstate; +using node::fAddressIndex; +using node::fPruneMode; +using node::fReindex; +using node::fSpentIndex; +using node::fTimestampIndex; +using node::nPruneTarget; +#ifdef ENABLE_WALLET +using wallet::DEFAULT_DISABLE_WALLET; +#endif // ENABLE_WALLET + static constexpr bool DEFAULT_PROXYRANDOMIZE{true}; static constexpr bool DEFAULT_REST_ENABLE{false}; static constexpr bool DEFAULT_I2P_ACCEPT_INCOMING{true}; diff --git a/src/init.h b/src/init.h index ef445a7e5926..00450e1f416d 100644 --- a/src/init.h +++ b/src/init.h @@ -17,14 +17,16 @@ static constexpr bool DEFAULT_DAEMON = false; static constexpr bool DEFAULT_DAEMONWAIT = false; class ArgsManager; -struct NodeContext; namespace interfaces { struct BlockAndHeaderTipInfo; } // namespace interfaces +namespace node { +struct NodeContext; +} // namespace node /** Interrupt threads */ -void Interrupt(NodeContext& node); -void Shutdown(NodeContext& node); +void Interrupt(node::NodeContext& node); +void Shutdown(node::NodeContext& node); //!Initialize the logging infrastructure void InitLogging(const ArgsManager& args); //!Parameter interaction: change current parameters depending on various rules @@ -56,14 +58,14 @@ bool AppInitLockDataDirectory(); /** * Initialize node and wallet interface pointers. Has no prerequisites or side effects besides allocating memory. */ -bool AppInitInterfaces(NodeContext& node); +bool AppInitInterfaces(node::NodeContext& node); /** * Dash Core main initialization. * @note This should only be done after daemonization. Call Shutdown() if this function fails. * @pre Parameters should be parsed and config file should be read, AppInitLockDataDirectory should have been called. */ -bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info = nullptr); -void PrepareShutdown(NodeContext& node); +bool AppInitMain(node::NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info = nullptr); +void PrepareShutdown(node::NodeContext& node); /** * Register all arguments with the ArgsManager diff --git a/src/init/bitcoin-node.cpp b/src/init/bitcoin-node.cpp index b64f663a2377..bf7f935d24ed 100644 --- a/src/init/bitcoin-node.cpp +++ b/src/init/bitcoin-node.cpp @@ -22,7 +22,7 @@ const char* EXE_NAME = "dash-node"; class BitcoinNodeInit : public interfaces::Init { public: - BitcoinNodeInit(NodeContext& node, const char* arg0) + BitcoinNodeInit(node::NodeContext& node, const char* arg0) : m_node(node), m_ipc(interfaces::MakeIpc(EXE_NAME, arg0, *this)) { @@ -41,14 +41,14 @@ class BitcoinNodeInit : public interfaces::Init } std::unique_ptr makeEcho() override { return interfaces::MakeEcho(); } interfaces::Ipc* ipc() override { return m_ipc.get(); } - NodeContext& m_node; + node::NodeContext& m_node; std::unique_ptr m_ipc; }; } // namespace } // namespace init namespace interfaces { -std::unique_ptr MakeNodeInit(NodeContext& node, int argc, char* argv[], int& exit_status) +std::unique_ptr MakeNodeInit(node::NodeContext& node, int argc, char* argv[], int& exit_status) { auto init = std::make_unique(node, argc > 0 ? argv[0] : ""); // Check if bitcoin-node is being invoked as an IPC server. If so, then diff --git a/src/init/bitcoind.cpp b/src/init/bitcoind.cpp index 4b6f23ded92c..aafb27ddfca9 100644 --- a/src/init/bitcoind.cpp +++ b/src/init/bitcoind.cpp @@ -14,6 +14,8 @@ #include +using node::NodeContext; + namespace init { namespace { class BitcoindInit : public interfaces::Init diff --git a/src/interfaces/chain.h b/src/interfaces/chain.h index 6a8dd5bbc3c8..bb5058f8ea80 100644 --- a/src/interfaces/chain.h +++ b/src/interfaces/chain.h @@ -31,13 +31,13 @@ enum class MemPoolRemovalReason; struct bilingual_str; struct CBlockLocator; struct FeeCalculation; -struct NodeContext; -enum class MemPoolRemovalReason; - namespace llmq { class CChainLockSig; struct CInstantSendLock; } // namespace llmq +namespace node { +struct NodeContext; +} // namespace node typedef std::shared_ptr CTransactionRef; @@ -339,7 +339,7 @@ class ChainClient }; //! Return implementation of Chain interface. -std::unique_ptr MakeChain(NodeContext& node); +std::unique_ptr MakeChain(node::NodeContext& node); } // namespace interfaces diff --git a/src/interfaces/coinjoin.h b/src/interfaces/coinjoin.h index a96c524080e7..7a7706441f1d 100644 --- a/src/interfaces/coinjoin.h +++ b/src/interfaces/coinjoin.h @@ -9,8 +9,12 @@ #include #include -class CWallet; +namespace node { struct NodeContext; +} // namespace node +namespace wallet { +class CWallet; +} // namespace wallet class UniValue; @@ -38,7 +42,7 @@ class Loader public: virtual ~Loader() {} //! Add new wallet to CoinJoin client manager - virtual void AddWallet(const std::shared_ptr&) = 0; + virtual void AddWallet(const std::shared_ptr&) = 0; //! Remove wallet from CoinJoin client manager virtual void RemoveWallet(const std::string&) = 0; virtual void FlushWallet(const std::string&) = 0; @@ -46,7 +50,7 @@ class Loader }; } // namespace CoinJoin -std::unique_ptr MakeCoinJoinLoader(NodeContext& node); +std::unique_ptr MakeCoinJoinLoader(node::NodeContext& node); } // namespace interfaces diff --git a/src/interfaces/init.h b/src/interfaces/init.h index c1c6edab8148..2679e33d5cb3 100644 --- a/src/interfaces/init.h +++ b/src/interfaces/init.h @@ -7,7 +7,9 @@ #include +namespace node { struct NodeContext; +} // namespace node namespace interfaces { class Chain; @@ -44,7 +46,7 @@ class Init //! status code to exit with. If this returns non-null, the caller can start up //! normally and use the Init object to spawn and connect to other processes //! while it is running. -std::unique_ptr MakeNodeInit(NodeContext& node, int argc, char* argv[], int& exit_status); +std::unique_ptr MakeNodeInit(node::NodeContext& node, int argc, char* argv[], int& exit_status); //! Return implementation of Init interface for the wallet process. std::unique_ptr MakeWalletInit(int argc, char* argv[], int& exit_status); diff --git a/src/interfaces/node.h b/src/interfaces/node.h index 088423986a02..88f38241b964 100644 --- a/src/interfaces/node.h +++ b/src/interfaces/node.h @@ -24,7 +24,6 @@ class BanMan; class CBlockIndex; -class CCoinControl; class CDeterministicMNList; class CFeeRate; class CGovernanceObject; @@ -33,20 +32,24 @@ class Coin; class RPCTimerInterface; class UniValue; class Proxy; -struct bilingual_str; enum class SynchronizationState; enum class TransactionError; +enum vote_signal_enum_t : int; +struct bilingual_str; struct CNodeStateStats; +namespace node { struct NodeContext; - -enum vote_signal_enum_t : int; +} // namespace node +namespace wallet { +class CCoinControl; +} // namespace wallet namespace interfaces { class Handler; class WalletLoader; namespace CoinJoin { class Loader; -} //namespsace CoinJoin +} // namespace CoinJoin struct BlockTip; //! Interface for the src/evo part of a dash node (dashd process). @@ -55,7 +58,7 @@ class EVO public: virtual ~EVO() {} virtual std::pair getListAtChainTip() = 0; - virtual void setContext(NodeContext* context) {} + virtual void setContext(node::NodeContext* context) {} }; //! Interface for the src/governance part of a dash node (dashd process). @@ -67,7 +70,7 @@ class GOV virtual int32_t getObjAbsYesCount(const CGovernanceObject& obj, vote_signal_enum_t vote_signal) = 0; virtual bool getObjLocalValidity(const CGovernanceObject& obj, std::string& error, bool check_collateral) = 0; virtual bool isEnabled() = 0; - virtual void setContext(NodeContext* context) {} + virtual void setContext(node::NodeContext* context) {} }; //! Interface for the src/llmq part of a dash node (dashd process). @@ -76,7 +79,7 @@ class LLMQ public: virtual ~LLMQ() {} virtual size_t getInstantSentLockCount() = 0; - virtual void setContext(NodeContext* context) {} + virtual void setContext(node::NodeContext* context) {} }; //! Interface for the src/masternode part of a dash node (dashd process). @@ -89,7 +92,7 @@ class Sync virtual bool isBlockchainSynced() = 0; virtual bool isSynced() = 0; virtual std::string getSyncStatus() = 0; - virtual void setContext(NodeContext* context) {} + virtual void setContext(node::NodeContext* context) {} }; } @@ -354,12 +357,12 @@ class Node //! Get and set internal node context. Useful for testing, but not //! accessible across processes. - virtual NodeContext* context() { return nullptr; } - virtual void setContext(NodeContext* context) { } + virtual node::NodeContext* context() { return nullptr; } + virtual void setContext(node::NodeContext* context) { } }; //! Return implementation of Node interface. -std::unique_ptr MakeNode(NodeContext& context); +std::unique_ptr MakeNode(node::NodeContext& context); //! Block tip (could be a header or not, depends on the subscribed signal). struct BlockTip { diff --git a/src/interfaces/wallet.h b/src/interfaces/wallet.h index c0fbd86cfc2f..4732fe4a1e42 100644 --- a/src/interfaces/wallet.h +++ b/src/interfaces/wallet.h @@ -25,21 +25,26 @@ #include #include -class CCoinControl; class CFeeRate; class CKey; class CRPCCommand; -class CWallet; -class UniValue; enum class FeeReason; enum class TransactionError; +struct bilingual_str; +struct PartiallySignedTransaction; +namespace node { +struct NodeContext; +} // namespace node +namespace wallet { +class CCoinControl; +class CWallet; enum isminetype : unsigned int; struct CRecipient; -struct NodeContext; -struct PartiallySignedTransaction; struct WalletContext; -struct bilingual_str; using isminefilter = std::underlying_type::type; +} // namespace wallet + +class UniValue; template class Span; @@ -130,7 +135,7 @@ class Wallet //! Look up address in wallet, return whether exists. virtual bool getAddress(const CTxDestination& dest, std::string* name, - isminetype* is_mine, + wallet::isminetype* is_mine, std::string* purpose) = 0; //! Get wallet address list. @@ -158,8 +163,8 @@ class Wallet virtual std::vector listProTxCoins() = 0; //! Create transaction. - virtual CTransactionRef createTransaction(const std::vector& recipients, - const CCoinControl& coin_control, + virtual CTransactionRef createTransaction(const std::vector& recipients, + const wallet::CCoinControl& coin_control, bool sign, int& change_pos, CAmount& fee, @@ -237,19 +242,19 @@ class Wallet virtual CAmount getAverageAnonymizedRounds() = 0; //! Get available balance. - virtual CAmount getAvailableBalance(const CCoinControl& coin_control) = 0; + virtual CAmount getAvailableBalance(const wallet::CCoinControl& coin_control) = 0; //! Return whether transaction input belongs to wallet. - virtual isminetype txinIsMine(const CTxIn& txin) = 0; + virtual wallet::isminetype txinIsMine(const CTxIn& txin) = 0; //! Return whether transaction output belongs to wallet. - virtual isminetype txoutIsMine(const CTxOut& txout) = 0; + virtual wallet::isminetype txoutIsMine(const CTxOut& txout) = 0; //! Return debit amount if transaction input belongs to wallet. - virtual CAmount getDebit(const CTxIn& txin, isminefilter filter) = 0; + virtual CAmount getDebit(const CTxIn& txin, wallet::isminefilter filter) = 0; //! Return credit amount if transaction input belongs to wallet. - virtual CAmount getCredit(const CTxOut& txout, isminefilter filter) = 0; + virtual CAmount getCredit(const CTxOut& txout, wallet::isminefilter filter) = 0; //! Return AvailableCoins + LockedCoins grouped by wallet address. //! (put change in one group with wallet address) @@ -264,7 +269,7 @@ class Wallet //! Get minimum fee. virtual CAmount getMinimumFee(unsigned int tx_bytes, - const CCoinControl& coin_control, + const wallet::CCoinControl& coin_control, int* returned_target, FeeReason* reason) = 0; @@ -330,7 +335,7 @@ class Wallet virtual std::unique_ptr handleCanGetAddressesChanged(CanGetAddressesChangedFn fn) = 0; //! Return pointer to internal wallet class, useful for testing. - virtual CWallet* wallet() { return nullptr; } + virtual wallet::CWallet* wallet() { return nullptr; } }; //! Wallet chain client that in addition to having chain client methods for @@ -367,18 +372,18 @@ class WalletLoader : public ChainClient virtual std::unique_ptr handleLoadWallet(LoadWalletFn fn) = 0; //! Return pointer to internal context, useful for testing. - virtual WalletContext* context() { return nullptr; } + virtual wallet::WalletContext* context() { return nullptr; } }; //! Information about one wallet address. struct WalletAddress { CTxDestination dest; - isminetype is_mine; + wallet::isminetype is_mine; std::string name; std::string purpose; - WalletAddress(CTxDestination dest, isminetype is_mine, std::string name, std::string purpose) + WalletAddress(CTxDestination dest, wallet::isminetype is_mine, std::string name, std::string purpose) : dest(std::move(dest)), is_mine(is_mine), name(std::move(name)), purpose(std::move(purpose)) { } @@ -411,10 +416,10 @@ struct WalletBalances struct WalletTx { CTransactionRef tx; - std::vector txin_is_mine; - std::vector txout_is_mine; + std::vector txin_is_mine; + std::vector txout_is_mine; std::vector txout_address; - std::vector txout_address_is_mine; + std::vector txout_address_is_mine; CAmount credit; CAmount debit; CAmount change; @@ -452,11 +457,11 @@ struct WalletTxOut //! Return implementation of Wallet interface. This function is defined in //! dummywallet.cpp and throws if the wallet component is not compiled. -std::unique_ptr MakeWallet(WalletContext& context, const std::shared_ptr& wallet); +std::unique_ptr MakeWallet(wallet::WalletContext& context, const std::shared_ptr& wallet); //! Return implementation of ChainClient interface for a wallet loader. This //! function will be undefined in builds where ENABLE_WALLET is false. -std::unique_ptr MakeWalletLoader(Chain& chain, ArgsManager& args, NodeContext& node_context, +std::unique_ptr MakeWalletLoader(Chain& chain, ArgsManager& args, node::NodeContext& node_context, CoinJoin::Loader& coinjoin_loader); } // namespace interfaces diff --git a/src/llmq/blockprocessor.cpp b/src/llmq/blockprocessor.cpp index c5b968e5adfd..e554948a7429 100644 --- a/src/llmq/blockprocessor.cpp +++ b/src/llmq/blockprocessor.cpp @@ -85,7 +85,7 @@ MessageProcessingResult CQuorumBlockProcessor::ProcessMessage(const CNode& peer, // Verify that quorumHash is part of the active chain and that it's the first block in the DKG interval const CBlockIndex* pQuorumBaseBlockIndex; { - LOCK(cs_main); + LOCK(::cs_main); pQuorumBaseBlockIndex = m_chainstate.m_blockman.LookupBlockIndex(qc.quorumHash); if (pQuorumBaseBlockIndex == nullptr) { LogPrint(BCLog::LLMQ, "CQuorumBlockProcessor::%s -- unknown block %s in commitment, peer=%d\n", __func__, @@ -153,7 +153,7 @@ MessageProcessingResult CQuorumBlockProcessor::ProcessMessage(const CNode& peer, bool CQuorumBlockProcessor::ProcessBlock(const CBlock& block, gsl::not_null pindex, BlockValidationState& state, bool fJustCheck, bool fBLSChecks) { - AssertLockHeld(cs_main); + AssertLockHeld(::cs_main); const auto blockHash = pindex->GetBlockHash(); @@ -222,7 +222,7 @@ static std::tuple BuildInversed bool CQuorumBlockProcessor::ProcessCommitment(int nHeight, const uint256& blockHash, const CFinalCommitment& qc, BlockValidationState& state, bool fJustCheck, bool fBLSChecks) { - AssertLockHeld(cs_main); + AssertLockHeld(::cs_main); const auto& llmq_params_opt = Params().GetLLMQ(qc.llmqType); if (!llmq_params_opt.has_value()) { @@ -315,7 +315,7 @@ bool CQuorumBlockProcessor::ProcessCommitment(int nHeight, const uint256& blockH bool CQuorumBlockProcessor::UndoBlock(const CBlock& block, gsl::not_null pindex) { - AssertLockHeld(cs_main); + AssertLockHeld(::cs_main); PreComputeQuorumMembers(m_dmnman, m_qsnapman, pindex, /*reset_cache=*/true); @@ -354,7 +354,7 @@ bool CQuorumBlockProcessor::UndoBlock(const CBlock& block, gsl::not_null pindex, std::multimap& ret, BlockValidationState& state) { - AssertLockHeld(cs_main); + AssertLockHeld(::cs_main); const auto& consensus = Params().GetConsensus(); @@ -396,7 +396,7 @@ bool CQuorumBlockProcessor::GetCommitmentsFromBlock(const CBlock& block, gsl::no bool CQuorumBlockProcessor::IsMiningPhase(const Consensus::LLMQParams& llmqParams, const CChain& active_chain, int nHeight) { - AssertLockHeld(cs_main); + AssertLockHeld(::cs_main); // Note: This function can be called for new blocks assert(nHeight <= active_chain.Height() + 1); @@ -416,7 +416,7 @@ bool CQuorumBlockProcessor::IsMiningPhase(const Consensus::LLMQParams& llmqParam size_t CQuorumBlockProcessor::GetNumCommitmentsRequired(const Consensus::LLMQParams& llmqParams, int nHeight) const { - AssertLockHeld(cs_main); + AssertLockHeld(::cs_main); if (!IsMiningPhase(llmqParams, m_chainstate.m_chain, nHeight)) return 0; @@ -439,7 +439,7 @@ size_t CQuorumBlockProcessor::GetNumCommitmentsRequired(const Consensus::LLMQPar // WARNING: This method returns uint256() on the first block of the DKG interval (because the block hash is not known yet) uint256 CQuorumBlockProcessor::GetQuorumBlockHash(const Consensus::LLMQParams& llmqParams, const CChain& active_chain, int nHeight, int quorumIndex) { - AssertLockHeld(cs_main); + AssertLockHeld(::cs_main); int quorumStartHeight = nHeight - (nHeight % llmqParams.dkgInterval) + quorumIndex; @@ -689,7 +689,7 @@ bool CQuorumBlockProcessor::GetMineableCommitmentByHash(const uint256& commitmen // Will return a null commitment if no mineable commitment is known and none was mined yet std::optional> CQuorumBlockProcessor::GetMineableCommitments(const Consensus::LLMQParams& llmqParams, int nHeight) const { - AssertLockHeld(cs_main); + AssertLockHeld(::cs_main); std::vector ret; @@ -744,7 +744,7 @@ std::optional> CQuorumBlockProcessor::GetMineableC bool CQuorumBlockProcessor::GetMineableCommitmentsTx(const Consensus::LLMQParams& llmqParams, int nHeight, std::vector& ret) const { - AssertLockHeld(cs_main); + AssertLockHeld(::cs_main); std::optional> qcs = GetMineableCommitments(llmqParams, nHeight); if (!qcs.has_value()) { return false; diff --git a/src/llmq/blockprocessor.h b/src/llmq/blockprocessor.h index ff9dadf7aa4b..170e0007f742 100644 --- a/src/llmq/blockprocessor.h +++ b/src/llmq/blockprocessor.h @@ -55,15 +55,15 @@ class CQuorumBlockProcessor MessageProcessingResult ProcessMessage(const CNode& peer, std::string_view msg_type, CDataStream& vRecv); - bool ProcessBlock(const CBlock& block, gsl::not_null pindex, BlockValidationState& state, bool fJustCheck, bool fBLSChecks) EXCLUSIVE_LOCKS_REQUIRED(cs_main); - bool UndoBlock(const CBlock& block, gsl::not_null pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main); + bool ProcessBlock(const CBlock& block, gsl::not_null pindex, BlockValidationState& state, bool fJustCheck, bool fBLSChecks) EXCLUSIVE_LOCKS_REQUIRED(::cs_main); + bool UndoBlock(const CBlock& block, gsl::not_null pindex) EXCLUSIVE_LOCKS_REQUIRED(::cs_main); //! it returns hash of commitment if it should be relay, otherwise nullopt std::optional AddMineableCommitment(const CFinalCommitment& fqc); bool HasMineableCommitment(const uint256& hash) const; bool GetMineableCommitmentByHash(const uint256& commitmentHash, CFinalCommitment& ret) const; - std::optional> GetMineableCommitments(const Consensus::LLMQParams& llmqParams, int nHeight) const EXCLUSIVE_LOCKS_REQUIRED(cs_main); - bool GetMineableCommitmentsTx(const Consensus::LLMQParams& llmqParams, int nHeight, std::vector& ret) const EXCLUSIVE_LOCKS_REQUIRED(cs_main); + std::optional> GetMineableCommitments(const Consensus::LLMQParams& llmqParams, int nHeight) const EXCLUSIVE_LOCKS_REQUIRED(::cs_main); + bool GetMineableCommitmentsTx(const Consensus::LLMQParams& llmqParams, int nHeight, std::vector& ret) const EXCLUSIVE_LOCKS_REQUIRED(::cs_main); bool HasMinedCommitment(Consensus::LLMQType llmqType, const uint256& quorumHash) const; CFinalCommitmentPtr GetMinedCommitment(Consensus::LLMQType llmqType, const uint256& quorumHash, uint256& retMinedBlockHash) const; @@ -74,11 +74,11 @@ class CQuorumBlockProcessor std::vector> GetLastMinedCommitmentsPerQuorumIndexUntilBlock(Consensus::LLMQType llmqType, const CBlockIndex* pindex, size_t cycle) const; std::optional GetLastMinedCommitmentsByQuorumIndexUntilBlock(Consensus::LLMQType llmqType, const CBlockIndex* pindex, int quorumIndex, size_t cycle) const; private: - static bool GetCommitmentsFromBlock(const CBlock& block, gsl::not_null pindex, std::multimap& ret, BlockValidationState& state) EXCLUSIVE_LOCKS_REQUIRED(cs_main); - bool ProcessCommitment(int nHeight, const uint256& blockHash, const CFinalCommitment& qc, BlockValidationState& state, bool fJustCheck, bool fBLSChecks) EXCLUSIVE_LOCKS_REQUIRED(cs_main); - static bool IsMiningPhase(const Consensus::LLMQParams& llmqParams, const CChain& active_chain, int nHeight) EXCLUSIVE_LOCKS_REQUIRED(cs_main); - size_t GetNumCommitmentsRequired(const Consensus::LLMQParams& llmqParams, int nHeight) const EXCLUSIVE_LOCKS_REQUIRED(cs_main); - static uint256 GetQuorumBlockHash(const Consensus::LLMQParams& llmqParams, const CChain& active_chain, int nHeight, int quorumIndex) EXCLUSIVE_LOCKS_REQUIRED(cs_main); + static bool GetCommitmentsFromBlock(const CBlock& block, gsl::not_null pindex, std::multimap& ret, BlockValidationState& state) EXCLUSIVE_LOCKS_REQUIRED(::cs_main); + bool ProcessCommitment(int nHeight, const uint256& blockHash, const CFinalCommitment& qc, BlockValidationState& state, bool fJustCheck, bool fBLSChecks) EXCLUSIVE_LOCKS_REQUIRED(::cs_main); + static bool IsMiningPhase(const Consensus::LLMQParams& llmqParams, const CChain& active_chain, int nHeight) EXCLUSIVE_LOCKS_REQUIRED(::cs_main); + size_t GetNumCommitmentsRequired(const Consensus::LLMQParams& llmqParams, int nHeight) const EXCLUSIVE_LOCKS_REQUIRED(::cs_main); + static uint256 GetQuorumBlockHash(const Consensus::LLMQParams& llmqParams, const CChain& active_chain, int nHeight, int quorumIndex) EXCLUSIVE_LOCKS_REQUIRED(::cs_main); }; } // namespace llmq diff --git a/src/llmq/chainlocks.cpp b/src/llmq/chainlocks.cpp index bd49fd0ad6ad..3364fa3b6637 100644 --- a/src/llmq/chainlocks.cpp +++ b/src/llmq/chainlocks.cpp @@ -24,6 +24,8 @@ #include #include +using node::ReadBlockFromDisk; + static bool ChainLocksSigningEnabled(const CSporkManager& sporkman) { return sporkman.GetSporkValue(SPORK_19_CHAINLOCKS_ENABLED) == 0; @@ -121,7 +123,7 @@ MessageProcessingResult CChainLocksHandler::ProcessNewChainLock(const NodeId fro return {}; } - const CBlockIndex* pindex = WITH_LOCK(cs_main, return m_chainstate.m_blockman.LookupBlockIndex(clsig.getBlockHash())); + const CBlockIndex* pindex = WITH_LOCK(::cs_main, return m_chainstate.m_blockman.LookupBlockIndex(clsig.getBlockHash())); { LOCK(cs); @@ -237,7 +239,7 @@ void CChainLocksHandler::TrySignChainTip(const llmq::CInstantSendManager& isman) return; } - const CBlockIndex* pindex = WITH_LOCK(cs_main, return m_chainstate.m_chain.Tip()); + const CBlockIndex* pindex = WITH_LOCK(::cs_main, return m_chainstate.m_chain.Tip()); if (pindex->pprev == nullptr) { return; @@ -404,7 +406,7 @@ CChainLocksHandler::BlockTxs::mapped_type CChainLocksHandler::GetBlockTxs(const uint32_t blockTime; { - LOCK(cs_main); + LOCK(::cs_main); const auto* pindex = m_chainstate.m_blockman.LookupBlockIndex(blockHash); CBlock block; if (!ReadBlockFromDisk(block, pindex, Params().GetConsensus())) { @@ -485,7 +487,7 @@ void CChainLocksHandler::EnforceBestChainLock() LogPrintf("CChainLocksHandler::%s -- ActivateBestChain failed: %s\n", __func__, dummy_state.ToString()); return; } - LOCK(cs_main); + LOCK(::cs_main); if (m_chainstate.m_chain.Tip()->GetAncestor(currentBestChainLockBlockIndex->nHeight) != currentBestChainLockBlockIndex) { return; } @@ -619,7 +621,7 @@ void CChainLocksHandler::Cleanup() } } // need mempool.cs due to GetTransaction calls - LOCK2(cs_main, mempool.cs); + LOCK2(::cs_main, mempool.cs); LOCK(cs); for (auto it = blockTxs.begin(); it != blockTxs.end(); ) { diff --git a/src/llmq/commitment.cpp b/src/llmq/commitment.cpp index 3586e2159750..345a113219de 100644 --- a/src/llmq/commitment.cpp +++ b/src/llmq/commitment.cpp @@ -212,7 +212,7 @@ bool CheckLLMQCommitment(CDeterministicMNManager& dmnman, CQuorumSnapshotManager return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-qc-height"); } - const CBlockIndex* pQuorumBaseBlockIndex = WITH_LOCK(cs_main, return chainman.m_blockman.LookupBlockIndex(qcTx.commitment.quorumHash)); + const CBlockIndex* pQuorumBaseBlockIndex = WITH_LOCK(::cs_main, return chainman.m_blockman.LookupBlockIndex(qcTx.commitment.quorumHash)); if (pQuorumBaseBlockIndex == nullptr) { return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-qc-quorum-hash"); } diff --git a/src/llmq/debug.cpp b/src/llmq/debug.cpp index 51b1fae24020..0952c3f52192 100644 --- a/src/llmq/debug.cpp +++ b/src/llmq/debug.cpp @@ -26,7 +26,7 @@ UniValue CDKGDebugSessionStatus::ToJson(CDeterministicMNManager& dmnman, CQuorum std::vector dmnMembers; if (detailLevel == 2) { - const CBlockIndex* pindex = WITH_LOCK(cs_main, return chainman.m_blockman.LookupBlockIndex(quorumHash)); + const CBlockIndex* pindex = WITH_LOCK(::cs_main, return chainman.m_blockman.LookupBlockIndex(quorumHash)); if (pindex != nullptr) { dmnMembers = utils::GetAllQuorumMembers(llmqType, dmnman, qsnapman, pindex); } diff --git a/src/llmq/dkgsessionhandler.cpp b/src/llmq/dkgsessionhandler.cpp index c823066f7e09..beb111533e9e 100644 --- a/src/llmq/dkgsessionhandler.cpp +++ b/src/llmq/dkgsessionhandler.cpp @@ -535,7 +535,7 @@ void CDKGSessionHandler::HandleDKGRound(CConnman& connman, PeerManager& peerman) pendingPrematureCommitments.Clear(); uint256 curQuorumHash = WITH_LOCK(cs_phase_qhash, return quorumHash); - const CBlockIndex* pQuorumBaseBlockIndex = WITH_LOCK(cs_main, return m_chainstate.m_blockman.LookupBlockIndex(curQuorumHash)); + const CBlockIndex* pQuorumBaseBlockIndex = WITH_LOCK(::cs_main, return m_chainstate.m_blockman.LookupBlockIndex(curQuorumHash)); if (!InitNewQuorum(pQuorumBaseBlockIndex)) { // should actually never happen diff --git a/src/llmq/dkgsessionmgr.cpp b/src/llmq/dkgsessionmgr.cpp index 43a9f4acd203..f0169b86b713 100644 --- a/src/llmq/dkgsessionmgr.cpp +++ b/src/llmq/dkgsessionmgr.cpp @@ -155,7 +155,7 @@ PeerMsgRet CDKGSessionManager::ProcessMessage(CNode& pfrom, PeerManager& peerman // No luck, try to compute if (quorumIndex == -1) { - CBlockIndex* pQuorumBaseBlockIndex = WITH_LOCK(cs_main, return m_chainstate.m_blockman.LookupBlockIndex(quorumHash)); + CBlockIndex* pQuorumBaseBlockIndex = WITH_LOCK(::cs_main, return m_chainstate.m_blockman.LookupBlockIndex(quorumHash)); if (pQuorumBaseBlockIndex == nullptr) { LogPrintf("CDKGSessionManager -- unknown quorumHash %s\n", quorumHash.ToString()); // NOTE: do not insta-ban for this, we might be lagging behind @@ -408,7 +408,7 @@ void CDKGSessionManager::CleanupOldContributions() const decltype(start) k; pcursor->Seek(start); - LOCK(cs_main); + LOCK(::cs_main); while (pcursor->Valid()) { if (!pcursor->GetKey(k) || std::get<0>(k) != prefix || std::get<1>(k) != params.type) { break; diff --git a/src/llmq/ehf_signals.cpp b/src/llmq/ehf_signals.cpp index c5388e46dd5e..3272acb8a166 100644 --- a/src/llmq/ehf_signals.cpp +++ b/src/llmq/ehf_signals.cpp @@ -101,7 +101,7 @@ MessageProcessingResult CEHFSignalsHandler::HandleNewRecoveredSig(const CRecover } MessageProcessingResult ret; - const auto ehfSignals = mnhfman.GetSignalsStage(WITH_LOCK(cs_main, return m_chainman.ActiveTip())); + 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 @@ -123,7 +123,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); + LOCK(::cs_main); 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()); diff --git a/src/llmq/instantsend.cpp b/src/llmq/instantsend.cpp index 2b52deeb8f3c..a700605a00ea 100644 --- a/src/llmq/instantsend.cpp +++ b/src/llmq/instantsend.cpp @@ -28,6 +28,9 @@ #include +using node::fImporting; +using node::fReindex; + namespace llmq { @@ -588,7 +591,7 @@ bool CInstantSendManager::CheckCanLock(const COutPoint& outpoint, bool printDebu const CBlockIndex* pindexMined; int nTxAge; { - LOCK(cs_main); + LOCK(::cs_main); pindexMined = m_chainstate.m_blockman.LookupBlockIndex(hashBlock); nTxAge = m_chainstate.m_chain.Height() - pindexMined->nHeight + 1; } @@ -761,7 +764,7 @@ PeerMsgRet CInstantSendManager::ProcessMessageInstantSendLock(const CNode& pfrom return tl::unexpected{100}; } - const auto blockIndex = WITH_LOCK(cs_main, return m_chainstate.m_blockman.LookupBlockIndex(islock->cycleHash)); + const auto blockIndex = WITH_LOCK(::cs_main, return m_chainstate.m_blockman.LookupBlockIndex(islock->cycleHash)); if (blockIndex == nullptr) { // Maybe we don't have the block yet or maybe some peer spams invalid values for cycleHash return tl::unexpected{1}; @@ -921,7 +924,7 @@ std::unordered_set CInstantSendManager::ProcessPend continue; } - const auto blockIndex = WITH_LOCK(cs_main, return m_chainstate.m_blockman.LookupBlockIndex(islock->cycleHash)); + const auto blockIndex = WITH_LOCK(::cs_main, return m_chainstate.m_blockman.LookupBlockIndex(islock->cycleHash)); if (blockIndex == nullptr) { batchVerifier.badSources.emplace(nodeId); continue; @@ -960,7 +963,7 @@ std::unordered_set CInstantSendManager::ProcessPend std::unordered_set badISLocks; if (ban && !batchVerifier.badSources.empty()) { - LOCK(cs_main); + LOCK(::cs_main); for (const auto& nodeId : batchVerifier.badSources) { // Let's not be too harsh, as the peer might simply be unlucky and might have sent us an old lock which // does not validate anymore due to changed quorums @@ -1015,7 +1018,7 @@ void CInstantSendManager::ProcessInstantSendLock(NodeId from, PeerManager& peerm const CBlockIndex* pindexMined{nullptr}; // we ignore failure here as we must be able to propagate the lock even if we don't have the TX locally if (tx && !hashBlock.IsNull()) { - pindexMined = WITH_LOCK(cs_main, return m_chainstate.m_blockman.LookupBlockIndex(hashBlock)); + pindexMined = WITH_LOCK(::cs_main, return m_chainstate.m_blockman.LookupBlockIndex(hashBlock)); // Let's see if the TX that was locked by this islock is already mined in a ChainLocked block. If yes, // we can simply ignore the islock, as the ChainLock implies locking of all TXs in that chain @@ -1434,7 +1437,7 @@ void CInstantSendManager::ResolveBlockConflicts(const uint256& islockHash, const activateBestChain = true; } else { LogPrintf("CInstantSendManager::%s -- resetting block %s\n", __func__, pindex2->GetBlockHash().ToString()); - LOCK(cs_main); + LOCK(::cs_main); m_chainstate.ResetBlockFailureFlags(pindex2); } } @@ -1453,7 +1456,7 @@ void CInstantSendManager::RemoveConflictingLock(const uint256& islockHash, const { LogPrintf("CInstantSendManager::%s -- txid=%s, islock=%s: Removing ISLOCK and its chained children\n", __func__, islock.txid.ToString(), islockHash.ToString()); - int tipHeight = WITH_LOCK(cs_main, return m_chainstate.m_chain.Height()); + int tipHeight = WITH_LOCK(::cs_main, return m_chainstate.m_chain.Height()); auto removedIslocks = db.RemoveChainedInstantSendLocks(islockHash, islock.txid, tipHeight); for (const auto& h : removedIslocks) { diff --git a/src/llmq/quorums.cpp b/src/llmq/quorums.cpp index 0b01f2a46572..de1b3815c59b 100644 --- a/src/llmq/quorums.cpp +++ b/src/llmq/quorums.cpp @@ -527,7 +527,7 @@ bool CQuorumManager::RequestQuorumData(CNode* pfrom, CConnman& connman, CQuorumC std::vector CQuorumManager::ScanQuorums(Consensus::LLMQType llmqType, size_t nCountRequested) const { - const CBlockIndex* pindex = WITH_LOCK(cs_main, return m_chainstate.m_chain.Tip()); + const CBlockIndex* pindex = WITH_LOCK(::cs_main, return m_chainstate.m_chain.Tip()); return ScanQuorums(llmqType, pindex, nCountRequested); } @@ -647,7 +647,7 @@ CQuorumCPtr CQuorumManager::GetQuorum(Consensus::LLMQType llmqType, const uint25 // We cannot acquire cs_main if we have cs_quorumBaseBlockIndexCache held const CBlockIndex* pindex; if (!WITH_LOCK(cs_quorumBaseBlockIndexCache, return quorumBaseBlockIndexCache.get(quorumHash, pindex))) { - pindex = WITH_LOCK(cs_main, return m_chainstate.m_blockman.LookupBlockIndex(quorumHash)); + pindex = WITH_LOCK(::cs_main, return m_chainstate.m_blockman.LookupBlockIndex(quorumHash)); if (pindex) { LOCK(cs_quorumBaseBlockIndexCache); quorumBaseBlockIndexCache.insert(quorumHash, pindex); @@ -750,7 +750,7 @@ PeerMsgRet CQuorumManager::ProcessMessage(CNode& pfrom, CConnman& connman, const bool request_limit_exceeded(false); { - LOCK2(cs_main, cs_data_requests); + LOCK2(::cs_main, cs_data_requests); const CQuorumDataRequestKey key(pfrom.GetVerifiedProRegTxHash(), false, request.GetQuorumHash(), request.GetLLMQType()); auto it = mapQuorumDataRequests.find(key); if (it == mapQuorumDataRequests.end()) { @@ -766,7 +766,7 @@ PeerMsgRet CQuorumManager::ProcessMessage(CNode& pfrom, CConnman& connman, const return sendQDATA(CQuorumDataRequest::Errors::QUORUM_TYPE_INVALID, request_limit_exceeded); } - const CBlockIndex* pQuorumBaseBlockIndex = WITH_LOCK(cs_main, return m_chainstate.m_blockman.LookupBlockIndex(request.GetQuorumHash())); + const CBlockIndex* pQuorumBaseBlockIndex = WITH_LOCK(::cs_main, return m_chainstate.m_blockman.LookupBlockIndex(request.GetQuorumHash())); if (pQuorumBaseBlockIndex == nullptr) { return sendQDATA(CQuorumDataRequest::Errors::QUORUM_BLOCK_NOT_FOUND, request_limit_exceeded); } @@ -815,7 +815,7 @@ PeerMsgRet CQuorumManager::ProcessMessage(CNode& pfrom, CConnman& connman, const vRecv >> request; { - LOCK2(cs_main, cs_data_requests); + LOCK2(::cs_main, cs_data_requests); const CQuorumDataRequestKey key(pfrom.GetVerifiedProRegTxHash(), true, request.GetQuorumHash(), request.GetLLMQType()); auto it = mapQuorumDataRequests.find(key); if (it == mapQuorumDataRequests.end()) { @@ -1214,7 +1214,7 @@ CQuorumCPtr SelectQuorumForSigning(const Consensus::LLMQParams& llmq_params, con CBlockIndex* pindexStart; { - LOCK(cs_main); + LOCK(::cs_main); if (signHeight == -1) { signHeight = active_chain.Height(); } diff --git a/src/llmq/snapshot.cpp b/src/llmq/snapshot.cpp index e2cbf337197d..5ee8ab6bcca7 100644 --- a/src/llmq/snapshot.cpp +++ b/src/llmq/snapshot.cpp @@ -87,7 +87,7 @@ bool BuildQuorumRotationInfo(CDeterministicMNManager& dmnman, CQuorumSnapshotMan const CQuorumBlockProcessor& qblockman, const CGetQuorumRotationInfo& request, bool use_legacy_construction, CQuorumRotationInfo& response, std::string& errorRet) { - AssertLockHeld(cs_main); + AssertLockHeld(::cs_main); std::vector baseBlockIndexes; if (request.baseBlockHashes.size() == 0) { @@ -426,7 +426,7 @@ void CQuorumSnapshotManager::StoreSnapshotForBlock(const Consensus::LLMQType llm { auto snapshotHash = ::SerializeHash(std::make_pair(llmqType, pindex->GetBlockHash())); - // LOCK(cs_main); + // LOCK(::cs_main); AssertLockNotHeld(m_evoDb.cs); LOCK2(snapshotCacheCs, m_evoDb.cs); m_evoDb.GetRawDB().Write(std::make_pair(DB_QUORUM_SNAPSHOT, snapshotHash), snapshot); diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 68fe4f5f06df..03a6d83a2117 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -77,6 +77,11 @@ #include +using node::ReadBlockFromDisk; +using node::fImporting; +using node::fPruneMode; +using node::fReindex; + /** Maximum number of in-flight objects from a peer */ static constexpr int32_t MAX_PEER_OBJECT_IN_FLIGHT = 100; /** Maximum number of announced objects from a peer */ diff --git a/src/node/blockstorage.cpp b/src/node/blockstorage.cpp index d634af2ae888..e97e4ac6f3c9 100644 --- a/src/node/blockstorage.cpp +++ b/src/node/blockstorage.cpp @@ -26,6 +26,7 @@ #include #include +namespace node { std::atomic_bool fImporting(false); std::atomic_bool fReindex(false); bool fPruneMode = false; @@ -479,11 +480,6 @@ void CleanupBlockRevFiles() } } -std::string CBlockFileInfo::ToString() const -{ - return strprintf("CBlockFileInfo(blocks=%u, size=%u, heights=%u...%u, time=%s...%s)", nBlocks, nSize, nHeightFirst, nHeightLast, FormatISO8601Date(nTimeFirst), FormatISO8601Date(nTimeLast)); -} - CBlockFileInfo* BlockManager::GetBlockFileInfo(size_t n) { LOCK(cs_LastBlockFile); @@ -928,3 +924,4 @@ void ThreadImport(ChainstateManager& chainman, CDeterministicMNManager& dmnman, chainman.ActiveChainstate().LoadMempool(args); } +} // namespace node diff --git a/src/node/blockstorage.h b/src/node/blockstorage.h index 5b7468e79c24..128fb884ac4b 100644 --- a/src/node/blockstorage.h +++ b/src/node/blockstorage.h @@ -35,6 +35,7 @@ namespace Consensus { struct Params; } +namespace node { static constexpr bool DEFAULT_ADDRESSINDEX{false}; static constexpr bool DEFAULT_SPENTINDEX{false}; static constexpr bool DEFAULT_STOPAFTERBLOCKIMPORT{false}; @@ -230,5 +231,6 @@ bool UndoReadFromDisk(CBlockUndo& blockundo, const CBlockIndex* pindex); void ThreadImport(ChainstateManager& chainman, CDeterministicMNManager& dmnman, CDSNotificationInterface& dsnfi, std::vector vImportFiles, CActiveMasternodeManager* const mn_activeman, const ArgsManager& args); +} // namespace node #endif // BITCOIN_NODE_BLOCKSTORAGE_H diff --git a/src/node/caches.cpp b/src/node/caches.cpp index 36254dc71419..f168332ee657 100644 --- a/src/node/caches.cpp +++ b/src/node/caches.cpp @@ -8,6 +8,7 @@ #include #include +namespace node { CacheSizes CalculateCacheSizes(const ArgsManager& args, size_t n_indexes) { int64_t nTotalCache = (args.GetIntArg("-dbcache", nDefaultDbCache) << 20); @@ -30,3 +31,4 @@ CacheSizes CalculateCacheSizes(const ArgsManager& args, size_t n_indexes) sizes.coins = nTotalCache; // the rest goes to in-memory cache return sizes; } +} // namespace node diff --git a/src/node/caches.h b/src/node/caches.h index 200f0b85b8ea..67388b91fd26 100644 --- a/src/node/caches.h +++ b/src/node/caches.h @@ -10,6 +10,7 @@ class ArgsManager; +namespace node { struct CacheSizes { int64_t block_tree_db; int64_t coins_db; @@ -18,5 +19,6 @@ struct CacheSizes { int64_t filter_index; }; CacheSizes CalculateCacheSizes(const ArgsManager& args, size_t n_indexes = 0); +} // namespace node #endif // BITCOIN_NODE_CACHES_H diff --git a/src/node/chainstate.cpp b/src/node/chainstate.cpp index fbfad427d749..5066eb1ab2eb 100644 --- a/src/node/chainstate.cpp +++ b/src/node/chainstate.cpp @@ -17,6 +17,7 @@ #include #include +namespace node { std::optional LoadChainstate(bool fReset, ChainstateManager& chainman, CGovernanceManager& govman, @@ -313,3 +314,4 @@ std::optional VerifyLoadedChainstate(ChainstateManage return std::nullopt; } +} // namespace node diff --git a/src/node/chainstate.h b/src/node/chainstate.h index 014b43d164df..54870a8f7bfa 100644 --- a/src/node/chainstate.h +++ b/src/node/chainstate.h @@ -29,6 +29,7 @@ namespace Consensus { struct Params; } +namespace node { enum class ChainstateLoadingError { ERROR_LOADING_BLOCK_DB, ERROR_BAD_GENESIS_BLOCK, @@ -146,5 +147,6 @@ std::optional VerifyLoadedChainstate(ChainstateManage int check_level, std::function get_unix_time_seconds, std::function notify_bls_state = nullptr); +} // namespace node #endif // BITCOIN_NODE_CHAINSTATE_H diff --git a/src/node/coin.cpp b/src/node/coin.cpp index 78ab46f2e84d..221854c5f67d 100644 --- a/src/node/coin.cpp +++ b/src/node/coin.cpp @@ -8,6 +8,7 @@ #include #include +namespace node { void FindCoins(const NodeContext& node, std::map& coins) { assert(node.mempool); @@ -22,3 +23,4 @@ void FindCoins(const NodeContext& node, std::map& coins) } } } +} // namespace node diff --git a/src/node/coin.h b/src/node/coin.h index 908850e2a5ac..3d534463e88d 100644 --- a/src/node/coin.h +++ b/src/node/coin.h @@ -9,6 +9,8 @@ class COutPoint; class Coin; + +namespace node { struct NodeContext; /** @@ -19,6 +21,7 @@ struct NodeContext; * @param[in] node The node context to use for lookup * @param[in,out] coins map to fill */ -void FindCoins(const NodeContext& node, std::map& coins); +void FindCoins(const node::NodeContext& node, std::map& coins); +} // namespace node #endif // BITCOIN_NODE_COIN_H diff --git a/src/node/coinstats.cpp b/src/node/coinstats.cpp index cd8748d17009..c31509e15304 100644 --- a/src/node/coinstats.cpp +++ b/src/node/coinstats.cpp @@ -18,6 +18,7 @@ #include +namespace node { // Database-independent metric indicating the UTXO set size uint64_t GetBogoSize(const CScript& script_pub_key) { @@ -182,3 +183,4 @@ static void FinalizeHash(MuHash3072& muhash, CCoinsStats& stats) stats.hashSerialized = out; } static void FinalizeHash(std::nullptr_t, CCoinsStats& stats) {} +} // namespace node diff --git a/src/node/coinstats.h b/src/node/coinstats.h index 57915dea3025..4ca9274db35f 100644 --- a/src/node/coinstats.h +++ b/src/node/coinstats.h @@ -16,9 +16,12 @@ #include #include -class BlockManager; class CCoinsView; +namespace node { +class BlockManager; +} // namespace node +namespace node { enum class CoinStatsHashType { HASH_SERIALIZED, MUHASH, @@ -72,10 +75,11 @@ struct CCoinsStats { }; //! Calculate statistics about the unspent transaction output set -bool GetUTXOStats(CCoinsView* view, BlockManager& blockman, CCoinsStats& stats, const std::function& interruption_point = {}, const CBlockIndex* pindex = nullptr); +bool GetUTXOStats(CCoinsView* view, node::BlockManager& blockman, CCoinsStats& stats, const std::function& interruption_point = {}, const CBlockIndex* pindex = nullptr); uint64_t GetBogoSize(const CScript& script_pub_key); CDataStream TxOutSer(const COutPoint& outpoint, const Coin& coin); +} // namespace node #endif // BITCOIN_NODE_COINSTATS_H diff --git a/src/node/context.cpp b/src/node/context.cpp index aa63c1301db4..87ead0700582 100644 --- a/src/node/context.cpp +++ b/src/node/context.cpp @@ -29,5 +29,7 @@ #include #include +namespace node { NodeContext::NodeContext() {} NodeContext::~NodeContext() {} +} // namespace node diff --git a/src/node/context.h b/src/node/context.h index 72f6eb9124cb..3ce539df983a 100644 --- a/src/node/context.h +++ b/src/node/context.h @@ -44,6 +44,7 @@ class Loader; } // namspace CoinJoin } // namespace interfaces +namespace node { //! NodeContext struct containing references to chain state and connection //! state. //! @@ -96,5 +97,6 @@ struct NodeContext { NodeContext(); ~NodeContext(); }; +} // namespace node #endif // BITCOIN_NODE_CONTEXT_H diff --git a/src/node/interfaces.cpp b/src/node/interfaces.cpp index 64b3b929d6cd..251a58fdab9a 100644 --- a/src/node/interfaces.cpp +++ b/src/node/interfaces.cpp @@ -468,7 +468,7 @@ class NodeImpl : public Node { return m_context->mn_activeman != nullptr; } - bool isLoadingBlocks() override { return ::fReindex || ::fImporting; } + bool isLoadingBlocks() override { return node::fReindex || node::fImporting; } void setNetworkActive(bool active) override { if (m_context->connman) { @@ -938,7 +938,7 @@ class ChainImpl : public Chain LOCK(cs_main); return m_node.chainman->m_blockman.m_have_pruned; } - bool isReadyToBroadcast() override { return !::fImporting && !::fReindex && !isInitialBlockDownload(); } + bool isReadyToBroadcast() override { return !node::fImporting && !node::fReindex && !isInitialBlockDownload(); } bool isInitialBlockDownload() override { return chainman().ActiveChainstate().IsInitialBlockDownload(); } @@ -1020,6 +1020,6 @@ class ChainImpl : public Chain } // namespace node namespace interfaces { -std::unique_ptr MakeNode(NodeContext& context) { return std::make_unique(context); } -std::unique_ptr MakeChain(NodeContext& node) { return std::make_unique(node); } +std::unique_ptr MakeNode(node::NodeContext& context) { return std::make_unique(context); } +std::unique_ptr MakeChain(node::NodeContext& node) { return std::make_unique(node); } } // namespace interfaces diff --git a/src/node/miner.cpp b/src/node/miner.cpp index 9b6cb5084012..ad210a3d4c8d 100644 --- a/src/node/miner.cpp +++ b/src/node/miner.cpp @@ -44,6 +44,7 @@ #include #include +namespace node { int64_t UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev) { int64_t nOldTime = pblock->nTime; @@ -584,3 +585,4 @@ void BlockAssembler::addPackageTxs(const CTxMemPool& mempool, int& nPackagesSele nDescendantsUpdated += UpdatePackagesForAdded(mempool, ancestors, mapModifiedTx); } } +} // namespace node diff --git a/src/node/miner.h b/src/node/miner.h index 11ffe0e84498..96116c0345f1 100644 --- a/src/node/miner.h +++ b/src/node/miner.h @@ -19,7 +19,6 @@ #include #include -class BlockManager; class CBlockIndex; class CChainParams; class CChainstateHelper; @@ -30,7 +29,6 @@ class CEvoDB; class CMNHFManager; class CScript; struct LLMQContext; -struct NodeContext; namespace Consensus { struct Params; }; namespace llmq { @@ -41,6 +39,10 @@ class CQuorumManager; class CQuorumSnapshotManager; } // namespace llmq +namespace node { +class BlockManager; +struct NodeContext; + static const bool DEFAULT_PRINTPRIORITY = false; struct CBlockTemplate @@ -188,8 +190,8 @@ class BlockAssembler CFeeRate blockMinFeeRate; }; - explicit BlockAssembler(CChainState& chainstate, const NodeContext& node, const CTxMemPool* mempool, const CChainParams& params); - explicit BlockAssembler(CChainState& chainstate, const NodeContext& node, const CTxMemPool* mempool, const CChainParams& params, + explicit BlockAssembler(CChainState& chainstate, const node::NodeContext& node, const CTxMemPool* mempool, const CChainParams& params); + explicit BlockAssembler(CChainState& chainstate, const node::NodeContext& node, const CTxMemPool* mempool, const CChainParams& params, const Options& options); /** Construct a new block template with coinbase to scriptPubKeyIn */ @@ -227,5 +229,6 @@ class BlockAssembler }; int64_t UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev); +} // namespace node #endif // BITCOIN_NODE_MINER_H diff --git a/src/node/minisketchwrapper.cpp b/src/node/minisketchwrapper.cpp index 572df63463ab..67e823cb6827 100644 --- a/src/node/minisketchwrapper.cpp +++ b/src/node/minisketchwrapper.cpp @@ -16,6 +16,7 @@ #include #include +namespace node { namespace { static constexpr uint32_t BITS = 32; @@ -75,3 +76,4 @@ Minisketch MakeMinisketch32FP(size_t max_elements, uint32_t fpbits) { return Minisketch::CreateFP(BITS, Minisketch32Implementation(), max_elements, fpbits); } +} // namespace node diff --git a/src/node/minisketchwrapper.h b/src/node/minisketchwrapper.h index 426781d50869..ee108ba14430 100644 --- a/src/node/minisketchwrapper.h +++ b/src/node/minisketchwrapper.h @@ -9,9 +9,11 @@ #include #include +namespace node { /** Wrapper around Minisketch::Minisketch(32, implementation, capacity). */ Minisketch MakeMinisketch32(size_t capacity); /** Wrapper around Minisketch::CreateFP. */ Minisketch MakeMinisketch32FP(size_t max_elements, uint32_t fpbits); +} // namespace node #endif // BITCOIN_NODE_MINISKETCHWRAPPER_H diff --git a/src/node/psbt.cpp b/src/node/psbt.cpp index 0b0a3cd45dcc..1f905b3c44fa 100644 --- a/src/node/psbt.cpp +++ b/src/node/psbt.cpp @@ -11,6 +11,7 @@ #include +namespace node { PSBTAnalysis AnalyzePSBT(PartiallySignedTransaction psbtx) { // Go through each input and build status @@ -144,4 +145,4 @@ PSBTAnalysis AnalyzePSBT(PartiallySignedTransaction psbtx) return result; } - +} // namespace node diff --git a/src/node/psbt.h b/src/node/psbt.h index c2826e3ea1e8..5b76298b4cda 100644 --- a/src/node/psbt.h +++ b/src/node/psbt.h @@ -7,6 +7,7 @@ #include +namespace node { /** * Holds an analysis of one input from a PSBT */ @@ -49,5 +50,6 @@ struct PSBTAnalysis { * @return A PSBTAnalysis with information about the provided PSBT. */ PSBTAnalysis AnalyzePSBT(PartiallySignedTransaction psbtx); +} // namespace node #endif // BITCOIN_NODE_PSBT_H diff --git a/src/node/transaction.cpp b/src/node/transaction.cpp index 88d691628d7a..a66c036bbfda 100644 --- a/src/node/transaction.cpp +++ b/src/node/transaction.cpp @@ -17,6 +17,7 @@ #include +namespace node { static TransactionError HandleATMPError(const TxValidationState& state, std::string& err_string_out) { err_string_out = state.ToString(); if (state.IsInvalid()) { @@ -148,3 +149,4 @@ CTransactionRef GetTransaction(const CBlockIndex* const block_index, const CTxMe } return nullptr; } +} // namespace node diff --git a/src/node/transaction.h b/src/node/transaction.h index 98a6b61a2f38..3156e841e594 100644 --- a/src/node/transaction.h +++ b/src/node/transaction.h @@ -12,11 +12,13 @@ class CBlockIndex; class CTxMemPool; -struct NodeContext; namespace Consensus { struct Params; } +namespace node { +struct NodeContext; + /** Maximum fee rate for sendrawtransaction and testmempoolaccept RPC calls. * Also used by the GUI when broadcasting a completed PSBT. * By default, a transaction with a fee rate higher than this will be rejected @@ -40,7 +42,7 @@ static const CFeeRate DEFAULT_MAX_RAW_TX_FEE_RATE{COIN / 10}; * @param[in] wait_callback wait until callbacks have been processed to avoid stale result due to a sequentially RPC. * return error */ -[[nodiscard]] TransactionError BroadcastTransaction(NodeContext& node, CTransactionRef tx, bilingual_str& err_string, const CAmount& highfee, bool relay, bool wait_callback, bool bypass_limits = false); +[[nodiscard]] TransactionError BroadcastTransaction(node::NodeContext& node, CTransactionRef tx, bilingual_str& err_string, const CAmount& highfee, bool relay, bool wait_callback, bool bypass_limits = false); /** * Return transaction with a given hash. @@ -56,5 +58,6 @@ static const CFeeRate DEFAULT_MAX_RAW_TX_FEE_RATE{COIN / 10}; * @returns The tx if found, otherwise nullptr */ CTransactionRef GetTransaction(const CBlockIndex* const block_index, const CTxMemPool* const mempool, const uint256& hash, const Consensus::Params& consensusParams, uint256& hashBlock); +} // namespace node #endif // BITCOIN_NODE_TRANSACTION_H diff --git a/src/node/utxo_snapshot.h b/src/node/utxo_snapshot.h index 9b0df96a75f6..401d4baaeb92 100644 --- a/src/node/utxo_snapshot.h +++ b/src/node/utxo_snapshot.h @@ -9,6 +9,7 @@ #include #include +namespace node { //! Metadata describing a serialized version of a UTXO set from which an //! assumeutxo CChainState can be constructed. class SnapshotMetadata @@ -32,5 +33,6 @@ class SnapshotMetadata SERIALIZE_METHODS(SnapshotMetadata, obj) { READWRITE(obj.m_base_blockhash, obj.m_coins_count); } }; +} // namespace node #endif // BITCOIN_NODE_UTXO_SNAPSHOT_H diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp index 8c1ca8c2e379..3b99604d8868 100644 --- a/src/qt/bitcoin.cpp +++ b/src/qt/bitcoin.cpp @@ -81,6 +81,8 @@ Q_DECLARE_METATYPE(CAmount) Q_DECLARE_METATYPE(SynchronizationState) Q_DECLARE_METATYPE(uint256) +using node::NodeContext; + static void RegisterMetaTypes() { // Register meta types used for QMetaObject::invokeMethod and Qt::QueuedConnection diff --git a/src/qt/coincontroldialog.cpp b/src/qt/coincontroldialog.cpp index d8ebaf82c6ca..bffcdad54e37 100644 --- a/src/qt/coincontroldialog.cpp +++ b/src/qt/coincontroldialog.cpp @@ -31,6 +31,8 @@ #include #include +using wallet::CCoinControl; + QList CoinControlDialog::payAmounts; bool CoinControlDialog::fSubtractFeeFromAmount = false; diff --git a/src/qt/coincontroldialog.h b/src/qt/coincontroldialog.h index f0d217118cb0..7158f778d01a 100644 --- a/src/qt/coincontroldialog.h +++ b/src/qt/coincontroldialog.h @@ -18,7 +18,9 @@ class WalletModel; +namespace wallet { class CCoinControl; +} // namespace wallet namespace Ui { class CoinControlDialog; @@ -41,18 +43,18 @@ class CoinControlDialog : public QDialog Q_OBJECT public: - explicit CoinControlDialog(CCoinControl& coin_control, WalletModel* model, QWidget *parent = nullptr); + explicit CoinControlDialog(wallet::CCoinControl& coin_control, WalletModel* model, QWidget *parent = nullptr); ~CoinControlDialog(); // static because also called from sendcoinsdialog - static void updateLabels(CCoinControl& m_coin_control, WalletModel*, QDialog*); + static void updateLabels(wallet::CCoinControl& m_coin_control, WalletModel*, QDialog*); static QList payAmounts; static bool fSubtractFeeFromAmount; private: Ui::CoinControlDialog *ui; - CCoinControl& m_coin_control; + wallet::CCoinControl& m_coin_control; WalletModel *model; int sortColumn; Qt::SortOrder sortOrder; diff --git a/src/qt/psbtoperationsdialog.cpp b/src/qt/psbtoperationsdialog.cpp index d8b23ee57f88..5e817cdc4f6f 100644 --- a/src/qt/psbtoperationsdialog.cpp +++ b/src/qt/psbtoperationsdialog.cpp @@ -20,6 +20,9 @@ #include #include +using node::AnalyzePSBT; +using node::DEFAULT_MAX_RAW_TX_FEE_RATE; +using node::PSBTAnalysis; PSBTOperationsDialog::PSBTOperationsDialog( QWidget* parent, WalletModel* wallet_model, ClientModel* client_model) : QDialog(parent, GUIUtil::dialog_flags), diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp index 1546dad74e00..a44190ff71b1 100644 --- a/src/qt/rpcconsole.cpp +++ b/src/qt/rpcconsole.cpp @@ -60,6 +60,10 @@ #include #include +#ifdef ENABLE_WALLET +using wallet::GetWalletDir; +#endif // ENABLE_WALLET + const int CONSOLE_HISTORY = 50; const QSize FONT_RANGE(4, 40); const char fontSizeSettingsKey[] = "consoleFontSize"; diff --git a/src/qt/sendcoinsdialog.cpp b/src/qt/sendcoinsdialog.cpp index 205d2571df7f..e51a55286913 100644 --- a/src/qt/sendcoinsdialog.cpp +++ b/src/qt/sendcoinsdialog.cpp @@ -30,6 +30,9 @@ #include #include +using wallet::CCoinControl; +using wallet::DEFAULT_PAY_TX_FEE; + #include #include #include diff --git a/src/qt/sendcoinsdialog.h b/src/qt/sendcoinsdialog.h index 163f898cf0d7..1376f781b43e 100644 --- a/src/qt/sendcoinsdialog.h +++ b/src/qt/sendcoinsdialog.h @@ -15,11 +15,13 @@ static const int MAX_SEND_POPUP_ENTRIES = 10; -class CCoinControl; class ClientModel; class SendCoinsEntry; class SendCoinsRecipient; enum class SynchronizationState; +namespace wallet { +class CCoinControl; +} // namespace wallet namespace Ui { class SendCoinsDialog; @@ -64,7 +66,7 @@ public Q_SLOTS: Ui::SendCoinsDialog *ui; ClientModel *clientModel; WalletModel *model; - std::unique_ptr m_coin_control; + std::unique_ptr m_coin_control; std::unique_ptr m_current_transaction; bool fNewRecipientAllowed; bool send(const QList& recipients, QString& question_string, QString& informative_text, QString& detailed_text); diff --git a/src/qt/test/addressbooktests.cpp b/src/qt/test/addressbooktests.cpp index fa7a361b2683..49d81f3d65e9 100644 --- a/src/qt/test/addressbooktests.cpp +++ b/src/qt/test/addressbooktests.cpp @@ -27,6 +27,13 @@ #include #include +using wallet::AddWallet; +using wallet::CreateMockWalletDatabase; +using wallet::CWallet; +using wallet::RemoveWallet; +using wallet::WALLET_FLAG_DESCRIPTORS; +using wallet::WalletContext; + namespace { diff --git a/src/qt/test/test_main.cpp b/src/qt/test/test_main.cpp index b204ac015bbf..d2f56ab891d6 100644 --- a/src/qt/test/test_main.cpp +++ b/src/qt/test/test_main.cpp @@ -45,6 +45,8 @@ Q_IMPORT_PLUGIN(QAndroidPlatformIntegrationPlugin) #endif #endif +using node::NodeContext; + const std::function G_TEST_LOG_FUN{}; const std::function()> G_TEST_COMMAND_LINE_ARGUMENTS{}; diff --git a/src/qt/test/wallettests.cpp b/src/qt/test/wallettests.cpp index 6f73429d9434..4d960fe35369 100644 --- a/src/qt/test/wallettests.cpp +++ b/src/qt/test/wallettests.cpp @@ -40,6 +40,15 @@ #include #include +using wallet::AddWallet; +using wallet::CWallet; +using wallet::CreateMockWalletDatabase; +using wallet::RemoveWallet; +using wallet::WALLET_FLAG_DESCRIPTORS; +using wallet::WalletContext; +using wallet::WalletDescriptor; +using wallet::WalletRescanReserver; + namespace { //! Press "Yes" or "Cancel" buttons in modal send confirmation dialog. diff --git a/src/qt/transactiondesc.cpp b/src/qt/transactiondesc.cpp index 1dc172af1a97..bb6ac6992289 100644 --- a/src/qt/transactiondesc.cpp +++ b/src/qt/transactiondesc.cpp @@ -27,6 +27,11 @@ #include +using wallet::ISMINE_ALL; +using wallet::ISMINE_SPENDABLE; +using wallet::ISMINE_WATCH_ONLY; +using wallet::isminetype; + QString TransactionDesc::FormatTxStatus(const interfaces::WalletTxStatus& status, bool inMempool) { int depth = status.depth_in_main_chain; diff --git a/src/qt/transactionrecord.cpp b/src/qt/transactionrecord.cpp index 001f3397b000..2e013f95ef16 100644 --- a/src/qt/transactionrecord.cpp +++ b/src/qt/transactionrecord.cpp @@ -15,6 +15,11 @@ #include +using wallet::ISMINE_ALL; +using wallet::ISMINE_SPENDABLE; +using wallet::ISMINE_WATCH_ONLY; +using wallet::isminetype; + /* Return positive answer if transaction should be shown in list. */ bool TransactionRecord::showTransaction() diff --git a/src/qt/walletcontroller.cpp b/src/qt/walletcontroller.cpp index f0512699c0a7..a39f5de1c616 100644 --- a/src/qt/walletcontroller.cpp +++ b/src/qt/walletcontroller.cpp @@ -31,6 +31,10 @@ #include #include +using wallet::WALLET_FLAG_BLANK_WALLET; +using wallet::WALLET_FLAG_DESCRIPTORS; +using wallet::WALLET_FLAG_DISABLE_PRIVATE_KEYS; + WalletController::WalletController(ClientModel& client_model, QObject* parent) : QObject(parent) , m_activity_thread(new QThread(this)) diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp index 4684965c1844..a2c907c181b7 100644 --- a/src/qt/walletmodel.cpp +++ b/src/qt/walletmodel.cpp @@ -38,6 +38,10 @@ #include #include +using wallet::CCoinControl; +using wallet::CRecipient; +using wallet::DEFAULT_DISABLE_WALLET; +using wallet::mapValue_t; WalletModel::WalletModel(std::unique_ptr wallet, ClientModel& client_model, QObject *parent) : QObject(parent), diff --git a/src/qt/walletmodel.h b/src/qt/walletmodel.h index 2d48ca2014f4..03f146b8ec5c 100644 --- a/src/qt/walletmodel.h +++ b/src/qt/walletmodel.h @@ -29,7 +29,6 @@ class SendCoinsRecipient; class TransactionTableModel; class WalletModelTransaction; -class CCoinControl; class CKeyID; class COutPoint; class COutput; @@ -42,6 +41,9 @@ namespace CoinJoin { class Client; } // namespace CoinJoin } // namespace interfaces +namespace wallet { +class CCoinControl; +} // namespace wallet QT_BEGIN_NAMESPACE class QTimer; @@ -100,7 +102,7 @@ class WalletModel : public QObject }; // prepare transaction for getting txfee before sending coins - SendCoinsReturn prepareTransaction(WalletModelTransaction &transaction, const CCoinControl& coinControl); + SendCoinsReturn prepareTransaction(WalletModelTransaction &transaction, const wallet::CCoinControl& coinControl); // Send coins to a list of recipients void sendCoins(WalletModelTransaction& transaction, bool fIsCoinJoin); diff --git a/src/rest.cpp b/src/rest.cpp index bf5703ef34a1..39be8e6e3eb1 100644 --- a/src/rest.cpp +++ b/src/rest.cpp @@ -32,6 +32,10 @@ #include +using node::GetTransaction; +using node::NodeContext; +using node::ReadBlockFromDisk; + static const size_t MAX_GETUTXOS_OUTPOINTS = 15; //allow a max of 15 outpoints to be queried at once static constexpr unsigned int MAX_REST_HEADERS_RESULTS = 2000; diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 0888896dd636..0da3c8583e99 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -64,6 +64,14 @@ #include #include +using node::BlockManager; +using node::CCoinsStats; +using node::CoinStatsHashType; +using node::NodeContext; +using node::ReadBlockFromDisk; +using node::SnapshotMetadata; +using node::UndoReadFromDisk; + struct CUpdatedBlock { uint256 hash; @@ -1040,7 +1048,7 @@ static RPCHelpMan pruneblockchain() }, [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { - if (!fPruneMode) + if (!node::fPruneMode) throw JSONRPCError(RPC_MISC_ERROR, "Cannot prune blocks because node is not in prune mode."); ChainstateManager& chainman = EnsureAnyChainman(request.context); @@ -1516,15 +1524,15 @@ RPCHelpMan getblockchaininfo() obj.pushKV("initialblockdownload", active_chainstate.IsInitialBlockDownload()); obj.pushKV("chainwork", tip.nChainWork.GetHex()); obj.pushKV("size_on_disk", chainman.m_blockman.CalculateCurrentUsage()); - obj.pushKV("pruned", fPruneMode); - if (fPruneMode) { + obj.pushKV("pruned", node::fPruneMode); + if (node::fPruneMode) { obj.pushKV("pruneheight", chainman.m_blockman.GetFirstStoredBlock(tip)->nHeight); // if 0, execution bypasses the whole if block. bool automatic_pruning{args.GetIntArg("-prune", 0) != 1}; obj.pushKV("automatic_pruning", automatic_pruning); if (automatic_pruning) { - obj.pushKV("prune_target_size", nPruneTarget); + obj.pushKV("prune_target_size", node::nPruneTarget); } } diff --git a/src/rpc/blockchain.h b/src/rpc/blockchain.h index bd0a69381410..6438cfcf6a02 100644 --- a/src/rpc/blockchain.h +++ b/src/rpc/blockchain.h @@ -16,16 +16,18 @@ extern RecursiveMutex cs_main; -class BlockManager; class CBlock; class CBlockIndex; class CChainState; class UniValue; -struct NodeContext; namespace llmq { class CChainLocksHandler; class CInstantSendManager; } // namespace llmq +namespace node { +class BlockManager; +struct NodeContext; +} // namespace node static constexpr int NUM_GETBLOCKSTATS_PERCENTILES = 5; @@ -41,7 +43,7 @@ double GetDifficulty(const CBlockIndex* blockindex); void RPCNotifyBlockChange(const CBlockIndex*); /** Block description to JSON */ -UniValue blockToJSON(BlockManager& blockman, const CBlock& block, const CBlockIndex* tip, const CBlockIndex* blockindex, const llmq::CChainLocksHandler& clhandler, const llmq::CInstantSendManager& isman, TxVerbosity verbosity) LOCKS_EXCLUDED(cs_main); +UniValue blockToJSON(node::BlockManager& blockman, const CBlock& block, const CBlockIndex* tip, const CBlockIndex* blockindex, const llmq::CChainLocksHandler& clhandler, const llmq::CInstantSendManager& isman, TxVerbosity verbosity) LOCKS_EXCLUDED(cs_main); /** Block header to JSON */ UniValue blockheaderToJSON(const CBlockIndex* tip, const CBlockIndex* blockindex, const llmq::CChainLocksHandler& clhandler) LOCKS_EXCLUDED(cs_main); @@ -54,7 +56,7 @@ void CalculatePercentilesBySize(CAmount result[NUM_GETBLOCKSTATS_PERCENTILES], s * @return a UniValue map containing metadata about the snapshot. */ UniValue CreateUTXOSnapshot( - NodeContext& node, + node::NodeContext& node, CChainState& chainstate, CAutoFile& afile, const fs::path& path, diff --git a/src/rpc/coinjoin.cpp b/src/rpc/coinjoin.cpp index cc67eb17ab44..15a36d3c67dc 100644 --- a/src/rpc/coinjoin.cpp +++ b/src/rpc/coinjoin.cpp @@ -24,6 +24,14 @@ #include +using node::NodeContext; +#ifdef ENABLE_WALLET +using wallet::CWallet; +using wallet::GetWalletForJSONRPCRequest; +using wallet::DEFAULT_DISABLE_WALLET; +using wallet::WALLET_FLAG_DISABLE_PRIVATE_KEYS; +#endif // ENABLE_WALLET + #ifdef ENABLE_WALLET namespace { void ValidateCoinJoinArguments() diff --git a/src/rpc/evo.cpp b/src/rpc/evo.cpp index bd197c04e41c..1d8c7a5a3bae 100644 --- a/src/rpc/evo.cpp +++ b/src/rpc/evo.cpp @@ -37,14 +37,32 @@ #include #include #include -#endif//ENABLE_WALLET +#endif // ENABLE_WALLET #ifdef ENABLE_WALLET -extern RPCHelpMan signrawtransactionwithwallet(); extern RPCHelpMan sendrawtransaction(); +namespace wallet { +extern RPCHelpMan signrawtransactionwithwallet(); +} // namespace wallet #else +namespace wallet { class CWallet; -#endif//ENABLE_WALLET +} // namespace wallet +#endif // ENABLE_WALLET + +using node::GetTransaction; +using node::NodeContext; +using wallet::CWallet; +#ifdef ENABLE_WALLET +using wallet::CCoinControl; +using wallet::CoinType; +using wallet::COutput; +using wallet::CRecipient; +using wallet::DEFAULT_DISABLE_WALLET; +using wallet::GetWalletForJSONRPCRequest; +using wallet::HELP_REQUIRING_PASSPHRASE; +using wallet::isminetype; +#endif // ENABLE_WALLET static RPCArg GetRpcArg(const std::string& strParamName) { @@ -323,7 +341,7 @@ static void SignSpecialTxPayloadByHash(const CMutableTransaction& tx, SpecialTxP static std::string SignAndSendSpecialTx(const JSONRPCRequest& request, CChainstateHelper& chain_helper, const ChainstateManager& chainman, const CMutableTransaction& tx, bool fSubmit) { { - LOCK(cs_main); + LOCK(::cs_main); TxValidationState state; if (!chain_helper.special_tx->CheckSpecialTx(CTransaction(tx), chainman.ActiveChain().Tip(), chainman.ActiveChainstate().CoinsTip(), true, state)) { @@ -337,7 +355,7 @@ static std::string SignAndSendSpecialTx(const JSONRPCRequest& request, CChainsta JSONRPCRequest signRequest(request); signRequest.params.setArray(); signRequest.params.push_back(HexStr(ds)); - UniValue signResult = signrawtransactionwithwallet().HandleRequest(signRequest); + UniValue signResult = wallet::signrawtransactionwithwallet().HandleRequest(signRequest); if (!fSubmit) { return signResult["hex"].get_str(); @@ -346,7 +364,7 @@ static std::string SignAndSendSpecialTx(const JSONRPCRequest& request, CChainsta JSONRPCRequest sendRequest(request); sendRequest.params.setArray(); sendRequest.params.push_back(signResult["hex"].get_str()); - return sendrawtransaction().HandleRequest(sendRequest).get_str(); + return ::sendrawtransaction().HandleRequest(sendRequest).get_str(); } // forward declaration @@ -1071,7 +1089,7 @@ static UniValue protx_update_service_common_wrapper(const JSONRPCRequest& reques FundSpecialTx(*wallet, tx, ptx, feeSource); - const bool isV19active = DeploymentActiveAfter(WITH_LOCK(cs_main, return chainman.ActiveChain().Tip();), + const bool isV19active = DeploymentActiveAfter(WITH_LOCK(::cs_main, return chainman.ActiveChain().Tip();), Params().GetConsensus(), Consensus::DEPLOYMENT_V19); SignSpecialTxPayloadByHash(tx, ptx, keyOperator, !isV19active); SetTxPayload(tx, ptx); @@ -1245,7 +1263,7 @@ static RPCHelpMan protx_revoke() EnsureWalletIsUnlocked(*pwallet); - const bool isV19active{DeploymentActiveAfter(WITH_LOCK(cs_main, return chainman.ActiveChain().Tip();), Params().GetConsensus(), Consensus::DEPLOYMENT_V19)}; + const bool isV19active{DeploymentActiveAfter(WITH_LOCK(::cs_main, return chainman.ActiveChain().Tip();), Params().GetConsensus(), Consensus::DEPLOYMENT_V19)}; CProUpRevTx ptx; ptx.nVersion = CProUpRevTx::GetMaxVersion(/*is_basic_scheme_active=*/isV19active); @@ -1333,11 +1351,11 @@ static UniValue BuildDMNListEntry(const CWallet* const pwallet, const CDetermini if (pindex != nullptr) { if (confirmations > -1) { - confirmations -= WITH_LOCK(cs_main, return chainman.ActiveChain().Height()) - pindex->nHeight; + confirmations -= WITH_LOCK(::cs_main, return chainman.ActiveChain().Height()) - pindex->nHeight; } else { uint256 minedBlockHash; collateralTx = GetTransaction(/* pindex */ nullptr, /* mempool */ nullptr, dmn.collateralOutpoint.hash, Params().GetConsensus(), minedBlockHash); - const CBlockIndex* const pindexMined = WITH_LOCK(cs_main, return chainman.m_blockman.LookupBlockIndex(minedBlockHash)); + const CBlockIndex* const pindexMined = WITH_LOCK(::cs_main, return chainman.m_blockman.LookupBlockIndex(minedBlockHash)); CHECK_NONFATAL(pindexMined != nullptr); CHECK_NONFATAL(pindex->GetAncestor(pindexMined->nHeight) == pindexMined); confirmations = pindex->nHeight - pindexMined->nHeight + 1; @@ -1434,7 +1452,7 @@ static RPCHelpMan protx_list() bool detailed = !request.params[1].isNull() ? ParseBoolV(request.params[1], "detailed") : false; - LOCK2(wallet->cs_wallet, cs_main); + LOCK2(wallet->cs_wallet, ::cs_main); int height = !request.params[2].isNull() ? ParseInt32V(request.params[2], "height") : chainman.ActiveChain().Height(); if (height < 1 || height > chainman.ActiveChain().Height()) { throw JSONRPCError(RPC_INVALID_PARAMETER, "invalid height specified"); @@ -1464,9 +1482,9 @@ static RPCHelpMan protx_list() bool detailed = !request.params[1].isNull() ? ParseBoolV(request.params[1], "detailed") : false; #ifdef ENABLE_WALLET - LOCK2(wallet ? wallet->cs_wallet : cs_main, cs_main); + LOCK2(wallet ? wallet->cs_wallet : ::cs_main, ::cs_main); #else - LOCK(cs_main); + LOCK(::cs_main); #endif int height = !request.params[2].isNull() ? ParseInt32V(request.params[2], "height") : chainman.ActiveChain().Height(); if (height < 1 || height > chainman.ActiveChain().Height()) { @@ -1531,10 +1549,10 @@ static RPCHelpMan protx_info() uint256 proTxHash(ParseHashV(request.params[0], "proTxHash")); if (request.params[1].isNull()) { - LOCK(cs_main); + LOCK(::cs_main); pindex = chainman.ActiveChain().Tip(); } else { - LOCK(cs_main); + LOCK(::cs_main); uint256 blockHash(ParseHashV(request.params[1], "blockHash")); pindex = chainman.m_blockman.LookupBlockIndex(blockHash); if (pindex == nullptr) { @@ -1552,9 +1570,9 @@ static RPCHelpMan protx_info() }; } -static uint256 ParseBlock(const UniValue& v, const ChainstateManager& chainman, const std::string& strName) EXCLUSIVE_LOCKS_REQUIRED(cs_main) +static uint256 ParseBlock(const UniValue& v, const ChainstateManager& chainman, const std::string& strName) EXCLUSIVE_LOCKS_REQUIRED(::cs_main) { - AssertLockHeld(cs_main); + AssertLockHeld(::cs_main); try { return ParseHashV(v, strName); @@ -1585,7 +1603,7 @@ static RPCHelpMan protx_diff() CDeterministicMNManager& dmnman = *CHECK_NONFATAL(node.dmnman); const LLMQContext& llmq_ctx = *CHECK_NONFATAL(node.llmq_ctx); - LOCK(cs_main); + LOCK(::cs_main); uint256 baseBlockHash = ParseBlock(request.params[0], chainman, "baseBlock"); uint256 blockHash = ParseBlock(request.params[1], chainman, "block"); bool extended = false; @@ -1607,9 +1625,9 @@ static RPCHelpMan protx_diff() }; } -static const CBlockIndex* ParseBlockIndex(const UniValue& v, const ChainstateManager& chainman, const std::string& strName) EXCLUSIVE_LOCKS_REQUIRED(cs_main) +static const CBlockIndex* ParseBlockIndex(const UniValue& v, const ChainstateManager& chainman, const std::string& strName) EXCLUSIVE_LOCKS_REQUIRED(::cs_main) { - AssertLockHeld(cs_main); + AssertLockHeld(::cs_main); try { uint256 hash = ParseHashV(v, strName); @@ -1642,7 +1660,7 @@ static RPCHelpMan protx_listdiff() CDeterministicMNManager& dmnman = *CHECK_NONFATAL(node.dmnman); - LOCK(cs_main); + LOCK(::cs_main); UniValue ret(UniValue::VOBJ); const CBlockIndex* pBaseBlockIndex = ParseBlockIndex(request.params[0], chainman, "baseBlock"); diff --git a/src/rpc/fees.cpp b/src/rpc/fees.cpp index 1146e9256e58..00940a583279 100644 --- a/src/rpc/fees.cpp +++ b/src/rpc/fees.cpp @@ -4,6 +4,7 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include +#include #include #include #include @@ -25,7 +26,7 @@ #include #include -struct NodeContext; +using node::NodeContext; static RPCHelpMan estimatesmartfee() { diff --git a/src/rpc/governance.cpp b/src/rpc/governance.cpp index ff58bde080c0..6d74cba915cd 100644 --- a/src/rpc/governance.cpp +++ b/src/rpc/governance.cpp @@ -32,6 +32,14 @@ #include #endif // ENABLE_WALLET +using node::NodeContext; +#ifdef ENABLE_WALLET +using wallet::CWallet; +using wallet::GetWalletForJSONRPCRequest; +using wallet::HELP_REQUIRING_PASSPHRASE; +using wallet::isminetype; +#endif // ENABLE_WALLET + static RPCHelpMan gobject_count() { return RPCHelpMan{"gobject count", diff --git a/src/rpc/index_util.cpp b/src/rpc/index_util.cpp index 30ca50caa10c..e5e6960f311e 100644 --- a/src/rpc/index_util.cpp +++ b/src/rpc/index_util.cpp @@ -14,7 +14,7 @@ static void EnsureAddressIndexAvailable() { - if (!fAddressIndex) { + if (!node::fAddressIndex) { throw JSONRPCError(RPC_INVALID_REQUEST, "Address index is disabled. You should run Dash Core with -addressindex (requires reindex)"); } } @@ -77,7 +77,7 @@ bool GetSpentIndex(CBlockTreeDB& block_tree_db, const CTxMemPool& mempool, const { AssertLockHeld(::cs_main); - if (!fSpentIndex) { + if (!node::fSpentIndex) { throw JSONRPCError(RPC_INVALID_REQUEST, "Spent index is disabled. You should run Dash Core with -spentindex (requires reindex)"); } @@ -95,7 +95,7 @@ bool GetTimestampIndex(CBlockTreeDB& block_tree_db, const uint32_t high, const u { AssertLockHeld(::cs_main); - if (!fTimestampIndex) { + if (!node::fTimestampIndex) { throw JSONRPCError(RPC_INVALID_REQUEST, "Timestamp index is disabled. You should run Dash Core with -timestampindex (requires reindex)"); } diff --git a/src/rpc/masternode.cpp b/src/rpc/masternode.cpp index a0acb8661ec8..4cbdbd09bf04 100644 --- a/src/rpc/masternode.cpp +++ b/src/rpc/masternode.cpp @@ -34,6 +34,17 @@ #include #include +using node::GetTransaction; +using node::NodeContext; +using node::ReadBlockFromDisk; +#ifdef ENABLE_WALLET +using wallet::CCoinControl; +using wallet::CoinType; +using wallet::COutput; +using wallet::CWallet; +using wallet::GetWalletForJSONRPCRequest; +#endif // ENABLE_WALLET + static RPCHelpMan masternode_connect() { return RPCHelpMan{"masternode connect", @@ -237,7 +248,7 @@ static RPCHelpMan masternode_winners() const ChainstateManager& chainman = EnsureChainman(node); const CBlockIndex* pindexTip{nullptr}; { - LOCK(cs_main); + LOCK(::cs_main); pindexTip = chainman.ActiveChain().Tip(); if (!pindexTip) return NullUniValue; } @@ -325,10 +336,10 @@ static RPCHelpMan masternode_payments() } if (request.params[0].isNull()) { - LOCK(cs_main); + LOCK(::cs_main); pindex = chainman.ActiveChain().Tip(); } else { - LOCK(cs_main); + LOCK(::cs_main); uint256 blockHash(ParseHashV(request.params[0], "blockhash")); pindex = chainman.m_blockman.LookupBlockIndex(blockHash); if (pindex == nullptr) { @@ -412,7 +423,7 @@ static RPCHelpMan masternode_payments() vecPayments.push_back(blockObj); if (nCount > 0) { - LOCK(cs_main); + LOCK(::cs_main); pindex = chainman.ActiveChain().Next(pindex); } else { pindex = pindex->pprev; @@ -527,14 +538,14 @@ static RPCHelpMan masternodelist_helper(bool is_composite) return (int)0; } - LOCK(cs_main); + LOCK(::cs_main); const CBlockIndex* pindex = chainman.ActiveChain()[dmn.pdmnState->nLastPaidHeight]; return (int)pindex->nTime; }; const bool showRecentMnsOnly = strMode == "recent"; const bool showEvoOnly = strMode == "evo"; - const int tipHeight = WITH_LOCK(cs_main, return chainman.ActiveChain().Tip()->nHeight); + const int tipHeight = WITH_LOCK(::cs_main, return chainman.ActiveChain().Tip()->nHeight); mnList.ForEachMN(false, [&](auto& dmn) { if (showRecentMnsOnly && dmn.pdmnState->IsBanned()) { if (tipHeight - dmn.pdmnState->GetBannedHeight() > Params().GetConsensus().nSuperblockCycle) { diff --git a/src/rpc/mempool.cpp b/src/rpc/mempool.cpp index cd05f91b1270..c090221f0540 100644 --- a/src/rpc/mempool.cpp +++ b/src/rpc/mempool.cpp @@ -19,6 +19,8 @@ #include #include +using node::NodeContext; + static std::vector MempoolEntryDescription() { return { RPCResult{RPCResult::Type::NUM, "vsize", "virtual transaction size. This can be different from actual serialized size for high-sigop transactions."}, RPCResult{RPCResult::Type::STR_AMOUNT, "fee", /*optional=*/true, diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index 54cb60ddc7a3..963372066621 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -52,6 +52,11 @@ #include #include +using node::BlockAssembler; +using node::CBlockTemplate; +using node::NodeContext; +using node::UpdateTime; + /** * Return average network hashes per second based on the last 'lookup' blocks, * or from the last difficulty change if 'lookup' is nonpositive. diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index 23424abefa32..9023c4b72746 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -41,6 +41,8 @@ #include #endif +using node::NodeContext; + static RPCHelpMan debug() { return RPCHelpMan{"debug", diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp index f6a965ffaa5d..c9379156f2f7 100644 --- a/src/rpc/net.cpp +++ b/src/rpc/net.cpp @@ -32,6 +32,8 @@ #include +using node::NodeContext; + const std::vector CONNECTION_TYPE_DOC{ "outbound-full-relay (default automatic connections)", "block-relay-only (does not relay transactions or addresses)", diff --git a/src/rpc/quorums.cpp b/src/rpc/quorums.cpp index e59b3a1df398..5001246f6b9a 100644 --- a/src/rpc/quorums.cpp +++ b/src/rpc/quorums.cpp @@ -33,6 +33,9 @@ #include #include +using node::GetTransaction; +using node::NodeContext; + static RPCHelpMan quorum_list() { return RPCHelpMan{"quorum list", diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index e903506114f3..3f6ec00219e2 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -60,6 +60,12 @@ #include +using node::AnalyzePSBT; +using node::DEFAULT_MAX_RAW_TX_FEE_RATE; +using node::GetTransaction; +using node::NodeContext; +using node::PSBTAnalysis; + void TxToJSON(const CTransaction& tx, const uint256 hashBlock, const CTxMemPool& mempool, const CChainState& active_chainstate, const llmq::CChainLocksHandler& clhandler, const llmq::CInstantSendManager& isman, UniValue& entry) { LOCK(::cs_main); @@ -75,7 +81,7 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, const CTxMemPool // Add spent information if spentindex is enabled CSpentIndexTxInfo txSpentInfo; - if (fSpentIndex) { + if (node::fSpentIndex) { txSpentInfo = CSpentIndexTxInfo{}; for (const auto& txin : tx.vin) { if (!tx.IsCoinBase()) { diff --git a/src/rpc/server_util.cpp b/src/rpc/server_util.cpp index 2700a7851f8e..feaa859b52fc 100644 --- a/src/rpc/server_util.cpp +++ b/src/rpc/server_util.cpp @@ -19,6 +19,11 @@ #include +using node::NodeContext; +#ifdef ENABLE_WALLET +using wallet::WalletContext; +#endif // ENABLE_WALLET + NodeContext& EnsureAnyNodeContext(const CoreContext& context) { auto* const node_context = GetContext(context); diff --git a/src/rpc/server_util.h b/src/rpc/server_util.h index 9bcf1b7d081d..79ad619ece01 100644 --- a/src/rpc/server_util.h +++ b/src/rpc/server_util.h @@ -13,21 +13,23 @@ class CConnman; class CTxMemPool; class ChainstateManager; class PeerManager; -struct NodeContext; struct LLMQContext; +namespace node { +struct NodeContext; +} // namespace node -NodeContext& EnsureAnyNodeContext(const CoreContext& context); -CTxMemPool& EnsureMemPool(const NodeContext& node); +node::NodeContext& EnsureAnyNodeContext(const CoreContext& context); +CTxMemPool& EnsureMemPool(const node::NodeContext& node); CTxMemPool& EnsureAnyMemPool(const CoreContext& context); -ArgsManager& EnsureArgsman(const NodeContext& node); +ArgsManager& EnsureArgsman(const node::NodeContext& node); ArgsManager& EnsureAnyArgsman(const CoreContext& context); -ChainstateManager& EnsureChainman(const NodeContext& node); +ChainstateManager& EnsureChainman(const node::NodeContext& node); ChainstateManager& EnsureAnyChainman(const CoreContext& context); -CBlockPolicyEstimator& EnsureFeeEstimator(const NodeContext& node); +CBlockPolicyEstimator& EnsureFeeEstimator(const node::NodeContext& node); CBlockPolicyEstimator& EnsureAnyFeeEstimator(const CoreContext& context); -LLMQContext& EnsureLLMQContext(const NodeContext& node); +LLMQContext& EnsureLLMQContext(const node::NodeContext& node); LLMQContext& EnsureAnyLLMQContext(const CoreContext& context); -CConnman& EnsureConnman(const NodeContext& node); -PeerManager& EnsurePeerman(const NodeContext& node); +CConnman& EnsureConnman(const node::NodeContext& node); +PeerManager& EnsurePeerman(const node::NodeContext& node); #endif // BITCOIN_RPC_SERVER_UTIL_H diff --git a/src/rpc/txoutproof.cpp b/src/rpc/txoutproof.cpp index 13fe376dc472..78300720306c 100644 --- a/src/rpc/txoutproof.cpp +++ b/src/rpc/txoutproof.cpp @@ -17,6 +17,9 @@ #include #include +using node::GetTransaction; +using node::ReadBlockFromDisk; + static RPCHelpMan gettxoutproof() { return RPCHelpMan{"gettxoutproof", diff --git a/src/test/addrman_tests.cpp b/src/test/addrman_tests.cpp index c1cbde592ecc..897b4d88705a 100644 --- a/src/test/addrman_tests.cpp +++ b/src/test/addrman_tests.cpp @@ -20,6 +20,7 @@ #include using namespace std::literals; +using node::NodeContext; static NetGroupManager EMPTY_NETGROUPMAN{std::vector()}; static const bool DETERMINISTIC{true}; diff --git a/src/test/block_reward_reallocation_tests.cpp b/src/test/block_reward_reallocation_tests.cpp index a19431ff6210..f77410b697b5 100644 --- a/src/test/block_reward_reallocation_tests.cpp +++ b/src/test/block_reward_reallocation_tests.cpp @@ -30,6 +30,9 @@ #include #include +using node::BlockAssembler; +using node::GetTransaction; + using SimpleUTXOMap = std::map>; struct TestChainBRRBeforeActivationSetup : public TestChainSetup diff --git a/src/test/blockfilter_index_tests.cpp b/src/test/blockfilter_index_tests.cpp index 7ffa28eec5c8..a94bb2fe74e5 100644 --- a/src/test/blockfilter_index_tests.cpp +++ b/src/test/blockfilter_index_tests.cpp @@ -18,6 +18,9 @@ #include +using node::BlockAssembler; +using node::CBlockTemplate; + BOOST_AUTO_TEST_SUITE(blockfilter_index_tests) struct BuildChainTestingSetup : public TestChain100Setup { diff --git a/src/test/blockmanager_tests.cpp b/src/test/blockmanager_tests.cpp index a9ce570a3df5..dd7c32cc46c0 100644 --- a/src/test/blockmanager_tests.cpp +++ b/src/test/blockmanager_tests.cpp @@ -10,6 +10,9 @@ #include #include +using node::BlockManager; +using node::BLOCK_SERIALIZATION_HEADER_SIZE; + // use BasicTestingSetup here for the data directory configuration, setup, and cleanup BOOST_FIXTURE_TEST_SUITE(blockmanager_tests, BasicTestingSetup) diff --git a/src/test/coinstatsindex_tests.cpp b/src/test/coinstatsindex_tests.cpp index ef9beae6da22..769935c284e0 100644 --- a/src/test/coinstatsindex_tests.cpp +++ b/src/test/coinstatsindex_tests.cpp @@ -12,6 +12,9 @@ #include +using node::CCoinsStats; +using node::CoinStatsHashType; + BOOST_AUTO_TEST_SUITE(coinstatsindex_tests) BOOST_FIXTURE_TEST_CASE(coinstatsindex_initial_sync, TestChain100Setup) diff --git a/src/test/dynamic_activation_thresholds_tests.cpp b/src/test/dynamic_activation_thresholds_tests.cpp index 792a60ae1aa1..f8684be042b8 100644 --- a/src/test/dynamic_activation_thresholds_tests.cpp +++ b/src/test/dynamic_activation_thresholds_tests.cpp @@ -15,6 +15,8 @@ #include +using node::BlockAssembler; + const auto deployment_id = Consensus::DEPLOYMENT_TESTDUMMY; constexpr int window{100}, th_start{80}, th_end{60}; diff --git a/src/test/evo_deterministicmns_tests.cpp b/src/test/evo_deterministicmns_tests.cpp index 73ffb54dbf88..018b1cb15161 100644 --- a/src/test/evo_deterministicmns_tests.cpp +++ b/src/test/evo_deterministicmns_tests.cpp @@ -28,6 +28,8 @@ #include +using node::GetTransaction; + using SimpleUTXOMap = std::map>; static SimpleUTXOMap BuildSimpleUtxoMap(const std::vector& txs) diff --git a/src/test/evo_utils_tests.cpp b/src/test/evo_utils_tests.cpp index 4d555492469b..b2aeeb85fcdc 100644 --- a/src/test/evo_utils_tests.cpp +++ b/src/test/evo_utils_tests.cpp @@ -13,6 +13,8 @@ #include +using node::NodeContext; + /* TODO: rename this file and test to llmq_options_test */ BOOST_AUTO_TEST_SUITE(evo_utils_tests) diff --git a/src/test/fuzz/coins_view.cpp b/src/test/fuzz/coins_view.cpp index 96c2db213ca8..a8ba484f610d 100644 --- a/src/test/fuzz/coins_view.cpp +++ b/src/test/fuzz/coins_view.cpp @@ -27,6 +27,9 @@ #include #include +using node::CCoinsStats; +using node::CoinStatsHashType; + namespace { const TestingSetup* g_setup; const Coin EMPTY_COIN{}; diff --git a/src/test/fuzz/deserialize.cpp b/src/test/fuzz/deserialize.cpp index a9967ecbe323..d34cbb25fea3 100644 --- a/src/test/fuzz/deserialize.cpp +++ b/src/test/fuzz/deserialize.cpp @@ -35,6 +35,8 @@ #include +using node::SnapshotMetadata; + namespace { const BasicTestingSetup* g_setup; } // namespace diff --git a/src/test/fuzz/minisketch.cpp b/src/test/fuzz/minisketch.cpp index 93954bd3cf24..a17be73f6c80 100644 --- a/src/test/fuzz/minisketch.cpp +++ b/src/test/fuzz/minisketch.cpp @@ -12,6 +12,8 @@ #include #include +using node::MakeMinisketch32; + FUZZ_TARGET(minisketch) { FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()}; diff --git a/src/test/fuzz/psbt.cpp b/src/test/fuzz/psbt.cpp index f4e126ae701f..81d0b953413c 100644 --- a/src/test/fuzz/psbt.cpp +++ b/src/test/fuzz/psbt.cpp @@ -18,6 +18,10 @@ #include #include +using node::AnalyzePSBT; +using node::PSBTAnalysis; +using node::PSBTInputAnalysis; + FUZZ_TARGET(psbt) { FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()}; diff --git a/src/test/fuzz/tx_pool.cpp b/src/test/fuzz/tx_pool.cpp index 9849feb1ede7..7940c4a3b467 100644 --- a/src/test/fuzz/tx_pool.cpp +++ b/src/test/fuzz/tx_pool.cpp @@ -13,6 +13,9 @@ #include #include +using node::BlockAssembler; +using node::NodeContext; + namespace { const TestingSetup* g_setup; diff --git a/src/test/fuzz/utxo_snapshot.cpp b/src/test/fuzz/utxo_snapshot.cpp index 388ce6a4d58a..a587cf919fb9 100644 --- a/src/test/fuzz/utxo_snapshot.cpp +++ b/src/test/fuzz/utxo_snapshot.cpp @@ -13,6 +13,8 @@ #include #include +using node::SnapshotMetadata; + namespace { const std::vector>* g_chain; diff --git a/src/test/miner_tests.cpp b/src/test/miner_tests.cpp index a303b617e4a5..3dd4d3482835 100644 --- a/src/test/miner_tests.cpp +++ b/src/test/miner_tests.cpp @@ -31,6 +31,9 @@ #include +using node::BlockAssembler; +using node::CBlockTemplate; + namespace miner_tests { struct MinerTestingSetup : public TestingSetup { void TestPackageSelection(const CChainParams& chainparams, const CScript& scriptPubKey, const std::vector& txFirst) EXCLUSIVE_LOCKS_REQUIRED(::cs_main, m_node.mempool->cs); diff --git a/src/test/minisketch_tests.cpp b/src/test/minisketch_tests.cpp index d07924d18b8e..81f2aad62309 100644 --- a/src/test/minisketch_tests.cpp +++ b/src/test/minisketch_tests.cpp @@ -11,6 +11,8 @@ #include +using node::MakeMinisketch32; + BOOST_AUTO_TEST_SUITE(minisketch_tests) BOOST_AUTO_TEST_CASE(minisketch_test) diff --git a/src/test/util/blockfilter.cpp b/src/test/util/blockfilter.cpp index b8f3e462334d..3ae22921b9c2 100644 --- a/src/test/util/blockfilter.cpp +++ b/src/test/util/blockfilter.cpp @@ -8,6 +8,9 @@ #include #include +using node::ReadBlockFromDisk; +using node::UndoReadFromDisk; + bool ComputeFilter(BlockFilterType filter_type, const CBlockIndex* block_index, BlockFilter& filter) { LOCK(::cs_main); diff --git a/src/test/util/chainstate.h b/src/test/util/chainstate.h index 3b6b504ef8b9..b82368aa7051 100644 --- a/src/test/util/chainstate.h +++ b/src/test/util/chainstate.h @@ -15,7 +15,7 @@ #include -const auto NoMalleation = [](CAutoFile& file, SnapshotMetadata& meta){}; +const auto NoMalleation = [](CAutoFile& file, node::SnapshotMetadata& meta){}; /** * Create and activate a UTXO snapshot, optionally providing a function to @@ -23,7 +23,7 @@ const auto NoMalleation = [](CAutoFile& file, SnapshotMetadata& meta){}; */ template static bool -CreateAndActivateUTXOSnapshot(NodeContext& node, const fs::path root, F malleation = NoMalleation) +CreateAndActivateUTXOSnapshot(node::NodeContext& node, const fs::path root, F malleation = NoMalleation) { // Write out a snapshot to the test's tempdir. // @@ -42,7 +42,7 @@ CreateAndActivateUTXOSnapshot(NodeContext& node, const fs::path root, F malleati // FILE* infile{fsbridge::fopen(snapshot_path, "rb")}; CAutoFile auto_infile{infile, SER_DISK, CLIENT_VERSION}; - SnapshotMetadata metadata; + node::SnapshotMetadata metadata; auto_infile >> metadata; malleation(auto_infile, metadata); diff --git a/src/test/util/mining.cpp b/src/test/util/mining.cpp index 653814db5e7a..e98eed3f8fd9 100644 --- a/src/test/util/mining.cpp +++ b/src/test/util/mining.cpp @@ -18,6 +18,9 @@ #include #include +using node::BlockAssembler; +using node::NodeContext; + CTxIn generatetoaddress(const NodeContext& node, const std::string& address) { const auto dest = DecodeDestination(address); diff --git a/src/test/util/mining.h b/src/test/util/mining.h index e6cdbfd6d597..09e712cd35c9 100644 --- a/src/test/util/mining.h +++ b/src/test/util/mining.h @@ -13,18 +13,20 @@ class CBlock; class CChainParams; class CScript; class CTxIn; +namespace node { struct NodeContext; +} // namespace node /** Create a blockchain, starting from genesis */ std::vector> CreateBlockChain(size_t total_height, const CChainParams& params); /** Returns the generated coin */ -CTxIn MineBlock(const NodeContext&, const CScript& coinbase_scriptPubKey); +CTxIn MineBlock(const node::NodeContext&, const CScript& coinbase_scriptPubKey); /** Prepare a block to be mined */ -std::shared_ptr PrepareBlock(const NodeContext&, const CScript& coinbase_scriptPubKey); +std::shared_ptr PrepareBlock(const node::NodeContext&, const CScript& coinbase_scriptPubKey); /** RPC-like helper function, returns the generated coin */ -CTxIn generatetoaddress(const NodeContext&, const std::string& address); +CTxIn generatetoaddress(const node::NodeContext&, const std::string& address); #endif // BITCOIN_TEST_UTIL_MINING_H diff --git a/src/test/util/setup_common.cpp b/src/test/util/setup_common.cpp index 3800a0e15a70..8e4b054caf3c 100644 --- a/src/test/util/setup_common.cpp +++ b/src/test/util/setup_common.cpp @@ -72,6 +72,19 @@ #include #include +using node::BlockAssembler; +using node::CalculateCacheSizes; +using node::DashChainstateSetup; +using node::DashChainstateSetupClose; +using node::DEFAULT_ADDRESSINDEX; +using node::DEFAULT_SPENTINDEX; +using node::DEFAULT_TIMESTAMPINDEX; +using node::LoadChainstate; +using node::NodeContext; +using node::VerifyLoadedChainstate; +using node::fPruneMode; +using node::fReindex; + const std::function G_TRANSLATION_FUN = nullptr; UrlDecodeFn* const URL_DECODE = nullptr; diff --git a/src/test/util/setup_common.h b/src/test/util/setup_common.h index 8a5f626e1b3d..e072e9ac204a 100644 --- a/src/test/util/setup_common.h +++ b/src/test/util/setup_common.h @@ -85,17 +85,17 @@ static constexpr CAmount CENT{1000000}; /** Initialize Dash-specific components during chainstate initialization (NodeContext-friendly aliases) */ void DashChainstateSetup(ChainstateManager& chainman, - NodeContext& node, + node::NodeContext& node, bool fReset, bool fReindexChainState, const Consensus::Params& consensus_params); -void DashChainstateSetupClose(NodeContext& node); +void DashChainstateSetupClose(node::NodeContext& node); /** Basic testing setup. * This just configures logging, data dir and chain parameters. */ struct BasicTestingSetup { - NodeContext m_node; + node::NodeContext m_node; explicit BasicTestingSetup(const std::string& chainName = CBaseChainParams::MAIN, const std::vector& extra_args = {}); ~BasicTestingSetup(); @@ -109,7 +109,7 @@ struct BasicTestingSetup { * initialization behaviour. */ struct ChainTestingSetup : public BasicTestingSetup { - CacheSizes m_cache_sizes{}; + node::CacheSizes m_cache_sizes{}; explicit ChainTestingSetup(const std::string& chainName = CBaseChainParams::MAIN, const std::vector& extra_args = {}); ~ChainTestingSetup(); diff --git a/src/test/util/wallet.cpp b/src/test/util/wallet.cpp index 836543da9ee3..190abea0c3c0 100644 --- a/src/test/util/wallet.cpp +++ b/src/test/util/wallet.cpp @@ -16,6 +16,8 @@ #include #endif +using wallet::CWallet; + const std::string ADDRESS_B58T_UNSPENDABLE = "yXXXXXXXXXXXXXXXXXXXXXXXXXXXVd2rXU"; const std::string ADDRESS_BCRT1_UNSPENDABLE = "bcrt1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq3xueyj"; diff --git a/src/test/util/wallet.h b/src/test/util/wallet.h index 14a41ae47377..d8a81c2d8224 100644 --- a/src/test/util/wallet.h +++ b/src/test/util/wallet.h @@ -7,7 +7,9 @@ #include +namespace wallet { class CWallet; +} // namespace wallet // Constants // @@ -17,9 +19,9 @@ extern const std::string ADDRESS_BCRT1_UNSPENDABLE; // RPC-like // /** Import the address to the wallet */ -void importaddress(CWallet& wallet, const std::string& address); +void importaddress(wallet::CWallet& wallet, const std::string& address); /** Returns a new address from the wallet */ -std::string getnewaddress(CWallet& w); +std::string getnewaddress(wallet::CWallet& w); #endif // BITCOIN_TEST_UTIL_WALLET_H diff --git a/src/test/validation_block_tests.cpp b/src/test/validation_block_tests.cpp index d87929767e33..99a6109fee68 100644 --- a/src/test/validation_block_tests.cpp +++ b/src/test/validation_block_tests.cpp @@ -20,6 +20,8 @@ #include +using node::BlockAssembler; + namespace validation_block_tests { struct MinerTestingSetup : public RegTestingSetup { std::shared_ptr Block(const uint256& prev_hash); diff --git a/src/test/validation_chainstatemanager_tests.cpp b/src/test/validation_chainstatemanager_tests.cpp index 7e2ad79cafa7..2de98a6fc65b 100644 --- a/src/test/validation_chainstatemanager_tests.cpp +++ b/src/test/validation_chainstatemanager_tests.cpp @@ -26,6 +26,8 @@ #include +using node::SnapshotMetadata; + BOOST_FIXTURE_TEST_SUITE(validation_chainstatemanager_tests, ChainTestingSetup) //! Basic tests for ChainstateManager. diff --git a/src/test/validation_flush_tests.cpp b/src/test/validation_flush_tests.cpp index 1e78f0c73e84..e06afa93bbd0 100644 --- a/src/test/validation_flush_tests.cpp +++ b/src/test/validation_flush_tests.cpp @@ -10,6 +10,8 @@ #include +using node::BlockManager; + BOOST_FIXTURE_TEST_SUITE(validation_flush_tests, ChainTestingSetup) //! Test utilities for detecting when we need to flush the coins cache based diff --git a/src/validation.cpp b/src/validation.cpp index 30ef488288c5..bc9b2acbbf10 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -68,6 +68,26 @@ #include #include +using node::BlockManager; +using node::BlockMap; +using node::CBlockIndexHeightOnlyComparator; +using node::CBlockIndexWorkComparator; +using node::CCoinsStats; +using node::CoinStatsHashType; +using node::DEFAULT_ADDRESSINDEX; +using node::DEFAULT_SPENTINDEX; +using node::DEFAULT_TIMESTAMPINDEX; +using node::fAddressIndex; +using node::fImporting; +using node::fPruneMode; +using node::fReindex; +using node::fSpentIndex; +using node::fTimestampIndex; +using node::ReadBlockFromDisk; +using node::SnapshotMetadata; +using node::UndoReadFromDisk; +using node::UnlinkPrunedFiles; + #define MICRO 0.000001 #define MILLI 0.001 diff --git a/src/validation.h b/src/validation.h index 7e931955c2cb..3c3815357678 100644 --- a/src/validation.h +++ b/src/validation.h @@ -51,12 +51,13 @@ class TxValidationState; class CChainstateHelper; class ChainstateManager; struct PrecomputedTransactionData; -class SnapshotMetadata; struct ChainTxData; struct DisconnectedBlockTransactions; struct LockPoints; struct AssumeutxoData; - +namespace node { +class SnapshotMetadata; +} // namespace node namespace llmq { class CChainLocksHandler; } // namespace llmq @@ -487,7 +488,7 @@ class CChainState public: //! Reference to a BlockManager instance which itself is shared across all //! CChainState instances. - BlockManager& m_blockman; + node::BlockManager& m_blockman; /** Chain parameters for this chainstate */ const CChainParams& m_params; @@ -498,7 +499,7 @@ class CChainState ChainstateManager& m_chainman; explicit CChainState(CTxMemPool* mempool, - BlockManager& blockman, + node::BlockManager& blockman, ChainstateManager& chainman, CEvoDB& evoDb, const std::unique_ptr& chain_helper, @@ -549,7 +550,7 @@ class CChainState * chainstates) and as good as our current tip or better. Entries may be failed, * though, and pruning nodes may be missing the data for the block. */ - std::set setBlockIndexCandidates; + std::set setBlockIndexCandidates; CChainstateHelper& ChainHelper() { @@ -872,7 +873,7 @@ class ChainstateManager [[nodiscard]] bool PopulateAndValidateSnapshot( CChainState& snapshot_chainstate, CAutoFile& coins_file, - const SnapshotMetadata& metadata); + const node::SnapshotMetadata& metadata); /** * If a block header hasn't already been seen, call CheckBlockHeader on it, ensure @@ -889,7 +890,7 @@ class ChainstateManager std::thread m_load_block; //! A single BlockManager instance is shared across each constructed //! chainstate to avoid duplicating block metadata. - BlockManager m_blockman; + node::BlockManager m_blockman; /** * In order to efficiently track invalidity of headers, we keep the set of @@ -953,7 +954,7 @@ class ChainstateManager //! - Move the new chainstate to `m_snapshot_chainstate` and make it our //! ChainstateActive(). [[nodiscard]] bool ActivateSnapshot( - CAutoFile& coins_file, const SnapshotMetadata& metadata, bool in_memory); + CAutoFile& coins_file, const node::SnapshotMetadata& metadata, bool in_memory); //! The most-work chain. CChainState& ActiveChainstate() const; @@ -961,13 +962,13 @@ class ChainstateManager int ActiveHeight() const { return ActiveChain().Height(); } CBlockIndex* ActiveTip() const { return ActiveChain().Tip(); } - BlockMap& BlockIndex() EXCLUSIVE_LOCKS_REQUIRED(::cs_main) + node::BlockMap& BlockIndex() EXCLUSIVE_LOCKS_REQUIRED(::cs_main) { AssertLockHeld(::cs_main); return m_blockman.m_block_index; } - PrevBlockMap& PrevBlockIndex() EXCLUSIVE_LOCKS_REQUIRED(::cs_main) + node::PrevBlockMap& PrevBlockIndex() EXCLUSIVE_LOCKS_REQUIRED(::cs_main) { return m_blockman.m_prev_block_index; } diff --git a/src/wallet/bdb.cpp b/src/wallet/bdb.cpp index 877a28e86f0a..c89c3f1ad9d6 100644 --- a/src/wallet/bdb.cpp +++ b/src/wallet/bdb.cpp @@ -24,6 +24,7 @@ #endif #endif +namespace wallet { namespace { Span SpanFromDbt(const BerkeleyBatch::SafeDbt& dbt) { @@ -861,3 +862,4 @@ std::unique_ptr MakeBerkeleyDatabase(const fs::path& path, con status = DatabaseStatus::SUCCESS; return db; } +} // namespace wallet diff --git a/src/wallet/bdb.h b/src/wallet/bdb.h index d1566410aed5..8a4feb696bc8 100644 --- a/src/wallet/bdb.h +++ b/src/wallet/bdb.h @@ -30,6 +30,7 @@ struct bilingual_str; #pragma GCC diagnostic pop #endif +namespace wallet { struct WalletDatabaseFileId { uint8_t value[DB_FILE_ID_LEN]; bool operator==(const WalletDatabaseFileId& rhs) const; @@ -230,5 +231,6 @@ bool BerkeleyDatabaseSanityCheck(); //! Return object giving access to Berkeley database at specified path. std::unique_ptr MakeBerkeleyDatabase(const fs::path& path, const DatabaseOptions& options, DatabaseStatus& status, bilingual_str& error); +} // namespace wallet #endif // BITCOIN_WALLET_BDB_H diff --git a/src/wallet/coincontrol.cpp b/src/wallet/coincontrol.cpp index 97fcb8b6b355..57c7f0a4459c 100644 --- a/src/wallet/coincontrol.cpp +++ b/src/wallet/coincontrol.cpp @@ -6,8 +6,10 @@ #include +namespace wallet { CCoinControl::CCoinControl(CoinType coinType) : nCoinType(coinType) { m_avoid_partial_spends = gArgs.GetBoolArg("-avoidpartialspends", DEFAULT_AVOIDPARTIALSPENDS); } +} // namespace wallet diff --git a/src/wallet/coincontrol.h b/src/wallet/coincontrol.h index 1379366283e4..851c37838278 100644 --- a/src/wallet/coincontrol.h +++ b/src/wallet/coincontrol.h @@ -13,6 +13,7 @@ #include +namespace wallet { enum class CoinType : uint8_t { ALL_COINS, @@ -116,5 +117,6 @@ class CCoinControl private: std::set setSelected; }; +} // namespace wallet #endif // BITCOIN_WALLET_COINCONTROL_H diff --git a/src/wallet/coinjoin.cpp b/src/wallet/coinjoin.cpp index 0c641abde0f5..5900d416c00d 100644 --- a/src/wallet/coinjoin.cpp +++ b/src/wallet/coinjoin.cpp @@ -14,6 +14,7 @@ #include #include +namespace wallet { void CWallet::InitCJSaltFromDb() { assert(nCoinJoinSalt.IsNull()); @@ -573,3 +574,4 @@ CoinJoinCredits CachedTxGetAvailableCoinJoinCredits(const CWallet& wallet, const } return ret; } +} // namespace wallet diff --git a/src/wallet/coinjoin.h b/src/wallet/coinjoin.h index ae2f785d6eae..44512b4ca57e 100644 --- a/src/wallet/coinjoin.h +++ b/src/wallet/coinjoin.h @@ -10,10 +10,6 @@ #include #include -class CCoinControl; -class CWallet; -class CWalletTx; - // Use a macro instead of a function for conditional logging to prevent // evaluating arguments when logging for the category is not enabled. #define WalletCJLogPrint(wallet, ...) \ @@ -23,6 +19,11 @@ class CWalletTx; } \ } while (0) +namespace wallet { +class CCoinControl; +class CWallet; +class CWalletTx; + CAmount GetBalanceAnonymized(const CWallet& wallet, const CCoinControl& coinControl); CAmount CachedTxGetAnonymizedCredit(const CWallet& wallet, const CWalletTx& wtx, const CCoinControl& coinControl) @@ -37,5 +38,6 @@ struct CoinJoinCredits CoinJoinCredits CachedTxGetAvailableCoinJoinCredits(const CWallet& wallet, const CWalletTx& wtx) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet); +} // namespace wallet #endif // BITCOIN_WALLET_COINJOIN_H diff --git a/src/wallet/coinselection.cpp b/src/wallet/coinselection.cpp index 7d66d9dfa892..0f6588c1f06f 100644 --- a/src/wallet/coinselection.cpp +++ b/src/wallet/coinselection.cpp @@ -14,6 +14,7 @@ #include #include +namespace wallet { // Descending order comparator struct { bool operator()(const OutputGroup& a, const OutputGroup& b) const @@ -544,3 +545,4 @@ std::string GetAlgorithmName(const SelectionAlgorithm algo) } assert(false); } +} // namespace wallet diff --git a/src/wallet/coinselection.h b/src/wallet/coinselection.h index c5fc194d1657..3afbcb64955d 100644 --- a/src/wallet/coinselection.h +++ b/src/wallet/coinselection.h @@ -12,6 +12,7 @@ #include +namespace wallet { //! lower bound for randomly-chosen target change amount static constexpr CAmount CHANGE_LOWER{50000}; //! upper bound for randomly-chosen target change amount @@ -299,5 +300,6 @@ std::optional SelectCoinsSRD(const std::vector& ut // Original coin selection algorithm as a fallback std::optional KnapsackSolver(std::vector& groups, const CAmount& nTargetValue, CAmount change_target, FastRandomContext& rng, bool fFullyMixedOnly, CAmount maxTxFee); +} // namespace wallet #endif // BITCOIN_WALLET_COINSELECTION_H diff --git a/src/wallet/context.cpp b/src/wallet/context.cpp index 09b2f3046709..800aa5bf9c46 100644 --- a/src/wallet/context.cpp +++ b/src/wallet/context.cpp @@ -4,5 +4,7 @@ #include +namespace wallet { WalletContext::WalletContext() {} WalletContext::~WalletContext() {} +} // namespace wallet diff --git a/src/wallet/context.h b/src/wallet/context.h index 4c710018b3dc..269b24e82cda 100644 --- a/src/wallet/context.h +++ b/src/wallet/context.h @@ -13,8 +13,6 @@ #include class ArgsManager; -class CWallet; -struct NodeContext; namespace interfaces { class Chain; namespace CoinJoin { @@ -22,6 +20,12 @@ class Loader; } // namspace CoinJoin class Wallet; } // namespace interfaces +namespace node { +struct NodeContext; +} // namespace node + +namespace wallet { +class CWallet; using LoadWalletFn = std::function wallet)>; @@ -49,7 +53,7 @@ struct WalletContext { // capabilities (even though it is a hard ask sometimes). We should get // rid of this at some point but until then, here's NodeContext. // TODO: Get rid of this. It's not nice. - NodeContext* node_context{nullptr}; + node::NodeContext* node_context{nullptr}; //! Declare default constructor and destructor that are not inline, so code //! instantiating the WalletContext struct doesn't need to #include class @@ -57,5 +61,6 @@ struct WalletContext { WalletContext(); ~WalletContext(); }; +} // namespace wallet #endif // BITCOIN_WALLET_CONTEXT_H diff --git a/src/wallet/crypter.cpp b/src/wallet/crypter.cpp index d4dc17aaf2a0..4918944af24f 100644 --- a/src/wallet/crypter.cpp +++ b/src/wallet/crypter.cpp @@ -10,6 +10,7 @@ #include +namespace wallet { int CCrypter::BytesToKeySHA512AES(const std::vector& chSalt, const SecureString& strKeyData, int count, unsigned char *key,unsigned char *iv) const { // This mimics the behavior of openssl's EVP_BytesToKey with an aes256cbc @@ -181,3 +182,4 @@ bool DecryptKey(const CKeyingMaterial& vMasterKey, const std::vector #include