From 709fd12b7fc5a402295980f59dc70ba0f4ce533a Mon Sep 17 00:00:00 2001 From: steven004 Date: Thu, 6 Feb 2020 14:25:30 +0800 Subject: [PATCH] better power show --- chain/actors/actor_storagepower.go | 3 ++- cli/state.go | 9 ++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/chain/actors/actor_storagepower.go b/chain/actors/actor_storagepower.go index 1a2491aa7..0c33f3056 100644 --- a/chain/actors/actor_storagepower.go +++ b/chain/actors/actor_storagepower.go @@ -475,7 +475,8 @@ func powerLookup(ctx context.Context, vmctx types.VMContext, self *StoragePowerS } if !has { - return types.EmptyInt, aerrors.New(1, "miner not registered with storage power actor") + // A miner could be registered with storage power actor, but removed for some reasons, e.g. consensus fault + return types.EmptyInt, aerrors.New(1, "miner not registered with storage power actor, or removed already") } // TODO: Use local amt diff --git a/cli/state.go b/cli/state.go index f92044aaa..7abc1e3f4 100644 --- a/cli/state.go +++ b/cli/state.go @@ -119,12 +119,15 @@ var statePowerCmd = &cli.Command{ return err } - res := power.TotalPower + tp := power.TotalPower if cctx.Args().Present() { - res = power.MinerPower + mp := power.MinerPower + percI := types.BigDiv(types.BigMul(mp, types.NewInt(1000000)), tp) + fmt.Printf("%s(%s) / %s(%s) ~= %0.4f%%\n", mp.String(), mp.SizeStr(), tp.String(), tp.SizeStr(), float64(percI.Int64())/10000) + } else { + fmt.Printf("%s(%s)\n", tp.String(), tp.SizeStr()) } - fmt.Println(res.String()) return nil }, }