Check for existing L2 geth data directory

This commit is contained in:
2023-04-04 18:12:40 +05:30
parent 6ac8d7f3f7
commit 2a2e52751a
3 changed files with 32 additions and 19 deletions
@@ -41,7 +41,7 @@ services:
extra_hosts: extra_hosts:
- "host.docker.internal:host-gateway" - "host.docker.internal:host-gateway"
# Initializes and runs the L2 execution client # Initializes and runs the L2 execution client (outputs to volume l2_geth_data)
op-geth: op-geth:
image: cerc/optimism-l2geth:local image: cerc/optimism-l2geth:local
depends_on: depends_on:
@@ -51,6 +51,7 @@ services:
- ../config/fixturenet-optimism/run-op-geth.sh:/run-op-geth.sh - ../config/fixturenet-optimism/run-op-geth.sh:/run-op-geth.sh
- l2_config:/op-node:ro - l2_config:/op-node:ro
- l2_accounts:/l2-accounts:ro - l2_accounts:/l2-accounts:ro
- l2_geth_data:/datadir
entrypoint: "sh" entrypoint: "sh"
command: "/run-op-geth.sh" command: "/run-op-geth.sh"
ports: ports:
@@ -112,3 +113,4 @@ volumes:
l1_deployment: l1_deployment:
l2_accounts: l2_accounts:
l2_config: l2_config:
l2_geth_data:
@@ -4,6 +4,12 @@ if [ -n "$CERC_SCRIPT_DEBUG" ]; then
set -x set -x
fi fi
# Skip if /app/jwt.txt exists
if [ -f /app/jwt.txt ]; then
echo "Found existing config, exiting"
exit 0
fi
op-node genesis l2 \ op-node genesis l2 \
--deploy-config /contracts-bedrock/deploy-config/getting-started.json \ --deploy-config /contracts-bedrock/deploy-config/getting-started.json \
--deployment-dir /contracts-bedrock/deployments/getting-started/ \ --deployment-dir /contracts-bedrock/deployments/getting-started/ \
@@ -4,34 +4,39 @@ if [ -n "$CERC_SCRIPT_DEBUG" ]; then
set -x set -x
fi fi
mkdir datadir
echo "pwd" > datadir/password
# TODO: Add in container build or use other tool # TODO: Add in container build or use other tool
echo "Installing jq" echo "Installing jq"
apk update && apk add jq apk update && apk add jq
# Get SEQUENCER KEY from keys.json # Initialize op-geth if datadir/geth not found
SEQUENCER_KEY=$(jq -r '.Sequencer.privateKey' /l2-accounts/keys.json | tr -d '"') if [ -f /op-node/jwt.txt ] && [ -d datadir/geth ]; then
echo $SEQUENCER_KEY > datadir/block-signer-key echo "Found existing datadir, skipping initialization"
else
echo "Initializing op-geth"
geth account import --datadir=datadir --password=datadir/password datadir/block-signer-key mkdir datadir
echo "pwd" > datadir/password
while [ ! -f "/op-node/jwt.txt" ] # Get SEQUENCER KEY from keys.json
do SEQUENCER_KEY=$(jq -r '.Sequencer.privateKey' /l2-accounts/keys.json | tr -d '"')
echo "Config files not created. Checking after 5 seconds." echo $SEQUENCER_KEY > datadir/block-signer-key
sleep 5
done
echo "Config files created by op-node, proceeding with script..." geth account import --datadir=datadir --password=datadir/password datadir/block-signer-key
cp /op-node/genesis.json ./ while [ ! -f "/op-node/jwt.txt" ]
geth init --datadir=datadir genesis.json do
echo "Config files not created. Checking after 5 seconds."
sleep 5
done
echo "Config files created by op-node, proceeding with the initialization..."
geth init --datadir=datadir /op-node/genesis.json
echo "Node Initialized"
fi
SEQUENCER_ADDRESS=$(jq -r '.Sequencer.address' /l2-accounts/keys.json | tr -d '"') SEQUENCER_ADDRESS=$(jq -r '.Sequencer.address' /l2-accounts/keys.json | tr -d '"')
echo "SEQUENCER_ADDRESS: ${SEQUENCER_ADDRESS}" echo "SEQUENCER_ADDRESS: ${SEQUENCER_ADDRESS}"
cp /op-node/jwt.txt ./
# Run op-geth # Run op-geth
geth \ geth \
@@ -54,7 +59,7 @@ geth \
--authrpc.vhosts="*" \ --authrpc.vhosts="*" \
--authrpc.addr=0.0.0.0 \ --authrpc.addr=0.0.0.0 \
--authrpc.port=8551 \ --authrpc.port=8551 \
--authrpc.jwtsecret=./jwt.txt \ --authrpc.jwtsecret=/op-node/jwt.txt \
--rollup.disabletxpoolgossip=true \ --rollup.disabletxpoolgossip=true \
--password=./datadir/password \ --password=./datadir/password \
--allow-insecure-unlock \ --allow-insecure-unlock \