Shed: Add a util to find the most recent null tipset

This commit is contained in:
Aayush Rajasekaran 2021-10-06 19:11:14 -04:00
parent 26ae8bb3a7
commit 89db4235ce
2 changed files with 50 additions and 0 deletions

49
cmd/lotus-shed/chain.go Normal file
View File

@ -0,0 +1,49 @@
package main
import (
"fmt"
lcli "github.com/filecoin-project/lotus/cli"
"github.com/urfave/cli/v2"
)
var chainCmd = &cli.Command{
Name: "chain",
Usage: "chain-related utilities",
Subcommands: []*cli.Command{
chainNullTsCmd,
},
}
var chainNullTsCmd = &cli.Command{
Name: "latest-null",
Usage: "finds the most recent null tipset",
Action: func(cctx *cli.Context) error {
api, closer, err := lcli.GetFullNodeAPI(cctx)
if err != nil {
return err
}
defer closer()
ctx := lcli.ReqContext(cctx)
ts, err := lcli.LoadTipSet(ctx, cctx, api)
if err != nil {
return err
}
for {
pts, err := api.ChainGetTipSet(ctx, ts.Parents())
if err != nil {
return err
}
if ts.Height() != pts.Height()+1 {
fmt.Println("null tipset at height ", ts.Height()-1)
return nil
}
ts = pts
}
},
}

View File

@ -62,6 +62,7 @@ func main() {
minerMultisigsCmd,
splitstoreCmd,
fr32Cmd,
chainCmd,
}
app := &cli.App{