diff --git a/yarn-project/aztec/src/cli/aztec_start_options.ts b/yarn-project/aztec/src/cli/aztec_start_options.ts index 26d3f88df3f..bdd9229bb15 100644 --- a/yarn-project/aztec/src/cli/aztec_start_options.ts +++ b/yarn-project/aztec/src/cli/aztec_start_options.ts @@ -3,6 +3,7 @@ import { sequencerClientConfigMappings } from '@aztec/aztec-node'; import { botConfigMappings } from '@aztec/bot'; import { type ConfigMapping, + type EnvVar, booleanConfigHelper, filterConfigMappings, isBooleanConfigValue, @@ -21,7 +22,7 @@ export interface AztecStartOption { description: string; defaultValue: any | undefined; printDefault?: (val: any) => string; - envVar: string | undefined; + envVar: EnvVar | undefined; parseVal?: (val: string) => any; } @@ -45,7 +46,7 @@ export const getOptions = (namespace: string, configMappings: Record', - description: 'URL for an archiver service', + flag: '--data-directory ', + description: 'Where to store data. If not set, will store temporarily', defaultValue: undefined, - envVar: 'ARCHIVER_URL', + envVar: 'DATA_DIRECTORY', }, { - flag: '--node.dataDirectory ', - description: 'Where to store node data. If not set, will store temporarily', + flag: '--node.archiverUrl ', + description: 'URL for an archiver service', defaultValue: undefined, - envVar: 'NODE_DATA_DIRECTORY', + envVar: 'ARCHIVER_URL', }, { flag: '--node.deployAztecContracts', @@ -221,6 +222,12 @@ export const aztecStartOptions: { [key: string]: AztecStartOption[] } = { defaultValue: undefined, envVar: undefined, }, + { + flag: '--pxe.dataDirectory ', + description: 'Where to store PXE data. If not set, will store in memory', + defaultValue: undefined, + envVar: 'PXE_DATA_DIRECTORY', + }, ...getOptions('pxe', allPxeConfigMappings), ], ARCHIVER: [ diff --git a/yarn-project/aztec/src/cli/cmds/start_archiver.ts b/yarn-project/aztec/src/cli/cmds/start_archiver.ts index ff3690ae66d..95ad83b9972 100644 --- a/yarn-project/aztec/src/cli/cmds/start_archiver.ts +++ b/yarn-project/aztec/src/cli/cmds/start_archiver.ts @@ -18,7 +18,7 @@ import { extractRelevantOptions } from '../util.js'; export const startArchiver = async (options: any, signalHandlers: (() => Promise)[]) => { const services: ServerList = []; // Start a standalone archiver. - const archiverConfig = extractRelevantOptions(options, archiverConfigMappings); + const archiverConfig = extractRelevantOptions(options, archiverConfigMappings, 'archiver'); const storeLog = createDebugLogger('aztec:archiver:lmdb'); const rollupAddress = archiverConfig.l1Contracts.rollupAddress; diff --git a/yarn-project/aztec/src/cli/cmds/start_bot.ts b/yarn-project/aztec/src/cli/cmds/start_bot.ts index 4d45dd4e0db..cf61ed0aa95 100644 --- a/yarn-project/aztec/src/cli/cmds/start_bot.ts +++ b/yarn-project/aztec/src/cli/cmds/start_bot.ts @@ -37,7 +37,7 @@ export function addBot( signalHandlers: (() => Promise)[], deps: { pxe?: PXE; node?: AztecNode } = {}, ) { - const config = extractRelevantOptions(options, botConfigMappings); + const config = extractRelevantOptions(options, botConfigMappings, 'bot'); const botRunner = new BotRunner(config, deps); const botServer = createBotRunnerRpcServer(botRunner); diff --git a/yarn-project/aztec/src/cli/cmds/start_node.ts b/yarn-project/aztec/src/cli/cmds/start_node.ts index 9748e4f57e1..b4279d7b2d7 100644 --- a/yarn-project/aztec/src/cli/cmds/start_node.ts +++ b/yarn-project/aztec/src/cli/cmds/start_node.ts @@ -27,7 +27,7 @@ export const startNode = async ( const nodeSpecificOptions = extractNamespacedOptions(options, 'node'); // All options that are relevant to the Aztec Node const nodeConfig = { - ...extractRelevantOptions(options, aztecNodeConfigMappings), + ...extractRelevantOptions(options, aztecNodeConfigMappings, 'node'), l1Contracts: extractL1ContractAddresses(options), }; @@ -90,7 +90,7 @@ export const startNode = async ( } } - const telemetryConfig = extractRelevantOptions(options, telemetryClientConfigMappings); + const telemetryConfig = extractRelevantOptions(options, telemetryClientConfigMappings, 'tel'); const telemetryClient = createAndStartTelemetryClient(telemetryConfig); // Create and start Aztec Node. diff --git a/yarn-project/aztec/src/cli/cmds/start_p2p_bootstrap.ts b/yarn-project/aztec/src/cli/cmds/start_p2p_bootstrap.ts index c2d57597e39..60ffada5411 100644 --- a/yarn-project/aztec/src/cli/cmds/start_p2p_bootstrap.ts +++ b/yarn-project/aztec/src/cli/cmds/start_p2p_bootstrap.ts @@ -7,7 +7,7 @@ import { extractRelevantOptions } from '../util.js'; export const startP2PBootstrap = async (options: any, userLog: LogFn, debugLogger: DebugLogger) => { // Start a P2P bootstrap node. - const config = extractRelevantOptions(options, bootnodeConfigMappings); + const config = extractRelevantOptions(options, bootnodeConfigMappings, 'p2p'); await runBootstrapNode(config, debugLogger); userLog(`P2P bootstrap node started on ${config.udpListenAddress}`); }; diff --git a/yarn-project/aztec/src/cli/cmds/start_prover_agent.ts b/yarn-project/aztec/src/cli/cmds/start_prover_agent.ts index 1c71b49de8e..f6c73503816 100644 --- a/yarn-project/aztec/src/cli/cmds/start_prover_agent.ts +++ b/yarn-project/aztec/src/cli/cmds/start_prover_agent.ts @@ -11,7 +11,7 @@ import { import { type ServiceStarter, extractRelevantOptions } from '../util.js'; export const startProverAgent: ServiceStarter = async (options, signalHandlers, logger) => { - const proverConfig = extractRelevantOptions(options, proverClientConfigMappings); + const proverConfig = extractRelevantOptions(options, proverClientConfigMappings, 'prover'); if (!proverConfig.nodeUrl) { throw new Error('Starting prover without an orchestrator is not supported'); @@ -20,7 +20,7 @@ export const startProverAgent: ServiceStarter = async (options, signalHandlers, logger(`Connecting to prover at ${proverConfig.nodeUrl}`); const source = createProvingJobSourceClient(proverConfig.nodeUrl, 'provingJobSource'); - const telemetryConfig = extractRelevantOptions(options, telemetryClientConfigMappings); + const telemetryConfig = extractRelevantOptions(options, telemetryClientConfigMappings, 'tel'); const telemetry = createAndStartTelemetryClient(telemetryConfig); let circuitProver: ServerCircuitProver; diff --git a/yarn-project/aztec/src/cli/cmds/start_prover_node.ts b/yarn-project/aztec/src/cli/cmds/start_prover_node.ts index 8b0017c7a81..1c22e3d7308 100644 --- a/yarn-project/aztec/src/cli/cmds/start_prover_node.ts +++ b/yarn-project/aztec/src/cli/cmds/start_prover_node.ts @@ -32,7 +32,7 @@ export const startProverNode = async ( } const proverConfig = { - ...extractRelevantOptions(options, proverNodeConfigMappings), + ...extractRelevantOptions(options, proverNodeConfigMappings, 'proverNode'), l1Contracts: extractL1ContractAddresses(options), }; diff --git a/yarn-project/aztec/src/cli/cmds/start_pxe.ts b/yarn-project/aztec/src/cli/cmds/start_pxe.ts index 60bd6d52899..674657fd303 100644 --- a/yarn-project/aztec/src/cli/cmds/start_pxe.ts +++ b/yarn-project/aztec/src/cli/cmds/start_pxe.ts @@ -47,7 +47,7 @@ export async function addPXE( userLog: LogFn, deps: { node?: AztecNode } = {}, ) { - const pxeConfig = extractRelevantOptions(options, allPxeConfigMappings); + const pxeConfig = extractRelevantOptions(options, allPxeConfigMappings, 'pxe'); let nodeUrl; if (pxeConfig.network) { diff --git a/yarn-project/aztec/src/cli/util.ts b/yarn-project/aztec/src/cli/util.ts index ba6838fc9b8..cfdaaec236a 100644 --- a/yarn-project/aztec/src/cli/util.ts +++ b/yarn-project/aztec/src/cli/util.ts @@ -198,17 +198,39 @@ export const extractL1ContractAddresses = (options: Record): L1Cont * @template T - The type of the relevant options. * @param options - Key-value map of options. * @param mappings - The mappings to extract. + * @param namespace - The namespace to extract for. * @returns Key-value map of relevant options. */ -export const extractRelevantOptions = (options: Record, mappings: ConfigMappingsType): T => { +export const extractRelevantOptions = ( + options: Record, + mappings: ConfigMappingsType, + namespace: string, +): T => { const relevantOptions: T = {} as T; - Object.keys(options).forEach(key => { - const keyParts = key.split('.'); + // Iterate over each key in the options + Object.keys(options).forEach(optionKey => { + const keyParts = optionKey.split('.'); + const optionNamespace = keyParts.length > 1 ? keyParts[0] : ''; const mainKey = keyParts.length > 1 ? keyParts[1] : keyParts[0]; + // Check if the key exists in the mappings if (mainKey in mappings) { - relevantOptions[mainKey as keyof T] = options[key]; + // Check for duplicates in the options + const duplicates = Object.keys(options).filter(optKey => { + const optKeyParts = optKey.split('.'); + return optKeyParts[1] === mainKey || optKeyParts[0] === mainKey; + }); + + // If duplicates are found, use the namespace to differentiate + if (duplicates.length > 1) { + if (namespace === optionNamespace) { + relevantOptions[mainKey as keyof T] = options[optionKey]; + } + } else { + // If no duplicates, extract the value without considering the namespace + relevantOptions[mainKey as keyof T] = options[optionKey]; + } } }); diff --git a/yarn-project/foundation/src/config/env_var.ts b/yarn-project/foundation/src/config/env_var.ts index 10c3c4a22f8..ea5027b309a 100644 --- a/yarn-project/foundation/src/config/env_var.ts +++ b/yarn-project/foundation/src/config/env_var.ts @@ -1,4 +1,6 @@ export type EnvVar = + | 'AZTEC_PORT' + | 'ASSUME_PROVEN_UNTIL_BLOCK_NUMBER' | 'TEST_ACCOUNTS' | 'ENABLE_GAS' | 'API_PREFIX'