From 0a5d64a0ef5e72d570aab94619cc740b9b19da70 Mon Sep 17 00:00:00 2001 From: geoknee Date: Thu, 22 Aug 2024 15:54:15 +0100 Subject: [PATCH 01/15] add-chain: ingest and store deploy-config and genesis-creation commit --- .env.example | 9 +++++++- add-chain/flags/flags.go | 12 +++++++++++ add-chain/main.go | 45 +++++++++++++++++++++++++++++++++++++++- 3 files changed, 64 insertions(+), 2 deletions(-) diff --git a/.env.example b/.env.example index 6edb20be5b..2a16f03b31 100644 --- a/.env.example +++ b/.env.example @@ -21,11 +21,18 @@ SCR_STANDARD_CHAIN_CANDIDATE=false # It is defined for convenience and reuse by other vars below SCR_MONOREPO_DIR=../optimism # path to local "ethereum-optimism/optimism" monorepo -# The following vars point to three input files required for adding a chain +# The following vars point to four input files required for adding a chain # Data will be scraped from these files in order to construct the required registry data +# and for genesis validation purposes. SCR_DEPLOYMENTS_DIR=${SCR_MONOREPO_DIR}/packages/contracts-bedrock/deployments/getting-started SCR_ROLLUP_CONFIG=${SCR_MONOREPO_DIR}/op-node/rollup.json SCR_GENESIS=${SCR_MONOREPO_DIR}/op-node/genesis.json +SCR_DEPLOY_CONFIG=${SCR_MONOREPO_DIR}/packages/contracts-bedrock/deploy-config/getting-started.json + +# This is the commit in the https://github.com/ethereum-optimism/optimism/ repo +# at which the chain's genesis was created. This is necessary to have out validation checks +# recreate the genesis file using identical source code +SCR_GENESIS_CREATION_COMMIT="" # Your chain's endpoint for ETHEREUM JSON-RPC requests SCR_PUBLIC_RPC="http://awe.some.rpc" # new OP Stack L2 RPC URL diff --git a/add-chain/flags/flags.go b/add-chain/flags/flags.go index 53fc057b90..ec127405e9 100644 --- a/add-chain/flags/flags.go +++ b/add-chain/flags/flags.go @@ -70,6 +70,18 @@ var ( Usage: "Filepath to rollup.json input file", Required: true, } + DeployConfigFlag = &cli.StringFlag{ + Name: "deploy-config", + EnvVars: prefixEnvVars("DEPLOY_CONFIG"), + Usage: "Filepath to deploy-config json input file", + Required: true, + } + GenesisCreationCommit = &cli.StringFlag{ + Name: "genesis-creation-commit", + EnvVars: prefixEnvVars("GENESIS_CREATION_COMMIT"), + Usage: "Commit in the https://github.com/ethereum-optimism/optimism/ repo at which the chain's genesis was created", + Required: true, + } GenesisFlag = &cli.StringFlag{ Name: "genesis", EnvVars: prefixEnvVars("GENESIS"), diff --git a/add-chain/main.go b/add-chain/main.go index b93e9f637f..423ca0530f 100644 --- a/add-chain/main.go +++ b/add-chain/main.go @@ -3,16 +3,19 @@ package main import ( "fmt" "os" + "path" "path/filepath" "runtime" "strconv" "strings" + "github.com/BurntSushi/toml" "github.com/ethereum-optimism/optimism/op-e2e/bindings" "github.com/ethereum-optimism/superchain-registry/add-chain/cmd" "github.com/ethereum-optimism/superchain-registry/add-chain/config" "github.com/ethereum-optimism/superchain-registry/add-chain/flags" "github.com/ethereum-optimism/superchain-registry/superchain" + "github.com/ethereum-optimism/superchain-registry/validation/genesis" "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/ethclient" @@ -87,6 +90,8 @@ func entrypoint(ctx *cli.Context) error { chainName := ctx.String(flags.ChainNameFlag.Name) rollupConfigPath := ctx.String(flags.RollupConfigFlag.Name) + deployConfigPath := ctx.String(flags.DeployConfigFlag.Name) + genesisCreationCommit := ctx.String(flags.GenesisCreationCommit.Name) deploymentsDir := ctx.String(flags.DeploymentsDirFlag.Name) chainShortName := ctx.String(flags.ChainShortNameFlag.Name) if chainShortName == "" { @@ -107,6 +112,8 @@ func entrypoint(ctx *cli.Context) error { fmt.Printf("Monorepo dir: %s\n", monorepoDir) fmt.Printf("Deployments directory: %s\n", deploymentsDir) fmt.Printf("Rollup config filepath: %s\n", rollupConfigPath) + fmt.Printf("Deploy config filepath: %s\n", deployConfigPath) + fmt.Printf("Genesis creation commit: %s\n", genesisCreationCommit) fmt.Printf("Public RPC endpoint: %s\n", publicRPC) fmt.Printf("Sequencer RPC endpoint: %s\n", sequencerRPC) fmt.Printf("Block Explorer: %s\n", explorer) @@ -166,7 +173,21 @@ func entrypoint(ctx *cli.Context) error { return fmt.Errorf("error generating chain config .yaml file: %w", err) } - fmt.Printf("Wrote config for new chain with identifier %s", rollupConfig.Identifier()) + fmt.Printf("✅ Wrote config for new chain with identifier %s", rollupConfig.Identifier()) + + genesisValidationInputsDir := filepath.Join(superchainRepoRoot, "validation", "genesis", "validation-inputs") + copyDeployConfigFile(rollupConfig.ChainID, deployConfigPath, genesisValidationInputsDir) + if err != nil { + return fmt.Errorf("error copying deploy-config json file: %w", err) + } + fmt.Printf("✅ Copied deploy-config json file to validation module") + + writeGenesisValidationMetadata(rollupConfig.ChainID, genesisCreationCommit, genesisValidationInputsDir) + if err != nil { + return fmt.Errorf("error writing genesis validation metadata file: %w", err) + } + fmt.Printf("✅ Wrote genesis validation metadata file") + return nil } @@ -227,3 +248,25 @@ func getGasPayingToken(l1rpcURl string, SystemConfigAddress superchain.Address) return (*superchain.Address)(&result.Addr), nil } + +func copyDeployConfigFile(chainId uint64, sourcePath string, targetDir string) error { + data, err := os.ReadFile(sourcePath) + if err != nil { + return err + } + return os.WriteFile(path.Join(targetDir, fmt.Sprintf("%d", chainId), "deploy-config.json"), data, 0777) +} + +func writeGenesisValidationMetadata(chainId uint64, commit string, targetDir string) error { + vm := genesis.ValidationMetadata{ + GenesisCreationCommit: commit, + NodeVersion: "18.12.1", + MonorepoBuildCommand: "pnpm", + GenesisCreationCommand: "opnode1", + } + data, err := toml.Marshal(vm) + if err != nil { + return err + } + return os.WriteFile(path.Join(targetDir, fmt.Sprintf("%d", chainId), "meta.toml"), data, 0777) +} From 1137921123b89e0580f5f19dde826a4a9326ed6b Mon Sep 17 00:00:00 2001 From: geoknee Date: Thu, 22 Aug 2024 16:06:42 +0100 Subject: [PATCH 02/15] remove genesis-system-configs dir we no longer use this --- add-chain/e2e_test.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/add-chain/e2e_test.go b/add-chain/e2e_test.go index 885cd1fcd5..2e777afd70 100644 --- a/add-chain/e2e_test.go +++ b/add-chain/e2e_test.go @@ -10,9 +10,8 @@ import ( ) const ( - addressDir = "../superchain/extra/addresses/sepolia/" - configDir = "../superchain/configs/sepolia/" - genesisSystemConfigDir = "../superchain/extra/genesis-system-configs/sepolia/" + addressDir = "../superchain/extra/addresses/sepolia/" + configDir = "../superchain/configs/sepolia/" ) var tests = []struct { @@ -171,7 +170,6 @@ func checkConfigTOML(t *testing.T, testName, chainShortName string) { func cleanupTestFiles(t *testing.T, chainShortName string) { paths := []string{ addressDir + chainShortName + ".json", - genesisSystemConfigDir + chainShortName + ".json", configDir + chainShortName + ".toml", } From d9d43744d4ac299112f3875d4fb207b87060b6ee Mon Sep 17 00:00:00 2001 From: geoknee Date: Thu, 22 Aug 2024 16:27:50 +0100 Subject: [PATCH 03/15] add test data for deploy-config --- add-chain/testdata/.env.test | 2 + .../monorepo/deploy-config.json/sepolia.json | 41 +++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 add-chain/testdata/monorepo/deploy-config.json/sepolia.json diff --git a/add-chain/testdata/.env.test b/add-chain/testdata/.env.test index d5291cdde1..13c6763cfb 100644 --- a/add-chain/testdata/.env.test +++ b/add-chain/testdata/.env.test @@ -4,6 +4,8 @@ SCR_SUPERCHAIN_TARGET=sepolia # L1 chain name SCR_MONOREPO_DIR=./testdata/monorepo SCR_DEPLOYMENTS_DIR=${SCR_MONOREPO_DIR}/deployments SCR_ROLLUP_CONFIG=${SCR_MONOREPO_DIR}/op-node/rollup.json +SCR_GENESIS_CREATION_COMMIT=somecommit +SCR_DEPLOY_CONFIG=${SCR_MONOREPO_DIR}/deploy-config/sepolia.json SCR_PUBLIC_RPC="http://awe.some.rpc" # L2 RPC URL SCR_SEQUENCER_RPC="http://awe.some.seq.rpc" SCR_EXPLORER="https://awesomescan.org" # L2 block explorer URL diff --git a/add-chain/testdata/monorepo/deploy-config.json/sepolia.json b/add-chain/testdata/monorepo/deploy-config.json/sepolia.json new file mode 100644 index 0000000000..bcc13611fe --- /dev/null +++ b/add-chain/testdata/monorepo/deploy-config.json/sepolia.json @@ -0,0 +1,41 @@ +{ + "finalSystemOwner": "0xfd1D2e729aE8eEe2E146c033bf4400fE75284301", + "portalGuardian": "0xfd1D2e729aE8eEe2E146c033bf4400fE75284301", + "l1StartingBlockTag": "0x70e5634d09793b1cfaa7d0a2a5d3289a3b2308de1e82f682b4f817fc670f9797", + "l1ChainID": 11155111, + "l2ChainID": 11155420, + "l2BlockTime": 2, + "maxSequencerDrift": 600, + "sequencerWindowSize": 3600, + "channelTimeout": 300, + "p2pSequencerAddress": "0x715b7219D986641DF9eFd9C7Ef01218D528e19ec", + "batchInboxAddress": "0xff00000000000000000000000000000011155420", + "batchSenderAddress": "0x7431310e026B69BFC676C0013E12A1A11411EEc9", + "l2OutputOracleSubmissionInterval": 120, + "l2OutputOracleStartingBlockNumber": 0, + "l2OutputOracleStartingTimestamp": 0, + "l2OutputOracleProposer": "0x02b1786A85Ec3f71fBbBa46507780dB7cF9014f6", + "l2OutputOracleChallenger": "0xfd1D2e729aE8eEe2E146c033bf4400fE75284301", + "finalizationPeriodSeconds": 12, + "proxyAdminOwner": "0xfd1D2e729aE8eEe2E146c033bf4400fE75284301", + "baseFeeVaultRecipient": "0xfd1D2e729aE8eEe2E146c033bf4400fE75284301", + "l1FeeVaultRecipient": "0xfd1D2e729aE8eEe2E146c033bf4400fE75284301", + "sequencerFeeVaultRecipient": "0xfd1D2e729aE8eEe2E146c033bf4400fE75284301", + "baseFeeVaultMinimumWithdrawalAmount": "0x8ac7230489e80000", + "l1FeeVaultMinimumWithdrawalAmount": "0x8ac7230489e80000", + "sequencerFeeVaultMinimumWithdrawalAmount": "0x8ac7230489e80000", + "baseFeeVaultWithdrawalNetwork": 0, + "l1FeeVaultWithdrawalNetwork": 0, + "sequencerFeeVaultWithdrawalNetwork": 0, + "gasPriceOracleOverhead": 188, + "gasPriceOracleScalar": 684000, + "enableGovernance": true, + "governanceTokenSymbol": "OP", + "governanceTokenName": "Optimism", + "governanceTokenOwner": "0xfd1D2e729aE8eEe2E146c033bf4400fE75284301", + "l2GenesisBlockGasLimit": "0x1c9c380", + "l2GenesisBlockBaseFeePerGas": "0x3b9aca00", + "eip1559Denominator": 50, + "eip1559Elasticity": 6, + "l2GenesisRegolithTimeOffset": "0x0" +} From c9ba92fd3c2c5b1412fe6f868de159832b67dbec Mon Sep 17 00:00:00 2001 From: geoknee Date: Thu, 22 Aug 2024 17:23:30 +0100 Subject: [PATCH 04/15] check errs properly --- add-chain/main.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/add-chain/main.go b/add-chain/main.go index 423ca0530f..5c3def315b 100644 --- a/add-chain/main.go +++ b/add-chain/main.go @@ -176,13 +176,13 @@ func entrypoint(ctx *cli.Context) error { fmt.Printf("✅ Wrote config for new chain with identifier %s", rollupConfig.Identifier()) genesisValidationInputsDir := filepath.Join(superchainRepoRoot, "validation", "genesis", "validation-inputs") - copyDeployConfigFile(rollupConfig.ChainID, deployConfigPath, genesisValidationInputsDir) + err = copyDeployConfigFile(rollupConfig.ChainID, deployConfigPath, genesisValidationInputsDir) if err != nil { return fmt.Errorf("error copying deploy-config json file: %w", err) } fmt.Printf("✅ Copied deploy-config json file to validation module") - writeGenesisValidationMetadata(rollupConfig.ChainID, genesisCreationCommit, genesisValidationInputsDir) + err = writeGenesisValidationMetadata(rollupConfig.ChainID, genesisCreationCommit, genesisValidationInputsDir) if err != nil { return fmt.Errorf("error writing genesis validation metadata file: %w", err) } @@ -254,7 +254,7 @@ func copyDeployConfigFile(chainId uint64, sourcePath string, targetDir string) e if err != nil { return err } - return os.WriteFile(path.Join(targetDir, fmt.Sprintf("%d", chainId), "deploy-config.json"), data, 0777) + return os.WriteFile(path.Join(targetDir, fmt.Sprintf("%d", chainId), "deploy-config.json"), data, 0o777) } func writeGenesisValidationMetadata(chainId uint64, commit string, targetDir string) error { @@ -268,5 +268,5 @@ func writeGenesisValidationMetadata(chainId uint64, commit string, targetDir str if err != nil { return err } - return os.WriteFile(path.Join(targetDir, fmt.Sprintf("%d", chainId), "meta.toml"), data, 0777) + return os.WriteFile(path.Join(targetDir, fmt.Sprintf("%d", chainId), "meta.toml"), data, 0o777) } From 8408a536a9d17aa6293d0a805a8a4a140a717dfb Mon Sep 17 00:00:00 2001 From: geoknee Date: Thu, 22 Aug 2024 17:27:12 +0100 Subject: [PATCH 05/15] link validation to add-chain --- add-chain/go.mod | 3 +++ 1 file changed, 3 insertions(+) diff --git a/add-chain/go.mod b/add-chain/go.mod index 27e0efb288..afd28f1d9f 100644 --- a/add-chain/go.mod +++ b/add-chain/go.mod @@ -4,12 +4,15 @@ go 1.21 replace github.com/ethereum-optimism/superchain-registry/superchain => ../superchain +replace github.com/ethereum-optimism/superchain-registry/validation => ../validation + replace github.com/ethereum/go-ethereum => github.com/ethereum-optimism/op-geth v1.101407.0-rc.1.0.20240812224053-8d99ca68bb1a require ( github.com/BurntSushi/toml v1.4.0 github.com/ethereum-optimism/optimism v1.9.1-0.20240814195148-0bb2ff57c813 github.com/ethereum-optimism/superchain-registry/superchain v0.0.0-20240814192743-ea7e768a02a6 + github.com/ethereum-optimism/superchain-registry/validation v0.0.0-00010101000000-000000000000 github.com/ethereum/go-ethereum v1.14.7 github.com/google/go-cmp v0.6.0 github.com/joho/godotenv v1.5.1 From f501c5a6863be120466582de3a9f868d8ba2376f Mon Sep 17 00:00:00 2001 From: geoknee Date: Fri, 23 Aug 2024 11:43:09 +0100 Subject: [PATCH 06/15] fix up add-chain e2e tests --- add-chain/e2e_test.go | 55 ++++++++++++++----- add-chain/main.go | 12 +++- .../sepolia.json | 0 justfile | 6 ++ 4 files changed, 56 insertions(+), 17 deletions(-) rename add-chain/testdata/monorepo/{deploy-config.json => deploy-config}/sepolia.json (100%) diff --git a/add-chain/e2e_test.go b/add-chain/e2e_test.go index 2e777afd70..624a3f94bf 100644 --- a/add-chain/e2e_test.go +++ b/add-chain/e2e_test.go @@ -1,6 +1,7 @@ package main import ( + "fmt" "os" "strconv" "testing" @@ -10,64 +11,86 @@ import ( ) const ( - addressDir = "../superchain/extra/addresses/sepolia/" - configDir = "../superchain/configs/sepolia/" + addressDir = "../superchain/extra/addresses/sepolia/" + configDir = "../superchain/configs/sepolia/" + validtionInputsDir = "../validation/genesis/validation-inputs" ) var tests = []struct { name string + chainID uint64 chainName string chainShortName string rollupConfigFile string standardChainCandidate bool chainType string deploymentsDir string + deployConfigPath string + genesisCreationCommit string }{ { - name: "baseline", - chainName: "testchain_baseline", - chainShortName: "testchain_b", - rollupConfigFile: "./testdata/monorepo/op-node/rollup_baseline.json", - deploymentsDir: "./testdata/monorepo/deployments", + name: "baseline", + chainID: 4206900, + chainName: "testchain_baseline", + chainShortName: "testchain_b", + rollupConfigFile: "./testdata/monorepo/op-node/rollup_baseline.json", + deploymentsDir: "./testdata/monorepo/deployments", + deployConfigPath: "./testdata/monorepo/deploy-config/sepolia.json", + genesisCreationCommit: "somecommit", }, { - name: "baseline_legacy", - chainName: "testchain_baseline_legacy", - chainShortName: "testchain_bl", - rollupConfigFile: "./testdata/monorepo/op-node/rollup_baseline_legacy.json", - deploymentsDir: "./testdata/monorepo/deployments-legacy", + name: "baseline_legacy", + chainID: 4206901, + chainName: "testchain_baseline_legacy", + chainShortName: "testchain_bl", + rollupConfigFile: "./testdata/monorepo/op-node/rollup_baseline_legacy.json", + deploymentsDir: "./testdata/monorepo/deployments-legacy", + deployConfigPath: "./testdata/monorepo/deploy-config/sepolia.json", + genesisCreationCommit: "somecommit", }, { name: "zorasep", + chainID: 4206902, chainName: "testchain_zorasep", chainShortName: "testchain_zs", rollupConfigFile: "./testdata/monorepo/op-node/rollup_zorasep.json", deploymentsDir: "./testdata/monorepo/deployments", standardChainCandidate: true, + deployConfigPath: "./testdata/monorepo/deploy-config/sepolia.json", + genesisCreationCommit: "somecommit", }, { name: "altda", + chainID: 4206903, chainName: "testchain_altda", chainShortName: "testchain_ad", rollupConfigFile: "./testdata/monorepo/op-node/rollup_altda.json", deploymentsDir: "./testdata/monorepo/deployments", standardChainCandidate: true, + deployConfigPath: "./testdata/monorepo/deploy-config/sepolia.json", + genesisCreationCommit: "somecommit", }, { name: "standard-candidate", + chainID: 4206904, chainName: "testchain_standard-candidate", chainShortName: "testchain_sc", rollupConfigFile: "./testdata/monorepo/op-node/rollup_standard-candidate.json", deploymentsDir: "./testdata/monorepo/deployments", standardChainCandidate: true, + deployConfigPath: "./testdata/monorepo/deploy-config/sepolia.json", + genesisCreationCommit: "somecommit", }, { name: "faultproofs", + chainID: 4206905, chainName: "testchain_faultproofs", chainShortName: "testchain_fp", rollupConfigFile: "./testdata/monorepo/op-node/rollup_faultproofs.json", deploymentsDir: "./testdata/monorepo/deployments-faultproofs", standardChainCandidate: true, + deployConfigPath: "./testdata/monorepo/deploy-config/sepolia.json", + genesisCreationCommit: "somecommit", }, } @@ -77,7 +100,7 @@ func TestAddChain_Main(t *testing.T) { t.Run(tt.name, func(t *testing.T) { t.Parallel() - cleanupTestFiles(t, tt.chainShortName) + cleanupTestFiles(t, tt.chainShortName, tt.chainID) err := os.Setenv("SCR_RUN_TESTS", "true") require.NoError(t, err, "failed to set SCR_RUN_TESTS env var") @@ -89,6 +112,8 @@ func TestAddChain_Main(t *testing.T) { "--rollup-config=" + tt.rollupConfigFile, "--deployments-dir=" + tt.deploymentsDir, "--standard-chain-candidate=" + strconv.FormatBool(tt.standardChainCandidate), + "--deploy-config=" + tt.deployConfigPath, + "--genesis-creation-commit=" + tt.genesisCreationCommit, } err = runApp(args) @@ -167,10 +192,12 @@ func checkConfigTOML(t *testing.T, testName, chainShortName string) { require.Equal(t, string(expectedBytes), string(testBytes), "test .toml contents do not meet expectation") } -func cleanupTestFiles(t *testing.T, chainShortName string) { +func cleanupTestFiles(t *testing.T, chainShortName string, chainId uint64) { paths := []string{ addressDir + chainShortName + ".json", configDir + chainShortName + ".toml", + validtionInputsDir + fmt.Sprintf("%d", chainId) + "meta.toml", + validtionInputsDir + fmt.Sprintf("%d", chainId) + "deploy-config.json", } for _, path := range paths { diff --git a/add-chain/main.go b/add-chain/main.go index 5c3def315b..cdfdd7daac 100644 --- a/add-chain/main.go +++ b/add-chain/main.go @@ -37,6 +37,8 @@ var app = &cli.App{ flags.RollupConfigFlag, flags.DeploymentsDirFlag, flags.StandardChainCandidateFlag, + flags.GenesisCreationCommit, + flags.DeployConfigFlag, }, Action: entrypoint, Commands: []*cli.Command{ @@ -175,7 +177,11 @@ func entrypoint(ctx *cli.Context) error { fmt.Printf("✅ Wrote config for new chain with identifier %s", rollupConfig.Identifier()) - genesisValidationInputsDir := filepath.Join(superchainRepoRoot, "validation", "genesis", "validation-inputs") + genesisValidationInputsDir := filepath.Join(superchainRepoRoot, "validation", "genesis", "validation-inputs", fmt.Sprintf("%d", rollupConfig.ChainID)) + err = os.MkdirAll(genesisValidationInputsDir, os.ModePerm) + if err != nil { + return err + } err = copyDeployConfigFile(rollupConfig.ChainID, deployConfigPath, genesisValidationInputsDir) if err != nil { return fmt.Errorf("error copying deploy-config json file: %w", err) @@ -254,7 +260,7 @@ func copyDeployConfigFile(chainId uint64, sourcePath string, targetDir string) e if err != nil { return err } - return os.WriteFile(path.Join(targetDir, fmt.Sprintf("%d", chainId), "deploy-config.json"), data, 0o777) + return os.WriteFile(path.Join(targetDir, "deploy-config.json"), data, 0o777) } func writeGenesisValidationMetadata(chainId uint64, commit string, targetDir string) error { @@ -268,5 +274,5 @@ func writeGenesisValidationMetadata(chainId uint64, commit string, targetDir str if err != nil { return err } - return os.WriteFile(path.Join(targetDir, fmt.Sprintf("%d", chainId), "meta.toml"), data, 0o777) + return os.WriteFile(path.Join(targetDir, "meta.toml"), data, 0o777) } diff --git a/add-chain/testdata/monorepo/deploy-config.json/sepolia.json b/add-chain/testdata/monorepo/deploy-config/sepolia.json similarity index 100% rename from add-chain/testdata/monorepo/deploy-config.json/sepolia.json rename to add-chain/testdata/monorepo/deploy-config/sepolia.json diff --git a/justfile b/justfile index 4172e3b724..9e05f45447 100644 --- a/justfile +++ b/justfile @@ -59,6 +59,12 @@ promotion-test: clean-add-chain: rm -f superchain/configs/sepolia/testchain_*.toml rm -f superchain/extra/sepolia/testchain_*.json.gz + rm -rf validation/genesis/validation-inputs/4206900 + rm -rf validation/genesis/validation-inputs/4206901 + rm -rf validation/genesis/validation-inputs/4206902 + rm -rf validation/genesis/validation-inputs/4206903 + rm -rf validation/genesis/validation-inputs/4206904 + rm -rf validation/genesis/validation-inputs/4206905 # Tidying all go.mod files tidy-all: tidy-add-chain tidy-superchain tidy-validation From e00a814505c2e492916c16dfe4b1da80b2151dbb Mon Sep 17 00:00:00 2001 From: geoknee Date: Fri, 23 Aug 2024 12:13:52 +0100 Subject: [PATCH 07/15] simplify test side effect handling --- add-chain/e2e_test.go | 69 ++++++++++++++++------------------- add-chain/main.go | 6 ++- justfile | 8 +--- validation/.gitignore | 5 +++ validation/genesis/genesis.go | 5 +++ 5 files changed, 49 insertions(+), 44 deletions(-) diff --git a/add-chain/e2e_test.go b/add-chain/e2e_test.go index 624a3f94bf..d037395681 100644 --- a/add-chain/e2e_test.go +++ b/add-chain/e2e_test.go @@ -3,7 +3,9 @@ package main import ( "fmt" "os" + "path/filepath" "strconv" + "strings" "testing" "github.com/BurntSushi/toml" @@ -18,79 +20,58 @@ const ( var tests = []struct { name string - chainID uint64 chainName string chainShortName string rollupConfigFile string standardChainCandidate bool chainType string deploymentsDir string - deployConfigPath string - genesisCreationCommit string }{ { - name: "baseline", - chainID: 4206900, - chainName: "testchain_baseline", - chainShortName: "testchain_b", - rollupConfigFile: "./testdata/monorepo/op-node/rollup_baseline.json", - deploymentsDir: "./testdata/monorepo/deployments", - deployConfigPath: "./testdata/monorepo/deploy-config/sepolia.json", - genesisCreationCommit: "somecommit", + name: "baseline", + chainName: "testchain_baseline", + chainShortName: "testchain_b", + rollupConfigFile: "./testdata/monorepo/op-node/rollup_baseline.json", + deploymentsDir: "./testdata/monorepo/deployments", }, { - name: "baseline_legacy", - chainID: 4206901, - chainName: "testchain_baseline_legacy", - chainShortName: "testchain_bl", - rollupConfigFile: "./testdata/monorepo/op-node/rollup_baseline_legacy.json", - deploymentsDir: "./testdata/monorepo/deployments-legacy", - deployConfigPath: "./testdata/monorepo/deploy-config/sepolia.json", - genesisCreationCommit: "somecommit", + name: "baseline_legacy", + chainName: "testchain_baseline_legacy", + chainShortName: "testchain_bl", + rollupConfigFile: "./testdata/monorepo/op-node/rollup_baseline_legacy.json", + deploymentsDir: "./testdata/monorepo/deployments-legacy", }, { name: "zorasep", - chainID: 4206902, chainName: "testchain_zorasep", chainShortName: "testchain_zs", rollupConfigFile: "./testdata/monorepo/op-node/rollup_zorasep.json", deploymentsDir: "./testdata/monorepo/deployments", standardChainCandidate: true, - deployConfigPath: "./testdata/monorepo/deploy-config/sepolia.json", - genesisCreationCommit: "somecommit", }, { name: "altda", - chainID: 4206903, chainName: "testchain_altda", chainShortName: "testchain_ad", rollupConfigFile: "./testdata/monorepo/op-node/rollup_altda.json", deploymentsDir: "./testdata/monorepo/deployments", standardChainCandidate: true, - deployConfigPath: "./testdata/monorepo/deploy-config/sepolia.json", - genesisCreationCommit: "somecommit", }, { name: "standard-candidate", - chainID: 4206904, chainName: "testchain_standard-candidate", chainShortName: "testchain_sc", rollupConfigFile: "./testdata/monorepo/op-node/rollup_standard-candidate.json", deploymentsDir: "./testdata/monorepo/deployments", standardChainCandidate: true, - deployConfigPath: "./testdata/monorepo/deploy-config/sepolia.json", - genesisCreationCommit: "somecommit", }, { name: "faultproofs", - chainID: 4206905, chainName: "testchain_faultproofs", chainShortName: "testchain_fp", rollupConfigFile: "./testdata/monorepo/op-node/rollup_faultproofs.json", deploymentsDir: "./testdata/monorepo/deployments-faultproofs", standardChainCandidate: true, - deployConfigPath: "./testdata/monorepo/deploy-config/sepolia.json", - genesisCreationCommit: "somecommit", }, } @@ -100,7 +81,7 @@ func TestAddChain_Main(t *testing.T) { t.Run(tt.name, func(t *testing.T) { t.Parallel() - cleanupTestFiles(t, tt.chainShortName, tt.chainID) + cleanupTestFiles(t, tt.chainShortName) err := os.Setenv("SCR_RUN_TESTS", "true") require.NoError(t, err, "failed to set SCR_RUN_TESTS env var") @@ -112,8 +93,6 @@ func TestAddChain_Main(t *testing.T) { "--rollup-config=" + tt.rollupConfigFile, "--deployments-dir=" + tt.deploymentsDir, "--standard-chain-candidate=" + strconv.FormatBool(tt.standardChainCandidate), - "--deploy-config=" + tt.deployConfigPath, - "--genesis-creation-commit=" + tt.genesisCreationCommit, } err = runApp(args) @@ -192,12 +171,10 @@ func checkConfigTOML(t *testing.T, testName, chainShortName string) { require.Equal(t, string(expectedBytes), string(testBytes), "test .toml contents do not meet expectation") } -func cleanupTestFiles(t *testing.T, chainShortName string, chainId uint64) { +func cleanupTestFiles(t *testing.T, chainShortName string) { paths := []string{ addressDir + chainShortName + ".json", configDir + chainShortName + ".toml", - validtionInputsDir + fmt.Sprintf("%d", chainId) + "meta.toml", - validtionInputsDir + fmt.Sprintf("%d", chainId) + "deploy-config.json", } for _, path := range paths { @@ -206,5 +183,23 @@ func cleanupTestFiles(t *testing.T, chainShortName string, chainId uint64) { t.Logf("Error removing file %s: %v\n", path, err) } } + + // Remove genesis validation input directories (and files within) + dirEntries, err := os.ReadDir(validtionInputsDir) + if err != nil { + fmt.Printf("Failed to read directory: %v\n", err) + return + } + for _, entry := range dirEntries { + if entry.IsDir() && strings.HasSuffix(entry.Name(), "-test") { + dirPath := filepath.Join(validtionInputsDir, entry.Name()) + fmt.Printf("Removing directory: %s\n", dirPath) + err := os.RemoveAll(dirPath) + if err != nil { + fmt.Printf("Failed to remove directory %s: %v\n", dirPath, err) + } + } + } + t.Logf("Removed test artifacts for chain: %s", chainShortName) } diff --git a/add-chain/main.go b/add-chain/main.go index cdfdd7daac..bfed175ad3 100644 --- a/add-chain/main.go +++ b/add-chain/main.go @@ -177,7 +177,11 @@ func entrypoint(ctx *cli.Context) error { fmt.Printf("✅ Wrote config for new chain with identifier %s", rollupConfig.Identifier()) - genesisValidationInputsDir := filepath.Join(superchainRepoRoot, "validation", "genesis", "validation-inputs", fmt.Sprintf("%d", rollupConfig.ChainID)) + folderName := fmt.Sprintf("%d", rollupConfig.ChainID) + if runningTests := os.Getenv("SCR_RUN_TESTS"); runningTests == "true" { + folderName = folderName + "-test" + } + genesisValidationInputsDir := filepath.Join(superchainRepoRoot, "validation", "genesis", "validation-inputs", folderName) err = os.MkdirAll(genesisValidationInputsDir, os.ModePerm) if err != nil { return err diff --git a/justfile b/justfile index 9e05f45447..0e621aac60 100644 --- a/justfile +++ b/justfile @@ -59,12 +59,8 @@ promotion-test: clean-add-chain: rm -f superchain/configs/sepolia/testchain_*.toml rm -f superchain/extra/sepolia/testchain_*.json.gz - rm -rf validation/genesis/validation-inputs/4206900 - rm -rf validation/genesis/validation-inputs/4206901 - rm -rf validation/genesis/validation-inputs/4206902 - rm -rf validation/genesis/validation-inputs/4206903 - rm -rf validation/genesis/validation-inputs/4206904 - rm -rf validation/genesis/validation-inputs/4206905 + rm -r -- validation/genesis/validation-inputs/*-test/ + # Tidying all go.mod files tidy-all: tidy-add-chain tidy-superchain tidy-validation diff --git a/validation/.gitignore b/validation/.gitignore index a658e35344..c271a45fdf 100644 --- a/validation/.gitignore +++ b/validation/.gitignore @@ -1,2 +1,7 @@ generate-rollup-config/output-* generate-genesis/output-* + + +# test output artifacts +genesis/validation-inputs/*-test + diff --git a/validation/genesis/genesis.go b/validation/genesis/genesis.go index 6e70f73279..04f8f859a6 100644 --- a/validation/genesis/genesis.go +++ b/validation/genesis/genesis.go @@ -5,6 +5,7 @@ import ( "fmt" "path" "strconv" + "strings" "github.com/BurntSushi/toml" ) @@ -40,6 +41,10 @@ func init() { panic(fmt.Errorf("failed to decode metadata file: %w", err)) } + if strings.HasSuffix(s.Name(), "-test") { + continue + } + chainID, err := strconv.Atoi(s.Name()) if err != nil { panic(fmt.Errorf("failed to decode chain id from dir name: %w", err)) From 9ae82c7660cf2d8d8fb972432e7eaccb3a2da7b6 Mon Sep 17 00:00:00 2001 From: geoknee Date: Fri, 23 Aug 2024 12:15:13 +0100 Subject: [PATCH 08/15] don't bother cleaning up -test genesis validation inputs (They now don't end up bound into the validation package) --- add-chain/e2e_test.go | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/add-chain/e2e_test.go b/add-chain/e2e_test.go index d037395681..66e6ea2eb9 100644 --- a/add-chain/e2e_test.go +++ b/add-chain/e2e_test.go @@ -1,11 +1,8 @@ package main import ( - "fmt" "os" - "path/filepath" "strconv" - "strings" "testing" "github.com/BurntSushi/toml" @@ -184,22 +181,5 @@ func cleanupTestFiles(t *testing.T, chainShortName string) { } } - // Remove genesis validation input directories (and files within) - dirEntries, err := os.ReadDir(validtionInputsDir) - if err != nil { - fmt.Printf("Failed to read directory: %v\n", err) - return - } - for _, entry := range dirEntries { - if entry.IsDir() && strings.HasSuffix(entry.Name(), "-test") { - dirPath := filepath.Join(validtionInputsDir, entry.Name()) - fmt.Printf("Removing directory: %s\n", dirPath) - err := os.RemoveAll(dirPath) - if err != nil { - fmt.Printf("Failed to remove directory %s: %v\n", dirPath, err) - } - } - } - t.Logf("Removed test artifacts for chain: %s", chainShortName) } From 08dc4cbb7034a349832371be02fa34471ad649a9 Mon Sep 17 00:00:00 2001 From: geoknee Date: Fri, 23 Aug 2024 12:23:14 +0100 Subject: [PATCH 09/15] tweak spacing --- add-chain/e2e_test.go | 1 - justfile | 1 - validation/.gitignore | 3 +-- 3 files changed, 1 insertion(+), 4 deletions(-) diff --git a/add-chain/e2e_test.go b/add-chain/e2e_test.go index 66e6ea2eb9..938473733d 100644 --- a/add-chain/e2e_test.go +++ b/add-chain/e2e_test.go @@ -180,6 +180,5 @@ func cleanupTestFiles(t *testing.T, chainShortName string) { t.Logf("Error removing file %s: %v\n", path, err) } } - t.Logf("Removed test artifacts for chain: %s", chainShortName) } diff --git a/justfile b/justfile index 0e621aac60..3160f70736 100644 --- a/justfile +++ b/justfile @@ -61,7 +61,6 @@ clean-add-chain: rm -f superchain/extra/sepolia/testchain_*.json.gz rm -r -- validation/genesis/validation-inputs/*-test/ - # Tidying all go.mod files tidy-all: tidy-add-chain tidy-superchain tidy-validation diff --git a/validation/.gitignore b/validation/.gitignore index c271a45fdf..8a5e1f6911 100644 --- a/validation/.gitignore +++ b/validation/.gitignore @@ -1,7 +1,6 @@ +# diff tool artifacts generate-rollup-config/output-* generate-genesis/output-* - # test output artifacts genesis/validation-inputs/*-test - From 77fdea5828c69729ad7436da016176af388fd9a1 Mon Sep 17 00:00:00 2001 From: geoknee Date: Sat, 24 Aug 2024 17:15:16 +0100 Subject: [PATCH 10/15] prefer os.ModePerm over 0o777 --- add-chain/main.go | 4 ++-- validation/genesis/genesis-predeploy_test.go | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/add-chain/main.go b/add-chain/main.go index bfed175ad3..6443e59c51 100644 --- a/add-chain/main.go +++ b/add-chain/main.go @@ -264,7 +264,7 @@ func copyDeployConfigFile(chainId uint64, sourcePath string, targetDir string) e if err != nil { return err } - return os.WriteFile(path.Join(targetDir, "deploy-config.json"), data, 0o777) + return os.WriteFile(path.Join(targetDir, "deploy-config.json"), data, os.ModePerm) } func writeGenesisValidationMetadata(chainId uint64, commit string, targetDir string) error { @@ -278,5 +278,5 @@ func writeGenesisValidationMetadata(chainId uint64, commit string, targetDir str if err != nil { return err } - return os.WriteFile(path.Join(targetDir, "meta.toml"), data, 0o777) + return os.WriteFile(path.Join(targetDir, "meta.toml"), data, os.ModePerm) } diff --git a/validation/genesis/genesis-predeploy_test.go b/validation/genesis/genesis-predeploy_test.go index 9eab1223d4..981599dec4 100644 --- a/validation/genesis/genesis-predeploy_test.go +++ b/validation/genesis/genesis-predeploy_test.go @@ -111,9 +111,9 @@ func testGenesisPredeploys(t *testing.T, chain *ChainConfig) { gotData, err := json.MarshalIndent(g.Alloc, "", " ") require.NoError(t, err) - err = os.WriteFile(path.Join(monorepoDir, "want-alloc.json"), expectedData, 0o777) + err = os.WriteFile(path.Join(monorepoDir, "want-alloc.json"), expectedData, os.ModePerm) require.NoError(t, err) - err = os.WriteFile(path.Join(monorepoDir, "got-alloc.json"), gotData, 0o777) + err = os.WriteFile(path.Join(monorepoDir, "got-alloc.json"), gotData, os.ModePerm) require.NoError(t, err) require.Equal(t, string(expectedData), string(gotData)) @@ -135,7 +135,7 @@ func writeDeployments(chainId uint64, directory string) error { return err } - err = os.WriteFile(path.Join(directory, ".deploy"), data, 0o777) + err = os.WriteFile(path.Join(directory, ".deploy"), data, os.ModePerm) if err != nil { return err } From 8cd3d9a4663419d34e31e013b46247c35aad73d4 Mon Sep 17 00:00:00 2001 From: geoknee Date: Sat, 24 Aug 2024 17:15:44 +0100 Subject: [PATCH 11/15] typo --- add-chain/e2e_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/add-chain/e2e_test.go b/add-chain/e2e_test.go index 938473733d..e79d0fadbb 100644 --- a/add-chain/e2e_test.go +++ b/add-chain/e2e_test.go @@ -10,9 +10,9 @@ import ( ) const ( - addressDir = "../superchain/extra/addresses/sepolia/" - configDir = "../superchain/configs/sepolia/" - validtionInputsDir = "../validation/genesis/validation-inputs" + addressDir = "../superchain/extra/addresses/sepolia/" + configDir = "../superchain/configs/sepolia/" + validationInputsDir = "../validation/genesis/validation-inputs" ) var tests = []struct { From bda3064010016480ad9783a9371fcf37bd5382b6 Mon Sep 17 00:00:00 2001 From: geoknee Date: Sat, 24 Aug 2024 17:16:08 +0100 Subject: [PATCH 12/15] typo --- .env.example | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.env.example b/.env.example index 2a16f03b31..f2ba870ed4 100644 --- a/.env.example +++ b/.env.example @@ -30,7 +30,7 @@ SCR_GENESIS=${SCR_MONOREPO_DIR}/op-node/genesis.json SCR_DEPLOY_CONFIG=${SCR_MONOREPO_DIR}/packages/contracts-bedrock/deploy-config/getting-started.json # This is the commit in the https://github.com/ethereum-optimism/optimism/ repo -# at which the chain's genesis was created. This is necessary to have out validation checks +# at which the chain's genesis was created. This is necessary to have our validation checks # recreate the genesis file using identical source code SCR_GENESIS_CREATION_COMMIT="" From 24818b62f1c128e335b56320f29fbef5de4c9c53 Mon Sep 17 00:00:00 2001 From: geoknee Date: Sat, 24 Aug 2024 17:17:15 +0100 Subject: [PATCH 13/15] remove unused params --- add-chain/main.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/add-chain/main.go b/add-chain/main.go index 6443e59c51..fefa7af3c6 100644 --- a/add-chain/main.go +++ b/add-chain/main.go @@ -186,13 +186,13 @@ func entrypoint(ctx *cli.Context) error { if err != nil { return err } - err = copyDeployConfigFile(rollupConfig.ChainID, deployConfigPath, genesisValidationInputsDir) + err = copyDeployConfigFile(deployConfigPath, genesisValidationInputsDir) if err != nil { return fmt.Errorf("error copying deploy-config json file: %w", err) } fmt.Printf("✅ Copied deploy-config json file to validation module") - err = writeGenesisValidationMetadata(rollupConfig.ChainID, genesisCreationCommit, genesisValidationInputsDir) + err = writeGenesisValidationMetadata(genesisCreationCommit, genesisValidationInputsDir) if err != nil { return fmt.Errorf("error writing genesis validation metadata file: %w", err) } @@ -259,7 +259,7 @@ func getGasPayingToken(l1rpcURl string, SystemConfigAddress superchain.Address) return (*superchain.Address)(&result.Addr), nil } -func copyDeployConfigFile(chainId uint64, sourcePath string, targetDir string) error { +func copyDeployConfigFile(sourcePath string, targetDir string) error { data, err := os.ReadFile(sourcePath) if err != nil { return err @@ -267,7 +267,7 @@ func copyDeployConfigFile(chainId uint64, sourcePath string, targetDir string) e return os.WriteFile(path.Join(targetDir, "deploy-config.json"), data, os.ModePerm) } -func writeGenesisValidationMetadata(chainId uint64, commit string, targetDir string) error { +func writeGenesisValidationMetadata(commit string, targetDir string) error { vm := genesis.ValidationMetadata{ GenesisCreationCommit: commit, NodeVersion: "18.12.1", From e7b0e73e755f03e5ddbc5e4bf93b34ffd25486f7 Mon Sep 17 00:00:00 2001 From: geoknee Date: Sat, 24 Aug 2024 17:20:37 +0100 Subject: [PATCH 14/15] use commented constants for metadata defaults --- add-chain/main.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/add-chain/main.go b/add-chain/main.go index fefa7af3c6..44c96d24b8 100644 --- a/add-chain/main.go +++ b/add-chain/main.go @@ -268,11 +268,18 @@ func copyDeployConfigFile(sourcePath string, targetDir string) error { } func writeGenesisValidationMetadata(commit string, targetDir string) error { + // Define default metadata params: + // These may not be sufficient to make the genesis validation work, + // but we address that with some manual trial-and-error intervention + // involving OPLabs engineers after the add-chain command runs. + const defaultNodeVersion = "18.12.1" + const defaultMonorepoBuildCommand = "pnpm" + const defaultGenesisCreationCommand = "opnode1" vm := genesis.ValidationMetadata{ GenesisCreationCommit: commit, - NodeVersion: "18.12.1", - MonorepoBuildCommand: "pnpm", - GenesisCreationCommand: "opnode1", + NodeVersion: defaultNodeVersion, + MonorepoBuildCommand: defaultMonorepoBuildCommand, + GenesisCreationCommand: defaultGenesisCreationCommand, } data, err := toml.Marshal(vm) if err != nil { From e8383fbbffe840448fe23b3b282bd7938ede015a Mon Sep 17 00:00:00 2001 From: geoknee Date: Sat, 24 Aug 2024 17:25:00 +0100 Subject: [PATCH 15/15] fix clean-add-chain cmd --- justfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/justfile b/justfile index 3160f70736..b6ff2c7b03 100644 --- a/justfile +++ b/justfile @@ -59,7 +59,7 @@ promotion-test: clean-add-chain: rm -f superchain/configs/sepolia/testchain_*.toml rm -f superchain/extra/sepolia/testchain_*.json.gz - rm -r -- validation/genesis/validation-inputs/*-test/ + rm -rf -- validation/genesis/validation-inputs/*-test/ # Tidying all go.mod files tidy-all: tidy-add-chain tidy-superchain tidy-validation