1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package pipeline
import (
"fmt"
"github.com/ethereum-optimism/optimism/op-deployer/pkg/env"
"github.com/ethereum-optimism/optimism/op-chain-ops/foundry"
"github.com/ethereum-optimism/optimism/op-deployer/pkg/deployer/broadcaster"
"github.com/ethereum-optimism/optimism/op-deployer/pkg/deployer/opcm"
"github.com/ethereum-optimism/optimism/op-deployer/pkg/deployer/state"
"github.com/ethereum/go-ethereum/common"
)
func GenerateL2Genesis(pEnv *Env, intent *state.Intent, bundle ArtifactsBundle, st *state.State, chainID common.Hash) error {
lgr := pEnv.Logger.New("stage", "generate-l2-genesis")
thisIntent, err := intent.Chain(chainID)
if err != nil {
return fmt.Errorf("failed to get chain intent: %w", err)
}
thisChainState, err := st.Chain(chainID)
if err != nil {
return fmt.Errorf("failed to get chain state: %w", err)
}
if !shouldGenerateL2Genesis(thisChainState) {
lgr.Info("L2 genesis generation not needed")
return nil
}
lgr.Info("generating L2 genesis", "id", chainID.Hex())
initCfg, err := state.CombineDeployConfig(intent, thisIntent, st, thisChainState)
if err != nil {
return fmt.Errorf("failed to combine L2 init config: %w", err)
}
host, err := env.DefaultScriptHost(
broadcaster.NoopBroadcaster(),
pEnv.Logger,
pEnv.Deployer,
bundle.L2,
)
if err != nil {
return fmt.Errorf("failed to create L2 script host: %w", err)
}
if err := opcm.L2Genesis(host, &opcm.L2GenesisInput{
L1Deployments: opcm.L1Deployments{
L1CrossDomainMessengerProxy: thisChainState.L1CrossDomainMessengerProxyAddress,
L1StandardBridgeProxy: thisChainState.L1StandardBridgeProxyAddress,
L1ERC721BridgeProxy: thisChainState.L1ERC721BridgeProxyAddress,
},
L2Config: initCfg.L2InitializationConfig,
}); err != nil {
return fmt.Errorf("failed to call L2Genesis script: %w", err)
}
host.Wipe(pEnv.Deployer)
dump, err := host.StateDump()
if err != nil {
return fmt.Errorf("failed to dump state: %w", err)
}
thisChainState.Allocs = &state.GzipData[foundry.ForgeAllocs]{
Data: dump,
}
return nil
}
func shouldGenerateL2Genesis(thisChainState *state.ChainState) bool {
return thisChainState.Allocs == nil
}