Commit 14d0ece7 authored by Mark Tyneway's avatar Mark Tyneway

op-node: flexible L2 genesis generation

Allow for the `op-node` L2 genesis generation to use either
hardhat artifacts or the `.deploy` L1Deployments JSON file
that is created by the solidity deployment script. While adding
extra logic, this makes genesis generation much easier to be
consumed by the solidity scripts. It also sets up the ability
to deprecate the need for maintaining hardhat deploy style
artifacts. This will allow us to remove a lot of solidity code
and remove the need to call `sync()` to generate the artifacts.
The artifacts make less sense now, especially since it is planned
to have one set of implementation contracts for the entire superchain.
There isn't as much of a need to keep around artifacts for many
contracts separated by network when they are shared between
different L2s.
parent 122f041d
...@@ -388,41 +388,28 @@ func (d *DeployConfig) SetDeployments(deployments *L1Deployments) { ...@@ -388,41 +388,28 @@ func (d *DeployConfig) SetDeployments(deployments *L1Deployments) {
} }
// GetDeployedAddresses will get the deployed addresses of deployed L1 contracts // GetDeployedAddresses will get the deployed addresses of deployed L1 contracts
// required for the L2 genesis creation. Legacy systems use the `Proxy__` prefix // required for the L2 genesis creation.
// while modern systems use the `Proxy` suffix. First check for the legacy
// deployments so that this works with upgrading a system.
func (d *DeployConfig) GetDeployedAddresses(hh *hardhat.Hardhat) error { func (d *DeployConfig) GetDeployedAddresses(hh *hardhat.Hardhat) error {
var err error
if d.L1StandardBridgeProxy == (common.Address{}) { if d.L1StandardBridgeProxy == (common.Address{}) {
var l1StandardBridgeProxyDeployment *hardhat.Deployment l1StandardBridgeProxyDeployment, err := hh.GetDeployment("L1StandardBridgeProxy")
l1StandardBridgeProxyDeployment, err = hh.GetDeployment("Proxy__OVM_L1StandardBridge") if err != nil {
if errors.Is(err, hardhat.ErrCannotFindDeployment) { return fmt.Errorf("cannot find L1StandardBridgeProxy artifact: %s", err)
l1StandardBridgeProxyDeployment, err = hh.GetDeployment("L1StandardBridgeProxy")
if err != nil {
return err
}
} }
d.L1StandardBridgeProxy = l1StandardBridgeProxyDeployment.Address d.L1StandardBridgeProxy = l1StandardBridgeProxyDeployment.Address
} }
if d.L1CrossDomainMessengerProxy == (common.Address{}) { if d.L1CrossDomainMessengerProxy == (common.Address{}) {
var l1CrossDomainMessengerProxyDeployment *hardhat.Deployment l1CrossDomainMessengerProxyDeployment, err := hh.GetDeployment("L1CrossDomainMessengerProxy")
l1CrossDomainMessengerProxyDeployment, err = hh.GetDeployment("Proxy__OVM_L1CrossDomainMessenger") if err != nil {
if errors.Is(err, hardhat.ErrCannotFindDeployment) { return fmt.Errorf("cannot find L1CrossDomainMessengerProxy artifact: %s", err)
l1CrossDomainMessengerProxyDeployment, err = hh.GetDeployment("L1CrossDomainMessengerProxy")
if err != nil {
return err
}
} }
d.L1CrossDomainMessengerProxy = l1CrossDomainMessengerProxyDeployment.Address d.L1CrossDomainMessengerProxy = l1CrossDomainMessengerProxyDeployment.Address
} }
if d.L1ERC721BridgeProxy == (common.Address{}) { if d.L1ERC721BridgeProxy == (common.Address{}) {
// There is no legacy deployment of this contract
l1ERC721BridgeProxyDeployment, err := hh.GetDeployment("L1ERC721BridgeProxy") l1ERC721BridgeProxyDeployment, err := hh.GetDeployment("L1ERC721BridgeProxy")
if err != nil { if err != nil {
return err return fmt.Errorf("cannot find L1ERC721BridgeProxy artifact: %s", err)
} }
d.L1ERC721BridgeProxy = l1ERC721BridgeProxyDeployment.Address d.L1ERC721BridgeProxy = l1ERC721BridgeProxyDeployment.Address
} }
...@@ -430,7 +417,7 @@ func (d *DeployConfig) GetDeployedAddresses(hh *hardhat.Hardhat) error { ...@@ -430,7 +417,7 @@ func (d *DeployConfig) GetDeployedAddresses(hh *hardhat.Hardhat) error {
if d.SystemConfigProxy == (common.Address{}) { if d.SystemConfigProxy == (common.Address{}) {
systemConfigProxyDeployment, err := hh.GetDeployment("SystemConfigProxy") systemConfigProxyDeployment, err := hh.GetDeployment("SystemConfigProxy")
if err != nil { if err != nil {
return err return fmt.Errorf("cannot find SystemConfigProxy artifact: %s", err)
} }
d.SystemConfigProxy = systemConfigProxyDeployment.Address d.SystemConfigProxy = systemConfigProxyDeployment.Address
} }
...@@ -438,7 +425,7 @@ func (d *DeployConfig) GetDeployedAddresses(hh *hardhat.Hardhat) error { ...@@ -438,7 +425,7 @@ func (d *DeployConfig) GetDeployedAddresses(hh *hardhat.Hardhat) error {
if d.OptimismPortalProxy == (common.Address{}) { if d.OptimismPortalProxy == (common.Address{}) {
optimismPortalProxyDeployment, err := hh.GetDeployment("OptimismPortalProxy") optimismPortalProxyDeployment, err := hh.GetDeployment("OptimismPortalProxy")
if err != nil { if err != nil {
return err return fmt.Errorf("cannot find OptimismPortalProxy artifact: %s", err)
} }
d.OptimismPortalProxy = optimismPortalProxyDeployment.Address d.OptimismPortalProxy = optimismPortalProxyDeployment.Address
} }
......
...@@ -28,7 +28,7 @@ var Subcommands = cli.Commands{ ...@@ -28,7 +28,7 @@ var Subcommands = cli.Commands{
Flags: []cli.Flag{ Flags: []cli.Flag{
&cli.StringFlag{ &cli.StringFlag{
Name: "deploy-config", Name: "deploy-config",
Usage: "Path to hardhat deploy config file", Usage: "Path to deploy config file",
Required: true, Required: true,
}, },
&cli.StringFlag{ &cli.StringFlag{
...@@ -97,12 +97,17 @@ var Subcommands = cli.Commands{ ...@@ -97,12 +97,17 @@ var Subcommands = cli.Commands{
Usage: "L1 RPC URL", Usage: "L1 RPC URL",
}, },
&cli.StringFlag{ &cli.StringFlag{
Name: "deploy-config", Name: "deploy-config",
Usage: "Path to deploy config file", Usage: "Path to deploy config file",
Required: true,
}, },
&cli.StringFlag{ &cli.StringFlag{
Name: "deployment-dir", 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{ &cli.StringFlag{
Name: "outfile.l2", Name: "outfile.l2",
...@@ -122,20 +127,36 @@ var Subcommands = cli.Commands{ ...@@ -122,20 +127,36 @@ var Subcommands = cli.Commands{
} }
deployDir := ctx.String("deployment-dir") deployDir := ctx.String("deployment-dir")
if deployDir == "" { l1Deployments := ctx.String("l1-deployments")
return errors.New("Must specify --deployment-dir")
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) if deployDir != "" {
depPath, network := filepath.Split(deployDir) log.Info("Deployment directory", "path", deployDir)
hh, err := hardhat.New(network, nil, []string{depPath}) depPath, network := filepath.Split(deployDir)
if err != nil { hh, err := hardhat.New(network, nil, []string{depPath})
return err 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 l1Deployments != "" {
if err := config.GetDeployedAddresses(hh); err != nil { log.Info("L1 deployments", "path", l1Deployments)
return err deployments, err := genesis.NewL1Deployments(l1Deployments)
if err != nil {
return err
}
config.SetDeployments(deployments)
} }
client, err := ethclient.Dial(ctx.String("l1-rpc")) client, err := ethclient.Dial(ctx.String("l1-rpc"))
......
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