Skip to content

Commit

Permalink
feat: support eth_maxPriorityFeePerGas query
Browse files Browse the repository at this point in the history
  • Loading branch information
ptrus committed Nov 20, 2024
1 parent fe4de7b commit eca135b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
9 changes: 9 additions & 0 deletions rpc/eth/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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")
Expand Down
9 changes: 9 additions & 0 deletions rpc/eth/metrics/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
9 changes: 9 additions & 0 deletions tests/rpc/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit eca135b

Please sign in to comment.