Skip to content

Commit fa03b26

Browse files
authored
all: Introduce feature toggles for Jovian (#677)
* introduce IsMinBaseFee feature toggle Allows feature to be easily removed from Jovian hardfork. When the hardfork scope is locked, this commit can be reverted. * decouple features * add isOperatorFeeFix toggle
1 parent b51c72e commit fa03b26

File tree

5 files changed

+45
-28
lines changed

5 files changed

+45
-28
lines changed

beacon/engine/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ type PayloadAttributes struct {
6060
// and contains encoded EIP-1559 parameters. See:
6161
// https://github.com/ethereum-optimism/specs/blob/main/specs/protocol/holocene/exec-engine.md#eip1559params-encoding
6262
EIP1559Params []byte `json:"eip1559Params,omitempty" gencodec:"optional"`
63-
// MinBaseFee is a field for rollups implementing the Jovian upgrade's minimum base fee feature.
63+
// MinBaseFee is a field for rollups implementing the minimum base fee feature.
6464
// See https://github.com/ethereum-optimism/specs/blob/main/specs/protocol/jovian/exec-engine.md#minimum-base-fee-in-payloadattributesv3
6565
MinBaseFee *uint64 `json:"minBaseFee,omitempty" gencodec:"optional"`
6666
}

consensus/misc/eip1559/eip1559_optimism.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@ import (
88
)
99

1010
const HoloceneExtraDataVersionByte = uint8(0x00)
11-
const JovianExtraDataVersionByte = uint8(0x01)
11+
const MinBaseFeeExtraDataVersionByte = uint8(0x01)
1212

1313
type ForkChecker interface {
1414
IsHolocene(time uint64) bool
15-
IsJovian(time uint64) bool
15+
IsMinBaseFee(time uint64) bool
1616
}
1717

1818
// ValidateOptimismExtraData validates the Optimism extra data.
1919
// It uses the config and parent time to determine how to do the validation.
2020
func ValidateOptimismExtraData(fc ForkChecker, time uint64, extraData []byte) error {
21-
if fc.IsJovian(time) {
22-
return ValidateJovianExtraData(extraData)
21+
if fc.IsMinBaseFee(time) {
22+
return ValidateMinBaseFeeExtraData(extraData)
2323
} else if fc.IsHolocene(time) {
2424
return ValidateHoloceneExtraData(extraData)
2525
} else if len(extraData) > 0 { // pre-Holocene
@@ -32,8 +32,8 @@ func ValidateOptimismExtraData(fc ForkChecker, time uint64, extraData []byte) er
3232
// It uses the config and parent time to determine how to do the decoding.
3333
// The parent.extraData is expected to be valid (i.e. ValidateOptimismExtraData has been called previously)
3434
func DecodeOptimismExtraData(fc ForkChecker, time uint64, extraData []byte) (uint64, uint64, *uint64) {
35-
if fc.IsJovian(time) {
36-
denominator, elasticity, minBaseFee := DecodeJovianExtraData(extraData)
35+
if fc.IsMinBaseFee(time) {
36+
denominator, elasticity, minBaseFee := DecodeMinBaseFeeExtraData(extraData)
3737
return denominator, elasticity, minBaseFee
3838
} else if fc.IsHolocene(time) {
3939
denominator, elasticity := DecodeHoloceneExtraData(extraData)
@@ -45,11 +45,11 @@ func DecodeOptimismExtraData(fc ForkChecker, time uint64, extraData []byte) (uin
4545
// EncodeOptimismExtraData encodes the Optimism extra data.
4646
// It uses the config and parent time to determine how to do the encoding.
4747
func EncodeOptimismExtraData(fc ForkChecker, time uint64, denominator, elasticity uint64, minBaseFee *uint64) []byte {
48-
if fc.IsJovian(time) {
48+
if fc.IsMinBaseFee(time) {
4949
if minBaseFee == nil {
50-
panic("minBaseFee cannot be nil for Jovian")
50+
panic("minBaseFee cannot be nil since the MinBaseFee feature is enabled")
5151
}
52-
return EncodeJovianExtraData(denominator, elasticity, *minBaseFee)
52+
return EncodeMinBaseFeeExtraData(denominator, elasticity, *minBaseFee)
5353
} else if fc.IsHolocene(time) {
5454
return EncodeHoloceneExtraData(denominator, elasticity)
5555
} else {
@@ -133,12 +133,12 @@ func ValidateHoloceneExtraData(extra []byte) error {
133133
return ValidateHolocene1559Params(extra[1:])
134134
}
135135

136-
// DecodeJovianExtraData decodes the extraData parameters from the encoded form defined here:
136+
// DecodeMinBaseFeeExtraData decodes the extraData parameters from the encoded form defined here:
137137
// https://specs.optimism.io/protocol/jovian/exec-engine.html
138138
//
139-
// Returns 0,0,nil if the format is invalid, and d, e, nil for the Holocene length, to provide best effort behavior for non-Jovian extradata, though ValidateMinBaseFeeExtraData should be used instead of this function for
139+
// Returns 0,0,nil if the format is invalid, and d, e, nil for the Holocene length, to provide best effort behavior for non-MinBaseFee extradata, though ValidateMinBaseFeeExtraData should be used instead of this function for
140140
// validity checking.
141-
func DecodeJovianExtraData(extra []byte) (uint64, uint64, *uint64) {
141+
func DecodeMinBaseFeeExtraData(extra []byte) (uint64, uint64, *uint64) {
142142
// Best effort to decode the extraData for every block in the chain's history,
143143
// including blocks before the minimum base fee feature was enabled.
144144
if len(extra) == 9 {
@@ -154,27 +154,27 @@ func DecodeJovianExtraData(extra []byte) (uint64, uint64, *uint64) {
154154
return 0, 0, nil
155155
}
156156

157-
// EncodeJovianExtraData encodes the EIP-1559 and minBaseFee parameters into the header 'ExtraData' format.
157+
// EncodeMinBaseFeeExtraData encodes the EIP-1559 and minBaseFee parameters into the header 'ExtraData' format.
158158
// Will panic if EIP-1559 parameters are outside uint32 range.
159-
func EncodeJovianExtraData(denom, elasticity, minBaseFee uint64) []byte {
159+
func EncodeMinBaseFeeExtraData(denom, elasticity, minBaseFee uint64) []byte {
160160
r := make([]byte, 17)
161161
if denom > gomath.MaxUint32 || elasticity > gomath.MaxUint32 {
162162
panic("eip-1559 parameters out of uint32 range")
163163
}
164-
r[0] = JovianExtraDataVersionByte
164+
r[0] = MinBaseFeeExtraDataVersionByte
165165
binary.BigEndian.PutUint32(r[1:5], uint32(denom))
166166
binary.BigEndian.PutUint32(r[5:9], uint32(elasticity))
167167
binary.BigEndian.PutUint64(r[9:], minBaseFee)
168168
return r
169169
}
170170

171-
// ValidateJovianExtraData checks if the header extraData is valid according to the minimum base fee feature.
172-
func ValidateJovianExtraData(extra []byte) error {
171+
// ValidateMinBaseFeeExtraData checks if the header extraData is valid according to the minimum base fee feature.
172+
func ValidateMinBaseFeeExtraData(extra []byte) error {
173173
if len(extra) != 17 {
174-
return fmt.Errorf("jovian extraData should be 17 bytes, got %d", len(extra))
174+
return fmt.Errorf("MinBaseFee extraData should be 17 bytes, got %d", len(extra))
175175
}
176-
if extra[0] != JovianExtraDataVersionByte {
177-
return fmt.Errorf("jovian extraData version byte should be %d, got %d", JovianExtraDataVersionByte, extra[0])
176+
if extra[0] != MinBaseFeeExtraDataVersionByte {
177+
return fmt.Errorf("MinBaseFee extraData version byte should be %d, got %d", MinBaseFeeExtraDataVersionByte, extra[0])
178178
}
179179
return ValidateHolocene1559Params(extra[1:9])
180180
}

eth/catalyst/api_optimism_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ func TestCheckOptimismPayload(t *testing.T) {
162162
ExtraData: validExtraData,
163163
},
164164
cfg: postJovian(),
165-
expected: errors.New("jovian extraData should be 17 bytes, got 9"),
165+
expected: errors.New("MinBaseFee extraData should be 17 bytes, got 9"),
166166
},
167167
}
168168

miner/payload_building_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ func testBuildPayload(t *testing.T, noTxPool, interrupt bool, params1559 []byte,
243243
db := rawdb.NewMemoryDatabase()
244244

245245
var minBaseFee *uint64
246-
if config.IsOptimismJovian(testTimestamp) {
246+
if config.IsMinBaseFee(testTimestamp) {
247247
val := uint64(1e9)
248248
minBaseFee = &val
249249
}
@@ -301,8 +301,8 @@ func testBuildPayload(t *testing.T, noTxPool, interrupt bool, params1559 []byte,
301301
var expected []byte
302302
if len(params1559) != 0 {
303303
versionByte := eip1559.HoloceneExtraDataVersionByte
304-
if config.IsOptimismJovian(testTimestamp) {
305-
versionByte = eip1559.JovianExtraDataVersionByte
304+
if config.IsMinBaseFee(testTimestamp) {
305+
versionByte = eip1559.MinBaseFeeExtraDataVersionByte
306306
}
307307
expected = []byte{versionByte}
308308

@@ -312,7 +312,7 @@ func testBuildPayload(t *testing.T, noTxPool, interrupt bool, params1559 []byte,
312312
} else {
313313
expected = append(expected, params1559...)
314314
}
315-
if versionByte == eip1559.JovianExtraDataVersionByte {
315+
if versionByte == eip1559.MinBaseFeeExtraDataVersionByte {
316316
buf := make([]byte, 8)
317317
binary.BigEndian.PutUint64(buf, *minBaseFee)
318318
expected = append(expected, buf...)
@@ -426,14 +426,14 @@ func TestBuildPayloadInvalidHoloceneParams(t *testing.T) {
426426
}
427427
}
428428

429-
func TestBuildPayloadInvalidJovianExtraData(t *testing.T) {
429+
func TestBuildPayloadInvalidMinBaseFeeExtraData(t *testing.T) {
430430
t.Parallel()
431431
db := rawdb.NewMemoryDatabase()
432432
config := jovianConfig()
433433
w, b := newTestWorker(t, config, ethash.NewFaker(), db, 0)
434434

435435
// 0 denominators shouldn't be allowed
436-
badParams := eip1559.EncodeJovianExtraData(0, 6, 0)
436+
badParams := eip1559.EncodeMinBaseFeeExtraData(0, 6, 0)
437437

438438
args := newPayloadArgs(b.chain.CurrentBlock().Hash(), badParams, &zero)
439439
payload, err := w.buildPayload(args, false)

params/optimism_feature_toggles.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package params
2+
3+
// OPStack diff
4+
// This file contains ephemeral feature toggles which should be removed
5+
// after the fork scope is locked.
6+
7+
func (c *ChainConfig) IsMinBaseFee(time uint64) bool {
8+
return c.IsJovian(time) // Replace with return false to disable
9+
}
10+
11+
func (c *ChainConfig) IsDAFootprintBlockLimit(time uint64) bool {
12+
return c.IsJovian(time) // Replace with return false to disable
13+
}
14+
15+
func (c *ChainConfig) IsOperatorFeeFix(time uint64) bool {
16+
return c.IsJovian(time) // Replace with return false to disable
17+
}

0 commit comments

Comments
 (0)