Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ CELESTIA_MODE=false
# If not set, default to the official optimism implementation

OPTIMISM_REPO_URL=https://github.com/ethereum-optimism/optimism.git
OPTIMISM_BRANCH_OR_COMMIT=v1.8.0
OPTIMISM_BRANCH_OR_COMMIT=v1.9.1

OP_GETH_REPO_URL=https://github.com/ethereum-optimism/op-geth.git
OP_GETH_BRANCH_OR_COMMIT=v1.101315.2
OP_GETH_BRANCH_OR_COMMIT=v1.101315.3

##################################################
# Accounts Info #
Expand Down Expand Up @@ -66,9 +66,6 @@ L2_CHAIN_ID=42069

L2_BLOCK_TIME=2

# Name for the deploy config file (Default to getting-started)
DEPLOYMENT_CONTEXT=getting-started

##################################################
# celestia-da Configuration #
##################################################
Expand Down
10 changes: 6 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ RUN mkdir -p /etc/apt/keyrings && \
apt-get update && \
apt-get install nodejs -y

# Install PNPM
RUN npm install -g pnpm
# Install just
RUN mkdir -p /app/bin
RUN curl --proto '=https' --tlsv1.2 -sSf https://just.systems/install.sh | bash -s -- --to /app/bin
ENV PATH="$PATH:/app/bin"

# Install Go
RUN ARCH=$(dpkg --print-architecture) && echo "Architecture: ${ARCH}" && \
Expand Down Expand Up @@ -59,8 +61,8 @@ RUN chmod +x /app/clone-repos.sh
RUN chmod +x /app/prepare.sh

# MacOS pnpm fix
RUN mkdir -p /app/pnpm/store
RUN pnpm config set store-dir /app/pnpm/store
#RUN mkdir -p /app/pnpm/store
#RUN pnpm config set store-dir /app/pnpm/store

# Set the clone-repos.sh script as the entry point
ENTRYPOINT ["/app/prepare.sh"]
6 changes: 3 additions & 3 deletions entrypoints/op-proposer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ fi
# Check if OP_PROPOSER_L2OO_ADDRESS environment variable is set
if [ -z "$OP_PROPOSER_L2OO_ADDRESS" ]; then
# If not set, check if the file exists
if [ ! -f "$DEPLOYMENT_DIR/.deploy" ]; then
echo "File $DEPLOYMENT_DIR/.deploy does not exist. Please import data/deployments or set the OP_PROPOSER_L2OO_ADDRESS variable."
if [ ! -f "$DEPLOYMENT_DIR/artifact.json" ]; then
echo "File $DEPLOYMENT_DIR/artifact.json does not exist. Please import data/deployments or set the OP_PROPOSER_L2OO_ADDRESS variable."
exit 1
fi
# Use the address from the $DEPLOYMENT_DIR
OP_PROPOSER_L2OO_ADDRESS=$(jq -r .L2OutputOracleProxy $DEPLOYMENT_DIR/.deploy)
OP_PROPOSER_L2OO_ADDRESS=$(jq -r .L2OutputOracleProxy $DEPLOYMENT_DIR/artifact.json)
fi

exec "$BIN_DIR"/op-proposer
31 changes: 26 additions & 5 deletions run
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
#!/bin/bash

# Define colors
ORANGE='\e[0;33m'
BLUE='\e[0;34m'
RED='\e[0;31m'
GREEN='\e[0;32m'
NC='\e[0m'

# Check if .env file exists
if [ ! -f .env ]; then
if [ -f .env.example ]; then
echo -e "${RED}Error${NC}: .env file not found."
echo -ne "${ORANGE}Do you want to use .env.example and rename it to .env? (yes/no): ${NC}"
read -r rename_confirm
if [[ "$rename_confirm" =~ ^(yes|y)$ ]]; then
mv .env.example .env
echo -e "${GREEN}.env.example has been renamed to .env.${NC}"
else
echo "Exiting."
exit 1
fi
else
echo -e "${RED}Error${NC}: .env and .env.example files not found. Exiting."
exit 1
fi
fi

# Load environment variables from .env file
# shellcheck disable=SC1091
source .env
Expand All @@ -11,11 +37,6 @@ command="docker compose"
[ "$SEQUENCER_MODE" = "true" ] && command+=" --profile sequencer"
[ "$CELESTIA_MODE" = "true" ] && command+=" --profile celestia"

# Define colors
ORANGE='\e[0;33m'
BLUE='\e[0;34m'
NC='\e[0m'

if [ "$SKIP_DEPLOYMENT_CHECK" = "true" ]; then
echo -e "${ORANGE}NOTE${NC}: Only genesis.json and rollup.json will be checked (SKIP_DEPLOYMENT_CHECK=$SKIP_DEPLOYMENT_CHECK)."
fi
Expand Down
6 changes: 3 additions & 3 deletions scripts/clone-repos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ clone_repo() {

# Clone the repository
echo "Cloning $repo_url into $dest_dir"
git clone "$repo_url" .
git clone --recursive "$repo_url" .
echo "Cloning complete"

# Checkout to the specific branch or commit
Expand All @@ -67,9 +67,9 @@ clone_repo() {

# Use environment variables if set, otherwise default to the official repositories
OPTIMISM_REPO=${OPTIMISM_REPO_URL:-https://github.com/ethereum-optimism/optimism.git}
OPTIMISM_BRANCH_OR_COMMIT=${OPTIMISM_BRANCH_OR_COMMIT:-op-node/v1.3.0}
OPTIMISM_BRANCH_OR_COMMIT=${OPTIMISM_BRANCH_OR_COMMIT:-v1.9.0}
OP_GETH_REPO=${OP_GETH_REPO_URL:-https://github.com/ethereum-optimism/op-geth.git}
OP_GETH_BRANCH_OR_COMMIT=${OP_GETH_BRANCH_OR_COMMIT:-v1.101304.2}
OP_GETH_BRANCH_OR_COMMIT=${OP_GETH_BRANCH_OR_COMMIT:-v1.101315.3}

# Cloning repositories
clone_repo "$OPTIMISM_REPO" "$OPTIMISM_BRANCH_OR_COMMIT" "$OPTIMISM_DIR" || exit 1
Expand Down
99 changes: 42 additions & 57 deletions scripts/prepare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ set -e
if [ ! -f "$BIN_DIR/op-node" ] || [ ! -f "$BIN_DIR/op-batcher" ] || [ ! -f "$BIN_DIR/op-proposer" ] || [ ! -f "$BIN_DIR/geth" ]; then
# Build op-node, op-batcher and op-proposer
cd "$OPTIMISM_DIR"
pnpm install
make op-node op-batcher op-proposer
pnpm build

# Copy binaries to the bin volume
cp -f "$OPTIMISM_DIR"/op-node/bin/op-node "$BIN_DIR"/
Expand All @@ -32,16 +30,16 @@ fi

# Check if all required config files exist
if [ -f "$CONFIG_PATH/genesis.json" ] && [ -f "$CONFIG_PATH/rollup.json" ]; then
echo "L2 config files are present, skipping script."
echo "L2 config files are present, skipping prepare.sh script."
exec "$@"
exit 0
elif [ -f "$CONFIG_PATH/genesis.json" ] || [ -f "$CONFIG_PATH/rollup.json" ]; then
echo "Error: Partial L2 config files are present, but not all. Exiting script."
echo "Error: One of the genesis.json or rollup.json files is missing."
exit 1
fi

# If no components exist, continue with the script
echo "No required components are present, continuing script execution."
# If no L2 config files exist, continue with the script
echo "No required L2 config files are present, continuing script execution."

# Check if all or none of the private keys are provided
if [ -z "$BATCHER_PRIVATE_KEY" ] && [ -z "$PROPOSER_PRIVATE_KEY" ] && [ -z "$SEQUENCER_PRIVATE_KEY" ]; then
Expand All @@ -60,20 +58,7 @@ else
exit 1
fi

# Check if both L1_BLOCKHASH and L1_TIMESTAMP are set or unset
if [ -n "$L1_BLOCKHASH" ] && [ -z "$L1_TIMESTAMP" ] || [ -z "$L1_BLOCKHASH" ] && [ -n "$L1_TIMESTAMP" ]; then
echo "Error: Both L1_BLOCKHASH and L1_TIMESTAMP must be set or unset."
exit 1
elif [ -z "$L1_BLOCKHASH" ] && [ -z "$L1_TIMESTAMP" ]; then
# Fetch block details if both variables are unset
echo "Fetching block details from L1_RPC_URL..."
block=$(cast block finalized --rpc-url "$L1_RPC_URL")
L1_TIMESTAMP=$(echo "$block" | awk '/timestamp/ { print $2 }')
export L1_TIMESTAMP
L1_BLOCKHASH=$(echo "$block" | awk '/hash/ { print $2 }')
export L1_BLOCKHASH
fi

# Get L1 chain ID and export it
L1_CHAIN_ID=$(cast chain-id --rpc-url "$L1_RPC_URL")
export L1_CHAIN_ID

Expand All @@ -93,79 +78,79 @@ cd "$OPTIMISM_DIR"/packages/contracts-bedrock
rm -f ./deploy-config/internal-opstack-compose.json

# Check if deploy-config.json exists
if [ -f "/app/data/configurations/deploy-config.json" ]; then
if [ -f "$CONFIG_PATH/deploy-config.json" ]; then
# Populate deploy-config.json with env variables
echo "Populating deploy-config.json with env variables..."
# NOTE: scripts/Deploy.s.sol:Deploy expects the deploy-config.json file to be in $OPTIMISM_DIR/packages/contracts-bedrock/deploy-config/
envsubst < /app/data/configurations/deploy-config.json > /app/temp-deploy-config.json && mv /app/temp-deploy-config.json ./deploy-config/internal-opstack-compose.json
elif [ -f "./deploy-config/$DEPLOYMENT_CONTEXT.json" ]; then
# Populate deploy-config.json with env variables
echo "Populating deploy-config.json with env variables..."
# NOTE: scripts/Deploy.s.sol:Deploy expects the deploy-config.json file to be in $OPTIMISM_DIR/packages/contracts-bedrock/deploy-config/
envsubst < ./deploy-config/$DEPLOYMENT_CONTEXT.json > /app/temp-deploy-config.json && mv /app/temp-deploy-config.json ./deploy-config/internal-opstack-compose.json
envsubst < "$CONFIG_PATH"/deploy-config.json > /app/temp-deploy-config.json && mv /app/temp-deploy-config.json ./deploy-config/internal-opstack-compose.json
else
# If deploy-config.json does not exist, use config.sh to generate it
echo "Generating deploy-config.json..."
# If deploy-config.json does not exist, use config.sh to generate getting-started.json
echo "Generating getting-started.json..."

./scripts/getting-started/config.sh
mv ./deploy-config/getting-started.json ./deploy-config/internal-opstack-compose.json
fi

# Fix L1 and L2 Chain ID to the one set in the environment variable
export BATCH_INBOX_ADDRESS_TEMP=$(openssl rand -hex 32 | head -c 40)
BATCH_INBOX_ADDRESS_TEMP=$(openssl rand -hex 32 | head -c 40)
export BATCH_INBOX_ADDRESS_TEMP
jq \
--argjson l1ChainID $L1_CHAIN_ID \
--argjson l2ChainID $L2_CHAIN_ID \
--argjson l1ChainID "$L1_CHAIN_ID" \
--argjson l2ChainID "$L2_CHAIN_ID" \
--arg batchInboxAddress "0x$BATCH_INBOX_ADDRESS_TEMP" \
'.l1ChainID = $l1ChainID | .l2ChainID = $l2ChainID | .batchInboxAddress = $batchInboxAddress' \
./deploy-config/internal-opstack-compose.json > /app/temp-deploy-config.json && mv /app/temp-deploy-config.json ./deploy-config/internal-opstack-compose.json

# Merge deploy override
if [ -f /app/data/configurations/deploy-override.json ]; then
jq -s '.[0] * .[1]' ./deploy-config/internal-opstack-compose.json /app/data/configurations/deploy-override.json > /app/temp-deploy-config.json && mv /app/temp-deploy-config.json ./deploy-config/internal-opstack-compose.json
if [ -f "$CONFIG_PATH"/deploy-override.json ]; then
jq -s '.[0] * .[1]' ./deploy-config/internal-opstack-compose.json "$CONFIG_PATH"/deploy-override.json > /app/temp-deploy-config.json && mv /app/temp-deploy-config.json ./deploy-config/internal-opstack-compose.json
fi

# Show deployment config for better debuggability
cat ./deploy-config/internal-opstack-compose.json

# Generate IMPL_SALT
if [ -z "$IMPL_SALT" ]; then
export IMPL_SALT=$(sha256sum ./deploy-config/internal-opstack-compose.json | cut -d ' ' -f1)
IMPL_SALT=$(sha256sum ./deploy-config/internal-opstack-compose.json | cut -d ' ' -f1)
export IMPL_SALT
fi

# If not deployed
if [ ! -f /app/data/deployments/.deploy ]; then
# Set deployment context to internal
export DEPLOYMENT_CONTEXT=internal-opstack-compose
# NOTE: The $DEPLOYMENT_OUTFILE and $DEPLOY_CONFIG_PATH vars are required for line 136
export DEPLOYMENT_OUTFILE=./deployments/artifact.json
export DEPLOY_CONFIG_PATH=./deploy-config/internal-opstack-compose.json # "$CONFIG_PATH"/deploy-config.json not suitable due to the error "... not allowed to be accessed for read operations"

export DEPLOY_CONFIG_PATH=deploy-config/internal-opstack-compose.json
mkdir -p deployments
mkdir deployments/internal-opstack-compose
export DEPLOYMENT_OUTFILE="$OPTIMISM_DIR"/packages/contracts-bedrock/deployments/"$DEPLOYMENT_CONTEXT"/.deploy
# If not deployed
if [ ! -f "$DEPLOYMENT_DIR"/artifact.json ]; then
# Determine the script path (fix for v1.7.7)
DEPLOY_SCRIPT_PATH=$(test -f scripts/deploy/Deploy.s.sol && echo "scripts/deploy/Deploy.s.sol" || echo "scripts/Deploy.s.sol")

# Deploy the L1 contracts
forge script scripts/Deploy.s.sol:Deploy --private-key "$DEPLOYER_PRIVATE_KEY" --broadcast --rpc-url "$L1_RPC_URL"

# Save the deployment address
cp -r "$OPTIMISM_DIR"/packages/contracts-bedrock/deployments/"$DEPLOYMENT_CONTEXT"/. /app/data/deployments/
forge script $DEPLOY_SCRIPT_PATH --private-key "$DEPLOYER_PRIVATE_KEY" --broadcast --rpc-url "$L1_RPC_URL"

# Copy deploy-config.json to the configurations volume
cp ./deploy-config/internal-opstack-compose.json "$CONFIG_PATH"/deploy-config.json
# Copy the deployment files to the data volume
cp $DEPLOYMENT_OUTFILE "$DEPLOYMENT_DIR"/
cp $DEPLOY_CONFIG_PATH "$CONFIG_PATH"/deploy-config.json
fi

export CONTRACT_ADDRESSES_PATH=/app/data/deployments/.deploy
export STATE_DUMP_PATH=/app/data/deployments/allocs.json
forge script scripts/L2Genesis.s.sol:L2Genesis --chain-id $L2_CHAIN_ID --sig 'runWithAllUpgrades()' --private-key $DEPLOYER_PRIVATE_KEY
# Generating L2 Allocs
export CONTRACT_ADDRESSES_PATH=$DEPLOYMENT_DIR/artifact.json
export STATE_DUMP_PATH=$DEPLOYMENT_DIR/allocs.json

if [ -f "$STATE_DUMP_PATH" ]; then
echo "State dump already exists, skipping state dump generation."
else
forge script scripts/L2Genesis.s.sol:L2Genesis --chain-id "$L2_CHAIN_ID" --sig 'runWithAllUpgrades()' --private-key "$DEPLOYER_PRIVATE_KEY" # OR runWithStateDump()
fi

# Generate the L2 config files
export DEPLOY_CONFIG_PATH="$CONFIG_PATH"/deploy-config.json
# Generate the L2 genesis files
cd "$OPTIMISM_DIR"/op-node
go run cmd/main.go genesis l2 \
--deploy-config "$CONFIG_PATH"/deploy-config.json \
--l1-deployments "/app/data/deployments/.deploy" \
--deploy-config "$DEPLOY_CONFIG_PATH" \
--l1-deployments "$CONTRACT_ADDRESSES_PATH" \
--outfile.l2 genesis.json \
--outfile.rollup rollup.json \
--l1-rpc "$L1_RPC_URL" \
--l2-allocs /app/data/deployments/allocs.json
--l2-allocs "$STATE_DUMP_PATH"
cp genesis.json "$CONFIG_PATH"/
cp rollup.json "$CONFIG_PATH"/

Expand Down