Commit d73a4bcc authored by Matthew Slipper's avatar Matthew Slipper Committed by GitHub

op-service, op-deployer: Support marshaling systemconfig in pre-Holocene format (#12619)

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 https://github.com/ethereum-optimism/optimism/issues/12615.
parent 196613d9
......@@ -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)
}
......
......@@ -3,6 +3,7 @@ package eth
import (
"bytes"
"encoding/binary"
"encoding/json"
"errors"
"fmt"
"math"
......@@ -419,8 +420,42 @@ type SystemConfig struct {
// EIP1559Params contains the Holocene-encoded EIP-1559 parameters. This
// value will be 0 if Holocene is not active, or if derivation has yet to
// process any EIP_1559_PARAMS system config update events.
EIP1559Params Bytes8 `json:"eip1559Params,omitempty"`
EIP1559Params Bytes8 `json:"eip1559Params"`
// 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
......
package eth
import (
"encoding/json"
"errors"
"math"
"testing"
"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require"
)
......@@ -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))
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment