Omit check of Orchard commitment root after rewind past first checkpoint.

If we no longer have any checkpoints in the Orchard wallet, we must
skip the check against the prior note commitment tree root because
we know that the Orchard wallet's state may be for a chain that is
being reorg'ed away. This is safe because we know that we will have
removed all information from the wallet that we need to perform spends
from that state, and we also know that when we start rolling forward
along the new chain that we will overwrite the initial state of the
Orchard note commitment tree.
This commit is contained in:
Kris Nuttycombe 2022-04-04 13:05:46 -06:00
parent 5b7370c55e
commit afb503503d
1 changed files with 5 additions and 1 deletions

View File

@ -2742,7 +2742,11 @@ void CWallet::DecrementNoteWitnesses(const Consensus::Params& consensus, const C
assert(pindex->nHeight >= 1);
assert(orchardWallet.Rewind(pindex->nHeight - 1, uResultHeight));
assert(uResultHeight == pindex->nHeight - 1);
if (consensus.NetworkUpgradeActive(pindex->nHeight - 1, Consensus::UPGRADE_NU5)) {
// If we have no checkpoints after the rewind, then the latest anchor of the
// wallet's Orchard note commitment tree will be in an indeterminate state and it
// will be overwritten in the next `IncrementNoteWitnesses` call, so we can skip
// the check against `hashFinalOrchardRoot`.
if (orchardWallet.GetLastCheckpointHeight().has_value()) {
assert(pindex->pprev->hashFinalOrchardRoot == orchardWallet.GetLatestAnchor());
}
}