Skip to content

Commit

Permalink
fix: restart scripts (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
lesterli authored and bap2pecs committed Nov 6, 2024
1 parent 4074901 commit aa0b641
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 84 deletions.
2 changes: 0 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 4 additions & 8 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 Expand Up @@ -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
.PHONY: l2-explorer-logs
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,6 @@ You can also verify the L2 chain with:
cast block latest --rpc-url http://<l2-server-ip>:9545 # (need to have foundry installed)
```

You can also access the explorer at `http://<l2-server-ip>:3001/` and bridge UI at `http://<l2-server-ip>:3002/`.
You can also access the explorer at `http://<l2-server-ip>` and bridge UI at `http://<l2-server-ip>:3002/`.

You can also bridge funds from L1 to L2 via the bridge UI.
8 changes: 1 addition & 7 deletions docker/docker-compose-l2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand Down
Empty file modified scripts/l2-explorer/l2-explorer-restart.sh
100644 → 100755
Empty file.
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
}
2 changes: 0 additions & 2 deletions scripts/l2/l2-generate-deploy-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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.

53 changes: 4 additions & 49 deletions scripts/l2/l2-start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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..."
Expand All @@ -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
echo

0 comments on commit aa0b641

Please sign in to comment.