From 36e826cea14585f68d5c363a82c1a887a779e130 Mon Sep 17 00:00:00 2001 From: Gavin Andresen Date: Thu, 23 May 2013 14:13:05 -0400 Subject: Clean up mining CReserveKey to prevent crash at shutdown Fixes issue#2687 --- src/rpcmining.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'src/rpcmining.cpp') diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp index fddda8b5f..b8b745963 100644 --- a/src/rpcmining.cpp +++ b/src/rpcmining.cpp @@ -104,7 +104,6 @@ Value getwork(const Array& params, bool fHelp) typedef map > mapNewBlock_t; static mapNewBlock_t mapNewBlock; // FIXME: thread safety static vector vNewBlockTemplate; - static CReserveKey reservekey(pwalletMain); if (params.size() == 0) { @@ -134,7 +133,7 @@ Value getwork(const Array& params, bool fHelp) nStart = GetTime(); // Create new block - pblocktemplate = CreateNewBlock(reservekey); + pblocktemplate = CreateNewBlock(*pMiningKey); if (!pblocktemplate) throw JSONRPCError(RPC_OUT_OF_MEMORY, "Out of memory"); vNewBlockTemplate.push_back(pblocktemplate); @@ -192,7 +191,7 @@ Value getwork(const Array& params, bool fHelp) pblock->vtx[0].vin[0].scriptSig = mapNewBlock[pdata->hashMerkleRoot].second; pblock->hashMerkleRoot = pblock->BuildMerkleTree(); - return CheckWork(pblock, *pwalletMain, reservekey); + return CheckWork(pblock, *pwalletMain, *pMiningKey); } } @@ -243,8 +242,6 @@ Value getblocktemplate(const Array& params, bool fHelp) if (IsInitialBlockDownload()) throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD, "Bitcoin is downloading blocks..."); - static CReserveKey reservekey(pwalletMain); - // Update block static unsigned int nTransactionsUpdatedLast; static CBlockIndex* pindexPrev; @@ -267,7 +264,7 @@ Value getblocktemplate(const Array& params, bool fHelp) delete pblocktemplate; pblocktemplate = NULL; } - pblocktemplate = CreateNewBlock(reservekey); + pblocktemplate = CreateNewBlock(*pMiningKey); if (!pblocktemplate) throw JSONRPCError(RPC_OUT_OF_MEMORY, "Out of memory"); -- cgit v1.2.3 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/rpcmining.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/rpcmining.cpp') diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp index b8b745963..845e7f1f9 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 From 3260b4c09006ea5c1b00c599a14e6c706ac760f8 Mon Sep 17 00:00:00 2001 From: Philip Kaufmann Date: Sun, 28 Apr 2013 17:37:50 +0200 Subject: remove GetBoolArg() fDefault parameter defaulting to false - explicitly set the default of all GetBoolArg() calls - rework getarg_test.cpp and util_tests.cpp to cover this change - some indentation fixes - move macdockiconhandler.h include in bitcoin.cpp to the "our headers" section --- src/rpcmining.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'src/rpcmining.cpp') diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp index 845e7f1f9..d2cac6870 100644 --- a/src/rpcmining.cpp +++ b/src/rpcmining.cpp @@ -33,7 +33,7 @@ Value getgenerate(const Array& params, bool fHelp) "getgenerate\n" "Returns true or false."); - return GetBoolArg("-gen"); + return GetBoolArg("-gen", false); } @@ -84,16 +84,16 @@ Value getmininginfo(const Array& params, bool fHelp) "Returns an object containing mining-related information."); Object obj; - obj.push_back(Pair("blocks", (int)nBestHeight)); - obj.push_back(Pair("currentblocksize",(uint64_t)nLastBlockSize)); - obj.push_back(Pair("currentblocktx",(uint64_t)nLastBlockTx)); - obj.push_back(Pair("difficulty", (double)GetDifficulty())); - obj.push_back(Pair("errors", GetWarnings("statusbar"))); - obj.push_back(Pair("generate", GetBoolArg("-gen"))); - obj.push_back(Pair("genproclimit", (int)GetArg("-genproclimit", -1))); - obj.push_back(Pair("hashespersec", gethashespersec(params, false))); - obj.push_back(Pair("pooledtx", (uint64_t)mempool.size())); - obj.push_back(Pair("testnet", fTestNet)); + obj.push_back(Pair("blocks", (int)nBestHeight)); + obj.push_back(Pair("currentblocksize", (uint64_t)nLastBlockSize)); + obj.push_back(Pair("currentblocktx", (uint64_t)nLastBlockTx)); + obj.push_back(Pair("difficulty", (double)GetDifficulty())); + obj.push_back(Pair("errors", GetWarnings("statusbar"))); + obj.push_back(Pair("generate", GetBoolArg("-gen", false))); + obj.push_back(Pair("genproclimit", (int)GetArg("-genproclimit", -1))); + obj.push_back(Pair("hashespersec", gethashespersec(params, false))); + obj.push_back(Pair("pooledtx", (uint64_t)mempool.size())); + obj.push_back(Pair("testnet", fTestNet)); return obj; } -- cgit v1.2.3