diff --git a/scripts/setup-devnet.sh b/scripts/setup-devnet.sh index 4c50e353..8c610fec 100755 --- a/scripts/setup-devnet.sh +++ b/scripts/setup-devnet.sh @@ -4,7 +4,7 @@ # This script initializes a complete devnet environment including: # - Validator keys and configuration # - Genesis file with funded validator accounts -# - Docker Compose configuration +# - Docker Compose configuration (only when --ips is not specified) # # Usage: # ./scripts/setup-devnet.sh [options] @@ -17,6 +17,10 @@ # --network-id Network identifier (default: cipherbft-devnet-1) # --output Output directory (default: ./devnet) # --extra-alloc Extra account allocation (can be repeated) +# --ips Comma-separated list of validator IPs (one per validator). +# When provided, peer addresses in node configs will use these +# IPs instead of 127.0.0.1. Docker Compose is not generated. +# The number of IPs must match --validators. # --force Overwrite existing devnet directory # --help Show this help message # @@ -24,6 +28,7 @@ # ./scripts/setup-devnet.sh # Default 4 validators, 100 ETH each # ./scripts/setup-devnet.sh -n 7 --balance 1000 # 7 validators, 1000 ETH each # ./scripts/setup-devnet.sh --extra-alloc 0x123...abc:5000 # Add extra funded account +# ./scripts/setup-devnet.sh --ips 10.0.0.1,10.0.0.2,10.0.0.3,10.0.0.4 # Multi-machine devnet set -e @@ -39,6 +44,7 @@ NETWORK_ID="cipherbft-devnet-1" OUTPUT_DIR="$PROJECT_ROOT/devnet" EXTRA_ALLOC=() FORCE=false +VALIDATOR_IPS="" # Comma-separated IPs; empty means use localhost # Parse arguments while [[ $# -gt 0 ]]; do @@ -71,6 +77,10 @@ while [[ $# -gt 0 ]]; do EXTRA_ALLOC+=("--extra-alloc" "$2") shift 2 ;; + --ips) + VALIDATOR_IPS="$2" + shift 2 + ;; --force) FORCE=true shift @@ -103,6 +113,18 @@ if [ -d "$OUTPUT_DIR" ]; then fi fi +# Validate --ips if provided +if [ -n "$VALIDATOR_IPS" ]; then + IFS=',' read -ra IP_ARRAY <<< "$VALIDATOR_IPS" + IP_COUNT=${#IP_ARRAY[@]} + if [ "$IP_COUNT" -ne "$NUM_VALIDATORS" ]; then + echo "Error: --ips requires exactly $NUM_VALIDATORS IP addresses (got $IP_COUNT)" + echo " Provided: $VALIDATOR_IPS" + echo " Use -n/--validators to change the validator count" + exit 1 + fi +fi + echo "Setting up devnet with $NUM_VALIDATORS validators..." echo "" echo "Configuration:" @@ -112,6 +134,9 @@ echo " Initial Balance: $INITIAL_BALANCE_ETH ETH per validator" echo " Chain ID: $CHAIN_ID" echo " Network ID: $NETWORK_ID" echo " Output: $OUTPUT_DIR" +if [ -n "$VALIDATOR_IPS" ]; then + echo " Validator IPs: $VALIDATOR_IPS" +fi if [ ${#EXTRA_ALLOC[@]} -gt 0 ]; then echo " Extra Allocs: ${EXTRA_ALLOC[*]}" fi @@ -146,24 +171,95 @@ echo "Generating devnet configuration..." echo "" -# Generate docker-compose configuration -echo "Generating Docker Compose configuration..." -"$SCRIPT_DIR/generate-compose.sh" "$OUTPUT_DIR" "$PROJECT_ROOT/docker" +# If custom IPs are provided, rewrite peer addresses in all node configs +if [ -n "$VALIDATOR_IPS" ]; then + echo "Updating peer addresses in node configs with provided IPs..." + IFS=',' read -ra IP_ARRAY <<< "$VALIDATOR_IPS" + + for ((i=0; i ${IP} (RPC: http://${IP}:${PORT})" + done + echo "" + echo "On each machine, copy the corresponding node directory and run:" + echo " cipherd start --config ./nodeN/config/node.json" +fi