@aztec/aztec-node 0.0.1-commit.f295ac2 → 0.0.1-commit.f504929

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.
@@ -374,12 +374,13 @@ var _dec, _initProto;
374
374
  import { createArchiver } from '@aztec/archiver';
375
375
  import { BBCircuitVerifier, QueuedIVCVerifier, TestCircuitVerifier } from '@aztec/bb-prover';
376
376
  import { createBlobClientWithFileStores } from '@aztec/blob-client/client';
377
+ import { Blob } from '@aztec/blob-lib';
377
378
  import { EpochCache } from '@aztec/epoch-cache';
378
379
  import { createEthereumChain } from '@aztec/ethereum/chain';
379
380
  import { getPublicClient } from '@aztec/ethereum/client';
380
381
  import { RegistryContract, RollupContract } from '@aztec/ethereum/contracts';
381
382
  import { BlockNumber, SlotNumber } from '@aztec/foundation/branded-types';
382
- import { compactArray, pick } from '@aztec/foundation/collection';
383
+ import { compactArray, pick, unique } from '@aztec/foundation/collection';
383
384
  import { Fr } from '@aztec/foundation/curves/bn254';
384
385
  import { EthAddress } from '@aztec/foundation/eth-address';
385
386
  import { BadRequestError } from '@aztec/foundation/json-rpc';
@@ -389,26 +390,28 @@ import { DateProvider, Timer } from '@aztec/foundation/timer';
389
390
  import { MembershipWitness } from '@aztec/foundation/trees';
390
391
  import { KeystoreManager, loadKeystores, mergeKeystores } from '@aztec/node-keystore';
391
392
  import { trySnapshotSync, uploadSnapshot } from '@aztec/node-lib/actions';
392
- import { createForwarderL1TxUtilsFromEthSigner, createL1TxUtilsWithBlobsFromEthSigner } from '@aztec/node-lib/factories';
393
- import { createP2PClient, getDefaultAllowedSetupFunctions } from '@aztec/p2p';
393
+ import { createForwarderL1TxUtilsFromSigners, createL1TxUtilsFromSigners } from '@aztec/node-lib/factories';
394
+ import { createP2PClient, createTxValidatorForAcceptingTxsOverRPC, getDefaultAllowedSetupFunctions } from '@aztec/p2p';
394
395
  import { ProtocolContractAddress } from '@aztec/protocol-contracts';
396
+ import { createProverNode } from '@aztec/prover-node';
397
+ import { createKeyStoreForProver } from '@aztec/prover-node/config';
395
398
  import { GlobalVariableBuilder, SequencerClient } from '@aztec/sequencer-client';
396
399
  import { PublicProcessorFactory } from '@aztec/simulator/server';
397
400
  import { AttestationsBlockWatcher, EpochPruneWatcher, createSlasher } from '@aztec/slasher';
398
401
  import { CollectionLimitsConfig, PublicSimulatorConfig } from '@aztec/stdlib/avm';
399
402
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
400
- import { L2BlockHash, L2BlockNew } from '@aztec/stdlib/block';
403
+ import { BlockHash, L2Block } from '@aztec/stdlib/block';
401
404
  import { GasFees } from '@aztec/stdlib/gas';
402
405
  import { computePublicDataTreeLeafSlot } from '@aztec/stdlib/hash';
403
406
  import { AztecNodeAdminConfigSchema } from '@aztec/stdlib/interfaces/client';
404
407
  import { tryStop } from '@aztec/stdlib/interfaces/server';
408
+ import { InMemoryDebugLogStore, NullDebugLogStore } from '@aztec/stdlib/logs';
405
409
  import { InboxLeaf } from '@aztec/stdlib/messaging';
406
- import { P2PClientType } from '@aztec/stdlib/p2p';
407
410
  import { MerkleTreeId, NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
408
411
  import { PublicSimulationOutput, TxReceipt, TxStatus } from '@aztec/stdlib/tx';
409
412
  import { getPackageVersion } from '@aztec/stdlib/update-checker';
410
413
  import { Attributes, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
411
- import { FullNodeCheckpointsBuilder as CheckpointsBuilder, FullNodeCheckpointsBuilder, NodeKeystoreAdapter, ValidatorClient, createBlockProposalHandler, createValidatorClient, createValidatorForAcceptingTxs } from '@aztec/validator-client';
414
+ import { FullNodeCheckpointsBuilder as CheckpointsBuilder, FullNodeCheckpointsBuilder, NodeKeystoreAdapter, ValidatorClient, createBlockProposalHandler, createValidatorClient } from '@aztec/validator-client';
412
415
  import { createWorldStateSynchronizer } from '@aztec/world-state';
413
416
  import { createPublicClient, fallback, http } from 'viem';
414
417
  import { createSentinel } from '../sentinel/factory.js';
@@ -428,6 +431,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
428
431
  l1ToL2MessageSource;
429
432
  worldStateSynchronizer;
430
433
  sequencer;
434
+ proverNode;
431
435
  slasherClient;
432
436
  validatorsSentinel;
433
437
  epochPruneWatcher;
@@ -440,6 +444,9 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
440
444
  telemetry;
441
445
  log;
442
446
  blobClient;
447
+ validatorClient;
448
+ keyStoreManager;
449
+ debugLogStore;
443
450
  static{
444
451
  ({ e: [_initProto] } = _apply_decs_2203_r(this, [
445
452
  [
@@ -454,7 +461,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
454
461
  // Prevent two snapshot operations to happen simultaneously
455
462
  isUploadingSnapshot;
456
463
  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){
464
+ constructor(config, p2pClient, blockSource, logsSource, contractDataSource, l1ToL2MessageSource, worldStateSynchronizer, sequencer, proverNode, slasherClient, validatorsSentinel, epochPruneWatcher, l1ChainId, version, globalVariableBuilder, epochCache, packageVersion, proofVerifier, telemetry = getTelemetryClient(), log = createLogger('node'), blobClient, validatorClient, keyStoreManager, debugLogStore = new NullDebugLogStore()){
458
465
  this.config = config;
459
466
  this.p2pClient = p2pClient;
460
467
  this.blockSource = blockSource;
@@ -463,6 +470,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
463
470
  this.l1ToL2MessageSource = l1ToL2MessageSource;
464
471
  this.worldStateSynchronizer = worldStateSynchronizer;
465
472
  this.sequencer = sequencer;
473
+ this.proverNode = proverNode;
466
474
  this.slasherClient = slasherClient;
467
475
  this.validatorsSentinel = validatorsSentinel;
468
476
  this.epochPruneWatcher = epochPruneWatcher;
@@ -475,12 +483,21 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
475
483
  this.telemetry = telemetry;
476
484
  this.log = log;
477
485
  this.blobClient = blobClient;
486
+ this.validatorClient = validatorClient;
487
+ this.keyStoreManager = keyStoreManager;
488
+ this.debugLogStore = debugLogStore;
478
489
  this.initialHeaderHashPromise = (_initProto(this), undefined);
479
490
  this.isUploadingSnapshot = false;
480
491
  this.metrics = new NodeMetrics(telemetry, 'AztecNodeService');
481
492
  this.tracer = telemetry.getTracer('AztecNodeService');
482
493
  this.log.info(`Aztec Node version: ${this.packageVersion}`);
483
494
  this.log.info(`Aztec Node started on chain 0x${l1ChainId.toString(16)}`, config.l1Contracts);
495
+ // A defensive check that protects us against introducing a bug in the complex `createAndSync` function. We must
496
+ // never have debugLogStore enabled when not in test mode because then we would be accumulating debug logs in
497
+ // memory which could be a DoS vector on the sequencer (since no fees are paid for debug logs).
498
+ if (debugLogStore.isEnabled && config.realProofs) {
499
+ throw new Error('debugLogStore should never be enabled when realProofs are set');
500
+ }
484
501
  }
485
502
  async getWorldStateSyncStatus() {
486
503
  const status = await this.worldStateSynchronizer.status();
@@ -502,16 +519,27 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
502
519
  const telemetry = deps.telemetry ?? getTelemetryClient();
503
520
  const dateProvider = deps.dateProvider ?? new DateProvider();
504
521
  const ethereumChain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
505
- // Build a key store from file if given or from environment otherwise
522
+ // Build a key store from file if given or from environment otherwise.
523
+ // We keep the raw KeyStore available so we can merge with prover keys if enableProverNode is set.
506
524
  let keyStoreManager;
507
525
  const keyStoreProvided = config.keyStoreDirectory !== undefined && config.keyStoreDirectory.length > 0;
508
526
  if (keyStoreProvided) {
509
527
  const keyStores = loadKeystores(config.keyStoreDirectory);
510
528
  keyStoreManager = new KeystoreManager(mergeKeystores(keyStores));
511
529
  } else {
512
- const keyStore = createKeyStoreForValidator(config);
513
- if (keyStore) {
514
- keyStoreManager = new KeystoreManager(keyStore);
530
+ const rawKeyStores = [];
531
+ const validatorKeyStore = createKeyStoreForValidator(config);
532
+ if (validatorKeyStore) {
533
+ rawKeyStores.push(validatorKeyStore);
534
+ }
535
+ if (config.enableProverNode) {
536
+ const proverKeyStore = createKeyStoreForProver(config);
537
+ if (proverKeyStore) {
538
+ rawKeyStores.push(proverKeyStore);
539
+ }
540
+ }
541
+ if (rawKeyStores.length > 0) {
542
+ keyStoreManager = new KeystoreManager(rawKeyStores.length === 1 ? rawKeyStores[0] : mergeKeystores(rawKeyStores));
515
543
  }
516
544
  }
517
545
  await keyStoreManager?.validateSigners();
@@ -520,8 +548,8 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
520
548
  if (keyStoreManager === undefined) {
521
549
  throw new Error('Failed to create key store, a requirement for running a validator');
522
550
  }
523
- if (!keyStoreProvided) {
524
- log.warn('KEY STORE CREATED FROM ENVIRONMENT, IT IS RECOMMENDED TO USE A FILE-BASED KEY STORE IN PRODUCTION ENVIRONMENTS');
551
+ if (!keyStoreProvided && process.env.NODE_ENV !== 'test') {
552
+ log.warn("Keystore created from env: it's recommended to use a file-based key store for production");
525
553
  }
526
554
  ValidatorClient.validateKeyStoreConfiguration(keyStoreManager, log);
527
555
  }
@@ -552,7 +580,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
552
580
  if (config.rollupVersion !== Number(rollupVersionFromRollup)) {
553
581
  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
582
  }
555
- const blobClient = await createBlobClientWithFileStores(config, createLogger('node:blob-client:client'));
583
+ const blobClient = await createBlobClientWithFileStores(config, log.createChild('blob-client'));
556
584
  // attempt snapshot sync if possible
557
585
  await trySnapshotSync(config, log);
558
586
  const epochCache = await EpochCache.create(config.l1Contracts.rollupAddress, config, {
@@ -569,77 +597,90 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
569
597
  // now create the merkle trees and the world state synchronizer
570
598
  const worldStateSynchronizer = await createWorldStateSynchronizer(config, archiver, options.prefilledPublicData, telemetry);
571
599
  const circuitVerifier = config.realProofs || config.debugForceTxProofVerification ? await BBCircuitVerifier.new(config) : new TestCircuitVerifier(config.proverTestVerificationDelayMs);
600
+ let debugLogStore;
572
601
  if (!config.realProofs) {
573
602
  log.warn(`Aztec node is accepting fake proofs`);
603
+ debugLogStore = new InMemoryDebugLogStore();
604
+ log.info('Aztec node started in test mode (realProofs set to false) hence debug logs from public functions will be collected and served');
605
+ } else {
606
+ debugLogStore = new NullDebugLogStore();
574
607
  }
575
608
  const proofVerifier = new QueuedIVCVerifier(config, circuitVerifier);
609
+ const proverOnly = config.enableProverNode && config.disableValidator;
610
+ if (proverOnly) {
611
+ log.info('Starting in prover-only mode: skipping validator, sequencer, sentinel, and slasher subsystems');
612
+ }
576
613
  // 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
614
+ const p2pClient = await createP2PClient(config, archiver, proofVerifier, worldStateSynchronizer, epochCache, packageVersion, dateProvider, telemetry, deps.p2pClientDeps);
615
+ // We'll accumulate sentinel watchers here
616
+ const watchers = [];
617
+ // Create FullNodeCheckpointsBuilder for block proposal handling and tx validation
581
618
  const validatorCheckpointsBuilder = new FullNodeCheckpointsBuilder({
582
619
  ...config,
583
620
  l1GenesisTime,
584
621
  slotDuration: Number(slotDuration)
585
622
  }, 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, {
623
+ let validatorClient;
624
+ if (!proverOnly) {
625
+ // Create validator client if required
626
+ validatorClient = await createValidatorClient(config, {
615
627
  checkpointsBuilder: validatorCheckpointsBuilder,
616
628
  worldState: worldStateSynchronizer,
629
+ p2pClient,
630
+ telemetry,
631
+ dateProvider,
617
632
  epochCache,
618
633
  blockSource: archiver,
619
634
  l1ToL2MessageSource: archiver,
620
- p2pClient,
621
- dateProvider,
622
- telemetry
623
- }).registerForReexecution(p2pClient);
635
+ keyStoreManager,
636
+ blobClient
637
+ });
638
+ // If we have a validator client, register it as a source of offenses for the slasher,
639
+ // and have it register callbacks on the p2p client *before* we start it, otherwise messages
640
+ // like attestations or auths will fail.
641
+ if (validatorClient) {
642
+ watchers.push(validatorClient);
643
+ if (!options.dontStartSequencer) {
644
+ await validatorClient.registerHandlers();
645
+ }
646
+ }
647
+ // If there's no validator client but alwaysReexecuteBlockProposals is enabled,
648
+ // create a BlockProposalHandler to reexecute block proposals for monitoring
649
+ if (!validatorClient && config.alwaysReexecuteBlockProposals) {
650
+ log.info('Setting up block proposal reexecution for monitoring');
651
+ createBlockProposalHandler(config, {
652
+ checkpointsBuilder: validatorCheckpointsBuilder,
653
+ worldState: worldStateSynchronizer,
654
+ epochCache,
655
+ blockSource: archiver,
656
+ l1ToL2MessageSource: archiver,
657
+ p2pClient,
658
+ dateProvider,
659
+ telemetry
660
+ }).registerForReexecution(p2pClient);
661
+ }
624
662
  }
625
663
  // Start world state and wait for it to sync to the archiver.
626
664
  await worldStateSynchronizer.start();
627
665
  // Start p2p. Note that it depends on world state to be running.
628
666
  await p2pClient.start();
629
- const validatorsSentinel = await createSentinel(epochCache, archiver, p2pClient, config);
630
- if (validatorsSentinel && config.slashInactivityPenalty > 0n) {
631
- watchers.push(validatorsSentinel);
632
- }
667
+ let validatorsSentinel;
633
668
  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
669
  let attestationsBlockWatcher;
640
- if (config.slashProposeInvalidAttestationsPenalty > 0n || config.slashAttestDescendantOfInvalidPenalty > 0n) {
641
- attestationsBlockWatcher = new AttestationsBlockWatcher(archiver, epochCache, config);
642
- watchers.push(attestationsBlockWatcher);
670
+ if (!proverOnly) {
671
+ validatorsSentinel = await createSentinel(epochCache, archiver, p2pClient, config);
672
+ if (validatorsSentinel && config.slashInactivityPenalty > 0n) {
673
+ watchers.push(validatorsSentinel);
674
+ }
675
+ if (config.slashPrunePenalty > 0n || config.slashDataWithholdingPenalty > 0n) {
676
+ epochPruneWatcher = new EpochPruneWatcher(archiver, archiver, epochCache, p2pClient.getTxProvider(), validatorCheckpointsBuilder, config);
677
+ watchers.push(epochPruneWatcher);
678
+ }
679
+ // We assume we want to slash for invalid attestations unless all max penalties are set to 0
680
+ if (config.slashProposeInvalidAttestationsPenalty > 0n || config.slashAttestDescendantOfInvalidPenalty > 0n) {
681
+ attestationsBlockWatcher = new AttestationsBlockWatcher(archiver, epochCache, config);
682
+ watchers.push(attestationsBlockWatcher);
683
+ }
643
684
  }
644
685
  // Start p2p-related services once the archiver has completed sync
645
686
  void archiver.waitForInitialSync().then(async ()=>{
@@ -658,27 +699,29 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
658
699
  const validatorAddresses = keyStoreManager ? NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager).getAddresses() : [];
659
700
  slasherClient = await createSlasher(config, config.l1Contracts, getPublicClient(config), watchers, dateProvider, epochCache, validatorAddresses, undefined);
660
701
  await slasherClient.start();
661
- const l1TxUtils = config.publisherForwarderAddress ? await createForwarderL1TxUtilsFromEthSigner(publicClient, keyStoreManager.createAllValidatorPublisherSigners(), config.publisherForwarderAddress, {
702
+ const l1TxUtils = config.sequencerPublisherForwarderAddress ? await createForwarderL1TxUtilsFromSigners(publicClient, keyStoreManager.createAllValidatorPublisherSigners(), config.sequencerPublisherForwarderAddress, {
662
703
  ...config,
663
704
  scope: 'sequencer'
664
705
  }, {
665
706
  telemetry,
666
707
  logger: log.createChild('l1-tx-utils'),
667
- dateProvider
668
- }) : await createL1TxUtilsWithBlobsFromEthSigner(publicClient, keyStoreManager.createAllValidatorPublisherSigners(), {
708
+ dateProvider,
709
+ kzg: Blob.getViemKzgInstance()
710
+ }) : await createL1TxUtilsFromSigners(publicClient, keyStoreManager.createAllValidatorPublisherSigners(), {
669
711
  ...config,
670
712
  scope: 'sequencer'
671
713
  }, {
672
714
  telemetry,
673
715
  logger: log.createChild('l1-tx-utils'),
674
- dateProvider
716
+ dateProvider,
717
+ kzg: Blob.getViemKzgInstance()
675
718
  });
676
719
  // Create and start the sequencer client
677
720
  const checkpointsBuilder = new CheckpointsBuilder({
678
721
  ...config,
679
722
  l1GenesisTime,
680
723
  slotDuration: Number(slotDuration)
681
- }, worldStateSynchronizer, archiver, dateProvider, telemetry);
724
+ }, worldStateSynchronizer, archiver, dateProvider, telemetry, debugLogStore);
682
725
  sequencer = await SequencerClient.new(config, {
683
726
  ...deps,
684
727
  epochCache,
@@ -702,13 +745,35 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
702
745
  } else if (sequencer) {
703
746
  log.warn(`Sequencer created but not started`);
704
747
  }
748
+ // Create prover node subsystem if enabled
749
+ let proverNode;
750
+ if (config.enableProverNode) {
751
+ proverNode = await createProverNode(config, {
752
+ ...deps.proverNodeDeps,
753
+ telemetry,
754
+ dateProvider,
755
+ archiver,
756
+ worldStateSynchronizer,
757
+ p2pClient,
758
+ epochCache,
759
+ blobClient,
760
+ keyStoreManager
761
+ });
762
+ if (!options.dontStartProverNode) {
763
+ await proverNode.start();
764
+ log.info(`Prover node subsystem started`);
765
+ } else {
766
+ log.info(`Prover node subsystem created but not started`);
767
+ }
768
+ }
705
769
  const globalVariableBuilder = new GlobalVariableBuilder({
706
770
  ...config,
707
771
  rollupVersion: BigInt(config.rollupVersion),
708
772
  l1GenesisTime,
709
773
  slotDuration: Number(slotDuration)
710
774
  });
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);
775
+ const node = new AztecNodeService(config, p2pClient, archiver, archiver, archiver, archiver, worldStateSynchronizer, sequencer, proverNode, slasherClient, validatorsSentinel, epochPruneWatcher, ethereumChain.chainInfo.id, config.rollupVersion, globalVariableBuilder, epochCache, packageVersion, proofVerifier, telemetry, log, blobClient, validatorClient, keyStoreManager, debugLogStore);
776
+ return node;
712
777
  }
713
778
  /**
714
779
  * Returns the sequencer client instance.
@@ -716,6 +781,9 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
716
781
  */ getSequencer() {
717
782
  return this.sequencer;
718
783
  }
784
+ /** Returns the prover node subsystem, if enabled. */ getProverNode() {
785
+ return this.proverNode;
786
+ }
719
787
  getBlockSource() {
720
788
  return this.blockSource;
721
789
  }
@@ -735,7 +803,10 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
735
803
  return Promise.resolve(this.p2pClient.getEnr()?.encodeTxt());
736
804
  }
737
805
  async getAllowedPublicSetup() {
738
- return this.config.txPublicSetupAllowList ?? await getDefaultAllowedSetupFunctions();
806
+ return [
807
+ ...await getDefaultAllowedSetupFunctions(),
808
+ ...this.config.txPublicSetupAllowListExtend ?? []
809
+ ];
739
810
  }
740
811
  /**
741
812
  * Method to determine if the node is ready to accept transactions.
@@ -758,7 +829,8 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
758
829
  rollupVersion,
759
830
  enr,
760
831
  l1ContractAddresses: contractAddresses,
761
- protocolContractAddresses: protocolContractAddresses
832
+ protocolContractAddresses: protocolContractAddresses,
833
+ realProofs: !!this.config.realProofs
762
834
  };
763
835
  return nodeInfo;
764
836
  }
@@ -767,14 +839,14 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
767
839
  * @param block - The block parameter (block number, block hash, or 'latest').
768
840
  * @returns The requested block.
769
841
  */ async getBlock(block) {
770
- if (L2BlockHash.isL2BlockHash(block)) {
771
- return this.getBlockByHash(Fr.fromBuffer(block.toBuffer()));
842
+ if (BlockHash.isBlockHash(block)) {
843
+ return this.getBlockByHash(block);
772
844
  }
773
845
  const blockNumber = block === 'latest' ? await this.getBlockNumber() : block;
774
846
  if (blockNumber === BlockNumber.ZERO) {
775
847
  return this.buildInitialBlock();
776
848
  }
777
- return await this.blockSource.getL2BlockNew(blockNumber);
849
+ return await this.blockSource.getL2Block(blockNumber);
778
850
  }
779
851
  /**
780
852
  * Get a block specified by its hash.
@@ -782,21 +854,21 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
782
854
  * @returns The requested block.
783
855
  */ async getBlockByHash(blockHash) {
784
856
  const initialBlockHash = await this.#getInitialHeaderHash();
785
- if (blockHash.equals(Fr.fromBuffer(initialBlockHash.toBuffer()))) {
857
+ if (blockHash.equals(initialBlockHash)) {
786
858
  return this.buildInitialBlock();
787
859
  }
788
- return await this.blockSource.getL2BlockNewByHash(blockHash);
860
+ return await this.blockSource.getL2BlockByHash(blockHash);
789
861
  }
790
862
  buildInitialBlock() {
791
863
  const initialHeader = this.worldStateSynchronizer.getCommitted().getInitialHeader();
792
- return L2BlockNew.empty(initialHeader);
864
+ return L2Block.empty(initialHeader);
793
865
  }
794
866
  /**
795
867
  * Get a block specified by its archive root.
796
868
  * @param archive - The archive root being requested.
797
869
  * @returns The requested block.
798
870
  */ async getBlockByArchive(archive) {
799
- return await this.blockSource.getL2BlockNewByArchive(archive);
871
+ return await this.blockSource.getL2BlockByArchive(archive);
800
872
  }
801
873
  /**
802
874
  * Method to request blocks. Will attempt to return all requested blocks but will return only those available.
@@ -804,19 +876,13 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
804
876
  * @param limit - The maximum number of blocks to obtain.
805
877
  * @returns The blocks requested.
806
878
  */ async getBlocks(from, limit) {
807
- return await this.blockSource.getL2BlocksNew(from, limit) ?? [];
808
- }
809
- async getPublishedBlocks(from, limit) {
810
- return await this.blockSource.getPublishedBlocks(from, limit) ?? [];
879
+ return await this.blockSource.getBlocks(from, BlockNumber(limit)) ?? [];
811
880
  }
812
- async getPublishedCheckpoints(from, limit) {
813
- return await this.blockSource.getPublishedCheckpoints(from, limit) ?? [];
881
+ async getCheckpoints(from, limit) {
882
+ return await this.blockSource.getCheckpoints(from, limit) ?? [];
814
883
  }
815
- async getL2BlocksNew(from, limit) {
816
- return await this.blockSource.getL2BlocksNew(from, limit) ?? [];
817
- }
818
- async getCheckpointedBlocks(from, limit, proven) {
819
- return await this.blockSource.getCheckpointedBlocks(from, limit, proven) ?? [];
884
+ async getCheckpointedBlocks(from, limit) {
885
+ return await this.blockSource.getCheckpointedBlocks(from, limit) ?? [];
820
886
  }
821
887
  /**
822
888
  * Method to fetch the current min L2 fees.
@@ -842,6 +908,9 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
842
908
  async getProvenBlockNumber() {
843
909
  return await this.blockSource.getProvenBlockNumber();
844
910
  }
911
+ async getCheckpointedBlockNumber() {
912
+ return await this.blockSource.getCheckpointedL2BlockNumber();
913
+ }
845
914
  /**
846
915
  * Method to fetch the version of the package.
847
916
  * @returns The node package version
@@ -866,11 +935,29 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
866
935
  getContract(address) {
867
936
  return this.contractDataSource.getContract(address);
868
937
  }
869
- getPrivateLogsByTags(tags) {
870
- return this.logsSource.getPrivateLogsByTags(tags);
938
+ async getPrivateLogsByTags(tags, page, referenceBlock) {
939
+ if (referenceBlock) {
940
+ const initialBlockHash = await this.#getInitialHeaderHash();
941
+ if (!referenceBlock.equals(initialBlockHash)) {
942
+ const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
943
+ if (!header) {
944
+ throw new Error(`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`);
945
+ }
946
+ }
947
+ }
948
+ return this.logsSource.getPrivateLogsByTags(tags, page);
871
949
  }
872
- getPublicLogsByTagsFromContract(contractAddress, tags) {
873
- return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags);
950
+ async getPublicLogsByTagsFromContract(contractAddress, tags, page, referenceBlock) {
951
+ if (referenceBlock) {
952
+ const initialBlockHash = await this.#getInitialHeaderHash();
953
+ if (!referenceBlock.equals(initialBlockHash)) {
954
+ const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
955
+ if (!header) {
956
+ throw new Error(`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`);
957
+ }
958
+ }
959
+ }
960
+ return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page);
874
961
  }
875
962
  /**
876
963
  * Gets public logs based on the provided filter.
@@ -905,24 +992,33 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
905
992
  throw new Error(`Invalid tx: ${reason}`);
906
993
  }
907
994
  await this.p2pClient.sendTx(tx);
908
- this.metrics.receivedTx(timer.ms(), true);
909
- this.log.info(`Received tx ${txHash}`, {
995
+ const duration = timer.ms();
996
+ this.metrics.receivedTx(duration, true);
997
+ this.log.info(`Received tx ${txHash} in ${duration}ms`, {
910
998
  txHash
911
999
  });
912
1000
  }
913
1001
  async getTxReceipt(txHash) {
914
- let txReceipt = new TxReceipt(txHash, TxStatus.DROPPED, 'Tx dropped by P2P node.');
915
- // We first check if the tx is in pending (instead of first checking if it is mined) because if we first check
916
- // for mined and then for pending there could be a race condition where the tx is mined between the two checks
917
- // and we would incorrectly return a TxReceipt with status DROPPED
918
- if (await this.p2pClient.getTxStatus(txHash) === 'pending') {
919
- txReceipt = new TxReceipt(txHash, TxStatus.PENDING, '');
920
- }
1002
+ // Check the tx pool status first. If the tx is known to the pool (pending or mined), we'll use that
1003
+ // as a fallback if we don't find a settled receipt in the archiver.
1004
+ const txPoolStatus = await this.p2pClient.getTxStatus(txHash);
1005
+ const isKnownToPool = txPoolStatus === 'pending' || txPoolStatus === 'mined';
1006
+ // Then get the actual tx from the archiver, which tracks every tx in a mined block.
921
1007
  const settledTxReceipt = await this.blockSource.getSettledTxReceipt(txHash);
1008
+ let receipt;
922
1009
  if (settledTxReceipt) {
923
- txReceipt = settledTxReceipt;
1010
+ receipt = settledTxReceipt;
1011
+ } else if (isKnownToPool) {
1012
+ // If the tx is in the pool but not in the archiver, it's pending.
1013
+ // This handles race conditions between archiver and p2p, where the archiver
1014
+ // has pruned the block in which a tx was mined, but p2p has not caught up yet.
1015
+ receipt = new TxReceipt(txHash, TxStatus.PENDING, undefined, undefined);
1016
+ } else {
1017
+ // Otherwise, if we don't know the tx, we consider it dropped.
1018
+ receipt = new TxReceipt(txHash, TxStatus.DROPPED, undefined, 'Tx dropped by P2P node');
924
1019
  }
925
- return txReceipt;
1020
+ this.debugLogStore.decorateReceiptWithLogs(txHash.toString(), receipt);
1021
+ return receipt;
926
1022
  }
927
1023
  getTxEffect(txHash) {
928
1024
  return this.blockSource.getTxEffect(txHash);
@@ -936,6 +1032,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
936
1032
  await tryStop(this.slasherClient);
937
1033
  await tryStop(this.proofVerifier);
938
1034
  await tryStop(this.sequencer);
1035
+ await tryStop(this.proverNode);
939
1036
  await tryStop(this.p2pClient);
940
1037
  await tryStop(this.worldStateSynchronizer);
941
1038
  await tryStop(this.blockSource);
@@ -974,8 +1071,8 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
974
1071
  */ async getTxsByHash(txHashes) {
975
1072
  return compactArray(await Promise.all(txHashes.map((txHash)=>this.getTxByHash(txHash))));
976
1073
  }
977
- async findLeavesIndexes(block, treeId, leafValues) {
978
- const committedDb = await this.#getWorldState(block);
1074
+ async findLeavesIndexes(referenceBlock, treeId, leafValues) {
1075
+ const committedDb = await this.#getWorldState(referenceBlock);
979
1076
  const maybeIndices = await committedDb.findLeafIndices(treeId, leafValues.map((x)=>x.toBuffer()));
980
1077
  // We filter out undefined values
981
1078
  const indices = maybeIndices.filter((x)=>x !== undefined);
@@ -1018,35 +1115,27 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
1018
1115
  }
1019
1116
  return {
1020
1117
  l2BlockNumber: BlockNumber(Number(blockNumber)),
1021
- l2BlockHash: L2BlockHash.fromField(blockHash),
1118
+ l2BlockHash: new BlockHash(blockHash),
1022
1119
  data: index
1023
1120
  };
1024
1121
  });
1025
1122
  }
1026
- async getNullifierSiblingPath(block, leafIndex) {
1027
- const committedDb = await this.#getWorldState(block);
1028
- return committedDb.getSiblingPath(MerkleTreeId.NULLIFIER_TREE, leafIndex);
1029
- }
1030
- async getNoteHashSiblingPath(block, leafIndex) {
1031
- const committedDb = await this.#getWorldState(block);
1032
- return committedDb.getSiblingPath(MerkleTreeId.NOTE_HASH_TREE, leafIndex);
1033
- }
1034
- async getArchiveMembershipWitness(block, archive) {
1035
- const committedDb = await this.#getWorldState(block);
1123
+ async getBlockHashMembershipWitness(referenceBlock, blockHash) {
1124
+ const committedDb = await this.#getWorldState(referenceBlock);
1036
1125
  const [pathAndIndex] = await committedDb.findSiblingPaths(MerkleTreeId.ARCHIVE, [
1037
- archive
1126
+ blockHash
1038
1127
  ]);
1039
1128
  return pathAndIndex === undefined ? undefined : MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
1040
1129
  }
1041
- async getNoteHashMembershipWitness(block, noteHash) {
1042
- const committedDb = await this.#getWorldState(block);
1130
+ async getNoteHashMembershipWitness(referenceBlock, noteHash) {
1131
+ const committedDb = await this.#getWorldState(referenceBlock);
1043
1132
  const [pathAndIndex] = await committedDb.findSiblingPaths(MerkleTreeId.NOTE_HASH_TREE, [
1044
1133
  noteHash
1045
1134
  ]);
1046
1135
  return pathAndIndex === undefined ? undefined : MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
1047
1136
  }
1048
- async getL1ToL2MessageMembershipWitness(block, l1ToL2Message) {
1049
- const db = await this.#getWorldState(block);
1137
+ async getL1ToL2MessageMembershipWitness(referenceBlock, l1ToL2Message) {
1138
+ const db = await this.#getWorldState(referenceBlock);
1050
1139
  const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [
1051
1140
  l1ToL2Message
1052
1141
  ]);
@@ -1076,12 +1165,13 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
1076
1165
  * @param epoch - The epoch at which to get the data.
1077
1166
  * @returns The L2 to L1 messages (empty array if the epoch is not found).
1078
1167
  */ async getL2ToL1Messages(epoch) {
1079
- // Assumes `getBlocksForEpoch` returns blocks in ascending order of block number.
1080
- const blocks = await this.blockSource.getBlocksForEpoch(epoch);
1168
+ // Assumes `getCheckpointedBlocksForEpoch` returns blocks in ascending order of block number.
1169
+ const checkpointedBlocks = await this.blockSource.getCheckpointedBlocksForEpoch(epoch);
1081
1170
  const blocksInCheckpoints = [];
1082
1171
  let previousSlotNumber = SlotNumber.ZERO;
1083
1172
  let checkpointIndex = -1;
1084
- for (const block of blocks){
1173
+ for (const checkpointedBlock of checkpointedBlocks){
1174
+ const block = checkpointedBlock.block;
1085
1175
  const slotNumber = block.header.globalVariables.slotNumber;
1086
1176
  if (slotNumber !== previousSlotNumber) {
1087
1177
  checkpointIndex++;
@@ -1092,16 +1182,8 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
1092
1182
  }
1093
1183
  return blocksInCheckpoints.map((blocks)=>blocks.map((block)=>block.body.txEffects.map((txEffect)=>txEffect.l2ToL1Msgs)));
1094
1184
  }
1095
- async getArchiveSiblingPath(block, leafIndex) {
1096
- const committedDb = await this.#getWorldState(block);
1097
- return committedDb.getSiblingPath(MerkleTreeId.ARCHIVE, leafIndex);
1098
- }
1099
- async getPublicDataSiblingPath(block, leafIndex) {
1100
- const committedDb = await this.#getWorldState(block);
1101
- return committedDb.getSiblingPath(MerkleTreeId.PUBLIC_DATA_TREE, leafIndex);
1102
- }
1103
- async getNullifierMembershipWitness(block, nullifier) {
1104
- const db = await this.#getWorldState(block);
1185
+ async getNullifierMembershipWitness(referenceBlock, nullifier) {
1186
+ const db = await this.#getWorldState(referenceBlock);
1105
1187
  const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [
1106
1188
  nullifier.toBuffer()
1107
1189
  ]);
@@ -1117,7 +1199,8 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
1117
1199
  }
1118
1200
  /**
1119
1201
  * Returns a low nullifier membership witness for a given nullifier at a given block.
1120
- * @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
1202
+ * @param referenceBlock - The block parameter (block number, block hash, or 'latest') at which to get the data
1203
+ * (which contains the root of the nullifier tree in which we are searching for the nullifier).
1121
1204
  * @param nullifier - Nullifier we try to find the low nullifier witness for.
1122
1205
  * @returns The low nullifier membership witness (if found).
1123
1206
  * @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
@@ -1128,8 +1211,8 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
1128
1211
  * the nullifier already exists in the tree. This is because the `getPreviousValueIndex` function returns the
1129
1212
  * index of the nullifier itself when it already exists in the tree.
1130
1213
  * TODO: This is a confusing behavior and we should eventually address that.
1131
- */ async getLowNullifierMembershipWitness(block, nullifier) {
1132
- const committedDb = await this.#getWorldState(block);
1214
+ */ async getLowNullifierMembershipWitness(referenceBlock, nullifier) {
1215
+ const committedDb = await this.#getWorldState(referenceBlock);
1133
1216
  const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
1134
1217
  if (!findResult) {
1135
1218
  return undefined;
@@ -1142,8 +1225,8 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
1142
1225
  const siblingPath = await committedDb.getSiblingPath(MerkleTreeId.NULLIFIER_TREE, BigInt(index));
1143
1226
  return new NullifierMembershipWitness(BigInt(index), preimageData, siblingPath);
1144
1227
  }
1145
- async getPublicDataWitness(block, leafSlot) {
1146
- const committedDb = await this.#getWorldState(block);
1228
+ async getPublicDataWitness(referenceBlock, leafSlot) {
1229
+ const committedDb = await this.#getWorldState(referenceBlock);
1147
1230
  const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
1148
1231
  if (!lowLeafResult) {
1149
1232
  return undefined;
@@ -1153,8 +1236,8 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
1153
1236
  return new PublicDataWitness(lowLeafResult.index, preimage, path);
1154
1237
  }
1155
1238
  }
1156
- async getPublicStorageAt(block, contract, slot) {
1157
- const committedDb = await this.#getWorldState(block);
1239
+ async getPublicStorageAt(referenceBlock, contract, slot) {
1240
+ const committedDb = await this.#getWorldState(referenceBlock);
1158
1241
  const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
1159
1242
  const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
1160
1243
  if (!lowLeafResult || !lowLeafResult.alreadyPresent) {
@@ -1164,14 +1247,13 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
1164
1247
  return preimage.leaf.value;
1165
1248
  }
1166
1249
  async getBlockHeader(block = 'latest') {
1167
- if (L2BlockHash.isL2BlockHash(block)) {
1250
+ if (BlockHash.isBlockHash(block)) {
1168
1251
  const initialBlockHash = await this.#getInitialHeaderHash();
1169
1252
  if (block.equals(initialBlockHash)) {
1170
1253
  // Block source doesn't handle initial header so we need to handle the case separately.
1171
1254
  return this.worldStateSynchronizer.getCommitted().getInitialHeader();
1172
1255
  }
1173
- const blockHashFr = Fr.fromBuffer(block.toBuffer());
1174
- return this.blockSource.getBlockHeaderByHash(blockHashFr);
1256
+ return this.blockSource.getBlockHeaderByHash(block);
1175
1257
  } else {
1176
1258
  // Block source doesn't handle initial header so we need to handle the case separately.
1177
1259
  const blockNumber = block === 'latest' ? await this.getBlockNumber() : block;
@@ -1188,6 +1270,12 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
1188
1270
  */ async getBlockHeaderByArchive(archive) {
1189
1271
  return await this.blockSource.getBlockHeaderByArchive(archive);
1190
1272
  }
1273
+ getBlockData(number) {
1274
+ return this.blockSource.getBlockData(number);
1275
+ }
1276
+ getBlockDataByArchive(archive) {
1277
+ return this.blockSource.getBlockDataByArchive(archive);
1278
+ }
1191
1279
  /**
1192
1280
  * Simulates the public part of a transaction with the current state.
1193
1281
  * @param tx - The transaction to simulate.
@@ -1200,17 +1288,20 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
1200
1288
  throw new BadRequestError(`Transaction total gas limit ${txGasLimit + teardownGasLimit} (${txGasLimit} + ${teardownGasLimit}) exceeds maximum gas limit ${this.config.rpcSimulatePublicMaxGasLimit} for simulation`);
1201
1289
  }
1202
1290
  const txHash = tx.getTxHash();
1203
- const blockNumber = BlockNumber(await this.blockSource.getBlockNumber() + 1);
1291
+ const latestBlockNumber = await this.blockSource.getBlockNumber();
1292
+ const blockNumber = BlockNumber.add(latestBlockNumber, 1);
1204
1293
  // If sequencer is not initialized, we just set these values to zero for simulation.
1205
1294
  const coinbase = EthAddress.ZERO;
1206
1295
  const feeRecipient = AztecAddress.ZERO;
1207
1296
  const newGlobalVariables = await this.globalVariableBuilder.buildGlobalVariables(blockNumber, coinbase, feeRecipient);
1208
- const publicProcessorFactory = new PublicProcessorFactory(this.contractDataSource, new DateProvider(), this.telemetry);
1297
+ const publicProcessorFactory = new PublicProcessorFactory(this.contractDataSource, new DateProvider(), this.telemetry, this.log.getBindings());
1209
1298
  this.log.verbose(`Simulating public calls for tx ${txHash}`, {
1210
1299
  globalVariables: newGlobalVariables.toInspect(),
1211
1300
  txHash,
1212
1301
  blockNumber
1213
1302
  });
1303
+ // Ensure world-state has caught up with the latest block we loaded from the archiver
1304
+ await this.worldStateSynchronizer.syncImmediate(latestBlockNumber);
1214
1305
  const merkleTreeFork = await this.worldStateSynchronizer.fork();
1215
1306
  try {
1216
1307
  const config = PublicSimulatorConfig.from({
@@ -1225,7 +1316,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
1225
1316
  });
1226
1317
  const processor = publicProcessorFactory.create(merkleTreeFork, newGlobalVariables, config);
1227
1318
  // REFACTOR: Consider merging ProcessReturnValues into ProcessedTx
1228
- const [processedTxs, failedTxs, _usedTxs, returns] = await processor.process([
1319
+ const [processedTxs, failedTxs, _usedTxs, returns, _blobFields, debugLogs] = await processor.process([
1229
1320
  tx
1230
1321
  ]);
1231
1322
  // REFACTOR: Consider returning the error rather than throwing
@@ -1236,7 +1327,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
1236
1327
  throw failedTxs[0].error;
1237
1328
  }
1238
1329
  const [processedTx] = processedTxs;
1239
- return new PublicSimulationOutput(processedTx.revertReason, processedTx.globalVariables, processedTx.txEffect, returns, processedTx.gasUsed);
1330
+ return new PublicSimulationOutput(processedTx.revertReason, processedTx.globalVariables, processedTx.txEffect, returns, processedTx.gasUsed, debugLogs);
1240
1331
  } finally{
1241
1332
  await merkleTreeFork.close();
1242
1333
  }
@@ -1244,19 +1335,22 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
1244
1335
  async isValidTx(tx, { isSimulation, skipFeeEnforcement } = {}) {
1245
1336
  const db = this.worldStateSynchronizer.getCommitted();
1246
1337
  const verifier = isSimulation ? undefined : this.proofVerifier;
1247
- // We accept transactions if they are not expired by the next slot (checked based on the IncludeByTimestamp field)
1338
+ // We accept transactions if they are not expired by the next slot (checked based on the ExpirationTimestamp field)
1248
1339
  const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
1249
1340
  const blockNumber = BlockNumber(await this.blockSource.getBlockNumber() + 1);
1250
- const validator = createValidatorForAcceptingTxs(db, this.contractDataSource, verifier, {
1341
+ const validator = createTxValidatorForAcceptingTxsOverRPC(db, this.contractDataSource, verifier, {
1251
1342
  timestamp: nextSlotTimestamp,
1252
1343
  blockNumber,
1253
1344
  l1ChainId: this.l1ChainId,
1254
1345
  rollupVersion: this.version,
1255
- setupAllowList: this.config.txPublicSetupAllowList ?? await getDefaultAllowedSetupFunctions(),
1346
+ setupAllowList: [
1347
+ ...await getDefaultAllowedSetupFunctions(),
1348
+ ...this.config.txPublicSetupAllowListExtend ?? []
1349
+ ],
1256
1350
  gasFees: await this.getCurrentMinFees(),
1257
1351
  skipFeeEnforcement,
1258
1352
  txsPermitted: !this.config.disableTransactions
1259
- });
1353
+ }, this.log.getBindings());
1260
1354
  return await validator.validateTx(tx);
1261
1355
  }
1262
1356
  getConfig() {
@@ -1398,9 +1492,76 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
1398
1492
  return this.slasherClient.gatherOffensesForRound(round === 'current' ? undefined : BigInt(round));
1399
1493
  }
1400
1494
  }
1495
+ async reloadKeystore() {
1496
+ if (!this.config.keyStoreDirectory?.length) {
1497
+ throw new BadRequestError('Cannot reload keystore: node is not using a file-based keystore. ' + 'Set KEY_STORE_DIRECTORY to use file-based keystores.');
1498
+ }
1499
+ if (!this.validatorClient) {
1500
+ throw new BadRequestError('Cannot reload keystore: validator is not enabled.');
1501
+ }
1502
+ this.log.info('Reloading keystore from disk');
1503
+ // Re-read and validate keystore files
1504
+ const keyStores = loadKeystores(this.config.keyStoreDirectory);
1505
+ const newManager = new KeystoreManager(mergeKeystores(keyStores));
1506
+ await newManager.validateSigners();
1507
+ ValidatorClient.validateKeyStoreConfiguration(newManager, this.log);
1508
+ // Validate that every validator's publisher keys overlap with the L1 signers
1509
+ // that were initialized at startup. Publishers cannot be hot-reloaded, so a
1510
+ // validator with a publisher key that doesn't match any existing L1 signer
1511
+ // would silently fail on every proposer slot.
1512
+ if (this.keyStoreManager && this.sequencer) {
1513
+ const oldAdapter = NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager);
1514
+ const availablePublishers = new Set(oldAdapter.getAttesterAddresses().flatMap((a)=>oldAdapter.getPublisherAddresses(a).map((p)=>p.toString().toLowerCase())));
1515
+ const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
1516
+ for (const attester of newAdapter.getAttesterAddresses()){
1517
+ const pubs = newAdapter.getPublisherAddresses(attester);
1518
+ if (pubs.length > 0 && !pubs.some((p)=>availablePublishers.has(p.toString().toLowerCase()))) {
1519
+ 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 ` + `[${[
1520
+ ...availablePublishers
1521
+ ].join(', ')}]. Publishers cannot be hot-reloaded — ` + `use an existing publisher key or restart the node.`);
1522
+ }
1523
+ }
1524
+ }
1525
+ // Build adapters for old and new keystores to compute diff
1526
+ const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
1527
+ const newAddresses = newAdapter.getAttesterAddresses();
1528
+ const oldAddresses = this.keyStoreManager ? NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager).getAttesterAddresses() : [];
1529
+ const oldSet = new Set(oldAddresses.map((a)=>a.toString()));
1530
+ const newSet = new Set(newAddresses.map((a)=>a.toString()));
1531
+ const added = newAddresses.filter((a)=>!oldSet.has(a.toString()));
1532
+ const removed = oldAddresses.filter((a)=>!newSet.has(a.toString()));
1533
+ if (added.length > 0) {
1534
+ this.log.info(`Keystore reload: adding attester keys: ${added.map((a)=>a.toString()).join(', ')}`);
1535
+ }
1536
+ if (removed.length > 0) {
1537
+ this.log.info(`Keystore reload: removing attester keys: ${removed.map((a)=>a.toString()).join(', ')}`);
1538
+ }
1539
+ if (added.length === 0 && removed.length === 0) {
1540
+ this.log.info('Keystore reload: attester keys unchanged');
1541
+ }
1542
+ // Update the validator client (coinbase, feeRecipient, attester keys)
1543
+ this.validatorClient.reloadKeystore(newManager);
1544
+ // Update the publisher factory's keystore so newly-added validators
1545
+ // can be matched to existing publisher keys when proposing blocks.
1546
+ if (this.sequencer) {
1547
+ this.sequencer.updatePublisherNodeKeyStore(newAdapter);
1548
+ }
1549
+ // Update slasher's "don't-slash-self" list with new validator addresses
1550
+ if (this.slasherClient && !this.config.slashSelfAllowed) {
1551
+ const slashValidatorsNever = unique([
1552
+ ...this.config.slashValidatorsNever ?? [],
1553
+ ...newAddresses
1554
+ ].map((a)=>a.toString())).map(EthAddress.fromString);
1555
+ this.slasherClient.updateConfig({
1556
+ slashValidatorsNever
1557
+ });
1558
+ }
1559
+ this.keyStoreManager = newManager;
1560
+ this.log.info('Keystore reloaded: coinbase, feeRecipient, and attester keys updated');
1561
+ }
1401
1562
  #getInitialHeaderHash() {
1402
1563
  if (!this.initialHeaderHashPromise) {
1403
- this.initialHeaderHashPromise = this.worldStateSynchronizer.getCommitted().getInitialHeader().hash().then((hash)=>L2BlockHash.fromField(hash));
1564
+ this.initialHeaderHashPromise = this.worldStateSynchronizer.getCommitted().getInitialHeader().hash();
1404
1565
  }
1405
1566
  return this.initialHeaderHashPromise;
1406
1567
  }
@@ -1420,14 +1581,13 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
1420
1581
  this.log.debug(`Using committed db for block 'latest', world state synced upto ${blockSyncedTo}`);
1421
1582
  return this.worldStateSynchronizer.getCommitted();
1422
1583
  }
1423
- if (L2BlockHash.isL2BlockHash(block)) {
1584
+ if (BlockHash.isBlockHash(block)) {
1424
1585
  const initialBlockHash = await this.#getInitialHeaderHash();
1425
1586
  if (block.equals(initialBlockHash)) {
1426
1587
  // Block source doesn't handle initial header so we need to handle the case separately.
1427
1588
  return this.worldStateSynchronizer.getSnapshot(BlockNumber.ZERO);
1428
1589
  }
1429
- const blockHashFr = Fr.fromBuffer(block.toBuffer());
1430
- const header = await this.blockSource.getBlockHeaderByHash(blockHashFr);
1590
+ const header = await this.blockSource.getBlockHeaderByHash(block);
1431
1591
  if (!header) {
1432
1592
  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.`);
1433
1593
  }