Write witness caches when writing the best block
For steady-state operation, this reduces the average time between wallet disk writes from once per block to once per hour. On -rescan, witness caches are only written out at the end along with the best block, increasing speed while ensuring that on-disk state is kept consistent. Witness caches are now never recreated during a -reindex, on the assumption that the blocks themselves are not changing (the chain is just being reconstructed), and so the witnesses will remain valid. Part of #1749.
This commit is contained in:
@@ -380,7 +380,7 @@ void CWallet::ChainTip(const CBlockIndex *pindex, const CBlock *pblock,
|
||||
void CWallet::SetBestChain(const CBlockLocator& loc)
|
||||
{
|
||||
CWalletDB walletdb(strWalletFile);
|
||||
walletdb.WriteBestBlock(loc);
|
||||
SetBestChainINTERNAL(walletdb, loc);
|
||||
}
|
||||
|
||||
bool CWallet::SetMinVersion(enum WalletFeature nVersion, CWalletDB* pwalletdbIn, bool fExplicit)
|
||||
@@ -741,10 +741,9 @@ void CWallet::IncrementNoteWitnesses(const CBlockIndex* pindex,
|
||||
}
|
||||
}
|
||||
|
||||
if (fFileBacked) {
|
||||
CWalletDB walletdb(strWalletFile);
|
||||
WriteWitnessCache(walletdb);
|
||||
}
|
||||
// For performance reasons, we write out the witness cache in
|
||||
// CWallet::SetBestChain() (which also ensures that overall consistency
|
||||
// of the wallet.dat is maintained).
|
||||
}
|
||||
}
|
||||
|
||||
@@ -779,10 +778,10 @@ void CWallet::DecrementNoteWitnesses(const CBlockIndex* pindex)
|
||||
}
|
||||
// TODO: If nWitnessCache is zero, we need to regenerate the caches (#1302)
|
||||
assert(nWitnessCacheSize > 0);
|
||||
if (fFileBacked) {
|
||||
CWalletDB walletdb(strWalletFile);
|
||||
WriteWitnessCache(walletdb);
|
||||
}
|
||||
|
||||
// For performance reasons, we write out the witness cache in
|
||||
// CWallet::SetBestChain() (which also ensures that overall consistency
|
||||
// of the wallet.dat is maintained).
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user