Add more info to storage-miner info command output
This commit is contained in:
parent
990147a4f1
commit
e8a1b54740
@ -150,7 +150,7 @@ type FullNode interface {
|
|||||||
type StorageMiner interface {
|
type StorageMiner interface {
|
||||||
Common
|
Common
|
||||||
|
|
||||||
ActorAddresses(context.Context) ([]address.Address, error)
|
ActorAddress(context.Context) (address.Address, error)
|
||||||
|
|
||||||
// Temp api for testing
|
// Temp api for testing
|
||||||
StoreGarbageData(context.Context) (uint64, error)
|
StoreGarbageData(context.Context) (uint64, error)
|
||||||
@ -159,7 +159,7 @@ type StorageMiner interface {
|
|||||||
SectorsStatus(context.Context, uint64) (sectorbuilder.SectorSealingStatus, error)
|
SectorsStatus(context.Context, uint64) (sectorbuilder.SectorSealingStatus, error)
|
||||||
|
|
||||||
// List all staged sectors
|
// List all staged sectors
|
||||||
SectorsStagedList(context.Context) ([]sectorbuilder.StagedSectorMetadata, error)
|
SectorsList(context.Context) ([]uint64, error)
|
||||||
|
|
||||||
// Seal all staged sectors
|
// Seal all staged sectors
|
||||||
SectorsStagedSeal(context.Context) error
|
SectorsStagedSeal(context.Context) error
|
||||||
|
@ -118,12 +118,12 @@ type StorageMinerStruct struct {
|
|||||||
CommonStruct
|
CommonStruct
|
||||||
|
|
||||||
Internal struct {
|
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"`
|
StoreGarbageData func(context.Context) (uint64, error) `perm:"write"`
|
||||||
|
|
||||||
SectorsStatus func(context.Context, uint64) (sectorbuilder.SectorSealingStatus, error) `perm:"read"`
|
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"`
|
SectorsStagedSeal func(context.Context) error `perm:"write"`
|
||||||
|
|
||||||
SectorsRefs func(context.Context) (map[string][]SealedRef, error) `perm:"read"`
|
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)
|
return c.Internal.PaychVoucherSubmit(ctx, ch, sv)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *StorageMinerStruct) ActorAddresses(ctx context.Context) ([]address.Address, error) {
|
func (c *StorageMinerStruct) ActorAddress(ctx context.Context) (address.Address, error) {
|
||||||
return c.Internal.ActorAddresses(ctx)
|
return c.Internal.ActorAddress(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *StorageMinerStruct) StoreGarbageData(ctx context.Context) (uint64, error) {
|
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
|
// List all staged sectors
|
||||||
func (c *StorageMinerStruct) SectorsStagedList(ctx context.Context) ([]sectorbuilder.StagedSectorMetadata, error) {
|
func (c *StorageMinerStruct) SectorsList(ctx context.Context) ([]uint64, error) {
|
||||||
return c.Internal.SectorsStagedList(ctx)
|
return c.Internal.SectorsList(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Seal all staged sectors
|
// Seal all staged sectors
|
||||||
|
@ -1,11 +1,15 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"gopkg.in/urfave/cli.v2"
|
"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"
|
lcli "github.com/filecoin-project/go-lotus/cli"
|
||||||
|
sectorstate "github.com/filecoin-project/go-sectorbuilder/sealing_state"
|
||||||
)
|
)
|
||||||
|
|
||||||
var infoCmd = &cli.Command{
|
var infoCmd = &cli.Command{
|
||||||
@ -17,14 +21,40 @@ var infoCmd = &cli.Command{
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer closer()
|
defer closer()
|
||||||
|
|
||||||
|
api, acloser, err := lcli.GetFullNodeAPI(cctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer acloser()
|
||||||
|
|
||||||
ctx := lcli.ReqContext(cctx)
|
ctx := lcli.ReqContext(cctx)
|
||||||
|
|
||||||
aaddr, err := nodeApi.ActorAddresses(ctx)
|
maddr, err := nodeApi.ActorAddress(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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
|
// TODO: grab actr state / info
|
||||||
// * Sector size
|
// * Sector size
|
||||||
// * Sealed sectors (count / bytes)
|
// * Sealed sectors (count / bytes)
|
||||||
@ -32,3 +62,42 @@ var infoCmd = &cli.Command{
|
|||||||
return nil
|
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
|
||||||
|
}
|
||||||
|
@ -89,7 +89,7 @@ var sectorsStagedListCmd = &cli.Command{
|
|||||||
defer closer()
|
defer closer()
|
||||||
ctx := lcli.ReqContext(cctx)
|
ctx := lcli.ReqContext(cctx)
|
||||||
|
|
||||||
staged, err := nodeApi.SectorsStagedList(ctx)
|
staged, err := nodeApi.SectorsList(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
"sort"
|
||||||
"sync"
|
"sync"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
@ -14,6 +15,8 @@ import (
|
|||||||
"github.com/filecoin-project/go-lotus/chain/address"
|
"github.com/filecoin-project/go-lotus/chain/address"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const ()
|
||||||
|
|
||||||
var log = logging.Logger("sectorbuilder")
|
var log = logging.Logger("sectorbuilder")
|
||||||
|
|
||||||
type SectorSealingStatus = sectorbuilder.SectorSealingStatus
|
type SectorSealingStatus = sectorbuilder.SectorSealingStatus
|
||||||
@ -94,8 +97,22 @@ func (sb *SectorBuilder) SealStatus(sector uint64) (SectorSealingStatus, error)
|
|||||||
return sectorbuilder.GetSectorSealingStatusByID(sb.handle, sector)
|
return sectorbuilder.GetSectorSealingStatusByID(sb.handle, sector)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sb *SectorBuilder) GetAllStagedSectors() ([]StagedSectorMetadata, error) {
|
func (sb *SectorBuilder) GetAllStagedSectors() ([]uint64, error) {
|
||||||
return sectorbuilder.GetAllStagedSectors(sb.handle)
|
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) {
|
func (sb *SectorBuilder) GeneratePoSt(sectorInfo SortedSectorInfo, challengeSeed [CommLen]byte, faults []uint64) ([]byte, error) {
|
||||||
|
@ -26,8 +26,8 @@ type StorageMinerAPI struct {
|
|||||||
Miner *storage.Miner
|
Miner *storage.Miner
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sm *StorageMinerAPI) ActorAddresses(context.Context) ([]address.Address, error) {
|
func (sm *StorageMinerAPI) ActorAddress(context.Context) (address.Address, error) {
|
||||||
return []address.Address{sm.SectorBuilderConfig.Miner}, nil
|
return sm.SectorBuilderConfig.Miner, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sm *StorageMinerAPI) StoreGarbageData(ctx context.Context) (uint64, error) {
|
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
|
// 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()
|
return sm.SectorBuilder.GetAllStagedSectors()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user