Skip to content

Commit

Permalink
fix: port option & extracting correct namespaced options (#8097)
Browse files Browse the repository at this point in the history
  • Loading branch information
spypsy authored Aug 22, 2024
1 parent e8a9eb4 commit e74c83e
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 21 deletions.
23 changes: 15 additions & 8 deletions yarn-project/aztec/src/cli/aztec_start_options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { sequencerClientConfigMappings } from '@aztec/aztec-node';
import { botConfigMappings } from '@aztec/bot';
import {
type ConfigMapping,
type EnvVar,
booleanConfigHelper,
filterConfigMappings,
isBooleanConfigValue,
Expand All @@ -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;
}

Expand All @@ -45,7 +46,7 @@ export const getOptions = (namespace: string, configMappings: Record<string, Con
};

// These are options used by multiple modules so should be inputted once
export const universalOptions = ['l1RpcUrl', 'l1ChainId', 'l1Contracts', 'p2pEnabled'];
export const universalOptions = ['l1RpcUrl', 'l1ChainId', 'l1Contracts', 'p2pEnabled', 'dataDirectory'];

// Define categories and options
export const aztecStartOptions: { [key: string]: AztecStartOption[] } = {
Expand Down Expand Up @@ -158,16 +159,16 @@ export const aztecStartOptions: { [key: string]: AztecStartOption[] } = {
envVar: undefined,
},
{
flag: '--node.archiverUrl <value>',
description: 'URL for an archiver service',
flag: '--data-directory <value>',
description: 'Where to store data. If not set, will store temporarily',
defaultValue: undefined,
envVar: 'ARCHIVER_URL',
envVar: 'DATA_DIRECTORY',
},
{
flag: '--node.dataDirectory <value>',
description: 'Where to store node data. If not set, will store temporarily',
flag: '--node.archiverUrl <value>',
description: 'URL for an archiver service',
defaultValue: undefined,
envVar: 'NODE_DATA_DIRECTORY',
envVar: 'ARCHIVER_URL',
},
{
flag: '--node.deployAztecContracts',
Expand Down Expand Up @@ -221,6 +222,12 @@ export const aztecStartOptions: { [key: string]: AztecStartOption[] } = {
defaultValue: undefined,
envVar: undefined,
},
{
flag: '--pxe.dataDirectory <value>',
description: 'Where to store PXE data. If not set, will store in memory',
defaultValue: undefined,
envVar: 'PXE_DATA_DIRECTORY',
},
...getOptions('pxe', allPxeConfigMappings),
],
ARCHIVER: [
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec/src/cli/cmds/start_archiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { extractRelevantOptions } from '../util.js';
export const startArchiver = async (options: any, signalHandlers: (() => Promise<void>)[]) => {
const services: ServerList = [];
// Start a standalone archiver.
const archiverConfig = extractRelevantOptions<ArchiverConfig>(options, archiverConfigMappings);
const archiverConfig = extractRelevantOptions<ArchiverConfig>(options, archiverConfigMappings, 'archiver');

const storeLog = createDebugLogger('aztec:archiver:lmdb');
const rollupAddress = archiverConfig.l1Contracts.rollupAddress;
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec/src/cli/cmds/start_bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function addBot(
signalHandlers: (() => Promise<void>)[],
deps: { pxe?: PXE; node?: AztecNode } = {},
) {
const config = extractRelevantOptions<BotConfig>(options, botConfigMappings);
const config = extractRelevantOptions<BotConfig>(options, botConfigMappings, 'bot');

const botRunner = new BotRunner(config, deps);
const botServer = createBotRunnerRpcServer(botRunner);
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/aztec/src/cli/cmds/start_node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
};

Expand Down Expand Up @@ -90,7 +90,7 @@ export const startNode = async (
}
}

const telemetryConfig = extractRelevantOptions<TelemetryClientConfig>(options, telemetryClientConfigMappings);
const telemetryConfig = extractRelevantOptions<TelemetryClientConfig>(options, telemetryClientConfigMappings, 'tel');
const telemetryClient = createAndStartTelemetryClient(telemetryConfig);

// Create and start Aztec Node.
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec/src/cli/cmds/start_p2p_bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<BootnodeConfig>(options, bootnodeConfigMappings);
const config = extractRelevantOptions<BootnodeConfig>(options, bootnodeConfigMappings, 'p2p');
await runBootstrapNode(config, debugLogger);
userLog(`P2P bootstrap node started on ${config.udpListenAddress}`);
};
4 changes: 2 additions & 2 deletions yarn-project/aztec/src/cli/cmds/start_prover_agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
import { type ServiceStarter, extractRelevantOptions } from '../util.js';

export const startProverAgent: ServiceStarter = async (options, signalHandlers, logger) => {
const proverConfig = extractRelevantOptions<ProverClientConfig>(options, proverClientConfigMappings);
const proverConfig = extractRelevantOptions<ProverClientConfig>(options, proverClientConfigMappings, 'prover');

if (!proverConfig.nodeUrl) {
throw new Error('Starting prover without an orchestrator is not supported');
Expand All @@ -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<TelemetryClientConfig>(options, telemetryClientConfigMappings);
const telemetryConfig = extractRelevantOptions<TelemetryClientConfig>(options, telemetryClientConfigMappings, 'tel');
const telemetry = createAndStartTelemetryClient(telemetryConfig);

let circuitProver: ServerCircuitProver;
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec/src/cli/cmds/start_prover_node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const startProverNode = async (
}

const proverConfig = {
...extractRelevantOptions<ProverNodeConfig>(options, proverNodeConfigMappings),
...extractRelevantOptions<ProverNodeConfig>(options, proverNodeConfigMappings, 'proverNode'),
l1Contracts: extractL1ContractAddresses(options),
};

Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec/src/cli/cmds/start_pxe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export async function addPXE(
userLog: LogFn,
deps: { node?: AztecNode } = {},
) {
const pxeConfig = extractRelevantOptions<PXEServiceConfig & CliPXEOptions>(options, allPxeConfigMappings);
const pxeConfig = extractRelevantOptions<PXEServiceConfig & CliPXEOptions>(options, allPxeConfigMappings, 'pxe');

let nodeUrl;
if (pxeConfig.network) {
Expand Down
30 changes: 26 additions & 4 deletions yarn-project/aztec/src/cli/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,17 +198,39 @@ export const extractL1ContractAddresses = (options: Record<string, any>): 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 = <T>(options: Record<string, any>, mappings: ConfigMappingsType<T>): T => {
export const extractRelevantOptions = <T>(
options: Record<string, any>,
mappings: ConfigMappingsType<T>,
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];
}
}
});

Expand Down
2 changes: 2 additions & 0 deletions yarn-project/foundation/src/config/env_var.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export type EnvVar =
| 'AZTEC_PORT'
| 'ASSUME_PROVEN_UNTIL_BLOCK_NUMBER'
| 'TEST_ACCOUNTS'
| 'ENABLE_GAS'
| 'API_PREFIX'
Expand Down

0 comments on commit e74c83e

Please sign in to comment.