wallet: start recovery from the wallet's best height

Previously, the wallet would attempt to store the same block it
checkpointed during its initial sync when performing a recovery. This
would cause the previous block existence validation check to be in
place, which would ultimately fail because the previous block was not
stored intentionally.

To address this, we always start/resume our recovery from the wallet's
best height. This also ensures that we do not rescan the same block
again when resuming a recovery after a shutdown.
This commit is contained in:
Wilmer Paulino 2019-06-19 19:59:02 -07:00
parent de02d6fdfb
commit 426f523475
No known key found for this signature in database
GPG key ID: 6DF57B9F9514972F

View file

@ -643,23 +643,24 @@ func (w *Wallet) recovery(chainClient chain.Interface,
return err
}
// We'll then need to determine the range of our recovery. This properly
// handles the case where we resume a previous recovery attempt after a
// restart.
startHeight, bestHeight, err := w.getSyncRange(chainClient, birthdayBlock)
// Fetch the best height from the backend to determine when we should
// stop.
_, bestHeight, err := chainClient.GetBestBlock()
if err != nil {
return err
}
// Now we can begin scanning the chain from the specified starting
// height. Since the recovery process itself acts as rescan, we'll also
// update our wallet's synced state along the way to reflect the blocks
// we process and prevent rescanning them later on.
// Now we can begin scanning the chain from the wallet's current tip to
// ensure we properly handle restarts. Since the recovery process itself
// acts as rescan, we'll also update our wallet's synced state along the
// way to reflect the blocks we process and prevent rescanning them
// later on.
//
// NOTE: We purposefully don't update our best height since we assume
// that a wallet rescan will be performed from the wallet's tip, which
// will be of bestHeight after completing the recovery process.
var blocks []*waddrmgr.BlockStamp
startHeight := w.Manager.SyncedTo().Height + 1
for height := startHeight; height <= bestHeight; height++ {
hash, err := chainClient.GetBlockHash(int64(height))
if err != nil {