From 87deec3b0e363157285eae838d7a248eafa5956d Mon Sep 17 00:00:00 2001 From: simlecode <69969590+simlecode@users.noreply.github.com> Date: Mon, 21 Aug 2023 15:24:04 +0800 Subject: [PATCH 1/3] fix: cli: Only display warning if behind sync --- cmd/address.go | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/cmd/address.go b/cmd/address.go index ac6b0e96cf..b63a3d863b 100644 --- a/cmd/address.go +++ b/cmd/address.go @@ -9,6 +9,7 @@ import ( "fmt" "os" "strings" + "time" "github.com/howeyc/gopass" @@ -261,10 +262,35 @@ var balanceCmd = &cmds.Command{ return err } - return printOneString(re, (types.FIL)(balance).String()) + isDone, err := isSyncDone(req.Context, env) + if err != nil { + return err + } + + var balanceStr string + if balance.Equals(big.NewInt(0)) && !isDone { + balanceStr = fmt.Sprintf("%s (warning: may display 0 if chain sync in progress)\n", types.FIL(balance)) + } else { + balanceStr = (types.FIL)(balance).String() + } + + return printOneString(re, balanceStr) }, } +func isSyncDone(ctx context.Context, env cmds.Environment) (bool, error) { + head, err := getEnv(env).ChainAPI.ChainHead(ctx) + if err != nil { + return false, err + } + params, err := getEnv(env).ChainAPI.StateGetNetworkParams(ctx) + if err != nil { + return false, err + } + + return time.Now().Unix()-int64(head.MinTimestamp()) < int64(params.BlockDelaySecs), nil +} + // WalletSerializeResult is the type wallet export and import return and expect. type WalletSerializeResult struct { KeyInfo []*key.KeyInfo From de2aae1981668f6a5eb4f34c284e13ec6dc9ab44 Mon Sep 17 00:00:00 2001 From: simlecode <69969590+simlecode@users.noreply.github.com> Date: Mon, 21 Aug 2023 15:24:42 +0800 Subject: [PATCH 2/3] fix: break loop when ts height is 0 --- pkg/events/filter/index.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/events/filter/index.go b/pkg/events/filter/index.go index 4a7b7829ab..1d97338835 100644 --- a/pkg/events/filter/index.go +++ b/pkg/events/filter/index.go @@ -168,6 +168,10 @@ func (ei *EventIndex) migrateToVersion2(ctx context.Context, chainStore *chain.S currTS := chainStore.GetHead() for int64(currTS.Height()) >= minHeight.Int64 { + if currTS.Height() == 0 { + break + } + if currTS.Height()%1000 == 0 { log.Infof("Migrating height %d (remaining %d)", currTS.Height(), int64(currTS.Height())-minHeight.Int64) } From c6e3952a9d464332f494e97d760f27109aa0458d Mon Sep 17 00:00:00 2001 From: simlecode <69969590+simlecode@users.noreply.github.com> Date: Mon, 21 Aug 2023 16:34:05 +0800 Subject: [PATCH 3/3] chore: fix lint --- cmd/address.go | 2 +- cmd/address_integration_test.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/address.go b/cmd/address.go index b63a3d863b..edf2756779 100644 --- a/cmd/address.go +++ b/cmd/address.go @@ -269,7 +269,7 @@ var balanceCmd = &cmds.Command{ var balanceStr string if balance.Equals(big.NewInt(0)) && !isDone { - balanceStr = fmt.Sprintf("%s (warning: may display 0 if chain sync in progress)\n", types.FIL(balance)) + balanceStr = fmt.Sprintf("%s (warning: may display 0 if chain sync in progress)", types.FIL(balance)) } else { balanceStr = (types.FIL)(balance).String() } diff --git a/cmd/address_integration_test.go b/cmd/address_integration_test.go index 42b0d93d80..4c3a6a70d5 100644 --- a/cmd/address_integration_test.go +++ b/cmd/address_integration_test.go @@ -59,7 +59,7 @@ func TestWalletBalance(t *testing.T) { t.Log("[success] not found, zero") balance := cmdClient.RunSuccess(ctx, "wallet", "balance", addr.String()).ReadStdout() - assert.Equal(t, "0 FIL\n", balance) + assert.Equal(t, "0 FIL (warning: may display 0 if chain sync in progress)\n", balance) t.Log("[success] balance 1394000000000000000000000000") balance = cmdClient.RunSuccess(ctx, "wallet", "balance", builtin.RewardActorAddr.String()).ReadStdout() @@ -69,7 +69,7 @@ func TestWalletBalance(t *testing.T) { var addrNew cmd.AddressResult cmdClient.RunSuccessFirstLine(ctx, "wallet", "new") balance = cmdClient.RunSuccess(ctx, "wallet", "balance", addrNew.Address.String()).ReadStdout() - assert.Equal(t, "0 FIL\n", balance) + assert.Equal(t, "0 FIL (warning: may display 0 if chain sync in progress)\n", balance) } func TestWalletLoadFromFile(t *testing.T) {