@aztec/aztec-node 0.0.1-commit.0b941701 → 0.0.1-commit.0dc957cde

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