wallet: always wait for Neutrino IsCurrent during initial sync

This commit is contained in:
Johan T. Halseth 2018-09-10 16:50:51 +02:00
parent 060361939b
commit d791cb7c30
No known key found for this signature in database
GPG key ID: 15BAADA29DA20D26

View file

@ -443,36 +443,31 @@ func (w *Wallet) syncWithChain() error {
return err return err
} }
// If we're using the Neutrino backend, we can check if
// it's current or not. For other backends we'll assume
// it is current if the best height has reached the
// last checkpoint.
isCurrent := func(bestHeight int32) bool {
switch c := chainClient.(type) {
case *chain.NeutrinoClient:
return c.CS.IsCurrent()
}
return bestHeight >= checkHeight
}
// If we've found the best height the backend knows // If we've found the best height the backend knows
// about, but we haven't reached the last checkpoint, we // about, and the backend is still synchronizing, we'll
// know the backend is still synchronizing. We can give // wait. We can give it a little bit of time to
// it a little bit of time to synchronize further before // synchronize further before updating the best height
// updating the best height based on the backend. Once // based on the backend. Once we see that the backend
// we see that the backend has advanced, we can catch // has advanced, we can catch up to it.
// up to it. for height == bestHeight && !isCurrent(bestHeight) {
for height == bestHeight && bestHeight < checkHeight {
time.Sleep(100 * time.Millisecond) time.Sleep(100 * time.Millisecond)
_, bestHeight, err = chainClient.GetBestBlock() _, bestHeight, err = chainClient.GetBestBlock()
if err != nil { if err != nil {
tx.Rollback() tx.Rollback()
return err return err
} }
// If we're using the Neutrino backend, we can
// check if it's current or not. If it's not and
// we've exceeded the original checkHeight, we
// can keep the loop going by increasing the
// checkHeight to be greater than the bestHeight
// and if it is, we can set checkHeight to the
// same as the bestHeight so the loop exits.
switch c := chainClient.(type) {
case *chain.NeutrinoClient:
if c.CS.IsCurrent() {
checkHeight = bestHeight
} else if checkHeight < bestHeight+1 {
checkHeight = bestHeight + 1
}
}
} }
header, err := chainClient.GetBlockHeader(hash) header, err := chainClient.GetBlockHeader(hash)