@aztec/aztec-node 0.0.1-commit.fce3e4f → 0.0.1-commit.ff7989d6c

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 { 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';
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,16 +33,17 @@ import {
46
33
  type Watcher,
47
34
  createSlasher,
48
35
  } from '@aztec/slasher';
49
- import { PublicSimulatorConfig } from '@aztec/stdlib/avm';
36
+ import { CollectionLimitsConfig, PublicSimulatorConfig } from '@aztec/stdlib/avm';
50
37
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
51
38
  import {
52
- type InBlock,
53
- type L2Block,
54
- L2BlockHash,
55
- type L2BlockNumber,
39
+ type BlockData,
40
+ BlockHash,
41
+ type BlockParameter,
42
+ type DataInBlock,
43
+ L2Block,
56
44
  type L2BlockSource,
57
- type PublishedL2Block,
58
45
  } from '@aztec/stdlib/block';
46
+ import type { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
59
47
  import type {
60
48
  ContractClassPublic,
61
49
  ContractDataSource,
@@ -63,7 +51,7 @@ import type {
63
51
  NodeInfo,
64
52
  ProtocolContractAddresses,
65
53
  } from '@aztec/stdlib/contract';
66
- import type { GasFees } from '@aztec/stdlib/gas';
54
+ import { GasFees } from '@aztec/stdlib/gas';
67
55
  import { computePublicDataTreeLeafSlot } from '@aztec/stdlib/hash';
68
56
  import {
69
57
  type AztecNode,
@@ -82,7 +70,7 @@ import {
82
70
  type WorldStateSynchronizer,
83
71
  tryStop,
84
72
  } from '@aztec/stdlib/interfaces/server';
85
- import type { LogFilter, PrivateLog, TxScopedL2Log } from '@aztec/stdlib/logs';
73
+ import type { LogFilter, SiloedTag, Tag, TxScopedL2Log } from '@aztec/stdlib/logs';
86
74
  import { InboxLeaf, type L1ToL2MessageSource } from '@aztec/stdlib/messaging';
87
75
  import { P2PClientType } from '@aztec/stdlib/p2p';
88
76
  import type { Offense, SlashPayloadRound } from '@aztec/stdlib/slashing';
@@ -110,10 +98,13 @@ import {
110
98
  trackSpan,
111
99
  } from '@aztec/telemetry-client';
112
100
  import {
101
+ FullNodeCheckpointsBuilder as CheckpointsBuilder,
102
+ FullNodeCheckpointsBuilder,
113
103
  NodeKeystoreAdapter,
114
104
  ValidatorClient,
115
105
  createBlockProposalHandler,
116
106
  createValidatorClient,
107
+ createValidatorForAcceptingTxs,
117
108
  } from '@aztec/validator-client';
118
109
  import { createWorldStateSynchronizer } from '@aztec/world-state';
119
110
 
@@ -129,6 +120,7 @@ import { NodeMetrics } from './node_metrics.js';
129
120
  */
130
121
  export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
131
122
  private metrics: NodeMetrics;
123
+ private initialHeaderHashPromise: Promise<BlockHash> | undefined = undefined;
132
124
 
133
125
  // Prevent two snapshot operations to happen simultaneously
134
126
  private isUploadingSnapshot = false;
@@ -144,6 +136,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
144
136
  protected readonly l1ToL2MessageSource: L1ToL2MessageSource,
145
137
  protected readonly worldStateSynchronizer: WorldStateSynchronizer,
146
138
  protected readonly sequencer: SequencerClient | undefined,
139
+ protected readonly proverNode: ProverNode | undefined,
147
140
  protected readonly slasherClient: SlasherClientInterface | undefined,
148
141
  protected readonly validatorsSentinel: Sentinel | undefined,
149
142
  protected readonly epochPruneWatcher: EpochPruneWatcher | undefined,
@@ -155,6 +148,9 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
155
148
  private proofVerifier: ClientProtocolCircuitVerifier,
156
149
  private telemetry: TelemetryClient = getTelemetryClient(),
157
150
  private log = createLogger('node'),
151
+ private blobClient?: BlobClientInterface,
152
+ private validatorClient?: ValidatorClient,
153
+ private keyStoreManager?: KeystoreManager,
158
154
  ) {
159
155
  this.metrics = new NodeMetrics(telemetry, 'AztecNodeService');
160
156
  this.tracer = telemetry.getTracer('AztecNodeService');
@@ -184,12 +180,13 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
184
180
  logger?: Logger;
185
181
  publisher?: SequencerPublisher;
186
182
  dateProvider?: DateProvider;
187
- blobSinkClient?: BlobSinkClientInterface;
188
183
  p2pClientDeps?: P2PClientDeps<P2PClientType.Full>;
184
+ proverNodeDeps?: Partial<ProverNodeDeps>;
189
185
  } = {},
190
186
  options: {
191
187
  prefilledPublicData?: PublicDataTreeLeaf[];
192
188
  dontStartSequencer?: boolean;
189
+ dontStartProverNode?: boolean;
193
190
  } = {},
194
191
  ): Promise<AztecNodeService> {
195
192
  const config = { ...inputConfig }; // Copy the config so we dont mutate the input object
@@ -197,20 +194,31 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
197
194
  const packageVersion = getPackageVersion() ?? '';
198
195
  const telemetry = deps.telemetry ?? getTelemetryClient();
199
196
  const dateProvider = deps.dateProvider ?? new DateProvider();
200
- const blobSinkClient =
201
- deps.blobSinkClient ?? createBlobSinkClient(config, { logger: createLogger('node:blob-sink:client') });
202
197
  const ethereumChain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
203
198
 
204
- // 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.
205
201
  let keyStoreManager: KeystoreManager | undefined;
206
202
  const keyStoreProvided = config.keyStoreDirectory !== undefined && config.keyStoreDirectory.length > 0;
207
203
  if (keyStoreProvided) {
208
204
  const keyStores = loadKeystores(config.keyStoreDirectory!);
209
205
  keyStoreManager = new KeystoreManager(mergeKeystores(keyStores));
210
206
  } else {
211
- const keyStore = createKeyStoreForValidator(config);
212
- if (keyStore) {
213
- 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
+ );
214
222
  }
215
223
  }
216
224
 
@@ -221,10 +229,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
221
229
  if (keyStoreManager === undefined) {
222
230
  throw new Error('Failed to create key store, a requirement for running a validator');
223
231
  }
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
- );
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");
228
234
  }
229
235
  ValidatorClient.validateKeyStoreConfiguration(keyStoreManager, log);
230
236
  }
@@ -238,7 +244,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
238
244
 
239
245
  const publicClient = createPublicClient({
240
246
  chain: ethereumChain.chainInfo,
241
- transport: fallback(config.l1RpcUrls.map((url: string) => http(url))),
247
+ transport: fallback(config.l1RpcUrls.map((url: string) => http(url, { batch: false }))),
242
248
  pollingInterval: config.viemPollingIntervalMS,
243
249
  });
244
250
 
@@ -266,6 +272,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
266
272
  );
267
273
  }
268
274
 
275
+ const blobClient = await createBlobClientWithFileStores(config, log.createChild('blob-client'));
276
+
269
277
  // attempt snapshot sync if possible
270
278
  await trySnapshotSync(config, log);
271
279
 
@@ -273,7 +281,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
273
281
 
274
282
  const archiver = await createArchiver(
275
283
  config,
276
- { blobSinkClient, epochCache, telemetry, dateProvider },
284
+ { blobClient, epochCache, telemetry, dateProvider },
277
285
  { blockUntilSync: !config.skipArchiverInitialSync },
278
286
  );
279
287
 
@@ -284,9 +292,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
284
292
  options.prefilledPublicData,
285
293
  telemetry,
286
294
  );
287
- const circuitVerifier = config.realProofs
288
- ? await BBCircuitVerifier.new(config)
289
- : new TestCircuitVerifier(config.proverTestVerificationDelayMs);
295
+ const circuitVerifier =
296
+ config.realProofs || config.debugForceTxProofVerification
297
+ ? await BBCircuitVerifier.new(config)
298
+ : new TestCircuitVerifier(config.proverTestVerificationDelayMs);
290
299
  if (!config.realProofs) {
291
300
  log.warn(`Aztec node is accepting fake proofs`);
292
301
  }
@@ -309,7 +318,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
309
318
  // We should really not be modifying the config object
310
319
  config.txPublicSetupAllowList = config.txPublicSetupAllowList ?? (await getDefaultAllowedSetupFunctions());
311
320
 
312
- const blockBuilder = new BlockBuilder(
321
+ // Create FullNodeCheckpointsBuilder for validator and non-validator block proposal handling
322
+ const validatorCheckpointsBuilder = new FullNodeCheckpointsBuilder(
313
323
  { ...config, l1GenesisTime, slotDuration: Number(slotDuration) },
314
324
  worldStateSynchronizer,
315
325
  archiver,
@@ -321,15 +331,17 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
321
331
  const watchers: Watcher[] = [];
322
332
 
323
333
  // Create validator client if required
324
- const validatorClient = createValidatorClient(config, {
334
+ const validatorClient = await createValidatorClient(config, {
335
+ checkpointsBuilder: validatorCheckpointsBuilder,
336
+ worldState: worldStateSynchronizer,
325
337
  p2pClient,
326
338
  telemetry,
327
339
  dateProvider,
328
340
  epochCache,
329
- blockBuilder,
330
341
  blockSource: archiver,
331
342
  l1ToL2MessageSource: archiver,
332
343
  keyStoreManager,
344
+ blobClient,
333
345
  });
334
346
 
335
347
  // If we have a validator client, register it as a source of offenses for the slasher,
@@ -347,7 +359,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
347
359
  if (!validatorClient && config.alwaysReexecuteBlockProposals) {
348
360
  log.info('Setting up block proposal reexecution for monitoring');
349
361
  createBlockProposalHandler(config, {
350
- blockBuilder,
362
+ checkpointsBuilder: validatorCheckpointsBuilder,
363
+ worldState: worldStateSynchronizer,
351
364
  epochCache,
352
365
  blockSource: archiver,
353
366
  l1ToL2MessageSource: archiver,
@@ -375,7 +388,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
375
388
  archiver,
376
389
  epochCache,
377
390
  p2pClient.getTxProvider(),
378
- blockBuilder,
391
+ validatorCheckpointsBuilder,
379
392
  config,
380
393
  );
381
394
  watchers.push(epochPruneWatcher);
@@ -403,7 +416,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
403
416
  // Validator enabled, create/start relevant service
404
417
  let sequencer: SequencerClient | undefined;
405
418
  let slasherClient: SlasherClientInterface | undefined;
406
- if (!config.disableValidator) {
419
+ if (!config.disableValidator && validatorClient) {
407
420
  // We create a slasher only if we have a sequencer, since all slashing actions go through the sequencer publisher
408
421
  // as they are executed when the node is selected as proposer.
409
422
  const validatorAddresses = keyStoreManager
@@ -422,14 +435,30 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
422
435
  );
423
436
  await slasherClient.start();
424
437
 
425
- const l1TxUtils = await createL1TxUtilsWithBlobsFromEthSigner(
426
- publicClient,
427
- keyStoreManager!.createAllValidatorPublisherSigners(),
428
- { ...config, scope: 'sequencer' },
429
- { telemetry, logger: log.createChild('l1-tx-utils'), dateProvider },
430
- );
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
+ );
431
452
 
432
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
+
433
462
  sequencer = await SequencerClient.new(config, {
434
463
  ...deps,
435
464
  epochCache,
@@ -438,12 +467,12 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
438
467
  p2pClient,
439
468
  worldStateSynchronizer,
440
469
  slasherClient,
441
- blockBuilder,
470
+ checkpointsBuilder,
442
471
  l2BlockSource: archiver,
443
472
  l1ToL2MessageSource: archiver,
444
473
  telemetry,
445
474
  dateProvider,
446
- blobSinkClient,
475
+ blobClient,
447
476
  nodeKeyStore: keyStoreManager!,
448
477
  });
449
478
  }
@@ -455,7 +484,37 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
455
484
  log.warn(`Sequencer created but not started`);
456
485
  }
457
486
 
458
- 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(
459
518
  config,
460
519
  p2pClient,
461
520
  archiver,
@@ -464,18 +523,24 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
464
523
  archiver,
465
524
  worldStateSynchronizer,
466
525
  sequencer,
526
+ proverNode,
467
527
  slasherClient,
468
528
  validatorsSentinel,
469
529
  epochPruneWatcher,
470
530
  ethereumChain.chainInfo.id,
471
531
  config.rollupVersion,
472
- new GlobalVariableBuilder(config),
532
+ globalVariableBuilder,
473
533
  epochCache,
474
534
  packageVersion,
475
535
  proofVerifier,
476
536
  telemetry,
477
537
  log,
538
+ blobClient,
539
+ validatorClient,
540
+ keyStoreManager,
478
541
  );
542
+
543
+ return node;
479
544
  }
480
545
 
481
546
  /**
@@ -486,6 +551,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
486
551
  return this.sequencer;
487
552
  }
488
553
 
554
+ /** Returns the prover node subsystem, if enabled. */
555
+ public getProverNode(): ProverNode | undefined {
556
+ return this.proverNode;
557
+ }
558
+
489
559
  public getBlockSource(): L2BlockSource {
490
560
  return this.blockSource;
491
561
  }
@@ -539,19 +609,26 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
539
609
  enr,
540
610
  l1ContractAddresses: contractAddresses,
541
611
  protocolContractAddresses: protocolContractAddresses,
612
+ realProofs: !!this.config.realProofs,
542
613
  };
543
614
 
544
615
  return nodeInfo;
545
616
  }
546
617
 
547
618
  /**
548
- * Get a block specified by its number.
549
- * @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').
550
621
  * @returns The requested block.
551
622
  */
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);
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);
555
632
  }
556
633
 
557
634
  /**
@@ -559,9 +636,17 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
559
636
  * @param blockHash - The block hash being requested.
560
637
  * @returns The requested block.
561
638
  */
562
- public async getBlockByHash(blockHash: Fr): Promise<L2Block | undefined> {
563
- const publishedBlock = await this.blockSource.getPublishedBlockByHash(blockHash);
564
- 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);
565
650
  }
566
651
 
567
652
  /**
@@ -570,8 +655,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
570
655
  * @returns The requested block.
571
656
  */
572
657
  public async getBlockByArchive(archive: Fr): Promise<L2Block | undefined> {
573
- const publishedBlock = await this.blockSource.getPublishedBlockByArchive(archive);
574
- return publishedBlock?.block;
658
+ return await this.blockSource.getL2BlockByArchive(archive);
575
659
  }
576
660
 
577
661
  /**
@@ -580,34 +664,50 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
580
664
  * @param limit - The maximum number of blocks to obtain.
581
665
  * @returns The blocks requested.
582
666
  */
583
- public async getBlocks(from: number, limit: number): Promise<L2Block[]> {
584
- 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)) ?? [];
585
673
  }
586
674
 
587
- public async getPublishedBlocks(from: number, limit: number): Promise<PublishedL2Block[]> {
588
- return (await this.blockSource.getPublishedBlocks(from, limit)) ?? [];
675
+ public async getCheckpointedBlocks(from: BlockNumber, limit: number) {
676
+ return (await this.blockSource.getCheckpointedBlocks(from, limit)) ?? [];
589
677
  }
590
678
 
591
679
  /**
592
- * Method to fetch the current base fees.
593
- * @returns The current base fees.
680
+ * Method to fetch the current min L2 fees.
681
+ * @returns The current min L2 fees.
594
682
  */
595
- public async getCurrentBaseFees(): Promise<GasFees> {
596
- 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 });
597
693
  }
598
694
 
599
695
  /**
600
696
  * Method to fetch the latest block number synchronized by the node.
601
697
  * @returns The block number.
602
698
  */
603
- public async getBlockNumber(): Promise<number> {
699
+ public async getBlockNumber(): Promise<BlockNumber> {
604
700
  return await this.blockSource.getBlockNumber();
605
701
  }
606
702
 
607
- public async getProvenBlockNumber(): Promise<number> {
703
+ public async getProvenBlockNumber(): Promise<BlockNumber> {
608
704
  return await this.blockSource.getProvenBlockNumber();
609
705
  }
610
706
 
707
+ public async getCheckpointedBlockNumber(): Promise<BlockNumber> {
708
+ return await this.blockSource.getCheckpointedL2BlockNumber();
709
+ }
710
+
611
711
  /**
612
712
  * Method to fetch the version of the package.
613
713
  * @returns The node package version
@@ -640,25 +740,43 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
640
740
  return this.contractDataSource.getContract(address);
641
741
  }
642
742
 
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);
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);
662
780
  }
663
781
 
664
782
  /**
@@ -705,21 +823,26 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
705
823
  }
706
824
 
707
825
  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
- }
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';
716
830
 
831
+ // Then get the actual tx from the archiver, which tracks every tx in a mined block.
717
832
  const settledTxReceipt = await this.blockSource.getSettledTxReceipt(txHash);
833
+
718
834
  if (settledTxReceipt) {
719
- 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');
720
845
  }
721
-
722
- return txReceipt;
723
846
  }
724
847
 
725
848
  public getTxEffect(txHash: TxHash): Promise<IndexedTxEffect | undefined> {
@@ -736,13 +859,23 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
736
859
  await tryStop(this.slasherClient);
737
860
  await tryStop(this.proofVerifier);
738
861
  await tryStop(this.sequencer);
862
+ await tryStop(this.proverNode);
739
863
  await tryStop(this.p2pClient);
740
864
  await tryStop(this.worldStateSynchronizer);
741
865
  await tryStop(this.blockSource);
866
+ await tryStop(this.blobClient);
742
867
  await tryStop(this.telemetry);
743
868
  this.log.info(`Stopped Aztec Node`);
744
869
  }
745
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
+
746
879
  /**
747
880
  * Method to retrieve pending txs.
748
881
  * @param limit - The number of items to returns
@@ -775,20 +908,12 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
775
908
  return compactArray(await Promise.all(txHashes.map(txHash => this.getTxByHash(txHash))));
776
909
  }
777
910
 
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
911
  public async findLeavesIndexes(
787
- blockNumber: L2BlockNumber,
912
+ referenceBlock: BlockParameter,
788
913
  treeId: MerkleTreeId,
789
914
  leafValues: Fr[],
790
- ): Promise<(InBlock<bigint> | undefined)[]> {
791
- const committedDb = await this.#getWorldState(blockNumber);
915
+ ): Promise<(DataInBlock<bigint> | undefined)[]> {
916
+ const committedDb = await this.#getWorldState(referenceBlock);
792
917
  const maybeIndices = await committedDb.findLeafIndices(
793
918
  treeId,
794
919
  leafValues.map(x => x.toBuffer()),
@@ -813,7 +938,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
813
938
  // (note that block number corresponds to the leaf index in the archive tree).
814
939
  const blockHashes = await Promise.all(
815
940
  uniqueBlockNumbers.map(blockNumber => {
816
- return committedDb.getLeafValue(MerkleTreeId.ARCHIVE, blockNumber!);
941
+ return committedDb.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
817
942
  }),
818
943
  );
819
944
 
@@ -824,7 +949,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
824
949
  }
825
950
  }
826
951
 
827
- // 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.
828
953
  return maybeIndices.map((index, i) => {
829
954
  if (index === undefined) {
830
955
  return undefined;
@@ -839,57 +964,29 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
839
964
  return undefined;
840
965
  }
841
966
  return {
842
- l2BlockNumber: Number(blockNumber),
843
- l2BlockHash: L2BlockHash.fromField(blockHash),
967
+ l2BlockNumber: BlockNumber(Number(blockNumber)),
968
+ l2BlockHash: new BlockHash(blockHash),
844
969
  data: index,
845
970
  };
846
971
  });
847
972
  }
848
973
 
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,
974
+ public async getBlockHashMembershipWitness(
975
+ referenceBlock: BlockParameter,
976
+ blockHash: BlockHash,
880
977
  ): Promise<MembershipWitness<typeof ARCHIVE_HEIGHT> | undefined> {
881
- const committedDb = await this.#getWorldState(blockNumber);
882
- 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]);
883
980
  return pathAndIndex === undefined
884
981
  ? undefined
885
982
  : MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
886
983
  }
887
984
 
888
985
  public async getNoteHashMembershipWitness(
889
- blockNumber: L2BlockNumber,
986
+ referenceBlock: BlockParameter,
890
987
  noteHash: Fr,
891
988
  ): Promise<MembershipWitness<typeof NOTE_HASH_TREE_HEIGHT> | undefined> {
892
- const committedDb = await this.#getWorldState(blockNumber);
989
+ const committedDb = await this.#getWorldState(referenceBlock);
893
990
  const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.NOTE_HASH_TREE>(
894
991
  MerkleTreeId.NOTE_HASH_TREE,
895
992
  [noteHash],
@@ -899,17 +996,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
899
996
  : MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
900
997
  }
901
998
 
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
999
  public async getL1ToL2MessageMembershipWitness(
909
- blockNumber: L2BlockNumber,
1000
+ referenceBlock: BlockParameter,
910
1001
  l1ToL2Message: Fr,
911
1002
  ): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>] | undefined> {
912
- const db = await this.#getWorldState(blockNumber);
1003
+ const db = await this.#getWorldState(referenceBlock);
913
1004
  const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [l1ToL2Message]);
914
1005
  if (!witness) {
915
1006
  return undefined;
@@ -919,9 +1010,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
919
1010
  return [witness.index, witness.path];
920
1011
  }
921
1012
 
922
- public async getL1ToL2MessageBlock(l1ToL2Message: Fr): Promise<number | undefined> {
1013
+ public async getL1ToL2MessageBlock(l1ToL2Message: Fr): Promise<BlockNumber | undefined> {
923
1014
  const messageIndex = await this.l1ToL2MessageSource.getL1ToL2MessageIndex(l1ToL2Message);
924
- return messageIndex ? InboxLeaf.l2BlockFromIndex(messageIndex) : undefined;
1015
+ return messageIndex
1016
+ ? BlockNumber.fromCheckpointNumber(InboxLeaf.checkpointNumberFromIndex(messageIndex))
1017
+ : undefined;
925
1018
  }
926
1019
 
927
1020
  /**
@@ -935,54 +1028,36 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
935
1028
  }
936
1029
 
937
1030
  /**
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).
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).
941
1034
  */
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.
966
- */
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);
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
+ );
973
1054
  }
974
1055
 
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
1056
  public async getNullifierMembershipWitness(
982
- blockNumber: L2BlockNumber,
1057
+ referenceBlock: BlockParameter,
983
1058
  nullifier: Fr,
984
1059
  ): Promise<NullifierMembershipWitness | undefined> {
985
- const db = await this.#getWorldState(blockNumber);
1060
+ const db = await this.#getWorldState(referenceBlock);
986
1061
  const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [nullifier.toBuffer()]);
987
1062
  if (!witness) {
988
1063
  return undefined;
@@ -999,7 +1074,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
999
1074
 
1000
1075
  /**
1001
1076
  * 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.
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).
1003
1079
  * @param nullifier - Nullifier we try to find the low nullifier witness for.
1004
1080
  * @returns The low nullifier membership witness (if found).
1005
1081
  * @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
@@ -1012,10 +1088,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1012
1088
  * TODO: This is a confusing behavior and we should eventually address that.
1013
1089
  */
1014
1090
  public async getLowNullifierMembershipWitness(
1015
- blockNumber: L2BlockNumber,
1091
+ referenceBlock: BlockParameter,
1016
1092
  nullifier: Fr,
1017
1093
  ): Promise<NullifierMembershipWitness | undefined> {
1018
- const committedDb = await this.#getWorldState(blockNumber);
1094
+ const committedDb = await this.#getWorldState(referenceBlock);
1019
1095
  const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
1020
1096
  if (!findResult) {
1021
1097
  return undefined;
@@ -1030,8 +1106,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1030
1106
  return new NullifierMembershipWitness(BigInt(index), preimageData as NullifierLeafPreimage, siblingPath);
1031
1107
  }
1032
1108
 
1033
- async getPublicDataWitness(blockNumber: L2BlockNumber, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
1034
- const committedDb = await this.#getWorldState(blockNumber);
1109
+ async getPublicDataWitness(referenceBlock: BlockParameter, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
1110
+ const committedDb = await this.#getWorldState(referenceBlock);
1035
1111
  const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
1036
1112
  if (!lowLeafResult) {
1037
1113
  return undefined;
@@ -1045,19 +1121,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1045
1121
  }
1046
1122
  }
1047
1123
 
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);
1124
+ public async getPublicStorageAt(referenceBlock: BlockParameter, contract: AztecAddress, slot: Fr): Promise<Fr> {
1125
+ const committedDb = await this.#getWorldState(referenceBlock);
1061
1126
  const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
1062
1127
 
1063
1128
  const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
@@ -1071,23 +1136,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1071
1136
  return preimage.leaf.value;
1072
1137
  }
1073
1138
 
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);
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
+ }
1091
1155
  }
1092
1156
 
1093
1157
  /**
@@ -1099,6 +1163,14 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1099
1163
  return await this.blockSource.getBlockHeaderByArchive(archive);
1100
1164
  }
1101
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
+
1102
1174
  /**
1103
1175
  * Simulates the public part of a transaction with the current state.
1104
1176
  * @param tx - The transaction to simulate.
@@ -1122,7 +1194,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1122
1194
  }
1123
1195
 
1124
1196
  const txHash = tx.getTxHash();
1125
- const blockNumber = (await this.blockSource.getBlockNumber()) + 1;
1197
+ const latestBlockNumber = await this.blockSource.getBlockNumber();
1198
+ const blockNumber = BlockNumber.add(latestBlockNumber, 1);
1126
1199
 
1127
1200
  // If sequencer is not initialized, we just set these values to zero for simulation.
1128
1201
  const coinbase = EthAddress.ZERO;
@@ -1137,6 +1210,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1137
1210
  this.contractDataSource,
1138
1211
  new DateProvider(),
1139
1212
  this.telemetry,
1213
+ this.log.getBindings(),
1140
1214
  );
1141
1215
 
1142
1216
  this.log.verbose(`Simulating public calls for tx ${txHash}`, {
@@ -1145,6 +1219,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1145
1219
  blockNumber,
1146
1220
  });
1147
1221
 
1222
+ // Ensure world-state has caught up with the latest block we loaded from the archiver
1223
+ await this.worldStateSynchronizer.syncImmediate(latestBlockNumber);
1148
1224
  const merkleTreeFork = await this.worldStateSynchronizer.fork();
1149
1225
  try {
1150
1226
  const config = PublicSimulatorConfig.from({
@@ -1152,13 +1228,15 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1152
1228
  collectDebugLogs: true,
1153
1229
  collectHints: false,
1154
1230
  collectCallMetadata: true,
1155
- maxDebugLogMemoryReads: this.config.rpcSimulatePublicMaxDebugLogMemoryReads,
1156
1231
  collectStatistics: false,
1232
+ collectionLimits: CollectionLimitsConfig.from({
1233
+ maxDebugLogMemoryReads: this.config.rpcSimulatePublicMaxDebugLogMemoryReads,
1234
+ }),
1157
1235
  });
1158
1236
  const processor = publicProcessorFactory.create(merkleTreeFork, newGlobalVariables, config);
1159
1237
 
1160
1238
  // REFACTOR: Consider merging ProcessReturnValues into ProcessedTx
1161
- const [processedTxs, failedTxs, _usedTxs, returns] = await processor.process([tx]);
1239
+ const [processedTxs, failedTxs, _usedTxs, returns, _blobFields, debugLogs] = await processor.process([tx]);
1162
1240
  // REFACTOR: Consider returning the error rather than throwing
1163
1241
  if (failedTxs.length) {
1164
1242
  this.log.warn(`Simulated tx ${txHash} fails: ${failedTxs[0].error}`, { txHash });
@@ -1172,6 +1250,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1172
1250
  processedTx.txEffect,
1173
1251
  returns,
1174
1252
  processedTx.gasUsed,
1253
+ debugLogs,
1175
1254
  );
1176
1255
  } finally {
1177
1256
  await merkleTreeFork.close();
@@ -1185,19 +1264,25 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1185
1264
  const db = this.worldStateSynchronizer.getCommitted();
1186
1265
  const verifier = isSimulation ? undefined : this.proofVerifier;
1187
1266
 
1188
- // 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)
1189
1268
  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
- });
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
+ );
1201
1286
 
1202
1287
  return await validator.validateTx(tx);
1203
1288
  }
@@ -1266,7 +1351,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1266
1351
  }
1267
1352
 
1268
1353
  // And it has an L2 block hash
1269
- const l2BlockHash = await archiver.getL2Tips().then(tips => tips.latest.hash);
1354
+ const l2BlockHash = await archiver.getL2Tips().then(tips => tips.proposed.hash);
1270
1355
  if (!l2BlockHash) {
1271
1356
  this.metrics.recordSnapshotError();
1272
1357
  throw new Error(`Archiver has no latest L2 block hash downloaded. Cannot start snapshot.`);
@@ -1294,13 +1379,13 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1294
1379
  return Promise.resolve();
1295
1380
  }
1296
1381
 
1297
- public async rollbackTo(targetBlock: number, force?: boolean): Promise<void> {
1382
+ public async rollbackTo(targetBlock: BlockNumber, force?: boolean): Promise<void> {
1298
1383
  const archiver = this.blockSource as Archiver;
1299
1384
  if (!('rollbackTo' in archiver)) {
1300
1385
  throw new Error('Archiver implementation does not support rollbacks.');
1301
1386
  }
1302
1387
 
1303
- const finalizedBlock = await archiver.getL2Tips().then(tips => tips.finalized.number);
1388
+ const finalizedBlock = await archiver.getL2Tips().then(tips => tips.finalized.block.number);
1304
1389
  if (targetBlock < finalizedBlock) {
1305
1390
  if (force) {
1306
1391
  this.log.warn(`Clearing world state database to allow rolling back behind finalized block ${finalizedBlock}`);
@@ -1361,17 +1446,108 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1361
1446
  }
1362
1447
  }
1363
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
+
1364
1544
  /**
1365
1545
  * 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.
1546
+ * @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
1367
1547
  * @returns An instance of a committed MerkleTreeOperations
1368
1548
  */
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;
1549
+ async #getWorldState(block: BlockParameter) {
1550
+ let blockSyncedTo: BlockNumber = BlockNumber.ZERO;
1375
1551
  try {
1376
1552
  // Attempt to sync the world state if necessary
1377
1553
  blockSyncedTo = await this.#syncWorldState();
@@ -1379,15 +1555,39 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1379
1555
  this.log.error(`Error getting world state: ${err}`);
1380
1556
  }
1381
1557
 
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}`);
1558
+ if (block === 'latest') {
1559
+ this.log.debug(`Using committed db for block 'latest', world state synced upto ${blockSyncedTo}`);
1385
1560
  return this.worldStateSynchronizer.getCommitted();
1386
- } 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
+
1387
1589
  this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
1388
1590
  return this.worldStateSynchronizer.getSnapshot(blockNumber);
1389
- } else {
1390
- throw new Error(`Block ${blockNumber} not yet synced`);
1391
1591
  }
1392
1592
  }
1393
1593
 
@@ -1395,8 +1595,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1395
1595
  * Ensure we fully sync the world state
1396
1596
  * @returns A promise that fulfils once the world state is synced
1397
1597
  */
1398
- async #syncWorldState(): Promise<number> {
1598
+ async #syncWorldState(): Promise<BlockNumber> {
1399
1599
  const blockSourceHeight = await this.blockSource.getBlockNumber();
1400
- return this.worldStateSynchronizer.syncImmediate(blockSourceHeight);
1600
+ return await this.worldStateSynchronizer.syncImmediate(blockSourceHeight);
1401
1601
  }
1402
1602
  }