From 0db5236e31d64439f039eb5c95d1c5f01c95908d Mon Sep 17 00:00:00 2001 From: Mitch Date: Fri, 30 Aug 2024 20:13:51 -0400 Subject: [PATCH 1/9] add validators to set --- .../configure-validator-env.config-map.yaml | 10 ++++ yarn-project/Earthfile | 2 +- yarn-project/cli/src/cmds/l1/index.ts | 44 ++++++++++++++++ .../cli/src/cmds/l1/update_l1_validators.ts | 50 +++++++++++++++++++ yarn-project/ethereum/src/index.ts | 2 +- 5 files changed, 106 insertions(+), 2 deletions(-) create mode 100644 yarn-project/cli/src/cmds/l1/update_l1_validators.ts diff --git a/helm-charts/aztec-network/templates/configure-validator-env.config-map.yaml b/helm-charts/aztec-network/templates/configure-validator-env.config-map.yaml index 47ddeba836c..8a629a3e690 100644 --- a/helm-charts/aztec-network/templates/configure-validator-env.config-map.yaml +++ b/helm-charts/aztec-network/templates/configure-validator-env.config-map.yaml @@ -23,6 +23,15 @@ data: 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=$(node --no-warnings /usr/src/yarn-project/aztec/dest/bin/index.js generate-l1-account) + + echo "$json_account" + address=$(echo $json_account | jq -r '.address') + private_key=$(echo $json_account | jq -r '.privateKey') + + node --no-warnings /usr/src/yarn-project/aztec/dest/bin/index.js add-l1-validator --validator $address --rollup $rollup_address + # Write the addresses to a file in the shared volume cat < /shared/contracts.env export BOOTSTRAP_NODES=$boot_node_enr @@ -33,6 +42,7 @@ data: export AVAILABILITY_ORACLE_CONTRACT_ADDRESS=$availability_oracle_address export FEE_JUICE_CONTRACT_ADDRESS=$fee_juice_address export FEE_JUICE_PORTAL_CONTRACT_ADDRESS=$fee_juice_portal_address + export VALIDATOR_PRIVATE_KEY=$private_key EOF cat /shared/contracts.env \ No newline at end of file diff --git a/yarn-project/Earthfile b/yarn-project/Earthfile index a9b151cd7ec..0098093957e 100644 --- a/yarn-project/Earthfile +++ b/yarn-project/Earthfile @@ -150,7 +150,7 @@ aztec-prod: aztec: FROM ubuntu:noble - RUN apt update && apt install nodejs curl -y && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* + RUN apt update && apt install nodejs curl jq -y && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* COPY +aztec-prod/usr/src /usr/src ENV BB_WORKING_DIRECTORY=/usr/src/bb ENV BB_BINARY_PATH=/usr/src/barretenberg/cpp/build/bin/bb diff --git a/yarn-project/cli/src/cmds/l1/index.ts b/yarn-project/cli/src/cmds/l1/index.ts index f3ca73f3683..b9faae2a9ec 100644 --- a/yarn-project/cli/src/cmds/l1/index.ts +++ b/yarn-project/cli/src/cmds/l1/index.ts @@ -46,6 +46,50 @@ export function injectCommands(program: Command, log: LogFn, debugLogger: DebugL ); }); + program + .command('generate-l1-account') + .description('Generates a new private key for an account on L1.') + .option('--json', 'Output the private key in JSON format') + .action(async () => { + const { generateL1Account } = await import('./update_l1_validators.js'); + const account = generateL1Account(); + log(JSON.stringify(account, null, 2)); + }); + + program + .command('add-l1-validator') + .description('Adds a validator to the L1 rollup contract.') + .requiredOption( + '-u, --rpc-url ', + 'Url of the ethereum host. Chain identifiers localhost and testnet can be used', + ETHEREUM_HOST, + ) + .option('-pk, --private-key ', 'The private key to use for deployment', PRIVATE_KEY) + .option( + '-m, --mnemonic ', + 'The mnemonic to use in deployment', + 'test test test test test test test test test test test junk', + ) + .addOption(l1ChainIdOption) + .option('--validator ', 'ethereum address of the validator', parseEthereumAddress) + .option('--rollup
', 'ethereum address of the rollup contract', parseEthereumAddress) + .action(async options => { + const { addL1Validator } = await import('./update_l1_validators.js'); + await addL1Validator( + options.rpcUrl, + options.l1ChainId, + options.privateKey, + options.mnemonic, + options.validator, + options.rollup, + + log, + debugLogger, + ); + }); + + // TODO fastforward epoch + program .command('deploy-l1-verifier') .description('Deploys the rollup verifier contract') diff --git a/yarn-project/cli/src/cmds/l1/update_l1_validators.ts b/yarn-project/cli/src/cmds/l1/update_l1_validators.ts new file mode 100644 index 00000000000..3ff8fe88f1f --- /dev/null +++ b/yarn-project/cli/src/cmds/l1/update_l1_validators.ts @@ -0,0 +1,50 @@ +import { type EthAddress } from '@aztec/circuits.js'; +import { createEthereumChain } from '@aztec/ethereum'; +import { type DebugLogger, type LogFn } from '@aztec/foundation/log'; +import { RollupAbi } from '@aztec/l1-artifacts'; + +import { createPublicClient, createWalletClient, getContract, http } from 'viem'; +import { generatePrivateKey, mnemonicToAccount, privateKeyToAccount } from 'viem/accounts'; + +export function generateL1Account() { + const privateKey = generatePrivateKey(); + const account = privateKeyToAccount(privateKey); + account.address; + return { + privateKey, + address: account.address, + }; +} + +export async function addL1Validator( + rpcUrl: string, + chainId: number, + // the private key of the rollup owner + privateKey: string | undefined, + // the mnemonic of the rollup owner + mnemonic: string, + validatorAddress: EthAddress, + rollupAddress: EthAddress, + log: LogFn, + debugLogger: DebugLogger, +) { + const chain = createEthereumChain(rpcUrl, chainId); + const account = !privateKey + ? mnemonicToAccount(mnemonic!) + : privateKeyToAccount(`${privateKey.startsWith('0x') ? '' : '0x'}${privateKey}` as `0x${string}`); + const walletClient = createWalletClient({ account, chain: chain.chainInfo, transport: http(rpcUrl) }); + const publicClient = createPublicClient({ chain: chain.chainInfo, transport: http(rpcUrl) }); + const rollup = getContract({ + address: rollupAddress.toString(), + abi: RollupAbi, + client: walletClient, + }); + let msg = `Adding validator ${validatorAddress.toString()} to rollup ${rollupAddress.toString()}`; + log(msg); + debugLogger.info(msg); + const txHash = await rollup.write.addValidator([validatorAddress.toString()]); + msg = `Transaction hash: ${txHash}`; + log(msg); + debugLogger.info(msg); + await publicClient.waitForTransactionReceipt({ hash: txHash }); +} diff --git a/yarn-project/ethereum/src/index.ts b/yarn-project/ethereum/src/index.ts index 4474be5894e..c136dcdb263 100644 --- a/yarn-project/ethereum/src/index.ts +++ b/yarn-project/ethereum/src/index.ts @@ -2,9 +2,9 @@ import { foundry } from 'viem/chains'; import { type EthereumChain } from './ethereum_chain.js'; +export * from './constants.js'; export * from './deploy_l1_contracts.js'; export * from './l1_contract_addresses.js'; -export * from './constants.js'; export * from './l1_reader.js'; /** From b7b653b1832569b1a0ce794e8cabde5c31435bbc Mon Sep 17 00:00:00 2001 From: Mitch Date: Sat, 31 Aug 2024 11:59:59 -0400 Subject: [PATCH 2/9] cli to fast forward epoch --- .../configure-validator-env.config-map.yaml | 12 ++- yarn-project/cli/src/cmds/l1/index.ts | 48 +++++++-- .../cli/src/cmds/l1/update_l1_validators.ts | 101 +++++++++++++----- 3 files changed, 124 insertions(+), 37 deletions(-) diff --git a/helm-charts/aztec-network/templates/configure-validator-env.config-map.yaml b/helm-charts/aztec-network/templates/configure-validator-env.config-map.yaml index 8a629a3e690..cd33696b7b0 100644 --- a/helm-charts/aztec-network/templates/configure-validator-env.config-map.yaml +++ b/helm-charts/aztec-network/templates/configure-validator-env.config-map.yaml @@ -9,8 +9,10 @@ data: #!/bin/sh set -e + alias aztec='node --no-warnings /usr/src/yarn-project/aztec/dest/bin/index.js' + # Ask the bootnode for l1 contract addresses - output=$(node --no-warnings /usr/src/yarn-project/aztec/dest/bin/index.js get-node-info -u {{ include "aztec-network.bootNodeUrl" . }}) + output=$(aztec get-node-info -u {{ include "aztec-network.bootNodeUrl" . }}) echo "$output" @@ -24,13 +26,17 @@ data: 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=$(node --no-warnings /usr/src/yarn-project/aztec/dest/bin/index.js generate-l1-account) + json_account=$(aztec generate-l1-account) echo "$json_account" address=$(echo $json_account | jq -r '.address') private_key=$(echo $json_account | jq -r '.privateKey') - node --no-warnings /usr/src/yarn-project/aztec/dest/bin/index.js add-l1-validator --validator $address --rollup $rollup_address + aztec add-l1-validator --validator $address --rollup $rollup_address + + aztec fast-forward-epochs --rollup $rollup_address --count 1 + + # Write the addresses to a file in the shared volume cat < /shared/contracts.env diff --git a/yarn-project/cli/src/cmds/l1/index.ts b/yarn-project/cli/src/cmds/l1/index.ts index b9faae2a9ec..fc6576169b6 100644 --- a/yarn-project/cli/src/cmds/l1/index.ts +++ b/yarn-project/cli/src/cmds/l1/index.ts @@ -75,20 +75,48 @@ export function injectCommands(program: Command, log: LogFn, debugLogger: DebugL .option('--rollup
', 'ethereum address of the rollup contract', parseEthereumAddress) .action(async options => { const { addL1Validator } = await import('./update_l1_validators.js'); - await addL1Validator( - options.rpcUrl, - options.l1ChainId, - options.privateKey, - options.mnemonic, - options.validator, - options.rollup, - + await addL1Validator({ + rpcUrl: options.rpcUrl, + chainId: options.l1ChainId, + privateKey: options.privateKey, + mnemonic: options.mnemonic, + validatorAddress: options.validator, + rollupAddress: options.rollup, log, debugLogger, - ); + }); }); - // TODO fastforward epoch + program + .command('fast-forward-epochs') + .description('Fast forwards the epoch of the L1 rollup contract.') + .requiredOption( + '-u, --rpc-url ', + 'Url of the ethereum host. Chain identifiers localhost and testnet can be used', + ETHEREUM_HOST, + ) + .option('-pk, --private-key ', 'The private key to use for deployment', PRIVATE_KEY) + .option( + '-m, --mnemonic ', + 'The mnemonic to use in deployment', + 'test test test test test test test test test test test junk', + ) + .addOption(l1ChainIdOption) + .option('--rollup
', 'ethereum address of the rollup contract', parseEthereumAddress) + .option('--count ', 'The number of epochs to fast forward', arg => BigInt(parseInt(arg)), 1n) + .action(async options => { + const { fastForwardEpochs } = await import('./update_l1_validators.js'); + await fastForwardEpochs({ + rpcUrl: options.rpcUrl, + chainId: options.l1ChainId, + privateKey: options.privateKey, + mnemonic: options.mnemonic, + rollupAddress: options.rollup, + numEpochs: options.count, + log, + debugLogger, + }); + }); program .command('deploy-l1-verifier') diff --git a/yarn-project/cli/src/cmds/l1/update_l1_validators.ts b/yarn-project/cli/src/cmds/l1/update_l1_validators.ts index 3ff8fe88f1f..eb3be061b96 100644 --- a/yarn-project/cli/src/cmds/l1/update_l1_validators.ts +++ b/yarn-project/cli/src/cmds/l1/update_l1_validators.ts @@ -1,3 +1,4 @@ +import { EthCheatCodes } from '@aztec/aztec.js'; import { type EthAddress } from '@aztec/circuits.js'; import { createEthereumChain } from '@aztec/ethereum'; import { type DebugLogger, type LogFn } from '@aztec/foundation/log'; @@ -6,6 +7,19 @@ import { RollupAbi } from '@aztec/l1-artifacts'; import { createPublicClient, createWalletClient, getContract, http } from 'viem'; import { generatePrivateKey, mnemonicToAccount, privateKeyToAccount } from 'viem/accounts'; +export interface RollupCommandArgs { + rpcUrl: string; + chainId: number; + privateKey: string | undefined; + mnemonic: string; + rollupAddress: EthAddress; +} + +export interface LoggerArgs { + log: LogFn; + debugLogger: DebugLogger; +} + export function generateL1Account() { const privateKey = generatePrivateKey(); const account = privateKeyToAccount(privateKey); @@ -16,35 +30,74 @@ export function generateL1Account() { }; } -export async function addL1Validator( - rpcUrl: string, - chainId: number, - // the private key of the rollup owner - privateKey: string | undefined, - // the mnemonic of the rollup owner - mnemonic: string, - validatorAddress: EthAddress, - rollupAddress: EthAddress, - log: LogFn, - debugLogger: DebugLogger, -) { - const chain = createEthereumChain(rpcUrl, chainId); - const account = !privateKey - ? mnemonicToAccount(mnemonic!) - : privateKeyToAccount(`${privateKey.startsWith('0x') ? '' : '0x'}${privateKey}` as `0x${string}`); - const walletClient = createWalletClient({ account, chain: chain.chainInfo, transport: http(rpcUrl) }); - const publicClient = createPublicClient({ chain: chain.chainInfo, transport: http(rpcUrl) }); +export async function addL1Validator({ + rpcUrl, + chainId, + privateKey, + mnemonic, + validatorAddress, + rollupAddress, + log, + debugLogger, +}: RollupCommandArgs & LoggerArgs & { validatorAddress: EthAddress }) { + const dualLog = makeDualLog(log, debugLogger); + const { walletClient, publicClient } = getL1Clients(rpcUrl, chainId, privateKey, mnemonic); const rollup = getContract({ address: rollupAddress.toString(), abi: RollupAbi, client: walletClient, }); - let msg = `Adding validator ${validatorAddress.toString()} to rollup ${rollupAddress.toString()}`; - log(msg); - debugLogger.info(msg); + + dualLog(`Adding validator ${validatorAddress.toString()} to rollup ${rollupAddress.toString()}`); const txHash = await rollup.write.addValidator([validatorAddress.toString()]); - msg = `Transaction hash: ${txHash}`; - log(msg); - debugLogger.info(msg); + dualLog(`Transaction hash: ${txHash}`); await publicClient.waitForTransactionReceipt({ hash: txHash }); } + +export async function fastForwardEpochs({ + rpcUrl, + chainId, + privateKey, + mnemonic, + rollupAddress, + numEpochs, + log, + debugLogger, +}: RollupCommandArgs & LoggerArgs & { numEpochs: bigint }) { + const dualLog = makeDualLog(log, debugLogger); + const { walletClient } = getL1Clients(rpcUrl, chainId, privateKey, mnemonic); + const rollup = getContract({ + address: rollupAddress.toString(), + abi: RollupAbi, + client: walletClient, + }); + + const cheatCodes = new EthCheatCodes(rpcUrl, debugLogger); + const genesisTs = await rollup.read.GENESIS_TIME(); + const slotsInEpoch = await rollup.read.EPOCH_DURATION(); + const slotDuration = await rollup.read.SLOT_DURATION(); + const epochDuration = slotsInEpoch * slotDuration; + const warpTime = genesisTs + numEpochs * epochDuration; + await cheatCodes.warp(Number(warpTime)); + dualLog(`Fast forwarded ${numEpochs} epochs to ${warpTime}`); +} + +function makeDualLog(log: LogFn, debugLogger: DebugLogger) { + return (msg: string) => { + log(msg); + debugLogger.info(msg); + }; +} + +function getL1Clients(rpcUrl: string, chainId: number, privateKey: string | undefined, mnemonic: string) { + const chain = createEthereumChain(rpcUrl, chainId); + const account = !privateKey + ? mnemonicToAccount(mnemonic!) + : privateKeyToAccount(`${privateKey.startsWith('0x') ? '' : '0x'}${privateKey}` as `0x${string}`); + const walletClient = createWalletClient({ account, chain: chain.chainInfo, transport: http(rpcUrl) }); + const publicClient = createPublicClient({ chain: chain.chainInfo, transport: http(rpcUrl) }); + return { + walletClient, + publicClient, + }; +} From a18527f9081c82443c81bcae4dcf421e16b28f8c Mon Sep 17 00:00:00 2001 From: Mitch Date: Sat, 31 Aug 2024 13:45:55 -0400 Subject: [PATCH 3/9] fix: timestamp times 1000 --- yarn-project/cli/src/cmds/l1/update_l1_validators.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yarn-project/cli/src/cmds/l1/update_l1_validators.ts b/yarn-project/cli/src/cmds/l1/update_l1_validators.ts index eb3be061b96..2c04b163526 100644 --- a/yarn-project/cli/src/cmds/l1/update_l1_validators.ts +++ b/yarn-project/cli/src/cmds/l1/update_l1_validators.ts @@ -77,7 +77,7 @@ export async function fastForwardEpochs({ const slotsInEpoch = await rollup.read.EPOCH_DURATION(); const slotDuration = await rollup.read.SLOT_DURATION(); const epochDuration = slotsInEpoch * slotDuration; - const warpTime = genesisTs + numEpochs * epochDuration; + const warpTime = genesisTs + numEpochs * epochDuration * 1000n; await cheatCodes.warp(Number(warpTime)); dualLog(`Fast forwarded ${numEpochs} epochs to ${warpTime}`); } From a31fdbb38b36aa924a5105e362f8c1eeca9cc655 Mon Sep 17 00:00:00 2001 From: Mitch Date: Sat, 31 Aug 2024 16:04:46 -0400 Subject: [PATCH 4/9] fix validator/prover setup --- .../files/config/config-prover-env.sh | 34 ++++++++++++ .../files/config/config-validator-env.sh | 46 ++++++++++++++++ .../configure-validator-env.config-map.yaml | 54 ------------------- .../templates/deploy-l2-contracts.job.yaml | 1 + .../templates/prover-node.stateful-set.yaml | 17 ++++-- .../templates/validator.stateful-set.yaml | 15 +++++- .../aztec-network/values/3-validators.yaml | 2 +- .../cli/src/cmds/l1/update_l1_validators.ts | 24 ++++++--- 8 files changed, 126 insertions(+), 67 deletions(-) create mode 100644 helm-charts/aztec-network/files/config/config-prover-env.sh create mode 100644 helm-charts/aztec-network/files/config/config-validator-env.sh delete mode 100644 helm-charts/aztec-network/templates/configure-validator-env.config-map.yaml diff --git a/helm-charts/aztec-network/files/config/config-prover-env.sh b/helm-charts/aztec-network/files/config/config-prover-env.sh new file mode 100644 index 00000000000..a4bd508a111 --- /dev/null +++ b/helm-charts/aztec-network/files/config/config-prover-env.sh @@ -0,0 +1,34 @@ +#!/bin/sh +set -e + +alias aztec='node --no-warnings /usr/src/yarn-project/aztec/dest/bin/index.js' + +# Pass the bootnode url as an argument +# Ask the bootnode for l1 contract addresses +output=$(aztec get-node-info -u $1) + +echo "$output" + +boot_node_enr=$(echo "$output" | grep -oP 'Node ENR: \Kenr:[a-zA-Z0-9\-\_\.]+') +rollup_address=$(echo "$output" | grep -oP 'Rollup Address: \K0x[a-fA-F0-9]{40}') +registry_address=$(echo "$output" | grep -oP 'Registry Address: \K0x[a-fA-F0-9]{40}') +inbox_address=$(echo "$output" | grep -oP 'L1 -> L2 Inbox Address: \K0x[a-fA-F0-9]{40}') +outbox_address=$(echo "$output" | grep -oP 'L2 -> L1 Outbox Address: \K0x[a-fA-F0-9]{40}') +availability_oracle_address=$(echo "$output" | grep -oP 'Availability Oracle Address: \K0x[a-fA-F0-9]{40}') +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}') + + +# Write the addresses to a file in the shared volume +cat < /shared/contracts.env +export BOOTSTRAP_NODES=$boot_node_enr +export ROLLUP_CONTRACT_ADDRESS=$rollup_address +export REGISTRY_CONTRACT_ADDRESS=$registry_address +export INBOX_CONTRACT_ADDRESS=$inbox_address +export OUTBOX_CONTRACT_ADDRESS=$outbox_address +export AVAILABILITY_ORACLE_CONTRACT_ADDRESS=$availability_oracle_address +export FEE_JUICE_CONTRACT_ADDRESS=$fee_juice_address +export FEE_JUICE_PORTAL_CONTRACT_ADDRESS=$fee_juice_portal_address +EOF + +cat /shared/contracts.env \ No newline at end of file diff --git a/helm-charts/aztec-network/files/config/config-validator-env.sh b/helm-charts/aztec-network/files/config/config-validator-env.sh new file mode 100644 index 00000000000..bc538c296ae --- /dev/null +++ b/helm-charts/aztec-network/files/config/config-validator-env.sh @@ -0,0 +1,46 @@ +#!/bin/sh +set -e + +alias aztec='node --no-warnings /usr/src/yarn-project/aztec/dest/bin/index.js' + +# Pass the bootnode url as an argument +# Ask the bootnode for l1 contract addresses +output=$(aztec get-node-info -u $1) + +echo "$output" + +boot_node_enr=$(echo "$output" | grep -oP 'Node ENR: \Kenr:[a-zA-Z0-9\-\_\.]+') +rollup_address=$(echo "$output" | grep -oP 'Rollup Address: \K0x[a-fA-F0-9]{40}') +registry_address=$(echo "$output" | grep -oP 'Registry Address: \K0x[a-fA-F0-9]{40}') +inbox_address=$(echo "$output" | grep -oP 'L1 -> L2 Inbox Address: \K0x[a-fA-F0-9]{40}') +outbox_address=$(echo "$output" | grep -oP 'L2 -> L1 Outbox Address: \K0x[a-fA-F0-9]{40}') +availability_oracle_address=$(echo "$output" | grep -oP 'Availability Oracle Address: \K0x[a-fA-F0-9]{40}') +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) + +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 + + +# Write the addresses to a file in the shared volume +cat < /shared/contracts.env +export BOOTSTRAP_NODES=$boot_node_enr +export ROLLUP_CONTRACT_ADDRESS=$rollup_address +export REGISTRY_CONTRACT_ADDRESS=$registry_address +export INBOX_CONTRACT_ADDRESS=$inbox_address +export OUTBOX_CONTRACT_ADDRESS=$outbox_address +export AVAILABILITY_ORACLE_CONTRACT_ADDRESS=$availability_oracle_address +export FEE_JUICE_CONTRACT_ADDRESS=$fee_juice_address +export FEE_JUICE_PORTAL_CONTRACT_ADDRESS=$fee_juice_portal_address +export VALIDATOR_PRIVATE_KEY=$private_key +EOF + +cat /shared/contracts.env \ No newline at end of file diff --git a/helm-charts/aztec-network/templates/configure-validator-env.config-map.yaml b/helm-charts/aztec-network/templates/configure-validator-env.config-map.yaml deleted file mode 100644 index cd33696b7b0..00000000000 --- a/helm-charts/aztec-network/templates/configure-validator-env.config-map.yaml +++ /dev/null @@ -1,54 +0,0 @@ -apiVersion: v1 -kind: ConfigMap -metadata: - name: {{ include "aztec-network.fullname" . }}-configure-validator-env - labels: - {{- include "aztec-network.labels" . | nindent 4 }} -data: - configure-validator-env.sh: | - #!/bin/sh - set -e - - alias aztec='node --no-warnings /usr/src/yarn-project/aztec/dest/bin/index.js' - - # Ask the bootnode for l1 contract addresses - output=$(aztec get-node-info -u {{ include "aztec-network.bootNodeUrl" . }}) - - echo "$output" - - boot_node_enr=$(echo "$output" | grep -oP 'Node ENR: \Kenr:[a-zA-Z0-9\-\_\.]+') - rollup_address=$(echo "$output" | grep -oP 'Rollup Address: \K0x[a-fA-F0-9]{40}') - registry_address=$(echo "$output" | grep -oP 'Registry Address: \K0x[a-fA-F0-9]{40}') - inbox_address=$(echo "$output" | grep -oP 'L1 -> L2 Inbox Address: \K0x[a-fA-F0-9]{40}') - outbox_address=$(echo "$output" | grep -oP 'L2 -> L1 Outbox Address: \K0x[a-fA-F0-9]{40}') - availability_oracle_address=$(echo "$output" | grep -oP 'Availability Oracle Address: \K0x[a-fA-F0-9]{40}') - 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) - - 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 - - - - # Write the addresses to a file in the shared volume - cat < /shared/contracts.env - export BOOTSTRAP_NODES=$boot_node_enr - export ROLLUP_CONTRACT_ADDRESS=$rollup_address - export REGISTRY_CONTRACT_ADDRESS=$registry_address - export INBOX_CONTRACT_ADDRESS=$inbox_address - export OUTBOX_CONTRACT_ADDRESS=$outbox_address - export AVAILABILITY_ORACLE_CONTRACT_ADDRESS=$availability_oracle_address - export FEE_JUICE_CONTRACT_ADDRESS=$fee_juice_address - export FEE_JUICE_PORTAL_CONTRACT_ADDRESS=$fee_juice_portal_address - export VALIDATOR_PRIVATE_KEY=$private_key - EOF - - cat /shared/contracts.env \ No newline at end of file diff --git a/helm-charts/aztec-network/templates/deploy-l2-contracts.job.yaml b/helm-charts/aztec-network/templates/deploy-l2-contracts.job.yaml index 56f2dd3b998..0a5a73bcb1c 100644 --- a/helm-charts/aztec-network/templates/deploy-l2-contracts.job.yaml +++ b/helm-charts/aztec-network/templates/deploy-l2-contracts.job.yaml @@ -27,6 +27,7 @@ spec: done echo "PXE service is ready!" node --no-warnings /usr/src/yarn-project/aztec/dest/bin/index.js deploy-protocol-contracts + echo "Deployed L2 contracts" env: - name: PXE_URL value: {{ include "aztec-network.pxeUrl" . | quote }} diff --git a/helm-charts/aztec-network/templates/prover-node.stateful-set.yaml b/helm-charts/aztec-network/templates/prover-node.stateful-set.yaml index 79a2da1f581..a1804ac40d9 100644 --- a/helm-charts/aztec-network/templates/prover-node.stateful-set.yaml +++ b/helm-charts/aztec-network/templates/prover-node.stateful-set.yaml @@ -18,13 +18,13 @@ spec: app: prover-node spec: initContainers: - - name: configure-validator-env + - name: configure-prover-env image: "{{ .Values.images.aztec.image }}" imagePullPolicy: {{ .Values.images.aztec.pullPolicy }} command: - "/bin/sh" - "-c" - - "cp /scripts/configure-validator-env.sh /tmp/configure-validator-env.sh && chmod +x /tmp/configure-validator-env.sh && /tmp/configure-validator-env.sh" + - "cp /scripts/configure-prover-env.sh /tmp/configure-prover-env.sh && chmod +x /tmp/configure-prover-env.sh && /tmp/configure-prover-env.sh {{ include "aztec-network.bootNodeUrl" . }}" volumeMounts: - name: shared-volume mountPath: /shared @@ -84,4 +84,15 @@ spec: emptyDir: {} - name: scripts configMap: - name: {{ include "aztec-network.fullname" . }}-configure-validator-env \ No newline at end of file + name: {{ include "aztec-network.fullname" . }}-configure-prover-env + +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ include "aztec-network.fullname" . }}-configure-prover-env + labels: + {{- include "aztec-network.labels" . | nindent 4 }} +data: + configure-prover-env.sh: | + {{ .Files.Get "files/config/config-prover-env.sh" | nindent 4 }} diff --git a/helm-charts/aztec-network/templates/validator.stateful-set.yaml b/helm-charts/aztec-network/templates/validator.stateful-set.yaml index 99ab91363e5..fec535503c3 100644 --- a/helm-charts/aztec-network/templates/validator.stateful-set.yaml +++ b/helm-charts/aztec-network/templates/validator.stateful-set.yaml @@ -24,7 +24,7 @@ spec: command: - "/bin/sh" - "-c" - - "cp /scripts/configure-validator-env.sh /tmp/configure-validator-env.sh && chmod +x /tmp/configure-validator-env.sh && /tmp/configure-validator-env.sh" + - "cp /scripts/configure-validator-env.sh /tmp/configure-validator-env.sh && chmod +x /tmp/configure-validator-env.sh && /tmp/configure-validator-env.sh {{ include "aztec-network.bootNodeUrl" . }}" volumeMounts: - name: shared-volume mountPath: /shared @@ -93,4 +93,15 @@ spec: emptyDir: {} - name: scripts configMap: - name: {{ include "aztec-network.fullname" . }}-configure-validator-env \ No newline at end of file + name: {{ include "aztec-network.fullname" . }}-configure-validator-env + +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ include "aztec-network.fullname" . }}-configure-validator-env + labels: + {{- include "aztec-network.labels" . | nindent 4 }} +data: + configure-validator-env.sh: | + {{ .Files.Get "files/config/config-validator-env.sh" | nindent 4 }} diff --git a/helm-charts/aztec-network/values/3-validators.yaml b/helm-charts/aztec-network/values/3-validators.yaml index eeef1a6136e..7ae76a0a305 100644 --- a/helm-charts/aztec-network/values/3-validators.yaml +++ b/helm-charts/aztec-network/values/3-validators.yaml @@ -5,4 +5,4 @@ validator: bootNode: validator: - disabled: false + disabled: true diff --git a/yarn-project/cli/src/cmds/l1/update_l1_validators.ts b/yarn-project/cli/src/cmds/l1/update_l1_validators.ts index 2c04b163526..9216d744d11 100644 --- a/yarn-project/cli/src/cmds/l1/update_l1_validators.ts +++ b/yarn-project/cli/src/cmds/l1/update_l1_validators.ts @@ -73,13 +73,23 @@ export async function fastForwardEpochs({ }); const cheatCodes = new EthCheatCodes(rpcUrl, debugLogger); - const genesisTs = await rollup.read.GENESIS_TIME(); - const slotsInEpoch = await rollup.read.EPOCH_DURATION(); - const slotDuration = await rollup.read.SLOT_DURATION(); - const epochDuration = slotsInEpoch * slotDuration; - const warpTime = genesisTs + numEpochs * epochDuration * 1000n; - await cheatCodes.warp(Number(warpTime)); - dualLog(`Fast forwarded ${numEpochs} epochs to ${warpTime}`); + const genesisSeconds = await rollup.read.GENESIS_TIME(); + const l2SlotsInEpoch = await rollup.read.EPOCH_DURATION(); + const l2SlotDurationSeconds = await rollup.read.SLOT_DURATION(); + dualLog(`Genesis time: ${genesisSeconds}`); + const warpTimeSeconds = genesisSeconds + l2SlotsInEpoch * l2SlotDurationSeconds * numEpochs; + dualLog(`Fast forwarding ${numEpochs} epochs to ${warpTimeSeconds}`); + try { + await cheatCodes.warp(Number(warpTimeSeconds)); + dualLog(`Fast forwarded ${numEpochs} epochs to ${warpTimeSeconds}`); + } catch (error) { + if (error instanceof Error && error.message.includes("is lower than or equal to previous block's timestamp")) { + dualLog(`Someone else fast forwarded the chain to a point after/equal to the target time`); + } else { + // Re-throw other errors + throw error; + } + } } function makeDualLog(log: LogFn, debugLogger: DebugLogger) { From e0b319cb61d38f88f30dc2a11791e4f3486d7c9d Mon Sep 17 00:00:00 2001 From: Mitch Date: Sat, 31 Aug 2024 16:28:29 -0400 Subject: [PATCH 5/9] add debug command --- yarn-project/cli/src/cmds/l1/index.ts | 29 +++++++++++++++++ .../cli/src/cmds/l1/update_l1_validators.ts | 31 +++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/yarn-project/cli/src/cmds/l1/index.ts b/yarn-project/cli/src/cmds/l1/index.ts index fc6576169b6..54de41cb7bc 100644 --- a/yarn-project/cli/src/cmds/l1/index.ts +++ b/yarn-project/cli/src/cmds/l1/index.ts @@ -118,6 +118,35 @@ export function injectCommands(program: Command, log: LogFn, debugLogger: DebugL }); }); + program + .command('debug-rollup') + .description('Debugs the rollup contract.') + .requiredOption( + '-u, --rpc-url ', + 'Url of the ethereum host. Chain identifiers localhost and testnet can be used', + ETHEREUM_HOST, + ) + .option('-pk, --private-key ', 'The private key to use for deployment', PRIVATE_KEY) + .option( + '-m, --mnemonic ', + 'The mnemonic to use in deployment', + 'test test test test test test test test test test test junk', + ) + .addOption(l1ChainIdOption) + .option('--rollup
', 'ethereum address of the rollup contract', parseEthereumAddress) + .action(async options => { + const { debugRollup } = await import('./update_l1_validators.js'); + await debugRollup({ + rpcUrl: options.rpcUrl, + chainId: options.l1ChainId, + privateKey: options.privateKey, + mnemonic: options.mnemonic, + rollupAddress: options.rollup, + log, + debugLogger, + }); + }); + program .command('deploy-l1-verifier') .description('Deploys the rollup verifier contract') diff --git a/yarn-project/cli/src/cmds/l1/update_l1_validators.ts b/yarn-project/cli/src/cmds/l1/update_l1_validators.ts index 9216d744d11..9241ab06586 100644 --- a/yarn-project/cli/src/cmds/l1/update_l1_validators.ts +++ b/yarn-project/cli/src/cmds/l1/update_l1_validators.ts @@ -92,6 +92,37 @@ export async function fastForwardEpochs({ } } +export async function debugRollup({ + rpcUrl, + chainId, + privateKey, + mnemonic, + rollupAddress, + log, + debugLogger, +}: RollupCommandArgs & LoggerArgs) { + const dualLog = makeDualLog(log, debugLogger); + const { publicClient } = getL1Clients(rpcUrl, chainId, privateKey, mnemonic); + const rollup = getContract({ + address: rollupAddress.toString(), + abi: RollupAbi, + client: publicClient, + }); + + const epoch = await rollup.read.getCurrentEpoch(); + dualLog(`Current epoch: ${epoch}`); + const slot = await rollup.read.getCurrentSlot(); + dualLog(`Current slot: ${slot}`); + const validators = await rollup.read.getValidators(); + dualLog(`Validators: ${validators.map(v => v.toString()).join(', ')}`); + const committee = await rollup.read.getCurrentEpochCommittee(); + dualLog(`Committee: ${committee.map(v => v.toString()).join(', ')}`); + const proposer = await rollup.read.getCurrentProposer(); + dualLog(`Proposer: ${proposer.toString()}`); + const archive = await rollup.read.archive(); + dualLog(`Archive: ${archive}`); +} + function makeDualLog(log: LogFn, debugLogger: DebugLogger) { return (msg: string) => { log(msg); From 55680c220bb159889b1fc87b5d64b61e5e8e7e0c Mon Sep 17 00:00:00 2001 From: Mitch Date: Sat, 31 Aug 2024 16:30:01 -0400 Subject: [PATCH 6/9] protocol contracts deploy correctly --- helm-charts/aztec-network/templates/deploy-l2-contracts.job.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/helm-charts/aztec-network/templates/deploy-l2-contracts.job.yaml b/helm-charts/aztec-network/templates/deploy-l2-contracts.job.yaml index 0a5a73bcb1c..aeb84cc4eae 100644 --- a/helm-charts/aztec-network/templates/deploy-l2-contracts.job.yaml +++ b/helm-charts/aztec-network/templates/deploy-l2-contracts.job.yaml @@ -26,6 +26,7 @@ spec: sleep 5 done echo "PXE service is ready!" + set -e node --no-warnings /usr/src/yarn-project/aztec/dest/bin/index.js deploy-protocol-contracts echo "Deployed L2 contracts" env: From c75737a930461a8c5f753d1aa3cfde1fedca8e23 Mon Sep 17 00:00:00 2001 From: Mitch Date: Sun, 1 Sep 2024 14:41:51 -0400 Subject: [PATCH 7/9] better debugging --- .../files/config/config-validator-env.sh | 2 ++ .../aztec-network/values/3-validators.yaml | 1 + .../cli/src/cmds/l1/update_l1_validators.ts | 36 +++++++++++-------- .../src/publisher/l1-publisher.ts | 1 + .../src/sequencer/sequencer.ts | 1 + 5 files changed, 26 insertions(+), 15 deletions(-) diff --git a/helm-charts/aztec-network/files/config/config-validator-env.sh b/helm-charts/aztec-network/files/config/config-validator-env.sh index bc538c296ae..e2b29694bc7 100644 --- a/helm-charts/aztec-network/files/config/config-validator-env.sh +++ b/helm-charts/aztec-network/files/config/config-validator-env.sh @@ -41,6 +41,8 @@ export AVAILABILITY_ORACLE_CONTRACT_ADDRESS=$availability_oracle_address export FEE_JUICE_CONTRACT_ADDRESS=$fee_juice_address export FEE_JUICE_PORTAL_CONTRACT_ADDRESS=$fee_juice_portal_address export VALIDATOR_PRIVATE_KEY=$private_key +export L1_PRIVATE_KEY=$private_key +export SEQ_PUBLISHER_PRIVATE_KEY=$private_key EOF cat /shared/contracts.env \ No newline at end of file diff --git a/helm-charts/aztec-network/values/3-validators.yaml b/helm-charts/aztec-network/values/3-validators.yaml index 7ae76a0a305..54c33daf0c4 100644 --- a/helm-charts/aztec-network/values/3-validators.yaml +++ b/helm-charts/aztec-network/values/3-validators.yaml @@ -1,4 +1,5 @@ validator: + debug: "aztec:*,-aztec:avm_simulator:*,-aztec:libp2p_service" replicas: 3 validator: disabled: false diff --git a/yarn-project/cli/src/cmds/l1/update_l1_validators.ts b/yarn-project/cli/src/cmds/l1/update_l1_validators.ts index 9241ab06586..667960726da 100644 --- a/yarn-project/cli/src/cmds/l1/update_l1_validators.ts +++ b/yarn-project/cli/src/cmds/l1/update_l1_validators.ts @@ -1,5 +1,5 @@ import { EthCheatCodes } from '@aztec/aztec.js'; -import { type EthAddress } from '@aztec/circuits.js'; +import { ETHEREUM_SLOT_DURATION, type EthAddress } from '@aztec/circuits.js'; import { createEthereumChain } from '@aztec/ethereum'; import { type DebugLogger, type LogFn } from '@aztec/foundation/log'; import { RollupAbi } from '@aztec/l1-artifacts'; @@ -73,11 +73,10 @@ export async function fastForwardEpochs({ }); const cheatCodes = new EthCheatCodes(rpcUrl, debugLogger); - const genesisSeconds = await rollup.read.GENESIS_TIME(); + const nowSeconds = BigInt(Math.floor(new Date().getTime() / 1000)); const l2SlotsInEpoch = await rollup.read.EPOCH_DURATION(); const l2SlotDurationSeconds = await rollup.read.SLOT_DURATION(); - dualLog(`Genesis time: ${genesisSeconds}`); - const warpTimeSeconds = genesisSeconds + l2SlotsInEpoch * l2SlotDurationSeconds * numEpochs; + const warpTimeSeconds = nowSeconds + l2SlotsInEpoch * l2SlotDurationSeconds * numEpochs; dualLog(`Fast forwarding ${numEpochs} epochs to ${warpTimeSeconds}`); try { await cheatCodes.warp(Number(warpTimeSeconds)); @@ -99,9 +98,7 @@ export async function debugRollup({ mnemonic, rollupAddress, log, - debugLogger, }: RollupCommandArgs & LoggerArgs) { - const dualLog = makeDualLog(log, debugLogger); const { publicClient } = getL1Clients(rpcUrl, chainId, privateKey, mnemonic); const rollup = getContract({ address: rollupAddress.toString(), @@ -109,18 +106,27 @@ export async function debugRollup({ client: publicClient, }); - const epoch = await rollup.read.getCurrentEpoch(); - dualLog(`Current epoch: ${epoch}`); - const slot = await rollup.read.getCurrentSlot(); - dualLog(`Current slot: ${slot}`); + const pendingCount = await rollup.read.pendingBlockCount(); + log(`Pending block count: ${pendingCount}`); + const provenCount = await rollup.read.provenBlockCount(); + log(`Proven block count: ${provenCount}`); const validators = await rollup.read.getValidators(); - dualLog(`Validators: ${validators.map(v => v.toString()).join(', ')}`); + log(`Validators: ${validators.map(v => v.toString()).join(', ')}`); const committee = await rollup.read.getCurrentEpochCommittee(); - dualLog(`Committee: ${committee.map(v => v.toString()).join(', ')}`); - const proposer = await rollup.read.getCurrentProposer(); - dualLog(`Proposer: ${proposer.toString()}`); + log(`Committee: ${committee.map(v => v.toString()).join(', ')}`); const archive = await rollup.read.archive(); - dualLog(`Archive: ${archive}`); + log(`Archive: ${archive}`); + const epochNum = await rollup.read.getCurrentEpoch(); + log(`Current epoch: ${epochNum}`); + const epoch = await rollup.read.epochs([epochNum]); + log(`Epoch Sample Seed: ${epoch[0].toString()}, Next Seed: ${epoch[1].toString()}`); + const slot = await rollup.read.getCurrentSlot(); + log(`Current slot: ${slot}`); + const proposerDuringPrevL1Block = await rollup.read.getCurrentProposer(); + log(`Proposer during previous L1 block: ${proposerDuringPrevL1Block}`); + const nextBlockTS = BigInt((await publicClient.getBlock()).timestamp + BigInt(ETHEREUM_SLOT_DURATION)); + const proposer = await rollup.read.getProposerAt([nextBlockTS]); + log(`Proposer NOW: ${proposer.toString()}`); } function makeDualLog(log: LogFn, debugLogger: DebugLogger) { diff --git a/yarn-project/sequencer-client/src/publisher/l1-publisher.ts b/yarn-project/sequencer-client/src/publisher/l1-publisher.ts index dc36dee4f9c..b8521cf5247 100644 --- a/yarn-project/sequencer-client/src/publisher/l1-publisher.ts +++ b/yarn-project/sequencer-client/src/publisher/l1-publisher.ts @@ -137,6 +137,7 @@ export class L1Publisher { const { l1RpcUrl: rpcUrl, l1ChainId: chainId, publisherPrivateKey, l1Contracts } = config; const chain = createEthereumChain(rpcUrl, chainId); this.account = privateKeyToAccount(publisherPrivateKey); + this.log.debug(`Publishing from address ${this.account.address}`); const walletClient = createWalletClient({ account: this.account, chain: chain.chainInfo, diff --git a/yarn-project/sequencer-client/src/sequencer/sequencer.ts b/yarn-project/sequencer-client/src/sequencer/sequencer.ts index 2f90618e58f..acc7851b43f 100644 --- a/yarn-project/sequencer-client/src/sequencer/sequencer.ts +++ b/yarn-project/sequencer-client/src/sequencer/sequencer.ts @@ -307,6 +307,7 @@ export class Sequencer { throw new Error(msg); } + this.log.debug(`Can propose block ${proposalBlockNumber} at slot ${slot}`); return slot; } catch (err) { if (err instanceof BaseError) { From 6c7647123618f502bf78363b48e3fa694b71cd13 Mon Sep 17 00:00:00 2001 From: Mitch Date: Sun, 1 Sep 2024 17:18:46 -0400 Subject: [PATCH 8/9] give validators gas use latest anvil --- .../aztec-network/templates/_helpers.tpl | 14 ++++++++++- .../templates/anvil.deployment.yaml | 23 ++++++++----------- helm-charts/aztec-network/values.yaml | 6 ++++- .../aztec.js/src/utils/cheat_codes.ts | 13 +++++++++++ .../cli/src/cmds/l1/update_l1_validators.ts | 3 +++ 5 files changed, 43 insertions(+), 16 deletions(-) diff --git a/helm-charts/aztec-network/templates/_helpers.tpl b/helm-charts/aztec-network/templates/_helpers.tpl index dea62e55f6d..632b4614882 100644 --- a/helm-charts/aztec-network/templates/_helpers.tpl +++ b/helm-charts/aztec-network/templates/_helpers.tpl @@ -76,4 +76,16 @@ http://{{ include "aztec-network.fullname" . }}-metrics.{{ .Release.Namespace }} - +{{- define "helpers.flag" -}} +{{- $name := index . 0 -}} +{{- $value := index . 1 -}} +{{- if $value -}} + {{- if kindIs "string" $value -}} + {{- if ne $value "" -}} +--{{ $name }} {{ $value }} + {{- end -}} + {{- else -}} +--{{ $name }} {{ $value }} + {{- end -}} +{{- end -}} +{{- end -}} diff --git a/helm-charts/aztec-network/templates/anvil.deployment.yaml b/helm-charts/aztec-network/templates/anvil.deployment.yaml index 05917e1ad36..3894ee5607e 100644 --- a/helm-charts/aztec-network/templates/anvil.deployment.yaml +++ b/helm-charts/aztec-network/templates/anvil.deployment.yaml @@ -22,23 +22,18 @@ spec: imagePullPolicy: {{ .Values.images.foundry.pullPolicy }} command: ["/bin/sh", "-c"] args: - - | - [ -n "$FORK_URL" ] && ARGS="$ARGS --fork-url $FORK_URL"; - [ -n "$FORK_BLOCK_NUMBER" ] && ARGS="$ARGS --fork-block-number $FORK_BLOCK_NUMBER"; - echo anvil --block-time 12 -p $ANVIL_PORT --host 0.0.0.0 --chain-id {{ .Values.ethereum.chainId }} $ARGS; - anvil --block-time 12 -p $ANVIL_PORT --host 0.0.0.0 --chain-id {{ .Values.ethereum.chainId }} $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) }} + -p {{ .Values.ethereum.service.port }} ports: - containerPort: {{ .Values.ethereum.service.port }} name: anvil - env: - - name: FORK_URL - value: {{ .Values.ethereum.forkUrl | quote }} - - name: FORK_BLOCK_NUMBER - value: {{ .Values.ethereum.forkBlockNumber | quote }} - - name: ANVIL_PORT - value: {{ .Values.ethereum.service.port | quote }} - - name: ARGS - value: {{ .Values.ethereum.args | quote }} readinessProbe: exec: command: diff --git a/helm-charts/aztec-network/values.yaml b/helm-charts/aztec-network/values.yaml index afad21361c4..13acf19ddbe 100644 --- a/helm-charts/aztec-network/values.yaml +++ b/helm-charts/aztec-network/values.yaml @@ -9,7 +9,7 @@ images: image: curlimages/curl:7.81.0 pullPolicy: IfNotPresent foundry: - image: ghcr.io/foundry-rs/foundry@sha256:29ba6e34379e79c342ec02d437beb7929c9e254261e8032b17e187be71a2609f + image: ghcr.io/foundry-rs/foundry@sha256:ce4b236f6760fdeb08e82267c9fa17647d29a374760bfe7ee01998fb8c0aaad7 pullPolicy: IfNotPresent otelCollector: image: otel/opentelemetry-collector-contrib @@ -83,6 +83,10 @@ pxe: ethereum: replicas: 1 chainId: 31337 + blockTime: 12 + # 1 billion gas limit + # helps ensure we can deploy public contracts + gasLimit: "1000000000" forkUrl: "" forkBlockNumber: "" args: "" diff --git a/yarn-project/aztec.js/src/utils/cheat_codes.ts b/yarn-project/aztec.js/src/utils/cheat_codes.ts index 83266fd6275..95d8d4710b3 100644 --- a/yarn-project/aztec.js/src/utils/cheat_codes.ts +++ b/yarn-project/aztec.js/src/utils/cheat_codes.ts @@ -94,6 +94,19 @@ export class EthCheatCodes { this.logger.info(`Mined ${numberOfBlocks} blocks`); } + /** + * Set the balance of an account + * @param account - The account to set the balance for + * @param balance - The balance to set + */ + public async setBalance(account: EthAddress, balance: bigint): Promise { + const res = await this.rpcCall('anvil_setBalance', [account.toString(), toHex(balance)]); + if (res.error) { + throw new Error(`Error setting balance for ${account}: ${res.error.message}`); + } + this.logger.info(`Set balance for ${account} to ${balance}`); + } + /** * Set the interval between blocks (block time) * @param interval - The interval to use between blocks diff --git a/yarn-project/cli/src/cmds/l1/update_l1_validators.ts b/yarn-project/cli/src/cmds/l1/update_l1_validators.ts index 667960726da..ae7873a650c 100644 --- a/yarn-project/cli/src/cmds/l1/update_l1_validators.ts +++ b/yarn-project/cli/src/cmds/l1/update_l1_validators.ts @@ -52,6 +52,9 @@ export async function addL1Validator({ const txHash = await rollup.write.addValidator([validatorAddress.toString()]); dualLog(`Transaction hash: ${txHash}`); await publicClient.waitForTransactionReceipt({ hash: txHash }); + dualLog(`Funding validator on L1`); + const cheatCodes = new EthCheatCodes(rpcUrl, debugLogger); + await cheatCodes.setBalance(validatorAddress, 100000000000000000000n); } export async function fastForwardEpochs({ From dabfa025aea2032eeedd329f8048f6f5aedf4af3 Mon Sep 17 00:00:00 2001 From: Mitch Date: Mon, 2 Sep 2024 13:08:49 -0400 Subject: [PATCH 9/9] review response --- yarn-project/cli/src/cmds/l1/index.ts | 14 ----- .../cli/src/cmds/l1/update_l1_validators.ts | 60 +++++++++---------- 2 files changed, 30 insertions(+), 44 deletions(-) diff --git a/yarn-project/cli/src/cmds/l1/index.ts b/yarn-project/cli/src/cmds/l1/index.ts index 54de41cb7bc..50dfa071e2e 100644 --- a/yarn-project/cli/src/cmds/l1/index.ts +++ b/yarn-project/cli/src/cmds/l1/index.ts @@ -95,12 +95,6 @@ export function injectCommands(program: Command, log: LogFn, debugLogger: DebugL 'Url of the ethereum host. Chain identifiers localhost and testnet can be used', ETHEREUM_HOST, ) - .option('-pk, --private-key ', 'The private key to use for deployment', PRIVATE_KEY) - .option( - '-m, --mnemonic ', - 'The mnemonic to use in deployment', - 'test test test test test test test test test test test junk', - ) .addOption(l1ChainIdOption) .option('--rollup
', 'ethereum address of the rollup contract', parseEthereumAddress) .option('--count ', 'The number of epochs to fast forward', arg => BigInt(parseInt(arg)), 1n) @@ -109,8 +103,6 @@ export function injectCommands(program: Command, log: LogFn, debugLogger: DebugL await fastForwardEpochs({ rpcUrl: options.rpcUrl, chainId: options.l1ChainId, - privateKey: options.privateKey, - mnemonic: options.mnemonic, rollupAddress: options.rollup, numEpochs: options.count, log, @@ -126,12 +118,6 @@ export function injectCommands(program: Command, log: LogFn, debugLogger: DebugL 'Url of the ethereum host. Chain identifiers localhost and testnet can be used', ETHEREUM_HOST, ) - .option('-pk, --private-key ', 'The private key to use for deployment', PRIVATE_KEY) - .option( - '-m, --mnemonic ', - 'The mnemonic to use in deployment', - 'test test test test test test test test test test test junk', - ) .addOption(l1ChainIdOption) .option('--rollup
', 'ethereum address of the rollup contract', parseEthereumAddress) .action(async options => { diff --git a/yarn-project/cli/src/cmds/l1/update_l1_validators.ts b/yarn-project/cli/src/cmds/l1/update_l1_validators.ts index ae7873a650c..a230ed32b3b 100644 --- a/yarn-project/cli/src/cmds/l1/update_l1_validators.ts +++ b/yarn-project/cli/src/cmds/l1/update_l1_validators.ts @@ -10,8 +10,8 @@ import { generatePrivateKey, mnemonicToAccount, privateKeyToAccount } from 'viem export interface RollupCommandArgs { rpcUrl: string; chainId: number; - privateKey: string | undefined; - mnemonic: string; + privateKey?: string; + mnemonic?: string; rollupAddress: EthAddress; } @@ -41,7 +41,8 @@ export async function addL1Validator({ debugLogger, }: RollupCommandArgs & LoggerArgs & { validatorAddress: EthAddress }) { const dualLog = makeDualLog(log, debugLogger); - const { walletClient, publicClient } = getL1Clients(rpcUrl, chainId, privateKey, mnemonic); + const publicClient = getPublicClient(rpcUrl, chainId); + const walletClient = getWalletClient(rpcUrl, chainId, privateKey, mnemonic); const rollup = getContract({ address: rollupAddress.toString(), abi: RollupAbi, @@ -54,36 +55,33 @@ export async function addL1Validator({ await publicClient.waitForTransactionReceipt({ hash: txHash }); dualLog(`Funding validator on L1`); const cheatCodes = new EthCheatCodes(rpcUrl, debugLogger); - await cheatCodes.setBalance(validatorAddress, 100000000000000000000n); + await cheatCodes.setBalance(validatorAddress, 10n ** 20n); } export async function fastForwardEpochs({ rpcUrl, chainId, - privateKey, - mnemonic, rollupAddress, numEpochs, log, debugLogger, }: RollupCommandArgs & LoggerArgs & { numEpochs: bigint }) { const dualLog = makeDualLog(log, debugLogger); - const { walletClient } = getL1Clients(rpcUrl, chainId, privateKey, mnemonic); + const publicClient = getPublicClient(rpcUrl, chainId); const rollup = getContract({ address: rollupAddress.toString(), abi: RollupAbi, - client: walletClient, + client: publicClient, }); const cheatCodes = new EthCheatCodes(rpcUrl, debugLogger); - const nowSeconds = BigInt(Math.floor(new Date().getTime() / 1000)); + const currentSlot = await rollup.read.getCurrentSlot(); const l2SlotsInEpoch = await rollup.read.EPOCH_DURATION(); - const l2SlotDurationSeconds = await rollup.read.SLOT_DURATION(); - const warpTimeSeconds = nowSeconds + l2SlotsInEpoch * l2SlotDurationSeconds * numEpochs; - dualLog(`Fast forwarding ${numEpochs} epochs to ${warpTimeSeconds}`); + const timestamp = await rollup.read.getTimestampForSlot([currentSlot + l2SlotsInEpoch * numEpochs]); + dualLog(`Fast forwarding ${numEpochs} epochs to ${timestamp}`); try { - await cheatCodes.warp(Number(warpTimeSeconds)); - dualLog(`Fast forwarded ${numEpochs} epochs to ${warpTimeSeconds}`); + await cheatCodes.warp(Number(timestamp)); + dualLog(`Fast forwarded ${numEpochs} epochs to ${timestamp}`); } catch (error) { if (error instanceof Error && error.message.includes("is lower than or equal to previous block's timestamp")) { dualLog(`Someone else fast forwarded the chain to a point after/equal to the target time`); @@ -94,15 +92,8 @@ export async function fastForwardEpochs({ } } -export async function debugRollup({ - rpcUrl, - chainId, - privateKey, - mnemonic, - rollupAddress, - log, -}: RollupCommandArgs & LoggerArgs) { - const { publicClient } = getL1Clients(rpcUrl, chainId, privateKey, mnemonic); +export async function debugRollup({ rpcUrl, chainId, rollupAddress, log }: RollupCommandArgs & LoggerArgs) { + const publicClient = getPublicClient(rpcUrl, chainId); const rollup = getContract({ address: rollupAddress.toString(), abi: RollupAbi, @@ -139,15 +130,24 @@ function makeDualLog(log: LogFn, debugLogger: DebugLogger) { }; } -function getL1Clients(rpcUrl: string, chainId: number, privateKey: string | undefined, mnemonic: string) { +function getPublicClient(rpcUrl: string, chainId: number) { + const chain = createEthereumChain(rpcUrl, chainId); + return createPublicClient({ chain: chain.chainInfo, transport: http(rpcUrl) }); +} + +function getWalletClient( + rpcUrl: string, + chainId: number, + privateKey: string | undefined, + mnemonic: string | undefined, +) { + if (!privateKey && !mnemonic) { + throw new Error('Either privateKey or mnemonic must be provided to create a wallet client'); + } + const chain = createEthereumChain(rpcUrl, chainId); const account = !privateKey ? mnemonicToAccount(mnemonic!) : privateKeyToAccount(`${privateKey.startsWith('0x') ? '' : '0x'}${privateKey}` as `0x${string}`); - const walletClient = createWalletClient({ account, chain: chain.chainInfo, transport: http(rpcUrl) }); - const publicClient = createPublicClient({ chain: chain.chainInfo, transport: http(rpcUrl) }); - return { - walletClient, - publicClient, - }; + return createWalletClient({ account, chain: chain.chainInfo, transport: http(rpcUrl) }); }