@aztec/aztec-node 0.0.1-commit.e61ad554 → 0.0.1-commit.ec5f612

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,20 +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
- type L1_TO_L2_MSG_TREE_HEIGHT,
7
- type NOTE_HASH_TREE_HEIGHT,
8
- type NULLIFIER_TREE_HEIGHT,
9
- type PUBLIC_DATA_TREE_HEIGHT,
10
- } 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';
11
6
  import { EpochCache, type EpochCacheInterface } from '@aztec/epoch-cache';
12
7
  import { createEthereumChain } from '@aztec/ethereum/chain';
13
8
  import { getPublicClient } from '@aztec/ethereum/client';
14
9
  import { RegistryContract, RollupContract } from '@aztec/ethereum/contracts';
15
10
  import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
16
11
  import { BlockNumber, CheckpointNumber, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
17
- import { compactArray, pick } from '@aztec/foundation/collection';
12
+ import { compactArray, pick, unique } from '@aztec/foundation/collection';
18
13
  import { Fr } from '@aztec/foundation/curves/bn254';
19
14
  import { EthAddress } from '@aztec/foundation/eth-address';
20
15
  import { BadRequestError } from '@aztec/foundation/json-rpc';
@@ -22,14 +17,19 @@ import { type Logger, createLogger } from '@aztec/foundation/log';
22
17
  import { count } from '@aztec/foundation/string';
23
18
  import { DateProvider, Timer } from '@aztec/foundation/timer';
24
19
  import { MembershipWitness, SiblingPath } from '@aztec/foundation/trees';
25
- import { KeystoreManager, loadKeystores, mergeKeystores } from '@aztec/node-keystore';
20
+ import { type KeyStore, KeystoreManager, loadKeystores, mergeKeystores } from '@aztec/node-keystore';
26
21
  import { trySnapshotSync, uploadSnapshot } from '@aztec/node-lib/actions';
22
+ import { createForwarderL1TxUtilsFromSigners, createL1TxUtilsFromSigners } from '@aztec/node-lib/factories';
27
23
  import {
28
- createForwarderL1TxUtilsFromEthSigner,
29
- createL1TxUtilsWithBlobsFromEthSigner,
30
- } from '@aztec/node-lib/factories';
31
- 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';
32
30
  import { ProtocolContractAddress } from '@aztec/protocol-contracts';
31
+ import { type ProverNode, type ProverNodeDeps, createProverNode } from '@aztec/prover-node';
32
+ import { createKeyStoreForProver } from '@aztec/prover-node/config';
33
33
  import { GlobalVariableBuilder, SequencerClient, type SequencerPublisher } from '@aztec/sequencer-client';
34
34
  import { PublicProcessorFactory } from '@aztec/simulator/server';
35
35
  import {
@@ -41,7 +41,14 @@ import {
41
41
  } from '@aztec/slasher';
42
42
  import { CollectionLimitsConfig, PublicSimulatorConfig } from '@aztec/stdlib/avm';
43
43
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
44
- import { type BlockParameter, type DataInBlock, L2Block, L2BlockHash, type L2BlockSource } from '@aztec/stdlib/block';
44
+ import {
45
+ type BlockData,
46
+ BlockHash,
47
+ type BlockParameter,
48
+ type DataInBlock,
49
+ L2Block,
50
+ type L2BlockSource,
51
+ } from '@aztec/stdlib/block';
45
52
  import type { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
46
53
  import type {
47
54
  ContractClassPublic,
@@ -69,9 +76,9 @@ import {
69
76
  type WorldStateSynchronizer,
70
77
  tryStop,
71
78
  } from '@aztec/stdlib/interfaces/server';
72
- 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';
73
81
  import { InboxLeaf, type L1ToL2MessageSource } from '@aztec/stdlib/messaging';
74
- import { P2PClientType } from '@aztec/stdlib/p2p';
75
82
  import type { Offense, SlashPayloadRound } from '@aztec/stdlib/slashing';
76
83
  import type { NullifierLeafPreimage, PublicDataTreeLeaf, PublicDataTreeLeafPreimage } from '@aztec/stdlib/trees';
77
84
  import { MerkleTreeId, NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
@@ -103,7 +110,6 @@ import {
103
110
  ValidatorClient,
104
111
  createBlockProposalHandler,
105
112
  createValidatorClient,
106
- createValidatorForAcceptingTxs,
107
113
  } from '@aztec/validator-client';
108
114
  import { createWorldStateSynchronizer } from '@aztec/world-state';
109
115
 
@@ -119,7 +125,7 @@ import { NodeMetrics } from './node_metrics.js';
119
125
  */
120
126
  export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
121
127
  private metrics: NodeMetrics;
122
- private initialHeaderHashPromise: Promise<L2BlockHash> | undefined = undefined;
128
+ private initialHeaderHashPromise: Promise<BlockHash> | undefined = undefined;
123
129
 
124
130
  // Prevent two snapshot operations to happen simultaneously
125
131
  private isUploadingSnapshot = false;
@@ -135,6 +141,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
135
141
  protected readonly l1ToL2MessageSource: L1ToL2MessageSource,
136
142
  protected readonly worldStateSynchronizer: WorldStateSynchronizer,
137
143
  protected readonly sequencer: SequencerClient | undefined,
144
+ protected readonly proverNode: ProverNode | undefined,
138
145
  protected readonly slasherClient: SlasherClientInterface | undefined,
139
146
  protected readonly validatorsSentinel: Sentinel | undefined,
140
147
  protected readonly epochPruneWatcher: EpochPruneWatcher | undefined,
@@ -147,12 +154,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
147
154
  private telemetry: TelemetryClient = getTelemetryClient(),
148
155
  private log = createLogger('node'),
149
156
  private blobClient?: BlobClientInterface,
157
+ private validatorClient?: ValidatorClient,
158
+ private keyStoreManager?: KeystoreManager,
159
+ private debugLogStore: DebugLogStore = new NullDebugLogStore(),
150
160
  ) {
151
161
  this.metrics = new NodeMetrics(telemetry, 'AztecNodeService');
152
162
  this.tracer = telemetry.getTracer('AztecNodeService');
153
163
 
154
164
  this.log.info(`Aztec Node version: ${this.packageVersion}`);
155
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
+ }
156
173
  }
157
174
 
158
175
  public async getWorldStateSyncStatus(): Promise<WorldStateSyncStatus> {
@@ -176,11 +193,13 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
176
193
  logger?: Logger;
177
194
  publisher?: SequencerPublisher;
178
195
  dateProvider?: DateProvider;
179
- p2pClientDeps?: P2PClientDeps<P2PClientType.Full>;
196
+ p2pClientDeps?: P2PClientDeps;
197
+ proverNodeDeps?: Partial<ProverNodeDeps>;
180
198
  } = {},
181
199
  options: {
182
200
  prefilledPublicData?: PublicDataTreeLeaf[];
183
201
  dontStartSequencer?: boolean;
202
+ dontStartProverNode?: boolean;
184
203
  } = {},
185
204
  ): Promise<AztecNodeService> {
186
205
  const config = { ...inputConfig }; // Copy the config so we dont mutate the input object
@@ -190,16 +209,29 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
190
209
  const dateProvider = deps.dateProvider ?? new DateProvider();
191
210
  const ethereumChain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
192
211
 
193
- // 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.
194
214
  let keyStoreManager: KeystoreManager | undefined;
195
215
  const keyStoreProvided = config.keyStoreDirectory !== undefined && config.keyStoreDirectory.length > 0;
196
216
  if (keyStoreProvided) {
197
217
  const keyStores = loadKeystores(config.keyStoreDirectory!);
198
218
  keyStoreManager = new KeystoreManager(mergeKeystores(keyStores));
199
219
  } else {
200
- const keyStore = createKeyStoreForValidator(config);
201
- if (keyStore) {
202
- 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
+ );
203
235
  }
204
236
  }
205
237
 
@@ -210,10 +242,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
210
242
  if (keyStoreManager === undefined) {
211
243
  throw new Error('Failed to create key store, a requirement for running a validator');
212
244
  }
213
- if (!keyStoreProvided) {
214
- log.warn(
215
- 'KEY STORE CREATED FROM ENVIRONMENT, IT IS RECOMMENDED TO USE A FILE-BASED KEY STORE IN PRODUCTION ENVIRONMENTS',
216
- );
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");
217
247
  }
218
248
  ValidatorClient.validateKeyStoreConfiguration(keyStoreManager, log);
219
249
  }
@@ -255,7 +285,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
255
285
  );
256
286
  }
257
287
 
258
- const blobClient = await createBlobClientWithFileStores(config, createLogger('node:blob-client:client'));
288
+ const blobClient = await createBlobClientWithFileStores(config, log.createChild('blob-client'));
259
289
 
260
290
  // attempt snapshot sync if possible
261
291
  await trySnapshotSync(config, log);
@@ -279,14 +309,28 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
279
309
  config.realProofs || config.debugForceTxProofVerification
280
310
  ? await BBCircuitVerifier.new(config)
281
311
  : new TestCircuitVerifier(config.proverTestVerificationDelayMs);
312
+
313
+ let debugLogStore: DebugLogStore;
282
314
  if (!config.realProofs) {
283
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();
284
323
  }
324
+
285
325
  const proofVerifier = new QueuedIVCVerifier(config, circuitVerifier);
286
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
+
287
332
  // create the tx pool and the p2p client, which will need the l2 block source
288
333
  const p2pClient = await createP2PClient(
289
- P2PClientType.Full,
290
334
  config,
291
335
  archiver,
292
336
  proofVerifier,
@@ -301,7 +345,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
301
345
  // We should really not be modifying the config object
302
346
  config.txPublicSetupAllowList = config.txPublicSetupAllowList ?? (await getDefaultAllowedSetupFunctions());
303
347
 
304
- // Create FullNodeCheckpointsBuilder for validator and non-validator block proposal handling
348
+ // We'll accumulate sentinel watchers here
349
+ const watchers: Watcher[] = [];
350
+
351
+ // Create FullNodeCheckpointsBuilder for block proposal handling and tx validation
305
352
  const validatorCheckpointsBuilder = new FullNodeCheckpointsBuilder(
306
353
  { ...config, l1GenesisTime, slotDuration: Number(slotDuration) },
307
354
  worldStateSynchronizer,
@@ -310,47 +357,48 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
310
357
  telemetry,
311
358
  );
312
359
 
313
- // We'll accumulate sentinel watchers here
314
- const watchers: Watcher[] = [];
315
-
316
- // Create validator client if required
317
- const validatorClient = await createValidatorClient(config, {
318
- checkpointsBuilder: validatorCheckpointsBuilder,
319
- worldState: worldStateSynchronizer,
320
- p2pClient,
321
- telemetry,
322
- dateProvider,
323
- epochCache,
324
- blockSource: archiver,
325
- l1ToL2MessageSource: archiver,
326
- keyStoreManager,
327
- blobClient,
328
- });
329
-
330
- // If we have a validator client, register it as a source of offenses for the slasher,
331
- // and have it register callbacks on the p2p client *before* we start it, otherwise messages
332
- // like attestations or auths will fail.
333
- if (validatorClient) {
334
- watchers.push(validatorClient);
335
- if (!options.dontStartSequencer) {
336
- await validatorClient.registerHandlers();
337
- }
338
- }
360
+ let validatorClient: ValidatorClient | undefined;
339
361
 
340
- // If there's no validator client but alwaysReexecuteBlockProposals is enabled,
341
- // create a BlockProposalHandler to reexecute block proposals for monitoring
342
- if (!validatorClient && config.alwaysReexecuteBlockProposals) {
343
- log.info('Setting up block proposal reexecution for monitoring');
344
- createBlockProposalHandler(config, {
362
+ if (!proverOnly) {
363
+ // Create validator client if required
364
+ validatorClient = await createValidatorClient(config, {
345
365
  checkpointsBuilder: validatorCheckpointsBuilder,
346
366
  worldState: worldStateSynchronizer,
367
+ p2pClient,
368
+ telemetry,
369
+ dateProvider,
347
370
  epochCache,
348
371
  blockSource: archiver,
349
372
  l1ToL2MessageSource: archiver,
350
- p2pClient,
351
- dateProvider,
352
- telemetry,
353
- }).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
+ }
354
402
  }
355
403
 
356
404
  // Start world state and wait for it to sync to the archiver.
@@ -359,29 +407,33 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
359
407
  // Start p2p. Note that it depends on world state to be running.
360
408
  await p2pClient.start();
361
409
 
362
- const validatorsSentinel = await createSentinel(epochCache, archiver, p2pClient, config);
363
- if (validatorsSentinel && config.slashInactivityPenalty > 0n) {
364
- watchers.push(validatorsSentinel);
365
- }
366
-
410
+ let validatorsSentinel: Awaited<ReturnType<typeof createSentinel>> | undefined;
367
411
  let epochPruneWatcher: EpochPruneWatcher | undefined;
368
- if (config.slashPrunePenalty > 0n || config.slashDataWithholdingPenalty > 0n) {
369
- epochPruneWatcher = new EpochPruneWatcher(
370
- archiver,
371
- archiver,
372
- epochCache,
373
- p2pClient.getTxProvider(),
374
- validatorCheckpointsBuilder,
375
- config,
376
- );
377
- watchers.push(epochPruneWatcher);
378
- }
379
-
380
- // We assume we want to slash for invalid attestations unless all max penalties are set to 0
381
412
  let attestationsBlockWatcher: AttestationsBlockWatcher | undefined;
382
- if (config.slashProposeInvalidAttestationsPenalty > 0n || config.slashAttestDescendantOfInvalidPenalty > 0n) {
383
- attestationsBlockWatcher = new AttestationsBlockWatcher(archiver, epochCache, config);
384
- 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
+ }
385
437
  }
386
438
 
387
439
  // Start p2p-related services once the archiver has completed sync
@@ -418,19 +470,19 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
418
470
  );
419
471
  await slasherClient.start();
420
472
 
421
- const l1TxUtils = config.publisherForwarderAddress
422
- ? await createForwarderL1TxUtilsFromEthSigner(
473
+ const l1TxUtils = config.sequencerPublisherForwarderAddress
474
+ ? await createForwarderL1TxUtilsFromSigners(
423
475
  publicClient,
424
476
  keyStoreManager!.createAllValidatorPublisherSigners(),
425
- config.publisherForwarderAddress,
477
+ config.sequencerPublisherForwarderAddress,
426
478
  { ...config, scope: 'sequencer' },
427
- { telemetry, logger: log.createChild('l1-tx-utils'), dateProvider },
479
+ { telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
428
480
  )
429
- : await createL1TxUtilsWithBlobsFromEthSigner(
481
+ : await createL1TxUtilsFromSigners(
430
482
  publicClient,
431
483
  keyStoreManager!.createAllValidatorPublisherSigners(),
432
484
  { ...config, scope: 'sequencer' },
433
- { telemetry, logger: log.createChild('l1-tx-utils'), dateProvider },
485
+ { telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
434
486
  );
435
487
 
436
488
  // Create and start the sequencer client
@@ -440,6 +492,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
440
492
  archiver,
441
493
  dateProvider,
442
494
  telemetry,
495
+ debugLogStore,
443
496
  );
444
497
 
445
498
  sequencer = await SequencerClient.new(config, {
@@ -467,6 +520,29 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
467
520
  log.warn(`Sequencer created but not started`);
468
521
  }
469
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
+
470
546
  const globalVariableBuilder = new GlobalVariableBuilder({
471
547
  ...config,
472
548
  rollupVersion: BigInt(config.rollupVersion),
@@ -474,7 +550,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
474
550
  slotDuration: Number(slotDuration),
475
551
  });
476
552
 
477
- return new AztecNodeService(
553
+ const node = new AztecNodeService(
478
554
  config,
479
555
  p2pClient,
480
556
  archiver,
@@ -483,6 +559,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
483
559
  archiver,
484
560
  worldStateSynchronizer,
485
561
  sequencer,
562
+ proverNode,
486
563
  slasherClient,
487
564
  validatorsSentinel,
488
565
  epochPruneWatcher,
@@ -495,7 +572,12 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
495
572
  telemetry,
496
573
  log,
497
574
  blobClient,
575
+ validatorClient,
576
+ keyStoreManager,
577
+ debugLogStore,
498
578
  );
579
+
580
+ return node;
499
581
  }
500
582
 
501
583
  /**
@@ -506,6 +588,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
506
588
  return this.sequencer;
507
589
  }
508
590
 
591
+ /** Returns the prover node subsystem, if enabled. */
592
+ public getProverNode(): ProverNode | undefined {
593
+ return this.proverNode;
594
+ }
595
+
509
596
  public getBlockSource(): L2BlockSource {
510
597
  return this.blockSource;
511
598
  }
@@ -559,6 +646,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
559
646
  enr,
560
647
  l1ContractAddresses: contractAddresses,
561
648
  protocolContractAddresses: protocolContractAddresses,
649
+ realProofs: !!this.config.realProofs,
562
650
  };
563
651
 
564
652
  return nodeInfo;
@@ -570,8 +658,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
570
658
  * @returns The requested block.
571
659
  */
572
660
  public async getBlock(block: BlockParameter): Promise<L2Block | undefined> {
573
- if (L2BlockHash.isL2BlockHash(block)) {
574
- return this.getBlockByHash(Fr.fromBuffer(block.toBuffer()));
661
+ if (BlockHash.isBlockHash(block)) {
662
+ return this.getBlockByHash(block);
575
663
  }
576
664
  const blockNumber = block === 'latest' ? await this.getBlockNumber() : (block as BlockNumber);
577
665
  if (blockNumber === BlockNumber.ZERO) {
@@ -585,9 +673,9 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
585
673
  * @param blockHash - The block hash being requested.
586
674
  * @returns The requested block.
587
675
  */
588
- public async getBlockByHash(blockHash: Fr): Promise<L2Block | undefined> {
676
+ public async getBlockByHash(blockHash: BlockHash): Promise<L2Block | undefined> {
589
677
  const initialBlockHash = await this.#getInitialHeaderHash();
590
- if (blockHash.equals(Fr.fromBuffer(initialBlockHash.toBuffer()))) {
678
+ if (blockHash.equals(initialBlockHash)) {
591
679
  return this.buildInitialBlock();
592
680
  }
593
681
  return await this.blockSource.getL2BlockByHash(blockHash);
@@ -692,13 +780,12 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
692
780
  public async getPrivateLogsByTags(
693
781
  tags: SiloedTag[],
694
782
  page?: number,
695
- referenceBlock?: L2BlockHash,
783
+ referenceBlock?: BlockHash,
696
784
  ): Promise<TxScopedL2Log[][]> {
697
785
  if (referenceBlock) {
698
786
  const initialBlockHash = await this.#getInitialHeaderHash();
699
787
  if (!referenceBlock.equals(initialBlockHash)) {
700
- const blockHashFr = Fr.fromBuffer(referenceBlock.toBuffer());
701
- const header = await this.blockSource.getBlockHeaderByHash(blockHashFr);
788
+ const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
702
789
  if (!header) {
703
790
  throw new Error(
704
791
  `Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
@@ -713,13 +800,12 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
713
800
  contractAddress: AztecAddress,
714
801
  tags: Tag[],
715
802
  page?: number,
716
- referenceBlock?: L2BlockHash,
803
+ referenceBlock?: BlockHash,
717
804
  ): Promise<TxScopedL2Log[][]> {
718
805
  if (referenceBlock) {
719
806
  const initialBlockHash = await this.#getInitialHeaderHash();
720
807
  if (!referenceBlock.equals(initialBlockHash)) {
721
- const blockHashFr = Fr.fromBuffer(referenceBlock.toBuffer());
722
- const header = await this.blockSource.getBlockHeaderByHash(blockHashFr);
808
+ const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
723
809
  if (!header) {
724
810
  throw new Error(
725
811
  `Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
@@ -769,8 +855,9 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
769
855
  }
770
856
 
771
857
  await this.p2pClient!.sendTx(tx);
772
- this.metrics.receivedTx(timer.ms(), true);
773
- 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 });
774
861
  }
775
862
 
776
863
  public async getTxReceipt(txHash: TxHash): Promise<TxReceipt> {
@@ -782,18 +869,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
782
869
  // Then get the actual tx from the archiver, which tracks every tx in a mined block.
783
870
  const settledTxReceipt = await this.blockSource.getSettledTxReceipt(txHash);
784
871
 
872
+ let receipt: TxReceipt;
785
873
  if (settledTxReceipt) {
786
- // If the archiver has the receipt then return it.
787
- return settledTxReceipt;
874
+ receipt = settledTxReceipt;
788
875
  } else if (isKnownToPool) {
789
876
  // If the tx is in the pool but not in the archiver, it's pending.
790
877
  // This handles race conditions between archiver and p2p, where the archiver
791
878
  // has pruned the block in which a tx was mined, but p2p has not caught up yet.
792
- return new TxReceipt(txHash, TxStatus.PENDING, undefined, undefined);
879
+ receipt = new TxReceipt(txHash, TxStatus.PENDING, undefined, undefined);
793
880
  } else {
794
881
  // Otherwise, if we don't know the tx, we consider it dropped.
795
- return new TxReceipt(txHash, TxStatus.DROPPED, undefined, 'Tx dropped by P2P node');
882
+ receipt = new TxReceipt(txHash, TxStatus.DROPPED, undefined, 'Tx dropped by P2P node');
796
883
  }
884
+
885
+ this.debugLogStore.decorateReceiptWithLogs(txHash.toString(), receipt);
886
+
887
+ return receipt;
797
888
  }
798
889
 
799
890
  public getTxEffect(txHash: TxHash): Promise<IndexedTxEffect | undefined> {
@@ -810,6 +901,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
810
901
  await tryStop(this.slasherClient);
811
902
  await tryStop(this.proofVerifier);
812
903
  await tryStop(this.sequencer);
904
+ await tryStop(this.proverNode);
813
905
  await tryStop(this.p2pClient);
814
906
  await tryStop(this.worldStateSynchronizer);
815
907
  await tryStop(this.blockSource);
@@ -859,11 +951,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
859
951
  }
860
952
 
861
953
  public async findLeavesIndexes(
862
- block: BlockParameter,
954
+ referenceBlock: BlockParameter,
863
955
  treeId: MerkleTreeId,
864
956
  leafValues: Fr[],
865
957
  ): Promise<(DataInBlock<bigint> | undefined)[]> {
866
- const committedDb = await this.#getWorldState(block);
958
+ const committedDb = await this.#getWorldState(referenceBlock);
867
959
  const maybeIndices = await committedDb.findLeafIndices(
868
960
  treeId,
869
961
  leafValues.map(x => x.toBuffer()),
@@ -915,44 +1007,28 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
915
1007
  }
916
1008
  return {
917
1009
  l2BlockNumber: BlockNumber(Number(blockNumber)),
918
- l2BlockHash: L2BlockHash.fromField(blockHash),
1010
+ l2BlockHash: new BlockHash(blockHash),
919
1011
  data: index,
920
1012
  };
921
1013
  });
922
1014
  }
923
1015
 
924
- public async getNullifierSiblingPath(
925
- block: BlockParameter,
926
- leafIndex: bigint,
927
- ): Promise<SiblingPath<typeof NULLIFIER_TREE_HEIGHT>> {
928
- const committedDb = await this.#getWorldState(block);
929
- return committedDb.getSiblingPath(MerkleTreeId.NULLIFIER_TREE, leafIndex);
930
- }
931
-
932
- public async getNoteHashSiblingPath(
933
- block: BlockParameter,
934
- leafIndex: bigint,
935
- ): Promise<SiblingPath<typeof NOTE_HASH_TREE_HEIGHT>> {
936
- const committedDb = await this.#getWorldState(block);
937
- return committedDb.getSiblingPath(MerkleTreeId.NOTE_HASH_TREE, leafIndex);
938
- }
939
-
940
- public async getArchiveMembershipWitness(
941
- block: BlockParameter,
942
- archive: Fr,
1016
+ public async getBlockHashMembershipWitness(
1017
+ referenceBlock: BlockParameter,
1018
+ blockHash: BlockHash,
943
1019
  ): Promise<MembershipWitness<typeof ARCHIVE_HEIGHT> | undefined> {
944
- const committedDb = await this.#getWorldState(block);
945
- 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]);
946
1022
  return pathAndIndex === undefined
947
1023
  ? undefined
948
1024
  : MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
949
1025
  }
950
1026
 
951
1027
  public async getNoteHashMembershipWitness(
952
- block: BlockParameter,
1028
+ referenceBlock: BlockParameter,
953
1029
  noteHash: Fr,
954
1030
  ): Promise<MembershipWitness<typeof NOTE_HASH_TREE_HEIGHT> | undefined> {
955
- const committedDb = await this.#getWorldState(block);
1031
+ const committedDb = await this.#getWorldState(referenceBlock);
956
1032
  const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.NOTE_HASH_TREE>(
957
1033
  MerkleTreeId.NOTE_HASH_TREE,
958
1034
  [noteHash],
@@ -963,10 +1039,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
963
1039
  }
964
1040
 
965
1041
  public async getL1ToL2MessageMembershipWitness(
966
- block: BlockParameter,
1042
+ referenceBlock: BlockParameter,
967
1043
  l1ToL2Message: Fr,
968
1044
  ): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>] | undefined> {
969
- const db = await this.#getWorldState(block);
1045
+ const db = await this.#getWorldState(referenceBlock);
970
1046
  const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [l1ToL2Message]);
971
1047
  if (!witness) {
972
1048
  return undefined;
@@ -1019,27 +1095,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1019
1095
  );
1020
1096
  }
1021
1097
 
1022
- public async getArchiveSiblingPath(
1023
- block: BlockParameter,
1024
- leafIndex: bigint,
1025
- ): Promise<SiblingPath<typeof ARCHIVE_HEIGHT>> {
1026
- const committedDb = await this.#getWorldState(block);
1027
- return committedDb.getSiblingPath(MerkleTreeId.ARCHIVE, leafIndex);
1028
- }
1029
-
1030
- public async getPublicDataSiblingPath(
1031
- block: BlockParameter,
1032
- leafIndex: bigint,
1033
- ): Promise<SiblingPath<typeof PUBLIC_DATA_TREE_HEIGHT>> {
1034
- const committedDb = await this.#getWorldState(block);
1035
- return committedDb.getSiblingPath(MerkleTreeId.PUBLIC_DATA_TREE, leafIndex);
1036
- }
1037
-
1038
1098
  public async getNullifierMembershipWitness(
1039
- block: BlockParameter,
1099
+ referenceBlock: BlockParameter,
1040
1100
  nullifier: Fr,
1041
1101
  ): Promise<NullifierMembershipWitness | undefined> {
1042
- const db = await this.#getWorldState(block);
1102
+ const db = await this.#getWorldState(referenceBlock);
1043
1103
  const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [nullifier.toBuffer()]);
1044
1104
  if (!witness) {
1045
1105
  return undefined;
@@ -1056,7 +1116,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1056
1116
 
1057
1117
  /**
1058
1118
  * Returns a low nullifier membership witness for a given nullifier at a given block.
1059
- * @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
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).
1060
1121
  * @param nullifier - Nullifier we try to find the low nullifier witness for.
1061
1122
  * @returns The low nullifier membership witness (if found).
1062
1123
  * @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
@@ -1069,10 +1130,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1069
1130
  * TODO: This is a confusing behavior and we should eventually address that.
1070
1131
  */
1071
1132
  public async getLowNullifierMembershipWitness(
1072
- block: BlockParameter,
1133
+ referenceBlock: BlockParameter,
1073
1134
  nullifier: Fr,
1074
1135
  ): Promise<NullifierMembershipWitness | undefined> {
1075
- const committedDb = await this.#getWorldState(block);
1136
+ const committedDb = await this.#getWorldState(referenceBlock);
1076
1137
  const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
1077
1138
  if (!findResult) {
1078
1139
  return undefined;
@@ -1087,8 +1148,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1087
1148
  return new NullifierMembershipWitness(BigInt(index), preimageData as NullifierLeafPreimage, siblingPath);
1088
1149
  }
1089
1150
 
1090
- async getPublicDataWitness(block: BlockParameter, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
1091
- const committedDb = await this.#getWorldState(block);
1151
+ async getPublicDataWitness(referenceBlock: BlockParameter, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
1152
+ const committedDb = await this.#getWorldState(referenceBlock);
1092
1153
  const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
1093
1154
  if (!lowLeafResult) {
1094
1155
  return undefined;
@@ -1102,8 +1163,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1102
1163
  }
1103
1164
  }
1104
1165
 
1105
- public async getPublicStorageAt(block: BlockParameter, contract: AztecAddress, slot: Fr): Promise<Fr> {
1106
- const committedDb = await this.#getWorldState(block);
1166
+ public async getPublicStorageAt(referenceBlock: BlockParameter, contract: AztecAddress, slot: Fr): Promise<Fr> {
1167
+ const committedDb = await this.#getWorldState(referenceBlock);
1107
1168
  const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
1108
1169
 
1109
1170
  const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
@@ -1118,14 +1179,13 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1118
1179
  }
1119
1180
 
1120
1181
  public async getBlockHeader(block: BlockParameter = 'latest'): Promise<BlockHeader | undefined> {
1121
- if (L2BlockHash.isL2BlockHash(block)) {
1182
+ if (BlockHash.isBlockHash(block)) {
1122
1183
  const initialBlockHash = await this.#getInitialHeaderHash();
1123
1184
  if (block.equals(initialBlockHash)) {
1124
1185
  // Block source doesn't handle initial header so we need to handle the case separately.
1125
1186
  return this.worldStateSynchronizer.getCommitted().getInitialHeader();
1126
1187
  }
1127
- const blockHashFr = Fr.fromBuffer(block.toBuffer());
1128
- return this.blockSource.getBlockHeaderByHash(blockHashFr);
1188
+ return this.blockSource.getBlockHeaderByHash(block);
1129
1189
  } else {
1130
1190
  // Block source doesn't handle initial header so we need to handle the case separately.
1131
1191
  const blockNumber = block === 'latest' ? await this.getBlockNumber() : (block as BlockNumber);
@@ -1145,6 +1205,14 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1145
1205
  return await this.blockSource.getBlockHeaderByArchive(archive);
1146
1206
  }
1147
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
+
1148
1216
  /**
1149
1217
  * Simulates the public part of a transaction with the current state.
1150
1218
  * @param tx - The transaction to simulate.
@@ -1168,7 +1236,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1168
1236
  }
1169
1237
 
1170
1238
  const txHash = tx.getTxHash();
1171
- const blockNumber = BlockNumber((await this.blockSource.getBlockNumber()) + 1);
1239
+ const latestBlockNumber = await this.blockSource.getBlockNumber();
1240
+ const blockNumber = BlockNumber.add(latestBlockNumber, 1);
1172
1241
 
1173
1242
  // If sequencer is not initialized, we just set these values to zero for simulation.
1174
1243
  const coinbase = EthAddress.ZERO;
@@ -1183,6 +1252,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1183
1252
  this.contractDataSource,
1184
1253
  new DateProvider(),
1185
1254
  this.telemetry,
1255
+ this.log.getBindings(),
1186
1256
  );
1187
1257
 
1188
1258
  this.log.verbose(`Simulating public calls for tx ${txHash}`, {
@@ -1191,6 +1261,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1191
1261
  blockNumber,
1192
1262
  });
1193
1263
 
1264
+ // Ensure world-state has caught up with the latest block we loaded from the archiver
1265
+ await this.worldStateSynchronizer.syncImmediate(latestBlockNumber);
1194
1266
  const merkleTreeFork = await this.worldStateSynchronizer.fork();
1195
1267
  try {
1196
1268
  const config = PublicSimulatorConfig.from({
@@ -1206,7 +1278,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1206
1278
  const processor = publicProcessorFactory.create(merkleTreeFork, newGlobalVariables, config);
1207
1279
 
1208
1280
  // REFACTOR: Consider merging ProcessReturnValues into ProcessedTx
1209
- const [processedTxs, failedTxs, _usedTxs, returns] = await processor.process([tx]);
1281
+ const [processedTxs, failedTxs, _usedTxs, returns, _blobFields, debugLogs] = await processor.process([tx]);
1210
1282
  // REFACTOR: Consider returning the error rather than throwing
1211
1283
  if (failedTxs.length) {
1212
1284
  this.log.warn(`Simulated tx ${txHash} fails: ${failedTxs[0].error}`, { txHash });
@@ -1220,6 +1292,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1220
1292
  processedTx.txEffect,
1221
1293
  returns,
1222
1294
  processedTx.gasUsed,
1295
+ debugLogs,
1223
1296
  );
1224
1297
  } finally {
1225
1298
  await merkleTreeFork.close();
@@ -1233,19 +1306,25 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1233
1306
  const db = this.worldStateSynchronizer.getCommitted();
1234
1307
  const verifier = isSimulation ? undefined : this.proofVerifier;
1235
1308
 
1236
- // 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)
1237
1310
  const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
1238
1311
  const blockNumber = BlockNumber((await this.blockSource.getBlockNumber()) + 1);
1239
- const validator = createValidatorForAcceptingTxs(db, this.contractDataSource, verifier, {
1240
- timestamp: nextSlotTimestamp,
1241
- blockNumber,
1242
- l1ChainId: this.l1ChainId,
1243
- rollupVersion: this.version,
1244
- setupAllowList: this.config.txPublicSetupAllowList ?? (await getDefaultAllowedSetupFunctions()),
1245
- gasFees: await this.getCurrentMinFees(),
1246
- skipFeeEnforcement,
1247
- txsPermitted: !this.config.disableTransactions,
1248
- });
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
+ );
1249
1328
 
1250
1329
  return await validator.validateTx(tx);
1251
1330
  }
@@ -1409,7 +1488,95 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1409
1488
  }
1410
1489
  }
1411
1490
 
1412
- #getInitialHeaderHash(): Promise<L2BlockHash> {
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> {
1413
1580
  if (!this.initialHeaderHashPromise) {
1414
1581
  this.initialHeaderHashPromise = this.worldStateSynchronizer.getCommitted().getInitialHeader().hash();
1415
1582
  }
@@ -1435,15 +1602,14 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1435
1602
  return this.worldStateSynchronizer.getCommitted();
1436
1603
  }
1437
1604
 
1438
- if (L2BlockHash.isL2BlockHash(block)) {
1605
+ if (BlockHash.isBlockHash(block)) {
1439
1606
  const initialBlockHash = await this.#getInitialHeaderHash();
1440
1607
  if (block.equals(initialBlockHash)) {
1441
1608
  // Block source doesn't handle initial header so we need to handle the case separately.
1442
1609
  return this.worldStateSynchronizer.getSnapshot(BlockNumber.ZERO);
1443
1610
  }
1444
1611
 
1445
- const blockHashFr = Fr.fromBuffer(block.toBuffer());
1446
- const header = await this.blockSource.getBlockHeaderByHash(blockHashFr);
1612
+ const header = await this.blockSource.getBlockHeaderByHash(block);
1447
1613
  if (!header) {
1448
1614
  throw new Error(
1449
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.`,