Skip to content

Commit

Permalink
op-service, op-deployer: Support marshaling systemconfig in pre-Holoc…
Browse files Browse the repository at this point in the history
…ene format

op-deployer generates rollup configs, and those rollup configs are currently broken for older versions of op-node that don't support reading the EIP1559Params field in the SystemConfig. This PR adds a meta field within the SystemConfig that, when enabled, marshals the SystemConfig without the EIP1559Params field. This solution is backwards-compatible and minimally invasive, requiring no changes to the consensus-critical code that consumes the SystemConfig elsewhere.

Closes #12615.
  • Loading branch information
mslipper committed Oct 24, 2024
1 parent 5f2cc84 commit d214b78
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
3 changes: 3 additions & 0 deletions op-deployer/pkg/deployer/inspect/rollup.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ func RollupCLI(cliCtx *cli.Context) error {
}

_, rollupConfig, err := GenesisAndRollup(globalState, cfg.ChainID)
if rollupConfig.HoloceneTime == nil {
rollupConfig.Genesis.SystemConfig.MarshalPreHolocene = true
}
if err != nil {
return fmt.Errorf("failed to generate rollup config: %w", err)
}
Expand Down
35 changes: 35 additions & 0 deletions op-service/eth/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package eth
import (
"bytes"
"encoding/binary"
"encoding/json"
"errors"
"fmt"
"math"
Expand Down Expand Up @@ -421,6 +422,40 @@ type SystemConfig struct {
// process any EIP_1559_PARAMS system config update events.
EIP1559Params Bytes8 `json:"eip1559Params,omitempty"`
// More fields can be added for future SystemConfig versions.

// MarshalPreHolocene indicates whether or not this struct should be
// marshaled in the pre-Holocene format. The pre-Holocene format does
// not marshal the EIP1559Params field. The presence of this field in
// pre-Holocene codebases causes the rollup config to be rejected.
MarshalPreHolocene bool `json:"-"`
}

func (sysCfg SystemConfig) MarshalJSON() ([]byte, error) {
if sysCfg.MarshalPreHolocene {
return jsonMarshalPreHolocene(sysCfg)
}
return jsonMarshalHolocene(sysCfg)
}

func jsonMarshalHolocene(sysCfg SystemConfig) ([]byte, error) {
type sysCfgMarshaling SystemConfig
return json.Marshal(sysCfgMarshaling(sysCfg))
}

func jsonMarshalPreHolocene(sysCfg SystemConfig) ([]byte, error) {
type sysCfgMarshaling struct {
BatcherAddr common.Address `json:"batcherAddr"`
Overhead Bytes32 `json:"overhead"`
Scalar Bytes32 `json:"scalar"`
GasLimit uint64 `json:"gasLimit"`
}
sc := sysCfgMarshaling{
BatcherAddr: sysCfg.BatcherAddr,
Overhead: sysCfg.Overhead,
Scalar: sysCfg.Scalar,
GasLimit: sysCfg.GasLimit,
}
return json.Marshal(sc)
}

// The Ecotone upgrade introduces a versioned L1 scalar format
Expand Down
21 changes: 21 additions & 0 deletions op-service/eth/types_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package eth

import (
"encoding/json"
"errors"
"math"
"testing"

"github.com/ethereum/go-ethereum/common"

"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -66,3 +69,21 @@ func FuzzEncodeScalar(f *testing.F) {
require.Equal(t, baseFeeScalar, scalars.BaseFeeScalar)
})
}

func TestSystemConfigMarshaling(t *testing.T) {
sysConfig := SystemConfig{
BatcherAddr: common.Address{'A'},
Overhead: Bytes32{0x4, 0x5, 0x6},
Scalar: Bytes32{0x7, 0x8, 0x9},
GasLimit: 1234,
// Leave EIP1559 params empty to prove that the
// zero value is sent.
}
j, err := json.Marshal(sysConfig)
require.NoError(t, err)
require.Equal(t, `{"batcherAddr":"0x4100000000000000000000000000000000000000","overhead":"0x0405060000000000000000000000000000000000000000000000000000000000","scalar":"0x0708090000000000000000000000000000000000000000000000000000000000","gasLimit":1234,"eip1559Params":"0x0000000000000000"}`, string(j))
sysConfig.MarshalPreHolocene = true
j, err = json.Marshal(sysConfig)
require.NoError(t, err)
require.Equal(t, `{"batcherAddr":"0x4100000000000000000000000000000000000000","overhead":"0x0405060000000000000000000000000000000000000000000000000000000000","scalar":"0x0708090000000000000000000000000000000000000000000000000000000000","gasLimit":1234}`, string(j))
}

0 comments on commit d214b78

Please sign in to comment.