Skip to content

Commit cf63324

Browse files
authored
refactor(config): drop nested config option, flatten l1Contracts (#23143)
- Drop the `nested` field from `ConfigMapping` and the recursive branch in `getConfigFromMappings`. Env-var groups now have to be expressed as flat keys. - Flatten `l1Contracts` from every config that exposed it (`ChainConfig`, `DataStoreConfig`, `L1ReaderConfig`, `BaseSignerConfig`, `AztecNodeConfig`, archiver, etc.); L1 contract addresses are top-level keys everywhere. - Centralise the L1 address mapping in `ethereum/src/l1_contract_addresses.ts` and add `pickL1ContractAddressMappings`, `pickL1ContractAddressesSchema`, `pickL1ContractAddresses`, `randomL1ContractAddresses` so other configs can compose the addresses they need without reintroducing nesting. Fixes [A-986](https://linear.app/aztec-labs/issue/A-986/flatten-l1-contracts-config-remove-nested-top-level-mapping-entries)
1 parent 02265b1 commit cf63324

79 files changed

Lines changed: 327 additions & 371 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

yarn-project/archiver/src/config.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { type BlobClientConfig, blobClientConfigMapping } from '@aztec/blob-client/client/config';
22
import { type L1ContractsConfig, l1ContractsConfigMappings } from '@aztec/ethereum/config';
3-
import { l1ContractAddressesMapping } from '@aztec/ethereum/l1-contract-addresses';
43
import { type L1ReaderConfig, l1ReaderConfigMappings } from '@aztec/ethereum/l1-reader';
54
import {
65
type ConfigMappingsType,
@@ -87,10 +86,6 @@ export const archiverConfigMappings: ConfigMappingsType<ArchiverConfig> = {
8786
...numberConfigHelper(1000),
8887
},
8988
...l1ContractsConfigMappings,
90-
l1Contracts: {
91-
description: 'The deployed L1 contract addresses',
92-
nested: l1ContractAddressesMapping,
93-
},
9489
};
9590

9691
/**

yarn-project/archiver/src/factory.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { EpochCache } from '@aztec/epoch-cache';
22
import { createEthereumChain } from '@aztec/ethereum/chain';
33
import { makeL1HttpTransport } from '@aztec/ethereum/client';
44
import { InboxContract, RollupContract } from '@aztec/ethereum/contracts';
5+
import { pickL1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
56
import type { ViemPublicDebugClient } from '@aztec/ethereum/types';
67
import { BlockNumber } from '@aztec/foundation/branded-types';
78
import { Buffer32 } from '@aztec/foundation/buffer';
@@ -80,8 +81,8 @@ export async function createArchiver(
8081
}) as ViemPublicDebugClient;
8182

8283
// Create L1 contract instances
83-
const rollup = new RollupContract(publicClient, config.l1Contracts.rollupAddress);
84-
const inbox = new InboxContract(publicClient, config.l1Contracts.inboxAddress);
84+
const rollup = new RollupContract(publicClient, config.rollupAddress);
85+
const inbox = new InboxContract(publicClient, config.inboxAddress);
8586

8687
// Fetch L1 constants from rollup contract
8788
const [
@@ -132,7 +133,7 @@ export async function createArchiver(
132133
mapArchiverConfig(config),
133134
);
134135

135-
const epochCache = deps.epochCache ?? (await EpochCache.create(config.l1Contracts.rollupAddress, config, deps));
136+
const epochCache = deps.epochCache ?? (await EpochCache.create(config.rollupAddress, config, deps));
136137
const telemetry = deps.telemetry ?? getTelemetryClient();
137138
const instrumentation = await ArchiverInstrumentation.new(telemetry, () => archiverStore.db.estimateSize());
138139

@@ -167,7 +168,7 @@ export async function createArchiver(
167168
publicClient,
168169
debugClient,
169170
rollup,
170-
{ ...config.l1Contracts, slashingProposerAddress },
171+
{ ...pickL1ContractAddresses(config), slashingProposerAddress },
171172
archiverStore,
172173
archiverConfig,
173174
deps.blobClient,

yarn-project/aztec-node/src/aztec-node/config.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ describe('createKeyStoreForValidator', () => {
5252
web3SignerUrl,
5353
validatorAddresses: validatorAddresses.map(addr => addr),
5454
sequencerPublisherAddresses: publisherAddresses.map(addr => addr),
55-
l1Contracts: { rollupAddress: EthAddress.random() },
55+
rollupAddress: EthAddress.random(),
5656
} as SequencerTxSenderConfig & ValidatorClientConfig & SequencerClientConfig & SharedNodeConfig;
5757
};
5858

@@ -72,7 +72,7 @@ describe('createKeyStoreForValidator', () => {
7272
sequencerPublisherPrivateKeys: undefined,
7373
coinbase: undefined,
7474
feeRecipient: undefined,
75-
l1Contracts: { rollupAddress: EthAddress.random() },
75+
rollupAddress: EthAddress.random(),
7676
} as unknown as SequencerTxSenderConfig & ValidatorClientConfig & SequencerClientConfig & SharedNodeConfig;
7777
const result = createKeyStoreForValidator(config);
7878
expect(result).toBeUndefined();

yarn-project/aztec-node/src/aztec-node/config.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { type ArchiverConfig, archiverConfigMappings } from '@aztec/archiver/config';
22
import { type GenesisStateConfig, genesisStateConfigMappings } from '@aztec/ethereum/config';
3-
import { type L1ContractAddresses, l1ContractAddressesMapping } from '@aztec/ethereum/l1-contract-addresses';
43
import { type ConfigMappingsType, booleanConfigHelper, getConfigFromMappings } from '@aztec/foundation/config';
54
import { EthAddress } from '@aztec/foundation/eth-address';
65
import {
@@ -53,8 +52,6 @@ export type AztecNodeConfig = ArchiverConfig &
5352
NodeRPCConfig &
5453
SlasherConfig &
5554
ProverNodeConfig & {
56-
/** L1 contracts addresses */
57-
l1Contracts: L1ContractAddresses;
5855
/** Whether the validator is disabled for this node */
5956
disableValidator: boolean;
6057
/** Whether to skip waiting for the archiver to be fully synced before starting other services */
@@ -81,10 +78,6 @@ export const aztecNodeConfigMappings: ConfigMappingsType<AztecNodeConfig> = {
8178
...nodeRpcConfigMappings,
8279
...slasherConfigMappings,
8380
...specificProverNodeConfigMappings,
84-
l1Contracts: {
85-
description: 'The deployed L1 contract addresses',
86-
nested: l1ContractAddressesMapping,
87-
},
8881
disableValidator: {
8982
env: 'VALIDATOR_DISABLED',
9083
description: 'Whether the validator is disabled for this node.',

yarn-project/aztec-node/src/aztec-node/server.test.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,10 @@ describe('aztec node', () => {
191191
const nodeConfigFromEnvVars: AztecNodeConfig = getConfigEnvVars();
192192
nodeConfig = {
193193
...nodeConfigFromEnvVars,
194-
l1Contracts: {
195-
...nodeConfigFromEnvVars.l1Contracts,
196-
rollupAddress: EthAddress.ZERO,
197-
registryAddress: EthAddress.ZERO,
198-
inboxAddress: EthAddress.ZERO,
199-
outboxAddress: EthAddress.ZERO,
200-
},
194+
rollupAddress: EthAddress.ZERO,
195+
registryAddress: EthAddress.ZERO,
196+
inboxAddress: EthAddress.ZERO,
197+
outboxAddress: EthAddress.ZERO,
201198
};
202199

203200
// Inject a spurious config value to test that the config is correctly picked up

yarn-project/aztec-node/src/aztec-node/server.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { EpochCache, type EpochCacheInterface } from '@aztec/epoch-cache';
88
import { createEthereumChain } from '@aztec/ethereum/chain';
99
import { getPublicClient, makeL1HttpTransport } from '@aztec/ethereum/client';
1010
import { RegistryContract, RollupContract } from '@aztec/ethereum/contracts';
11-
import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
11+
import { type L1ContractAddresses, pickL1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
1212
import type { L1TxUtils } from '@aztec/ethereum/l1-tx-utils';
1313
import { BlockNumber, CheckpointNumber, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
1414
import { chunkBy, compactArray, pick, unique } from '@aztec/foundation/collection';
@@ -195,7 +195,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, AztecNodeDeb
195195
this.tracer = telemetry.getTracer('AztecNodeService');
196196

197197
this.log.info(`Aztec Node version: ${this.packageVersion}`);
198-
this.log.info(`Aztec Node started on chain 0x${l1ChainId.toString(16)}`, config.l1Contracts);
198+
this.log.info(`Aztec Node started on chain 0x${l1ChainId.toString(16)}`, pickL1ContractAddresses(config));
199199

200200
// A defensive check that protects us against introducing a bug in the complex `createAndSync` function. We must
201201
// never have debugLogStore enabled when not in test mode because then we would be accumulating debug logs in
@@ -533,14 +533,13 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, AztecNodeDeb
533533

534534
const l1ContractsAddresses = await RegistryContract.collectAddresses(
535535
publicClient,
536-
config.l1Contracts.registryAddress,
536+
config.registryAddress,
537537
config.rollupVersion ?? 'canonical',
538538
);
539539

540-
// Overwrite the passed in vars.
541-
config.l1Contracts = { ...config.l1Contracts, ...l1ContractsAddresses };
540+
Object.assign(config, l1ContractsAddresses);
542541

543-
const rollupContract = new RollupContract(publicClient, config.l1Contracts.rollupAddress.toString());
542+
const rollupContract = new RollupContract(publicClient, config.rollupAddress.toString());
544543
const [l1GenesisTime, slotDuration, rollupVersionFromRollup, rollupManaLimit] = await Promise.all([
545544
rollupContract.getL1GenesisTime(),
546545
rollupContract.getSlotDuration(),
@@ -561,7 +560,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, AztecNodeDeb
561560
// attempt snapshot sync if possible
562561
await trySnapshotSync(config, log);
563562

564-
const epochCache = await EpochCache.create(config.l1Contracts.rollupAddress, config, { dateProvider });
563+
const epochCache = await EpochCache.create(config.rollupAddress, config, { dateProvider });
565564

566565
// Track started resources so we can clean up on partial failure during node creation.
567566
const started: { stop?(): Promise<void> | void }[] = [];
@@ -608,7 +607,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, AztecNodeDeb
608607
}
609608

610609
const globalVariableBuilderConfig = {
611-
l1Contracts: config.l1Contracts,
610+
rollupAddress: config.rollupAddress,
612611
ethereumSlotDuration: config.ethereumSlotDuration,
613612
rollupVersion: BigInt(config.rollupVersion),
614613
l1GenesisTime,
@@ -779,7 +778,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, AztecNodeDeb
779778

780779
slasherClient = await createSlasher(
781780
config,
782-
config.l1Contracts,
781+
pickL1ContractAddresses(config),
783782
getPublicClient(config),
784783
watchers,
785784
dateProvider,
@@ -950,7 +949,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, AztecNodeDeb
950949
* @returns - The currently deployed L1 contract addresses.
951950
*/
952951
public getL1ContractAddresses(): Promise<L1ContractAddresses> {
953-
return Promise.resolve(this.config.l1Contracts);
952+
return Promise.resolve(pickL1ContractAddresses(this.config));
954953
}
955954

956955
public getEncodedEnr(): Promise<string | undefined> {

yarn-project/aztec-node/src/sentinel/factory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export async function createSentinel(
1515
epochCache: EpochCache,
1616
archiver: L2BlockSource,
1717
p2p: P2PClient,
18-
config: SentinelConfig & DataStoreConfig & SlasherConfig & Pick<ChainConfig, 'l1ChainId' | 'l1Contracts'>,
18+
config: SentinelConfig & DataStoreConfig & SlasherConfig & Pick<ChainConfig, 'l1ChainId' | 'rollupAddress'>,
1919
logger = createLogger('node:sentinel'),
2020
): Promise<Sentinel | undefined> {
2121
if (!config.sentinelEnabled) {

yarn-project/aztec-node/src/sentinel/sentinel.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ describe('sentinel', () => {
5656
slashInactivityTargetPercentage: 0.8,
5757
slashInactivityConsecutiveEpochThreshold: 1,
5858
l1ChainId: TEST_COORDINATION_SIGNATURE_CONTEXT.chainId,
59-
l1Contracts: { rollupAddress: TEST_COORDINATION_SIGNATURE_CONTEXT.rollupAddress },
59+
rollupAddress: TEST_COORDINATION_SIGNATURE_CONTEXT.rollupAddress,
6060
};
6161

6262
beforeEach(async () => {

yarn-project/aztec-node/src/sentinel/sentinel.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export type SentinelRuntimeConfig = Pick<
4848
SlasherConfig,
4949
'slashInactivityTargetPercentage' | 'slashInactivityPenalty' | 'slashInactivityConsecutiveEpochThreshold'
5050
> &
51-
Pick<ChainConfig, 'l1ChainId' | 'l1Contracts'>;
51+
Pick<ChainConfig, 'l1ChainId' | 'rollupAddress'>;
5252

5353
/** Maps a validator status to its category: proposer or attestation. */
5454
function statusToCategory(status: ValidatorStatusInSlot): ValidatorStatusType {
@@ -96,7 +96,7 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
9696
private getSignatureContext(): CoordinationSignatureContext {
9797
return {
9898
chainId: this.config.l1ChainId,
99-
rollupAddress: this.config.l1Contracts.rollupAddress,
99+
rollupAddress: this.config.rollupAddress,
100100
};
101101
}
102102

yarn-project/aztec/src/cli/cmds/standby.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export async function waitForCompatibleRollup(
6767
config: {
6868
l1RpcUrls: string[];
6969
l1ChainId: number;
70-
l1Contracts: { registryAddress: EthAddress };
70+
registryAddress: EthAddress;
7171
rollupVersion?: number;
7272
},
7373
expected: { genesisArchiveRoot: Fr; vkTreeRoot: Fr; protocolContractsHash: Fr },
@@ -77,7 +77,7 @@ export async function waitForCompatibleRollup(
7777
const publicClient = getPublicClient(config);
7878
const rollupVersion: number | 'canonical' = config.rollupVersion ?? 'canonical';
7979

80-
const registry = new RegistryContract(publicClient, config.l1Contracts.registryAddress);
80+
const registry = new RegistryContract(publicClient, config.registryAddress);
8181
const rollupAddress = await registry.getRollupAddress(rollupVersion);
8282
const rollup = new RollupContract(publicClient, rollupAddress.toString());
8383

0 commit comments

Comments
 (0)