Merge pull request #360 from filecoin-project/feat/storage-miner-info

Add more info to storage-miner info command output
This commit is contained in:
Whyrusleeping 2019-10-15 11:12:53 +09:00 committed by GitHub
commit 54a3d2b48e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 100 additions and 16 deletions

View File

@ -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

View File

@ -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

View File

@ -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
}

View File

@ -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
}

View File

@ -4,6 +4,7 @@ import (
"encoding/binary"
"io"
"os"
"sort"
"sync"
"unsafe"
@ -94,8 +95,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) {

View File

@ -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()
}