From ea282ea0558aaf57d1524d15e114307405596fc0 Mon Sep 17 00:00:00 2001 From: swift-mx Date: Mon, 23 May 2022 12:54:00 +0800 Subject: [PATCH 1/5] feat: precommits info --- cmd/lotus-miner/precommits-info.go | 54 ++++++++++++++++++++++++++++++ cmd/lotus-miner/sectors.go | 1 + 2 files changed, 55 insertions(+) create mode 100644 cmd/lotus-miner/precommits-info.go diff --git a/cmd/lotus-miner/precommits-info.go b/cmd/lotus-miner/precommits-info.go new file mode 100644 index 000000000..9416e6f58 --- /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-info", + Usage: "Print precommits 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 1aa964f7e..0e9957528 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, From 3ea55333a8d2a020bd9ef80d61953600a99c8d49 Mon Sep 17 00:00:00 2001 From: swift-mx Date: Mon, 23 May 2022 14:28:47 +0800 Subject: [PATCH 2/5] fix: docsgen-cli --- documentation/en/cli-lotus-miner.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/documentation/en/cli-lotus-miner.md b/documentation/en/cli-lotus-miner.md index e03ae7cc1..d6f37861d 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-info Print precommits 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-info +``` +NAME: + lotus-miner sectors precommits-info - Print precommits info + +USAGE: + lotus-miner sectors precommits-info [command options] [arguments...] + +OPTIONS: + --help, -h show help (default: false) + +``` + ### lotus-miner sectors check-expire ``` NAME: From 0b3ee32ce48ff981f4ed0204ef9bce2e8909cb38 Mon Sep 17 00:00:00 2001 From: swift-mx Date: Tue, 24 May 2022 00:11:59 +0800 Subject: [PATCH 3/5] Update cmd/lotus-miner/precommits-info.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Łukasz Magiera --- cmd/lotus-miner/precommits-info.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/lotus-miner/precommits-info.go b/cmd/lotus-miner/precommits-info.go index 9416e6f58..23616e895 100644 --- a/cmd/lotus-miner/precommits-info.go +++ b/cmd/lotus-miner/precommits-info.go @@ -14,7 +14,7 @@ import ( ) var sectorPreCommitsCmd = &cli.Command{ - Name: "precommits-info", + Name: "precommits", Usage: "Print precommits info", Action: func(cctx *cli.Context) error { ctx := lcli.ReqContext(cctx) From ae8f3d8fe2a7107b8213f01228f2057b580ed2b0 Mon Sep 17 00:00:00 2001 From: swift-mx Date: Tue, 24 May 2022 00:12:09 +0800 Subject: [PATCH 4/5] Update cmd/lotus-miner/precommits-info.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Łukasz Magiera --- cmd/lotus-miner/precommits-info.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/lotus-miner/precommits-info.go b/cmd/lotus-miner/precommits-info.go index 23616e895..e700859e9 100644 --- a/cmd/lotus-miner/precommits-info.go +++ b/cmd/lotus-miner/precommits-info.go @@ -15,7 +15,7 @@ import ( var sectorPreCommitsCmd = &cli.Command{ Name: "precommits", - Usage: "Print precommits info", + Usage: "Print on-chain precommit info", Action: func(cctx *cli.Context) error { ctx := lcli.ReqContext(cctx) mapi, closer, err := lcli.GetFullNodeAPI(cctx) From 23f9ac4c3c1b3c06a410b42a3e0cecf70ef3351f Mon Sep 17 00:00:00 2001 From: swift-mx Date: Tue, 24 May 2022 00:17:38 +0800 Subject: [PATCH 5/5] Update cli-lotus-miner.md --- documentation/en/cli-lotus-miner.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/documentation/en/cli-lotus-miner.md b/documentation/en/cli-lotus-miner.md index d6f37861d..78f11e822 100644 --- a/documentation/en/cli-lotus-miner.md +++ b/documentation/en/cli-lotus-miner.md @@ -1667,7 +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-info Print precommits info + 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 @@ -1766,13 +1766,13 @@ OPTIONS: ``` -### lotus-miner sectors precommits-info +### lotus-miner sectors precommits ``` NAME: - lotus-miner sectors precommits-info - Print precommits info + lotus-miner sectors precommits - Print on-chain precommit info USAGE: - lotus-miner sectors precommits-info [command options] [arguments...] + lotus-miner sectors precommits [command options] [arguments...] OPTIONS: --help, -h show help (default: false)