From 0d39941515ea7baf55b339a9a0cc3b03e5fb685f Mon Sep 17 00:00:00 2001 From: Patrick Lodder Date: Mon, 17 Jul 2023 11:49:54 -0400 Subject: [PATCH] mining: replace boost::shared_ptr with std::shared_ptr Throughout the codebase we use std::shared_ptr, except for some instances in the miner code, where we use boost::shared_ptr for sharing a wallet address with the miner and rpc across threads. This patch removes all usage of boost::shared_ptr to instead use std::shared_ptr, to reduce exposure to multiple shared pointer implementations. --- src/primitives/block.h | 4 +--- src/rpc/mining.cpp | 9 ++++----- src/rpc/server.cpp | 1 - src/validationinterface.h | 5 ++--- src/wallet/wallet.cpp | 4 ++-- src/wallet/wallet.h | 3 +-- 6 files changed, 10 insertions(+), 16 deletions(-) diff --git a/src/primitives/block.h b/src/primitives/block.h index dcde500abb..fb6c2da8ed 100644 --- a/src/primitives/block.h +++ b/src/primitives/block.h @@ -12,8 +12,6 @@ #include "serialize.h" #include "uint256.h" -#include - /** Nodes collect new transactions into a block, hash them into a hash tree, * and scan through nonce values to make the block's hash satisfy proof-of-work * requirements. When they solve the proof-of-work, they broadcast the block @@ -25,7 +23,7 @@ class CBlockHeader : public CPureBlockHeader { public: // auxpow (if this is a merge-minded block) - boost::shared_ptr auxpow; + std::shared_ptr auxpow; CBlockHeader() { diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index 7b280300ca..00fe383c0e 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -27,7 +27,6 @@ #include #include -#include #include @@ -97,7 +96,7 @@ UniValue getnetworkhashps(const JSONRPCRequest& request) return GetNetworkHashPS(request.params.size() > 0 ? request.params[0].get_int() : 120, request.params.size() > 1 ? request.params[1].get_int() : -1); } -UniValue generateBlocks(boost::shared_ptr coinbaseScript, int nGenerate, uint64_t nMaxTries, bool keepScript, int nMineAuxPow) +UniValue generateBlocks(std::shared_ptr coinbaseScript, int nGenerate, uint64_t nMaxTries, bool keepScript, int nMineAuxPow) { // Dogecoin: Never mine witness tx const bool fMineWitnessTx = false; @@ -198,7 +197,7 @@ UniValue generate(const JSONRPCRequest& request) nMineAuxPow = request.params[2].get_int(); } - boost::shared_ptr coinbaseScript; + std::shared_ptr coinbaseScript; GetMainSignals().ScriptForMining(coinbaseScript); // If the keypool is exhausted, no script is returned at all. Catch this. @@ -245,7 +244,7 @@ UniValue generatetoaddress(const JSONRPCRequest& request) if (!address.IsValid()) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Error: Invalid address"); - boost::shared_ptr coinbaseScript(new CReserveScript()); + std::shared_ptr coinbaseScript(new CReserveScript()); coinbaseScript->reserveScript = GetScriptForDestination(address.Get()); return generateBlocks(coinbaseScript, nGenerate, nMaxTries, false, nMineAuxPow); @@ -1164,7 +1163,7 @@ UniValue getauxblockbip22(const JSONRPCRequest& request) + HelpExampleRpc("getauxblock", "") ); - boost::shared_ptr coinbaseScript; + std::shared_ptr coinbaseScript; GetMainSignals().ScriptForMining(coinbaseScript); // If the keypool is exhausted, no script is returned at all. Catch this. diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 11570db1f7..8a25f97497 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -19,7 +19,6 @@ #include #include #include -#include #include #include #include // for to_upper() diff --git a/src/validationinterface.h b/src/validationinterface.h index b0e98a7b5f..e5123d2997 100644 --- a/src/validationinterface.h +++ b/src/validationinterface.h @@ -8,7 +8,6 @@ #define BITCOIN_VALIDATIONINTERFACE_H #include -#include #include class CBlock; @@ -39,7 +38,7 @@ class CValidationInterface { virtual void UpdatedTransaction(const uint256 &hash) {} virtual void ResendWalletTransactions(int64_t nBestBlockTime, CConnman* connman) {} virtual void BlockChecked(const CBlock&, const CValidationState&) {} - virtual void GetScriptForMining(boost::shared_ptr&) {}; + virtual void GetScriptForMining(std::shared_ptr&) {}; virtual void ResetRequestCount(const uint256 &hash) {}; virtual void NewPoWValidBlock(const CBlockIndex *pindex, const std::shared_ptr& block) {}; friend void ::RegisterValidationInterface(CValidationInterface*); @@ -70,7 +69,7 @@ struct CMainSignals { /** Notifies listeners of a block validation result */ boost::signals2::signal BlockChecked; /** Notifies listeners that a key for mining is required (coinbase) */ - boost::signals2::signal&)> ScriptForMining; + boost::signals2::signal&)> ScriptForMining; /** Notifies listeners that a block has been successfully mined */ boost::signals2::signal BlockFound; /** diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 9784b68f70..e2197f5605 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -3458,9 +3458,9 @@ void CWallet::UpdatedTransaction(const uint256 &hashTx) } } -void CWallet::GetScriptForMining(boost::shared_ptr &script) +void CWallet::GetScriptForMining(std::shared_ptr &script) { - boost::shared_ptr rKey(new CReserveKey(this)); + std::shared_ptr rKey(new CReserveKey(this)); CPubKey pubkey; if (!rKey->GetReservedKey(pubkey)) return; diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 3f5fb238d5..2ea9628163 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -32,7 +32,6 @@ #include #include -#include #include extern CWallet* pwalletMain; @@ -878,7 +877,7 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface void UpdatedTransaction(const uint256 &hashTx) override; - void GetScriptForMining(boost::shared_ptr &script) override; + void GetScriptForMining(std::shared_ptr &script) override; unsigned int GetKeyPoolSize() {