@aztec/aztec-node 0.0.1-commit.e6bd8901 → 0.0.1-commit.ec7ac5448

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,35 +1,38 @@
1
1
  import { Archiver, createArchiver } from '@aztec/archiver';
2
- import { BBCircuitVerifier, QueuedIVCVerifier, TestCircuitVerifier } from '@aztec/bb-prover';
2
+ import { BBCircuitVerifier, BatchChonkVerifier, QueuedIVCVerifier } from '@aztec/bb-prover';
3
+ import { TestCircuitVerifier } from '@aztec/bb-prover/test';
3
4
  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';
5
+ import { Blob } from '@aztec/blob-lib';
6
+ import { ARCHIVE_HEIGHT, type L1_TO_L2_MSG_TREE_HEIGHT, type NOTE_HASH_TREE_HEIGHT } from '@aztec/constants';
11
7
  import { EpochCache, type EpochCacheInterface } from '@aztec/epoch-cache';
12
8
  import { createEthereumChain } from '@aztec/ethereum/chain';
13
- import { getPublicClient } from '@aztec/ethereum/client';
9
+ import { getPublicClient, makeL1HttpTransport } from '@aztec/ethereum/client';
14
10
  import { RegistryContract, RollupContract } from '@aztec/ethereum/contracts';
15
11
  import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
12
+ import type { L1TxUtils } from '@aztec/ethereum/l1-tx-utils';
16
13
  import { BlockNumber, CheckpointNumber, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
17
- import { compactArray, pick } from '@aztec/foundation/collection';
14
+ import { chunkBy, compactArray, pick, unique } from '@aztec/foundation/collection';
18
15
  import { Fr } from '@aztec/foundation/curves/bn254';
19
16
  import { EthAddress } from '@aztec/foundation/eth-address';
20
17
  import { BadRequestError } from '@aztec/foundation/json-rpc';
21
18
  import { type Logger, createLogger } from '@aztec/foundation/log';
19
+ import { retryUntil } from '@aztec/foundation/retry';
22
20
  import { count } from '@aztec/foundation/string';
23
21
  import { DateProvider, Timer } from '@aztec/foundation/timer';
24
22
  import { MembershipWitness, SiblingPath } from '@aztec/foundation/trees';
25
- import { KeystoreManager, loadKeystores, mergeKeystores } from '@aztec/node-keystore';
23
+ import { type KeyStore, KeystoreManager, loadKeystores, mergeKeystores } from '@aztec/node-keystore';
26
24
  import { trySnapshotSync, uploadSnapshot } from '@aztec/node-lib/actions';
25
+ import { createForwarderL1TxUtilsFromSigners, createL1TxUtilsFromSigners } from '@aztec/node-lib/factories';
27
26
  import {
28
- createForwarderL1TxUtilsFromEthSigner,
29
- createL1TxUtilsWithBlobsFromEthSigner,
30
- } from '@aztec/node-lib/factories';
31
- import { type P2P, type P2PClientDeps, createP2PClient, getDefaultAllowedSetupFunctions } from '@aztec/p2p';
27
+ type P2P,
28
+ type P2PClientDeps,
29
+ createP2PClient,
30
+ createTxValidatorForAcceptingTxsOverRPC,
31
+ getDefaultAllowedSetupFunctions,
32
+ } from '@aztec/p2p';
32
33
  import { ProtocolContractAddress } from '@aztec/protocol-contracts';
34
+ import { type ProverNode, type ProverNodeDeps, createProverNode } from '@aztec/prover-node';
35
+ import { createKeyStoreForProver } from '@aztec/prover-node/config';
33
36
  import { GlobalVariableBuilder, SequencerClient, type SequencerPublisher } from '@aztec/sequencer-client';
34
37
  import { PublicProcessorFactory } from '@aztec/simulator/server';
35
38
  import {
@@ -41,7 +44,14 @@ import {
41
44
  } from '@aztec/slasher';
42
45
  import { CollectionLimitsConfig, PublicSimulatorConfig } from '@aztec/stdlib/avm';
43
46
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
44
- import { type BlockParameter, type DataInBlock, L2Block, L2BlockHash, type L2BlockSource } from '@aztec/stdlib/block';
47
+ import {
48
+ type BlockData,
49
+ BlockHash,
50
+ type BlockParameter,
51
+ type DataInBlock,
52
+ L2Block,
53
+ type L2BlockSource,
54
+ } from '@aztec/stdlib/block';
45
55
  import type { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
46
56
  import type {
47
57
  ContractClassPublic,
@@ -57,6 +67,7 @@ import {
57
67
  type AztecNodeAdmin,
58
68
  type AztecNodeAdminConfig,
59
69
  AztecNodeAdminConfigSchema,
70
+ type AztecNodeDebug,
60
71
  type GetContractClassLogsResponse,
61
72
  type GetPublicLogsResponse,
62
73
  } from '@aztec/stdlib/interfaces/client';
@@ -69,11 +80,11 @@ import {
69
80
  type WorldStateSynchronizer,
70
81
  tryStop,
71
82
  } from '@aztec/stdlib/interfaces/server';
72
- import type { LogFilter, SiloedTag, Tag, TxScopedL2Log } from '@aztec/stdlib/logs';
83
+ import type { DebugLogStore, LogFilter, SiloedTag, Tag, TxScopedL2Log } from '@aztec/stdlib/logs';
84
+ import { InMemoryDebugLogStore, NullDebugLogStore } from '@aztec/stdlib/logs';
73
85
  import { InboxLeaf, type L1ToL2MessageSource } from '@aztec/stdlib/messaging';
74
- import { P2PClientType } from '@aztec/stdlib/p2p';
75
- import type { Offense, SlashPayloadRound } from '@aztec/stdlib/slashing';
76
- import type { NullifierLeafPreimage, PublicDataTreeLeaf, PublicDataTreeLeafPreimage } from '@aztec/stdlib/trees';
86
+ import type { Offense } from '@aztec/stdlib/slashing';
87
+ import type { NullifierLeafPreimage, PublicDataTreeLeafPreimage } from '@aztec/stdlib/trees';
77
88
  import { MerkleTreeId, NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
78
89
  import {
79
90
  type BlockHeader,
@@ -88,6 +99,7 @@ import {
88
99
  } from '@aztec/stdlib/tx';
89
100
  import { getPackageVersion } from '@aztec/stdlib/update-checker';
90
101
  import type { SingleValidatorStats, ValidatorsStats } from '@aztec/stdlib/validators';
102
+ import type { GenesisData } from '@aztec/stdlib/world-state';
91
103
  import {
92
104
  Attributes,
93
105
  type TelemetryClient,
@@ -101,13 +113,13 @@ import {
101
113
  FullNodeCheckpointsBuilder,
102
114
  NodeKeystoreAdapter,
103
115
  ValidatorClient,
104
- createBlockProposalHandler,
116
+ createProposalHandler,
105
117
  createValidatorClient,
106
- createValidatorForAcceptingTxs,
107
118
  } from '@aztec/validator-client';
119
+ import type { SlashingProtectionDatabase } from '@aztec/validator-ha-signer/types';
108
120
  import { createWorldStateSynchronizer } from '@aztec/world-state';
109
121
 
110
- import { createPublicClient, fallback, http } from 'viem';
122
+ import { createPublicClient } from 'viem';
111
123
 
112
124
  import { createSentinel } from '../sentinel/factory.js';
113
125
  import { Sentinel } from '../sentinel/sentinel.js';
@@ -117,9 +129,9 @@ import { NodeMetrics } from './node_metrics.js';
117
129
  /**
118
130
  * The aztec node.
119
131
  */
120
- export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
132
+ export class AztecNodeService implements AztecNode, AztecNodeAdmin, AztecNodeDebug, Traceable {
121
133
  private metrics: NodeMetrics;
122
- private initialHeaderHashPromise: Promise<L2BlockHash> | undefined = undefined;
134
+ private initialHeaderHashPromise: Promise<BlockHash> | undefined = undefined;
123
135
 
124
136
  // Prevent two snapshot operations to happen simultaneously
125
137
  private isUploadingSnapshot = false;
@@ -135,6 +147,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
135
147
  protected readonly l1ToL2MessageSource: L1ToL2MessageSource,
136
148
  protected readonly worldStateSynchronizer: WorldStateSynchronizer,
137
149
  protected readonly sequencer: SequencerClient | undefined,
150
+ protected readonly proverNode: ProverNode | undefined,
138
151
  protected readonly slasherClient: SlasherClientInterface | undefined,
139
152
  protected readonly validatorsSentinel: Sentinel | undefined,
140
153
  protected readonly epochPruneWatcher: EpochPruneWatcher | undefined,
@@ -143,16 +156,32 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
143
156
  protected readonly globalVariableBuilder: GlobalVariableBuilderInterface,
144
157
  protected readonly epochCache: EpochCacheInterface,
145
158
  protected readonly packageVersion: string,
146
- private proofVerifier: ClientProtocolCircuitVerifier,
159
+ private peerProofVerifier: ClientProtocolCircuitVerifier,
160
+ private rpcProofVerifier: ClientProtocolCircuitVerifier,
147
161
  private telemetry: TelemetryClient = getTelemetryClient(),
148
162
  private log = createLogger('node'),
149
163
  private blobClient?: BlobClientInterface,
164
+ private validatorClient?: ValidatorClient,
165
+ private keyStoreManager?: KeystoreManager,
166
+ private debugLogStore: DebugLogStore = new NullDebugLogStore(),
150
167
  ) {
151
168
  this.metrics = new NodeMetrics(telemetry, 'AztecNodeService');
152
169
  this.tracer = telemetry.getTracer('AztecNodeService');
153
170
 
154
171
  this.log.info(`Aztec Node version: ${this.packageVersion}`);
155
172
  this.log.info(`Aztec Node started on chain 0x${l1ChainId.toString(16)}`, config.l1Contracts);
173
+
174
+ // A defensive check that protects us against introducing a bug in the complex `createAndSync` function. We must
175
+ // never have debugLogStore enabled when not in test mode because then we would be accumulating debug logs in
176
+ // memory which could be a DoS vector on the sequencer (since no fees are paid for debug logs).
177
+ if (debugLogStore.isEnabled && config.realProofs) {
178
+ throw new Error('debugLogStore should never be enabled when realProofs are set');
179
+ }
180
+ }
181
+
182
+ /** @internal Exposed for testing — returns the RPC proof verifier. */
183
+ public getProofVerifier(): ClientProtocolCircuitVerifier {
184
+ return this.rpcProofVerifier;
156
185
  }
157
186
 
158
187
  public async getWorldStateSyncStatus(): Promise<WorldStateSyncStatus> {
@@ -176,11 +205,14 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
176
205
  logger?: Logger;
177
206
  publisher?: SequencerPublisher;
178
207
  dateProvider?: DateProvider;
179
- p2pClientDeps?: P2PClientDeps<P2PClientType.Full>;
208
+ p2pClientDeps?: P2PClientDeps;
209
+ proverNodeDeps?: Partial<ProverNodeDeps>;
210
+ slashingProtectionDb?: SlashingProtectionDatabase;
180
211
  } = {},
181
212
  options: {
182
- prefilledPublicData?: PublicDataTreeLeaf[];
213
+ genesis?: GenesisData;
183
214
  dontStartSequencer?: boolean;
215
+ dontStartProverNode?: boolean;
184
216
  } = {},
185
217
  ): Promise<AztecNodeService> {
186
218
  const config = { ...inputConfig }; // Copy the config so we dont mutate the input object
@@ -190,16 +222,29 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
190
222
  const dateProvider = deps.dateProvider ?? new DateProvider();
191
223
  const ethereumChain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
192
224
 
193
- // Build a key store from file if given or from environment otherwise
225
+ // Build a key store from file if given or from environment otherwise.
226
+ // We keep the raw KeyStore available so we can merge with prover keys if enableProverNode is set.
194
227
  let keyStoreManager: KeystoreManager | undefined;
195
228
  const keyStoreProvided = config.keyStoreDirectory !== undefined && config.keyStoreDirectory.length > 0;
196
229
  if (keyStoreProvided) {
197
230
  const keyStores = loadKeystores(config.keyStoreDirectory!);
198
231
  keyStoreManager = new KeystoreManager(mergeKeystores(keyStores));
199
232
  } else {
200
- const keyStore = createKeyStoreForValidator(config);
201
- if (keyStore) {
202
- keyStoreManager = new KeystoreManager(keyStore);
233
+ const rawKeyStores: KeyStore[] = [];
234
+ const validatorKeyStore = createKeyStoreForValidator(config);
235
+ if (validatorKeyStore) {
236
+ rawKeyStores.push(validatorKeyStore);
237
+ }
238
+ if (config.enableProverNode) {
239
+ const proverKeyStore = createKeyStoreForProver(config);
240
+ if (proverKeyStore) {
241
+ rawKeyStores.push(proverKeyStore);
242
+ }
243
+ }
244
+ if (rawKeyStores.length > 0) {
245
+ keyStoreManager = new KeystoreManager(
246
+ rawKeyStores.length === 1 ? rawKeyStores[0] : mergeKeystores(rawKeyStores),
247
+ );
203
248
  }
204
249
  }
205
250
 
@@ -210,10 +255,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
210
255
  if (keyStoreManager === undefined) {
211
256
  throw new Error('Failed to create key store, a requirement for running a validator');
212
257
  }
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
- );
258
+ if (!keyStoreProvided && process.env.NODE_ENV !== 'test') {
259
+ log.warn("Keystore created from env: it's recommended to use a file-based key store for production");
217
260
  }
218
261
  ValidatorClient.validateKeyStoreConfiguration(keyStoreManager, log);
219
262
  }
@@ -227,7 +270,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
227
270
 
228
271
  const publicClient = createPublicClient({
229
272
  chain: ethereumChain.chainInfo,
230
- transport: fallback(config.l1RpcUrls.map((url: string) => http(url, { batch: false }))),
273
+ transport: makeL1HttpTransport(config.l1RpcUrls, { timeout: config.l1HttpTimeoutMS }),
231
274
  pollingInterval: config.viemPollingIntervalMS,
232
275
  });
233
276
 
@@ -241,10 +284,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
241
284
  config.l1Contracts = { ...config.l1Contracts, ...l1ContractsAddresses };
242
285
 
243
286
  const rollupContract = new RollupContract(publicClient, config.l1Contracts.rollupAddress.toString());
244
- const [l1GenesisTime, slotDuration, rollupVersionFromRollup] = await Promise.all([
287
+ const [l1GenesisTime, slotDuration, rollupVersionFromRollup, rollupManaLimit] = await Promise.all([
245
288
  rollupContract.getL1GenesisTime(),
246
289
  rollupContract.getSlotDuration(),
247
290
  rollupContract.getVersion(),
291
+ rollupContract.getManaLimit().then(Number),
248
292
  ] as const);
249
293
 
250
294
  config.rollupVersion ??= Number(rollupVersionFromRollup);
@@ -255,7 +299,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
255
299
  );
256
300
  }
257
301
 
258
- const blobClient = await createBlobClientWithFileStores(config, createLogger('node:blob-client:client'));
302
+ const blobClient = await createBlobClientWithFileStores(config, log.createChild('blob-client'));
259
303
 
260
304
  // attempt snapshot sync if possible
261
305
  await trySnapshotSync(config, log);
@@ -269,27 +313,41 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
269
313
  );
270
314
 
271
315
  // now create the merkle trees and the world state synchronizer
272
- const worldStateSynchronizer = await createWorldStateSynchronizer(
273
- config,
274
- archiver,
275
- options.prefilledPublicData,
276
- telemetry,
277
- );
278
- const circuitVerifier =
279
- config.realProofs || config.debugForceTxProofVerification
280
- ? await BBCircuitVerifier.new(config)
281
- : new TestCircuitVerifier(config.proverTestVerificationDelayMs);
316
+ const worldStateSynchronizer = await createWorldStateSynchronizer(config, archiver, options.genesis, telemetry);
317
+ const useRealVerifiers = config.realProofs || config.debugForceTxProofVerification;
318
+ let peerProofVerifier: ClientProtocolCircuitVerifier;
319
+ let rpcProofVerifier: ClientProtocolCircuitVerifier;
320
+ if (useRealVerifiers) {
321
+ peerProofVerifier = await BatchChonkVerifier.new(config, config.bbChonkVerifyMaxBatch, 'peer');
322
+ const rpcVerifier = await BBCircuitVerifier.new(config);
323
+ rpcProofVerifier = new QueuedIVCVerifier(rpcVerifier, config.numConcurrentIVCVerifiers);
324
+ } else {
325
+ peerProofVerifier = new TestCircuitVerifier(config.proverTestVerificationDelayMs);
326
+ rpcProofVerifier = new TestCircuitVerifier(config.proverTestVerificationDelayMs);
327
+ }
328
+
329
+ let debugLogStore: DebugLogStore;
282
330
  if (!config.realProofs) {
283
331
  log.warn(`Aztec node is accepting fake proofs`);
332
+
333
+ debugLogStore = new InMemoryDebugLogStore();
334
+ log.info(
335
+ 'Aztec node started in test mode (realProofs set to false) hence debug logs from public functions will be collected and served',
336
+ );
337
+ } else {
338
+ debugLogStore = new NullDebugLogStore();
339
+ }
340
+
341
+ const proverOnly = config.enableProverNode && config.disableValidator;
342
+ if (proverOnly) {
343
+ log.info('Starting in prover-only mode: skipping validator, sequencer, sentinel, and slasher subsystems');
284
344
  }
285
- const proofVerifier = new QueuedIVCVerifier(config, circuitVerifier);
286
345
 
287
346
  // create the tx pool and the p2p client, which will need the l2 block source
288
347
  const p2pClient = await createP2PClient(
289
- P2PClientType.Full,
290
348
  config,
291
349
  archiver,
292
- proofVerifier,
350
+ peerProofVerifier,
293
351
  worldStateSynchronizer,
294
352
  epochCache,
295
353
  packageVersion,
@@ -298,59 +356,77 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
298
356
  deps.p2pClientDeps,
299
357
  );
300
358
 
301
- // We should really not be modifying the config object
302
- config.txPublicSetupAllowList = config.txPublicSetupAllowList ?? (await getDefaultAllowedSetupFunctions());
359
+ // We'll accumulate sentinel watchers here
360
+ const watchers: Watcher[] = [];
303
361
 
304
- // Create FullNodeCheckpointsBuilder for validator and non-validator block proposal handling
362
+ // Create FullNodeCheckpointsBuilder for block proposal handling and tx validation.
363
+ // Override maxTxsPerCheckpoint with the validator-specific limit if set.
305
364
  const validatorCheckpointsBuilder = new FullNodeCheckpointsBuilder(
306
- { ...config, l1GenesisTime, slotDuration: Number(slotDuration) },
365
+ {
366
+ ...config,
367
+ l1GenesisTime,
368
+ slotDuration: Number(slotDuration),
369
+ rollupManaLimit,
370
+ maxTxsPerCheckpoint: config.validateMaxTxsPerCheckpoint,
371
+ },
307
372
  worldStateSynchronizer,
308
373
  archiver,
309
374
  dateProvider,
310
375
  telemetry,
311
376
  );
312
377
 
313
- // We'll accumulate sentinel watchers here
314
- const watchers: Watcher[] = [];
378
+ let validatorClient: ValidatorClient | undefined;
315
379
 
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
- });
380
+ if (!proverOnly) {
381
+ // Create validator client if required
382
+ validatorClient = await createValidatorClient(config, {
383
+ checkpointsBuilder: validatorCheckpointsBuilder,
384
+ worldState: worldStateSynchronizer,
385
+ p2pClient,
386
+ telemetry,
387
+ dateProvider,
388
+ epochCache,
389
+ blockSource: archiver,
390
+ l1ToL2MessageSource: archiver,
391
+ keyStoreManager,
392
+ blobClient,
393
+ slashingProtectionDb: deps.slashingProtectionDb,
394
+ });
395
+
396
+ // If we have a validator client, register it as a source of offenses for the slasher,
397
+ // and have it register callbacks on the p2p client *before* we start it, otherwise messages
398
+ // like attestations or auths will fail.
399
+ if (validatorClient) {
400
+ watchers.push(validatorClient);
401
+
402
+ const vc = validatorClient;
403
+ const getValidatorAddresses = () => vc.getValidatorAddresses().map(a => a.toString());
404
+ validatorClient.getProposalHandler().register(p2pClient, true, archiver, getValidatorAddresses);
329
405
 
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();
406
+ if (!options.dontStartSequencer) {
407
+ await validatorClient.registerHandlers();
408
+ }
337
409
  }
338
410
  }
339
411
 
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, {
412
+ // If there's no validator client, create a ProposalHandler to handle block and checkpoint proposals
413
+ // for monitoring or reexecution. Reexecution (default) allows us to follow the pending chain,
414
+ // while non-reexecution is used for validating the proposals and collecting their txs.
415
+ // Checkpoint proposals rebuild blobs if the blob client can upload blobs.
416
+ if (!validatorClient) {
417
+ const reexecute = !!config.alwaysReexecuteBlockProposals;
418
+ log.info(`Setting up proposal handler` + (reexecute ? ' with reexecution of proposals' : ''));
419
+ createProposalHandler(config, {
345
420
  checkpointsBuilder: validatorCheckpointsBuilder,
346
421
  worldState: worldStateSynchronizer,
347
422
  epochCache,
348
423
  blockSource: archiver,
349
424
  l1ToL2MessageSource: archiver,
350
425
  p2pClient,
426
+ blobClient,
351
427
  dateProvider,
352
428
  telemetry,
353
- }).registerForReexecution(p2pClient);
429
+ }).register(p2pClient, reexecute, archiver);
354
430
  }
355
431
 
356
432
  // Start world state and wait for it to sync to the archiver.
@@ -359,36 +435,39 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
359
435
  // Start p2p. Note that it depends on world state to be running.
360
436
  await p2pClient.start();
361
437
 
362
- const validatorsSentinel = await createSentinel(epochCache, archiver, p2pClient, config);
363
- if (validatorsSentinel && config.slashInactivityPenalty > 0n) {
364
- watchers.push(validatorsSentinel);
365
- }
366
-
438
+ let validatorsSentinel: Awaited<ReturnType<typeof createSentinel>> | undefined;
367
439
  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
440
  let attestationsBlockWatcher: AttestationsBlockWatcher | undefined;
382
- if (config.slashProposeInvalidAttestationsPenalty > 0n || config.slashAttestDescendantOfInvalidPenalty > 0n) {
383
- attestationsBlockWatcher = new AttestationsBlockWatcher(archiver, epochCache, config);
384
- watchers.push(attestationsBlockWatcher);
441
+
442
+ if (!proverOnly) {
443
+ validatorsSentinel = await createSentinel(epochCache, archiver, p2pClient, config);
444
+ if (validatorsSentinel && config.slashInactivityPenalty > 0n) {
445
+ watchers.push(validatorsSentinel);
446
+ }
447
+
448
+ if (config.slashPrunePenalty > 0n || config.slashDataWithholdingPenalty > 0n) {
449
+ epochPruneWatcher = new EpochPruneWatcher(
450
+ archiver,
451
+ archiver,
452
+ epochCache,
453
+ p2pClient.getTxProvider(),
454
+ validatorCheckpointsBuilder,
455
+ config,
456
+ );
457
+ watchers.push(epochPruneWatcher);
458
+ }
459
+
460
+ // We assume we want to slash for invalid attestations unless all max penalties are set to 0
461
+ if (config.slashProposeInvalidAttestationsPenalty > 0n || config.slashAttestDescendantOfInvalidPenalty > 0n) {
462
+ attestationsBlockWatcher = new AttestationsBlockWatcher(archiver, epochCache, config);
463
+ watchers.push(attestationsBlockWatcher);
464
+ }
385
465
  }
386
466
 
387
467
  // Start p2p-related services once the archiver has completed sync
388
468
  void archiver
389
469
  .waitForInitialSync()
390
470
  .then(async () => {
391
- await p2pClient.start();
392
471
  await validatorsSentinel?.start();
393
472
  await epochPruneWatcher?.start();
394
473
  await attestationsBlockWatcher?.start();
@@ -396,6 +475,14 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
396
475
  })
397
476
  .catch(err => log.error('Failed to start p2p services after archiver sync', err));
398
477
 
478
+ const globalVariableBuilder = new GlobalVariableBuilder(dateProvider, publicClient, {
479
+ l1Contracts: config.l1Contracts,
480
+ ethereumSlotDuration: config.ethereumSlotDuration,
481
+ rollupVersion: BigInt(config.rollupVersion),
482
+ l1GenesisTime,
483
+ slotDuration: Number(slotDuration),
484
+ });
485
+
399
486
  // Validator enabled, create/start relevant service
400
487
  let sequencer: SequencerClient | undefined;
401
488
  let slasherClient: SlasherClientInterface | undefined;
@@ -418,34 +505,49 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
418
505
  );
419
506
  await slasherClient.start();
420
507
 
421
- const l1TxUtils = config.publisherForwarderAddress
422
- ? await createForwarderL1TxUtilsFromEthSigner(
508
+ const l1TxUtils = config.sequencerPublisherForwarderAddress
509
+ ? await createForwarderL1TxUtilsFromSigners(
423
510
  publicClient,
424
511
  keyStoreManager!.createAllValidatorPublisherSigners(),
425
- config.publisherForwarderAddress,
512
+ config.sequencerPublisherForwarderAddress,
426
513
  { ...config, scope: 'sequencer' },
427
- { telemetry, logger: log.createChild('l1-tx-utils'), dateProvider },
514
+ { telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
428
515
  )
429
- : await createL1TxUtilsWithBlobsFromEthSigner(
516
+ : await createL1TxUtilsFromSigners(
430
517
  publicClient,
431
518
  keyStoreManager!.createAllValidatorPublisherSigners(),
432
519
  { ...config, scope: 'sequencer' },
433
- { telemetry, logger: log.createChild('l1-tx-utils'), dateProvider },
520
+ { telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
434
521
  );
435
522
 
523
+ // Create a funder L1TxUtils from the keystore funding account (if configured)
524
+ const fundingSigner = keyStoreManager?.createFundingSigner();
525
+ let funderL1TxUtils: L1TxUtils | undefined;
526
+ if (fundingSigner) {
527
+ const [funder] = await createL1TxUtilsFromSigners(
528
+ publicClient,
529
+ [fundingSigner],
530
+ { ...config, scope: 'sequencer' },
531
+ { telemetry, logger: log.createChild('l1-tx-utils:funder'), dateProvider },
532
+ );
533
+ funderL1TxUtils = funder;
534
+ }
535
+
436
536
  // Create and start the sequencer client
437
537
  const checkpointsBuilder = new CheckpointsBuilder(
438
- { ...config, l1GenesisTime, slotDuration: Number(slotDuration) },
538
+ { ...config, l1GenesisTime, slotDuration: Number(slotDuration), rollupManaLimit },
439
539
  worldStateSynchronizer,
440
540
  archiver,
441
541
  dateProvider,
442
542
  telemetry,
543
+ debugLogStore,
443
544
  );
444
545
 
445
546
  sequencer = await SequencerClient.new(config, {
446
547
  ...deps,
447
548
  epochCache,
448
549
  l1TxUtils,
550
+ funderL1TxUtils,
449
551
  validatorClient,
450
552
  p2pClient,
451
553
  worldStateSynchronizer,
@@ -457,6 +559,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
457
559
  dateProvider,
458
560
  blobClient,
459
561
  nodeKeyStore: keyStoreManager!,
562
+ globalVariableBuilder,
460
563
  });
461
564
  }
462
565
 
@@ -467,14 +570,30 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
467
570
  log.warn(`Sequencer created but not started`);
468
571
  }
469
572
 
470
- const globalVariableBuilder = new GlobalVariableBuilder({
471
- ...config,
472
- rollupVersion: BigInt(config.rollupVersion),
473
- l1GenesisTime,
474
- slotDuration: Number(slotDuration),
475
- });
573
+ // Create prover node subsystem if enabled
574
+ let proverNode: ProverNode | undefined;
575
+ if (config.enableProverNode) {
576
+ proverNode = await createProverNode(config, {
577
+ ...deps.proverNodeDeps,
578
+ telemetry,
579
+ dateProvider,
580
+ archiver,
581
+ worldStateSynchronizer,
582
+ p2pClient,
583
+ epochCache,
584
+ blobClient,
585
+ keyStoreManager,
586
+ });
587
+
588
+ if (!options.dontStartProverNode) {
589
+ await proverNode.start();
590
+ log.info(`Prover node subsystem started`);
591
+ } else {
592
+ log.info(`Prover node subsystem created but not started`);
593
+ }
594
+ }
476
595
 
477
- return new AztecNodeService(
596
+ const node = new AztecNodeService(
478
597
  config,
479
598
  p2pClient,
480
599
  archiver,
@@ -483,6 +602,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
483
602
  archiver,
484
603
  worldStateSynchronizer,
485
604
  sequencer,
605
+ proverNode,
486
606
  slasherClient,
487
607
  validatorsSentinel,
488
608
  epochPruneWatcher,
@@ -491,11 +611,17 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
491
611
  globalVariableBuilder,
492
612
  epochCache,
493
613
  packageVersion,
494
- proofVerifier,
614
+ peerProofVerifier,
615
+ rpcProofVerifier,
495
616
  telemetry,
496
617
  log,
497
618
  blobClient,
619
+ validatorClient,
620
+ keyStoreManager,
621
+ debugLogStore,
498
622
  );
623
+
624
+ return node;
499
625
  }
500
626
 
501
627
  /**
@@ -506,6 +632,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
506
632
  return this.sequencer;
507
633
  }
508
634
 
635
+ /** Returns the prover node subsystem, if enabled. */
636
+ public getProverNode(): ProverNode | undefined {
637
+ return this.proverNode;
638
+ }
639
+
509
640
  public getBlockSource(): L2BlockSource {
510
641
  return this.blockSource;
511
642
  }
@@ -531,7 +662,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
531
662
  }
532
663
 
533
664
  public async getAllowedPublicSetup(): Promise<AllowedElement[]> {
534
- return this.config.txPublicSetupAllowList ?? (await getDefaultAllowedSetupFunctions());
665
+ return [...(await getDefaultAllowedSetupFunctions()), ...(this.config.txPublicSetupAllowListExtend ?? [])];
535
666
  }
536
667
 
537
668
  /**
@@ -559,6 +690,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
559
690
  enr,
560
691
  l1ContractAddresses: contractAddresses,
561
692
  protocolContractAddresses: protocolContractAddresses,
693
+ realProofs: !!this.config.realProofs,
562
694
  };
563
695
 
564
696
  return nodeInfo;
@@ -570,8 +702,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
570
702
  * @returns The requested block.
571
703
  */
572
704
  public async getBlock(block: BlockParameter): Promise<L2Block | undefined> {
573
- if (L2BlockHash.isL2BlockHash(block)) {
574
- return this.getBlockByHash(Fr.fromBuffer(block.toBuffer()));
705
+ if (BlockHash.isBlockHash(block)) {
706
+ return this.getBlockByHash(block);
575
707
  }
576
708
  const blockNumber = block === 'latest' ? await this.getBlockNumber() : (block as BlockNumber);
577
709
  if (blockNumber === BlockNumber.ZERO) {
@@ -585,9 +717,9 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
585
717
  * @param blockHash - The block hash being requested.
586
718
  * @returns The requested block.
587
719
  */
588
- public async getBlockByHash(blockHash: Fr): Promise<L2Block | undefined> {
720
+ public async getBlockByHash(blockHash: BlockHash): Promise<L2Block | undefined> {
589
721
  const initialBlockHash = await this.#getInitialHeaderHash();
590
- if (blockHash.equals(Fr.fromBuffer(initialBlockHash.toBuffer()))) {
722
+ if (blockHash.equals(initialBlockHash)) {
591
723
  return this.buildInitialBlock();
592
724
  }
593
725
  return await this.blockSource.getL2BlockByHash(blockHash);
@@ -625,6 +757,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
625
757
  return (await this.blockSource.getCheckpointedBlocks(from, limit)) ?? [];
626
758
  }
627
759
 
760
+ public getCheckpointsDataForEpoch(epochNumber: EpochNumber) {
761
+ return this.blockSource.getCheckpointsDataForEpoch(epochNumber);
762
+ }
763
+
628
764
  /**
629
765
  * Method to fetch the current min L2 fees.
630
766
  * @returns The current min L2 fees.
@@ -657,6 +793,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
657
793
  return await this.blockSource.getCheckpointedL2BlockNumber();
658
794
  }
659
795
 
796
+ public getCheckpointNumber(): Promise<CheckpointNumber> {
797
+ return this.blockSource.getCheckpointNumber();
798
+ }
799
+
660
800
  /**
661
801
  * Method to fetch the version of the package.
662
802
  * @returns The node package version
@@ -692,42 +832,48 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
692
832
  public async getPrivateLogsByTags(
693
833
  tags: SiloedTag[],
694
834
  page?: number,
695
- referenceBlock?: L2BlockHash,
835
+ referenceBlock?: BlockHash,
696
836
  ): Promise<TxScopedL2Log[][]> {
837
+ let upToBlockNumber: BlockNumber | undefined;
697
838
  if (referenceBlock) {
698
839
  const initialBlockHash = await this.#getInitialHeaderHash();
699
- if (!referenceBlock.equals(initialBlockHash)) {
700
- const blockHashFr = Fr.fromBuffer(referenceBlock.toBuffer());
701
- const header = await this.blockSource.getBlockHeaderByHash(blockHashFr);
840
+ if (referenceBlock.equals(initialBlockHash)) {
841
+ upToBlockNumber = BlockNumber(0);
842
+ } else {
843
+ const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
702
844
  if (!header) {
703
845
  throw new Error(
704
846
  `Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
705
847
  );
706
848
  }
849
+ upToBlockNumber = header.globalVariables.blockNumber;
707
850
  }
708
851
  }
709
- return this.logsSource.getPrivateLogsByTags(tags, page);
852
+ return this.logsSource.getPrivateLogsByTags(tags, page, upToBlockNumber);
710
853
  }
711
854
 
712
855
  public async getPublicLogsByTagsFromContract(
713
856
  contractAddress: AztecAddress,
714
857
  tags: Tag[],
715
858
  page?: number,
716
- referenceBlock?: L2BlockHash,
859
+ referenceBlock?: BlockHash,
717
860
  ): Promise<TxScopedL2Log[][]> {
861
+ let upToBlockNumber: BlockNumber | undefined;
718
862
  if (referenceBlock) {
719
863
  const initialBlockHash = await this.#getInitialHeaderHash();
720
- if (!referenceBlock.equals(initialBlockHash)) {
721
- const blockHashFr = Fr.fromBuffer(referenceBlock.toBuffer());
722
- const header = await this.blockSource.getBlockHeaderByHash(blockHashFr);
864
+ if (referenceBlock.equals(initialBlockHash)) {
865
+ upToBlockNumber = BlockNumber(0);
866
+ } else {
867
+ const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
723
868
  if (!header) {
724
869
  throw new Error(
725
870
  `Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
726
871
  );
727
872
  }
873
+ upToBlockNumber = header.globalVariables.blockNumber;
728
874
  }
729
875
  }
730
- return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page);
876
+ return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page, upToBlockNumber);
731
877
  }
732
878
 
733
879
  /**
@@ -769,8 +915,9 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
769
915
  }
770
916
 
771
917
  await this.p2pClient!.sendTx(tx);
772
- this.metrics.receivedTx(timer.ms(), true);
773
- this.log.info(`Received tx ${txHash}`, { txHash });
918
+ const duration = timer.ms();
919
+ this.metrics.receivedTx(duration, true);
920
+ this.log.info(`Received tx ${txHash} in ${duration}ms`, { txHash });
774
921
  }
775
922
 
776
923
  public async getTxReceipt(txHash: TxHash): Promise<TxReceipt> {
@@ -782,18 +929,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
782
929
  // Then get the actual tx from the archiver, which tracks every tx in a mined block.
783
930
  const settledTxReceipt = await this.blockSource.getSettledTxReceipt(txHash);
784
931
 
932
+ let receipt: TxReceipt;
785
933
  if (settledTxReceipt) {
786
- // If the archiver has the receipt then return it.
787
- return settledTxReceipt;
934
+ receipt = settledTxReceipt;
788
935
  } else if (isKnownToPool) {
789
936
  // If the tx is in the pool but not in the archiver, it's pending.
790
937
  // This handles race conditions between archiver and p2p, where the archiver
791
938
  // 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);
939
+ receipt = new TxReceipt(txHash, TxStatus.PENDING, undefined, undefined);
793
940
  } else {
794
941
  // 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');
942
+ receipt = new TxReceipt(txHash, TxStatus.DROPPED, undefined, 'Tx dropped by P2P node');
796
943
  }
944
+
945
+ this.debugLogStore.decorateReceiptWithLogs(txHash.toString(), receipt);
946
+
947
+ return receipt;
797
948
  }
798
949
 
799
950
  public getTxEffect(txHash: TxHash): Promise<IndexedTxEffect | undefined> {
@@ -808,8 +959,9 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
808
959
  await tryStop(this.validatorsSentinel);
809
960
  await tryStop(this.epochPruneWatcher);
810
961
  await tryStop(this.slasherClient);
811
- await tryStop(this.proofVerifier);
962
+ await Promise.all([tryStop(this.peerProofVerifier), tryStop(this.rpcProofVerifier)]);
812
963
  await tryStop(this.sequencer);
964
+ await tryStop(this.proverNode);
813
965
  await tryStop(this.p2pClient);
814
966
  await tryStop(this.worldStateSynchronizer);
815
967
  await tryStop(this.blockSource);
@@ -859,100 +1011,98 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
859
1011
  }
860
1012
 
861
1013
  public async findLeavesIndexes(
862
- block: BlockParameter,
1014
+ referenceBlock: BlockParameter,
863
1015
  treeId: MerkleTreeId,
864
1016
  leafValues: Fr[],
865
1017
  ): Promise<(DataInBlock<bigint> | undefined)[]> {
866
- const committedDb = await this.#getWorldState(block);
1018
+ const committedDb = await this.getWorldState(referenceBlock);
867
1019
  const maybeIndices = await committedDb.findLeafIndices(
868
1020
  treeId,
869
1021
  leafValues.map(x => x.toBuffer()),
870
1022
  );
871
- // We filter out undefined values
872
- const indices = maybeIndices.filter(x => x !== undefined) as bigint[];
1023
+ // Filter out undefined values to query block numbers only for found leaves
1024
+ const definedIndices = maybeIndices.filter(x => x !== undefined);
873
1025
 
874
- // Now we find the block numbers for the indices
875
- const blockNumbers = await committedDb.getBlockNumbersForLeafIndices(treeId, indices);
1026
+ // Now we find the block numbers for the defined indices
1027
+ const blockNumbers = await committedDb.getBlockNumbersForLeafIndices(treeId, definedIndices);
876
1028
 
877
- // If any of the block numbers are undefined, we throw an error.
878
- for (let i = 0; i < indices.length; i++) {
879
- if (blockNumbers[i] === undefined) {
880
- throw new Error(`Block number is undefined for leaf index ${indices[i]} in tree ${MerkleTreeId[treeId]}`);
1029
+ // Build a map from leaf index to block number
1030
+ const indexToBlockNumber = new Map<bigint, BlockNumber>();
1031
+ for (let i = 0; i < definedIndices.length; i++) {
1032
+ const blockNumber = blockNumbers[i];
1033
+ if (blockNumber === undefined) {
1034
+ throw new Error(
1035
+ `Block number is undefined for leaf index ${definedIndices[i]} in tree ${MerkleTreeId[treeId]}`,
1036
+ );
881
1037
  }
1038
+ indexToBlockNumber.set(definedIndices[i], blockNumber);
882
1039
  }
883
1040
 
884
1041
  // Get unique block numbers in order to optimize num calls to getLeafValue function.
885
- const uniqueBlockNumbers = [...new Set(blockNumbers.filter(x => x !== undefined))];
1042
+ const uniqueBlockNumbers = [...new Set(indexToBlockNumber.values())];
886
1043
 
887
- // Now we obtain the block hashes from the archive tree by calling await `committedDb.getLeafValue(treeId, index)`
888
- // (note that block number corresponds to the leaf index in the archive tree).
1044
+ // Now we obtain the block hashes from the archive tree (block number = leaf index in archive tree).
889
1045
  const blockHashes = await Promise.all(
890
1046
  uniqueBlockNumbers.map(blockNumber => {
891
1047
  return committedDb.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
892
1048
  }),
893
1049
  );
894
1050
 
895
- // If any of the block hashes are undefined, we throw an error.
1051
+ // Build a map from block number to block hash
1052
+ const blockNumberToHash = new Map<BlockNumber, Fr>();
896
1053
  for (let i = 0; i < uniqueBlockNumbers.length; i++) {
897
- if (blockHashes[i] === undefined) {
1054
+ const blockHash = blockHashes[i];
1055
+ if (blockHash === undefined) {
898
1056
  throw new Error(`Block hash is undefined for block number ${uniqueBlockNumbers[i]}`);
899
1057
  }
1058
+ blockNumberToHash.set(uniqueBlockNumbers[i], blockHash);
900
1059
  }
901
1060
 
902
1061
  // Create DataInBlock objects by combining indices, blockNumbers and blockHashes and return them.
903
- return maybeIndices.map((index, i) => {
1062
+ return maybeIndices.map(index => {
904
1063
  if (index === undefined) {
905
1064
  return undefined;
906
1065
  }
907
- const blockNumber = blockNumbers[i];
1066
+ const blockNumber = indexToBlockNumber.get(index);
908
1067
  if (blockNumber === undefined) {
909
- return undefined;
1068
+ throw new Error(`Block number not found for leaf index ${index} in tree ${MerkleTreeId[treeId]}`);
910
1069
  }
911
- const blockHashIndex = uniqueBlockNumbers.indexOf(blockNumber);
912
- const blockHash = blockHashes[blockHashIndex];
913
- if (!blockHash) {
914
- return undefined;
1070
+ const blockHash = blockNumberToHash.get(blockNumber);
1071
+ if (blockHash === undefined) {
1072
+ throw new Error(`Block hash not found for block number ${blockNumber}`);
915
1073
  }
916
1074
  return {
917
- l2BlockNumber: BlockNumber(Number(blockNumber)),
918
- l2BlockHash: L2BlockHash.fromField(blockHash),
1075
+ l2BlockNumber: blockNumber,
1076
+ l2BlockHash: new BlockHash(blockHash),
919
1077
  data: index,
920
1078
  };
921
1079
  });
922
1080
  }
923
1081
 
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,
1082
+ public async getBlockHashMembershipWitness(
1083
+ referenceBlock: BlockParameter,
1084
+ blockHash: BlockHash,
943
1085
  ): Promise<MembershipWitness<typeof ARCHIVE_HEIGHT> | undefined> {
944
- const committedDb = await this.#getWorldState(block);
945
- const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.ARCHIVE>(MerkleTreeId.ARCHIVE, [archive]);
1086
+ // The Noir circuit checks the archive membership proof against `anchor_block_header.last_archive.root`,
1087
+ // which is the archive tree root BEFORE the anchor block was added (i.e. the state after block N-1).
1088
+ // So we need the world state at block N-1, not block N, to produce a sibling path matching that root.
1089
+ const referenceBlockNumber = await this.resolveBlockNumber(referenceBlock);
1090
+ if (referenceBlockNumber === BlockNumber.ZERO) {
1091
+ // Block 0 (the initial block) has an empty archive, so no membership witness can exist.
1092
+ return undefined;
1093
+ }
1094
+ const committedDb = await this.getWorldState(BlockNumber(referenceBlockNumber - 1));
1095
+ const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.ARCHIVE>(MerkleTreeId.ARCHIVE, [blockHash]);
946
1096
  return pathAndIndex === undefined
947
1097
  ? undefined
948
1098
  : MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
949
1099
  }
950
1100
 
951
1101
  public async getNoteHashMembershipWitness(
952
- block: BlockParameter,
1102
+ referenceBlock: BlockParameter,
953
1103
  noteHash: Fr,
954
1104
  ): Promise<MembershipWitness<typeof NOTE_HASH_TREE_HEIGHT> | undefined> {
955
- const committedDb = await this.#getWorldState(block);
1105
+ const committedDb = await this.getWorldState(referenceBlock);
956
1106
  const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.NOTE_HASH_TREE>(
957
1107
  MerkleTreeId.NOTE_HASH_TREE,
958
1108
  [noteHash],
@@ -963,10 +1113,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
963
1113
  }
964
1114
 
965
1115
  public async getL1ToL2MessageMembershipWitness(
966
- block: BlockParameter,
1116
+ referenceBlock: BlockParameter,
967
1117
  l1ToL2Message: Fr,
968
1118
  ): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>] | undefined> {
969
- const db = await this.#getWorldState(block);
1119
+ const db = await this.getWorldState(referenceBlock);
970
1120
  const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [l1ToL2Message]);
971
1121
  if (!witness) {
972
1122
  return undefined;
@@ -976,11 +1126,9 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
976
1126
  return [witness.index, witness.path];
977
1127
  }
978
1128
 
979
- public async getL1ToL2MessageBlock(l1ToL2Message: Fr): Promise<BlockNumber | undefined> {
1129
+ public async getL1ToL2MessageCheckpoint(l1ToL2Message: Fr): Promise<CheckpointNumber | undefined> {
980
1130
  const messageIndex = await this.l1ToL2MessageSource.getL1ToL2MessageIndex(l1ToL2Message);
981
- return messageIndex
982
- ? BlockNumber.fromCheckpointNumber(InboxLeaf.checkpointNumberFromIndex(messageIndex))
983
- : undefined;
1131
+ return messageIndex ? InboxLeaf.checkpointNumberFromIndex(messageIndex) : undefined;
984
1132
  }
985
1133
 
986
1134
  /**
@@ -1001,45 +1149,19 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1001
1149
  public async getL2ToL1Messages(epoch: EpochNumber): Promise<Fr[][][][]> {
1002
1150
  // Assumes `getCheckpointedBlocksForEpoch` returns blocks in ascending order of block number.
1003
1151
  const checkpointedBlocks = await this.blockSource.getCheckpointedBlocksForEpoch(epoch);
1004
- const blocksInCheckpoints: L2Block[][] = [];
1005
- let previousSlotNumber = SlotNumber.ZERO;
1006
- let checkpointIndex = -1;
1007
- for (const checkpointedBlock of checkpointedBlocks) {
1008
- const block = checkpointedBlock.block;
1009
- const slotNumber = block.header.globalVariables.slotNumber;
1010
- if (slotNumber !== previousSlotNumber) {
1011
- checkpointIndex++;
1012
- blocksInCheckpoints.push([]);
1013
- previousSlotNumber = slotNumber;
1014
- }
1015
- blocksInCheckpoints[checkpointIndex].push(block);
1016
- }
1152
+ const blocksInCheckpoints = chunkBy(checkpointedBlocks, cb => cb.block.header.globalVariables.slotNumber).map(
1153
+ group => group.map(cb => cb.block),
1154
+ );
1017
1155
  return blocksInCheckpoints.map(blocks =>
1018
1156
  blocks.map(block => block.body.txEffects.map(txEffect => txEffect.l2ToL1Msgs)),
1019
1157
  );
1020
1158
  }
1021
1159
 
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
1160
  public async getNullifierMembershipWitness(
1039
- block: BlockParameter,
1161
+ referenceBlock: BlockParameter,
1040
1162
  nullifier: Fr,
1041
1163
  ): Promise<NullifierMembershipWitness | undefined> {
1042
- const db = await this.#getWorldState(block);
1164
+ const db = await this.getWorldState(referenceBlock);
1043
1165
  const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [nullifier.toBuffer()]);
1044
1166
  if (!witness) {
1045
1167
  return undefined;
@@ -1054,32 +1176,20 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1054
1176
  return new NullifierMembershipWitness(index, leafPreimage as NullifierLeafPreimage, path);
1055
1177
  }
1056
1178
 
1057
- /**
1058
- * 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.
1060
- * @param nullifier - Nullifier we try to find the low nullifier witness for.
1061
- * @returns The low nullifier membership witness (if found).
1062
- * @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
1063
- * list structure" of leaves and proving that a lower nullifier is pointing to a bigger next value than the nullifier
1064
- * we are trying to prove non-inclusion for.
1065
- *
1066
- * Note: This function returns the membership witness of the nullifier itself and not the low nullifier when
1067
- * the nullifier already exists in the tree. This is because the `getPreviousValueIndex` function returns the
1068
- * index of the nullifier itself when it already exists in the tree.
1069
- * TODO: This is a confusing behavior and we should eventually address that.
1070
- */
1071
1179
  public async getLowNullifierMembershipWitness(
1072
- block: BlockParameter,
1180
+ referenceBlock: BlockParameter,
1073
1181
  nullifier: Fr,
1074
1182
  ): Promise<NullifierMembershipWitness | undefined> {
1075
- const committedDb = await this.#getWorldState(block);
1183
+ const committedDb = await this.getWorldState(referenceBlock);
1076
1184
  const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
1077
1185
  if (!findResult) {
1078
1186
  return undefined;
1079
1187
  }
1080
1188
  const { index, alreadyPresent } = findResult;
1081
1189
  if (alreadyPresent) {
1082
- this.log.warn(`Nullifier ${nullifier.toBigInt()} already exists in the tree`);
1190
+ throw new Error(
1191
+ `Cannot prove nullifier non-inclusion: nullifier ${nullifier.toBigInt()} already exists in the tree`,
1192
+ );
1083
1193
  }
1084
1194
  const preimageData = (await committedDb.getLeafPreimage(MerkleTreeId.NULLIFIER_TREE, index))!;
1085
1195
 
@@ -1087,8 +1197,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1087
1197
  return new NullifierMembershipWitness(BigInt(index), preimageData as NullifierLeafPreimage, siblingPath);
1088
1198
  }
1089
1199
 
1090
- async getPublicDataWitness(block: BlockParameter, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
1091
- const committedDb = await this.#getWorldState(block);
1200
+ async getPublicDataWitness(referenceBlock: BlockParameter, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
1201
+ const committedDb = await this.getWorldState(referenceBlock);
1092
1202
  const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
1093
1203
  if (!lowLeafResult) {
1094
1204
  return undefined;
@@ -1102,8 +1212,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1102
1212
  }
1103
1213
  }
1104
1214
 
1105
- public async getPublicStorageAt(block: BlockParameter, contract: AztecAddress, slot: Fr): Promise<Fr> {
1106
- const committedDb = await this.#getWorldState(block);
1215
+ public async getPublicStorageAt(referenceBlock: BlockParameter, contract: AztecAddress, slot: Fr): Promise<Fr> {
1216
+ const committedDb = await this.getWorldState(referenceBlock);
1107
1217
  const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
1108
1218
 
1109
1219
  const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
@@ -1118,14 +1228,13 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1118
1228
  }
1119
1229
 
1120
1230
  public async getBlockHeader(block: BlockParameter = 'latest'): Promise<BlockHeader | undefined> {
1121
- if (L2BlockHash.isL2BlockHash(block)) {
1231
+ if (BlockHash.isBlockHash(block)) {
1122
1232
  const initialBlockHash = await this.#getInitialHeaderHash();
1123
1233
  if (block.equals(initialBlockHash)) {
1124
1234
  // Block source doesn't handle initial header so we need to handle the case separately.
1125
1235
  return this.worldStateSynchronizer.getCommitted().getInitialHeader();
1126
1236
  }
1127
- const blockHashFr = Fr.fromBuffer(block.toBuffer());
1128
- return this.blockSource.getBlockHeaderByHash(blockHashFr);
1237
+ return this.blockSource.getBlockHeaderByHash(block);
1129
1238
  } else {
1130
1239
  // Block source doesn't handle initial header so we need to handle the case separately.
1131
1240
  const blockNumber = block === 'latest' ? await this.getBlockNumber() : (block as BlockNumber);
@@ -1145,6 +1254,14 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1145
1254
  return await this.blockSource.getBlockHeaderByArchive(archive);
1146
1255
  }
1147
1256
 
1257
+ public getBlockData(number: BlockNumber): Promise<BlockData | undefined> {
1258
+ return this.blockSource.getBlockData(number);
1259
+ }
1260
+
1261
+ public getBlockDataByArchive(archive: Fr): Promise<BlockData | undefined> {
1262
+ return this.blockSource.getBlockDataByArchive(archive);
1263
+ }
1264
+
1148
1265
  /**
1149
1266
  * Simulates the public part of a transaction with the current state.
1150
1267
  * @param tx - The transaction to simulate.
@@ -1168,7 +1285,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1168
1285
  }
1169
1286
 
1170
1287
  const txHash = tx.getTxHash();
1171
- const blockNumber = BlockNumber((await this.blockSource.getBlockNumber()) + 1);
1288
+ const latestBlockNumber = await this.blockSource.getBlockNumber();
1289
+ const blockNumber = BlockNumber.add(latestBlockNumber, 1);
1172
1290
 
1173
1291
  // If sequencer is not initialized, we just set these values to zero for simulation.
1174
1292
  const coinbase = EthAddress.ZERO;
@@ -1183,6 +1301,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1183
1301
  this.contractDataSource,
1184
1302
  new DateProvider(),
1185
1303
  this.telemetry,
1304
+ this.log.getBindings(),
1186
1305
  );
1187
1306
 
1188
1307
  this.log.verbose(`Simulating public calls for tx ${txHash}`, {
@@ -1191,6 +1310,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1191
1310
  blockNumber,
1192
1311
  });
1193
1312
 
1313
+ // Ensure world-state has caught up with the latest block we loaded from the archiver
1314
+ await this.worldStateSynchronizer.syncImmediate(latestBlockNumber);
1194
1315
  const merkleTreeFork = await this.worldStateSynchronizer.fork();
1195
1316
  try {
1196
1317
  const config = PublicSimulatorConfig.from({
@@ -1206,7 +1327,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1206
1327
  const processor = publicProcessorFactory.create(merkleTreeFork, newGlobalVariables, config);
1207
1328
 
1208
1329
  // REFACTOR: Consider merging ProcessReturnValues into ProcessedTx
1209
- const [processedTxs, failedTxs, _usedTxs, returns] = await processor.process([tx]);
1330
+ const [processedTxs, failedTxs, _usedTxs, returns, debugLogs] = await processor.process([tx]);
1210
1331
  // REFACTOR: Consider returning the error rather than throwing
1211
1332
  if (failedTxs.length) {
1212
1333
  this.log.warn(`Simulated tx ${txHash} fails: ${failedTxs[0].error}`, { txHash });
@@ -1220,6 +1341,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1220
1341
  processedTx.txEffect,
1221
1342
  returns,
1222
1343
  processedTx.gasUsed,
1344
+ debugLogs,
1223
1345
  );
1224
1346
  } finally {
1225
1347
  await merkleTreeFork.close();
@@ -1231,21 +1353,34 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1231
1353
  { isSimulation, skipFeeEnforcement }: { isSimulation?: boolean; skipFeeEnforcement?: boolean } = {},
1232
1354
  ): Promise<TxValidationResult> {
1233
1355
  const db = this.worldStateSynchronizer.getCommitted();
1234
- const verifier = isSimulation ? undefined : this.proofVerifier;
1356
+ const verifier = isSimulation ? undefined : this.rpcProofVerifier;
1235
1357
 
1236
- // We accept transactions if they are not expired by the next slot (checked based on the IncludeByTimestamp field)
1358
+ // We accept transactions if they are not expired by the next slot (checked based on the ExpirationTimestamp field)
1237
1359
  const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
1238
1360
  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
- });
1361
+ const l1Constants = await this.blockSource.getL1Constants();
1362
+ const validator = createTxValidatorForAcceptingTxsOverRPC(
1363
+ db,
1364
+ this.contractDataSource,
1365
+ verifier,
1366
+ {
1367
+ timestamp: nextSlotTimestamp,
1368
+ blockNumber,
1369
+ l1ChainId: this.l1ChainId,
1370
+ rollupVersion: this.version,
1371
+ setupAllowList: [
1372
+ ...(await getDefaultAllowedSetupFunctions()),
1373
+ ...(this.config.txPublicSetupAllowListExtend ?? []),
1374
+ ],
1375
+ gasFees: await this.getCurrentMinFees(),
1376
+ skipFeeEnforcement,
1377
+ txsPermitted: !this.config.disableTransactions,
1378
+ rollupManaLimit: l1Constants.rollupManaLimit,
1379
+ maxBlockL2Gas: this.config.validateMaxL2BlockGas,
1380
+ maxBlockDAGas: this.config.validateMaxDABlockGas,
1381
+ },
1382
+ this.log.getBindings(),
1383
+ );
1249
1384
 
1250
1385
  return await validator.validateTx(tx);
1251
1386
  }
@@ -1267,7 +1402,15 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1267
1402
  archiver.updateConfig(config);
1268
1403
  }
1269
1404
  if (newConfig.realProofs !== this.config.realProofs) {
1270
- this.proofVerifier = config.realProofs ? await BBCircuitVerifier.new(newConfig) : new TestCircuitVerifier();
1405
+ await Promise.all([tryStop(this.peerProofVerifier), tryStop(this.rpcProofVerifier)]);
1406
+ if (newConfig.realProofs) {
1407
+ this.peerProofVerifier = await BatchChonkVerifier.new(newConfig, newConfig.bbChonkVerifyMaxBatch, 'peer');
1408
+ const rpcVerifier = await BBCircuitVerifier.new(newConfig);
1409
+ this.rpcProofVerifier = new QueuedIVCVerifier(rpcVerifier, newConfig.numConcurrentIVCVerifiers);
1410
+ } else {
1411
+ this.peerProofVerifier = new TestCircuitVerifier();
1412
+ this.rpcProofVerifier = new TestCircuitVerifier();
1413
+ }
1271
1414
  }
1272
1415
 
1273
1416
  this.config = newConfig;
@@ -1342,7 +1485,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1342
1485
  return Promise.resolve();
1343
1486
  }
1344
1487
 
1345
- public async rollbackTo(targetBlock: BlockNumber, force?: boolean): Promise<void> {
1488
+ public async rollbackTo(targetBlock: BlockNumber, force?: boolean, resumeSync = true): Promise<void> {
1346
1489
  const archiver = this.blockSource as Archiver;
1347
1490
  if (!('rollbackTo' in archiver)) {
1348
1491
  throw new Error('Archiver implementation does not support rollbacks.');
@@ -1372,9 +1515,13 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1372
1515
  this.log.error(`Error during rollback`, err);
1373
1516
  throw err;
1374
1517
  } finally {
1375
- this.log.info(`Resuming world state and archiver sync.`);
1376
- this.worldStateSynchronizer.resumeSync();
1377
- archiver.resume();
1518
+ if (resumeSync) {
1519
+ this.log.info(`Resuming world state and archiver sync.`);
1520
+ this.worldStateSynchronizer.resumeSync();
1521
+ archiver.resume();
1522
+ } else {
1523
+ this.log.info(`Sync left paused after rollback (resumeSync=false).`);
1524
+ }
1378
1525
  }
1379
1526
  }
1380
1527
 
@@ -1391,31 +1538,142 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1391
1538
  return Promise.resolve();
1392
1539
  }
1393
1540
 
1394
- public getSlashPayloads(): Promise<SlashPayloadRound[]> {
1395
- if (!this.slasherClient) {
1396
- throw new Error(`Slasher client not enabled`);
1397
- }
1398
- return this.slasherClient.getSlashPayloads();
1399
- }
1400
-
1401
1541
  public getSlashOffenses(round: bigint | 'all' | 'current'): Promise<Offense[]> {
1402
1542
  if (!this.slasherClient) {
1403
1543
  throw new Error(`Slasher client not enabled`);
1404
1544
  }
1405
1545
  if (round === 'all') {
1406
- return this.slasherClient.getPendingOffenses();
1546
+ return this.slasherClient.getOffenses();
1407
1547
  } else {
1408
1548
  return this.slasherClient.gatherOffensesForRound(round === 'current' ? undefined : BigInt(round));
1409
1549
  }
1410
1550
  }
1411
1551
 
1412
- #getInitialHeaderHash(): Promise<L2BlockHash> {
1552
+ public async reloadKeystore(): Promise<void> {
1553
+ if (!this.config.keyStoreDirectory?.length) {
1554
+ throw new BadRequestError(
1555
+ 'Cannot reload keystore: node is not using a file-based keystore. ' +
1556
+ 'Set KEY_STORE_DIRECTORY to use file-based keystores.',
1557
+ );
1558
+ }
1559
+ if (!this.validatorClient) {
1560
+ throw new BadRequestError('Cannot reload keystore: validator is not enabled.');
1561
+ }
1562
+
1563
+ this.log.info('Reloading keystore from disk');
1564
+
1565
+ // Re-read and validate keystore files
1566
+ const keyStores = loadKeystores(this.config.keyStoreDirectory);
1567
+ const newManager = new KeystoreManager(mergeKeystores(keyStores));
1568
+ await newManager.validateSigners();
1569
+ ValidatorClient.validateKeyStoreConfiguration(newManager, this.log);
1570
+
1571
+ // Validate that every validator's publisher keys overlap with the L1 signers
1572
+ // that were initialized at startup. Publishers cannot be hot-reloaded, so a
1573
+ // validator with a publisher key that doesn't match any existing L1 signer
1574
+ // would silently fail on every proposer slot.
1575
+ if (this.keyStoreManager && this.sequencer) {
1576
+ const oldAdapter = NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager);
1577
+ const availablePublishers = new Set(
1578
+ oldAdapter
1579
+ .getAttesterAddresses()
1580
+ .flatMap(a => oldAdapter.getPublisherAddresses(a).map(p => p.toString().toLowerCase())),
1581
+ );
1582
+
1583
+ const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
1584
+ for (const attester of newAdapter.getAttesterAddresses()) {
1585
+ const pubs = newAdapter.getPublisherAddresses(attester);
1586
+ if (pubs.length > 0 && !pubs.some(p => availablePublishers.has(p.toString().toLowerCase()))) {
1587
+ throw new BadRequestError(
1588
+ `Cannot reload keystore: validator ${attester} has publisher keys ` +
1589
+ `[${pubs.map(p => p.toString()).join(', ')}] but none match the L1 signers initialized at startup ` +
1590
+ `[${[...availablePublishers].join(', ')}]. Publishers cannot be hot-reloaded — ` +
1591
+ `use an existing publisher key or restart the node.`,
1592
+ );
1593
+ }
1594
+ }
1595
+ }
1596
+
1597
+ // Build adapters for old and new keystores to compute diff
1598
+ const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
1599
+ const newAddresses = newAdapter.getAttesterAddresses();
1600
+ const oldAddresses = this.keyStoreManager
1601
+ ? NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager).getAttesterAddresses()
1602
+ : [];
1603
+
1604
+ const oldSet = new Set(oldAddresses.map(a => a.toString()));
1605
+ const newSet = new Set(newAddresses.map(a => a.toString()));
1606
+ const added = newAddresses.filter(a => !oldSet.has(a.toString()));
1607
+ const removed = oldAddresses.filter(a => !newSet.has(a.toString()));
1608
+
1609
+ if (added.length > 0) {
1610
+ this.log.info(`Keystore reload: adding attester keys: ${added.map(a => a.toString()).join(', ')}`);
1611
+ }
1612
+ if (removed.length > 0) {
1613
+ this.log.info(`Keystore reload: removing attester keys: ${removed.map(a => a.toString()).join(', ')}`);
1614
+ }
1615
+ if (added.length === 0 && removed.length === 0) {
1616
+ this.log.info('Keystore reload: attester keys unchanged');
1617
+ }
1618
+
1619
+ // Update the validator client (coinbase, feeRecipient, attester keys)
1620
+ this.validatorClient.reloadKeystore(newManager);
1621
+
1622
+ // Update the publisher factory's keystore so newly-added validators
1623
+ // can be matched to existing publisher keys when proposing blocks.
1624
+ if (this.sequencer) {
1625
+ this.sequencer.updatePublisherNodeKeyStore(newAdapter);
1626
+ }
1627
+
1628
+ // Update slasher's "don't-slash-self" list with new validator addresses
1629
+ if (this.slasherClient && !this.config.slashSelfAllowed) {
1630
+ const slashValidatorsNever = unique(
1631
+ [...(this.config.slashValidatorsNever ?? []), ...newAddresses].map(a => a.toString()),
1632
+ ).map(EthAddress.fromString);
1633
+ this.slasherClient.updateConfig({ slashValidatorsNever });
1634
+ }
1635
+
1636
+ this.keyStoreManager = newManager;
1637
+ this.log.info('Keystore reloaded: coinbase, feeRecipient, and attester keys updated');
1638
+ }
1639
+
1640
+ public async mineBlock(): Promise<void> {
1641
+ if (!this.sequencer) {
1642
+ throw new BadRequestError('Cannot mine block: no sequencer is running');
1643
+ }
1644
+
1645
+ const currentBlockNumber = await this.getBlockNumber();
1646
+
1647
+ // Use slot duration + 50% buffer as the timeout so this works on running networks too
1648
+ const { slotDuration } = await this.blockSource.getL1Constants();
1649
+ const timeoutSeconds = Math.ceil(slotDuration * 1.5);
1650
+
1651
+ // Temporarily set minTxsPerBlock to 0 so the sequencer produces a block even with no txs
1652
+ const originalMinTxsPerBlock = this.sequencer.getSequencer().getConfig().minTxsPerBlock;
1653
+ this.sequencer.updateConfig({ minTxsPerBlock: 0 });
1654
+
1655
+ try {
1656
+ // Trigger the sequencer to produce a block immediately
1657
+ void this.sequencer.trigger();
1658
+
1659
+ // Wait for the new L2 block to appear
1660
+ await retryUntil(
1661
+ async () => {
1662
+ const newBlockNumber = await this.getBlockNumber();
1663
+ return newBlockNumber > currentBlockNumber ? true : undefined;
1664
+ },
1665
+ 'mineBlock',
1666
+ timeoutSeconds,
1667
+ 0.1,
1668
+ );
1669
+ } finally {
1670
+ this.sequencer.updateConfig({ minTxsPerBlock: originalMinTxsPerBlock });
1671
+ }
1672
+ }
1673
+
1674
+ #getInitialHeaderHash(): Promise<BlockHash> {
1413
1675
  if (!this.initialHeaderHashPromise) {
1414
- this.initialHeaderHashPromise = this.worldStateSynchronizer
1415
- .getCommitted()
1416
- .getInitialHeader()
1417
- .hash()
1418
- .then(hash => L2BlockHash.fromField(hash));
1676
+ this.initialHeaderHashPromise = this.worldStateSynchronizer.getCommitted().getInitialHeader().hash();
1419
1677
  }
1420
1678
  return this.initialHeaderHashPromise;
1421
1679
  }
@@ -1425,7 +1683,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1425
1683
  * @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
1426
1684
  * @returns An instance of a committed MerkleTreeOperations
1427
1685
  */
1428
- async #getWorldState(block: BlockParameter) {
1686
+ protected async getWorldState(block: BlockParameter) {
1429
1687
  let blockSyncedTo: BlockNumber = BlockNumber.ZERO;
1430
1688
  try {
1431
1689
  // Attempt to sync the world state if necessary
@@ -1439,36 +1697,65 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1439
1697
  return this.worldStateSynchronizer.getCommitted();
1440
1698
  }
1441
1699
 
1442
- if (L2BlockHash.isL2BlockHash(block)) {
1700
+ // Get the block number, either directly from the parameter or by quering the archiver with the block hash
1701
+ let blockNumber: BlockNumber;
1702
+ if (BlockHash.isBlockHash(block)) {
1443
1703
  const initialBlockHash = await this.#getInitialHeaderHash();
1444
1704
  if (block.equals(initialBlockHash)) {
1445
1705
  // Block source doesn't handle initial header so we need to handle the case separately.
1446
1706
  return this.worldStateSynchronizer.getSnapshot(BlockNumber.ZERO);
1447
1707
  }
1448
1708
 
1449
- const blockHashFr = Fr.fromBuffer(block.toBuffer());
1450
- const header = await this.blockSource.getBlockHeaderByHash(blockHashFr);
1709
+ const header = await this.blockSource.getBlockHeaderByHash(block);
1451
1710
  if (!header) {
1452
1711
  throw new Error(
1453
1712
  `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.`,
1454
1713
  );
1455
1714
  }
1456
- const blockNumber = header.getBlockNumber();
1457
- this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
1458
- return this.worldStateSynchronizer.getSnapshot(blockNumber);
1715
+
1716
+ blockNumber = header.getBlockNumber();
1717
+ } else {
1718
+ blockNumber = block as BlockNumber;
1719
+ }
1720
+
1721
+ // Check it's within world state sync range
1722
+ if (blockNumber > blockSyncedTo) {
1723
+ throw new Error(`Queried block ${block} not yet synced by the node (node is synced upto ${blockSyncedTo}).`);
1459
1724
  }
1725
+ this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
1460
1726
 
1461
- // Block number provided
1462
- {
1463
- const blockNumber = block as BlockNumber;
1727
+ const snapshot = this.worldStateSynchronizer.getSnapshot(blockNumber);
1464
1728
 
1465
- if (blockNumber > blockSyncedTo) {
1466
- throw new Error(`Queried block ${block} not yet synced by the node (node is synced upto ${blockSyncedTo}).`);
1729
+ // Double-check world-state synced to the same block hash as was requested
1730
+ if (BlockHash.isBlockHash(block)) {
1731
+ const blockHash = await snapshot.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
1732
+ if (!blockHash || !new BlockHash(blockHash).equals(block)) {
1733
+ throw new Error(
1734
+ `Block hash ${block.toString()} not found in world state at block number ${blockNumber}. If the node API has been queried with anchor block hash possibly a reorg has occurred.`,
1735
+ );
1467
1736
  }
1737
+ }
1468
1738
 
1469
- this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
1470
- return this.worldStateSynchronizer.getSnapshot(blockNumber);
1739
+ return snapshot;
1740
+ }
1741
+
1742
+ /** Resolves a block parameter to a block number. */
1743
+ protected async resolveBlockNumber(block: BlockParameter): Promise<BlockNumber> {
1744
+ if (block === 'latest') {
1745
+ return BlockNumber(await this.blockSource.getBlockNumber());
1746
+ }
1747
+ if (BlockHash.isBlockHash(block)) {
1748
+ const initialBlockHash = await this.#getInitialHeaderHash();
1749
+ if (block.equals(initialBlockHash)) {
1750
+ return BlockNumber.ZERO;
1751
+ }
1752
+ const header = await this.blockSource.getBlockHeaderByHash(block);
1753
+ if (!header) {
1754
+ throw new Error(`Block hash ${block.toString()} not found.`);
1755
+ }
1756
+ return header.getBlockNumber();
1471
1757
  }
1758
+ return block as BlockNumber;
1472
1759
  }
1473
1760
 
1474
1761
  /**