Skip to content

Commit

Permalink
add produced blocks info
Browse files Browse the repository at this point in the history
  • Loading branch information
deaswang committed Jan 5, 2021
1 parent bb5a92e commit 20aa4bd
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 17 deletions.
2 changes: 1 addition & 1 deletion chain/actors/builtin/reward/reward.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type State interface {
cbor.Marshaler

ThisEpochBaselinePower() (abi.StoragePower, error)
ThisEpochReward() (abi.StoragePower, error)
ThisEpochReward() (abi.TokenAmount, error)
ThisEpochRewardSmoothed() (builtin.FilterEstimate, error)

EffectiveBaselinePower() (abi.StoragePower, error)
Expand Down
84 changes: 68 additions & 16 deletions cmd/lotus-storage-miner/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,22 @@ import (

cbor "github.com/ipfs/go-ipld-cbor"

"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-fil-markets/storagemarket"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/big"
sealing "github.com/filecoin-project/lotus/extern/storage-sealing"
"github.com/filecoin-project/specs-actors/actors/builtin"

"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/api/apibstore"
"github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/chain/actors/adt"
"github.com/filecoin-project/lotus/chain/actors/builtin/miner"
"github.com/filecoin-project/lotus/chain/actors/builtin/reward"
"github.com/filecoin-project/lotus/chain/types"
lcli "github.com/filecoin-project/lotus/cli"
cw_util "github.com/filecoin-project/lotus/cmd/lotus-chainwatch/util"
"github.com/filecoin-project/lotus/lib/blockstore"
"github.com/filecoin-project/lotus/lib/bufbstore"
)
Expand All @@ -39,20 +43,24 @@ var infoCmd = &cli.Command{
Name: "hide-sectors-info",
Usage: "hide sectors info",
},
&cli.IntFlag{
Name: "blocks",
Usage: "Log of produced <blocks> newest blocks and rewards(Miner Fee excluded)",
},
},
Action: infoCmdAct,
}

func infoCmdAct(cctx *cli.Context) error {
color.NoColor = !cctx.Bool("color")

nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx)
minerApi, closer, err := lcli.GetStorageMinerAPI(cctx)
if err != nil {
return err
}
defer closer()

api, acloser, err := lcli.GetFullNodeAPI(cctx)
nodeApi, acloser, err := lcli.GetFullNodeAPI(cctx)
if err != nil {
return err
}
Expand All @@ -62,7 +70,7 @@ func infoCmdAct(cctx *cli.Context) error {

fmt.Print("Chain: ")

head, err := api.ChainHead(ctx)
head, err := nodeApi.ChainHead(ctx)
if err != nil {
return err
}
Expand Down Expand Up @@ -92,32 +100,32 @@ func infoCmdAct(cctx *cli.Context) error {

fmt.Println()

maddr, err := getActorAddress(ctx, nodeApi, cctx.String("actor"))
maddr, err := getActorAddress(ctx, minerApi, cctx.String("actor"))
if err != nil {
return err
}

mact, err := api.StateGetActor(ctx, maddr, types.EmptyTSK)
mact, err := nodeApi.StateGetActor(ctx, maddr, types.EmptyTSK)
if err != nil {
return err
}

tbs := bufbstore.NewTieredBstore(apibstore.NewAPIBlockstore(api), blockstore.NewTemporary())
tbs := bufbstore.NewTieredBstore(apibstore.NewAPIBlockstore(nodeApi), blockstore.NewTemporary())
mas, err := miner.Load(adt.WrapStore(ctx, cbor.NewCborStore(tbs)), mact)
if err != nil {
return err
}

// Sector size
mi, err := api.StateMinerInfo(ctx, maddr, types.EmptyTSK)
mi, err := nodeApi.StateMinerInfo(ctx, maddr, types.EmptyTSK)
if err != nil {
return err
}

ssize := types.SizeStr(types.NewInt(uint64(mi.SectorSize)))
fmt.Printf("Miner: %s (%s sectors)\n", color.BlueString("%s", maddr), ssize)

pow, err := api.StateMinerPower(ctx, maddr, types.EmptyTSK)
pow, err := nodeApi.StateMinerPower(ctx, maddr, types.EmptyTSK)
if err != nil {
return err
}
Expand All @@ -135,7 +143,7 @@ func infoCmdAct(cctx *cli.Context) error {
types.SizeStr(pow.TotalPower.RawBytePower),
float64(rpercI.Int64())/10000)

secCounts, err := api.StateMinerSectorCount(ctx, maddr, types.EmptyTSK)
secCounts, err := nodeApi.StateMinerSectorCount(ctx, maddr, types.EmptyTSK)
if err != nil {
return err
}
Expand Down Expand Up @@ -174,7 +182,7 @@ func infoCmdAct(cctx *cli.Context) error {

fmt.Println()

deals, err := nodeApi.MarketListIncompleteDeals(ctx)
deals, err := minerApi.MarketListIncompleteDeals(ctx)
if err != nil {
return err
}
Expand Down Expand Up @@ -224,7 +232,7 @@ func infoCmdAct(cctx *cli.Context) error {
fmt.Printf(" Vesting: %s\n", types.FIL(lockedFunds.VestingFunds).Short())
color.Green(" Available: %s", types.FIL(availBalance).Short())

mb, err := api.StateMarketBalance(ctx, maddr, types.EmptyTSK)
mb, err := nodeApi.StateMarketBalance(ctx, maddr, types.EmptyTSK)
if err != nil {
return xerrors.Errorf("getting market balance: %w", err)
}
Expand All @@ -234,7 +242,7 @@ func infoCmdAct(cctx *cli.Context) error {
fmt.Printf(" Locked: %s\n", types.FIL(mb.Locked).Short())
color.Green(" Available: %s\n", types.FIL(big.Sub(mb.Escrow, mb.Locked)).Short())

wb, err := api.WalletBalance(ctx, mi.Worker)
wb, err := nodeApi.WalletBalance(ctx, mi.Worker)
if err != nil {
return xerrors.Errorf("getting worker balance: %w", err)
}
Expand All @@ -243,7 +251,7 @@ func infoCmdAct(cctx *cli.Context) error {
if len(mi.ControlAddresses) > 0 {
cbsum := big.Zero()
for _, ca := range mi.ControlAddresses {
b, err := api.WalletBalance(ctx, ca)
b, err := nodeApi.WalletBalance(ctx, ca)
if err != nil {
return xerrors.Errorf("getting control address balance: %w", err)
}
Expand All @@ -259,12 +267,19 @@ func infoCmdAct(cctx *cli.Context) error {

if !cctx.Bool("hide-sectors-info") {
fmt.Println("Sectors:")
err = sectorsInfo(ctx, nodeApi)
err = sectorsInfo(ctx, minerApi)
if err != nil {
return err
}
}

if cctx.IsSet("blocks") {
fmt.Println("Produced newest blocks:")
err = producedBlocks(ctx, cctx.Int("blocks"), head, maddr, nodeApi)
if err != nil {
return err
}
}
// TODO: grab actr state / info
// * Sealed sectors (count / bytes)
// * Power
Expand Down Expand Up @@ -326,8 +341,8 @@ func init() {
}
}

func sectorsInfo(ctx context.Context, napi api.StorageMiner) error {
summary, err := napi.SectorsSummary(ctx)
func sectorsInfo(ctx context.Context, mapi api.StorageMiner) error {
summary, err := mapi.SectorsSummary(ctx)
if err != nil {
return err
}
Expand Down Expand Up @@ -355,3 +370,40 @@ func sectorsInfo(ctx context.Context, napi api.StorageMiner) error {

return nil
}

func producedBlocks(ctx context.Context, count int, head *types.TipSet, maddr address.Address, napi api.FullNode) error {
var err error
ts := head
fmt.Printf(" Epoch | Block ID | Reward\n")
for count > 0 {
tsk := ts.Key()
bhs := ts.Blocks()
for _, bh := range bhs {
if bh.Miner == maddr {
rewardActor, err := napi.StateGetActor(ctx, reward.Address, tsk)
if err != nil {
return err
}

rewardActorState, err := reward.Load(cw_util.NewAPIIpldStore(ctx, napi), rewardActor)
if err != nil {
return err
}
blockReward, err := rewardActorState.ThisEpochReward()
if err != nil {
return err
}
fmt.Printf("%8d | %s | %s\n", ts.Height(), bh.Cid(),
types.BigDiv(types.BigMul(types.NewInt(uint64(bh.ElectionProof.WinCount)),
blockReward), types.NewInt(uint64(builtin.ExpectedLeadersPerEpoch))))
count--
}
}
tsk = ts.Parents()
ts, err = napi.ChainGetTipSet(ctx, tsk)
if err != nil {
return err
}
}
return nil
}

0 comments on commit 20aa4bd

Please sign in to comment.