Skip to content
Merged
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
48 changes: 43 additions & 5 deletions devnet/3-op-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ if [ -z "$FORK_BLOCK" ]; then
exit 1
fi

echo "🔧 Setting fork block and parent hash in genesis.json ..."
FORK_BLOCK_HEX=$(printf "0x%x" "$FORK_BLOCK")
sed_inplace '/"config": {/,/}/ s/"optimism": {/"legacyXLayerBlock": '"$((FORK_BLOCK + 1))"',\n "optimism": {/' ./config-op/genesis.json
sed_inplace 's/"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000"/"parentHash": "'"$PARENT_HASH"'"/' ./config-op/genesis.json
Expand All @@ -31,11 +32,24 @@ sed_inplace 's/"eip1559Elasticity": [0-9]*/"eip1559Elasticity": '"$(jq -r '.conf
sed_inplace 's/"eip1559Denominator": [0-9]*/"eip1559Denominator": '"$(jq -r '.config.optimism.eip1559Denominator' ./config-op/genesis.json)"'/' ./config-op/rollup.json
sed_inplace 's/"eip1559DenominatorCanyon": [0-9]*/"eip1559DenominatorCanyon": '"$(jq -r '.config.optimism.eip1559DenominatorCanyon' ./config-op/genesis.json)"'/' ./config-op/rollup.json

# echo "🔧 Merging genesis files..."
# /usr/local/bin/merge_genesis ~/dev/okx/xlayer-toolkit/devnet/config-op/genesis.json ~/data/xlayer/genesis_2m.json ~/dev/okx/xlayer-toolkit/devnet/config-op/merged.genesis.json
# cp ./config-op/merged.genesis.json ./config-op/genesis-reth.json
cp ./config-op/genesis.json ./config-op/genesis-reth.json
sed_inplace 's/"number": "0x0"/"number": "'"$NEXT_BLOCK_NUMBER_HEX"'"/' ./config-op/genesis-reth.json
if [ "$MERGE_RETH_GENESIS" = "true" ]; then
echo "🔧 Merging genesis files..."

if [ -z "$MERGE_RETH_DATADIR_PATH" ]; then
echo " ❌ MERGE_RETH_DATADIR_PATH environment variable is not set"
echo "Please set MERGE_RETH_DATADIR_PATH in your .env file"
exit 1
fi

docker run --rm -v "./config-op:/config-op" -v "$MERGE_RETH_DATADIR_PATH:/reth-datadir" $XLAYER_RETH_TOOLS_IMAGE_TAG \
gen-genesis --datadir /reth-datadir --chain $MERGE_RETH_CHAIN \
--template-genesis /config-op/genesis.json --output /config-op/genesis-reth.json --output-chainspec /config-op/xlayer-devnet.json
else
# Create genesis-reth.json from genesis.json
echo "🔧 Creating genesis-reth.json from genesis.json ..."
cp ./config-op/genesis.json ./config-op/genesis-reth.json
sed_inplace 's/"number": "0x0"/"number": "'"$NEXT_BLOCK_NUMBER_HEX"'"/' ./config-op/genesis-reth.json
fi

# Extract contract addresses from state.json and update .env file
echo "🔧 Extracting contract addresses from state.json..."
Expand Down Expand Up @@ -176,6 +190,30 @@ NEW_BLOCK_HASH=$(tail -n 1 init.log | jq -r .fields.hash)
echo "NEW_BLOCK_HASH=$NEW_BLOCK_HASH"
sed_inplace "s/NEW_BLOCK_HASH=.*/NEW_BLOCK_HASH=$NEW_BLOCK_HASH/" .env

if [ "${USE_CHAINSPEC:-false}" = "true" ]; then
if [ -z "$OP_RETH_LOCAL_DIRECTORY" ]; then
echo " ❌ OP_RETH_LOCAL_DIRECTORY environment variable is not set."
echo "This is required to re-build op-reth with chainspec."
echo "Please set OP_RETH_LOCAL_DIRECTORY in your .env file"
exit 1
fi
cd "$OP_RETH_LOCAL_DIRECTORY"
if [ ! -f "crates/chainspec/res/genesis/xlayer-devnet-genesis-hash.txt" ]; then
echo " ❌ crates/chainspec/res/genesis/xlayer-devnet-genesis-hash.txt not found."
echo "This is required to re-build op-reth with chainspec."
echo "Please run 'just build-docker' to build op-reth with chainspec."
exit 1
fi
echo $NEW_BLOCK_HASH > crates/chainspec/res/genesis/xlayer-devnet-genesis-hash.txt
cp $PWD_DIR/config-op/xlayer-devnet.json crates/chainspec/res/genesis/xlayer-devnet.json
just build-docker
cd "$PWD_DIR"

if [ "$LAUNCH_RPC_NODE" = "true" ] && [ "$RPC_TYPE" = "reth" ]; then
echo " 🔄 Copying database from op-reth-seq to op-reth-rpc..."
cp -r $OP_RETH_DATADIR "$(pwd)/data/op-reth-rpc"
fi
fi

# Copy initialized database from op-geth-seq to other nodes
OP_GETH_RPC_DATADIR="$(pwd)/data/op-geth-rpc"
Expand Down
36 changes: 36 additions & 0 deletions devnet/4-op-start-service.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,38 @@ sed_inplace() {
fi
}

wait_for_el_to_start() {
CONTAINER_NAME=$1
if [ -z "$CONTAINER_NAME" ]; then
echo "Error: CONTAINER_NAME is not set"
exit 1
fi

# Wait for execution layer to start
echo "⏳ Waiting for execution layer to start in ${CONTAINER_NAME} ..."
MAX_WAIT=300 # 5 minutes timeout
ELAPSED=0
FOUND=false

while [ $ELAPSED -lt $MAX_WAIT ]; do
if docker logs ${CONTAINER_NAME} 2>&1 | grep -q "Starting consensus engine"; then
echo "✅ Execution layer started!"
FOUND=true
break
fi
sleep 2
ELAPSED=$((ELAPSED + 2))
if [ $((ELAPSED % 10)) -eq 0 ]; then
echo " Still waiting... (${ELAPSED}s/${MAX_WAIT}s)"
fi
done

if [ "$FOUND" = false ]; then
echo "❌ Error: Timeout waiting for execution layer to start (${MAX_WAIT}s)"
exit 1
fi
}

PWD_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SCRIPTS_DIR=$PWD_DIR/scripts

Expand Down Expand Up @@ -62,6 +94,8 @@ if [ "$CONDUCTOR_ENABLED" = "true" ]; then
sleep 10
$SCRIPTS_DIR/active-sequencer.sh
else
docker compose up -d op-${SEQ_TYPE}-seq
wait_for_el_to_start "op-${SEQ_TYPE}-seq"
docker compose up -d op-seq
fi

Expand All @@ -75,6 +109,8 @@ echo "✅ Grafana available at http://localhost:3000 (admin/admin)"
#$SCRIPTS_DIR/add-peers.sh

if [ "$LAUNCH_RPC_NODE" = "true" ]; then
docker compose up -d op-${RPC_TYPE}-rpc
wait_for_el_to_start "op-${RPC_TYPE}-rpc"
docker compose up -d op-rpc
fi

Expand Down
2 changes: 1 addition & 1 deletion devnet/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ services:
- --l1.rpckind=standard
- --rollup.l1-chain-config=/l1-genesis.json
- --safedb.path=/data/safedb
- --conductor.enabled=${CONDUCTOR_ENABLED:-false} # 默认关闭
- --conductor.enabled=${CONDUCTOR_ENABLED:-false}
- --conductor.rpc=http://op-conductor:8547
- --pprof.enabled
- --pprof.addr=0.0.0.0
Expand Down
8 changes: 7 additions & 1 deletion devnet/entrypoint/reth-rpc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,16 @@ fi
# Read the first argument (1 or 0), default to 0 if not provided
FLASHBLOCKS_RPC=${FLASHBLOCKS_RPC:-"true"}

if [ "${USE_CHAINSPEC:-false}" = "true" ]; then
CHAIN="xlayer-devnet"
else
CHAIN="/genesis.json"
fi

# Build the command with common arguments
CMD="op-reth node \
--datadir=/datadir \
--chain=/genesis.json \
--chain=$CHAIN \
--config=/config.toml \
--http \
--http.corsdomain=* \
Expand Down
8 changes: 7 additions & 1 deletion devnet/entrypoint/reth-seq.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,15 @@ if [ "${JEMALLOC_PROFILING:-false}" = "true" ]; then
echo "Jemalloc profiling enabled: _RJEM_MALLOC_CONF=$_RJEM_MALLOC_CONF"
fi

if [ "${USE_CHAINSPEC:-false}" = "true" ]; then
CHAIN="xlayer-devnet"
else
CHAIN="/genesis.json"
fi

CMD="op-reth node \
--datadir=/datadir \
--chain=/genesis.json \
--chain=$CHAIN \
--config=/config.toml \
--http \
--http.corsdomain=* \
Expand Down
6 changes: 6 additions & 0 deletions devnet/example.env
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@ FORK_BLOCK=8593920
PARENT_HASH="0x6912fea590fd46ca6a63ec02c6733f6ffb942b84cdf86f7894c21e1757a1f68a"
NEW_BLOCK_HASH=0xddb9bdc86631494bab4b4749c4575035e2383da7c96d32d31341de862b1dd6c9

MERGE_RETH_GENESIS=false
MERGE_RETH_CHAIN=xlayer-testnet
MERGE_RETH_DATADIR_PATH=
XLAYER_RETH_TOOLS_IMAGE_TAG=xlayer-reth-tools:latest
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is built using the tool in okx/xlayer-reth#159.

USE_CHAINSPEC=false

# ==============================================================================
# Other Configuration
# ==============================================================================
Expand Down