lnwallet: modify IsSynced() for neutrino backend to ensure filter headers are synced

This commit is contained in:
Olaoluwa Osuntokun 2018-07-25 19:33:46 -07:00
parent 2d71b5a0d5
commit 293a377edd
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21
2 changed files with 21 additions and 5 deletions

@ -9,8 +9,6 @@ import (
"sync" "sync"
"time" "time"
"github.com/lightningnetwork/lnd/keychain"
"github.com/lightningnetwork/lnd/lnwallet"
"github.com/btcsuite/btcd/btcec" "github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcd/chaincfg" "github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcd/chaincfg/chainhash" "github.com/btcsuite/btcd/chaincfg/chainhash"
@ -21,6 +19,8 @@ import (
"github.com/btcsuite/btcwallet/waddrmgr" "github.com/btcsuite/btcwallet/waddrmgr"
base "github.com/btcsuite/btcwallet/wallet" base "github.com/btcsuite/btcwallet/wallet"
"github.com/btcsuite/btcwallet/walletdb" "github.com/btcsuite/btcwallet/walletdb"
"github.com/lightningnetwork/lnd/keychain"
"github.com/lightningnetwork/lnd/lnwallet"
) )
const ( const (
@ -745,8 +745,24 @@ func (b *BtcWallet) IsSynced() (bool, int64, error) {
return false, 0, err return false, 0, err
} }
// If the timestamp no the best header is more than 2 hours in the // If the timestamp on the best header is more than 2 hours in the
// past, then we're not yet synced. // past, then we're not yet synced.
minus24Hours := time.Now().Add(-2 * time.Hour) minus24Hours := time.Now().Add(-2 * time.Hour)
return !blockHeader.Timestamp.Before(minus24Hours), bestTimestamp, nil if blockHeader.Timestamp.Before(minus24Hours) {
return false, bestTimestamp, nil
}
// If this is neutrino, then we'll also want to wait until the set of
// filter headers also match
if neutrinoNode, ok := b.chain.(*chain.NeutrinoClient); ok {
filterDB := neutrinoNode.CS.RegFilterHeaders
_, filterHeaderTip, err := filterDB.ChainTip()
if err != nil {
return false, 0, err
}
return filterHeaderTip == uint32(bestHeight), bestTimestamp, nil
}
return true, bestTimestamp, nil
} }

@ -238,7 +238,7 @@ type BlockChainIO interface {
// GetUtxo attempts to return the passed outpoint if it's still a // GetUtxo attempts to return the passed outpoint if it's still a
// member of the utxo set. The passed height hint should be the "birth // member of the utxo set. The passed height hint should be the "birth
// height" of the passed outpoint. The script passed should be the // height" of the passed outpoint. The script passed should be the
// script that the oupoint creates. In the case that the output is in // script that the outpoint creates. In the case that the output is in
// the UTXO set, then the output corresponding to that output is // the UTXO set, then the output corresponding to that output is
// returned. Otherwise, a non-nil error will be returned. // returned. Otherwise, a non-nil error will be returned.
GetUtxo(op *wire.OutPoint, pkScript []byte, GetUtxo(op *wire.OutPoint, pkScript []byte,