@aztec/aztec-node 5.0.0-rc.1 → 5.0.0-rc.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/dest/aztec-node/config.d.ts +3 -1
  2. package/dest/aztec-node/config.d.ts.map +1 -1
  3. package/dest/aztec-node/config.js +5 -0
  4. package/dest/aztec-node/node_public_calls_simulator.d.ts +90 -0
  5. package/dest/aztec-node/node_public_calls_simulator.d.ts.map +1 -0
  6. package/dest/aztec-node/node_public_calls_simulator.js +346 -0
  7. package/dest/aztec-node/server.d.ts +68 -65
  8. package/dest/aztec-node/server.d.ts.map +1 -1
  9. package/dest/aztec-node/server.js +153 -1161
  10. package/dest/bin/index.js +2 -2
  11. package/dest/factory.d.ts +33 -0
  12. package/dest/factory.d.ts.map +1 -0
  13. package/dest/factory.js +496 -0
  14. package/dest/index.d.ts +2 -1
  15. package/dest/index.d.ts.map +1 -1
  16. package/dest/index.js +1 -0
  17. package/dest/modules/block_parameter.d.ts +25 -0
  18. package/dest/modules/block_parameter.d.ts.map +1 -0
  19. package/dest/modules/block_parameter.js +100 -0
  20. package/dest/modules/node_block_provider.d.ts +19 -0
  21. package/dest/modules/node_block_provider.d.ts.map +1 -0
  22. package/dest/modules/node_block_provider.js +112 -0
  23. package/dest/modules/node_tx_receipt.d.ts +24 -0
  24. package/dest/modules/node_tx_receipt.d.ts.map +1 -0
  25. package/dest/modules/node_tx_receipt.js +70 -0
  26. package/dest/modules/node_world_state_queries.d.ts +61 -0
  27. package/dest/modules/node_world_state_queries.d.ts.map +1 -0
  28. package/dest/modules/node_world_state_queries.js +257 -0
  29. package/dest/sentinel/factory.d.ts +3 -3
  30. package/dest/sentinel/factory.d.ts.map +1 -1
  31. package/dest/sentinel/factory.js +8 -1
  32. package/dest/sentinel/sentinel.d.ts +21 -21
  33. package/dest/sentinel/sentinel.d.ts.map +1 -1
  34. package/dest/sentinel/sentinel.js +27 -47
  35. package/package.json +28 -27
  36. package/src/aztec-node/config.ts +7 -0
  37. package/src/aztec-node/node_public_calls_simulator.ts +383 -0
  38. package/src/aztec-node/server.ts +221 -1342
  39. package/src/bin/index.ts +7 -2
  40. package/src/factory.ts +656 -0
  41. package/src/index.ts +1 -0
  42. package/src/modules/block_parameter.ts +93 -0
  43. package/src/modules/node_block_provider.ts +149 -0
  44. package/src/modules/node_tx_receipt.ts +115 -0
  45. package/src/modules/node_world_state_queries.ts +360 -0
  46. package/src/sentinel/README.md +3 -3
  47. package/src/sentinel/factory.ts +15 -3
  48. package/src/sentinel/sentinel.ts +34 -72
package/src/bin/index.ts CHANGED
@@ -7,7 +7,12 @@ import {
7
7
  import { createLogger } from '@aztec/foundation/log';
8
8
  import { getOtelJsonRpcPropagationMiddleware } from '@aztec/telemetry-client';
9
9
 
10
- import { type AztecNodeConfig, AztecNodeService, getConfigEnvVars, registerAztecNodeRpcHandlers } from '../index.js';
10
+ import {
11
+ type AztecNodeConfig,
12
+ createAztecNodeService,
13
+ getConfigEnvVars,
14
+ registerAztecNodeRpcHandlers,
15
+ } from '../index.js';
11
16
 
12
17
  const { AZTEC_NODE_PORT = 8081, API_PREFIX = '' } = process.env;
13
18
 
@@ -19,7 +24,7 @@ const logger = createLogger('node');
19
24
  async function createAndDeployAztecNode() {
20
25
  const aztecNodeConfig: AztecNodeConfig = { ...getConfigEnvVars() };
21
26
 
22
- return await AztecNodeService.createAndSync(aztecNodeConfig);
27
+ return await createAztecNodeService(aztecNodeConfig);
23
28
  }
24
29
 
25
30
  /**
package/src/factory.ts ADDED
@@ -0,0 +1,656 @@
1
+ import { createArchiver } from '@aztec/archiver';
2
+ import { BBCircuitVerifier, BatchChonkVerifier, QueuedIVCVerifier } from '@aztec/bb-prover';
3
+ import { TestCircuitVerifier } from '@aztec/bb-prover/test';
4
+ import { createBlobClientWithFileStores } from '@aztec/blob-client/client';
5
+ import { Blob } from '@aztec/blob-lib';
6
+ import { EpochCache } from '@aztec/epoch-cache';
7
+ import { createEthereumChain } from '@aztec/ethereum/chain';
8
+ import { getPublicClient, makeL1HttpTransport } from '@aztec/ethereum/client';
9
+ import { RegistryContract, RollupContract } from '@aztec/ethereum/contracts';
10
+ import { pickL1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
11
+ import type { L1TxUtils } from '@aztec/ethereum/l1-tx-utils';
12
+ import { compactArray } from '@aztec/foundation/collection';
13
+ import { type Logger, createLogger } from '@aztec/foundation/log';
14
+ import { DateProvider } from '@aztec/foundation/timer';
15
+ import { type KeyStore, KeystoreManager, loadKeystores, mergeKeystores } from '@aztec/node-keystore';
16
+ import { trySnapshotSync } from '@aztec/node-lib/actions';
17
+ import { createForwarderL1TxUtilsFromSigners, createL1TxUtilsFromSigners } from '@aztec/node-lib/factories';
18
+ import { type P2PClientDeps, createP2PClient } from '@aztec/p2p';
19
+ import { type ProverNode, type ProverNodeDeps, createProverNode } from '@aztec/prover-node';
20
+ import { createKeyStoreForProver } from '@aztec/prover-node/config';
21
+ import {
22
+ FeeProviderImpl,
23
+ GlobalVariableBuilder,
24
+ SequencerClient,
25
+ type SequencerPublisher,
26
+ } from '@aztec/sequencer-client';
27
+ import { type AutomineSequencer, createAutomineSequencer } from '@aztec/sequencer-client/automine';
28
+ import {
29
+ AttestationsBlockWatcher,
30
+ AttestedInvalidProposalWatcher,
31
+ BroadcastedInvalidCheckpointProposalWatcher,
32
+ CheckpointEquivocationWatcher,
33
+ DataWithholdingWatcher,
34
+ type SlasherClientInterface,
35
+ type Watcher,
36
+ createSlasher,
37
+ } from '@aztec/slasher';
38
+ import { CheckpointReexecutionTracker } from '@aztec/stdlib/checkpoint';
39
+ import { type ClientProtocolCircuitVerifier, tryStop } from '@aztec/stdlib/interfaces/server';
40
+ import { type DebugLogStore, InMemoryDebugLogStore, NullDebugLogStore } from '@aztec/stdlib/logs';
41
+ import { getPackageVersion } from '@aztec/stdlib/update-checker';
42
+ import type { GenesisData } from '@aztec/stdlib/world-state';
43
+ import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
44
+ import {
45
+ FullNodeCheckpointsBuilder as CheckpointsBuilder,
46
+ FullNodeCheckpointsBuilder,
47
+ NodeKeystoreAdapter,
48
+ type ProposalHandler,
49
+ ValidatorClient,
50
+ createProposalHandler,
51
+ createValidatorClient,
52
+ } from '@aztec/validator-client';
53
+ import type { SlashingProtectionDatabase } from '@aztec/validator-ha-signer/types';
54
+ import { createWorldState, createWorldStateSynchronizer } from '@aztec/world-state';
55
+
56
+ import { createPublicClient } from 'viem';
57
+
58
+ import { type AztecNodeConfig, createKeyStoreForValidator } from './aztec-node/config.js';
59
+ import { AztecNodeService } from './aztec-node/server.js';
60
+ import { createSentinel } from './sentinel/factory.js';
61
+
62
+ /** Dependencies that can be injected when creating a node, mostly to override defaults in tests. */
63
+ export interface CreateAztecNodeDeps {
64
+ telemetry?: TelemetryClient;
65
+ logger?: Logger;
66
+ publisher?: SequencerPublisher;
67
+ dateProvider?: DateProvider;
68
+ p2pClientDeps?: P2PClientDeps;
69
+ proverNodeDeps?: Partial<ProverNodeDeps>;
70
+ slashingProtectionDb?: SlashingProtectionDatabase;
71
+ }
72
+
73
+ /** Options controlling which subsystems are started when creating a node. */
74
+ export interface CreateAztecNodeOptions {
75
+ genesis?: GenesisData;
76
+ dontStartSequencer?: boolean;
77
+ dontStartProverNode?: boolean;
78
+ }
79
+
80
+ /**
81
+ * Initializes the Aztec Node, waiting for its components to sync.
82
+ * @param inputConfig - The configuration to be used by the aztec node.
83
+ * @returns A fully synced Aztec Node for use in development/testing.
84
+ */
85
+ export async function createAztecNodeService(
86
+ inputConfig: AztecNodeConfig,
87
+ deps: CreateAztecNodeDeps = {},
88
+ options: CreateAztecNodeOptions = {},
89
+ ): Promise<AztecNodeService> {
90
+ const config = { ...inputConfig }; // Copy the config so we dont mutate the input object
91
+ const log = deps.logger ?? createLogger('node');
92
+
93
+ // Initialise the bb.js sync WASM singleton here, before any subsystem runs.
94
+ const { BarretenbergSync } = await import('@aztec/bb.js');
95
+ await BarretenbergSync.initSingleton();
96
+
97
+ const packageVersion = getPackageVersion();
98
+ const telemetry = deps.telemetry ?? getTelemetryClient();
99
+ const dateProvider = deps.dateProvider ?? new DateProvider();
100
+ const ethereumChain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
101
+
102
+ // Build a key store from file if given or from environment otherwise.
103
+ // We keep the raw KeyStore available so we can merge with prover keys if enableProverNode is set.
104
+ let keyStoreManager: KeystoreManager | undefined;
105
+ const keyStoreProvided = config.keyStoreDirectory !== undefined && config.keyStoreDirectory.length > 0;
106
+ if (keyStoreProvided) {
107
+ const keyStores = loadKeystores(config.keyStoreDirectory!);
108
+ keyStoreManager = new KeystoreManager(mergeKeystores(keyStores));
109
+ } else {
110
+ const rawKeyStores: KeyStore[] = [];
111
+ const validatorKeyStore = createKeyStoreForValidator(config);
112
+ if (validatorKeyStore) {
113
+ rawKeyStores.push(validatorKeyStore);
114
+ }
115
+ if (config.enableProverNode) {
116
+ const proverKeyStore = createKeyStoreForProver(config);
117
+ if (proverKeyStore) {
118
+ rawKeyStores.push(proverKeyStore);
119
+ }
120
+ }
121
+ if (rawKeyStores.length > 0) {
122
+ keyStoreManager = new KeystoreManager(rawKeyStores.length === 1 ? rawKeyStores[0] : mergeKeystores(rawKeyStores));
123
+ }
124
+ }
125
+
126
+ await keyStoreManager?.validateSigners();
127
+
128
+ // If we are a validator, verify our configuration before doing too much more.
129
+ if (!config.disableValidator) {
130
+ if (keyStoreManager === undefined) {
131
+ throw new Error('Failed to create key store, a requirement for running a validator');
132
+ }
133
+ if (!keyStoreProvided && process.env.NODE_ENV !== 'test') {
134
+ log.warn("Keystore created from env: it's recommended to use a file-based key store for production");
135
+ }
136
+ ValidatorClient.validateKeyStoreConfiguration(keyStoreManager, log);
137
+ }
138
+
139
+ // validate that the actual chain id matches that specified in configuration
140
+ if (config.l1ChainId !== ethereumChain.chainInfo.id) {
141
+ throw new Error(
142
+ `RPC URL configured for chain id ${ethereumChain.chainInfo.id} but expected id ${config.l1ChainId}`,
143
+ );
144
+ }
145
+
146
+ const publicClient = createPublicClient({
147
+ chain: ethereumChain.chainInfo,
148
+ transport: makeL1HttpTransport(config.l1RpcUrls, { timeout: config.l1HttpTimeoutMS }),
149
+ pollingInterval: config.viemPollingIntervalMS,
150
+ });
151
+
152
+ const l1ContractsAddresses = await RegistryContract.collectAddresses(
153
+ publicClient,
154
+ config.registryAddress,
155
+ config.rollupVersion ?? 'canonical',
156
+ );
157
+
158
+ Object.assign(config, l1ContractsAddresses);
159
+
160
+ const rollupContract = new RollupContract(publicClient, config.rollupAddress.toString());
161
+ const [l1GenesisTime, slotDuration, epochDuration, rollupVersionFromRollup, rollupManaLimit] = await Promise.all([
162
+ rollupContract.getL1GenesisTime(),
163
+ rollupContract.getSlotDuration(),
164
+ rollupContract.getEpochDuration(),
165
+ rollupContract.getVersion(),
166
+ rollupContract.getManaLimit().then(Number),
167
+ ] as const);
168
+
169
+ config.rollupVersion ??= Number(rollupVersionFromRollup);
170
+
171
+ if (config.rollupVersion !== Number(rollupVersionFromRollup)) {
172
+ log.warn(
173
+ `Registry looked up and returned a rollup with version (${config.rollupVersion}), but this does not match with version detected from the rollup directly: (${rollupVersionFromRollup}).`,
174
+ );
175
+ }
176
+
177
+ const blobClient = await createBlobClientWithFileStores(config, log.createChild('blob-client'));
178
+
179
+ // attempt snapshot sync if possible
180
+ await trySnapshotSync(config, log);
181
+
182
+ const epochCache = await EpochCache.create(config.rollupAddress, config, { dateProvider });
183
+
184
+ // Track started resources so we can clean up on partial failure during node creation.
185
+ const started: { stop?(): Promise<void> | void }[] = [];
186
+ try {
187
+ config.skipOrphanProposedBlockPruning ||= !!config.useAutomineSequencer;
188
+
189
+ checkConfigMatchesRollup(config, {
190
+ slotDuration: Number(slotDuration),
191
+ epochDuration: Number(epochDuration),
192
+ });
193
+
194
+ // Create world-state first so we can retrieve the initial header before constructing the archiver.
195
+ const nativeWs = await createWorldState(config, options.genesis);
196
+ const initialHeader = nativeWs.getInitialHeader();
197
+ const initialBlockHash = await initialHeader.hash();
198
+ const archiver = await createArchiver(
199
+ config,
200
+ { blobClient, epochCache, telemetry, dateProvider },
201
+ { blockUntilSync: !config.skipArchiverInitialSync },
202
+ initialHeader,
203
+ initialBlockHash,
204
+ );
205
+ started.push(archiver);
206
+
207
+ // The synchronizer takes ownership of the native world-state from here
208
+ const worldStateSynchronizer = await createWorldStateSynchronizer(config, archiver, nativeWs, telemetry);
209
+ started.push(worldStateSynchronizer);
210
+ const useRealVerifiers = config.realProofs || config.debugForceTxProofVerification;
211
+ let peerProofVerifier: ClientProtocolCircuitVerifier;
212
+ let rpcProofVerifier: ClientProtocolCircuitVerifier;
213
+ if (useRealVerifiers) {
214
+ peerProofVerifier = await BatchChonkVerifier.new(config, config.bbChonkVerifyMaxBatch, 'peer');
215
+ const rpcVerifier = await BBCircuitVerifier.new(config);
216
+ rpcProofVerifier = new QueuedIVCVerifier(rpcVerifier, config.numConcurrentIVCVerifiers);
217
+ } else {
218
+ peerProofVerifier = new TestCircuitVerifier(config.proverTestVerificationDelayMs);
219
+ rpcProofVerifier = new TestCircuitVerifier(config.proverTestVerificationDelayMs);
220
+ }
221
+ started.push(peerProofVerifier, rpcProofVerifier);
222
+
223
+ let debugLogStore: DebugLogStore;
224
+ if (!config.realProofs) {
225
+ log.warn(`Aztec node is accepting fake proofs`);
226
+
227
+ debugLogStore = new InMemoryDebugLogStore();
228
+ log.info(
229
+ 'Aztec node started in test mode (realProofs set to false) hence debug logs from public functions will be collected and served',
230
+ );
231
+ } else {
232
+ debugLogStore = new NullDebugLogStore();
233
+ }
234
+
235
+ const globalVariableBuilderConfig = {
236
+ rollupAddress: config.rollupAddress,
237
+ ethereumSlotDuration: config.ethereumSlotDuration,
238
+ rollupVersion: BigInt(config.rollupVersion),
239
+ l1GenesisTime,
240
+ slotDuration: Number(slotDuration),
241
+ };
242
+
243
+ const globalVariableBuilder = new GlobalVariableBuilder(publicClient, globalVariableBuilderConfig);
244
+ const feeProvider = new FeeProviderImpl(dateProvider, publicClient, globalVariableBuilderConfig);
245
+
246
+ const collectOffenses = !config.disableValidator || config.enableOffenseCollection;
247
+
248
+ // create the tx pool and the p2p client, which will need the l2 block source
249
+ const p2pClient = await createP2PClient(
250
+ config,
251
+ archiver,
252
+ peerProofVerifier,
253
+ worldStateSynchronizer,
254
+ epochCache,
255
+ feeProvider,
256
+ packageVersion,
257
+ dateProvider,
258
+ telemetry,
259
+ deps.p2pClientDeps,
260
+ initialBlockHash,
261
+ );
262
+ started.push(p2pClient);
263
+ archiver.setCheckpointProposalPresence(p2pClient);
264
+
265
+ // We'll accumulate sentinel watchers here
266
+ const watchers: Watcher[] = [];
267
+
268
+ // Create FullNodeCheckpointsBuilder for block proposal handling and tx validation.
269
+ // Override maxTxsPerCheckpoint with the validator-specific limit if set.
270
+ const validatorCheckpointsBuilder = new FullNodeCheckpointsBuilder(
271
+ {
272
+ ...config,
273
+ l1GenesisTime,
274
+ slotDuration: Number(slotDuration),
275
+ rollupManaLimit,
276
+ maxTxsPerCheckpoint: config.validateMaxTxsPerCheckpoint,
277
+ },
278
+ worldStateSynchronizer,
279
+ archiver,
280
+ dateProvider,
281
+ telemetry,
282
+ );
283
+
284
+ let validatorClient: ValidatorClient | undefined;
285
+
286
+ // The proposal handler (validator-owned or standalone) tracks invalid-proposal/equivocation slots and
287
+ // feeds the attested-invalid-proposal watcher, so the watcher works on non-validator nodes too.
288
+ let proposalHandler: ProposalHandler | undefined;
289
+
290
+ // Tracks successful checkpoint re-execution by a checkpoint proposal handler.
291
+ const reexecutionTracker = new CheckpointReexecutionTracker();
292
+
293
+ if (!config.disableValidator) {
294
+ // Create validator client if required
295
+ validatorClient = await createValidatorClient(config, {
296
+ checkpointsBuilder: validatorCheckpointsBuilder,
297
+ worldState: worldStateSynchronizer,
298
+ p2pClient,
299
+ telemetry,
300
+ dateProvider,
301
+ epochCache,
302
+ blockSource: archiver,
303
+ l1ToL2MessageSource: archiver,
304
+ keyStoreManager,
305
+ blobClient,
306
+ reexecutionTracker,
307
+ slashingProtectionDb: deps.slashingProtectionDb,
308
+ });
309
+
310
+ // If we have a validator client, register it as a source of offenses for the slasher,
311
+ // and have it register callbacks on the p2p client *before* we start it, otherwise messages
312
+ // like attestations or auths will fail.
313
+ if (validatorClient) {
314
+ watchers.push(validatorClient);
315
+
316
+ const vc = validatorClient;
317
+ const getValidatorAddresses = () => vc.getValidatorAddresses().map(a => a.toString());
318
+ proposalHandler = validatorClient.getProposalHandler();
319
+ proposalHandler.register(p2pClient, true, archiver, getValidatorAddresses);
320
+
321
+ if (!options.dontStartSequencer) {
322
+ await validatorClient.registerHandlers();
323
+ }
324
+ }
325
+ }
326
+
327
+ // If there's no validator client, create a ProposalHandler to handle block and checkpoint proposals
328
+ // for monitoring or reexecution. Reexecution (default) allows us to follow the pending chain,
329
+ // while non-reexecution is used for validating the proposals and collecting their txs.
330
+ // Checkpoint proposals rebuild blobs if the blob client can upload blobs.
331
+ if (!validatorClient) {
332
+ const reexecute = !!config.alwaysReexecuteBlockProposals;
333
+ log.info(`Setting up proposal handler` + (reexecute ? ' with reexecution of proposals' : ''));
334
+ proposalHandler = createProposalHandler(config, {
335
+ checkpointsBuilder: validatorCheckpointsBuilder,
336
+ worldState: worldStateSynchronizer,
337
+ epochCache,
338
+ blockSource: archiver,
339
+ l1ToL2MessageSource: archiver,
340
+ p2pClient,
341
+ blobClient,
342
+ dateProvider,
343
+ telemetry,
344
+ reexecutionTracker,
345
+ });
346
+ proposalHandler.register(p2pClient, reexecute, archiver);
347
+ }
348
+
349
+ // Start world state and wait for it to sync to the archiver.
350
+ await worldStateSynchronizer.start();
351
+
352
+ // Start p2p. Note that it depends on world state to be running.
353
+ await p2pClient.start();
354
+
355
+ let dataWithholdingWatcher: DataWithholdingWatcher | undefined;
356
+ let attestationsBlockWatcher: AttestationsBlockWatcher | undefined;
357
+ let attestedInvalidProposalWatcher: AttestedInvalidProposalWatcher | undefined;
358
+ let broadcastedInvalidCheckpointProposalWatcher: BroadcastedInvalidCheckpointProposalWatcher | undefined;
359
+ let checkpointEquivocationWatcher: CheckpointEquivocationWatcher | undefined;
360
+
361
+ const validatorsSentinel = await createSentinel(epochCache, archiver, p2pClient, reexecutionTracker, config);
362
+ if (validatorsSentinel) {
363
+ watchers.push(validatorsSentinel);
364
+ }
365
+
366
+ if (collectOffenses) {
367
+ dataWithholdingWatcher = new DataWithholdingWatcher(
368
+ epochCache,
369
+ archiver,
370
+ p2pClient.getTxProvider(),
371
+ p2pClient,
372
+ reexecutionTracker,
373
+ { chainId: config.l1ChainId, rollupAddress: config.rollupAddress },
374
+ config,
375
+ );
376
+ watchers.push(dataWithholdingWatcher);
377
+
378
+ broadcastedInvalidCheckpointProposalWatcher = new BroadcastedInvalidCheckpointProposalWatcher(
379
+ p2pClient,
380
+ archiver,
381
+ epochCache,
382
+ config,
383
+ );
384
+ watchers.push(broadcastedInvalidCheckpointProposalWatcher);
385
+
386
+ // The proposal handler (validator-owned or standalone) is the source of invalid-proposal/equivocation
387
+ // slots, so the watcher runs on non-validator offense collectors too.
388
+ if (proposalHandler) {
389
+ attestedInvalidProposalWatcher = new AttestedInvalidProposalWatcher(
390
+ p2pClient,
391
+ proposalHandler,
392
+ archiver,
393
+ epochCache,
394
+ config,
395
+ { log: log.createChild('attested-invalid-proposal-watcher') },
396
+ );
397
+ watchers.push(attestedInvalidProposalWatcher);
398
+ }
399
+
400
+ checkpointEquivocationWatcher = new CheckpointEquivocationWatcher(archiver, epochCache, config);
401
+ watchers.push(checkpointEquivocationWatcher);
402
+
403
+ attestationsBlockWatcher = new AttestationsBlockWatcher(archiver, epochCache, config, log.getBindings());
404
+ watchers.push(attestationsBlockWatcher);
405
+ }
406
+
407
+ const watchersToStart = compactArray([
408
+ validatorsSentinel,
409
+ dataWithholdingWatcher,
410
+ attestationsBlockWatcher,
411
+ broadcastedInvalidCheckpointProposalWatcher,
412
+ attestedInvalidProposalWatcher,
413
+ checkpointEquivocationWatcher,
414
+ ]);
415
+ const startedWatchers: Watcher[] = [];
416
+ const stopStartedWatchers = async () => {
417
+ for (const watcher of startedWatchers) {
418
+ await tryStop(watcher);
419
+ }
420
+ };
421
+
422
+ // Start p2p-related services once the archiver has completed sync
423
+ void archiver
424
+ .waitForInitialSync()
425
+ .then(async () => {
426
+ for (const watcher of watchersToStart) {
427
+ await watcher.start();
428
+ startedWatchers.push(watcher);
429
+ }
430
+ log.info(`All p2p services started`);
431
+ })
432
+ .catch(err => log.error('Failed to start p2p services after archiver sync', err));
433
+ started.push({ stop: stopStartedWatchers });
434
+
435
+ // Validator enabled, create/start relevant service
436
+ let sequencer: SequencerClient | undefined;
437
+ let automineSequencer: AutomineSequencer | undefined;
438
+ let slasherClient: SlasherClientInterface | undefined;
439
+
440
+ // The slasher can run standalone to collect offenses for non-validators; it only writes to L1 when a
441
+ // proposer is elected (which requires a sequencer), so running it read-only on a non-validator is safe.
442
+ if (collectOffenses) {
443
+ const validatorAddresses = keyStoreManager
444
+ ? NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager).getAddresses()
445
+ : [];
446
+
447
+ slasherClient = await createSlasher(
448
+ config,
449
+ pickL1ContractAddresses(config),
450
+ getPublicClient(config),
451
+ watchers,
452
+ dateProvider,
453
+ epochCache,
454
+ validatorAddresses,
455
+ undefined, // logger
456
+ );
457
+ await slasherClient.start();
458
+ started.push(slasherClient);
459
+ }
460
+
461
+ if (!config.disableValidator && validatorClient) {
462
+ const l1TxUtils = config.sequencerPublisherForwarderAddress
463
+ ? await createForwarderL1TxUtilsFromSigners(
464
+ publicClient,
465
+ keyStoreManager!.createAllValidatorPublisherSigners(),
466
+ config.sequencerPublisherForwarderAddress,
467
+ { ...config, scope: 'sequencer' },
468
+ { telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
469
+ )
470
+ : await createL1TxUtilsFromSigners(
471
+ publicClient,
472
+ keyStoreManager!.createAllValidatorPublisherSigners(),
473
+ { ...config, scope: 'sequencer' },
474
+ { telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
475
+ );
476
+
477
+ // Create a funder L1TxUtils from the keystore funding account (if configured)
478
+ const fundingSigner = keyStoreManager?.createFundingSigner();
479
+ let funderL1TxUtils: L1TxUtils | undefined;
480
+ if (fundingSigner) {
481
+ const [funder] = await createL1TxUtilsFromSigners(
482
+ publicClient,
483
+ [fundingSigner],
484
+ { ...config, scope: 'sequencer' },
485
+ { telemetry, logger: log.createChild('l1-tx-utils:funder'), dateProvider },
486
+ );
487
+ funderL1TxUtils = funder;
488
+ }
489
+
490
+ // Create and start the sequencer client
491
+ const checkpointsBuilder = new CheckpointsBuilder(
492
+ { ...config, l1GenesisTime, slotDuration: Number(slotDuration), rollupManaLimit },
493
+ worldStateSynchronizer,
494
+ archiver,
495
+ dateProvider,
496
+ telemetry,
497
+ debugLogStore,
498
+ );
499
+
500
+ if (config.useAutomineSequencer) {
501
+ // Test-only path: deterministic, queue-driven sequencer for non-block-building e2e tests.
502
+ // See `AUTOMINE_E2E_OPTS` in `end-to-end/src/fixtures/fixtures.ts`.
503
+ automineSequencer = await createAutomineSequencer({
504
+ config,
505
+ l1TxUtils,
506
+ funderL1TxUtils,
507
+ publicClient,
508
+ rollupContract,
509
+ epochCache,
510
+ blobClient,
511
+ telemetry,
512
+ dateProvider,
513
+ keyStoreManager: keyStoreManager!,
514
+ validatorClient,
515
+ checkpointsBuilder,
516
+ globalVariableBuilder,
517
+ worldStateSynchronizer,
518
+ archiver,
519
+ p2pClient,
520
+ l1Constants: {
521
+ l1GenesisTime,
522
+ slotDuration: Number(slotDuration),
523
+ ethereumSlotDuration: config.ethereumSlotDuration,
524
+ rollupManaLimit,
525
+ },
526
+ autoSettle: config.automineEnableProveEpoch,
527
+ log,
528
+ });
529
+ } else {
530
+ sequencer = await SequencerClient.new(config, {
531
+ ...deps,
532
+ epochCache,
533
+ l1TxUtils,
534
+ funderL1TxUtils,
535
+ validatorClient,
536
+ p2pClient,
537
+ worldStateSynchronizer,
538
+ slasherClient,
539
+ checkpointsBuilder,
540
+ l2BlockSource: archiver,
541
+ l1ToL2MessageSource: archiver,
542
+ telemetry,
543
+ dateProvider,
544
+ blobClient,
545
+ nodeKeyStore: keyStoreManager!,
546
+ globalVariableBuilder,
547
+ });
548
+ }
549
+ }
550
+
551
+ if (!options.dontStartSequencer && sequencer) {
552
+ await sequencer.start();
553
+ started.push(sequencer);
554
+ log.verbose(`Sequencer started`);
555
+ } else if (sequencer) {
556
+ log.warn(`Sequencer created but not started`);
557
+ }
558
+
559
+ if (!options.dontStartSequencer && automineSequencer) {
560
+ await automineSequencer.start();
561
+ started.push({ stop: () => automineSequencer!.stop() });
562
+ log.verbose(`AutomineSequencer started`);
563
+ } else if (automineSequencer) {
564
+ log.warn(`AutomineSequencer created but not started`);
565
+ }
566
+
567
+ // Create prover node subsystem if enabled
568
+ let proverNode: ProverNode | undefined;
569
+ if (config.enableProverNode) {
570
+ proverNode = await createProverNode(config, {
571
+ ...deps.proverNodeDeps,
572
+ telemetry,
573
+ dateProvider,
574
+ archiver,
575
+ worldStateSynchronizer,
576
+ p2pClient,
577
+ epochCache,
578
+ blobClient,
579
+ keyStoreManager,
580
+ });
581
+
582
+ if (!options.dontStartProverNode) {
583
+ await proverNode.start();
584
+ started.push(proverNode);
585
+ log.info(`Prover node subsystem started`);
586
+ } else {
587
+ log.info(`Prover node subsystem created but not started`);
588
+ }
589
+ }
590
+
591
+ const node = new AztecNodeService({
592
+ config,
593
+ p2pClient,
594
+ blockSource: archiver,
595
+ logsSource: archiver,
596
+ contractDataSource: archiver,
597
+ l1ToL2MessageSource: archiver,
598
+ worldStateSynchronizer,
599
+ sequencer,
600
+ proverNode,
601
+ slasherClient,
602
+ validatorsSentinel,
603
+ stopStartedWatchers,
604
+ l1ChainId: ethereumChain.chainInfo.id,
605
+ version: config.rollupVersion,
606
+ globalVariableBuilder,
607
+ rollupContract,
608
+ feeProvider,
609
+ epochCache,
610
+ packageVersion,
611
+ peerProofVerifier,
612
+ rpcProofVerifier,
613
+ telemetry,
614
+ log,
615
+ blobClient,
616
+ validatorClient,
617
+ keyStoreManager,
618
+ debugLogStore,
619
+ automineSequencer,
620
+ });
621
+
622
+ return node;
623
+ } catch (err) {
624
+ log.error('Failed during node creation, stopping started resources', err);
625
+ for (const resource of started.reverse()) {
626
+ await tryStop(resource);
627
+ }
628
+ throw err;
629
+ }
630
+ }
631
+
632
+ /**
633
+ * Verifies the node's configured L1 timing matches the rollup contract it is pointed at, for the fields the
634
+ * node's own config carries. Each comparison is guarded against an undefined config value, so a config that
635
+ * does not carry a field is not checked. Throws a single error listing every mismatch. Runs in the shared
636
+ * startup path for every node role.
637
+ */
638
+ function checkConfigMatchesRollup(
639
+ config: AztecNodeConfig,
640
+ rollup: { slotDuration: number; epochDuration: number },
641
+ ): void {
642
+ const mismatches: string[] = [];
643
+ if (config.aztecSlotDuration !== undefined && config.aztecSlotDuration !== rollup.slotDuration) {
644
+ mismatches.push(`aztecSlotDuration is ${config.aztecSlotDuration} but the rollup reports ${rollup.slotDuration}`);
645
+ }
646
+ if (config.aztecEpochDuration !== undefined && config.aztecEpochDuration !== rollup.epochDuration) {
647
+ mismatches.push(
648
+ `aztecEpochDuration is ${config.aztecEpochDuration} but the rollup reports ${rollup.epochDuration}`,
649
+ );
650
+ }
651
+ if (mismatches.length > 0) {
652
+ throw new Error(
653
+ `The node's configured L1 timing does not match the rollup contract it is pointed at: ${mismatches.join('; ')}`,
654
+ );
655
+ }
656
+ }
package/src/index.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './aztec-node/config.js';
2
2
  export * from './aztec-node/register_node_rpc_handlers.js';
3
3
  export * from './aztec-node/server.js';
4
+ export * from './factory.js';