Skip to content

Commit

Permalink
chore: pre-initialise validators in cluster (#9048)
Browse files Browse the repository at this point in the history
  • Loading branch information
Maddiaa0 authored Oct 8, 2024
1 parent 1798b1c commit e2d32a1
Show file tree
Hide file tree
Showing 12 changed files with 120 additions and 20 deletions.
13 changes: 4 additions & 9 deletions spartan/aztec-network/files/config/config-validator-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,11 @@ outbox_address=$(echo "$output" | grep -oP 'L2 -> L1 Outbox Address: \K0x[a-fA-F
fee_juice_address=$(echo "$output" | grep -oP 'Fee Juice Address: \K0x[a-fA-F0-9]{40}')
fee_juice_portal_address=$(echo "$output" | grep -oP 'Fee Juice Portal Address: \K0x[a-fA-F0-9]{40}')

# Generate a private key for the validator
json_account=$(aztec generate-l1-account)
# We assume that there is an env var set for validator keys from the config map
# We get the index in the config map from the pod name, which will have the validator index within it

echo "$json_account"
address=$(echo $json_account | jq -r '.address')
private_key=$(echo $json_account | jq -r '.privateKey')

aztec add-l1-validator --validator $address --rollup $rollup_address

aztec fast-forward-epochs --rollup $rollup_address --count 1
INDEX=$(echo $POD_NAME | awk -F'-' '{print $NF}')
private_key=$(jq -r ".[$INDEX]" /app/config/keys.json)


# Write the addresses to a file in the shared volume
Expand Down
4 changes: 2 additions & 2 deletions spartan/aztec-network/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ http://metrics-opentelemetry-collector.metrics:4318/v1/traces
{{- if $value -}}
{{- if kindIs "string" $value -}}
{{- if ne $value "" -}}
--{{ $name }} {{ $value }}
--{{ $name }} {{ $value }}{{ " " }}
{{- end -}}
{{- else -}}
--{{ $name }} {{ $value }}
--{{ $name }} {{ $value }}{{ " " }}
{{- end -}}
{{- end -}}
{{- end -}}
14 changes: 7 additions & 7 deletions spartan/aztec-network/templates/anvil.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ spec:
command: ["/bin/sh", "-c"]
args:
- >-
anvil
--host 0.0.0.0
{{ include "helpers.flag" (list "block-time" .Values.ethereum.blockTime) }}
{{ include "helpers.flag" (list "chain-id" .Values.ethereum.chainId) }}
{{ include "helpers.flag" (list "gas-limit" .Values.ethereum.gasLimit) }}
{{ include "helpers.flag" (list "fork-url" .Values.ethereum.forkUrl) }}
{{ include "helpers.flag" (list "fork-block-number" .Values.ethereum.forkBlockNumber) }}
anvil {{ include "helpers.flag" (list "host" "0.0.0.0") }}
{{- include "helpers.flag" (list "block-time" .Values.ethereum.blockTime) }}
{{- include "helpers.flag" (list "chain-id" .Values.ethereum.chainId) }}
{{- include "helpers.flag" (list "gas-limit" .Values.ethereum.gasLimit) }}
{{- include "helpers.flag" (list "fork-url" .Values.ethereum.forkUrl) }}
{{- include "helpers.flag" (list "fork-block-number" .Values.ethereum.forkBlockNumber) }}
{{- include "helpers.flag" (list "accounts" .Values.validator.replicas) }}
-p {{ .Values.ethereum.service.port }}
ports:
- containerPort: {{ .Values.ethereum.service.port }}
Expand Down
10 changes: 10 additions & 0 deletions spartan/aztec-network/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Config map that stores the validator keys for this cluster
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "aztec-network.fullname" . }}-validator-keys
labels:
{{- include "aztec-network.labels" . | nindent 4 }}
data:
keys.json: |
{{ .Values.validator.validatorKeys | toJson | nindent 4 }}
2 changes: 1 addition & 1 deletion spartan/aztec-network/templates/l2-contracts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ data:
set -e
# Run the deploy-l1-contracts command and capture the output
output=$(node --no-warnings /usr/src/yarn-project/aztec/dest/bin/index.js deploy-l1-contracts)
output=$(node --no-warnings /usr/src/yarn-project/aztec/dest/bin/index.js deploy-l1-contracts --validators {{ join "," .Values.validator.validatorAddresses | quote }})
echo "$output"
Expand Down
12 changes: 12 additions & 0 deletions spartan/aztec-network/templates/validator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ spec:
{{- include "aztec-network.selectorLabels" . | nindent 8 }}
app: validator
spec:
# We expect the validators to have already been added to the smart contract by this point - but this container still needs
# to be run in order to get the values
initContainers:
- name: configure-validator-env
image: "{{ .Values.images.aztec.image }}"
Expand All @@ -30,9 +32,16 @@ spec:
mountPath: /shared
- name: scripts
mountPath: /scripts
- name: validator-keys
mountPath: /app/config
readOnly: true
env:
- name: ETHEREUM_HOST
value: {{ include "aztec-network.ethereumHost" . | quote }}
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
containers:
- name: validator
image: "{{ .Values.images.aztec.image }}"
Expand Down Expand Up @@ -94,6 +103,9 @@ spec:
- name: scripts
configMap:
name: {{ include "aztec-network.fullname" . }}-configure-validator-env
- name: validator-keys
configMap:
name: {{ include "aztec-network.fullname" . }}-validator-keys
volumeClaimTemplates:
- metadata:
name: shared-volume
Expand Down
13 changes: 13 additions & 0 deletions spartan/aztec-network/values/1-validators.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
validator:
debug: "aztec:*,-aztec:avm_simulator:*,-aztec:libp2p_service"
replicas: 1
validatorKeys:
- 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
validatorAddresses:
- 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
validator:
disabled: false

bootNode:
validator:
disabled: true
43 changes: 43 additions & 0 deletions spartan/aztec-network/values/16-validators.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,55 @@
bootNode:
sequencer:
minTxsPerBlock: 4

validator:
debug: "aztec:*,-aztec:avm_simulator:*,-aztec:libp2p_service"
replicas: 16
sequencer:
minTxsPerBlock: 4
validatorKeys:
- 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
- 0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d
- 0x5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a
- 0x7c852118294e51e653712a81e05800f419141751be58f605c371e15141b007a6
- 0x47e179ec197488593b187f80a00eb0da91f1b9d0b13f8733639f19c30a34926a
- 0x8b3a350cf5c34c9194ca85829a2df0ec3153be0318b5e2d3348e872092edffba
- 0x92db14e403b83dfe3df233f83dfa3a0d7096f21ca9b0d6d6b8d88b2b4ec1564e
- 0x4bbbf85ce3377467afe5d46f804f221813b2bb87f24d81f60f1fcdbf7cbf4356
- 0xdbda1821b80551c9d65939329250298aa3472ba22feea921c0cf5d620ea67b97
- 0x2a871d0798f97d79848a013d4936a73bf4cc922c825d33c1cf7073dff6d409c6
- 0xf214f2b2cd398c806f84e317254e0f0b801d0643303237d97a22a48e01628897
- 0x701b615bbdfb9de65240bc28bd21bbc0d996645a3dd57e7b12bc2bdf6f192c82
- 0xa267530f49f8280200edf313ee7af6b827f2a8bce2897751d06a843f644967b1
- 0x47c99abed3324a2707c28affff1267e45918ec8c3f20b8aa892e8b065d2942dd
- 0xc526ee95bf44d8fc405a158bb884d9d1238d99f0612e9f33d006bb0789009aaa
- 0x8166f546bab6da521a8369cab06c5d2b9e46670292d85c875ee9ec20e84ffb61
validatorAddresses:
- 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
- 0x70997970C51812dc3A010C7d01b50e0d17dc79C8
- 0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC
- 0x90F79bf6EB2c4f870365E785982E1f101E93b906
- 0x15d34AAf54267DB7D7c367839AAf71A00a2C6A65
- 0x9965507D1a55bcC2695C58ba16FB37d819B0A4dc
- 0x976EA74026E726554dB657fA54763abd0C3a0aa9
- 0x14dC79964da2C08b23698B3D3cc7Ca32193d9955
- 0x23618e81E3f5cdF7f54C3d65f7FBc0aBf5B21E8f
- 0xa0Ee7A142d267C1f36714E4a8F75612F20a79720
- 0xBcd4042DE499D14e55001CcbB24a551F3b954096
- 0x71bE63f3384f5fb98995898A86B02Fb2426c5788
- 0xFABB0ac9d68B0B445fB7357272Ff202C5651694a
- 0x1CBd3b2770909D4e10f157cABC84C7264073C9Ec
- 0xdF3e18d64BC6A983f673Ab319CCaE4f1a57C7097
- 0xcd3B766CCDd6AE721141F452C550Ca635964ce71
resources:
requests:
memory: "512Mi"
validator:
disabled: false

bot:
txIntervalSeconds: 2

bootNode:
validator:
disabled: true
9 changes: 9 additions & 0 deletions spartan/aztec-network/values/3-validators.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
validator:
debug: "aztec:*,-aztec:avm_simulator:*,-aztec:libp2p_service"
replicas: 3
validatorKeys:
- 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
- 0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d
- 0x5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a
validatorAddresses:
- 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
- 0x70997970C51812dc3A010C7d01b50e0d17dc79C8
- 0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC
validator:
disabled: false


bootNode:
validator:
disabled: true
12 changes: 11 additions & 1 deletion yarn-project/cli/src/cmds/l1/deploy_l1_contracts.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { type EthAddress } from '@aztec/foundation/eth-address';
import { type DebugLogger, type LogFn } from '@aztec/foundation/log';

import { deployAztecContracts } from '../../utils/aztec.js';
Expand All @@ -9,10 +10,19 @@ export async function deployL1Contracts(
mnemonic: string,
salt: number | undefined,
json: boolean,
initialValidators: EthAddress[],
log: LogFn,
debugLogger: DebugLogger,
) {
const { l1ContractAddresses } = await deployAztecContracts(rpcUrl, chainId, privateKey, mnemonic, salt, debugLogger);
const { l1ContractAddresses } = await deployAztecContracts(
rpcUrl,
chainId,
privateKey,
mnemonic,
salt,
initialValidators,
debugLogger,
);

if (json) {
log(
Expand Down
6 changes: 6 additions & 0 deletions yarn-project/cli/src/cmds/l1/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { EthAddress } from '@aztec/foundation/eth-address';
import { type DebugLogger, type LogFn } from '@aztec/foundation/log';

import { type Command } from 'commander';
Expand All @@ -24,6 +25,7 @@ export function injectCommands(program: Command, log: LogFn, debugLogger: DebugL
ETHEREUM_HOST,
)
.option('-pk, --private-key <string>', 'The private key to use for deployment', PRIVATE_KEY)
.option('--validators <string>', 'Comma separated list of validators')
.option(
'-m, --mnemonic <string>',
'The mnemonic to use in deployment',
Expand All @@ -34,13 +36,17 @@ export function injectCommands(program: Command, log: LogFn, debugLogger: DebugL
.option('--json', 'Output the contract addresses in JSON format')
.action(async options => {
const { deployL1Contracts } = await import('./deploy_l1_contracts.js');

const initialValidators =
options.validators?.split(',').map((validator: string) => EthAddress.fromString(validator)) || [];
await deployL1Contracts(
options.rpcUrl,
options.l1ChainId,
options.privateKey,
options.mnemonic,
options.salt,
options.json,
initialValidators,
log,
debugLogger,
);
Expand Down
2 changes: 2 additions & 0 deletions yarn-project/cli/src/utils/aztec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export async function deployAztecContracts(
privateKey: string | undefined,
mnemonic: string,
salt: number | undefined,
initialValidators: EthAddress[],
debugLogger: DebugLogger,
): Promise<DeployL1Contracts> {
const {
Expand Down Expand Up @@ -113,6 +114,7 @@ export async function deployAztecContracts(
l2FeeJuiceAddress: FeeJuiceAddress,
vkTreeRoot: getVKTreeRoot(),
salt,
initialValidators,
});
}

Expand Down

0 comments on commit e2d32a1

Please sign in to comment.