2022-05-23 04:54:00 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"sort"
|
|
|
|
|
2022-06-14 15:00:51 +00:00
|
|
|
cbor "github.com/ipfs/go-ipld-cbor"
|
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
|
2022-06-03 17:51:46 +00:00
|
|
|
minertypes "github.com/filecoin-project/go-state-types/builtin/v8/miner"
|
2022-06-14 15:00:51 +00:00
|
|
|
"github.com/filecoin-project/specs-actors/v7/actors/util/adt"
|
2022-06-03 17:51:46 +00:00
|
|
|
|
|
|
|
"github.com/filecoin-project/lotus/blockstore"
|
2022-06-14 15:00:51 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/actors/builtin/miner"
|
2022-05-23 04:54:00 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
|
|
|
lcli "github.com/filecoin-project/lotus/cli"
|
|
|
|
)
|
|
|
|
|
|
|
|
var sectorPreCommitsCmd = &cli.Command{
|
2022-05-23 16:11:59 +00:00
|
|
|
Name: "precommits",
|
2022-05-23 16:12:09 +00:00
|
|
|
Usage: "Print on-chain precommit info",
|
2022-05-23 04:54:00 +00:00
|
|
|
Action: func(cctx *cli.Context) error {
|
|
|
|
ctx := lcli.ReqContext(cctx)
|
|
|
|
mapi, closer, err := lcli.GetFullNodeAPI(cctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer closer()
|
|
|
|
maddr, err := getActorAddress(ctx, cctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
mact, err := mapi.StateGetActor(ctx, maddr, types.EmptyTSK)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
store := adt.WrapStore(ctx, cbor.NewCborStore(blockstore.NewAPIBlockstore(mapi)))
|
|
|
|
mst, err := miner.Load(store, mact)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-06-03 17:51:46 +00:00
|
|
|
preCommitSector := make([]minertypes.SectorPreCommitOnChainInfo, 0)
|
|
|
|
err = mst.ForEachPrecommittedSector(func(info minertypes.SectorPreCommitOnChainInfo) error {
|
2022-05-23 04:54:00 +00:00
|
|
|
preCommitSector = append(preCommitSector, info)
|
|
|
|
return err
|
|
|
|
})
|
|
|
|
less := func(i, j int) bool {
|
|
|
|
return preCommitSector[i].Info.SectorNumber <= preCommitSector[j].Info.SectorNumber
|
|
|
|
}
|
|
|
|
sort.Slice(preCommitSector, less)
|
|
|
|
for _, info := range preCommitSector {
|
|
|
|
fmt.Printf("%s: %s\n", info.Info.SectorNumber, info.PreCommitEpoch)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|