From 57d5246c2d9104f51fbdaf14c5bbcf1e49b00667 Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Fri, 9 Aug 2019 09:46:46 -0400 Subject: [PATCH] Merge #16503: Remove p2pEnabled from Chain interface b7b9f6e4cee262004643e2fe03d56cb47fdbf5c2 Remove p2pEnabled from Chain interface (Antoine Riard) Pull request description: RPC server starts in warmup mode, it can't process yet calls, then follows connection manager initialization and finally RPC server get out of warmup mode. RPC calls shouldn't be able to get P2P disabled errors because once we initialize g_connman it's not unset until shutdown, after RPC server has been stopped. @mzumsande comment in #15713 let me thought that `p2pEnabled` was maybe useless, `g_connman` is always initialized before RPC server is getting out of warmup. These checks against P2P state were introduced in https://github.com/bitcoin/bitcoin/pull/8085/commits/5b446dd5b11d4f403554bc2dd5a7a94c7d20422a. ACKs for top commit: promag: ACK b7b9f6e4cee262004643e2fe03d56cb47fdbf5c2 jnewbery: ACK b7b9f6e4cee262004643e2fe03d56cb47fdbf5c2 Tree-SHA512: 4de2b9fc496bf8347ff5cc645848a5a44c8ca7596cd134f17f3088f5f8262d1d88b8e2a052df93e309ec9a81956a808df17a9eb9f10d4f4d693c95d607fe3561 --- src/interfaces/chain.cpp | 1 - src/interfaces/chain.h | 3 --- src/node/transaction.cpp | 3 +++ src/wallet/rpcwallet.cpp | 8 -------- 4 files changed, 3 insertions(+), 12 deletions(-) diff --git a/src/interfaces/chain.cpp b/src/interfaces/chain.cpp index e568448564..4795e5b9d4 100644 --- a/src/interfaces/chain.cpp +++ b/src/interfaces/chain.cpp @@ -333,7 +333,6 @@ public: LOCK(cs_main); return ::fHavePruned; } - bool p2pEnabled() override { return m_node.connman != nullptr; } bool isReadyToBroadcast() override { return !::fImporting && !::fReindex && !::ChainstateActive().IsInitialBlockDownload(); } bool isInitialBlockDownload() override { return ::ChainstateActive().IsInitialBlockDownload(); } bool shutdownRequested() override { return ShutdownRequested(); } diff --git a/src/interfaces/chain.h b/src/interfaces/chain.h index 115db1e37d..1028208697 100644 --- a/src/interfaces/chain.h +++ b/src/interfaces/chain.h @@ -189,9 +189,6 @@ public: //! Check if any block has been pruned. virtual bool havePruned() = 0; - //! Check if p2p enabled. - virtual bool p2pEnabled() = 0; - //! Check if the node is ready to broadcast transactions. virtual bool isReadyToBroadcast() = 0; diff --git a/src/node/transaction.cpp b/src/node/transaction.cpp index e44ae99197..21d762c51d 100644 --- a/src/node/transaction.cpp +++ b/src/node/transaction.cpp @@ -17,6 +17,9 @@ TransactionError BroadcastTransaction(NodeContext& node, const CTransactionRef tx, std::string& err_string, const CAmount& max_tx_fee, bool relay, bool wait_callback, bool bypass_limits) { + // BroadcastTransaction can be called by either sendrawtransaction RPC or wallet RPCs. + // g_connman is assigned both before chain clients and before RPC server is accepting calls, + // and reset after chain clients and RPC sever are stopped. g_connman should never be null here. assert(node.connman); assert(node.mempool); std::promise promise; diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 7bee95b7f8..b174178ae4 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -324,10 +324,6 @@ static CTransactionRef SendMoney(CWallet* const pwallet, const CTxDestination& a if (nValue > curBalance) throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Insufficient funds"); - if (pwallet->GetBroadcastTransactions() && !pwallet->chain().p2pEnabled()) { - throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled"); - } - if (coin_control.IsUsingCoinJoin()) { mapValue["DS"] = "1"; } @@ -883,10 +879,6 @@ static UniValue sendmany(const JSONRPCRequest& request) LOCK(pwallet->cs_wallet); - if (pwallet->GetBroadcastTransactions() && !pwallet->chain().p2pEnabled()) { - throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled"); - } - if (!request.params[0].isNull() && !request.params[0].get_str().empty()) { throw JSONRPCError(RPC_INVALID_PARAMETER, "Dummy value must be set to \"\""); }