@aztec/aztec-node 0.0.1-commit.9372f48 → 0.0.1-commit.949a33fd8

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.
@@ -372,46 +372,52 @@ function _apply_decs_2203_r(targetClass, memberDecs, classDecs, parentClass) {
372
372
  }
373
373
  var _dec, _initProto;
374
374
  import { createArchiver } from '@aztec/archiver';
375
- import { BBCircuitVerifier, QueuedIVCVerifier, TestCircuitVerifier } from '@aztec/bb-prover';
375
+ import { BBCircuitVerifier, BatchChonkVerifier, QueuedIVCVerifier } from '@aztec/bb-prover';
376
+ import { TestCircuitVerifier } from '@aztec/bb-prover/test';
376
377
  import { createBlobClientWithFileStores } from '@aztec/blob-client/client';
378
+ import { Blob } from '@aztec/blob-lib';
377
379
  import { EpochCache } from '@aztec/epoch-cache';
378
380
  import { createEthereumChain } from '@aztec/ethereum/chain';
379
- import { getPublicClient } from '@aztec/ethereum/client';
381
+ import { getPublicClient, makeL1HttpTransport } from '@aztec/ethereum/client';
380
382
  import { RegistryContract, RollupContract } from '@aztec/ethereum/contracts';
381
- import { BlockNumber, SlotNumber } from '@aztec/foundation/branded-types';
382
- import { compactArray, pick } from '@aztec/foundation/collection';
383
+ import { BlockNumber } from '@aztec/foundation/branded-types';
384
+ import { chunkBy, compactArray, pick, unique } from '@aztec/foundation/collection';
383
385
  import { Fr } from '@aztec/foundation/curves/bn254';
384
386
  import { EthAddress } from '@aztec/foundation/eth-address';
385
387
  import { BadRequestError } from '@aztec/foundation/json-rpc';
386
388
  import { createLogger } from '@aztec/foundation/log';
389
+ import { retryUntil } from '@aztec/foundation/retry';
387
390
  import { count } from '@aztec/foundation/string';
388
391
  import { DateProvider, Timer } from '@aztec/foundation/timer';
389
392
  import { MembershipWitness } from '@aztec/foundation/trees';
390
393
  import { KeystoreManager, loadKeystores, mergeKeystores } from '@aztec/node-keystore';
391
394
  import { trySnapshotSync, uploadSnapshot } from '@aztec/node-lib/actions';
392
- import { createForwarderL1TxUtilsFromEthSigner, createL1TxUtilsWithBlobsFromEthSigner } from '@aztec/node-lib/factories';
393
- import { createP2PClient, getDefaultAllowedSetupFunctions } from '@aztec/p2p';
395
+ import { createForwarderL1TxUtilsFromSigners, createL1TxUtilsFromSigners } from '@aztec/node-lib/factories';
396
+ import { createP2PClient, createTxValidatorForAcceptingTxsOverRPC, getDefaultAllowedSetupFunctions } from '@aztec/p2p';
394
397
  import { ProtocolContractAddress } from '@aztec/protocol-contracts';
395
- import { GlobalVariableBuilder, SequencerClient } from '@aztec/sequencer-client';
398
+ import { createProverNode } from '@aztec/prover-node';
399
+ import { createKeyStoreForProver } from '@aztec/prover-node/config';
400
+ import { FeeProviderImpl, GlobalVariableBuilder, SequencerClient } from '@aztec/sequencer-client';
396
401
  import { PublicProcessorFactory } from '@aztec/simulator/server';
397
402
  import { AttestationsBlockWatcher, EpochPruneWatcher, createSlasher } from '@aztec/slasher';
398
403
  import { CollectionLimitsConfig, PublicSimulatorConfig } from '@aztec/stdlib/avm';
399
404
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
400
- import { BlockHash, L2Block } from '@aztec/stdlib/block';
405
+ import { BlockHash, L2Block, inspectBlockParameter } from '@aztec/stdlib/block';
401
406
  import { GasFees } from '@aztec/stdlib/gas';
402
407
  import { computePublicDataTreeLeafSlot } from '@aztec/stdlib/hash';
403
408
  import { AztecNodeAdminConfigSchema } from '@aztec/stdlib/interfaces/client';
404
409
  import { tryStop } from '@aztec/stdlib/interfaces/server';
410
+ import { InMemoryDebugLogStore, NullDebugLogStore } from '@aztec/stdlib/logs';
405
411
  import { InboxLeaf } from '@aztec/stdlib/messaging';
406
- import { P2PClientType } from '@aztec/stdlib/p2p';
407
412
  import { MerkleTreeId, NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
408
413
  import { PublicSimulationOutput, TxReceipt, TxStatus } from '@aztec/stdlib/tx';
409
414
  import { getPackageVersion } from '@aztec/stdlib/update-checker';
410
415
  import { Attributes, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
411
- import { FullNodeCheckpointsBuilder as CheckpointsBuilder, FullNodeCheckpointsBuilder, NodeKeystoreAdapter, ValidatorClient, createBlockProposalHandler, createValidatorClient, createValidatorForAcceptingTxs } from '@aztec/validator-client';
416
+ import { FullNodeCheckpointsBuilder as CheckpointsBuilder, FullNodeCheckpointsBuilder, NodeKeystoreAdapter, ValidatorClient, createProposalHandler, createValidatorClient } from '@aztec/validator-client';
412
417
  import { createWorldStateSynchronizer } from '@aztec/world-state';
413
- import { createPublicClient, fallback, http } from 'viem';
418
+ import { createPublicClient } from 'viem';
414
419
  import { createSentinel } from '../sentinel/factory.js';
420
+ import { blockResponseFromBlockData, blockResponseFromL2Block, checkpointResponseFromCheckpointData, checkpointResponseFromPublishedCheckpoint } from './block_response_helpers.js';
415
421
  import { createKeyStoreForValidator } from './config.js';
416
422
  import { NodeMetrics } from './node_metrics.js';
417
423
  _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
@@ -428,18 +434,25 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
428
434
  l1ToL2MessageSource;
429
435
  worldStateSynchronizer;
430
436
  sequencer;
437
+ proverNode;
431
438
  slasherClient;
432
439
  validatorsSentinel;
433
440
  epochPruneWatcher;
441
+ attestationsBlockWatcher;
434
442
  l1ChainId;
435
443
  version;
436
444
  globalVariableBuilder;
445
+ feeProvider;
437
446
  epochCache;
438
447
  packageVersion;
439
- proofVerifier;
448
+ peerProofVerifier;
449
+ rpcProofVerifier;
440
450
  telemetry;
441
451
  log;
442
452
  blobClient;
453
+ validatorClient;
454
+ keyStoreManager;
455
+ debugLogStore;
443
456
  static{
444
457
  ({ e: [_initProto] } = _apply_decs_2203_r(this, [
445
458
  [
@@ -454,7 +467,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
454
467
  // Prevent two snapshot operations to happen simultaneously
455
468
  isUploadingSnapshot;
456
469
  tracer;
457
- constructor(config, p2pClient, blockSource, logsSource, contractDataSource, l1ToL2MessageSource, worldStateSynchronizer, sequencer, slasherClient, validatorsSentinel, epochPruneWatcher, l1ChainId, version, globalVariableBuilder, epochCache, packageVersion, proofVerifier, telemetry = getTelemetryClient(), log = createLogger('node'), blobClient){
470
+ constructor(config, p2pClient, blockSource, logsSource, contractDataSource, l1ToL2MessageSource, worldStateSynchronizer, sequencer, proverNode, slasherClient, validatorsSentinel, epochPruneWatcher, attestationsBlockWatcher, l1ChainId, version, globalVariableBuilder, feeProvider, epochCache, packageVersion, peerProofVerifier, rpcProofVerifier, telemetry = getTelemetryClient(), log = createLogger('node'), blobClient, validatorClient, keyStoreManager, debugLogStore = new NullDebugLogStore()){
458
471
  this.config = config;
459
472
  this.p2pClient = p2pClient;
460
473
  this.blockSource = blockSource;
@@ -463,32 +476,312 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
463
476
  this.l1ToL2MessageSource = l1ToL2MessageSource;
464
477
  this.worldStateSynchronizer = worldStateSynchronizer;
465
478
  this.sequencer = sequencer;
479
+ this.proverNode = proverNode;
466
480
  this.slasherClient = slasherClient;
467
481
  this.validatorsSentinel = validatorsSentinel;
468
482
  this.epochPruneWatcher = epochPruneWatcher;
483
+ this.attestationsBlockWatcher = attestationsBlockWatcher;
469
484
  this.l1ChainId = l1ChainId;
470
485
  this.version = version;
471
486
  this.globalVariableBuilder = globalVariableBuilder;
487
+ this.feeProvider = feeProvider;
472
488
  this.epochCache = epochCache;
473
489
  this.packageVersion = packageVersion;
474
- this.proofVerifier = proofVerifier;
490
+ this.peerProofVerifier = peerProofVerifier;
491
+ this.rpcProofVerifier = rpcProofVerifier;
475
492
  this.telemetry = telemetry;
476
493
  this.log = log;
477
494
  this.blobClient = blobClient;
495
+ this.validatorClient = validatorClient;
496
+ this.keyStoreManager = keyStoreManager;
497
+ this.debugLogStore = debugLogStore;
478
498
  this.initialHeaderHashPromise = (_initProto(this), undefined);
479
499
  this.isUploadingSnapshot = false;
480
500
  this.metrics = new NodeMetrics(telemetry, 'AztecNodeService');
481
501
  this.tracer = telemetry.getTracer('AztecNodeService');
482
502
  this.log.info(`Aztec Node version: ${this.packageVersion}`);
483
503
  this.log.info(`Aztec Node started on chain 0x${l1ChainId.toString(16)}`, config.l1Contracts);
504
+ // A defensive check that protects us against introducing a bug in the complex `createAndSync` function. We must
505
+ // never have debugLogStore enabled when not in test mode because then we would be accumulating debug logs in
506
+ // memory which could be a DoS vector on the sequencer (since no fees are paid for debug logs).
507
+ if (debugLogStore.isEnabled && config.realProofs) {
508
+ throw new Error('debugLogStore should never be enabled when realProofs are set');
509
+ }
510
+ }
511
+ /** @internal Exposed for testing — returns the RPC proof verifier. */ getProofVerifier() {
512
+ return this.rpcProofVerifier;
484
513
  }
485
514
  async getWorldStateSyncStatus() {
486
515
  const status = await this.worldStateSynchronizer.status();
487
516
  return status.syncSummary;
488
517
  }
518
+ async getChainTips() {
519
+ const { proposed, checkpointed, proven, finalized } = await this.blockSource.getL2Tips();
520
+ return {
521
+ proposed,
522
+ checkpointed,
523
+ proven,
524
+ finalized
525
+ };
526
+ }
489
527
  getL2Tips() {
490
528
  return this.blockSource.getL2Tips();
491
529
  }
530
+ async getBlockHeader(number) {
531
+ const resolvedNumber = number === 'latest' ? await this.blockSource.getBlockNumber() : number;
532
+ if (resolvedNumber === BlockNumber.ZERO) {
533
+ return this.worldStateSynchronizer.getCommitted().getInitialHeader();
534
+ }
535
+ return this.blockSource.getBlockHeader(resolvedNumber);
536
+ }
537
+ async getCheckpointedBlocks(from, limit) {
538
+ return await this.blockSource.getCheckpointedBlocks(from, limit) ?? [];
539
+ }
540
+ getCheckpointsDataForEpoch(epoch) {
541
+ return this.blockSource.getCheckpointsDataForEpoch(epoch);
542
+ }
543
+ getBlockNumber(tip) {
544
+ switch(tip){
545
+ case undefined:
546
+ case 'proposed':
547
+ return this.blockSource.getBlockNumber();
548
+ case 'checkpointed':
549
+ return this.blockSource.getCheckpointedL2BlockNumber();
550
+ case 'proven':
551
+ return this.blockSource.getProvenBlockNumber();
552
+ case 'finalized':
553
+ return this.blockSource.getFinalizedL2BlockNumber();
554
+ }
555
+ }
556
+ async getCheckpointNumber(tip) {
557
+ switch(tip){
558
+ case undefined:
559
+ case 'proposed':
560
+ case 'checkpointed':
561
+ return await this.blockSource.getCheckpointNumber();
562
+ case 'proven':
563
+ case 'finalized':
564
+ {
565
+ const tips = await this.blockSource.getL2Tips();
566
+ return tip === 'proven' ? tips.proven.checkpoint.number : tips.finalized.checkpoint.number;
567
+ }
568
+ }
569
+ }
570
+ isChainTip(value) {
571
+ return value === 'proposed' || value === 'checkpointed' || value === 'proven' || value === 'finalized';
572
+ }
573
+ async resolveBlockParameter(param) {
574
+ if (BlockHash.isBlockHash(param)) {
575
+ return {
576
+ hash: param
577
+ };
578
+ }
579
+ if (typeof param === 'number') {
580
+ return {
581
+ number: param
582
+ };
583
+ }
584
+ if (param === 'latest') {
585
+ return {
586
+ number: await this.blockSource.getBlockNumber()
587
+ };
588
+ }
589
+ if (this.isChainTip(param)) {
590
+ return {
591
+ number: await this.getBlockNumber(param)
592
+ };
593
+ }
594
+ if (typeof param === 'object' && param !== null) {
595
+ if ('number' in param) {
596
+ return {
597
+ number: param.number
598
+ };
599
+ }
600
+ if ('hash' in param) {
601
+ return {
602
+ hash: param.hash
603
+ };
604
+ }
605
+ if ('archive' in param) {
606
+ return {
607
+ archive: param.archive
608
+ };
609
+ }
610
+ }
611
+ throw new BadRequestError(`Invalid BlockParameter: ${JSON.stringify(param)}`);
612
+ }
613
+ async resolveCheckpointParameter(param) {
614
+ if (typeof param === 'number') {
615
+ return {
616
+ number: param
617
+ };
618
+ }
619
+ if (param === 'latest') {
620
+ return {
621
+ number: await this.blockSource.getCheckpointNumber()
622
+ };
623
+ }
624
+ if (this.isChainTip(param)) {
625
+ return {
626
+ number: await this.getCheckpointNumber(param)
627
+ };
628
+ }
629
+ if (typeof param === 'object' && param !== null) {
630
+ if ('number' in param) {
631
+ return {
632
+ number: param.number
633
+ };
634
+ }
635
+ if ('slot' in param) {
636
+ return {
637
+ slot: param.slot
638
+ };
639
+ }
640
+ }
641
+ throw new BadRequestError(`Invalid CheckpointParameter: ${JSON.stringify(param)}`);
642
+ }
643
+ async getBlock(param, options = {}) {
644
+ const resolved = await this.resolveBlockParameter(param);
645
+ const wantTxs = !!options.includeTransactions;
646
+ const wantContext = !!options.includeL1PublishInfo || !!options.includeAttestations;
647
+ if (resolved.hash !== undefined) {
648
+ const initial = await this.#getInitialHeaderHash();
649
+ if (resolved.hash.equals(initial)) {
650
+ return await this.buildGenesisBlockResponse(options);
651
+ }
652
+ if (wantTxs) {
653
+ const block = await this.blockSource.getL2BlockByHash(resolved.hash);
654
+ if (!block) {
655
+ return undefined;
656
+ }
657
+ const ctx = wantContext ? await this.blockSource.getBlockDataWithCheckpointContext(block.number) : undefined;
658
+ return await blockResponseFromL2Block(block, options, ctx);
659
+ }
660
+ const data = await this.blockSource.getBlockHeaderByHash(resolved.hash);
661
+ if (!data) {
662
+ return undefined;
663
+ }
664
+ const blockNumber = data.globalVariables.blockNumber;
665
+ const ctx = wantContext ? await this.blockSource.getBlockDataWithCheckpointContext(blockNumber) : undefined;
666
+ if (ctx) {
667
+ return blockResponseFromBlockData(ctx.data, blockNumber, options, ctx);
668
+ }
669
+ const blockData = await this.blockSource.getBlockData(blockNumber);
670
+ if (!blockData) {
671
+ return undefined;
672
+ }
673
+ return blockResponseFromBlockData(blockData, blockNumber, options);
674
+ }
675
+ if (resolved.archive !== undefined) {
676
+ if (wantTxs) {
677
+ const block = await this.blockSource.getL2BlockByArchive(resolved.archive);
678
+ if (!block) {
679
+ return undefined;
680
+ }
681
+ const ctx = wantContext ? await this.blockSource.getBlockDataWithCheckpointContext(block.number) : undefined;
682
+ return await blockResponseFromL2Block(block, options, ctx);
683
+ }
684
+ const data = await this.blockSource.getBlockDataByArchive(resolved.archive);
685
+ if (!data) {
686
+ return undefined;
687
+ }
688
+ const blockNumber = data.header.globalVariables.blockNumber;
689
+ const ctx = wantContext ? await this.blockSource.getBlockDataWithCheckpointContext(blockNumber) : undefined;
690
+ return blockResponseFromBlockData(data, blockNumber, options, ctx);
691
+ }
692
+ const blockNumber = resolved.number;
693
+ if (blockNumber === BlockNumber.ZERO) {
694
+ return await this.buildGenesisBlockResponse(options);
695
+ }
696
+ if (wantTxs) {
697
+ const block = await this.blockSource.getL2Block(blockNumber);
698
+ if (!block) {
699
+ return undefined;
700
+ }
701
+ const ctx = wantContext ? await this.blockSource.getBlockDataWithCheckpointContext(blockNumber) : undefined;
702
+ return await blockResponseFromL2Block(block, options, ctx);
703
+ }
704
+ const ctx = await this.blockSource.getBlockDataWithCheckpointContext(blockNumber);
705
+ if (!ctx) {
706
+ return undefined;
707
+ }
708
+ return blockResponseFromBlockData(ctx.data, blockNumber, options, ctx);
709
+ }
710
+ async getBlocks(from, limit, options = {}) {
711
+ const wantTxs = !!options.includeTransactions;
712
+ const wantContext = !!options.includeL1PublishInfo || !!options.includeAttestations;
713
+ if (wantTxs) {
714
+ const blocks = await this.blockSource.getBlocks(from, limit);
715
+ return await Promise.all(blocks.map(async (block)=>{
716
+ const ctx = wantContext ? await this.blockSource.getBlockDataWithCheckpointContext(block.number) : undefined;
717
+ return blockResponseFromL2Block(block, options, ctx);
718
+ }));
719
+ }
720
+ const results = [];
721
+ for(let i = 0; i < limit; i++){
722
+ const blockNumber = BlockNumber(from + i);
723
+ const ctx = await this.blockSource.getBlockDataWithCheckpointContext(blockNumber);
724
+ if (!ctx) {
725
+ break;
726
+ }
727
+ results.push(blockResponseFromBlockData(ctx.data, blockNumber, options, ctx));
728
+ }
729
+ return results;
730
+ }
731
+ async getCheckpoint(param, options = {}) {
732
+ const resolved = await this.resolveCheckpointParameter(param);
733
+ let checkpointNumber = resolved.number;
734
+ if (checkpointNumber === undefined && resolved.slot !== undefined) {
735
+ checkpointNumber = await this.blockSource.getCheckpointNumberBySlot(resolved.slot);
736
+ }
737
+ if (checkpointNumber === undefined) {
738
+ return undefined;
739
+ }
740
+ if (options.includeBlocks) {
741
+ const [checkpoint] = await this.blockSource.getCheckpoints(checkpointNumber, 1);
742
+ if (!checkpoint) {
743
+ return undefined;
744
+ }
745
+ return await checkpointResponseFromPublishedCheckpoint(checkpoint, options);
746
+ }
747
+ const data = await this.blockSource.getCheckpointData(checkpointNumber);
748
+ if (!data) {
749
+ return undefined;
750
+ }
751
+ return checkpointResponseFromCheckpointData(data, options);
752
+ }
753
+ async getCheckpoints(from, limit, options = {}) {
754
+ if (options.includeBlocks) {
755
+ const checkpoints = await this.blockSource.getCheckpoints(from, limit);
756
+ return await Promise.all(checkpoints.map((cp)=>checkpointResponseFromPublishedCheckpoint(cp, options)));
757
+ }
758
+ const datas = await this.blockSource.getCheckpointDataRange(from, limit);
759
+ return datas.map((d)=>checkpointResponseFromCheckpointData(d, options));
760
+ }
761
+ async buildGenesisBlockResponse(options) {
762
+ const initial = this.worldStateSynchronizer.getCommitted().getInitialHeader();
763
+ const empty = L2Block.empty(initial);
764
+ const response = {
765
+ header: empty.header,
766
+ archive: empty.archive,
767
+ hash: await this.#getInitialHeaderHash(),
768
+ checkpointNumber: empty.checkpointNumber,
769
+ indexWithinCheckpoint: empty.indexWithinCheckpoint,
770
+ number: empty.number
771
+ };
772
+ if (options.includeTransactions) {
773
+ response.body = empty.body;
774
+ }
775
+ if (options.includeL1PublishInfo) {
776
+ response.l1 = {
777
+ published: false
778
+ };
779
+ }
780
+ if (options.includeAttestations) {
781
+ response.attestations = [];
782
+ }
783
+ return response;
784
+ }
492
785
  /**
493
786
  * initializes the Aztec Node, wait for component to sync.
494
787
  * @param config - The configuration to be used by the aztec node.
@@ -502,16 +795,27 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
502
795
  const telemetry = deps.telemetry ?? getTelemetryClient();
503
796
  const dateProvider = deps.dateProvider ?? new DateProvider();
504
797
  const ethereumChain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
505
- // Build a key store from file if given or from environment otherwise
798
+ // Build a key store from file if given or from environment otherwise.
799
+ // We keep the raw KeyStore available so we can merge with prover keys if enableProverNode is set.
506
800
  let keyStoreManager;
507
801
  const keyStoreProvided = config.keyStoreDirectory !== undefined && config.keyStoreDirectory.length > 0;
508
802
  if (keyStoreProvided) {
509
803
  const keyStores = loadKeystores(config.keyStoreDirectory);
510
804
  keyStoreManager = new KeystoreManager(mergeKeystores(keyStores));
511
805
  } else {
512
- const keyStore = createKeyStoreForValidator(config);
513
- if (keyStore) {
514
- keyStoreManager = new KeystoreManager(keyStore);
806
+ const rawKeyStores = [];
807
+ const validatorKeyStore = createKeyStoreForValidator(config);
808
+ if (validatorKeyStore) {
809
+ rawKeyStores.push(validatorKeyStore);
810
+ }
811
+ if (config.enableProverNode) {
812
+ const proverKeyStore = createKeyStoreForProver(config);
813
+ if (proverKeyStore) {
814
+ rawKeyStores.push(proverKeyStore);
815
+ }
816
+ }
817
+ if (rawKeyStores.length > 0) {
818
+ keyStoreManager = new KeystoreManager(rawKeyStores.length === 1 ? rawKeyStores[0] : mergeKeystores(rawKeyStores));
515
819
  }
516
820
  }
517
821
  await keyStoreManager?.validateSigners();
@@ -520,8 +824,8 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
520
824
  if (keyStoreManager === undefined) {
521
825
  throw new Error('Failed to create key store, a requirement for running a validator');
522
826
  }
523
- if (!keyStoreProvided) {
524
- log.warn('KEY STORE CREATED FROM ENVIRONMENT, IT IS RECOMMENDED TO USE A FILE-BASED KEY STORE IN PRODUCTION ENVIRONMENTS');
827
+ if (!keyStoreProvided && process.env.NODE_ENV !== 'test') {
828
+ log.warn("Keystore created from env: it's recommended to use a file-based key store for production");
525
829
  }
526
830
  ValidatorClient.validateKeyStoreConfiguration(keyStoreManager, log);
527
831
  }
@@ -531,9 +835,9 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
531
835
  }
532
836
  const publicClient = createPublicClient({
533
837
  chain: ethereumChain.chainInfo,
534
- transport: fallback(config.l1RpcUrls.map((url)=>http(url, {
535
- batch: false
536
- }))),
838
+ transport: makeL1HttpTransport(config.l1RpcUrls, {
839
+ timeout: config.l1HttpTimeoutMS
840
+ }),
537
841
  pollingInterval: config.viemPollingIntervalMS
538
842
  });
539
843
  const l1ContractsAddresses = await RegistryContract.collectAddresses(publicClient, config.l1Contracts.registryAddress, config.rollupVersion ?? 'canonical');
@@ -543,172 +847,277 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
543
847
  ...l1ContractsAddresses
544
848
  };
545
849
  const rollupContract = new RollupContract(publicClient, config.l1Contracts.rollupAddress.toString());
546
- const [l1GenesisTime, slotDuration, rollupVersionFromRollup] = await Promise.all([
850
+ const [l1GenesisTime, slotDuration, rollupVersionFromRollup, rollupManaLimit] = await Promise.all([
547
851
  rollupContract.getL1GenesisTime(),
548
852
  rollupContract.getSlotDuration(),
549
- rollupContract.getVersion()
853
+ rollupContract.getVersion(),
854
+ rollupContract.getManaLimit().then(Number)
550
855
  ]);
551
856
  config.rollupVersion ??= Number(rollupVersionFromRollup);
552
857
  if (config.rollupVersion !== Number(rollupVersionFromRollup)) {
553
858
  log.warn(`Registry looked up and returned a rollup with version (${config.rollupVersion}), but this does not match with version detected from the rollup directly: (${rollupVersionFromRollup}).`);
554
859
  }
555
- const blobClient = await createBlobClientWithFileStores(config, createLogger('node:blob-client:client'));
860
+ const blobClient = await createBlobClientWithFileStores(config, log.createChild('blob-client'));
556
861
  // attempt snapshot sync if possible
557
862
  await trySnapshotSync(config, log);
558
863
  const epochCache = await EpochCache.create(config.l1Contracts.rollupAddress, config, {
559
864
  dateProvider
560
865
  });
561
- const archiver = await createArchiver(config, {
562
- blobClient,
563
- epochCache,
564
- telemetry,
565
- dateProvider
566
- }, {
567
- blockUntilSync: !config.skipArchiverInitialSync
568
- });
569
- // now create the merkle trees and the world state synchronizer
570
- const worldStateSynchronizer = await createWorldStateSynchronizer(config, archiver, options.prefilledPublicData, telemetry);
571
- const circuitVerifier = config.realProofs || config.debugForceTxProofVerification ? await BBCircuitVerifier.new(config) : new TestCircuitVerifier(config.proverTestVerificationDelayMs);
572
- if (!config.realProofs) {
573
- log.warn(`Aztec node is accepting fake proofs`);
574
- }
575
- const proofVerifier = new QueuedIVCVerifier(config, circuitVerifier);
576
- // create the tx pool and the p2p client, which will need the l2 block source
577
- const p2pClient = await createP2PClient(P2PClientType.Full, config, archiver, proofVerifier, worldStateSynchronizer, epochCache, packageVersion, dateProvider, telemetry, deps.p2pClientDeps);
578
- // We should really not be modifying the config object
579
- config.txPublicSetupAllowList = config.txPublicSetupAllowList ?? await getDefaultAllowedSetupFunctions();
580
- // Create FullNodeCheckpointsBuilder for validator and non-validator block proposal handling
581
- const validatorCheckpointsBuilder = new FullNodeCheckpointsBuilder({
582
- ...config,
583
- l1GenesisTime,
584
- slotDuration: Number(slotDuration)
585
- }, worldStateSynchronizer, archiver, dateProvider, telemetry);
586
- // We'll accumulate sentinel watchers here
587
- const watchers = [];
588
- // Create validator client if required
589
- const validatorClient = await createValidatorClient(config, {
590
- checkpointsBuilder: validatorCheckpointsBuilder,
591
- worldState: worldStateSynchronizer,
592
- p2pClient,
593
- telemetry,
594
- dateProvider,
595
- epochCache,
596
- blockSource: archiver,
597
- l1ToL2MessageSource: archiver,
598
- keyStoreManager,
599
- blobClient
600
- });
601
- // If we have a validator client, register it as a source of offenses for the slasher,
602
- // and have it register callbacks on the p2p client *before* we start it, otherwise messages
603
- // like attestations or auths will fail.
604
- if (validatorClient) {
605
- watchers.push(validatorClient);
606
- if (!options.dontStartSequencer) {
607
- await validatorClient.registerHandlers();
608
- }
609
- }
610
- // If there's no validator client but alwaysReexecuteBlockProposals is enabled,
611
- // create a BlockProposalHandler to reexecute block proposals for monitoring
612
- if (!validatorClient && config.alwaysReexecuteBlockProposals) {
613
- log.info('Setting up block proposal reexecution for monitoring');
614
- createBlockProposalHandler(config, {
615
- checkpointsBuilder: validatorCheckpointsBuilder,
616
- worldState: worldStateSynchronizer,
866
+ // Track started resources so we can clean up on partial failure during node creation.
867
+ const started = [];
868
+ try {
869
+ const archiver = await createArchiver(config, {
870
+ blobClient,
617
871
  epochCache,
618
- blockSource: archiver,
619
- l1ToL2MessageSource: archiver,
620
- p2pClient,
621
- dateProvider,
622
- telemetry
623
- }).registerForReexecution(p2pClient);
624
- }
625
- // Start world state and wait for it to sync to the archiver.
626
- await worldStateSynchronizer.start();
627
- // Start p2p. Note that it depends on world state to be running.
628
- await p2pClient.start();
629
- const validatorsSentinel = await createSentinel(epochCache, archiver, p2pClient, config);
630
- if (validatorsSentinel && config.slashInactivityPenalty > 0n) {
631
- watchers.push(validatorsSentinel);
632
- }
633
- let epochPruneWatcher;
634
- if (config.slashPrunePenalty > 0n || config.slashDataWithholdingPenalty > 0n) {
635
- epochPruneWatcher = new EpochPruneWatcher(archiver, archiver, epochCache, p2pClient.getTxProvider(), validatorCheckpointsBuilder, config);
636
- watchers.push(epochPruneWatcher);
637
- }
638
- // We assume we want to slash for invalid attestations unless all max penalties are set to 0
639
- let attestationsBlockWatcher;
640
- if (config.slashProposeInvalidAttestationsPenalty > 0n || config.slashAttestDescendantOfInvalidPenalty > 0n) {
641
- attestationsBlockWatcher = new AttestationsBlockWatcher(archiver, epochCache, config);
642
- watchers.push(attestationsBlockWatcher);
643
- }
644
- // Start p2p-related services once the archiver has completed sync
645
- void archiver.waitForInitialSync().then(async ()=>{
646
- await p2pClient.start();
647
- await validatorsSentinel?.start();
648
- await epochPruneWatcher?.start();
649
- await attestationsBlockWatcher?.start();
650
- log.info(`All p2p services started`);
651
- }).catch((err)=>log.error('Failed to start p2p services after archiver sync', err));
652
- // Validator enabled, create/start relevant service
653
- let sequencer;
654
- let slasherClient;
655
- if (!config.disableValidator && validatorClient) {
656
- // We create a slasher only if we have a sequencer, since all slashing actions go through the sequencer publisher
657
- // as they are executed when the node is selected as proposer.
658
- const validatorAddresses = keyStoreManager ? NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager).getAddresses() : [];
659
- slasherClient = await createSlasher(config, config.l1Contracts, getPublicClient(config), watchers, dateProvider, epochCache, validatorAddresses, undefined);
660
- await slasherClient.start();
661
- const l1TxUtils = config.publisherForwarderAddress ? await createForwarderL1TxUtilsFromEthSigner(publicClient, keyStoreManager.createAllValidatorPublisherSigners(), config.publisherForwarderAddress, {
662
- ...config,
663
- scope: 'sequencer'
664
- }, {
665
872
  telemetry,
666
- logger: log.createChild('l1-tx-utils'),
667
873
  dateProvider
668
- }) : await createL1TxUtilsWithBlobsFromEthSigner(publicClient, keyStoreManager.createAllValidatorPublisherSigners(), {
669
- ...config,
670
- scope: 'sequencer'
671
874
  }, {
672
- telemetry,
673
- logger: log.createChild('l1-tx-utils'),
674
- dateProvider
875
+ blockUntilSync: !config.skipArchiverInitialSync
675
876
  });
676
- // Create and start the sequencer client
677
- const checkpointsBuilder = new CheckpointsBuilder({
678
- ...config,
877
+ started.push(archiver);
878
+ // now create the merkle trees and the world state synchronizer
879
+ const worldStateSynchronizer = await createWorldStateSynchronizer(config, archiver, options.genesis, telemetry);
880
+ started.push(worldStateSynchronizer);
881
+ const useRealVerifiers = config.realProofs || config.debugForceTxProofVerification;
882
+ let peerProofVerifier;
883
+ let rpcProofVerifier;
884
+ if (useRealVerifiers) {
885
+ peerProofVerifier = await BatchChonkVerifier.new(config, config.bbChonkVerifyMaxBatch, 'peer');
886
+ const rpcVerifier = await BBCircuitVerifier.new(config);
887
+ rpcProofVerifier = new QueuedIVCVerifier(rpcVerifier, config.numConcurrentIVCVerifiers);
888
+ } else {
889
+ peerProofVerifier = new TestCircuitVerifier(config.proverTestVerificationDelayMs);
890
+ rpcProofVerifier = new TestCircuitVerifier(config.proverTestVerificationDelayMs);
891
+ }
892
+ started.push(peerProofVerifier, rpcProofVerifier);
893
+ let debugLogStore;
894
+ if (!config.realProofs) {
895
+ log.warn(`Aztec node is accepting fake proofs`);
896
+ debugLogStore = new InMemoryDebugLogStore();
897
+ log.info('Aztec node started in test mode (realProofs set to false) hence debug logs from public functions will be collected and served');
898
+ } else {
899
+ debugLogStore = new NullDebugLogStore();
900
+ }
901
+ const globalVariableBuilderConfig = {
902
+ l1Contracts: config.l1Contracts,
903
+ ethereumSlotDuration: config.ethereumSlotDuration,
904
+ rollupVersion: BigInt(config.rollupVersion),
679
905
  l1GenesisTime,
680
906
  slotDuration: Number(slotDuration)
907
+ };
908
+ const globalVariableBuilder = new GlobalVariableBuilder(dateProvider, publicClient, globalVariableBuilderConfig);
909
+ const feeProvider = new FeeProviderImpl(dateProvider, publicClient, globalVariableBuilderConfig);
910
+ const proverOnly = config.enableProverNode && config.disableValidator;
911
+ if (proverOnly) {
912
+ log.info('Starting in prover-only mode: skipping validator, sequencer, sentinel, and slasher subsystems');
913
+ }
914
+ // create the tx pool and the p2p client, which will need the l2 block source
915
+ const p2pClient = await createP2PClient(config, archiver, peerProofVerifier, worldStateSynchronizer, epochCache, feeProvider, packageVersion, dateProvider, telemetry, deps.p2pClientDeps);
916
+ started.push(p2pClient);
917
+ // We'll accumulate sentinel watchers here
918
+ const watchers = [];
919
+ // Create FullNodeCheckpointsBuilder for block proposal handling and tx validation.
920
+ // Override maxTxsPerCheckpoint with the validator-specific limit if set.
921
+ const validatorCheckpointsBuilder = new FullNodeCheckpointsBuilder({
922
+ ...config,
923
+ l1GenesisTime,
924
+ slotDuration: Number(slotDuration),
925
+ rollupManaLimit,
926
+ maxTxsPerCheckpoint: config.validateMaxTxsPerCheckpoint
681
927
  }, worldStateSynchronizer, archiver, dateProvider, telemetry);
682
- sequencer = await SequencerClient.new(config, {
683
- ...deps,
684
- epochCache,
685
- l1TxUtils,
686
- validatorClient,
687
- p2pClient,
688
- worldStateSynchronizer,
689
- slasherClient,
690
- checkpointsBuilder,
691
- l2BlockSource: archiver,
692
- l1ToL2MessageSource: archiver,
693
- telemetry,
694
- dateProvider,
695
- blobClient,
696
- nodeKeyStore: keyStoreManager
697
- });
928
+ let validatorClient;
929
+ if (!config.disableValidator) {
930
+ // Create validator client if required
931
+ validatorClient = await createValidatorClient(config, {
932
+ checkpointsBuilder: validatorCheckpointsBuilder,
933
+ worldState: worldStateSynchronizer,
934
+ p2pClient,
935
+ telemetry,
936
+ dateProvider,
937
+ epochCache,
938
+ blockSource: archiver,
939
+ l1ToL2MessageSource: archiver,
940
+ keyStoreManager,
941
+ blobClient,
942
+ slashingProtectionDb: deps.slashingProtectionDb
943
+ });
944
+ // If we have a validator client, register it as a source of offenses for the slasher,
945
+ // and have it register callbacks on the p2p client *before* we start it, otherwise messages
946
+ // like attestations or auths will fail.
947
+ if (validatorClient) {
948
+ watchers.push(validatorClient);
949
+ const vc = validatorClient;
950
+ const getValidatorAddresses = ()=>vc.getValidatorAddresses().map((a)=>a.toString());
951
+ validatorClient.getProposalHandler().register(p2pClient, true, archiver, getValidatorAddresses);
952
+ if (!options.dontStartSequencer) {
953
+ await validatorClient.registerHandlers();
954
+ }
955
+ }
956
+ }
957
+ // If there's no validator client, create a ProposalHandler to handle block and checkpoint proposals
958
+ // for monitoring or reexecution. Reexecution (default) allows us to follow the pending chain,
959
+ // while non-reexecution is used for validating the proposals and collecting their txs.
960
+ // Checkpoint proposals rebuild blobs if the blob client can upload blobs.
961
+ if (!validatorClient) {
962
+ const reexecute = !!config.alwaysReexecuteBlockProposals;
963
+ log.info(`Setting up proposal handler` + (reexecute ? ' with reexecution of proposals' : ''));
964
+ createProposalHandler(config, {
965
+ checkpointsBuilder: validatorCheckpointsBuilder,
966
+ worldState: worldStateSynchronizer,
967
+ epochCache,
968
+ blockSource: archiver,
969
+ l1ToL2MessageSource: archiver,
970
+ p2pClient,
971
+ blobClient,
972
+ dateProvider,
973
+ telemetry
974
+ }).register(p2pClient, reexecute, archiver);
975
+ }
976
+ // Start world state and wait for it to sync to the archiver.
977
+ await worldStateSynchronizer.start();
978
+ // Start p2p. Note that it depends on world state to be running.
979
+ await p2pClient.start();
980
+ let validatorsSentinel;
981
+ let epochPruneWatcher;
982
+ let attestationsBlockWatcher;
983
+ if (!proverOnly) {
984
+ validatorsSentinel = await createSentinel(epochCache, archiver, p2pClient, config);
985
+ if (validatorsSentinel && config.slashInactivityPenalty > 0n) {
986
+ watchers.push(validatorsSentinel);
987
+ }
988
+ if (config.slashPrunePenalty > 0n || config.slashDataWithholdingPenalty > 0n) {
989
+ epochPruneWatcher = new EpochPruneWatcher(archiver, archiver, epochCache, p2pClient.getTxProvider(), validatorCheckpointsBuilder, config);
990
+ watchers.push(epochPruneWatcher);
991
+ }
992
+ // We assume we want to slash for invalid attestations unless all max penalties are set to 0
993
+ if (config.slashProposeInvalidAttestationsPenalty > 0n || config.slashAttestDescendantOfInvalidPenalty > 0n) {
994
+ attestationsBlockWatcher = new AttestationsBlockWatcher(archiver, epochCache, config);
995
+ watchers.push(attestationsBlockWatcher);
996
+ }
997
+ }
998
+ // Start p2p-related services once the archiver has completed sync
999
+ void archiver.waitForInitialSync().then(async ()=>{
1000
+ if (validatorsSentinel) {
1001
+ await validatorsSentinel.start();
1002
+ started.push(validatorsSentinel);
1003
+ }
1004
+ if (epochPruneWatcher) {
1005
+ await epochPruneWatcher.start();
1006
+ started.push(epochPruneWatcher);
1007
+ }
1008
+ if (attestationsBlockWatcher) {
1009
+ await attestationsBlockWatcher.start();
1010
+ started.push(attestationsBlockWatcher);
1011
+ }
1012
+ log.info(`All p2p services started`);
1013
+ }).catch((err)=>log.error('Failed to start p2p services after archiver sync', err));
1014
+ // Validator enabled, create/start relevant service
1015
+ let sequencer;
1016
+ let slasherClient;
1017
+ if (!config.disableValidator && validatorClient) {
1018
+ // We create a slasher only if we have a sequencer, since all slashing actions go through the sequencer publisher
1019
+ // as they are executed when the node is selected as proposer.
1020
+ const validatorAddresses = keyStoreManager ? NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager).getAddresses() : [];
1021
+ slasherClient = await createSlasher(config, config.l1Contracts, getPublicClient(config), watchers, dateProvider, epochCache, validatorAddresses, undefined);
1022
+ await slasherClient.start();
1023
+ started.push(slasherClient);
1024
+ const l1TxUtils = config.sequencerPublisherForwarderAddress ? await createForwarderL1TxUtilsFromSigners(publicClient, keyStoreManager.createAllValidatorPublisherSigners(), config.sequencerPublisherForwarderAddress, {
1025
+ ...config,
1026
+ scope: 'sequencer'
1027
+ }, {
1028
+ telemetry,
1029
+ logger: log.createChild('l1-tx-utils'),
1030
+ dateProvider,
1031
+ kzg: Blob.getViemKzgInstance()
1032
+ }) : await createL1TxUtilsFromSigners(publicClient, keyStoreManager.createAllValidatorPublisherSigners(), {
1033
+ ...config,
1034
+ scope: 'sequencer'
1035
+ }, {
1036
+ telemetry,
1037
+ logger: log.createChild('l1-tx-utils'),
1038
+ dateProvider,
1039
+ kzg: Blob.getViemKzgInstance()
1040
+ });
1041
+ // Create a funder L1TxUtils from the keystore funding account (if configured)
1042
+ const fundingSigner = keyStoreManager?.createFundingSigner();
1043
+ let funderL1TxUtils;
1044
+ if (fundingSigner) {
1045
+ const [funder] = await createL1TxUtilsFromSigners(publicClient, [
1046
+ fundingSigner
1047
+ ], {
1048
+ ...config,
1049
+ scope: 'sequencer'
1050
+ }, {
1051
+ telemetry,
1052
+ logger: log.createChild('l1-tx-utils:funder'),
1053
+ dateProvider
1054
+ });
1055
+ funderL1TxUtils = funder;
1056
+ }
1057
+ // Create and start the sequencer client
1058
+ const checkpointsBuilder = new CheckpointsBuilder({
1059
+ ...config,
1060
+ l1GenesisTime,
1061
+ slotDuration: Number(slotDuration),
1062
+ rollupManaLimit
1063
+ }, worldStateSynchronizer, archiver, dateProvider, telemetry, debugLogStore);
1064
+ sequencer = await SequencerClient.new(config, {
1065
+ ...deps,
1066
+ epochCache,
1067
+ l1TxUtils,
1068
+ funderL1TxUtils,
1069
+ validatorClient,
1070
+ p2pClient,
1071
+ worldStateSynchronizer,
1072
+ slasherClient,
1073
+ checkpointsBuilder,
1074
+ l2BlockSource: archiver,
1075
+ l1ToL2MessageSource: archiver,
1076
+ telemetry,
1077
+ dateProvider,
1078
+ blobClient,
1079
+ nodeKeyStore: keyStoreManager,
1080
+ globalVariableBuilder
1081
+ });
1082
+ }
1083
+ if (!options.dontStartSequencer && sequencer) {
1084
+ await sequencer.start();
1085
+ started.push(sequencer);
1086
+ log.verbose(`Sequencer started`);
1087
+ } else if (sequencer) {
1088
+ log.warn(`Sequencer created but not started`);
1089
+ }
1090
+ // Create prover node subsystem if enabled
1091
+ let proverNode;
1092
+ if (config.enableProverNode) {
1093
+ proverNode = await createProverNode(config, {
1094
+ ...deps.proverNodeDeps,
1095
+ telemetry,
1096
+ dateProvider,
1097
+ archiver,
1098
+ worldStateSynchronizer,
1099
+ p2pClient,
1100
+ epochCache,
1101
+ blobClient,
1102
+ keyStoreManager
1103
+ });
1104
+ if (!options.dontStartProverNode) {
1105
+ await proverNode.start();
1106
+ started.push(proverNode);
1107
+ log.info(`Prover node subsystem started`);
1108
+ } else {
1109
+ log.info(`Prover node subsystem created but not started`);
1110
+ }
1111
+ }
1112
+ const node = new AztecNodeService(config, p2pClient, archiver, archiver, archiver, archiver, worldStateSynchronizer, sequencer, proverNode, slasherClient, validatorsSentinel, epochPruneWatcher, attestationsBlockWatcher, ethereumChain.chainInfo.id, config.rollupVersion, globalVariableBuilder, feeProvider, epochCache, packageVersion, peerProofVerifier, rpcProofVerifier, telemetry, log, blobClient, validatorClient, keyStoreManager, debugLogStore);
1113
+ return node;
1114
+ } catch (err) {
1115
+ log.error('Failed during node creation, stopping started resources', err);
1116
+ for (const resource of started.reverse()){
1117
+ await tryStop(resource);
1118
+ }
1119
+ throw err;
698
1120
  }
699
- if (!options.dontStartSequencer && sequencer) {
700
- await sequencer.start();
701
- log.verbose(`Sequencer started`);
702
- } else if (sequencer) {
703
- log.warn(`Sequencer created but not started`);
704
- }
705
- const globalVariableBuilder = new GlobalVariableBuilder({
706
- ...config,
707
- rollupVersion: BigInt(config.rollupVersion),
708
- l1GenesisTime,
709
- slotDuration: Number(slotDuration)
710
- });
711
- return new AztecNodeService(config, p2pClient, archiver, archiver, archiver, archiver, worldStateSynchronizer, sequencer, slasherClient, validatorsSentinel, epochPruneWatcher, ethereumChain.chainInfo.id, config.rollupVersion, globalVariableBuilder, epochCache, packageVersion, proofVerifier, telemetry, log, blobClient);
712
1121
  }
713
1122
  /**
714
1123
  * Returns the sequencer client instance.
@@ -716,6 +1125,9 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
716
1125
  */ getSequencer() {
717
1126
  return this.sequencer;
718
1127
  }
1128
+ /** Returns the prover node subsystem, if enabled. */ getProverNode() {
1129
+ return this.proverNode;
1130
+ }
719
1131
  getBlockSource() {
720
1132
  return this.blockSource;
721
1133
  }
@@ -735,7 +1147,10 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
735
1147
  return Promise.resolve(this.p2pClient.getEnr()?.encodeTxt());
736
1148
  }
737
1149
  async getAllowedPublicSetup() {
738
- return this.config.txPublicSetupAllowList ?? await getDefaultAllowedSetupFunctions();
1150
+ return [
1151
+ ...await getDefaultAllowedSetupFunctions(),
1152
+ ...this.config.txPublicSetupAllowListExtend ?? []
1153
+ ];
739
1154
  }
740
1155
  /**
741
1156
  * Method to determine if the node is ready to accept transactions.
@@ -758,65 +1173,16 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
758
1173
  rollupVersion,
759
1174
  enr,
760
1175
  l1ContractAddresses: contractAddresses,
761
- protocolContractAddresses: protocolContractAddresses
1176
+ protocolContractAddresses: protocolContractAddresses,
1177
+ realProofs: !!this.config.realProofs
762
1178
  };
763
1179
  return nodeInfo;
764
1180
  }
765
- /**
766
- * Get a block specified by its block number, block hash, or 'latest'.
767
- * @param block - The block parameter (block number, block hash, or 'latest').
768
- * @returns The requested block.
769
- */ async getBlock(block) {
770
- if (BlockHash.isBlockHash(block)) {
771
- return this.getBlockByHash(block);
772
- }
773
- const blockNumber = block === 'latest' ? await this.getBlockNumber() : block;
774
- if (blockNumber === BlockNumber.ZERO) {
775
- return this.buildInitialBlock();
776
- }
777
- return await this.blockSource.getL2Block(blockNumber);
778
- }
779
- /**
780
- * Get a block specified by its hash.
781
- * @param blockHash - The block hash being requested.
782
- * @returns The requested block.
783
- */ async getBlockByHash(blockHash) {
784
- const initialBlockHash = await this.#getInitialHeaderHash();
785
- if (blockHash.equals(initialBlockHash)) {
786
- return this.buildInitialBlock();
787
- }
788
- return await this.blockSource.getL2BlockByHash(blockHash);
1181
+ async getCurrentMinFees() {
1182
+ return await this.feeProvider.getCurrentMinFees();
789
1183
  }
790
- buildInitialBlock() {
791
- const initialHeader = this.worldStateSynchronizer.getCommitted().getInitialHeader();
792
- return L2Block.empty(initialHeader);
793
- }
794
- /**
795
- * Get a block specified by its archive root.
796
- * @param archive - The archive root being requested.
797
- * @returns The requested block.
798
- */ async getBlockByArchive(archive) {
799
- return await this.blockSource.getL2BlockByArchive(archive);
800
- }
801
- /**
802
- * Method to request blocks. Will attempt to return all requested blocks but will return only those available.
803
- * @param from - The start of the range of blocks to return.
804
- * @param limit - The maximum number of blocks to obtain.
805
- * @returns The blocks requested.
806
- */ async getBlocks(from, limit) {
807
- return await this.blockSource.getBlocks(from, BlockNumber(limit)) ?? [];
808
- }
809
- async getCheckpoints(from, limit) {
810
- return await this.blockSource.getCheckpoints(from, limit) ?? [];
811
- }
812
- async getCheckpointedBlocks(from, limit) {
813
- return await this.blockSource.getCheckpointedBlocks(from, limit) ?? [];
814
- }
815
- /**
816
- * Method to fetch the current min L2 fees.
817
- * @returns The current min L2 fees.
818
- */ async getCurrentMinFees() {
819
- return await this.globalVariableBuilder.getCurrentMinFees();
1184
+ /** Returns predicted min fees for the current slot and next N slots. */ async getPredictedMinFees(manaUsage) {
1185
+ return await this.feeProvider.getPredictedMinFees(manaUsage);
820
1186
  }
821
1187
  async getMaxPriorityFees() {
822
1188
  for await (const tx of this.p2pClient.iteratePendingTxs()){
@@ -828,18 +1194,6 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
828
1194
  });
829
1195
  }
830
1196
  /**
831
- * Method to fetch the latest block number synchronized by the node.
832
- * @returns The block number.
833
- */ async getBlockNumber() {
834
- return await this.blockSource.getBlockNumber();
835
- }
836
- async getProvenBlockNumber() {
837
- return await this.blockSource.getProvenBlockNumber();
838
- }
839
- async getCheckpointedBlockNumber() {
840
- return await this.blockSource.getCheckpointedL2BlockNumber();
841
- }
842
- /**
843
1197
  * Method to fetch the version of the package.
844
1198
  * @returns The node package version
845
1199
  */ getNodeVersion() {
@@ -864,28 +1218,36 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
864
1218
  return this.contractDataSource.getContract(address);
865
1219
  }
866
1220
  async getPrivateLogsByTags(tags, page, referenceBlock) {
1221
+ let upToBlockNumber;
867
1222
  if (referenceBlock) {
868
1223
  const initialBlockHash = await this.#getInitialHeaderHash();
869
- if (!referenceBlock.equals(initialBlockHash)) {
1224
+ if (referenceBlock.equals(initialBlockHash)) {
1225
+ upToBlockNumber = BlockNumber(0);
1226
+ } else {
870
1227
  const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
871
1228
  if (!header) {
872
1229
  throw new Error(`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`);
873
1230
  }
1231
+ upToBlockNumber = header.globalVariables.blockNumber;
874
1232
  }
875
1233
  }
876
- return this.logsSource.getPrivateLogsByTags(tags, page);
1234
+ return this.logsSource.getPrivateLogsByTags(tags, page, upToBlockNumber);
877
1235
  }
878
1236
  async getPublicLogsByTagsFromContract(contractAddress, tags, page, referenceBlock) {
1237
+ let upToBlockNumber;
879
1238
  if (referenceBlock) {
880
1239
  const initialBlockHash = await this.#getInitialHeaderHash();
881
- if (!referenceBlock.equals(initialBlockHash)) {
1240
+ if (referenceBlock.equals(initialBlockHash)) {
1241
+ upToBlockNumber = BlockNumber(0);
1242
+ } else {
882
1243
  const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
883
1244
  if (!header) {
884
1245
  throw new Error(`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`);
885
1246
  }
1247
+ upToBlockNumber = header.globalVariables.blockNumber;
886
1248
  }
887
1249
  }
888
- return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page);
1250
+ return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page, upToBlockNumber);
889
1251
  }
890
1252
  /**
891
1253
  * Gets public logs based on the provided filter.
@@ -919,9 +1281,18 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
919
1281
  });
920
1282
  throw new Error(`Invalid tx: ${reason}`);
921
1283
  }
922
- await this.p2pClient.sendTx(tx);
923
- this.metrics.receivedTx(timer.ms(), true);
924
- this.log.info(`Received tx ${txHash}`, {
1284
+ try {
1285
+ await this.p2pClient.sendTx(tx);
1286
+ } catch (err) {
1287
+ this.metrics.receivedTx(timer.ms(), false);
1288
+ this.log.warn(`Mempool rejected tx ${txHash}: ${err.message}`, {
1289
+ txHash
1290
+ });
1291
+ throw err;
1292
+ }
1293
+ const duration = timer.ms();
1294
+ this.metrics.receivedTx(duration, true);
1295
+ this.log.info(`Received tx ${txHash} in ${duration}ms`, {
925
1296
  txHash
926
1297
  });
927
1298
  }
@@ -932,18 +1303,20 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
932
1303
  const isKnownToPool = txPoolStatus === 'pending' || txPoolStatus === 'mined';
933
1304
  // Then get the actual tx from the archiver, which tracks every tx in a mined block.
934
1305
  const settledTxReceipt = await this.blockSource.getSettledTxReceipt(txHash);
1306
+ let receipt;
935
1307
  if (settledTxReceipt) {
936
- // If the archiver has the receipt then return it.
937
- return settledTxReceipt;
1308
+ receipt = settledTxReceipt;
938
1309
  } else if (isKnownToPool) {
939
1310
  // If the tx is in the pool but not in the archiver, it's pending.
940
1311
  // This handles race conditions between archiver and p2p, where the archiver
941
1312
  // has pruned the block in which a tx was mined, but p2p has not caught up yet.
942
- return new TxReceipt(txHash, TxStatus.PENDING, undefined, undefined);
1313
+ receipt = new TxReceipt(txHash, TxStatus.PENDING, /*executionResult=*/ undefined, /*error=*/ undefined);
943
1314
  } else {
944
1315
  // Otherwise, if we don't know the tx, we consider it dropped.
945
- return new TxReceipt(txHash, TxStatus.DROPPED, undefined, 'Tx dropped by P2P node');
1316
+ receipt = new TxReceipt(txHash, TxStatus.DROPPED, /*executionResult=*/ undefined, /*error=*/ 'Tx dropped by P2P node');
946
1317
  }
1318
+ this.debugLogStore.decorateReceiptWithLogs(txHash.toString(), receipt);
1319
+ return receipt;
947
1320
  }
948
1321
  getTxEffect(txHash) {
949
1322
  return this.blockSource.getTxEffect(txHash);
@@ -952,11 +1325,16 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
952
1325
  * Method to stop the aztec node.
953
1326
  */ async stop() {
954
1327
  this.log.info(`Stopping Aztec Node`);
1328
+ await tryStop(this.attestationsBlockWatcher);
955
1329
  await tryStop(this.validatorsSentinel);
956
1330
  await tryStop(this.epochPruneWatcher);
957
1331
  await tryStop(this.slasherClient);
958
- await tryStop(this.proofVerifier);
1332
+ await Promise.all([
1333
+ tryStop(this.peerProofVerifier),
1334
+ tryStop(this.rpcProofVerifier)
1335
+ ]);
959
1336
  await tryStop(this.sequencer);
1337
+ await tryStop(this.proverNode);
960
1338
  await tryStop(this.p2pClient);
961
1339
  await tryStop(this.worldStateSynchronizer);
962
1340
  await tryStop(this.blockSource);
@@ -996,70 +1374,82 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
996
1374
  return compactArray(await Promise.all(txHashes.map((txHash)=>this.getTxByHash(txHash))));
997
1375
  }
998
1376
  async findLeavesIndexes(referenceBlock, treeId, leafValues) {
999
- const committedDb = await this.#getWorldState(referenceBlock);
1377
+ const committedDb = await this.getWorldState(referenceBlock);
1000
1378
  const maybeIndices = await committedDb.findLeafIndices(treeId, leafValues.map((x)=>x.toBuffer()));
1001
- // We filter out undefined values
1002
- const indices = maybeIndices.filter((x)=>x !== undefined);
1003
- // Now we find the block numbers for the indices
1004
- const blockNumbers = await committedDb.getBlockNumbersForLeafIndices(treeId, indices);
1005
- // If any of the block numbers are undefined, we throw an error.
1006
- for(let i = 0; i < indices.length; i++){
1007
- if (blockNumbers[i] === undefined) {
1008
- throw new Error(`Block number is undefined for leaf index ${indices[i]} in tree ${MerkleTreeId[treeId]}`);
1379
+ // Filter out undefined values to query block numbers only for found leaves
1380
+ const definedIndices = maybeIndices.filter((x)=>x !== undefined);
1381
+ // Now we find the block numbers for the defined indices
1382
+ const blockNumbers = await committedDb.getBlockNumbersForLeafIndices(treeId, definedIndices);
1383
+ // Build a map from leaf index to block number
1384
+ const indexToBlockNumber = new Map();
1385
+ for(let i = 0; i < definedIndices.length; i++){
1386
+ const blockNumber = blockNumbers[i];
1387
+ if (blockNumber === undefined) {
1388
+ throw new Error(`Block number is undefined for leaf index ${definedIndices[i]} in tree ${MerkleTreeId[treeId]}`);
1009
1389
  }
1390
+ indexToBlockNumber.set(definedIndices[i], blockNumber);
1010
1391
  }
1011
1392
  // Get unique block numbers in order to optimize num calls to getLeafValue function.
1012
1393
  const uniqueBlockNumbers = [
1013
- ...new Set(blockNumbers.filter((x)=>x !== undefined))
1394
+ ...new Set(indexToBlockNumber.values())
1014
1395
  ];
1015
- // Now we obtain the block hashes from the archive tree by calling await `committedDb.getLeafValue(treeId, index)`
1016
- // (note that block number corresponds to the leaf index in the archive tree).
1396
+ // Now we obtain the block hashes from the archive tree (block number = leaf index in archive tree).
1017
1397
  const blockHashes = await Promise.all(uniqueBlockNumbers.map((blockNumber)=>{
1018
1398
  return committedDb.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
1019
1399
  }));
1020
- // If any of the block hashes are undefined, we throw an error.
1400
+ // Build a map from block number to block hash
1401
+ const blockNumberToHash = new Map();
1021
1402
  for(let i = 0; i < uniqueBlockNumbers.length; i++){
1022
- if (blockHashes[i] === undefined) {
1403
+ const blockHash = blockHashes[i];
1404
+ if (blockHash === undefined) {
1023
1405
  throw new Error(`Block hash is undefined for block number ${uniqueBlockNumbers[i]}`);
1024
1406
  }
1407
+ blockNumberToHash.set(uniqueBlockNumbers[i], blockHash);
1025
1408
  }
1026
1409
  // Create DataInBlock objects by combining indices, blockNumbers and blockHashes and return them.
1027
- return maybeIndices.map((index, i)=>{
1410
+ return maybeIndices.map((index)=>{
1028
1411
  if (index === undefined) {
1029
1412
  return undefined;
1030
1413
  }
1031
- const blockNumber = blockNumbers[i];
1414
+ const blockNumber = indexToBlockNumber.get(index);
1032
1415
  if (blockNumber === undefined) {
1033
- return undefined;
1416
+ throw new Error(`Block number not found for leaf index ${index} in tree ${MerkleTreeId[treeId]}`);
1034
1417
  }
1035
- const blockHashIndex = uniqueBlockNumbers.indexOf(blockNumber);
1036
- const blockHash = blockHashes[blockHashIndex];
1037
- if (!blockHash) {
1038
- return undefined;
1418
+ const l2BlockHash = blockNumberToHash.get(blockNumber);
1419
+ if (l2BlockHash === undefined) {
1420
+ throw new Error(`Block hash not found for block number ${blockNumber}`);
1039
1421
  }
1040
1422
  return {
1041
- l2BlockNumber: BlockNumber(Number(blockNumber)),
1042
- l2BlockHash: new BlockHash(blockHash),
1423
+ l2BlockNumber: blockNumber,
1424
+ l2BlockHash,
1043
1425
  data: index
1044
1426
  };
1045
1427
  });
1046
1428
  }
1047
1429
  async getBlockHashMembershipWitness(referenceBlock, blockHash) {
1048
- const committedDb = await this.#getWorldState(referenceBlock);
1430
+ // The Noir circuit checks the archive membership proof against `anchor_block_header.last_archive.root`,
1431
+ // which is the archive tree root BEFORE the anchor block was added (i.e. the state after block N-1).
1432
+ // So we need the world state at block N-1, not block N, to produce a sibling path matching that root.
1433
+ const referenceBlockNumber = await this.resolveBlockNumber(referenceBlock);
1434
+ if (referenceBlockNumber === BlockNumber.ZERO) {
1435
+ // Block 0 (the initial block) has an empty archive, so no membership witness can exist.
1436
+ return undefined;
1437
+ }
1438
+ const committedDb = await this.getWorldState(BlockNumber(referenceBlockNumber - 1));
1049
1439
  const [pathAndIndex] = await committedDb.findSiblingPaths(MerkleTreeId.ARCHIVE, [
1050
1440
  blockHash
1051
1441
  ]);
1052
1442
  return pathAndIndex === undefined ? undefined : MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
1053
1443
  }
1054
1444
  async getNoteHashMembershipWitness(referenceBlock, noteHash) {
1055
- const committedDb = await this.#getWorldState(referenceBlock);
1445
+ const committedDb = await this.getWorldState(referenceBlock);
1056
1446
  const [pathAndIndex] = await committedDb.findSiblingPaths(MerkleTreeId.NOTE_HASH_TREE, [
1057
1447
  noteHash
1058
1448
  ]);
1059
1449
  return pathAndIndex === undefined ? undefined : MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
1060
1450
  }
1061
1451
  async getL1ToL2MessageMembershipWitness(referenceBlock, l1ToL2Message) {
1062
- const db = await this.#getWorldState(referenceBlock);
1452
+ const db = await this.getWorldState(referenceBlock);
1063
1453
  const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [
1064
1454
  l1ToL2Message
1065
1455
  ]);
@@ -1072,9 +1462,9 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
1072
1462
  witness.path
1073
1463
  ];
1074
1464
  }
1075
- async getL1ToL2MessageBlock(l1ToL2Message) {
1465
+ async getL1ToL2MessageCheckpoint(l1ToL2Message) {
1076
1466
  const messageIndex = await this.l1ToL2MessageSource.getL1ToL2MessageIndex(l1ToL2Message);
1077
- return messageIndex ? BlockNumber.fromCheckpointNumber(InboxLeaf.checkpointNumberFromIndex(messageIndex)) : undefined;
1467
+ return messageIndex ? InboxLeaf.checkpointNumberFromIndex(messageIndex) : undefined;
1078
1468
  }
1079
1469
  /**
1080
1470
  * Returns whether an L1 to L2 message is synced by archiver and if it's ready to be included in a block.
@@ -1091,23 +1481,11 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
1091
1481
  */ async getL2ToL1Messages(epoch) {
1092
1482
  // Assumes `getCheckpointedBlocksForEpoch` returns blocks in ascending order of block number.
1093
1483
  const checkpointedBlocks = await this.blockSource.getCheckpointedBlocksForEpoch(epoch);
1094
- const blocksInCheckpoints = [];
1095
- let previousSlotNumber = SlotNumber.ZERO;
1096
- let checkpointIndex = -1;
1097
- for (const checkpointedBlock of checkpointedBlocks){
1098
- const block = checkpointedBlock.block;
1099
- const slotNumber = block.header.globalVariables.slotNumber;
1100
- if (slotNumber !== previousSlotNumber) {
1101
- checkpointIndex++;
1102
- blocksInCheckpoints.push([]);
1103
- previousSlotNumber = slotNumber;
1104
- }
1105
- blocksInCheckpoints[checkpointIndex].push(block);
1106
- }
1484
+ const blocksInCheckpoints = chunkBy(checkpointedBlocks, (cb)=>cb.block.header.globalVariables.slotNumber).map((group)=>group.map((cb)=>cb.block));
1107
1485
  return blocksInCheckpoints.map((blocks)=>blocks.map((block)=>block.body.txEffects.map((txEffect)=>txEffect.l2ToL1Msgs)));
1108
1486
  }
1109
1487
  async getNullifierMembershipWitness(referenceBlock, nullifier) {
1110
- const db = await this.#getWorldState(referenceBlock);
1488
+ const db = await this.getWorldState(referenceBlock);
1111
1489
  const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [
1112
1490
  nullifier.toBuffer()
1113
1491
  ]);
@@ -1121,36 +1499,22 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
1121
1499
  }
1122
1500
  return new NullifierMembershipWitness(index, leafPreimage, path);
1123
1501
  }
1124
- /**
1125
- * Returns a low nullifier membership witness for a given nullifier at a given block.
1126
- * @param referenceBlock - The block parameter (block number, block hash, or 'latest') at which to get the data
1127
- * (which contains the root of the nullifier tree in which we are searching for the nullifier).
1128
- * @param nullifier - Nullifier we try to find the low nullifier witness for.
1129
- * @returns The low nullifier membership witness (if found).
1130
- * @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
1131
- * list structure" of leaves and proving that a lower nullifier is pointing to a bigger next value than the nullifier
1132
- * we are trying to prove non-inclusion for.
1133
- *
1134
- * Note: This function returns the membership witness of the nullifier itself and not the low nullifier when
1135
- * the nullifier already exists in the tree. This is because the `getPreviousValueIndex` function returns the
1136
- * index of the nullifier itself when it already exists in the tree.
1137
- * TODO: This is a confusing behavior and we should eventually address that.
1138
- */ async getLowNullifierMembershipWitness(referenceBlock, nullifier) {
1139
- const committedDb = await this.#getWorldState(referenceBlock);
1502
+ async getLowNullifierMembershipWitness(referenceBlock, nullifier) {
1503
+ const committedDb = await this.getWorldState(referenceBlock);
1140
1504
  const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
1141
1505
  if (!findResult) {
1142
1506
  return undefined;
1143
1507
  }
1144
1508
  const { index, alreadyPresent } = findResult;
1145
1509
  if (alreadyPresent) {
1146
- this.log.warn(`Nullifier ${nullifier.toBigInt()} already exists in the tree`);
1510
+ throw new Error(`Cannot prove nullifier non-inclusion: nullifier ${nullifier.toBigInt()} already exists in the tree`);
1147
1511
  }
1148
1512
  const preimageData = await committedDb.getLeafPreimage(MerkleTreeId.NULLIFIER_TREE, index);
1149
1513
  const siblingPath = await committedDb.getSiblingPath(MerkleTreeId.NULLIFIER_TREE, BigInt(index));
1150
1514
  return new NullifierMembershipWitness(BigInt(index), preimageData, siblingPath);
1151
1515
  }
1152
1516
  async getPublicDataWitness(referenceBlock, leafSlot) {
1153
- const committedDb = await this.#getWorldState(referenceBlock);
1517
+ const committedDb = await this.getWorldState(referenceBlock);
1154
1518
  const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
1155
1519
  if (!lowLeafResult) {
1156
1520
  return undefined;
@@ -1161,7 +1525,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
1161
1525
  }
1162
1526
  }
1163
1527
  async getPublicStorageAt(referenceBlock, contract, slot) {
1164
- const committedDb = await this.#getWorldState(referenceBlock);
1528
+ const committedDb = await this.getWorldState(referenceBlock);
1165
1529
  const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
1166
1530
  const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
1167
1531
  if (!lowLeafResult || !lowLeafResult.alreadyPresent) {
@@ -1170,30 +1534,6 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
1170
1534
  const preimage = await committedDb.getLeafPreimage(MerkleTreeId.PUBLIC_DATA_TREE, lowLeafResult.index);
1171
1535
  return preimage.leaf.value;
1172
1536
  }
1173
- async getBlockHeader(block = 'latest') {
1174
- if (BlockHash.isBlockHash(block)) {
1175
- const initialBlockHash = await this.#getInitialHeaderHash();
1176
- if (block.equals(initialBlockHash)) {
1177
- // Block source doesn't handle initial header so we need to handle the case separately.
1178
- return this.worldStateSynchronizer.getCommitted().getInitialHeader();
1179
- }
1180
- return this.blockSource.getBlockHeaderByHash(block);
1181
- } else {
1182
- // Block source doesn't handle initial header so we need to handle the case separately.
1183
- const blockNumber = block === 'latest' ? await this.getBlockNumber() : block;
1184
- if (blockNumber === BlockNumber.ZERO) {
1185
- return this.worldStateSynchronizer.getCommitted().getInitialHeader();
1186
- }
1187
- return this.blockSource.getBlockHeader(block);
1188
- }
1189
- }
1190
- /**
1191
- * Get a block header specified by its archive root.
1192
- * @param archive - The archive root being requested.
1193
- * @returns The requested block header.
1194
- */ async getBlockHeaderByArchive(archive) {
1195
- return await this.blockSource.getBlockHeaderByArchive(archive);
1196
- }
1197
1537
  /**
1198
1538
  * Simulates the public part of a transaction with the current state.
1199
1539
  * @param tx - The transaction to simulate.
@@ -1206,7 +1546,8 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
1206
1546
  throw new BadRequestError(`Transaction total gas limit ${txGasLimit + teardownGasLimit} (${txGasLimit} + ${teardownGasLimit}) exceeds maximum gas limit ${this.config.rpcSimulatePublicMaxGasLimit} for simulation`);
1207
1547
  }
1208
1548
  const txHash = tx.getTxHash();
1209
- const blockNumber = BlockNumber(await this.blockSource.getBlockNumber() + 1);
1549
+ const latestBlockNumber = await this.blockSource.getBlockNumber();
1550
+ const blockNumber = BlockNumber.add(latestBlockNumber, 1);
1210
1551
  // If sequencer is not initialized, we just set these values to zero for simulation.
1211
1552
  const coinbase = EthAddress.ZERO;
1212
1553
  const feeRecipient = AztecAddress.ZERO;
@@ -1217,6 +1558,8 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
1217
1558
  txHash,
1218
1559
  blockNumber
1219
1560
  });
1561
+ // Ensure world-state has caught up with the latest block we loaded from the archiver
1562
+ await this.worldStateSynchronizer.syncImmediate(latestBlockNumber);
1220
1563
  const merkleTreeFork = await this.worldStateSynchronizer.fork();
1221
1564
  try {
1222
1565
  const config = PublicSimulatorConfig.from({
@@ -1231,7 +1574,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
1231
1574
  });
1232
1575
  const processor = publicProcessorFactory.create(merkleTreeFork, newGlobalVariables, config);
1233
1576
  // REFACTOR: Consider merging ProcessReturnValues into ProcessedTx
1234
- const [processedTxs, failedTxs, _usedTxs, returns] = await processor.process([
1577
+ const [processedTxs, failedTxs, _usedTxs, returns, debugLogs] = await processor.process([
1235
1578
  tx
1236
1579
  ]);
1237
1580
  // REFACTOR: Consider returning the error rather than throwing
@@ -1242,26 +1585,33 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
1242
1585
  throw failedTxs[0].error;
1243
1586
  }
1244
1587
  const [processedTx] = processedTxs;
1245
- return new PublicSimulationOutput(processedTx.revertReason, processedTx.globalVariables, processedTx.txEffect, returns, processedTx.gasUsed);
1588
+ return new PublicSimulationOutput(processedTx.revertReason, processedTx.globalVariables, processedTx.txEffect, returns, processedTx.gasUsed, debugLogs);
1246
1589
  } finally{
1247
1590
  await merkleTreeFork.close();
1248
1591
  }
1249
1592
  }
1250
1593
  async isValidTx(tx, { isSimulation, skipFeeEnforcement } = {}) {
1251
1594
  const db = this.worldStateSynchronizer.getCommitted();
1252
- const verifier = isSimulation ? undefined : this.proofVerifier;
1253
- // We accept transactions if they are not expired by the next slot (checked based on the IncludeByTimestamp field)
1595
+ const verifier = isSimulation ? undefined : this.rpcProofVerifier;
1596
+ // We accept transactions if they are not expired by the next slot (checked based on the ExpirationTimestamp field)
1254
1597
  const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
1255
1598
  const blockNumber = BlockNumber(await this.blockSource.getBlockNumber() + 1);
1256
- const validator = createValidatorForAcceptingTxs(db, this.contractDataSource, verifier, {
1599
+ const l1Constants = await this.blockSource.getL1Constants();
1600
+ const validator = createTxValidatorForAcceptingTxsOverRPC(db, this.contractDataSource, verifier, {
1257
1601
  timestamp: nextSlotTimestamp,
1258
1602
  blockNumber,
1259
1603
  l1ChainId: this.l1ChainId,
1260
1604
  rollupVersion: this.version,
1261
- setupAllowList: this.config.txPublicSetupAllowList ?? await getDefaultAllowedSetupFunctions(),
1605
+ setupAllowList: [
1606
+ ...await getDefaultAllowedSetupFunctions(),
1607
+ ...this.config.txPublicSetupAllowListExtend ?? []
1608
+ ],
1262
1609
  gasFees: await this.getCurrentMinFees(),
1263
1610
  skipFeeEnforcement,
1264
- txsPermitted: !this.config.disableTransactions
1611
+ txsPermitted: !this.config.disableTransactions,
1612
+ rollupManaLimit: l1Constants.rollupManaLimit,
1613
+ maxBlockL2Gas: this.config.validateMaxL2BlockGas,
1614
+ maxBlockDAGas: this.config.validateMaxDABlockGas
1265
1615
  }, this.log.getBindings());
1266
1616
  return await validator.validateTx(tx);
1267
1617
  }
@@ -1284,7 +1634,18 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
1284
1634
  archiver.updateConfig(config);
1285
1635
  }
1286
1636
  if (newConfig.realProofs !== this.config.realProofs) {
1287
- this.proofVerifier = config.realProofs ? await BBCircuitVerifier.new(newConfig) : new TestCircuitVerifier();
1637
+ await Promise.all([
1638
+ tryStop(this.peerProofVerifier),
1639
+ tryStop(this.rpcProofVerifier)
1640
+ ]);
1641
+ if (newConfig.realProofs) {
1642
+ this.peerProofVerifier = await BatchChonkVerifier.new(newConfig, newConfig.bbChonkVerifyMaxBatch, 'peer');
1643
+ const rpcVerifier = await BBCircuitVerifier.new(newConfig);
1644
+ this.rpcProofVerifier = new QueuedIVCVerifier(rpcVerifier, newConfig.numConcurrentIVCVerifiers);
1645
+ } else {
1646
+ this.peerProofVerifier = new TestCircuitVerifier();
1647
+ this.rpcProofVerifier = new TestCircuitVerifier();
1648
+ }
1288
1649
  }
1289
1650
  this.config = newConfig;
1290
1651
  }
@@ -1344,7 +1705,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
1344
1705
  });
1345
1706
  return Promise.resolve();
1346
1707
  }
1347
- async rollbackTo(targetBlock, force) {
1708
+ async rollbackTo(targetBlock, force, resumeSync = true) {
1348
1709
  const archiver = this.blockSource;
1349
1710
  if (!('rollbackTo' in archiver)) {
1350
1711
  throw new Error('Archiver implementation does not support rollbacks.');
@@ -1372,9 +1733,13 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
1372
1733
  this.log.error(`Error during rollback`, err);
1373
1734
  throw err;
1374
1735
  } finally{
1375
- this.log.info(`Resuming world state and archiver sync.`);
1376
- this.worldStateSynchronizer.resumeSync();
1377
- archiver.resume();
1736
+ if (resumeSync) {
1737
+ this.log.info(`Resuming world state and archiver sync.`);
1738
+ this.worldStateSynchronizer.resumeSync();
1739
+ archiver.resume();
1740
+ } else {
1741
+ this.log.info(`Sync left paused after rollback (resumeSync=false).`);
1742
+ }
1378
1743
  }
1379
1744
  }
1380
1745
  async pauseSync() {
@@ -1388,22 +1753,110 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
1388
1753
  this.blockSource.resume();
1389
1754
  return Promise.resolve();
1390
1755
  }
1391
- getSlashPayloads() {
1392
- if (!this.slasherClient) {
1393
- throw new Error(`Slasher client not enabled`);
1394
- }
1395
- return this.slasherClient.getSlashPayloads();
1396
- }
1397
1756
  getSlashOffenses(round) {
1398
1757
  if (!this.slasherClient) {
1399
1758
  throw new Error(`Slasher client not enabled`);
1400
1759
  }
1401
1760
  if (round === 'all') {
1402
- return this.slasherClient.getPendingOffenses();
1761
+ return this.slasherClient.getOffenses();
1403
1762
  } else {
1404
1763
  return this.slasherClient.gatherOffensesForRound(round === 'current' ? undefined : BigInt(round));
1405
1764
  }
1406
1765
  }
1766
+ async reloadKeystore() {
1767
+ if (!this.config.keyStoreDirectory?.length) {
1768
+ throw new BadRequestError('Cannot reload keystore: node is not using a file-based keystore. ' + 'Set KEY_STORE_DIRECTORY to use file-based keystores.');
1769
+ }
1770
+ if (!this.validatorClient) {
1771
+ throw new BadRequestError('Cannot reload keystore: validator is not enabled.');
1772
+ }
1773
+ this.log.info('Reloading keystore from disk');
1774
+ // Re-read and validate keystore files
1775
+ const keyStores = loadKeystores(this.config.keyStoreDirectory);
1776
+ const newManager = new KeystoreManager(mergeKeystores(keyStores));
1777
+ await newManager.validateSigners();
1778
+ ValidatorClient.validateKeyStoreConfiguration(newManager, this.log);
1779
+ // Validate that every validator's publisher keys overlap with the L1 signers
1780
+ // that were initialized at startup. Publishers cannot be hot-reloaded, so a
1781
+ // validator with a publisher key that doesn't match any existing L1 signer
1782
+ // would silently fail on every proposer slot.
1783
+ if (this.keyStoreManager && this.sequencer) {
1784
+ const oldAdapter = NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager);
1785
+ const availablePublishers = new Set(oldAdapter.getAttesterAddresses().flatMap((a)=>oldAdapter.getPublisherAddresses(a).map((p)=>p.toString().toLowerCase())));
1786
+ const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
1787
+ for (const attester of newAdapter.getAttesterAddresses()){
1788
+ const pubs = newAdapter.getPublisherAddresses(attester);
1789
+ if (pubs.length > 0 && !pubs.some((p)=>availablePublishers.has(p.toString().toLowerCase()))) {
1790
+ throw new BadRequestError(`Cannot reload keystore: validator ${attester} has publisher keys ` + `[${pubs.map((p)=>p.toString()).join(', ')}] but none match the L1 signers initialized at startup ` + `[${[
1791
+ ...availablePublishers
1792
+ ].join(', ')}]. Publishers cannot be hot-reloaded — ` + `use an existing publisher key or restart the node.`);
1793
+ }
1794
+ }
1795
+ }
1796
+ // Build adapters for old and new keystores to compute diff
1797
+ const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
1798
+ const newAddresses = newAdapter.getAttesterAddresses();
1799
+ const oldAddresses = this.keyStoreManager ? NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager).getAttesterAddresses() : [];
1800
+ const oldSet = new Set(oldAddresses.map((a)=>a.toString()));
1801
+ const newSet = new Set(newAddresses.map((a)=>a.toString()));
1802
+ const added = newAddresses.filter((a)=>!oldSet.has(a.toString()));
1803
+ const removed = oldAddresses.filter((a)=>!newSet.has(a.toString()));
1804
+ if (added.length > 0) {
1805
+ this.log.info(`Keystore reload: adding attester keys: ${added.map((a)=>a.toString()).join(', ')}`);
1806
+ }
1807
+ if (removed.length > 0) {
1808
+ this.log.info(`Keystore reload: removing attester keys: ${removed.map((a)=>a.toString()).join(', ')}`);
1809
+ }
1810
+ if (added.length === 0 && removed.length === 0) {
1811
+ this.log.info('Keystore reload: attester keys unchanged');
1812
+ }
1813
+ // Update the validator client (coinbase, feeRecipient, attester keys)
1814
+ this.validatorClient.reloadKeystore(newManager);
1815
+ // Update the publisher factory's keystore so newly-added validators
1816
+ // can be matched to existing publisher keys when proposing blocks.
1817
+ if (this.sequencer) {
1818
+ this.sequencer.updatePublisherNodeKeyStore(newAdapter);
1819
+ }
1820
+ // Update slasher's "don't-slash-self" list with new validator addresses
1821
+ if (this.slasherClient && !this.config.slashSelfAllowed) {
1822
+ const slashValidatorsNever = unique([
1823
+ ...this.config.slashValidatorsNever ?? [],
1824
+ ...newAddresses
1825
+ ].map((a)=>a.toString())).map(EthAddress.fromString);
1826
+ this.slasherClient.updateConfig({
1827
+ slashValidatorsNever
1828
+ });
1829
+ }
1830
+ this.keyStoreManager = newManager;
1831
+ this.log.info('Keystore reloaded: coinbase, feeRecipient, and attester keys updated');
1832
+ }
1833
+ async mineBlock() {
1834
+ if (!this.sequencer) {
1835
+ throw new BadRequestError('Cannot mine block: no sequencer is running');
1836
+ }
1837
+ const currentBlockNumber = await this.getBlockNumber();
1838
+ // Use slot duration + 50% buffer as the timeout so this works on running networks too
1839
+ const { slotDuration } = await this.blockSource.getL1Constants();
1840
+ const timeoutSeconds = Math.ceil(slotDuration * 1.5);
1841
+ // Temporarily set minTxsPerBlock to 0 so the sequencer produces a block even with no txs
1842
+ const originalMinTxsPerBlock = this.sequencer.getSequencer().getConfig().minTxsPerBlock;
1843
+ this.sequencer.updateConfig({
1844
+ minTxsPerBlock: 0
1845
+ });
1846
+ try {
1847
+ // Trigger the sequencer to produce a block immediately
1848
+ void this.sequencer.trigger();
1849
+ // Wait for the new L2 block to appear
1850
+ await retryUntil(async ()=>{
1851
+ const newBlockNumber = await this.getBlockNumber();
1852
+ return newBlockNumber > currentBlockNumber ? true : undefined;
1853
+ }, 'mineBlock', timeoutSeconds, 0.1);
1854
+ } finally{
1855
+ this.sequencer.updateConfig({
1856
+ minTxsPerBlock: originalMinTxsPerBlock
1857
+ });
1858
+ }
1859
+ }
1407
1860
  #getInitialHeaderHash() {
1408
1861
  if (!this.initialHeaderHashPromise) {
1409
1862
  this.initialHeaderHashPromise = this.worldStateSynchronizer.getCommitted().getInitialHeader().hash();
@@ -1414,7 +1867,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
1414
1867
  * Returns an instance of MerkleTreeOperations having first ensured the world state is fully synched
1415
1868
  * @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
1416
1869
  * @returns An instance of a committed MerkleTreeOperations
1417
- */ async #getWorldState(block) {
1870
+ */ async getWorldState(block) {
1418
1871
  let blockSyncedTo = BlockNumber.ZERO;
1419
1872
  try {
1420
1873
  // Attempt to sync the world state if necessary
@@ -1426,29 +1879,65 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
1426
1879
  this.log.debug(`Using committed db for block 'latest', world state synced upto ${blockSyncedTo}`);
1427
1880
  return this.worldStateSynchronizer.getCommitted();
1428
1881
  }
1882
+ // Get the block number, either directly from the parameter or by quering the archiver with the block hash
1883
+ let blockNumber;
1429
1884
  if (BlockHash.isBlockHash(block)) {
1430
1885
  const initialBlockHash = await this.#getInitialHeaderHash();
1431
1886
  if (block.equals(initialBlockHash)) {
1432
- // Block source doesn't handle initial header so we need to handle the case separately.
1433
- return this.worldStateSynchronizer.getSnapshot(BlockNumber.ZERO);
1887
+ // Block 0 is a first-class historical block: its state lives in the trees' persisted
1888
+ // block-0 payload. Resolving the genesis hash to block number 0 lets the snapshot path
1889
+ // pin reads to genesis state even after the node has advanced past it.
1890
+ blockNumber = BlockNumber.ZERO;
1891
+ } else {
1892
+ const header = await this.blockSource.getBlockHeaderByHash(block);
1893
+ if (!header) {
1894
+ throw new Error(`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.`);
1895
+ }
1896
+ blockNumber = header.getBlockNumber();
1897
+ }
1898
+ } else {
1899
+ blockNumber = block;
1900
+ }
1901
+ // Check it's within world state sync range
1902
+ if (blockNumber > blockSyncedTo) {
1903
+ throw new Error(`Queried block ${inspectBlockParameter(block)} not yet synced by the node (node is synced upto ${blockSyncedTo}).`);
1904
+ }
1905
+ this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
1906
+ const snapshot = this.worldStateSynchronizer.getSnapshot(blockNumber);
1907
+ // Double-check world-state synced to the same block hash as was requested
1908
+ if (BlockHash.isBlockHash(block)) {
1909
+ const blockHash = await snapshot.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
1910
+ if (!blockHash || !block.equals(blockHash)) {
1911
+ const initialBlockHash = await this.#getInitialHeaderHash();
1912
+ throw new Error(`Block hash ${block.toString()} not found in world state at block number ${blockNumber} (world state has ${blockHash?.toString() ?? 'no hash'} at that index, genesis header hash is ${initialBlockHash.toString()}). If the node API has been queried with anchor block hash possibly a reorg has occurred.`);
1434
1913
  }
1435
- const header = await this.blockSource.getBlockHeaderByHash(block);
1914
+ }
1915
+ return snapshot;
1916
+ }
1917
+ /** Resolves any {@link BlockParameter} variant to a concrete block number. */ async resolveBlockNumber(block) {
1918
+ const resolved = await this.resolveBlockParameter(block);
1919
+ if (resolved.number !== undefined) {
1920
+ return resolved.number;
1921
+ }
1922
+ if (resolved.hash !== undefined) {
1923
+ const initialBlockHash = await this.#getInitialHeaderHash();
1924
+ if (resolved.hash.equals(initialBlockHash)) {
1925
+ return BlockNumber.ZERO;
1926
+ }
1927
+ const header = await this.blockSource.getBlockHeaderByHash(resolved.hash);
1436
1928
  if (!header) {
1437
- throw new Error(`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.`);
1929
+ throw new Error(`Block hash ${resolved.hash.toString()} not found.`);
1438
1930
  }
1439
- const blockNumber = header.getBlockNumber();
1440
- this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
1441
- return this.worldStateSynchronizer.getSnapshot(blockNumber);
1931
+ return header.getBlockNumber();
1442
1932
  }
1443
- // Block number provided
1444
- {
1445
- const blockNumber = block;
1446
- if (blockNumber > blockSyncedTo) {
1447
- throw new Error(`Queried block ${block} not yet synced by the node (node is synced upto ${blockSyncedTo}).`);
1933
+ if (resolved.archive !== undefined) {
1934
+ const header = await this.blockSource.getBlockHeaderByArchive(resolved.archive);
1935
+ if (!header) {
1936
+ throw new Error(`Block with archive ${resolved.archive.toString()} not found.`);
1448
1937
  }
1449
- this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
1450
- return this.worldStateSynchronizer.getSnapshot(blockNumber);
1938
+ return header.getBlockNumber();
1451
1939
  }
1940
+ throw new BadRequestError(`Invalid BlockParameter: ${JSON.stringify(block)}`);
1452
1941
  }
1453
1942
  /**
1454
1943
  * Ensure we fully sync the world state