Skip to content

Commit b2eb977

Browse files
committed
[Mining] Use -miningaddress for in-wallet mining.
Replaces the hook to get a mining address from the wallet with a retrieval of the address set as `-miningaddress`. Performs an additional safety check at startup that the wallet actually owns the given address.
1 parent 1e2b060 commit b2eb977

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

src/init.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -1933,6 +1933,17 @@ bool AppInitMain()
19331933
// Link thread groups
19341934
LinkAutoSpendThreadGroup(&threadGroupAutoSpend);
19351935

1936+
// Validate wallet mining address.
1937+
std::string sAddress = gArgs.GetArg("-miningaddress", "");
1938+
if (!sAddress.empty()) {
1939+
CTxDestination dest = DecodeDestination(sAddress);
1940+
1941+
auto pt = GetMainWallet();
1942+
if (pt && pt->IsMine(dest) != ISMINE_SPENDABLE) {
1943+
return InitError(strprintf(_("Invalid -miningaddress: '%s' not owned by wallet"), sAddress));
1944+
}
1945+
}
1946+
19361947
// Start wallet CPU mining if the -gen=<n> parameter is given
19371948
int nThreads = gArgs.GetArg("-gen", 0);
19381949
if (nThreads) {

src/wallet/wallet.cpp

+14-1
Original file line numberDiff line numberDiff line change
@@ -4702,7 +4702,7 @@ void CWallet::MarkReserveKeysAsUsed(int64_t keypool_id)
47024702
}
47034703
}
47044704

4705-
void CWallet::GetScriptForMining(std::shared_ptr<CReserveScript> &script)
4705+
void CWallet::GetScriptForMiningReserveKey(std::shared_ptr<CReserveScript> &script)
47064706
{
47074707
std::shared_ptr<CReserveKey> rKey = std::make_shared<CReserveKey>(this);
47084708
CPubKey pubkey;
@@ -4713,6 +4713,19 @@ void CWallet::GetScriptForMining(std::shared_ptr<CReserveScript> &script)
47134713
script->reserveScript = CScript() << ToByteVector(pubkey) << OP_CHECKSIG;
47144714
}
47154715

4716+
void CWallet::GetScriptForMining(std::shared_ptr<CReserveScript> &script)
4717+
{
4718+
std::string sAddress = gArgs.GetArg("-miningaddress", "");
4719+
if (!sAddress.empty()) {
4720+
CTxDestination dest = DecodeDestination(sAddress);
4721+
4722+
script = std::make_shared<CReserveScript>();
4723+
script->reserveScript = GetScriptForDestination(dest);
4724+
return;
4725+
}
4726+
return GetScriptForMiningReserveKey(script);
4727+
}
4728+
47164729
void CWallet::LockCoin(const COutPoint& output)
47174730
{
47184731
AssertLockHeld(cs_wallet); // setLockedCoins

src/wallet/wallet.h

+1
Original file line numberDiff line numberDiff line change
@@ -1221,6 +1221,7 @@ class CWallet final : public CCryptoKeyStore, public CValidationInterface
12211221

12221222
const std::string& GetLabelName(const CScript& scriptPubKey) const;
12231223

1224+
void GetScriptForMiningReserveKey(std::shared_ptr<CReserveScript> &script);
12241225
void GetScriptForMining(std::shared_ptr<CReserveScript> &script);
12251226

12261227
unsigned int GetKeyPoolSize() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)

0 commit comments

Comments
 (0)