Skip to content

Commit

Permalink
Add evm rpc endpoint eth_maxPriorityFeePerGas (sei-protocol#1693)
Browse files Browse the repository at this point in the history
  • Loading branch information
yzang2019 authored May 23, 2024
1 parent d12cdfc commit e949a96
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
14 changes: 14 additions & 0 deletions evmrpc/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,20 @@ func (i *InfoAPI) FeeHistory(ctx context.Context, blockCount math.HexOrDecimal64
return result, nil
}

func (i *InfoAPI) MaxPriorityFeePerGas(ctx context.Context) (*hexutil.Big, error) {
startTime := time.Now()
defer recordMetrics("eth_maxPriorityFeePerGas", i.connectionType, startTime, true)
feeHist, err := i.FeeHistory(ctx, 1, rpc.LatestBlockNumber, []float64{0.5})
if err != nil {
return nil, err
}
if len(feeHist.Reward) == 0 || len(feeHist.Reward[0]) == 0 {
// if there is no EVM tx in the most recent block, return 0
return (*hexutil.Big)(big.NewInt(0)), nil
}
return (*hexutil.Big)(feeHist.Reward[0][0].ToInt()), nil
}

func (i *InfoAPI) safeGetBaseFee(targetHeight int64) (res *big.Int) {
defer func() {
if err := recover(); err != nil {
Expand Down
8 changes: 8 additions & 0 deletions evmrpc/info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/go-bip39"
"github.com/sei-protocol/sei-chain/evmrpc"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -158,3 +159,10 @@ func TestCalculatePercentiles(t *testing.T) {
require.Equal(t, big.NewInt(3), result[1].ToInt())
require.Equal(t, big.NewInt(10), result[2].ToInt())
}

func TestMaxPriorityFeePerGas(t *testing.T) {
Ctx = Ctx.WithBlockHeight(1)
// Mimic request sending and handle the response
resObj := sendRequestGood(t, "maxPriorityFeePerGas")
assert.Equal(t, "0xa", resObj["result"])
}

0 comments on commit e949a96

Please sign in to comment.