Commit 297dff38 authored by Mark Tyneway's avatar Mark Tyneway

op-chain-ops: more sanity checking in L2 genesis generation

Also delete more dead code, add comments explaining how
a function should be maintained.
parent 1a96fda0
...@@ -837,6 +837,7 @@ func checkEAS(addr common.Address, client *ethclient.Client) error { ...@@ -837,6 +837,7 @@ func checkEAS(addr common.Address, client *ethclient.Client) error {
if name != "EAS" { if name != "EAS" {
return fmt.Errorf("Incorrect name %s", name) return fmt.Errorf("Incorrect name %s", name)
} }
log.Info("EAS", "name", name)
version, err := contract.Version(&bind.CallOpts{}) version, err := contract.Version(&bind.CallOpts{})
if err != nil { if err != nil {
......
...@@ -184,7 +184,7 @@ func BuildOptimism(config *PredeploysImmutableConfig) (DeploymentResults, error) ...@@ -184,7 +184,7 @@ func BuildOptimism(config *PredeploysImmutableConfig) (DeploymentResults, error)
// inserted into the state via state surgery. // inserted into the state via state surgery.
func BuildL2(constructors []deployer.Constructor, superchainPredeploys []deployer.SuperchainPredeploy) (DeploymentResults, error) { func BuildL2(constructors []deployer.Constructor, superchainPredeploys []deployer.SuperchainPredeploy) (DeploymentResults, error) {
log.Info("Creating L2 state") log.Info("Creating L2 state")
deployments, err := deployer.Deploy(deployer.NewL2Backend(), constructors, l2Deployer) deployments, err := deployer.Deploy(deployer.NewL2Backend(), constructors, l2ImmutableDeployer)
if err != nil { if err != nil {
return nil, err return nil, err
} }
...@@ -202,18 +202,21 @@ func BuildL2(constructors []deployer.Constructor, superchainPredeploys []deploye ...@@ -202,18 +202,21 @@ func BuildL2(constructors []deployer.Constructor, superchainPredeploys []deploye
return results, nil return results, nil
} }
func l2Deployer(backend *backends.SimulatedBackend, opts *bind.TransactOpts, deployment deployer.Constructor) (*types.Transaction, error) { // l2ImmutableDeployer will deploy L2 predeploys that contain immutables to the simulated backend.
// It only needs to care about the predeploys that have immutables so that the deployed bytecode
// has the dynamic value set at the correct location in the bytecode.
func l2ImmutableDeployer(backend *backends.SimulatedBackend, opts *bind.TransactOpts, deployment deployer.Constructor) (*types.Transaction, error) {
var tx *types.Transaction var tx *types.Transaction
var recipient common.Address var recipient common.Address
var minimumWithdrawalAmount *big.Int var minimumWithdrawalAmount *big.Int
var withdrawalNetwork uint8 var withdrawalNetwork uint8
var err error var err error
if _, err := bindings.GetImmutableReferences(deployment.Name); err != nil {
return nil, fmt.Errorf("%s does not have immutables: %w", deployment.Name, err)
}
switch deployment.Name { switch deployment.Name {
case "GasPriceOracle":
_, tx, _, err = bindings.DeployGasPriceOracle(opts, backend)
case "L1Block":
// No arguments required for the L1Block contract
_, tx, _, err = bindings.DeployL1Block(opts, backend)
case "L2CrossDomainMessenger": case "L2CrossDomainMessenger":
otherMessenger, ok := deployment.Args[0].(common.Address) otherMessenger, ok := deployment.Args[0].(common.Address)
if !ok { if !ok {
...@@ -226,9 +229,6 @@ func l2Deployer(backend *backends.SimulatedBackend, opts *bind.TransactOpts, dep ...@@ -226,9 +229,6 @@ func l2Deployer(backend *backends.SimulatedBackend, opts *bind.TransactOpts, dep
return nil, fmt.Errorf("invalid type for otherBridge") return nil, fmt.Errorf("invalid type for otherBridge")
} }
_, tx, _, err = bindings.DeployL2StandardBridge(opts, backend, otherBridge) _, tx, _, err = bindings.DeployL2StandardBridge(opts, backend, otherBridge)
case "L2ToL1MessagePasser":
// No arguments required for L2ToL1MessagePasser
_, tx, _, err = bindings.DeployL2ToL1MessagePasser(opts, backend)
case "SequencerFeeVault": case "SequencerFeeVault":
recipient, minimumWithdrawalAmount, withdrawalNetwork, err = prepareFeeVaultArguments(deployment) recipient, minimumWithdrawalAmount, withdrawalNetwork, err = prepareFeeVaultArguments(deployment)
if err != nil { if err != nil {
...@@ -248,13 +248,15 @@ func l2Deployer(backend *backends.SimulatedBackend, opts *bind.TransactOpts, dep ...@@ -248,13 +248,15 @@ func l2Deployer(backend *backends.SimulatedBackend, opts *bind.TransactOpts, dep
} }
_, tx, _, err = bindings.DeployL1FeeVault(opts, backend, recipient, minimumWithdrawalAmount, withdrawalNetwork) _, tx, _, err = bindings.DeployL1FeeVault(opts, backend, recipient, minimumWithdrawalAmount, withdrawalNetwork)
case "OptimismMintableERC20Factory": case "OptimismMintableERC20Factory":
_, tx, _, err = bindings.DeployOptimismMintableERC20Factory(opts, backend, predeploys.L2StandardBridgeAddr) bridge, ok := deployment.Args[0].(common.Address)
case "DeployerWhitelist": if !ok {
_, tx, _, err = bindings.DeployDeployerWhitelist(opts, backend) return nil, fmt.Errorf("invalid type for bridge")
case "LegacyMessagePasser": }
_, tx, _, err = bindings.DeployLegacyMessagePasser(opts, backend) // Sanity check that the argument is correct
case "L1BlockNumber": if bridge != predeploys.L2StandardBridgeAddr {
_, tx, _, err = bindings.DeployL1BlockNumber(opts, backend) return nil, fmt.Errorf("invalid bridge address")
}
_, tx, _, err = bindings.DeployOptimismMintableERC20Factory(opts, backend, bridge)
case "L2ERC721Bridge": case "L2ERC721Bridge":
messenger, ok := deployment.Args[0].(common.Address) messenger, ok := deployment.Args[0].(common.Address)
if !ok { if !ok {
...@@ -275,12 +277,8 @@ func l2Deployer(backend *backends.SimulatedBackend, opts *bind.TransactOpts, dep ...@@ -275,12 +277,8 @@ func l2Deployer(backend *backends.SimulatedBackend, opts *bind.TransactOpts, dep
return nil, fmt.Errorf("invalid type for remoteChainId") return nil, fmt.Errorf("invalid type for remoteChainId")
} }
_, tx, _, err = bindings.DeployOptimismMintableERC721Factory(opts, backend, bridge, remoteChainId) _, tx, _, err = bindings.DeployOptimismMintableERC721Factory(opts, backend, bridge, remoteChainId)
case "LegacyERC20ETH":
_, tx, _, err = bindings.DeployLegacyERC20ETH(opts, backend)
case "EAS": case "EAS":
_, tx, _, err = bindings.DeployEAS(opts, backend) _, tx, _, err = bindings.DeployEAS(opts, backend)
case "SchemaRegistry":
_, tx, _, err = bindings.DeploySchemaRegistry(opts, backend)
default: default:
return tx, fmt.Errorf("unknown contract: %s", deployment.Name) return tx, fmt.Errorf("unknown contract: %s", deployment.Name)
} }
......
...@@ -53,13 +53,13 @@ func TestBuildOptimism(t *testing.T) { ...@@ -53,13 +53,13 @@ func TestBuildOptimism(t *testing.T) {
Bridge common.Address Bridge common.Address
RemoteChainId *big.Int RemoteChainId *big.Int
}{ }{
Bridge: common.HexToAddress("0x1234567890123456789012345678901234567890"), Bridge: predeploys.L2StandardBridgeAddr,
RemoteChainId: big.NewInt(1), RemoteChainId: big.NewInt(1),
}, },
OptimismMintableERC20Factory: struct { OptimismMintableERC20Factory: struct {
Bridge common.Address Bridge common.Address
}{ }{
Bridge: common.HexToAddress("0x1234567890123456789012345678901234567890"), Bridge: predeploys.L2StandardBridgeAddr,
}, },
ProxyAdmin: struct{}{}, ProxyAdmin: struct{}{},
BaseFeeVault: struct { BaseFeeVault: struct {
......
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