@aztec/aztec-node 0.0.1-commit.6d3c34e → 0.0.1-commit.72dcdcda8

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,21 +1,15 @@
1
1
  import { Archiver, createArchiver } from '@aztec/archiver';
2
2
  import { BBCircuitVerifier, QueuedIVCVerifier, TestCircuitVerifier } from '@aztec/bb-prover';
3
3
  import { type BlobClientInterface, createBlobClientWithFileStores } from '@aztec/blob-client/client';
4
- import {
5
- ARCHIVE_HEIGHT,
6
- 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';
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
7
  import { createEthereumChain } from '@aztec/ethereum/chain';
14
8
  import { getPublicClient } from '@aztec/ethereum/client';
15
9
  import { RegistryContract, RollupContract } from '@aztec/ethereum/contracts';
16
10
  import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
17
11
  import { BlockNumber, CheckpointNumber, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
18
- import { compactArray, pick } from '@aztec/foundation/collection';
12
+ import { compactArray, pick, unique } from '@aztec/foundation/collection';
19
13
  import { Fr } from '@aztec/foundation/curves/bn254';
20
14
  import { EthAddress } from '@aztec/foundation/eth-address';
21
15
  import { BadRequestError } from '@aztec/foundation/json-rpc';
@@ -23,15 +17,20 @@ import { type Logger, createLogger } from '@aztec/foundation/log';
23
17
  import { count } from '@aztec/foundation/string';
24
18
  import { DateProvider, Timer } from '@aztec/foundation/timer';
25
19
  import { MembershipWitness, SiblingPath } from '@aztec/foundation/trees';
26
- import { KeystoreManager, loadKeystores, mergeKeystores } from '@aztec/node-keystore';
20
+ import { type KeyStore, KeystoreManager, loadKeystores, mergeKeystores } from '@aztec/node-keystore';
27
21
  import { trySnapshotSync, uploadSnapshot } from '@aztec/node-lib/actions';
22
+ import { createForwarderL1TxUtilsFromSigners, createL1TxUtilsFromSigners } from '@aztec/node-lib/factories';
28
23
  import {
29
- createForwarderL1TxUtilsFromEthSigner,
30
- createL1TxUtilsWithBlobsFromEthSigner,
31
- } from '@aztec/node-lib/factories';
32
- import { type P2P, type P2PClientDeps, createP2PClient, getDefaultAllowedSetupFunctions } from '@aztec/p2p';
24
+ type P2P,
25
+ type P2PClientDeps,
26
+ createP2PClient,
27
+ createTxValidatorForAcceptingTxsOverRPC,
28
+ getDefaultAllowedSetupFunctions,
29
+ } from '@aztec/p2p';
33
30
  import { ProtocolContractAddress } from '@aztec/protocol-contracts';
34
- import { BlockBuilder, GlobalVariableBuilder, SequencerClient, type SequencerPublisher } from '@aztec/sequencer-client';
31
+ import { type ProverNode, type ProverNodeDeps, createProverNode } from '@aztec/prover-node';
32
+ import { createKeyStoreForProver } from '@aztec/prover-node/config';
33
+ import { GlobalVariableBuilder, SequencerClient, type SequencerPublisher } from '@aztec/sequencer-client';
35
34
  import { PublicProcessorFactory } from '@aztec/simulator/server';
36
35
  import {
37
36
  AttestationsBlockWatcher,
@@ -43,13 +42,12 @@ import {
43
42
  import { CollectionLimitsConfig, PublicSimulatorConfig } from '@aztec/stdlib/avm';
44
43
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
45
44
  import {
45
+ type BlockData,
46
+ BlockHash,
46
47
  type BlockParameter,
47
48
  type DataInBlock,
48
- type L2Block,
49
- L2BlockHash,
50
- L2BlockNew,
49
+ L2Block,
51
50
  type L2BlockSource,
52
- type PublishedL2Block,
53
51
  } from '@aztec/stdlib/block';
54
52
  import type { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
55
53
  import type {
@@ -78,9 +76,9 @@ import {
78
76
  type WorldStateSynchronizer,
79
77
  tryStop,
80
78
  } from '@aztec/stdlib/interfaces/server';
81
- import type { LogFilter, SiloedTag, Tag, TxScopedL2Log } from '@aztec/stdlib/logs';
79
+ import type { DebugLogStore, LogFilter, SiloedTag, Tag, TxScopedL2Log } from '@aztec/stdlib/logs';
80
+ import { InMemoryDebugLogStore, NullDebugLogStore } from '@aztec/stdlib/logs';
82
81
  import { InboxLeaf, type L1ToL2MessageSource } from '@aztec/stdlib/messaging';
83
- import { P2PClientType } from '@aztec/stdlib/p2p';
84
82
  import type { Offense, SlashPayloadRound } from '@aztec/stdlib/slashing';
85
83
  import type { NullifierLeafPreimage, PublicDataTreeLeaf, PublicDataTreeLeafPreimage } from '@aztec/stdlib/trees';
86
84
  import { MerkleTreeId, NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
@@ -112,7 +110,6 @@ import {
112
110
  ValidatorClient,
113
111
  createBlockProposalHandler,
114
112
  createValidatorClient,
115
- createValidatorForAcceptingTxs,
116
113
  } from '@aztec/validator-client';
117
114
  import { createWorldStateSynchronizer } from '@aztec/world-state';
118
115
 
@@ -128,6 +125,7 @@ import { NodeMetrics } from './node_metrics.js';
128
125
  */
129
126
  export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
130
127
  private metrics: NodeMetrics;
128
+ private initialHeaderHashPromise: Promise<BlockHash> | undefined = undefined;
131
129
 
132
130
  // Prevent two snapshot operations to happen simultaneously
133
131
  private isUploadingSnapshot = false;
@@ -143,6 +141,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
143
141
  protected readonly l1ToL2MessageSource: L1ToL2MessageSource,
144
142
  protected readonly worldStateSynchronizer: WorldStateSynchronizer,
145
143
  protected readonly sequencer: SequencerClient | undefined,
144
+ protected readonly proverNode: ProverNode | undefined,
146
145
  protected readonly slasherClient: SlasherClientInterface | undefined,
147
146
  protected readonly validatorsSentinel: Sentinel | undefined,
148
147
  protected readonly epochPruneWatcher: EpochPruneWatcher | undefined,
@@ -155,12 +154,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
155
154
  private telemetry: TelemetryClient = getTelemetryClient(),
156
155
  private log = createLogger('node'),
157
156
  private blobClient?: BlobClientInterface,
157
+ private validatorClient?: ValidatorClient,
158
+ private keyStoreManager?: KeystoreManager,
159
+ private debugLogStore: DebugLogStore = new NullDebugLogStore(),
158
160
  ) {
159
161
  this.metrics = new NodeMetrics(telemetry, 'AztecNodeService');
160
162
  this.tracer = telemetry.getTracer('AztecNodeService');
161
163
 
162
164
  this.log.info(`Aztec Node version: ${this.packageVersion}`);
163
165
  this.log.info(`Aztec Node started on chain 0x${l1ChainId.toString(16)}`, config.l1Contracts);
166
+
167
+ // A defensive check that protects us against introducing a bug in the complex `createAndSync` function. We must
168
+ // never have debugLogStore enabled when not in test mode because then we would be accumulating debug logs in
169
+ // memory which could be a DoS vector on the sequencer (since no fees are paid for debug logs).
170
+ if (debugLogStore.isEnabled && config.realProofs) {
171
+ throw new Error('debugLogStore should never be enabled when realProofs are set');
172
+ }
164
173
  }
165
174
 
166
175
  public async getWorldStateSyncStatus(): Promise<WorldStateSyncStatus> {
@@ -184,11 +193,13 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
184
193
  logger?: Logger;
185
194
  publisher?: SequencerPublisher;
186
195
  dateProvider?: DateProvider;
187
- p2pClientDeps?: P2PClientDeps<P2PClientType.Full>;
196
+ p2pClientDeps?: P2PClientDeps;
197
+ proverNodeDeps?: Partial<ProverNodeDeps>;
188
198
  } = {},
189
199
  options: {
190
200
  prefilledPublicData?: PublicDataTreeLeaf[];
191
201
  dontStartSequencer?: boolean;
202
+ dontStartProverNode?: boolean;
192
203
  } = {},
193
204
  ): Promise<AztecNodeService> {
194
205
  const config = { ...inputConfig }; // Copy the config so we dont mutate the input object
@@ -198,16 +209,29 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
198
209
  const dateProvider = deps.dateProvider ?? new DateProvider();
199
210
  const ethereumChain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
200
211
 
201
- // Build a key store from file if given or from environment otherwise
212
+ // Build a key store from file if given or from environment otherwise.
213
+ // We keep the raw KeyStore available so we can merge with prover keys if enableProverNode is set.
202
214
  let keyStoreManager: KeystoreManager | undefined;
203
215
  const keyStoreProvided = config.keyStoreDirectory !== undefined && config.keyStoreDirectory.length > 0;
204
216
  if (keyStoreProvided) {
205
217
  const keyStores = loadKeystores(config.keyStoreDirectory!);
206
218
  keyStoreManager = new KeystoreManager(mergeKeystores(keyStores));
207
219
  } else {
208
- const keyStore = createKeyStoreForValidator(config);
209
- if (keyStore) {
210
- keyStoreManager = new KeystoreManager(keyStore);
220
+ const rawKeyStores: KeyStore[] = [];
221
+ const validatorKeyStore = createKeyStoreForValidator(config);
222
+ if (validatorKeyStore) {
223
+ rawKeyStores.push(validatorKeyStore);
224
+ }
225
+ if (config.enableProverNode) {
226
+ const proverKeyStore = createKeyStoreForProver(config);
227
+ if (proverKeyStore) {
228
+ rawKeyStores.push(proverKeyStore);
229
+ }
230
+ }
231
+ if (rawKeyStores.length > 0) {
232
+ keyStoreManager = new KeystoreManager(
233
+ rawKeyStores.length === 1 ? rawKeyStores[0] : mergeKeystores(rawKeyStores),
234
+ );
211
235
  }
212
236
  }
213
237
 
@@ -218,10 +242,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
218
242
  if (keyStoreManager === undefined) {
219
243
  throw new Error('Failed to create key store, a requirement for running a validator');
220
244
  }
221
- if (!keyStoreProvided) {
222
- log.warn(
223
- 'KEY STORE CREATED FROM ENVIRONMENT, IT IS RECOMMENDED TO USE A FILE-BASED KEY STORE IN PRODUCTION ENVIRONMENTS',
224
- );
245
+ if (!keyStoreProvided && process.env.NODE_ENV !== 'test') {
246
+ log.warn("Keystore created from env: it's recommended to use a file-based key store for production");
225
247
  }
226
248
  ValidatorClient.validateKeyStoreConfiguration(keyStoreManager, log);
227
249
  }
@@ -263,7 +285,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
263
285
  );
264
286
  }
265
287
 
266
- const blobClient = await createBlobClientWithFileStores(config, createLogger('node:blob-client:client'));
288
+ const blobClient = await createBlobClientWithFileStores(config, log.createChild('blob-client'));
267
289
 
268
290
  // attempt snapshot sync if possible
269
291
  await trySnapshotSync(config, log);
@@ -287,14 +309,28 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
287
309
  config.realProofs || config.debugForceTxProofVerification
288
310
  ? await BBCircuitVerifier.new(config)
289
311
  : new TestCircuitVerifier(config.proverTestVerificationDelayMs);
312
+
313
+ let debugLogStore: DebugLogStore;
290
314
  if (!config.realProofs) {
291
315
  log.warn(`Aztec node is accepting fake proofs`);
316
+
317
+ debugLogStore = new InMemoryDebugLogStore();
318
+ log.info(
319
+ 'Aztec node started in test mode (realProofs set to false) hence debug logs from public functions will be collected and served',
320
+ );
321
+ } else {
322
+ debugLogStore = new NullDebugLogStore();
292
323
  }
324
+
293
325
  const proofVerifier = new QueuedIVCVerifier(config, circuitVerifier);
294
326
 
327
+ const proverOnly = config.enableProverNode && config.disableValidator;
328
+ if (proverOnly) {
329
+ log.info('Starting in prover-only mode: skipping validator, sequencer, sentinel, and slasher subsystems');
330
+ }
331
+
295
332
  // create the tx pool and the p2p client, which will need the l2 block source
296
333
  const p2pClient = await createP2PClient(
297
- P2PClientType.Full,
298
334
  config,
299
335
  archiver,
300
336
  proofVerifier,
@@ -309,64 +345,60 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
309
345
  // We should really not be modifying the config object
310
346
  config.txPublicSetupAllowList = config.txPublicSetupAllowList ?? (await getDefaultAllowedSetupFunctions());
311
347
 
312
- // Create BlockBuilder for EpochPruneWatcher (slasher functionality)
313
- const blockBuilder = new BlockBuilder(
314
- { ...config, l1GenesisTime, slotDuration: Number(slotDuration) },
315
- worldStateSynchronizer,
316
- archiver,
317
- dateProvider,
318
- telemetry,
319
- );
348
+ // We'll accumulate sentinel watchers here
349
+ const watchers: Watcher[] = [];
320
350
 
321
- // Create FullNodeCheckpointsBuilder for validator and non-validator block proposal handling
351
+ // Create FullNodeCheckpointsBuilder for block proposal handling and tx validation
322
352
  const validatorCheckpointsBuilder = new FullNodeCheckpointsBuilder(
323
353
  { ...config, l1GenesisTime, slotDuration: Number(slotDuration) },
354
+ worldStateSynchronizer,
324
355
  archiver,
325
356
  dateProvider,
326
357
  telemetry,
327
358
  );
328
359
 
329
- // We'll accumulate sentinel watchers here
330
- const watchers: Watcher[] = [];
360
+ let validatorClient: ValidatorClient | undefined;
331
361
 
332
- // Create validator client if required
333
- const validatorClient = createValidatorClient(config, {
334
- checkpointsBuilder: validatorCheckpointsBuilder,
335
- worldState: worldStateSynchronizer,
336
- p2pClient,
337
- telemetry,
338
- dateProvider,
339
- epochCache,
340
- blockSource: archiver,
341
- l1ToL2MessageSource: archiver,
342
- keyStoreManager,
343
- blobClient,
344
- });
345
-
346
- // If we have a validator client, register it as a source of offenses for the slasher,
347
- // and have it register callbacks on the p2p client *before* we start it, otherwise messages
348
- // like attestations or auths will fail.
349
- if (validatorClient) {
350
- watchers.push(validatorClient);
351
- if (!options.dontStartSequencer) {
352
- await validatorClient.registerHandlers();
353
- }
354
- }
355
-
356
- // If there's no validator client but alwaysReexecuteBlockProposals is enabled,
357
- // create a BlockProposalHandler to reexecute block proposals for monitoring
358
- if (!validatorClient && config.alwaysReexecuteBlockProposals) {
359
- log.info('Setting up block proposal reexecution for monitoring');
360
- createBlockProposalHandler(config, {
362
+ if (!proverOnly) {
363
+ // Create validator client if required
364
+ validatorClient = await createValidatorClient(config, {
361
365
  checkpointsBuilder: validatorCheckpointsBuilder,
362
366
  worldState: worldStateSynchronizer,
367
+ p2pClient,
368
+ telemetry,
369
+ dateProvider,
363
370
  epochCache,
364
371
  blockSource: archiver,
365
372
  l1ToL2MessageSource: archiver,
366
- p2pClient,
367
- dateProvider,
368
- telemetry,
369
- }).registerForReexecution(p2pClient);
373
+ keyStoreManager,
374
+ blobClient,
375
+ });
376
+
377
+ // If we have a validator client, register it as a source of offenses for the slasher,
378
+ // and have it register callbacks on the p2p client *before* we start it, otherwise messages
379
+ // like attestations or auths will fail.
380
+ if (validatorClient) {
381
+ watchers.push(validatorClient);
382
+ if (!options.dontStartSequencer) {
383
+ await validatorClient.registerHandlers();
384
+ }
385
+ }
386
+
387
+ // If there's no validator client but alwaysReexecuteBlockProposals is enabled,
388
+ // create a BlockProposalHandler to reexecute block proposals for monitoring
389
+ if (!validatorClient && config.alwaysReexecuteBlockProposals) {
390
+ log.info('Setting up block proposal reexecution for monitoring');
391
+ createBlockProposalHandler(config, {
392
+ checkpointsBuilder: validatorCheckpointsBuilder,
393
+ worldState: worldStateSynchronizer,
394
+ epochCache,
395
+ blockSource: archiver,
396
+ l1ToL2MessageSource: archiver,
397
+ p2pClient,
398
+ dateProvider,
399
+ telemetry,
400
+ }).registerForReexecution(p2pClient);
401
+ }
370
402
  }
371
403
 
372
404
  // Start world state and wait for it to sync to the archiver.
@@ -375,29 +407,33 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
375
407
  // Start p2p. Note that it depends on world state to be running.
376
408
  await p2pClient.start();
377
409
 
378
- const validatorsSentinel = await createSentinel(epochCache, archiver, p2pClient, config);
379
- if (validatorsSentinel && config.slashInactivityPenalty > 0n) {
380
- watchers.push(validatorsSentinel);
381
- }
382
-
410
+ let validatorsSentinel: Awaited<ReturnType<typeof createSentinel>> | undefined;
383
411
  let epochPruneWatcher: EpochPruneWatcher | undefined;
384
- if (config.slashPrunePenalty > 0n || config.slashDataWithholdingPenalty > 0n) {
385
- epochPruneWatcher = new EpochPruneWatcher(
386
- archiver,
387
- archiver,
388
- epochCache,
389
- p2pClient.getTxProvider(),
390
- blockBuilder,
391
- config,
392
- );
393
- watchers.push(epochPruneWatcher);
394
- }
395
-
396
- // We assume we want to slash for invalid attestations unless all max penalties are set to 0
397
412
  let attestationsBlockWatcher: AttestationsBlockWatcher | undefined;
398
- if (config.slashProposeInvalidAttestationsPenalty > 0n || config.slashAttestDescendantOfInvalidPenalty > 0n) {
399
- attestationsBlockWatcher = new AttestationsBlockWatcher(archiver, epochCache, config);
400
- watchers.push(attestationsBlockWatcher);
413
+
414
+ if (!proverOnly) {
415
+ validatorsSentinel = await createSentinel(epochCache, archiver, p2pClient, config);
416
+ if (validatorsSentinel && config.slashInactivityPenalty > 0n) {
417
+ watchers.push(validatorsSentinel);
418
+ }
419
+
420
+ if (config.slashPrunePenalty > 0n || config.slashDataWithholdingPenalty > 0n) {
421
+ epochPruneWatcher = new EpochPruneWatcher(
422
+ archiver,
423
+ archiver,
424
+ epochCache,
425
+ p2pClient.getTxProvider(),
426
+ validatorCheckpointsBuilder,
427
+ config,
428
+ );
429
+ watchers.push(epochPruneWatcher);
430
+ }
431
+
432
+ // We assume we want to slash for invalid attestations unless all max penalties are set to 0
433
+ if (config.slashProposeInvalidAttestationsPenalty > 0n || config.slashAttestDescendantOfInvalidPenalty > 0n) {
434
+ attestationsBlockWatcher = new AttestationsBlockWatcher(archiver, epochCache, config);
435
+ watchers.push(attestationsBlockWatcher);
436
+ }
401
437
  }
402
438
 
403
439
  // Start p2p-related services once the archiver has completed sync
@@ -434,27 +470,29 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
434
470
  );
435
471
  await slasherClient.start();
436
472
 
437
- const l1TxUtils = config.publisherForwarderAddress
438
- ? await createForwarderL1TxUtilsFromEthSigner(
473
+ const l1TxUtils = config.sequencerPublisherForwarderAddress
474
+ ? await createForwarderL1TxUtilsFromSigners(
439
475
  publicClient,
440
476
  keyStoreManager!.createAllValidatorPublisherSigners(),
441
- config.publisherForwarderAddress,
477
+ config.sequencerPublisherForwarderAddress,
442
478
  { ...config, scope: 'sequencer' },
443
- { telemetry, logger: log.createChild('l1-tx-utils'), dateProvider },
479
+ { telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
444
480
  )
445
- : await createL1TxUtilsWithBlobsFromEthSigner(
481
+ : await createL1TxUtilsFromSigners(
446
482
  publicClient,
447
483
  keyStoreManager!.createAllValidatorPublisherSigners(),
448
484
  { ...config, scope: 'sequencer' },
449
- { telemetry, logger: log.createChild('l1-tx-utils'), dateProvider },
485
+ { telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
450
486
  );
451
487
 
452
488
  // Create and start the sequencer client
453
489
  const checkpointsBuilder = new CheckpointsBuilder(
454
490
  { ...config, l1GenesisTime, slotDuration: Number(slotDuration) },
491
+ worldStateSynchronizer,
455
492
  archiver,
456
493
  dateProvider,
457
494
  telemetry,
495
+ debugLogStore,
458
496
  );
459
497
 
460
498
  sequencer = await SequencerClient.new(config, {
@@ -482,6 +520,29 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
482
520
  log.warn(`Sequencer created but not started`);
483
521
  }
484
522
 
523
+ // Create prover node subsystem if enabled
524
+ let proverNode: ProverNode | undefined;
525
+ if (config.enableProverNode) {
526
+ proverNode = await createProverNode(config, {
527
+ ...deps.proverNodeDeps,
528
+ telemetry,
529
+ dateProvider,
530
+ archiver,
531
+ worldStateSynchronizer,
532
+ p2pClient,
533
+ epochCache,
534
+ blobClient,
535
+ keyStoreManager,
536
+ });
537
+
538
+ if (!options.dontStartProverNode) {
539
+ await proverNode.start();
540
+ log.info(`Prover node subsystem started`);
541
+ } else {
542
+ log.info(`Prover node subsystem created but not started`);
543
+ }
544
+ }
545
+
485
546
  const globalVariableBuilder = new GlobalVariableBuilder({
486
547
  ...config,
487
548
  rollupVersion: BigInt(config.rollupVersion),
@@ -489,7 +550,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
489
550
  slotDuration: Number(slotDuration),
490
551
  });
491
552
 
492
- return new AztecNodeService(
553
+ const node = new AztecNodeService(
493
554
  config,
494
555
  p2pClient,
495
556
  archiver,
@@ -498,6 +559,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
498
559
  archiver,
499
560
  worldStateSynchronizer,
500
561
  sequencer,
562
+ proverNode,
501
563
  slasherClient,
502
564
  validatorsSentinel,
503
565
  epochPruneWatcher,
@@ -510,7 +572,12 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
510
572
  telemetry,
511
573
  log,
512
574
  blobClient,
575
+ validatorClient,
576
+ keyStoreManager,
577
+ debugLogStore,
513
578
  );
579
+
580
+ return node;
514
581
  }
515
582
 
516
583
  /**
@@ -521,6 +588,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
521
588
  return this.sequencer;
522
589
  }
523
590
 
591
+ /** Returns the prover node subsystem, if enabled. */
592
+ public getProverNode(): ProverNode | undefined {
593
+ return this.proverNode;
594
+ }
595
+
524
596
  public getBlockSource(): L2BlockSource {
525
597
  return this.blockSource;
526
598
  }
@@ -574,19 +646,26 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
574
646
  enr,
575
647
  l1ContractAddresses: contractAddresses,
576
648
  protocolContractAddresses: protocolContractAddresses,
649
+ realProofs: !!this.config.realProofs,
577
650
  };
578
651
 
579
652
  return nodeInfo;
580
653
  }
581
654
 
582
655
  /**
583
- * Get a block specified by its number.
584
- * @param number - The block number being requested.
656
+ * Get a block specified by its block number, block hash, or 'latest'.
657
+ * @param block - The block parameter (block number, block hash, or 'latest').
585
658
  * @returns The requested block.
586
659
  */
587
- public async getBlock(number: BlockParameter): Promise<L2Block | undefined> {
588
- const blockNumber = number === 'latest' ? await this.getBlockNumber() : (number as BlockNumber);
589
- return await this.blockSource.getBlock(blockNumber);
660
+ public async getBlock(block: BlockParameter): Promise<L2Block | undefined> {
661
+ if (BlockHash.isBlockHash(block)) {
662
+ return this.getBlockByHash(block);
663
+ }
664
+ const blockNumber = block === 'latest' ? await this.getBlockNumber() : (block as BlockNumber);
665
+ if (blockNumber === BlockNumber.ZERO) {
666
+ return this.buildInitialBlock();
667
+ }
668
+ return await this.blockSource.getL2Block(blockNumber);
590
669
  }
591
670
 
592
671
  /**
@@ -594,9 +673,17 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
594
673
  * @param blockHash - The block hash being requested.
595
674
  * @returns The requested block.
596
675
  */
597
- public async getBlockByHash(blockHash: Fr): Promise<L2Block | undefined> {
598
- const publishedBlock = await this.blockSource.getPublishedBlockByHash(blockHash);
599
- return publishedBlock?.block;
676
+ public async getBlockByHash(blockHash: BlockHash): Promise<L2Block | undefined> {
677
+ const initialBlockHash = await this.#getInitialHeaderHash();
678
+ if (blockHash.equals(initialBlockHash)) {
679
+ return this.buildInitialBlock();
680
+ }
681
+ return await this.blockSource.getL2BlockByHash(blockHash);
682
+ }
683
+
684
+ private buildInitialBlock(): L2Block {
685
+ const initialHeader = this.worldStateSynchronizer.getCommitted().getInitialHeader();
686
+ return L2Block.empty(initialHeader);
600
687
  }
601
688
 
602
689
  /**
@@ -605,8 +692,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
605
692
  * @returns The requested block.
606
693
  */
607
694
  public async getBlockByArchive(archive: Fr): Promise<L2Block | undefined> {
608
- const publishedBlock = await this.blockSource.getPublishedBlockByArchive(archive);
609
- return publishedBlock?.block;
695
+ return await this.blockSource.getL2BlockByArchive(archive);
610
696
  }
611
697
 
612
698
  /**
@@ -616,23 +702,15 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
616
702
  * @returns The blocks requested.
617
703
  */
618
704
  public async getBlocks(from: BlockNumber, limit: number): Promise<L2Block[]> {
619
- return (await this.blockSource.getBlocks(from, limit)) ?? [];
620
- }
621
-
622
- public async getPublishedBlocks(from: BlockNumber, limit: number): Promise<PublishedL2Block[]> {
623
- return (await this.blockSource.getPublishedBlocks(from, limit)) ?? [];
705
+ return (await this.blockSource.getBlocks(from, BlockNumber(limit))) ?? [];
624
706
  }
625
707
 
626
- public async getPublishedCheckpoints(from: CheckpointNumber, limit: number): Promise<PublishedCheckpoint[]> {
627
- return (await this.blockSource.getPublishedCheckpoints(from, limit)) ?? [];
708
+ public async getCheckpoints(from: CheckpointNumber, limit: number): Promise<PublishedCheckpoint[]> {
709
+ return (await this.blockSource.getCheckpoints(from, limit)) ?? [];
628
710
  }
629
711
 
630
- public async getL2BlocksNew(from: BlockNumber, limit: number): Promise<L2BlockNew[]> {
631
- return (await this.blockSource.getL2BlocksNew(from, limit)) ?? [];
632
- }
633
-
634
- public async getCheckpointedBlocks(from: BlockNumber, limit: number, proven?: boolean) {
635
- return (await this.blockSource.getCheckpointedBlocks(from, limit, proven)) ?? [];
712
+ public async getCheckpointedBlocks(from: BlockNumber, limit: number) {
713
+ return (await this.blockSource.getCheckpointedBlocks(from, limit)) ?? [];
636
714
  }
637
715
 
638
716
  /**
@@ -663,6 +741,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
663
741
  return await this.blockSource.getProvenBlockNumber();
664
742
  }
665
743
 
744
+ public async getCheckpointedBlockNumber(): Promise<BlockNumber> {
745
+ return await this.blockSource.getCheckpointedL2BlockNumber();
746
+ }
747
+
666
748
  /**
667
749
  * Method to fetch the version of the package.
668
750
  * @returns The node package version
@@ -695,12 +777,43 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
695
777
  return this.contractDataSource.getContract(address);
696
778
  }
697
779
 
698
- public getPrivateLogsByTags(tags: SiloedTag[]): Promise<TxScopedL2Log[][]> {
699
- return this.logsSource.getPrivateLogsByTags(tags);
700
- }
701
-
702
- public getPublicLogsByTagsFromContract(contractAddress: AztecAddress, tags: Tag[]): Promise<TxScopedL2Log[][]> {
703
- return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags);
780
+ public async getPrivateLogsByTags(
781
+ tags: SiloedTag[],
782
+ page?: number,
783
+ referenceBlock?: BlockHash,
784
+ ): Promise<TxScopedL2Log[][]> {
785
+ if (referenceBlock) {
786
+ const initialBlockHash = await this.#getInitialHeaderHash();
787
+ if (!referenceBlock.equals(initialBlockHash)) {
788
+ const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
789
+ if (!header) {
790
+ throw new Error(
791
+ `Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
792
+ );
793
+ }
794
+ }
795
+ }
796
+ return this.logsSource.getPrivateLogsByTags(tags, page);
797
+ }
798
+
799
+ public async getPublicLogsByTagsFromContract(
800
+ contractAddress: AztecAddress,
801
+ tags: Tag[],
802
+ page?: number,
803
+ referenceBlock?: BlockHash,
804
+ ): Promise<TxScopedL2Log[][]> {
805
+ if (referenceBlock) {
806
+ const initialBlockHash = await this.#getInitialHeaderHash();
807
+ if (!referenceBlock.equals(initialBlockHash)) {
808
+ const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
809
+ if (!header) {
810
+ throw new Error(
811
+ `Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
812
+ );
813
+ }
814
+ }
815
+ }
816
+ return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page);
704
817
  }
705
818
 
706
819
  /**
@@ -742,26 +855,36 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
742
855
  }
743
856
 
744
857
  await this.p2pClient!.sendTx(tx);
745
- this.metrics.receivedTx(timer.ms(), true);
746
- this.log.info(`Received tx ${txHash}`, { txHash });
858
+ const duration = timer.ms();
859
+ this.metrics.receivedTx(duration, true);
860
+ this.log.info(`Received tx ${txHash} in ${duration}ms`, { txHash });
747
861
  }
748
862
 
749
863
  public async getTxReceipt(txHash: TxHash): Promise<TxReceipt> {
750
- let txReceipt = new TxReceipt(txHash, TxStatus.DROPPED, 'Tx dropped by P2P node.');
751
-
752
- // We first check if the tx is in pending (instead of first checking if it is mined) because if we first check
753
- // for mined and then for pending there could be a race condition where the tx is mined between the two checks
754
- // and we would incorrectly return a TxReceipt with status DROPPED
755
- if ((await this.p2pClient.getTxStatus(txHash)) === 'pending') {
756
- txReceipt = new TxReceipt(txHash, TxStatus.PENDING, '');
757
- }
864
+ // Check the tx pool status first. If the tx is known to the pool (pending or mined), we'll use that
865
+ // as a fallback if we don't find a settled receipt in the archiver.
866
+ const txPoolStatus = await this.p2pClient.getTxStatus(txHash);
867
+ const isKnownToPool = txPoolStatus === 'pending' || txPoolStatus === 'mined';
758
868
 
869
+ // Then get the actual tx from the archiver, which tracks every tx in a mined block.
759
870
  const settledTxReceipt = await this.blockSource.getSettledTxReceipt(txHash);
871
+
872
+ let receipt: TxReceipt;
760
873
  if (settledTxReceipt) {
761
- txReceipt = settledTxReceipt;
874
+ receipt = settledTxReceipt;
875
+ } else if (isKnownToPool) {
876
+ // If the tx is in the pool but not in the archiver, it's pending.
877
+ // This handles race conditions between archiver and p2p, where the archiver
878
+ // has pruned the block in which a tx was mined, but p2p has not caught up yet.
879
+ receipt = new TxReceipt(txHash, TxStatus.PENDING, undefined, undefined);
880
+ } else {
881
+ // Otherwise, if we don't know the tx, we consider it dropped.
882
+ receipt = new TxReceipt(txHash, TxStatus.DROPPED, undefined, 'Tx dropped by P2P node');
762
883
  }
763
884
 
764
- return txReceipt;
885
+ this.debugLogStore.decorateReceiptWithLogs(txHash.toString(), receipt);
886
+
887
+ return receipt;
765
888
  }
766
889
 
767
890
  public getTxEffect(txHash: TxHash): Promise<IndexedTxEffect | undefined> {
@@ -778,6 +901,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
778
901
  await tryStop(this.slasherClient);
779
902
  await tryStop(this.proofVerifier);
780
903
  await tryStop(this.sequencer);
904
+ await tryStop(this.proverNode);
781
905
  await tryStop(this.p2pClient);
782
906
  await tryStop(this.worldStateSynchronizer);
783
907
  await tryStop(this.blockSource);
@@ -826,20 +950,12 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
826
950
  return compactArray(await Promise.all(txHashes.map(txHash => this.getTxByHash(txHash))));
827
951
  }
828
952
 
829
- /**
830
- * Find the indexes of the given leaves in the given tree along with a block metadata pointing to the block in which
831
- * the leaves were inserted.
832
- * @param blockNumber - The block number at which to get the data or 'latest' for latest data.
833
- * @param treeId - The tree to search in.
834
- * @param leafValues - The values to search for.
835
- * @returns The indices of leaves and the block metadata of a block in which the leaves were inserted.
836
- */
837
953
  public async findLeavesIndexes(
838
- blockNumber: BlockParameter,
954
+ referenceBlock: BlockParameter,
839
955
  treeId: MerkleTreeId,
840
956
  leafValues: Fr[],
841
957
  ): Promise<(DataInBlock<bigint> | undefined)[]> {
842
- const committedDb = await this.#getWorldState(blockNumber);
958
+ const committedDb = await this.#getWorldState(referenceBlock);
843
959
  const maybeIndices = await committedDb.findLeafIndices(
844
960
  treeId,
845
961
  leafValues.map(x => x.toBuffer()),
@@ -891,56 +1007,28 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
891
1007
  }
892
1008
  return {
893
1009
  l2BlockNumber: BlockNumber(Number(blockNumber)),
894
- l2BlockHash: L2BlockHash.fromField(blockHash),
1010
+ l2BlockHash: new BlockHash(blockHash),
895
1011
  data: index,
896
1012
  };
897
1013
  });
898
1014
  }
899
1015
 
900
- /**
901
- * Returns a sibling path for the given index in the nullifier tree.
902
- * @param blockNumber - The block number at which to get the data.
903
- * @param leafIndex - The index of the leaf for which the sibling path is required.
904
- * @returns The sibling path for the leaf index.
905
- */
906
- public async getNullifierSiblingPath(
907
- blockNumber: BlockParameter,
908
- leafIndex: bigint,
909
- ): Promise<SiblingPath<typeof NULLIFIER_TREE_HEIGHT>> {
910
- const committedDb = await this.#getWorldState(blockNumber);
911
- return committedDb.getSiblingPath(MerkleTreeId.NULLIFIER_TREE, leafIndex);
912
- }
913
-
914
- /**
915
- * Returns a sibling path for the given index in the data tree.
916
- * @param blockNumber - The block number at which to get the data.
917
- * @param leafIndex - The index of the leaf for which the sibling path is required.
918
- * @returns The sibling path for the leaf index.
919
- */
920
- public async getNoteHashSiblingPath(
921
- blockNumber: BlockParameter,
922
- leafIndex: bigint,
923
- ): Promise<SiblingPath<typeof NOTE_HASH_TREE_HEIGHT>> {
924
- const committedDb = await this.#getWorldState(blockNumber);
925
- return committedDb.getSiblingPath(MerkleTreeId.NOTE_HASH_TREE, leafIndex);
926
- }
927
-
928
- public async getArchiveMembershipWitness(
929
- blockNumber: BlockParameter,
930
- archive: Fr,
1016
+ public async getBlockHashMembershipWitness(
1017
+ referenceBlock: BlockParameter,
1018
+ blockHash: BlockHash,
931
1019
  ): Promise<MembershipWitness<typeof ARCHIVE_HEIGHT> | undefined> {
932
- const committedDb = await this.#getWorldState(blockNumber);
933
- const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.ARCHIVE>(MerkleTreeId.ARCHIVE, [archive]);
1020
+ const committedDb = await this.#getWorldState(referenceBlock);
1021
+ const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.ARCHIVE>(MerkleTreeId.ARCHIVE, [blockHash]);
934
1022
  return pathAndIndex === undefined
935
1023
  ? undefined
936
1024
  : MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
937
1025
  }
938
1026
 
939
1027
  public async getNoteHashMembershipWitness(
940
- blockNumber: BlockParameter,
1028
+ referenceBlock: BlockParameter,
941
1029
  noteHash: Fr,
942
1030
  ): Promise<MembershipWitness<typeof NOTE_HASH_TREE_HEIGHT> | undefined> {
943
- const committedDb = await this.#getWorldState(blockNumber);
1031
+ const committedDb = await this.#getWorldState(referenceBlock);
944
1032
  const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.NOTE_HASH_TREE>(
945
1033
  MerkleTreeId.NOTE_HASH_TREE,
946
1034
  [noteHash],
@@ -950,17 +1038,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
950
1038
  : MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
951
1039
  }
952
1040
 
953
- /**
954
- * Returns the index and a sibling path for a leaf in the committed l1 to l2 data tree.
955
- * @param blockNumber - The block number at which to get the data.
956
- * @param l1ToL2Message - The l1ToL2Message to get the index / sibling path for.
957
- * @returns A tuple of the index and the sibling path of the L1ToL2Message (undefined if not found).
958
- */
959
1041
  public async getL1ToL2MessageMembershipWitness(
960
- blockNumber: BlockParameter,
1042
+ referenceBlock: BlockParameter,
961
1043
  l1ToL2Message: Fr,
962
1044
  ): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>] | undefined> {
963
- const db = await this.#getWorldState(blockNumber);
1045
+ const db = await this.#getWorldState(referenceBlock);
964
1046
  const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [l1ToL2Message]);
965
1047
  if (!witness) {
966
1048
  return undefined;
@@ -993,12 +1075,13 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
993
1075
  * @returns The L2 to L1 messages (empty array if the epoch is not found).
994
1076
  */
995
1077
  public async getL2ToL1Messages(epoch: EpochNumber): Promise<Fr[][][][]> {
996
- // Assumes `getBlocksForEpoch` returns blocks in ascending order of block number.
997
- const blocks = await this.blockSource.getBlocksForEpoch(epoch);
1078
+ // Assumes `getCheckpointedBlocksForEpoch` returns blocks in ascending order of block number.
1079
+ const checkpointedBlocks = await this.blockSource.getCheckpointedBlocksForEpoch(epoch);
998
1080
  const blocksInCheckpoints: L2Block[][] = [];
999
1081
  let previousSlotNumber = SlotNumber.ZERO;
1000
1082
  let checkpointIndex = -1;
1001
- for (const block of blocks) {
1083
+ for (const checkpointedBlock of checkpointedBlocks) {
1084
+ const block = checkpointedBlock.block;
1002
1085
  const slotNumber = block.header.globalVariables.slotNumber;
1003
1086
  if (slotNumber !== previousSlotNumber) {
1004
1087
  checkpointIndex++;
@@ -1012,45 +1095,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1012
1095
  );
1013
1096
  }
1014
1097
 
1015
- /**
1016
- * Returns a sibling path for a leaf in the committed blocks tree.
1017
- * @param blockNumber - The block number at which to get the data.
1018
- * @param leafIndex - Index of the leaf in the tree.
1019
- * @returns The sibling path.
1020
- */
1021
- public async getArchiveSiblingPath(
1022
- blockNumber: BlockParameter,
1023
- leafIndex: bigint,
1024
- ): Promise<SiblingPath<typeof ARCHIVE_HEIGHT>> {
1025
- const committedDb = await this.#getWorldState(blockNumber);
1026
- return committedDb.getSiblingPath(MerkleTreeId.ARCHIVE, leafIndex);
1027
- }
1028
-
1029
- /**
1030
- * Returns a sibling path for a leaf in the committed public data tree.
1031
- * @param blockNumber - The block number at which to get the data.
1032
- * @param leafIndex - Index of the leaf in the tree.
1033
- * @returns The sibling path.
1034
- */
1035
- public async getPublicDataSiblingPath(
1036
- blockNumber: BlockParameter,
1037
- leafIndex: bigint,
1038
- ): Promise<SiblingPath<typeof PUBLIC_DATA_TREE_HEIGHT>> {
1039
- const committedDb = await this.#getWorldState(blockNumber);
1040
- return committedDb.getSiblingPath(MerkleTreeId.PUBLIC_DATA_TREE, leafIndex);
1041
- }
1042
-
1043
- /**
1044
- * Returns a nullifier membership witness for a given nullifier at a given block.
1045
- * @param blockNumber - The block number at which to get the index.
1046
- * @param nullifier - Nullifier we try to find witness for.
1047
- * @returns The nullifier membership witness (if found).
1048
- */
1049
1098
  public async getNullifierMembershipWitness(
1050
- blockNumber: BlockParameter,
1099
+ referenceBlock: BlockParameter,
1051
1100
  nullifier: Fr,
1052
1101
  ): Promise<NullifierMembershipWitness | undefined> {
1053
- const db = await this.#getWorldState(blockNumber);
1102
+ const db = await this.#getWorldState(referenceBlock);
1054
1103
  const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [nullifier.toBuffer()]);
1055
1104
  if (!witness) {
1056
1105
  return undefined;
@@ -1067,7 +1116,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1067
1116
 
1068
1117
  /**
1069
1118
  * Returns a low nullifier membership witness for a given nullifier at a given block.
1070
- * @param blockNumber - The block number at which to get the index.
1119
+ * @param referenceBlock - The block parameter (block number, block hash, or 'latest') at which to get the data
1120
+ * (which contains the root of the nullifier tree in which we are searching for the nullifier).
1071
1121
  * @param nullifier - Nullifier we try to find the low nullifier witness for.
1072
1122
  * @returns The low nullifier membership witness (if found).
1073
1123
  * @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
@@ -1080,10 +1130,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1080
1130
  * TODO: This is a confusing behavior and we should eventually address that.
1081
1131
  */
1082
1132
  public async getLowNullifierMembershipWitness(
1083
- blockNumber: BlockParameter,
1133
+ referenceBlock: BlockParameter,
1084
1134
  nullifier: Fr,
1085
1135
  ): Promise<NullifierMembershipWitness | undefined> {
1086
- const committedDb = await this.#getWorldState(blockNumber);
1136
+ const committedDb = await this.#getWorldState(referenceBlock);
1087
1137
  const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
1088
1138
  if (!findResult) {
1089
1139
  return undefined;
@@ -1098,8 +1148,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1098
1148
  return new NullifierMembershipWitness(BigInt(index), preimageData as NullifierLeafPreimage, siblingPath);
1099
1149
  }
1100
1150
 
1101
- async getPublicDataWitness(blockNumber: BlockParameter, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
1102
- const committedDb = await this.#getWorldState(blockNumber);
1151
+ async getPublicDataWitness(referenceBlock: BlockParameter, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
1152
+ const committedDb = await this.#getWorldState(referenceBlock);
1103
1153
  const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
1104
1154
  if (!lowLeafResult) {
1105
1155
  return undefined;
@@ -1113,19 +1163,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1113
1163
  }
1114
1164
  }
1115
1165
 
1116
- /**
1117
- * Gets the storage value at the given contract storage slot.
1118
- *
1119
- * @remarks The storage slot here refers to the slot as it is defined in Noir not the index in the merkle tree.
1120
- * Aztec's version of `eth_getStorageAt`.
1121
- *
1122
- * @param contract - Address of the contract to query.
1123
- * @param slot - Slot to query.
1124
- * @param blockNumber - The block number at which to get the data or 'latest'.
1125
- * @returns Storage value at the given contract slot.
1126
- */
1127
- public async getPublicStorageAt(blockNumber: BlockParameter, contract: AztecAddress, slot: Fr): Promise<Fr> {
1128
- const committedDb = await this.#getWorldState(blockNumber);
1166
+ public async getPublicStorageAt(referenceBlock: BlockParameter, contract: AztecAddress, slot: Fr): Promise<Fr> {
1167
+ const committedDb = await this.#getWorldState(referenceBlock);
1129
1168
  const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
1130
1169
 
1131
1170
  const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
@@ -1139,24 +1178,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1139
1178
  return preimage.leaf.value;
1140
1179
  }
1141
1180
 
1142
- /**
1143
- * Returns the currently committed block header, or the initial header if no blocks have been produced.
1144
- * @returns The current committed block header.
1145
- */
1146
- public async getBlockHeader(blockNumber: BlockParameter = 'latest'): Promise<BlockHeader | undefined> {
1147
- return blockNumber === BlockNumber.ZERO ||
1148
- (blockNumber === 'latest' && (await this.blockSource.getBlockNumber()) === BlockNumber.ZERO)
1149
- ? this.worldStateSynchronizer.getCommitted().getInitialHeader()
1150
- : this.blockSource.getBlockHeader(blockNumber === 'latest' ? blockNumber : (blockNumber as BlockNumber));
1151
- }
1152
-
1153
- /**
1154
- * Get a block header specified by its hash.
1155
- * @param blockHash - The block hash being requested.
1156
- * @returns The requested block header.
1157
- */
1158
- public async getBlockHeaderByHash(blockHash: Fr): Promise<BlockHeader | undefined> {
1159
- return await this.blockSource.getBlockHeaderByHash(blockHash);
1181
+ public async getBlockHeader(block: BlockParameter = 'latest'): Promise<BlockHeader | undefined> {
1182
+ if (BlockHash.isBlockHash(block)) {
1183
+ const initialBlockHash = await this.#getInitialHeaderHash();
1184
+ if (block.equals(initialBlockHash)) {
1185
+ // Block source doesn't handle initial header so we need to handle the case separately.
1186
+ return this.worldStateSynchronizer.getCommitted().getInitialHeader();
1187
+ }
1188
+ return this.blockSource.getBlockHeaderByHash(block);
1189
+ } else {
1190
+ // Block source doesn't handle initial header so we need to handle the case separately.
1191
+ const blockNumber = block === 'latest' ? await this.getBlockNumber() : (block as BlockNumber);
1192
+ if (blockNumber === BlockNumber.ZERO) {
1193
+ return this.worldStateSynchronizer.getCommitted().getInitialHeader();
1194
+ }
1195
+ return this.blockSource.getBlockHeader(block);
1196
+ }
1160
1197
  }
1161
1198
 
1162
1199
  /**
@@ -1168,6 +1205,14 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1168
1205
  return await this.blockSource.getBlockHeaderByArchive(archive);
1169
1206
  }
1170
1207
 
1208
+ public getBlockData(number: BlockNumber): Promise<BlockData | undefined> {
1209
+ return this.blockSource.getBlockData(number);
1210
+ }
1211
+
1212
+ public getBlockDataByArchive(archive: Fr): Promise<BlockData | undefined> {
1213
+ return this.blockSource.getBlockDataByArchive(archive);
1214
+ }
1215
+
1171
1216
  /**
1172
1217
  * Simulates the public part of a transaction with the current state.
1173
1218
  * @param tx - The transaction to simulate.
@@ -1191,7 +1236,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1191
1236
  }
1192
1237
 
1193
1238
  const txHash = tx.getTxHash();
1194
- const blockNumber = BlockNumber((await this.blockSource.getBlockNumber()) + 1);
1239
+ const latestBlockNumber = await this.blockSource.getBlockNumber();
1240
+ const blockNumber = BlockNumber.add(latestBlockNumber, 1);
1195
1241
 
1196
1242
  // If sequencer is not initialized, we just set these values to zero for simulation.
1197
1243
  const coinbase = EthAddress.ZERO;
@@ -1206,6 +1252,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1206
1252
  this.contractDataSource,
1207
1253
  new DateProvider(),
1208
1254
  this.telemetry,
1255
+ this.log.getBindings(),
1209
1256
  );
1210
1257
 
1211
1258
  this.log.verbose(`Simulating public calls for tx ${txHash}`, {
@@ -1214,6 +1261,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1214
1261
  blockNumber,
1215
1262
  });
1216
1263
 
1264
+ // Ensure world-state has caught up with the latest block we loaded from the archiver
1265
+ await this.worldStateSynchronizer.syncImmediate(latestBlockNumber);
1217
1266
  const merkleTreeFork = await this.worldStateSynchronizer.fork();
1218
1267
  try {
1219
1268
  const config = PublicSimulatorConfig.from({
@@ -1229,7 +1278,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1229
1278
  const processor = publicProcessorFactory.create(merkleTreeFork, newGlobalVariables, config);
1230
1279
 
1231
1280
  // REFACTOR: Consider merging ProcessReturnValues into ProcessedTx
1232
- const [processedTxs, failedTxs, _usedTxs, returns] = await processor.process([tx]);
1281
+ const [processedTxs, failedTxs, _usedTxs, returns, _blobFields, debugLogs] = await processor.process([tx]);
1233
1282
  // REFACTOR: Consider returning the error rather than throwing
1234
1283
  if (failedTxs.length) {
1235
1284
  this.log.warn(`Simulated tx ${txHash} fails: ${failedTxs[0].error}`, { txHash });
@@ -1243,6 +1292,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1243
1292
  processedTx.txEffect,
1244
1293
  returns,
1245
1294
  processedTx.gasUsed,
1295
+ debugLogs,
1246
1296
  );
1247
1297
  } finally {
1248
1298
  await merkleTreeFork.close();
@@ -1256,19 +1306,25 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1256
1306
  const db = this.worldStateSynchronizer.getCommitted();
1257
1307
  const verifier = isSimulation ? undefined : this.proofVerifier;
1258
1308
 
1259
- // We accept transactions if they are not expired by the next slot (checked based on the IncludeByTimestamp field)
1309
+ // We accept transactions if they are not expired by the next slot (checked based on the ExpirationTimestamp field)
1260
1310
  const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
1261
1311
  const blockNumber = BlockNumber((await this.blockSource.getBlockNumber()) + 1);
1262
- const validator = createValidatorForAcceptingTxs(db, this.contractDataSource, verifier, {
1263
- timestamp: nextSlotTimestamp,
1264
- blockNumber,
1265
- l1ChainId: this.l1ChainId,
1266
- rollupVersion: this.version,
1267
- setupAllowList: this.config.txPublicSetupAllowList ?? (await getDefaultAllowedSetupFunctions()),
1268
- gasFees: await this.getCurrentMinFees(),
1269
- skipFeeEnforcement,
1270
- txsPermitted: !this.config.disableTransactions,
1271
- });
1312
+ const validator = createTxValidatorForAcceptingTxsOverRPC(
1313
+ db,
1314
+ this.contractDataSource,
1315
+ verifier,
1316
+ {
1317
+ timestamp: nextSlotTimestamp,
1318
+ blockNumber,
1319
+ l1ChainId: this.l1ChainId,
1320
+ rollupVersion: this.version,
1321
+ setupAllowList: this.config.txPublicSetupAllowList ?? (await getDefaultAllowedSetupFunctions()),
1322
+ gasFees: await this.getCurrentMinFees(),
1323
+ skipFeeEnforcement,
1324
+ txsPermitted: !this.config.disableTransactions,
1325
+ },
1326
+ this.log.getBindings(),
1327
+ );
1272
1328
 
1273
1329
  return await validator.validateTx(tx);
1274
1330
  }
@@ -1432,16 +1488,107 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1432
1488
  }
1433
1489
  }
1434
1490
 
1491
+ public async reloadKeystore(): Promise<void> {
1492
+ if (!this.config.keyStoreDirectory?.length) {
1493
+ throw new BadRequestError(
1494
+ 'Cannot reload keystore: node is not using a file-based keystore. ' +
1495
+ 'Set KEY_STORE_DIRECTORY to use file-based keystores.',
1496
+ );
1497
+ }
1498
+ if (!this.validatorClient) {
1499
+ throw new BadRequestError('Cannot reload keystore: validator is not enabled.');
1500
+ }
1501
+
1502
+ this.log.info('Reloading keystore from disk');
1503
+
1504
+ // Re-read and validate keystore files
1505
+ const keyStores = loadKeystores(this.config.keyStoreDirectory);
1506
+ const newManager = new KeystoreManager(mergeKeystores(keyStores));
1507
+ await newManager.validateSigners();
1508
+ ValidatorClient.validateKeyStoreConfiguration(newManager, this.log);
1509
+
1510
+ // Validate that every validator's publisher keys overlap with the L1 signers
1511
+ // that were initialized at startup. Publishers cannot be hot-reloaded, so a
1512
+ // validator with a publisher key that doesn't match any existing L1 signer
1513
+ // would silently fail on every proposer slot.
1514
+ if (this.keyStoreManager && this.sequencer) {
1515
+ const oldAdapter = NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager);
1516
+ const availablePublishers = new Set(
1517
+ oldAdapter
1518
+ .getAttesterAddresses()
1519
+ .flatMap(a => oldAdapter.getPublisherAddresses(a).map(p => p.toString().toLowerCase())),
1520
+ );
1521
+
1522
+ const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
1523
+ for (const attester of newAdapter.getAttesterAddresses()) {
1524
+ const pubs = newAdapter.getPublisherAddresses(attester);
1525
+ if (pubs.length > 0 && !pubs.some(p => availablePublishers.has(p.toString().toLowerCase()))) {
1526
+ throw new BadRequestError(
1527
+ `Cannot reload keystore: validator ${attester} has publisher keys ` +
1528
+ `[${pubs.map(p => p.toString()).join(', ')}] but none match the L1 signers initialized at startup ` +
1529
+ `[${[...availablePublishers].join(', ')}]. Publishers cannot be hot-reloaded — ` +
1530
+ `use an existing publisher key or restart the node.`,
1531
+ );
1532
+ }
1533
+ }
1534
+ }
1535
+
1536
+ // Build adapters for old and new keystores to compute diff
1537
+ const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
1538
+ const newAddresses = newAdapter.getAttesterAddresses();
1539
+ const oldAddresses = this.keyStoreManager
1540
+ ? NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager).getAttesterAddresses()
1541
+ : [];
1542
+
1543
+ const oldSet = new Set(oldAddresses.map(a => a.toString()));
1544
+ const newSet = new Set(newAddresses.map(a => a.toString()));
1545
+ const added = newAddresses.filter(a => !oldSet.has(a.toString()));
1546
+ const removed = oldAddresses.filter(a => !newSet.has(a.toString()));
1547
+
1548
+ if (added.length > 0) {
1549
+ this.log.info(`Keystore reload: adding attester keys: ${added.map(a => a.toString()).join(', ')}`);
1550
+ }
1551
+ if (removed.length > 0) {
1552
+ this.log.info(`Keystore reload: removing attester keys: ${removed.map(a => a.toString()).join(', ')}`);
1553
+ }
1554
+ if (added.length === 0 && removed.length === 0) {
1555
+ this.log.info('Keystore reload: attester keys unchanged');
1556
+ }
1557
+
1558
+ // Update the validator client (coinbase, feeRecipient, attester keys)
1559
+ this.validatorClient.reloadKeystore(newManager);
1560
+
1561
+ // Update the publisher factory's keystore so newly-added validators
1562
+ // can be matched to existing publisher keys when proposing blocks.
1563
+ if (this.sequencer) {
1564
+ this.sequencer.updatePublisherNodeKeyStore(newAdapter);
1565
+ }
1566
+
1567
+ // Update slasher's "don't-slash-self" list with new validator addresses
1568
+ if (this.slasherClient && !this.config.slashSelfAllowed) {
1569
+ const slashValidatorsNever = unique(
1570
+ [...(this.config.slashValidatorsNever ?? []), ...newAddresses].map(a => a.toString()),
1571
+ ).map(EthAddress.fromString);
1572
+ this.slasherClient.updateConfig({ slashValidatorsNever });
1573
+ }
1574
+
1575
+ this.keyStoreManager = newManager;
1576
+ this.log.info('Keystore reloaded: coinbase, feeRecipient, and attester keys updated');
1577
+ }
1578
+
1579
+ #getInitialHeaderHash(): Promise<BlockHash> {
1580
+ if (!this.initialHeaderHashPromise) {
1581
+ this.initialHeaderHashPromise = this.worldStateSynchronizer.getCommitted().getInitialHeader().hash();
1582
+ }
1583
+ return this.initialHeaderHashPromise;
1584
+ }
1585
+
1435
1586
  /**
1436
1587
  * Returns an instance of MerkleTreeOperations having first ensured the world state is fully synched
1437
- * @param blockNumber - The block number at which to get the data.
1588
+ * @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
1438
1589
  * @returns An instance of a committed MerkleTreeOperations
1439
1590
  */
1440
- async #getWorldState(blockNumber: BlockParameter) {
1441
- if (typeof blockNumber === 'number' && blockNumber < INITIAL_L2_BLOCK_NUM - 1) {
1442
- throw new Error('Invalid block number to get world state for: ' + blockNumber);
1443
- }
1444
-
1591
+ async #getWorldState(block: BlockParameter) {
1445
1592
  let blockSyncedTo: BlockNumber = BlockNumber.ZERO;
1446
1593
  try {
1447
1594
  // Attempt to sync the world state if necessary
@@ -1450,15 +1597,39 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1450
1597
  this.log.error(`Error getting world state: ${err}`);
1451
1598
  }
1452
1599
 
1453
- // using a snapshot could be less efficient than using the committed db
1454
- if (blockNumber === 'latest' /*|| blockNumber === blockSyncedTo*/) {
1455
- this.log.debug(`Using committed db for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
1600
+ if (block === 'latest') {
1601
+ this.log.debug(`Using committed db for block 'latest', world state synced upto ${blockSyncedTo}`);
1456
1602
  return this.worldStateSynchronizer.getCommitted();
1457
- } else if (blockNumber <= blockSyncedTo) {
1603
+ }
1604
+
1605
+ if (BlockHash.isBlockHash(block)) {
1606
+ const initialBlockHash = await this.#getInitialHeaderHash();
1607
+ if (block.equals(initialBlockHash)) {
1608
+ // Block source doesn't handle initial header so we need to handle the case separately.
1609
+ return this.worldStateSynchronizer.getSnapshot(BlockNumber.ZERO);
1610
+ }
1611
+
1612
+ const header = await this.blockSource.getBlockHeaderByHash(block);
1613
+ if (!header) {
1614
+ throw new Error(
1615
+ `Block hash ${block.toString()} not found when querying world state. If the node API has been queried with anchor block hash possibly a reorg has occurred.`,
1616
+ );
1617
+ }
1618
+ const blockNumber = header.getBlockNumber();
1458
1619
  this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
1459
- return this.worldStateSynchronizer.getSnapshot(blockNumber as BlockNumber);
1460
- } else {
1461
- throw new Error(`Block ${blockNumber} not yet synced`);
1620
+ return this.worldStateSynchronizer.getSnapshot(blockNumber);
1621
+ }
1622
+
1623
+ // Block number provided
1624
+ {
1625
+ const blockNumber = block as BlockNumber;
1626
+
1627
+ if (blockNumber > blockSyncedTo) {
1628
+ throw new Error(`Queried block ${block} not yet synced by the node (node is synced upto ${blockSyncedTo}).`);
1629
+ }
1630
+
1631
+ this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
1632
+ return this.worldStateSynchronizer.getSnapshot(blockNumber);
1462
1633
  }
1463
1634
  }
1464
1635