From d98bf10f23e0e633ff2ff33075a353d30bf862b4 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Thu, 30 May 2013 15:51:41 +0200 Subject: Move pMiningKey init out of StartRPCThreads This commit decouples the pMiningKey initialization and shutdown from the RPC threads. `getwork` and `getblocktemplate` rely on pMiningKey, and can also be ran from the debug window in the UI even when the RPC server is not running. Solves issue #2706. --- src/bitcoinrpc.cpp | 9 --------- src/bitcoinrpc.h | 4 +++- src/init.cpp | 3 +++ src/rpcmining.cpp | 15 +++++++++++++++ 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index 2c4744a579..a9b73fd5a6 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -30,10 +30,6 @@ using namespace boost; using namespace boost::asio; using namespace json_spirit; -// Key used by getwork/getblocktemplate miners. -// Allocated in StartRPCThreads, free'd in StopRPCThreads -CReserveKey* pMiningKey = NULL; - static std::string strRPCUserColonPass; // These are created by StartRPCThreads, destroyed in StopRPCThreads @@ -726,9 +722,6 @@ static void RPCAcceptHandler(boost::shared_ptr< basic_socket_acceptorstop(); diff --git a/src/bitcoinrpc.h b/src/bitcoinrpc.h index cf5b137988..547cccf44b 100644 --- a/src/bitcoinrpc.h +++ b/src/bitcoinrpc.h @@ -123,7 +123,9 @@ public: }; extern const CRPCTable tableRPC; -extern CReserveKey* pMiningKey; + +extern void InitRPCMining(); +extern void ShutdownRPCMining(); extern int64 nWalletUnlockTime; extern int64 AmountFromValue(const json_spirit::Value& value); diff --git a/src/init.cpp b/src/init.cpp index 767d7525a6..9c807b288e 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -96,6 +96,7 @@ void Shutdown() RenameThread("bitcoin-shutoff"); nTransactionsUpdated++; StopRPCThreads(); + ShutdownRPCMining(); bitdb.Flush(false); StopNode(); { @@ -1081,6 +1082,8 @@ bool AppInit2(boost::thread_group& threadGroup) StartNode(threadGroup); + // InitRPCMining is needed here so getwork/getblocktemplate in the GUI debug console works properly. + InitRPCMining(); if (fServer) StartRPCThreads(); diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp index b8b7459634..845e7f1f9c 100644 --- a/src/rpcmining.cpp +++ b/src/rpcmining.cpp @@ -11,6 +11,21 @@ using namespace json_spirit; using namespace std; +// Key used by getwork/getblocktemplate miners. +// Allocated in InitRPCMining, free'd in ShutdownRPCMining +static CReserveKey* pMiningKey = NULL; + +void InitRPCMining() +{ + // getwork/getblocktemplate mining rewards paid here: + pMiningKey = new CReserveKey(pwalletMain); +} + +void ShutdownRPCMining() +{ + delete pMiningKey; pMiningKey = NULL; +} + Value getgenerate(const Array& params, bool fHelp) { if (fHelp || params.size() != 0) -- cgit v1.2.3