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

chore(spartan): kind test speedup #12478

Merged
merged 14 commits into from
Mar 6, 2025
24 changes: 20 additions & 4 deletions spartan/aztec-network/files/config/deploy-l1-contracts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ SALT=${1:-$RANDOM}
CHAIN_ID=$2
VALIDATOR_ADDRESSES=$3

# If the chain ID is 11155111 or 1, we are deploying to a public network, make sure that we do not use accelerated test deployments
PUBLIC_CHAIN_ID=false
if [ "$CHAIN_ID" = "11155111" -o "$CHAIN_ID" = "1" ]; then
PUBLIC_CHAIN_ID=true
fi

# Overwrite the value of ACCELERATED_TEST_DEPLOYMENTS env variable if we are deploying to a public network
if [ "$PUBLIC_CHAIN_ID" = "true" ]; then
ACCELERATED_TEST_DEPLOYMENTS=false
fi

# Run the deploy-l1-contracts command and capture the output
output=""
MAX_RETRIES=5
Expand All @@ -26,9 +37,14 @@ if [ "$TEST_ACCOUNTS" = "true" ]; then
TEST_ACCOUNTS_ARG="--test-accounts"
fi

ACCELERATED_TEST_DEPLOYMENTS_ARG=""
if [ "$ACCELERATED_TEST_DEPLOYMENTS" = "true" ]; then
ACCELERATED_TEST_DEPLOYMENTS_ARG="--accelerated-test-deployments"
fi

for attempt in $(seq 1 $MAX_RETRIES); do
# Construct base command
base_cmd="LOG_LEVEL=debug node --no-warnings /usr/src/yarn-project/aztec/dest/bin/index.js deploy-l1-contracts $TEST_ACCOUNTS_ARG"
base_cmd="LOG_LEVEL=debug node --no-warnings /usr/src/yarn-project/aztec/dest/bin/index.js deploy-l1-contracts $TEST_ACCOUNTS_ARG $ACCELERATED_TEST_DEPLOYMENTS_ARG"

# Add account - use private key if set, otherwise use mnemonic
if [ -n "${L1_DEPLOYMENT_PRIVATE_KEY:-}" ]; then
Expand All @@ -39,11 +55,11 @@ for attempt in $(seq 1 $MAX_RETRIES); do

# Add validators if INIT_VALIDATORS is true
if [ "${INIT_VALIDATORS:-false}" = "true" ]; then
output=$(eval $base_cmd --validators $VALIDATOR_ADDRESSES --l1-chain-id $CHAIN_ID --salt $SALT) && break
else
output=$(eval $base_cmd --l1-chain-id $CHAIN_ID --salt $SALT) && break
base_cmd="$base_cmd --validators $VALIDATOR_ADDRESSES"
fi

output=$(eval $base_cmd --l1-chain-id $CHAIN_ID --salt $SALT) && break

echo "Attempt $attempt failed. Retrying in $RETRY_DELAY seconds..."
sleep "$RETRY_DELAY"
done || {
Expand Down
10 changes: 5 additions & 5 deletions spartan/aztec-network/files/config/setup-p2p-addresses.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ else
fi

# Write addresses to file for sourcing
echo "export P2P_TCP_ANNOUNCE_ADDR=${TCP_ADDR}" > /shared/p2p/p2p-addresses
echo "export P2P_TCP_LISTEN_ADDR=0.0.0.0:${P2P_TCP_PORT}" >> /shared/p2p/p2p-addresses
echo "export P2P_UDP_ANNOUNCE_ADDR=${UDP_ADDR}" >> /shared/p2p/p2p-addresses
echo "export P2P_UDP_LISTEN_ADDR=0.0.0.0:${P2P_UDP_PORT}" >> /shared/p2p/p2p-addresses
echo "export P2P_TCP_ANNOUNCE_ADDR=${TCP_ADDR}" > /shared/config/p2p-addresses
echo "export P2P_TCP_LISTEN_ADDR=0.0.0.0:${P2P_TCP_PORT}" >> /shared/config/p2p-addresses
echo "export P2P_UDP_ANNOUNCE_ADDR=${UDP_ADDR}" >> /shared/config/p2p-addresses
echo "export P2P_UDP_LISTEN_ADDR=0.0.0.0:${P2P_UDP_PORT}" >> /shared/config/p2p-addresses

echo "P2P addresses configured:"
cat /shared/p2p/p2p-addresses
cat /shared/config/p2p-addresses
177 changes: 142 additions & 35 deletions spartan/aztec-network/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ http://{{ include "aztec-network.fullname" . }}-pxe.{{ .Release.Namespace }}:{{
{{- end -}}

{{- define "aztec-network.bootNodeUrl" -}}
http://{{ include "aztec-network.fullname" . }}-boot-node-0.{{ include "aztec-network.fullname" . }}-boot-node.{{ .Release.Namespace }}.svc.cluster.local:{{ .Values.bootNode.service.nodePort }}
http://{{ include "aztec-network.fullname" . }}-boot-node.{{ .Release.Namespace }}.svc.cluster.local:{{ .Values.bootNode.service.nodePort }}
{{- end -}}

{{- define "aztec-network.validatorUrl" -}}
Expand Down Expand Up @@ -94,34 +94,6 @@ http://{{ include "aztec-network.fullname" . }}-metrics.{{ .Release.Namespace }}
{{- end -}}
{{- end -}}

{{/*
P2P Setup Container
*/}}
{{- define "aztec-network.p2pSetupContainer" -}}
- name: setup-p2p-addresses
image: bitnami/kubectl
command:
- /bin/sh
- -c
- |
cp /scripts/setup-p2p-addresses.sh /tmp/setup-p2p-addresses.sh && \
chmod +x /tmp/setup-p2p-addresses.sh && \
/tmp/setup-p2p-addresses.sh
env:
- name: NETWORK_PUBLIC
value: "{{ .Values.network.public }}"
- name: NAMESPACE
value: {{ .Release.Namespace }}
- name: P2P_TCP_PORT
value: "{{ .Values.validator.service.p2pTcpPort }}"
- name: P2P_UDP_PORT
value: "{{ .Values.validator.service.p2pUdpPort }}"
volumeMounts:
- name: scripts
mountPath: /scripts
- name: p2p-addresses
mountPath: /shared/p2p
{{- end -}}

{{/*
Service Address Setup Container
Expand All @@ -133,9 +105,7 @@ Service Address Setup Container
- /bin/bash
- -c
- |
cp /scripts/setup-service-addresses.sh /tmp/setup-service-addresses.sh && \
chmod +x /tmp/setup-service-addresses.sh && \
/tmp/setup-service-addresses.sh
/scripts/setup-service-addresses.sh
env:
- name: NETWORK_PUBLIC
value: "{{ .Values.network.public }}"
Expand Down Expand Up @@ -189,9 +159,7 @@ Sets up the OpenTelemetry resource attributes for a service
- /bin/bash
- -c
- |
cp /scripts/setup-otel-resource.sh /tmp/setup-otel-resource.sh && \
chmod +x /tmp/setup-otel-resource.sh && \
/tmp/setup-otel-resource.sh
/scripts/setup-otel-resource.sh
env:
- name: POD_IP
valueFrom:
Expand Down Expand Up @@ -263,3 +231,142 @@ while true; do
sleep 5
done
{{- end -}}

{{/*
Combined wait-for-services and configure-env container for full nodes
*/}}
{{- define "aztec-network.combinedWaitAndConfigureContainer" -}}
- name: wait-and-configure
{{- include "aztec-network.image" . | nindent 2 }}
command:
- /bin/bash
- -c
- |
# If we already have a registry address, and the bootstrap nodes are set, then we don't need to wait for the services
if [ -n "{{ .Values.aztec.contracts.registryAddress }}" ] && [ -n "{{ .Values.aztec.bootstrapENRs }}" ]; then
echo "Registry address and bootstrap nodes already set, skipping wait for services"
echo "{{ include "aztec-network.pxeUrl" . }}" > /shared/pxe/pxe_url
else
source /shared/config/service-addresses
cat /shared/config/service-addresses
{{- include "aztec-network.waitForEthereum" . | nindent 8 }}

if [ "{{ .Values.validator.dynamicBootNode }}" = "true" ]; then
echo "{{ include "aztec-network.pxeUrl" . }}" > /shared/pxe/pxe_url
else
until curl --silent --head --fail "${BOOT_NODE_HOST}/status" > /dev/null; do
echo "Waiting for boot node..."
sleep 5
done
echo "Boot node is ready!"
echo "${BOOT_NODE_HOST}" > /shared/pxe/pxe_url
fi
fi

# Configure environment
source /shared/config/service-addresses
/scripts/configure-full-node-env.sh "$(cat /shared/pxe/pxe_url)"
volumeMounts:
- name: pxe-url
mountPath: /shared/pxe
- name: scripts
mountPath: /scripts
- name: config
mountPath: /shared/config
- name: contracts-env
mountPath: /shared/contracts
env:
- name: P2P_ENABLED
value: "{{ .Values.fullNode.p2p.enabled }}"
- name: BOOTSTRAP_NODES
value: "{{ .Values.aztec.bootstrapENRs }}"
- name: REGISTRY_CONTRACT_ADDRESS
value: "{{ .Values.aztec.contracts.registryAddress }}"
- name: SLASH_FACTORY_CONTRACT_ADDRESS
value: "{{ .Values.aztec.contracts.slashFactoryAddress }}"
{{- end -}}

{{/*
Combined P2P, Service Address, and OpenTelemetry Setup Container
*/}}
{{- define "aztec-network.combinedAllSetupContainer" -}}
{{- $serviceName := base $.Template.Name | trimSuffix ".yaml" -}}
- name: setup-all
{{- include "aztec-network.image" . | nindent 2 }}
command:
- /bin/bash
- -c
- |
# Setup P2P addresses
/scripts/setup-p2p-addresses.sh

# Setup service addresses
/scripts/setup-service-addresses.sh

# Setup OpenTelemetry resource
/scripts/setup-otel-resource.sh
env:
- name: NETWORK_PUBLIC
value: "{{ .Values.network.public }}"
- name: NAMESPACE
value: {{ .Release.Namespace }}
- name: P2P_TCP_PORT
value: "{{ .Values.validator.service.p2pTcpPort }}"
- name: P2P_UDP_PORT
value: "{{ .Values.validator.service.p2pUdpPort }}"
- name: TELEMETRY
value: "{{ .Values.telemetry.enabled }}"
- name: OTEL_COLLECTOR_ENDPOINT
value: "{{ .Values.telemetry.otelCollectorEndpoint }}"
- name: EXTERNAL_ETHEREUM_HOSTS
value: "{{ .Values.ethereum.execution.externalHosts }}"
- name: ETHEREUM_PORT
value: "{{ .Values.ethereum.execution.service.port }}"
- name: EXTERNAL_ETHEREUM_CONSENSUS_HOST
value: "{{ .Values.ethereum.beacon.externalHost }}"
- name: EXTERNAL_ETHEREUM_CONSENSUS_HOST_API_KEY
value: "{{ .Values.ethereum.beacon.apiKey }}"
- name: EXTERNAL_ETHEREUM_CONSENSUS_HOST_API_KEY_HEADER
value: "{{ .Values.ethereum.beacon.apiKeyHeader }}"
- name: ETHEREUM_CONSENSUS_PORT
value: "{{ .Values.ethereum.beacon.service.port }}"
- name: EXTERNAL_BOOT_NODE_HOST
value: "{{ .Values.bootNode.externalHost }}"
- name: BOOT_NODE_PORT
value: "{{ .Values.bootNode.service.nodePort }}"
- name: EXTERNAL_PROVER_NODE_HOST
value: "{{ .Values.proverNode.externalHost }}"
- name: PROVER_NODE_PORT
value: "{{ .Values.proverNode.service.nodePort }}"
- name: PROVER_BROKER_PORT
value: "{{ .Values.proverBroker.service.nodePort }}"
- name: USE_GCLOUD_LOGGING
value: "{{ .Values.telemetry.useGcloudLogging }}"
- name: SERVICE_NAME
value: {{ include "aztec-network.fullname" . }}
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
- name: K8S_POD_UID
valueFrom:
fieldRef:
fieldPath: metadata.uid
- name: K8S_POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: K8S_NAMESPACE_NAME
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: OTEL_SERVICE_NAME
value: "{{ $serviceName }}"
- name: OTEL_RESOURCE_ATTRIBUTES
value: 'service.namespace={{ .Release.Namespace }},environment={{ .Values.environment | default "production" }}'
volumeMounts:
- name: scripts
mountPath: /scripts
- name: config
mountPath: /shared/config
{{- end -}}
33 changes: 8 additions & 25 deletions spartan/aztec-network/templates/boot-node.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@ spec:
serviceAccountName: {{ include "aztec-network.fullname" . }}-node
{{- include "aztec-network.publicAntiAffinity" . | nindent 6 }}
{{- end }}
terminationGracePeriodSeconds: 5 # default is 30 - speed up initcontainer termination
initContainers:
{{- include "aztec-network.p2pSetupContainer" . | nindent 8 }}
{{- include "aztec-network.serviceAddressSetupContainer" . | nindent 8 }}
{{- include "aztec-network.otelResourceSetupContainer" . | nindent 8 }}
{{- include "aztec-network.combinedAllSetupContainer" . | nindent 8 }}

# Generate the validator addresses; used in the deploy-l1-contracts step
- name: generate-validator-addresses
Expand All @@ -66,32 +65,18 @@ spec:
- name: NUMBER_OF_VALIDATORS
value: {{ .Values.validator.replicas | quote }}

- name: wait-for-ethereum
{{- include "aztec-network.image" . | nindent 10 }}
command:
- /bin/bash
- -c
- |
source /shared/config/service-addresses
cat /shared/config/service-addresses
{{- include "aztec-network.waitForEthereum" . | nindent 14 }}
volumeMounts:
- name: config
mountPath: /shared/config
- name: deploy-l1-contracts
{{- include "aztec-network.image" . | nindent 10 }}
command:
- /bin/bash
- -c
- |
cp /scripts/deploy-l1-contracts.sh /tmp/deploy-l1-contracts.sh
chmod +x /tmp/deploy-l1-contracts.sh
source /shared/config/service-addresses
source /shared/config/validator-addresses
{{- include "aztec-network.waitForEthereum" . | nindent 14 }}


/tmp/deploy-l1-contracts.sh "{{ .Values.aztec.l1Salt }}" "{{ .Values.ethereum.chainId }}" "$VALIDATOR_ADDRESSES"
/scripts/deploy-l1-contracts.sh "{{ .Values.aztec.l1Salt }}" "{{ .Values.ethereum.chainId }}" "$VALIDATOR_ADDRESSES"
volumeMounts:
- name: scripts-output
mountPath: /shared/contracts
Expand All @@ -100,6 +85,8 @@ spec:
- name: scripts
mountPath: /scripts
env:
- name: ACCELERATED_TEST_DEPLOYMENTS
value: "{{ .Values.ethereum.acceleratedTestDeployments }}"
- name: TEST_ACCOUNTS
value: "{{ .Values.aztec.testAccounts }}"
- name: REGISTRY_CONTRACT_ADDRESS
Expand Down Expand Up @@ -145,9 +132,8 @@ spec:
- /bin/bash
- -c
- |
sleep 30 && \
source /shared/contracts/contracts.env && \
source /shared/p2p/p2p-addresses && \
source /shared/config/p2p-addresses && \
source /shared/config/service-addresses && \
source /shared/config/otel-resource && \
env && \
Expand All @@ -167,8 +153,6 @@ spec:
timeoutSeconds: 30
failureThreshold: 3
volumeMounts:
- name: p2p-addresses
mountPath: /shared/p2p
- name: config
mountPath: /shared/config
- name: boot-node-data
Expand Down Expand Up @@ -256,8 +240,6 @@ spec:
resources:
{{- toYaml .Values.bootNode.resources | nindent 12 }}
volumes:
- name: p2p-addresses
emptyDir: {}
- name: config
emptyDir: {}
{{- if .Values.storage.localSsd }}
Expand All @@ -271,6 +253,7 @@ spec:
- name: scripts
configMap:
name: {{ include "aztec-network.fullname" . }}-scripts
defaultMode: 0755
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦 Thank you

- name: scripts-output
emptyDir: {}
---
Expand Down Expand Up @@ -300,7 +283,7 @@ spec:
# External load balancers cannot handle mixed TCP/UDP ports, so we only expose the node port
{{- if not .Values.network.public }}
- port: {{ .Values.bootNode.service.p2pTcpPort }}
name: p2p-tpc
name: p2p-tcp
- port: {{ .Values.bootNode.service.p2pUdpPort }}
name: p2p-udp
protocol: UDP
Expand Down
5 changes: 2 additions & 3 deletions spartan/aztec-network/templates/consolidate-balances.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ spec:
- name: scripts
configMap:
name: {{ include "aztec-network.fullname" . }}-scripts
defaultMode: 0755
containers:
- name: consolidate-balances
{{- include "aztec-network.image" . | nindent 10 }}
Expand All @@ -38,9 +39,7 @@ spec:
- /bin/bash
- -c
- |
cp /scripts/consolidate-sepolia-balances.sh /tmp/consolidate-sepolia-balances.sh
chmod +x /tmp/consolidate-sepolia-balances.sh
/tmp/consolidate-sepolia-balances.sh "{{ .Values.aztec.l1DeploymentMnemonic }}" {{ add .Values.validator.replicas .Values.proverNode.replicas }}
/scripts/consolidate-sepolia-balances.sh "{{ .Values.aztec.l1DeploymentMnemonic }}" {{ add .Values.validator.replicas .Values.proverNode.replicas }}
env:
- name: ETHEREUM_HOSTS
value: "{{ .Values.ethereum.execution.externalHosts }}"
Expand Down
Loading