diff --git a/monitor/app/app.go b/monitor/app/app.go index 3218c6f0f..4c79a59ef 100644 --- a/monitor/app/app.go +++ b/monitor/app/app.go @@ -104,6 +104,7 @@ func Run(ctx context.Context, cfg Config) error { go routerecon.ReconForever(ctx, network, xprov, ethClients) go validator.MonitorForever(ctx, cprov) go monitorPublicRPCForever(ctx, network, ethClients) + go monitorOmniEVMGasTipForever(ctx, network, ethClients) select { case <-ctx.Done(): diff --git a/monitor/app/gastip.go b/monitor/app/gastip.go new file mode 100644 index 000000000..740f2f4d5 --- /dev/null +++ b/monitor/app/gastip.go @@ -0,0 +1,44 @@ +package monitor + +import ( + "context" + "math/big" + "time" + + "github.com/omni-network/omni/lib/ethclient" + "github.com/omni-network/omni/lib/log" + "github.com/omni-network/omni/lib/netconf" + + "github.com/ethereum/go-ethereum/params" +) + +// monitorOmniEVMGasTipForever monitors the suggested gas tip cap for the Omni EVM chain. +func monitorOmniEVMGasTipForever(ctx context.Context, + network netconf.Network, + ethClients map[uint64]ethclient.Client, +) { + ethCl, ok := ethClients[network.ID.Static().OmniExecutionChainID] + if !ok { + log.Error(ctx, "No eth client for omni chain", nil) + return + } + + ticker := time.NewTicker(time.Second * 30) + defer ticker.Stop() + + for { + select { + case <-ctx.Done(): + return + case <-ticker.C: + tip, err := ethCl.SuggestGasTipCap(ctx) + if err != nil { + log.Warn(ctx, "Failed to get gas tip (will retry)", err) + continue + } + + tipGwei := new(big.Int).Div(tip, big.NewInt(params.GWei)) + gasTipCap.Set(float64(tipGwei.Uint64())) + } + } +} diff --git a/monitor/app/metrics.go b/monitor/app/metrics.go index d673b7521..b8affd74f 100644 --- a/monitor/app/metrics.go +++ b/monitor/app/metrics.go @@ -43,4 +43,11 @@ var ( Name: "sync_diff", Help: "Sync difference (highest blocks) betweent public RPC and omni node", }) + + gasTipCap = promauto.NewGauge(prometheus.GaugeOpts{ + Namespace: "monitor", + Subsystem: "omni_evm", + Name: "gas_tip_cap_gwei", + Help: "Suggested OmniEVM gas tip cap in gwei", + }) )