Skip to content

Commit

Permalink
Merge pull request ethereum-optimism#4696 from ethereum-optimism/fix/…
Browse files Browse the repository at this point in the history
…wait-tasks

contracts-bedrock: fix migration tasks
  • Loading branch information
tynes authored Jan 17, 2023
2 parents d8e328a + d0ec9af commit f04170e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
17 changes: 11 additions & 6 deletions packages/contracts-bedrock/tasks/wait-for-final-batch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,26 +48,31 @@ task('wait-for-final-batch', 'Waits for the final batch to be submitted')
const wait = async (contract: Contract) => {
let height = await l2Provider.getBlockNumber()
let totalElements = await contract.getTotalElements()
// The genesis block was not batch submitted so subtract 1 from the height
// when comparing with the total elements
while (totalElements !== height - 1) {
console.log(` - height: ${height}`)
console.log(` - totalElements: ${totalElements}`)

while (totalElements.toNumber() !== height) {
console.log('Total elements does not match')
console.log(` - real height: ${height}`)
console.log(` - height: ${height - 1}`)
console.log(` - height: ${height}`)
console.log(` - totalElements: ${totalElements}`)
console.log(
`Waiting for ${height - totalElements} elements to be submitted`
)
totalElements = await contract.getTotalElements()
height = await l2Provider.getBlockNumber()
await sleep(2 * 1000)
await sleep(5 * 1000)
}
}

console.log('Waiting for the CanonicalTransactionChain...')
await wait(CanonicalTransactionChain)
console.log('All transaction batches have been submitted')
console.log()

console.log('Waiting for the StateCommitmentChain...')
await wait(StateCommitmentChain)
console.log('All state root batches have been submitted')
console.log()

console.log('All batches have been submitted')
})
9 changes: 7 additions & 2 deletions packages/contracts-bedrock/tasks/wait-for-final-deposit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ task('wait-for-final-deposit', 'Waits for the final deposit to be ingested')
const l1Provider = new hre.ethers.providers.StaticJsonRpcProvider(
args.l1RpcUrl
)

const l2Provider = new hre.ethers.providers.StaticJsonRpcProvider(
args.l2RpcUrl
)
Expand Down Expand Up @@ -63,6 +64,9 @@ task('wait-for-final-deposit', 'Waits for the final deposit to be ingested')

console.log(`DTL shutoff block ${dtlShutoffBlock.toString()}`)

let pending = await CanonicalTransactionChain.getNumPendingQueueElements()
console.log(`${pending} deposits must be batch submitted`)

// Now query the number of queue elements in the CTC
const queueLength = await CanonicalTransactionChain.getQueueLength()
console.log(`Total number of deposits: ${queueLength}`)
Expand All @@ -80,11 +84,10 @@ task('wait-for-final-deposit', 'Waits for the final deposit to be ingested')

if (tx.queueOrigin === 'l1') {
const queueIndex = BigNumber.from(tx.queueIndex).toNumber()
if (queueIndex === queueLength) {
if (queueIndex === queueLength - 1) {
break
}
if (queueIndex < queueLength) {
console.log()
throw new Error(
`Missed the final deposit. queueIndex ${queueIndex}, queueLength ${queueLength}`
)
Expand All @@ -94,4 +97,6 @@ task('wait-for-final-deposit', 'Waits for the final deposit to be ingested')
}

console.log('Final deposit has been ingested by l2geth')
pending = await CanonicalTransactionChain.getNumPendingQueueElements()
console.log(`${pending} deposits must be batch submitted`)
})

0 comments on commit f04170e

Please sign in to comment.