diff --git a/cmd/lotus-miner/precommits-info.go b/cmd/lotus-miner/precommits-info.go new file mode 100644 index 00000000000..e700859e9b8 --- /dev/null +++ b/cmd/lotus-miner/precommits-info.go @@ -0,0 +1,54 @@ +package main + +import ( + "fmt" + "sort" + + "github.com/filecoin-project/lotus/blockstore" + "github.com/filecoin-project/lotus/chain/actors/builtin/miner" + "github.com/filecoin-project/lotus/chain/types" + lcli "github.com/filecoin-project/lotus/cli" + "github.com/filecoin-project/specs-actors/v7/actors/util/adt" + cbor "github.com/ipfs/go-ipld-cbor" + "github.com/urfave/cli/v2" +) + +var sectorPreCommitsCmd = &cli.Command{ + Name: "precommits", + Usage: "Print on-chain precommit info", + 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 + } + preCommitSector := make([]miner.SectorPreCommitOnChainInfo, 0) + err = mst.ForEachPrecommittedSector(func(info miner.SectorPreCommitOnChainInfo) error { + 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 + }, +} diff --git a/cmd/lotus-miner/sectors.go b/cmd/lotus-miner/sectors.go index 1aa964f7ec3..0e995752862 100644 --- a/cmd/lotus-miner/sectors.go +++ b/cmd/lotus-miner/sectors.go @@ -45,6 +45,7 @@ var sectorsCmd = &cli.Command{ sectorsRefsCmd, sectorsUpdateCmd, sectorsPledgeCmd, + sectorPreCommitsCmd, sectorsCheckExpireCmd, sectorsExpiredCmd, sectorsRenewCmd, diff --git a/documentation/en/cli-lotus-miner.md b/documentation/en/cli-lotus-miner.md index e03ae7cc131..78f11e82221 100644 --- a/documentation/en/cli-lotus-miner.md +++ b/documentation/en/cli-lotus-miner.md @@ -1667,6 +1667,7 @@ COMMANDS: refs List References to sectors update-state ADVANCED: manually update the state of a sector, this may aid in error recovery pledge store random data in a sector + precommits Print on-chain precommit info check-expire Inspect expiring sectors expired Get or cleanup expired sectors renew Renew expiring sectors while not exceeding each sector's max life @@ -1765,6 +1766,19 @@ OPTIONS: ``` +### lotus-miner sectors precommits +``` +NAME: + lotus-miner sectors precommits - Print on-chain precommit info + +USAGE: + lotus-miner sectors precommits [command options] [arguments...] + +OPTIONS: + --help, -h show help (default: false) + +``` + ### lotus-miner sectors check-expire ``` NAME: