Skip to content

Commit

Permalink
consensus/misc/4844: add exception for OP-Stack in CalcBlobFee
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianst committed Feb 24, 2025
1 parent 543ecbb commit cb34678
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
10 changes: 10 additions & 0 deletions consensus/misc/eip4844/eip4844.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ func CalcExcessBlobGas(config *params.ChainConfig, parent *types.Header, headTim

// CalcBlobFee calculates the blobfee from the header's excess blob gas field.
func CalcBlobFee(config *params.ChainConfig, header *types.Header) *big.Int {
// OP-Stack chains don't support blobs, but still set the excessBlobGas field (always to zero).
// So this function is called in many places for OP-Stack chains too. In order to not require
// a blob schedule in the chain config, we short circuit here.
if config.IsOptimism() {
if config.BlobScheduleConfig != nil || header.ExcessBlobGas == nil || *header.ExcessBlobGas != 0 {
panic("OP-Stack: CalcBlobFee: unexpected blob schedule or excess blob gas")
}
return minBlobGasPrice
}

var frac uint64
switch config.LatestFork(header.Time) {
case forks.Prague:
Expand Down
24 changes: 24 additions & 0 deletions consensus/misc/eip4844/eip4844_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"math/big"
"testing"

"github.com/stretchr/testify/require"

"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/params"
)
Expand Down Expand Up @@ -90,6 +92,28 @@ func TestCalcBlobFee(t *testing.T) {
}
}

func TestCalcBlobFeeOPStack(t *testing.T) {
zero := uint64(0)
header := &types.Header{ExcessBlobGas: &zero}
// any non-nil optimism confic should do
config := &params.ChainConfig{Optimism: new(params.OptimismConfig)}
bfee := CalcBlobFee(config, header)
require.Equal(t, int64(1), bfee.Int64())

reqPanic := func() {
require.PanicsWithValue(t,
"OP-Stack: CalcBlobFee: unexpected blob schedule or excess blob gas",
func() { CalcBlobFee(config, header) })
}
(*header.ExcessBlobGas)++
reqPanic()
header.ExcessBlobGas = nil
reqPanic()
header.ExcessBlobGas = &zero
config.BlobScheduleConfig = params.DefaultBlobSchedule
reqPanic()
}

func TestFakeExponential(t *testing.T) {
tests := []struct {
factor int64
Expand Down

0 comments on commit cb34678

Please sign in to comment.