From 7131c30c33c980f0ba1d37dfc6a3fbe8c319813e Mon Sep 17 00:00:00 2001 From: Bitflash Date: Sat, 1 Aug 2026 12:56:16 -0300 Subject: wallet: generate keys ahead of use so a backup outlives the next block (#85) The wallet made a key per address and per block mined, so a backup only ever contained the keys that existed the moment it was taken -- mine one block and the coin lands on a key the backup has never heard of. The README warned about it, which is an admission rather than a fix. Keys are now generated a hundred at a time and handed out one at a time, each written to wallet.dat before it can be pointed at. A backup covers the next hundred addresses. Deterministic derivation (#47) stays open; this buys back the distance between a backup and the next mistake. --- src/rpc.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/rpc.cpp') diff --git a/src/rpc.cpp b/src/rpc.cpp index 3db8b94..97d8429 100644 --- a/src/rpc.cpp +++ b/src/rpc.cpp @@ -146,7 +146,9 @@ static bool RebuildJob() CBlockIndex* pindexPrev = pindexBest; unsigned int nBits = GetNextWorkRequired(pindexPrev); - CKey key; key.MakeNewKey(); + // From the pool, so the template's payout key is in wallet.dat before + // any miner is handed work against it. + vector vchPubKey = GetKeyFromPool(); static std::atomic sExtra{0}; uint32_t extraNonce = ++sExtra; @@ -160,7 +162,7 @@ static bool RebuildJob() // is mined and submitted like any other. #58. txNew.vin[0].scriptSig << (pindexPrev ? pindexPrev->nHeight + 1 : 0) << nBits << (CBigNum)extraNonce; txNew.vout.resize(1); - txNew.vout[0].scriptPubKey << key.GetPubKey() << OP_CHECKSIG; + txNew.vout[0].scriptPubKey << vchPubKey << OP_CHECKSIG; CBlock block; block.vtx.push_back(txNew); @@ -194,7 +196,8 @@ static bool RebuildJob() (unsigned int)GetAdjustedTime()); block.nBits = nBits; block.nNonce = 1; - AddKey(key); + // No AddKey here: the pool wrote this key to wallet.dat before it was + // handed out. StratumJob job; job.jobId = ToHex(&extraNonce, 4); -- cgit v1.2.3