@aztec/aztec-node 0.0.1-commit.03f7ef2 → 0.0.1-commit.0658669b3

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,26 +1,15 @@
1
1
  import { Archiver, createArchiver } from '@aztec/archiver';
2
2
  import { BBCircuitVerifier, QueuedIVCVerifier, TestCircuitVerifier } from '@aztec/bb-prover';
3
- import { type BlobClientInterface, createBlobClient } from '@aztec/blob-client/client';
4
- import {
5
- type BlobFileStoreMetadata,
6
- createReadOnlyFileStoreBlobClients,
7
- createWritableFileStoreBlobClient,
8
- } from '@aztec/blob-client/filestore';
9
- import {
10
- ARCHIVE_HEIGHT,
11
- INITIAL_L2_BLOCK_NUM,
12
- type L1_TO_L2_MSG_TREE_HEIGHT,
13
- type NOTE_HASH_TREE_HEIGHT,
14
- type NULLIFIER_TREE_HEIGHT,
15
- type PUBLIC_DATA_TREE_HEIGHT,
16
- } from '@aztec/constants';
3
+ import { type BlobClientInterface, createBlobClientWithFileStores } from '@aztec/blob-client/client';
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';
17
6
  import { EpochCache, type EpochCacheInterface } from '@aztec/epoch-cache';
18
7
  import { createEthereumChain } from '@aztec/ethereum/chain';
19
8
  import { getPublicClient } from '@aztec/ethereum/client';
20
9
  import { RegistryContract, RollupContract } from '@aztec/ethereum/contracts';
21
10
  import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
22
- import { BlockNumber, SlotNumber } from '@aztec/foundation/branded-types';
23
- import { compactArray, pick } from '@aztec/foundation/collection';
11
+ import { BlockNumber, CheckpointNumber, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
12
+ import { compactArray, pick, unique } from '@aztec/foundation/collection';
24
13
  import { Fr } from '@aztec/foundation/curves/bn254';
25
14
  import { EthAddress } from '@aztec/foundation/eth-address';
26
15
  import { BadRequestError } from '@aztec/foundation/json-rpc';
@@ -28,22 +17,20 @@ import { type Logger, createLogger } from '@aztec/foundation/log';
28
17
  import { count } from '@aztec/foundation/string';
29
18
  import { DateProvider, Timer } from '@aztec/foundation/timer';
30
19
  import { MembershipWitness, SiblingPath } from '@aztec/foundation/trees';
31
- import { KeystoreManager, loadKeystores, mergeKeystores } from '@aztec/node-keystore';
20
+ import { type KeyStore, KeystoreManager, loadKeystores, mergeKeystores } from '@aztec/node-keystore';
32
21
  import { trySnapshotSync, uploadSnapshot } from '@aztec/node-lib/actions';
22
+ import { createForwarderL1TxUtilsFromSigners, createL1TxUtilsFromSigners } from '@aztec/node-lib/factories';
33
23
  import {
34
- createForwarderL1TxUtilsFromEthSigner,
35
- createL1TxUtilsWithBlobsFromEthSigner,
36
- } from '@aztec/node-lib/factories';
37
- 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';
38
30
  import { ProtocolContractAddress } from '@aztec/protocol-contracts';
39
- import {
40
- BlockBuilder,
41
- GlobalVariableBuilder,
42
- SequencerClient,
43
- type SequencerPublisher,
44
- createValidatorForAcceptingTxs,
45
- } from '@aztec/sequencer-client';
46
- import { CheckpointsBuilder } from '@aztec/sequencer-client';
31
+ import { type ProverNode, type ProverNodeDeps, createProverNode } from '@aztec/prover-node';
32
+ import { createKeyStoreForProver } from '@aztec/prover-node/config';
33
+ import { GlobalVariableBuilder, SequencerClient, type SequencerPublisher } from '@aztec/sequencer-client';
47
34
  import { PublicProcessorFactory } from '@aztec/simulator/server';
48
35
  import {
49
36
  AttestationsBlockWatcher,
@@ -55,13 +42,14 @@ import {
55
42
  import { CollectionLimitsConfig, PublicSimulatorConfig } from '@aztec/stdlib/avm';
56
43
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
57
44
  import {
45
+ type BlockData,
46
+ BlockHash,
58
47
  type BlockParameter,
59
48
  type DataInBlock,
60
- type L2Block,
61
- L2BlockHash,
49
+ L2Block,
62
50
  type L2BlockSource,
63
- type PublishedL2Block,
64
51
  } from '@aztec/stdlib/block';
52
+ import type { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
65
53
  import type {
66
54
  ContractClassPublic,
67
55
  ContractDataSource,
@@ -88,7 +76,8 @@ import {
88
76
  type WorldStateSynchronizer,
89
77
  tryStop,
90
78
  } from '@aztec/stdlib/interfaces/server';
91
- 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';
92
81
  import { InboxLeaf, type L1ToL2MessageSource } from '@aztec/stdlib/messaging';
93
82
  import { P2PClientType } from '@aztec/stdlib/p2p';
94
83
  import type { Offense, SlashPayloadRound } from '@aztec/stdlib/slashing';
@@ -116,6 +105,8 @@ import {
116
105
  trackSpan,
117
106
  } from '@aztec/telemetry-client';
118
107
  import {
108
+ FullNodeCheckpointsBuilder as CheckpointsBuilder,
109
+ FullNodeCheckpointsBuilder,
119
110
  NodeKeystoreAdapter,
120
111
  ValidatorClient,
121
112
  createBlockProposalHandler,
@@ -135,6 +126,7 @@ import { NodeMetrics } from './node_metrics.js';
135
126
  */
136
127
  export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
137
128
  private metrics: NodeMetrics;
129
+ private initialHeaderHashPromise: Promise<BlockHash> | undefined = undefined;
138
130
 
139
131
  // Prevent two snapshot operations to happen simultaneously
140
132
  private isUploadingSnapshot = false;
@@ -150,6 +142,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
150
142
  protected readonly l1ToL2MessageSource: L1ToL2MessageSource,
151
143
  protected readonly worldStateSynchronizer: WorldStateSynchronizer,
152
144
  protected readonly sequencer: SequencerClient | undefined,
145
+ protected readonly proverNode: ProverNode | undefined,
153
146
  protected readonly slasherClient: SlasherClientInterface | undefined,
154
147
  protected readonly validatorsSentinel: Sentinel | undefined,
155
148
  protected readonly epochPruneWatcher: EpochPruneWatcher | undefined,
@@ -161,12 +154,23 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
161
154
  private proofVerifier: ClientProtocolCircuitVerifier,
162
155
  private telemetry: TelemetryClient = getTelemetryClient(),
163
156
  private log = createLogger('node'),
157
+ private blobClient?: BlobClientInterface,
158
+ private validatorClient?: ValidatorClient,
159
+ private keyStoreManager?: KeystoreManager,
160
+ private debugLogStore: DebugLogStore = new NullDebugLogStore(),
164
161
  ) {
165
162
  this.metrics = new NodeMetrics(telemetry, 'AztecNodeService');
166
163
  this.tracer = telemetry.getTracer('AztecNodeService');
167
164
 
168
165
  this.log.info(`Aztec Node version: ${this.packageVersion}`);
169
166
  this.log.info(`Aztec Node started on chain 0x${l1ChainId.toString(16)}`, config.l1Contracts);
167
+
168
+ // A defensive check that protects us against introducing a bug in the complex `createAndSync` function. We must
169
+ // never have debugLogStore enabled when not in test mode because then we would be accumulating debug logs in
170
+ // memory which could be a DoS vector on the sequencer (since no fees are paid for debug logs).
171
+ if (debugLogStore.isEnabled && config.realProofs) {
172
+ throw new Error('debugLogStore should never be enabled when realProofs are set');
173
+ }
170
174
  }
171
175
 
172
176
  public async getWorldStateSyncStatus(): Promise<WorldStateSyncStatus> {
@@ -190,12 +194,13 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
190
194
  logger?: Logger;
191
195
  publisher?: SequencerPublisher;
192
196
  dateProvider?: DateProvider;
193
- blobClient?: BlobClientInterface;
194
197
  p2pClientDeps?: P2PClientDeps<P2PClientType.Full>;
198
+ proverNodeDeps?: Partial<ProverNodeDeps>;
195
199
  } = {},
196
200
  options: {
197
201
  prefilledPublicData?: PublicDataTreeLeaf[];
198
202
  dontStartSequencer?: boolean;
203
+ dontStartProverNode?: boolean;
199
204
  } = {},
200
205
  ): Promise<AztecNodeService> {
201
206
  const config = { ...inputConfig }; // Copy the config so we dont mutate the input object
@@ -205,16 +210,29 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
205
210
  const dateProvider = deps.dateProvider ?? new DateProvider();
206
211
  const ethereumChain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
207
212
 
208
- // Build a key store from file if given or from environment otherwise
213
+ // Build a key store from file if given or from environment otherwise.
214
+ // We keep the raw KeyStore available so we can merge with prover keys if enableProverNode is set.
209
215
  let keyStoreManager: KeystoreManager | undefined;
210
216
  const keyStoreProvided = config.keyStoreDirectory !== undefined && config.keyStoreDirectory.length > 0;
211
217
  if (keyStoreProvided) {
212
218
  const keyStores = loadKeystores(config.keyStoreDirectory!);
213
219
  keyStoreManager = new KeystoreManager(mergeKeystores(keyStores));
214
220
  } else {
215
- const keyStore = createKeyStoreForValidator(config);
216
- if (keyStore) {
217
- keyStoreManager = new KeystoreManager(keyStore);
221
+ const rawKeyStores: KeyStore[] = [];
222
+ const validatorKeyStore = createKeyStoreForValidator(config);
223
+ if (validatorKeyStore) {
224
+ rawKeyStores.push(validatorKeyStore);
225
+ }
226
+ if (config.enableProverNode) {
227
+ const proverKeyStore = createKeyStoreForProver(config);
228
+ if (proverKeyStore) {
229
+ rawKeyStores.push(proverKeyStore);
230
+ }
231
+ }
232
+ if (rawKeyStores.length > 0) {
233
+ keyStoreManager = new KeystoreManager(
234
+ rawKeyStores.length === 1 ? rawKeyStores[0] : mergeKeystores(rawKeyStores),
235
+ );
218
236
  }
219
237
  }
220
238
 
@@ -225,10 +243,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
225
243
  if (keyStoreManager === undefined) {
226
244
  throw new Error('Failed to create key store, a requirement for running a validator');
227
245
  }
228
- if (!keyStoreProvided) {
229
- log.warn(
230
- 'KEY STORE CREATED FROM ENVIRONMENT, IT IS RECOMMENDED TO USE A FILE-BASED KEY STORE IN PRODUCTION ENVIRONMENTS',
231
- );
246
+ if (!keyStoreProvided && process.env.NODE_ENV !== 'test') {
247
+ log.warn("Keystore created from env: it's recommended to use a file-based key store for production");
232
248
  }
233
249
  ValidatorClient.validateKeyStoreConfiguration(keyStoreManager, log);
234
250
  }
@@ -270,24 +286,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
270
286
  );
271
287
  }
272
288
 
273
- const blobFileStoreMetadata: BlobFileStoreMetadata = {
274
- l1ChainId: config.l1ChainId,
275
- rollupVersion: config.rollupVersion,
276
- rollupAddress: config.l1Contracts.rollupAddress.toString(),
277
- };
278
-
279
- const [fileStoreClients, fileStoreUploadClient] = await Promise.all([
280
- createReadOnlyFileStoreBlobClients(config.blobFileStoreUrls, blobFileStoreMetadata, log),
281
- createWritableFileStoreBlobClient(config.blobFileStoreUploadUrl, blobFileStoreMetadata, log),
282
- ]);
283
-
284
- const blobClient =
285
- deps.blobClient ??
286
- createBlobClient(config, {
287
- logger: createLogger('node:blob-client:client'),
288
- fileStoreClients,
289
- fileStoreUploadClient,
290
- });
289
+ const blobClient = await createBlobClientWithFileStores(config, log.createChild('blob-client'));
291
290
 
292
291
  // attempt snapshot sync if possible
293
292
  await trySnapshotSync(config, log);
@@ -311,9 +310,19 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
311
310
  config.realProofs || config.debugForceTxProofVerification
312
311
  ? await BBCircuitVerifier.new(config)
313
312
  : new TestCircuitVerifier(config.proverTestVerificationDelayMs);
313
+
314
+ let debugLogStore: DebugLogStore;
314
315
  if (!config.realProofs) {
315
316
  log.warn(`Aztec node is accepting fake proofs`);
317
+
318
+ debugLogStore = new InMemoryDebugLogStore();
319
+ log.info(
320
+ 'Aztec node started in test mode (realProofs set to false) hence debug logs from public functions will be collected and served',
321
+ );
322
+ } else {
323
+ debugLogStore = new NullDebugLogStore();
316
324
  }
325
+
317
326
  const proofVerifier = new QueuedIVCVerifier(config, circuitVerifier);
318
327
 
319
328
  // create the tx pool and the p2p client, which will need the l2 block source
@@ -333,7 +342,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
333
342
  // We should really not be modifying the config object
334
343
  config.txPublicSetupAllowList = config.txPublicSetupAllowList ?? (await getDefaultAllowedSetupFunctions());
335
344
 
336
- const blockBuilder = new BlockBuilder(
345
+ // Create FullNodeCheckpointsBuilder for validator and non-validator block proposal handling
346
+ const validatorCheckpointsBuilder = new FullNodeCheckpointsBuilder(
337
347
  { ...config, l1GenesisTime, slotDuration: Number(slotDuration) },
338
348
  worldStateSynchronizer,
339
349
  archiver,
@@ -345,16 +355,17 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
345
355
  const watchers: Watcher[] = [];
346
356
 
347
357
  // Create validator client if required
348
- const validatorClient = createValidatorClient(config, {
358
+ const validatorClient = await createValidatorClient(config, {
359
+ checkpointsBuilder: validatorCheckpointsBuilder,
360
+ worldState: worldStateSynchronizer,
349
361
  p2pClient,
350
362
  telemetry,
351
363
  dateProvider,
352
364
  epochCache,
353
- blockBuilder,
354
365
  blockSource: archiver,
355
366
  l1ToL2MessageSource: archiver,
356
367
  keyStoreManager,
357
- fileStoreBlobUploadClient: fileStoreUploadClient,
368
+ blobClient,
358
369
  });
359
370
 
360
371
  // If we have a validator client, register it as a source of offenses for the slasher,
@@ -372,7 +383,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
372
383
  if (!validatorClient && config.alwaysReexecuteBlockProposals) {
373
384
  log.info('Setting up block proposal reexecution for monitoring');
374
385
  createBlockProposalHandler(config, {
375
- blockBuilder,
386
+ checkpointsBuilder: validatorCheckpointsBuilder,
387
+ worldState: worldStateSynchronizer,
376
388
  epochCache,
377
389
  blockSource: archiver,
378
390
  l1ToL2MessageSource: archiver,
@@ -400,7 +412,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
400
412
  archiver,
401
413
  epochCache,
402
414
  p2pClient.getTxProvider(),
403
- blockBuilder,
415
+ validatorCheckpointsBuilder,
404
416
  config,
405
417
  );
406
418
  watchers.push(epochPruneWatcher);
@@ -447,27 +459,29 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
447
459
  );
448
460
  await slasherClient.start();
449
461
 
450
- const l1TxUtils = config.publisherForwarderAddress
451
- ? await createForwarderL1TxUtilsFromEthSigner(
462
+ const l1TxUtils = config.sequencerPublisherForwarderAddress
463
+ ? await createForwarderL1TxUtilsFromSigners(
452
464
  publicClient,
453
465
  keyStoreManager!.createAllValidatorPublisherSigners(),
454
- config.publisherForwarderAddress,
466
+ config.sequencerPublisherForwarderAddress,
455
467
  { ...config, scope: 'sequencer' },
456
- { telemetry, logger: log.createChild('l1-tx-utils'), dateProvider },
468
+ { telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
457
469
  )
458
- : await createL1TxUtilsWithBlobsFromEthSigner(
470
+ : await createL1TxUtilsFromSigners(
459
471
  publicClient,
460
472
  keyStoreManager!.createAllValidatorPublisherSigners(),
461
473
  { ...config, scope: 'sequencer' },
462
- { telemetry, logger: log.createChild('l1-tx-utils'), dateProvider },
474
+ { telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
463
475
  );
464
476
 
465
477
  // Create and start the sequencer client
466
478
  const checkpointsBuilder = new CheckpointsBuilder(
467
479
  { ...config, l1GenesisTime, slotDuration: Number(slotDuration) },
480
+ worldStateSynchronizer,
468
481
  archiver,
469
482
  dateProvider,
470
483
  telemetry,
484
+ debugLogStore,
471
485
  );
472
486
 
473
487
  sequencer = await SequencerClient.new(config, {
@@ -495,6 +509,29 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
495
509
  log.warn(`Sequencer created but not started`);
496
510
  }
497
511
 
512
+ // Create prover node subsystem if enabled
513
+ let proverNode: ProverNode | undefined;
514
+ if (config.enableProverNode) {
515
+ proverNode = await createProverNode(config, {
516
+ ...deps.proverNodeDeps,
517
+ telemetry,
518
+ dateProvider,
519
+ archiver,
520
+ worldStateSynchronizer,
521
+ p2pClient,
522
+ epochCache,
523
+ blobClient,
524
+ keyStoreManager,
525
+ });
526
+
527
+ if (!options.dontStartProverNode) {
528
+ await proverNode.start();
529
+ log.info(`Prover node subsystem started`);
530
+ } else {
531
+ log.info(`Prover node subsystem created but not started`);
532
+ }
533
+ }
534
+
498
535
  const globalVariableBuilder = new GlobalVariableBuilder({
499
536
  ...config,
500
537
  rollupVersion: BigInt(config.rollupVersion),
@@ -502,7 +539,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
502
539
  slotDuration: Number(slotDuration),
503
540
  });
504
541
 
505
- return new AztecNodeService(
542
+ const node = new AztecNodeService(
506
543
  config,
507
544
  p2pClient,
508
545
  archiver,
@@ -511,6 +548,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
511
548
  archiver,
512
549
  worldStateSynchronizer,
513
550
  sequencer,
551
+ proverNode,
514
552
  slasherClient,
515
553
  validatorsSentinel,
516
554
  epochPruneWatcher,
@@ -522,7 +560,13 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
522
560
  proofVerifier,
523
561
  telemetry,
524
562
  log,
563
+ blobClient,
564
+ validatorClient,
565
+ keyStoreManager,
566
+ debugLogStore,
525
567
  );
568
+
569
+ return node;
526
570
  }
527
571
 
528
572
  /**
@@ -533,6 +577,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
533
577
  return this.sequencer;
534
578
  }
535
579
 
580
+ /** Returns the prover node subsystem, if enabled. */
581
+ public getProverNode(): ProverNode | undefined {
582
+ return this.proverNode;
583
+ }
584
+
536
585
  public getBlockSource(): L2BlockSource {
537
586
  return this.blockSource;
538
587
  }
@@ -586,19 +635,26 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
586
635
  enr,
587
636
  l1ContractAddresses: contractAddresses,
588
637
  protocolContractAddresses: protocolContractAddresses,
638
+ realProofs: !!this.config.realProofs,
589
639
  };
590
640
 
591
641
  return nodeInfo;
592
642
  }
593
643
 
594
644
  /**
595
- * Get a block specified by its number.
596
- * @param number - The block number being requested.
645
+ * Get a block specified by its block number, block hash, or 'latest'.
646
+ * @param block - The block parameter (block number, block hash, or 'latest').
597
647
  * @returns The requested block.
598
648
  */
599
- public async getBlock(number: BlockParameter): Promise<L2Block | undefined> {
600
- const blockNumber = number === 'latest' ? await this.getBlockNumber() : (number as BlockNumber);
601
- return await this.blockSource.getBlock(blockNumber);
649
+ public async getBlock(block: BlockParameter): Promise<L2Block | undefined> {
650
+ if (BlockHash.isBlockHash(block)) {
651
+ return this.getBlockByHash(block);
652
+ }
653
+ const blockNumber = block === 'latest' ? await this.getBlockNumber() : (block as BlockNumber);
654
+ if (blockNumber === BlockNumber.ZERO) {
655
+ return this.buildInitialBlock();
656
+ }
657
+ return await this.blockSource.getL2Block(blockNumber);
602
658
  }
603
659
 
604
660
  /**
@@ -606,9 +662,17 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
606
662
  * @param blockHash - The block hash being requested.
607
663
  * @returns The requested block.
608
664
  */
609
- public async getBlockByHash(blockHash: Fr): Promise<L2Block | undefined> {
610
- const publishedBlock = await this.blockSource.getPublishedBlockByHash(blockHash);
611
- return publishedBlock?.block;
665
+ public async getBlockByHash(blockHash: BlockHash): Promise<L2Block | undefined> {
666
+ const initialBlockHash = await this.#getInitialHeaderHash();
667
+ if (blockHash.equals(initialBlockHash)) {
668
+ return this.buildInitialBlock();
669
+ }
670
+ return await this.blockSource.getL2BlockByHash(blockHash);
671
+ }
672
+
673
+ private buildInitialBlock(): L2Block {
674
+ const initialHeader = this.worldStateSynchronizer.getCommitted().getInitialHeader();
675
+ return L2Block.empty(initialHeader);
612
676
  }
613
677
 
614
678
  /**
@@ -617,8 +681,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
617
681
  * @returns The requested block.
618
682
  */
619
683
  public async getBlockByArchive(archive: Fr): Promise<L2Block | undefined> {
620
- const publishedBlock = await this.blockSource.getPublishedBlockByArchive(archive);
621
- return publishedBlock?.block;
684
+ return await this.blockSource.getL2BlockByArchive(archive);
622
685
  }
623
686
 
624
687
  /**
@@ -628,19 +691,23 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
628
691
  * @returns The blocks requested.
629
692
  */
630
693
  public async getBlocks(from: BlockNumber, limit: number): Promise<L2Block[]> {
631
- return (await this.blockSource.getBlocks(from, limit)) ?? [];
694
+ return (await this.blockSource.getBlocks(from, BlockNumber(limit))) ?? [];
695
+ }
696
+
697
+ public async getCheckpoints(from: CheckpointNumber, limit: number): Promise<PublishedCheckpoint[]> {
698
+ return (await this.blockSource.getCheckpoints(from, limit)) ?? [];
632
699
  }
633
700
 
634
- public async getPublishedBlocks(from: BlockNumber, limit: number): Promise<PublishedL2Block[]> {
635
- return (await this.blockSource.getPublishedBlocks(from, limit)) ?? [];
701
+ public async getCheckpointedBlocks(from: BlockNumber, limit: number) {
702
+ return (await this.blockSource.getCheckpointedBlocks(from, limit)) ?? [];
636
703
  }
637
704
 
638
705
  /**
639
- * Method to fetch the current base fees.
640
- * @returns The current base fees.
706
+ * Method to fetch the current min L2 fees.
707
+ * @returns The current min L2 fees.
641
708
  */
642
- public async getCurrentBaseFees(): Promise<GasFees> {
643
- return await this.globalVariableBuilder.getCurrentBaseFees();
709
+ public async getCurrentMinFees(): Promise<GasFees> {
710
+ return await this.globalVariableBuilder.getCurrentMinFees();
644
711
  }
645
712
 
646
713
  public async getMaxPriorityFees(): Promise<GasFees> {
@@ -663,6 +730,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
663
730
  return await this.blockSource.getProvenBlockNumber();
664
731
  }
665
732
 
733
+ public async getCheckpointedBlockNumber(): Promise<BlockNumber> {
734
+ return await this.blockSource.getCheckpointedL2BlockNumber();
735
+ }
736
+
666
737
  /**
667
738
  * Method to fetch the version of the package.
668
739
  * @returns The node package version
@@ -695,12 +766,43 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
695
766
  return this.contractDataSource.getContract(address);
696
767
  }
697
768
 
698
- public getPrivateLogsByTags(tags: SiloedTag[]): Promise<TxScopedL2Log[][]> {
699
- return this.logsSource.getPrivateLogsByTags(tags);
700
- }
701
-
702
- public getPublicLogsByTagsFromContract(contractAddress: AztecAddress, tags: Tag[]): Promise<TxScopedL2Log[][]> {
703
- return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags);
769
+ public async getPrivateLogsByTags(
770
+ tags: SiloedTag[],
771
+ page?: number,
772
+ referenceBlock?: BlockHash,
773
+ ): Promise<TxScopedL2Log[][]> {
774
+ if (referenceBlock) {
775
+ const initialBlockHash = await this.#getInitialHeaderHash();
776
+ if (!referenceBlock.equals(initialBlockHash)) {
777
+ const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
778
+ if (!header) {
779
+ throw new Error(
780
+ `Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
781
+ );
782
+ }
783
+ }
784
+ }
785
+ return this.logsSource.getPrivateLogsByTags(tags, page);
786
+ }
787
+
788
+ public async getPublicLogsByTagsFromContract(
789
+ contractAddress: AztecAddress,
790
+ tags: Tag[],
791
+ page?: number,
792
+ referenceBlock?: BlockHash,
793
+ ): Promise<TxScopedL2Log[][]> {
794
+ if (referenceBlock) {
795
+ const initialBlockHash = await this.#getInitialHeaderHash();
796
+ if (!referenceBlock.equals(initialBlockHash)) {
797
+ const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
798
+ if (!header) {
799
+ throw new Error(
800
+ `Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
801
+ );
802
+ }
803
+ }
804
+ }
805
+ return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page);
704
806
  }
705
807
 
706
808
  /**
@@ -747,21 +849,30 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
747
849
  }
748
850
 
749
851
  public async getTxReceipt(txHash: TxHash): Promise<TxReceipt> {
750
- let txReceipt = new TxReceipt(txHash, TxStatus.DROPPED, 'Tx dropped by P2P node.');
751
-
752
- // We first check if the tx is in pending (instead of first checking if it is mined) because if we first check
753
- // for mined and then for pending there could be a race condition where the tx is mined between the two checks
754
- // and we would incorrectly return a TxReceipt with status DROPPED
755
- if ((await this.p2pClient.getTxStatus(txHash)) === 'pending') {
756
- txReceipt = new TxReceipt(txHash, TxStatus.PENDING, '');
757
- }
852
+ // Check the tx pool status first. If the tx is known to the pool (pending or mined), we'll use that
853
+ // as a fallback if we don't find a settled receipt in the archiver.
854
+ const txPoolStatus = await this.p2pClient.getTxStatus(txHash);
855
+ const isKnownToPool = txPoolStatus === 'pending' || txPoolStatus === 'mined';
758
856
 
857
+ // Then get the actual tx from the archiver, which tracks every tx in a mined block.
759
858
  const settledTxReceipt = await this.blockSource.getSettledTxReceipt(txHash);
859
+
860
+ let receipt: TxReceipt;
760
861
  if (settledTxReceipt) {
761
- txReceipt = settledTxReceipt;
862
+ receipt = settledTxReceipt;
863
+ } else if (isKnownToPool) {
864
+ // If the tx is in the pool but not in the archiver, it's pending.
865
+ // This handles race conditions between archiver and p2p, where the archiver
866
+ // has pruned the block in which a tx was mined, but p2p has not caught up yet.
867
+ receipt = new TxReceipt(txHash, TxStatus.PENDING, undefined, undefined);
868
+ } else {
869
+ // Otherwise, if we don't know the tx, we consider it dropped.
870
+ receipt = new TxReceipt(txHash, TxStatus.DROPPED, undefined, 'Tx dropped by P2P node');
762
871
  }
763
872
 
764
- return txReceipt;
873
+ this.debugLogStore.decorateReceiptWithLogs(txHash.toString(), receipt);
874
+
875
+ return receipt;
765
876
  }
766
877
 
767
878
  public getTxEffect(txHash: TxHash): Promise<IndexedTxEffect | undefined> {
@@ -778,13 +889,23 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
778
889
  await tryStop(this.slasherClient);
779
890
  await tryStop(this.proofVerifier);
780
891
  await tryStop(this.sequencer);
892
+ await tryStop(this.proverNode);
781
893
  await tryStop(this.p2pClient);
782
894
  await tryStop(this.worldStateSynchronizer);
783
895
  await tryStop(this.blockSource);
896
+ await tryStop(this.blobClient);
784
897
  await tryStop(this.telemetry);
785
898
  this.log.info(`Stopped Aztec Node`);
786
899
  }
787
900
 
901
+ /**
902
+ * Returns the blob client used by this node.
903
+ * @internal - Exposed for testing purposes only.
904
+ */
905
+ public getBlobClient(): BlobClientInterface | undefined {
906
+ return this.blobClient;
907
+ }
908
+
788
909
  /**
789
910
  * Method to retrieve pending txs.
790
911
  * @param limit - The number of items to returns
@@ -817,20 +938,12 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
817
938
  return compactArray(await Promise.all(txHashes.map(txHash => this.getTxByHash(txHash))));
818
939
  }
819
940
 
820
- /**
821
- * Find the indexes of the given leaves in the given tree along with a block metadata pointing to the block in which
822
- * the leaves were inserted.
823
- * @param blockNumber - The block number at which to get the data or 'latest' for latest data.
824
- * @param treeId - The tree to search in.
825
- * @param leafValues - The values to search for.
826
- * @returns The indices of leaves and the block metadata of a block in which the leaves were inserted.
827
- */
828
941
  public async findLeavesIndexes(
829
- blockNumber: BlockParameter,
942
+ referenceBlock: BlockParameter,
830
943
  treeId: MerkleTreeId,
831
944
  leafValues: Fr[],
832
945
  ): Promise<(DataInBlock<bigint> | undefined)[]> {
833
- const committedDb = await this.#getWorldState(blockNumber);
946
+ const committedDb = await this.#getWorldState(referenceBlock);
834
947
  const maybeIndices = await committedDb.findLeafIndices(
835
948
  treeId,
836
949
  leafValues.map(x => x.toBuffer()),
@@ -882,56 +995,28 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
882
995
  }
883
996
  return {
884
997
  l2BlockNumber: BlockNumber(Number(blockNumber)),
885
- l2BlockHash: L2BlockHash.fromField(blockHash),
998
+ l2BlockHash: new BlockHash(blockHash),
886
999
  data: index,
887
1000
  };
888
1001
  });
889
1002
  }
890
1003
 
891
- /**
892
- * Returns a sibling path for the given index in the nullifier tree.
893
- * @param blockNumber - The block number at which to get the data.
894
- * @param leafIndex - The index of the leaf for which the sibling path is required.
895
- * @returns The sibling path for the leaf index.
896
- */
897
- public async getNullifierSiblingPath(
898
- blockNumber: BlockParameter,
899
- leafIndex: bigint,
900
- ): Promise<SiblingPath<typeof NULLIFIER_TREE_HEIGHT>> {
901
- const committedDb = await this.#getWorldState(blockNumber);
902
- return committedDb.getSiblingPath(MerkleTreeId.NULLIFIER_TREE, leafIndex);
903
- }
904
-
905
- /**
906
- * Returns a sibling path for the given index in the data tree.
907
- * @param blockNumber - The block number at which to get the data.
908
- * @param leafIndex - The index of the leaf for which the sibling path is required.
909
- * @returns The sibling path for the leaf index.
910
- */
911
- public async getNoteHashSiblingPath(
912
- blockNumber: BlockParameter,
913
- leafIndex: bigint,
914
- ): Promise<SiblingPath<typeof NOTE_HASH_TREE_HEIGHT>> {
915
- const committedDb = await this.#getWorldState(blockNumber);
916
- return committedDb.getSiblingPath(MerkleTreeId.NOTE_HASH_TREE, leafIndex);
917
- }
918
-
919
- public async getArchiveMembershipWitness(
920
- blockNumber: BlockParameter,
921
- archive: Fr,
1004
+ public async getBlockHashMembershipWitness(
1005
+ referenceBlock: BlockParameter,
1006
+ blockHash: BlockHash,
922
1007
  ): Promise<MembershipWitness<typeof ARCHIVE_HEIGHT> | undefined> {
923
- const committedDb = await this.#getWorldState(blockNumber);
924
- const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.ARCHIVE>(MerkleTreeId.ARCHIVE, [archive]);
1008
+ const committedDb = await this.#getWorldState(referenceBlock);
1009
+ const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.ARCHIVE>(MerkleTreeId.ARCHIVE, [blockHash]);
925
1010
  return pathAndIndex === undefined
926
1011
  ? undefined
927
1012
  : MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
928
1013
  }
929
1014
 
930
1015
  public async getNoteHashMembershipWitness(
931
- blockNumber: BlockParameter,
1016
+ referenceBlock: BlockParameter,
932
1017
  noteHash: Fr,
933
1018
  ): Promise<MembershipWitness<typeof NOTE_HASH_TREE_HEIGHT> | undefined> {
934
- const committedDb = await this.#getWorldState(blockNumber);
1019
+ const committedDb = await this.#getWorldState(referenceBlock);
935
1020
  const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.NOTE_HASH_TREE>(
936
1021
  MerkleTreeId.NOTE_HASH_TREE,
937
1022
  [noteHash],
@@ -941,17 +1026,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
941
1026
  : MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
942
1027
  }
943
1028
 
944
- /**
945
- * Returns the index and a sibling path for a leaf in the committed l1 to l2 data tree.
946
- * @param blockNumber - The block number at which to get the data.
947
- * @param l1ToL2Message - The l1ToL2Message to get the index / sibling path for.
948
- * @returns A tuple of the index and the sibling path of the L1ToL2Message (undefined if not found).
949
- */
950
1029
  public async getL1ToL2MessageMembershipWitness(
951
- blockNumber: BlockParameter,
1030
+ referenceBlock: BlockParameter,
952
1031
  l1ToL2Message: Fr,
953
1032
  ): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>] | undefined> {
954
- const db = await this.#getWorldState(blockNumber);
1033
+ const db = await this.#getWorldState(referenceBlock);
955
1034
  const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [l1ToL2Message]);
956
1035
  if (!witness) {
957
1036
  return undefined;
@@ -979,56 +1058,36 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
979
1058
  }
980
1059
 
981
1060
  /**
982
- * Returns all the L2 to L1 messages in a block.
983
- * @param blockNumber - The block number at which to get the data.
984
- * @returns The L2 to L1 messages (undefined if the block number is not found).
1061
+ * Returns all the L2 to L1 messages in an epoch.
1062
+ * @param epoch - The epoch at which to get the data.
1063
+ * @returns The L2 to L1 messages (empty array if the epoch is not found).
985
1064
  */
986
- public async getL2ToL1Messages(blockNumber: BlockParameter): Promise<Fr[][] | undefined> {
987
- const block = await this.blockSource.getBlock(
988
- blockNumber === 'latest' ? await this.getBlockNumber() : (blockNumber as BlockNumber),
1065
+ public async getL2ToL1Messages(epoch: EpochNumber): Promise<Fr[][][][]> {
1066
+ // Assumes `getCheckpointedBlocksForEpoch` returns blocks in ascending order of block number.
1067
+ const checkpointedBlocks = await this.blockSource.getCheckpointedBlocksForEpoch(epoch);
1068
+ const blocksInCheckpoints: L2Block[][] = [];
1069
+ let previousSlotNumber = SlotNumber.ZERO;
1070
+ let checkpointIndex = -1;
1071
+ for (const checkpointedBlock of checkpointedBlocks) {
1072
+ const block = checkpointedBlock.block;
1073
+ const slotNumber = block.header.globalVariables.slotNumber;
1074
+ if (slotNumber !== previousSlotNumber) {
1075
+ checkpointIndex++;
1076
+ blocksInCheckpoints.push([]);
1077
+ previousSlotNumber = slotNumber;
1078
+ }
1079
+ blocksInCheckpoints[checkpointIndex].push(block);
1080
+ }
1081
+ return blocksInCheckpoints.map(blocks =>
1082
+ blocks.map(block => block.body.txEffects.map(txEffect => txEffect.l2ToL1Msgs)),
989
1083
  );
990
- return block?.body.txEffects.map(txEffect => txEffect.l2ToL1Msgs);
991
1084
  }
992
1085
 
993
- /**
994
- * Returns a sibling path for a leaf in the committed blocks tree.
995
- * @param blockNumber - The block number at which to get the data.
996
- * @param leafIndex - Index of the leaf in the tree.
997
- * @returns The sibling path.
998
- */
999
- public async getArchiveSiblingPath(
1000
- blockNumber: BlockParameter,
1001
- leafIndex: bigint,
1002
- ): Promise<SiblingPath<typeof ARCHIVE_HEIGHT>> {
1003
- const committedDb = await this.#getWorldState(blockNumber);
1004
- return committedDb.getSiblingPath(MerkleTreeId.ARCHIVE, leafIndex);
1005
- }
1006
-
1007
- /**
1008
- * Returns a sibling path for a leaf in the committed public data tree.
1009
- * @param blockNumber - The block number at which to get the data.
1010
- * @param leafIndex - Index of the leaf in the tree.
1011
- * @returns The sibling path.
1012
- */
1013
- public async getPublicDataSiblingPath(
1014
- blockNumber: BlockParameter,
1015
- leafIndex: bigint,
1016
- ): Promise<SiblingPath<typeof PUBLIC_DATA_TREE_HEIGHT>> {
1017
- const committedDb = await this.#getWorldState(blockNumber);
1018
- return committedDb.getSiblingPath(MerkleTreeId.PUBLIC_DATA_TREE, leafIndex);
1019
- }
1020
-
1021
- /**
1022
- * Returns a nullifier membership witness for a given nullifier at a given block.
1023
- * @param blockNumber - The block number at which to get the index.
1024
- * @param nullifier - Nullifier we try to find witness for.
1025
- * @returns The nullifier membership witness (if found).
1026
- */
1027
1086
  public async getNullifierMembershipWitness(
1028
- blockNumber: BlockParameter,
1087
+ referenceBlock: BlockParameter,
1029
1088
  nullifier: Fr,
1030
1089
  ): Promise<NullifierMembershipWitness | undefined> {
1031
- const db = await this.#getWorldState(blockNumber);
1090
+ const db = await this.#getWorldState(referenceBlock);
1032
1091
  const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [nullifier.toBuffer()]);
1033
1092
  if (!witness) {
1034
1093
  return undefined;
@@ -1045,7 +1104,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1045
1104
 
1046
1105
  /**
1047
1106
  * Returns a low nullifier membership witness for a given nullifier at a given block.
1048
- * @param blockNumber - The block number at which to get the index.
1107
+ * @param referenceBlock - The block parameter (block number, block hash, or 'latest') at which to get the data
1108
+ * (which contains the root of the nullifier tree in which we are searching for the nullifier).
1049
1109
  * @param nullifier - Nullifier we try to find the low nullifier witness for.
1050
1110
  * @returns The low nullifier membership witness (if found).
1051
1111
  * @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
@@ -1058,10 +1118,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1058
1118
  * TODO: This is a confusing behavior and we should eventually address that.
1059
1119
  */
1060
1120
  public async getLowNullifierMembershipWitness(
1061
- blockNumber: BlockParameter,
1121
+ referenceBlock: BlockParameter,
1062
1122
  nullifier: Fr,
1063
1123
  ): Promise<NullifierMembershipWitness | undefined> {
1064
- const committedDb = await this.#getWorldState(blockNumber);
1124
+ const committedDb = await this.#getWorldState(referenceBlock);
1065
1125
  const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
1066
1126
  if (!findResult) {
1067
1127
  return undefined;
@@ -1076,8 +1136,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1076
1136
  return new NullifierMembershipWitness(BigInt(index), preimageData as NullifierLeafPreimage, siblingPath);
1077
1137
  }
1078
1138
 
1079
- async getPublicDataWitness(blockNumber: BlockParameter, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
1080
- const committedDb = await this.#getWorldState(blockNumber);
1139
+ async getPublicDataWitness(referenceBlock: BlockParameter, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
1140
+ const committedDb = await this.#getWorldState(referenceBlock);
1081
1141
  const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
1082
1142
  if (!lowLeafResult) {
1083
1143
  return undefined;
@@ -1091,19 +1151,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1091
1151
  }
1092
1152
  }
1093
1153
 
1094
- /**
1095
- * Gets the storage value at the given contract storage slot.
1096
- *
1097
- * @remarks The storage slot here refers to the slot as it is defined in Noir not the index in the merkle tree.
1098
- * Aztec's version of `eth_getStorageAt`.
1099
- *
1100
- * @param contract - Address of the contract to query.
1101
- * @param slot - Slot to query.
1102
- * @param blockNumber - The block number at which to get the data or 'latest'.
1103
- * @returns Storage value at the given contract slot.
1104
- */
1105
- public async getPublicStorageAt(blockNumber: BlockParameter, contract: AztecAddress, slot: Fr): Promise<Fr> {
1106
- const committedDb = await this.#getWorldState(blockNumber);
1154
+ public async getPublicStorageAt(referenceBlock: BlockParameter, contract: AztecAddress, slot: Fr): Promise<Fr> {
1155
+ const committedDb = await this.#getWorldState(referenceBlock);
1107
1156
  const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
1108
1157
 
1109
1158
  const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
@@ -1117,24 +1166,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1117
1166
  return preimage.leaf.value;
1118
1167
  }
1119
1168
 
1120
- /**
1121
- * Returns the currently committed block header, or the initial header if no blocks have been produced.
1122
- * @returns The current committed block header.
1123
- */
1124
- public async getBlockHeader(blockNumber: BlockParameter = 'latest'): Promise<BlockHeader | undefined> {
1125
- return blockNumber === BlockNumber.ZERO ||
1126
- (blockNumber === 'latest' && (await this.blockSource.getBlockNumber()) === BlockNumber.ZERO)
1127
- ? this.worldStateSynchronizer.getCommitted().getInitialHeader()
1128
- : this.blockSource.getBlockHeader(blockNumber === 'latest' ? blockNumber : (blockNumber as BlockNumber));
1129
- }
1130
-
1131
- /**
1132
- * Get a block header specified by its hash.
1133
- * @param blockHash - The block hash being requested.
1134
- * @returns The requested block header.
1135
- */
1136
- public async getBlockHeaderByHash(blockHash: Fr): Promise<BlockHeader | undefined> {
1137
- return await this.blockSource.getBlockHeaderByHash(blockHash);
1169
+ public async getBlockHeader(block: BlockParameter = 'latest'): Promise<BlockHeader | undefined> {
1170
+ if (BlockHash.isBlockHash(block)) {
1171
+ const initialBlockHash = await this.#getInitialHeaderHash();
1172
+ if (block.equals(initialBlockHash)) {
1173
+ // Block source doesn't handle initial header so we need to handle the case separately.
1174
+ return this.worldStateSynchronizer.getCommitted().getInitialHeader();
1175
+ }
1176
+ return this.blockSource.getBlockHeaderByHash(block);
1177
+ } else {
1178
+ // Block source doesn't handle initial header so we need to handle the case separately.
1179
+ const blockNumber = block === 'latest' ? await this.getBlockNumber() : (block as BlockNumber);
1180
+ if (blockNumber === BlockNumber.ZERO) {
1181
+ return this.worldStateSynchronizer.getCommitted().getInitialHeader();
1182
+ }
1183
+ return this.blockSource.getBlockHeader(block);
1184
+ }
1138
1185
  }
1139
1186
 
1140
1187
  /**
@@ -1146,6 +1193,14 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1146
1193
  return await this.blockSource.getBlockHeaderByArchive(archive);
1147
1194
  }
1148
1195
 
1196
+ public getBlockData(number: BlockNumber): Promise<BlockData | undefined> {
1197
+ return this.blockSource.getBlockData(number);
1198
+ }
1199
+
1200
+ public getBlockDataByArchive(archive: Fr): Promise<BlockData | undefined> {
1201
+ return this.blockSource.getBlockDataByArchive(archive);
1202
+ }
1203
+
1149
1204
  /**
1150
1205
  * Simulates the public part of a transaction with the current state.
1151
1206
  * @param tx - The transaction to simulate.
@@ -1169,7 +1224,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1169
1224
  }
1170
1225
 
1171
1226
  const txHash = tx.getTxHash();
1172
- const blockNumber = BlockNumber((await this.blockSource.getBlockNumber()) + 1);
1227
+ const latestBlockNumber = await this.blockSource.getBlockNumber();
1228
+ const blockNumber = BlockNumber.add(latestBlockNumber, 1);
1173
1229
 
1174
1230
  // If sequencer is not initialized, we just set these values to zero for simulation.
1175
1231
  const coinbase = EthAddress.ZERO;
@@ -1184,6 +1240,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1184
1240
  this.contractDataSource,
1185
1241
  new DateProvider(),
1186
1242
  this.telemetry,
1243
+ this.log.getBindings(),
1187
1244
  );
1188
1245
 
1189
1246
  this.log.verbose(`Simulating public calls for tx ${txHash}`, {
@@ -1192,6 +1249,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1192
1249
  blockNumber,
1193
1250
  });
1194
1251
 
1252
+ // Ensure world-state has caught up with the latest block we loaded from the archiver
1253
+ await this.worldStateSynchronizer.syncImmediate(latestBlockNumber);
1195
1254
  const merkleTreeFork = await this.worldStateSynchronizer.fork();
1196
1255
  try {
1197
1256
  const config = PublicSimulatorConfig.from({
@@ -1207,7 +1266,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1207
1266
  const processor = publicProcessorFactory.create(merkleTreeFork, newGlobalVariables, config);
1208
1267
 
1209
1268
  // REFACTOR: Consider merging ProcessReturnValues into ProcessedTx
1210
- const [processedTxs, failedTxs, _usedTxs, returns] = await processor.process([tx]);
1269
+ const [processedTxs, failedTxs, _usedTxs, returns, _blobFields, debugLogs] = await processor.process([tx]);
1211
1270
  // REFACTOR: Consider returning the error rather than throwing
1212
1271
  if (failedTxs.length) {
1213
1272
  this.log.warn(`Simulated tx ${txHash} fails: ${failedTxs[0].error}`, { txHash });
@@ -1221,6 +1280,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1221
1280
  processedTx.txEffect,
1222
1281
  returns,
1223
1282
  processedTx.gasUsed,
1283
+ debugLogs,
1224
1284
  );
1225
1285
  } finally {
1226
1286
  await merkleTreeFork.close();
@@ -1234,19 +1294,25 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1234
1294
  const db = this.worldStateSynchronizer.getCommitted();
1235
1295
  const verifier = isSimulation ? undefined : this.proofVerifier;
1236
1296
 
1237
- // We accept transactions if they are not expired by the next slot (checked based on the IncludeByTimestamp field)
1297
+ // We accept transactions if they are not expired by the next slot (checked based on the ExpirationTimestamp field)
1238
1298
  const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
1239
1299
  const blockNumber = BlockNumber((await this.blockSource.getBlockNumber()) + 1);
1240
- const validator = createValidatorForAcceptingTxs(db, this.contractDataSource, verifier, {
1241
- timestamp: nextSlotTimestamp,
1242
- blockNumber,
1243
- l1ChainId: this.l1ChainId,
1244
- rollupVersion: this.version,
1245
- setupAllowList: this.config.txPublicSetupAllowList ?? (await getDefaultAllowedSetupFunctions()),
1246
- gasFees: await this.getCurrentBaseFees(),
1247
- skipFeeEnforcement,
1248
- txsPermitted: !this.config.disableTransactions,
1249
- });
1300
+ const validator = createTxValidatorForAcceptingTxsOverRPC(
1301
+ db,
1302
+ this.contractDataSource,
1303
+ verifier,
1304
+ {
1305
+ timestamp: nextSlotTimestamp,
1306
+ blockNumber,
1307
+ l1ChainId: this.l1ChainId,
1308
+ rollupVersion: this.version,
1309
+ setupAllowList: this.config.txPublicSetupAllowList ?? (await getDefaultAllowedSetupFunctions()),
1310
+ gasFees: await this.getCurrentMinFees(),
1311
+ skipFeeEnforcement,
1312
+ txsPermitted: !this.config.disableTransactions,
1313
+ },
1314
+ this.log.getBindings(),
1315
+ );
1250
1316
 
1251
1317
  return await validator.validateTx(tx);
1252
1318
  }
@@ -1315,7 +1381,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1315
1381
  }
1316
1382
 
1317
1383
  // And it has an L2 block hash
1318
- const l2BlockHash = await archiver.getL2Tips().then(tips => tips.latest.hash);
1384
+ const l2BlockHash = await archiver.getL2Tips().then(tips => tips.proposed.hash);
1319
1385
  if (!l2BlockHash) {
1320
1386
  this.metrics.recordSnapshotError();
1321
1387
  throw new Error(`Archiver has no latest L2 block hash downloaded. Cannot start snapshot.`);
@@ -1349,7 +1415,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1349
1415
  throw new Error('Archiver implementation does not support rollbacks.');
1350
1416
  }
1351
1417
 
1352
- const finalizedBlock = await archiver.getL2Tips().then(tips => tips.finalized.number);
1418
+ const finalizedBlock = await archiver.getL2Tips().then(tips => tips.finalized.block.number);
1353
1419
  if (targetBlock < finalizedBlock) {
1354
1420
  if (force) {
1355
1421
  this.log.warn(`Clearing world state database to allow rolling back behind finalized block ${finalizedBlock}`);
@@ -1410,16 +1476,107 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1410
1476
  }
1411
1477
  }
1412
1478
 
1479
+ public async reloadKeystore(): Promise<void> {
1480
+ if (!this.config.keyStoreDirectory?.length) {
1481
+ throw new BadRequestError(
1482
+ 'Cannot reload keystore: node is not using a file-based keystore. ' +
1483
+ 'Set KEY_STORE_DIRECTORY to use file-based keystores.',
1484
+ );
1485
+ }
1486
+ if (!this.validatorClient) {
1487
+ throw new BadRequestError('Cannot reload keystore: validator is not enabled.');
1488
+ }
1489
+
1490
+ this.log.info('Reloading keystore from disk');
1491
+
1492
+ // Re-read and validate keystore files
1493
+ const keyStores = loadKeystores(this.config.keyStoreDirectory);
1494
+ const newManager = new KeystoreManager(mergeKeystores(keyStores));
1495
+ await newManager.validateSigners();
1496
+ ValidatorClient.validateKeyStoreConfiguration(newManager, this.log);
1497
+
1498
+ // Validate that every validator's publisher keys overlap with the L1 signers
1499
+ // that were initialized at startup. Publishers cannot be hot-reloaded, so a
1500
+ // validator with a publisher key that doesn't match any existing L1 signer
1501
+ // would silently fail on every proposer slot.
1502
+ if (this.keyStoreManager && this.sequencer) {
1503
+ const oldAdapter = NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager);
1504
+ const availablePublishers = new Set(
1505
+ oldAdapter
1506
+ .getAttesterAddresses()
1507
+ .flatMap(a => oldAdapter.getPublisherAddresses(a).map(p => p.toString().toLowerCase())),
1508
+ );
1509
+
1510
+ const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
1511
+ for (const attester of newAdapter.getAttesterAddresses()) {
1512
+ const pubs = newAdapter.getPublisherAddresses(attester);
1513
+ if (pubs.length > 0 && !pubs.some(p => availablePublishers.has(p.toString().toLowerCase()))) {
1514
+ throw new BadRequestError(
1515
+ `Cannot reload keystore: validator ${attester} has publisher keys ` +
1516
+ `[${pubs.map(p => p.toString()).join(', ')}] but none match the L1 signers initialized at startup ` +
1517
+ `[${[...availablePublishers].join(', ')}]. Publishers cannot be hot-reloaded — ` +
1518
+ `use an existing publisher key or restart the node.`,
1519
+ );
1520
+ }
1521
+ }
1522
+ }
1523
+
1524
+ // Build adapters for old and new keystores to compute diff
1525
+ const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
1526
+ const newAddresses = newAdapter.getAttesterAddresses();
1527
+ const oldAddresses = this.keyStoreManager
1528
+ ? NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager).getAttesterAddresses()
1529
+ : [];
1530
+
1531
+ const oldSet = new Set(oldAddresses.map(a => a.toString()));
1532
+ const newSet = new Set(newAddresses.map(a => a.toString()));
1533
+ const added = newAddresses.filter(a => !oldSet.has(a.toString()));
1534
+ const removed = oldAddresses.filter(a => !newSet.has(a.toString()));
1535
+
1536
+ if (added.length > 0) {
1537
+ this.log.info(`Keystore reload: adding attester keys: ${added.map(a => a.toString()).join(', ')}`);
1538
+ }
1539
+ if (removed.length > 0) {
1540
+ this.log.info(`Keystore reload: removing attester keys: ${removed.map(a => a.toString()).join(', ')}`);
1541
+ }
1542
+ if (added.length === 0 && removed.length === 0) {
1543
+ this.log.info('Keystore reload: attester keys unchanged');
1544
+ }
1545
+
1546
+ // Update the validator client (coinbase, feeRecipient, attester keys)
1547
+ this.validatorClient.reloadKeystore(newManager);
1548
+
1549
+ // Update the publisher factory's keystore so newly-added validators
1550
+ // can be matched to existing publisher keys when proposing blocks.
1551
+ if (this.sequencer) {
1552
+ this.sequencer.updatePublisherNodeKeyStore(newAdapter);
1553
+ }
1554
+
1555
+ // Update slasher's "don't-slash-self" list with new validator addresses
1556
+ if (this.slasherClient && !this.config.slashSelfAllowed) {
1557
+ const slashValidatorsNever = unique(
1558
+ [...(this.config.slashValidatorsNever ?? []), ...newAddresses].map(a => a.toString()),
1559
+ ).map(EthAddress.fromString);
1560
+ this.slasherClient.updateConfig({ slashValidatorsNever });
1561
+ }
1562
+
1563
+ this.keyStoreManager = newManager;
1564
+ this.log.info('Keystore reloaded: coinbase, feeRecipient, and attester keys updated');
1565
+ }
1566
+
1567
+ #getInitialHeaderHash(): Promise<BlockHash> {
1568
+ if (!this.initialHeaderHashPromise) {
1569
+ this.initialHeaderHashPromise = this.worldStateSynchronizer.getCommitted().getInitialHeader().hash();
1570
+ }
1571
+ return this.initialHeaderHashPromise;
1572
+ }
1573
+
1413
1574
  /**
1414
1575
  * Returns an instance of MerkleTreeOperations having first ensured the world state is fully synched
1415
- * @param blockNumber - The block number at which to get the data.
1576
+ * @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
1416
1577
  * @returns An instance of a committed MerkleTreeOperations
1417
1578
  */
1418
- async #getWorldState(blockNumber: BlockParameter) {
1419
- if (typeof blockNumber === 'number' && blockNumber < INITIAL_L2_BLOCK_NUM - 1) {
1420
- throw new Error('Invalid block number to get world state for: ' + blockNumber);
1421
- }
1422
-
1579
+ async #getWorldState(block: BlockParameter) {
1423
1580
  let blockSyncedTo: BlockNumber = BlockNumber.ZERO;
1424
1581
  try {
1425
1582
  // Attempt to sync the world state if necessary
@@ -1428,15 +1585,39 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1428
1585
  this.log.error(`Error getting world state: ${err}`);
1429
1586
  }
1430
1587
 
1431
- // using a snapshot could be less efficient than using the committed db
1432
- if (blockNumber === 'latest' /*|| blockNumber === blockSyncedTo*/) {
1433
- this.log.debug(`Using committed db for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
1588
+ if (block === 'latest') {
1589
+ this.log.debug(`Using committed db for block 'latest', world state synced upto ${blockSyncedTo}`);
1434
1590
  return this.worldStateSynchronizer.getCommitted();
1435
- } else if (blockNumber <= blockSyncedTo) {
1591
+ }
1592
+
1593
+ if (BlockHash.isBlockHash(block)) {
1594
+ const initialBlockHash = await this.#getInitialHeaderHash();
1595
+ if (block.equals(initialBlockHash)) {
1596
+ // Block source doesn't handle initial header so we need to handle the case separately.
1597
+ return this.worldStateSynchronizer.getSnapshot(BlockNumber.ZERO);
1598
+ }
1599
+
1600
+ const header = await this.blockSource.getBlockHeaderByHash(block);
1601
+ if (!header) {
1602
+ throw new Error(
1603
+ `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.`,
1604
+ );
1605
+ }
1606
+ const blockNumber = header.getBlockNumber();
1436
1607
  this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
1437
- return this.worldStateSynchronizer.getSnapshot(blockNumber as BlockNumber);
1438
- } else {
1439
- throw new Error(`Block ${blockNumber} not yet synced`);
1608
+ return this.worldStateSynchronizer.getSnapshot(blockNumber);
1609
+ }
1610
+
1611
+ // Block number provided
1612
+ {
1613
+ const blockNumber = block as BlockNumber;
1614
+
1615
+ if (blockNumber > blockSyncedTo) {
1616
+ throw new Error(`Queried block ${block} not yet synced by the node (node is synced upto ${blockSyncedTo}).`);
1617
+ }
1618
+
1619
+ this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
1620
+ return this.worldStateSynchronizer.getSnapshot(blockNumber);
1440
1621
  }
1441
1622
  }
1442
1623