]> Git Repo - VerusCoin.git/commitdiff
Clean up mining CReserveKey to prevent crash at shutdown
authorGavin Andresen <[email protected]>
Thu, 23 May 2013 18:13:05 +0000 (14:13 -0400)
committerGavin Andresen <[email protected]>
Thu, 23 May 2013 18:17:15 +0000 (14:17 -0400)
Fixes issue#2687

src/bitcoinrpc.cpp
src/bitcoinrpc.h
src/rpcmining.cpp

index a9b73fd5a6a033aa58566923a1bc4aaebf129fb6..2c4744a579ea689f6fce7c01dc0ff17b51560651 100644 (file)
@@ -30,6 +30,10 @@ 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
@@ -722,6 +726,9 @@ static void RPCAcceptHandler(boost::shared_ptr< basic_socket_acceptor<Protocol,
 
 void StartRPCThreads()
 {
+    // getwork/getblocktemplate mining rewards paid here:
+    pMiningKey = new CReserveKey(pwalletMain);
+
     strRPCUserColonPass = mapArgs["-rpcuser"] + ":" + mapArgs["-rpcpassword"];
     if ((mapArgs["-rpcpassword"] == "") ||
         (mapArgs["-rpcuser"] == mapArgs["-rpcpassword"]))
@@ -841,6 +848,8 @@ void StartRPCThreads()
 
 void StopRPCThreads()
 {
+    delete pMiningKey; pMiningKey = NULL;
+
     if (rpc_io_service == NULL) return;
 
     rpc_io_service->stop();
index 315fd92383d593d4c8ddd47a1da85efd967cdc60..cf5b1379883561cfe8f7e03ea461515339122c44 100644 (file)
@@ -11,6 +11,7 @@
 #include <map>
 
 class CBlockIndex;
+class CReserveKey;
 
 #include "json/json_spirit_reader_template.h"
 #include "json/json_spirit_writer_template.h"
@@ -122,6 +123,7 @@ public:
 };
 
 extern const CRPCTable tableRPC;
+extern CReserveKey* pMiningKey;
 
 extern int64 nWalletUnlockTime;
 extern int64 AmountFromValue(const json_spirit::Value& value);
index fddda8b5f4ee9bf1d790337c3a3b47488f1ee41c..b8b7459634550dedf79fb0155546a8f3c94712fd 100644 (file)
@@ -104,7 +104,6 @@ Value getwork(const Array& params, bool fHelp)
     typedef map<uint256, pair<CBlock*, CScript> > mapNewBlock_t;
     static mapNewBlock_t mapNewBlock;    // FIXME: thread safety
     static vector<CBlockTemplate*> 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");
 
This page took 0.035719 seconds and 4 git commands to generate.