Skip to content

Commit

Permalink
internal/ethapi: implement eth_blobBaseFee
Browse files Browse the repository at this point in the history
  • Loading branch information
trantienduchn committed Dec 11, 2024
1 parent f230174 commit e9771ac
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 0 deletions.
8 changes: 8 additions & 0 deletions eth/api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"math/big"
"time"

"github.com/ethereum/go-ethereum/consensus/misc/eip4844"
"github.com/ethereum/go-ethereum/eth/tracers"

"github.com/ethereum/go-ethereum"
Expand Down Expand Up @@ -357,6 +358,13 @@ func (b *EthAPIBackend) FeeHistory(ctx context.Context, blockCount int, lastBloc
return b.gpo.FeeHistory(ctx, blockCount, lastBlock, rewardPercentiles)
}

func (b *EthAPIBackend) BlobBaseFee(ctx context.Context) *big.Int {
if excess := b.CurrentHeader().ExcessBlobGas; excess != nil {
return eip4844.CalcBlobFee(*excess)
}
return nil
}

func (b *EthAPIBackend) ChainDb() ethdb.Database {
return b.eth.ChainDb()
}
Expand Down
5 changes: 5 additions & 0 deletions internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ func (s *PublicEthereumAPI) FeeHistory(ctx context.Context, blockCount rpc.Decim
return results, nil
}

// BlobBaseFee returns the base fee for blob gas at the current head.
func (s *PublicEthereumAPI) BlobBaseFee(ctx context.Context) *hexutil.Big {
return (*hexutil.Big)(s.b.BlobBaseFee(ctx))
}

// 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 pears. In case it is synchronizing:
// - startingBlock: block number this node started to synchronise from
Expand Down
3 changes: 3 additions & 0 deletions internal/ethapi/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,9 @@ func (b testBackend) SuggestGasTipCap(ctx context.Context) (*big.Int, error) {
func (b testBackend) FeeHistory(ctx context.Context, blockCount int, lastBlock rpc.BlockNumber, rewardPercentiles []float64) (*big.Int, [][]*big.Int, []*big.Int, []float64, error) {
return nil, nil, nil, nil, nil
}
func (b testBackend) BlobBaseFee(ctx context.Context) *big.Int {
return new(big.Int)
}
func (b testBackend) ChainDb() ethdb.Database { return b.db }
func (b testBackend) AccountManager() *accounts.Manager { return b.accman }
func (b testBackend) ExtRPCEnabled() bool { return false }
Expand Down
1 change: 1 addition & 0 deletions internal/ethapi/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type Backend interface {

SuggestGasTipCap(ctx context.Context) (*big.Int, error)
FeeHistory(ctx context.Context, blockCount int, lastBlock rpc.BlockNumber, rewardPercentiles []float64) (*big.Int, [][]*big.Int, []*big.Int, []float64, error)
BlobBaseFee(ctx context.Context) *big.Int
ChainDb() ethdb.Database
AccountManager() *accounts.Manager
ExtRPCEnabled() bool
Expand Down
5 changes: 5 additions & 0 deletions internal/jsre/deps/web3.js
Original file line number Diff line number Diff line change
Expand Up @@ -5494,6 +5494,11 @@ var properties = function () {
getter: 'eth_gasPrice',
outputFormatter: formatters.outputBigNumberFormatter
}),
new Property({
name: 'blobBaseFee',
getter: 'eth_blobBaseFee',
outputFormatter: formatters.outputBigNumberFormatter
}),
new Property({
name: 'accounts',
getter: 'eth_accounts'
Expand Down
8 changes: 8 additions & 0 deletions les/api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"math/big"
"time"

"github.com/ethereum/go-ethereum/consensus/misc/eip4844"
"github.com/ethereum/go-ethereum/eth/tracers"

"github.com/ethereum/go-ethereum"
Expand Down Expand Up @@ -303,6 +304,13 @@ func (b *LesApiBackend) FeeHistory(ctx context.Context, blockCount int, lastBloc
return b.gpo.FeeHistory(ctx, blockCount, lastBlock, rewardPercentiles)
}

func (b *LesApiBackend) BlobBaseFee(ctx context.Context) *big.Int {
if excess := b.CurrentHeader().ExcessBlobGas; excess != nil {
return eip4844.CalcBlobFee(*excess)
}
return nil
}

func (b *LesApiBackend) ChainDb() ethdb.Database {
return b.eth.chainDb
}
Expand Down

0 comments on commit e9771ac

Please sign in to comment.