diff --git a/.github/workflows/network-deploy.yml b/.github/workflows/network-deploy.yml index 9d6a2f68292e..d095ade40904 100644 --- a/.github/workflows/network-deploy.yml +++ b/.github/workflows/network-deploy.yml @@ -84,11 +84,6 @@ on: required: false type: string default: "false" - ref: - description: The branch name to deploy from - required: false - type: string - default: "master" sepolia_deployment: description: "Whether to deploy on Sepolia network (default: false)" required: false @@ -123,7 +118,7 @@ jobs: - name: Checkout code uses: actions/checkout@v3 with: - ref: ${{ inputs.ref }} + ref: ${{ inputs.ref || github.ref }} - name: Authenticate to Google Cloud uses: google-github-actions/auth@v2 @@ -174,8 +169,12 @@ jobs: run: | REPO=$(git rev-parse --show-toplevel) export FUNDING_PRIVATE_KEY=${{ secrets.SEPOLIA_FUNDING_PRIVATE_KEY }} - export ETHEREUM_HOST=${{ env.EXTERNAL_ETHEREUM_HOST }} - mnemonic=$(bash $REPO/spartan/scripts/prepare_sepolia_accounts.sh ${{ env.VALUES_FILE }} 5) + export ETHEREUM_HOST="https://json-rpc.${{ secrets.GCP_SEPOLIA_URL }}?key=${{ secrets.GCP_SEPOLIA_API_KEY }}" + echo "Preparing sepolia accounts..." + MNEMONIC_FILE=$(mktemp) + $REPO/spartan/scripts/prepare_sepolia_accounts.sh ${{ env.VALUES_FILE }} 30 "$MNEMONIC_FILE" + mnemonic=$(cat "$MNEMONIC_FILE") + rm "$MNEMONIC_FILE" echo "::add-mask::$mnemonic" echo "mnemonic=$mnemonic" >> "$GITHUB_OUTPUT" diff --git a/spartan/aztec-network/files/cleanup/consolidate-sepolia-balances.sh b/spartan/aztec-network/files/cleanup/consolidate-sepolia-balances.sh index 491f68c01aad..e39d51fa5897 100755 --- a/spartan/aztec-network/files/cleanup/consolidate-sepolia-balances.sh +++ b/spartan/aztec-network/files/cleanup/consolidate-sepolia-balances.sh @@ -1,5 +1,5 @@ #!/bin/bash -set -eu +set -exu mnemonic=$1 # at least 2 accounts are needed for the validator and prover nodes @@ -8,6 +8,8 @@ funding_address=${3:-"0x33D525f5ac95c2BCf98b644738C7d5673480493A"} XDG_CONFIG_HOME=${XDG_CONFIG_HOME:-"$HOME/.config"} +ETHEREUM_RPC_URL=$(echo "$ETHEREUM_HOSTS" | cut -d',' -f1) + # Install cast if needed if ! command -v cast &>/dev/null; then curl -L https://foundry.paradigm.xyz | bash @@ -22,10 +24,10 @@ for i in $(seq 0 $((num_accounts - 1))); do private_key=$(cast wallet private-key --mnemonic "$mnemonic" --mnemonic-index $i) # Get balance - balance=$(cast balance $address --rpc-url "$ETHEREUM_HOST") + balance=$(cast balance $address --rpc-url "$ETHEREUM_RPC_URL") if [ "$balance" != "0" ]; then - gas_price=$(cast gas-price --rpc-url "$ETHEREUM_HOST") + gas_price=$(cast gas-price --rpc-url "$ETHEREUM_RPC_URL") gas_price=$((gas_price * 120 / 100)) # Add 20% to gas price gas_cost=$((21000 * gas_price)) @@ -34,7 +36,7 @@ for i in $(seq 0 $((num_accounts - 1))); do if [ "$send_amount" -gt "0" ]; then echo "Sending $send_amount wei from $address to $funding_address" - cast send --private-key "$private_key" --rpc-url "$ETHEREUM_HOST" "$funding_address" \ + cast send --private-key "$private_key" --rpc-url "$ETHEREUM_RPC_URL" "$funding_address" \ --value "$send_amount" --gas-price "$gas_price" --async else echo "Balance too low to cover gas costs for $address" diff --git a/spartan/aztec-network/templates/consolidate-balances.yaml b/spartan/aztec-network/templates/consolidate-balances.yaml index 2718967a71f1..8cd6ae9a27bb 100644 --- a/spartan/aztec-network/templates/consolidate-balances.yaml +++ b/spartan/aztec-network/templates/consolidate-balances.yaml @@ -42,6 +42,6 @@ spec: chmod +x /tmp/consolidate-sepolia-balances.sh /tmp/consolidate-sepolia-balances.sh "{{ .Values.aztec.l1DeploymentMnemonic }}" {{ add .Values.validator.replicas .Values.proverNode.replicas }} env: - - name: ETHEREUM_HOST - value: "{{ .Values.ethereum.execution.externalHost }}" + - name: ETHEREUM_HOSTS + value: "{{ .Values.ethereum.execution.externalHosts }}" {{ end }} diff --git a/spartan/scripts/deploy_kind.sh b/spartan/scripts/deploy_kind.sh index 1b4890a9fdaa..66f2108b1cba 100755 --- a/spartan/scripts/deploy_kind.sh +++ b/spartan/scripts/deploy_kind.sh @@ -21,7 +21,8 @@ set -x namespace="$1" values_file="${2:-default.yaml}" sepolia_deployment="${3:-false}" -helm_instance="${4:-spartan}" +mnemonic_file="${4:-"mnemonic.tmp"}" +helm_instance="${5:-spartan}" # Default values for environment variables chaos_values="${CHAOS_VALUES:-}" @@ -83,9 +84,7 @@ function generate_overrides { if [ "$sepolia_deployment" = "true" ]; then echo "Generating sepolia accounts..." set +x - L1_ACCOUNTS_MNEMONIC=$(./prepare_sepolia_accounts.sh "$values_file") - # write the mnemonic to a file - echo "$L1_ACCOUNTS_MNEMONIC" >mnemonic.tmp + L1_ACCOUNTS_MNEMONIC=$(./prepare_sepolia_accounts.sh "$values_file" "$mnemonic_file") set -x else echo "Generating devnet config..." diff --git a/spartan/scripts/prepare_sepolia_accounts.sh b/spartan/scripts/prepare_sepolia_accounts.sh index 923b451ed350..2d15266c0567 100755 --- a/spartan/scripts/prepare_sepolia_accounts.sh +++ b/spartan/scripts/prepare_sepolia_accounts.sh @@ -1,8 +1,24 @@ #!/bin/bash -set -eu + +set -euo pipefail + +source $(git rev-parse --show-toplevel)/ci3/source + +tmp_filename=$(mktemp) + +# Cleanup function to handle the temp file +cleanup() { + if [ -f "$tmp_filename" ]; then + rm -f "$tmp_filename" + fi +} + +# Set up trap to call cleanup on script exit +trap cleanup EXIT values_file=$1 eth_amount=${2:-"1"} +output_file=${3:-"mnemonic.tmp"} XDG_CONFIG_HOME=${XDG_CONFIG_HOME:-"$HOME/.config"} value_yamls="../aztec-network/values/$values_file ../aztec-network/values.yaml" @@ -14,31 +30,35 @@ num_accounts=$((num_validators + num_provers + num_bots)) # Install bc if needed if ! command -v bc &>/dev/null; then + echo "Installing bc..." apt-get update && apt-get install -y bc fi # Install cast if needed if ! command -v cast &>/dev/null; then + echo "Installing cast..." curl -L https://foundry.paradigm.xyz | bash - $HOME/.foundry/bin/foundryup && export PATH="$PATH:$HOME/.foundry/bin" || - $XDG_CONFIG_HOME/.foundry/bin/foundryup && export PATH="$PATH:$XDG_CONFIG_HOME/.foundry/bin" + $HOME/.foundry/bin/foundryup && export PATH="$PATH:$HOME/.foundry/bin" || $XDG_CONFIG_HOME/.foundry/bin/foundryup && export PATH="$PATH:$XDG_CONFIG_HOME/.foundry/bin" fi # Install yq if needed if ! command -v yq &>/dev/null; then + echo "Installing yq..." wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O /usr/local/bin/yq chmod +x /usr/local/bin/yq fi # Create a new mnemonic with the required number of accounts -cast wallet new-mnemonic --accounts "$num_accounts" --json >output.json -MNEMONIC=$(jq -r '.mnemonic' output.json) -ADDRESSES=$(jq -r '.accounts[].address' output.json) +echo "Creating mnemonic..." +cast wallet new-mnemonic --accounts "$num_accounts" --json >"$tmp_filename" +MNEMONIC=$(jq -r '.mnemonic' "$tmp_filename") +ADDRESSES=$(jq -r '.accounts[].address' "$tmp_filename") # Convert ETH to wei wei_amount=$(cast to-wei "$eth_amount" ether) # Get current gas price and add 25% buffer +echo "Getting gas price..." gas_price=$(cast gas-price --rpc-url "$ETHEREUM_HOST") gas_price=$((gas_price * 125 / 100)) # Add 25% to gas price @@ -56,6 +76,7 @@ total_value=$(echo "$wei_amount * $num_accounts" | bc) multicall_address="0xcA11bde05977b3631167028862bE2a173976CA11" # Sepolia Multicall3 contract +echo "Sending transaction..." tx_hash=$(cast send "$multicall_address" \ "aggregate3Value((address,bool,uint256,bytes)[])" \ "$calls" \ @@ -64,9 +85,7 @@ tx_hash=$(cast send "$multicall_address" \ --rpc-url "$ETHEREUM_HOST" \ --json --gas-price "$gas_price") -echo >&2 "Sent ${wei_amount} wei to ${num_accounts} addresses in tx $tx_hash" - -# Remove temp file -rm output.json +echo "Sent ${wei_amount} wei to ${num_accounts} addresses in tx $tx_hash" -echo "$MNEMONIC" +# Write mnemonic to output file +echo "$MNEMONIC" >"$output_file" diff --git a/spartan/scripts/test_kind.sh b/spartan/scripts/test_kind.sh index 73aca4b1e4d1..cdb50942ffcb 100755 --- a/spartan/scripts/test_kind.sh +++ b/spartan/scripts/test_kind.sh @@ -25,6 +25,7 @@ set -x test=$1 values_file="${2:-default.yaml}" namespace="${3:-$(basename $test | tr '.' '-')}" +mnemonic_file="${4:-$(mktemp)}" # Default values for environment variables helm_instance=${HELM_INSTANCE:-$namespace} @@ -84,7 +85,7 @@ copy_stern_to_log # uses VALUES_FILE, CHAOS_VALUES, AZTEC_DOCKER_TAG and INSTALL_TIMEOUT optional env vars if [ "$fresh_install" != "no-deploy" ]; then - deploy_result=$(OVERRIDES="$OVERRIDES" ./deploy_kind.sh $namespace $values_file $sepolia_run $helm_instance) + deploy_result=$(OVERRIDES="$OVERRIDES" ./deploy_kind.sh $namespace $values_file $sepolia_run $mnemonic_file $helm_instance) fi # Find 6 free ports between 9000 and 10000 @@ -113,11 +114,11 @@ aztec_epoch_duration=$(./read_value.sh "aztec.epochDuration" $value_yamls) aztec_proof_submission_window=$(./read_value.sh "aztec.proofSubmissionWindow" $value_yamls) if [ "$sepolia_run" = "true" ]; then - # Read the mnemonic from file mnemonic.tmp + # Read the mnemonic from tmp file set +x - l1_account_mnemonic=$(cat mnemonic.tmp) + l1_account_mnemonic=$(cat "$mnemonic_file") set -x - rm mnemonic.tmp + rm "$mnemonic_file" else l1_account_mnemonic=$(./read_value.sh "aztec.l1DeploymentMnemonic" $value_yamls) fi diff --git a/spartan/terraform/deploy-release/main.tf b/spartan/terraform/deploy-release/main.tf index 77a8a0b6e312..86ec09a57b63 100644 --- a/spartan/terraform/deploy-release/main.tf +++ b/spartan/terraform/deploy-release/main.tf @@ -84,7 +84,8 @@ resource "helm_release" "aztec-gke-cluster" { for_each = var.EXTERNAL_ETHEREUM_HOSTS != "" ? toset(["iterate"]) : toset([]) content { name = "ethereum.execution.externalHosts" - value = var.EXTERNAL_ETHEREUM_HOSTS + value = replace(var.EXTERNAL_ETHEREUM_HOSTS, ",", "\\,") + type = "string" } }