Skip to content

Commit 9ab9d63

Browse files
author
MarcoFalke
committed
Merge #16503: Remove p2pEnabled from Chain interface
b7b9f6e 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 bitcoin/bitcoin@5b446dd. ACKs for top commit: promag: ACK b7b9f6e jnewbery: ACK b7b9f6e Tree-SHA512: 4de2b9fc496bf8347ff5cc645848a5a44c8ca7596cd134f17f3088f5f8262d1d88b8e2a052df93e309ec9a81956a808df17a9eb9f10d4f4d693c95d607fe3561
2 parents 3277627 + b7b9f6e commit 9ab9d63

File tree

4 files changed

+3
-12
lines changed

4 files changed

+3
-12
lines changed

src/interfaces/chain.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,6 @@ class ChainImpl : public Chain
332332
LOCK(cs_main);
333333
return ::fHavePruned;
334334
}
335-
bool p2pEnabled() override { return g_connman != nullptr; }
336335
bool isReadyToBroadcast() override { return !::fImporting && !::fReindex && !isInitialBlockDownload(); }
337336
bool isInitialBlockDownload() override { return ::ChainstateActive().IsInitialBlockDownload(); }
338337
bool shutdownRequested() override { return ShutdownRequested(); }

src/interfaces/chain.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,6 @@ class Chain
187187
//! Check if any block has been pruned.
188188
virtual bool havePruned() = 0;
189189

190-
//! Check if p2p enabled.
191-
virtual bool p2pEnabled() = 0;
192-
193190
//! Check if the node is ready to broadcast transactions.
194191
virtual bool isReadyToBroadcast() = 0;
195192

src/node/transaction.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616

1717
TransactionError BroadcastTransaction(const CTransactionRef tx, std::string& err_string, const CAmount& max_tx_fee, bool relay, bool wait_callback)
1818
{
19+
// BroadcastTransaction can be called by either sendrawtransaction RPC or wallet RPCs.
20+
// g_connman is assigned both before chain clients and before RPC server is accepting calls,
21+
// and reset after chain clients and RPC sever are stopped. g_connman should never be null here.
1922
assert(g_connman);
2023
std::promise<void> promise;
2124
uint256 hashTx = tx->GetHash();

src/wallet/rpcwallet.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -309,10 +309,6 @@ static CTransactionRef SendMoney(interfaces::Chain::Lock& locked_chain, CWallet
309309
if (nValue > curBalance)
310310
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Insufficient funds");
311311

312-
if (pwallet->GetBroadcastTransactions() && !pwallet->chain().p2pEnabled()) {
313-
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
314-
}
315-
316312
// Parse Bitcoin address
317313
CScript scriptPubKey = GetScriptForDestination(address);
318314

@@ -845,10 +841,6 @@ static UniValue sendmany(const JSONRPCRequest& request)
845841
auto locked_chain = pwallet->chain().lock();
846842
LOCK(pwallet->cs_wallet);
847843

848-
if (pwallet->GetBroadcastTransactions() && !pwallet->chain().p2pEnabled()) {
849-
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
850-
}
851-
852844
if (!request.params[0].isNull() && !request.params[0].get_str().empty()) {
853845
throw JSONRPCError(RPC_INVALID_PARAMETER, "Dummy value must be set to \"\"");
854846
}

0 commit comments

Comments
 (0)