Skip to content

Commit 4a85e06

Browse files
committed
Allow mining RPCs with --disable-wallet
The following mining-related RPC calls don't use the wallet: - getnetworkhashps - getmininginfo - getblocktemplate - submitblock Enable them when compiling with --disable-wallet.
1 parent 70370ae commit 4a85e06

File tree

6 files changed

+44
-20
lines changed

6 files changed

+44
-20
lines changed

doc/build-unix.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,3 +187,7 @@ disable-wallet mode with:
187187
./configure --disable-wallet
188188

189189
In this case there is no dependency on Berkeley DB 4.8.
190+
191+
Mining is also possible in disable-wallet mode, but only using the `getblocktemplate` RPC
192+
call not `getwork`.
193+

src/Makefile.am

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,11 @@ libbitcoin_server_a_SOURCES = \
4848
keystore.cpp \
4949
leveldbwrapper.cpp \
5050
main.cpp \
51+
miner.cpp \
5152
net.cpp \
5253
noui.cpp \
5354
rpcblockchain.cpp \
55+
rpcmining.cpp \
5456
rpcnet.cpp \
5557
rpcrawtransaction.cpp \
5658
txdb.cpp \
@@ -61,9 +63,7 @@ libbitcoin_server_a_SOURCES = \
6163
libbitcoin_wallet_a_SOURCES = \
6264
db.cpp \
6365
crypter.cpp \
64-
miner.cpp \
6566
rpcdump.cpp \
66-
rpcmining.cpp \
6767
rpcwallet.cpp \
6868
wallet.cpp \
6969
walletdb.cpp \

src/init.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ void Shutdown()
113113
RenameThread("bitcoin-shutoff");
114114
mempool.AddTransactionsUpdated(1);
115115
StopRPCThreads();
116-
#ifdef ENABLE_WALLET
117116
ShutdownRPCMining();
117+
#ifdef ENABLE_WALLET
118118
if (pwalletMain)
119119
bitdb.Flush(false);
120120
GenerateBitcoins(false, NULL, 0);
@@ -1041,10 +1041,8 @@ bool AppInit2(boost::thread_group& threadGroup, bool fForceServer)
10411041
#endif
10421042

10431043
StartNode(threadGroup);
1044-
#ifdef ENABLE_WALLET
10451044
// InitRPCMining is needed here so getwork/getblocktemplate in the GUI debug console works properly.
10461045
InitRPCMining();
1047-
#endif
10481046
if (fServer)
10491047
StartRPCThreads();
10501048

src/miner.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@
1010
#include "net.h"
1111
#include "wallet.h"
1212

13+
#ifdef ENABLE_WALLET
14+
// These globals are only used by the built-in miner
1315
double dHashesPerSec = 0.0;
1416
int64_t nHPSTimerStart = 0;
17+
#endif
1518

1619
//////////////////////////////////////////////////////////////////////////////
1720
//
@@ -381,6 +384,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
381384
return pblocktemplate.release();
382385
}
383386

387+
#ifdef ENABLE_WALLET
384388
CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey)
385389
{
386390
CPubKey pubkey;
@@ -390,6 +394,7 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey)
390394
CScript scriptPubKey = CScript() << pubkey << OP_CHECKSIG;
391395
return CreateNewBlock(scriptPubKey);
392396
}
397+
#endif
393398

394399
void IncrementExtraNonce(CBlock* pblock, CBlockIndex* pindexPrev, unsigned int& nExtraNonce)
395400
{
@@ -454,7 +459,7 @@ void FormatHashBuffers(CBlock* pblock, char* pmidstate, char* pdata, char* phash
454459
memcpy(phash1, &tmp.hash1, 64);
455460
}
456461

457-
462+
#ifdef ENABLE_WALLET
458463
bool CheckWork(CBlock* pblock, CWallet& wallet, CReserveKey& reservekey)
459464
{
460465
uint256 hash = pblock->GetHash();
@@ -665,5 +670,5 @@ void GenerateBitcoins(bool fGenerate, CWallet* pwallet, int nThreads)
665670
minerThreads->create_thread(boost::bind(&BitcoinMiner, pwallet));
666671
}
667672

668-
673+
#endif
669674

src/rpcmining.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
using namespace json_spirit;
2121
using namespace std;
2222

23-
// Key used by getwork/getblocktemplate miners.
23+
#ifdef ENABLE_WALLET
24+
// Key used by getwork miners.
2425
// Allocated in InitRPCMining, free'd in ShutdownRPCMining
2526
static CReserveKey* pMiningKey = NULL;
2627

@@ -40,6 +41,14 @@ void ShutdownRPCMining()
4041

4142
delete pMiningKey; pMiningKey = NULL;
4243
}
44+
#else
45+
void InitRPCMining()
46+
{
47+
}
48+
void ShutdownRPCMining()
49+
{
50+
}
51+
#endif
4352

4453
// Return average network hashes per second based on the last 'lookup' blocks,
4554
// or from the last difficulty change if 'lookup' is nonpositive.
@@ -99,7 +108,7 @@ Value getnetworkhashps(const Array& params, bool fHelp)
99108
return GetNetworkHashPS(params.size() > 0 ? params[0].get_int() : 120, params.size() > 1 ? params[1].get_int() : -1);
100109
}
101110

102-
111+
#ifdef ENABLE_WALLET
103112
Value getgenerate(const Array& params, bool fHelp)
104113
{
105114
if (fHelp || params.size() != 0)
@@ -197,7 +206,6 @@ Value setgenerate(const Array& params, bool fHelp)
197206
return Value::null;
198207
}
199208

200-
201209
Value gethashespersec(const Array& params, bool fHelp)
202210
{
203211
if (fHelp || params.size() != 0)
@@ -216,6 +224,7 @@ Value gethashespersec(const Array& params, bool fHelp)
216224
return (boost::int64_t)0;
217225
return (boost::int64_t)dHashesPerSec;
218226
}
227+
#endif
219228

220229

221230
Value getmininginfo(const Array& params, bool fHelp)
@@ -248,16 +257,19 @@ Value getmininginfo(const Array& params, bool fHelp)
248257
obj.push_back(Pair("currentblocktx", (uint64_t)nLastBlockTx));
249258
obj.push_back(Pair("difficulty", (double)GetDifficulty()));
250259
obj.push_back(Pair("errors", GetWarnings("statusbar")));
251-
obj.push_back(Pair("generate", getgenerate(params, false)));
252260
obj.push_back(Pair("genproclimit", (int)GetArg("-genproclimit", -1)));
253-
obj.push_back(Pair("hashespersec", gethashespersec(params, false)));
254261
obj.push_back(Pair("networkhashps", getnetworkhashps(params, false)));
255262
obj.push_back(Pair("pooledtx", (uint64_t)mempool.size()));
256263
obj.push_back(Pair("testnet", TestNet()));
264+
#ifdef ENABLE_WALLET
265+
obj.push_back(Pair("generate", getgenerate(params, false)));
266+
obj.push_back(Pair("hashespersec", gethashespersec(params, false)));
267+
#endif
257268
return obj;
258269
}
259270

260271

272+
#ifdef ENABLE_WALLET
261273
Value getwork(const Array& params, bool fHelp)
262274
{
263275
if (fHelp || params.size() > 1)
@@ -381,7 +393,7 @@ Value getwork(const Array& params, bool fHelp)
381393
return CheckWork(pblock, *pwalletMain, *pMiningKey);
382394
}
383395
}
384-
396+
#endif
385397

386398
Value getblocktemplate(const Array& params, bool fHelp)
387399
{

src/rpcserver.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -248,12 +248,14 @@ static const CRPCCommand vRPCCommands[] =
248248
{ "gettxout", &gettxout, true, false, false },
249249
{ "verifychain", &verifychain, true, false, false },
250250

251-
#ifdef ENABLE_WALLET
251+
/* Mining */
252252
{ "getnetworkhashps", &getnetworkhashps, true, false, false },
253-
{ "getgenerate", &getgenerate, true, false, false },
254-
{ "setgenerate", &setgenerate, true, true, false },
255-
{ "gethashespersec", &gethashespersec, true, false, false },
256253
{ "getmininginfo", &getmininginfo, true, false, false },
254+
{ "getblocktemplate", &getblocktemplate, true, false, false },
255+
{ "submitblock", &submitblock, false, false, false },
256+
257+
#ifdef ENABLE_WALLET
258+
/* Wallet */
257259
{ "getnewaddress", &getnewaddress, true, false, true },
258260
{ "getaccountaddress", &getaccountaddress, true, false, true },
259261
{ "getrawchangeaddress", &getrawchangeaddress, true, false, true },
@@ -283,10 +285,7 @@ static const CRPCCommand vRPCCommands[] =
283285
{ "listaddressgroupings", &listaddressgroupings, false, false, true },
284286
{ "signmessage", &signmessage, false, false, true },
285287
{ "verifymessage", &verifymessage, false, false, false },
286-
{ "getwork", &getwork, true, false, true },
287288
{ "listaccounts", &listaccounts, false, false, true },
288-
{ "getblocktemplate", &getblocktemplate, true, false, false },
289-
{ "submitblock", &submitblock, false, false, false },
290289
{ "listsinceblock", &listsinceblock, false, false, true },
291290
{ "dumpprivkey", &dumpprivkey, true, false, true },
292291
{ "dumpwallet", &dumpwallet, true, false, true },
@@ -295,6 +294,12 @@ static const CRPCCommand vRPCCommands[] =
295294
{ "listunspent", &listunspent, false, false, true },
296295
{ "lockunspent", &lockunspent, false, false, true },
297296
{ "listlockunspent", &listlockunspent, false, false, true },
297+
298+
/* Wallet-enabled mining */
299+
{ "getgenerate", &getgenerate, true, false, false },
300+
{ "setgenerate", &setgenerate, true, true, false },
301+
{ "gethashespersec", &gethashespersec, true, false, false },
302+
{ "getwork", &getwork, true, false, true },
298303
#endif // ENABLE_WALLET
299304
};
300305

0 commit comments

Comments
 (0)