@aztec/aztec-node 0.0.1-commit.d431d1c → 0.0.1-commit.d939eb5aa

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