From e6ee79b1c5bd3a22035cd90c9bf859fa2dbfefac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Pedro=20Sousa?= Date: Thu, 5 Dec 2024 15:34:34 +0000 Subject: [PATCH] feat: adding configurable data dir and p2p pk for testnet nodes --- spartan/releases/README.md | 8 +- spartan/releases/rough-rhino/Earthfile | 51 +++++-- spartan/releases/rough-rhino/aztec-spartan.sh | 128 +++++++++++------- 3 files changed, 129 insertions(+), 58 deletions(-) diff --git a/spartan/releases/README.md b/spartan/releases/README.md index 527762ae112..7ab06050674 100644 --- a/spartan/releases/README.md +++ b/spartan/releases/README.md @@ -28,9 +28,13 @@ This will install `aztec-spartan.sh` in the current directory. You can now run i ./aztec-spartan.sh config ``` -If you don't have Docker installed, the script will do it for you. It will then prompt for any required environment variables and output a `docker-compose.yml` file. +If you don't have Docker installed, the script will do it for you. It will then prompt for any required environment variables and output both a `docker-compose.yml` and an `.env` file. -You can run the command without any command to see all available options, and pass them as flags, i.e. `npx aztec-spartan config -p 8080 -p2p 40400 -n nameme`. +You will also be prompted to choose whether to use a [named volume](https://docs.docker.com/engine/storage/volumes/) (default) or if you want to use a local directory to store the node's data. + +Run `./aztec-spartan.sh` without any command to see all available options, and pass them as flags, i.e. `npx aztec-spartan config -p 8080 -p2p 40400`. + +If you want to use a different key for p2p peer id, pass it with `-pk `. ## Running diff --git a/spartan/releases/rough-rhino/Earthfile b/spartan/releases/rough-rhino/Earthfile index 53e1f6365a7..a81d2453302 100644 --- a/spartan/releases/rough-rhino/Earthfile +++ b/spartan/releases/rough-rhino/Earthfile @@ -43,14 +43,13 @@ test-install: -p 8080 \ -p2p 40400 \ -ip 1.2.3.4 \ - -k 0x00 \ - -n test-validator + -k 0x00 # Verify docker-compose.yml was created and contains correct values - RUN test -f docker-compose.yml && \ - grep -q "name: test-validator" docker-compose.yml && \ - grep -q "P2P_UDP_ANNOUNCE_ADDR=1.2.3.4:40400" docker-compose.yml && \ - grep -q "AZTEC_PORT=8080" docker-compose.yml && \ - grep -q "VALIDATOR_PRIVATE_KEY=0x00" docker-compose.yml && \ + RUN test -f .env && \ + test -f docker-compose.yml && \ + grep -q "P2P_UDP_ANNOUNCE_ADDR=1.2.3.4:40400" .env && \ + grep -q "AZTEC_PORT=8080" .env && \ + grep -q "VALIDATOR_PRIVATE_KEY=0x00" .env && \ echo "✅ Config test passed" || \ (echo "❌ Config test failed" && exit 1) @@ -70,12 +69,11 @@ test-docker-check: test-start-stop: FROM +test-setup # First install with test configuration - RUN echo -e "\n\n" | ./aztec-spartan.sh config \ + RUN echo -e "\n" | ./aztec-spartan.sh config \ -p 8080 \ -p2p 40400 \ -ip 1.2.3.4 \ - -k 0x00 \ - -n test-validator + -k 0x00 # Test start command RUN ./aztec-spartan.sh start 2>&1 | grep -q "Starting containers" && \ echo "✅ Start command test passed" || \ @@ -91,6 +89,37 @@ test-update: echo "✅ Update command test passed" || \ (echo "❌ Update command test failed" && exit 1) +test-data-dir: + FROM +test-setup + # Test installation with data directory argument + RUN echo -e "\n\n" | ./aztec-spartan.sh config \ + -p 8080 \ + -p2p 40400 \ + -ip 1.2.3.4 \ + -k 0x00 \ + -d ./aztec-data + # Verify docker-compose.yml uses bind mount instead of named volume + RUN grep -q "volumes:" docker-compose.yml && \ + grep -q "./aztec-data:/var/lib/aztec" docker-compose.yml && \ + ! grep -q "volumes:\n aztec_data:" docker-compose.yml && \ + echo "✅ Data directory test passed" || \ + (echo "❌ Data directory test failed" && exit 1) + +test-p2p-key: + FROM +test-setup + # Test installation with P2P private key argument + RUN echo -e "\n\n" | ./aztec-spartan.sh config \ + -p 8080 \ + -p2p 40400 \ + -ip 1.2.3.4 \ + -k 0x00 \ + -pk 00000 + # Verify the P2P private key was set in the .env file + RUN test -f .env && \ + grep -q "PEER_ID_PRIVATE_KEY=00000" .env && \ + echo "✅ P2P private key test passed" || \ + (echo "❌ P2P private key test failed" && exit 1) + test-all: BUILD +test-help BUILD +test-no-config @@ -98,4 +127,6 @@ test-all: BUILD +test-docker-check BUILD +test-start-stop BUILD +test-update + BUILD +test-data-dir + BUILD +test-p2p-key diff --git a/spartan/releases/rough-rhino/aztec-spartan.sh b/spartan/releases/rough-rhino/aztec-spartan.sh index 5198a7bf78c..cb1823507a7 100755 --- a/spartan/releases/rough-rhino/aztec-spartan.sh +++ b/spartan/releases/rough-rhino/aztec-spartan.sh @@ -14,7 +14,7 @@ DEFAULT_PORT="8080" DEFAULT_KEY="0x0000000000000000000000000000000000000000000000000000000000000001" # Try to get default IP from ipify API, otherwise leave empty to require user input DEFAULT_IP=$(curl -s --connect-timeout 5 https://api.ipify.org?format=json | grep -o '"ip":"[^"]*' | cut -d'"' -f4 || echo "") -DEFAULT_NAME="validator-1" +DEFAULT_BIND_MOUNT_DIR="$HOME/aztec-data" # Parse command line arguments parse_args() { @@ -36,8 +36,12 @@ parse_args() { CLI_KEY="$2" shift 2 ;; - -n|--name) - CLI_NAME="$2" + -d|--data-dir) + BIND_MOUNT_DIR="$2" + shift 2 + ;; + -pk|--p2p-id-private-key) + PEER_ID_PRIVATE_KEY="$2" shift 2 ;; *) @@ -110,14 +114,6 @@ configure_environment() { echo -e "${BLUE}Configuring environment...${NC}" - # Use CLI arguments if provided, otherwise use defaults or prompt - if [ -n "$CLI_NAME" ]; then - NAME="$CLI_NAME" - else - read -p "Validator Name [$DEFAULT_NAME]: " NAME - NAME=${NAME:-$DEFAULT_NAME} - fi - if [ -n "$CLI_P2P_PORT" ]; then P2P_PORT="$CLI_P2P_PORT" else @@ -163,50 +159,89 @@ configure_environment() { fi fi + if [ -n "$BIND_MOUNT_DIR" ]; then + BIND_MOUNT_DIR="$BIND_MOUNT_DIR" + else + read -p "Use docker volume for data directory? [Y/n] " -n 1 -r + echo + if [[ $REPLY =~ ^[Nn]$ ]]; then + read -p "Relative path for data directory [${DEFAULT_BIND_MOUNT_DIR}]: " BIND_MOUNT_DIR + BIND_MOUNT_DIR=${BIND_MOUNT_DIR:-$DEFAULT_BIND_MOUNT_DIR} + fi + fi + + + # Generate .env file + cat > .env << EOF +P2P_UDP_ANNOUNCE_ADDR=${IP}:${P2P_PORT} +P2P_TCP_ANNOUNCE_ADDR=${IP}:${P2P_PORT} +COINBASE=0xbaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +VALIDATOR_DISABLED=false +VALIDATOR_PRIVATE_KEY=${KEY} +SEQ_PUBLISHER_PRIVATE_KEY=${KEY} +L1_PRIVATE_KEY=${KEY} +DEBUG=aztec:*,-aztec:avm_simulator*,-aztec:circuits:artifact_hash,-aztec:libp2p_service,-json-rpc*,-aztec:world-state:database,-aztec:l2_block_stream* +LOG_LEVEL=debug +AZTEC_PORT=${PORT} +P2P_ENABLED=true +L1_CHAIN_ID=1337 +PROVER_REAL_PROOFS=true +PXE_PROVER_ENABLED=true +ETHEREUM_SLOT_DURATION=12sec +AZTEC_SLOT_DURATION=36 +AZTEC_EPOCH_DURATION=32 +AZTEC_EPOCH_PROOF_CLAIM_WINDOW_IN_L2_SLOTS=13 +ETHEREUM_HOST=http://34.48.76.131:8545 +BOOTSTRAP_NODES=enr:-Jq4QO_3szmgtG2cbEdnFDIhpGAQkc1HwfNy4-M6sG9QmQbPTmp9PMOHR3xslfR23hORiU-GpA7uM9uXw49lFcnuuvYGjWF6dGVjX25ldHdvcmsBgmlkgnY0gmlwhCIwTIOJc2VjcDI1NmsxoQKQTN17XKCwjYSSwmTc-6YzCMhd3v6Ofl8TS-WunX6LCoN0Y3CCndCDdWRwgp3Q +REGISTRY_CONTRACT_ADDRESS=0x5fbdb2315678afecb367f032d93f642f64180aa3 +GOVERNANCE_PROPOSER_CONTRACT_ADDRESS=0x9fe46736679d2d9a65f0992f2272de9f3c7fa6e0 +FEE_JUICE_CONTRACT_ADDRESS=0xe7f1725e7734ce288f8367e1bb143e90bb3f0512 +ROLLUP_CONTRACT_ADDRESS=0x2279b7a0a67db372996a5fab50d91eaa73d2ebe6 +REWARD_DISTRIBUTOR_CONTRACT_ADDRESS=0x5fc8d32690cc91d4c39d9d3abcbd16989f875707 +GOVERNANCE_CONTRACT_ADDRESS=0xcf7ed3acca5a467e9e704c703e8d87f634fb0fc9 +COIN_ISSUER_CONTRACT_ADDRESS=0xdc64a140aa3e981100a9beca4e685f962f0cf6c9 +FEE_JUICE_PORTAL_CONTRACT_ADDRESS=0x0165878a594ca255338adfa4d48449f69242eb8f +INBOX_CONTRACT_ADDRESS=0xed179b78d5781f93eb169730d8ad1be7313123f4 +OUTBOX_CONTRACT_ADDRESS=0x1016b5aaa3270a65c315c664ecb238b6db270b64 +P2P_UDP_LISTEN_ADDR=0.0.0.0:${P2P_PORT} +P2P_TCP_LISTEN_ADDR=0.0.0.0:${P2P_PORT} +DATA_DIRECTORY=/var/lib/aztec +PEER_ID_PRIVATE_KEY=${PEER_ID_PRIVATE_KEY} +EOF + # Generate docker-compose.yml cat > docker-compose.yml << EOF -name: ${NAME} services: validator: network_mode: host restart: unless-stopped - environment: - - P2P_UDP_ANNOUNCE_ADDR=${IP}:${P2P_PORT} - - P2P_TCP_ANNOUNCE_ADDR=${IP}:${P2P_PORT} - - COINBASE=0xbaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa - - VALIDATOR_DISABLED=false - - VALIDATOR_PRIVATE_KEY=${KEY} - - SEQ_PUBLISHER_PRIVATE_KEY=${KEY} - - L1_PRIVATE_KEY=${KEY} - - DEBUG=aztec:*,-aztec:avm_simulator*,-aztec:circuits:artifact_hash,-aztec:libp2p_service,-json-rpc*,-aztec:world-state:database,-aztec:l2_block_stream* - - LOG_LEVEL=debug - - AZTEC_PORT=${PORT} - - P2P_ENABLED=true - - L1_CHAIN_ID=1337 - - PROVER_REAL_PROOFS=true - - PXE_PROVER_ENABLED=true - - ETHEREUM_SLOT_DURATION=12sec - - AZTEC_SLOT_DURATION=36 - - AZTEC_EPOCH_DURATION=32 - - AZTEC_EPOCH_PROOF_CLAIM_WINDOW_IN_L2_SLOTS=13 - - ETHEREUM_HOST=http://34.48.76.131:8545 - - BOOTSTRAP_NODES=enr:-Jq4QO_3szmgtG2cbEdnFDIhpGAQkc1HwfNy4-M6sG9QmQbPTmp9PMOHR3xslfR23hORiU-GpA7uM9uXw49lFcnuuvYGjWF6dGVjX25ldHdvcmsBgmlkgnY0gmlwhCIwTIOJc2VjcDI1NmsxoQKQTN17XKCwjYSSwmTc-6YzCMhd3v6Ofl8TS-WunX6LCoN0Y3CCndCDdWRwgp3Q - - REGISTRY_CONTRACT_ADDRESS=0x5fbdb2315678afecb367f032d93f642f64180aa3 - - GOVERNANCE_PROPOSER_CONTRACT_ADDRESS=0x9fe46736679d2d9a65f0992f2272de9f3c7fa6e0 - - FEE_JUICE_CONTRACT_ADDRESS=0xe7f1725e7734ce288f8367e1bb143e90bb3f0512 - - ROLLUP_CONTRACT_ADDRESS=0x2279b7a0a67db372996a5fab50d91eaa73d2ebe6 - - REWARD_DISTRIBUTOR_CONTRACT_ADDRESS=0x5fc8d32690cc91d4c39d9d3abcbd16989f875707 - - GOVERNANCE_CONTRACT_ADDRESS=0xcf7ed3acca5a467e9e704c703e8d87f634fb0fc9 - - COIN_ISSUER_CONTRACT_ADDRESS=0xdc64a140aa3e981100a9beca4e685f962f0cf6c9 - - FEE_JUICE_PORTAL_CONTRACT_ADDRESS=0x0165878a594ca255338adfa4d48449f69242eb8f - - INBOX_CONTRACT_ADDRESS=0xed179b78d5781f93eb169730d8ad1be7313123f4 - - OUTBOX_CONTRACT_ADDRESS=0x1016b5aaa3270a65c315c664ecb238b6db270b64 - - P2P_UDP_LISTEN_ADDR=0.0.0.0:${P2P_PORT} - - P2P_TCP_LISTEN_ADDR=0.0.0.0:${P2P_PORT} + env_file: .env image: aztecprotocol/aztec:698cd3d62680629a3f1bfc0f82604534cedbccf3-${ARCH} - command: start --node --archiver --sequencer + entrypoint: > + sh -c ' + + test -z "\$PEER_ID_PRIVATE_KEY" -a ! -f /var/lib/aztec/p2p-private-key && node /usr/src/yarn-project/aztec/dest/bin/index.js generate-p2p-private-key | head -1 | cut -d" " -f 3 | tee /var/lib/aztec/p2p-private-key || echo "Re-using existing P2P private key" + test -z "\$PEER_ID_PRIVATE_KEY" && export PEER_ID_PRIVATE_KEY=\$(cat /var/lib/aztec/p2p-private-key) + + node --no-warnings /usr/src/yarn-project/aztec/dest/bin/index.js start --node --archiver --sequencer' EOF + # Add volume configuration based on user choice + if [ -n "$BIND_MOUNT_DIR" ]; then + cat >> docker-compose.yml << EOF + volumes: + - ${BIND_MOUNT_DIR}:/var/lib/aztec +EOF + else + cat >> docker-compose.yml << EOF + volumes: + - aztec_data:/var/lib/aztec + +volumes: + aztec_data: +EOF + fi + echo -e "${GREEN}Configuration complete! Use './aztec-spartan.sh start' to launch your node.${NC}" } @@ -283,3 +318,4 @@ case "$1" in exit 1 ;; esac +