Skip to content

Commit 43d3a15

Browse files
authored
fix(kt-devnet): expose L2 rollup config (ethereum-optimism#15933)
1 parent 3a87059 commit 43d3a15

File tree

4 files changed

+61
-21
lines changed

4 files changed

+61
-21
lines changed

devnet-sdk/descriptors/deployment.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"net/http"
66

77
"github.com/ethereum-optimism/optimism/devnet-sdk/types"
8+
"github.com/ethereum-optimism/optimism/op-node/rollup"
89
"github.com/ethereum/go-ethereum/params"
910
)
1011

@@ -55,8 +56,9 @@ type Chain struct {
5556

5657
type L2Chain struct {
5758
*Chain
58-
L1Addresses AddressMap `json:"l1_addresses,omitempty"`
59-
L1Wallets WalletMap `json:"l1_wallets,omitempty"`
59+
L1Addresses AddressMap `json:"l1_addresses,omitempty"`
60+
L1Wallets WalletMap `json:"l1_wallets,omitempty"`
61+
RollupConfig *rollup.Config `json:"rollup_config"`
6062
}
6163

6264
// Wallet represents a wallet with an address and optional private key.

kurtosis-devnet/pkg/kurtosis/kurtosis.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ func (d *KurtosisDeployer) GetEnvironmentInfo(ctx context.Context, s *spec.Encla
247247
chain.L1Addresses = descriptors.AddressMap(deployment.L1Addresses)
248248
chain.Addresses = descriptors.AddressMap(deployment.L2Addresses)
249249
chain.Config = deployment.Config
250+
chain.RollupConfig = deployment.RollupConfig
250251
chain.Wallets = d.getWallets(deployment.L2Wallets)
251252
chain.L1Wallets = d.getWallets(deployment.L1Wallets)
252253
}

kurtosis-devnet/pkg/kurtosis/sources/deployer/deployer.go

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
ktfs "github.com/ethereum-optimism/optimism/devnet-sdk/kt/fs"
1414
"github.com/ethereum-optimism/optimism/devnet-sdk/types"
1515
"github.com/ethereum-optimism/optimism/op-chain-ops/devkeys"
16+
"github.com/ethereum-optimism/optimism/op-node/rollup"
1617
"github.com/ethereum/go-ethereum/common"
1718
"github.com/ethereum/go-ethereum/common/hexutil"
1819
"github.com/ethereum/go-ethereum/core"
@@ -28,6 +29,7 @@ const (
2829
defaultGenesisArtifactName = "el_cl_genesis_data"
2930
defaultMnemonicName = "mnemonics.yaml"
3031
defaultGenesisNameTemplate = "genesis-{{.ChainID}}.json"
32+
defaultRollupNameTemplate = "rollup-{{.ChainID}}.json"
3133
defaultL1GenesisName = "genesis.json"
3234
)
3335

@@ -38,11 +40,12 @@ type DeploymentAddresses map[string]types.Address
3840
type DeploymentStateAddresses map[string]DeploymentAddresses
3941

4042
type DeploymentState struct {
41-
L1Addresses DeploymentAddresses `json:"l1_addresses"`
42-
L2Addresses DeploymentAddresses `json:"l2_addresses"`
43-
L1Wallets WalletList `json:"l1_wallets"`
44-
L2Wallets WalletList `json:"l2_wallets"`
45-
Config *params.ChainConfig `json:"chain_config"`
43+
L1Addresses DeploymentAddresses `json:"l1_addresses"`
44+
L2Addresses DeploymentAddresses `json:"l2_addresses"`
45+
L1Wallets WalletList `json:"l1_wallets"`
46+
L2Wallets WalletList `json:"l2_wallets"`
47+
Config *params.ChainConfig `json:"chain_config"`
48+
RollupConfig *rollup.Config `json:"rollup_config"`
4649
}
4750

4851
type DeployerState struct {
@@ -83,6 +86,7 @@ type Deployer struct {
8386
genesisArtifactName string
8487
l1ValidatorMnemonicName string
8588
l2GenesisNameTemplate string
89+
l2RollupNameTemplate string
8690
l1GenesisName string
8791
}
8892

@@ -124,6 +128,12 @@ func WithGenesisNameTemplate(name string) DeployerOption {
124128
}
125129
}
126130

131+
func WithRollupNameTemplate(name string) DeployerOption {
132+
return func(d *Deployer) {
133+
d.l2RollupNameTemplate = name
134+
}
135+
}
136+
127137
func NewDeployer(enclave string, opts ...DeployerOption) *Deployer {
128138
d := &Deployer{
129139
enclave: enclave,
@@ -133,6 +143,7 @@ func NewDeployer(enclave string, opts ...DeployerOption) *Deployer {
133143
genesisArtifactName: defaultGenesisArtifactName,
134144
l1ValidatorMnemonicName: defaultMnemonicName,
135145
l2GenesisNameTemplate: defaultGenesisNameTemplate,
146+
l2RollupNameTemplate: defaultRollupNameTemplate,
136147
l1GenesisName: defaultL1GenesisName,
137148
}
138149

@@ -354,6 +365,29 @@ func (d *Deployer) ExtractData(ctx context.Context) (*DeployerData, error) {
354365

355366
// Store the genesis data in the deployment state
356367
deployment.Config = genesis.Config
368+
369+
rollupBuffer := bytes.NewBuffer(nil)
370+
rollupName, err := d.renderRollupNameTemplate(id)
371+
if err != nil {
372+
return nil, err
373+
}
374+
375+
if err := deployerArtifact.ExtractFiles(
376+
ktfs.NewArtifactFileWriter(rollupName, rollupBuffer),
377+
); err != nil {
378+
return nil, err
379+
}
380+
381+
// Parse the genesis file JSON into a core.Genesis struct
382+
var rollupCfg rollup.Config
383+
if err := json.NewDecoder(rollupBuffer).Decode(&rollupCfg); err != nil {
384+
return nil, fmt.Errorf("failed to parse rollup file %s in artifact %s for chain ID %s: %w", rollupName, d.deployerArtifactName, id, err)
385+
}
386+
387+
// Store the data in the deployment state
388+
deployment.Config = genesis.Config
389+
deployment.RollupConfig = &rollupCfg
390+
357391
state.Deployments[id] = deployment
358392
}
359393

@@ -381,15 +415,23 @@ func (d *Deployer) ExtractData(ctx context.Context) (*DeployerData, error) {
381415
}
382416

383417
func (d *Deployer) renderGenesisNameTemplate(chainID string) (string, error) {
384-
tmpl, err := template.New("genesis").Parse(d.l2GenesisNameTemplate)
418+
return d.renderNameTemplate(d.l2GenesisNameTemplate, chainID)
419+
}
420+
421+
func (d *Deployer) renderRollupNameTemplate(chainID string) (string, error) {
422+
return d.renderNameTemplate(d.l2RollupNameTemplate, chainID)
423+
}
424+
425+
func (d *Deployer) renderNameTemplate(t, chainID string) (string, error) {
426+
tmpl, err := template.New("").Parse(t)
385427
if err != nil {
386-
return "", fmt.Errorf("failed to compile genesis name template %s: %w", d.l2GenesisNameTemplate, err)
428+
return "", fmt.Errorf("failed to compile name template %s: %w", t, err)
387429
}
388430

389431
var buf bytes.Buffer
390432
err = tmpl.Execute(&buf, map[string]string{"ChainID": chainID})
391433
if err != nil {
392-
return "", fmt.Errorf("failed to execute name template %s: %w", d.l2GenesisNameTemplate, err)
434+
return "", fmt.Errorf("failed to execute name template %s: %w", t, err)
393435
}
394436

395437
return buf.String(), nil

op-devstack/sysext/l2.go

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"github.com/ethereum-optimism/optimism/op-devstack/shim"
1111
"github.com/ethereum-optimism/optimism/op-devstack/stack"
1212
"github.com/ethereum-optimism/optimism/op-devstack/stack/match"
13-
"github.com/ethereum-optimism/optimism/op-node/rollup"
1413
"github.com/ethereum-optimism/optimism/op-service/eth"
1514
)
1615

@@ -32,16 +31,12 @@ func (o *Orchestrator) hydrateL2(net *descriptors.L2Chain, system stack.Extensib
3231
CommonConfig: commonConfig,
3332
ChainConfig: net.Config,
3433
},
35-
ID: l2ID,
36-
RollupConfig: &rollup.Config{
37-
L1ChainID: l1.ChainID().ToBig(),
38-
L2ChainID: l2ID.ChainID().ToBig(),
39-
// TODO this rollup config should be loaded from kurtosis artifacts
40-
},
41-
Deployment: newL2AddressBook(t, net.L1Addresses),
42-
Keys: o.defineSystemKeys(t),
43-
Superchain: system.Superchain(stack.SuperchainID(env.Env.Name)),
44-
L1: l1,
34+
ID: l2ID,
35+
RollupConfig: net.RollupConfig,
36+
Deployment: newL2AddressBook(t, net.L1Addresses),
37+
Keys: o.defineSystemKeys(t),
38+
Superchain: system.Superchain(stack.SuperchainID(env.Env.Name)),
39+
L1: l1,
4540
}
4641
if o.isInterop() {
4742
cfg.Cluster = system.Cluster(stack.ClusterID(env.Env.Name))

0 commit comments

Comments
 (0)