wallet: test what the shutdown save records and a reseed that succeeds
The tests of the shutdown save covered the skip reasons and ClearNoteWitnessCache only, and the witness-root tests compared the new code with itself at 1 and at N threads, with every reseed throwing for want of block files. A stale root table, or a lost change bump, would have passed all of them. SetBestChain's work on an open database moves into a template, SetBestChainWith, so a fake database can fail each step of the transaction; SetBestChain itself only opens the database and calls it. The new tests check: - a write that fails at any step (begin, a tx, the cache size, the best block, the commit) records nothing; a committed one records the wallet tip, which is what is stamped, not the chain tip passed in; without a wallet tip, the block the locator names; - DecrementNoteWitnesses, and adding or changing a note-bearing tx, make the next shutdown save again; re-adding a tx unchanged or adding one without notes does not (AddToWallet on an in-memory BDB environment); - the save writes the best block through the real wallet database, and each skip path writes nothing to it; - a reseed that reads its block from disk and succeeds: the loop goes on, a sibling note in the same tx that had no nullifier gets one from that reseed and is checked with an inline root, every note ends as the serial rules say at 1 and at 8 threads, and the reseed counts as a change to save. Each assertion was checked by breaking the code it covers (the inline root fallback, each bump site, recording on failure, the rescan gate): every such change fails at least one test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+1
-27
@@ -822,36 +822,10 @@ bool CWallet::CommitAutomatedTx(const CTransaction& tx) {
|
||||
|
||||
bool CWallet::SetBestChain(const CBlockLocator& loc)
|
||||
{
|
||||
// FlushStateToDisk passes the chain tip, but ThreadNotifyWallets delivers blocks to the wallet
|
||||
// asynchronously and can lag it. Stamping a locator ahead of what the wallet has processed makes
|
||||
// the next start skip those blocks for good (no rescan, no notification): notes received in them
|
||||
// go missing and spends in them go unseen. So stamp the block the wallet's state reflects (seeded
|
||||
// by init before the notifier starts, then advanced by ChainTip). Init's own calls, made before
|
||||
// it is seeded, pass the right locator themselves.
|
||||
CBlockLocator locator = loc;
|
||||
const CBlockIndex* pindexStamped = nullptr;
|
||||
uint64_t nGeneration;
|
||||
{
|
||||
LOCK2(cs_main, cs_wallet);
|
||||
// Read before the write: a change made while it runs bumps the counter past this value, so
|
||||
// the shutdown save still sees it as unsaved.
|
||||
nGeneration = nWitnessGeneration;
|
||||
if (pindexWalletTip != nullptr) {
|
||||
locator = chainActive.GetLocator(pindexWalletTip);
|
||||
pindexStamped = pindexWalletTip;
|
||||
} else if (!loc.vHave.empty()) {
|
||||
BlockMap::const_iterator mi = mapBlockIndex.find(loc.vHave.front());
|
||||
if (mi != mapBlockIndex.end())
|
||||
pindexStamped = mi->second;
|
||||
}
|
||||
}
|
||||
// Default ctor => fFlushOnClose=true => ~CDB runs a full BDB txn_checkpoint over the entire
|
||||
// cache. Fine for the hourly/shutdown callers; ruinous inside a scan (see SetBestChainNoFlush).
|
||||
CWalletDB walletdb(strWalletFile);
|
||||
bool fWritten = SetBestChainINTERNAL(walletdb, locator);
|
||||
if (fWritten)
|
||||
RecordStatePersisted(pindexStamped, nGeneration);
|
||||
return fWritten;
|
||||
return SetBestChainWith(walletdb, loc);
|
||||
}
|
||||
|
||||
void CWallet::RecordStatePersisted(const CBlockIndex* pindex, uint64_t nGeneration)
|
||||
|
||||
Reference in New Issue
Block a user