• Joshua Gutow's avatar
    ops: Use starting L1 Block for timestamp everywhere (#3085) · 9e976947
    Joshua Gutow authored
    * ops: Use starting L1 Block for timestamp everywhere
    
    This transitions the starting timestamp to a new flow. The L2 rollup
    is anchored on a L1 block. The L2 genesis block & rollup config use
    the timestamp of the L1 start block as the their time. Properly
    threading this through the HH tasks is a little tricky but possible.
    This is because we have two flows: creating a L1 network & placing
    the rollup on that and creating a rollup on an existing L1 network
    (like goerli). There is still a L1 starting time for the first flow.
    
    This also fixes a circular dependcy that previously existed. The
    starting timestamp was provided and served as the starting timestamp
    for the L1 genesis & the "L2 Starting Time" in the L2 Output Oracle.
    The actual L2 genesis & rollup start time were based on when the
    Optimism Portal contract was deployed (after the L2 Output Oracle
    contract must have been deployed). The rollup is resilient to being
    started before contracts are fully deployed, so using a specific
    L1 block as the start is the cleanest solution I have seen.
    
    * Fix lint
    
    * Update packages/contracts-bedrock/deploy-config/goerli.ts
    
    * Add undefined checks to l1StartingBlockTag
    
    * lint
    
    * fix checks
    Co-authored-by: default avatarMatthew Slipper <me@matthewslipper.com>
    Co-authored-by: default avatarmergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
    9e976947
rollup-config.ts 2.02 KB
import fs from 'fs'

import { task } from 'hardhat/config'
import { OpNodeConfig, getChainId } from '@eth-optimism/core-utils'
import { ethers } from 'ethers'
import 'hardhat-deploy'
import '@eth-optimism/hardhat-deploy-config'

task('rollup-config', 'create a genesis config')
  .addOptionalParam(
    'outfile',
    'The file to write the output JSON to',
    'rollup.json'
  )
  .addOptionalParam('l1RpcUrl', 'The L1 RPC URL', 'http://127.0.0.1:8545')
  .addOptionalParam('l2RpcUrl', 'The L2 RPC URL', 'http://127.0.0.1:9545')
  .setAction(async (args, hre) => {
    const { deployConfig } = hre

    const l1 = new ethers.providers.StaticJsonRpcProvider(args.l1RpcUrl)
    const l2 = new ethers.providers.StaticJsonRpcProvider(args.l2RpcUrl)

    const l2Genesis = await l2.getBlock('earliest')

    const portal = await hre.deployments.get('OptimismPortalProxy')
    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: l1StartingBlock.hash,
          number: l1StartingBlock.number,
        },
        l2: {
          hash: l2Genesis.hash,
          number: 0,
        },
        l2_time: l1StartingBlock.timestamp,
      },
      block_time: deployConfig.l2BlockTime,
      max_sequencer_drift: deployConfig.maxSequencerDrift,
      seq_window_size: deployConfig.sequencerWindowSize,
      channel_timeout: deployConfig.channelTimeout,

      l1_chain_id: await getChainId(l1),
      l2_chain_id: await getChainId(l2),

      p2p_sequencer_address: deployConfig.p2pSequencerAddress,
      fee_recipient_address: deployConfig.optimismL2FeeRecipient,
      batch_inbox_address: '0xff00000000000000000000000000000000000002',
      batch_sender_address: deployConfig.batchSenderAddress,
      deposit_contract_address: portal.address,
    }

    fs.writeFileSync(args.outfile, JSON.stringify(config, null, 2))
  })