From 7f3a33564a703f8efb12f55300c01f2923857441 Mon Sep 17 00:00:00 2001 From: prathamesh0 <42446521+prathamesh0@users.noreply.github.com> Date: Tue, 25 Apr 2023 10:41:47 +0530 Subject: [PATCH] Upgrade Optimism and add op-proposer (#364) * Use the latest stable optimism release * Remove unnecessary repos from repo-list * Add op-proposer service to fixturenet-optimism stack * Add jq and bash to op-proposer image * Update instructions * Update op-batcher and op-geth commands Former-commit-id: 988be0ef9ab6c4f3b74431ca0bd31c41fa0584b0 --- .../docker-compose-fixturenet-optimism.yml | 23 ++++++++++++ .../optimism-contracts/run.sh | 16 ++++----- .../fixturenet-optimism/run-op-batcher.sh | 4 +-- .../config/fixturenet-optimism/run-op-geth.sh | 4 +-- .../config/fixturenet-optimism/run-op-node.sh | 3 +- .../fixturenet-optimism/run-op-proposer.sh | 36 +++++++++++++++++++ .../cerc-optimism-l2geth/build.sh | 3 ++ .../cerc-optimism-op-batcher/build.sh | 3 ++ .../cerc-optimism-op-node/build.sh | 3 ++ .../cerc-optimism-op-proposer/Dockerfile | 31 ++++++++++++++++ .../cerc-optimism-op-proposer/build.sh | 8 +++++ app/data/container-image-list.txt | 1 + app/data/pod-list.txt | 1 - app/data/repository-list.txt | 2 -- app/data/stacks/fixturenet-optimism/README.md | 5 +-- .../stacks/fixturenet-optimism/l2-only.md | 7 ++-- app/data/stacks/fixturenet-optimism/stack.yml | 1 + app/data/stacks/mobymask-v2/README.md | 2 +- 18 files changed, 131 insertions(+), 22 deletions(-) create mode 100755 app/data/config/fixturenet-optimism/run-op-proposer.sh create mode 100644 app/data/container-build/cerc-optimism-op-proposer/Dockerfile create mode 100755 app/data/container-build/cerc-optimism-op-proposer/build.sh diff --git a/app/data/compose/docker-compose-fixturenet-optimism.yml b/app/data/compose/docker-compose-fixturenet-optimism.yml index 02b0cbc3..c9e17b03 100644 --- a/app/data/compose/docker-compose-fixturenet-optimism.yml +++ b/app/data/compose/docker-compose-fixturenet-optimism.yml @@ -125,6 +125,29 @@ services: extra_hosts: - "host.docker.internal:host-gateway" + # Runs the proposer (periodically submits new state roots to L1) + op-proposer: + image: cerc/optimism-op-proposer:local + depends_on: + op-node: + condition: service_healthy + env_file: + - ../config/fixturenet-optimism/l1-params.env + environment: + CERC_SCRIPT_DEBUG: ${CERC_SCRIPT_DEBUG} + CERC_L1_RPC: ${CERC_L1_RPC} + volumes: + - ../config/wait-for-it.sh:/wait-for-it.sh + - ../config/fixturenet-optimism/run-op-proposer.sh:/run-op-proposer.sh + - l1_deployment:/contracts-bedrock:ro + - l2_accounts:/l2-accounts:ro + entrypoint: ["sh", "-c"] + # Waits for L1 endpoint to be up before running the proposer + command: | + "/wait-for-it.sh -h ${CERC_L1_HOST:-$${DEFAULT_CERC_L1_HOST}} -p ${CERC_L1_PORT:-$${DEFAULT_CERC_L1_PORT}} -s -t 60 -- /run-op-proposer.sh" + extra_hosts: + - "host.docker.internal:host-gateway" + volumes: l1_deployment: l2_accounts: diff --git a/app/data/config/fixturenet-optimism/optimism-contracts/run.sh b/app/data/config/fixturenet-optimism/optimism-contracts/run.sh index eb55e1fd..d878c03f 100755 --- a/app/data/config/fixturenet-optimism/optimism-contracts/run.sh +++ b/app/data/config/fixturenet-optimism/optimism-contracts/run.sh @@ -76,6 +76,13 @@ else echo "Couldn't fetch L1 account credentials, using them from env" fi +# Send balances to the above L2 addresses +yarn hardhat send-balance --to "${ADMIN_ADDRESS}" --amount 2 --private-key "${CERC_L1_PRIV_KEY}" --network getting-started +yarn hardhat send-balance --to "${PROPOSER_ADDRESS}" --amount 5 --private-key "${CERC_L1_PRIV_KEY}" --network getting-started +yarn hardhat send-balance --to "${BATCHER_ADDRESS}" --amount 1000 --private-key "${CERC_L1_PRIV_KEY}" --network getting-started + +echo "Balances sent to L2 accounts" + # Select a finalized L1 block as the starting point for roll ups until FINALIZED_BLOCK=$(cast block finalized --rpc-url "$CERC_L1_RPC"); do echo "Waiting for a finalized L1 block to exist, retrying after 10s" @@ -88,13 +95,6 @@ L1_BLOCKTIMESTAMP=$(echo "$FINALIZED_BLOCK" | awk '/timestamp/{print $2}') echo "Selected L1 block ${L1_BLOCKNUMBER} as the starting block for roll ups" -# Send balances to the above L2 addresses -yarn hardhat send-balance --to "${ADMIN_ADDRESS}" --amount 2 --private-key "${CERC_L1_PRIV_KEY}" --network getting-started -yarn hardhat send-balance --to "${PROPOSER_ADDRESS}" --amount 5 --private-key "${CERC_L1_PRIV_KEY}" --network getting-started -yarn hardhat send-balance --to "${BATCHER_ADDRESS}" --amount 1000 --private-key "${CERC_L1_PRIV_KEY}" --network getting-started - -echo "Balances sent to L2 accounts" - # Update the deployment config sed -i 's/"l2OutputOracleStartingTimestamp": TIMESTAMP/"l2OutputOracleStartingTimestamp": '"$L1_BLOCKTIMESTAMP"'/g' deploy-config/getting-started.json jq --arg chainid "$CERC_L1_CHAIN_ID" '.l1ChainID = ($chainid | tonumber)' deploy-config/getting-started.json > tmp.json && mv tmp.json deploy-config/getting-started.json @@ -110,7 +110,7 @@ echo "PRIVATE_KEY_DEPLOYER=$ADMIN_PRIV_KEY" >> .env echo "Deploying the L1 smart contracts, this will take a while..." # Deploy the L1 smart contracts -yarn hardhat deploy --network getting-started +yarn hardhat deploy --network getting-started --tags l1 echo "Deployed the L1 smart contracts" diff --git a/app/data/config/fixturenet-optimism/run-op-batcher.sh b/app/data/config/fixturenet-optimism/run-op-batcher.sh index 4bee6036..18955545 100755 --- a/app/data/config/fixturenet-optimism/run-op-batcher.sh +++ b/app/data/config/fixturenet-optimism/run-op-batcher.sh @@ -6,7 +6,7 @@ fi CERC_L1_RPC="${CERC_L1_RPC:-${DEFAULT_CERC_L1_RPC}}" -# Get BACTHER_KEY from keys.json +# Get Batcher key from keys.json BATCHER_KEY=$(jq -r '.Batcher.privateKey' /l2-accounts/keys.json | tr -d '"') cleanup() { @@ -18,6 +18,7 @@ cleanup() { } trap 'cleanup' INT TERM +# Run op-batcher op-batcher \ --l2-eth-rpc=http://op-geth:8545 \ --rollup-rpc=http://op-node:8547 \ @@ -30,7 +31,6 @@ op-batcher \ --rpc.port=8548 \ --rpc.enable-admin \ --max-channel-duration=1 \ - --target-l1-tx-size-bytes=2048 \ --l1-eth-rpc=$CERC_L1_RPC \ --private-key=$BATCHER_KEY \ & diff --git a/app/data/config/fixturenet-optimism/run-op-geth.sh b/app/data/config/fixturenet-optimism/run-op-geth.sh index 48391d73..8b521f85 100755 --- a/app/data/config/fixturenet-optimism/run-op-geth.sh +++ b/app/data/config/fixturenet-optimism/run-op-geth.sh @@ -8,7 +8,7 @@ fi echo "Installing jq" apk update && apk add jq -# Get SEQUENCER key from keys.json +# Get Sequencer key from keys.json SEQUENCER_KEY=$(jq -r '.Sequencer.privateKey' /l2-accounts/keys.json | tr -d '"') # Initialize op-geth if datadir/geth not found @@ -70,7 +70,7 @@ geth \ --ws.origins="*" \ --ws.api=debug,eth,txpool,net,engine \ --syncmode=full \ - --gcmode=full \ + --gcmode=archive \ --nodiscover \ --maxpeers=0 \ --networkid=42069 \ diff --git a/app/data/config/fixturenet-optimism/run-op-node.sh b/app/data/config/fixturenet-optimism/run-op-node.sh index b7cc8680..516cf0a5 100755 --- a/app/data/config/fixturenet-optimism/run-op-node.sh +++ b/app/data/config/fixturenet-optimism/run-op-node.sh @@ -6,9 +6,10 @@ fi CERC_L1_RPC="${CERC_L1_RPC:-${DEFAULT_CERC_L1_RPC}}" -# Get SEQUENCER KEY from keys.json +# Get Sequencer key from keys.json SEQUENCER_KEY=$(jq -r '.Sequencer.privateKey' /l2-accounts/keys.json | tr -d '"') +# Run op-node op-node \ --l2=http://op-geth:8551 \ --l2.jwt-secret=/op-node-data/jwt.txt \ diff --git a/app/data/config/fixturenet-optimism/run-op-proposer.sh b/app/data/config/fixturenet-optimism/run-op-proposer.sh new file mode 100755 index 00000000..09746760 --- /dev/null +++ b/app/data/config/fixturenet-optimism/run-op-proposer.sh @@ -0,0 +1,36 @@ +#!/bin/sh +set -e +if [ -n "$CERC_SCRIPT_DEBUG" ]; then + set -x +fi + +CERC_L1_RPC="${CERC_L1_RPC:-${DEFAULT_CERC_L1_RPC}}" + +# Read the L2OutputOracle contract address from the deployment +L2OO_DEPLOYMENT=$(cat /contracts-bedrock/deployments/getting-started/L2OutputOracle.json) +L2OO_ADDR=$(echo "$L2OO_DEPLOYMENT" | jq -r '.address') + +# Get Proposer key from keys.json +PROPOSER_KEY=$(jq -r '.Proposer.privateKey' /l2-accounts/keys.json | tr -d '"') + +cleanup() { + echo "Signal received, cleaning up..." + kill ${proposer_pid} + + wait + echo "Done" +} +trap 'cleanup' INT TERM + +# Run op-proposer +op-proposer \ + --poll-interval 12s \ + --rpc.port 8560 \ + --rollup-rpc http://op-node:8547 \ + --l2oo-address $L2OO_ADDR \ + --private-key $PROPOSER_KEY \ + --l1-eth-rpc $CERC_L1_RPC \ + & + +proposer_pid=$! +wait $proposer_pid diff --git a/app/data/container-build/cerc-optimism-l2geth/build.sh b/app/data/container-build/cerc-optimism-l2geth/build.sh index 5e125703..86c84a74 100755 --- a/app/data/container-build/cerc-optimism-l2geth/build.sh +++ b/app/data/container-build/cerc-optimism-l2geth/build.sh @@ -1,4 +1,7 @@ #!/usr/bin/env bash + # Build cerc/optimism-l2geth + source ${CERC_CONTAINER_BASE_DIR}/build-base.sh + docker build -t cerc/optimism-l2geth:local ${build_command_args} ${CERC_REPO_BASE_DIR}/op-geth diff --git a/app/data/container-build/cerc-optimism-op-batcher/build.sh b/app/data/container-build/cerc-optimism-op-batcher/build.sh index 08b209d0..a91c0063 100755 --- a/app/data/container-build/cerc-optimism-op-batcher/build.sh +++ b/app/data/container-build/cerc-optimism-op-batcher/build.sh @@ -1,6 +1,9 @@ #!/usr/bin/env bash + # Build cerc/optimism-op-batcher # TODO: use upstream Dockerfile once its buildx-specific content has been removed + source ${CERC_CONTAINER_BASE_DIR}/build-base.sh + SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) docker build -t cerc/optimism-op-batcher:local -f ${SCRIPT_DIR}/Dockerfile ${build_command_args} ${CERC_REPO_BASE_DIR}/optimism diff --git a/app/data/container-build/cerc-optimism-op-node/build.sh b/app/data/container-build/cerc-optimism-op-node/build.sh index 9c33529a..be68cbbd 100755 --- a/app/data/container-build/cerc-optimism-op-node/build.sh +++ b/app/data/container-build/cerc-optimism-op-node/build.sh @@ -1,6 +1,9 @@ #!/usr/bin/env bash + # Build cerc/optimism-op-node # TODO: use upstream Dockerfile once its buildx-specific content has been removed + source ${CERC_CONTAINER_BASE_DIR}/build-base.sh + SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) docker build -t cerc/optimism-op-node:local -f ${SCRIPT_DIR}/Dockerfile ${build_command_args} ${CERC_REPO_BASE_DIR}/optimism diff --git a/app/data/container-build/cerc-optimism-op-proposer/Dockerfile b/app/data/container-build/cerc-optimism-op-proposer/Dockerfile new file mode 100644 index 00000000..e91aa4bb --- /dev/null +++ b/app/data/container-build/cerc-optimism-op-proposer/Dockerfile @@ -0,0 +1,31 @@ +FROM golang:1.19.0-alpine3.15 as builder + +ARG VERSION=v0.0.0 + +RUN apk add --no-cache make gcc musl-dev linux-headers git jq bash + +# build op-proposer with the shared go.mod & go.sum files +COPY ./op-proposer /app/op-proposer +COPY ./op-bindings /app/op-bindings +COPY ./op-node /app/op-node +COPY ./op-service /app/op-service +COPY ./op-signer /app/op-signer +COPY ./go.mod /app/go.mod +COPY ./go.sum /app/go.sum +COPY ./.git /app/.git + +WORKDIR /app/op-proposer + +RUN go mod download + +ARG TARGETOS TARGETARCH + +RUN make op-proposer VERSION="$VERSION" GOOS=$TARGETOS GOARCH=$TARGETARCH + +FROM alpine:3.15 + +RUN apk add --no-cache jq bash + +COPY --from=builder /app/op-proposer/bin/op-proposer /usr/local/bin + +CMD ["op-proposer"] diff --git a/app/data/container-build/cerc-optimism-op-proposer/build.sh b/app/data/container-build/cerc-optimism-op-proposer/build.sh new file mode 100755 index 00000000..f3c975dc --- /dev/null +++ b/app/data/container-build/cerc-optimism-op-proposer/build.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +# Build cerc/optimism-op-proposer + +source ${CERC_CONTAINER_BASE_DIR}/build-base.sh + +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +docker build -t cerc/optimism-op-proposer:local -f ${SCRIPT_DIR}/Dockerfile ${build_command_args} ${CERC_REPO_BASE_DIR}/optimism diff --git a/app/data/container-image-list.txt b/app/data/container-image-list.txt index 0635c4c8..0caea48a 100644 --- a/app/data/container-image-list.txt +++ b/app/data/container-image-list.txt @@ -35,3 +35,4 @@ cerc/act-runner-task-executor cerc/optimism-l2geth cerc/optimism-op-batcher cerc/optimism-op-node +cerc/optimism-op-proposer diff --git a/app/data/pod-list.txt b/app/data/pod-list.txt index ef42ad9e..f24c9ed0 100644 --- a/app/data/pod-list.txt +++ b/app/data/pod-list.txt @@ -10,7 +10,6 @@ laconicd fixturenet-laconicd fixturenet-eth fixturenet-eth-metrics -watcher-ts watcher-mobymask watcher-erc20 watcher-erc721 diff --git a/app/data/repository-list.txt b/app/data/repository-list.txt index bfb6085c..0d808d68 100644 --- a/app/data/repository-list.txt +++ b/app/data/repository-list.txt @@ -13,8 +13,6 @@ cerc-io/laconic-console cerc-io/mobymask-watcher cerc-io/watcher-ts cerc-io/mobymask-v2-watcher-ts -cerc-io/react-peer -cerc-io/mobymask-ui cerc-io/MobyMask vulcanize/uniswap-watcher-ts vulcanize/uniswap-v3-info diff --git a/app/data/stacks/fixturenet-optimism/README.md b/app/data/stacks/fixturenet-optimism/README.md index 345e9a8d..bbe41c6a 100644 --- a/app/data/stacks/fixturenet-optimism/README.md +++ b/app/data/stacks/fixturenet-optimism/README.md @@ -19,7 +19,7 @@ Checkout to the required versions and branches in repos: ```bash # Optimism cd ~/cerc/optimism -git checkout @eth-optimism/sdk@0.0.0-20230329025055 +git checkout v1.0.3 ``` Build the container images: @@ -36,8 +36,9 @@ This should create the required docker images in the local image registry: * `cerc/foundry` * `cerc/optimism-contracts` * `cerc/optimism-l2geth` -* `cerc/optimism-op-batcher` * `cerc/optimism-op-node` +* `cerc/optimism-op-batcher` +* `cerc/optimism-op-proposer` ## Deploy diff --git a/app/data/stacks/fixturenet-optimism/l2-only.md b/app/data/stacks/fixturenet-optimism/l2-only.md index 957627d3..72bf93cb 100644 --- a/app/data/stacks/fixturenet-optimism/l2-only.md +++ b/app/data/stacks/fixturenet-optimism/l2-only.md @@ -19,21 +19,22 @@ Checkout to the required versions and branches in repos: ```bash # Optimism cd ~/cerc/optimism -git checkout @eth-optimism/sdk@0.0.0-20230329025055 +git checkout v1.0.3 ``` Build the container images: ```bash -laconic-so --stack fixturenet-optimism build-containers --include cerc/foundry,cerc/optimism-contracts,cerc/optimism-op-node,cerc/optimism-l2geth,cerc/optimism-op-batcher +laconic-so --stack fixturenet-optimism build-containers --include cerc/foundry,cerc/optimism-contracts,cerc/optimism-op-node,cerc/optimism-l2geth,cerc/optimism-op-batcher,cerc/optimism-op-proposer ``` This should create the required docker images in the local image registry: * `cerc/foundry` * `cerc/optimism-contracts` * `cerc/optimism-l2geth` -* `cerc/optimism-op-batcher` * `cerc/optimism-op-node` +* `cerc/optimism-op-batcher` +* `cerc/optimism-op-proposer` ## Deploy diff --git a/app/data/stacks/fixturenet-optimism/stack.yml b/app/data/stacks/fixturenet-optimism/stack.yml index e53623ca..45bb1709 100644 --- a/app/data/stacks/fixturenet-optimism/stack.yml +++ b/app/data/stacks/fixturenet-optimism/stack.yml @@ -16,6 +16,7 @@ containers: - cerc/optimism-op-node - cerc/optimism-l2geth - cerc/optimism-op-batcher + - cerc/optimism-op-proposer pods: - fixturenet-eth - fixturenet-optimism diff --git a/app/data/stacks/mobymask-v2/README.md b/app/data/stacks/mobymask-v2/README.md index ff67b55c..e781af79 100644 --- a/app/data/stacks/mobymask-v2/README.md +++ b/app/data/stacks/mobymask-v2/README.md @@ -35,7 +35,7 @@ git checkout v0.1.2 # Optimism cd ~/cerc/optimism -git checkout @eth-optimism/sdk@0.0.0-20230329025055 +git checkout v1.0.3 ``` Build the container images: