From 0e1d3551da570655d141d4b6d0b1bdbc0e931dbb Mon Sep 17 00:00:00 2001 From: Jeff Garzik Date: Tue, 21 Aug 2012 12:03:52 -0400 Subject: [PATCH] RPC: add facility to enable RPCs to run outside cs_main, wallet locks Use with 'stop' and 'help' RPCs. This provides a facility to individually evaluate the locking for an RPC, and potentially make it more parallel. --- src/bitcoinrpc.cpp | 120 +++++++++++++++++++++++---------------------- src/bitcoinrpc.h | 1 + 2 files changed, 63 insertions(+), 58 deletions(-) diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index 8991de7dea9..5537eb4815f 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -191,62 +191,62 @@ Value stop(const Array& params, bool fHelp) static const CRPCCommand vRPCCommands[] = -{ // name function safe mode? - // ------------------------ ----------------------- ---------- - { "help", &help, true }, - { "stop", &stop, true }, - { "getblockcount", &getblockcount, true }, - { "getconnectioncount", &getconnectioncount, true }, - { "getpeerinfo", &getpeerinfo, true }, - { "getdifficulty", &getdifficulty, true }, - { "getgenerate", &getgenerate, true }, - { "setgenerate", &setgenerate, true }, - { "gethashespersec", &gethashespersec, true }, - { "getinfo", &getinfo, true }, - { "getmininginfo", &getmininginfo, true }, - { "getnewaddress", &getnewaddress, true }, - { "getaccountaddress", &getaccountaddress, true }, - { "setaccount", &setaccount, true }, - { "getaccount", &getaccount, false }, - { "getaddressesbyaccount", &getaddressesbyaccount, true }, - { "sendtoaddress", &sendtoaddress, false }, - { "getreceivedbyaddress", &getreceivedbyaddress, false }, - { "getreceivedbyaccount", &getreceivedbyaccount, false }, - { "listreceivedbyaddress", &listreceivedbyaddress, false }, - { "listreceivedbyaccount", &listreceivedbyaccount, false }, - { "backupwallet", &backupwallet, true }, - { "keypoolrefill", &keypoolrefill, true }, - { "walletpassphrase", &walletpassphrase, true }, - { "walletpassphrasechange", &walletpassphrasechange, false }, - { "walletlock", &walletlock, true }, - { "encryptwallet", &encryptwallet, false }, - { "validateaddress", &validateaddress, true }, - { "getbalance", &getbalance, false }, - { "move", &movecmd, false }, - { "sendfrom", &sendfrom, false }, - { "sendmany", &sendmany, false }, - { "addmultisigaddress", &addmultisigaddress, false }, - { "getrawmempool", &getrawmempool, true }, - { "getblock", &getblock, false }, - { "getblockhash", &getblockhash, false }, - { "gettransaction", &gettransaction, false }, - { "listtransactions", &listtransactions, false }, - { "signmessage", &signmessage, false }, - { "verifymessage", &verifymessage, false }, - { "getwork", &getwork, true }, - { "listaccounts", &listaccounts, false }, - { "settxfee", &settxfee, false }, - { "getblocktemplate", &getblocktemplate, true }, - { "submitblock", &submitblock, false }, - { "listsinceblock", &listsinceblock, false }, - { "dumpprivkey", &dumpprivkey, false }, - { "importprivkey", &importprivkey, false }, - { "listunspent", &listunspent, false }, - { "getrawtransaction", &getrawtransaction, false }, - { "createrawtransaction", &createrawtransaction, false }, - { "decoderawtransaction", &decoderawtransaction, false }, - { "signrawtransaction", &signrawtransaction, false }, - { "sendrawtransaction", &sendrawtransaction, false }, +{ // name function safemd unlocked + // ------------------------ ----------------------- ------ -------- + { "help", &help, true, true }, + { "stop", &stop, true, true }, + { "getblockcount", &getblockcount, true, false }, + { "getconnectioncount", &getconnectioncount, true, false }, + { "getpeerinfo", &getpeerinfo, true, false }, + { "getdifficulty", &getdifficulty, true, false }, + { "getgenerate", &getgenerate, true, false }, + { "setgenerate", &setgenerate, true, false }, + { "gethashespersec", &gethashespersec, true, false }, + { "getinfo", &getinfo, true, false }, + { "getmininginfo", &getmininginfo, true, false }, + { "getnewaddress", &getnewaddress, true, false }, + { "getaccountaddress", &getaccountaddress, true, false }, + { "setaccount", &setaccount, true, false }, + { "getaccount", &getaccount, false, false }, + { "getaddressesbyaccount", &getaddressesbyaccount, true, false }, + { "sendtoaddress", &sendtoaddress, false, false }, + { "getreceivedbyaddress", &getreceivedbyaddress, false, false }, + { "getreceivedbyaccount", &getreceivedbyaccount, false, false }, + { "listreceivedbyaddress", &listreceivedbyaddress, false, false }, + { "listreceivedbyaccount", &listreceivedbyaccount, false, false }, + { "backupwallet", &backupwallet, true, false }, + { "keypoolrefill", &keypoolrefill, true, false }, + { "walletpassphrase", &walletpassphrase, true, false }, + { "walletpassphrasechange", &walletpassphrasechange, false, false }, + { "walletlock", &walletlock, true, false }, + { "encryptwallet", &encryptwallet, false, false }, + { "validateaddress", &validateaddress, true, false }, + { "getbalance", &getbalance, false, false }, + { "move", &movecmd, false, false }, + { "sendfrom", &sendfrom, false, false }, + { "sendmany", &sendmany, false, false }, + { "addmultisigaddress", &addmultisigaddress, false, false }, + { "getrawmempool", &getrawmempool, true, false }, + { "getblock", &getblock, false, false }, + { "getblockhash", &getblockhash, false, false }, + { "gettransaction", &gettransaction, false, false }, + { "listtransactions", &listtransactions, false, false }, + { "signmessage", &signmessage, false, false }, + { "verifymessage", &verifymessage, false, false }, + { "getwork", &getwork, true, false }, + { "listaccounts", &listaccounts, false, false }, + { "settxfee", &settxfee, false, false }, + { "getblocktemplate", &getblocktemplate, true, false }, + { "submitblock", &submitblock, false, false }, + { "listsinceblock", &listsinceblock, false, false }, + { "dumpprivkey", &dumpprivkey, false, false }, + { "importprivkey", &importprivkey, false, false }, + { "listunspent", &listunspent, false, false }, + { "getrawtransaction", &getrawtransaction, false, false }, + { "createrawtransaction", &createrawtransaction, false, false }, + { "decoderawtransaction", &decoderawtransaction, false, false }, + { "signrawtransaction", &signrawtransaction, false, false }, + { "sendrawtransaction", &sendrawtransaction, false, false }, }; CRPCTable::CRPCTable() @@ -1008,8 +1008,12 @@ json_spirit::Value CRPCTable::execute(const std::string &strMethod, const json_s // Execute Value result; { - LOCK2(cs_main, pwalletMain->cs_wallet); - result = pcmd->actor(params, false); + if (pcmd->unlocked) + result = pcmd->actor(params, false); + else { + LOCK2(cs_main, pwalletMain->cs_wallet); + result = pcmd->actor(params, false); + } } return result; } diff --git a/src/bitcoinrpc.h b/src/bitcoinrpc.h index 4abda7eda6b..f70216392d4 100644 --- a/src/bitcoinrpc.h +++ b/src/bitcoinrpc.h @@ -46,6 +46,7 @@ public: std::string name; rpcfn_type actor; bool okSafeMode; + bool unlocked; }; /**