Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: lotus-shed: add command to compute state over a range of tipsets. #8371

Merged
merged 1 commit into from
Mar 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 60 additions & 1 deletion cmd/lotus-shed/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ package main
import (
"fmt"

lcli "github.com/filecoin-project/lotus/cli"
"github.com/urfave/cli/v2"

lcli "github.com/filecoin-project/lotus/cli"
)

var chainCmd = &cli.Command{
Name: "chain",
Usage: "chain-related utilities",
Subcommands: []*cli.Command{
chainNullTsCmd,
computeStateRangeCmd,
},
}

Expand Down Expand Up @@ -47,3 +49,60 @@ var chainNullTsCmd = &cli.Command{
}
},
}

var computeStateRangeCmd = &cli.Command{
Name: "compute-state-range",
Usage: "forces the computation of a range of tipsets",
ArgsUsage: "[START_TIPSET_REF] [END_TIPSET_REF]",
Action: func(cctx *cli.Context) error {
if cctx.NArg() != 2 {
return fmt.Errorf("expected two arguments: a start and an end tipset")
}

api, closer, err := lcli.GetFullNodeAPI(cctx)
if err != nil {
return err
}

defer closer()
ctx := lcli.ReqContext(cctx)

startTs, err := lcli.ParseTipSetRef(ctx, api, cctx.Args().First())
if err != nil {
return err
}

endTs, err := lcli.ParseTipSetRef(ctx, api, cctx.Args().Get(1))
if err != nil {
return err
}

fmt.Printf("computing tipset at height %d (start)\n", startTs.Height())
if _, err := api.StateCompute(ctx, startTs.Height(), nil, startTs.Key()); err != nil {
return err
}

for height := startTs.Height() + 1; height < endTs.Height(); height++ {
fmt.Printf("computing tipset at height %d\n", height)

// The fact that the tipset lookup method takes a tipset is rather annoying.
// This is because we walk back from the supplied tipset (which could be the HEAD)
// to locate the desired one.
ts, err := api.ChainGetTipSetByHeight(ctx, height, endTs.Key())
if err != nil {
return err
}

if _, err := api.StateCompute(ctx, height, nil, ts.Key()); err != nil {
return err
}
}

fmt.Printf("computing tipset at height %d (end)\n", endTs.Height())
if _, err := api.StateCompute(ctx, endTs.Height(), nil, endTs.Key()); err != nil {
return err
}

return nil
},
}