@aztec/aztec-node 0.0.1-commit.9b94fc1 → 0.0.1-commit.9badcec54

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