@aztec/aztec-node 0.0.1-commit.9593d84 → 0.0.1-commit.96dac018d

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,36 @@
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 { SlotNumber } from '@aztec/foundation/branded-types';
21
- 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';
22
14
  import { EthAddress } from '@aztec/foundation/eth-address';
23
- import { Fr } from '@aztec/foundation/fields';
24
15
  import { BadRequestError } from '@aztec/foundation/json-rpc';
25
16
  import { type Logger, createLogger } from '@aztec/foundation/log';
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';
32
- import { type P2P, type P2PClientDeps, createP2PClient, getDefaultAllowedSetupFunctions } from '@aztec/p2p';
33
- import { ProtocolContractAddress } from '@aztec/protocol-contracts';
22
+ import { createForwarderL1TxUtilsFromSigners, createL1TxUtilsFromSigners } from '@aztec/node-lib/factories';
34
23
  import {
35
- BlockBuilder,
36
- GlobalVariableBuilder,
37
- SequencerClient,
38
- type SequencerPublisher,
39
- createValidatorForAcceptingTxs,
40
- } from '@aztec/sequencer-client';
24
+ type P2P,
25
+ type P2PClientDeps,
26
+ createP2PClient,
27
+ createTxValidatorForAcceptingTxsOverRPC,
28
+ getDefaultAllowedSetupFunctions,
29
+ } from '@aztec/p2p';
30
+ import { ProtocolContractAddress } from '@aztec/protocol-contracts';
31
+ import { type ProverNode, type ProverNodeDeps, createProverNode } from '@aztec/prover-node';
32
+ import { createKeyStoreForProver } from '@aztec/prover-node/config';
33
+ import { GlobalVariableBuilder, SequencerClient, type SequencerPublisher } from '@aztec/sequencer-client';
41
34
  import { PublicProcessorFactory } from '@aztec/simulator/server';
42
35
  import {
43
36
  AttestationsBlockWatcher,
@@ -46,16 +39,17 @@ import {
46
39
  type Watcher,
47
40
  createSlasher,
48
41
  } from '@aztec/slasher';
49
- import { PublicSimulatorConfig } from '@aztec/stdlib/avm';
42
+ import { CollectionLimitsConfig, PublicSimulatorConfig } from '@aztec/stdlib/avm';
50
43
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
51
44
  import {
52
- type InBlock,
53
- type L2Block,
54
- L2BlockHash,
55
- type L2BlockNumber,
45
+ type BlockData,
46
+ BlockHash,
47
+ type BlockParameter,
48
+ type DataInBlock,
49
+ L2Block,
56
50
  type L2BlockSource,
57
- type PublishedL2Block,
58
51
  } from '@aztec/stdlib/block';
52
+ import type { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
59
53
  import type {
60
54
  ContractClassPublic,
61
55
  ContractDataSource,
@@ -63,7 +57,7 @@ import type {
63
57
  NodeInfo,
64
58
  ProtocolContractAddresses,
65
59
  } from '@aztec/stdlib/contract';
66
- import type { GasFees } from '@aztec/stdlib/gas';
60
+ import { GasFees } from '@aztec/stdlib/gas';
67
61
  import { computePublicDataTreeLeafSlot } from '@aztec/stdlib/hash';
68
62
  import {
69
63
  type AztecNode,
@@ -82,7 +76,8 @@ import {
82
76
  type WorldStateSynchronizer,
83
77
  tryStop,
84
78
  } from '@aztec/stdlib/interfaces/server';
85
- import type { LogFilter, PrivateLog, 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';
86
81
  import { InboxLeaf, type L1ToL2MessageSource } from '@aztec/stdlib/messaging';
87
82
  import { P2PClientType } from '@aztec/stdlib/p2p';
88
83
  import type { Offense, SlashPayloadRound } from '@aztec/stdlib/slashing';
@@ -110,6 +105,8 @@ import {
110
105
  trackSpan,
111
106
  } from '@aztec/telemetry-client';
112
107
  import {
108
+ FullNodeCheckpointsBuilder as CheckpointsBuilder,
109
+ FullNodeCheckpointsBuilder,
113
110
  NodeKeystoreAdapter,
114
111
  ValidatorClient,
115
112
  createBlockProposalHandler,
@@ -129,6 +126,7 @@ import { NodeMetrics } from './node_metrics.js';
129
126
  */
130
127
  export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
131
128
  private metrics: NodeMetrics;
129
+ private initialHeaderHashPromise: Promise<BlockHash> | undefined = undefined;
132
130
 
133
131
  // Prevent two snapshot operations to happen simultaneously
134
132
  private isUploadingSnapshot = false;
@@ -144,6 +142,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
144
142
  protected readonly l1ToL2MessageSource: L1ToL2MessageSource,
145
143
  protected readonly worldStateSynchronizer: WorldStateSynchronizer,
146
144
  protected readonly sequencer: SequencerClient | undefined,
145
+ protected readonly proverNode: ProverNode | undefined,
147
146
  protected readonly slasherClient: SlasherClientInterface | undefined,
148
147
  protected readonly validatorsSentinel: Sentinel | undefined,
149
148
  protected readonly epochPruneWatcher: EpochPruneWatcher | undefined,
@@ -155,12 +154,23 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
155
154
  private proofVerifier: ClientProtocolCircuitVerifier,
156
155
  private telemetry: TelemetryClient = getTelemetryClient(),
157
156
  private log = createLogger('node'),
157
+ private blobClient?: BlobClientInterface,
158
+ private validatorClient?: ValidatorClient,
159
+ private keyStoreManager?: KeystoreManager,
160
+ private debugLogStore: DebugLogStore = new NullDebugLogStore(),
158
161
  ) {
159
162
  this.metrics = new NodeMetrics(telemetry, 'AztecNodeService');
160
163
  this.tracer = telemetry.getTracer('AztecNodeService');
161
164
 
162
165
  this.log.info(`Aztec Node version: ${this.packageVersion}`);
163
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
+ }
164
174
  }
165
175
 
166
176
  public async getWorldStateSyncStatus(): Promise<WorldStateSyncStatus> {
@@ -184,12 +194,13 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
184
194
  logger?: Logger;
185
195
  publisher?: SequencerPublisher;
186
196
  dateProvider?: DateProvider;
187
- blobSinkClient?: BlobSinkClientInterface;
188
197
  p2pClientDeps?: P2PClientDeps<P2PClientType.Full>;
198
+ proverNodeDeps?: Partial<ProverNodeDeps>;
189
199
  } = {},
190
200
  options: {
191
201
  prefilledPublicData?: PublicDataTreeLeaf[];
192
202
  dontStartSequencer?: boolean;
203
+ dontStartProverNode?: boolean;
193
204
  } = {},
194
205
  ): Promise<AztecNodeService> {
195
206
  const config = { ...inputConfig }; // Copy the config so we dont mutate the input object
@@ -197,20 +208,31 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
197
208
  const packageVersion = getPackageVersion() ?? '';
198
209
  const telemetry = deps.telemetry ?? getTelemetryClient();
199
210
  const dateProvider = deps.dateProvider ?? new DateProvider();
200
- const blobSinkClient =
201
- deps.blobSinkClient ?? createBlobSinkClient(config, { logger: createLogger('node:blob-sink:client') });
202
211
  const ethereumChain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
203
212
 
204
- // 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.
205
215
  let keyStoreManager: KeystoreManager | undefined;
206
216
  const keyStoreProvided = config.keyStoreDirectory !== undefined && config.keyStoreDirectory.length > 0;
207
217
  if (keyStoreProvided) {
208
218
  const keyStores = loadKeystores(config.keyStoreDirectory!);
209
219
  keyStoreManager = new KeystoreManager(mergeKeystores(keyStores));
210
220
  } else {
211
- const keyStore = createKeyStoreForValidator(config);
212
- if (keyStore) {
213
- 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
+ );
214
236
  }
215
237
  }
216
238
 
@@ -221,10 +243,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
221
243
  if (keyStoreManager === undefined) {
222
244
  throw new Error('Failed to create key store, a requirement for running a validator');
223
245
  }
224
- if (!keyStoreProvided) {
225
- log.warn(
226
- 'KEY STORE CREATED FROM ENVIRONMENT, IT IS RECOMMENDED TO USE A FILE-BASED KEY STORE IN PRODUCTION ENVIRONMENTS',
227
- );
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");
228
248
  }
229
249
  ValidatorClient.validateKeyStoreConfiguration(keyStoreManager, log);
230
250
  }
@@ -238,7 +258,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
238
258
 
239
259
  const publicClient = createPublicClient({
240
260
  chain: ethereumChain.chainInfo,
241
- transport: fallback(config.l1RpcUrls.map((url: string) => http(url))),
261
+ transport: fallback(config.l1RpcUrls.map((url: string) => http(url, { batch: false }))),
242
262
  pollingInterval: config.viemPollingIntervalMS,
243
263
  });
244
264
 
@@ -266,6 +286,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
266
286
  );
267
287
  }
268
288
 
289
+ const blobClient = await createBlobClientWithFileStores(config, log.createChild('blob-client'));
290
+
269
291
  // attempt snapshot sync if possible
270
292
  await trySnapshotSync(config, log);
271
293
 
@@ -273,7 +295,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
273
295
 
274
296
  const archiver = await createArchiver(
275
297
  config,
276
- { blobSinkClient, epochCache, telemetry, dateProvider },
298
+ { blobClient, epochCache, telemetry, dateProvider },
277
299
  { blockUntilSync: !config.skipArchiverInitialSync },
278
300
  );
279
301
 
@@ -284,12 +306,23 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
284
306
  options.prefilledPublicData,
285
307
  telemetry,
286
308
  );
287
- const circuitVerifier = config.realProofs
288
- ? await BBCircuitVerifier.new(config)
289
- : new TestCircuitVerifier(config.proverTestVerificationDelayMs);
309
+ const circuitVerifier =
310
+ config.realProofs || config.debugForceTxProofVerification
311
+ ? await BBCircuitVerifier.new(config)
312
+ : new TestCircuitVerifier(config.proverTestVerificationDelayMs);
313
+
314
+ let debugLogStore: DebugLogStore;
290
315
  if (!config.realProofs) {
291
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();
292
324
  }
325
+
293
326
  const proofVerifier = new QueuedIVCVerifier(config, circuitVerifier);
294
327
 
295
328
  // create the tx pool and the p2p client, which will need the l2 block source
@@ -309,7 +342,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
309
342
  // We should really not be modifying the config object
310
343
  config.txPublicSetupAllowList = config.txPublicSetupAllowList ?? (await getDefaultAllowedSetupFunctions());
311
344
 
312
- const blockBuilder = new BlockBuilder(
345
+ // Create FullNodeCheckpointsBuilder for validator and non-validator block proposal handling
346
+ const validatorCheckpointsBuilder = new FullNodeCheckpointsBuilder(
313
347
  { ...config, l1GenesisTime, slotDuration: Number(slotDuration) },
314
348
  worldStateSynchronizer,
315
349
  archiver,
@@ -321,15 +355,17 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
321
355
  const watchers: Watcher[] = [];
322
356
 
323
357
  // Create validator client if required
324
- const validatorClient = createValidatorClient(config, {
358
+ const validatorClient = await createValidatorClient(config, {
359
+ checkpointsBuilder: validatorCheckpointsBuilder,
360
+ worldState: worldStateSynchronizer,
325
361
  p2pClient,
326
362
  telemetry,
327
363
  dateProvider,
328
364
  epochCache,
329
- blockBuilder,
330
365
  blockSource: archiver,
331
366
  l1ToL2MessageSource: archiver,
332
367
  keyStoreManager,
368
+ blobClient,
333
369
  });
334
370
 
335
371
  // If we have a validator client, register it as a source of offenses for the slasher,
@@ -347,7 +383,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
347
383
  if (!validatorClient && config.alwaysReexecuteBlockProposals) {
348
384
  log.info('Setting up block proposal reexecution for monitoring');
349
385
  createBlockProposalHandler(config, {
350
- blockBuilder,
386
+ checkpointsBuilder: validatorCheckpointsBuilder,
387
+ worldState: worldStateSynchronizer,
351
388
  epochCache,
352
389
  blockSource: archiver,
353
390
  l1ToL2MessageSource: archiver,
@@ -375,7 +412,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
375
412
  archiver,
376
413
  epochCache,
377
414
  p2pClient.getTxProvider(),
378
- blockBuilder,
415
+ validatorCheckpointsBuilder,
379
416
  config,
380
417
  );
381
418
  watchers.push(epochPruneWatcher);
@@ -403,7 +440,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
403
440
  // Validator enabled, create/start relevant service
404
441
  let sequencer: SequencerClient | undefined;
405
442
  let slasherClient: SlasherClientInterface | undefined;
406
- if (!config.disableValidator) {
443
+ if (!config.disableValidator && validatorClient) {
407
444
  // We create a slasher only if we have a sequencer, since all slashing actions go through the sequencer publisher
408
445
  // as they are executed when the node is selected as proposer.
409
446
  const validatorAddresses = keyStoreManager
@@ -422,14 +459,31 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
422
459
  );
423
460
  await slasherClient.start();
424
461
 
425
- const l1TxUtils = await createL1TxUtilsWithBlobsFromEthSigner(
426
- publicClient,
427
- keyStoreManager!.createAllValidatorPublisherSigners(),
428
- { ...config, scope: 'sequencer' },
429
- { telemetry, logger: log.createChild('l1-tx-utils'), dateProvider },
430
- );
462
+ const l1TxUtils = config.sequencerPublisherForwarderAddress
463
+ ? await createForwarderL1TxUtilsFromSigners(
464
+ publicClient,
465
+ keyStoreManager!.createAllValidatorPublisherSigners(),
466
+ config.sequencerPublisherForwarderAddress,
467
+ { ...config, scope: 'sequencer' },
468
+ { telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
469
+ )
470
+ : await createL1TxUtilsFromSigners(
471
+ publicClient,
472
+ keyStoreManager!.createAllValidatorPublisherSigners(),
473
+ { ...config, scope: 'sequencer' },
474
+ { telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
475
+ );
431
476
 
432
477
  // Create and start the sequencer client
478
+ const checkpointsBuilder = new CheckpointsBuilder(
479
+ { ...config, l1GenesisTime, slotDuration: Number(slotDuration) },
480
+ worldStateSynchronizer,
481
+ archiver,
482
+ dateProvider,
483
+ telemetry,
484
+ debugLogStore,
485
+ );
486
+
433
487
  sequencer = await SequencerClient.new(config, {
434
488
  ...deps,
435
489
  epochCache,
@@ -438,12 +492,12 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
438
492
  p2pClient,
439
493
  worldStateSynchronizer,
440
494
  slasherClient,
441
- blockBuilder,
495
+ checkpointsBuilder,
442
496
  l2BlockSource: archiver,
443
497
  l1ToL2MessageSource: archiver,
444
498
  telemetry,
445
499
  dateProvider,
446
- blobSinkClient,
500
+ blobClient,
447
501
  nodeKeyStore: keyStoreManager!,
448
502
  });
449
503
  }
@@ -455,7 +509,37 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
455
509
  log.warn(`Sequencer created but not started`);
456
510
  }
457
511
 
458
- return new AztecNodeService(
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
+
535
+ const globalVariableBuilder = new GlobalVariableBuilder({
536
+ ...config,
537
+ rollupVersion: BigInt(config.rollupVersion),
538
+ l1GenesisTime,
539
+ slotDuration: Number(slotDuration),
540
+ });
541
+
542
+ const node = new AztecNodeService(
459
543
  config,
460
544
  p2pClient,
461
545
  archiver,
@@ -464,18 +548,25 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
464
548
  archiver,
465
549
  worldStateSynchronizer,
466
550
  sequencer,
551
+ proverNode,
467
552
  slasherClient,
468
553
  validatorsSentinel,
469
554
  epochPruneWatcher,
470
555
  ethereumChain.chainInfo.id,
471
556
  config.rollupVersion,
472
- new GlobalVariableBuilder(config),
557
+ globalVariableBuilder,
473
558
  epochCache,
474
559
  packageVersion,
475
560
  proofVerifier,
476
561
  telemetry,
477
562
  log,
563
+ blobClient,
564
+ validatorClient,
565
+ keyStoreManager,
566
+ debugLogStore,
478
567
  );
568
+
569
+ return node;
479
570
  }
480
571
 
481
572
  /**
@@ -486,6 +577,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
486
577
  return this.sequencer;
487
578
  }
488
579
 
580
+ /** Returns the prover node subsystem, if enabled. */
581
+ public getProverNode(): ProverNode | undefined {
582
+ return this.proverNode;
583
+ }
584
+
489
585
  public getBlockSource(): L2BlockSource {
490
586
  return this.blockSource;
491
587
  }
@@ -539,19 +635,26 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
539
635
  enr,
540
636
  l1ContractAddresses: contractAddresses,
541
637
  protocolContractAddresses: protocolContractAddresses,
638
+ realProofs: !!this.config.realProofs,
542
639
  };
543
640
 
544
641
  return nodeInfo;
545
642
  }
546
643
 
547
644
  /**
548
- * Get a block specified by its number.
549
- * @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').
550
647
  * @returns The requested block.
551
648
  */
552
- public async getBlock(number: L2BlockNumber): Promise<L2Block | undefined> {
553
- const blockNumber = number === 'latest' ? await this.getBlockNumber() : number;
554
- 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);
555
658
  }
556
659
 
557
660
  /**
@@ -559,9 +662,17 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
559
662
  * @param blockHash - The block hash being requested.
560
663
  * @returns The requested block.
561
664
  */
562
- public async getBlockByHash(blockHash: Fr): Promise<L2Block | undefined> {
563
- const publishedBlock = await this.blockSource.getPublishedBlockByHash(blockHash);
564
- 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);
565
676
  }
566
677
 
567
678
  /**
@@ -570,8 +681,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
570
681
  * @returns The requested block.
571
682
  */
572
683
  public async getBlockByArchive(archive: Fr): Promise<L2Block | undefined> {
573
- const publishedBlock = await this.blockSource.getPublishedBlockByArchive(archive);
574
- return publishedBlock?.block;
684
+ return await this.blockSource.getL2BlockByArchive(archive);
575
685
  }
576
686
 
577
687
  /**
@@ -580,34 +690,50 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
580
690
  * @param limit - The maximum number of blocks to obtain.
581
691
  * @returns The blocks requested.
582
692
  */
583
- public async getBlocks(from: number, limit: number): Promise<L2Block[]> {
584
- return (await this.blockSource.getBlocks(from, limit)) ?? [];
693
+ public async getBlocks(from: BlockNumber, limit: number): Promise<L2Block[]> {
694
+ return (await this.blockSource.getBlocks(from, BlockNumber(limit))) ?? [];
585
695
  }
586
696
 
587
- public async getPublishedBlocks(from: number, limit: number): Promise<PublishedL2Block[]> {
588
- return (await this.blockSource.getPublishedBlocks(from, limit)) ?? [];
697
+ public async getCheckpoints(from: CheckpointNumber, limit: number): Promise<PublishedCheckpoint[]> {
698
+ return (await this.blockSource.getCheckpoints(from, limit)) ?? [];
699
+ }
700
+
701
+ public async getCheckpointedBlocks(from: BlockNumber, limit: number) {
702
+ return (await this.blockSource.getCheckpointedBlocks(from, limit)) ?? [];
589
703
  }
590
704
 
591
705
  /**
592
- * Method to fetch the current base fees.
593
- * @returns The current base fees.
706
+ * Method to fetch the current min L2 fees.
707
+ * @returns The current min L2 fees.
594
708
  */
595
- public async getCurrentBaseFees(): Promise<GasFees> {
596
- return await this.globalVariableBuilder.getCurrentBaseFees();
709
+ public async getCurrentMinFees(): Promise<GasFees> {
710
+ return await this.globalVariableBuilder.getCurrentMinFees();
711
+ }
712
+
713
+ public async getMaxPriorityFees(): Promise<GasFees> {
714
+ for await (const tx of this.p2pClient.iteratePendingTxs()) {
715
+ return tx.getGasSettings().maxPriorityFeesPerGas;
716
+ }
717
+
718
+ return GasFees.from({ feePerDaGas: 0n, feePerL2Gas: 0n });
597
719
  }
598
720
 
599
721
  /**
600
722
  * Method to fetch the latest block number synchronized by the node.
601
723
  * @returns The block number.
602
724
  */
603
- public async getBlockNumber(): Promise<number> {
725
+ public async getBlockNumber(): Promise<BlockNumber> {
604
726
  return await this.blockSource.getBlockNumber();
605
727
  }
606
728
 
607
- public async getProvenBlockNumber(): Promise<number> {
729
+ public async getProvenBlockNumber(): Promise<BlockNumber> {
608
730
  return await this.blockSource.getProvenBlockNumber();
609
731
  }
610
732
 
733
+ public async getCheckpointedBlockNumber(): Promise<BlockNumber> {
734
+ return await this.blockSource.getCheckpointedL2BlockNumber();
735
+ }
736
+
611
737
  /**
612
738
  * Method to fetch the version of the package.
613
739
  * @returns The node package version
@@ -640,25 +766,43 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
640
766
  return this.contractDataSource.getContract(address);
641
767
  }
642
768
 
643
- /**
644
- * Retrieves all private logs from up to `limit` blocks, starting from the block number `from`.
645
- * @param from - The block number from which to begin retrieving logs.
646
- * @param limit - The maximum number of blocks to retrieve logs from.
647
- * @returns An array of private logs from the specified range of blocks.
648
- */
649
- public getPrivateLogs(from: number, limit: number): Promise<PrivateLog[]> {
650
- return this.logsSource.getPrivateLogs(from, limit);
651
- }
652
-
653
- /**
654
- * Gets all logs that match any of the received tags (i.e. logs with their first field equal to a tag).
655
- * @param tags - The tags to filter the logs by.
656
- * @param logsPerTag - The maximum number of logs to return for each tag. By default no limit is set
657
- * @returns For each received tag, an array of matching logs is returned. An empty array implies no logs match
658
- * that tag.
659
- */
660
- public getLogsByTags(tags: Fr[], logsPerTag?: number): Promise<TxScopedL2Log[][]> {
661
- return this.logsSource.getLogsByTags(tags, logsPerTag);
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);
662
806
  }
663
807
 
664
808
  /**
@@ -705,21 +849,30 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
705
849
  }
706
850
 
707
851
  public async getTxReceipt(txHash: TxHash): Promise<TxReceipt> {
708
- let txReceipt = new TxReceipt(txHash, TxStatus.DROPPED, 'Tx dropped by P2P node.');
709
-
710
- // We first check if the tx is in pending (instead of first checking if it is mined) because if we first check
711
- // for mined and then for pending there could be a race condition where the tx is mined between the two checks
712
- // and we would incorrectly return a TxReceipt with status DROPPED
713
- if ((await this.p2pClient.getTxStatus(txHash)) === 'pending') {
714
- txReceipt = new TxReceipt(txHash, TxStatus.PENDING, '');
715
- }
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';
716
856
 
857
+ // Then get the actual tx from the archiver, which tracks every tx in a mined block.
717
858
  const settledTxReceipt = await this.blockSource.getSettledTxReceipt(txHash);
859
+
860
+ let receipt: TxReceipt;
718
861
  if (settledTxReceipt) {
719
- 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');
720
871
  }
721
872
 
722
- return txReceipt;
873
+ this.debugLogStore.decorateReceiptWithLogs(txHash.toString(), receipt);
874
+
875
+ return receipt;
723
876
  }
724
877
 
725
878
  public getTxEffect(txHash: TxHash): Promise<IndexedTxEffect | undefined> {
@@ -736,13 +889,23 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
736
889
  await tryStop(this.slasherClient);
737
890
  await tryStop(this.proofVerifier);
738
891
  await tryStop(this.sequencer);
892
+ await tryStop(this.proverNode);
739
893
  await tryStop(this.p2pClient);
740
894
  await tryStop(this.worldStateSynchronizer);
741
895
  await tryStop(this.blockSource);
896
+ await tryStop(this.blobClient);
742
897
  await tryStop(this.telemetry);
743
898
  this.log.info(`Stopped Aztec Node`);
744
899
  }
745
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
+
746
909
  /**
747
910
  * Method to retrieve pending txs.
748
911
  * @param limit - The number of items to returns
@@ -775,20 +938,12 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
775
938
  return compactArray(await Promise.all(txHashes.map(txHash => this.getTxByHash(txHash))));
776
939
  }
777
940
 
778
- /**
779
- * Find the indexes of the given leaves in the given tree along with a block metadata pointing to the block in which
780
- * the leaves were inserted.
781
- * @param blockNumber - The block number at which to get the data or 'latest' for latest data.
782
- * @param treeId - The tree to search in.
783
- * @param leafValues - The values to search for.
784
- * @returns The indices of leaves and the block metadata of a block in which the leaves were inserted.
785
- */
786
941
  public async findLeavesIndexes(
787
- blockNumber: L2BlockNumber,
942
+ referenceBlock: BlockParameter,
788
943
  treeId: MerkleTreeId,
789
944
  leafValues: Fr[],
790
- ): Promise<(InBlock<bigint> | undefined)[]> {
791
- const committedDb = await this.#getWorldState(blockNumber);
945
+ ): Promise<(DataInBlock<bigint> | undefined)[]> {
946
+ const committedDb = await this.#getWorldState(referenceBlock);
792
947
  const maybeIndices = await committedDb.findLeafIndices(
793
948
  treeId,
794
949
  leafValues.map(x => x.toBuffer()),
@@ -813,7 +968,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
813
968
  // (note that block number corresponds to the leaf index in the archive tree).
814
969
  const blockHashes = await Promise.all(
815
970
  uniqueBlockNumbers.map(blockNumber => {
816
- return committedDb.getLeafValue(MerkleTreeId.ARCHIVE, blockNumber!);
971
+ return committedDb.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
817
972
  }),
818
973
  );
819
974
 
@@ -824,7 +979,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
824
979
  }
825
980
  }
826
981
 
827
- // Create InBlock objects by combining indices, blockNumbers and blockHashes and return them.
982
+ // Create DataInBlock objects by combining indices, blockNumbers and blockHashes and return them.
828
983
  return maybeIndices.map((index, i) => {
829
984
  if (index === undefined) {
830
985
  return undefined;
@@ -839,57 +994,29 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
839
994
  return undefined;
840
995
  }
841
996
  return {
842
- l2BlockNumber: Number(blockNumber),
843
- l2BlockHash: L2BlockHash.fromField(blockHash),
997
+ l2BlockNumber: BlockNumber(Number(blockNumber)),
998
+ l2BlockHash: new BlockHash(blockHash),
844
999
  data: index,
845
1000
  };
846
1001
  });
847
1002
  }
848
1003
 
849
- /**
850
- * Returns a sibling path for the given index in the nullifier tree.
851
- * @param blockNumber - The block number at which to get the data.
852
- * @param leafIndex - The index of the leaf for which the sibling path is required.
853
- * @returns The sibling path for the leaf index.
854
- */
855
- public async getNullifierSiblingPath(
856
- blockNumber: L2BlockNumber,
857
- leafIndex: bigint,
858
- ): Promise<SiblingPath<typeof NULLIFIER_TREE_HEIGHT>> {
859
- const committedDb = await this.#getWorldState(blockNumber);
860
- return committedDb.getSiblingPath(MerkleTreeId.NULLIFIER_TREE, leafIndex);
861
- }
862
-
863
- /**
864
- * Returns a sibling path for the given index in the data tree.
865
- * @param blockNumber - The block number at which to get the data.
866
- * @param leafIndex - The index of the leaf for which the sibling path is required.
867
- * @returns The sibling path for the leaf index.
868
- */
869
- public async getNoteHashSiblingPath(
870
- blockNumber: L2BlockNumber,
871
- leafIndex: bigint,
872
- ): Promise<SiblingPath<typeof NOTE_HASH_TREE_HEIGHT>> {
873
- const committedDb = await this.#getWorldState(blockNumber);
874
- return committedDb.getSiblingPath(MerkleTreeId.NOTE_HASH_TREE, leafIndex);
875
- }
876
-
877
- public async getArchiveMembershipWitness(
878
- blockNumber: L2BlockNumber,
879
- archive: Fr,
1004
+ public async getBlockHashMembershipWitness(
1005
+ referenceBlock: BlockParameter,
1006
+ blockHash: BlockHash,
880
1007
  ): Promise<MembershipWitness<typeof ARCHIVE_HEIGHT> | undefined> {
881
- const committedDb = await this.#getWorldState(blockNumber);
882
- 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]);
883
1010
  return pathAndIndex === undefined
884
1011
  ? undefined
885
1012
  : MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
886
1013
  }
887
1014
 
888
1015
  public async getNoteHashMembershipWitness(
889
- blockNumber: L2BlockNumber,
1016
+ referenceBlock: BlockParameter,
890
1017
  noteHash: Fr,
891
1018
  ): Promise<MembershipWitness<typeof NOTE_HASH_TREE_HEIGHT> | undefined> {
892
- const committedDb = await this.#getWorldState(blockNumber);
1019
+ const committedDb = await this.#getWorldState(referenceBlock);
893
1020
  const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.NOTE_HASH_TREE>(
894
1021
  MerkleTreeId.NOTE_HASH_TREE,
895
1022
  [noteHash],
@@ -899,17 +1026,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
899
1026
  : MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
900
1027
  }
901
1028
 
902
- /**
903
- * Returns the index and a sibling path for a leaf in the committed l1 to l2 data tree.
904
- * @param blockNumber - The block number at which to get the data.
905
- * @param l1ToL2Message - The l1ToL2Message to get the index / sibling path for.
906
- * @returns A tuple of the index and the sibling path of the L1ToL2Message (undefined if not found).
907
- */
908
1029
  public async getL1ToL2MessageMembershipWitness(
909
- blockNumber: L2BlockNumber,
1030
+ referenceBlock: BlockParameter,
910
1031
  l1ToL2Message: Fr,
911
1032
  ): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>] | undefined> {
912
- const db = await this.#getWorldState(blockNumber);
1033
+ const db = await this.#getWorldState(referenceBlock);
913
1034
  const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [l1ToL2Message]);
914
1035
  if (!witness) {
915
1036
  return undefined;
@@ -919,9 +1040,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
919
1040
  return [witness.index, witness.path];
920
1041
  }
921
1042
 
922
- public async getL1ToL2MessageBlock(l1ToL2Message: Fr): Promise<number | undefined> {
1043
+ public async getL1ToL2MessageBlock(l1ToL2Message: Fr): Promise<BlockNumber | undefined> {
923
1044
  const messageIndex = await this.l1ToL2MessageSource.getL1ToL2MessageIndex(l1ToL2Message);
924
- return messageIndex ? InboxLeaf.l2BlockFromIndex(messageIndex) : undefined;
1045
+ return messageIndex
1046
+ ? BlockNumber.fromCheckpointNumber(InboxLeaf.checkpointNumberFromIndex(messageIndex))
1047
+ : undefined;
925
1048
  }
926
1049
 
927
1050
  /**
@@ -935,54 +1058,36 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
935
1058
  }
936
1059
 
937
1060
  /**
938
- * Returns all the L2 to L1 messages in a block.
939
- * @param blockNumber - The block number at which to get the data.
940
- * @returns The L2 to L1 messages (undefined if the block number is not found).
941
- */
942
- public async getL2ToL1Messages(blockNumber: L2BlockNumber): Promise<Fr[][] | undefined> {
943
- const block = await this.blockSource.getBlock(blockNumber === 'latest' ? await this.getBlockNumber() : blockNumber);
944
- return block?.body.txEffects.map(txEffect => txEffect.l2ToL1Msgs);
945
- }
946
-
947
- /**
948
- * Returns a sibling path for a leaf in the committed blocks tree.
949
- * @param blockNumber - The block number at which to get the data.
950
- * @param leafIndex - Index of the leaf in the tree.
951
- * @returns The sibling path.
952
- */
953
- public async getArchiveSiblingPath(
954
- blockNumber: L2BlockNumber,
955
- leafIndex: bigint,
956
- ): Promise<SiblingPath<typeof ARCHIVE_HEIGHT>> {
957
- const committedDb = await this.#getWorldState(blockNumber);
958
- return committedDb.getSiblingPath(MerkleTreeId.ARCHIVE, leafIndex);
959
- }
960
-
961
- /**
962
- * Returns a sibling path for a leaf in the committed public data tree.
963
- * @param blockNumber - The block number at which to get the data.
964
- * @param leafIndex - Index of the leaf in the tree.
965
- * @returns The sibling path.
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).
966
1064
  */
967
- public async getPublicDataSiblingPath(
968
- blockNumber: L2BlockNumber,
969
- leafIndex: bigint,
970
- ): Promise<SiblingPath<typeof PUBLIC_DATA_TREE_HEIGHT>> {
971
- const committedDb = await this.#getWorldState(blockNumber);
972
- return committedDb.getSiblingPath(MerkleTreeId.PUBLIC_DATA_TREE, leafIndex);
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)),
1083
+ );
973
1084
  }
974
1085
 
975
- /**
976
- * Returns a nullifier membership witness for a given nullifier at a given block.
977
- * @param blockNumber - The block number at which to get the index.
978
- * @param nullifier - Nullifier we try to find witness for.
979
- * @returns The nullifier membership witness (if found).
980
- */
981
1086
  public async getNullifierMembershipWitness(
982
- blockNumber: L2BlockNumber,
1087
+ referenceBlock: BlockParameter,
983
1088
  nullifier: Fr,
984
1089
  ): Promise<NullifierMembershipWitness | undefined> {
985
- const db = await this.#getWorldState(blockNumber);
1090
+ const db = await this.#getWorldState(referenceBlock);
986
1091
  const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [nullifier.toBuffer()]);
987
1092
  if (!witness) {
988
1093
  return undefined;
@@ -999,7 +1104,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
999
1104
 
1000
1105
  /**
1001
1106
  * Returns a low nullifier membership witness for a given nullifier at a given block.
1002
- * @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).
1003
1109
  * @param nullifier - Nullifier we try to find the low nullifier witness for.
1004
1110
  * @returns The low nullifier membership witness (if found).
1005
1111
  * @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
@@ -1012,10 +1118,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1012
1118
  * TODO: This is a confusing behavior and we should eventually address that.
1013
1119
  */
1014
1120
  public async getLowNullifierMembershipWitness(
1015
- blockNumber: L2BlockNumber,
1121
+ referenceBlock: BlockParameter,
1016
1122
  nullifier: Fr,
1017
1123
  ): Promise<NullifierMembershipWitness | undefined> {
1018
- const committedDb = await this.#getWorldState(blockNumber);
1124
+ const committedDb = await this.#getWorldState(referenceBlock);
1019
1125
  const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
1020
1126
  if (!findResult) {
1021
1127
  return undefined;
@@ -1030,8 +1136,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1030
1136
  return new NullifierMembershipWitness(BigInt(index), preimageData as NullifierLeafPreimage, siblingPath);
1031
1137
  }
1032
1138
 
1033
- async getPublicDataWitness(blockNumber: L2BlockNumber, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
1034
- const committedDb = await this.#getWorldState(blockNumber);
1139
+ async getPublicDataWitness(referenceBlock: BlockParameter, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
1140
+ const committedDb = await this.#getWorldState(referenceBlock);
1035
1141
  const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
1036
1142
  if (!lowLeafResult) {
1037
1143
  return undefined;
@@ -1045,19 +1151,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1045
1151
  }
1046
1152
  }
1047
1153
 
1048
- /**
1049
- * Gets the storage value at the given contract storage slot.
1050
- *
1051
- * @remarks The storage slot here refers to the slot as it is defined in Noir not the index in the merkle tree.
1052
- * Aztec's version of `eth_getStorageAt`.
1053
- *
1054
- * @param contract - Address of the contract to query.
1055
- * @param slot - Slot to query.
1056
- * @param blockNumber - The block number at which to get the data or 'latest'.
1057
- * @returns Storage value at the given contract slot.
1058
- */
1059
- public async getPublicStorageAt(blockNumber: L2BlockNumber, contract: AztecAddress, slot: Fr): Promise<Fr> {
1060
- 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);
1061
1156
  const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
1062
1157
 
1063
1158
  const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
@@ -1071,23 +1166,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1071
1166
  return preimage.leaf.value;
1072
1167
  }
1073
1168
 
1074
- /**
1075
- * Returns the currently committed block header, or the initial header if no blocks have been produced.
1076
- * @returns The current committed block header.
1077
- */
1078
- public async getBlockHeader(blockNumber: L2BlockNumber = 'latest'): Promise<BlockHeader | undefined> {
1079
- return blockNumber === 0 || (blockNumber === 'latest' && (await this.blockSource.getBlockNumber()) === 0)
1080
- ? this.worldStateSynchronizer.getCommitted().getInitialHeader()
1081
- : this.blockSource.getBlockHeader(blockNumber);
1082
- }
1083
-
1084
- /**
1085
- * Get a block header specified by its hash.
1086
- * @param blockHash - The block hash being requested.
1087
- * @returns The requested block header.
1088
- */
1089
- public async getBlockHeaderByHash(blockHash: Fr): Promise<BlockHeader | undefined> {
1090
- 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
+ }
1091
1185
  }
1092
1186
 
1093
1187
  /**
@@ -1099,6 +1193,14 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1099
1193
  return await this.blockSource.getBlockHeaderByArchive(archive);
1100
1194
  }
1101
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
+
1102
1204
  /**
1103
1205
  * Simulates the public part of a transaction with the current state.
1104
1206
  * @param tx - The transaction to simulate.
@@ -1122,7 +1224,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1122
1224
  }
1123
1225
 
1124
1226
  const txHash = tx.getTxHash();
1125
- const blockNumber = (await this.blockSource.getBlockNumber()) + 1;
1227
+ const latestBlockNumber = await this.blockSource.getBlockNumber();
1228
+ const blockNumber = BlockNumber.add(latestBlockNumber, 1);
1126
1229
 
1127
1230
  // If sequencer is not initialized, we just set these values to zero for simulation.
1128
1231
  const coinbase = EthAddress.ZERO;
@@ -1137,6 +1240,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1137
1240
  this.contractDataSource,
1138
1241
  new DateProvider(),
1139
1242
  this.telemetry,
1243
+ this.log.getBindings(),
1140
1244
  );
1141
1245
 
1142
1246
  this.log.verbose(`Simulating public calls for tx ${txHash}`, {
@@ -1145,6 +1249,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1145
1249
  blockNumber,
1146
1250
  });
1147
1251
 
1252
+ // Ensure world-state has caught up with the latest block we loaded from the archiver
1253
+ await this.worldStateSynchronizer.syncImmediate(latestBlockNumber);
1148
1254
  const merkleTreeFork = await this.worldStateSynchronizer.fork();
1149
1255
  try {
1150
1256
  const config = PublicSimulatorConfig.from({
@@ -1152,13 +1258,15 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1152
1258
  collectDebugLogs: true,
1153
1259
  collectHints: false,
1154
1260
  collectCallMetadata: true,
1155
- maxDebugLogMemoryReads: this.config.rpcSimulatePublicMaxDebugLogMemoryReads,
1156
1261
  collectStatistics: false,
1262
+ collectionLimits: CollectionLimitsConfig.from({
1263
+ maxDebugLogMemoryReads: this.config.rpcSimulatePublicMaxDebugLogMemoryReads,
1264
+ }),
1157
1265
  });
1158
1266
  const processor = publicProcessorFactory.create(merkleTreeFork, newGlobalVariables, config);
1159
1267
 
1160
1268
  // REFACTOR: Consider merging ProcessReturnValues into ProcessedTx
1161
- const [processedTxs, failedTxs, _usedTxs, returns] = await processor.process([tx]);
1269
+ const [processedTxs, failedTxs, _usedTxs, returns, _blobFields, debugLogs] = await processor.process([tx]);
1162
1270
  // REFACTOR: Consider returning the error rather than throwing
1163
1271
  if (failedTxs.length) {
1164
1272
  this.log.warn(`Simulated tx ${txHash} fails: ${failedTxs[0].error}`, { txHash });
@@ -1172,6 +1280,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1172
1280
  processedTx.txEffect,
1173
1281
  returns,
1174
1282
  processedTx.gasUsed,
1283
+ debugLogs,
1175
1284
  );
1176
1285
  } finally {
1177
1286
  await merkleTreeFork.close();
@@ -1185,19 +1294,25 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1185
1294
  const db = this.worldStateSynchronizer.getCommitted();
1186
1295
  const verifier = isSimulation ? undefined : this.proofVerifier;
1187
1296
 
1188
- // 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)
1189
1298
  const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
1190
- const blockNumber = (await this.blockSource.getBlockNumber()) + 1;
1191
- const validator = createValidatorForAcceptingTxs(db, this.contractDataSource, verifier, {
1192
- timestamp: nextSlotTimestamp,
1193
- blockNumber,
1194
- l1ChainId: this.l1ChainId,
1195
- rollupVersion: this.version,
1196
- setupAllowList: this.config.txPublicSetupAllowList ?? (await getDefaultAllowedSetupFunctions()),
1197
- gasFees: await this.getCurrentBaseFees(),
1198
- skipFeeEnforcement,
1199
- txsPermitted: !this.config.disableTransactions,
1200
- });
1299
+ const blockNumber = BlockNumber((await this.blockSource.getBlockNumber()) + 1);
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
+ );
1201
1316
 
1202
1317
  return await validator.validateTx(tx);
1203
1318
  }
@@ -1266,7 +1381,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1266
1381
  }
1267
1382
 
1268
1383
  // And it has an L2 block hash
1269
- const l2BlockHash = await archiver.getL2Tips().then(tips => tips.latest.hash);
1384
+ const l2BlockHash = await archiver.getL2Tips().then(tips => tips.proposed.hash);
1270
1385
  if (!l2BlockHash) {
1271
1386
  this.metrics.recordSnapshotError();
1272
1387
  throw new Error(`Archiver has no latest L2 block hash downloaded. Cannot start snapshot.`);
@@ -1294,13 +1409,13 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1294
1409
  return Promise.resolve();
1295
1410
  }
1296
1411
 
1297
- public async rollbackTo(targetBlock: number, force?: boolean): Promise<void> {
1412
+ public async rollbackTo(targetBlock: BlockNumber, force?: boolean): Promise<void> {
1298
1413
  const archiver = this.blockSource as Archiver;
1299
1414
  if (!('rollbackTo' in archiver)) {
1300
1415
  throw new Error('Archiver implementation does not support rollbacks.');
1301
1416
  }
1302
1417
 
1303
- const finalizedBlock = await archiver.getL2Tips().then(tips => tips.finalized.number);
1418
+ const finalizedBlock = await archiver.getL2Tips().then(tips => tips.finalized.block.number);
1304
1419
  if (targetBlock < finalizedBlock) {
1305
1420
  if (force) {
1306
1421
  this.log.warn(`Clearing world state database to allow rolling back behind finalized block ${finalizedBlock}`);
@@ -1361,17 +1476,108 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1361
1476
  }
1362
1477
  }
1363
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
+
1364
1574
  /**
1365
1575
  * Returns an instance of MerkleTreeOperations having first ensured the world state is fully synched
1366
- * @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.
1367
1577
  * @returns An instance of a committed MerkleTreeOperations
1368
1578
  */
1369
- async #getWorldState(blockNumber: L2BlockNumber) {
1370
- if (typeof blockNumber === 'number' && blockNumber < INITIAL_L2_BLOCK_NUM - 1) {
1371
- throw new Error('Invalid block number to get world state for: ' + blockNumber);
1372
- }
1373
-
1374
- let blockSyncedTo: number = 0;
1579
+ async #getWorldState(block: BlockParameter) {
1580
+ let blockSyncedTo: BlockNumber = BlockNumber.ZERO;
1375
1581
  try {
1376
1582
  // Attempt to sync the world state if necessary
1377
1583
  blockSyncedTo = await this.#syncWorldState();
@@ -1379,15 +1585,39 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1379
1585
  this.log.error(`Error getting world state: ${err}`);
1380
1586
  }
1381
1587
 
1382
- // using a snapshot could be less efficient than using the committed db
1383
- if (blockNumber === 'latest' /*|| blockNumber === blockSyncedTo*/) {
1384
- 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}`);
1385
1590
  return this.worldStateSynchronizer.getCommitted();
1386
- } 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();
1607
+ this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
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
+
1387
1619
  this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
1388
1620
  return this.worldStateSynchronizer.getSnapshot(blockNumber);
1389
- } else {
1390
- throw new Error(`Block ${blockNumber} not yet synced`);
1391
1621
  }
1392
1622
  }
1393
1623
 
@@ -1395,8 +1625,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1395
1625
  * Ensure we fully sync the world state
1396
1626
  * @returns A promise that fulfils once the world state is synced
1397
1627
  */
1398
- async #syncWorldState(): Promise<number> {
1628
+ async #syncWorldState(): Promise<BlockNumber> {
1399
1629
  const blockSourceHeight = await this.blockSource.getBlockNumber();
1400
- return this.worldStateSynchronizer.syncImmediate(blockSourceHeight);
1630
+ return await this.worldStateSynchronizer.syncImmediate(blockSourceHeight);
1401
1631
  }
1402
1632
  }