Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

op-node: flexible L2 genesis generation #8102

Merged
merged 3 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 10 additions & 23 deletions op-chain-ops/genesis/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,57 +388,44 @@ func (d *DeployConfig) SetDeployments(deployments *L1Deployments) {
}

// GetDeployedAddresses will get the deployed addresses of deployed L1 contracts
// required for the L2 genesis creation. Legacy systems use the `Proxy__` prefix
// while modern systems use the `Proxy` suffix. First check for the legacy
// deployments so that this works with upgrading a system.
// required for the L2 genesis creation.
func (d *DeployConfig) GetDeployedAddresses(hh *hardhat.Hardhat) error {
var err error

if d.L1StandardBridgeProxy == (common.Address{}) {
var l1StandardBridgeProxyDeployment *hardhat.Deployment
l1StandardBridgeProxyDeployment, err = hh.GetDeployment("Proxy__OVM_L1StandardBridge")
if errors.Is(err, hardhat.ErrCannotFindDeployment) {
l1StandardBridgeProxyDeployment, err = hh.GetDeployment("L1StandardBridgeProxy")
if err != nil {
return err
}
l1StandardBridgeProxyDeployment, err := hh.GetDeployment("L1StandardBridgeProxy")
if err != nil {
return fmt.Errorf("cannot find L1StandardBridgeProxy artifact: %w", err)
}
d.L1StandardBridgeProxy = l1StandardBridgeProxyDeployment.Address
}

if d.L1CrossDomainMessengerProxy == (common.Address{}) {
var l1CrossDomainMessengerProxyDeployment *hardhat.Deployment
l1CrossDomainMessengerProxyDeployment, err = hh.GetDeployment("Proxy__OVM_L1CrossDomainMessenger")
if errors.Is(err, hardhat.ErrCannotFindDeployment) {
l1CrossDomainMessengerProxyDeployment, err = hh.GetDeployment("L1CrossDomainMessengerProxy")
if err != nil {
return err
}
l1CrossDomainMessengerProxyDeployment, err := hh.GetDeployment("L1CrossDomainMessengerProxy")
if err != nil {
return fmt.Errorf("cannot find L1CrossDomainMessengerProxy artifact: %w", err)
}
d.L1CrossDomainMessengerProxy = l1CrossDomainMessengerProxyDeployment.Address
}

if d.L1ERC721BridgeProxy == (common.Address{}) {
// There is no legacy deployment of this contract
l1ERC721BridgeProxyDeployment, err := hh.GetDeployment("L1ERC721BridgeProxy")
if err != nil {
return err
return fmt.Errorf("cannot find L1ERC721BridgeProxy artifact: %w", err)
}
d.L1ERC721BridgeProxy = l1ERC721BridgeProxyDeployment.Address
}

if d.SystemConfigProxy == (common.Address{}) {
systemConfigProxyDeployment, err := hh.GetDeployment("SystemConfigProxy")
if err != nil {
return err
return fmt.Errorf("cannot find SystemConfigProxy artifact: %w", err)
}
d.SystemConfigProxy = systemConfigProxyDeployment.Address
}

if d.OptimismPortalProxy == (common.Address{}) {
optimismPortalProxyDeployment, err := hh.GetDeployment("OptimismPortalProxy")
if err != nil {
return err
return fmt.Errorf("cannot find OptimismPortalProxy artifact: %w", err)
}
d.OptimismPortalProxy = optimismPortalProxyDeployment.Address
}
Expand Down
52 changes: 38 additions & 14 deletions op-node/cmd/genesis/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var Subcommands = cli.Commands{
Flags: []cli.Flag{
&cli.StringFlag{
Name: "deploy-config",
Usage: "Path to hardhat deploy config file",
Usage: "Path to deploy config file",
Required: true,
},
&cli.StringFlag{
Expand Down Expand Up @@ -91,18 +91,26 @@ var Subcommands = cli.Commands{
{
Name: "l2",
Usage: "Generates an L2 genesis file and rollup config suitable for a deployed network",
Description: "Generating the L2 genesis depends on knowledge of L1 contract addresses for the bridge to be secure. " +
"A deploy config and either a deployment directory or an L1 deployments file are used to create the L2 genesis. " +
"The deploy directory and L1 deployments file are generated by the L1 contract deployments.",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "l1-rpc",
Usage: "L1 RPC URL",
},
&cli.StringFlag{
Name: "deploy-config",
Usage: "Path to deploy config file",
Name: "deploy-config",
Usage: "Path to deploy config file",
Required: true,
},
&cli.StringFlag{
Name: "deployment-dir",
Usage: "Path to network deployment directory",
Usage: "Path to network deployment directory. Cannot be used with --l1-deployments",
},
&cli.StringFlag{
Name: "l1-deployments",
Usage: "Path to L1 deployments JSON file. Cannot be used with --deployment-dir",
},
&cli.StringFlag{
Name: "outfile.l2",
Expand All @@ -122,20 +130,36 @@ var Subcommands = cli.Commands{
}

deployDir := ctx.String("deployment-dir")
if deployDir == "" {
return errors.New("Must specify --deployment-dir")
l1Deployments := ctx.String("l1-deployments")

if deployDir != "" && l1Deployments != "" {
return errors.New("cannot specify both --deployment-dir and --l1-deployments")
}
if deployDir == "" && l1Deployments == "" {
return errors.New("must specify either --deployment-dir or --l1-deployments")
}

log.Info("Deployment directory", "path", deployDir)
depPath, network := filepath.Split(deployDir)
hh, err := hardhat.New(network, nil, []string{depPath})
if err != nil {
return err
if deployDir != "" {
log.Info("Deployment directory", "path", deployDir)
depPath, network := filepath.Split(deployDir)
hh, err := hardhat.New(network, nil, []string{depPath})
if err != nil {
return err
}

// Read the appropriate deployment addresses from disk
if err := config.GetDeployedAddresses(hh); err != nil {
return err
}
}

// Read the appropriate deployment addresses from disk
if err := config.GetDeployedAddresses(hh); err != nil {
return err
if l1Deployments != "" {
log.Info("L1 deployments", "path", l1Deployments)
deployments, err := genesis.NewL1Deployments(l1Deployments)
if err != nil {
return err
}
config.SetDeployments(deployments)
}

client, err := ethclient.Dial(ctx.String("l1-rpc"))
Expand Down