@aztec/aztec-node 0.0.1-commit.2c85e299c → 0.0.1-commit.2e20a94

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,19 +1,22 @@
1
1
  import { Archiver, createArchiver } from '@aztec/archiver';
2
- import { BBCircuitVerifier, QueuedIVCVerifier, TestCircuitVerifier } from '@aztec/bb-prover';
2
+ import { BBCircuitVerifier, BatchChonkVerifier, QueuedIVCVerifier } from '@aztec/bb-prover';
3
+ import { TestCircuitVerifier } from '@aztec/bb-prover/test';
3
4
  import { type BlobClientInterface, createBlobClientWithFileStores } from '@aztec/blob-client/client';
4
5
  import { Blob } from '@aztec/blob-lib';
5
6
  import { ARCHIVE_HEIGHT, type L1_TO_L2_MSG_TREE_HEIGHT, type NOTE_HASH_TREE_HEIGHT } from '@aztec/constants';
6
7
  import { EpochCache, type EpochCacheInterface } from '@aztec/epoch-cache';
7
8
  import { createEthereumChain } from '@aztec/ethereum/chain';
8
- import { getPublicClient } from '@aztec/ethereum/client';
9
+ import { getPublicClient, makeL1HttpTransport } from '@aztec/ethereum/client';
9
10
  import { RegistryContract, RollupContract } from '@aztec/ethereum/contracts';
10
11
  import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
12
+ import type { L1TxUtils } from '@aztec/ethereum/l1-tx-utils';
11
13
  import { BlockNumber, CheckpointNumber, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
12
- import { compactArray, pick, unique } from '@aztec/foundation/collection';
14
+ import { chunkBy, compactArray, pick, unique } from '@aztec/foundation/collection';
13
15
  import { Fr } from '@aztec/foundation/curves/bn254';
14
16
  import { EthAddress } from '@aztec/foundation/eth-address';
15
17
  import { BadRequestError } from '@aztec/foundation/json-rpc';
16
18
  import { type Logger, createLogger } from '@aztec/foundation/log';
19
+ import { retryUntil } from '@aztec/foundation/retry';
17
20
  import { count } from '@aztec/foundation/string';
18
21
  import { DateProvider, Timer } from '@aztec/foundation/timer';
19
22
  import { MembershipWitness, SiblingPath } from '@aztec/foundation/trees';
@@ -30,7 +33,12 @@ import {
30
33
  import { ProtocolContractAddress } from '@aztec/protocol-contracts';
31
34
  import { type ProverNode, type ProverNodeDeps, createProverNode } from '@aztec/prover-node';
32
35
  import { createKeyStoreForProver } from '@aztec/prover-node/config';
33
- import { GlobalVariableBuilder, SequencerClient, type SequencerPublisher } from '@aztec/sequencer-client';
36
+ import {
37
+ FeeProviderImpl,
38
+ GlobalVariableBuilder,
39
+ SequencerClient,
40
+ type SequencerPublisher,
41
+ } from '@aztec/sequencer-client';
34
42
  import { PublicProcessorFactory } from '@aztec/simulator/server';
35
43
  import {
36
44
  AttestationsBlockWatcher,
@@ -57,13 +65,14 @@ import type {
57
65
  NodeInfo,
58
66
  ProtocolContractAddresses,
59
67
  } from '@aztec/stdlib/contract';
60
- import { GasFees } from '@aztec/stdlib/gas';
68
+ import { GasFees, type ManaUsageEstimate } from '@aztec/stdlib/gas';
61
69
  import { computePublicDataTreeLeafSlot } from '@aztec/stdlib/hash';
62
70
  import {
63
71
  type AztecNode,
64
72
  type AztecNodeAdmin,
65
73
  type AztecNodeAdminConfig,
66
74
  AztecNodeAdminConfigSchema,
75
+ type AztecNodeDebug,
67
76
  type GetContractClassLogsResponse,
68
77
  type GetPublicLogsResponse,
69
78
  } from '@aztec/stdlib/interfaces/client';
@@ -79,11 +88,12 @@ import {
79
88
  import type { DebugLogStore, LogFilter, SiloedTag, Tag, TxScopedL2Log } from '@aztec/stdlib/logs';
80
89
  import { InMemoryDebugLogStore, NullDebugLogStore } from '@aztec/stdlib/logs';
81
90
  import { InboxLeaf, type L1ToL2MessageSource } from '@aztec/stdlib/messaging';
82
- import type { Offense, SlashPayloadRound } from '@aztec/stdlib/slashing';
83
- import type { NullifierLeafPreimage, PublicDataTreeLeaf, PublicDataTreeLeafPreimage } from '@aztec/stdlib/trees';
91
+ import type { Offense } from '@aztec/stdlib/slashing';
92
+ import type { NullifierLeafPreimage, PublicDataTreeLeafPreimage } from '@aztec/stdlib/trees';
84
93
  import { MerkleTreeId, NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
85
94
  import {
86
95
  type BlockHeader,
96
+ type FeeProvider,
87
97
  type GlobalVariableBuilder as GlobalVariableBuilderInterface,
88
98
  type IndexedTxEffect,
89
99
  PublicSimulationOutput,
@@ -95,6 +105,7 @@ import {
95
105
  } from '@aztec/stdlib/tx';
96
106
  import { getPackageVersion } from '@aztec/stdlib/update-checker';
97
107
  import type { SingleValidatorStats, ValidatorsStats } from '@aztec/stdlib/validators';
108
+ import type { GenesisData } from '@aztec/stdlib/world-state';
98
109
  import {
99
110
  Attributes,
100
111
  type TelemetryClient,
@@ -108,12 +119,13 @@ import {
108
119
  FullNodeCheckpointsBuilder,
109
120
  NodeKeystoreAdapter,
110
121
  ValidatorClient,
111
- createBlockProposalHandler,
122
+ createProposalHandler,
112
123
  createValidatorClient,
113
124
  } from '@aztec/validator-client';
125
+ import type { SlashingProtectionDatabase } from '@aztec/validator-ha-signer/types';
114
126
  import { createWorldStateSynchronizer } from '@aztec/world-state';
115
127
 
116
- import { createPublicClient, fallback, http } from 'viem';
128
+ import { createPublicClient } from 'viem';
117
129
 
118
130
  import { createSentinel } from '../sentinel/factory.js';
119
131
  import { Sentinel } from '../sentinel/sentinel.js';
@@ -123,7 +135,7 @@ import { NodeMetrics } from './node_metrics.js';
123
135
  /**
124
136
  * The aztec node.
125
137
  */
126
- export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
138
+ export class AztecNodeService implements AztecNode, AztecNodeAdmin, AztecNodeDebug, Traceable {
127
139
  private metrics: NodeMetrics;
128
140
  private initialHeaderHashPromise: Promise<BlockHash> | undefined = undefined;
129
141
 
@@ -148,9 +160,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
148
160
  protected readonly l1ChainId: number,
149
161
  protected readonly version: number,
150
162
  protected readonly globalVariableBuilder: GlobalVariableBuilderInterface,
163
+ protected readonly feeProvider: FeeProvider,
151
164
  protected readonly epochCache: EpochCacheInterface,
152
165
  protected readonly packageVersion: string,
153
- private proofVerifier: ClientProtocolCircuitVerifier,
166
+ private peerProofVerifier: ClientProtocolCircuitVerifier,
167
+ private rpcProofVerifier: ClientProtocolCircuitVerifier,
154
168
  private telemetry: TelemetryClient = getTelemetryClient(),
155
169
  private log = createLogger('node'),
156
170
  private blobClient?: BlobClientInterface,
@@ -172,6 +186,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
172
186
  }
173
187
  }
174
188
 
189
+ /** @internal Exposed for testing — returns the RPC proof verifier. */
190
+ public getProofVerifier(): ClientProtocolCircuitVerifier {
191
+ return this.rpcProofVerifier;
192
+ }
193
+
175
194
  public async getWorldStateSyncStatus(): Promise<WorldStateSyncStatus> {
176
195
  const status = await this.worldStateSynchronizer.status();
177
196
  return status.syncSummary;
@@ -195,9 +214,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
195
214
  dateProvider?: DateProvider;
196
215
  p2pClientDeps?: P2PClientDeps;
197
216
  proverNodeDeps?: Partial<ProverNodeDeps>;
217
+ slashingProtectionDb?: SlashingProtectionDatabase;
198
218
  } = {},
199
219
  options: {
200
- prefilledPublicData?: PublicDataTreeLeaf[];
220
+ genesis?: GenesisData;
201
221
  dontStartSequencer?: boolean;
202
222
  dontStartProverNode?: boolean;
203
223
  } = {},
@@ -257,7 +277,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
257
277
 
258
278
  const publicClient = createPublicClient({
259
279
  chain: ethereumChain.chainInfo,
260
- transport: fallback(config.l1RpcUrls.map((url: string) => http(url, { batch: false }))),
280
+ transport: makeL1HttpTransport(config.l1RpcUrls, { timeout: config.l1HttpTimeoutMS }),
261
281
  pollingInterval: config.viemPollingIntervalMS,
262
282
  });
263
283
 
@@ -300,16 +320,18 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
300
320
  );
301
321
 
302
322
  // now create the merkle trees and the world state synchronizer
303
- const worldStateSynchronizer = await createWorldStateSynchronizer(
304
- config,
305
- archiver,
306
- options.prefilledPublicData,
307
- telemetry,
308
- );
309
- const circuitVerifier =
310
- config.realProofs || config.debugForceTxProofVerification
311
- ? await BBCircuitVerifier.new(config)
312
- : 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
+ }
313
335
 
314
336
  let debugLogStore: DebugLogStore;
315
337
  if (!config.realProofs) {
@@ -323,8 +345,6 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
323
345
  debugLogStore = new NullDebugLogStore();
324
346
  }
325
347
 
326
- const proofVerifier = new QueuedIVCVerifier(config, circuitVerifier);
327
-
328
348
  const proverOnly = config.enableProverNode && config.disableValidator;
329
349
  if (proverOnly) {
330
350
  log.info('Starting in prover-only mode: skipping validator, sequencer, sentinel, and slasher subsystems');
@@ -334,7 +354,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
334
354
  const p2pClient = await createP2PClient(
335
355
  config,
336
356
  archiver,
337
- proofVerifier,
357
+ peerProofVerifier,
338
358
  worldStateSynchronizer,
339
359
  epochCache,
340
360
  packageVersion,
@@ -377,6 +397,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
377
397
  l1ToL2MessageSource: archiver,
378
398
  keyStoreManager,
379
399
  blobClient,
400
+ slashingProtectionDb: deps.slashingProtectionDb,
380
401
  });
381
402
 
382
403
  // If we have a validator client, register it as a source of offenses for the slasher,
@@ -384,28 +405,35 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
384
405
  // like attestations or auths will fail.
385
406
  if (validatorClient) {
386
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
+
387
413
  if (!options.dontStartSequencer) {
388
414
  await validatorClient.registerHandlers();
389
415
  }
390
416
  }
391
417
  }
392
418
 
393
- // If there's no validator client, create a BlockProposalHandler to handle block proposals
419
+ // If there's no validator client, create a ProposalHandler to handle block and checkpoint proposals
394
420
  // for monitoring or reexecution. Reexecution (default) allows us to follow the pending chain,
395
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.
396
423
  if (!validatorClient) {
397
424
  const reexecute = !!config.alwaysReexecuteBlockProposals;
398
- log.info(`Setting up block proposal handler` + (reexecute ? ' with reexecution of proposals' : ''));
399
- createBlockProposalHandler(config, {
425
+ log.info(`Setting up proposal handler` + (reexecute ? ' with reexecution of proposals' : ''));
426
+ createProposalHandler(config, {
400
427
  checkpointsBuilder: validatorCheckpointsBuilder,
401
428
  worldState: worldStateSynchronizer,
402
429
  epochCache,
403
430
  blockSource: archiver,
404
431
  l1ToL2MessageSource: archiver,
405
432
  p2pClient,
433
+ blobClient,
406
434
  dateProvider,
407
435
  telemetry,
408
- }).register(p2pClient, reexecute);
436
+ }).register(p2pClient, reexecute, archiver);
409
437
  }
410
438
 
411
439
  // Start world state and wait for it to sync to the archiver.
@@ -447,7 +475,6 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
447
475
  void archiver
448
476
  .waitForInitialSync()
449
477
  .then(async () => {
450
- await p2pClient.start();
451
478
  await validatorsSentinel?.start();
452
479
  await epochPruneWatcher?.start();
453
480
  await attestationsBlockWatcher?.start();
@@ -455,6 +482,17 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
455
482
  })
456
483
  .catch(err => log.error('Failed to start p2p services after archiver sync', err));
457
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
+
458
496
  // Validator enabled, create/start relevant service
459
497
  let sequencer: SequencerClient | undefined;
460
498
  let slasherClient: SlasherClientInterface | undefined;
@@ -492,6 +530,19 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
492
530
  { telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
493
531
  );
494
532
 
533
+ // Create a funder L1TxUtils from the keystore funding account (if configured)
534
+ const fundingSigner = keyStoreManager?.createFundingSigner();
535
+ let funderL1TxUtils: L1TxUtils | undefined;
536
+ if (fundingSigner) {
537
+ const [funder] = await createL1TxUtilsFromSigners(
538
+ publicClient,
539
+ [fundingSigner],
540
+ { ...config, scope: 'sequencer' },
541
+ { telemetry, logger: log.createChild('l1-tx-utils:funder'), dateProvider },
542
+ );
543
+ funderL1TxUtils = funder;
544
+ }
545
+
495
546
  // Create and start the sequencer client
496
547
  const checkpointsBuilder = new CheckpointsBuilder(
497
548
  { ...config, l1GenesisTime, slotDuration: Number(slotDuration), rollupManaLimit },
@@ -506,6 +557,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
506
557
  ...deps,
507
558
  epochCache,
508
559
  l1TxUtils,
560
+ funderL1TxUtils,
509
561
  validatorClient,
510
562
  p2pClient,
511
563
  worldStateSynchronizer,
@@ -517,6 +569,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
517
569
  dateProvider,
518
570
  blobClient,
519
571
  nodeKeyStore: keyStoreManager!,
572
+ globalVariableBuilder,
520
573
  });
521
574
  }
522
575
 
@@ -550,13 +603,6 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
550
603
  }
551
604
  }
552
605
 
553
- const globalVariableBuilder = new GlobalVariableBuilder({
554
- ...config,
555
- rollupVersion: BigInt(config.rollupVersion),
556
- l1GenesisTime,
557
- slotDuration: Number(slotDuration),
558
- });
559
-
560
606
  const node = new AztecNodeService(
561
607
  config,
562
608
  p2pClient,
@@ -573,9 +619,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
573
619
  ethereumChain.chainInfo.id,
574
620
  config.rollupVersion,
575
621
  globalVariableBuilder,
622
+ feeProvider,
576
623
  epochCache,
577
624
  packageVersion,
578
- proofVerifier,
625
+ peerProofVerifier,
626
+ rpcProofVerifier,
579
627
  telemetry,
580
628
  log,
581
629
  blobClient,
@@ -720,12 +768,17 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
720
768
  return (await this.blockSource.getCheckpointedBlocks(from, limit)) ?? [];
721
769
  }
722
770
 
723
- /**
724
- * Method to fetch the current min L2 fees.
725
- * @returns The current min L2 fees.
726
- */
771
+ public getCheckpointsDataForEpoch(epochNumber: EpochNumber) {
772
+ return this.blockSource.getCheckpointsDataForEpoch(epochNumber);
773
+ }
774
+
727
775
  public async getCurrentMinFees(): Promise<GasFees> {
728
- return await this.globalVariableBuilder.getCurrentMinFees();
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);
729
782
  }
730
783
 
731
784
  public async getMaxPriorityFees(): Promise<GasFees> {
@@ -793,18 +846,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
793
846
  page?: number,
794
847
  referenceBlock?: BlockHash,
795
848
  ): Promise<TxScopedL2Log[][]> {
849
+ let upToBlockNumber: BlockNumber | undefined;
796
850
  if (referenceBlock) {
797
851
  const initialBlockHash = await this.#getInitialHeaderHash();
798
- if (!referenceBlock.equals(initialBlockHash)) {
852
+ if (referenceBlock.equals(initialBlockHash)) {
853
+ upToBlockNumber = BlockNumber(0);
854
+ } else {
799
855
  const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
800
856
  if (!header) {
801
857
  throw new Error(
802
858
  `Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
803
859
  );
804
860
  }
861
+ upToBlockNumber = header.globalVariables.blockNumber;
805
862
  }
806
863
  }
807
- return this.logsSource.getPrivateLogsByTags(tags, page);
864
+ return this.logsSource.getPrivateLogsByTags(tags, page, upToBlockNumber);
808
865
  }
809
866
 
810
867
  public async getPublicLogsByTagsFromContract(
@@ -813,18 +870,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
813
870
  page?: number,
814
871
  referenceBlock?: BlockHash,
815
872
  ): Promise<TxScopedL2Log[][]> {
873
+ let upToBlockNumber: BlockNumber | undefined;
816
874
  if (referenceBlock) {
817
875
  const initialBlockHash = await this.#getInitialHeaderHash();
818
- if (!referenceBlock.equals(initialBlockHash)) {
876
+ if (referenceBlock.equals(initialBlockHash)) {
877
+ upToBlockNumber = BlockNumber(0);
878
+ } else {
819
879
  const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
820
880
  if (!header) {
821
881
  throw new Error(
822
882
  `Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
823
883
  );
824
884
  }
885
+ upToBlockNumber = header.globalVariables.blockNumber;
825
886
  }
826
887
  }
827
- return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page);
888
+ return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page, upToBlockNumber);
828
889
  }
829
890
 
830
891
  /**
@@ -910,7 +971,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
910
971
  await tryStop(this.validatorsSentinel);
911
972
  await tryStop(this.epochPruneWatcher);
912
973
  await tryStop(this.slasherClient);
913
- await tryStop(this.proofVerifier);
974
+ await Promise.all([tryStop(this.peerProofVerifier), tryStop(this.rpcProofVerifier)]);
914
975
  await tryStop(this.sequencer);
915
976
  await tryStop(this.proverNode);
916
977
  await tryStop(this.p2pClient);
@@ -966,59 +1027,65 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
966
1027
  treeId: MerkleTreeId,
967
1028
  leafValues: Fr[],
968
1029
  ): Promise<(DataInBlock<bigint> | undefined)[]> {
969
- const committedDb = await this.#getWorldState(referenceBlock);
1030
+ const committedDb = await this.getWorldState(referenceBlock);
970
1031
  const maybeIndices = await committedDb.findLeafIndices(
971
1032
  treeId,
972
1033
  leafValues.map(x => x.toBuffer()),
973
1034
  );
974
- // We filter out undefined values
975
- 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);
976
1037
 
977
- // Now we find the block numbers for the indices
978
- 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);
979
1040
 
980
- // If any of the block numbers are undefined, we throw an error.
981
- for (let i = 0; i < indices.length; i++) {
982
- if (blockNumbers[i] === undefined) {
983
- 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
+ );
984
1049
  }
1050
+ indexToBlockNumber.set(definedIndices[i], blockNumber);
985
1051
  }
986
1052
 
987
1053
  // Get unique block numbers in order to optimize num calls to getLeafValue function.
988
- const uniqueBlockNumbers = [...new Set(blockNumbers.filter(x => x !== undefined))];
1054
+ const uniqueBlockNumbers = [...new Set(indexToBlockNumber.values())];
989
1055
 
990
- // Now we obtain the block hashes from the archive tree by calling await `committedDb.getLeafValue(treeId, index)`
991
- // (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).
992
1057
  const blockHashes = await Promise.all(
993
1058
  uniqueBlockNumbers.map(blockNumber => {
994
1059
  return committedDb.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
995
1060
  }),
996
1061
  );
997
1062
 
998
- // 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>();
999
1065
  for (let i = 0; i < uniqueBlockNumbers.length; i++) {
1000
- if (blockHashes[i] === undefined) {
1066
+ const blockHash = blockHashes[i];
1067
+ if (blockHash === undefined) {
1001
1068
  throw new Error(`Block hash is undefined for block number ${uniqueBlockNumbers[i]}`);
1002
1069
  }
1070
+ blockNumberToHash.set(uniqueBlockNumbers[i], blockHash);
1003
1071
  }
1004
1072
 
1005
1073
  // Create DataInBlock objects by combining indices, blockNumbers and blockHashes and return them.
1006
- return maybeIndices.map((index, i) => {
1074
+ return maybeIndices.map(index => {
1007
1075
  if (index === undefined) {
1008
1076
  return undefined;
1009
1077
  }
1010
- const blockNumber = blockNumbers[i];
1078
+ const blockNumber = indexToBlockNumber.get(index);
1011
1079
  if (blockNumber === undefined) {
1012
- return undefined;
1080
+ throw new Error(`Block number not found for leaf index ${index} in tree ${MerkleTreeId[treeId]}`);
1013
1081
  }
1014
- const blockHashIndex = uniqueBlockNumbers.indexOf(blockNumber);
1015
- const blockHash = blockHashes[blockHashIndex];
1016
- if (!blockHash) {
1017
- return undefined;
1082
+ const l2BlockHash = blockNumberToHash.get(blockNumber);
1083
+ if (l2BlockHash === undefined) {
1084
+ throw new Error(`Block hash not found for block number ${blockNumber}`);
1018
1085
  }
1019
1086
  return {
1020
- l2BlockNumber: BlockNumber(Number(blockNumber)),
1021
- l2BlockHash: new BlockHash(blockHash),
1087
+ l2BlockNumber: blockNumber,
1088
+ l2BlockHash,
1022
1089
  data: index,
1023
1090
  };
1024
1091
  });
@@ -1028,7 +1095,15 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1028
1095
  referenceBlock: BlockParameter,
1029
1096
  blockHash: BlockHash,
1030
1097
  ): Promise<MembershipWitness<typeof ARCHIVE_HEIGHT> | undefined> {
1031
- const committedDb = await this.#getWorldState(referenceBlock);
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));
1032
1107
  const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.ARCHIVE>(MerkleTreeId.ARCHIVE, [blockHash]);
1033
1108
  return pathAndIndex === undefined
1034
1109
  ? undefined
@@ -1039,7 +1114,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1039
1114
  referenceBlock: BlockParameter,
1040
1115
  noteHash: Fr,
1041
1116
  ): Promise<MembershipWitness<typeof NOTE_HASH_TREE_HEIGHT> | undefined> {
1042
- const committedDb = await this.#getWorldState(referenceBlock);
1117
+ const committedDb = await this.getWorldState(referenceBlock);
1043
1118
  const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.NOTE_HASH_TREE>(
1044
1119
  MerkleTreeId.NOTE_HASH_TREE,
1045
1120
  [noteHash],
@@ -1053,7 +1128,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1053
1128
  referenceBlock: BlockParameter,
1054
1129
  l1ToL2Message: Fr,
1055
1130
  ): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>] | undefined> {
1056
- const db = await this.#getWorldState(referenceBlock);
1131
+ const db = await this.getWorldState(referenceBlock);
1057
1132
  const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [l1ToL2Message]);
1058
1133
  if (!witness) {
1059
1134
  return undefined;
@@ -1086,19 +1161,9 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1086
1161
  public async getL2ToL1Messages(epoch: EpochNumber): Promise<Fr[][][][]> {
1087
1162
  // Assumes `getCheckpointedBlocksForEpoch` returns blocks in ascending order of block number.
1088
1163
  const checkpointedBlocks = await this.blockSource.getCheckpointedBlocksForEpoch(epoch);
1089
- const blocksInCheckpoints: L2Block[][] = [];
1090
- let previousSlotNumber = SlotNumber.ZERO;
1091
- let checkpointIndex = -1;
1092
- for (const checkpointedBlock of checkpointedBlocks) {
1093
- const block = checkpointedBlock.block;
1094
- const slotNumber = block.header.globalVariables.slotNumber;
1095
- if (slotNumber !== previousSlotNumber) {
1096
- checkpointIndex++;
1097
- blocksInCheckpoints.push([]);
1098
- previousSlotNumber = slotNumber;
1099
- }
1100
- blocksInCheckpoints[checkpointIndex].push(block);
1101
- }
1164
+ const blocksInCheckpoints = chunkBy(checkpointedBlocks, cb => cb.block.header.globalVariables.slotNumber).map(
1165
+ group => group.map(cb => cb.block),
1166
+ );
1102
1167
  return blocksInCheckpoints.map(blocks =>
1103
1168
  blocks.map(block => block.body.txEffects.map(txEffect => txEffect.l2ToL1Msgs)),
1104
1169
  );
@@ -1108,7 +1173,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1108
1173
  referenceBlock: BlockParameter,
1109
1174
  nullifier: Fr,
1110
1175
  ): Promise<NullifierMembershipWitness | undefined> {
1111
- const db = await this.#getWorldState(referenceBlock);
1176
+ const db = await this.getWorldState(referenceBlock);
1112
1177
  const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [nullifier.toBuffer()]);
1113
1178
  if (!witness) {
1114
1179
  return undefined;
@@ -1123,33 +1188,20 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1123
1188
  return new NullifierMembershipWitness(index, leafPreimage as NullifierLeafPreimage, path);
1124
1189
  }
1125
1190
 
1126
- /**
1127
- * Returns a low nullifier membership witness for a given nullifier at a given block.
1128
- * @param referenceBlock - The block parameter (block number, block hash, or 'latest') at which to get the data
1129
- * (which contains the root of the nullifier tree in which we are searching for the nullifier).
1130
- * @param nullifier - Nullifier we try to find the low nullifier witness for.
1131
- * @returns The low nullifier membership witness (if found).
1132
- * @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
1133
- * list structure" of leaves and proving that a lower nullifier is pointing to a bigger next value than the nullifier
1134
- * we are trying to prove non-inclusion for.
1135
- *
1136
- * Note: This function returns the membership witness of the nullifier itself and not the low nullifier when
1137
- * the nullifier already exists in the tree. This is because the `getPreviousValueIndex` function returns the
1138
- * index of the nullifier itself when it already exists in the tree.
1139
- * TODO: This is a confusing behavior and we should eventually address that.
1140
- */
1141
1191
  public async getLowNullifierMembershipWitness(
1142
1192
  referenceBlock: BlockParameter,
1143
1193
  nullifier: Fr,
1144
1194
  ): Promise<NullifierMembershipWitness | undefined> {
1145
- const committedDb = await this.#getWorldState(referenceBlock);
1195
+ const committedDb = await this.getWorldState(referenceBlock);
1146
1196
  const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
1147
1197
  if (!findResult) {
1148
1198
  return undefined;
1149
1199
  }
1150
1200
  const { index, alreadyPresent } = findResult;
1151
1201
  if (alreadyPresent) {
1152
- 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
+ );
1153
1205
  }
1154
1206
  const preimageData = (await committedDb.getLeafPreimage(MerkleTreeId.NULLIFIER_TREE, index))!;
1155
1207
 
@@ -1158,7 +1210,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1158
1210
  }
1159
1211
 
1160
1212
  async getPublicDataWitness(referenceBlock: BlockParameter, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
1161
- const committedDb = await this.#getWorldState(referenceBlock);
1213
+ const committedDb = await this.getWorldState(referenceBlock);
1162
1214
  const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
1163
1215
  if (!lowLeafResult) {
1164
1216
  return undefined;
@@ -1173,7 +1225,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1173
1225
  }
1174
1226
 
1175
1227
  public async getPublicStorageAt(referenceBlock: BlockParameter, contract: AztecAddress, slot: Fr): Promise<Fr> {
1176
- const committedDb = await this.#getWorldState(referenceBlock);
1228
+ const committedDb = await this.getWorldState(referenceBlock);
1177
1229
  const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
1178
1230
 
1179
1231
  const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
@@ -1313,11 +1365,12 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1313
1365
  { isSimulation, skipFeeEnforcement }: { isSimulation?: boolean; skipFeeEnforcement?: boolean } = {},
1314
1366
  ): Promise<TxValidationResult> {
1315
1367
  const db = this.worldStateSynchronizer.getCommitted();
1316
- const verifier = isSimulation ? undefined : this.proofVerifier;
1368
+ const verifier = isSimulation ? undefined : this.rpcProofVerifier;
1317
1369
 
1318
1370
  // We accept transactions if they are not expired by the next slot (checked based on the ExpirationTimestamp field)
1319
1371
  const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
1320
1372
  const blockNumber = BlockNumber((await this.blockSource.getBlockNumber()) + 1);
1373
+ const l1Constants = await this.blockSource.getL1Constants();
1321
1374
  const validator = createTxValidatorForAcceptingTxsOverRPC(
1322
1375
  db,
1323
1376
  this.contractDataSource,
@@ -1334,6 +1387,9 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1334
1387
  gasFees: await this.getCurrentMinFees(),
1335
1388
  skipFeeEnforcement,
1336
1389
  txsPermitted: !this.config.disableTransactions,
1390
+ rollupManaLimit: l1Constants.rollupManaLimit,
1391
+ maxBlockL2Gas: this.config.validateMaxL2BlockGas,
1392
+ maxBlockDAGas: this.config.validateMaxDABlockGas,
1337
1393
  },
1338
1394
  this.log.getBindings(),
1339
1395
  );
@@ -1358,7 +1414,15 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1358
1414
  archiver.updateConfig(config);
1359
1415
  }
1360
1416
  if (newConfig.realProofs !== this.config.realProofs) {
1361
- 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
+ }
1362
1426
  }
1363
1427
 
1364
1428
  this.config = newConfig;
@@ -1433,7 +1497,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1433
1497
  return Promise.resolve();
1434
1498
  }
1435
1499
 
1436
- public async rollbackTo(targetBlock: BlockNumber, force?: boolean): Promise<void> {
1500
+ public async rollbackTo(targetBlock: BlockNumber, force?: boolean, resumeSync = true): Promise<void> {
1437
1501
  const archiver = this.blockSource as Archiver;
1438
1502
  if (!('rollbackTo' in archiver)) {
1439
1503
  throw new Error('Archiver implementation does not support rollbacks.');
@@ -1463,9 +1527,13 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1463
1527
  this.log.error(`Error during rollback`, err);
1464
1528
  throw err;
1465
1529
  } finally {
1466
- this.log.info(`Resuming world state and archiver sync.`);
1467
- this.worldStateSynchronizer.resumeSync();
1468
- 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
+ }
1469
1537
  }
1470
1538
  }
1471
1539
 
@@ -1482,19 +1550,12 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1482
1550
  return Promise.resolve();
1483
1551
  }
1484
1552
 
1485
- public getSlashPayloads(): Promise<SlashPayloadRound[]> {
1486
- if (!this.slasherClient) {
1487
- throw new Error(`Slasher client not enabled`);
1488
- }
1489
- return this.slasherClient.getSlashPayloads();
1490
- }
1491
-
1492
1553
  public getSlashOffenses(round: bigint | 'all' | 'current'): Promise<Offense[]> {
1493
1554
  if (!this.slasherClient) {
1494
1555
  throw new Error(`Slasher client not enabled`);
1495
1556
  }
1496
1557
  if (round === 'all') {
1497
- return this.slasherClient.getPendingOffenses();
1558
+ return this.slasherClient.getOffenses();
1498
1559
  } else {
1499
1560
  return this.slasherClient.gatherOffensesForRound(round === 'current' ? undefined : BigInt(round));
1500
1561
  }
@@ -1588,6 +1649,40 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1588
1649
  this.log.info('Keystore reloaded: coinbase, feeRecipient, and attester keys updated');
1589
1650
  }
1590
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
+
1591
1686
  #getInitialHeaderHash(): Promise<BlockHash> {
1592
1687
  if (!this.initialHeaderHashPromise) {
1593
1688
  this.initialHeaderHashPromise = this.worldStateSynchronizer.getCommitted().getInitialHeader().hash();
@@ -1600,7 +1695,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1600
1695
  * @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
1601
1696
  * @returns An instance of a committed MerkleTreeOperations
1602
1697
  */
1603
- async #getWorldState(block: BlockParameter) {
1698
+ protected async getWorldState(block: BlockParameter) {
1604
1699
  let blockSyncedTo: BlockNumber = BlockNumber.ZERO;
1605
1700
  try {
1606
1701
  // Attempt to sync the world state if necessary
@@ -1614,6 +1709,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1614
1709
  return this.worldStateSynchronizer.getCommitted();
1615
1710
  }
1616
1711
 
1712
+ // Get the block number, either directly from the parameter or by quering the archiver with the block hash
1713
+ let blockNumber: BlockNumber;
1617
1714
  if (BlockHash.isBlockHash(block)) {
1618
1715
  const initialBlockHash = await this.#getInitialHeaderHash();
1619
1716
  if (block.equals(initialBlockHash)) {
@@ -1627,22 +1724,50 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1627
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.`,
1628
1725
  );
1629
1726
  }
1630
- const blockNumber = header.getBlockNumber();
1631
- this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
1632
- return this.worldStateSynchronizer.getSnapshot(blockNumber);
1727
+
1728
+ blockNumber = header.getBlockNumber();
1729
+ } else {
1730
+ blockNumber = block as BlockNumber;
1633
1731
  }
1634
1732
 
1635
- // Block number provided
1636
- {
1637
- const blockNumber = block as BlockNumber;
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}`);
1638
1738
 
1639
- if (blockNumber > blockSyncedTo) {
1640
- throw new Error(`Queried block ${block} not yet synced by the node (node is synced upto ${blockSyncedTo}).`);
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
+ );
1641
1748
  }
1749
+ }
1642
1750
 
1643
- this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
1644
- return this.worldStateSynchronizer.getSnapshot(blockNumber);
1751
+ return snapshot;
1752
+ }
1753
+
1754
+ /** Resolves a block parameter to a block number. */
1755
+ protected async resolveBlockNumber(block: BlockParameter): Promise<BlockNumber> {
1756
+ if (block === 'latest') {
1757
+ return BlockNumber(await this.blockSource.getBlockNumber());
1758
+ }
1759
+ if (BlockHash.isBlockHash(block)) {
1760
+ const initialBlockHash = await this.#getInitialHeaderHash();
1761
+ if (block.equals(initialBlockHash)) {
1762
+ return BlockNumber.ZERO;
1763
+ }
1764
+ const header = await this.blockSource.getBlockHeaderByHash(block);
1765
+ if (!header) {
1766
+ throw new Error(`Block hash ${block.toString()} not found.`);
1767
+ }
1768
+ return header.getBlockNumber();
1645
1769
  }
1770
+ return block as BlockNumber;
1646
1771
  }
1647
1772
 
1648
1773
  /**