internal/ethapi: add eth_baseFee RPC method (#34904)
Some checks are pending
/ Linux Build (push) Waiting to run
/ Linux Build (arm) (push) Waiting to run
/ Keeper Build (push) Waiting to run
/ Windows Build (push) Waiting to run
/ Docker Image (push) Waiting to run

This method is similar to `eth_blobBaseFee` but returns the next base
fee.
This commit is contained in:
William Morriss 2026-05-19 01:05:00 -05:00 committed by GitHub
parent 3d1e6aa6c3
commit 1149f76dca
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 16 additions and 0 deletions

View file

@ -26,6 +26,7 @@ import (
"github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/consensus" "github.com/ethereum/go-ethereum/consensus"
"github.com/ethereum/go-ethereum/consensus/misc/eip1559"
"github.com/ethereum/go-ethereum/consensus/misc/eip4844" "github.com/ethereum/go-ethereum/consensus/misc/eip4844"
"github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/filtermaps" "github.com/ethereum/go-ethereum/core/filtermaps"
@ -430,6 +431,13 @@ func (b *EthAPIBackend) FeeHistory(ctx context.Context, blockCount uint64, lastB
return b.gpo.FeeHistory(ctx, blockCount, lastBlock, rewardPercentiles) return b.gpo.FeeHistory(ctx, blockCount, lastBlock, rewardPercentiles)
} }
func (b *EthAPIBackend) BaseFee(ctx context.Context) *big.Int {
if b.ChainConfig().IsLondon(b.CurrentHeader().Number) {
return eip1559.CalcBaseFee(b.ChainConfig(), b.CurrentHeader())
}
return nil
}
func (b *EthAPIBackend) BlobBaseFee(ctx context.Context) *big.Int { func (b *EthAPIBackend) BlobBaseFee(ctx context.Context) *big.Int {
if excess := b.CurrentHeader().ExcessBlobGas; excess != nil { if excess := b.CurrentHeader().ExcessBlobGas; excess != nil {
return eip4844.CalcBlobFee(b.ChainConfig(), b.CurrentHeader()) return eip4844.CalcBlobFee(b.ChainConfig(), b.CurrentHeader())

View file

@ -146,6 +146,11 @@ func (api *EthereumAPI) BlobBaseFee(ctx context.Context) *hexutil.Big {
return (*hexutil.Big)(api.b.BlobBaseFee(ctx)) return (*hexutil.Big)(api.b.BlobBaseFee(ctx))
} }
// BaseFee returns the base fee for the next block.
func (api *EthereumAPI) BaseFee(ctx context.Context) *hexutil.Big {
return (*hexutil.Big)(api.b.BaseFee(ctx))
}
// Syncing returns false in case the node is currently not syncing with the network. It can be up-to-date or has not // Syncing returns false in case the node is currently not syncing with the network. It can be up-to-date or has not
// yet received the latest block headers from its peers. In case it is synchronizing: // yet received the latest block headers from its peers. In case it is synchronizing:
// - startingBlock: block number this node started to synchronize from // - startingBlock: block number this node started to synchronize from

View file

@ -500,6 +500,7 @@ func (b testBackend) FeeHistory(ctx context.Context, blockCount uint64, lastBloc
return nil, nil, nil, nil, nil, nil, nil return nil, nil, nil, nil, nil, nil, nil
} }
func (b testBackend) BlobBaseFee(ctx context.Context) *big.Int { return new(big.Int) } func (b testBackend) BlobBaseFee(ctx context.Context) *big.Int { return new(big.Int) }
func (b testBackend) BaseFee(ctx context.Context) *big.Int { return new(big.Int) }
func (b testBackend) ChainDb() ethdb.Database { return b.db } func (b testBackend) ChainDb() ethdb.Database { return b.db }
func (b testBackend) AccountManager() *accounts.Manager { return b.accman } func (b testBackend) AccountManager() *accounts.Manager { return b.accman }
func (b testBackend) ExtRPCEnabled() bool { return false } func (b testBackend) ExtRPCEnabled() bool { return false }

View file

@ -46,6 +46,7 @@ type Backend interface {
SuggestGasTipCap(ctx context.Context) (*big.Int, error) SuggestGasTipCap(ctx context.Context) (*big.Int, error)
FeeHistory(ctx context.Context, blockCount uint64, lastBlock rpc.BlockNumber, rewardPercentiles []float64) (*big.Int, [][]*big.Int, []*big.Int, []float64, []*big.Int, []float64, error) FeeHistory(ctx context.Context, blockCount uint64, lastBlock rpc.BlockNumber, rewardPercentiles []float64) (*big.Int, [][]*big.Int, []*big.Int, []float64, []*big.Int, []float64, error)
BlobBaseFee(ctx context.Context) *big.Int BlobBaseFee(ctx context.Context) *big.Int
BaseFee(ctx context.Context) *big.Int
ChainDb() ethdb.Database ChainDb() ethdb.Database
AccountManager() *accounts.Manager AccountManager() *accounts.Manager
ExtRPCEnabled() bool ExtRPCEnabled() bool

View file

@ -318,6 +318,7 @@ func (b *backendMock) SuggestGasTipCap(ctx context.Context) (*big.Int, error) {
return big.NewInt(42), nil return big.NewInt(42), nil
} }
func (b *backendMock) BlobBaseFee(ctx context.Context) *big.Int { return big.NewInt(42) } func (b *backendMock) BlobBaseFee(ctx context.Context) *big.Int { return big.NewInt(42) }
func (b *backendMock) BaseFee(ctx context.Context) *big.Int { return big.NewInt(42) }
func (b *backendMock) CurrentHeader() *types.Header { return b.current } func (b *backendMock) CurrentHeader() *types.Header { return b.current }
func (b *backendMock) ChainConfig() *params.ChainConfig { return b.config } func (b *backendMock) ChainConfig() *params.ChainConfig { return b.config }