@aztec/aztec-node 0.0.1-commit.0c875d939 → 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,30 +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';
5
+ import { Blob } from '@aztec/blob-lib';
4
6
  import { ARCHIVE_HEIGHT, type L1_TO_L2_MSG_TREE_HEIGHT, type NOTE_HASH_TREE_HEIGHT } from '@aztec/constants';
5
7
  import { EpochCache, type EpochCacheInterface } from '@aztec/epoch-cache';
6
8
  import { createEthereumChain } from '@aztec/ethereum/chain';
7
- import { getPublicClient } from '@aztec/ethereum/client';
9
+ import { getPublicClient, makeL1HttpTransport } from '@aztec/ethereum/client';
8
10
  import { RegistryContract, RollupContract } from '@aztec/ethereum/contracts';
9
11
  import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
12
+ import type { L1TxUtils } from '@aztec/ethereum/l1-tx-utils';
10
13
  import { BlockNumber, CheckpointNumber, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
11
- import { compactArray, pick } from '@aztec/foundation/collection';
14
+ import { chunkBy, compactArray, pick, unique } from '@aztec/foundation/collection';
12
15
  import { Fr } from '@aztec/foundation/curves/bn254';
13
16
  import { EthAddress } from '@aztec/foundation/eth-address';
14
17
  import { BadRequestError } from '@aztec/foundation/json-rpc';
15
18
  import { type Logger, createLogger } from '@aztec/foundation/log';
19
+ import { retryUntil } from '@aztec/foundation/retry';
16
20
  import { count } from '@aztec/foundation/string';
17
21
  import { DateProvider, Timer } from '@aztec/foundation/timer';
18
22
  import { MembershipWitness, SiblingPath } from '@aztec/foundation/trees';
19
- import { KeystoreManager, loadKeystores, mergeKeystores } from '@aztec/node-keystore';
23
+ import { type KeyStore, KeystoreManager, loadKeystores, mergeKeystores } from '@aztec/node-keystore';
20
24
  import { trySnapshotSync, uploadSnapshot } from '@aztec/node-lib/actions';
25
+ import { createForwarderL1TxUtilsFromSigners, createL1TxUtilsFromSigners } from '@aztec/node-lib/factories';
21
26
  import {
22
- createForwarderL1TxUtilsFromEthSigner,
23
- createL1TxUtilsWithBlobsFromEthSigner,
24
- } from '@aztec/node-lib/factories';
25
- 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';
26
33
  import { ProtocolContractAddress } from '@aztec/protocol-contracts';
27
- 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';
28
42
  import { PublicProcessorFactory } from '@aztec/simulator/server';
29
43
  import {
30
44
  AttestationsBlockWatcher,
@@ -35,7 +49,14 @@ import {
35
49
  } from '@aztec/slasher';
36
50
  import { CollectionLimitsConfig, PublicSimulatorConfig } from '@aztec/stdlib/avm';
37
51
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
38
- import { BlockHash, type BlockParameter, type DataInBlock, L2Block, 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';
39
60
  import type { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
40
61
  import type {
41
62
  ContractClassPublic,
@@ -44,13 +65,14 @@ import type {
44
65
  NodeInfo,
45
66
  ProtocolContractAddresses,
46
67
  } from '@aztec/stdlib/contract';
47
- import { GasFees } from '@aztec/stdlib/gas';
68
+ import { GasFees, type ManaUsageEstimate } from '@aztec/stdlib/gas';
48
69
  import { computePublicDataTreeLeafSlot } from '@aztec/stdlib/hash';
49
70
  import {
50
71
  type AztecNode,
51
72
  type AztecNodeAdmin,
52
73
  type AztecNodeAdminConfig,
53
74
  AztecNodeAdminConfigSchema,
75
+ type AztecNodeDebug,
54
76
  type GetContractClassLogsResponse,
55
77
  type GetPublicLogsResponse,
56
78
  } from '@aztec/stdlib/interfaces/client';
@@ -63,14 +85,15 @@ import {
63
85
  type WorldStateSynchronizer,
64
86
  tryStop,
65
87
  } from '@aztec/stdlib/interfaces/server';
66
- 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';
67
90
  import { InboxLeaf, type L1ToL2MessageSource } from '@aztec/stdlib/messaging';
68
- import { P2PClientType } from '@aztec/stdlib/p2p';
69
- import type { Offense, SlashPayloadRound } from '@aztec/stdlib/slashing';
70
- 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';
71
93
  import { MerkleTreeId, NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
72
94
  import {
73
95
  type BlockHeader,
96
+ type FeeProvider,
74
97
  type GlobalVariableBuilder as GlobalVariableBuilderInterface,
75
98
  type IndexedTxEffect,
76
99
  PublicSimulationOutput,
@@ -82,6 +105,7 @@ import {
82
105
  } from '@aztec/stdlib/tx';
83
106
  import { getPackageVersion } from '@aztec/stdlib/update-checker';
84
107
  import type { SingleValidatorStats, ValidatorsStats } from '@aztec/stdlib/validators';
108
+ import type { GenesisData } from '@aztec/stdlib/world-state';
85
109
  import {
86
110
  Attributes,
87
111
  type TelemetryClient,
@@ -95,13 +119,13 @@ import {
95
119
  FullNodeCheckpointsBuilder,
96
120
  NodeKeystoreAdapter,
97
121
  ValidatorClient,
98
- createBlockProposalHandler,
122
+ createProposalHandler,
99
123
  createValidatorClient,
100
- createValidatorForAcceptingTxs,
101
124
  } from '@aztec/validator-client';
125
+ import type { SlashingProtectionDatabase } from '@aztec/validator-ha-signer/types';
102
126
  import { createWorldStateSynchronizer } from '@aztec/world-state';
103
127
 
104
- import { createPublicClient, fallback, http } from 'viem';
128
+ import { createPublicClient } from 'viem';
105
129
 
106
130
  import { createSentinel } from '../sentinel/factory.js';
107
131
  import { Sentinel } from '../sentinel/sentinel.js';
@@ -111,7 +135,7 @@ import { NodeMetrics } from './node_metrics.js';
111
135
  /**
112
136
  * The aztec node.
113
137
  */
114
- export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
138
+ export class AztecNodeService implements AztecNode, AztecNodeAdmin, AztecNodeDebug, Traceable {
115
139
  private metrics: NodeMetrics;
116
140
  private initialHeaderHashPromise: Promise<BlockHash> | undefined = undefined;
117
141
 
@@ -129,24 +153,42 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
129
153
  protected readonly l1ToL2MessageSource: L1ToL2MessageSource,
130
154
  protected readonly worldStateSynchronizer: WorldStateSynchronizer,
131
155
  protected readonly sequencer: SequencerClient | undefined,
156
+ protected readonly proverNode: ProverNode | undefined,
132
157
  protected readonly slasherClient: SlasherClientInterface | undefined,
133
158
  protected readonly validatorsSentinel: Sentinel | undefined,
134
159
  protected readonly epochPruneWatcher: EpochPruneWatcher | undefined,
135
160
  protected readonly l1ChainId: number,
136
161
  protected readonly version: number,
137
162
  protected readonly globalVariableBuilder: GlobalVariableBuilderInterface,
163
+ protected readonly feeProvider: FeeProvider,
138
164
  protected readonly epochCache: EpochCacheInterface,
139
165
  protected readonly packageVersion: string,
140
- private proofVerifier: ClientProtocolCircuitVerifier,
166
+ private peerProofVerifier: ClientProtocolCircuitVerifier,
167
+ private rpcProofVerifier: ClientProtocolCircuitVerifier,
141
168
  private telemetry: TelemetryClient = getTelemetryClient(),
142
169
  private log = createLogger('node'),
143
170
  private blobClient?: BlobClientInterface,
171
+ private validatorClient?: ValidatorClient,
172
+ private keyStoreManager?: KeystoreManager,
173
+ private debugLogStore: DebugLogStore = new NullDebugLogStore(),
144
174
  ) {
145
175
  this.metrics = new NodeMetrics(telemetry, 'AztecNodeService');
146
176
  this.tracer = telemetry.getTracer('AztecNodeService');
147
177
 
148
178
  this.log.info(`Aztec Node version: ${this.packageVersion}`);
149
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;
150
192
  }
151
193
 
152
194
  public async getWorldStateSyncStatus(): Promise<WorldStateSyncStatus> {
@@ -170,11 +212,14 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
170
212
  logger?: Logger;
171
213
  publisher?: SequencerPublisher;
172
214
  dateProvider?: DateProvider;
173
- p2pClientDeps?: P2PClientDeps<P2PClientType.Full>;
215
+ p2pClientDeps?: P2PClientDeps;
216
+ proverNodeDeps?: Partial<ProverNodeDeps>;
217
+ slashingProtectionDb?: SlashingProtectionDatabase;
174
218
  } = {},
175
219
  options: {
176
- prefilledPublicData?: PublicDataTreeLeaf[];
220
+ genesis?: GenesisData;
177
221
  dontStartSequencer?: boolean;
222
+ dontStartProverNode?: boolean;
178
223
  } = {},
179
224
  ): Promise<AztecNodeService> {
180
225
  const config = { ...inputConfig }; // Copy the config so we dont mutate the input object
@@ -184,16 +229,29 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
184
229
  const dateProvider = deps.dateProvider ?? new DateProvider();
185
230
  const ethereumChain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
186
231
 
187
- // 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.
188
234
  let keyStoreManager: KeystoreManager | undefined;
189
235
  const keyStoreProvided = config.keyStoreDirectory !== undefined && config.keyStoreDirectory.length > 0;
190
236
  if (keyStoreProvided) {
191
237
  const keyStores = loadKeystores(config.keyStoreDirectory!);
192
238
  keyStoreManager = new KeystoreManager(mergeKeystores(keyStores));
193
239
  } else {
194
- const keyStore = createKeyStoreForValidator(config);
195
- if (keyStore) {
196
- 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
+ );
197
255
  }
198
256
  }
199
257
 
@@ -204,10 +262,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
204
262
  if (keyStoreManager === undefined) {
205
263
  throw new Error('Failed to create key store, a requirement for running a validator');
206
264
  }
207
- if (!keyStoreProvided) {
208
- log.warn(
209
- 'KEY STORE CREATED FROM ENVIRONMENT, IT IS RECOMMENDED TO USE A FILE-BASED KEY STORE IN PRODUCTION ENVIRONMENTS',
210
- );
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");
211
267
  }
212
268
  ValidatorClient.validateKeyStoreConfiguration(keyStoreManager, log);
213
269
  }
@@ -221,7 +277,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
221
277
 
222
278
  const publicClient = createPublicClient({
223
279
  chain: ethereumChain.chainInfo,
224
- transport: fallback(config.l1RpcUrls.map((url: string) => http(url, { batch: false }))),
280
+ transport: makeL1HttpTransport(config.l1RpcUrls, { timeout: config.l1HttpTimeoutMS }),
225
281
  pollingInterval: config.viemPollingIntervalMS,
226
282
  });
227
283
 
@@ -235,10 +291,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
235
291
  config.l1Contracts = { ...config.l1Contracts, ...l1ContractsAddresses };
236
292
 
237
293
  const rollupContract = new RollupContract(publicClient, config.l1Contracts.rollupAddress.toString());
238
- const [l1GenesisTime, slotDuration, rollupVersionFromRollup] = await Promise.all([
294
+ const [l1GenesisTime, slotDuration, rollupVersionFromRollup, rollupManaLimit] = await Promise.all([
239
295
  rollupContract.getL1GenesisTime(),
240
296
  rollupContract.getSlotDuration(),
241
297
  rollupContract.getVersion(),
298
+ rollupContract.getManaLimit().then(Number),
242
299
  ] as const);
243
300
 
244
301
  config.rollupVersion ??= Number(rollupVersionFromRollup);
@@ -249,247 +306,351 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
249
306
  );
250
307
  }
251
308
 
252
- const blobClient = await createBlobClientWithFileStores(config, createLogger('node:blob-client:client'));
309
+ const blobClient = await createBlobClientWithFileStores(config, log.createChild('blob-client'));
253
310
 
254
311
  // attempt snapshot sync if possible
255
312
  await trySnapshotSync(config, log);
256
313
 
257
314
  const epochCache = await EpochCache.create(config.l1Contracts.rollupAddress, config, { dateProvider });
258
315
 
259
- const archiver = await createArchiver(
260
- config,
261
- { blobClient, epochCache, telemetry, dateProvider },
262
- { blockUntilSync: !config.skipArchiverInitialSync },
263
- );
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);
264
341
 
265
- // now create the merkle trees and the world state synchronizer
266
- const worldStateSynchronizer = await createWorldStateSynchronizer(
267
- config,
268
- archiver,
269
- options.prefilledPublicData,
270
- telemetry,
271
- );
272
- const circuitVerifier =
273
- config.realProofs || config.debugForceTxProofVerification
274
- ? await BBCircuitVerifier.new(config)
275
- : new TestCircuitVerifier(config.proverTestVerificationDelayMs);
276
- if (!config.realProofs) {
277
- log.warn(`Aztec node is accepting fake proofs`);
278
- }
279
- const proofVerifier = new QueuedIVCVerifier(config, circuitVerifier);
280
-
281
- // create the tx pool and the p2p client, which will need the l2 block source
282
- const p2pClient = await createP2PClient(
283
- P2PClientType.Full,
284
- config,
285
- archiver,
286
- proofVerifier,
287
- worldStateSynchronizer,
288
- epochCache,
289
- packageVersion,
290
- dateProvider,
291
- telemetry,
292
- deps.p2pClientDeps,
293
- );
342
+ let debugLogStore: DebugLogStore;
343
+ if (!config.realProofs) {
344
+ log.warn(`Aztec node is accepting fake proofs`);
294
345
 
295
- // We should really not be modifying the config object
296
- 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
+ }
297
353
 
298
- // Create FullNodeCheckpointsBuilder for validator and non-validator block proposal handling
299
- const validatorCheckpointsBuilder = new FullNodeCheckpointsBuilder(
300
- { ...config, l1GenesisTime, slotDuration: Number(slotDuration) },
301
- worldStateSynchronizer,
302
- archiver,
303
- dateProvider,
304
- telemetry,
305
- );
354
+ const globalVariableBuilderConfig = {
355
+ l1Contracts: config.l1Contracts,
356
+ ethereumSlotDuration: config.ethereumSlotDuration,
357
+ rollupVersion: BigInt(config.rollupVersion),
358
+ l1GenesisTime,
359
+ slotDuration: Number(slotDuration),
360
+ };
306
361
 
307
- // We'll accumulate sentinel watchers here
308
- const watchers: Watcher[] = [];
309
-
310
- // Create validator client if required
311
- const validatorClient = await createValidatorClient(config, {
312
- checkpointsBuilder: validatorCheckpointsBuilder,
313
- worldState: worldStateSynchronizer,
314
- p2pClient,
315
- telemetry,
316
- dateProvider,
317
- epochCache,
318
- blockSource: archiver,
319
- l1ToL2MessageSource: archiver,
320
- keyStoreManager,
321
- blobClient,
322
- });
362
+ const globalVariableBuilder = new GlobalVariableBuilder(dateProvider, publicClient, globalVariableBuilderConfig);
363
+ const feeProvider = new FeeProviderImpl(dateProvider, publicClient, globalVariableBuilderConfig);
323
364
 
324
- // If we have a validator client, register it as a source of offenses for the slasher,
325
- // and have it register callbacks on the p2p client *before* we start it, otherwise messages
326
- // like attestations or auths will fail.
327
- if (validatorClient) {
328
- watchers.push(validatorClient);
329
- if (!options.dontStartSequencer) {
330
- 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');
331
368
  }
332
- }
333
369
 
334
- // If there's no validator client but alwaysReexecuteBlockProposals is enabled,
335
- // create a BlockProposalHandler to reexecute block proposals for monitoring
336
- if (!validatorClient && config.alwaysReexecuteBlockProposals) {
337
- log.info('Setting up block proposal reexecution for monitoring');
338
- createBlockProposalHandler(config, {
339
- checkpointsBuilder: validatorCheckpointsBuilder,
340
- 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,
341
376
  epochCache,
342
- blockSource: archiver,
343
- l1ToL2MessageSource: archiver,
344
- p2pClient,
377
+ feeProvider,
378
+ packageVersion,
345
379
  dateProvider,
346
380
  telemetry,
347
- }).registerForReexecution(p2pClient);
348
- }
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
+ );
349
403
 
350
- // Start world state and wait for it to sync to the archiver.
351
- 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
+ }
352
437
 
353
- // Start p2p. Note that it depends on world state to be running.
354
- 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
+ }
355
457
 
356
- const validatorsSentinel = await createSentinel(epochCache, archiver, p2pClient, config);
357
- if (validatorsSentinel && config.slashInactivityPenalty > 0n) {
358
- watchers.push(validatorsSentinel);
359
- }
458
+ // Start world state and wait for it to sync to the archiver.
459
+ await worldStateSynchronizer.start();
360
460
 
361
- let epochPruneWatcher: EpochPruneWatcher | undefined;
362
- if (config.slashPrunePenalty > 0n || config.slashDataWithholdingPenalty > 0n) {
363
- epochPruneWatcher = new EpochPruneWatcher(
364
- archiver,
365
- archiver,
366
- epochCache,
367
- p2pClient.getTxProvider(),
368
- validatorCheckpointsBuilder,
369
- config,
370
- );
371
- watchers.push(epochPruneWatcher);
372
- }
461
+ // Start p2p. Note that it depends on world state to be running.
462
+ await p2pClient.start();
373
463
 
374
- // We assume we want to slash for invalid attestations unless all max penalties are set to 0
375
- let attestationsBlockWatcher: AttestationsBlockWatcher | undefined;
376
- if (config.slashProposeInvalidAttestationsPenalty > 0n || config.slashAttestDescendantOfInvalidPenalty > 0n) {
377
- attestationsBlockWatcher = new AttestationsBlockWatcher(archiver, epochCache, config);
378
- watchers.push(attestationsBlockWatcher);
379
- }
464
+ let validatorsSentinel: Awaited<ReturnType<typeof createSentinel>> | undefined;
465
+ let epochPruneWatcher: EpochPruneWatcher | undefined;
466
+ let attestationsBlockWatcher: AttestationsBlockWatcher | undefined;
380
467
 
381
- // Start p2p-related services once the archiver has completed sync
382
- void archiver
383
- .waitForInitialSync()
384
- .then(async () => {
385
- await p2pClient.start();
386
- await validatorsSentinel?.start();
387
- await epochPruneWatcher?.start();
388
- await attestationsBlockWatcher?.start();
389
- log.info(`All p2p services started`);
390
- })
391
- .catch(err => log.error('Failed to start p2p services after archiver sync', err));
392
-
393
- // Validator enabled, create/start relevant service
394
- let sequencer: SequencerClient | undefined;
395
- let slasherClient: SlasherClientInterface | undefined;
396
- if (!config.disableValidator && validatorClient) {
397
- // We create a slasher only if we have a sequencer, since all slashing actions go through the sequencer publisher
398
- // as they are executed when the node is selected as proposer.
399
- const validatorAddresses = keyStoreManager
400
- ? NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager).getAddresses()
401
- : [];
402
-
403
- slasherClient = await createSlasher(
404
- config,
405
- config.l1Contracts,
406
- getPublicClient(config),
407
- watchers,
408
- dateProvider,
409
- epochCache,
410
- validatorAddresses,
411
- undefined, // logger
412
- );
413
- 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
+ }
414
473
 
415
- const l1TxUtils = config.publisherForwarderAddress
416
- ? await createForwarderL1TxUtilsFromEthSigner(
417
- publicClient,
418
- keyStoreManager!.createAllValidatorPublisherSigners(),
419
- config.publisherForwarderAddress,
420
- { ...config, scope: 'sequencer' },
421
- { telemetry, logger: log.createChild('l1-tx-utils'), dateProvider },
422
- )
423
- : 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(
424
547
  publicClient,
425
- keyStoreManager!.createAllValidatorPublisherSigners(),
548
+ [fundingSigner],
426
549
  { ...config, scope: 'sequencer' },
427
- { telemetry, logger: log.createChild('l1-tx-utils'), dateProvider },
550
+ { telemetry, logger: log.createChild('l1-tx-utils:funder'), dateProvider },
428
551
  );
552
+ funderL1TxUtils = funder;
553
+ }
429
554
 
430
- // Create and start the sequencer client
431
- const checkpointsBuilder = new CheckpointsBuilder(
432
- { ...config, l1GenesisTime, slotDuration: Number(slotDuration) },
433
- worldStateSynchronizer,
434
- archiver,
435
- dateProvider,
436
- telemetry,
437
- );
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
+ );
438
564
 
439
- sequencer = await SequencerClient.new(config, {
440
- ...deps,
441
- epochCache,
442
- l1TxUtils,
443
- 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,
444
619
  p2pClient,
620
+ archiver,
621
+ archiver,
622
+ archiver,
623
+ archiver,
445
624
  worldStateSynchronizer,
625
+ sequencer,
626
+ proverNode,
446
627
  slasherClient,
447
- checkpointsBuilder,
448
- l2BlockSource: archiver,
449
- 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,
450
638
  telemetry,
451
- dateProvider,
639
+ log,
452
640
  blobClient,
453
- nodeKeyStore: keyStoreManager!,
454
- });
455
- }
641
+ validatorClient,
642
+ keyStoreManager,
643
+ debugLogStore,
644
+ );
456
645
 
457
- if (!options.dontStartSequencer && sequencer) {
458
- await sequencer.start();
459
- log.verbose(`Sequencer started`);
460
- } else if (sequencer) {
461
- 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;
462
653
  }
463
-
464
- const globalVariableBuilder = new GlobalVariableBuilder({
465
- ...config,
466
- rollupVersion: BigInt(config.rollupVersion),
467
- l1GenesisTime,
468
- slotDuration: Number(slotDuration),
469
- });
470
-
471
- return new AztecNodeService(
472
- config,
473
- p2pClient,
474
- archiver,
475
- archiver,
476
- archiver,
477
- archiver,
478
- worldStateSynchronizer,
479
- sequencer,
480
- slasherClient,
481
- validatorsSentinel,
482
- epochPruneWatcher,
483
- ethereumChain.chainInfo.id,
484
- config.rollupVersion,
485
- globalVariableBuilder,
486
- epochCache,
487
- packageVersion,
488
- proofVerifier,
489
- telemetry,
490
- log,
491
- blobClient,
492
- );
493
654
  }
494
655
 
495
656
  /**
@@ -500,6 +661,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
500
661
  return this.sequencer;
501
662
  }
502
663
 
664
+ /** Returns the prover node subsystem, if enabled. */
665
+ public getProverNode(): ProverNode | undefined {
666
+ return this.proverNode;
667
+ }
668
+
503
669
  public getBlockSource(): L2BlockSource {
504
670
  return this.blockSource;
505
671
  }
@@ -525,7 +691,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
525
691
  }
526
692
 
527
693
  public async getAllowedPublicSetup(): Promise<AllowedElement[]> {
528
- return this.config.txPublicSetupAllowList ?? (await getDefaultAllowedSetupFunctions());
694
+ return [...(await getDefaultAllowedSetupFunctions()), ...(this.config.txPublicSetupAllowListExtend ?? [])];
529
695
  }
530
696
 
531
697
  /**
@@ -620,12 +786,17 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
620
786
  return (await this.blockSource.getCheckpointedBlocks(from, limit)) ?? [];
621
787
  }
622
788
 
623
- /**
624
- * Method to fetch the current min L2 fees.
625
- * @returns The current min L2 fees.
626
- */
789
+ public getCheckpointsDataForEpoch(epochNumber: EpochNumber) {
790
+ return this.blockSource.getCheckpointsDataForEpoch(epochNumber);
791
+ }
792
+
627
793
  public async getCurrentMinFees(): Promise<GasFees> {
628
- 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);
629
800
  }
630
801
 
631
802
  public async getMaxPriorityFees(): Promise<GasFees> {
@@ -652,6 +823,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
652
823
  return await this.blockSource.getCheckpointedL2BlockNumber();
653
824
  }
654
825
 
826
+ public getCheckpointNumber(): Promise<CheckpointNumber> {
827
+ return this.blockSource.getCheckpointNumber();
828
+ }
829
+
655
830
  /**
656
831
  * Method to fetch the version of the package.
657
832
  * @returns The node package version
@@ -689,18 +864,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
689
864
  page?: number,
690
865
  referenceBlock?: BlockHash,
691
866
  ): Promise<TxScopedL2Log[][]> {
867
+ let upToBlockNumber: BlockNumber | undefined;
692
868
  if (referenceBlock) {
693
869
  const initialBlockHash = await this.#getInitialHeaderHash();
694
- if (!referenceBlock.equals(initialBlockHash)) {
870
+ if (referenceBlock.equals(initialBlockHash)) {
871
+ upToBlockNumber = BlockNumber(0);
872
+ } else {
695
873
  const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
696
874
  if (!header) {
697
875
  throw new Error(
698
876
  `Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
699
877
  );
700
878
  }
879
+ upToBlockNumber = header.globalVariables.blockNumber;
701
880
  }
702
881
  }
703
- return this.logsSource.getPrivateLogsByTags(tags, page);
882
+ return this.logsSource.getPrivateLogsByTags(tags, page, upToBlockNumber);
704
883
  }
705
884
 
706
885
  public async getPublicLogsByTagsFromContract(
@@ -709,18 +888,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
709
888
  page?: number,
710
889
  referenceBlock?: BlockHash,
711
890
  ): Promise<TxScopedL2Log[][]> {
891
+ let upToBlockNumber: BlockNumber | undefined;
712
892
  if (referenceBlock) {
713
893
  const initialBlockHash = await this.#getInitialHeaderHash();
714
- if (!referenceBlock.equals(initialBlockHash)) {
894
+ if (referenceBlock.equals(initialBlockHash)) {
895
+ upToBlockNumber = BlockNumber(0);
896
+ } else {
715
897
  const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
716
898
  if (!header) {
717
899
  throw new Error(
718
900
  `Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
719
901
  );
720
902
  }
903
+ upToBlockNumber = header.globalVariables.blockNumber;
721
904
  }
722
905
  }
723
- return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page);
906
+ return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page, upToBlockNumber);
724
907
  }
725
908
 
726
909
  /**
@@ -762,8 +945,9 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
762
945
  }
763
946
 
764
947
  await this.p2pClient!.sendTx(tx);
765
- this.metrics.receivedTx(timer.ms(), true);
766
- 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 });
767
951
  }
768
952
 
769
953
  public async getTxReceipt(txHash: TxHash): Promise<TxReceipt> {
@@ -775,18 +959,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
775
959
  // Then get the actual tx from the archiver, which tracks every tx in a mined block.
776
960
  const settledTxReceipt = await this.blockSource.getSettledTxReceipt(txHash);
777
961
 
962
+ let receipt: TxReceipt;
778
963
  if (settledTxReceipt) {
779
- // If the archiver has the receipt then return it.
780
- return settledTxReceipt;
964
+ receipt = settledTxReceipt;
781
965
  } else if (isKnownToPool) {
782
966
  // If the tx is in the pool but not in the archiver, it's pending.
783
967
  // This handles race conditions between archiver and p2p, where the archiver
784
968
  // has pruned the block in which a tx was mined, but p2p has not caught up yet.
785
- return new TxReceipt(txHash, TxStatus.PENDING, undefined, undefined);
969
+ receipt = new TxReceipt(txHash, TxStatus.PENDING, undefined, undefined);
786
970
  } else {
787
971
  // Otherwise, if we don't know the tx, we consider it dropped.
788
- 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');
789
973
  }
974
+
975
+ this.debugLogStore.decorateReceiptWithLogs(txHash.toString(), receipt);
976
+
977
+ return receipt;
790
978
  }
791
979
 
792
980
  public getTxEffect(txHash: TxHash): Promise<IndexedTxEffect | undefined> {
@@ -801,8 +989,9 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
801
989
  await tryStop(this.validatorsSentinel);
802
990
  await tryStop(this.epochPruneWatcher);
803
991
  await tryStop(this.slasherClient);
804
- await tryStop(this.proofVerifier);
992
+ await Promise.all([tryStop(this.peerProofVerifier), tryStop(this.rpcProofVerifier)]);
805
993
  await tryStop(this.sequencer);
994
+ await tryStop(this.proverNode);
806
995
  await tryStop(this.p2pClient);
807
996
  await tryStop(this.worldStateSynchronizer);
808
997
  await tryStop(this.blockSource);
@@ -856,59 +1045,65 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
856
1045
  treeId: MerkleTreeId,
857
1046
  leafValues: Fr[],
858
1047
  ): Promise<(DataInBlock<bigint> | undefined)[]> {
859
- const committedDb = await this.#getWorldState(referenceBlock);
1048
+ const committedDb = await this.getWorldState(referenceBlock);
860
1049
  const maybeIndices = await committedDb.findLeafIndices(
861
1050
  treeId,
862
1051
  leafValues.map(x => x.toBuffer()),
863
1052
  );
864
- // We filter out undefined values
865
- 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);
866
1055
 
867
- // Now we find the block numbers for the indices
868
- 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);
869
1058
 
870
- // If any of the block numbers are undefined, we throw an error.
871
- for (let i = 0; i < indices.length; i++) {
872
- if (blockNumbers[i] === undefined) {
873
- 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
+ );
874
1067
  }
1068
+ indexToBlockNumber.set(definedIndices[i], blockNumber);
875
1069
  }
876
1070
 
877
1071
  // Get unique block numbers in order to optimize num calls to getLeafValue function.
878
- const uniqueBlockNumbers = [...new Set(blockNumbers.filter(x => x !== undefined))];
1072
+ const uniqueBlockNumbers = [...new Set(indexToBlockNumber.values())];
879
1073
 
880
- // Now we obtain the block hashes from the archive tree by calling await `committedDb.getLeafValue(treeId, index)`
881
- // (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).
882
1075
  const blockHashes = await Promise.all(
883
1076
  uniqueBlockNumbers.map(blockNumber => {
884
1077
  return committedDb.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
885
1078
  }),
886
1079
  );
887
1080
 
888
- // 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>();
889
1083
  for (let i = 0; i < uniqueBlockNumbers.length; i++) {
890
- if (blockHashes[i] === undefined) {
1084
+ const blockHash = blockHashes[i];
1085
+ if (blockHash === undefined) {
891
1086
  throw new Error(`Block hash is undefined for block number ${uniqueBlockNumbers[i]}`);
892
1087
  }
1088
+ blockNumberToHash.set(uniqueBlockNumbers[i], blockHash);
893
1089
  }
894
1090
 
895
1091
  // Create DataInBlock objects by combining indices, blockNumbers and blockHashes and return them.
896
- return maybeIndices.map((index, i) => {
1092
+ return maybeIndices.map(index => {
897
1093
  if (index === undefined) {
898
1094
  return undefined;
899
1095
  }
900
- const blockNumber = blockNumbers[i];
1096
+ const blockNumber = indexToBlockNumber.get(index);
901
1097
  if (blockNumber === undefined) {
902
- return undefined;
1098
+ throw new Error(`Block number not found for leaf index ${index} in tree ${MerkleTreeId[treeId]}`);
903
1099
  }
904
- const blockHashIndex = uniqueBlockNumbers.indexOf(blockNumber);
905
- const blockHash = blockHashes[blockHashIndex];
906
- if (!blockHash) {
907
- return undefined;
1100
+ const l2BlockHash = blockNumberToHash.get(blockNumber);
1101
+ if (l2BlockHash === undefined) {
1102
+ throw new Error(`Block hash not found for block number ${blockNumber}`);
908
1103
  }
909
1104
  return {
910
- l2BlockNumber: BlockNumber(Number(blockNumber)),
911
- l2BlockHash: new BlockHash(blockHash),
1105
+ l2BlockNumber: blockNumber,
1106
+ l2BlockHash,
912
1107
  data: index,
913
1108
  };
914
1109
  });
@@ -918,7 +1113,15 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
918
1113
  referenceBlock: BlockParameter,
919
1114
  blockHash: BlockHash,
920
1115
  ): Promise<MembershipWitness<typeof ARCHIVE_HEIGHT> | undefined> {
921
- const committedDb = await this.#getWorldState(referenceBlock);
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));
922
1125
  const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.ARCHIVE>(MerkleTreeId.ARCHIVE, [blockHash]);
923
1126
  return pathAndIndex === undefined
924
1127
  ? undefined
@@ -929,7 +1132,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
929
1132
  referenceBlock: BlockParameter,
930
1133
  noteHash: Fr,
931
1134
  ): Promise<MembershipWitness<typeof NOTE_HASH_TREE_HEIGHT> | undefined> {
932
- const committedDb = await this.#getWorldState(referenceBlock);
1135
+ const committedDb = await this.getWorldState(referenceBlock);
933
1136
  const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.NOTE_HASH_TREE>(
934
1137
  MerkleTreeId.NOTE_HASH_TREE,
935
1138
  [noteHash],
@@ -943,7 +1146,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
943
1146
  referenceBlock: BlockParameter,
944
1147
  l1ToL2Message: Fr,
945
1148
  ): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>] | undefined> {
946
- const db = await this.#getWorldState(referenceBlock);
1149
+ const db = await this.getWorldState(referenceBlock);
947
1150
  const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [l1ToL2Message]);
948
1151
  if (!witness) {
949
1152
  return undefined;
@@ -953,11 +1156,9 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
953
1156
  return [witness.index, witness.path];
954
1157
  }
955
1158
 
956
- public async getL1ToL2MessageBlock(l1ToL2Message: Fr): Promise<BlockNumber | undefined> {
1159
+ public async getL1ToL2MessageCheckpoint(l1ToL2Message: Fr): Promise<CheckpointNumber | undefined> {
957
1160
  const messageIndex = await this.l1ToL2MessageSource.getL1ToL2MessageIndex(l1ToL2Message);
958
- return messageIndex
959
- ? BlockNumber.fromCheckpointNumber(InboxLeaf.checkpointNumberFromIndex(messageIndex))
960
- : undefined;
1161
+ return messageIndex ? InboxLeaf.checkpointNumberFromIndex(messageIndex) : undefined;
961
1162
  }
962
1163
 
963
1164
  /**
@@ -978,19 +1179,9 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
978
1179
  public async getL2ToL1Messages(epoch: EpochNumber): Promise<Fr[][][][]> {
979
1180
  // Assumes `getCheckpointedBlocksForEpoch` returns blocks in ascending order of block number.
980
1181
  const checkpointedBlocks = await this.blockSource.getCheckpointedBlocksForEpoch(epoch);
981
- const blocksInCheckpoints: L2Block[][] = [];
982
- let previousSlotNumber = SlotNumber.ZERO;
983
- let checkpointIndex = -1;
984
- for (const checkpointedBlock of checkpointedBlocks) {
985
- const block = checkpointedBlock.block;
986
- const slotNumber = block.header.globalVariables.slotNumber;
987
- if (slotNumber !== previousSlotNumber) {
988
- checkpointIndex++;
989
- blocksInCheckpoints.push([]);
990
- previousSlotNumber = slotNumber;
991
- }
992
- blocksInCheckpoints[checkpointIndex].push(block);
993
- }
1182
+ const blocksInCheckpoints = chunkBy(checkpointedBlocks, cb => cb.block.header.globalVariables.slotNumber).map(
1183
+ group => group.map(cb => cb.block),
1184
+ );
994
1185
  return blocksInCheckpoints.map(blocks =>
995
1186
  blocks.map(block => block.body.txEffects.map(txEffect => txEffect.l2ToL1Msgs)),
996
1187
  );
@@ -1000,7 +1191,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1000
1191
  referenceBlock: BlockParameter,
1001
1192
  nullifier: Fr,
1002
1193
  ): Promise<NullifierMembershipWitness | undefined> {
1003
- const db = await this.#getWorldState(referenceBlock);
1194
+ const db = await this.getWorldState(referenceBlock);
1004
1195
  const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [nullifier.toBuffer()]);
1005
1196
  if (!witness) {
1006
1197
  return undefined;
@@ -1015,33 +1206,20 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1015
1206
  return new NullifierMembershipWitness(index, leafPreimage as NullifierLeafPreimage, path);
1016
1207
  }
1017
1208
 
1018
- /**
1019
- * Returns a low nullifier membership witness for a given nullifier at a given block.
1020
- * @param referenceBlock - The block parameter (block number, block hash, or 'latest') at which to get the data
1021
- * (which contains the root of the nullifier tree in which we are searching for the nullifier).
1022
- * @param nullifier - Nullifier we try to find the low nullifier witness for.
1023
- * @returns The low nullifier membership witness (if found).
1024
- * @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
1025
- * list structure" of leaves and proving that a lower nullifier is pointing to a bigger next value than the nullifier
1026
- * we are trying to prove non-inclusion for.
1027
- *
1028
- * Note: This function returns the membership witness of the nullifier itself and not the low nullifier when
1029
- * the nullifier already exists in the tree. This is because the `getPreviousValueIndex` function returns the
1030
- * index of the nullifier itself when it already exists in the tree.
1031
- * TODO: This is a confusing behavior and we should eventually address that.
1032
- */
1033
1209
  public async getLowNullifierMembershipWitness(
1034
1210
  referenceBlock: BlockParameter,
1035
1211
  nullifier: Fr,
1036
1212
  ): Promise<NullifierMembershipWitness | undefined> {
1037
- const committedDb = await this.#getWorldState(referenceBlock);
1213
+ const committedDb = await this.getWorldState(referenceBlock);
1038
1214
  const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
1039
1215
  if (!findResult) {
1040
1216
  return undefined;
1041
1217
  }
1042
1218
  const { index, alreadyPresent } = findResult;
1043
1219
  if (alreadyPresent) {
1044
- 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
+ );
1045
1223
  }
1046
1224
  const preimageData = (await committedDb.getLeafPreimage(MerkleTreeId.NULLIFIER_TREE, index))!;
1047
1225
 
@@ -1050,7 +1228,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1050
1228
  }
1051
1229
 
1052
1230
  async getPublicDataWitness(referenceBlock: BlockParameter, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
1053
- const committedDb = await this.#getWorldState(referenceBlock);
1231
+ const committedDb = await this.getWorldState(referenceBlock);
1054
1232
  const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
1055
1233
  if (!lowLeafResult) {
1056
1234
  return undefined;
@@ -1065,7 +1243,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1065
1243
  }
1066
1244
 
1067
1245
  public async getPublicStorageAt(referenceBlock: BlockParameter, contract: AztecAddress, slot: Fr): Promise<Fr> {
1068
- const committedDb = await this.#getWorldState(referenceBlock);
1246
+ const committedDb = await this.getWorldState(referenceBlock);
1069
1247
  const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
1070
1248
 
1071
1249
  const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
@@ -1106,6 +1284,14 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1106
1284
  return await this.blockSource.getBlockHeaderByArchive(archive);
1107
1285
  }
1108
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
+
1109
1295
  /**
1110
1296
  * Simulates the public part of a transaction with the current state.
1111
1297
  * @param tx - The transaction to simulate.
@@ -1129,7 +1315,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1129
1315
  }
1130
1316
 
1131
1317
  const txHash = tx.getTxHash();
1132
- const blockNumber = BlockNumber((await this.blockSource.getBlockNumber()) + 1);
1318
+ const latestBlockNumber = await this.blockSource.getBlockNumber();
1319
+ const blockNumber = BlockNumber.add(latestBlockNumber, 1);
1133
1320
 
1134
1321
  // If sequencer is not initialized, we just set these values to zero for simulation.
1135
1322
  const coinbase = EthAddress.ZERO;
@@ -1153,6 +1340,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1153
1340
  blockNumber,
1154
1341
  });
1155
1342
 
1343
+ // Ensure world-state has caught up with the latest block we loaded from the archiver
1344
+ await this.worldStateSynchronizer.syncImmediate(latestBlockNumber);
1156
1345
  const merkleTreeFork = await this.worldStateSynchronizer.fork();
1157
1346
  try {
1158
1347
  const config = PublicSimulatorConfig.from({
@@ -1168,7 +1357,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1168
1357
  const processor = publicProcessorFactory.create(merkleTreeFork, newGlobalVariables, config);
1169
1358
 
1170
1359
  // REFACTOR: Consider merging ProcessReturnValues into ProcessedTx
1171
- const [processedTxs, failedTxs, _usedTxs, returns] = await processor.process([tx]);
1360
+ const [processedTxs, failedTxs, _usedTxs, returns, debugLogs] = await processor.process([tx]);
1172
1361
  // REFACTOR: Consider returning the error rather than throwing
1173
1362
  if (failedTxs.length) {
1174
1363
  this.log.warn(`Simulated tx ${txHash} fails: ${failedTxs[0].error}`, { txHash });
@@ -1182,6 +1371,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1182
1371
  processedTx.txEffect,
1183
1372
  returns,
1184
1373
  processedTx.gasUsed,
1374
+ debugLogs,
1185
1375
  );
1186
1376
  } finally {
1187
1377
  await merkleTreeFork.close();
@@ -1193,12 +1383,13 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1193
1383
  { isSimulation, skipFeeEnforcement }: { isSimulation?: boolean; skipFeeEnforcement?: boolean } = {},
1194
1384
  ): Promise<TxValidationResult> {
1195
1385
  const db = this.worldStateSynchronizer.getCommitted();
1196
- const verifier = isSimulation ? undefined : this.proofVerifier;
1386
+ const verifier = isSimulation ? undefined : this.rpcProofVerifier;
1197
1387
 
1198
- // 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)
1199
1389
  const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
1200
1390
  const blockNumber = BlockNumber((await this.blockSource.getBlockNumber()) + 1);
1201
- const validator = createValidatorForAcceptingTxs(
1391
+ const l1Constants = await this.blockSource.getL1Constants();
1392
+ const validator = createTxValidatorForAcceptingTxsOverRPC(
1202
1393
  db,
1203
1394
  this.contractDataSource,
1204
1395
  verifier,
@@ -1207,10 +1398,16 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1207
1398
  blockNumber,
1208
1399
  l1ChainId: this.l1ChainId,
1209
1400
  rollupVersion: this.version,
1210
- setupAllowList: this.config.txPublicSetupAllowList ?? (await getDefaultAllowedSetupFunctions()),
1401
+ setupAllowList: [
1402
+ ...(await getDefaultAllowedSetupFunctions()),
1403
+ ...(this.config.txPublicSetupAllowListExtend ?? []),
1404
+ ],
1211
1405
  gasFees: await this.getCurrentMinFees(),
1212
1406
  skipFeeEnforcement,
1213
1407
  txsPermitted: !this.config.disableTransactions,
1408
+ rollupManaLimit: l1Constants.rollupManaLimit,
1409
+ maxBlockL2Gas: this.config.validateMaxL2BlockGas,
1410
+ maxBlockDAGas: this.config.validateMaxDABlockGas,
1214
1411
  },
1215
1412
  this.log.getBindings(),
1216
1413
  );
@@ -1235,7 +1432,15 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1235
1432
  archiver.updateConfig(config);
1236
1433
  }
1237
1434
  if (newConfig.realProofs !== this.config.realProofs) {
1238
- 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
+ }
1239
1444
  }
1240
1445
 
1241
1446
  this.config = newConfig;
@@ -1310,7 +1515,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1310
1515
  return Promise.resolve();
1311
1516
  }
1312
1517
 
1313
- public async rollbackTo(targetBlock: BlockNumber, force?: boolean): Promise<void> {
1518
+ public async rollbackTo(targetBlock: BlockNumber, force?: boolean, resumeSync = true): Promise<void> {
1314
1519
  const archiver = this.blockSource as Archiver;
1315
1520
  if (!('rollbackTo' in archiver)) {
1316
1521
  throw new Error('Archiver implementation does not support rollbacks.');
@@ -1340,9 +1545,13 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1340
1545
  this.log.error(`Error during rollback`, err);
1341
1546
  throw err;
1342
1547
  } finally {
1343
- this.log.info(`Resuming world state and archiver sync.`);
1344
- this.worldStateSynchronizer.resumeSync();
1345
- 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
+ }
1346
1555
  }
1347
1556
  }
1348
1557
 
@@ -1359,24 +1568,139 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1359
1568
  return Promise.resolve();
1360
1569
  }
1361
1570
 
1362
- public getSlashPayloads(): Promise<SlashPayloadRound[]> {
1363
- if (!this.slasherClient) {
1364
- throw new Error(`Slasher client not enabled`);
1365
- }
1366
- return this.slasherClient.getSlashPayloads();
1367
- }
1368
-
1369
1571
  public getSlashOffenses(round: bigint | 'all' | 'current'): Promise<Offense[]> {
1370
1572
  if (!this.slasherClient) {
1371
1573
  throw new Error(`Slasher client not enabled`);
1372
1574
  }
1373
1575
  if (round === 'all') {
1374
- return this.slasherClient.getPendingOffenses();
1576
+ return this.slasherClient.getOffenses();
1375
1577
  } else {
1376
1578
  return this.slasherClient.gatherOffensesForRound(round === 'current' ? undefined : BigInt(round));
1377
1579
  }
1378
1580
  }
1379
1581
 
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
+
1380
1704
  #getInitialHeaderHash(): Promise<BlockHash> {
1381
1705
  if (!this.initialHeaderHashPromise) {
1382
1706
  this.initialHeaderHashPromise = this.worldStateSynchronizer.getCommitted().getInitialHeader().hash();
@@ -1389,7 +1713,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1389
1713
  * @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
1390
1714
  * @returns An instance of a committed MerkleTreeOperations
1391
1715
  */
1392
- async #getWorldState(block: BlockParameter) {
1716
+ protected async getWorldState(block: BlockParameter) {
1393
1717
  let blockSyncedTo: BlockNumber = BlockNumber.ZERO;
1394
1718
  try {
1395
1719
  // Attempt to sync the world state if necessary
@@ -1403,35 +1727,67 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1403
1727
  return this.worldStateSynchronizer.getCommitted();
1404
1728
  }
1405
1729
 
1730
+ // Get the block number, either directly from the parameter or by quering the archiver with the block hash
1731
+ let blockNumber: BlockNumber;
1406
1732
  if (BlockHash.isBlockHash(block)) {
1407
1733
  const initialBlockHash = await this.#getInitialHeaderHash();
1408
1734
  if (block.equals(initialBlockHash)) {
1409
- // Block source doesn't handle initial header so we need to handle the case separately.
1410
- 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();
1411
1747
  }
1748
+ } else {
1749
+ blockNumber = block as BlockNumber;
1750
+ }
1412
1751
 
1413
- const header = await this.blockSource.getBlockHeaderByHash(block);
1414
- 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();
1415
1765
  throw new Error(
1416
- `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.`,
1417
1767
  );
1418
1768
  }
1419
- const blockNumber = header.getBlockNumber();
1420
- this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
1421
- return this.worldStateSynchronizer.getSnapshot(blockNumber);
1422
1769
  }
1423
1770
 
1424
- // Block number provided
1425
- {
1426
- const blockNumber = block as BlockNumber;
1771
+ return snapshot;
1772
+ }
1427
1773
 
1428
- if (blockNumber > blockSyncedTo) {
1429
- 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;
1430
1783
  }
1431
-
1432
- this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
1433
- 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();
1434
1789
  }
1790
+ return block as BlockNumber;
1435
1791
  }
1436
1792
 
1437
1793
  /**