From eca135b40e568c277f10efa581520b6caf3f5276 Mon Sep 17 00:00:00 2001 From: ptrus Date: Wed, 20 Nov 2024 10:09:24 +0100 Subject: [PATCH] feat: support eth_maxPriorityFeePerGas query --- rpc/eth/api.go | 9 +++++++++ rpc/eth/metrics/api.go | 9 +++++++++ tests/rpc/rpc_test.go | 9 +++++++++ 3 files changed, 27 insertions(+) diff --git a/rpc/eth/api.go b/rpc/eth/api.go index 7abd0f00..e3144a4a 100644 --- a/rpc/eth/api.go +++ b/rpc/eth/api.go @@ -64,6 +64,8 @@ type API interface { ChainId() (*hexutil.Big, error) // GasPrice returns a suggestion for a gas price for legacy transactions. GasPrice(ctx context.Context) (*hexutil.Big, error) + // MaxPriorityFeePerGas returns a suggestion for a gas tip cap for dynamic fee transactions + MaxPriorityFeePerGas(ctx context.Context) (*hexutil.Big, error) // FeeHistory returns the transaction base fee per gas and effective priority fee per gas for the requested/supported block range. FeeHistory(ctx context.Context, blockCount math.HexOrDecimal64, lastBlock ethrpc.BlockNumber, rewardPercentiles []float64) (*gas.FeeHistoryResult, error) // GetBlockTransactionCountByHash returns the number of transactions in the block identified by hash. @@ -294,6 +296,13 @@ func (api *publicAPI) GasPrice(_ context.Context) (*hexutil.Big, error) { return api.gasPriceOracle.GasPrice(), nil } +func (api *publicAPI) MaxPriorityFeePerGas(_ context.Context) (*hexutil.Big, error) { + logger := api.Logger.With("method", "eth_maxPriorityFeePerGas") + logger.Debug("request") + + return api.gasPriceOracle.GasPrice(), nil +} + func (api *publicAPI) FeeHistory(_ context.Context, blockCount math.HexOrDecimal64, lastBlock ethrpc.BlockNumber, rewardPercentiles []float64) (*gas.FeeHistoryResult, error) { logger := api.Logger.With("method", "eth_feeHistory", "block_count", blockCount, "last_block", lastBlock, "reward_percentiles", rewardPercentiles) logger.Debug("request") diff --git a/rpc/eth/metrics/api.go b/rpc/eth/metrics/api.go index 508dc118..052aad26 100644 --- a/rpc/eth/metrics/api.go +++ b/rpc/eth/metrics/api.go @@ -148,6 +148,15 @@ func (m *metricsWrapper) GasPrice(ctx context.Context) (res *hexutil.Big, err er return } +// MaxPriorityFeePerGas implements eth.API. +func (m *metricsWrapper) MaxPriorityFeePerGas(ctx context.Context) (res *hexutil.Big, err error) { + r, s, f, i, d := metrics.GetAPIMethodMetrics("eth_maxPriorityFeePerGas") + defer metrics.InstrumentCaller(r, s, f, i, d, &err)() + + res, err = m.api.MaxPriorityFeePerGas(ctx) + return +} + // FeeHistory implements eth.API. func (m *metricsWrapper) FeeHistory(ctx context.Context, blockCount math.HexOrDecimal64, lastBlock ethrpc.BlockNumber, rewardPercentiles []float64) (res *gas.FeeHistoryResult, err error) { r, s, f, i, d := metrics.GetAPIMethodMetrics("eth_feeHistory") diff --git a/tests/rpc/rpc_test.go b/tests/rpc/rpc_test.go index a2d6170b..1b4bfc39 100644 --- a/tests/rpc/rpc_test.go +++ b/tests/rpc/rpc_test.go @@ -146,6 +146,15 @@ func TestEth_GasPrice(t *testing.T) { t.Logf("gas price: %v", price) } +func TestEth_MaxPriorityFeePerGas(t *testing.T) { + ec := localClient(t, false) + + price, err := ec.SuggestGasTipCap(context.Background()) + require.Nil(t, err, "get maxPriorityFeePerGas") + + t.Logf("max priority fee per gas: %v", price) +} + func TestEth_FeeHistory(t *testing.T) { ec := localClient(t, false)