Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: kind on sepolia + balance consolidation + sepolia values service indices #12473

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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

This file was deleted.

105 changes: 101 additions & 4 deletions spartan/aztec-network/templates/consolidate-balances.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# NOTE: If script logic below is updated, then scripts/consolidate-sepolia-balances.sh should be updated as well.
{{- if .Values.ethereum.execution.externalHosts }}
apiVersion: batch/v1
kind: Job
Expand All @@ -24,9 +25,105 @@ spec:
- name: config
emptyDir: {}
- name: scripts
configMap:
name: {{ include "aztec-network.fullname" . }}-scripts
defaultMode: 0755
# Use emptyDir instead of ConfigMap to avoid dependency on a resource that might be deleted
emptyDir: {}
initContainers:
- name: create-scripts
image: busybox
command:
- /bin/sh
- -c
- |
cat > /scripts/consolidate-sepolia-balances.sh << 'EOF'
#!/bin/bash
set -eu

mnemonic=$1
funding_address=${2:-"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
$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

# Get the indices to check based on the configuration
validator_key_index_start={{ .Values.aztec.validatorKeyIndexStart }}
prover_key_index_start={{ .Values.aztec.proverKeyIndexStart }}
bot_key_index_start={{ .Values.aztec.botKeyIndexStart }}

num_validators={{ .Values.validator.replicas }}
num_provers={{ .Values.proverNode.replicas }}

# Check if bots are enabled
bot_enabled={{ .Values.bot.enabled }}
if [ "$bot_enabled" = "true" ]; then
num_bots={{ .Values.bot.replicas }}
else
num_bots=0
fi

# Build an array of indices to check
declare -a indices_to_check

# Add validator indices
for ((i = 0; i < num_validators; i++)); do
indices_to_check+=($((validator_key_index_start + i)))
done

# Add prover indices
for ((i = 0; i < num_provers; i++)); do
indices_to_check+=($((prover_key_index_start + i)))
done

# Add bot indices if enabled
if [ "$bot_enabled" = "true" ]; then
for ((i = 0; i < num_bots; i++)); do
indices_to_check+=($((bot_key_index_start + i)))
done
fi

echo "Checking balances for ${#indices_to_check[@]} accounts..."

# For each index in our list
for i in "${indices_to_check[@]}"; do
# Get address and private key for this index
address=$(cast wallet address --mnemonic "$mnemonic" --mnemonic-index $i)
private_key=$(cast wallet private-key --mnemonic "$mnemonic" --mnemonic-index $i)

# Get balance
balance=$(cast balance $address --rpc-url "$ETHEREUM_RPC_URL")

if [ "$balance" != "0" ]; then
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))

# Calculate amount to send (balance - gas cost)
send_amount=$((balance - gas_cost))

if [ "$send_amount" -gt "0" ]; then
echo "Sending $send_amount wei from $address (index $i) to $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 (index $i)"
fi
else
echo "No balance in $address (index $i)"
fi
done
EOF
chmod +x /scripts/consolidate-sepolia-balances.sh
volumeMounts:
- name: scripts
mountPath: /scripts

containers:
- name: consolidate-balances
{{- include "aztec-network.image" . | nindent 10 }}
Expand All @@ -39,7 +136,7 @@ spec:
- /bin/bash
- -c
- |
/scripts/consolidate-sepolia-balances.sh "{{ .Values.aztec.l1DeploymentMnemonic }}" {{ add .Values.validator.replicas .Values.proverNode.replicas }}
/scripts/consolidate-sepolia-balances.sh "{{ .Values.aztec.l1DeploymentMnemonic }}"
env:
- name: ETHEREUM_HOSTS
value: "{{ .Values.ethereum.execution.externalHosts }}"
Expand Down
3 changes: 0 additions & 3 deletions spartan/aztec-network/values/ci-sepolia.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ aztec:
proofSubmissionWindow: 8
realProofs: false
l1DeploymentMnemonic: ""
validatorKeyIndexStart: 0
proverKeyIndexStart: 3
botKeyIndexStart: 4

network:
setupL2Contracts: false
Expand Down
2 changes: 0 additions & 2 deletions spartan/aztec-network/values/ignition-testnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ telemetry:

aztec:
realProofs: true
validatorKeyIndexStart: 0
proverKeyIndexStart: 3
testAccounts: true
bootstrapENRs: "enr:-LO4QDwlKJN0BqMc4hYPsI-MQoR1O7qLVr4TK6DhqGsZT_pPTmg3gS-JD072rKI4vlaR0N4SdeH2gCD09oh-zMVT3JkEhWF6dGVjqDAwLTExMTU1MTExLTAwMDAwMDAwLTAtMmM4ZmM0NjMtMjM3YWFkY2WCaWSCdjSCaXCEI-XzqolzZWNwMjU2azGhA0da3IZGbY1tLdqXgdQKG-SW-Z4D6dvXJBeoXn8EZsCVg3VkcIKd0A,enr:-LO4QPJR493G_BQG1UU0_h-g0TEBnZEJ-zgWYH3YctVAn3GzfM9dWVIO7_TSETXYLy-h34bF6sSoSfpP5O44qsZnp00EhWF6dGVjqDAwLTExMTU1MTExLTAwMDAwMDAwLTAtMmM4ZmM0NjMtMjM3YWFkY2WCaWSCdjSCaXCEIlle64lzZWNwMjU2azGhAwuSF_VE1cRfSc3MvtDZvvaTl2Qo_dJK-Qp7TcnhYWBtg3VkcIKd0A,enr:-LO4QKq488wXvw6vAHToGWJYkxMmKsjQCsFjPs5Pt_MrawlnZ7G-xIfwhkXR1afddf8lFj_RNVZdBfGzHHR262pXNhMEhWF6dGVjqDAwLTExMTU1MTExLTAwMDAwMDAwLTAtMmM4ZmM0NjMtMjM3YWFkY2WCaWSCdjSCaXCEI8VFSYlzZWNwMjU2azGhA2xqOyFaHAARgLAi3dORuPmFHbxgoMDWBZJnnbiatW8jg3VkcIKd0A"
contracts:
Expand Down
3 changes: 0 additions & 3 deletions spartan/aztec-network/values/rc-2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ aztec:
realProofs: true
# TODO: Will need to change these as ignition will be using them
l1DeploymentMnemonic: ""
validatorKeyIndexStart: 0
proverKeyIndexStart: 48
botKeyIndexStart: 49

images:
aztec:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ telemetry:

aztec:
realProofs: false
validatorKeyIndexStart: 0
proverKeyIndexStart: 3
botKeyIndexStart: 4

network:
setupL2Contracts: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ telemetry:

aztec:
l1DeploymentMnemonic: ""
validatorKeyIndexStart: 0
proverKeyIndexStart: 48
botKeyIndexStart: 49

network:
setupL2Contracts: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ telemetry:
aztec:
realProofs: true
l1DeploymentMnemonic: ""
validatorKeyIndexStart: 0
proverKeyIndexStart: 48
botKeyIndexStart: 49

images:
aztec:
Expand Down
98 changes: 98 additions & 0 deletions spartan/scripts/consolidate-sepolia-balances.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#!/bin/bash

# Helper script for consolidating balances on Sepolia, that were previously dispersed across multiple accounts.
# The script uses the mnemonic to get the accounts' private keys & calculate which ones were funded from a helm chart yaml.
# Usage: ./consolidate-sepolia-balances.sh <mnemonic> <funding_address> <values_file>
# Environment variables:
# ETHEREUM_HOSTS (must be provided)

# IMPORTANT NOTE: The script should be the same as the one found in the consolidate-balances.yaml template.
# This standalone is left here for ad-hoc use if needed.

set -exu

mnemonic=$1
funding_address=${2:-"0x33D525f5ac95c2BCf98b644738C7d5673480493A"}
values_file=${3:-"ignition-testnet"}

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
$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

# Get values from the values file
value_yamls="../aztec-network/values/$values_file ../aztec-network/values.yaml"

# Get the number of replicas for each service
num_validators=$(./read_value.sh "validator.replicas" $value_yamls)
num_provers=$(./read_value.sh "proverNode.replicas" $value_yamls)

# Get the key index start values
validator_key_index_start=$(./read_value.sh "aztec.validatorKeyIndexStart" $value_yamls)
prover_key_index_start=$(./read_value.sh "aztec.proverKeyIndexStart" $value_yamls)
bot_key_index_start=$(./read_value.sh "aztec.botKeyIndexStart" $value_yamls)

# bots might be disabled
bot_enabled=$(./read_value.sh "bot.enabled" $value_yamls)
if [ "$bot_enabled" = "true" ]; then
num_bots=$(./read_value.sh "bot.replicas" $value_yamls)
else
num_bots=0
fi

# Build an array of indices to check
declare -a indices_to_check

# Add validator indices
for ((i = 0; i < num_validators; i++)); do
indices_to_check+=($((validator_key_index_start + i)))
done

# Add prover indices
for ((i = 0; i < num_provers; i++)); do
indices_to_check+=($((prover_key_index_start + i)))
done

# Add bot indices if enabled
if [ "$bot_enabled" = "true" ]; then
for ((i = 0; i < num_bots; i++)); do
indices_to_check+=($((bot_key_index_start + i)))
done
fi

echo "Checking balances for ${#indices_to_check[@]} accounts..."

# For each index in our list
for i in "${indices_to_check[@]}"; do
# Get address and private key for this index
address=$(cast wallet address --mnemonic "$mnemonic" --mnemonic-index $i)
private_key=$(cast wallet private-key --mnemonic "$mnemonic" --mnemonic-index $i)

# Get balance
balance=$(cast balance $address --rpc-url "$ETHEREUM_RPC_URL")

if [ "$balance" != "0" ]; then
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))

# Calculate amount to send (balance - gas cost)
send_amount=$((balance - gas_cost))

if [ "$send_amount" -gt "0" ]; then
echo "Sending $send_amount wei from $address (index $i) to $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 (index $i)"
fi
else
echo "No balance in $address (index $i)"
fi
done
19 changes: 11 additions & 8 deletions spartan/scripts/deploy_kind.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function show_status_until_pxe_ready {
show_status_until_pxe_ready &

function cleanup {
trap - SIGTERM && kill $(jobs -p) &>/dev/null || true
trap - SIGTERM && kill $(jobs -p) &>/dev/null && rm "$mnemonic_file" || true
}
trap cleanup SIGINT SIGTERM EXIT

Expand Down Expand Up @@ -84,7 +84,8 @@ function generate_overrides {
if [ "$sepolia_deployment" = "true" ]; then
echo "Generating sepolia accounts..."
set +x
L1_ACCOUNTS_MNEMONIC=$(./prepare_sepolia_accounts.sh "$values_file" "$mnemonic_file")
./prepare_sepolia_accounts.sh "$values_file" 1 "$mnemonic_file"
L1_ACCOUNTS_MNEMONIC=$(cat "$mnemonic_file")
set -x
else
echo "Generating devnet config..."
Expand All @@ -104,19 +105,21 @@ helm_set_args=(
# If this is a sepolia run, we need to write some values
if [ "$sepolia_deployment" = "true" ]; then
set +x
# Escape commas in the EXTERNAL_ETHEREUM_HOSTS value
ESCAPED_HOSTS=$(echo "$EXTERNAL_ETHEREUM_HOSTS" | sed 's/,/\\,/g')
helm_set_args+=(
--set ethereum.execution.externalHosts="$EXTERNAL_ETHEREUM_HOSTS"
--set ethereum.beacon.externalHost="$EXTERNAL_ETHEREUM_CONSENSUS_HOST"
--set aztec.l1DeploymentMnemonic="$L1_ACCOUNTS_MNEMONIC"
--set ethereum.deployL1ContractsPrivateKey="$L1_DEPLOYMENT_PRIVATE_KEY"
--set "ethereum.execution.externalHosts=$ESCAPED_HOSTS"
--set "ethereum.beacon.externalHost=$EXTERNAL_ETHEREUM_CONSENSUS_HOST"
--set "aztec.l1DeploymentMnemonic=$L1_ACCOUNTS_MNEMONIC"
--set "ethereum.deployL1ContractsPrivateKey=$L1_DEPLOYMENT_PRIVATE_KEY"
)

if [ -n "${EXTERNAL_ETHEREUM_CONSENSUS_HOST_API_KEY:-}" ]; then
helm_set_args+=(--set ethereum.beacon.apiKey="$EXTERNAL_ETHEREUM_CONSENSUS_HOST_API_KEY")
helm_set_args+=(--set "ethereum.beacon.apiKey=$EXTERNAL_ETHEREUM_CONSENSUS_HOST_API_KEY")
fi

if [ -n "${EXTERNAL_ETHEREUM_CONSENSUS_HOST_API_KEY_HEADER:-}" ]; then
helm_set_args+=(--set ethereum.beacon.apiKeyHeader="$EXTERNAL_ETHEREUM_CONSENSUS_HOST_API_KEY_HEADER")
helm_set_args+=(--set "ethereum.beacon.apiKeyHeader=$EXTERNAL_ETHEREUM_CONSENSUS_HOST_API_KEY_HEADER")
fi
set -x
fi
Expand Down
Loading