Commit 11b1ab33 authored by Mark Tyneway's avatar Mark Tyneway

op-chain-ops: delete concepts of `L2Addrs`

Now all of the config lives in the `DeployConfig`
and there is a method to read dynamic config values
from disk given a hh or the dev addresses can be
added to the config with `GetDeveloperDeployedAddresses`.

This is useful to deduplicate code that has been changing
a lot, resulting in code changes in many places to get
tests passing again.

This will break hive when we do another release of the go
packages.
parent 4950656a
...@@ -152,18 +152,8 @@ func main() { ...@@ -152,18 +152,8 @@ func main() {
return err return err
} }
l2Addrs := genesis.L2Addresses{
ProxyAdminOwner: config.ProxyAdminOwner,
L1StandardBridgeProxy: config.L1StandardBridgeProxy,
L1CrossDomainMessengerProxy: config.L1CrossDomainMessengerProxy,
L1ERC721BridgeProxy: config.L1ERC721BridgeProxy,
BaseFeeVaultRecipient: config.BaseFeeVaultRecipient,
L1FeeVaultRecipient: config.L1FeeVaultRecipient,
SequencerFeeVaultRecipient: config.SequencerFeeVaultRecipient,
}
dryRun := ctx.Bool("dry-run") dryRun := ctx.Bool("dry-run")
if err := genesis.MigrateDB(ldb, config, block, &l2Addrs, &migrationData, !dryRun); err != nil { if err := genesis.MigrateDB(ldb, config, block, &migrationData, !dryRun); err != nil {
return err return err
} }
......
...@@ -173,19 +173,19 @@ func (d *DeployConfig) Check() error { ...@@ -173,19 +173,19 @@ func (d *DeployConfig) Check() error {
log.Warn("GasPriceOracleScalar is address(0)") log.Warn("GasPriceOracleScalar is address(0)")
} }
if d.L1StandardBridgeProxy == (common.Address{}) { if d.L1StandardBridgeProxy == (common.Address{}) {
log.Warn("L1StandardBridgeProxy is address(0)") return fmt.Errorf("%w: L1StandardBridgeProxy cannot be address(0)", ErrInvalidDeployConfig)
} }
if d.L1CrossDomainMessengerProxy == (common.Address{}) { if d.L1CrossDomainMessengerProxy == (common.Address{}) {
log.Warn("L1CrossDomainMessengerProxy is address(0)") return fmt.Errorf("%w: L1CrossDomainMessengerProxy cannot be address(0)", ErrInvalidDeployConfig)
} }
if d.L1ERC721BridgeProxy == (common.Address{}) { if d.L1ERC721BridgeProxy == (common.Address{}) {
log.Warn("L1ERC721BridgeProxy is address(0)") return fmt.Errorf("%w: L1ERC721BridgeProxy cannot be address(0)", ErrInvalidDeployConfig)
} }
if d.SystemConfigProxy == (common.Address{}) { if d.SystemConfigProxy == (common.Address{}) {
log.Warn("SystemConfigProxy is address(0)") return fmt.Errorf("%w: SystemConfigProxy cannot be address(0)", ErrInvalidDeployConfig)
} }
if d.OptimismPortalProxy == (common.Address{}) { if d.OptimismPortalProxy == (common.Address{}) {
log.Warn("OptimismPortalProxy is address(0)") return fmt.Errorf("%w: OptimismPortalProxy cannot be address(0)", ErrInvalidDeployConfig)
} }
return nil return nil
} }
...@@ -249,6 +249,16 @@ func (d *DeployConfig) GetDeployedAddresses(hh *hardhat.Hardhat) error { ...@@ -249,6 +249,16 @@ func (d *DeployConfig) GetDeployedAddresses(hh *hardhat.Hardhat) error {
return nil return nil
} }
// GetDeveloperDeployedAddresses will set the dev addresses on the DeployConfig
func (d *DeployConfig) GetDeveloperDeployedAddresses() error {
d.L1StandardBridgeProxy = predeploys.DevL1StandardBridgeAddr
d.L1CrossDomainMessengerProxy = predeploys.DevL1CrossDomainMessengerAddr
d.L1ERC721BridgeProxy = predeploys.DevL1ERC721BridgeAddr
d.OptimismPortalProxy = predeploys.DevOptimismPortalAddr
d.SystemConfigProxy = predeploys.DevSystemConfigAddr
return nil
}
// NewDeployConfig reads a config file given a path on the filesystem. // NewDeployConfig reads a config file given a path on the filesystem.
func NewDeployConfig(path string) (*DeployConfig, error) { func NewDeployConfig(path string) (*DeployConfig, error) {
file, err := os.ReadFile(path) file, err := os.ReadFile(path)
...@@ -274,39 +284,35 @@ func NewDeployConfigWithNetwork(network, path string) (*DeployConfig, error) { ...@@ -274,39 +284,35 @@ func NewDeployConfigWithNetwork(network, path string) (*DeployConfig, error) {
// NewL2ImmutableConfig will create an ImmutableConfig given an instance of a // NewL2ImmutableConfig will create an ImmutableConfig given an instance of a
// Hardhat and a DeployConfig. // Hardhat and a DeployConfig.
func NewL2ImmutableConfig(config *DeployConfig, block *types.Block, l2Addrs *L2Addresses) (immutables.ImmutableConfig, error) { func NewL2ImmutableConfig(config *DeployConfig, block *types.Block) (immutables.ImmutableConfig, error) {
immutable := make(immutables.ImmutableConfig) immutable := make(immutables.ImmutableConfig)
if l2Addrs == nil { if config.L1ERC721BridgeProxy == (common.Address{}) {
return immutable, errors.New("must pass L1 contract addresses")
}
if l2Addrs.L1ERC721BridgeProxy == (common.Address{}) {
return immutable, errors.New("L1ERC721BridgeProxy cannot be address(0)") return immutable, errors.New("L1ERC721BridgeProxy cannot be address(0)")
} }
immutable["L2StandardBridge"] = immutables.ImmutableValues{ immutable["L2StandardBridge"] = immutables.ImmutableValues{
"otherBridge": l2Addrs.L1StandardBridgeProxy, "otherBridge": config.L1StandardBridgeProxy,
} }
immutable["L2CrossDomainMessenger"] = immutables.ImmutableValues{ immutable["L2CrossDomainMessenger"] = immutables.ImmutableValues{
"otherMessenger": l2Addrs.L1CrossDomainMessengerProxy, "otherMessenger": config.L1CrossDomainMessengerProxy,
} }
immutable["L2ERC721Bridge"] = immutables.ImmutableValues{ immutable["L2ERC721Bridge"] = immutables.ImmutableValues{
"messenger": predeploys.L2CrossDomainMessengerAddr, "messenger": predeploys.L2CrossDomainMessengerAddr,
"otherBridge": l2Addrs.L1ERC721BridgeProxy, "otherBridge": config.L1ERC721BridgeProxy,
} }
immutable["OptimismMintableERC721Factory"] = immutables.ImmutableValues{ immutable["OptimismMintableERC721Factory"] = immutables.ImmutableValues{
"bridge": predeploys.L2ERC721BridgeAddr, "bridge": predeploys.L2ERC721BridgeAddr,
"remoteChainId": new(big.Int).SetUint64(config.L1ChainID), "remoteChainId": new(big.Int).SetUint64(config.L1ChainID),
} }
immutable["SequencerFeeVault"] = immutables.ImmutableValues{ immutable["SequencerFeeVault"] = immutables.ImmutableValues{
"recipient": l2Addrs.SequencerFeeVaultRecipient, "recipient": config.SequencerFeeVaultRecipient,
} }
immutable["L1FeeVault"] = immutables.ImmutableValues{ immutable["L1FeeVault"] = immutables.ImmutableValues{
"recipient": l2Addrs.L1FeeVaultRecipient, "recipient": config.L1FeeVaultRecipient,
} }
immutable["BaseFeeVault"] = immutables.ImmutableValues{ immutable["BaseFeeVault"] = immutables.ImmutableValues{
"recipient": l2Addrs.BaseFeeVaultRecipient, "recipient": config.BaseFeeVaultRecipient,
} }
return immutable, nil return immutable, nil
...@@ -314,7 +320,7 @@ func NewL2ImmutableConfig(config *DeployConfig, block *types.Block, l2Addrs *L2A ...@@ -314,7 +320,7 @@ func NewL2ImmutableConfig(config *DeployConfig, block *types.Block, l2Addrs *L2A
// NewL2StorageConfig will create a StorageConfig given an instance of a // NewL2StorageConfig will create a StorageConfig given an instance of a
// Hardhat and a DeployConfig. // Hardhat and a DeployConfig.
func NewL2StorageConfig(config *DeployConfig, block *types.Block, l2Addrs *L2Addresses) (state.StorageConfig, error) { func NewL2StorageConfig(config *DeployConfig, block *types.Block) (state.StorageConfig, error) {
storage := make(state.StorageConfig) storage := make(state.StorageConfig)
if block.Number() == nil { if block.Number() == nil {
...@@ -323,9 +329,6 @@ func NewL2StorageConfig(config *DeployConfig, block *types.Block, l2Addrs *L2Add ...@@ -323,9 +329,6 @@ func NewL2StorageConfig(config *DeployConfig, block *types.Block, l2Addrs *L2Add
if block.BaseFee() == nil { if block.BaseFee() == nil {
return storage, errors.New("block base fee not set") return storage, errors.New("block base fee not set")
} }
if l2Addrs == nil {
return storage, errors.New("must pass L1 address info")
}
storage["L2ToL1MessagePasser"] = state.StorageValues{ storage["L2ToL1MessagePasser"] = state.StorageValues{
"nonce": 0, "nonce": 0,
...@@ -368,7 +371,7 @@ func NewL2StorageConfig(config *DeployConfig, block *types.Block, l2Addrs *L2Add ...@@ -368,7 +371,7 @@ func NewL2StorageConfig(config *DeployConfig, block *types.Block, l2Addrs *L2Add
"_owner": common.Address{}, "_owner": common.Address{},
} }
storage["ProxyAdmin"] = state.StorageValues{ storage["ProxyAdmin"] = state.StorageValues{
"_owner": l2Addrs.ProxyAdminOwner, "_owner": config.ProxyAdminOwner,
} }
return storage, nil return storage, nil
} }
...@@ -20,7 +20,7 @@ import ( ...@@ -20,7 +20,7 @@ import (
var abiTrue = common.Hash{31: 0x01} var abiTrue = common.Hash{31: 0x01}
// MigrateDB will migrate an old l2geth database to the new bedrock style system // MigrateDB will migrate an old l2geth database to the new bedrock style system
func MigrateDB(ldb ethdb.Database, config *DeployConfig, l1Block *types.Block, l2Addrs *L2Addresses, migrationData *migration.MigrationData, commit bool) error { func MigrateDB(ldb ethdb.Database, config *DeployConfig, l1Block *types.Block, migrationData *migration.MigrationData, commit bool) error {
hash := rawdb.ReadHeadHeaderHash(ldb) hash := rawdb.ReadHeadHeaderHash(ldb)
num := rawdb.ReadHeaderNumber(ldb, hash) num := rawdb.ReadHeaderNumber(ldb, hash)
header := rawdb.ReadHeader(ldb, hash, *num) header := rawdb.ReadHeader(ldb, hash, *num)
...@@ -45,12 +45,12 @@ func MigrateDB(ldb ethdb.Database, config *DeployConfig, l1Block *types.Block, l ...@@ -45,12 +45,12 @@ func MigrateDB(ldb ethdb.Database, config *DeployConfig, l1Block *types.Block, l
return fmt.Errorf("cannot set L2Proxies: %w", err) return fmt.Errorf("cannot set L2Proxies: %w", err)
} }
storage, err := NewL2StorageConfig(config, l1Block, l2Addrs) storage, err := NewL2StorageConfig(config, l1Block)
if err != nil { if err != nil {
return fmt.Errorf("cannot create storage config: %w", err) return fmt.Errorf("cannot create storage config: %w", err)
} }
immutable, err := NewL2ImmutableConfig(config, l1Block, l2Addrs) immutable, err := NewL2ImmutableConfig(config, l1Block)
if err != nil { if err != nil {
return fmt.Errorf("cannot create immutable config: %w", err) return fmt.Errorf("cannot create immutable config: %w", err)
} }
...@@ -59,7 +59,7 @@ func MigrateDB(ldb ethdb.Database, config *DeployConfig, l1Block *types.Block, l ...@@ -59,7 +59,7 @@ func MigrateDB(ldb ethdb.Database, config *DeployConfig, l1Block *types.Block, l
return fmt.Errorf("cannot set implementations: %w", err) return fmt.Errorf("cannot set implementations: %w", err)
} }
err = crossdomain.MigrateWithdrawals(withdrawals, db, &l2Addrs.L1CrossDomainMessengerProxy, &l2Addrs.L1StandardBridgeProxy) err = crossdomain.MigrateWithdrawals(withdrawals, db, &config.L1CrossDomainMessengerProxy, &config.L1StandardBridgeProxy)
if err != nil { if err != nil {
return fmt.Errorf("cannot migrate withdrawals: %w", err) return fmt.Errorf("cannot migrate withdrawals: %w", err)
} }
......
package genesis package genesis
import ( import (
"github.com/ethereum-optimism/optimism/op-bindings/predeploys"
"github.com/ethereum-optimism/optimism/op-chain-ops/state" "github.com/ethereum-optimism/optimism/op-chain-ops/state"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core"
) )
// L2Addresses represents L1 contract addresses
// that are required for the construction of an L2 state
type L2Addresses struct {
// ProxyAdminOwner represents the admin of the L2 ProxyAdmin predeploy
ProxyAdminOwner common.Address
// L1StandardBridgeProxy represents the L1 contract address of the L1StandardBridgeProxy
L1StandardBridgeProxy common.Address
// L1CrossDomainMessengerProxy represents the L1 contract address of the L1CrossDomainMessengerProxy
L1CrossDomainMessengerProxy common.Address
// L1ERC721BridgeProxy represents the L1 contract address of the L1ERC721BridgeProxy
L1ERC721BridgeProxy common.Address
// SequencerFeeVaultRecipient represents the L1 address that the SequencerFeeVault can withdraw to
SequencerFeeVaultRecipient common.Address
// L1FeeVaultRecipient represents the L1 address that the L1FeeVault can withdraw to
L1FeeVaultRecipient common.Address
// BaseFeeVaultRecipient represents the L1 address that the BaseFeeVault can withdraw to
BaseFeeVaultRecipient common.Address
// SystemConfigProxy represents the L1 contract address of the SystemConfigProxy
SystemConfigProxy common.Address
}
// BuildL2DeveloperGenesis will build the developer Optimism Genesis // BuildL2DeveloperGenesis will build the developer Optimism Genesis
// Block. Suitable for devnets. // Block. Suitable for devnets.
func BuildL2DeveloperGenesis(config *DeployConfig, l1StartBlock *types.Block, l2Addrs *L2Addresses) (*core.Genesis, error) { func BuildL2DeveloperGenesis(config *DeployConfig, l1StartBlock *types.Block) (*core.Genesis, error) {
genspec, err := NewL2Genesis(config, l1StartBlock) genspec, err := NewL2Genesis(config, l1StartBlock)
if err != nil { if err != nil {
return nil, err return nil, err
...@@ -45,36 +22,21 @@ func BuildL2DeveloperGenesis(config *DeployConfig, l1StartBlock *types.Block, l2 ...@@ -45,36 +22,21 @@ func BuildL2DeveloperGenesis(config *DeployConfig, l1StartBlock *types.Block, l2
} }
SetPrecompileBalances(db) SetPrecompileBalances(db)
// Use the known developer addresses if they are not set return BuildL2Genesis(db, config, l1StartBlock)
if l2Addrs == nil {
l2Addrs = &L2Addresses{
L1StandardBridgeProxy: predeploys.DevL1StandardBridgeAddr,
L1CrossDomainMessengerProxy: predeploys.DevL1CrossDomainMessengerAddr,
L1ERC721BridgeProxy: predeploys.DevL1ERC721BridgeAddr,
SystemConfigProxy: predeploys.DevSystemConfigAddr,
// Hardcoded address corresponds to m/44'/60'/0'/0/1 in the 'test test... junk' mnemonic
ProxyAdminOwner: common.HexToAddress("0x70997970C51812dc3A010C7d01b50e0d17dc79C8"),
SequencerFeeVaultRecipient: common.HexToAddress("0x70997970C51812dc3A010C7d01b50e0d17dc79C8"),
L1FeeVaultRecipient: common.HexToAddress("0x70997970C51812dc3A010C7d01b50e0d17dc79C8"),
BaseFeeVaultRecipient: common.HexToAddress("0x70997970C51812dc3A010C7d01b50e0d17dc79C8"),
}
}
return BuildL2Genesis(db, config, l1StartBlock, l2Addrs)
} }
// BuildL2Genesis will build the L2 Optimism Genesis Block // BuildL2Genesis will build the L2 Optimism Genesis Block
func BuildL2Genesis(db *state.MemoryStateDB, config *DeployConfig, l1Block *types.Block, l2Addrs *L2Addresses) (*core.Genesis, error) { func BuildL2Genesis(db *state.MemoryStateDB, config *DeployConfig, l1Block *types.Block) (*core.Genesis, error) {
if err := SetL2Proxies(db); err != nil { if err := SetL2Proxies(db); err != nil {
return nil, err return nil, err
} }
storage, err := NewL2StorageConfig(config, l1Block, l2Addrs) storage, err := NewL2StorageConfig(config, l1Block)
if err != nil { if err != nil {
return nil, err return nil, err
} }
immutable, err := NewL2ImmutableConfig(config, l1Block, l2Addrs) immutable, err := NewL2ImmutableConfig(config, l1Block)
if err != nil { if err != nil {
return nil, err return nil, err
} }
......
...@@ -42,7 +42,7 @@ func TestBuildL2DeveloperGenesis(t *testing.T) { ...@@ -42,7 +42,7 @@ func TestBuildL2DeveloperGenesis(t *testing.T) {
block, err := backend.BlockByNumber(context.Background(), common.Big0) block, err := backend.BlockByNumber(context.Background(), common.Big0)
require.NoError(t, err) require.NoError(t, err)
gen, err := genesis.BuildL2DeveloperGenesis(config, block, nil) gen, err := genesis.BuildL2DeveloperGenesis(config, block)
require.Nil(t, err) require.Nil(t, err)
require.NotNil(t, gen) require.NotNil(t, gen)
...@@ -78,6 +78,9 @@ func TestBuildL2DeveloperGenesisDevAccountsFunding(t *testing.T) { ...@@ -78,6 +78,9 @@ func TestBuildL2DeveloperGenesisDevAccountsFunding(t *testing.T) {
require.Nil(t, err) require.Nil(t, err)
config.FundDevAccounts = false config.FundDevAccounts = false
err = config.GetDeveloperDeployedAddresses()
require.NoError(t, err)
backend := backends.NewSimulatedBackend( backend := backends.NewSimulatedBackend(
core.GenesisAlloc{ core.GenesisAlloc{
crypto.PubkeyToAddress(testKey.PublicKey): {Balance: big.NewInt(10000000000000000)}, crypto.PubkeyToAddress(testKey.PublicKey): {Balance: big.NewInt(10000000000000000)},
...@@ -87,7 +90,7 @@ func TestBuildL2DeveloperGenesisDevAccountsFunding(t *testing.T) { ...@@ -87,7 +90,7 @@ func TestBuildL2DeveloperGenesisDevAccountsFunding(t *testing.T) {
block, err := backend.BlockByNumber(context.Background(), common.Big0) block, err := backend.BlockByNumber(context.Background(), common.Big0)
require.NoError(t, err) require.NoError(t, err)
gen, err := genesis.BuildL2DeveloperGenesis(config, block, nil) gen, err := genesis.BuildL2DeveloperGenesis(config, block)
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, 2321, len(gen.Alloc)) require.Equal(t, 2321, len(gen.Alloc))
} }
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
"baseFeeVaultRecipient": "0xBcd4042DE499D14e55001CcbB24a551F3b954096", "baseFeeVaultRecipient": "0xBcd4042DE499D14e55001CcbB24a551F3b954096",
"l1FeeVaultRecipient": "0x71bE63f3384f5fb98995898A86B02Fb2426c5788", "l1FeeVaultRecipient": "0x71bE63f3384f5fb98995898A86B02Fb2426c5788",
"sequencerFeeVaultRecipient": "0x71bE63f3384f5fb98995898A86B02Fb2426c5788", "sequencerFeeVaultRecipient": "0x71bE63f3384f5fb98995898A86B02Fb2426c5788",
"l1ERC721BridgeProxy": "0xff000000000000000000000000000000000000ff",
"deploymentWaitConfirmations": 1, "deploymentWaitConfirmations": 1,
"fundDevAccounts": true "fundDevAccounts": true
......
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