lnwallet/btcwallet: grab best header timestamp directly from wallet

In this commit, we modify the way we obtain the current best header
timestamp. In doing this, we fix an intermittent flake that would pop
up at times on the integration tests. This could occur as if the wallet
was lagging behind the chain backend for a re-org, then a hash that the
backend knew of, may not be known by the wallet.

To remedy this, we’ll take advantage of a recent change to btcwallet to
actually include the timestamp in its sync state.
This commit is contained in:
Olaoluwa Osuntokun 2018-03-06 13:17:09 -05:00
parent 78cbe7a141
commit 18e9475a9a
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21
1 changed files with 7 additions and 14 deletions

View File

@ -700,23 +700,16 @@ func (b *BtcWallet) SubscribeTransactions() (lnwallet.TransactionSubscription, e
//
// This is a part of the WalletController interface.
func (b *BtcWallet) IsSynced() (bool, int64, error) {
// Grab the best chain state the wallet is currently aware of. We'll
// also grab the timestamp of the best block to return for determining
// sync progress.
// Grab the best chain state the wallet is currently aware of.
syncState := b.wallet.Manager.SyncedTo()
walletBestHeader, err := b.chain.GetBlockHeader(&syncState.Hash)
if err != nil {
return false, 0, err
}
var (
bestHash *chainhash.Hash
bestHeight int32
)
// We'll also extract the current best wallet timestamp so the caller
// can get an idea of where we are in the sync timeline.
bestTimestamp := syncState.Timestamp.Unix()
// Next, query the chain backend to grab the info about the tip of the
// main chain.
bestHash, bestHeight, err = b.cfg.ChainSource.GetBestBlock()
bestHash, bestHeight, err := b.cfg.ChainSource.GetBestBlock()
if err != nil {
return false, 0, err
}
@ -724,7 +717,7 @@ func (b *BtcWallet) IsSynced() (bool, int64, error) {
// If the wallet hasn't yet fully synced to the node's best chain tip,
// then we're not yet fully synced.
if syncState.Height < bestHeight {
return false, walletBestHeader.Timestamp.Unix(), nil
return false, bestTimestamp, nil
}
// If the wallet is on par with the current best chain tip, then we
@ -739,5 +732,5 @@ func (b *BtcWallet) IsSynced() (bool, int64, error) {
// If the timestamp no the best header is more than 2 hours in the
// past, then we're not yet synced.
minus24Hours := time.Now().Add(-2 * time.Hour)
return !blockHeader.Timestamp.Before(minus24Hours), walletBestHeader.Timestamp.Unix(), nil
return !blockHeader.Timestamp.Before(minus24Hours), bestTimestamp, nil
}