Add stats for base fee
Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
This commit is contained in:
parent
0162a485d8
commit
4be8964062
69
cli/mpool.go
69
cli/mpool.go
@ -164,14 +164,6 @@ var mpoolSub = &cli.Command{
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
type statBucket struct {
|
|
||||||
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",
|
||||||
Usage: "print mempool stats",
|
Usage: "print mempool stats",
|
||||||
@ -180,6 +172,11 @@ var mpoolStat = &cli.Command{
|
|||||||
Name: "local",
|
Name: "local",
|
||||||
Usage: "print stats for addresses in local wallet only",
|
Usage: "print stats for addresses in local wallet only",
|
||||||
},
|
},
|
||||||
|
&cli.IntFlag{
|
||||||
|
Name: "basefee-lookback",
|
||||||
|
Usage: "number of blocks to look back for minimum basefee",
|
||||||
|
Value: 60,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Action: func(cctx *cli.Context) error {
|
Action: func(cctx *cli.Context) error {
|
||||||
api, closer, err := GetFullNodeAPI(cctx)
|
api, closer, err := GetFullNodeAPI(cctx)
|
||||||
@ -194,6 +191,20 @@ var mpoolStat = &cli.Command{
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return xerrors.Errorf("getting chain head: %w", err)
|
return xerrors.Errorf("getting chain head: %w", err)
|
||||||
}
|
}
|
||||||
|
currBF := ts.Blocks()[0].ParentBaseFee
|
||||||
|
minBF := currBF
|
||||||
|
{
|
||||||
|
currTs := ts
|
||||||
|
for i := 0; i < cctx.Int("basefee-lookback"); i++ {
|
||||||
|
currTs, err = api.ChainGetTipSet(ctx, currTs.Parents())
|
||||||
|
if err != nil {
|
||||||
|
return xerrors.Errorf("walking chain: %w", err)
|
||||||
|
}
|
||||||
|
if newBF := currTs.Blocks()[0].ParentBaseFee; newBF.LessThan(minBF) {
|
||||||
|
minBF = newBF
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var filter map[address.Address]struct{}
|
var filter map[address.Address]struct{}
|
||||||
if cctx.Bool("local") {
|
if cctx.Bool("local") {
|
||||||
@ -214,8 +225,16 @@ var mpoolStat = &cli.Command{
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
buckets := map[address.Address]*statBucket{}
|
type statBucket struct {
|
||||||
|
msgs map[uint64]*types.SignedMessage
|
||||||
|
}
|
||||||
|
type mpStat struct {
|
||||||
|
addr string
|
||||||
|
past, cur, future uint64
|
||||||
|
belowCurr, belowPast uint64
|
||||||
|
}
|
||||||
|
|
||||||
|
buckets := map[address.Address]*statBucket{}
|
||||||
for _, v := range msgs {
|
for _, v := range msgs {
|
||||||
if filter != nil {
|
if filter != nil {
|
||||||
if _, has := filter[v.Message.From]; !has {
|
if _, has := filter[v.Message.From]; !has {
|
||||||
@ -252,23 +271,27 @@ var mpoolStat = &cli.Command{
|
|||||||
cur++
|
cur++
|
||||||
}
|
}
|
||||||
|
|
||||||
past := uint64(0)
|
var s mpStat
|
||||||
future := uint64(0)
|
s.addr = a.String()
|
||||||
|
|
||||||
for _, m := range bkt.msgs {
|
for _, m := range bkt.msgs {
|
||||||
if m.Message.Nonce < act.Nonce {
|
if m.Message.Nonce < act.Nonce {
|
||||||
past++
|
s.past++
|
||||||
|
} else if m.Message.Nonce > cur {
|
||||||
|
s.future++
|
||||||
|
} else {
|
||||||
|
s.cur++
|
||||||
}
|
}
|
||||||
if m.Message.Nonce > cur {
|
|
||||||
future++
|
if m.Message.GasFeeCap.LessThan(currBF) {
|
||||||
|
s.belowCurr++
|
||||||
|
}
|
||||||
|
if m.Message.GasFeeCap.LessThan(minBF) {
|
||||||
|
s.belowPast++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
out = append(out, mpStat{
|
out = append(out, s)
|
||||||
addr: a.String(),
|
|
||||||
past: past,
|
|
||||||
cur: cur - act.Nonce,
|
|
||||||
future: future,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sort.Slice(out, func(i, j int) bool {
|
sort.Slice(out, func(i, j int) bool {
|
||||||
@ -281,12 +304,14 @@ var mpoolStat = &cli.Command{
|
|||||||
total.past += stat.past
|
total.past += stat.past
|
||||||
total.cur += stat.cur
|
total.cur += stat.cur
|
||||||
total.future += stat.future
|
total.future += stat.future
|
||||||
|
total.belowCurr += stat.belowCurr
|
||||||
|
total.belowPast += stat.belowPast
|
||||||
|
|
||||||
fmt.Printf("%s: past: %d, cur: %d, future: %d\n", stat.addr, stat.past, stat.cur, stat.future)
|
fmt.Printf("%s: Nonce past: %d, cur: %d, future: %d; FeeCap cur: %d, min-%d: %d \n", stat.addr, stat.past, stat.cur, stat.future, stat.belowCurr, cctx.Int("basefee-lookback"), stat.belowPast)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("-----")
|
fmt.Println("-----")
|
||||||
fmt.Printf("total: past: %d, cur: %d, future: %d\n", total.past, total.cur, total.future)
|
fmt.Printf("total: Nonce past: %d, cur: %d, future: %d; FeeCap cur: %d, min-%d: %d \n", total.past, total.cur, total.future, total.belowCurr, cctx.Int("basefee-lookback"), total.belowPast)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user