@aztec/aztec-node 0.0.1-commit.d431d1c → 0.0.1-commit.dbf9cec

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,
@@ -308,7 +345,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
308
345
  // We should really not be modifying the config object
309
346
  config.txPublicSetupAllowList = config.txPublicSetupAllowList ?? (await getDefaultAllowedSetupFunctions());
310
347
 
311
- // Create FullNodeCheckpointsBuilder for validator and non-validator block proposal handling
348
+ // We'll accumulate sentinel watchers here
349
+ const watchers: Watcher[] = [];
350
+
351
+ // Create FullNodeCheckpointsBuilder for block proposal handling and tx validation
312
352
  const validatorCheckpointsBuilder = new FullNodeCheckpointsBuilder(
313
353
  { ...config, l1GenesisTime, slotDuration: Number(slotDuration) },
314
354
  worldStateSynchronizer,
@@ -317,47 +357,48 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
317
357
  telemetry,
318
358
  );
319
359
 
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
- });
360
+ let validatorClient: ValidatorClient | undefined;
336
361
 
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, {
362
+ if (!proverOnly) {
363
+ // Create validator client if required
364
+ validatorClient = await createValidatorClient(config, {
352
365
  checkpointsBuilder: validatorCheckpointsBuilder,
353
366
  worldState: worldStateSynchronizer,
367
+ p2pClient,
368
+ telemetry,
369
+ dateProvider,
354
370
  epochCache,
355
371
  blockSource: archiver,
356
372
  l1ToL2MessageSource: archiver,
357
- p2pClient,
358
- dateProvider,
359
- telemetry,
360
- }).registerForReexecution(p2pClient);
373
+ keyStoreManager,
374
+ blobClient,
375
+ });
376
+
377
+ // If we have a validator client, register it as a source of offenses for the slasher,
378
+ // and have it register callbacks on the p2p client *before* we start it, otherwise messages
379
+ // like attestations or auths will fail.
380
+ if (validatorClient) {
381
+ watchers.push(validatorClient);
382
+ if (!options.dontStartSequencer) {
383
+ await validatorClient.registerHandlers();
384
+ }
385
+ }
386
+
387
+ // If there's no validator client but alwaysReexecuteBlockProposals is enabled,
388
+ // create a BlockProposalHandler to reexecute block proposals for monitoring
389
+ if (!validatorClient && config.alwaysReexecuteBlockProposals) {
390
+ log.info('Setting up block proposal reexecution for monitoring');
391
+ createBlockProposalHandler(config, {
392
+ checkpointsBuilder: validatorCheckpointsBuilder,
393
+ worldState: worldStateSynchronizer,
394
+ epochCache,
395
+ blockSource: archiver,
396
+ l1ToL2MessageSource: archiver,
397
+ p2pClient,
398
+ dateProvider,
399
+ telemetry,
400
+ }).registerForReexecution(p2pClient);
401
+ }
361
402
  }
362
403
 
363
404
  // Start world state and wait for it to sync to the archiver.
@@ -366,29 +407,33 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
366
407
  // Start p2p. Note that it depends on world state to be running.
367
408
  await p2pClient.start();
368
409
 
369
- const validatorsSentinel = await createSentinel(epochCache, archiver, p2pClient, config);
370
- if (validatorsSentinel && config.slashInactivityPenalty > 0n) {
371
- watchers.push(validatorsSentinel);
372
- }
373
-
410
+ let validatorsSentinel: Awaited<ReturnType<typeof createSentinel>> | undefined;
374
411
  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
412
  let attestationsBlockWatcher: AttestationsBlockWatcher | undefined;
389
- if (config.slashProposeInvalidAttestationsPenalty > 0n || config.slashAttestDescendantOfInvalidPenalty > 0n) {
390
- attestationsBlockWatcher = new AttestationsBlockWatcher(archiver, epochCache, config);
391
- watchers.push(attestationsBlockWatcher);
413
+
414
+ if (!proverOnly) {
415
+ validatorsSentinel = await createSentinel(epochCache, archiver, p2pClient, config);
416
+ if (validatorsSentinel && config.slashInactivityPenalty > 0n) {
417
+ watchers.push(validatorsSentinel);
418
+ }
419
+
420
+ if (config.slashPrunePenalty > 0n || config.slashDataWithholdingPenalty > 0n) {
421
+ epochPruneWatcher = new EpochPruneWatcher(
422
+ archiver,
423
+ archiver,
424
+ epochCache,
425
+ p2pClient.getTxProvider(),
426
+ validatorCheckpointsBuilder,
427
+ config,
428
+ );
429
+ watchers.push(epochPruneWatcher);
430
+ }
431
+
432
+ // We assume we want to slash for invalid attestations unless all max penalties are set to 0
433
+ if (config.slashProposeInvalidAttestationsPenalty > 0n || config.slashAttestDescendantOfInvalidPenalty > 0n) {
434
+ attestationsBlockWatcher = new AttestationsBlockWatcher(archiver, epochCache, config);
435
+ watchers.push(attestationsBlockWatcher);
436
+ }
392
437
  }
393
438
 
394
439
  // Start p2p-related services once the archiver has completed sync
@@ -425,19 +470,19 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
425
470
  );
426
471
  await slasherClient.start();
427
472
 
428
- const l1TxUtils = config.publisherForwarderAddress
429
- ? await createForwarderL1TxUtilsFromEthSigner(
473
+ const l1TxUtils = config.sequencerPublisherForwarderAddress
474
+ ? await createForwarderL1TxUtilsFromSigners(
430
475
  publicClient,
431
476
  keyStoreManager!.createAllValidatorPublisherSigners(),
432
- config.publisherForwarderAddress,
477
+ config.sequencerPublisherForwarderAddress,
433
478
  { ...config, scope: 'sequencer' },
434
- { telemetry, logger: log.createChild('l1-tx-utils'), dateProvider },
479
+ { telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
435
480
  )
436
- : await createL1TxUtilsWithBlobsFromEthSigner(
481
+ : await createL1TxUtilsFromSigners(
437
482
  publicClient,
438
483
  keyStoreManager!.createAllValidatorPublisherSigners(),
439
484
  { ...config, scope: 'sequencer' },
440
- { telemetry, logger: log.createChild('l1-tx-utils'), dateProvider },
485
+ { telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
441
486
  );
442
487
 
443
488
  // Create and start the sequencer client
@@ -447,6 +492,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
447
492
  archiver,
448
493
  dateProvider,
449
494
  telemetry,
495
+ debugLogStore,
450
496
  );
451
497
 
452
498
  sequencer = await SequencerClient.new(config, {
@@ -474,6 +520,29 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
474
520
  log.warn(`Sequencer created but not started`);
475
521
  }
476
522
 
523
+ // Create prover node subsystem if enabled
524
+ let proverNode: ProverNode | undefined;
525
+ if (config.enableProverNode) {
526
+ proverNode = await createProverNode(config, {
527
+ ...deps.proverNodeDeps,
528
+ telemetry,
529
+ dateProvider,
530
+ archiver,
531
+ worldStateSynchronizer,
532
+ p2pClient,
533
+ epochCache,
534
+ blobClient,
535
+ keyStoreManager,
536
+ });
537
+
538
+ if (!options.dontStartProverNode) {
539
+ await proverNode.start();
540
+ log.info(`Prover node subsystem started`);
541
+ } else {
542
+ log.info(`Prover node subsystem created but not started`);
543
+ }
544
+ }
545
+
477
546
  const globalVariableBuilder = new GlobalVariableBuilder({
478
547
  ...config,
479
548
  rollupVersion: BigInt(config.rollupVersion),
@@ -481,7 +550,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
481
550
  slotDuration: Number(slotDuration),
482
551
  });
483
552
 
484
- return new AztecNodeService(
553
+ const node = new AztecNodeService(
485
554
  config,
486
555
  p2pClient,
487
556
  archiver,
@@ -490,6 +559,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
490
559
  archiver,
491
560
  worldStateSynchronizer,
492
561
  sequencer,
562
+ proverNode,
493
563
  slasherClient,
494
564
  validatorsSentinel,
495
565
  epochPruneWatcher,
@@ -502,7 +572,12 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
502
572
  telemetry,
503
573
  log,
504
574
  blobClient,
575
+ validatorClient,
576
+ keyStoreManager,
577
+ debugLogStore,
505
578
  );
579
+
580
+ return node;
506
581
  }
507
582
 
508
583
  /**
@@ -513,6 +588,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
513
588
  return this.sequencer;
514
589
  }
515
590
 
591
+ /** Returns the prover node subsystem, if enabled. */
592
+ public getProverNode(): ProverNode | undefined {
593
+ return this.proverNode;
594
+ }
595
+
516
596
  public getBlockSource(): L2BlockSource {
517
597
  return this.blockSource;
518
598
  }
@@ -566,6 +646,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
566
646
  enr,
567
647
  l1ContractAddresses: contractAddresses,
568
648
  protocolContractAddresses: protocolContractAddresses,
649
+ realProofs: !!this.config.realProofs,
569
650
  };
570
651
 
571
652
  return nodeInfo;
@@ -576,15 +657,15 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
576
657
  * @param block - The block parameter (block number, block hash, or 'latest').
577
658
  * @returns The requested block.
578
659
  */
579
- public async getBlock(block: BlockParameter): Promise<L2BlockNew | undefined> {
580
- if (L2BlockHash.isL2BlockHash(block)) {
581
- return this.getBlockByHash(Fr.fromBuffer(block.toBuffer()));
660
+ public async getBlock(block: BlockParameter): Promise<L2Block | undefined> {
661
+ if (BlockHash.isBlockHash(block)) {
662
+ return this.getBlockByHash(block);
582
663
  }
583
664
  const blockNumber = block === 'latest' ? await this.getBlockNumber() : (block as BlockNumber);
584
665
  if (blockNumber === BlockNumber.ZERO) {
585
666
  return this.buildInitialBlock();
586
667
  }
587
- return await this.blockSource.getL2BlockNew(blockNumber);
668
+ return await this.blockSource.getL2Block(blockNumber);
588
669
  }
589
670
 
590
671
  /**
@@ -592,17 +673,17 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
592
673
  * @param blockHash - The block hash being requested.
593
674
  * @returns The requested block.
594
675
  */
595
- public async getBlockByHash(blockHash: Fr): Promise<L2BlockNew | undefined> {
676
+ public async getBlockByHash(blockHash: BlockHash): Promise<L2Block | undefined> {
596
677
  const initialBlockHash = await this.#getInitialHeaderHash();
597
- if (blockHash.equals(Fr.fromBuffer(initialBlockHash.toBuffer()))) {
678
+ if (blockHash.equals(initialBlockHash)) {
598
679
  return this.buildInitialBlock();
599
680
  }
600
- return await this.blockSource.getL2BlockNewByHash(blockHash);
681
+ return await this.blockSource.getL2BlockByHash(blockHash);
601
682
  }
602
683
 
603
- private buildInitialBlock(): L2BlockNew {
684
+ private buildInitialBlock(): L2Block {
604
685
  const initialHeader = this.worldStateSynchronizer.getCommitted().getInitialHeader();
605
- return L2BlockNew.empty(initialHeader);
686
+ return L2Block.empty(initialHeader);
606
687
  }
607
688
 
608
689
  /**
@@ -610,8 +691,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
610
691
  * @param archive - The archive root being requested.
611
692
  * @returns The requested block.
612
693
  */
613
- public async getBlockByArchive(archive: Fr): Promise<L2BlockNew | undefined> {
614
- return await this.blockSource.getL2BlockNewByArchive(archive);
694
+ public async getBlockByArchive(archive: Fr): Promise<L2Block | undefined> {
695
+ return await this.blockSource.getL2BlockByArchive(archive);
615
696
  }
616
697
 
617
698
  /**
@@ -620,24 +701,16 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
620
701
  * @param limit - The maximum number of blocks to obtain.
621
702
  * @returns The blocks requested.
622
703
  */
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)) ?? [];
629
- }
630
-
631
- public async getPublishedCheckpoints(from: CheckpointNumber, limit: number): Promise<PublishedCheckpoint[]> {
632
- return (await this.blockSource.getPublishedCheckpoints(from, limit)) ?? [];
704
+ public async getBlocks(from: BlockNumber, limit: number): Promise<L2Block[]> {
705
+ return (await this.blockSource.getBlocks(from, BlockNumber(limit))) ?? [];
633
706
  }
634
707
 
635
- public async getL2BlocksNew(from: BlockNumber, limit: number): Promise<L2BlockNew[]> {
636
- return (await this.blockSource.getL2BlocksNew(from, limit)) ?? [];
708
+ public async getCheckpoints(from: CheckpointNumber, limit: number): Promise<PublishedCheckpoint[]> {
709
+ return (await this.blockSource.getCheckpoints(from, limit)) ?? [];
637
710
  }
638
711
 
639
- public async getCheckpointedBlocks(from: BlockNumber, limit: number, proven?: boolean) {
640
- return (await this.blockSource.getCheckpointedBlocks(from, limit, proven)) ?? [];
712
+ public async getCheckpointedBlocks(from: BlockNumber, limit: number) {
713
+ return (await this.blockSource.getCheckpointedBlocks(from, limit)) ?? [];
641
714
  }
642
715
 
643
716
  /**
@@ -668,6 +741,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
668
741
  return await this.blockSource.getProvenBlockNumber();
669
742
  }
670
743
 
744
+ public async getCheckpointedBlockNumber(): Promise<BlockNumber> {
745
+ return await this.blockSource.getCheckpointedL2BlockNumber();
746
+ }
747
+
671
748
  /**
672
749
  * Method to fetch the version of the package.
673
750
  * @returns The node package version
@@ -700,15 +777,42 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
700
777
  return this.contractDataSource.getContract(address);
701
778
  }
702
779
 
703
- public getPrivateLogsByTags(tags: SiloedTag[], page?: number): Promise<TxScopedL2Log[][]> {
780
+ public async getPrivateLogsByTags(
781
+ tags: SiloedTag[],
782
+ page?: number,
783
+ referenceBlock?: BlockHash,
784
+ ): Promise<TxScopedL2Log[][]> {
785
+ if (referenceBlock) {
786
+ const initialBlockHash = await this.#getInitialHeaderHash();
787
+ if (!referenceBlock.equals(initialBlockHash)) {
788
+ const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
789
+ if (!header) {
790
+ throw new Error(
791
+ `Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
792
+ );
793
+ }
794
+ }
795
+ }
704
796
  return this.logsSource.getPrivateLogsByTags(tags, page);
705
797
  }
706
798
 
707
- public getPublicLogsByTagsFromContract(
799
+ public async getPublicLogsByTagsFromContract(
708
800
  contractAddress: AztecAddress,
709
801
  tags: Tag[],
710
802
  page?: number,
803
+ referenceBlock?: BlockHash,
711
804
  ): Promise<TxScopedL2Log[][]> {
805
+ if (referenceBlock) {
806
+ const initialBlockHash = await this.#getInitialHeaderHash();
807
+ if (!referenceBlock.equals(initialBlockHash)) {
808
+ const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
809
+ if (!header) {
810
+ throw new Error(
811
+ `Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
812
+ );
813
+ }
814
+ }
815
+ }
712
816
  return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page);
713
817
  }
714
818
 
@@ -751,26 +855,36 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
751
855
  }
752
856
 
753
857
  await this.p2pClient!.sendTx(tx);
754
- this.metrics.receivedTx(timer.ms(), true);
755
- this.log.info(`Received tx ${txHash}`, { txHash });
858
+ const duration = timer.ms();
859
+ this.metrics.receivedTx(duration, true);
860
+ this.log.info(`Received tx ${txHash} in ${duration}ms`, { txHash });
756
861
  }
757
862
 
758
863
  public async getTxReceipt(txHash: TxHash): Promise<TxReceipt> {
759
- let txReceipt = new TxReceipt(txHash, TxStatus.DROPPED, 'Tx dropped by P2P node.');
760
-
761
- // We first check if the tx is in pending (instead of first checking if it is mined) because if we first check
762
- // for mined and then for pending there could be a race condition where the tx is mined between the two checks
763
- // and we would incorrectly return a TxReceipt with status DROPPED
764
- if ((await this.p2pClient.getTxStatus(txHash)) === 'pending') {
765
- txReceipt = new TxReceipt(txHash, TxStatus.PENDING, '');
766
- }
864
+ // Check the tx pool status first. If the tx is known to the pool (pending or mined), we'll use that
865
+ // as a fallback if we don't find a settled receipt in the archiver.
866
+ const txPoolStatus = await this.p2pClient.getTxStatus(txHash);
867
+ const isKnownToPool = txPoolStatus === 'pending' || txPoolStatus === 'mined';
767
868
 
869
+ // Then get the actual tx from the archiver, which tracks every tx in a mined block.
768
870
  const settledTxReceipt = await this.blockSource.getSettledTxReceipt(txHash);
871
+
872
+ let receipt: TxReceipt;
769
873
  if (settledTxReceipt) {
770
- txReceipt = settledTxReceipt;
874
+ receipt = settledTxReceipt;
875
+ } else if (isKnownToPool) {
876
+ // If the tx is in the pool but not in the archiver, it's pending.
877
+ // This handles race conditions between archiver and p2p, where the archiver
878
+ // has pruned the block in which a tx was mined, but p2p has not caught up yet.
879
+ receipt = new TxReceipt(txHash, TxStatus.PENDING, undefined, undefined);
880
+ } else {
881
+ // Otherwise, if we don't know the tx, we consider it dropped.
882
+ receipt = new TxReceipt(txHash, TxStatus.DROPPED, undefined, 'Tx dropped by P2P node');
771
883
  }
772
884
 
773
- return txReceipt;
885
+ this.debugLogStore.decorateReceiptWithLogs(txHash.toString(), receipt);
886
+
887
+ return receipt;
774
888
  }
775
889
 
776
890
  public getTxEffect(txHash: TxHash): Promise<IndexedTxEffect | undefined> {
@@ -787,6 +901,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
787
901
  await tryStop(this.slasherClient);
788
902
  await tryStop(this.proofVerifier);
789
903
  await tryStop(this.sequencer);
904
+ await tryStop(this.proverNode);
790
905
  await tryStop(this.p2pClient);
791
906
  await tryStop(this.worldStateSynchronizer);
792
907
  await tryStop(this.blockSource);
@@ -836,11 +951,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
836
951
  }
837
952
 
838
953
  public async findLeavesIndexes(
839
- block: BlockParameter,
954
+ referenceBlock: BlockParameter,
840
955
  treeId: MerkleTreeId,
841
956
  leafValues: Fr[],
842
957
  ): Promise<(DataInBlock<bigint> | undefined)[]> {
843
- const committedDb = await this.#getWorldState(block);
958
+ const committedDb = await this.#getWorldState(referenceBlock);
844
959
  const maybeIndices = await committedDb.findLeafIndices(
845
960
  treeId,
846
961
  leafValues.map(x => x.toBuffer()),
@@ -892,44 +1007,28 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
892
1007
  }
893
1008
  return {
894
1009
  l2BlockNumber: BlockNumber(Number(blockNumber)),
895
- l2BlockHash: L2BlockHash.fromField(blockHash),
1010
+ l2BlockHash: new BlockHash(blockHash),
896
1011
  data: index,
897
1012
  };
898
1013
  });
899
1014
  }
900
1015
 
901
- public async getNullifierSiblingPath(
902
- block: BlockParameter,
903
- leafIndex: bigint,
904
- ): Promise<SiblingPath<typeof NULLIFIER_TREE_HEIGHT>> {
905
- const committedDb = await this.#getWorldState(block);
906
- return committedDb.getSiblingPath(MerkleTreeId.NULLIFIER_TREE, leafIndex);
907
- }
908
-
909
- public async getNoteHashSiblingPath(
910
- block: BlockParameter,
911
- leafIndex: bigint,
912
- ): Promise<SiblingPath<typeof NOTE_HASH_TREE_HEIGHT>> {
913
- const committedDb = await this.#getWorldState(block);
914
- return committedDb.getSiblingPath(MerkleTreeId.NOTE_HASH_TREE, leafIndex);
915
- }
916
-
917
- public async getArchiveMembershipWitness(
918
- block: BlockParameter,
919
- archive: Fr,
1016
+ public async getBlockHashMembershipWitness(
1017
+ referenceBlock: BlockParameter,
1018
+ blockHash: BlockHash,
920
1019
  ): Promise<MembershipWitness<typeof ARCHIVE_HEIGHT> | undefined> {
921
- const committedDb = await this.#getWorldState(block);
922
- const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.ARCHIVE>(MerkleTreeId.ARCHIVE, [archive]);
1020
+ const committedDb = await this.#getWorldState(referenceBlock);
1021
+ const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.ARCHIVE>(MerkleTreeId.ARCHIVE, [blockHash]);
923
1022
  return pathAndIndex === undefined
924
1023
  ? undefined
925
1024
  : MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
926
1025
  }
927
1026
 
928
1027
  public async getNoteHashMembershipWitness(
929
- block: BlockParameter,
1028
+ referenceBlock: BlockParameter,
930
1029
  noteHash: Fr,
931
1030
  ): Promise<MembershipWitness<typeof NOTE_HASH_TREE_HEIGHT> | undefined> {
932
- const committedDb = await this.#getWorldState(block);
1031
+ const committedDb = await this.#getWorldState(referenceBlock);
933
1032
  const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.NOTE_HASH_TREE>(
934
1033
  MerkleTreeId.NOTE_HASH_TREE,
935
1034
  [noteHash],
@@ -940,10 +1039,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
940
1039
  }
941
1040
 
942
1041
  public async getL1ToL2MessageMembershipWitness(
943
- block: BlockParameter,
1042
+ referenceBlock: BlockParameter,
944
1043
  l1ToL2Message: Fr,
945
1044
  ): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>] | undefined> {
946
- const db = await this.#getWorldState(block);
1045
+ const db = await this.#getWorldState(referenceBlock);
947
1046
  const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [l1ToL2Message]);
948
1047
  if (!witness) {
949
1048
  return undefined;
@@ -976,12 +1075,13 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
976
1075
  * @returns The L2 to L1 messages (empty array if the epoch is not found).
977
1076
  */
978
1077
  public async getL2ToL1Messages(epoch: EpochNumber): Promise<Fr[][][][]> {
979
- // Assumes `getBlocksForEpoch` returns blocks in ascending order of block number.
980
- const blocks = await this.blockSource.getBlocksForEpoch(epoch);
981
- const blocksInCheckpoints: L2BlockNew[][] = [];
1078
+ // Assumes `getCheckpointedBlocksForEpoch` returns blocks in ascending order of block number.
1079
+ const checkpointedBlocks = await this.blockSource.getCheckpointedBlocksForEpoch(epoch);
1080
+ const blocksInCheckpoints: L2Block[][] = [];
982
1081
  let previousSlotNumber = SlotNumber.ZERO;
983
1082
  let checkpointIndex = -1;
984
- for (const block of blocks) {
1083
+ for (const checkpointedBlock of checkpointedBlocks) {
1084
+ const block = checkpointedBlock.block;
985
1085
  const slotNumber = block.header.globalVariables.slotNumber;
986
1086
  if (slotNumber !== previousSlotNumber) {
987
1087
  checkpointIndex++;
@@ -995,27 +1095,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
995
1095
  );
996
1096
  }
997
1097
 
998
- public async getArchiveSiblingPath(
999
- block: BlockParameter,
1000
- leafIndex: bigint,
1001
- ): Promise<SiblingPath<typeof ARCHIVE_HEIGHT>> {
1002
- const committedDb = await this.#getWorldState(block);
1003
- return committedDb.getSiblingPath(MerkleTreeId.ARCHIVE, leafIndex);
1004
- }
1005
-
1006
- public async getPublicDataSiblingPath(
1007
- block: BlockParameter,
1008
- leafIndex: bigint,
1009
- ): Promise<SiblingPath<typeof PUBLIC_DATA_TREE_HEIGHT>> {
1010
- const committedDb = await this.#getWorldState(block);
1011
- return committedDb.getSiblingPath(MerkleTreeId.PUBLIC_DATA_TREE, leafIndex);
1012
- }
1013
-
1014
1098
  public async getNullifierMembershipWitness(
1015
- block: BlockParameter,
1099
+ referenceBlock: BlockParameter,
1016
1100
  nullifier: Fr,
1017
1101
  ): Promise<NullifierMembershipWitness | undefined> {
1018
- const db = await this.#getWorldState(block);
1102
+ const db = await this.#getWorldState(referenceBlock);
1019
1103
  const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [nullifier.toBuffer()]);
1020
1104
  if (!witness) {
1021
1105
  return undefined;
@@ -1032,7 +1116,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1032
1116
 
1033
1117
  /**
1034
1118
  * Returns a low nullifier membership witness for a given nullifier at a given block.
1035
- * @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
1119
+ * @param referenceBlock - The block parameter (block number, block hash, or 'latest') at which to get the data
1120
+ * (which contains the root of the nullifier tree in which we are searching for the nullifier).
1036
1121
  * @param nullifier - Nullifier we try to find the low nullifier witness for.
1037
1122
  * @returns The low nullifier membership witness (if found).
1038
1123
  * @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
@@ -1045,10 +1130,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1045
1130
  * TODO: This is a confusing behavior and we should eventually address that.
1046
1131
  */
1047
1132
  public async getLowNullifierMembershipWitness(
1048
- block: BlockParameter,
1133
+ referenceBlock: BlockParameter,
1049
1134
  nullifier: Fr,
1050
1135
  ): Promise<NullifierMembershipWitness | undefined> {
1051
- const committedDb = await this.#getWorldState(block);
1136
+ const committedDb = await this.#getWorldState(referenceBlock);
1052
1137
  const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
1053
1138
  if (!findResult) {
1054
1139
  return undefined;
@@ -1063,8 +1148,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1063
1148
  return new NullifierMembershipWitness(BigInt(index), preimageData as NullifierLeafPreimage, siblingPath);
1064
1149
  }
1065
1150
 
1066
- async getPublicDataWitness(block: BlockParameter, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
1067
- const committedDb = await this.#getWorldState(block);
1151
+ async getPublicDataWitness(referenceBlock: BlockParameter, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
1152
+ const committedDb = await this.#getWorldState(referenceBlock);
1068
1153
  const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
1069
1154
  if (!lowLeafResult) {
1070
1155
  return undefined;
@@ -1078,8 +1163,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1078
1163
  }
1079
1164
  }
1080
1165
 
1081
- public async getPublicStorageAt(block: BlockParameter, contract: AztecAddress, slot: Fr): Promise<Fr> {
1082
- const committedDb = await this.#getWorldState(block);
1166
+ public async getPublicStorageAt(referenceBlock: BlockParameter, contract: AztecAddress, slot: Fr): Promise<Fr> {
1167
+ const committedDb = await this.#getWorldState(referenceBlock);
1083
1168
  const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
1084
1169
 
1085
1170
  const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
@@ -1094,14 +1179,13 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1094
1179
  }
1095
1180
 
1096
1181
  public async getBlockHeader(block: BlockParameter = 'latest'): Promise<BlockHeader | undefined> {
1097
- if (L2BlockHash.isL2BlockHash(block)) {
1182
+ if (BlockHash.isBlockHash(block)) {
1098
1183
  const initialBlockHash = await this.#getInitialHeaderHash();
1099
1184
  if (block.equals(initialBlockHash)) {
1100
1185
  // Block source doesn't handle initial header so we need to handle the case separately.
1101
1186
  return this.worldStateSynchronizer.getCommitted().getInitialHeader();
1102
1187
  }
1103
- const blockHashFr = Fr.fromBuffer(block.toBuffer());
1104
- return this.blockSource.getBlockHeaderByHash(blockHashFr);
1188
+ return this.blockSource.getBlockHeaderByHash(block);
1105
1189
  } else {
1106
1190
  // Block source doesn't handle initial header so we need to handle the case separately.
1107
1191
  const blockNumber = block === 'latest' ? await this.getBlockNumber() : (block as BlockNumber);
@@ -1121,6 +1205,14 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1121
1205
  return await this.blockSource.getBlockHeaderByArchive(archive);
1122
1206
  }
1123
1207
 
1208
+ public getBlockData(number: BlockNumber): Promise<BlockData | undefined> {
1209
+ return this.blockSource.getBlockData(number);
1210
+ }
1211
+
1212
+ public getBlockDataByArchive(archive: Fr): Promise<BlockData | undefined> {
1213
+ return this.blockSource.getBlockDataByArchive(archive);
1214
+ }
1215
+
1124
1216
  /**
1125
1217
  * Simulates the public part of a transaction with the current state.
1126
1218
  * @param tx - The transaction to simulate.
@@ -1144,7 +1236,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1144
1236
  }
1145
1237
 
1146
1238
  const txHash = tx.getTxHash();
1147
- const blockNumber = BlockNumber((await this.blockSource.getBlockNumber()) + 1);
1239
+ const latestBlockNumber = await this.blockSource.getBlockNumber();
1240
+ const blockNumber = BlockNumber.add(latestBlockNumber, 1);
1148
1241
 
1149
1242
  // If sequencer is not initialized, we just set these values to zero for simulation.
1150
1243
  const coinbase = EthAddress.ZERO;
@@ -1159,6 +1252,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1159
1252
  this.contractDataSource,
1160
1253
  new DateProvider(),
1161
1254
  this.telemetry,
1255
+ this.log.getBindings(),
1162
1256
  );
1163
1257
 
1164
1258
  this.log.verbose(`Simulating public calls for tx ${txHash}`, {
@@ -1167,6 +1261,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1167
1261
  blockNumber,
1168
1262
  });
1169
1263
 
1264
+ // Ensure world-state has caught up with the latest block we loaded from the archiver
1265
+ await this.worldStateSynchronizer.syncImmediate(latestBlockNumber);
1170
1266
  const merkleTreeFork = await this.worldStateSynchronizer.fork();
1171
1267
  try {
1172
1268
  const config = PublicSimulatorConfig.from({
@@ -1182,7 +1278,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1182
1278
  const processor = publicProcessorFactory.create(merkleTreeFork, newGlobalVariables, config);
1183
1279
 
1184
1280
  // REFACTOR: Consider merging ProcessReturnValues into ProcessedTx
1185
- const [processedTxs, failedTxs, _usedTxs, returns] = await processor.process([tx]);
1281
+ const [processedTxs, failedTxs, _usedTxs, returns, _blobFields, debugLogs] = await processor.process([tx]);
1186
1282
  // REFACTOR: Consider returning the error rather than throwing
1187
1283
  if (failedTxs.length) {
1188
1284
  this.log.warn(`Simulated tx ${txHash} fails: ${failedTxs[0].error}`, { txHash });
@@ -1196,6 +1292,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1196
1292
  processedTx.txEffect,
1197
1293
  returns,
1198
1294
  processedTx.gasUsed,
1295
+ debugLogs,
1199
1296
  );
1200
1297
  } finally {
1201
1298
  await merkleTreeFork.close();
@@ -1209,19 +1306,25 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1209
1306
  const db = this.worldStateSynchronizer.getCommitted();
1210
1307
  const verifier = isSimulation ? undefined : this.proofVerifier;
1211
1308
 
1212
- // We accept transactions if they are not expired by the next slot (checked based on the IncludeByTimestamp field)
1309
+ // We accept transactions if they are not expired by the next slot (checked based on the ExpirationTimestamp field)
1213
1310
  const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
1214
1311
  const blockNumber = BlockNumber((await this.blockSource.getBlockNumber()) + 1);
1215
- const validator = createValidatorForAcceptingTxs(db, this.contractDataSource, verifier, {
1216
- timestamp: nextSlotTimestamp,
1217
- blockNumber,
1218
- l1ChainId: this.l1ChainId,
1219
- rollupVersion: this.version,
1220
- setupAllowList: this.config.txPublicSetupAllowList ?? (await getDefaultAllowedSetupFunctions()),
1221
- gasFees: await this.getCurrentMinFees(),
1222
- skipFeeEnforcement,
1223
- txsPermitted: !this.config.disableTransactions,
1224
- });
1312
+ const validator = createTxValidatorForAcceptingTxsOverRPC(
1313
+ db,
1314
+ this.contractDataSource,
1315
+ verifier,
1316
+ {
1317
+ timestamp: nextSlotTimestamp,
1318
+ blockNumber,
1319
+ l1ChainId: this.l1ChainId,
1320
+ rollupVersion: this.version,
1321
+ setupAllowList: this.config.txPublicSetupAllowList ?? (await getDefaultAllowedSetupFunctions()),
1322
+ gasFees: await this.getCurrentMinFees(),
1323
+ skipFeeEnforcement,
1324
+ txsPermitted: !this.config.disableTransactions,
1325
+ },
1326
+ this.log.getBindings(),
1327
+ );
1225
1328
 
1226
1329
  return await validator.validateTx(tx);
1227
1330
  }
@@ -1385,13 +1488,97 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1385
1488
  }
1386
1489
  }
1387
1490
 
1388
- #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> {
1389
1580
  if (!this.initialHeaderHashPromise) {
1390
- this.initialHeaderHashPromise = this.worldStateSynchronizer
1391
- .getCommitted()
1392
- .getInitialHeader()
1393
- .hash()
1394
- .then(hash => L2BlockHash.fromField(hash));
1581
+ this.initialHeaderHashPromise = this.worldStateSynchronizer.getCommitted().getInitialHeader().hash();
1395
1582
  }
1396
1583
  return this.initialHeaderHashPromise;
1397
1584
  }
@@ -1415,15 +1602,14 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1415
1602
  return this.worldStateSynchronizer.getCommitted();
1416
1603
  }
1417
1604
 
1418
- if (L2BlockHash.isL2BlockHash(block)) {
1605
+ if (BlockHash.isBlockHash(block)) {
1419
1606
  const initialBlockHash = await this.#getInitialHeaderHash();
1420
1607
  if (block.equals(initialBlockHash)) {
1421
1608
  // Block source doesn't handle initial header so we need to handle the case separately.
1422
1609
  return this.worldStateSynchronizer.getSnapshot(BlockNumber.ZERO);
1423
1610
  }
1424
1611
 
1425
- const blockHashFr = Fr.fromBuffer(block.toBuffer());
1426
- const header = await this.blockSource.getBlockHeaderByHash(blockHashFr);
1612
+ const header = await this.blockSource.getBlockHeaderByHash(block);
1427
1613
  if (!header) {
1428
1614
  throw new Error(
1429
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.`,