From aa0b641a1ef6de465ed30517823238bf670409b5 Mon Sep 17 00:00:00 2001 From: lesterli Date: Wed, 6 Nov 2024 09:49:46 +0800 Subject: [PATCH] fix: restart scripts (#32) --- .env.example | 2 - Makefile | 12 ++--- README.md | 2 +- docker/docker-compose-l2.yml | 8 +--- scripts/l2-explorer/l2-explorer-restart.sh | 0 scripts/l2/common.sh | 50 ++++++++++++++++++++ scripts/l2/l2-generate-deploy-config.sh | 2 - scripts/l2/l2-generate-l2-config.sh | 6 +++ scripts/l2/l2-op-node-restart.sh | 5 ++ scripts/l2/l2-restart.sh | 15 ------ scripts/l2/l2-start.sh | 53 ++-------------------- 11 files changed, 71 insertions(+), 84 deletions(-) mode change 100644 => 100755 scripts/l2-explorer/l2-explorer-restart.sh create mode 100755 scripts/l2/common.sh delete mode 100755 scripts/l2/l2-restart.sh diff --git a/.env.example b/.env.example index ce041b4..35cbf01 100644 --- a/.env.example +++ b/.env.example @@ -17,8 +17,6 @@ L2_CHAIN_ID=11155420 L2_CHAIN_NAME="L2 Devnet" L2_BLOCK_TIME=2 DEVNET_L2OO=true -DEVNET_ALTDA=false -GENERIC_ALTDA=false BATCH_INBOX_ADDRESS=0xff00000000000000000000000000000000042069 FINALIZATION_PERIOD_SECONDS=12 ENABLE_GOVERNANCE=false diff --git a/Makefile b/Makefile index 6963175..bb86280 100644 --- a/Makefile +++ b/Makefile @@ -63,7 +63,7 @@ l2-prepare: ## Start the OP chain core components (op-node, op-geth, proposer, batcher) l2-start: - @$(CURDIR)/scripts/l2/l2-start.sh $(CURDIR)/optimism + @$(CURDIR)/scripts/l2/l2-start.sh .PHONY: l2-start ## Verify the OP chain is running @@ -78,7 +78,8 @@ l2-op-node-restart: ## Restart the OP chain l2-restart: - @$(CURDIR)/scripts/l2/l2-restart.sh + @docker compose -f docker/docker-compose-l2.yml stop l2 op-node op-proposer op-batcher + @$(CURDIR)/scripts/l2/l2-start.sh .PHONY: l2-restart ############################ @@ -134,9 +135,4 @@ l2-explorer-ps: ## Show logs for the OP chain explorer l2-explorer-logs: docker compose -f docker/docker-compose-l2-explorer.yml logs -f -.PHONY: l2-explorer-logs - -## Restart the OP chain explorer -l2-explorer-restart: - @$(CURDIR)/scripts/l2-explorer/l2-explorer-restart.sh -.PHONY: l2-explorer-restart \ No newline at end of file +.PHONY: l2-explorer-logs \ No newline at end of file diff --git a/README.md b/README.md index ba3fd7a..da42e02 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,6 @@ You can also verify the L2 chain with: cast block latest --rpc-url http://:9545 # (need to have foundry installed) ``` -You can also access the explorer at `http://:3001/` and bridge UI at `http://:3002/`. +You can also access the explorer at `http://` and bridge UI at `http://:3002/`. You can also bridge funds from L1 to L2 via the bridge UI. \ No newline at end of file diff --git a/docker/docker-compose-l2.yml b/docker/docker-compose-l2.yml index 362a95a..0770e5f 100644 --- a/docker/docker-compose-l2.yml +++ b/docker/docker-compose-l2.yml @@ -38,9 +38,6 @@ services: --p2p.disable --p2p.sequencer.key=${GS_SEQUENCER_PRIVATE_KEY} --safedb.path=/db - --altda.enabled=${ALTDA_ENABLED} - --altda.da-service=${ALTDA_SERVICE} - --altda.da-server=http://da-server:3100 ports: - "7545:8545" volumes: @@ -95,10 +92,7 @@ services: OP_BATCHER_TXMGR_MIN_BASEFEE: 2.0 # 2 gwei, might need to tweak, depending on gas market OP_BATCHER_TXMGR_MIN_TIP_CAP: 2.0 # 2 gwei, might need to tweak, depending on gas market OP_BATCHER_RESUBMISSION_TIMEOUT: 240s # wait 4 min before bumping fees - OP_BATCHER_ALTDA_ENABLED: "${ALTDA_ENABLED}" - OP_BATCHER_ALTDA_DA_SERVICE: "${ALTDA_SERVICE}" - OP_BATCHER_ALTDA_DA_SERVER: "http://da-server:3100" - OP_BATCHER_DATA_AVAILABILITY_TYPE: "${DA_TYPE}" + OP_BATCHER_DATA_AVAILABILITY_TYPE: "blobs" networks: - ops-bedrock_default diff --git a/scripts/l2-explorer/l2-explorer-restart.sh b/scripts/l2-explorer/l2-explorer-restart.sh old mode 100644 new mode 100755 diff --git a/scripts/l2/common.sh b/scripts/l2/common.sh new file mode 100755 index 0000000..5a700e6 --- /dev/null +++ b/scripts/l2/common.sh @@ -0,0 +1,50 @@ +#!/bin/bash +set -euo pipefail + +# function to wait for a port to be available +wait_up() { + local port=$1 + local retries=10 + local wait_time=1 + + for i in $(seq 1 $retries); do + if nc -z localhost $port; then + echo "Port $port is available" + return 0 + fi + echo "Attempt $i: Port $port is not available yet. Waiting $wait_time seconds..." + sleep $wait_time + done + + echo "Error: Port $port did not become available after $retries attempts" + return 1 +} + +# function to setup the env vars after the deployment +post_deployment_setup_env_vars() { + local deployment_file=$1 + local devnet_l2oo=${2:-true} + + if [ ! -f "$deployment_file" ]; then + echo "Error: Deployment file not found at $deployment_file" + return 1 + fi + + if [ "$devnet_l2oo" = true ]; then + export L2OO_ADDRESS=$(jq -r .L2OutputOracleProxy < "$deployment_file") + if [ -z "$L2OO_ADDRESS" ]; then + echo "Error: L2OutputOracleProxy address not found in deployment file" + return 1 + fi + else + export DGF_ADDRESS=$(jq -r .DisputeGameFactoryProxy < "$deployment_file") + if [ -z "$DGF_ADDRESS" ]; then + echo "Error: DisputeGameFactoryProxy address not found in deployment file" + return 1 + fi + export DG_TYPE=254 + export PROPOSAL_INTERVAL=12s + fi + + return 0 +} \ No newline at end of file diff --git a/scripts/l2/l2-generate-deploy-config.sh b/scripts/l2/l2-generate-deploy-config.sh index 096ef47..a479cb4 100755 --- a/scripts/l2/l2-generate-deploy-config.sh +++ b/scripts/l2/l2-generate-deploy-config.sh @@ -19,8 +19,6 @@ fi # Check optional environment variables DEVNET_L2OO=${DEVNET_L2OO:-true} -DEVNET_ALTDA=${DEVNET_ALTDA:-false} -GENERIC_ALTDA=${GENERIC_ALTDA:-false} if [ "$DEVNET_L2OO" = true ]; then USE_FAULT_PROOFS=false else diff --git a/scripts/l2/l2-generate-l2-config.sh b/scripts/l2/l2-generate-l2-config.sh index f7f69d2..bdde7d8 100755 --- a/scripts/l2/l2-generate-l2-config.sh +++ b/scripts/l2/l2-generate-l2-config.sh @@ -53,4 +53,10 @@ echo echo "Creating an authentication key..." openssl rand -hex 32 > ${JWT_SECRET_PATH} echo "Authentication key created at ${JWT_SECRET_PATH}" +echo + +# Move the deployment and deploy-config files to the .deploy directory +echo "Moving the deployment and deploy-config files to the .deploy directory..." +mv $DEPLOYMENT_OUTFILE $(pwd)/.deploy/op-devnet-deployments-${L2_CHAIN_ID}.json +mv $DEPLOY_CONFIG_PATH $(pwd)/.deploy/op-devnet-deploy-config-${L2_CHAIN_ID}.json echo \ No newline at end of file diff --git a/scripts/l2/l2-op-node-restart.sh b/scripts/l2/l2-op-node-restart.sh index b94e282..455c8db 100755 --- a/scripts/l2/l2-op-node-restart.sh +++ b/scripts/l2/l2-op-node-restart.sh @@ -6,10 +6,15 @@ set -a source $(pwd)/.env set +a +source $(pwd)/scripts/l2/common.sh + # Stop the OP Node echo "Stopping the OP Node..." docker compose -f docker/docker-compose-l2.yml stop op-node +# set L2OO or DGF env vars +post_deployment_setup_env_vars $(pwd)/.deploy/op-devnet-deployments-${L2_CHAIN_ID}.json $DEVNET_L2OO + # Start the OP Node echo "Starting the OP Node..." docker compose -f docker/docker-compose-l2.yml up -d op-node \ No newline at end of file diff --git a/scripts/l2/l2-restart.sh b/scripts/l2/l2-restart.sh deleted file mode 100755 index 78741d5..0000000 --- a/scripts/l2/l2-restart.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash -set -euo pipefail - -# Load environment variables from the top-level .env file -set -a -source $(pwd)/.env -set +a - -# Stop the OP Geth, OP Node, Proposer and Batcher -echo "Stopping the OP Geth, OP Node, Proposer and Batcher..." -docker compose -f docker/docker-compose-l2.yml stop l2 op-node op-proposer op-batcher - -# Start the OP Geth, OP Node, Proposer and Batcher -echo "Starting the OP Geth, OP Node, Proposer and Batcher..." -docker compose -f docker/docker-compose-l2.yml up -d l2 op-node op-proposer op-batcher \ No newline at end of file diff --git a/scripts/l2/l2-start.sh b/scripts/l2/l2-start.sh index d194a93..ac4f0f3 100755 --- a/scripts/l2/l2-start.sh +++ b/scripts/l2/l2-start.sh @@ -6,50 +6,10 @@ set -a source $(pwd)/.env set +a -wait_up() { - local port=$1 - local retries=10 - local wait_time=1 +source $(pwd)/scripts/l2/common.sh - for i in $(seq 1 $retries); do - if nc -z localhost $port; then - echo "Port $port is available" - return 0 - fi - echo "Attempt $i: Port $port is not available yet. Waiting $wait_time seconds..." - sleep $wait_time - done - - echo "Error: Port $port did not become available after $retries attempts" - return 1 -} - -# set the needed environment variable -echo "Setting the needed environment variable..." -DEPLOYMENT_OUTFILE=$1/packages/contracts-bedrock/deployments/op-devnet-${L2_CHAIN_ID}.json -if [ "$DEVNET_L2OO" = true ]; then - export L2OO_ADDRESS=$(jq -r .L2OutputOracleProxy < ${DEPLOYMENT_OUTFILE}) -else - export DGF_ADDRESS=$(jq -r .DisputeGameFactoryProxy < ${DEPLOYMENT_OUTFILE}) - # these two values are from the bedrock-devnet - export DG_TYPE=254 - export PROPOSAL_INTERVAL=12s -fi -if [ "$DEVNET_ALTDA" = true ]; then - export ALTDA_ENABLED=true - export DA_TYPE=calldata -else - export ALTDA_ENABLED=false - export DA_TYPE=blobs -fi -if [ "$GENERIC_ALTDA" = true ]; then - export ALTDA_GENERIC_DA=true - export ALTDA_SERVICE=true -else - export ALTDA_GENERIC_DA=false - export ALTDA_SERVICE=false -fi -echo +# set L2OO or DGF env vars after the deployment +post_deployment_setup_env_vars $(pwd)/.deploy/op-devnet-deployments-${L2_CHAIN_ID}.json $DEVNET_L2OO # Launch the OP L2 echo "Launching the OP L2..." @@ -70,9 +30,4 @@ echo "Waiting for OP Node, Proposer and Batcher to be available..." wait_up 7545 wait_up 7546 wait_up 7547 -echo - -sleep 10 -OP_BEDROCK_DIR=$(pwd)/optimism/packages/contracts-bedrock -mv ${OP_BEDROCK_DIR}/deployments/op-devnet-${L2_CHAIN_ID}.json $(pwd)/.deploy/op-devnet-deployments-${L2_CHAIN_ID}.json -mv ${OP_BEDROCK_DIR}/deploy-config/op-devnet-${L2_CHAIN_ID}.json $(pwd)/.deploy/op-devnet-deploy-config-${L2_CHAIN_ID}.json \ No newline at end of file +echo \ No newline at end of file