From f0ef708507b521b2046b6a7646fd60a82301e167 Mon Sep 17 00:00:00 2001 From: Hamdi Allam Date: Fri, 26 Jul 2024 19:10:01 -0400 Subject: [PATCH] chore: merge genesisapplier & genesisdeployment (#63) * genesis package * nits --- config/chain.go | 22 ++++++------- genesis/applier.go | 27 +++++++++++++++ .../deployment.go | 2 +- .../generated/addresses/901-addresses.json | 0 .../generated/addresses/902-addresses.json | 0 .../generated/addresses/903-addresses.json | 0 .../generated/addresses/904-addresses.json | 0 .../generated/addresses/905-addresses.json | 0 .../deploy-configs/901-deploy-config.json | 0 .../deploy-configs/902-deploy-config.json | 0 .../deploy-configs/903-deploy-config.json | 0 .../deploy-configs/904-deploy-config.json | 0 .../deploy-configs/905-deploy-config.json | 0 .../generated/l1-allocs/901-l1-allocs.json | 0 .../generated/l1-allocs/902-l1-allocs.json | 0 .../generated/l1-allocs/903-l1-allocs.json | 0 .../generated/l1-allocs/904-l1-allocs.json | 0 .../generated/l1-allocs/905-l1-allocs.json | 0 .../generated/l1-combined-allocs.json | 0 .../generated/l1-genesis.json | 0 .../generated/l2-allocs/901-l2-allocs.json | 0 .../generated/l2-allocs/902-l2-allocs.json | 0 .../generated/l2-allocs/903-l2-allocs.json | 0 .../generated/l2-allocs/904-l2-allocs.json | 0 .../generated/l2-allocs/905-l2-allocs.json | 0 .../generated/l2-genesis/901-l2-genesis.json | 0 .../generated/l2-genesis/902-l2-genesis.json | 0 .../generated/l2-genesis/903-l2-genesis.json | 0 .../generated/l2-genesis/904-l2-genesis.json | 0 .../generated/l2-genesis/905-l2-genesis.json | 0 .../rollup-configs/901-rollup-config.json | 0 .../rollup-configs/902-rollup-config.json | 0 .../rollup-configs/903-rollup-config.json | 0 .../rollup-configs/904-rollup-config.json | 0 .../rollup-configs/905-rollup-config.json | 0 genesisapplier/genesisapplier.go | 33 ------------------- 36 files changed, 39 insertions(+), 45 deletions(-) create mode 100644 genesis/applier.go rename genesisdeployment/genesisdeployment.go => genesis/deployment.go (99%) rename {genesisdeployment => genesis}/generated/addresses/901-addresses.json (100%) rename {genesisdeployment => genesis}/generated/addresses/902-addresses.json (100%) rename {genesisdeployment => genesis}/generated/addresses/903-addresses.json (100%) rename {genesisdeployment => genesis}/generated/addresses/904-addresses.json (100%) rename {genesisdeployment => genesis}/generated/addresses/905-addresses.json (100%) rename {genesisdeployment => genesis}/generated/deploy-configs/901-deploy-config.json (100%) rename {genesisdeployment => genesis}/generated/deploy-configs/902-deploy-config.json (100%) rename {genesisdeployment => genesis}/generated/deploy-configs/903-deploy-config.json (100%) rename {genesisdeployment => genesis}/generated/deploy-configs/904-deploy-config.json (100%) rename {genesisdeployment => genesis}/generated/deploy-configs/905-deploy-config.json (100%) rename {genesisdeployment => genesis}/generated/l1-allocs/901-l1-allocs.json (100%) rename {genesisdeployment => genesis}/generated/l1-allocs/902-l1-allocs.json (100%) rename {genesisdeployment => genesis}/generated/l1-allocs/903-l1-allocs.json (100%) rename {genesisdeployment => genesis}/generated/l1-allocs/904-l1-allocs.json (100%) rename {genesisdeployment => genesis}/generated/l1-allocs/905-l1-allocs.json (100%) rename {genesisdeployment => genesis}/generated/l1-combined-allocs.json (100%) rename {genesisdeployment => genesis}/generated/l1-genesis.json (100%) rename {genesisdeployment => genesis}/generated/l2-allocs/901-l2-allocs.json (100%) rename {genesisdeployment => genesis}/generated/l2-allocs/902-l2-allocs.json (100%) rename {genesisdeployment => genesis}/generated/l2-allocs/903-l2-allocs.json (100%) rename {genesisdeployment => genesis}/generated/l2-allocs/904-l2-allocs.json (100%) rename {genesisdeployment => genesis}/generated/l2-allocs/905-l2-allocs.json (100%) rename {genesisdeployment => genesis}/generated/l2-genesis/901-l2-genesis.json (100%) rename {genesisdeployment => genesis}/generated/l2-genesis/902-l2-genesis.json (100%) rename {genesisdeployment => genesis}/generated/l2-genesis/903-l2-genesis.json (100%) rename {genesisdeployment => genesis}/generated/l2-genesis/904-l2-genesis.json (100%) rename {genesisdeployment => genesis}/generated/l2-genesis/905-l2-genesis.json (100%) rename {genesisdeployment => genesis}/generated/rollup-configs/901-rollup-config.json (100%) rename {genesisdeployment => genesis}/generated/rollup-configs/902-rollup-config.json (100%) rename {genesisdeployment => genesis}/generated/rollup-configs/903-rollup-config.json (100%) rename {genesisdeployment => genesis}/generated/rollup-configs/904-rollup-config.json (100%) rename {genesisdeployment => genesis}/generated/rollup-configs/905-rollup-config.json (100%) delete mode 100644 genesisapplier/genesisapplier.go diff --git a/config/chain.go b/config/chain.go index 1f636f9f..3f525459 100644 --- a/config/chain.go +++ b/config/chain.go @@ -6,7 +6,7 @@ import ( "strings" registry "github.com/ethereum-optimism/superchain-registry/superchain" - "github.com/ethereum-optimism/supersim/genesisdeployment" + "github.com/ethereum-optimism/supersim/genesis" "github.com/ethereum-optimism/supersim/hdaccount" "github.com/ethereum/go-ethereum" @@ -25,28 +25,28 @@ var ( DefaultChainConfigs = []ChainConfig{ { Name: "SourceChain", - ChainID: genesisdeployment.GeneratedGenesisDeployment.L1.ChainID, + ChainID: genesis.GeneratedGenesisDeployment.L1.ChainID, SecretsConfig: DefaultSecretsConfig, - GenesisJSON: genesisdeployment.GeneratedGenesisDeployment.L1.GenesisJSON, + GenesisJSON: genesis.GeneratedGenesisDeployment.L1.GenesisJSON, }, { Name: "OPChainA", - ChainID: genesisdeployment.GeneratedGenesisDeployment.L2s[0].ChainID, + ChainID: genesis.GeneratedGenesisDeployment.L2s[0].ChainID, SecretsConfig: DefaultSecretsConfig, - GenesisJSON: genesisdeployment.GeneratedGenesisDeployment.L2s[0].GenesisJSON, + GenesisJSON: genesis.GeneratedGenesisDeployment.L2s[0].GenesisJSON, L2Config: &L2Config{ - L1ChainID: genesisdeployment.GeneratedGenesisDeployment.L1.ChainID, - L1Addresses: genesisdeployment.GeneratedGenesisDeployment.L2s[0].RegistryAddressList(), + L1ChainID: genesis.GeneratedGenesisDeployment.L1.ChainID, + L1Addresses: genesis.GeneratedGenesisDeployment.L2s[0].RegistryAddressList(), }, }, { Name: "OPChainB", - ChainID: genesisdeployment.GeneratedGenesisDeployment.L2s[1].ChainID, + ChainID: genesis.GeneratedGenesisDeployment.L2s[1].ChainID, SecretsConfig: DefaultSecretsConfig, - GenesisJSON: genesisdeployment.GeneratedGenesisDeployment.L2s[1].GenesisJSON, + GenesisJSON: genesis.GeneratedGenesisDeployment.L2s[1].GenesisJSON, L2Config: &L2Config{ - L1ChainID: genesisdeployment.GeneratedGenesisDeployment.L1.ChainID, - L1Addresses: genesisdeployment.GeneratedGenesisDeployment.L2s[1].RegistryAddressList(), + L1ChainID: genesis.GeneratedGenesisDeployment.L1.ChainID, + L1Addresses: genesis.GeneratedGenesisDeployment.L2s[1].RegistryAddressList(), }, }, } diff --git a/genesis/applier.go b/genesis/applier.go new file mode 100644 index 00000000..232ebe5b --- /dev/null +++ b/genesis/applier.go @@ -0,0 +1,27 @@ +package genesis + +import ( + "encoding/json" + "fmt" + "math/big" + + "github.com/ethereum/go-ethereum/core" +) + +func ApplyChainID(genesisJson []byte, chainId *big.Int) ([]byte, error) { + var genesis core.Genesis + if err := json.Unmarshal(genesisJson, &genesis); err != nil { + return nil, fmt.Errorf("unable to parse genesis json: %w", err) + } + + if genesis.Config.ChainID.Cmp(chainId) != 0 { + genesis.Config.ChainID = chainId + } + + result, err := json.Marshal(genesis) + if err != nil { + return nil, fmt.Errorf("error marshaling genesis: %w", err) + } + + return result, nil +} diff --git a/genesisdeployment/genesisdeployment.go b/genesis/deployment.go similarity index 99% rename from genesisdeployment/genesisdeployment.go rename to genesis/deployment.go index 5529dba6..1d83ad35 100644 --- a/genesisdeployment/genesisdeployment.go +++ b/genesis/deployment.go @@ -1,4 +1,4 @@ -package genesisdeployment +package genesis import ( _ "embed" diff --git a/genesisdeployment/generated/addresses/901-addresses.json b/genesis/generated/addresses/901-addresses.json similarity index 100% rename from genesisdeployment/generated/addresses/901-addresses.json rename to genesis/generated/addresses/901-addresses.json diff --git a/genesisdeployment/generated/addresses/902-addresses.json b/genesis/generated/addresses/902-addresses.json similarity index 100% rename from genesisdeployment/generated/addresses/902-addresses.json rename to genesis/generated/addresses/902-addresses.json diff --git a/genesisdeployment/generated/addresses/903-addresses.json b/genesis/generated/addresses/903-addresses.json similarity index 100% rename from genesisdeployment/generated/addresses/903-addresses.json rename to genesis/generated/addresses/903-addresses.json diff --git a/genesisdeployment/generated/addresses/904-addresses.json b/genesis/generated/addresses/904-addresses.json similarity index 100% rename from genesisdeployment/generated/addresses/904-addresses.json rename to genesis/generated/addresses/904-addresses.json diff --git a/genesisdeployment/generated/addresses/905-addresses.json b/genesis/generated/addresses/905-addresses.json similarity index 100% rename from genesisdeployment/generated/addresses/905-addresses.json rename to genesis/generated/addresses/905-addresses.json diff --git a/genesisdeployment/generated/deploy-configs/901-deploy-config.json b/genesis/generated/deploy-configs/901-deploy-config.json similarity index 100% rename from genesisdeployment/generated/deploy-configs/901-deploy-config.json rename to genesis/generated/deploy-configs/901-deploy-config.json diff --git a/genesisdeployment/generated/deploy-configs/902-deploy-config.json b/genesis/generated/deploy-configs/902-deploy-config.json similarity index 100% rename from genesisdeployment/generated/deploy-configs/902-deploy-config.json rename to genesis/generated/deploy-configs/902-deploy-config.json diff --git a/genesisdeployment/generated/deploy-configs/903-deploy-config.json b/genesis/generated/deploy-configs/903-deploy-config.json similarity index 100% rename from genesisdeployment/generated/deploy-configs/903-deploy-config.json rename to genesis/generated/deploy-configs/903-deploy-config.json diff --git a/genesisdeployment/generated/deploy-configs/904-deploy-config.json b/genesis/generated/deploy-configs/904-deploy-config.json similarity index 100% rename from genesisdeployment/generated/deploy-configs/904-deploy-config.json rename to genesis/generated/deploy-configs/904-deploy-config.json diff --git a/genesisdeployment/generated/deploy-configs/905-deploy-config.json b/genesis/generated/deploy-configs/905-deploy-config.json similarity index 100% rename from genesisdeployment/generated/deploy-configs/905-deploy-config.json rename to genesis/generated/deploy-configs/905-deploy-config.json diff --git a/genesisdeployment/generated/l1-allocs/901-l1-allocs.json b/genesis/generated/l1-allocs/901-l1-allocs.json similarity index 100% rename from genesisdeployment/generated/l1-allocs/901-l1-allocs.json rename to genesis/generated/l1-allocs/901-l1-allocs.json diff --git a/genesisdeployment/generated/l1-allocs/902-l1-allocs.json b/genesis/generated/l1-allocs/902-l1-allocs.json similarity index 100% rename from genesisdeployment/generated/l1-allocs/902-l1-allocs.json rename to genesis/generated/l1-allocs/902-l1-allocs.json diff --git a/genesisdeployment/generated/l1-allocs/903-l1-allocs.json b/genesis/generated/l1-allocs/903-l1-allocs.json similarity index 100% rename from genesisdeployment/generated/l1-allocs/903-l1-allocs.json rename to genesis/generated/l1-allocs/903-l1-allocs.json diff --git a/genesisdeployment/generated/l1-allocs/904-l1-allocs.json b/genesis/generated/l1-allocs/904-l1-allocs.json similarity index 100% rename from genesisdeployment/generated/l1-allocs/904-l1-allocs.json rename to genesis/generated/l1-allocs/904-l1-allocs.json diff --git a/genesisdeployment/generated/l1-allocs/905-l1-allocs.json b/genesis/generated/l1-allocs/905-l1-allocs.json similarity index 100% rename from genesisdeployment/generated/l1-allocs/905-l1-allocs.json rename to genesis/generated/l1-allocs/905-l1-allocs.json diff --git a/genesisdeployment/generated/l1-combined-allocs.json b/genesis/generated/l1-combined-allocs.json similarity index 100% rename from genesisdeployment/generated/l1-combined-allocs.json rename to genesis/generated/l1-combined-allocs.json diff --git a/genesisdeployment/generated/l1-genesis.json b/genesis/generated/l1-genesis.json similarity index 100% rename from genesisdeployment/generated/l1-genesis.json rename to genesis/generated/l1-genesis.json diff --git a/genesisdeployment/generated/l2-allocs/901-l2-allocs.json b/genesis/generated/l2-allocs/901-l2-allocs.json similarity index 100% rename from genesisdeployment/generated/l2-allocs/901-l2-allocs.json rename to genesis/generated/l2-allocs/901-l2-allocs.json diff --git a/genesisdeployment/generated/l2-allocs/902-l2-allocs.json b/genesis/generated/l2-allocs/902-l2-allocs.json similarity index 100% rename from genesisdeployment/generated/l2-allocs/902-l2-allocs.json rename to genesis/generated/l2-allocs/902-l2-allocs.json diff --git a/genesisdeployment/generated/l2-allocs/903-l2-allocs.json b/genesis/generated/l2-allocs/903-l2-allocs.json similarity index 100% rename from genesisdeployment/generated/l2-allocs/903-l2-allocs.json rename to genesis/generated/l2-allocs/903-l2-allocs.json diff --git a/genesisdeployment/generated/l2-allocs/904-l2-allocs.json b/genesis/generated/l2-allocs/904-l2-allocs.json similarity index 100% rename from genesisdeployment/generated/l2-allocs/904-l2-allocs.json rename to genesis/generated/l2-allocs/904-l2-allocs.json diff --git a/genesisdeployment/generated/l2-allocs/905-l2-allocs.json b/genesis/generated/l2-allocs/905-l2-allocs.json similarity index 100% rename from genesisdeployment/generated/l2-allocs/905-l2-allocs.json rename to genesis/generated/l2-allocs/905-l2-allocs.json diff --git a/genesisdeployment/generated/l2-genesis/901-l2-genesis.json b/genesis/generated/l2-genesis/901-l2-genesis.json similarity index 100% rename from genesisdeployment/generated/l2-genesis/901-l2-genesis.json rename to genesis/generated/l2-genesis/901-l2-genesis.json diff --git a/genesisdeployment/generated/l2-genesis/902-l2-genesis.json b/genesis/generated/l2-genesis/902-l2-genesis.json similarity index 100% rename from genesisdeployment/generated/l2-genesis/902-l2-genesis.json rename to genesis/generated/l2-genesis/902-l2-genesis.json diff --git a/genesisdeployment/generated/l2-genesis/903-l2-genesis.json b/genesis/generated/l2-genesis/903-l2-genesis.json similarity index 100% rename from genesisdeployment/generated/l2-genesis/903-l2-genesis.json rename to genesis/generated/l2-genesis/903-l2-genesis.json diff --git a/genesisdeployment/generated/l2-genesis/904-l2-genesis.json b/genesis/generated/l2-genesis/904-l2-genesis.json similarity index 100% rename from genesisdeployment/generated/l2-genesis/904-l2-genesis.json rename to genesis/generated/l2-genesis/904-l2-genesis.json diff --git a/genesisdeployment/generated/l2-genesis/905-l2-genesis.json b/genesis/generated/l2-genesis/905-l2-genesis.json similarity index 100% rename from genesisdeployment/generated/l2-genesis/905-l2-genesis.json rename to genesis/generated/l2-genesis/905-l2-genesis.json diff --git a/genesisdeployment/generated/rollup-configs/901-rollup-config.json b/genesis/generated/rollup-configs/901-rollup-config.json similarity index 100% rename from genesisdeployment/generated/rollup-configs/901-rollup-config.json rename to genesis/generated/rollup-configs/901-rollup-config.json diff --git a/genesisdeployment/generated/rollup-configs/902-rollup-config.json b/genesis/generated/rollup-configs/902-rollup-config.json similarity index 100% rename from genesisdeployment/generated/rollup-configs/902-rollup-config.json rename to genesis/generated/rollup-configs/902-rollup-config.json diff --git a/genesisdeployment/generated/rollup-configs/903-rollup-config.json b/genesis/generated/rollup-configs/903-rollup-config.json similarity index 100% rename from genesisdeployment/generated/rollup-configs/903-rollup-config.json rename to genesis/generated/rollup-configs/903-rollup-config.json diff --git a/genesisdeployment/generated/rollup-configs/904-rollup-config.json b/genesis/generated/rollup-configs/904-rollup-config.json similarity index 100% rename from genesisdeployment/generated/rollup-configs/904-rollup-config.json rename to genesis/generated/rollup-configs/904-rollup-config.json diff --git a/genesisdeployment/generated/rollup-configs/905-rollup-config.json b/genesis/generated/rollup-configs/905-rollup-config.json similarity index 100% rename from genesisdeployment/generated/rollup-configs/905-rollup-config.json rename to genesis/generated/rollup-configs/905-rollup-config.json diff --git a/genesisapplier/genesisapplier.go b/genesisapplier/genesisapplier.go deleted file mode 100644 index f6817612..00000000 --- a/genesisapplier/genesisapplier.go +++ /dev/null @@ -1,33 +0,0 @@ -package genesisapplier - -import ( - "encoding/json" - "fmt" - "math/big" - - "github.com/ethereum/go-ethereum/core" -) - -type Config struct { - ChainID *big.Int -} - -func UpdateGenesisWithConfig(genesisJson []byte, config Config) ([]byte, error) { - var genesis core.Genesis - - err := json.Unmarshal(genesisJson, &genesis) - if err != nil { - return nil, fmt.Errorf("unable to parse genesis json") - } - - if config.ChainID != nil && genesis.Config.ChainID != config.ChainID { - genesis.Config.ChainID = config.ChainID - } - - result, err := json.Marshal(genesis) - if err != nil { - return nil, fmt.Errorf("error marshaling genesis") - } - - return result, nil -}