Skip to content

Commit

Permalink
fix: Add boolean config helper
Browse files Browse the repository at this point in the history
Adds a helper method for parsing boolean env vars, and fixes instances
where we were looking for true (boolean) instead of 'true' (string) when
parsing env.
  • Loading branch information
spalladino committed Aug 9, 2024
1 parent 79613a7 commit 651a375
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 39 deletions.
8 changes: 3 additions & 5 deletions yarn-project/aztec-node/src/aztec-node/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type ArchiverConfig, archiverConfigMappings } from '@aztec/archiver';
import { type ConfigMappingsType, getConfigFromMappings } from '@aztec/foundation/config';
import { type ConfigMappingsType, booleanConfigHelper, getConfigFromMappings } from '@aztec/foundation/config';
import { type P2PConfig, p2pConfigMappings } from '@aztec/p2p';
import { type ProverClientConfig, proverClientConfigMappings } from '@aztec/prover-client';
import { type SequencerClientConfig, sequencerClientConfigMappings } from '@aztec/sequencer-client';
Expand Down Expand Up @@ -34,15 +34,13 @@ export const aztecNodeConfigMappings: ConfigMappingsType<AztecNodeConfig> = {
...p2pConfigMappings,
disableSequencer: {
env: 'SEQ_DISABLED',
parseEnv: (val: string) => ['1', 'true'].includes(val),
default: false,
description: 'Whether the sequencer is disabled for this node.',
...booleanConfigHelper(),
},
disableProver: {
env: 'PROVER_DISABLED',
parseEnv: (val: string) => ['1', 'true'].includes(val),
default: false,
description: 'Whether the prover is disabled for this node.',
...booleanConfigHelper(),
},
};

Expand Down
19 changes: 10 additions & 9 deletions yarn-project/aztec/src/cli/aztec_start_options.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { type ArchiverConfig, archiverConfigMappings } from '@aztec/archiver';
import { sequencerClientConfigMappings } from '@aztec/aztec-node';
import { botConfigMappings } from '@aztec/bot';
import { type ConfigMapping, filterConfigMappings, isBooleanConfigValue } from '@aztec/foundation/config';
import {
type ConfigMapping,
booleanConfigHelper,
filterConfigMappings,
isBooleanConfigValue,
} from '@aztec/foundation/config';
import { bootnodeConfigMappings, p2pConfigMappings } from '@aztec/p2p';
import { proverClientConfigMappings } from '@aztec/prover-client';
import { proverNodeConfigMappings } from '@aztec/prover-node';
Expand Down Expand Up @@ -54,16 +59,14 @@ export const aztecStartOptions: { [key: string]: AztecStartOption[] } = {
{
flag: '--sandbox.testAccounts',
description: 'Deploy test accounts on sandbox start',
defaultValue: true,
envVar: 'TEST_ACCOUNTS',
parseVal: val => ['1', true].includes(val),
...booleanConfigHelper(true),
},
{
flag: '--sandbox.enableGas',
description: 'Enable gas on sandbox start',
defaultValue: false,
envVar: 'ENABLE_GAS',
parseVal: val => ['1', true].includes(val),
...booleanConfigHelper(),
},
],
API: [
Expand Down Expand Up @@ -169,9 +172,8 @@ export const aztecStartOptions: { [key: string]: AztecStartOption[] } = {
{
flag: '--node.deployAztecContracts',
description: 'Deploys L1 Aztec contracts before starting the node. Needs mnemonic or private key to be set',
defaultValue: false,
envVar: 'DEPLOY_AZTEC_CONTRACTS',
parseVal: val => ['1', true].includes(val),
...booleanConfigHelper(),
},
{
flag: '--node.publisherPrivateKey <value>',
Expand All @@ -198,9 +200,8 @@ export const aztecStartOptions: { [key: string]: AztecStartOption[] } = {
{
flag: '--p2p-enabled',
description: 'Enable P2P subsystem',
defaultValue: false,
envVar: 'P2P_ENABLED',
parseVal: val => ['1', true].includes(val),
...booleanConfigHelper(),
},
...getOptions('p2p', p2pConfigMappings),
],
Expand Down
7 changes: 3 additions & 4 deletions yarn-project/bot/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Fr } from '@aztec/circuits.js';
import {
type ConfigMappingsType,
booleanConfigHelper,
getConfigFromMappings,
getDefaultConfig,
numberConfigHelper,
Expand Down Expand Up @@ -78,8 +79,7 @@ export const botConfigMappings: ConfigMappingsType<BotConfig> = {
noStart: {
env: 'BOT_NO_START',
description: 'True to not automatically setup or start the bot on initialization.',
parseEnv: val => ['1', 'true'].includes(val),
default: false,
...booleanConfigHelper(),
},
txMinedWaitSeconds: {
env: 'BOT_TX_MINED_WAIT_SECONDS',
Expand All @@ -89,8 +89,7 @@ export const botConfigMappings: ConfigMappingsType<BotConfig> = {
noWaitForTransfers: {
env: 'BOT_NO_WAIT_FOR_TRANSFERS',
description: "Don't wait for transfer transactions.",
parseEnv: val => ['1', 'true'].includes(val),
default: false,
...booleanConfigHelper(),
},
};

Expand Down
8 changes: 3 additions & 5 deletions yarn-project/circuit-types/src/interfaces/prover-client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type TxHash } from '@aztec/circuit-types';
import { Fr } from '@aztec/circuits.js';
import { type ConfigMappingsType, numberConfigHelper } from '@aztec/foundation/config';
import { type ConfigMappingsType, booleanConfigHelper, numberConfigHelper } from '@aztec/foundation/config';

import { type BlockProver } from './block-prover.js';
import { type MerkleTreeOperations } from './merkle_tree_operations.js';
Expand Down Expand Up @@ -37,15 +37,13 @@ export const proverConfigMappings: ConfigMappingsType<ProverConfig> = {
},
realProofs: {
env: 'PROVER_REAL_PROOFS',
parseEnv: (val: string) => ['1', 'true'].includes(val),
default: false,
description: 'Whether to construct real proofs',
...booleanConfigHelper(),
},
proverAgentEnabled: {
env: 'PROVER_AGENT_ENABLED',
parseEnv: (val: string) => ['1', 'true'].includes(val),
default: true,
description: 'Whether this prover has a local prover agent',
...booleanConfigHelper(true),
},
proverAgentPollInterval: {
env: 'PROVER_AGENT_POLL_INTERVAL_MS',
Expand Down
15 changes: 14 additions & 1 deletion yarn-project/foundation/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,26 @@ export function filterConfigMappings<T, K extends keyof T>(
* @param defaultVal - The default numerical value to use if the environment variable is not set or is invalid
* @returns Object with parseEnv and default values for a numerical config value
*/
export function numberConfigHelper(defaultVal: number): Partial<ConfigMapping> {
export function numberConfigHelper(defaultVal: number): Pick<ConfigMapping, 'parseEnv' | 'default'> {
return {
parseEnv: (val: string) => safeParseNumber(val, defaultVal),
default: defaultVal,
};
}

/**
* Generates parseEnv and default values for a boolean config value.
* @param defaultVal - The default value to use if the environment variable is not set or is invalid
* @returns Object with parseEnv and default values for a boolean config value
*/
export function booleanConfigHelper(defaultVal = false): Pick<ConfigMapping, 'parseEnv' | 'default' | 'isBoolean'> {
return {
parseEnv: (val: string) => ['1', 'true', 'TRUE'].includes(val),
default: defaultVal,
isBoolean: true,
};
}

/**
* Safely parses a number from a string.
* If the value is not a number or is not a safe integer, the default value is returned.
Expand Down
5 changes: 3 additions & 2 deletions yarn-project/p2p/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
type ConfigMappingsType,
booleanConfigHelper,
getConfigFromMappings,
numberConfigHelper,
pickConfigMappings,
Expand Down Expand Up @@ -91,8 +92,8 @@ export interface P2PConfig {
export const p2pConfigMappings: ConfigMappingsType<P2PConfig> = {
p2pEnabled: {
env: 'P2P_ENABLED',
parseEnv: (val: string) => ['1', 'true'].includes(val),
description: 'A flag dictating whether the P2P subsystem should be enabled.',
...booleanConfigHelper(),
},
blockCheckIntervalMS: {
env: 'P2P_BLOCK_CHECK_INTERVAL_MS',
Expand Down Expand Up @@ -161,7 +162,7 @@ export const p2pConfigMappings: ConfigMappingsType<P2PConfig> = {
env: 'P2P_QUERY_FOR_IP',
description:
'If announceUdpAddress or announceTcpAddress are not provided, query for the IP address of the machine. Default is false.',
parseEnv: (val: string) => ['1', 'true'].includes(val),
...booleanConfigHelper(),
},
keepProvenTxsInPoolFor: {
env: 'P2P_TX_POOL_KEEP_PROVEN_FOR',
Expand Down
5 changes: 2 additions & 3 deletions yarn-project/prover-client/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type ProverConfig, proverConfigMappings } from '@aztec/circuit-types';
import { type ConfigMappingsType, getConfigFromMappings } from '@aztec/foundation/config';
import { type ConfigMappingsType, booleanConfigHelper, getConfigFromMappings } from '@aztec/foundation/config';

/**
* The prover configuration.
Expand Down Expand Up @@ -36,9 +36,8 @@ export const proverClientConfigMappings: ConfigMappingsType<ProverClientConfig>
},
disableProver: {
env: 'PROVER_DISABLED',
parseEnv: (val: string) => ['1', 'true'].includes(val),
default: false,
description: 'Whether to disable proving.',
...booleanConfigHelper(),
},
...proverConfigMappings,
};
Expand Down
12 changes: 8 additions & 4 deletions yarn-project/pxe/src/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { INITIAL_L2_BLOCK_NUM } from '@aztec/circuits.js/constants';
import { type ConfigMappingsType, getConfigFromMappings, numberConfigHelper } from '@aztec/foundation/config';
import {
type ConfigMappingsType,
booleanConfigHelper,
getConfigFromMappings,
numberConfigHelper,
} from '@aztec/foundation/config';
import { type Network } from '@aztec/types/network';

import { readFileSync } from 'fs';
Expand Down Expand Up @@ -69,9 +74,8 @@ export const pxeConfigMappings: ConfigMappingsType<PXEServiceConfig> = {
},
proverEnabled: {
env: 'PXE_PROVER_ENABLED',
parseEnv: (val: string) => ['1', 'true'].includes(val),
description: 'Enable real proofs',
isBoolean: true,
...booleanConfigHelper(),
},
};

Expand Down Expand Up @@ -103,7 +107,7 @@ export const allPxeConfigMappings: ConfigMappingsType<CliPXEOptions & PXEService
...pxeCliConfigMappings,
proverEnabled: {
env: 'PXE_PROVER_ENABLED',
parseEnv: (val: string) => ['1', 'true'].includes(val) || !!process.env.NETWORK,
parseEnv: (val: string) => ['1', 'true', 'TRUE'].includes(val) || !!process.env.NETWORK,
description: 'Enable real proofs',
isBoolean: true,
},
Expand Down
11 changes: 8 additions & 3 deletions yarn-project/sequencer-client/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { type AllowedElement } from '@aztec/circuit-types';
import { AztecAddress, Fr, FunctionSelector, getContractClassFromArtifact } from '@aztec/circuits.js';
import { type L1ReaderConfig, l1ReaderConfigMappings } from '@aztec/ethereum';
import { type ConfigMappingsType, getConfigFromMappings, numberConfigHelper } from '@aztec/foundation/config';
import {
type ConfigMappingsType,
booleanConfigHelper,
getConfigFromMappings,
numberConfigHelper,
} from '@aztec/foundation/config';
import { EthAddress } from '@aztec/foundation/eth-address';
import { FPCContract } from '@aztec/noir-contracts.js/FPC';
import { TokenContractArtifact } from '@aztec/noir-contracts.js/Token';
Expand Down Expand Up @@ -96,13 +101,13 @@ export const sequencerConfigMappings: ConfigMappingsType<SequencerConfig> = {
},
enforceFees: {
env: 'ENFORCE_FEES',
parseEnv: (val: string) => ['1', 'true'].includes(val),
description: 'Whether to require every tx to have a fee payer',
...booleanConfigHelper(),
},
sequencerSkipSubmitProofs: {
env: 'SEQ_SKIP_SUBMIT_PROOFS',
parseEnv: (val: string) => ['1', 'true'].includes(val),
description: 'Temporary flag to skip submitting proofs, so a prover-node takes care of it.',
...booleanConfigHelper(),
},
};

Expand Down
5 changes: 2 additions & 3 deletions yarn-project/world-state/src/synchronizer/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type ConfigMappingsType, getConfigFromMappings } from '@aztec/foundation/config';
import { type ConfigMappingsType, booleanConfigHelper, getConfigFromMappings } from '@aztec/foundation/config';

/** World State synchronizer configuration values. */
export interface WorldStateConfig {
Expand Down Expand Up @@ -27,9 +27,8 @@ export const worldStateConfigMappings: ConfigMappingsType<WorldStateConfig> = {
},
worldStateProvenBlocksOnly: {
env: 'WS_PROVEN_BLOCKS_ONLY',
parseEnv: (val: string) => ['1', 'true'].includes(val),
default: false,
description: 'Whether to follow only the proven chain.',
...booleanConfigHelper(),
},
};

Expand Down

0 comments on commit 651a375

Please sign in to comment.