Skip to content

Commit

Permalink
fix: restart l2
Browse files Browse the repository at this point in the history
  • Loading branch information
lesterli committed Nov 5, 2024
1 parent a36fc62 commit 973c639
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 51 deletions.
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

############################
Expand Down
50 changes: 50 additions & 0 deletions scripts/l2/common.sh
Original file line number Diff line number Diff line change
@@ -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
}
6 changes: 6 additions & 0 deletions scripts/l2/l2-generate-l2-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions scripts/l2/l2-op-node-restart.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 0 additions & 15 deletions scripts/l2/l2-restart.sh

This file was deleted.

38 changes: 4 additions & 34 deletions scripts/l2/l2-start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +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
# 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..."
Expand All @@ -55,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
echo

0 comments on commit 973c639

Please sign in to comment.