-
Notifications
You must be signed in to change notification settings - Fork 71
feat: add genesis file generator example #629
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
Open
TucksonDev
wants to merge
12
commits into
main
Choose a base branch
from
add-genesis-file-generator-script
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
2f987e0
Add genesis file generator example
TucksonDev ad0ec61
Merge branch 'main' into add-genesis-file-generator-script
TucksonDev 6ff5128
Format
TucksonDev b5238bb
Merge branch 'add-genesis-file-generator-script' of https://github.co…
TucksonDev 42c263f
Add rollup creation
TucksonDev aa7e0af
Prompt questions for generating the genesis file and creating the rollup
TucksonDev 00d933a
Add instructions in README file
TucksonDev 885a644
Use main branch instead of containerization
TucksonDev 603027f
Add function to minify the chainConfig property in the genesis.json file
TucksonDev 62b9af4
Remove minification of chain config since it is now done in the genes…
TucksonDev 56323cf
Remove genesis-file-generator tag and use the main branch
TucksonDev 3a2679a
Merge branch 'main' into add-genesis-file-generator-script
TucksonDev 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
Add rollup creation
- Loading branch information
commit 42c263f2f65eb2e4d1a0e58e5b79666c43d4a68d
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,11 @@ | ||
| import { Address, createPublicClient, http, toHex } from 'viem'; | ||
| import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts'; | ||
| import { arbitrumSepolia } from 'viem/chains'; | ||
| import { createRollupPrepareDeploymentParamsConfig, createRollup } from '@arbitrum/orbit-sdk'; | ||
| import { sanitizePrivateKey } from '@arbitrum/orbit-sdk/utils'; | ||
| import { config } from 'dotenv'; | ||
| import { execSync } from 'child_process'; | ||
| import * as fs from 'fs'; | ||
| config(); | ||
|
|
||
| // Env variables check | ||
|
|
@@ -12,7 +18,30 @@ if (typeof process.env.L1_BASE_FEE === 'undefined') { | |
| const nitroNodeImage = process.env.NITRO_NODE_IMAGE; | ||
| const l1BaseFee = Number(process.env.L1_BASE_FEE); | ||
|
|
||
| function main() { | ||
| // Optional checks when creating a rollup | ||
| if (process.env.CREATE_ROLLUP === 'true') { | ||
| // Check environment variables | ||
| if (typeof process.env.DEPLOYER_PRIVATE_KEY === 'undefined') { | ||
| throw new Error(`Please provide the "DEPLOYER_PRIVATE_KEY" environment variable`); | ||
| } | ||
|
|
||
| if (typeof process.env.PARENT_CHAIN_RPC === 'undefined' || process.env.PARENT_CHAIN_RPC === '') { | ||
| console.warn( | ||
| `Warning: you may encounter timeout errors while running the script with the default rpc endpoint. Please provide the "PARENT_CHAIN_RPC" environment variable instead.`, | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| // Helpers | ||
| function withFallbackPrivateKey(privateKey: string | undefined): `0x${string}` { | ||
| if (typeof privateKey === 'undefined' || privateKey === '') { | ||
| return generatePrivateKey(); | ||
| } | ||
|
|
||
| return sanitizePrivateKey(privateKey); | ||
| } | ||
|
|
||
| async function main() { | ||
| // Step 0 - Build genesis file generator container from Github | ||
| // Note: remove this step once we have a public image | ||
| console.log(`Build genesis file generator container...`); | ||
|
|
@@ -45,6 +74,98 @@ function main() { | |
| console.log('Genesis file generated: genesis.json'); | ||
| console.log(`Block hash: ${genesisBlockHash}`); | ||
| console.log(`SendRoot hash: ${sendRootHash}`); | ||
|
|
||
| // Step 4 - Create Rollup (optional) | ||
| if (process.env.CREATE_ROLLUP === 'true') { | ||
| // load or generate a random batch poster account | ||
| const batchPosterPrivateKey = withFallbackPrivateKey(process.env.BATCH_POSTER_PRIVATE_KEY); | ||
| const batchPoster = privateKeyToAccount(batchPosterPrivateKey).address; | ||
|
|
||
| // load or generate a random validator account | ||
| const validatorPrivateKey = withFallbackPrivateKey(process.env.VALIDATOR_PRIVATE_KEY); | ||
| const validator = privateKeyToAccount(validatorPrivateKey).address; | ||
|
|
||
| // set the parent chain and create a public client for it | ||
| const parentChain = arbitrumSepolia; | ||
| const parentChainPublicClient = createPublicClient({ | ||
| chain: parentChain, | ||
| transport: http(process.env.PARENT_CHAIN_RPC), | ||
| }); | ||
|
|
||
| // load the deployer account | ||
| const deployer = privateKeyToAccount(sanitizePrivateKey(process.env.DEPLOYER_PRIVATE_KEY!)); | ||
|
|
||
| // The following env variables must exist, otherwise the genesis generation would have failed | ||
| const chainId = Number(process.env.CHAIN_ID!); | ||
| const chainOwner = process.env.CHAIN_OWNER as Address; | ||
|
|
||
| // Load chain config from the genesis file | ||
| let genesisFileContents: string; | ||
| try { | ||
| genesisFileContents = fs.readFileSync('genesis.json', { encoding: 'utf8' }); | ||
| } catch (err) { | ||
| console.error('Failed to read generated genesis.json file'); | ||
| throw err; | ||
| } | ||
| const genesisConfiguration = JSON.parse(genesisFileContents); | ||
|
|
||
| // Check whether or not we need to deploy the L2 factories (since they are included in the genesis file by default) | ||
| const l2Factories = [ | ||
| // Arachnid's deterministic deployment proxy | ||
| '0x4e59b44847b379578588920cA78FbF26c0B4956C', | ||
| // Zoltu's deterministic deployment proxy | ||
| '0x7A0D94F55792C434d74a40883C6ed8545E406D12', | ||
| // ERC-2470 Singleton Factory | ||
| '0xce0042B868300000d44A59004Da54A005ffdcf9f', | ||
| // ERC-1820: Pseudo-introspection Registry Contract | ||
| '0x1820a4B7618BdE71Dce8cdc73aAB6C95905faD24', | ||
| ] as const; | ||
|
|
||
| const allocKeys = new Set( | ||
| Object.keys(genesisConfiguration.alloc ?? {}).map((k) => k.toLowerCase()), | ||
| ); | ||
| const hasAllFactories = l2Factories.every((a) => allocKeys.has(a.toLowerCase())); | ||
|
|
||
| // Prepare the genesis assertion state | ||
| const genesisAssertionState = { | ||
| globalState: { | ||
| bytes32Vals: [genesisBlockHash as `0x${string}`, sendRootHash as `0x${string}`] as [ | ||
| `0x${string}`, | ||
| `0x${string}`, | ||
| ], | ||
| // Set inbox position to 1 | ||
| u64Vals: [1n, 0n] as [bigint, bigint], | ||
| }, | ||
| machineStatus: 0, // Running | ||
| endHistoryRoot: toHex(0, { size: 32 }), | ||
| }; | ||
|
Comment on lines
+165
to
+176
Member
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. prepareGenesisAssertionState(params: { genesisBlockHash: Hex, sendRootHash: Hex }): GenesisAssertionState |
||
|
|
||
| console.log(''); | ||
| console.log('------------------'); | ||
| console.log('Creating Rollup...'); | ||
| console.log('------------------'); | ||
| const createRollupConfig = createRollupPrepareDeploymentParamsConfig(parentChainPublicClient, { | ||
| chainId: BigInt(chainId), | ||
| owner: chainOwner, | ||
| chainConfig: genesisConfiguration.config, | ||
| genesisAssertionState, | ||
| }); | ||
|
|
||
| try { | ||
| await createRollup({ | ||
| params: { | ||
| config: createRollupConfig, | ||
| batchPosters: [batchPoster], | ||
| validators: [validator], | ||
| deployFactoriesToL2: !hasAllFactories, | ||
| }, | ||
| account: deployer, | ||
| parentChainPublicClient, | ||
| }); | ||
| } catch (error) { | ||
| console.error(`Rollup creation failed with error: ${error}`); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| main(); | ||
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.
Uh oh!
There was an error while loading. Please reload this page.