fix storage-miner cli
This commit is contained in:
parent
0ccc9f65a6
commit
59e5144122
@ -7,20 +7,15 @@ import (
|
|||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
cbor "github.com/ipfs/go-ipld-cbor"
|
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
"golang.org/x/xerrors"
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-bitfield"
|
|
||||||
rlepluslazy "github.com/filecoin-project/go-bitfield/rle"
|
|
||||||
"github.com/filecoin-project/specs-actors/actors/abi"
|
"github.com/filecoin-project/specs-actors/actors/abi"
|
||||||
"github.com/filecoin-project/specs-actors/actors/builtin/miner"
|
"github.com/filecoin-project/specs-actors/actors/builtin/miner"
|
||||||
|
|
||||||
"github.com/filecoin-project/lotus/api/apibstore"
|
|
||||||
"github.com/filecoin-project/lotus/build"
|
"github.com/filecoin-project/lotus/build"
|
||||||
"github.com/filecoin-project/lotus/chain/types"
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
lcli "github.com/filecoin-project/lotus/cli"
|
lcli "github.com/filecoin-project/lotus/cli"
|
||||||
"github.com/filecoin-project/lotus/lib/adtutil"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var provingCmd = &cli.Command{
|
var provingCmd = &cli.Command{
|
||||||
@ -70,14 +65,7 @@ var provingFaultsCmd = &cli.Command{
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
faults, err := mas.Faults.All(100000000000)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if len(faults) == 0 {
|
|
||||||
fmt.Println("no faulty sectors")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
head, err := api.ChainHead(ctx)
|
head, err := api.ChainHead(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return xerrors.Errorf("getting chain head: %w", err)
|
return xerrors.Errorf("getting chain head: %w", err)
|
||||||
@ -87,16 +75,23 @@ var provingFaultsCmd = &cli.Command{
|
|||||||
return xerrors.Errorf("getting miner deadlines: %w", err)
|
return xerrors.Errorf("getting miner deadlines: %w", err)
|
||||||
}
|
}
|
||||||
tw := tabwriter.NewWriter(os.Stdout, 2, 4, 2, ' ', 0)
|
tw := tabwriter.NewWriter(os.Stdout, 2, 4, 2, ' ', 0)
|
||||||
_, _ = fmt.Fprintln(tw, "deadline\tsectors")
|
_, _ = fmt.Fprintln(tw, "deadline\tpartition\tsectors")
|
||||||
for deadline, sectors := range deadlines.Due {
|
for dlIdx := range deadlines {
|
||||||
intersectSectors, _ := bitfield.IntersectBitField(sectors, mas.Faults)
|
partitions, err := api.StateMinerPartitions(ctx, maddr, uint64(dlIdx), types.EmptyTSK)
|
||||||
if intersectSectors != nil {
|
if err != nil {
|
||||||
allSectors, _ := intersectSectors.All(100000000000)
|
return xerrors.Errorf("loading partitions for deadline %d: %w", dlIdx, err)
|
||||||
for _, num := range allSectors {
|
|
||||||
_, _ = fmt.Fprintf(tw, "%d\t%d\n", deadline, num)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for partIdx, partition := range partitions {
|
||||||
|
faulty, err := partition.Faults.All(10000000)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, num := range faulty {
|
||||||
|
_, _ = fmt.Fprintf(tw, "%d\t%d\t%d\n", dlIdx, partIdx, num)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return tw.Flush()
|
return tw.Flush()
|
||||||
},
|
},
|
||||||
@ -155,55 +150,68 @@ var provingInfoCmd = &cli.Command{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
newSectors, err := mas.NewSectors.Count()
|
parts := map[uint64][]*miner.Partition{}
|
||||||
if err != nil {
|
for dlIdx := range deadlines {
|
||||||
return err
|
part, err := api.StateMinerPartitions(ctx, maddr, uint64(dlIdx), types.EmptyTSK)
|
||||||
}
|
|
||||||
|
|
||||||
faults, err := mas.Faults.Count()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
recoveries, err := mas.Recoveries.Count()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
var provenSectors uint64
|
|
||||||
for _, d := range deadlines.Due {
|
|
||||||
c, err := d.Count()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return xerrors.Errorf("getting miner partition: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
parts[uint64(dlIdx)] = part
|
||||||
|
}
|
||||||
|
|
||||||
|
proving := uint64(0)
|
||||||
|
faults := uint64(0)
|
||||||
|
recovering := uint64(0)
|
||||||
|
|
||||||
|
for _, partitions := range parts {
|
||||||
|
for _, partition := range partitions {
|
||||||
|
sc, err := partition.Sectors.Count()
|
||||||
|
if err != nil {
|
||||||
|
return xerrors.Errorf("count partition sectors: %w", err)
|
||||||
|
}
|
||||||
|
proving += sc
|
||||||
|
|
||||||
|
fc, err := partition.Faults.Count()
|
||||||
|
if err != nil {
|
||||||
|
return xerrors.Errorf("count partition sectors: %w", err)
|
||||||
|
}
|
||||||
|
faults += fc
|
||||||
|
|
||||||
|
rc, err := partition.Faults.Count()
|
||||||
|
if err != nil {
|
||||||
|
return xerrors.Errorf("count partition sectors: %w", err)
|
||||||
|
}
|
||||||
|
recovering += rc
|
||||||
}
|
}
|
||||||
provenSectors += c
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var faultPerc float64
|
var faultPerc float64
|
||||||
if provenSectors > 0 {
|
if proving > 0 {
|
||||||
faultPerc = float64(faults*10000/provenSectors) / 100
|
faultPerc = float64(faults*10000/proving) / 100
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("Current Epoch: %d\n", cd.CurrentEpoch)
|
fmt.Printf("Current Epoch: %d\n", cd.CurrentEpoch)
|
||||||
fmt.Printf("Chain Period: %d\n", cd.CurrentEpoch/miner.WPoStProvingPeriod)
|
|
||||||
fmt.Printf("Chain Period Start: %s\n", epochTime(cd.CurrentEpoch, (cd.CurrentEpoch/miner.WPoStProvingPeriod)*miner.WPoStProvingPeriod))
|
|
||||||
fmt.Printf("Chain Period End: %s\n\n", epochTime(cd.CurrentEpoch, (cd.CurrentEpoch/miner.WPoStProvingPeriod+1)*miner.WPoStProvingPeriod))
|
|
||||||
|
|
||||||
fmt.Printf("Proving Period Boundary: %d\n", cd.PeriodStart%miner.WPoStProvingPeriod)
|
fmt.Printf("Proving Period Boundary: %d\n", cd.PeriodStart%miner.WPoStProvingPeriod)
|
||||||
fmt.Printf("Proving Period Start: %s\n", epochTime(cd.CurrentEpoch, cd.PeriodStart))
|
fmt.Printf("Proving Period Start: %s\n", epochTime(cd.CurrentEpoch, cd.PeriodStart))
|
||||||
fmt.Printf("Next Period Start: %s\n\n", epochTime(cd.CurrentEpoch, cd.PeriodStart+miner.WPoStProvingPeriod))
|
fmt.Printf("Next Period Start: %s\n\n", epochTime(cd.CurrentEpoch, cd.PeriodStart+miner.WPoStProvingPeriod))
|
||||||
|
|
||||||
fmt.Printf("Faults: %d (%.2f%%)\n", faults, faultPerc)
|
fmt.Printf("Faults: %d (%.2f%%)\n", faults, faultPerc)
|
||||||
fmt.Printf("Recovering: %d\n", recoveries)
|
fmt.Printf("Recovering: %d\n", recovering)
|
||||||
fmt.Printf("New Sectors: %d\n\n", newSectors)
|
|
||||||
|
|
||||||
fmt.Printf("Deadline Index: %d\n", cd.Index)
|
fmt.Printf("Deadline Index: %d\n", cd.Index)
|
||||||
|
|
||||||
if cd.Index < uint64(len(deadlines.Due)) {
|
if cd.Index < miner.WPoStPeriodDeadlines {
|
||||||
curDeadlineSectors, err := deadlines.Due[cd.Index].Count()
|
curDeadlineSectors := uint64(0)
|
||||||
if err != nil {
|
for _, partition := range parts[cd.Index] {
|
||||||
return xerrors.Errorf("counting deadline sectors: %w", err)
|
sc, err := partition.Sectors.Count()
|
||||||
|
if err != nil {
|
||||||
|
return xerrors.Errorf("counting current deadline sectors: %w", err)
|
||||||
|
}
|
||||||
|
curDeadlineSectors += sc
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("Deadline Sectors: %d\n", curDeadlineSectors)
|
fmt.Printf("Deadline Sectors: %d\n", curDeadlineSectors)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -262,7 +270,6 @@ var provingDeadlinesCmd = &cli.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
var mas miner.State
|
var mas miner.State
|
||||||
var info *miner.MinerInfo
|
|
||||||
{
|
{
|
||||||
mact, err := api.StateGetActor(ctx, maddr, types.EmptyTSK)
|
mact, err := api.StateGetActor(ctx, maddr, types.EmptyTSK)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -275,64 +282,27 @@ var provingDeadlinesCmd = &cli.Command{
|
|||||||
if err := mas.UnmarshalCBOR(bytes.NewReader(rmas)); err != nil {
|
if err := mas.UnmarshalCBOR(bytes.NewReader(rmas)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
info, err = mas.GetInfo(adtutil.NewStore(ctx, cbor.NewCborStore(apibstore.NewAPIBlockstore(api))))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tw := tabwriter.NewWriter(os.Stdout, 2, 4, 2, ' ', 0)
|
tw := tabwriter.NewWriter(os.Stdout, 2, 4, 2, ' ', 0)
|
||||||
_, _ = fmt.Fprintln(tw, "deadline\tsectors\tpartitions\tproven")
|
_, _ = fmt.Fprintln(tw, "deadline\tpartitions\tsectors\tproven")
|
||||||
|
|
||||||
for i, field := range deadlines.Due {
|
for dlIdx, deadline := range deadlines {
|
||||||
c, err := field.Count()
|
partitions, err := api.StateMinerPartitions(ctx, maddr, uint64(dlIdx), types.EmptyTSK)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return xerrors.Errorf("getting partitions for deadline %d: %w", dlIdx, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
firstPartition, sectorCount, err := miner.PartitionsForDeadline(deadlines, info.WindowPoStPartitionSectors, uint64(i))
|
provenPartitions, err := deadline.PostSubmissions.Count()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
partitionCount := (sectorCount + info.WindowPoStPartitionSectors - 1) / info.WindowPoStPartitionSectors
|
|
||||||
|
|
||||||
var provenPartitions uint64
|
|
||||||
{
|
|
||||||
var maskRuns []rlepluslazy.Run
|
|
||||||
if firstPartition > 0 {
|
|
||||||
maskRuns = append(maskRuns, rlepluslazy.Run{
|
|
||||||
Val: false,
|
|
||||||
Len: firstPartition,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
maskRuns = append(maskRuns, rlepluslazy.Run{
|
|
||||||
Val: true,
|
|
||||||
Len: partitionCount,
|
|
||||||
})
|
|
||||||
|
|
||||||
ppbm, err := bitfield.NewFromIter(&rlepluslazy.RunSliceIterator{Runs: maskRuns})
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
pp, err := bitfield.IntersectBitField(ppbm, mas.PostSubmissions)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
provenPartitions, err = pp.Count()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var cur string
|
var cur string
|
||||||
if di.Index == uint64(i) {
|
if di.Index == uint64(dlIdx) {
|
||||||
cur += "\t(current)"
|
cur += "\t(current)"
|
||||||
}
|
}
|
||||||
_, _ = fmt.Fprintf(tw, "%d\t%d\t%d\t%d%s\n", i, c, partitionCount, provenPartitions, cur)
|
_, _ = fmt.Fprintf(tw, "%d\t%d\t%d\t%d%s\n", dlIdx, len(partitions), provenPartitions)
|
||||||
}
|
}
|
||||||
|
|
||||||
return tw.Flush()
|
return tw.Flush()
|
||||||
|
Loading…
Reference in New Issue
Block a user