Skip to content

Commit

Permalink
fix: sepolia deployments (#12329)
Browse files Browse the repository at this point in the history
Follow-up fixes from merging #11945 & #12076
  • Loading branch information
spypsy authored Mar 3, 2025
1 parent 0b0127f commit f72ccc2
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 34 deletions.
15 changes: 7 additions & 8 deletions .github/workflows/network-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
set -eu
set -exu

mnemonic=$1
# at least 2 accounts are needed for the validator and prover nodes
Expand All @@ -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
Expand All @@ -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))

Expand All @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions spartan/aztec-network/templates/consolidate-balances.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
7 changes: 3 additions & 4 deletions spartan/scripts/deploy_kind.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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:-}"
Expand Down Expand Up @@ -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..."
Expand Down
41 changes: 30 additions & 11 deletions spartan/scripts/prepare_sepolia_accounts.sh
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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

Expand All @@ -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" \
Expand All @@ -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"
9 changes: 5 additions & 4 deletions spartan/scripts/test_kind.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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

if [ "$install_metrics" = "true" ]; then
Expand All @@ -102,11 +103,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
Expand Down
3 changes: 2 additions & 1 deletion spartan/terraform/deploy-release/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}

Expand Down

0 comments on commit f72ccc2

Please sign in to comment.