-
Notifications
You must be signed in to change notification settings - Fork 3.9k
feat(ct): overhaul deployment process #2298
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| # Name for the network to deploy to ("mainnet", "kovan", etc.) | ||
| CONTRACTS_TARGET_NETWORK= | ||
|
|
||
| # Private key that will send deployment transactions | ||
| CONTRACTS_DEPLOYER_KEY= | ||
|
|
||
| # RPC URL connected to the L1 chain we're deploying to | ||
| CONTRACTS_RPC_URL= | ||
|
|
||
| # Your Etherscan API key for the L1 network | ||
| ETHERSCAN_API_KEY= | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,7 +32,9 @@ import { L1CrossDomainMessenger } from "@eth-optimism/contracts/L1/messaging/L1C | |
| ``` | ||
|
|
||
| ## Guide for Developers | ||
|
|
||
| ### Setup | ||
|
|
||
| Install the following: | ||
| - [`Node.js` (14+)](https://nodejs.org/en/) | ||
| - [`npm`](https://www.npmjs.com/get-npm) | ||
|
|
@@ -46,107 +48,105 @@ cd contracts | |
| ``` | ||
|
|
||
| Install `npm` packages: | ||
|
|
||
| ```shell | ||
| yarn install | ||
| ``` | ||
|
|
||
| ### Running Tests | ||
|
|
||
| Tests are executed via `yarn`: | ||
|
|
||
| ```shell | ||
| yarn test | ||
| ``` | ||
|
|
||
| Run specific tests by giving a path to the file you want to run: | ||
|
|
||
| ```shell | ||
| yarn test ./test/path/to/my/test.spec.ts | ||
| ``` | ||
|
|
||
| ### Measuring test coverage: | ||
|
|
||
| ```shell | ||
| yarn test:coverage | ||
| ``` | ||
|
|
||
| The output is most easily viewable by opening the html file in your browser: | ||
|
|
||
| ```shell | ||
| open ./coverage/index.html | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll fix this in another PR |
||
| ``` | ||
|
|
||
| ### Compiling and Building | ||
| Easiest way is to run the primary build script: | ||
| ```shell | ||
| yarn build | ||
| ``` | ||
|
|
||
| Running the full build command will perform the following actions: | ||
| 1. `build:contracts` - Compile all Solidity contracts with both the EVM and OVM compilers. | ||
| 2. `build:typescript` - Builds the typescript files that are used to export utilities into js. | ||
| 3. `build:copy` - Copies various other files into the dist folder. | ||
| 4. `build:dump` - Generates a genesis state from the contracts that L2 geth will use. | ||
| 5. `build:typechain` - Generates [TypeChain](https://github.com/ethereum-ts/TypeChain) artifacts. | ||
| Compile and build the various required with the `build` command: | ||
|
|
||
| You can also build specific components as follows: | ||
| ```shell | ||
| yarn build:contracts | ||
| yarn build | ||
| ``` | ||
|
|
||
| ### Deploying the Contracts | ||
|
|
||
| #### Required environment variables | ||
|
|
||
| You must set the following environment variables to execute a deployment: | ||
|
|
||
| ```bash | ||
| # Name for the network to deploy to ("mainnet", "kovan", etc.) | ||
| export CONTRACTS_TARGET_NETWORK=... | ||
|
|
||
| # Private key that will send deployment transactions | ||
| export CONTRACTS_DEPLOYER_KEY=... | ||
| You must set several required environment variables before you can execute a deployment. | ||
| Duplicate the file [`.env.example`](./.env.example) and rename your duplicate to `.env`. | ||
| Fill out each of the environment variables before continuing. | ||
|
|
||
| # RPC URL connected to the L1 chain we're deploying to | ||
| export CONTRACTS_RPC_URL=... | ||
| #### Creating a deployment configuration | ||
|
|
||
| # Your Etherscan API key for the L1 network | ||
| export ETHERSCAN_API_KEY=... | ||
| ``` | ||
|
|
||
| #### Creating a deployment script | ||
| Before you can carry out a deployment, you must create a deployment configuration file inside of the [deploy-config](./deploy-config/) folder. | ||
| Deployment configuration files are TypeScript files that export an object that conforms to the `DeployConfig` type. | ||
| See [mainnet.ts](./deploy-config/mainnet.ts) for an example deployment configuration. | ||
| We recommend duplicating an existing deployment config and modifying it to satisfy your requirements. | ||
|
|
||
| Before you can carry out a deployment, you must create a deployment script. | ||
| See [mainnet.sh](./scripts/deploy-scripts/mainnet.sh) for an example deployment script. | ||
| We recommend duplicating an existing deployment script and modifying it to satisfy your requirements. | ||
| #### Executing a deployment | ||
|
|
||
| Most variables within the deploy script are relatively self-explanatory. | ||
| If you intend to upgrade an existing system you **MUST** [include the following argument](https://github.com/ethereum-optimism/optimism/blob/6f633f915b34a46ac14430724bed9722af8bd05e/packages/contracts/scripts/deploy-scripts/mainnet.sh#L33) in the deploy script: | ||
| Once you've created your deploy config, you can execute a deployment with the following command: | ||
|
|
||
| ``` | ||
| --tags upgrade | ||
| npx hardhat deploy --network <my network name> | ||
| ``` | ||
|
|
||
| If you are deploying a system from scratch, you should **NOT** include `--tags upgrade` or you will fail to deploy several contracts. | ||
| Note that this only applies to fresh deployments. | ||
| If you want to upgrade an existing system (instead of deploying a new system from scratch), you must use the following command instead: | ||
|
|
||
| #### Executing a deployment | ||
| ``` | ||
| npx hardhat deploy --network <my network name> --tags upgrade | ||
| ``` | ||
|
|
||
| Once you've created your deploy script, simply run the script to trigger a deployment. | ||
| During the deployment process, you will be asked to transfer ownership of several contracts to a special contract address. | ||
| You will also be asked to verify various configuration values. | ||
| This is a safety mechanism to make sure that actions within an upgrade are performed atomically. | ||
| Ownership of these addresses will be automatically returned to the original owner address once the upgrade is complete. | ||
| The original owner can always recover ownership from the upgrade contract in an emergency. | ||
| Please read these instructions carefully, verify each of the presented configuration values, and carefully confirm that the contract you are giving ownership to has not been compromised (e.g., check the code on Etherscan). | ||
|
|
||
| After your deployment is complete, your new contracts will be written to an artifacts directory in `./deployments/<name>`. | ||
| Your contracts will also be automatically verified as part of the deployment script. | ||
| After your deployment is complete, your new contracts will be written to an artifacts directory in `./deployments/<my network name>`. | ||
|
|
||
| #### Verifying contract source code | ||
|
|
||
| Contracts will be automatically verified via both [Etherscan](https://etherscan.io) and [Sourcify](https://sourcify.dev/) during the deployment process. | ||
| If there was an issue with verification during the deployment, you can manually verify your contracts with the command: | ||
|
|
||
| ``` | ||
| npx hardhat etherscan-verify --network <my network name> | ||
| ``` | ||
|
|
||
| #### Creating a genesis file | ||
|
|
||
| Optimism expects that certain contracts (called "predeploys") be deployed to the L2 network at pre-determined addresses. | ||
| Doing this requires that you generate a special genesis file to be used by your corresponding L2Geth nodes. | ||
| You must first create a genesis generation script. | ||
| Like in the deploy script, we recommend starting from an [existing script](./scripts/deploy-scripts/mainnet-genesis.sh). | ||
| Modify each of the values within this script to match the values of your own deployment, taking any L1 contract addresses from the `./deployments/<name>` folder that was just generated or modified. | ||
| We guarantee this by creating a genesis file in which certain contracts are already within the L2 state at the genesis block. | ||
| To create the genesis file for your network, you must first deploy the L1 contracts using the appropriate commands from above. | ||
| Once you've deployed your contracts, run the following command: | ||
|
|
||
| ``` | ||
| npx hardhat take-dump --network <my network name> | ||
| ``` | ||
|
|
||
| Execute this script to generate the genesis file. | ||
| You will find this genesis file at `./dist/dumps/state-dump.latest.json`. | ||
| A genesis file will be created for you at `/genesis/<my network name>.json`. | ||
| You can then ingest this file via `geth init`. | ||
|
|
||
| ### Hardhat tasks | ||
|
|
||
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import { DeployConfig } from '../src/deploy-config' | ||
|
|
||
| const config: DeployConfig = { | ||
| network: 'goerli', | ||
| l1BlockTimeSeconds: 15, | ||
| l2BlockGasLimit: 15_000_000, | ||
| l2ChainId: 420, | ||
| ctcL2GasDiscountDivisor: 32, | ||
| ctcEnqueueGasCost: 60_000, | ||
| sccFaultProofWindowSeconds: 604800, | ||
| sccSequencerPublishWindowSeconds: 12592000, | ||
| ovmSequencerAddress: '0xB79f76EF2c5F0286176833E7B2eEe103b1CC3244', | ||
| ovmProposerAddress: '0x9A2F243c605e6908D96b18e21Fb82Bf288B19EF3', | ||
| ovmBlockSignerAddress: '0x27770a9694e4B4b1E130Ab91Bc327C36855f612E', | ||
| ovmFeeWalletAddress: '0xB79f76EF2c5F0286176833E7B2eEe103b1CC3244', | ||
| ovmAddressManagerOwner: '0x32b70c156302d28A9119445d2bbb9ab1cBD01671', | ||
| ovmGasPriceOracleOwner: '0x84f70449f90300997840eCb0918873745Ede7aE6', | ||
| } | ||
|
|
||
| export default config |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After a quick text search, I don't see any of these 3 values used anywhere outside the deleted bash scripts.
Can these be deleted? Where would these values now be specified? I don't see where that would be done in the deploy configs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, looks like they're already in hardhat.config.ts