diff --git a/CHANGELOG.md b/CHANGELOG.md index 2010004dd5..acb0d8676a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## Unreleased +* (rpc) [#963](https://github.com/crypto-org-chain/ethermint/pull/963) fix(rpc): align eth_feeHistory response with execution-apis spec. * (ante) [#948](https://github.com/crypto-org-chain/ethermint/pull/948) fix(ante): enforce eip-1559 cost balance check even if it is not checkTx. * (evm) [#948](https://github.com/crypto-org-chain/ethermint/pull/948) fix(evm): fix SetCodeTx nil pointer panics, missing AuthList in Copy. * (evm) [#951](https://github.com/crypto-org-chain/ethermint/pull/951) chore(evm): preallocate slices in AccessList conversion functions. diff --git a/rpc/backend/chain_info.go b/rpc/backend/chain_info.go index 96ba5193cb..9c16034bce 100644 --- a/rpc/backend/chain_info.go +++ b/rpc/backend/chain_info.go @@ -214,7 +214,16 @@ func (b *Backend) FeeHistory( } maxBlockCount := int64(b.cfg.JSONRPC.FeeHistoryCap) if blocks > maxBlockCount { - return nil, fmt.Errorf("FeeHistory user block count %d higher than %d", blocks, maxBlockCount) + blocks = maxBlockCount + } + if blocks == 0 { + return &rpctypes.FeeHistoryResult{ + OldestBlock: (*hexutil.Big)(new(big.Int)), + BaseFee: []*hexutil.Big{}, + GasUsedRatio: []float64{}, + BlobBaseFee: []*hexutil.Big{}, + BlobGasUsedRatio: []float64{}, + }, nil } if blockEnd < math.MaxInt64 && blockEnd+1 < blocks { blocks = blockEnd + 1 @@ -317,10 +326,19 @@ func (b *Backend) FeeHistory( } } + // EIP-4844 blob transactions are not supported; return zeros per spec. + thisBlobBaseFee := make([]*hexutil.Big, blocks+1) + for i := range thisBlobBaseFee { + thisBlobBaseFee[i] = (*hexutil.Big)(new(big.Int)) + } + thisBlobGasUsedRatio := make([]float64, blocks) + feeHistory := rpctypes.FeeHistoryResult{ - OldestBlock: oldestBlock, - BaseFee: thisBaseFee, - GasUsedRatio: thisGasUsedRatio, + OldestBlock: oldestBlock, + BaseFee: thisBaseFee, + GasUsedRatio: thisGasUsedRatio, + BlobBaseFee: thisBlobBaseFee, + BlobGasUsedRatio: thisBlobGasUsedRatio, } if calculateRewards { diff --git a/rpc/backend/chain_info_test.go b/rpc/backend/chain_info_test.go index 4eb01ce378..4a0e154a7d 100644 --- a/rpc/backend/chain_info_test.go +++ b/rpc/backend/chain_info_test.go @@ -347,7 +347,7 @@ func (suite *BackendTestSuite) TestFeeHistory() { nil, }, { - "fail - user block count higher than max block count ", + "pass - user block count higher than max block count is silently capped", func(validator sdk.AccAddress) { var header metadata.MD queryClient := suite.backend.queryClient.QueryClient.(*mocks.EVMQueryClient) @@ -356,9 +356,15 @@ func (suite *BackendTestSuite) TestFeeHistory() { }, 1, -1, + &rpc.FeeHistoryResult{ + OldestBlock: (*hexutil.Big)(new(big.Int)), + BaseFee: []*hexutil.Big{}, + GasUsedRatio: []float64{}, + BlobBaseFee: []*hexutil.Big{}, + BlobGasUsedRatio: []float64{}, + }, nil, - nil, - false, + true, nil, }, { @@ -433,10 +439,12 @@ func (suite *BackendTestSuite) TestFeeHistory() { 1, 1, &rpc.FeeHistoryResult{ - OldestBlock: (*hexutil.Big)(big.NewInt(1)), - BaseFee: []*hexutil.Big{(*hexutil.Big)(big.NewInt(0)), (*hexutil.Big)(new(big.Int).SetBits([]big.Word{}))}, - GasUsedRatio: []float64{0}, - Reward: [][]*hexutil.Big{{(*hexutil.Big)(big.NewInt(0)), (*hexutil.Big)(big.NewInt(0)), (*hexutil.Big)(big.NewInt(0)), (*hexutil.Big)(big.NewInt(0))}}, + OldestBlock: (*hexutil.Big)(big.NewInt(1)), + BaseFee: []*hexutil.Big{(*hexutil.Big)(big.NewInt(0)), (*hexutil.Big)(new(big.Int).SetBits([]big.Word{}))}, + GasUsedRatio: []float64{0}, + Reward: [][]*hexutil.Big{{(*hexutil.Big)(big.NewInt(0)), (*hexutil.Big)(big.NewInt(0)), (*hexutil.Big)(big.NewInt(0)), (*hexutil.Big)(big.NewInt(0))}}, + BlobBaseFee: []*hexutil.Big{(*hexutil.Big)(new(big.Int)), (*hexutil.Big)(new(big.Int))}, + BlobGasUsedRatio: []float64{0}, }, sdk.AccAddress(tests.GenerateAddress().Bytes()), true, @@ -463,10 +471,12 @@ func (suite *BackendTestSuite) TestFeeHistory() { 1, 1, &rpc.FeeHistoryResult{ - OldestBlock: (*hexutil.Big)(big.NewInt(1)), - BaseFee: []*hexutil.Big{(*hexutil.Big)(big.NewInt(1)), (*hexutil.Big)(big.NewInt(1))}, - GasUsedRatio: []float64{0}, - Reward: [][]*hexutil.Big{{(*hexutil.Big)(big.NewInt(0)), (*hexutil.Big)(big.NewInt(0)), (*hexutil.Big)(big.NewInt(0)), (*hexutil.Big)(big.NewInt(0))}}, + OldestBlock: (*hexutil.Big)(big.NewInt(1)), + BaseFee: []*hexutil.Big{(*hexutil.Big)(big.NewInt(1)), (*hexutil.Big)(big.NewInt(1))}, + GasUsedRatio: []float64{0}, + Reward: [][]*hexutil.Big{{(*hexutil.Big)(big.NewInt(0)), (*hexutil.Big)(big.NewInt(0)), (*hexutil.Big)(big.NewInt(0)), (*hexutil.Big)(big.NewInt(0))}}, + BlobBaseFee: []*hexutil.Big{(*hexutil.Big)(new(big.Int)), (*hexutil.Big)(new(big.Int))}, + BlobGasUsedRatio: []float64{0}, }, sdk.AccAddress(tests.GenerateAddress().Bytes()), true, @@ -493,10 +503,12 @@ func (suite *BackendTestSuite) TestFeeHistory() { 1, 1, &rpc.FeeHistoryResult{ - OldestBlock: (*hexutil.Big)(big.NewInt(1)), - BaseFee: []*hexutil.Big{(*hexutil.Big)(big.NewInt(1)), (*hexutil.Big)(big.NewInt(0))}, - GasUsedRatio: []float64{0}, - Reward: [][]*hexutil.Big{{(*hexutil.Big)(big.NewInt(0)), (*hexutil.Big)(big.NewInt(0)), (*hexutil.Big)(big.NewInt(0)), (*hexutil.Big)(big.NewInt(0))}}, + OldestBlock: (*hexutil.Big)(big.NewInt(1)), + BaseFee: []*hexutil.Big{(*hexutil.Big)(big.NewInt(1)), (*hexutil.Big)(big.NewInt(0))}, + GasUsedRatio: []float64{0}, + Reward: [][]*hexutil.Big{{(*hexutil.Big)(big.NewInt(0)), (*hexutil.Big)(big.NewInt(0)), (*hexutil.Big)(big.NewInt(0)), (*hexutil.Big)(big.NewInt(0))}}, + BlobBaseFee: []*hexutil.Big{(*hexutil.Big)(new(big.Int)), (*hexutil.Big)(new(big.Int))}, + BlobGasUsedRatio: []float64{0}, }, sdk.AccAddress(tests.GenerateAddress().Bytes()), true, diff --git a/rpc/types/types.go b/rpc/types/types.go index 305a662777..2973382f36 100644 --- a/rpc/types/types.go +++ b/rpc/types/types.go @@ -173,10 +173,12 @@ type OverrideAccount struct { } type FeeHistoryResult struct { - OldestBlock *hexutil.Big `json:"oldestBlock"` - Reward [][]*hexutil.Big `json:"reward,omitempty"` - BaseFee []*hexutil.Big `json:"baseFeePerGas,omitempty"` - GasUsedRatio []float64 `json:"gasUsedRatio"` + OldestBlock *hexutil.Big `json:"oldestBlock"` + Reward [][]*hexutil.Big `json:"reward,omitempty"` + BaseFee []*hexutil.Big `json:"baseFeePerGas,omitempty"` + GasUsedRatio []float64 `json:"gasUsedRatio"` + BlobBaseFee []*hexutil.Big `json:"baseFeePerBlobGas,omitempty"` + BlobGasUsedRatio []float64 `json:"blobGasUsedRatio"` } // SignTransactionResult represents a RLP encoded signed transaction.