Tweak miner info --blocks output

This commit is contained in:
Łukasz Magiera 2021-08-27 13:36:40 +02:00
parent 4630216c38
commit 22d75f4843
3 changed files with 25 additions and 4 deletions

View File

@ -123,7 +123,7 @@ type State interface {
cbor.Marshaler cbor.Marshaler
ThisEpochBaselinePower() (abi.StoragePower, error) ThisEpochBaselinePower() (abi.StoragePower, error)
ThisEpochReward() (abi.TokenAmount, error) ThisEpochReward() (abi.StoragePower, error)
ThisEpochRewardSmoothed() (builtin.FilterEstimate, error) ThisEpochRewardSmoothed() (builtin.FilterEstimate, error)
EffectiveBaselinePower() (abi.StoragePower, error) EffectiveBaselinePower() (abi.StoragePower, error)

View File

@ -12,6 +12,7 @@ import (
"time" "time"
"github.com/fatih/color" "github.com/fatih/color"
"github.com/mattn/go-isatty"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
"golang.org/x/xerrors" "golang.org/x/xerrors"
@ -567,13 +568,23 @@ func producedBlocks(ctx context.Context, count int, maddr address.Address, napi
tbs := blockstore.NewTieredBstore(blockstore.NewAPIBlockstore(napi), blockstore.NewMemory()) tbs := blockstore.NewTieredBstore(blockstore.NewAPIBlockstore(napi), blockstore.NewMemory())
tty := isatty.IsTerminal(os.Stderr.Fd())
ts := head ts := head
fmt.Printf(" Epoch | Block ID | Reward\n") fmt.Printf(" Epoch | Block ID | Reward\n")
for count > 0 { for count > 0 {
tsk := ts.Key() tsk := ts.Key()
bhs := ts.Blocks() bhs := ts.Blocks()
for _, bh := range bhs { for _, bh := range bhs {
if ctx.Err() != nil {
return ctx.Err()
}
if bh.Miner == maddr { if bh.Miner == maddr {
if tty {
_, _ = fmt.Fprint(os.Stderr, "\r\x1b[0K")
}
rewardActor, err := napi.StateGetActor(ctx, reward.Address, tsk) rewardActor, err := napi.StateGetActor(ctx, reward.Address, tsk)
if err != nil { if err != nil {
return err return err
@ -587,10 +598,14 @@ func producedBlocks(ctx context.Context, count int, maddr address.Address, napi
if err != nil { if err != nil {
return err return err
} }
fmt.Printf("%8d | %s | %s\n", ts.Height(), bh.Cid(),
types.BigDiv(types.BigMul(types.NewInt(uint64(bh.ElectionProof.WinCount)), minerReward := types.BigDiv(types.BigMul(types.NewInt(uint64(bh.ElectionProof.WinCount)),
blockReward), types.NewInt(uint64(builtin.ExpectedLeadersPerEpoch)))) blockReward), types.NewInt(uint64(builtin.ExpectedLeadersPerEpoch)))
fmt.Printf("%8d | %s | %s\n", ts.Height(), bh.Cid(), types.FIL(minerReward))
count-- count--
} else if tty && bh.Height%120 == 0 {
_, _ = fmt.Fprintf(os.Stderr, "\r\x1b[0KChecking epoch %s", lcli.EpochTime(head.Height(), bh.Height))
} }
} }
tsk = ts.Parents() tsk = ts.Parents()
@ -599,5 +614,10 @@ func producedBlocks(ctx context.Context, count int, maddr address.Address, napi
return err return err
} }
} }
if tty {
_, _ = fmt.Fprint(os.Stderr, "\r\x1b[0K")
}
return nil return nil
} }

View File

@ -430,6 +430,7 @@ COMMANDS:
OPTIONS: OPTIONS:
--hide-sectors-info hide sectors info (default: false) --hide-sectors-info hide sectors info (default: false)
--blocks value Log of produced <blocks> newest blocks and rewards(Miner Fee excluded) (default: 0)
--help, -h show help (default: false) --help, -h show help (default: false)
--version, -v print the version (default: false) --version, -v print the version (default: false)