Skip to content

Commit

Permalink
fix rpc console crash in non server mode
Browse files Browse the repository at this point in the history
corrects the crashing of rpc console with getblocktemplate getwork
getwork2 and other commands
  • Loading branch information
cinnamoncoin committed Aug 20, 2014
1 parent dbb213b commit bd9a439
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 12 deletions.
9 changes: 1 addition & 8 deletions src/bitcoinrpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,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
Expand Down Expand Up @@ -732,8 +728,6 @@ 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"] == "") ||
Expand Down Expand Up @@ -854,8 +848,7 @@ void StartRPCThreads()

void StopRPCThreads()
{
delete pMiningKey; pMiningKey = NULL;


if (rpc_io_service == NULL) return;

rpc_io_service->stop();
Expand Down
4 changes: 3 additions & 1 deletion src/bitcoinrpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ class CRPCTable
};

extern const CRPCTable tableRPC;
extern CReserveKey* pMiningKey;

extern void InitRPCMining();
extern void ShutdownRPCMining();

extern int64 nWalletUnlockTime;
extern int64 AmountFromValue(const json_spirit::Value& value);
Expand Down
4 changes: 3 additions & 1 deletion src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ void Shutdown()
RenameThread("bitcoin-shutoff");
nTransactionsUpdated++;
StopRPCThreads();
bitdb.Flush(false);
ShutdownRPCMining();
bitdb.Flush(false);
StopNode();
{
LOCK(cs_main);
Expand Down Expand Up @@ -1083,6 +1084,7 @@ bool AppInit2(boost::thread_group& threadGroup)

StartNode(threadGroup);

InitRPCMining();
if (fServer)
StartRPCThreads();

Expand Down
4 changes: 2 additions & 2 deletions src/makefile.mingw
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ INCLUDEPATHS= \
-I"c:/deps/boost_1_55_0" \
-I"c:/deps/db-4.8.30.NC/build_unix" \
-I"c:/deps/miniupnpc" \
-I"c:/deps/openssl-1.0.1g/include"
-I"c:/deps/openssl-1.0.1h/include"

LIBPATHS= \
-L"$(CURDIR)/leveldb" \
-L"$(DEPSDIR)/lib" \
-L"c:/deps/boost_1_55_0/stage/lib" \
-L"c:/deps/db-4.8.30.NC/build_unix" \
-L"c:/deps/miniupnpc" \
-L"c:/deps/openssl-1.0.1g"
-L"c:/deps/openssl-1.0.1h"

LIBS= \
-l leveldb \
Expand Down
13 changes: 13 additions & 0 deletions src/rpcmining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@
using namespace json_spirit;
using namespace std;

static CReserveKey* pMiningKey = NULL;

void InitRPCMining()
{

pMiningKey = new CReserveKey(pwalletMain);
}

void ShutdownRPCMining()
{
delete pMiningKey; pMiningKey = NULL;
}

// Return average network hashes per second based on the last 'lookup' blocks,
// or from the last difficulty change if 'lookup' is nonpositive.
// If 'height' is nonnegative, compute the estimate at the time when a given block was found.
Expand Down

0 comments on commit bd9a439

Please sign in to comment.