From e8a1b54740d003f69456fd65dea98b9c66adf728 Mon Sep 17 00:00:00 2001 From: whyrusleeping Date: Mon, 14 Oct 2019 11:32:32 +0900 Subject: [PATCH 1/2] Add more info to storage-miner info command output --- api/api.go | 4 +- api/struct.go | 12 ++--- cmd/lotus-storage-miner/info.go | 73 +++++++++++++++++++++++++++++- cmd/lotus-storage-miner/sectors.go | 2 +- lib/sectorbuilder/sectorbuilder.go | 21 ++++++++- node/impl/storminer.go | 6 +-- 6 files changed, 102 insertions(+), 16 deletions(-) diff --git a/api/api.go b/api/api.go index cb1c72bef..ceb68c85c 100644 --- a/api/api.go +++ b/api/api.go @@ -150,7 +150,7 @@ type FullNode interface { type StorageMiner interface { Common - ActorAddresses(context.Context) ([]address.Address, error) + ActorAddress(context.Context) (address.Address, error) // Temp api for testing StoreGarbageData(context.Context) (uint64, error) @@ -159,7 +159,7 @@ type StorageMiner interface { SectorsStatus(context.Context, uint64) (sectorbuilder.SectorSealingStatus, error) // List all staged sectors - SectorsStagedList(context.Context) ([]sectorbuilder.StagedSectorMetadata, error) + SectorsList(context.Context) ([]uint64, error) // Seal all staged sectors SectorsStagedSeal(context.Context) error diff --git a/api/struct.go b/api/struct.go index b1df124b2..6fa47e043 100644 --- a/api/struct.go +++ b/api/struct.go @@ -118,12 +118,12 @@ type StorageMinerStruct struct { CommonStruct Internal struct { - ActorAddresses func(context.Context) ([]address.Address, error) `perm:"read"` + ActorAddress func(context.Context) (address.Address, error) `perm:"read"` StoreGarbageData func(context.Context) (uint64, error) `perm:"write"` SectorsStatus func(context.Context, uint64) (sectorbuilder.SectorSealingStatus, error) `perm:"read"` - SectorsStagedList func(context.Context) ([]sectorbuilder.StagedSectorMetadata, error) `perm:"read"` + SectorsList func(context.Context) ([]uint64, error) `perm:"read"` SectorsStagedSeal func(context.Context) error `perm:"write"` SectorsRefs func(context.Context) (map[string][]SealedRef, error) `perm:"read"` @@ -426,8 +426,8 @@ func (c *FullNodeStruct) PaychVoucherSubmit(ctx context.Context, ch address.Addr return c.Internal.PaychVoucherSubmit(ctx, ch, sv) } -func (c *StorageMinerStruct) ActorAddresses(ctx context.Context) ([]address.Address, error) { - return c.Internal.ActorAddresses(ctx) +func (c *StorageMinerStruct) ActorAddress(ctx context.Context) (address.Address, error) { + return c.Internal.ActorAddress(ctx) } func (c *StorageMinerStruct) StoreGarbageData(ctx context.Context) (uint64, error) { @@ -440,8 +440,8 @@ func (c *StorageMinerStruct) SectorsStatus(ctx context.Context, sid uint64) (sec } // List all staged sectors -func (c *StorageMinerStruct) SectorsStagedList(ctx context.Context) ([]sectorbuilder.StagedSectorMetadata, error) { - return c.Internal.SectorsStagedList(ctx) +func (c *StorageMinerStruct) SectorsList(ctx context.Context) ([]uint64, error) { + return c.Internal.SectorsList(ctx) } // Seal all staged sectors diff --git a/cmd/lotus-storage-miner/info.go b/cmd/lotus-storage-miner/info.go index 702af2c2b..cd097810f 100644 --- a/cmd/lotus-storage-miner/info.go +++ b/cmd/lotus-storage-miner/info.go @@ -1,11 +1,15 @@ package main import ( + "context" "fmt" "gopkg.in/urfave/cli.v2" + "github.com/filecoin-project/go-lotus/api" + "github.com/filecoin-project/go-lotus/chain/types" lcli "github.com/filecoin-project/go-lotus/cli" + sectorstate "github.com/filecoin-project/go-sectorbuilder/sealing_state" ) var infoCmd = &cli.Command{ @@ -17,14 +21,40 @@ var infoCmd = &cli.Command{ return err } defer closer() + + api, acloser, err := lcli.GetFullNodeAPI(cctx) + if err != nil { + return err + } + defer acloser() + ctx := lcli.ReqContext(cctx) - aaddr, err := nodeApi.ActorAddresses(ctx) + maddr, err := nodeApi.ActorAddress(ctx) if err != nil { return err } - fmt.Printf("actor address: %s\n", aaddr) + fmt.Printf("Miner: %s\n", maddr) + + pow, err := api.StateMinerPower(ctx, maddr, nil) + if err != nil { + return err + } + + percI := types.BigDiv(types.BigMul(pow.MinerPower, types.NewInt(1000)), pow.TotalPower) + fmt.Printf("Power: %s / %s (%0.2f%%)\n", pow.MinerPower, pow.TotalPower, float64(percI.Int64())/1000) + + sinfo, err := sectorsInfo(ctx, nodeApi) + if err != nil { + return err + } + + fmt.Println("Sealed Sectors:\t", sinfo.SealedCount) + fmt.Println("Sealing Sectors:\t", sinfo.SealingCount) + fmt.Println("Pending Sectors:\t", sinfo.PendingCount) + fmt.Println("Failed Sectors:\t", sinfo.FailedCount) + // TODO: grab actr state / info // * Sector size // * Sealed sectors (count / bytes) @@ -32,3 +62,42 @@ var infoCmd = &cli.Command{ return nil }, } + +type SectorsInfo struct { + TotalCount int + SealingCount int + FailedCount int + SealedCount int + PendingCount int +} + +func sectorsInfo(ctx context.Context, napi api.StorageMiner) (*SectorsInfo, error) { + sectors, err := napi.SectorsList(ctx) + if err != nil { + return nil, err + } + + out := SectorsInfo{ + TotalCount: len(sectors), + } + for _, s := range sectors { + st, err := napi.SectorsStatus(ctx, s) + if err != nil { + return nil, err + } + + switch st.State { + case sectorstate.Sealed: + out.SealedCount++ + case sectorstate.Pending: + out.PendingCount++ + case sectorstate.Sealing: + out.SealingCount++ + case sectorstate.Failed: + out.FailedCount++ + case sectorstate.Unknown: + } + } + + return &out, nil +} diff --git a/cmd/lotus-storage-miner/sectors.go b/cmd/lotus-storage-miner/sectors.go index b048b2f67..8011db4cd 100644 --- a/cmd/lotus-storage-miner/sectors.go +++ b/cmd/lotus-storage-miner/sectors.go @@ -89,7 +89,7 @@ var sectorsStagedListCmd = &cli.Command{ defer closer() ctx := lcli.ReqContext(cctx) - staged, err := nodeApi.SectorsStagedList(ctx) + staged, err := nodeApi.SectorsList(ctx) if err != nil { return err } diff --git a/lib/sectorbuilder/sectorbuilder.go b/lib/sectorbuilder/sectorbuilder.go index 4613750ae..6e7101efa 100644 --- a/lib/sectorbuilder/sectorbuilder.go +++ b/lib/sectorbuilder/sectorbuilder.go @@ -4,6 +4,7 @@ import ( "encoding/binary" "io" "os" + "sort" "sync" "unsafe" @@ -14,6 +15,8 @@ import ( "github.com/filecoin-project/go-lotus/chain/address" ) +const () + var log = logging.Logger("sectorbuilder") type SectorSealingStatus = sectorbuilder.SectorSealingStatus @@ -94,8 +97,22 @@ func (sb *SectorBuilder) SealStatus(sector uint64) (SectorSealingStatus, error) return sectorbuilder.GetSectorSealingStatusByID(sb.handle, sector) } -func (sb *SectorBuilder) GetAllStagedSectors() ([]StagedSectorMetadata, error) { - return sectorbuilder.GetAllStagedSectors(sb.handle) +func (sb *SectorBuilder) GetAllStagedSectors() ([]uint64, error) { + sectors, err := sectorbuilder.GetAllStagedSectors(sb.handle) + if err != nil { + return nil, err + } + + out := make([]uint64, len(sectors)) + for i, v := range sectors { + out[i] = v.SectorID + } + + sort.Slice(out, func(i, j int) bool { + return out[i] < out[j] + }) + + return out, nil } func (sb *SectorBuilder) GeneratePoSt(sectorInfo SortedSectorInfo, challengeSeed [CommLen]byte, faults []uint64) ([]byte, error) { diff --git a/node/impl/storminer.go b/node/impl/storminer.go index 92c7162c2..995c20da6 100644 --- a/node/impl/storminer.go +++ b/node/impl/storminer.go @@ -26,8 +26,8 @@ type StorageMinerAPI struct { Miner *storage.Miner } -func (sm *StorageMinerAPI) ActorAddresses(context.Context) ([]address.Address, error) { - return []address.Address{sm.SectorBuilderConfig.Miner}, nil +func (sm *StorageMinerAPI) ActorAddress(context.Context) (address.Address, error) { + return sm.SectorBuilderConfig.Miner, nil } func (sm *StorageMinerAPI) StoreGarbageData(ctx context.Context) (uint64, error) { @@ -47,7 +47,7 @@ func (sm *StorageMinerAPI) SectorsStatus(ctx context.Context, sid uint64) (secto } // List all staged sectors -func (sm *StorageMinerAPI) SectorsStagedList(context.Context) ([]sectorbuilder.StagedSectorMetadata, error) { +func (sm *StorageMinerAPI) SectorsList(context.Context) ([]uint64, error) { return sm.SectorBuilder.GetAllStagedSectors() } From ab7eafe76c1bc85b3fbaebac0fb6ea978272445f Mon Sep 17 00:00:00 2001 From: whyrusleeping Date: Tue, 15 Oct 2019 09:56:40 +0900 Subject: [PATCH 2/2] remove empty const block --- lib/sectorbuilder/sectorbuilder.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/sectorbuilder/sectorbuilder.go b/lib/sectorbuilder/sectorbuilder.go index 6e7101efa..f6c412a83 100644 --- a/lib/sectorbuilder/sectorbuilder.go +++ b/lib/sectorbuilder/sectorbuilder.go @@ -15,8 +15,6 @@ import ( "github.com/filecoin-project/go-lotus/chain/address" ) -const () - var log = logging.Logger("sectorbuilder") type SectorSealingStatus = sectorbuilder.SectorSealingStatus