upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/rpc.cpp
diff options
context:
space:
mode:
authorBitflash <btf01@proton.me>2026-08-01 12:56:16 -0300
committerGitHub <noreply@github.com>2026-08-01 12:56:16 -0300
commit7131c30c33c980f0ba1d37dfc6a3fbe8c319813e (patch)
tree668de28f9aec4f8f350146f1d824b487752cf747 /src/rpc.cpp
parentb426948b966405b65f3ea6c1994164b462980694 (diff)
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.
Diffstat (limited to 'src/rpc.cpp')
-rw-r--r--src/rpc.cpp9
1 files changed, 6 insertions, 3 deletions
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()
146 CBlockIndex* pindexPrev = pindexBest; 146 CBlockIndex* pindexPrev = pindexBest;
147 unsigned int nBits = GetNextWorkRequired(pindexPrev); 147 unsigned int nBits = GetNextWorkRequired(pindexPrev);
148 148
149 CKey key; key.MakeNewKey(); 149 // From the pool, so the template's payout key is in wallet.dat before
150 // any miner is handed work against it.
151 vector<unsigned char> vchPubKey = GetKeyFromPool();
150 static std::atomic<uint32_t> sExtra{0}; 152 static std::atomic<uint32_t> sExtra{0};
151 uint32_t extraNonce = ++sExtra; 153 uint32_t extraNonce = ++sExtra;
152 154
@@ -160,7 +162,7 @@ static bool RebuildJob()
160 // is mined and submitted like any other. #58. 162 // is mined and submitted like any other. #58.
161 txNew.vin[0].scriptSig << (pindexPrev ? pindexPrev->nHeight + 1 : 0) << nBits << (CBigNum)extraNonce; 163 txNew.vin[0].scriptSig << (pindexPrev ? pindexPrev->nHeight + 1 : 0) << nBits << (CBigNum)extraNonce;
162 txNew.vout.resize(1); 164 txNew.vout.resize(1);
163 txNew.vout[0].scriptPubKey << key.GetPubKey() << OP_CHECKSIG; 165 txNew.vout[0].scriptPubKey << vchPubKey << OP_CHECKSIG;
164 166
165 CBlock block; 167 CBlock block;
166 block.vtx.push_back(txNew); 168 block.vtx.push_back(txNew);
@@ -194,7 +196,8 @@ static bool RebuildJob()
194 (unsigned int)GetAdjustedTime()); 196 (unsigned int)GetAdjustedTime());
195 block.nBits = nBits; 197 block.nBits = nBits;
196 block.nNonce = 1; 198 block.nNonce = 1;
197 AddKey(key); 199 // No AddKey here: the pool wrote this key to wallet.dat before it was
200 // handed out.
198 201
199 StratumJob job; 202 StratumJob job;
200 job.jobId = ToHex(&extraNonce, 4); 203 job.jobId = ToHex(&extraNonce, 4);