diff --git a/yarn-project/aztec-node/src/aztec-node/config.ts b/yarn-project/aztec-node/src/aztec-node/config.ts index 79f705ab417..15ec2cf7048 100644 --- a/yarn-project/aztec-node/src/aztec-node/config.ts +++ b/yarn-project/aztec-node/src/aztec-node/config.ts @@ -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'; @@ -34,15 +34,13 @@ export const aztecNodeConfigMappings: ConfigMappingsType = { ...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(), }, }; diff --git a/yarn-project/aztec/src/cli/aztec_start_options.ts b/yarn-project/aztec/src/cli/aztec_start_options.ts index 5eafd33c650..e73acad5f61 100644 --- a/yarn-project/aztec/src/cli/aztec_start_options.ts +++ b/yarn-project/aztec/src/cli/aztec_start_options.ts @@ -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'; @@ -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: [ @@ -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 ', @@ -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), ], diff --git a/yarn-project/bot/src/config.ts b/yarn-project/bot/src/config.ts index 56623ae1634..86fe614b87d 100644 --- a/yarn-project/bot/src/config.ts +++ b/yarn-project/bot/src/config.ts @@ -1,6 +1,7 @@ import { Fr } from '@aztec/circuits.js'; import { type ConfigMappingsType, + booleanConfigHelper, getConfigFromMappings, getDefaultConfig, numberConfigHelper, @@ -78,8 +79,7 @@ export const botConfigMappings: ConfigMappingsType = { 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', @@ -89,8 +89,7 @@ export const botConfigMappings: ConfigMappingsType = { noWaitForTransfers: { env: 'BOT_NO_WAIT_FOR_TRANSFERS', description: "Don't wait for transfer transactions.", - parseEnv: val => ['1', 'true'].includes(val), - default: false, + ...booleanConfigHelper(), }, }; diff --git a/yarn-project/circuit-types/src/interfaces/prover-client.ts b/yarn-project/circuit-types/src/interfaces/prover-client.ts index 1bf302762a1..7e8aa848f4f 100644 --- a/yarn-project/circuit-types/src/interfaces/prover-client.ts +++ b/yarn-project/circuit-types/src/interfaces/prover-client.ts @@ -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'; @@ -37,15 +37,13 @@ export const proverConfigMappings: ConfigMappingsType = { }, 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', diff --git a/yarn-project/foundation/src/config/index.ts b/yarn-project/foundation/src/config/index.ts index 5c6bf1bdf19..3dac5808506 100644 --- a/yarn-project/foundation/src/config/index.ts +++ b/yarn-project/foundation/src/config/index.ts @@ -60,13 +60,26 @@ export function filterConfigMappings( * @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 { +export function numberConfigHelper(defaultVal: number): Pick { 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 { + 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. diff --git a/yarn-project/p2p/src/config.ts b/yarn-project/p2p/src/config.ts index 15aa326fc93..ed24e597578 100644 --- a/yarn-project/p2p/src/config.ts +++ b/yarn-project/p2p/src/config.ts @@ -1,5 +1,6 @@ import { type ConfigMappingsType, + booleanConfigHelper, getConfigFromMappings, numberConfigHelper, pickConfigMappings, @@ -91,8 +92,8 @@ export interface P2PConfig { export const p2pConfigMappings: ConfigMappingsType = { 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', @@ -161,7 +162,7 @@ export const p2pConfigMappings: ConfigMappingsType = { 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', diff --git a/yarn-project/prover-client/src/config.ts b/yarn-project/prover-client/src/config.ts index 89ad7b49da8..fb751c5c605 100644 --- a/yarn-project/prover-client/src/config.ts +++ b/yarn-project/prover-client/src/config.ts @@ -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. @@ -36,9 +36,8 @@ export const proverClientConfigMappings: ConfigMappingsType }, disableProver: { env: 'PROVER_DISABLED', - parseEnv: (val: string) => ['1', 'true'].includes(val), - default: false, description: 'Whether to disable proving.', + ...booleanConfigHelper(), }, ...proverConfigMappings, }; diff --git a/yarn-project/pxe/src/config/index.ts b/yarn-project/pxe/src/config/index.ts index be807ec3e5a..dbc82c4fa70 100644 --- a/yarn-project/pxe/src/config/index.ts +++ b/yarn-project/pxe/src/config/index.ts @@ -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'; @@ -69,9 +74,8 @@ export const pxeConfigMappings: ConfigMappingsType = { }, proverEnabled: { env: 'PXE_PROVER_ENABLED', - parseEnv: (val: string) => ['1', 'true'].includes(val), description: 'Enable real proofs', - isBoolean: true, + ...booleanConfigHelper(), }, }; @@ -103,7 +107,7 @@ export const allPxeConfigMappings: ConfigMappingsType ['1', 'true'].includes(val) || !!process.env.NETWORK, + parseEnv: (val: string) => ['1', 'true', 'TRUE'].includes(val) || !!process.env.NETWORK, description: 'Enable real proofs', isBoolean: true, }, diff --git a/yarn-project/sequencer-client/src/config.ts b/yarn-project/sequencer-client/src/config.ts index 1ff66343d93..6c692eb6905 100644 --- a/yarn-project/sequencer-client/src/config.ts +++ b/yarn-project/sequencer-client/src/config.ts @@ -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'; @@ -96,13 +101,13 @@ export const sequencerConfigMappings: ConfigMappingsType = { }, 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(), }, }; diff --git a/yarn-project/world-state/src/synchronizer/config.ts b/yarn-project/world-state/src/synchronizer/config.ts index c16e1236ae2..78666dd2566 100644 --- a/yarn-project/world-state/src/synchronizer/config.ts +++ b/yarn-project/world-state/src/synchronizer/config.ts @@ -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 { @@ -27,9 +27,8 @@ export const worldStateConfigMappings: ConfigMappingsType = { }, worldStateProvenBlocksOnly: { env: 'WS_PROVEN_BLOCKS_ONLY', - parseEnv: (val: string) => ['1', 'true'].includes(val), - default: false, description: 'Whether to follow only the proven chain.', + ...booleanConfigHelper(), }, };