From f8624c9774ac1d638385793b29b50b64d7ce95b1 Mon Sep 17 00:00:00 2001 From: VM Date: Mon, 19 May 2025 11:36:23 +0800 Subject: [PATCH 1/5] feat: op-node genesis l2 command supports generate geneisis state root to file --- op-node/cmd/genesis/cmd.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/op-node/cmd/genesis/cmd.go b/op-node/cmd/genesis/cmd.go index 6d3d68744..8b3e6e644 100644 --- a/op-node/cmd/genesis/cmd.go +++ b/op-node/cmd/genesis/cmd.go @@ -47,6 +47,10 @@ var ( Name: "outfile.rollup", Usage: "Path to rollup output file", } + outfileStateRootFlag = &cli.PathFlag{ + Name: "outfile.stateroot", + Usage: "Path to genesis state root output file", + } l1AllocsFlag = &cli.StringFlag{ Name: "l1-allocs", @@ -76,6 +80,7 @@ var ( l1DeploymentsFlag, outfileL2Flag, outfileRollupFlag, + outfileStateRootFlag, } ) @@ -225,6 +230,17 @@ var Subcommands = cli.Commands{ } l2GenesisBlock := l2Genesis.ToBlock() + if ctx.IsSet("outfile.stateroot") { + stateRoot := struct { + StateRoot string `json:"stateRoot"` + }{ + StateRoot: l2GenesisBlock.Header().Root.Hex(), + } + if err := jsonutil.WriteJSON(ctx.String("outfile.stateroot"), stateRoot, 0o666); err != nil { + return err + } + } + rollupConfig, err := config.RollupConfig(l1StartBlock, l2GenesisBlock.Hash(), l2GenesisBlock.Number().Uint64()) if err != nil { return err From 4f2a845898875f4fb83e1a5c4f26beee9c38af9e Mon Sep 17 00:00:00 2001 From: VM Date: Mon, 19 May 2025 11:40:03 +0800 Subject: [PATCH 2/5] fix: rename to genesisroot --- op-node/cmd/genesis/cmd.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/op-node/cmd/genesis/cmd.go b/op-node/cmd/genesis/cmd.go index 8b3e6e644..52d408346 100644 --- a/op-node/cmd/genesis/cmd.go +++ b/op-node/cmd/genesis/cmd.go @@ -48,7 +48,7 @@ var ( Usage: "Path to rollup output file", } outfileStateRootFlag = &cli.PathFlag{ - Name: "outfile.stateroot", + Name: "outfile.genesisroot", Usage: "Path to genesis state root output file", } @@ -230,13 +230,13 @@ var Subcommands = cli.Commands{ } l2GenesisBlock := l2Genesis.ToBlock() - if ctx.IsSet("outfile.stateroot") { - stateRoot := struct { - StateRoot string `json:"stateRoot"` + if ctx.IsSet("outfile.genesisroot") { + genesisStateRoot := struct { + GenesisStateRoot string `json:"genesisStateRoot"` }{ - StateRoot: l2GenesisBlock.Header().Root.Hex(), + GenesisStateRoot: l2GenesisBlock.Header().Root.Hex(), } - if err := jsonutil.WriteJSON(ctx.String("outfile.stateroot"), stateRoot, 0o666); err != nil { + if err := jsonutil.WriteJSON(ctx.String("outfile.genesisroot"), genesisStateRoot, 0o666); err != nil { return err } } From c1bf592c3406de225426cb03c2796f1465f44f0f Mon Sep 17 00:00:00 2001 From: VM Date: Mon, 19 May 2025 12:53:01 +0800 Subject: [PATCH 3/5] fix: add l2 genesis state root hash in rollup --- op-chain-ops/genesis/config.go | 4 +++- op-node/cmd/genesis/cmd.go | 19 ++----------------- op-node/rollup/types.go | 2 ++ 3 files changed, 7 insertions(+), 18 deletions(-) diff --git a/op-chain-ops/genesis/config.go b/op-chain-ops/genesis/config.go index c91b5bc42..d5cd937c2 100644 --- a/op-chain-ops/genesis/config.go +++ b/op-chain-ops/genesis/config.go @@ -694,7 +694,8 @@ func (d *DeployConfig) WrightTime(genesisTime uint64) *uint64 { // RollupConfig converts a DeployConfig to a rollup.Config. If Ecotone is active at genesis, the // Overhead value is considered a noop. -func (d *DeployConfig) RollupConfig(l1StartBlock *types.Block, l2GenesisBlockHash common.Hash, l2GenesisBlockNumber uint64) (*rollup.Config, error) { +func (d *DeployConfig) RollupConfig(l1StartBlock *types.Block, l2GenesisBlockHash common.Hash, l2GenesisBlockNumber uint64, + l2GenesisStateRoot common.Hash) (*rollup.Config, error) { if d.OptimismPortalProxy == (common.Address{}) { return nil, errors.New("OptimismPortalProxy cannot be address(0)") } @@ -728,6 +729,7 @@ func (d *DeployConfig) RollupConfig(l1StartBlock *types.Block, l2GenesisBlockHas Scalar: eth.Bytes32(d.FeeScalar()), GasLimit: uint64(d.L2GenesisBlockGasLimit), }, + L2GenesisStateRoot: l2GenesisStateRoot, }, BlockTime: d.L2BlockTime, MaxSequencerDrift: d.MaxSequencerDrift, diff --git a/op-node/cmd/genesis/cmd.go b/op-node/cmd/genesis/cmd.go index 52d408346..b144dbf91 100644 --- a/op-node/cmd/genesis/cmd.go +++ b/op-node/cmd/genesis/cmd.go @@ -47,10 +47,6 @@ var ( Name: "outfile.rollup", Usage: "Path to rollup output file", } - outfileStateRootFlag = &cli.PathFlag{ - Name: "outfile.genesisroot", - Usage: "Path to genesis state root output file", - } l1AllocsFlag = &cli.StringFlag{ Name: "l1-allocs", @@ -80,7 +76,6 @@ var ( l1DeploymentsFlag, outfileL2Flag, outfileRollupFlag, - outfileStateRootFlag, } ) @@ -230,18 +225,8 @@ var Subcommands = cli.Commands{ } l2GenesisBlock := l2Genesis.ToBlock() - if ctx.IsSet("outfile.genesisroot") { - genesisStateRoot := struct { - GenesisStateRoot string `json:"genesisStateRoot"` - }{ - GenesisStateRoot: l2GenesisBlock.Header().Root.Hex(), - } - if err := jsonutil.WriteJSON(ctx.String("outfile.genesisroot"), genesisStateRoot, 0o666); err != nil { - return err - } - } - - rollupConfig, err := config.RollupConfig(l1StartBlock, l2GenesisBlock.Hash(), l2GenesisBlock.Number().Uint64()) + rollupConfig, err := config.RollupConfig(l1StartBlock, l2GenesisBlock.Hash(), l2GenesisBlock.Number().Uint64(), + l2GenesisBlock.Header().Root) if err != nil { return err } diff --git a/op-node/rollup/types.go b/op-node/rollup/types.go index b8658a96d..3f3379995 100644 --- a/op-node/rollup/types.go +++ b/op-node/rollup/types.go @@ -54,6 +54,8 @@ type Genesis struct { // The L2 genesis block may not include transactions, and thus cannot encode the config values, // unlike later L2 blocks. SystemConfig eth.SystemConfig `json:"system_config"` + // The genesis state root of L2 genesis block + L2GenesisStateRoot common.Hash `json:"l2_genesis_state_root"` } type PlasmaConfig struct { From 20b6f9397b050c622cd4df0f9717a3c7efded13d Mon Sep 17 00:00:00 2001 From: VM Date: Mon, 19 May 2025 14:39:56 +0800 Subject: [PATCH 4/5] fix: add omitempty tag --- op-node/rollup/types.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/op-node/rollup/types.go b/op-node/rollup/types.go index 3f3379995..21349b1b2 100644 --- a/op-node/rollup/types.go +++ b/op-node/rollup/types.go @@ -55,7 +55,7 @@ type Genesis struct { // unlike later L2 blocks. SystemConfig eth.SystemConfig `json:"system_config"` // The genesis state root of L2 genesis block - L2GenesisStateRoot common.Hash `json:"l2_genesis_state_root"` + L2GenesisStateRoot common.Hash `json:"l2_genesis_state_root,omitempty"` } type PlasmaConfig struct { From 23e19b56a2ff46cfdf2746748865cc4c7129cdaf Mon Sep 17 00:00:00 2001 From: VM Date: Mon, 19 May 2025 15:00:22 +0800 Subject: [PATCH 5/5] fix: solve e2e test --- op-e2e/op_geth.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/op-e2e/op_geth.go b/op-e2e/op_geth.go index d356068cf..fdf8664c8 100644 --- a/op-e2e/op_geth.go +++ b/op-e2e/op_geth.go @@ -104,7 +104,8 @@ func NewOpGeth(t testing.TB, ctx context.Context, cfg *SystemConfig) (*OpGeth, e require.NoError(t, err) // Finally create the engine client - rollupCfg, err := cfg.DeployConfig.RollupConfig(l1Block, l2GenesisBlock.Hash(), l2GenesisBlock.NumberU64()) + rollupCfg, err := cfg.DeployConfig.RollupConfig(l1Block, l2GenesisBlock.Hash(), l2GenesisBlock.NumberU64(), + l2GenesisBlock.Header().Root) require.NoError(t, err) rollupCfg.Genesis = rollupGenesis l2Engine, err := sources.NewEngineClient(