wallet: ensure bestHeight is updated before isCurrent check
In this commit, we fix an issue with the wallet's initial sync logic where we'd miss processing all of the blocks in the chain. This can happen if the backend is considered current while we're still catching up. To address this, we make sure we update our best height to process those missed blocks. Co-authored-by: Roei Erez <roeierez@gmail.com>
This commit is contained in:
parent
8c64a08971
commit
5f1ab915be
1 changed files with 9 additions and 4 deletions
|
@ -505,15 +505,20 @@ func (w *Wallet) scanChain(startHeight int32,
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we've reached our best height and we're not current, we'll
|
// If we've reached our best height, we'll wait for blocks at
|
||||||
// wait for blocks at tip to ensure we go through all existent
|
// tip to ensure we go through all existent blocks in the chain.
|
||||||
// blocks.
|
// We'll update our bestHeight before checking if we're current
|
||||||
for height == bestHeight && !isCurrent(bestHeight) {
|
// with the chain to ensure we process any additional blocks
|
||||||
|
// that came in while we were scanning from our starting point.
|
||||||
|
for height == bestHeight {
|
||||||
time.Sleep(100 * time.Millisecond)
|
time.Sleep(100 * time.Millisecond)
|
||||||
_, bestHeight, err = chainClient.GetBestBlock()
|
_, bestHeight, err = chainClient.GetBestBlock()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if isCurrent(bestHeight) {
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue