@aztec-labs/aztec-node 6.0.0-nightly.20260829

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