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.
This commit is contained in:
parent
e5fdda68c6
commit
b7b9f6e4ce
4 changed files with 3 additions and 12 deletions
|
@ -332,7 +332,6 @@ public:
|
||||||
LOCK(cs_main);
|
LOCK(cs_main);
|
||||||
return ::fHavePruned;
|
return ::fHavePruned;
|
||||||
}
|
}
|
||||||
bool p2pEnabled() override { return g_connman != nullptr; }
|
|
||||||
bool isReadyToBroadcast() override { return !::fImporting && !::fReindex && !isInitialBlockDownload(); }
|
bool isReadyToBroadcast() override { return !::fImporting && !::fReindex && !isInitialBlockDownload(); }
|
||||||
bool isInitialBlockDownload() override { return ::ChainstateActive().IsInitialBlockDownload(); }
|
bool isInitialBlockDownload() override { return ::ChainstateActive().IsInitialBlockDownload(); }
|
||||||
bool shutdownRequested() override { return ShutdownRequested(); }
|
bool shutdownRequested() override { return ShutdownRequested(); }
|
||||||
|
|
|
@ -187,9 +187,6 @@ public:
|
||||||
//! Check if any block has been pruned.
|
//! Check if any block has been pruned.
|
||||||
virtual bool havePruned() = 0;
|
virtual bool havePruned() = 0;
|
||||||
|
|
||||||
//! Check if p2p enabled.
|
|
||||||
virtual bool p2pEnabled() = 0;
|
|
||||||
|
|
||||||
//! Check if the node is ready to broadcast transactions.
|
//! Check if the node is ready to broadcast transactions.
|
||||||
virtual bool isReadyToBroadcast() = 0;
|
virtual bool isReadyToBroadcast() = 0;
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,9 @@
|
||||||
|
|
||||||
TransactionError BroadcastTransaction(const CTransactionRef tx, std::string& err_string, const CAmount& max_tx_fee, bool relay, bool wait_callback)
|
TransactionError BroadcastTransaction(const CTransactionRef tx, std::string& err_string, const CAmount& max_tx_fee, bool relay, bool wait_callback)
|
||||||
{
|
{
|
||||||
|
// 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(g_connman);
|
assert(g_connman);
|
||||||
std::promise<void> promise;
|
std::promise<void> promise;
|
||||||
uint256 hashTx = tx->GetHash();
|
uint256 hashTx = tx->GetHash();
|
||||||
|
|
|
@ -309,10 +309,6 @@ static CTransactionRef SendMoney(interfaces::Chain::Lock& locked_chain, CWallet
|
||||||
if (nValue > curBalance)
|
if (nValue > curBalance)
|
||||||
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Insufficient funds");
|
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");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parse Bitcoin address
|
// Parse Bitcoin address
|
||||||
CScript scriptPubKey = GetScriptForDestination(address);
|
CScript scriptPubKey = GetScriptForDestination(address);
|
||||||
|
|
||||||
|
@ -845,10 +841,6 @@ static UniValue sendmany(const JSONRPCRequest& request)
|
||||||
auto locked_chain = pwallet->chain().lock();
|
auto locked_chain = pwallet->chain().lock();
|
||||||
LOCK(pwallet->cs_wallet);
|
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()) {
|
if (!request.params[0].isNull() && !request.params[0].get_str().empty()) {
|
||||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Dummy value must be set to \"\"");
|
throw JSONRPCError(RPC_INVALID_PARAMETER, "Dummy value must be set to \"\"");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue