Skip to content
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

ops: Use starting L1 Block for timestamp everywhere #3085

Merged
merged 7 commits into from
Jul 29, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions ops-bedrock/devnet-up.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
)
Expand All @@ -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."
Expand All @@ -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."
)
Expand All @@ -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
Expand Down
9 changes: 5 additions & 4 deletions packages/contracts-bedrock/deploy-config/devnetL1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions packages/contracts-bedrock/deploy-config/goerli.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { ethers } from 'ethers'


const sequencerAddress = '0x6c23a0dcdfc44b7a57bed148de598895e398d984'
const startingTimestamp = 1658777882
const l1StartingBlockTag = ''
trianglesphere marked this conversation as resolved.
Show resolved Hide resolved
trianglesphere marked this conversation as resolved.
Show resolved Hide resolved

const config = {
submissionInterval: 6,
genesisOutput: ethers.constants.HashZero,
historicalBlocks: 0,
startingBlockNumber: 0,
l2BlockTime: 2,
startingTimestamp,
l1StartingBlockTag,
sequencerAddress,

l2CrossDomainMessengerOwner: ethers.constants.AddressZero,
Expand Down
9 changes: 5 additions & 4 deletions packages/contracts-bedrock/deploy-config/hardhat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@ 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,
startingBlockNumber: 0,
l1StartingBlockTag: 'earliest',
l2BlockTime: 2,
startingTimestamp,
l1GenesisTimestamp,
sequencerAddress: '0x70997970C51812dc3A010C7d01b50e0d17dc79C8',
maxSequencerDrift: 10,
sequencerWindowSize: 4,
Expand Down
14 changes: 4 additions & 10 deletions packages/contracts-bedrock/deploy/000-L2OutputOracle.deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,8 @@ 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)
trianglesphere marked this conversation as resolved.
Show resolved Hide resolved

await deploy('L2OutputOracleProxy', {
contract: 'Proxy',
Expand All @@ -34,7 +28,7 @@ const deployFn: DeployFunction = async (hre) => {
deployConfig.genesisOutput,
deployConfig.historicalBlocks,
deployConfig.startingBlockNumber,
deployConfig.startingTimestamp,
l1StartingBlock.timestamp,
deployConfig.l2BlockTime,
deployConfig.sequencerAddress,
deployConfig.outputOracleOwner,
Expand Down Expand Up @@ -84,7 +78,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()
Expand Down
9 changes: 3 additions & 6 deletions packages/contracts-bedrock/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,15 @@ const config: HardhatUserConfig = {
historicalBlocks: {
type: 'number',
},
startingBlockNumber: {
type: 'number',
},
startingTimestamp: {
type: 'number',
},
sequencerAddress: {
type: 'address',
},
outputOracleOwner: {
type: 'address',
},
l1StartingBlockTag: {
type: 'string',
},
},
external: {
contracts: [
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts-bedrock/tasks/genesis-l1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
Expand Down
3 changes: 1 addition & 2 deletions packages/contracts-bedrock/tasks/genesis-l2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,7 @@ 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)

const genesis: OptimismGenesis = {
config: {
Expand Down
6 changes: 3 additions & 3 deletions packages/contracts-bedrock/tasks/rollup-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ 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)
trianglesphere marked this conversation as resolved.
Show resolved Hide resolved

const config: OpNodeConfig = {
genesis: {
l1: {
hash: portal.receipt.blockHash,
number: portal.receipt.blockNumber,
hash: l1StartingBlock.hash,
number: l1StartingBlock.number,
},
l2: {
hash: l2Genesis.hash,
Expand Down