Auto merge of #1904 - str4d:1749-write-witness-cache-with-best-block, r=ebfull

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:
zkbot
2016-12-09 21:11:15 +00:00
5 changed files with 184 additions and 39 deletions

View File

@@ -542,11 +542,6 @@ void ThreadImport(std::vector<boost::filesystem::path> vImportFiles)
RenameThread("zcash-loadblk");
// -reindex
if (fReindex) {
#ifdef ENABLE_WALLET
if (pwalletMain) {
pwalletMain->ClearNoteWitnessCache();
}
#endif
CImportingNow imp;
int nFile = 0;
while (true) {
@@ -1387,7 +1382,10 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
CBlockIndex *pindexRescan = chainActive.Tip();
if (GetBoolArg("-rescan", false))
{
pwalletMain->ClearNoteWitnessCache();
pindexRescan = chainActive.Genesis();
}
else
{
CWalletDB walletdb(strWalletFile);