lotus/cmd/lotus-shed/nonce-fix.go

104 lines
1.8 KiB
Go
Raw Normal View History

package main
import (
2020-03-10 00:26:10 +00:00
"fmt"
"math"
"github.com/filecoin-project/go-address"
"github.com/urfave/cli/v2"
2020-03-10 00:26:10 +00:00
"github.com/filecoin-project/lotus/chain/types"
lcli "github.com/filecoin-project/lotus/cli"
)
var noncefix = &cli.Command{
Name: "noncefix",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "repo",
EnvVars: []string{"LOTUS_PATH"},
Hidden: true,
Value: "~/.lotus", // TODO: Consider XDG_DATA_HOME
},
&cli.Uint64Flag{
Name: "start",
},
&cli.Uint64Flag{
Name: "end",
},
&cli.StringFlag{
Name: "addr",
},
2020-03-10 00:26:10 +00:00
&cli.BoolFlag{
2020-03-10 00:28:31 +00:00
Name: "auto",
2020-03-10 00:26:10 +00:00
},
},
Action: func(cctx *cli.Context) error {
api, closer, err := lcli.GetFullNodeAPI(cctx)
if err != nil {
return err
}
defer closer()
ctx := lcli.ReqContext(cctx)
addr, err := address.NewFromString(cctx.String("addr"))
if err != nil {
return err
}
2020-03-10 00:26:10 +00:00
start := cctx.Uint64("start")
end := cctx.Uint64("end")
if end == 0 {
end = math.MaxUint64
}
if cctx.Bool("auto") {
a, err := api.StateGetActor(ctx, addr, types.EmptyTSK)
if err != nil {
return err
}
2020-03-10 00:28:31 +00:00
start = a.Nonce
2020-03-10 00:26:10 +00:00
msgs, err := api.MpoolPending(ctx, types.EmptyTSK)
if err != nil {
return err
}
for _, msg := range msgs {
if msg.Message.From != addr {
continue
}
if msg.Message.Nonce < start {
continue // past
}
if msg.Message.Nonce < end {
end = msg.Message.Nonce
}
}
2020-03-10 01:11:07 +00:00
}
if end == math.MaxUint64 {
fmt.Println("No nonce gap found or no --end flag specified")
return nil
2020-03-10 00:26:10 +00:00
}
2020-03-10 00:28:31 +00:00
fmt.Printf("Creating %d filler messages (%d ~ %d)\n", end-start, start, end)
2020-03-10 00:26:10 +00:00
for i := start; i < end; i++ {
msg := &types.Message{
From: addr,
To: addr,
Value: types.NewInt(1),
Nonce: i,
}
2020-10-06 23:46:47 +00:00
_, err = api.MpoolPushMessage(ctx, msg, nil)
if err != nil {
return err
}
}
return nil
},
}