Skip to content

Commit b7b9f6e

Browse files
author
Antoine Riard
committed
Remove p2pEnabled from Chain interface
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.
1 parent e5fdda6 commit b7b9f6e

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)