Merge pull request #1376 from filecoin-project/feat/shed-ncfix-auto

shed: auto mode for nonce-fix
This commit is contained in:
Łukasz Magiera 2020-03-10 03:01:37 +01:00 committed by GitHub
commit dcd12bff7c
2 changed files with 71 additions and 5 deletions

View File

@ -3,11 +3,13 @@ package cli
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"sort"
"golang.org/x/xerrors" "golang.org/x/xerrors"
"gopkg.in/urfave/cli.v2" "gopkg.in/urfave/cli.v2"
"github.com/filecoin-project/go-address" "github.com/filecoin-project/go-address"
"github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/chain/types"
) )
@ -85,6 +87,10 @@ var mpoolSub = &cli.Command{
type statBucket struct { type statBucket struct {
msgs map[uint64]*types.SignedMessage msgs map[uint64]*types.SignedMessage
} }
type mpStat struct {
addr string
past, cur, future uint64
}
var mpoolStat = &cli.Command{ var mpoolStat = &cli.Command{
Name: "stat", Name: "stat",
@ -121,6 +127,9 @@ var mpoolStat = &cli.Command{
bkt.msgs[v.Message.Nonce] = v bkt.msgs[v.Message.Nonce] = v
} }
var out []mpStat
for a, bkt := range buckets { for a, bkt := range buckets {
act, err := api.StateGetActor(ctx, a, ts.Key()) act, err := api.StateGetActor(ctx, a, ts.Key())
if err != nil { if err != nil {
@ -137,8 +146,8 @@ var mpoolStat = &cli.Command{
cur++ cur++
} }
past := 0 past := uint64(0)
future := 0 future := uint64(0)
for _, m := range bkt.msgs { for _, m := range bkt.msgs {
if m.Message.Nonce < act.Nonce { if m.Message.Nonce < act.Nonce {
past++ past++
@ -148,7 +157,20 @@ var mpoolStat = &cli.Command{
} }
} }
fmt.Printf("%s, past: %d, cur: %d, future: %d\n", a, past, cur-act.Nonce, future) out = append(out, mpStat{
addr: a.String(),
past: past,
cur: cur - act.Nonce,
future: future,
})
}
sort.Slice(out, func(i, j int) bool {
return out[i].addr < out[j].addr
})
for _, stat := range out {
fmt.Printf("%s, past: %d, cur: %d, future: %d\n", stat.addr, stat.past, stat.cur, stat.future)
} }
return nil return nil

View File

@ -1,10 +1,14 @@
package main package main
import ( import (
"fmt"
"math"
"github.com/filecoin-project/go-address" "github.com/filecoin-project/go-address"
"gopkg.in/urfave/cli.v2"
"github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/chain/types"
lcli "github.com/filecoin-project/lotus/cli" lcli "github.com/filecoin-project/lotus/cli"
"gopkg.in/urfave/cli.v2"
) )
var noncefix = &cli.Command{ var noncefix = &cli.Command{
@ -25,6 +29,9 @@ var noncefix = &cli.Command{
&cli.StringFlag{ &cli.StringFlag{
Name: "addr", Name: "addr",
}, },
&cli.BoolFlag{
Name: "auto",
},
}, },
Action: func(cctx *cli.Context) error { Action: func(cctx *cli.Context) error {
api, closer, err := lcli.GetFullNodeAPI(cctx) api, closer, err := lcli.GetFullNodeAPI(cctx)
@ -40,7 +47,44 @@ var noncefix = &cli.Command{
return err return err
} }
for i := cctx.Uint64("start"); i < cctx.Uint64("end"); i++ { 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
}
start = a.Nonce
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
}
}
}
if end == math.MaxUint64 {
fmt.Println("No nonce gap found or no --end flag specified")
return nil
}
fmt.Printf("Creating %d filler messages (%d ~ %d)\n", end-start, start, end)
for i := start; i < end; i++ {
msg := &types.Message{ msg := &types.Message{
From: addr, From: addr,
To: addr, To: addr,