Skip to content

Commit

Permalink
Merge bitcoin#2675: [Wallet] Clear Shield notes witness cache before …
Browse files Browse the repository at this point in the history
…a full rescan

fb025b1 [Wallet] Clear Shield notes witness cache before a full rescan (random-zebra)

Pull request description:

  So they are rebuilt via `ScanForWalletTransactions` --> `ChainTipAdded`, and a corrupted cache can be fixed with a simple `-rescan` of the chain data (instead of a complete reindex).

ACKs for top commit:
  furszy:
    ACK fb025b1
  Fuzzbawls:
    ACK fb025b1

Tree-SHA512: 3963d2fa4586bfc999a96f76e4fe537c484ccc07e9b7cebfa32dba771d4113e3f5a583b45bf4ee1010be2bdca4a27aab662054a391f6e30c705af41771e2d144
  • Loading branch information
furszy committed Dec 12, 2021
2 parents 8eb5087 + fb025b1 commit 4b8b541
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4280,7 +4280,11 @@ CWallet* CWallet::CreateWalletFromFile(const std::string& name, const fs::path&

LOCK(cs_main);
CBlockIndex* pindexRescan = chainActive.Genesis();
if (!gArgs.GetBoolArg("-rescan", false)) {

if (gArgs.GetBoolArg("-rescan", false)) {
// clear note witness cache before a full rescan
walletInstance->ClearNoteWitnessCache();
} else {
WalletBatch batch(*walletInstance->database);
CBlockLocator locator;
if (batch.ReadBestBlock(locator))
Expand Down Expand Up @@ -4621,6 +4625,8 @@ void CWallet::IncrementNoteWitnesses(const CBlockIndex* pindex,

void CWallet::DecrementNoteWitnesses(const CBlockIndex* pindex) { m_sspk_man->DecrementNoteWitnesses(pindex->nHeight); }

void CWallet::ClearNoteWitnessCache() { m_sspk_man->ClearNoteWitnessCache(); }

bool CWallet::AddSaplingZKey(const libzcash::SaplingExtendedSpendingKey &key) { return m_sspk_man->AddSaplingZKey(key); }

bool CWallet::AddSaplingIncomingViewingKeyW(
Expand Down
3 changes: 3 additions & 0 deletions src/wallet/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,9 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
//! pindex is the old tip being disconnected.
void DecrementNoteWitnesses(const CBlockIndex* pindex);

//! clear note witness cache
void ClearNoteWitnessCache();


//! Adds Sapling spending key to the store, and saves it to disk
bool AddSaplingZKey(const libzcash::SaplingExtendedSpendingKey &key);
Expand Down

0 comments on commit 4b8b541

Please sign in to comment.