Skip to content

Commit

Permalink
Merge bitcoin#11179: rpc: Push down safe mode checks
Browse files Browse the repository at this point in the history
ec6902d rpc: Push down safe mode checks (Andrew Chow)

Pull request description:

  This contains most of the changes of bitcoin#10563 "remove safe mode" by @achow101, but doesn't remove the safe mode yet, but put an `ObserveSafeMode()` check in (all 23) individual calls which used to have okSafeMode=false.

  This cleans up the ugly "okSafeMode" flag from the dispatch tables, which is not a concern for the RPC server.

  Extra-author: Wladimir J. van der Laan <laanwj@gmail.com>

Tree-SHA512: eee0f251fe2f38f122e7391e3c4e98d6a1e2757f3b718d6b560ad835ae94f11490865a0aef893e90b5fe298165932c8dd8298224173ac2677a5245cd532bac6e
  • Loading branch information
laanwj authored and PastaPastaPasta committed Sep 19, 2019
1 parent 48a55dd commit 8333834
Show file tree
Hide file tree
Showing 14 changed files with 206 additions and 167 deletions.
2 changes: 2 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ BITCOIN_CORE_H = \
rpc/client.h \
rpc/mining.h \
rpc/protocol.h \
rpc/safemode.h \
rpc/server.h \
rpc/register.h \
saltedhasher.h \
Expand Down Expand Up @@ -324,6 +325,7 @@ libdash_server_a_SOURCES = \
rpc/rawtransaction.cpp \
rpc/rpcevo.cpp \
rpc/rpcquorums.cpp \
rpc/safemode.cpp \
rpc/server.cpp \
script/sigcache.cpp \
script/ismine.cpp \
Expand Down
12 changes: 1 addition & 11 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "policy/policy.h"
#include "rpc/server.h"
#include "rpc/register.h"
#include "rpc/safemode.h"
#include "rpc/blockchain.h"
#include "script/standard.h"
#include "script/sigcache.h"
Expand Down Expand Up @@ -98,7 +99,6 @@
bool fFeeEstimatesInitialized = false;
static const bool DEFAULT_PROXYRANDOMIZE = true;
static const bool DEFAULT_REST_ENABLE = false;
static const bool DEFAULT_DISABLE_SAFEMODE = true;
static const bool DEFAULT_STOPAFTERBLOCKIMPORT = false;


Expand Down Expand Up @@ -419,15 +419,6 @@ void OnRPCStopped()
LogPrint(BCLog::RPC, "RPC stopped.\n");
}

void OnRPCPreCommand(const CRPCCommand& cmd)
{
// Observe safe mode
std::string strWarning = GetWarnings("rpc");
if (strWarning != "" && !gArgs.GetBoolArg("-disablesafemode", DEFAULT_DISABLE_SAFEMODE) &&
!cmd.okSafeMode)
throw JSONRPCError(RPC_FORBIDDEN_BY_SAFE_MODE, std::string("Safe mode: ") + strWarning);
}

std::string HelpMessage(HelpMessageMode mode)
{
const auto defaultBaseParams = CreateBaseChainParams(CBaseChainParams::MAIN);
Expand Down Expand Up @@ -878,7 +869,6 @@ bool AppInitServers(boost::thread_group& threadGroup)
{
RPCServer::OnStarted(&OnRPCStarted);
RPCServer::OnStopped(&OnRPCStopped);
RPCServer::OnPreCommand(&OnRPCPreCommand);
if (!InitHTTPServer())
return false;
if (!StartRPC())
Expand Down
2 changes: 1 addition & 1 deletion src/qt/test/rpcnestedtests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ static UniValue rpcNestedTest_rpc(const JSONRPCRequest& request)

static const CRPCCommand vRPCCommands[] =
{
{ "test", "rpcNestedTest", &rpcNestedTest_rpc, true, {} },
{ "test", "rpcNestedTest", &rpcNestedTest_rpc, {} },
};

void RPCNestedTests::rpcNestedTests()
Expand Down
64 changes: 32 additions & 32 deletions src/rpc/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2156,40 +2156,40 @@ UniValue getspecialtxes(const JSONRPCRequest& request)
}

static const CRPCCommand commands[] =
{ // category name actor (function) okSafe argNames
// --------------------- ------------------------ ----------------------- ------ ----------
{ "blockchain", "getblockchaininfo", &getblockchaininfo, true, {} },
{ "blockchain", "getchaintxstats", &getchaintxstats, true, {"nblocks", "blockhash"} },
{ "blockchain", "getblockstats", &getblockstats, true, {"hash_or_height", "stats"} },
{ "blockchain", "getbestblockhash", &getbestblockhash, true, {} },
{ "blockchain", "getblockcount", &getblockcount, true, {} },
{ "blockchain", "getblock", &getblock, true, {"blockhash","verbosity|verbose"} },
{ "blockchain", "getblockhashes", &getblockhashes, true, {"high","low"} },
{ "blockchain", "getblockhash", &getblockhash, true, {"height"} },
{ "blockchain", "getblockheader", &getblockheader, true, {"blockhash","verbose"} },
{ "blockchain", "getblockheaders", &getblockheaders, true, {"blockhash","count","verbose"} },
{ "blockchain", "getmerkleblocks", &getmerkleblocks, true, {"filter","blockhash","count"} },
{ "blockchain", "getchaintips", &getchaintips, true, {"count","branchlen"} },
{ "blockchain", "getdifficulty", &getdifficulty, true, {} },
{ "blockchain", "getmempoolancestors", &getmempoolancestors, true, {"txid","verbose"} },
{ "blockchain", "getmempooldescendants", &getmempooldescendants, true, {"txid","verbose"} },
{ "blockchain", "getmempoolentry", &getmempoolentry, true, {"txid"} },
{ "blockchain", "getmempoolinfo", &getmempoolinfo, true, {} },
{ "blockchain", "getrawmempool", &getrawmempool, true, {"verbose"} },
{ "blockchain", "getspecialtxes", &getspecialtxes, true, {"blockhash", "type", "count", "skip", "verbosity"} },
{ "blockchain", "gettxout", &gettxout, true, {"txid","n","include_mempool"} },
{ "blockchain", "gettxoutsetinfo", &gettxoutsetinfo, true, {} },
{ "blockchain", "pruneblockchain", &pruneblockchain, true, {"height"} },
{ "blockchain", "verifychain", &verifychain, true, {"checklevel","nblocks"} },

{ "blockchain", "preciousblock", &preciousblock, true, {"blockhash"} },
{ // category name actor (function) argNames
// --------------------- ------------------------ ----------------------- ----------
{ "blockchain", "getblockchaininfo", &getblockchaininfo, {} },
{ "blockchain", "getchaintxstats", &getchaintxstats, {"nblocks", "blockhash"} },
{ "blockchain", "getblockstats", &getblockstats, {"hash_or_height", "stats"} },
{ "blockchain", "getbestblockhash", &getbestblockhash, {} },
{ "blockchain", "getblockcount", &getblockcount, {} },
{ "blockchain", "getblock", &getblock, {"blockhash","verbosity|verbose"} },
{ "blockchain", "getblockhashes", &getblockhashes, {"high","low"} },
{ "blockchain", "getblockhash", &getblockhash, {"height"} },
{ "blockchain", "getblockheader", &getblockheader, {"blockhash","verbose"} },
{ "blockchain", "getblockheaders", &getblockheaders, {"blockhash","count","verbose"} },
{ "blockchain", "getmerkleblocks", &getmerkleblocks, {"filter","blockhash","count"} },
{ "blockchain", "getchaintips", &getchaintips, {"count","branchlen"} },
{ "blockchain", "getdifficulty", &getdifficulty, {} },
{ "blockchain", "getmempoolancestors", &getmempoolancestors, {"txid","verbose"} },
{ "blockchain", "getmempooldescendants", &getmempooldescendants, {"txid","verbose"} },
{ "blockchain", "getmempoolentry", &getmempoolentry, {"txid"} },
{ "blockchain", "getmempoolinfo", &getmempoolinfo, {} },
{ "blockchain", "getrawmempool", &getrawmempool, {"verbose"} },
{ "blockchain", "getspecialtxes", &getspecialtxes, {"blockhash", "type", "count", "skip", "verbosity"} },
{ "blockchain", "gettxout", &gettxout, {"txid","n","include_mempool"} },
{ "blockchain", "gettxoutsetinfo", &gettxoutsetinfo, {} },
{ "blockchain", "pruneblockchain", &pruneblockchain, {"height"} },
{ "blockchain", "verifychain", &verifychain, {"checklevel","nblocks"} },

{ "blockchain", "preciousblock", &preciousblock, {"blockhash"} },

/* Not shown in help */
{ "hidden", "invalidateblock", &invalidateblock, true, {"blockhash"} },
{ "hidden", "reconsiderblock", &reconsiderblock, true, {"blockhash"} },
{ "hidden", "waitfornewblock", &waitfornewblock, true, {"timeout"} },
{ "hidden", "waitforblock", &waitforblock, true, {"blockhash","timeout"} },
{ "hidden", "waitforblockheight", &waitforblockheight, true, {"height","timeout"} },
{ "hidden", "invalidateblock", &invalidateblock, {"blockhash"} },
{ "hidden", "reconsiderblock", &reconsiderblock, {"blockhash"} },
{ "hidden", "waitfornewblock", &waitfornewblock, {"timeout"} },
{ "hidden", "waitforblock", &waitforblock, {"blockhash","timeout"} },
{ "hidden", "waitforblockheight", &waitforblockheight, {"height","timeout"} },
};

void RegisterBlockchainRPCCommands(CRPCTable &t)
Expand Down
21 changes: 11 additions & 10 deletions src/rpc/mining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -991,21 +991,22 @@ UniValue estimaterawfee(const JSONRPCRequest& request)
}

static const CRPCCommand commands[] =
{ // category name actor (function) okSafeMode
{ // category name actor (function) argNames
// --------------------- ------------------------ ----------------------- ----------
{ "mining", "getnetworkhashps", &getnetworkhashps, true, {"nblocks","height"} },
{ "mining", "getmininginfo", &getmininginfo, true, {} },
{ "mining", "prioritisetransaction", &prioritisetransaction, true, {"txid","fee_delta"} },
{ "mining", "getblocktemplate", &getblocktemplate, true, {"template_request"} },
{ "mining", "submitblock", &submitblock, true, {"hexdata","dummy"} },
{ "mining", "getnetworkhashps", &getnetworkhashps, {"nblocks","height"} },
{ "mining", "getmininginfo", &getmininginfo, {} },
{ "mining", "prioritisetransaction", &prioritisetransaction, {"txid","fee_delta"} },
{ "mining", "getblocktemplate", &getblocktemplate, {"template_request"} },
{ "mining", "submitblock", &submitblock, {"hexdata","dummy"} },

#if ENABLE_MINER
{ "generating", "generatetoaddress", &generatetoaddress, true, {"nblocks","address","maxtries"} },
{ "generating", "generatetoaddress", &generatetoaddress, {"nblocks","address","maxtries"} },
#endif // ENABLE_MINER
{ "util", "estimatefee", &estimatefee, true, {"nblocks"} },
{ "util", "estimatesmartfee", &estimatesmartfee, true, {"conf_target", "estimate_mode"} },

{ "hidden", "estimaterawfee", &estimaterawfee, true, {"conf_target", "threshold"} },
{ "util", "estimatefee", &estimatefee, {"nblocks"} },
{ "util", "estimatesmartfee", &estimatesmartfee, {"nblocks", "estimate_mode"} },

{ "hidden", "estimaterawfee", &estimaterawfee, {"conf_target", "threshold"} },
};

void RegisterMiningRPCCommands(CRPCTable &t)
Expand Down
40 changes: 20 additions & 20 deletions src/rpc/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1287,33 +1287,33 @@ UniValue echo(const JSONRPCRequest& request)
}

static const CRPCCommand commands[] =
{ // category name actor (function) okSafeMode
{ // category name actor (function) argNames
// --------------------- ------------------------ ----------------------- ----------
{ "control", "debug", &debug, true, {} },
{ "control", "getinfo", &getinfo, true, {} }, /* uses wallet if enabled */
{ "control", "getmemoryinfo", &getmemoryinfo, true, {"mode"} },
{ "util", "validateaddress", &validateaddress, true, {"address"} }, /* uses wallet if enabled */
{ "util", "createmultisig", &createmultisig, true, {"nrequired","keys"} },
{ "util", "verifymessage", &verifymessage, true, {"address","signature","message"} },
{ "util", "signmessagewithprivkey", &signmessagewithprivkey, true, {"privkey","message"} },
{ "blockchain", "getspentinfo", &getspentinfo, false, {"json"} },
{ "control", "debug", &debug, {} },
{ "control", "getinfo", &getinfo, {} }, /* uses wallet if enabled */
{ "control", "getmemoryinfo", &getmemoryinfo, {"mode"} },
{ "util", "validateaddress", &validateaddress, {"address"} }, /* uses wallet if enabled */
{ "util", "createmultisig", &createmultisig, {"nrequired","keys"} },
{ "util", "verifymessage", &verifymessage, {"address","signature","message"} },
{ "util", "signmessagewithprivkey", &signmessagewithprivkey, {"privkey","message"} },
{ "blockchain", "getspentinfo", &getspentinfo, {"json"} },

/* Address index */
{ "addressindex", "getaddressmempool", &getaddressmempool, true, {"addresses"} },
{ "addressindex", "getaddressutxos", &getaddressutxos, false, {"addresses"} },
{ "addressindex", "getaddressdeltas", &getaddressdeltas, false, {"addresses"} },
{ "addressindex", "getaddresstxids", &getaddresstxids, false, {"addresses"} },
{ "addressindex", "getaddressbalance", &getaddressbalance, false, {"addresses"} },
{ "addressindex", "getaddressmempool", &getaddressmempool, {"addresses"} },
{ "addressindex", "getaddressutxos", &getaddressutxos, {"addresses"} },
{ "addressindex", "getaddressdeltas", &getaddressdeltas, {"addresses"} },
{ "addressindex", "getaddresstxids", &getaddresstxids, {"addresses"} },
{ "addressindex", "getaddressbalance", &getaddressbalance, {"addresses"} },

/* Dash features */
{ "dash", "mnsync", &mnsync, true, {} },
{ "dash", "spork", &spork, true, {"value"} },
{ "dash", "mnsync", &mnsync, {} },
{ "dash", "spork", &spork, {"value"} },

/* Not shown in help */
{ "hidden", "setmocktime", &setmocktime, true, {"timestamp"}},
{ "hidden", "echo", &echo, true, {"arg0","arg1","arg2","arg3","arg4","arg5","arg6","arg7","arg8","arg9"}},
{ "hidden", "echojson", &echo, true, {"arg0","arg1","arg2","arg3","arg4","arg5","arg6","arg7","arg8","arg9"}},
{ "hidden", "logging", &logging, true, {"include", "exclude"}},
{ "hidden", "setmocktime", &setmocktime, {"timestamp"}},
{ "hidden", "echo", &echo, {"arg0","arg1","arg2","arg3","arg4","arg5","arg6","arg7","arg8","arg9"}},
{ "hidden", "echojson", &echo, {"arg0","arg1","arg2","arg3","arg4","arg5","arg6","arg7","arg8","arg9"}},
{ "hidden", "logging", &logging, {"include", "exclude"}},
};

void RegisterMiscRPCCommands(CRPCTable &t)
Expand Down
26 changes: 13 additions & 13 deletions src/rpc/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -625,20 +625,20 @@ UniValue setnetworkactive(const JSONRPCRequest& request)
}

static const CRPCCommand commands[] =
{ // category name actor (function) okSafeMode
{ // category name actor (function) argNames
// --------------------- ------------------------ ----------------------- ----------
{ "network", "getconnectioncount", &getconnectioncount, true, {} },
{ "network", "ping", &ping, true, {} },
{ "network", "getpeerinfo", &getpeerinfo, true, {} },
{ "network", "addnode", &addnode, true, {"node","command"} },
{ "network", "disconnectnode", &disconnectnode, true, {"address", "nodeid"} },
{ "network", "getaddednodeinfo", &getaddednodeinfo, true, {"node"} },
{ "network", "getnettotals", &getnettotals, true, {} },
{ "network", "getnetworkinfo", &getnetworkinfo, true, {} },
{ "network", "setban", &setban, true, {"subnet", "command", "bantime", "absolute"} },
{ "network", "listbanned", &listbanned, true, {} },
{ "network", "clearbanned", &clearbanned, true, {} },
{ "network", "setnetworkactive", &setnetworkactive, true, {"state"} },
{ "network", "getconnectioncount", &getconnectioncount, {} },
{ "network", "ping", &ping, {} },
{ "network", "getpeerinfo", &getpeerinfo, {} },
{ "network", "addnode", &addnode, {"node","command"} },
{ "network", "disconnectnode", &disconnectnode, {"address", "nodeid"} },
{ "network", "getaddednodeinfo", &getaddednodeinfo, {"node"} },
{ "network", "getnettotals", &getnettotals, {} },
{ "network", "getnetworkinfo", &getnetworkinfo, {} },
{ "network", "setban", &setban, {"subnet", "command", "bantime", "absolute"} },
{ "network", "listbanned", &listbanned, {} },
{ "network", "clearbanned", &clearbanned, {} },
{ "network", "setnetworkactive", &setnetworkactive, {"state"} },
};

void RegisterNetRPCCommands(CRPCTable &t)
Expand Down

0 comments on commit 8333834

Please sign in to comment.