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