add basic command for printing gas performance of messages in the mempool

This commit is contained in:
whyrusleeping 2020-09-09 11:23:48 -07:00
parent e2a6d02570
commit 7747f5a3fa

View File

@ -29,6 +29,7 @@ var mpoolCmd = &cli.Command{
mpoolReplaceCmd,
mpoolFindCmd,
mpoolConfig,
mpoolGasPerfCmd,
},
}
@ -516,3 +517,65 @@ var mpoolConfig = &cli.Command{
return nil
},
}
var mpoolGasPerfCmd = &cli.Command{
Name: "gas-perf",
Usage: "Check gas performance of messages in mempool",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "all",
Usage: "print gas performance for all mempool messages (default only prints for local)",
},
},
Action: func(cctx *cli.Context) error {
api, closer, err := GetFullNodeAPI(cctx)
if err != nil {
return err
}
defer closer()
ctx := ReqContext(cctx)
msgs, err := api.MpoolPending(ctx, types.EmptyTSK)
if err != nil {
return err
}
var filter map[address.Address]struct{}
if !cctx.Bool("all") {
filter = map[address.Address]struct{}{}
addrss, err := api.WalletList(ctx)
if err != nil {
return xerrors.Errorf("getting local addresses: %w", err)
}
for _, a := range addrss {
filter[a] = struct{}{}
}
var filtered []*types.SignedMessage
for _, msg := range msgs {
if _, has := filter[msg.Message.From]; !has {
continue
}
filtered = append(filtered, msg)
}
msgs = filtered
}
ts, err := api.ChainHead(ctx)
if err != nil {
return xerrors.Errorf("failed to get chain head: %w", err)
}
baseFee := ts.Blocks()[0].ParentBaseFee
for _, m := range msgs {
feeCapSlack := types.BigSub(m.Message.GasFeeCap, baseFee)
fmt.Printf("%s\t%d\t%s\n", m.Message.From, m.Message.Nonce, feeCapSlack)
}
return nil
},
}