lnwallet/lnrpc: Expose sync status to gRPC interface
This commit adds wallet_best_block_timestamp to the gRPC interface. This is done in order to allow clients to calculate progress while lnd syncs to the blockchain. wallet_best_block_timestamp is exposed via the GetInfo() rpc call. Additionally, IsSynced() returns the WalletBestBlockTimestamp as the second value in the tuple that is returned, providing additional detail when querying about the status of the sync. The BtcWallet interface has also been updated accordingly. This commit was created to support the issue to [Add progress bar for chain sync] (lightninglabs/lightning-app#10) in lightning-app
This commit is contained in:
1 parent
2a61ccec96
commit
84551c616f
9 files changed
+361
-336
No files matched your search
@@ -667,27 +667,32 @@ func (b *BtcWallet) SubscribeTransactions() (lnwallet.TransactionSubscription, e
|
||||
// it has fully synced to the current best block in the main chain.
|
||||
//
|
||||
// This is a part of the WalletController interface.
|
||||
func (b *BtcWallet) IsSynced() (bool, error) {
|
||||
// Grab the best chain state the wallet is currently aware of.
|
||||
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.
|
||||
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
|
||||
err error
|
||||
)
|
||||
|
||||
// Next, query the chain backend to grab the info about the tip of the
|
||||
// main chain.
|
||||
bestHash, bestHeight, err = b.cfg.ChainSource.GetBestBlock()
|
||||
if err != nil {
|
||||
return false, err
|
||||
return false, 0, err
|
||||
}
|
||||
|
||||
// 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, nil
|
||||
return false, walletBestHeader.Timestamp.Unix(), nil
|
||||
}
|
||||
|
||||
// If the wallet is on par with the current best chain tip, then we
|
||||
@@ -696,11 +701,11 @@ func (b *BtcWallet) IsSynced() (bool, error) {
|
||||
// order to make a guess based on the current time stamp.
|
||||
blockHeader, err := b.cfg.ChainSource.GetBlockHeader(bestHash)
|
||||
if err != nil {
|
||||
return false, err
|
||||
return false, 0, err
|
||||
}
|
||||
|
||||
// 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), nil
|
||||
return !blockHeader.Timestamp.Before(minus24Hours), walletBestHeader.Timestamp.Unix(), nil
|
||||
}
|
||||
@@ -198,7 +198,9 @@ type WalletController interface {
|
||||
|
||||
// IsSynced returns a boolean indicating if from the PoV of the wallet,
|
||||
// it has fully synced to the current best block in the main chain.
|
||||
IsSynced() (bool, error)
|
||||
// It also returns an int64 indicating the timestamp of the best block
|
||||
// known to the wallet, expressed in Unix epoch time
|
||||
IsSynced() (bool, int64, error)
|
||||
|
||||
// Start initializes the wallet, making any necessary connections,
|
||||
// starting up required goroutines etc.
|
||||
|
||||
Reference in new issue
Block a user