2019-12-13 14:47:21 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2020-03-10 00:26:10 +00:00
|
|
|
"fmt"
|
|
|
|
"math"
|
|
|
|
|
2022-06-14 15:00:51 +00:00
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
|
2019-12-19 20:13:17 +00:00
|
|
|
"github.com/filecoin-project/go-address"
|
2020-10-07 01:07:34 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
|
|
|
"github.com/filecoin-project/go-state-types/big"
|
2023-11-14 00:06:11 +00:00
|
|
|
|
2019-12-13 14:47:21 +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{
|
2023-02-15 16:09:24 +00:00
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "repo",
|
|
|
|
EnvVars: []string{"LOTUS_PATH"},
|
|
|
|
Hidden: true,
|
|
|
|
Value: "~/.lotus", // TODO: Consider XDG_DATA_HOME
|
|
|
|
},
|
2019-12-13 14:47:21 +00:00
|
|
|
&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
|
|
|
},
|
2020-10-07 01:07:34 +00:00
|
|
|
&cli.Int64Flag{
|
|
|
|
Name: "gas-fee-cap",
|
|
|
|
Usage: "specify gas fee cap for nonce filling messages",
|
|
|
|
},
|
2019-12-13 14:47:21 +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
|
|
|
|
2020-10-07 01:07:34 +00:00
|
|
|
ts, err := api.ChainHead(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
feeCap := big.Mul(ts.Blocks()[0].ParentBaseFee, big.NewInt(2)) // default fee cap to 2 * parent base fee
|
|
|
|
if fcf := cctx.Int64("gas-fee-cap"); fcf != 0 {
|
|
|
|
feeCap = abi.NewTokenAmount(fcf)
|
|
|
|
}
|
|
|
|
|
2020-03-10 00:26:10 +00:00
|
|
|
for i := start; i < end; i++ {
|
2019-12-13 14:47:21 +00:00
|
|
|
msg := &types.Message{
|
2020-10-07 01:07:34 +00:00
|
|
|
From: addr,
|
|
|
|
To: addr,
|
|
|
|
Value: types.NewInt(0),
|
|
|
|
Nonce: i,
|
|
|
|
GasLimit: 1000000,
|
|
|
|
GasFeeCap: feeCap,
|
|
|
|
GasPremium: abi.NewTokenAmount(5),
|
|
|
|
}
|
|
|
|
smsg, err := api.WalletSignMessage(ctx, addr, msg)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2019-12-13 14:47:21 +00:00
|
|
|
}
|
|
|
|
|
2020-10-07 01:07:34 +00:00
|
|
|
_, err = api.MpoolPush(ctx, smsg)
|
2019-12-13 14:47:21 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|