@aztec/aztec-node 0.0.1-commit.f295ac2 → 0.0.1-commit.f504929

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.
@@ -1,20 +1,15 @@
1
1
  import { Archiver, createArchiver } from '@aztec/archiver';
2
2
  import { BBCircuitVerifier, QueuedIVCVerifier, TestCircuitVerifier } from '@aztec/bb-prover';
3
3
  import { type BlobClientInterface, createBlobClientWithFileStores } from '@aztec/blob-client/client';
4
- import {
5
- ARCHIVE_HEIGHT,
6
- type L1_TO_L2_MSG_TREE_HEIGHT,
7
- type NOTE_HASH_TREE_HEIGHT,
8
- type NULLIFIER_TREE_HEIGHT,
9
- type PUBLIC_DATA_TREE_HEIGHT,
10
- } from '@aztec/constants';
4
+ import { Blob } from '@aztec/blob-lib';
5
+ import { ARCHIVE_HEIGHT, type L1_TO_L2_MSG_TREE_HEIGHT, type NOTE_HASH_TREE_HEIGHT } from '@aztec/constants';
11
6
  import { EpochCache, type EpochCacheInterface } from '@aztec/epoch-cache';
12
7
  import { createEthereumChain } from '@aztec/ethereum/chain';
13
8
  import { getPublicClient } from '@aztec/ethereum/client';
14
9
  import { RegistryContract, RollupContract } from '@aztec/ethereum/contracts';
15
10
  import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
16
11
  import { BlockNumber, CheckpointNumber, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
17
- import { compactArray, pick } from '@aztec/foundation/collection';
12
+ import { compactArray, pick, unique } from '@aztec/foundation/collection';
18
13
  import { Fr } from '@aztec/foundation/curves/bn254';
19
14
  import { EthAddress } from '@aztec/foundation/eth-address';
20
15
  import { BadRequestError } from '@aztec/foundation/json-rpc';
@@ -22,14 +17,19 @@ import { type Logger, createLogger } from '@aztec/foundation/log';
22
17
  import { count } from '@aztec/foundation/string';
23
18
  import { DateProvider, Timer } from '@aztec/foundation/timer';
24
19
  import { MembershipWitness, SiblingPath } from '@aztec/foundation/trees';
25
- import { KeystoreManager, loadKeystores, mergeKeystores } from '@aztec/node-keystore';
20
+ import { type KeyStore, KeystoreManager, loadKeystores, mergeKeystores } from '@aztec/node-keystore';
26
21
  import { trySnapshotSync, uploadSnapshot } from '@aztec/node-lib/actions';
22
+ import { createForwarderL1TxUtilsFromSigners, createL1TxUtilsFromSigners } from '@aztec/node-lib/factories';
27
23
  import {
28
- createForwarderL1TxUtilsFromEthSigner,
29
- createL1TxUtilsWithBlobsFromEthSigner,
30
- } from '@aztec/node-lib/factories';
31
- import { type P2P, type P2PClientDeps, createP2PClient, getDefaultAllowedSetupFunctions } from '@aztec/p2p';
24
+ type P2P,
25
+ type P2PClientDeps,
26
+ createP2PClient,
27
+ createTxValidatorForAcceptingTxsOverRPC,
28
+ getDefaultAllowedSetupFunctions,
29
+ } from '@aztec/p2p';
32
30
  import { ProtocolContractAddress } from '@aztec/protocol-contracts';
31
+ import { type ProverNode, type ProverNodeDeps, createProverNode } from '@aztec/prover-node';
32
+ import { createKeyStoreForProver } from '@aztec/prover-node/config';
33
33
  import { GlobalVariableBuilder, SequencerClient, type SequencerPublisher } from '@aztec/sequencer-client';
34
34
  import { PublicProcessorFactory } from '@aztec/simulator/server';
35
35
  import {
@@ -42,11 +42,11 @@ import {
42
42
  import { CollectionLimitsConfig, PublicSimulatorConfig } from '@aztec/stdlib/avm';
43
43
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
44
44
  import {
45
+ type BlockData,
46
+ BlockHash,
45
47
  type BlockParameter,
46
- type CheckpointedL2Block,
47
48
  type DataInBlock,
48
- L2BlockHash,
49
- L2BlockNew,
49
+ L2Block,
50
50
  type L2BlockSource,
51
51
  } from '@aztec/stdlib/block';
52
52
  import type { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
@@ -76,9 +76,9 @@ import {
76
76
  type WorldStateSynchronizer,
77
77
  tryStop,
78
78
  } from '@aztec/stdlib/interfaces/server';
79
- import type { LogFilter, SiloedTag, Tag, TxScopedL2Log } from '@aztec/stdlib/logs';
79
+ import type { DebugLogStore, LogFilter, SiloedTag, Tag, TxScopedL2Log } from '@aztec/stdlib/logs';
80
+ import { InMemoryDebugLogStore, NullDebugLogStore } from '@aztec/stdlib/logs';
80
81
  import { InboxLeaf, type L1ToL2MessageSource } from '@aztec/stdlib/messaging';
81
- import { P2PClientType } from '@aztec/stdlib/p2p';
82
82
  import type { Offense, SlashPayloadRound } from '@aztec/stdlib/slashing';
83
83
  import type { NullifierLeafPreimage, PublicDataTreeLeaf, PublicDataTreeLeafPreimage } from '@aztec/stdlib/trees';
84
84
  import { MerkleTreeId, NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
@@ -110,7 +110,6 @@ import {
110
110
  ValidatorClient,
111
111
  createBlockProposalHandler,
112
112
  createValidatorClient,
113
- createValidatorForAcceptingTxs,
114
113
  } from '@aztec/validator-client';
115
114
  import { createWorldStateSynchronizer } from '@aztec/world-state';
116
115
 
@@ -126,7 +125,7 @@ import { NodeMetrics } from './node_metrics.js';
126
125
  */
127
126
  export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
128
127
  private metrics: NodeMetrics;
129
- private initialHeaderHashPromise: Promise<L2BlockHash> | undefined = undefined;
128
+ private initialHeaderHashPromise: Promise<BlockHash> | undefined = undefined;
130
129
 
131
130
  // Prevent two snapshot operations to happen simultaneously
132
131
  private isUploadingSnapshot = false;
@@ -142,6 +141,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
142
141
  protected readonly l1ToL2MessageSource: L1ToL2MessageSource,
143
142
  protected readonly worldStateSynchronizer: WorldStateSynchronizer,
144
143
  protected readonly sequencer: SequencerClient | undefined,
144
+ protected readonly proverNode: ProverNode | undefined,
145
145
  protected readonly slasherClient: SlasherClientInterface | undefined,
146
146
  protected readonly validatorsSentinel: Sentinel | undefined,
147
147
  protected readonly epochPruneWatcher: EpochPruneWatcher | undefined,
@@ -154,12 +154,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
154
154
  private telemetry: TelemetryClient = getTelemetryClient(),
155
155
  private log = createLogger('node'),
156
156
  private blobClient?: BlobClientInterface,
157
+ private validatorClient?: ValidatorClient,
158
+ private keyStoreManager?: KeystoreManager,
159
+ private debugLogStore: DebugLogStore = new NullDebugLogStore(),
157
160
  ) {
158
161
  this.metrics = new NodeMetrics(telemetry, 'AztecNodeService');
159
162
  this.tracer = telemetry.getTracer('AztecNodeService');
160
163
 
161
164
  this.log.info(`Aztec Node version: ${this.packageVersion}`);
162
165
  this.log.info(`Aztec Node started on chain 0x${l1ChainId.toString(16)}`, config.l1Contracts);
166
+
167
+ // A defensive check that protects us against introducing a bug in the complex `createAndSync` function. We must
168
+ // never have debugLogStore enabled when not in test mode because then we would be accumulating debug logs in
169
+ // memory which could be a DoS vector on the sequencer (since no fees are paid for debug logs).
170
+ if (debugLogStore.isEnabled && config.realProofs) {
171
+ throw new Error('debugLogStore should never be enabled when realProofs are set');
172
+ }
163
173
  }
164
174
 
165
175
  public async getWorldStateSyncStatus(): Promise<WorldStateSyncStatus> {
@@ -183,11 +193,13 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
183
193
  logger?: Logger;
184
194
  publisher?: SequencerPublisher;
185
195
  dateProvider?: DateProvider;
186
- p2pClientDeps?: P2PClientDeps<P2PClientType.Full>;
196
+ p2pClientDeps?: P2PClientDeps;
197
+ proverNodeDeps?: Partial<ProverNodeDeps>;
187
198
  } = {},
188
199
  options: {
189
200
  prefilledPublicData?: PublicDataTreeLeaf[];
190
201
  dontStartSequencer?: boolean;
202
+ dontStartProverNode?: boolean;
191
203
  } = {},
192
204
  ): Promise<AztecNodeService> {
193
205
  const config = { ...inputConfig }; // Copy the config so we dont mutate the input object
@@ -197,16 +209,29 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
197
209
  const dateProvider = deps.dateProvider ?? new DateProvider();
198
210
  const ethereumChain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
199
211
 
200
- // Build a key store from file if given or from environment otherwise
212
+ // Build a key store from file if given or from environment otherwise.
213
+ // We keep the raw KeyStore available so we can merge with prover keys if enableProverNode is set.
201
214
  let keyStoreManager: KeystoreManager | undefined;
202
215
  const keyStoreProvided = config.keyStoreDirectory !== undefined && config.keyStoreDirectory.length > 0;
203
216
  if (keyStoreProvided) {
204
217
  const keyStores = loadKeystores(config.keyStoreDirectory!);
205
218
  keyStoreManager = new KeystoreManager(mergeKeystores(keyStores));
206
219
  } else {
207
- const keyStore = createKeyStoreForValidator(config);
208
- if (keyStore) {
209
- keyStoreManager = new KeystoreManager(keyStore);
220
+ const rawKeyStores: KeyStore[] = [];
221
+ const validatorKeyStore = createKeyStoreForValidator(config);
222
+ if (validatorKeyStore) {
223
+ rawKeyStores.push(validatorKeyStore);
224
+ }
225
+ if (config.enableProverNode) {
226
+ const proverKeyStore = createKeyStoreForProver(config);
227
+ if (proverKeyStore) {
228
+ rawKeyStores.push(proverKeyStore);
229
+ }
230
+ }
231
+ if (rawKeyStores.length > 0) {
232
+ keyStoreManager = new KeystoreManager(
233
+ rawKeyStores.length === 1 ? rawKeyStores[0] : mergeKeystores(rawKeyStores),
234
+ );
210
235
  }
211
236
  }
212
237
 
@@ -217,10 +242,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
217
242
  if (keyStoreManager === undefined) {
218
243
  throw new Error('Failed to create key store, a requirement for running a validator');
219
244
  }
220
- if (!keyStoreProvided) {
221
- log.warn(
222
- 'KEY STORE CREATED FROM ENVIRONMENT, IT IS RECOMMENDED TO USE A FILE-BASED KEY STORE IN PRODUCTION ENVIRONMENTS',
223
- );
245
+ if (!keyStoreProvided && process.env.NODE_ENV !== 'test') {
246
+ log.warn("Keystore created from env: it's recommended to use a file-based key store for production");
224
247
  }
225
248
  ValidatorClient.validateKeyStoreConfiguration(keyStoreManager, log);
226
249
  }
@@ -262,7 +285,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
262
285
  );
263
286
  }
264
287
 
265
- const blobClient = await createBlobClientWithFileStores(config, createLogger('node:blob-client:client'));
288
+ const blobClient = await createBlobClientWithFileStores(config, log.createChild('blob-client'));
266
289
 
267
290
  // attempt snapshot sync if possible
268
291
  await trySnapshotSync(config, log);
@@ -286,14 +309,28 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
286
309
  config.realProofs || config.debugForceTxProofVerification
287
310
  ? await BBCircuitVerifier.new(config)
288
311
  : new TestCircuitVerifier(config.proverTestVerificationDelayMs);
312
+
313
+ let debugLogStore: DebugLogStore;
289
314
  if (!config.realProofs) {
290
315
  log.warn(`Aztec node is accepting fake proofs`);
316
+
317
+ debugLogStore = new InMemoryDebugLogStore();
318
+ log.info(
319
+ 'Aztec node started in test mode (realProofs set to false) hence debug logs from public functions will be collected and served',
320
+ );
321
+ } else {
322
+ debugLogStore = new NullDebugLogStore();
291
323
  }
324
+
292
325
  const proofVerifier = new QueuedIVCVerifier(config, circuitVerifier);
293
326
 
327
+ const proverOnly = config.enableProverNode && config.disableValidator;
328
+ if (proverOnly) {
329
+ log.info('Starting in prover-only mode: skipping validator, sequencer, sentinel, and slasher subsystems');
330
+ }
331
+
294
332
  // create the tx pool and the p2p client, which will need the l2 block source
295
333
  const p2pClient = await createP2PClient(
296
- P2PClientType.Full,
297
334
  config,
298
335
  archiver,
299
336
  proofVerifier,
@@ -305,10 +342,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
305
342
  deps.p2pClientDeps,
306
343
  );
307
344
 
308
- // We should really not be modifying the config object
309
- config.txPublicSetupAllowList = config.txPublicSetupAllowList ?? (await getDefaultAllowedSetupFunctions());
345
+ // We'll accumulate sentinel watchers here
346
+ const watchers: Watcher[] = [];
310
347
 
311
- // Create FullNodeCheckpointsBuilder for validator and non-validator block proposal handling
348
+ // Create FullNodeCheckpointsBuilder for block proposal handling and tx validation
312
349
  const validatorCheckpointsBuilder = new FullNodeCheckpointsBuilder(
313
350
  { ...config, l1GenesisTime, slotDuration: Number(slotDuration) },
314
351
  worldStateSynchronizer,
@@ -317,47 +354,48 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
317
354
  telemetry,
318
355
  );
319
356
 
320
- // We'll accumulate sentinel watchers here
321
- const watchers: Watcher[] = [];
322
-
323
- // Create validator client if required
324
- const validatorClient = await createValidatorClient(config, {
325
- checkpointsBuilder: validatorCheckpointsBuilder,
326
- worldState: worldStateSynchronizer,
327
- p2pClient,
328
- telemetry,
329
- dateProvider,
330
- epochCache,
331
- blockSource: archiver,
332
- l1ToL2MessageSource: archiver,
333
- keyStoreManager,
334
- blobClient,
335
- });
357
+ let validatorClient: ValidatorClient | undefined;
336
358
 
337
- // If we have a validator client, register it as a source of offenses for the slasher,
338
- // and have it register callbacks on the p2p client *before* we start it, otherwise messages
339
- // like attestations or auths will fail.
340
- if (validatorClient) {
341
- watchers.push(validatorClient);
342
- if (!options.dontStartSequencer) {
343
- await validatorClient.registerHandlers();
344
- }
345
- }
346
-
347
- // If there's no validator client but alwaysReexecuteBlockProposals is enabled,
348
- // create a BlockProposalHandler to reexecute block proposals for monitoring
349
- if (!validatorClient && config.alwaysReexecuteBlockProposals) {
350
- log.info('Setting up block proposal reexecution for monitoring');
351
- createBlockProposalHandler(config, {
359
+ if (!proverOnly) {
360
+ // Create validator client if required
361
+ validatorClient = await createValidatorClient(config, {
352
362
  checkpointsBuilder: validatorCheckpointsBuilder,
353
363
  worldState: worldStateSynchronizer,
364
+ p2pClient,
365
+ telemetry,
366
+ dateProvider,
354
367
  epochCache,
355
368
  blockSource: archiver,
356
369
  l1ToL2MessageSource: archiver,
357
- p2pClient,
358
- dateProvider,
359
- telemetry,
360
- }).registerForReexecution(p2pClient);
370
+ keyStoreManager,
371
+ blobClient,
372
+ });
373
+
374
+ // If we have a validator client, register it as a source of offenses for the slasher,
375
+ // and have it register callbacks on the p2p client *before* we start it, otherwise messages
376
+ // like attestations or auths will fail.
377
+ if (validatorClient) {
378
+ watchers.push(validatorClient);
379
+ if (!options.dontStartSequencer) {
380
+ await validatorClient.registerHandlers();
381
+ }
382
+ }
383
+
384
+ // If there's no validator client but alwaysReexecuteBlockProposals is enabled,
385
+ // create a BlockProposalHandler to reexecute block proposals for monitoring
386
+ if (!validatorClient && config.alwaysReexecuteBlockProposals) {
387
+ log.info('Setting up block proposal reexecution for monitoring');
388
+ createBlockProposalHandler(config, {
389
+ checkpointsBuilder: validatorCheckpointsBuilder,
390
+ worldState: worldStateSynchronizer,
391
+ epochCache,
392
+ blockSource: archiver,
393
+ l1ToL2MessageSource: archiver,
394
+ p2pClient,
395
+ dateProvider,
396
+ telemetry,
397
+ }).registerForReexecution(p2pClient);
398
+ }
361
399
  }
362
400
 
363
401
  // Start world state and wait for it to sync to the archiver.
@@ -366,29 +404,33 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
366
404
  // Start p2p. Note that it depends on world state to be running.
367
405
  await p2pClient.start();
368
406
 
369
- const validatorsSentinel = await createSentinel(epochCache, archiver, p2pClient, config);
370
- if (validatorsSentinel && config.slashInactivityPenalty > 0n) {
371
- watchers.push(validatorsSentinel);
372
- }
373
-
407
+ let validatorsSentinel: Awaited<ReturnType<typeof createSentinel>> | undefined;
374
408
  let epochPruneWatcher: EpochPruneWatcher | undefined;
375
- if (config.slashPrunePenalty > 0n || config.slashDataWithholdingPenalty > 0n) {
376
- epochPruneWatcher = new EpochPruneWatcher(
377
- archiver,
378
- archiver,
379
- epochCache,
380
- p2pClient.getTxProvider(),
381
- validatorCheckpointsBuilder,
382
- config,
383
- );
384
- watchers.push(epochPruneWatcher);
385
- }
386
-
387
- // We assume we want to slash for invalid attestations unless all max penalties are set to 0
388
409
  let attestationsBlockWatcher: AttestationsBlockWatcher | undefined;
389
- if (config.slashProposeInvalidAttestationsPenalty > 0n || config.slashAttestDescendantOfInvalidPenalty > 0n) {
390
- attestationsBlockWatcher = new AttestationsBlockWatcher(archiver, epochCache, config);
391
- watchers.push(attestationsBlockWatcher);
410
+
411
+ if (!proverOnly) {
412
+ validatorsSentinel = await createSentinel(epochCache, archiver, p2pClient, config);
413
+ if (validatorsSentinel && config.slashInactivityPenalty > 0n) {
414
+ watchers.push(validatorsSentinel);
415
+ }
416
+
417
+ if (config.slashPrunePenalty > 0n || config.slashDataWithholdingPenalty > 0n) {
418
+ epochPruneWatcher = new EpochPruneWatcher(
419
+ archiver,
420
+ archiver,
421
+ epochCache,
422
+ p2pClient.getTxProvider(),
423
+ validatorCheckpointsBuilder,
424
+ config,
425
+ );
426
+ watchers.push(epochPruneWatcher);
427
+ }
428
+
429
+ // We assume we want to slash for invalid attestations unless all max penalties are set to 0
430
+ if (config.slashProposeInvalidAttestationsPenalty > 0n || config.slashAttestDescendantOfInvalidPenalty > 0n) {
431
+ attestationsBlockWatcher = new AttestationsBlockWatcher(archiver, epochCache, config);
432
+ watchers.push(attestationsBlockWatcher);
433
+ }
392
434
  }
393
435
 
394
436
  // Start p2p-related services once the archiver has completed sync
@@ -425,19 +467,19 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
425
467
  );
426
468
  await slasherClient.start();
427
469
 
428
- const l1TxUtils = config.publisherForwarderAddress
429
- ? await createForwarderL1TxUtilsFromEthSigner(
470
+ const l1TxUtils = config.sequencerPublisherForwarderAddress
471
+ ? await createForwarderL1TxUtilsFromSigners(
430
472
  publicClient,
431
473
  keyStoreManager!.createAllValidatorPublisherSigners(),
432
- config.publisherForwarderAddress,
474
+ config.sequencerPublisherForwarderAddress,
433
475
  { ...config, scope: 'sequencer' },
434
- { telemetry, logger: log.createChild('l1-tx-utils'), dateProvider },
476
+ { telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
435
477
  )
436
- : await createL1TxUtilsWithBlobsFromEthSigner(
478
+ : await createL1TxUtilsFromSigners(
437
479
  publicClient,
438
480
  keyStoreManager!.createAllValidatorPublisherSigners(),
439
481
  { ...config, scope: 'sequencer' },
440
- { telemetry, logger: log.createChild('l1-tx-utils'), dateProvider },
482
+ { telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
441
483
  );
442
484
 
443
485
  // Create and start the sequencer client
@@ -447,6 +489,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
447
489
  archiver,
448
490
  dateProvider,
449
491
  telemetry,
492
+ debugLogStore,
450
493
  );
451
494
 
452
495
  sequencer = await SequencerClient.new(config, {
@@ -474,6 +517,29 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
474
517
  log.warn(`Sequencer created but not started`);
475
518
  }
476
519
 
520
+ // Create prover node subsystem if enabled
521
+ let proverNode: ProverNode | undefined;
522
+ if (config.enableProverNode) {
523
+ proverNode = await createProverNode(config, {
524
+ ...deps.proverNodeDeps,
525
+ telemetry,
526
+ dateProvider,
527
+ archiver,
528
+ worldStateSynchronizer,
529
+ p2pClient,
530
+ epochCache,
531
+ blobClient,
532
+ keyStoreManager,
533
+ });
534
+
535
+ if (!options.dontStartProverNode) {
536
+ await proverNode.start();
537
+ log.info(`Prover node subsystem started`);
538
+ } else {
539
+ log.info(`Prover node subsystem created but not started`);
540
+ }
541
+ }
542
+
477
543
  const globalVariableBuilder = new GlobalVariableBuilder({
478
544
  ...config,
479
545
  rollupVersion: BigInt(config.rollupVersion),
@@ -481,7 +547,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
481
547
  slotDuration: Number(slotDuration),
482
548
  });
483
549
 
484
- return new AztecNodeService(
550
+ const node = new AztecNodeService(
485
551
  config,
486
552
  p2pClient,
487
553
  archiver,
@@ -490,6 +556,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
490
556
  archiver,
491
557
  worldStateSynchronizer,
492
558
  sequencer,
559
+ proverNode,
493
560
  slasherClient,
494
561
  validatorsSentinel,
495
562
  epochPruneWatcher,
@@ -502,7 +569,12 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
502
569
  telemetry,
503
570
  log,
504
571
  blobClient,
572
+ validatorClient,
573
+ keyStoreManager,
574
+ debugLogStore,
505
575
  );
576
+
577
+ return node;
506
578
  }
507
579
 
508
580
  /**
@@ -513,6 +585,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
513
585
  return this.sequencer;
514
586
  }
515
587
 
588
+ /** Returns the prover node subsystem, if enabled. */
589
+ public getProverNode(): ProverNode | undefined {
590
+ return this.proverNode;
591
+ }
592
+
516
593
  public getBlockSource(): L2BlockSource {
517
594
  return this.blockSource;
518
595
  }
@@ -538,7 +615,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
538
615
  }
539
616
 
540
617
  public async getAllowedPublicSetup(): Promise<AllowedElement[]> {
541
- return this.config.txPublicSetupAllowList ?? (await getDefaultAllowedSetupFunctions());
618
+ return [...(await getDefaultAllowedSetupFunctions()), ...(this.config.txPublicSetupAllowListExtend ?? [])];
542
619
  }
543
620
 
544
621
  /**
@@ -566,6 +643,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
566
643
  enr,
567
644
  l1ContractAddresses: contractAddresses,
568
645
  protocolContractAddresses: protocolContractAddresses,
646
+ realProofs: !!this.config.realProofs,
569
647
  };
570
648
 
571
649
  return nodeInfo;
@@ -576,15 +654,15 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
576
654
  * @param block - The block parameter (block number, block hash, or 'latest').
577
655
  * @returns The requested block.
578
656
  */
579
- public async getBlock(block: BlockParameter): Promise<L2BlockNew | undefined> {
580
- if (L2BlockHash.isL2BlockHash(block)) {
581
- return this.getBlockByHash(Fr.fromBuffer(block.toBuffer()));
657
+ public async getBlock(block: BlockParameter): Promise<L2Block | undefined> {
658
+ if (BlockHash.isBlockHash(block)) {
659
+ return this.getBlockByHash(block);
582
660
  }
583
661
  const blockNumber = block === 'latest' ? await this.getBlockNumber() : (block as BlockNumber);
584
662
  if (blockNumber === BlockNumber.ZERO) {
585
663
  return this.buildInitialBlock();
586
664
  }
587
- return await this.blockSource.getL2BlockNew(blockNumber);
665
+ return await this.blockSource.getL2Block(blockNumber);
588
666
  }
589
667
 
590
668
  /**
@@ -592,17 +670,17 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
592
670
  * @param blockHash - The block hash being requested.
593
671
  * @returns The requested block.
594
672
  */
595
- public async getBlockByHash(blockHash: Fr): Promise<L2BlockNew | undefined> {
673
+ public async getBlockByHash(blockHash: BlockHash): Promise<L2Block | undefined> {
596
674
  const initialBlockHash = await this.#getInitialHeaderHash();
597
- if (blockHash.equals(Fr.fromBuffer(initialBlockHash.toBuffer()))) {
675
+ if (blockHash.equals(initialBlockHash)) {
598
676
  return this.buildInitialBlock();
599
677
  }
600
- return await this.blockSource.getL2BlockNewByHash(blockHash);
678
+ return await this.blockSource.getL2BlockByHash(blockHash);
601
679
  }
602
680
 
603
- private buildInitialBlock(): L2BlockNew {
681
+ private buildInitialBlock(): L2Block {
604
682
  const initialHeader = this.worldStateSynchronizer.getCommitted().getInitialHeader();
605
- return L2BlockNew.empty(initialHeader);
683
+ return L2Block.empty(initialHeader);
606
684
  }
607
685
 
608
686
  /**
@@ -610,8 +688,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
610
688
  * @param archive - The archive root being requested.
611
689
  * @returns The requested block.
612
690
  */
613
- public async getBlockByArchive(archive: Fr): Promise<L2BlockNew | undefined> {
614
- return await this.blockSource.getL2BlockNewByArchive(archive);
691
+ public async getBlockByArchive(archive: Fr): Promise<L2Block | undefined> {
692
+ return await this.blockSource.getL2BlockByArchive(archive);
615
693
  }
616
694
 
617
695
  /**
@@ -620,24 +698,16 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
620
698
  * @param limit - The maximum number of blocks to obtain.
621
699
  * @returns The blocks requested.
622
700
  */
623
- public async getBlocks(from: BlockNumber, limit: number): Promise<L2BlockNew[]> {
624
- return (await this.blockSource.getL2BlocksNew(from, limit)) ?? [];
625
- }
626
-
627
- public async getPublishedBlocks(from: BlockNumber, limit: number): Promise<CheckpointedL2Block[]> {
628
- return (await this.blockSource.getPublishedBlocks(from, limit)) ?? [];
701
+ public async getBlocks(from: BlockNumber, limit: number): Promise<L2Block[]> {
702
+ return (await this.blockSource.getBlocks(from, BlockNumber(limit))) ?? [];
629
703
  }
630
704
 
631
- public async getPublishedCheckpoints(from: CheckpointNumber, limit: number): Promise<PublishedCheckpoint[]> {
632
- return (await this.blockSource.getPublishedCheckpoints(from, limit)) ?? [];
705
+ public async getCheckpoints(from: CheckpointNumber, limit: number): Promise<PublishedCheckpoint[]> {
706
+ return (await this.blockSource.getCheckpoints(from, limit)) ?? [];
633
707
  }
634
708
 
635
- public async getL2BlocksNew(from: BlockNumber, limit: number): Promise<L2BlockNew[]> {
636
- return (await this.blockSource.getL2BlocksNew(from, limit)) ?? [];
637
- }
638
-
639
- public async getCheckpointedBlocks(from: BlockNumber, limit: number, proven?: boolean) {
640
- return (await this.blockSource.getCheckpointedBlocks(from, limit, proven)) ?? [];
709
+ public async getCheckpointedBlocks(from: BlockNumber, limit: number) {
710
+ return (await this.blockSource.getCheckpointedBlocks(from, limit)) ?? [];
641
711
  }
642
712
 
643
713
  /**
@@ -668,6 +738,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
668
738
  return await this.blockSource.getProvenBlockNumber();
669
739
  }
670
740
 
741
+ public async getCheckpointedBlockNumber(): Promise<BlockNumber> {
742
+ return await this.blockSource.getCheckpointedL2BlockNumber();
743
+ }
744
+
671
745
  /**
672
746
  * Method to fetch the version of the package.
673
747
  * @returns The node package version
@@ -700,12 +774,43 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
700
774
  return this.contractDataSource.getContract(address);
701
775
  }
702
776
 
703
- public getPrivateLogsByTags(tags: SiloedTag[]): Promise<TxScopedL2Log[][]> {
704
- return this.logsSource.getPrivateLogsByTags(tags);
777
+ public async getPrivateLogsByTags(
778
+ tags: SiloedTag[],
779
+ page?: number,
780
+ referenceBlock?: BlockHash,
781
+ ): Promise<TxScopedL2Log[][]> {
782
+ if (referenceBlock) {
783
+ const initialBlockHash = await this.#getInitialHeaderHash();
784
+ if (!referenceBlock.equals(initialBlockHash)) {
785
+ const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
786
+ if (!header) {
787
+ throw new Error(
788
+ `Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
789
+ );
790
+ }
791
+ }
792
+ }
793
+ return this.logsSource.getPrivateLogsByTags(tags, page);
705
794
  }
706
795
 
707
- public getPublicLogsByTagsFromContract(contractAddress: AztecAddress, tags: Tag[]): Promise<TxScopedL2Log[][]> {
708
- return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags);
796
+ public async getPublicLogsByTagsFromContract(
797
+ contractAddress: AztecAddress,
798
+ tags: Tag[],
799
+ page?: number,
800
+ referenceBlock?: BlockHash,
801
+ ): Promise<TxScopedL2Log[][]> {
802
+ if (referenceBlock) {
803
+ const initialBlockHash = await this.#getInitialHeaderHash();
804
+ if (!referenceBlock.equals(initialBlockHash)) {
805
+ const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
806
+ if (!header) {
807
+ throw new Error(
808
+ `Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
809
+ );
810
+ }
811
+ }
812
+ }
813
+ return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page);
709
814
  }
710
815
 
711
816
  /**
@@ -747,26 +852,36 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
747
852
  }
748
853
 
749
854
  await this.p2pClient!.sendTx(tx);
750
- this.metrics.receivedTx(timer.ms(), true);
751
- this.log.info(`Received tx ${txHash}`, { txHash });
855
+ const duration = timer.ms();
856
+ this.metrics.receivedTx(duration, true);
857
+ this.log.info(`Received tx ${txHash} in ${duration}ms`, { txHash });
752
858
  }
753
859
 
754
860
  public async getTxReceipt(txHash: TxHash): Promise<TxReceipt> {
755
- let txReceipt = new TxReceipt(txHash, TxStatus.DROPPED, 'Tx dropped by P2P node.');
756
-
757
- // We first check if the tx is in pending (instead of first checking if it is mined) because if we first check
758
- // for mined and then for pending there could be a race condition where the tx is mined between the two checks
759
- // and we would incorrectly return a TxReceipt with status DROPPED
760
- if ((await this.p2pClient.getTxStatus(txHash)) === 'pending') {
761
- txReceipt = new TxReceipt(txHash, TxStatus.PENDING, '');
762
- }
861
+ // Check the tx pool status first. If the tx is known to the pool (pending or mined), we'll use that
862
+ // as a fallback if we don't find a settled receipt in the archiver.
863
+ const txPoolStatus = await this.p2pClient.getTxStatus(txHash);
864
+ const isKnownToPool = txPoolStatus === 'pending' || txPoolStatus === 'mined';
763
865
 
866
+ // Then get the actual tx from the archiver, which tracks every tx in a mined block.
764
867
  const settledTxReceipt = await this.blockSource.getSettledTxReceipt(txHash);
868
+
869
+ let receipt: TxReceipt;
765
870
  if (settledTxReceipt) {
766
- txReceipt = settledTxReceipt;
871
+ receipt = settledTxReceipt;
872
+ } else if (isKnownToPool) {
873
+ // If the tx is in the pool but not in the archiver, it's pending.
874
+ // This handles race conditions between archiver and p2p, where the archiver
875
+ // has pruned the block in which a tx was mined, but p2p has not caught up yet.
876
+ receipt = new TxReceipt(txHash, TxStatus.PENDING, undefined, undefined);
877
+ } else {
878
+ // Otherwise, if we don't know the tx, we consider it dropped.
879
+ receipt = new TxReceipt(txHash, TxStatus.DROPPED, undefined, 'Tx dropped by P2P node');
767
880
  }
768
881
 
769
- return txReceipt;
882
+ this.debugLogStore.decorateReceiptWithLogs(txHash.toString(), receipt);
883
+
884
+ return receipt;
770
885
  }
771
886
 
772
887
  public getTxEffect(txHash: TxHash): Promise<IndexedTxEffect | undefined> {
@@ -783,6 +898,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
783
898
  await tryStop(this.slasherClient);
784
899
  await tryStop(this.proofVerifier);
785
900
  await tryStop(this.sequencer);
901
+ await tryStop(this.proverNode);
786
902
  await tryStop(this.p2pClient);
787
903
  await tryStop(this.worldStateSynchronizer);
788
904
  await tryStop(this.blockSource);
@@ -832,11 +948,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
832
948
  }
833
949
 
834
950
  public async findLeavesIndexes(
835
- block: BlockParameter,
951
+ referenceBlock: BlockParameter,
836
952
  treeId: MerkleTreeId,
837
953
  leafValues: Fr[],
838
954
  ): Promise<(DataInBlock<bigint> | undefined)[]> {
839
- const committedDb = await this.#getWorldState(block);
955
+ const committedDb = await this.#getWorldState(referenceBlock);
840
956
  const maybeIndices = await committedDb.findLeafIndices(
841
957
  treeId,
842
958
  leafValues.map(x => x.toBuffer()),
@@ -888,44 +1004,28 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
888
1004
  }
889
1005
  return {
890
1006
  l2BlockNumber: BlockNumber(Number(blockNumber)),
891
- l2BlockHash: L2BlockHash.fromField(blockHash),
1007
+ l2BlockHash: new BlockHash(blockHash),
892
1008
  data: index,
893
1009
  };
894
1010
  });
895
1011
  }
896
1012
 
897
- public async getNullifierSiblingPath(
898
- block: BlockParameter,
899
- leafIndex: bigint,
900
- ): Promise<SiblingPath<typeof NULLIFIER_TREE_HEIGHT>> {
901
- const committedDb = await this.#getWorldState(block);
902
- return committedDb.getSiblingPath(MerkleTreeId.NULLIFIER_TREE, leafIndex);
903
- }
904
-
905
- public async getNoteHashSiblingPath(
906
- block: BlockParameter,
907
- leafIndex: bigint,
908
- ): Promise<SiblingPath<typeof NOTE_HASH_TREE_HEIGHT>> {
909
- const committedDb = await this.#getWorldState(block);
910
- return committedDb.getSiblingPath(MerkleTreeId.NOTE_HASH_TREE, leafIndex);
911
- }
912
-
913
- public async getArchiveMembershipWitness(
914
- block: BlockParameter,
915
- archive: Fr,
1013
+ public async getBlockHashMembershipWitness(
1014
+ referenceBlock: BlockParameter,
1015
+ blockHash: BlockHash,
916
1016
  ): Promise<MembershipWitness<typeof ARCHIVE_HEIGHT> | undefined> {
917
- const committedDb = await this.#getWorldState(block);
918
- const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.ARCHIVE>(MerkleTreeId.ARCHIVE, [archive]);
1017
+ const committedDb = await this.#getWorldState(referenceBlock);
1018
+ const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.ARCHIVE>(MerkleTreeId.ARCHIVE, [blockHash]);
919
1019
  return pathAndIndex === undefined
920
1020
  ? undefined
921
1021
  : MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
922
1022
  }
923
1023
 
924
1024
  public async getNoteHashMembershipWitness(
925
- block: BlockParameter,
1025
+ referenceBlock: BlockParameter,
926
1026
  noteHash: Fr,
927
1027
  ): Promise<MembershipWitness<typeof NOTE_HASH_TREE_HEIGHT> | undefined> {
928
- const committedDb = await this.#getWorldState(block);
1028
+ const committedDb = await this.#getWorldState(referenceBlock);
929
1029
  const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.NOTE_HASH_TREE>(
930
1030
  MerkleTreeId.NOTE_HASH_TREE,
931
1031
  [noteHash],
@@ -936,10 +1036,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
936
1036
  }
937
1037
 
938
1038
  public async getL1ToL2MessageMembershipWitness(
939
- block: BlockParameter,
1039
+ referenceBlock: BlockParameter,
940
1040
  l1ToL2Message: Fr,
941
1041
  ): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>] | undefined> {
942
- const db = await this.#getWorldState(block);
1042
+ const db = await this.#getWorldState(referenceBlock);
943
1043
  const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [l1ToL2Message]);
944
1044
  if (!witness) {
945
1045
  return undefined;
@@ -972,12 +1072,13 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
972
1072
  * @returns The L2 to L1 messages (empty array if the epoch is not found).
973
1073
  */
974
1074
  public async getL2ToL1Messages(epoch: EpochNumber): Promise<Fr[][][][]> {
975
- // Assumes `getBlocksForEpoch` returns blocks in ascending order of block number.
976
- const blocks = await this.blockSource.getBlocksForEpoch(epoch);
977
- const blocksInCheckpoints: L2BlockNew[][] = [];
1075
+ // Assumes `getCheckpointedBlocksForEpoch` returns blocks in ascending order of block number.
1076
+ const checkpointedBlocks = await this.blockSource.getCheckpointedBlocksForEpoch(epoch);
1077
+ const blocksInCheckpoints: L2Block[][] = [];
978
1078
  let previousSlotNumber = SlotNumber.ZERO;
979
1079
  let checkpointIndex = -1;
980
- for (const block of blocks) {
1080
+ for (const checkpointedBlock of checkpointedBlocks) {
1081
+ const block = checkpointedBlock.block;
981
1082
  const slotNumber = block.header.globalVariables.slotNumber;
982
1083
  if (slotNumber !== previousSlotNumber) {
983
1084
  checkpointIndex++;
@@ -991,27 +1092,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
991
1092
  );
992
1093
  }
993
1094
 
994
- public async getArchiveSiblingPath(
995
- block: BlockParameter,
996
- leafIndex: bigint,
997
- ): Promise<SiblingPath<typeof ARCHIVE_HEIGHT>> {
998
- const committedDb = await this.#getWorldState(block);
999
- return committedDb.getSiblingPath(MerkleTreeId.ARCHIVE, leafIndex);
1000
- }
1001
-
1002
- public async getPublicDataSiblingPath(
1003
- block: BlockParameter,
1004
- leafIndex: bigint,
1005
- ): Promise<SiblingPath<typeof PUBLIC_DATA_TREE_HEIGHT>> {
1006
- const committedDb = await this.#getWorldState(block);
1007
- return committedDb.getSiblingPath(MerkleTreeId.PUBLIC_DATA_TREE, leafIndex);
1008
- }
1009
-
1010
1095
  public async getNullifierMembershipWitness(
1011
- block: BlockParameter,
1096
+ referenceBlock: BlockParameter,
1012
1097
  nullifier: Fr,
1013
1098
  ): Promise<NullifierMembershipWitness | undefined> {
1014
- const db = await this.#getWorldState(block);
1099
+ const db = await this.#getWorldState(referenceBlock);
1015
1100
  const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [nullifier.toBuffer()]);
1016
1101
  if (!witness) {
1017
1102
  return undefined;
@@ -1028,7 +1113,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1028
1113
 
1029
1114
  /**
1030
1115
  * Returns a low nullifier membership witness for a given nullifier at a given block.
1031
- * @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
1116
+ * @param referenceBlock - The block parameter (block number, block hash, or 'latest') at which to get the data
1117
+ * (which contains the root of the nullifier tree in which we are searching for the nullifier).
1032
1118
  * @param nullifier - Nullifier we try to find the low nullifier witness for.
1033
1119
  * @returns The low nullifier membership witness (if found).
1034
1120
  * @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
@@ -1041,10 +1127,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1041
1127
  * TODO: This is a confusing behavior and we should eventually address that.
1042
1128
  */
1043
1129
  public async getLowNullifierMembershipWitness(
1044
- block: BlockParameter,
1130
+ referenceBlock: BlockParameter,
1045
1131
  nullifier: Fr,
1046
1132
  ): Promise<NullifierMembershipWitness | undefined> {
1047
- const committedDb = await this.#getWorldState(block);
1133
+ const committedDb = await this.#getWorldState(referenceBlock);
1048
1134
  const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
1049
1135
  if (!findResult) {
1050
1136
  return undefined;
@@ -1059,8 +1145,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1059
1145
  return new NullifierMembershipWitness(BigInt(index), preimageData as NullifierLeafPreimage, siblingPath);
1060
1146
  }
1061
1147
 
1062
- async getPublicDataWitness(block: BlockParameter, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
1063
- const committedDb = await this.#getWorldState(block);
1148
+ async getPublicDataWitness(referenceBlock: BlockParameter, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
1149
+ const committedDb = await this.#getWorldState(referenceBlock);
1064
1150
  const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
1065
1151
  if (!lowLeafResult) {
1066
1152
  return undefined;
@@ -1074,8 +1160,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1074
1160
  }
1075
1161
  }
1076
1162
 
1077
- public async getPublicStorageAt(block: BlockParameter, contract: AztecAddress, slot: Fr): Promise<Fr> {
1078
- const committedDb = await this.#getWorldState(block);
1163
+ public async getPublicStorageAt(referenceBlock: BlockParameter, contract: AztecAddress, slot: Fr): Promise<Fr> {
1164
+ const committedDb = await this.#getWorldState(referenceBlock);
1079
1165
  const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
1080
1166
 
1081
1167
  const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
@@ -1090,14 +1176,13 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1090
1176
  }
1091
1177
 
1092
1178
  public async getBlockHeader(block: BlockParameter = 'latest'): Promise<BlockHeader | undefined> {
1093
- if (L2BlockHash.isL2BlockHash(block)) {
1179
+ if (BlockHash.isBlockHash(block)) {
1094
1180
  const initialBlockHash = await this.#getInitialHeaderHash();
1095
1181
  if (block.equals(initialBlockHash)) {
1096
1182
  // Block source doesn't handle initial header so we need to handle the case separately.
1097
1183
  return this.worldStateSynchronizer.getCommitted().getInitialHeader();
1098
1184
  }
1099
- const blockHashFr = Fr.fromBuffer(block.toBuffer());
1100
- return this.blockSource.getBlockHeaderByHash(blockHashFr);
1185
+ return this.blockSource.getBlockHeaderByHash(block);
1101
1186
  } else {
1102
1187
  // Block source doesn't handle initial header so we need to handle the case separately.
1103
1188
  const blockNumber = block === 'latest' ? await this.getBlockNumber() : (block as BlockNumber);
@@ -1117,6 +1202,14 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1117
1202
  return await this.blockSource.getBlockHeaderByArchive(archive);
1118
1203
  }
1119
1204
 
1205
+ public getBlockData(number: BlockNumber): Promise<BlockData | undefined> {
1206
+ return this.blockSource.getBlockData(number);
1207
+ }
1208
+
1209
+ public getBlockDataByArchive(archive: Fr): Promise<BlockData | undefined> {
1210
+ return this.blockSource.getBlockDataByArchive(archive);
1211
+ }
1212
+
1120
1213
  /**
1121
1214
  * Simulates the public part of a transaction with the current state.
1122
1215
  * @param tx - The transaction to simulate.
@@ -1140,7 +1233,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1140
1233
  }
1141
1234
 
1142
1235
  const txHash = tx.getTxHash();
1143
- const blockNumber = BlockNumber((await this.blockSource.getBlockNumber()) + 1);
1236
+ const latestBlockNumber = await this.blockSource.getBlockNumber();
1237
+ const blockNumber = BlockNumber.add(latestBlockNumber, 1);
1144
1238
 
1145
1239
  // If sequencer is not initialized, we just set these values to zero for simulation.
1146
1240
  const coinbase = EthAddress.ZERO;
@@ -1155,6 +1249,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1155
1249
  this.contractDataSource,
1156
1250
  new DateProvider(),
1157
1251
  this.telemetry,
1252
+ this.log.getBindings(),
1158
1253
  );
1159
1254
 
1160
1255
  this.log.verbose(`Simulating public calls for tx ${txHash}`, {
@@ -1163,6 +1258,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1163
1258
  blockNumber,
1164
1259
  });
1165
1260
 
1261
+ // Ensure world-state has caught up with the latest block we loaded from the archiver
1262
+ await this.worldStateSynchronizer.syncImmediate(latestBlockNumber);
1166
1263
  const merkleTreeFork = await this.worldStateSynchronizer.fork();
1167
1264
  try {
1168
1265
  const config = PublicSimulatorConfig.from({
@@ -1178,7 +1275,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1178
1275
  const processor = publicProcessorFactory.create(merkleTreeFork, newGlobalVariables, config);
1179
1276
 
1180
1277
  // REFACTOR: Consider merging ProcessReturnValues into ProcessedTx
1181
- const [processedTxs, failedTxs, _usedTxs, returns] = await processor.process([tx]);
1278
+ const [processedTxs, failedTxs, _usedTxs, returns, _blobFields, debugLogs] = await processor.process([tx]);
1182
1279
  // REFACTOR: Consider returning the error rather than throwing
1183
1280
  if (failedTxs.length) {
1184
1281
  this.log.warn(`Simulated tx ${txHash} fails: ${failedTxs[0].error}`, { txHash });
@@ -1192,6 +1289,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1192
1289
  processedTx.txEffect,
1193
1290
  returns,
1194
1291
  processedTx.gasUsed,
1292
+ debugLogs,
1195
1293
  );
1196
1294
  } finally {
1197
1295
  await merkleTreeFork.close();
@@ -1205,19 +1303,28 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1205
1303
  const db = this.worldStateSynchronizer.getCommitted();
1206
1304
  const verifier = isSimulation ? undefined : this.proofVerifier;
1207
1305
 
1208
- // We accept transactions if they are not expired by the next slot (checked based on the IncludeByTimestamp field)
1306
+ // We accept transactions if they are not expired by the next slot (checked based on the ExpirationTimestamp field)
1209
1307
  const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
1210
1308
  const blockNumber = BlockNumber((await this.blockSource.getBlockNumber()) + 1);
1211
- const validator = createValidatorForAcceptingTxs(db, this.contractDataSource, verifier, {
1212
- timestamp: nextSlotTimestamp,
1213
- blockNumber,
1214
- l1ChainId: this.l1ChainId,
1215
- rollupVersion: this.version,
1216
- setupAllowList: this.config.txPublicSetupAllowList ?? (await getDefaultAllowedSetupFunctions()),
1217
- gasFees: await this.getCurrentMinFees(),
1218
- skipFeeEnforcement,
1219
- txsPermitted: !this.config.disableTransactions,
1220
- });
1309
+ const validator = createTxValidatorForAcceptingTxsOverRPC(
1310
+ db,
1311
+ this.contractDataSource,
1312
+ verifier,
1313
+ {
1314
+ timestamp: nextSlotTimestamp,
1315
+ blockNumber,
1316
+ l1ChainId: this.l1ChainId,
1317
+ rollupVersion: this.version,
1318
+ setupAllowList: [
1319
+ ...(await getDefaultAllowedSetupFunctions()),
1320
+ ...(this.config.txPublicSetupAllowListExtend ?? []),
1321
+ ],
1322
+ gasFees: await this.getCurrentMinFees(),
1323
+ skipFeeEnforcement,
1324
+ txsPermitted: !this.config.disableTransactions,
1325
+ },
1326
+ this.log.getBindings(),
1327
+ );
1221
1328
 
1222
1329
  return await validator.validateTx(tx);
1223
1330
  }
@@ -1381,13 +1488,97 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1381
1488
  }
1382
1489
  }
1383
1490
 
1384
- #getInitialHeaderHash(): Promise<L2BlockHash> {
1491
+ public async reloadKeystore(): Promise<void> {
1492
+ if (!this.config.keyStoreDirectory?.length) {
1493
+ throw new BadRequestError(
1494
+ 'Cannot reload keystore: node is not using a file-based keystore. ' +
1495
+ 'Set KEY_STORE_DIRECTORY to use file-based keystores.',
1496
+ );
1497
+ }
1498
+ if (!this.validatorClient) {
1499
+ throw new BadRequestError('Cannot reload keystore: validator is not enabled.');
1500
+ }
1501
+
1502
+ this.log.info('Reloading keystore from disk');
1503
+
1504
+ // Re-read and validate keystore files
1505
+ const keyStores = loadKeystores(this.config.keyStoreDirectory);
1506
+ const newManager = new KeystoreManager(mergeKeystores(keyStores));
1507
+ await newManager.validateSigners();
1508
+ ValidatorClient.validateKeyStoreConfiguration(newManager, this.log);
1509
+
1510
+ // Validate that every validator's publisher keys overlap with the L1 signers
1511
+ // that were initialized at startup. Publishers cannot be hot-reloaded, so a
1512
+ // validator with a publisher key that doesn't match any existing L1 signer
1513
+ // would silently fail on every proposer slot.
1514
+ if (this.keyStoreManager && this.sequencer) {
1515
+ const oldAdapter = NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager);
1516
+ const availablePublishers = new Set(
1517
+ oldAdapter
1518
+ .getAttesterAddresses()
1519
+ .flatMap(a => oldAdapter.getPublisherAddresses(a).map(p => p.toString().toLowerCase())),
1520
+ );
1521
+
1522
+ const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
1523
+ for (const attester of newAdapter.getAttesterAddresses()) {
1524
+ const pubs = newAdapter.getPublisherAddresses(attester);
1525
+ if (pubs.length > 0 && !pubs.some(p => availablePublishers.has(p.toString().toLowerCase()))) {
1526
+ throw new BadRequestError(
1527
+ `Cannot reload keystore: validator ${attester} has publisher keys ` +
1528
+ `[${pubs.map(p => p.toString()).join(', ')}] but none match the L1 signers initialized at startup ` +
1529
+ `[${[...availablePublishers].join(', ')}]. Publishers cannot be hot-reloaded — ` +
1530
+ `use an existing publisher key or restart the node.`,
1531
+ );
1532
+ }
1533
+ }
1534
+ }
1535
+
1536
+ // Build adapters for old and new keystores to compute diff
1537
+ const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
1538
+ const newAddresses = newAdapter.getAttesterAddresses();
1539
+ const oldAddresses = this.keyStoreManager
1540
+ ? NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager).getAttesterAddresses()
1541
+ : [];
1542
+
1543
+ const oldSet = new Set(oldAddresses.map(a => a.toString()));
1544
+ const newSet = new Set(newAddresses.map(a => a.toString()));
1545
+ const added = newAddresses.filter(a => !oldSet.has(a.toString()));
1546
+ const removed = oldAddresses.filter(a => !newSet.has(a.toString()));
1547
+
1548
+ if (added.length > 0) {
1549
+ this.log.info(`Keystore reload: adding attester keys: ${added.map(a => a.toString()).join(', ')}`);
1550
+ }
1551
+ if (removed.length > 0) {
1552
+ this.log.info(`Keystore reload: removing attester keys: ${removed.map(a => a.toString()).join(', ')}`);
1553
+ }
1554
+ if (added.length === 0 && removed.length === 0) {
1555
+ this.log.info('Keystore reload: attester keys unchanged');
1556
+ }
1557
+
1558
+ // Update the validator client (coinbase, feeRecipient, attester keys)
1559
+ this.validatorClient.reloadKeystore(newManager);
1560
+
1561
+ // Update the publisher factory's keystore so newly-added validators
1562
+ // can be matched to existing publisher keys when proposing blocks.
1563
+ if (this.sequencer) {
1564
+ this.sequencer.updatePublisherNodeKeyStore(newAdapter);
1565
+ }
1566
+
1567
+ // Update slasher's "don't-slash-self" list with new validator addresses
1568
+ if (this.slasherClient && !this.config.slashSelfAllowed) {
1569
+ const slashValidatorsNever = unique(
1570
+ [...(this.config.slashValidatorsNever ?? []), ...newAddresses].map(a => a.toString()),
1571
+ ).map(EthAddress.fromString);
1572
+ this.slasherClient.updateConfig({ slashValidatorsNever });
1573
+ }
1574
+
1575
+ this.keyStoreManager = newManager;
1576
+ this.log.info('Keystore reloaded: coinbase, feeRecipient, and attester keys updated');
1577
+ }
1578
+
1579
+ #getInitialHeaderHash(): Promise<BlockHash> {
1385
1580
  if (!this.initialHeaderHashPromise) {
1386
- this.initialHeaderHashPromise = this.worldStateSynchronizer
1387
- .getCommitted()
1388
- .getInitialHeader()
1389
- .hash()
1390
- .then(hash => L2BlockHash.fromField(hash));
1581
+ this.initialHeaderHashPromise = this.worldStateSynchronizer.getCommitted().getInitialHeader().hash();
1391
1582
  }
1392
1583
  return this.initialHeaderHashPromise;
1393
1584
  }
@@ -1411,15 +1602,14 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1411
1602
  return this.worldStateSynchronizer.getCommitted();
1412
1603
  }
1413
1604
 
1414
- if (L2BlockHash.isL2BlockHash(block)) {
1605
+ if (BlockHash.isBlockHash(block)) {
1415
1606
  const initialBlockHash = await this.#getInitialHeaderHash();
1416
1607
  if (block.equals(initialBlockHash)) {
1417
1608
  // Block source doesn't handle initial header so we need to handle the case separately.
1418
1609
  return this.worldStateSynchronizer.getSnapshot(BlockNumber.ZERO);
1419
1610
  }
1420
1611
 
1421
- const blockHashFr = Fr.fromBuffer(block.toBuffer());
1422
- const header = await this.blockSource.getBlockHeaderByHash(blockHashFr);
1612
+ const header = await this.blockSource.getBlockHeaderByHash(block);
1423
1613
  if (!header) {
1424
1614
  throw new Error(
1425
1615
  `Block hash ${block.toString()} not found when querying world state. If the node API has been queried with anchor block hash possibly a reorg has occurred.`,