Only display chain sync in progress
if behind sync
Only display `chain sync in progress` if behind sync
This commit is contained in:
parent
884246677b
commit
826ef40626
@ -3,11 +3,13 @@ package cli
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
"golang.org/x/term"
|
||||
@ -19,6 +21,7 @@ import (
|
||||
"github.com/filecoin-project/go-state-types/crypto"
|
||||
"github.com/filecoin-project/go-state-types/network"
|
||||
|
||||
"github.com/filecoin-project/lotus/api/v0api"
|
||||
"github.com/filecoin-project/lotus/build"
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
"github.com/filecoin-project/lotus/lib/tablewriter"
|
||||
@ -206,7 +209,12 @@ var walletBalance = &cli.Command{
|
||||
return err
|
||||
}
|
||||
|
||||
if balance.Equals(types.NewInt(0)) {
|
||||
behindSync, err := isSyncBehind(ctx, api)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if balance.Equals(types.NewInt(0)) && behindSync {
|
||||
afmt.Printf("%s (warning: may display 0 if chain sync in progress)\n", types.FIL(balance))
|
||||
} else {
|
||||
afmt.Printf("%s\n", types.FIL(balance))
|
||||
@ -754,3 +762,16 @@ var walletMarketAdd = &cli.Command{
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
func isSyncBehind(ctx context.Context, fullapi v0api.FullNode) (bool, error) {
|
||||
head, err := fullapi.ChainHead(ctx)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
if time.Now().Unix()-int64(head.MinTimestamp()) >= int64(build.BlockDelaySecs*5) { // if more than 5 epochs
|
||||
return true, nil
|
||||
}
|
||||
|
||||
return false, nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user