-
Notifications
You must be signed in to change notification settings - Fork 158
feat: NO_PARALLEL_DEPLOYMENT #368
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
Closed
gzeoneth
wants to merge
5
commits into
deterministic-factory-deployments-parallel
from
deterministic-factory-deployments-series
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
29f5b78
feat: NO_PARALLEL_DEPLOYMENT
gzeoneth 47804db
Merge branch 'deterministic-factory-deployments-parallel' into determ…
gzeoneth 4b6898d
Merge branch 'deterministic-factory-deployments-parallel' into determ…
gzeoneth 3defdfd
Merge branch 'deterministic-factory-deployments-parallel' into determ…
gzeoneth ec344f6
fix: resolveDeployLock
gzeoneth 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,6 +48,7 @@ class SimpleMutex { | |
| let nonceManager: { [key: string]: number } = {} | ||
| let nonceLock = new SimpleMutex() | ||
| let verifyLock = new SimpleMutex() | ||
| let deployLock = new SimpleMutex() | ||
|
|
||
| // Define a verification function | ||
| export async function verifyContract( | ||
|
|
@@ -135,15 +136,20 @@ export async function deployContract( | |
| overrides | ||
| ) | ||
| } else { | ||
| // For non-CREATE2 deployments, use nonce manager | ||
| const nonce = await getNextNonce(signer) | ||
| const deployOverrides = { ...overrides, nonce } | ||
|
|
||
| // Update deployment args with overrides | ||
| if (overrides) { | ||
| deploymentArgs[deploymentArgs.length - 1] = deployOverrides | ||
| } else { | ||
| deploymentArgs.push(deployOverrides) | ||
| // For non-CREATE2 deployments, use nonce manager only in parallel mode | ||
| const useSerialDeployment = process.env.NO_PARALLEL_DEPLOYMENT === 'true' | ||
|
|
||
| if (!useSerialDeployment) { | ||
| // Parallel mode: use nonce manager | ||
| const nonce = await getNextNonce(signer) | ||
| const deployOverrides = { ...overrides, nonce } | ||
|
|
||
| // Update deployment args with overrides | ||
| if (overrides) { | ||
| deploymentArgs[deploymentArgs.length - 1] = deployOverrides | ||
| } else { | ||
| deploymentArgs.push(deployOverrides) | ||
| } | ||
| } | ||
|
|
||
| contract = await connectedFactory.deploy(...deploymentArgs) | ||
|
|
@@ -178,6 +184,32 @@ async function getNextNonce(signer: any): Promise<number> { | |
| } | ||
| } | ||
|
|
||
| // Helper function to handle both parallel and serial deployments | ||
| async function deployBatch<T>( | ||
| deployFunctions: (() => Promise<T>)[] | ||
| ): Promise<T[]> { | ||
| const isSerialDeployment = process.env.NO_PARALLEL_DEPLOYMENT === 'true' | ||
|
|
||
| if (isSerialDeployment) { | ||
gzeoneth marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // Serial deployment: execute one by one using the nonce lock as mutex | ||
| const results: T[] = [] | ||
| for (const deployFn of deployFunctions) { | ||
| const resolveDeployLock = await deployLock.lock() | ||
|
|
||
| try { | ||
| const result = await deployFn() | ||
| results.push(result) | ||
| } finally { | ||
| resolveDeployLock() | ||
| } | ||
| } | ||
| return results | ||
| } else { | ||
| // Parallel deployment | ||
| return Promise.all(deployFunctions.map(fn => fn())) | ||
| } | ||
| } | ||
|
|
||
| export async function create2( | ||
| fac: ContractFactory, | ||
| deploymentArgs: Array<any>, | ||
|
|
@@ -209,13 +241,21 @@ export async function create2( | |
| return fac.attach(address) | ||
| } | ||
|
|
||
| const nonce = await getNextNonce(fac.signer) | ||
| const tx = await fac.signer.sendTransaction({ | ||
| const isSerialDeployment = process.env.NO_PARALLEL_DEPLOYMENT === 'true' | ||
|
|
||
| const txParams: any = { | ||
| to: FACTORY, | ||
| data: concat([salt, data]), | ||
| nonce, | ||
| ...overrides, | ||
|
Comment on lines
247
to
249
|
||
| }) | ||
| } | ||
|
|
||
| if (!isSerialDeployment) { | ||
| // Only use nonce manager in parallel mode | ||
| const nonce = await getNextNonce(fac.signer) | ||
| txParams.nonce = nonce | ||
| } | ||
|
|
||
| const tx = await fac.signer.sendTransaction(txParams) | ||
| await tx.wait() | ||
|
|
||
| return fac.attach(address) | ||
|
|
@@ -231,6 +271,11 @@ export async function deployAllContracts( | |
| // Reset nonce manager for fresh deployment | ||
| nonceManager = {} | ||
|
|
||
| const isSerialDeployment = process.env.NO_PARALLEL_DEPLOYMENT === 'true' | ||
| if (isSerialDeployment) { | ||
| console.log('Using serial deployment mode (NO_PARALLEL_DEPLOYMENT=true)') | ||
| } | ||
|
|
||
| const isOnArb = await _isRunningOnArbitrum(signer) | ||
|
|
||
| // Deploy Reader4844 first if not on Arbitrum | ||
|
|
@@ -248,7 +293,12 @@ export async function deployAllContracts( | |
| ) | ||
| ).address | ||
|
|
||
| console.log('Deploying bridge templates in parallel...') | ||
| console.log( | ||
| `Deploying bridge templates${ | ||
| isSerialDeployment ? ' in serial mode' : ' in parallel' | ||
| }...` | ||
| ) | ||
|
|
||
| const [ | ||
| ethBridge, | ||
| ethSequencerInbox, | ||
|
|
@@ -262,74 +312,87 @@ export async function deployAllContracts( | |
| erc20Inbox, | ||
| erc20RollupEventInbox, | ||
| erc20Outbox, | ||
| ] = await Promise.all([ | ||
| deployContract('Bridge', signer, [], verify, true), | ||
| deployContract( | ||
| 'SequencerInbox', | ||
| signer, | ||
| [maxDataSize, reader4844, false, false], | ||
| verify, | ||
| true | ||
| ), | ||
| deployContract( | ||
| 'SequencerInbox', | ||
| signer, | ||
| [maxDataSize, reader4844, false, true], | ||
| verify, | ||
| true | ||
| ), | ||
| deployContract('Inbox', signer, [maxDataSize], verify, true), | ||
| deployContract('RollupEventInbox', signer, [], verify, true), | ||
| deployContract('Outbox', signer, [], verify, true), | ||
| deployContract('ERC20Bridge', signer, [], verify, true), | ||
| deployContract( | ||
| 'SequencerInbox', | ||
| signer, | ||
| [maxDataSize, reader4844, true, false], | ||
| verify, | ||
| true | ||
| ), | ||
| deployContract( | ||
| 'SequencerInbox', | ||
| signer, | ||
| [maxDataSize, reader4844, true, true], | ||
| verify, | ||
| true | ||
| ), | ||
| deployContract('ERC20Inbox', signer, [maxDataSize], verify, true), | ||
| deployContract('ERC20RollupEventInbox', signer, [], verify, true), | ||
| deployContract('ERC20Outbox', signer, [], verify, true), | ||
| ] = await deployBatch([ | ||
| () => deployContract('Bridge', signer, [], verify, true), | ||
| () => | ||
| deployContract( | ||
| 'SequencerInbox', | ||
| signer, | ||
| [maxDataSize, reader4844, false, false], | ||
| verify, | ||
| true | ||
| ), | ||
| () => | ||
| deployContract( | ||
| 'SequencerInbox', | ||
| signer, | ||
| [maxDataSize, reader4844, false, true], | ||
| verify, | ||
| true | ||
| ), | ||
| () => deployContract('Inbox', signer, [maxDataSize], verify, true), | ||
| () => deployContract('RollupEventInbox', signer, [], verify, true), | ||
| () => deployContract('Outbox', signer, [], verify, true), | ||
| () => deployContract('ERC20Bridge', signer, [], verify, true), | ||
| () => | ||
| deployContract( | ||
| 'SequencerInbox', | ||
| signer, | ||
| [maxDataSize, reader4844, true, false], | ||
| verify, | ||
| true | ||
| ), | ||
| () => | ||
| deployContract( | ||
| 'SequencerInbox', | ||
| signer, | ||
| [maxDataSize, reader4844, true, true], | ||
| verify, | ||
| true | ||
| ), | ||
| () => deployContract('ERC20Inbox', signer, [maxDataSize], verify, true), | ||
| () => deployContract('ERC20RollupEventInbox', signer, [], verify, true), | ||
| () => deployContract('ERC20Outbox', signer, [], verify, true), | ||
| ]) | ||
|
|
||
| console.log('Deploying OneStepProver contracts and OneStepProofEntry...') | ||
| const ospDeployment = await deployOneStepProofEntry(signer, verify) | ||
| const ospDeployment = await deployOneStepProofEntry( | ||
| signer, | ||
| verify, | ||
| isSerialDeployment | ||
| ) | ||
| const { prover0, proverMem, proverMath, proverHostIo, osp } = ospDeployment | ||
|
|
||
| console.log('Deploying core contracts in parallel...') | ||
| console.log( | ||
| `Deploying core contracts${ | ||
| isSerialDeployment ? ' in serial mode' : ' in parallel' | ||
| }...` | ||
| ) | ||
|
|
||
| const [ | ||
| challengeManager, | ||
| rollupAdmin, | ||
| rollupUser, | ||
| upgradeExecutorResult, | ||
| upgradeExecutor, | ||
| validatorWalletCreator, | ||
| deployHelper, | ||
| ] = await Promise.all([ | ||
| deployContract('EdgeChallengeManager', signer, [], verify, true), | ||
| deployContract('RollupAdminLogic', signer, [], verify, true), | ||
| deployContract('RollupUserLogic', signer, [], verify, true), | ||
| create2( | ||
| ( | ||
| await ethers.getContractFactory( | ||
| UpgradeExecutorABI, | ||
| UpgradeExecutorBytecode | ||
| ) | ||
| ).connect(signer), | ||
| [] | ||
| ), | ||
| deployContract('ValidatorWalletCreator', signer, [], verify, true), | ||
| deployContract('DeployHelper', signer, [], verify, true), | ||
| ] = await deployBatch([ | ||
| () => deployContract('EdgeChallengeManager', signer, [], verify, true), | ||
| () => deployContract('RollupAdminLogic', signer, [], verify, true), | ||
| () => deployContract('RollupUserLogic', signer, [], verify, true), | ||
| async () => | ||
| create2( | ||
gzeoneth marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ( | ||
| await ethers.getContractFactory( | ||
| UpgradeExecutorABI, | ||
| UpgradeExecutorBytecode | ||
| ) | ||
| ).connect(signer), | ||
| [] | ||
| ), | ||
| () => deployContract('ValidatorWalletCreator', signer, [], verify, true), | ||
| () => deployContract('DeployHelper', signer, [], verify, true), | ||
| ]) | ||
| const upgradeExecutor = upgradeExecutorResult | ||
|
|
||
| console.log('Deploying bridgeCreator...') | ||
| const bridgeCreator = await deployContract( | ||
|
|
@@ -401,22 +464,26 @@ export async function deployAllContracts( | |
|
|
||
| export async function deployOneStepProofEntry( | ||
| signer: any, | ||
| verify: boolean = true | ||
| verify: boolean = true, | ||
| isSerialDeployment: boolean = false | ||
| ): Promise<{ | ||
| prover0: Contract | ||
| proverMem: Contract | ||
| proverMath: Contract | ||
| proverHostIo: Contract | ||
| osp: Contract | ||
| }> { | ||
| console.log('Deploying OneStepProver contracts with custom DA validator...') | ||
|
|
||
| // Deploy the four OneStepProver contracts in parallel | ||
| const [prover0, proverMem, proverMath, proverHostIo] = await Promise.all([ | ||
| deployContract('OneStepProver0', signer, [], verify, true), | ||
| deployContract('OneStepProverMemory', signer, [], verify, true), | ||
| deployContract('OneStepProverMath', signer, [], verify, true), | ||
| deployContract('OneStepProverHostIo', signer, [], verify, true), | ||
| console.log( | ||
| `Deploying OneStepProver contracts${ | ||
| isSerialDeployment ? ' in serial mode' : '' | ||
| }...` | ||
| ) | ||
|
|
||
| const [prover0, proverMem, proverMath, proverHostIo] = await deployBatch([ | ||
| () => deployContract('OneStepProver0', signer, [], verify, true), | ||
| () => deployContract('OneStepProverMemory', signer, [], verify, true), | ||
| () => deployContract('OneStepProverMath', signer, [], verify, true), | ||
| () => deployContract('OneStepProverHostIo', signer, [], verify, true), | ||
| ]) | ||
|
|
||
| console.log('Deploying OneStepProofEntry...') | ||
|
|
||
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.
[nitpick] The environment check
process.env.NO_PARALLEL_DEPLOYMENT === 'true'is repeated in multiple functions. Extract this into a single helper constant or function to reduce duplication and simplify future changes.