state replay: find correct tipset

This commit is contained in:
Łukasz Magiera 2020-02-22 14:31:13 +01:00
parent b8428423a1
commit 03b8ab724a

View File

@ -218,8 +218,8 @@ var stateReplaySetCmd = &cli.Command{
Name: "replay",
Usage: "Replay a particular message within a tipset",
Action: func(cctx *cli.Context) error {
if cctx.Args().Len() < 2 {
fmt.Println("usage: <tipset> <message cid>")
if cctx.Args().Len() < 1 {
fmt.Println("usage: [tipset] <message cid>")
fmt.Println("The last cid passed will be used as the message CID")
fmt.Println("All preceding ones will be used as the tipset")
return nil
@ -231,6 +231,16 @@ var stateReplaySetCmd = &cli.Command{
return fmt.Errorf("message cid was invalid: %s", err)
}
api, closer, err := GetFullNodeAPI(cctx)
if err != nil {
return err
}
defer closer()
ctx := ReqContext(cctx)
var ts *types.TipSet
{
var tscids []cid.Cid
for _, s := range args[:len(args)-1] {
c, err := cid.Decode(s)
@ -240,14 +250,7 @@ var stateReplaySetCmd = &cli.Command{
tscids = append(tscids, c)
}
api, closer, err := GetFullNodeAPI(cctx)
if err != nil {
return err
}
defer closer()
ctx := ReqContext(cctx)
if len(tscids) > 0 {
var headers []*types.BlockHeader
for _, c := range tscids {
h, err := api.ChainGetBlock(ctx, c)
@ -258,11 +261,23 @@ var stateReplaySetCmd = &cli.Command{
headers = append(headers, h)
}
ts, err := types.NewTipSet(headers)
ts, err = types.NewTipSet(headers)
} else {
r, err := api.StateWaitMsg(ctx, mcid)
if err != nil {
return xerrors.Errorf("finding message in chain: %w", err)
}
ts, err = api.ChainGetTipSet(ctx, r.TipSet.Parents())
}
if err != nil {
return err
}
}
res, err := api.StateReplay(ctx, ts, mcid)
if err != nil {
return xerrors.Errorf("replay call failed: %w", err)