@aztec/aztec-node 0.0.1-fake-c83136db25 → 0.0.2-commit.217f559981

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,43 +1,30 @@
1
1
  import { Archiver, createArchiver } from '@aztec/archiver';
2
2
  import { BBCircuitVerifier, QueuedIVCVerifier, TestCircuitVerifier } from '@aztec/bb-prover';
3
- import { type BlobSinkClientInterface, createBlobSinkClient } from '@aztec/blob-sink/client';
4
- import {
5
- ARCHIVE_HEIGHT,
6
- INITIAL_L2_BLOCK_NUM,
7
- type L1_TO_L2_MSG_TREE_HEIGHT,
8
- type NOTE_HASH_TREE_HEIGHT,
9
- type NULLIFIER_TREE_HEIGHT,
10
- type PUBLIC_DATA_TREE_HEIGHT,
11
- } 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';
12
6
  import { EpochCache, type EpochCacheInterface } from '@aztec/epoch-cache';
13
- import {
14
- type L1ContractAddresses,
15
- RegistryContract,
16
- RollupContract,
17
- createEthereumChain,
18
- getPublicClient,
19
- } from '@aztec/ethereum';
20
- import { compactArray, pick } from '@aztec/foundation/collection';
7
+ import { createEthereumChain } from '@aztec/ethereum/chain';
8
+ import { getPublicClient } from '@aztec/ethereum/client';
9
+ import { RegistryContract, RollupContract } from '@aztec/ethereum/contracts';
10
+ import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
11
+ import { BlockNumber, CheckpointNumber, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
12
+ import { compactArray, pick, unique } from '@aztec/foundation/collection';
13
+ import { Fr } from '@aztec/foundation/curves/bn254';
21
14
  import { EthAddress } from '@aztec/foundation/eth-address';
22
- import { Fr } from '@aztec/foundation/fields';
23
15
  import { BadRequestError } from '@aztec/foundation/json-rpc';
24
16
  import { type Logger, createLogger } from '@aztec/foundation/log';
25
- import { SerialQueue } from '@aztec/foundation/queue';
26
17
  import { count } from '@aztec/foundation/string';
27
18
  import { DateProvider, Timer } from '@aztec/foundation/timer';
28
19
  import { MembershipWitness, SiblingPath } from '@aztec/foundation/trees';
29
- import { KeystoreManager, loadKeystores, mergeKeystores } from '@aztec/node-keystore';
20
+ import { type KeyStore, KeystoreManager, loadKeystores, mergeKeystores } from '@aztec/node-keystore';
30
21
  import { trySnapshotSync, uploadSnapshot } from '@aztec/node-lib/actions';
31
- import { createL1TxUtilsWithBlobsFromEthSigner } from '@aztec/node-lib/factories';
22
+ import { createForwarderL1TxUtilsFromSigners, createL1TxUtilsFromSigners } from '@aztec/node-lib/factories';
32
23
  import { type P2P, type P2PClientDeps, createP2PClient, getDefaultAllowedSetupFunctions } from '@aztec/p2p';
33
24
  import { ProtocolContractAddress } from '@aztec/protocol-contracts';
34
- import {
35
- BlockBuilder,
36
- GlobalVariableBuilder,
37
- SequencerClient,
38
- type SequencerPublisher,
39
- createValidatorForAcceptingTxs,
40
- } from '@aztec/sequencer-client';
25
+ import { type ProverNode, type ProverNodeDeps, createProverNode } from '@aztec/prover-node';
26
+ import { createKeyStoreForProver } from '@aztec/prover-node/config';
27
+ import { GlobalVariableBuilder, SequencerClient, type SequencerPublisher } from '@aztec/sequencer-client';
41
28
  import { PublicProcessorFactory } from '@aztec/simulator/server';
42
29
  import {
43
30
  AttestationsBlockWatcher,
@@ -46,15 +33,17 @@ import {
46
33
  type Watcher,
47
34
  createSlasher,
48
35
  } from '@aztec/slasher';
36
+ import { CollectionLimitsConfig, PublicSimulatorConfig } from '@aztec/stdlib/avm';
49
37
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
50
38
  import {
51
- type InBlock,
52
- type L2Block,
53
- L2BlockHash,
54
- type L2BlockNumber,
39
+ type BlockData,
40
+ BlockHash,
41
+ type BlockParameter,
42
+ type DataInBlock,
43
+ L2Block,
55
44
  type L2BlockSource,
56
- type PublishedL2Block,
57
45
  } from '@aztec/stdlib/block';
46
+ import type { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
58
47
  import type {
59
48
  ContractClassPublic,
60
49
  ContractDataSource,
@@ -62,7 +51,7 @@ import type {
62
51
  NodeInfo,
63
52
  ProtocolContractAddresses,
64
53
  } from '@aztec/stdlib/contract';
65
- import type { GasFees } from '@aztec/stdlib/gas';
54
+ import { GasFees } from '@aztec/stdlib/gas';
66
55
  import { computePublicDataTreeLeafSlot } from '@aztec/stdlib/hash';
67
56
  import {
68
57
  type AztecNode,
@@ -81,7 +70,7 @@ import {
81
70
  type WorldStateSynchronizer,
82
71
  tryStop,
83
72
  } from '@aztec/stdlib/interfaces/server';
84
- import type { LogFilter, PrivateLog, TxScopedL2Log } from '@aztec/stdlib/logs';
73
+ import type { LogFilter, SiloedTag, Tag, TxScopedL2Log } from '@aztec/stdlib/logs';
85
74
  import { InboxLeaf, type L1ToL2MessageSource } from '@aztec/stdlib/messaging';
86
75
  import { P2PClientType } from '@aztec/stdlib/p2p';
87
76
  import type { Offense, SlashPayloadRound } from '@aztec/stdlib/slashing';
@@ -109,10 +98,13 @@ import {
109
98
  trackSpan,
110
99
  } from '@aztec/telemetry-client';
111
100
  import {
101
+ FullNodeCheckpointsBuilder as CheckpointsBuilder,
102
+ FullNodeCheckpointsBuilder,
112
103
  NodeKeystoreAdapter,
113
104
  ValidatorClient,
114
105
  createBlockProposalHandler,
115
106
  createValidatorClient,
107
+ createValidatorForAcceptingTxs,
116
108
  } from '@aztec/validator-client';
117
109
  import { createWorldStateSynchronizer } from '@aztec/world-state';
118
110
 
@@ -128,13 +120,11 @@ import { NodeMetrics } from './node_metrics.js';
128
120
  */
129
121
  export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
130
122
  private metrics: NodeMetrics;
123
+ private initialHeaderHashPromise: Promise<BlockHash> | undefined = undefined;
131
124
 
132
125
  // Prevent two snapshot operations to happen simultaneously
133
126
  private isUploadingSnapshot = false;
134
127
 
135
- // Serial queue to ensure that we only send one tx at a time
136
- private txQueue: SerialQueue = new SerialQueue();
137
-
138
128
  public readonly tracer: Tracer;
139
129
 
140
130
  constructor(
@@ -146,6 +136,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
146
136
  protected readonly l1ToL2MessageSource: L1ToL2MessageSource,
147
137
  protected readonly worldStateSynchronizer: WorldStateSynchronizer,
148
138
  protected readonly sequencer: SequencerClient | undefined,
139
+ protected readonly proverNode: ProverNode | undefined,
149
140
  protected readonly slasherClient: SlasherClientInterface | undefined,
150
141
  protected readonly validatorsSentinel: Sentinel | undefined,
151
142
  protected readonly epochPruneWatcher: EpochPruneWatcher | undefined,
@@ -157,10 +148,12 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
157
148
  private proofVerifier: ClientProtocolCircuitVerifier,
158
149
  private telemetry: TelemetryClient = getTelemetryClient(),
159
150
  private log = createLogger('node'),
151
+ private blobClient?: BlobClientInterface,
152
+ private validatorClient?: ValidatorClient,
153
+ private keyStoreManager?: KeystoreManager,
160
154
  ) {
161
155
  this.metrics = new NodeMetrics(telemetry, 'AztecNodeService');
162
156
  this.tracer = telemetry.getTracer('AztecNodeService');
163
- this.txQueue.start();
164
157
 
165
158
  this.log.info(`Aztec Node version: ${this.packageVersion}`);
166
159
  this.log.info(`Aztec Node started on chain 0x${l1ChainId.toString(16)}`, config.l1Contracts);
@@ -187,12 +180,13 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
187
180
  logger?: Logger;
188
181
  publisher?: SequencerPublisher;
189
182
  dateProvider?: DateProvider;
190
- blobSinkClient?: BlobSinkClientInterface;
191
183
  p2pClientDeps?: P2PClientDeps<P2PClientType.Full>;
184
+ proverNodeDeps?: Partial<ProverNodeDeps>;
192
185
  } = {},
193
186
  options: {
194
187
  prefilledPublicData?: PublicDataTreeLeaf[];
195
188
  dontStartSequencer?: boolean;
189
+ dontStartProverNode?: boolean;
196
190
  } = {},
197
191
  ): Promise<AztecNodeService> {
198
192
  const config = { ...inputConfig }; // Copy the config so we dont mutate the input object
@@ -200,20 +194,31 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
200
194
  const packageVersion = getPackageVersion() ?? '';
201
195
  const telemetry = deps.telemetry ?? getTelemetryClient();
202
196
  const dateProvider = deps.dateProvider ?? new DateProvider();
203
- const blobSinkClient =
204
- deps.blobSinkClient ?? createBlobSinkClient(config, { logger: createLogger('node:blob-sink:client') });
205
197
  const ethereumChain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
206
198
 
207
- // Build a key store from file if given or from environment otherwise
199
+ // Build a key store from file if given or from environment otherwise.
200
+ // We keep the raw KeyStore available so we can merge with prover keys if enableProverNode is set.
208
201
  let keyStoreManager: KeystoreManager | undefined;
209
202
  const keyStoreProvided = config.keyStoreDirectory !== undefined && config.keyStoreDirectory.length > 0;
210
203
  if (keyStoreProvided) {
211
204
  const keyStores = loadKeystores(config.keyStoreDirectory!);
212
205
  keyStoreManager = new KeystoreManager(mergeKeystores(keyStores));
213
206
  } else {
214
- const keyStore = createKeyStoreForValidator(config);
215
- if (keyStore) {
216
- keyStoreManager = new KeystoreManager(keyStore);
207
+ const rawKeyStores: KeyStore[] = [];
208
+ const validatorKeyStore = createKeyStoreForValidator(config);
209
+ if (validatorKeyStore) {
210
+ rawKeyStores.push(validatorKeyStore);
211
+ }
212
+ if (config.enableProverNode) {
213
+ const proverKeyStore = createKeyStoreForProver(config);
214
+ if (proverKeyStore) {
215
+ rawKeyStores.push(proverKeyStore);
216
+ }
217
+ }
218
+ if (rawKeyStores.length > 0) {
219
+ keyStoreManager = new KeystoreManager(
220
+ rawKeyStores.length === 1 ? rawKeyStores[0] : mergeKeystores(rawKeyStores),
221
+ );
217
222
  }
218
223
  }
219
224
 
@@ -224,10 +229,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
224
229
  if (keyStoreManager === undefined) {
225
230
  throw new Error('Failed to create key store, a requirement for running a validator');
226
231
  }
227
- if (!keyStoreProvided) {
228
- log.warn(
229
- 'KEY STORE CREATED FROM ENVIRONMENT, IT IS RECOMMENDED TO USE A FILE-BASED KEY STORE IN PRODUCTION ENVIRONMENTS',
230
- );
232
+ if (!keyStoreProvided && process.env.NODE_ENV !== 'test') {
233
+ log.warn("Keystore created from env: it's recommended to use a file-based key store for production");
231
234
  }
232
235
  ValidatorClient.validateKeyStoreConfiguration(keyStoreManager, log);
233
236
  }
@@ -241,7 +244,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
241
244
 
242
245
  const publicClient = createPublicClient({
243
246
  chain: ethereumChain.chainInfo,
244
- transport: fallback(config.l1RpcUrls.map((url: string) => http(url))),
247
+ transport: fallback(config.l1RpcUrls.map((url: string) => http(url, { batch: false }))),
245
248
  pollingInterval: config.viemPollingIntervalMS,
246
249
  });
247
250
 
@@ -269,6 +272,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
269
272
  );
270
273
  }
271
274
 
275
+ const blobClient = await createBlobClientWithFileStores(config, log.createChild('blob-client'));
276
+
272
277
  // attempt snapshot sync if possible
273
278
  await trySnapshotSync(config, log);
274
279
 
@@ -276,7 +281,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
276
281
 
277
282
  const archiver = await createArchiver(
278
283
  config,
279
- { blobSinkClient, epochCache, telemetry, dateProvider },
284
+ { blobClient, epochCache, telemetry, dateProvider },
280
285
  { blockUntilSync: !config.skipArchiverInitialSync },
281
286
  );
282
287
 
@@ -287,7 +292,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
287
292
  options.prefilledPublicData,
288
293
  telemetry,
289
294
  );
290
- const circuitVerifier = config.realProofs ? await BBCircuitVerifier.new(config) : new TestCircuitVerifier();
295
+ const circuitVerifier =
296
+ config.realProofs || config.debugForceTxProofVerification
297
+ ? await BBCircuitVerifier.new(config)
298
+ : new TestCircuitVerifier(config.proverTestVerificationDelayMs);
291
299
  if (!config.realProofs) {
292
300
  log.warn(`Aztec node is accepting fake proofs`);
293
301
  }
@@ -310,7 +318,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
310
318
  // We should really not be modifying the config object
311
319
  config.txPublicSetupAllowList = config.txPublicSetupAllowList ?? (await getDefaultAllowedSetupFunctions());
312
320
 
313
- const blockBuilder = new BlockBuilder(
321
+ // Create FullNodeCheckpointsBuilder for validator and non-validator block proposal handling
322
+ const validatorCheckpointsBuilder = new FullNodeCheckpointsBuilder(
314
323
  { ...config, l1GenesisTime, slotDuration: Number(slotDuration) },
315
324
  worldStateSynchronizer,
316
325
  archiver,
@@ -322,15 +331,17 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
322
331
  const watchers: Watcher[] = [];
323
332
 
324
333
  // Create validator client if required
325
- const validatorClient = createValidatorClient(config, {
334
+ const validatorClient = await createValidatorClient(config, {
335
+ checkpointsBuilder: validatorCheckpointsBuilder,
336
+ worldState: worldStateSynchronizer,
326
337
  p2pClient,
327
338
  telemetry,
328
339
  dateProvider,
329
340
  epochCache,
330
- blockBuilder,
331
341
  blockSource: archiver,
332
342
  l1ToL2MessageSource: archiver,
333
343
  keyStoreManager,
344
+ blobClient,
334
345
  });
335
346
 
336
347
  // If we have a validator client, register it as a source of offenses for the slasher,
@@ -348,7 +359,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
348
359
  if (!validatorClient && config.alwaysReexecuteBlockProposals) {
349
360
  log.info('Setting up block proposal reexecution for monitoring');
350
361
  createBlockProposalHandler(config, {
351
- blockBuilder,
362
+ checkpointsBuilder: validatorCheckpointsBuilder,
363
+ worldState: worldStateSynchronizer,
352
364
  epochCache,
353
365
  blockSource: archiver,
354
366
  l1ToL2MessageSource: archiver,
@@ -376,7 +388,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
376
388
  archiver,
377
389
  epochCache,
378
390
  p2pClient.getTxProvider(),
379
- blockBuilder,
391
+ validatorCheckpointsBuilder,
380
392
  config,
381
393
  );
382
394
  watchers.push(epochPruneWatcher);
@@ -404,7 +416,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
404
416
  // Validator enabled, create/start relevant service
405
417
  let sequencer: SequencerClient | undefined;
406
418
  let slasherClient: SlasherClientInterface | undefined;
407
- if (!config.disableValidator) {
419
+ if (!config.disableValidator && validatorClient) {
408
420
  // We create a slasher only if we have a sequencer, since all slashing actions go through the sequencer publisher
409
421
  // as they are executed when the node is selected as proposer.
410
422
  const validatorAddresses = keyStoreManager
@@ -423,14 +435,30 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
423
435
  );
424
436
  await slasherClient.start();
425
437
 
426
- const l1TxUtils = await createL1TxUtilsWithBlobsFromEthSigner(
427
- publicClient,
428
- keyStoreManager!.createAllValidatorPublisherSigners(),
429
- { ...config, scope: 'sequencer' },
430
- { telemetry, logger: log.createChild('l1-tx-utils'), dateProvider },
431
- );
438
+ const l1TxUtils = config.sequencerPublisherForwarderAddress
439
+ ? await createForwarderL1TxUtilsFromSigners(
440
+ publicClient,
441
+ keyStoreManager!.createAllValidatorPublisherSigners(),
442
+ config.sequencerPublisherForwarderAddress,
443
+ { ...config, scope: 'sequencer' },
444
+ { telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
445
+ )
446
+ : await createL1TxUtilsFromSigners(
447
+ publicClient,
448
+ keyStoreManager!.createAllValidatorPublisherSigners(),
449
+ { ...config, scope: 'sequencer' },
450
+ { telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
451
+ );
432
452
 
433
453
  // Create and start the sequencer client
454
+ const checkpointsBuilder = new CheckpointsBuilder(
455
+ { ...config, l1GenesisTime, slotDuration: Number(slotDuration) },
456
+ worldStateSynchronizer,
457
+ archiver,
458
+ dateProvider,
459
+ telemetry,
460
+ );
461
+
434
462
  sequencer = await SequencerClient.new(config, {
435
463
  ...deps,
436
464
  epochCache,
@@ -439,12 +467,12 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
439
467
  p2pClient,
440
468
  worldStateSynchronizer,
441
469
  slasherClient,
442
- blockBuilder,
470
+ checkpointsBuilder,
443
471
  l2BlockSource: archiver,
444
472
  l1ToL2MessageSource: archiver,
445
473
  telemetry,
446
474
  dateProvider,
447
- blobSinkClient,
475
+ blobClient,
448
476
  nodeKeyStore: keyStoreManager!,
449
477
  });
450
478
  }
@@ -456,7 +484,37 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
456
484
  log.warn(`Sequencer created but not started`);
457
485
  }
458
486
 
459
- return new AztecNodeService(
487
+ // Create prover node subsystem if enabled
488
+ let proverNode: ProverNode | undefined;
489
+ if (config.enableProverNode) {
490
+ proverNode = await createProverNode(config, {
491
+ ...deps.proverNodeDeps,
492
+ telemetry,
493
+ dateProvider,
494
+ archiver,
495
+ worldStateSynchronizer,
496
+ p2pClient,
497
+ epochCache,
498
+ blobClient,
499
+ keyStoreManager,
500
+ });
501
+
502
+ if (!options.dontStartProverNode) {
503
+ await proverNode.start();
504
+ log.info(`Prover node subsystem started`);
505
+ } else {
506
+ log.info(`Prover node subsystem created but not started`);
507
+ }
508
+ }
509
+
510
+ const globalVariableBuilder = new GlobalVariableBuilder({
511
+ ...config,
512
+ rollupVersion: BigInt(config.rollupVersion),
513
+ l1GenesisTime,
514
+ slotDuration: Number(slotDuration),
515
+ });
516
+
517
+ const node = new AztecNodeService(
460
518
  config,
461
519
  p2pClient,
462
520
  archiver,
@@ -465,18 +523,24 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
465
523
  archiver,
466
524
  worldStateSynchronizer,
467
525
  sequencer,
526
+ proverNode,
468
527
  slasherClient,
469
528
  validatorsSentinel,
470
529
  epochPruneWatcher,
471
530
  ethereumChain.chainInfo.id,
472
531
  config.rollupVersion,
473
- new GlobalVariableBuilder(config),
532
+ globalVariableBuilder,
474
533
  epochCache,
475
534
  packageVersion,
476
535
  proofVerifier,
477
536
  telemetry,
478
537
  log,
538
+ blobClient,
539
+ validatorClient,
540
+ keyStoreManager,
479
541
  );
542
+
543
+ return node;
480
544
  }
481
545
 
482
546
  /**
@@ -487,6 +551,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
487
551
  return this.sequencer;
488
552
  }
489
553
 
554
+ /** Returns the prover node subsystem, if enabled. */
555
+ public getProverNode(): ProverNode | undefined {
556
+ return this.proverNode;
557
+ }
558
+
490
559
  public getBlockSource(): L2BlockSource {
491
560
  return this.blockSource;
492
561
  }
@@ -540,19 +609,26 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
540
609
  enr,
541
610
  l1ContractAddresses: contractAddresses,
542
611
  protocolContractAddresses: protocolContractAddresses,
612
+ realProofs: !!this.config.realProofs,
543
613
  };
544
614
 
545
615
  return nodeInfo;
546
616
  }
547
617
 
548
618
  /**
549
- * Get a block specified by its number.
550
- * @param number - The block number being requested.
619
+ * Get a block specified by its block number, block hash, or 'latest'.
620
+ * @param block - The block parameter (block number, block hash, or 'latest').
551
621
  * @returns The requested block.
552
622
  */
553
- public async getBlock(number: L2BlockNumber): Promise<L2Block | undefined> {
554
- const blockNumber = number === 'latest' ? await this.getBlockNumber() : number;
555
- return await this.blockSource.getBlock(blockNumber);
623
+ public async getBlock(block: BlockParameter): Promise<L2Block | undefined> {
624
+ if (BlockHash.isBlockHash(block)) {
625
+ return this.getBlockByHash(block);
626
+ }
627
+ const blockNumber = block === 'latest' ? await this.getBlockNumber() : (block as BlockNumber);
628
+ if (blockNumber === BlockNumber.ZERO) {
629
+ return this.buildInitialBlock();
630
+ }
631
+ return await this.blockSource.getL2Block(blockNumber);
556
632
  }
557
633
 
558
634
  /**
@@ -560,9 +636,17 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
560
636
  * @param blockHash - The block hash being requested.
561
637
  * @returns The requested block.
562
638
  */
563
- public async getBlockByHash(blockHash: Fr): Promise<L2Block | undefined> {
564
- const publishedBlock = await this.blockSource.getPublishedBlockByHash(blockHash);
565
- return publishedBlock?.block;
639
+ public async getBlockByHash(blockHash: BlockHash): Promise<L2Block | undefined> {
640
+ const initialBlockHash = await this.#getInitialHeaderHash();
641
+ if (blockHash.equals(initialBlockHash)) {
642
+ return this.buildInitialBlock();
643
+ }
644
+ return await this.blockSource.getL2BlockByHash(blockHash);
645
+ }
646
+
647
+ private buildInitialBlock(): L2Block {
648
+ const initialHeader = this.worldStateSynchronizer.getCommitted().getInitialHeader();
649
+ return L2Block.empty(initialHeader);
566
650
  }
567
651
 
568
652
  /**
@@ -571,8 +655,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
571
655
  * @returns The requested block.
572
656
  */
573
657
  public async getBlockByArchive(archive: Fr): Promise<L2Block | undefined> {
574
- const publishedBlock = await this.blockSource.getPublishedBlockByArchive(archive);
575
- return publishedBlock?.block;
658
+ return await this.blockSource.getL2BlockByArchive(archive);
576
659
  }
577
660
 
578
661
  /**
@@ -581,34 +664,50 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
581
664
  * @param limit - The maximum number of blocks to obtain.
582
665
  * @returns The blocks requested.
583
666
  */
584
- public async getBlocks(from: number, limit: number): Promise<L2Block[]> {
585
- return (await this.blockSource.getBlocks(from, limit)) ?? [];
667
+ public async getBlocks(from: BlockNumber, limit: number): Promise<L2Block[]> {
668
+ return (await this.blockSource.getBlocks(from, BlockNumber(limit))) ?? [];
669
+ }
670
+
671
+ public async getCheckpoints(from: CheckpointNumber, limit: number): Promise<PublishedCheckpoint[]> {
672
+ return (await this.blockSource.getCheckpoints(from, limit)) ?? [];
586
673
  }
587
674
 
588
- public async getPublishedBlocks(from: number, limit: number): Promise<PublishedL2Block[]> {
589
- return (await this.blockSource.getPublishedBlocks(from, limit)) ?? [];
675
+ public async getCheckpointedBlocks(from: BlockNumber, limit: number) {
676
+ return (await this.blockSource.getCheckpointedBlocks(from, limit)) ?? [];
590
677
  }
591
678
 
592
679
  /**
593
- * Method to fetch the current base fees.
594
- * @returns The current base fees.
680
+ * Method to fetch the current min L2 fees.
681
+ * @returns The current min L2 fees.
595
682
  */
596
- public async getCurrentBaseFees(): Promise<GasFees> {
597
- return await this.globalVariableBuilder.getCurrentBaseFees();
683
+ public async getCurrentMinFees(): Promise<GasFees> {
684
+ return await this.globalVariableBuilder.getCurrentMinFees();
685
+ }
686
+
687
+ public async getMaxPriorityFees(): Promise<GasFees> {
688
+ for await (const tx of this.p2pClient.iteratePendingTxs()) {
689
+ return tx.getGasSettings().maxPriorityFeesPerGas;
690
+ }
691
+
692
+ return GasFees.from({ feePerDaGas: 0n, feePerL2Gas: 0n });
598
693
  }
599
694
 
600
695
  /**
601
696
  * Method to fetch the latest block number synchronized by the node.
602
697
  * @returns The block number.
603
698
  */
604
- public async getBlockNumber(): Promise<number> {
699
+ public async getBlockNumber(): Promise<BlockNumber> {
605
700
  return await this.blockSource.getBlockNumber();
606
701
  }
607
702
 
608
- public async getProvenBlockNumber(): Promise<number> {
703
+ public async getProvenBlockNumber(): Promise<BlockNumber> {
609
704
  return await this.blockSource.getProvenBlockNumber();
610
705
  }
611
706
 
707
+ public async getCheckpointedBlockNumber(): Promise<BlockNumber> {
708
+ return await this.blockSource.getCheckpointedL2BlockNumber();
709
+ }
710
+
612
711
  /**
613
712
  * Method to fetch the version of the package.
614
713
  * @returns The node package version
@@ -641,25 +740,43 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
641
740
  return this.contractDataSource.getContract(address);
642
741
  }
643
742
 
644
- /**
645
- * Retrieves all private logs from up to `limit` blocks, starting from the block number `from`.
646
- * @param from - The block number from which to begin retrieving logs.
647
- * @param limit - The maximum number of blocks to retrieve logs from.
648
- * @returns An array of private logs from the specified range of blocks.
649
- */
650
- public getPrivateLogs(from: number, limit: number): Promise<PrivateLog[]> {
651
- return this.logsSource.getPrivateLogs(from, limit);
652
- }
653
-
654
- /**
655
- * Gets all logs that match any of the received tags (i.e. logs with their first field equal to a tag).
656
- * @param tags - The tags to filter the logs by.
657
- * @param logsPerTag - The maximum number of logs to return for each tag. By default no limit is set
658
- * @returns For each received tag, an array of matching logs is returned. An empty array implies no logs match
659
- * that tag.
660
- */
661
- public getLogsByTags(tags: Fr[], logsPerTag?: number): Promise<TxScopedL2Log[][]> {
662
- return this.logsSource.getLogsByTags(tags, logsPerTag);
743
+ public async getPrivateLogsByTags(
744
+ tags: SiloedTag[],
745
+ page?: number,
746
+ referenceBlock?: BlockHash,
747
+ ): Promise<TxScopedL2Log[][]> {
748
+ if (referenceBlock) {
749
+ const initialBlockHash = await this.#getInitialHeaderHash();
750
+ if (!referenceBlock.equals(initialBlockHash)) {
751
+ const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
752
+ if (!header) {
753
+ throw new Error(
754
+ `Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
755
+ );
756
+ }
757
+ }
758
+ }
759
+ return this.logsSource.getPrivateLogsByTags(tags, page);
760
+ }
761
+
762
+ public async getPublicLogsByTagsFromContract(
763
+ contractAddress: AztecAddress,
764
+ tags: Tag[],
765
+ page?: number,
766
+ referenceBlock?: BlockHash,
767
+ ): Promise<TxScopedL2Log[][]> {
768
+ if (referenceBlock) {
769
+ const initialBlockHash = await this.#getInitialHeaderHash();
770
+ if (!referenceBlock.equals(initialBlockHash)) {
771
+ const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
772
+ if (!header) {
773
+ throw new Error(
774
+ `Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
775
+ );
776
+ }
777
+ }
778
+ }
779
+ return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page);
663
780
  }
664
781
 
665
782
  /**
@@ -685,7 +802,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
685
802
  * @param tx - The transaction to be submitted.
686
803
  */
687
804
  public async sendTx(tx: Tx) {
688
- await this.txQueue.put(() => this.#sendTx(tx));
805
+ await this.#sendTx(tx);
689
806
  }
690
807
 
691
808
  async #sendTx(tx: Tx) {
@@ -706,21 +823,26 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
706
823
  }
707
824
 
708
825
  public async getTxReceipt(txHash: TxHash): Promise<TxReceipt> {
709
- let txReceipt = new TxReceipt(txHash, TxStatus.DROPPED, 'Tx dropped by P2P node.');
710
-
711
- // We first check if the tx is in pending (instead of first checking if it is mined) because if we first check
712
- // for mined and then for pending there could be a race condition where the tx is mined between the two checks
713
- // and we would incorrectly return a TxReceipt with status DROPPED
714
- if ((await this.p2pClient.getTxStatus(txHash)) === 'pending') {
715
- txReceipt = new TxReceipt(txHash, TxStatus.PENDING, '');
716
- }
826
+ // Check the tx pool status first. If the tx is known to the pool (pending or mined), we'll use that
827
+ // as a fallback if we don't find a settled receipt in the archiver.
828
+ const txPoolStatus = await this.p2pClient.getTxStatus(txHash);
829
+ const isKnownToPool = txPoolStatus === 'pending' || txPoolStatus === 'mined';
717
830
 
831
+ // Then get the actual tx from the archiver, which tracks every tx in a mined block.
718
832
  const settledTxReceipt = await this.blockSource.getSettledTxReceipt(txHash);
833
+
719
834
  if (settledTxReceipt) {
720
- txReceipt = settledTxReceipt;
835
+ // If the archiver has the receipt then return it.
836
+ return settledTxReceipt;
837
+ } else if (isKnownToPool) {
838
+ // If the tx is in the pool but not in the archiver, it's pending.
839
+ // This handles race conditions between archiver and p2p, where the archiver
840
+ // has pruned the block in which a tx was mined, but p2p has not caught up yet.
841
+ return new TxReceipt(txHash, TxStatus.PENDING, undefined, undefined);
842
+ } else {
843
+ // Otherwise, if we don't know the tx, we consider it dropped.
844
+ return new TxReceipt(txHash, TxStatus.DROPPED, undefined, 'Tx dropped by P2P node');
721
845
  }
722
-
723
- return txReceipt;
724
846
  }
725
847
 
726
848
  public getTxEffect(txHash: TxHash): Promise<IndexedTxEffect | undefined> {
@@ -732,19 +854,28 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
732
854
  */
733
855
  public async stop() {
734
856
  this.log.info(`Stopping Aztec Node`);
735
- await this.txQueue.end();
736
857
  await tryStop(this.validatorsSentinel);
737
858
  await tryStop(this.epochPruneWatcher);
738
859
  await tryStop(this.slasherClient);
739
860
  await tryStop(this.proofVerifier);
740
861
  await tryStop(this.sequencer);
862
+ await tryStop(this.proverNode);
741
863
  await tryStop(this.p2pClient);
742
864
  await tryStop(this.worldStateSynchronizer);
743
865
  await tryStop(this.blockSource);
866
+ await tryStop(this.blobClient);
744
867
  await tryStop(this.telemetry);
745
868
  this.log.info(`Stopped Aztec Node`);
746
869
  }
747
870
 
871
+ /**
872
+ * Returns the blob client used by this node.
873
+ * @internal - Exposed for testing purposes only.
874
+ */
875
+ public getBlobClient(): BlobClientInterface | undefined {
876
+ return this.blobClient;
877
+ }
878
+
748
879
  /**
749
880
  * Method to retrieve pending txs.
750
881
  * @param limit - The number of items to returns
@@ -777,20 +908,12 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
777
908
  return compactArray(await Promise.all(txHashes.map(txHash => this.getTxByHash(txHash))));
778
909
  }
779
910
 
780
- /**
781
- * Find the indexes of the given leaves in the given tree along with a block metadata pointing to the block in which
782
- * the leaves were inserted.
783
- * @param blockNumber - The block number at which to get the data or 'latest' for latest data.
784
- * @param treeId - The tree to search in.
785
- * @param leafValues - The values to search for.
786
- * @returns The indices of leaves and the block metadata of a block in which the leaves were inserted.
787
- */
788
911
  public async findLeavesIndexes(
789
- blockNumber: L2BlockNumber,
912
+ referenceBlock: BlockParameter,
790
913
  treeId: MerkleTreeId,
791
914
  leafValues: Fr[],
792
- ): Promise<(InBlock<bigint> | undefined)[]> {
793
- const committedDb = await this.#getWorldState(blockNumber);
915
+ ): Promise<(DataInBlock<bigint> | undefined)[]> {
916
+ const committedDb = await this.#getWorldState(referenceBlock);
794
917
  const maybeIndices = await committedDb.findLeafIndices(
795
918
  treeId,
796
919
  leafValues.map(x => x.toBuffer()),
@@ -815,7 +938,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
815
938
  // (note that block number corresponds to the leaf index in the archive tree).
816
939
  const blockHashes = await Promise.all(
817
940
  uniqueBlockNumbers.map(blockNumber => {
818
- return committedDb.getLeafValue(MerkleTreeId.ARCHIVE, blockNumber!);
941
+ return committedDb.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
819
942
  }),
820
943
  );
821
944
 
@@ -826,7 +949,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
826
949
  }
827
950
  }
828
951
 
829
- // Create InBlock objects by combining indices, blockNumbers and blockHashes and return them.
952
+ // Create DataInBlock objects by combining indices, blockNumbers and blockHashes and return them.
830
953
  return maybeIndices.map((index, i) => {
831
954
  if (index === undefined) {
832
955
  return undefined;
@@ -841,57 +964,29 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
841
964
  return undefined;
842
965
  }
843
966
  return {
844
- l2BlockNumber: Number(blockNumber),
845
- l2BlockHash: L2BlockHash.fromField(blockHash),
967
+ l2BlockNumber: BlockNumber(Number(blockNumber)),
968
+ l2BlockHash: new BlockHash(blockHash),
846
969
  data: index,
847
970
  };
848
971
  });
849
972
  }
850
973
 
851
- /**
852
- * Returns a sibling path for the given index in the nullifier tree.
853
- * @param blockNumber - The block number at which to get the data.
854
- * @param leafIndex - The index of the leaf for which the sibling path is required.
855
- * @returns The sibling path for the leaf index.
856
- */
857
- public async getNullifierSiblingPath(
858
- blockNumber: L2BlockNumber,
859
- leafIndex: bigint,
860
- ): Promise<SiblingPath<typeof NULLIFIER_TREE_HEIGHT>> {
861
- const committedDb = await this.#getWorldState(blockNumber);
862
- return committedDb.getSiblingPath(MerkleTreeId.NULLIFIER_TREE, leafIndex);
863
- }
864
-
865
- /**
866
- * Returns a sibling path for the given index in the data tree.
867
- * @param blockNumber - The block number at which to get the data.
868
- * @param leafIndex - The index of the leaf for which the sibling path is required.
869
- * @returns The sibling path for the leaf index.
870
- */
871
- public async getNoteHashSiblingPath(
872
- blockNumber: L2BlockNumber,
873
- leafIndex: bigint,
874
- ): Promise<SiblingPath<typeof NOTE_HASH_TREE_HEIGHT>> {
875
- const committedDb = await this.#getWorldState(blockNumber);
876
- return committedDb.getSiblingPath(MerkleTreeId.NOTE_HASH_TREE, leafIndex);
877
- }
878
-
879
- public async getArchiveMembershipWitness(
880
- blockNumber: L2BlockNumber,
881
- archive: Fr,
974
+ public async getBlockHashMembershipWitness(
975
+ referenceBlock: BlockParameter,
976
+ blockHash: BlockHash,
882
977
  ): Promise<MembershipWitness<typeof ARCHIVE_HEIGHT> | undefined> {
883
- const committedDb = await this.#getWorldState(blockNumber);
884
- const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.ARCHIVE>(MerkleTreeId.ARCHIVE, [archive]);
978
+ const committedDb = await this.#getWorldState(referenceBlock);
979
+ const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.ARCHIVE>(MerkleTreeId.ARCHIVE, [blockHash]);
885
980
  return pathAndIndex === undefined
886
981
  ? undefined
887
982
  : MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
888
983
  }
889
984
 
890
985
  public async getNoteHashMembershipWitness(
891
- blockNumber: L2BlockNumber,
986
+ referenceBlock: BlockParameter,
892
987
  noteHash: Fr,
893
988
  ): Promise<MembershipWitness<typeof NOTE_HASH_TREE_HEIGHT> | undefined> {
894
- const committedDb = await this.#getWorldState(blockNumber);
989
+ const committedDb = await this.#getWorldState(referenceBlock);
895
990
  const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.NOTE_HASH_TREE>(
896
991
  MerkleTreeId.NOTE_HASH_TREE,
897
992
  [noteHash],
@@ -901,17 +996,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
901
996
  : MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
902
997
  }
903
998
 
904
- /**
905
- * Returns the index and a sibling path for a leaf in the committed l1 to l2 data tree.
906
- * @param blockNumber - The block number at which to get the data.
907
- * @param l1ToL2Message - The l1ToL2Message to get the index / sibling path for.
908
- * @returns A tuple of the index and the sibling path of the L1ToL2Message (undefined if not found).
909
- */
910
999
  public async getL1ToL2MessageMembershipWitness(
911
- blockNumber: L2BlockNumber,
1000
+ referenceBlock: BlockParameter,
912
1001
  l1ToL2Message: Fr,
913
1002
  ): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>] | undefined> {
914
- const db = await this.#getWorldState(blockNumber);
1003
+ const db = await this.#getWorldState(referenceBlock);
915
1004
  const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [l1ToL2Message]);
916
1005
  if (!witness) {
917
1006
  return undefined;
@@ -921,9 +1010,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
921
1010
  return [witness.index, witness.path];
922
1011
  }
923
1012
 
924
- public async getL1ToL2MessageBlock(l1ToL2Message: Fr): Promise<number | undefined> {
1013
+ public async getL1ToL2MessageBlock(l1ToL2Message: Fr): Promise<BlockNumber | undefined> {
925
1014
  const messageIndex = await this.l1ToL2MessageSource.getL1ToL2MessageIndex(l1ToL2Message);
926
- return messageIndex ? InboxLeaf.l2BlockFromIndex(messageIndex) : undefined;
1015
+ return messageIndex
1016
+ ? BlockNumber.fromCheckpointNumber(InboxLeaf.checkpointNumberFromIndex(messageIndex))
1017
+ : undefined;
927
1018
  }
928
1019
 
929
1020
  /**
@@ -937,54 +1028,36 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
937
1028
  }
938
1029
 
939
1030
  /**
940
- * Returns all the L2 to L1 messages in a block.
941
- * @param blockNumber - The block number at which to get the data.
942
- * @returns The L2 to L1 messages (undefined if the block number is not found).
1031
+ * Returns all the L2 to L1 messages in an epoch.
1032
+ * @param epoch - The epoch at which to get the data.
1033
+ * @returns The L2 to L1 messages (empty array if the epoch is not found).
943
1034
  */
944
- public async getL2ToL1Messages(blockNumber: L2BlockNumber): Promise<Fr[][] | undefined> {
945
- const block = await this.blockSource.getBlock(blockNumber === 'latest' ? await this.getBlockNumber() : blockNumber);
946
- return block?.body.txEffects.map(txEffect => txEffect.l2ToL1Msgs);
947
- }
948
-
949
- /**
950
- * Returns a sibling path for a leaf in the committed blocks tree.
951
- * @param blockNumber - The block number at which to get the data.
952
- * @param leafIndex - Index of the leaf in the tree.
953
- * @returns The sibling path.
954
- */
955
- public async getArchiveSiblingPath(
956
- blockNumber: L2BlockNumber,
957
- leafIndex: bigint,
958
- ): Promise<SiblingPath<typeof ARCHIVE_HEIGHT>> {
959
- const committedDb = await this.#getWorldState(blockNumber);
960
- return committedDb.getSiblingPath(MerkleTreeId.ARCHIVE, leafIndex);
961
- }
962
-
963
- /**
964
- * Returns a sibling path for a leaf in the committed public data tree.
965
- * @param blockNumber - The block number at which to get the data.
966
- * @param leafIndex - Index of the leaf in the tree.
967
- * @returns The sibling path.
968
- */
969
- public async getPublicDataSiblingPath(
970
- blockNumber: L2BlockNumber,
971
- leafIndex: bigint,
972
- ): Promise<SiblingPath<typeof PUBLIC_DATA_TREE_HEIGHT>> {
973
- const committedDb = await this.#getWorldState(blockNumber);
974
- return committedDb.getSiblingPath(MerkleTreeId.PUBLIC_DATA_TREE, leafIndex);
1035
+ public async getL2ToL1Messages(epoch: EpochNumber): Promise<Fr[][][][]> {
1036
+ // Assumes `getCheckpointedBlocksForEpoch` returns blocks in ascending order of block number.
1037
+ const checkpointedBlocks = await this.blockSource.getCheckpointedBlocksForEpoch(epoch);
1038
+ const blocksInCheckpoints: L2Block[][] = [];
1039
+ let previousSlotNumber = SlotNumber.ZERO;
1040
+ let checkpointIndex = -1;
1041
+ for (const checkpointedBlock of checkpointedBlocks) {
1042
+ const block = checkpointedBlock.block;
1043
+ const slotNumber = block.header.globalVariables.slotNumber;
1044
+ if (slotNumber !== previousSlotNumber) {
1045
+ checkpointIndex++;
1046
+ blocksInCheckpoints.push([]);
1047
+ previousSlotNumber = slotNumber;
1048
+ }
1049
+ blocksInCheckpoints[checkpointIndex].push(block);
1050
+ }
1051
+ return blocksInCheckpoints.map(blocks =>
1052
+ blocks.map(block => block.body.txEffects.map(txEffect => txEffect.l2ToL1Msgs)),
1053
+ );
975
1054
  }
976
1055
 
977
- /**
978
- * Returns a nullifier membership witness for a given nullifier at a given block.
979
- * @param blockNumber - The block number at which to get the index.
980
- * @param nullifier - Nullifier we try to find witness for.
981
- * @returns The nullifier membership witness (if found).
982
- */
983
1056
  public async getNullifierMembershipWitness(
984
- blockNumber: L2BlockNumber,
1057
+ referenceBlock: BlockParameter,
985
1058
  nullifier: Fr,
986
1059
  ): Promise<NullifierMembershipWitness | undefined> {
987
- const db = await this.#getWorldState(blockNumber);
1060
+ const db = await this.#getWorldState(referenceBlock);
988
1061
  const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [nullifier.toBuffer()]);
989
1062
  if (!witness) {
990
1063
  return undefined;
@@ -1001,7 +1074,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1001
1074
 
1002
1075
  /**
1003
1076
  * Returns a low nullifier membership witness for a given nullifier at a given block.
1004
- * @param blockNumber - The block number at which to get the index.
1077
+ * @param referenceBlock - The block parameter (block number, block hash, or 'latest') at which to get the data
1078
+ * (which contains the root of the nullifier tree in which we are searching for the nullifier).
1005
1079
  * @param nullifier - Nullifier we try to find the low nullifier witness for.
1006
1080
  * @returns The low nullifier membership witness (if found).
1007
1081
  * @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
@@ -1014,10 +1088,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1014
1088
  * TODO: This is a confusing behavior and we should eventually address that.
1015
1089
  */
1016
1090
  public async getLowNullifierMembershipWitness(
1017
- blockNumber: L2BlockNumber,
1091
+ referenceBlock: BlockParameter,
1018
1092
  nullifier: Fr,
1019
1093
  ): Promise<NullifierMembershipWitness | undefined> {
1020
- const committedDb = await this.#getWorldState(blockNumber);
1094
+ const committedDb = await this.#getWorldState(referenceBlock);
1021
1095
  const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
1022
1096
  if (!findResult) {
1023
1097
  return undefined;
@@ -1032,8 +1106,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1032
1106
  return new NullifierMembershipWitness(BigInt(index), preimageData as NullifierLeafPreimage, siblingPath);
1033
1107
  }
1034
1108
 
1035
- async getPublicDataWitness(blockNumber: L2BlockNumber, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
1036
- const committedDb = await this.#getWorldState(blockNumber);
1109
+ async getPublicDataWitness(referenceBlock: BlockParameter, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
1110
+ const committedDb = await this.#getWorldState(referenceBlock);
1037
1111
  const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
1038
1112
  if (!lowLeafResult) {
1039
1113
  return undefined;
@@ -1047,19 +1121,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1047
1121
  }
1048
1122
  }
1049
1123
 
1050
- /**
1051
- * Gets the storage value at the given contract storage slot.
1052
- *
1053
- * @remarks The storage slot here refers to the slot as it is defined in Noir not the index in the merkle tree.
1054
- * Aztec's version of `eth_getStorageAt`.
1055
- *
1056
- * @param contract - Address of the contract to query.
1057
- * @param slot - Slot to query.
1058
- * @param blockNumber - The block number at which to get the data or 'latest'.
1059
- * @returns Storage value at the given contract slot.
1060
- */
1061
- public async getPublicStorageAt(blockNumber: L2BlockNumber, contract: AztecAddress, slot: Fr): Promise<Fr> {
1062
- const committedDb = await this.#getWorldState(blockNumber);
1124
+ public async getPublicStorageAt(referenceBlock: BlockParameter, contract: AztecAddress, slot: Fr): Promise<Fr> {
1125
+ const committedDb = await this.#getWorldState(referenceBlock);
1063
1126
  const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
1064
1127
 
1065
1128
  const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
@@ -1073,23 +1136,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1073
1136
  return preimage.leaf.value;
1074
1137
  }
1075
1138
 
1076
- /**
1077
- * Returns the currently committed block header, or the initial header if no blocks have been produced.
1078
- * @returns The current committed block header.
1079
- */
1080
- public async getBlockHeader(blockNumber: L2BlockNumber = 'latest'): Promise<BlockHeader | undefined> {
1081
- return blockNumber === 0 || (blockNumber === 'latest' && (await this.blockSource.getBlockNumber()) === 0)
1082
- ? this.worldStateSynchronizer.getCommitted().getInitialHeader()
1083
- : this.blockSource.getBlockHeader(blockNumber);
1084
- }
1085
-
1086
- /**
1087
- * Get a block header specified by its hash.
1088
- * @param blockHash - The block hash being requested.
1089
- * @returns The requested block header.
1090
- */
1091
- public async getBlockHeaderByHash(blockHash: Fr): Promise<BlockHeader | undefined> {
1092
- return await this.blockSource.getBlockHeaderByHash(blockHash);
1139
+ public async getBlockHeader(block: BlockParameter = 'latest'): Promise<BlockHeader | undefined> {
1140
+ if (BlockHash.isBlockHash(block)) {
1141
+ const initialBlockHash = await this.#getInitialHeaderHash();
1142
+ if (block.equals(initialBlockHash)) {
1143
+ // Block source doesn't handle initial header so we need to handle the case separately.
1144
+ return this.worldStateSynchronizer.getCommitted().getInitialHeader();
1145
+ }
1146
+ return this.blockSource.getBlockHeaderByHash(block);
1147
+ } else {
1148
+ // Block source doesn't handle initial header so we need to handle the case separately.
1149
+ const blockNumber = block === 'latest' ? await this.getBlockNumber() : (block as BlockNumber);
1150
+ if (blockNumber === BlockNumber.ZERO) {
1151
+ return this.worldStateSynchronizer.getCommitted().getInitialHeader();
1152
+ }
1153
+ return this.blockSource.getBlockHeader(block);
1154
+ }
1093
1155
  }
1094
1156
 
1095
1157
  /**
@@ -1101,6 +1163,14 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1101
1163
  return await this.blockSource.getBlockHeaderByArchive(archive);
1102
1164
  }
1103
1165
 
1166
+ public getBlockData(number: BlockNumber): Promise<BlockData | undefined> {
1167
+ return this.blockSource.getBlockData(number);
1168
+ }
1169
+
1170
+ public getBlockDataByArchive(archive: Fr): Promise<BlockData | undefined> {
1171
+ return this.blockSource.getBlockDataByArchive(archive);
1172
+ }
1173
+
1104
1174
  /**
1105
1175
  * Simulates the public part of a transaction with the current state.
1106
1176
  * @param tx - The transaction to simulate.
@@ -1124,7 +1194,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1124
1194
  }
1125
1195
 
1126
1196
  const txHash = tx.getTxHash();
1127
- const blockNumber = (await this.blockSource.getBlockNumber()) + 1;
1197
+ const latestBlockNumber = await this.blockSource.getBlockNumber();
1198
+ const blockNumber = BlockNumber.add(latestBlockNumber, 1);
1128
1199
 
1129
1200
  // If sequencer is not initialized, we just set these values to zero for simulation.
1130
1201
  const coinbase = EthAddress.ZERO;
@@ -1139,6 +1210,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1139
1210
  this.contractDataSource,
1140
1211
  new DateProvider(),
1141
1212
  this.telemetry,
1213
+ this.log.getBindings(),
1142
1214
  );
1143
1215
 
1144
1216
  this.log.verbose(`Simulating public calls for tx ${txHash}`, {
@@ -1147,16 +1219,24 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1147
1219
  blockNumber,
1148
1220
  });
1149
1221
 
1222
+ // Ensure world-state has caught up with the latest block we loaded from the archiver
1223
+ await this.worldStateSynchronizer.syncImmediate(latestBlockNumber);
1150
1224
  const merkleTreeFork = await this.worldStateSynchronizer.fork();
1151
1225
  try {
1152
- const processor = publicProcessorFactory.create(merkleTreeFork, newGlobalVariables, {
1226
+ const config = PublicSimulatorConfig.from({
1153
1227
  skipFeeEnforcement,
1154
- clientInitiatedSimulation: true,
1155
- maxDebugLogMemoryReads: this.config.rpcSimulatePublicMaxDebugLogMemoryReads,
1228
+ collectDebugLogs: true,
1229
+ collectHints: false,
1230
+ collectCallMetadata: true,
1231
+ collectStatistics: false,
1232
+ collectionLimits: CollectionLimitsConfig.from({
1233
+ maxDebugLogMemoryReads: this.config.rpcSimulatePublicMaxDebugLogMemoryReads,
1234
+ }),
1156
1235
  });
1236
+ const processor = publicProcessorFactory.create(merkleTreeFork, newGlobalVariables, config);
1157
1237
 
1158
1238
  // REFACTOR: Consider merging ProcessReturnValues into ProcessedTx
1159
- const [processedTxs, failedTxs, _usedTxs, returns] = await processor.process([tx]);
1239
+ const [processedTxs, failedTxs, _usedTxs, returns, _blobFields, debugLogs] = await processor.process([tx]);
1160
1240
  // REFACTOR: Consider returning the error rather than throwing
1161
1241
  if (failedTxs.length) {
1162
1242
  this.log.warn(`Simulated tx ${txHash} fails: ${failedTxs[0].error}`, { txHash });
@@ -1170,6 +1250,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1170
1250
  processedTx.txEffect,
1171
1251
  returns,
1172
1252
  processedTx.gasUsed,
1253
+ debugLogs,
1173
1254
  );
1174
1255
  } finally {
1175
1256
  await merkleTreeFork.close();
@@ -1183,19 +1264,25 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1183
1264
  const db = this.worldStateSynchronizer.getCommitted();
1184
1265
  const verifier = isSimulation ? undefined : this.proofVerifier;
1185
1266
 
1186
- // We accept transactions if they are not expired by the next slot (checked based on the IncludeByTimestamp field)
1267
+ // We accept transactions if they are not expired by the next slot (checked based on the ExpirationTimestamp field)
1187
1268
  const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
1188
- const blockNumber = (await this.blockSource.getBlockNumber()) + 1;
1189
- const validator = createValidatorForAcceptingTxs(db, this.contractDataSource, verifier, {
1190
- timestamp: nextSlotTimestamp,
1191
- blockNumber,
1192
- l1ChainId: this.l1ChainId,
1193
- rollupVersion: this.version,
1194
- setupAllowList: this.config.txPublicSetupAllowList ?? (await getDefaultAllowedSetupFunctions()),
1195
- gasFees: await this.getCurrentBaseFees(),
1196
- skipFeeEnforcement,
1197
- txsPermitted: !this.config.disableTransactions,
1198
- });
1269
+ const blockNumber = BlockNumber((await this.blockSource.getBlockNumber()) + 1);
1270
+ const validator = createValidatorForAcceptingTxs(
1271
+ db,
1272
+ this.contractDataSource,
1273
+ verifier,
1274
+ {
1275
+ timestamp: nextSlotTimestamp,
1276
+ blockNumber,
1277
+ l1ChainId: this.l1ChainId,
1278
+ rollupVersion: this.version,
1279
+ setupAllowList: this.config.txPublicSetupAllowList ?? (await getDefaultAllowedSetupFunctions()),
1280
+ gasFees: await this.getCurrentMinFees(),
1281
+ skipFeeEnforcement,
1282
+ txsPermitted: !this.config.disableTransactions,
1283
+ },
1284
+ this.log.getBindings(),
1285
+ );
1199
1286
 
1200
1287
  return await validator.validateTx(tx);
1201
1288
  }
@@ -1242,8 +1329,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1242
1329
 
1243
1330
  public getValidatorStats(
1244
1331
  validatorAddress: EthAddress,
1245
- fromSlot?: bigint,
1246
- toSlot?: bigint,
1332
+ fromSlot?: SlotNumber,
1333
+ toSlot?: SlotNumber,
1247
1334
  ): Promise<SingleValidatorStats | undefined> {
1248
1335
  return this.validatorsSentinel?.getValidatorStats(validatorAddress, fromSlot, toSlot) ?? Promise.resolve(undefined);
1249
1336
  }
@@ -1253,45 +1340,52 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1253
1340
  // We break support for archiver running remotely to the node
1254
1341
  const archiver = this.blockSource as Archiver;
1255
1342
  if (!('backupTo' in archiver)) {
1343
+ this.metrics.recordSnapshotError();
1256
1344
  throw new Error('Archiver implementation does not support backups. Cannot generate snapshot.');
1257
1345
  }
1258
1346
 
1259
1347
  // Test that the archiver has done an initial sync.
1260
1348
  if (!archiver.isInitialSyncComplete()) {
1349
+ this.metrics.recordSnapshotError();
1261
1350
  throw new Error(`Archiver initial sync not complete. Cannot start snapshot.`);
1262
1351
  }
1263
1352
 
1264
1353
  // And it has an L2 block hash
1265
- const l2BlockHash = await archiver.getL2Tips().then(tips => tips.latest.hash);
1354
+ const l2BlockHash = await archiver.getL2Tips().then(tips => tips.proposed.hash);
1266
1355
  if (!l2BlockHash) {
1356
+ this.metrics.recordSnapshotError();
1267
1357
  throw new Error(`Archiver has no latest L2 block hash downloaded. Cannot start snapshot.`);
1268
1358
  }
1269
1359
 
1270
1360
  if (this.isUploadingSnapshot) {
1361
+ this.metrics.recordSnapshotError();
1271
1362
  throw new Error(`Snapshot upload already in progress. Cannot start another one until complete.`);
1272
1363
  }
1273
1364
 
1274
1365
  // Do not wait for the upload to be complete to return to the caller, but flag that an operation is in progress
1275
1366
  this.isUploadingSnapshot = true;
1367
+ const timer = new Timer();
1276
1368
  void uploadSnapshot(location, this.blockSource as Archiver, this.worldStateSynchronizer, this.config, this.log)
1277
1369
  .then(() => {
1278
1370
  this.isUploadingSnapshot = false;
1371
+ this.metrics.recordSnapshot(timer.ms());
1279
1372
  })
1280
1373
  .catch(err => {
1281
1374
  this.isUploadingSnapshot = false;
1375
+ this.metrics.recordSnapshotError();
1282
1376
  this.log.error(`Error uploading snapshot: ${err}`);
1283
1377
  });
1284
1378
 
1285
1379
  return Promise.resolve();
1286
1380
  }
1287
1381
 
1288
- public async rollbackTo(targetBlock: number, force?: boolean): Promise<void> {
1382
+ public async rollbackTo(targetBlock: BlockNumber, force?: boolean): Promise<void> {
1289
1383
  const archiver = this.blockSource as Archiver;
1290
1384
  if (!('rollbackTo' in archiver)) {
1291
1385
  throw new Error('Archiver implementation does not support rollbacks.');
1292
1386
  }
1293
1387
 
1294
- const finalizedBlock = await archiver.getL2Tips().then(tips => tips.finalized.number);
1388
+ const finalizedBlock = await archiver.getL2Tips().then(tips => tips.finalized.block.number);
1295
1389
  if (targetBlock < finalizedBlock) {
1296
1390
  if (force) {
1297
1391
  this.log.warn(`Clearing world state database to allow rolling back behind finalized block ${finalizedBlock}`);
@@ -1352,17 +1446,108 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1352
1446
  }
1353
1447
  }
1354
1448
 
1449
+ public async reloadKeystore(): Promise<void> {
1450
+ if (!this.config.keyStoreDirectory?.length) {
1451
+ throw new BadRequestError(
1452
+ 'Cannot reload keystore: node is not using a file-based keystore. ' +
1453
+ 'Set KEY_STORE_DIRECTORY to use file-based keystores.',
1454
+ );
1455
+ }
1456
+ if (!this.validatorClient) {
1457
+ throw new BadRequestError('Cannot reload keystore: validator is not enabled.');
1458
+ }
1459
+
1460
+ this.log.info('Reloading keystore from disk');
1461
+
1462
+ // Re-read and validate keystore files
1463
+ const keyStores = loadKeystores(this.config.keyStoreDirectory);
1464
+ const newManager = new KeystoreManager(mergeKeystores(keyStores));
1465
+ await newManager.validateSigners();
1466
+ ValidatorClient.validateKeyStoreConfiguration(newManager, this.log);
1467
+
1468
+ // Validate that every validator's publisher keys overlap with the L1 signers
1469
+ // that were initialized at startup. Publishers cannot be hot-reloaded, so a
1470
+ // validator with a publisher key that doesn't match any existing L1 signer
1471
+ // would silently fail on every proposer slot.
1472
+ if (this.keyStoreManager && this.sequencer) {
1473
+ const oldAdapter = NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager);
1474
+ const availablePublishers = new Set(
1475
+ oldAdapter
1476
+ .getAttesterAddresses()
1477
+ .flatMap(a => oldAdapter.getPublisherAddresses(a).map(p => p.toString().toLowerCase())),
1478
+ );
1479
+
1480
+ const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
1481
+ for (const attester of newAdapter.getAttesterAddresses()) {
1482
+ const pubs = newAdapter.getPublisherAddresses(attester);
1483
+ if (pubs.length > 0 && !pubs.some(p => availablePublishers.has(p.toString().toLowerCase()))) {
1484
+ throw new BadRequestError(
1485
+ `Cannot reload keystore: validator ${attester} has publisher keys ` +
1486
+ `[${pubs.map(p => p.toString()).join(', ')}] but none match the L1 signers initialized at startup ` +
1487
+ `[${[...availablePublishers].join(', ')}]. Publishers cannot be hot-reloaded — ` +
1488
+ `use an existing publisher key or restart the node.`,
1489
+ );
1490
+ }
1491
+ }
1492
+ }
1493
+
1494
+ // Build adapters for old and new keystores to compute diff
1495
+ const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
1496
+ const newAddresses = newAdapter.getAttesterAddresses();
1497
+ const oldAddresses = this.keyStoreManager
1498
+ ? NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager).getAttesterAddresses()
1499
+ : [];
1500
+
1501
+ const oldSet = new Set(oldAddresses.map(a => a.toString()));
1502
+ const newSet = new Set(newAddresses.map(a => a.toString()));
1503
+ const added = newAddresses.filter(a => !oldSet.has(a.toString()));
1504
+ const removed = oldAddresses.filter(a => !newSet.has(a.toString()));
1505
+
1506
+ if (added.length > 0) {
1507
+ this.log.info(`Keystore reload: adding attester keys: ${added.map(a => a.toString()).join(', ')}`);
1508
+ }
1509
+ if (removed.length > 0) {
1510
+ this.log.info(`Keystore reload: removing attester keys: ${removed.map(a => a.toString()).join(', ')}`);
1511
+ }
1512
+ if (added.length === 0 && removed.length === 0) {
1513
+ this.log.info('Keystore reload: attester keys unchanged');
1514
+ }
1515
+
1516
+ // Update the validator client (coinbase, feeRecipient, attester keys)
1517
+ this.validatorClient.reloadKeystore(newManager);
1518
+
1519
+ // Update the publisher factory's keystore so newly-added validators
1520
+ // can be matched to existing publisher keys when proposing blocks.
1521
+ if (this.sequencer) {
1522
+ this.sequencer.updatePublisherNodeKeyStore(newAdapter);
1523
+ }
1524
+
1525
+ // Update slasher's "don't-slash-self" list with new validator addresses
1526
+ if (this.slasherClient && !this.config.slashSelfAllowed) {
1527
+ const slashValidatorsNever = unique(
1528
+ [...(this.config.slashValidatorsNever ?? []), ...newAddresses].map(a => a.toString()),
1529
+ ).map(EthAddress.fromString);
1530
+ this.slasherClient.updateConfig({ slashValidatorsNever });
1531
+ }
1532
+
1533
+ this.keyStoreManager = newManager;
1534
+ this.log.info('Keystore reloaded: coinbase, feeRecipient, and attester keys updated');
1535
+ }
1536
+
1537
+ #getInitialHeaderHash(): Promise<BlockHash> {
1538
+ if (!this.initialHeaderHashPromise) {
1539
+ this.initialHeaderHashPromise = this.worldStateSynchronizer.getCommitted().getInitialHeader().hash();
1540
+ }
1541
+ return this.initialHeaderHashPromise;
1542
+ }
1543
+
1355
1544
  /**
1356
1545
  * Returns an instance of MerkleTreeOperations having first ensured the world state is fully synched
1357
- * @param blockNumber - The block number at which to get the data.
1546
+ * @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
1358
1547
  * @returns An instance of a committed MerkleTreeOperations
1359
1548
  */
1360
- async #getWorldState(blockNumber: L2BlockNumber) {
1361
- if (typeof blockNumber === 'number' && blockNumber < INITIAL_L2_BLOCK_NUM - 1) {
1362
- throw new Error('Invalid block number to get world state for: ' + blockNumber);
1363
- }
1364
-
1365
- let blockSyncedTo: number = 0;
1549
+ async #getWorldState(block: BlockParameter) {
1550
+ let blockSyncedTo: BlockNumber = BlockNumber.ZERO;
1366
1551
  try {
1367
1552
  // Attempt to sync the world state if necessary
1368
1553
  blockSyncedTo = await this.#syncWorldState();
@@ -1370,15 +1555,39 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1370
1555
  this.log.error(`Error getting world state: ${err}`);
1371
1556
  }
1372
1557
 
1373
- // using a snapshot could be less efficient than using the committed db
1374
- if (blockNumber === 'latest' /*|| blockNumber === blockSyncedTo*/) {
1375
- this.log.debug(`Using committed db for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
1558
+ if (block === 'latest') {
1559
+ this.log.debug(`Using committed db for block 'latest', world state synced upto ${blockSyncedTo}`);
1376
1560
  return this.worldStateSynchronizer.getCommitted();
1377
- } else if (blockNumber <= blockSyncedTo) {
1561
+ }
1562
+
1563
+ if (BlockHash.isBlockHash(block)) {
1564
+ const initialBlockHash = await this.#getInitialHeaderHash();
1565
+ if (block.equals(initialBlockHash)) {
1566
+ // Block source doesn't handle initial header so we need to handle the case separately.
1567
+ return this.worldStateSynchronizer.getSnapshot(BlockNumber.ZERO);
1568
+ }
1569
+
1570
+ const header = await this.blockSource.getBlockHeaderByHash(block);
1571
+ if (!header) {
1572
+ throw new Error(
1573
+ `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.`,
1574
+ );
1575
+ }
1576
+ const blockNumber = header.getBlockNumber();
1577
+ this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
1578
+ return this.worldStateSynchronizer.getSnapshot(blockNumber);
1579
+ }
1580
+
1581
+ // Block number provided
1582
+ {
1583
+ const blockNumber = block as BlockNumber;
1584
+
1585
+ if (blockNumber > blockSyncedTo) {
1586
+ throw new Error(`Queried block ${block} not yet synced by the node (node is synced upto ${blockSyncedTo}).`);
1587
+ }
1588
+
1378
1589
  this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
1379
1590
  return this.worldStateSynchronizer.getSnapshot(blockNumber);
1380
- } else {
1381
- throw new Error(`Block ${blockNumber} not yet synced`);
1382
1591
  }
1383
1592
  }
1384
1593
 
@@ -1386,8 +1595,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1386
1595
  * Ensure we fully sync the world state
1387
1596
  * @returns A promise that fulfils once the world state is synced
1388
1597
  */
1389
- async #syncWorldState(): Promise<number> {
1598
+ async #syncWorldState(): Promise<BlockNumber> {
1390
1599
  const blockSourceHeight = await this.blockSource.getBlockNumber();
1391
- return this.worldStateSynchronizer.syncImmediate(blockSourceHeight);
1600
+ return await this.worldStateSynchronizer.syncImmediate(blockSourceHeight);
1392
1601
  }
1393
1602
  }