diff --git a/ops-bedrock/devnet-up.sh b/ops-bedrock/devnet-up.sh index 3e562cfc3f0c..f98db3c4a06d 100755 --- a/ops-bedrock/devnet-up.sh +++ b/ops-bedrock/devnet-up.sh @@ -58,9 +58,9 @@ function wait_up { mkdir -p ./.devnet if [ ! -f ./.devnet/rollup.json ]; then - GENESIS_TIMESTAMP=$(date +%s | xargs printf "0x%x") + L1_GENESIS_TIMESTAMP=$(date +%s | xargs printf "0x%x") else - GENESIS_TIMESTAMP=$(jq '.timestamp' < .devnet/genesis-l1.json) + L1_GENESIS_TIMESTAMP=$(jq '.timestamp' < .devnet/genesis-l1.json) fi # Regenerate the L1 genesis file if necessary. The existence of the genesis @@ -69,7 +69,7 @@ if [ ! -f ./.devnet/genesis-l1.json ]; then echo "Regenerating L1 genesis." ( cd $CONTRACTS_BEDROCK - L2OO_STARTING_BLOCK_TIMESTAMP=$GENESIS_TIMESTAMP npx hardhat genesis-l1 \ + L1_GENESIS_TIMESTAMP=$L1_GENESIS_TIMESTAMP npx hardhat genesis-l1 \ --outfile genesis-l1.json mv genesis-l1.json ../../.devnet/genesis-l1.json ) @@ -89,7 +89,7 @@ if [ ! -d $CONTRACTS_BEDROCK/deployments/$NETWORK ]; then ( echo "Deploying contracts." cd $CONTRACTS_BEDROCK - L2OO_STARTING_BLOCK_TIMESTAMP=$GENESIS_TIMESTAMP yarn hardhat --network $NETWORK deploy + L1_GENESIS_TIMESTAMP=$L1_GENESIS_TIMESTAMP yarn hardhat --network $NETWORK deploy ) else echo "Contracts already deployed, skipping." @@ -99,7 +99,7 @@ if [ ! -f ./.devnet/genesis-l2.json ]; then ( echo "Creating L2 genesis file." cd $CONTRACTS_BEDROCK - L2OO_STARTING_BLOCK_TIMESTAMP=$GENESIS_TIMESTAMP npx hardhat --network $NETWORK genesis-l2 + L1_GENESIS_TIMESTAMP=$L1_GENESIS_TIMESTAMP npx hardhat --network $NETWORK genesis-l2 mv genesis.json ../../.devnet/genesis-l2.json echo "Created L2 genesis." ) @@ -120,7 +120,7 @@ if [ ! -f ./.devnet/rollup.json ]; then ( echo "Building rollup config..." cd $CONTRACTS_BEDROCK - L2OO_STARTING_BLOCK_TIMESTAMP=$GENESIS_TIMESTAMP npx hardhat --network $NETWORK rollup-config + L1_GENESIS_TIMESTAMP=$L1_GENESIS_TIMESTAMP npx hardhat --network $NETWORK rollup-config mv rollup.json ../../.devnet/rollup.json ) else diff --git a/packages/contracts-bedrock/deploy-config/devnetL1.ts b/packages/contracts-bedrock/deploy-config/devnetL1.ts index b52637588c79..183398b51331 100644 --- a/packages/contracts-bedrock/deploy-config/devnetL1.ts +++ b/packages/contracts-bedrock/deploy-config/devnetL1.ts @@ -2,19 +2,20 @@ import { ethers } from 'ethers' const { env } = process -const startingTimestamp = - typeof env.L2OO_STARTING_BLOCK_TIMESTAMP === 'string' - ? ethers.BigNumber.from(env.L2OO_STARTING_BLOCK_TIMESTAMP).toNumber() +const l1GenesisTimestamp = + typeof env.L1_GENESIS_TIMESTAMP === 'string' + ? ethers.BigNumber.from(env.L1_GENESIS_TIMESTAMP).toNumber() : Math.floor(Date.now() / 1000) const config = { submissionInterval: 6, genesisOutput: ethers.constants.HashZero, historicalBlocks: 0, + l1StartingBlockTag: 'earliest', startingBlockNumber: 0, l2BlockTime: 2, - startingTimestamp, + l1GenesisTimestamp, sequencerAddress: '0x70997970C51812dc3A010C7d01b50e0d17dc79C8', l2CrossDomainMessengerOwner: ethers.constants.AddressZero, diff --git a/packages/contracts-bedrock/deploy-config/goerli.ts b/packages/contracts-bedrock/deploy-config/goerli.ts index 3398fd6eb33c..93347179520e 100644 --- a/packages/contracts-bedrock/deploy-config/goerli.ts +++ b/packages/contracts-bedrock/deploy-config/goerli.ts @@ -1,7 +1,8 @@ import { ethers } from 'ethers' const sequencerAddress = '0x6c23a0dcdfc44b7a57bed148de598895e398d984' -const startingTimestamp = 1658777882 +const l1StartingBlockTag = + '0xafce66a0a2446856112e4069b275ad32b1f4a607888f9c4c59eddf9be81f8670' const config = { submissionInterval: 6, @@ -9,7 +10,7 @@ const config = { historicalBlocks: 0, startingBlockNumber: 0, l2BlockTime: 2, - startingTimestamp, + l1StartingBlockTag, sequencerAddress, l2CrossDomainMessengerOwner: ethers.constants.AddressZero, diff --git a/packages/contracts-bedrock/deploy-config/hardhat.ts b/packages/contracts-bedrock/deploy-config/hardhat.ts index 217c63a20321..596c5b03c625 100644 --- a/packages/contracts-bedrock/deploy-config/hardhat.ts +++ b/packages/contracts-bedrock/deploy-config/hardhat.ts @@ -2,9 +2,9 @@ import { ethers } from 'ethers' const { env } = process -const startingTimestamp = - typeof env.L2OO_STARTING_BLOCK_TIMESTAMP === 'string' - ? ethers.BigNumber.from(env.L2OO_STARTING_BLOCK_TIMESTAMP).toNumber() +const l1GenesisTimestamp = + typeof env.L1_GENESIS_TIMESTAMP === 'string' + ? ethers.BigNumber.from(env.L1_GENESIS_TIMESTAMP).toNumber() : Math.floor(Date.now() / 1000) const config = { @@ -12,8 +12,9 @@ const config = { genesisOutput: ethers.constants.HashZero, historicalBlocks: 0, startingBlockNumber: 0, + l1StartingBlockTag: 'earliest', l2BlockTime: 2, - startingTimestamp, + l1GenesisTimestamp, sequencerAddress: '0x70997970C51812dc3A010C7d01b50e0d17dc79C8', maxSequencerDrift: 10, sequencerWindowSize: 4, diff --git a/packages/contracts-bedrock/deploy/000-L2OutputOracle.deploy.ts b/packages/contracts-bedrock/deploy/000-L2OutputOracle.deploy.ts index 0cc44305e7b0..c7602623ebc9 100644 --- a/packages/contracts-bedrock/deploy/000-L2OutputOracle.deploy.ts +++ b/packages/contracts-bedrock/deploy/000-L2OutputOracle.deploy.ts @@ -10,13 +10,10 @@ const deployFn: DeployFunction = async (hre) => { const { deployer } = await hre.getNamedAccounts() const { deployConfig } = hre - if ( - typeof deployConfig.startingTimestamp !== 'number' || - isNaN(deployConfig.startingTimestamp) - ) { - throw new Error( - 'Cannot deploy L2OutputOracle without specifying a valid startingTimestamp.' - ) + const l1 = hre.ethers.getDefaultProvider() + const l1StartingBlock = await l1.getBlock(deployConfig.l1StartingBlockTag) + if (l1StartingBlock === null) { + throw new Error(`Cannot fetch block tag ${deployConfig.l1StartingBlockTag}`) } await deploy('L2OutputOracleProxy', { @@ -34,7 +31,7 @@ const deployFn: DeployFunction = async (hre) => { deployConfig.genesisOutput, deployConfig.historicalBlocks, deployConfig.startingBlockNumber, - deployConfig.startingTimestamp, + l1StartingBlock.timestamp, deployConfig.l2BlockTime, deployConfig.sequencerAddress, deployConfig.outputOracleOwner, @@ -84,7 +81,7 @@ const deployFn: DeployFunction = async (hre) => { } const startingTimestamp = await L2OutputOracle.STARTING_TIMESTAMP() - if (!startingTimestamp.eq(BigNumber.from(deployConfig.startingTimestamp))) { + if (!startingTimestamp.eq(BigNumber.from(l1StartingBlock.timestamp))) { throw new Error('starting timestamp misconfigured') } const l2BlockTime = await L2OutputOracle.L2_BLOCK_TIME() diff --git a/packages/contracts-bedrock/hardhat.config.ts b/packages/contracts-bedrock/hardhat.config.ts index de235ce8f315..e07578243e41 100644 --- a/packages/contracts-bedrock/hardhat.config.ts +++ b/packages/contracts-bedrock/hardhat.config.ts @@ -74,18 +74,15 @@ const config: HardhatUserConfig = { historicalBlocks: { type: 'number', }, - startingBlockNumber: { - type: 'number', - }, - startingTimestamp: { - type: 'number', - }, sequencerAddress: { type: 'address', }, outputOracleOwner: { type: 'address', }, + l1StartingBlockTag: { + type: 'string', + }, }, external: { contracts: [ diff --git a/packages/contracts-bedrock/tasks/genesis-l1.ts b/packages/contracts-bedrock/tasks/genesis-l1.ts index e01043582f54..deac7649c116 100644 --- a/packages/contracts-bedrock/tasks/genesis-l1.ts +++ b/packages/contracts-bedrock/tasks/genesis-l1.ts @@ -61,7 +61,7 @@ task('genesis-l1', 'create a genesis config') } } - const timestamp = hre.deployConfig.startingTimestamp + const timestamp = hre.deployConfig.l1GenesisTimestamp if (timestamp === undefined) { throw new Error('Must configure starting block timestamp') } diff --git a/packages/contracts-bedrock/tasks/genesis-l2.ts b/packages/contracts-bedrock/tasks/genesis-l2.ts index 322faa40fbe6..60a3de25e4c6 100644 --- a/packages/contracts-bedrock/tasks/genesis-l2.ts +++ b/packages/contracts-bedrock/tasks/genesis-l2.ts @@ -462,8 +462,12 @@ task('genesis-l2', 'create a genesis config') } } - const portal = await hre.deployments.get('OptimismPortalProxy') - const l1StartingBlock = await l1.getBlock(portal.receipt.blockHash) + const l1StartingBlock = await l1.getBlock(deployConfig.l1StartingBlockTag) + if (l1StartingBlock === null) { + throw new Error( + `Cannot fetch block tag ${deployConfig.l1StartingBlockTag}` + ) + } if (l1StartingBlock === null) { console.log(`Unable to fetch L1 starting timestamp`) diff --git a/packages/contracts-bedrock/tasks/rollup-config.ts b/packages/contracts-bedrock/tasks/rollup-config.ts index 268d2b39e47f..f80b0d523341 100644 --- a/packages/contracts-bedrock/tasks/rollup-config.ts +++ b/packages/contracts-bedrock/tasks/rollup-config.ts @@ -23,13 +23,18 @@ task('rollup-config', 'create a genesis config') const l2Genesis = await l2.getBlock('earliest') const portal = await hre.deployments.get('OptimismPortalProxy') - const l1StartingBlock = await l1.getBlock(portal.receipt.blockHash) + const l1StartingBlock = await l1.getBlock(deployConfig.l1StartingBlockTag) + if (l1StartingBlock === null) { + throw new Error( + `Cannot fetch block tag ${deployConfig.l1StartingBlockTag}` + ) + } const config: OpNodeConfig = { genesis: { l1: { - hash: portal.receipt.blockHash, - number: portal.receipt.blockNumber, + hash: l1StartingBlock.hash, + number: l1StartingBlock.number, }, l2: { hash: l2Genesis.hash, diff --git a/packages/contracts-bedrock/tsconfig.json b/packages/contracts-bedrock/tsconfig.json index 5cb4fda3c546..e5df8a66de31 100644 --- a/packages/contracts-bedrock/tsconfig.json +++ b/packages/contracts-bedrock/tsconfig.json @@ -4,7 +4,5 @@ "rootDir": "./src", "outDir": "./dist" }, - "include": [ - "src/**/*" - ] + "include": ["src/**/*"] }