@aztec/aztec-node 0.0.1-commit.8afd444 → 0.0.1-commit.8c0b8ff

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,24 +374,28 @@ 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
- import { getPublicClient } from '@aztec/ethereum/client';
380
+ import { getPublicClient, makeL1HttpTransport } from '@aztec/ethereum/client';
380
381
  import { RegistryContract, RollupContract } from '@aztec/ethereum/contracts';
381
- import { BlockNumber, SlotNumber } from '@aztec/foundation/branded-types';
382
- import { compactArray, pick } from '@aztec/foundation/collection';
382
+ import { BlockNumber } from '@aztec/foundation/branded-types';
383
+ import { chunkBy, 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';
386
387
  import { createLogger } from '@aztec/foundation/log';
388
+ import { retryUntil } from '@aztec/foundation/retry';
387
389
  import { count } from '@aztec/foundation/string';
388
390
  import { DateProvider, Timer } from '@aztec/foundation/timer';
389
391
  import { MembershipWitness } from '@aztec/foundation/trees';
390
392
  import { KeystoreManager, loadKeystores, mergeKeystores } from '@aztec/node-keystore';
391
393
  import { trySnapshotSync, uploadSnapshot } from '@aztec/node-lib/actions';
392
- import { createForwarderL1TxUtilsFromEthSigner, createL1TxUtilsWithBlobsFromEthSigner } from '@aztec/node-lib/factories';
393
- import { createP2PClient, getDefaultAllowedSetupFunctions } from '@aztec/p2p';
394
+ import { createForwarderL1TxUtilsFromSigners, createL1TxUtilsFromSigners } from '@aztec/node-lib/factories';
395
+ import { createP2PClient, createTxValidatorForAcceptingTxsOverRPC, getDefaultAllowedSetupFunctions } from '@aztec/p2p';
394
396
  import { ProtocolContractAddress } from '@aztec/protocol-contracts';
397
+ import { createProverNode } from '@aztec/prover-node';
398
+ import { createKeyStoreForProver } from '@aztec/prover-node/config';
395
399
  import { GlobalVariableBuilder, SequencerClient } from '@aztec/sequencer-client';
396
400
  import { PublicProcessorFactory } from '@aztec/simulator/server';
397
401
  import { AttestationsBlockWatcher, EpochPruneWatcher, createSlasher } from '@aztec/slasher';
@@ -402,15 +406,15 @@ import { GasFees } from '@aztec/stdlib/gas';
402
406
  import { computePublicDataTreeLeafSlot } from '@aztec/stdlib/hash';
403
407
  import { AztecNodeAdminConfigSchema } from '@aztec/stdlib/interfaces/client';
404
408
  import { tryStop } from '@aztec/stdlib/interfaces/server';
409
+ import { InMemoryDebugLogStore, NullDebugLogStore } from '@aztec/stdlib/logs';
405
410
  import { InboxLeaf } from '@aztec/stdlib/messaging';
406
- import { P2PClientType } from '@aztec/stdlib/p2p';
407
411
  import { MerkleTreeId, NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
408
412
  import { PublicSimulationOutput, TxReceipt, TxStatus } from '@aztec/stdlib/tx';
409
413
  import { getPackageVersion } from '@aztec/stdlib/update-checker';
410
414
  import { Attributes, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
411
- import { FullNodeCheckpointsBuilder as CheckpointsBuilder, FullNodeCheckpointsBuilder, NodeKeystoreAdapter, ValidatorClient, createBlockProposalHandler, createValidatorClient, createValidatorForAcceptingTxs } from '@aztec/validator-client';
415
+ import { FullNodeCheckpointsBuilder as CheckpointsBuilder, FullNodeCheckpointsBuilder, NodeKeystoreAdapter, ValidatorClient, createProposalHandler, createValidatorClient } from '@aztec/validator-client';
412
416
  import { createWorldStateSynchronizer } from '@aztec/world-state';
413
- import { createPublicClient, fallback, http } from 'viem';
417
+ import { createPublicClient } from 'viem';
414
418
  import { createSentinel } from '../sentinel/factory.js';
415
419
  import { createKeyStoreForValidator } from './config.js';
416
420
  import { NodeMetrics } from './node_metrics.js';
@@ -428,6 +432,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
428
432
  l1ToL2MessageSource;
429
433
  worldStateSynchronizer;
430
434
  sequencer;
435
+ proverNode;
431
436
  slasherClient;
432
437
  validatorsSentinel;
433
438
  epochPruneWatcher;
@@ -440,6 +445,9 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
440
445
  telemetry;
441
446
  log;
442
447
  blobClient;
448
+ validatorClient;
449
+ keyStoreManager;
450
+ debugLogStore;
443
451
  static{
444
452
  ({ e: [_initProto] } = _apply_decs_2203_r(this, [
445
453
  [
@@ -454,7 +462,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
454
462
  // Prevent two snapshot operations to happen simultaneously
455
463
  isUploadingSnapshot;
456
464
  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){
465
+ 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
466
  this.config = config;
459
467
  this.p2pClient = p2pClient;
460
468
  this.blockSource = blockSource;
@@ -463,6 +471,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
463
471
  this.l1ToL2MessageSource = l1ToL2MessageSource;
464
472
  this.worldStateSynchronizer = worldStateSynchronizer;
465
473
  this.sequencer = sequencer;
474
+ this.proverNode = proverNode;
466
475
  this.slasherClient = slasherClient;
467
476
  this.validatorsSentinel = validatorsSentinel;
468
477
  this.epochPruneWatcher = epochPruneWatcher;
@@ -475,12 +484,21 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
475
484
  this.telemetry = telemetry;
476
485
  this.log = log;
477
486
  this.blobClient = blobClient;
487
+ this.validatorClient = validatorClient;
488
+ this.keyStoreManager = keyStoreManager;
489
+ this.debugLogStore = debugLogStore;
478
490
  this.initialHeaderHashPromise = (_initProto(this), undefined);
479
491
  this.isUploadingSnapshot = false;
480
492
  this.metrics = new NodeMetrics(telemetry, 'AztecNodeService');
481
493
  this.tracer = telemetry.getTracer('AztecNodeService');
482
494
  this.log.info(`Aztec Node version: ${this.packageVersion}`);
483
495
  this.log.info(`Aztec Node started on chain 0x${l1ChainId.toString(16)}`, config.l1Contracts);
496
+ // A defensive check that protects us against introducing a bug in the complex `createAndSync` function. We must
497
+ // never have debugLogStore enabled when not in test mode because then we would be accumulating debug logs in
498
+ // memory which could be a DoS vector on the sequencer (since no fees are paid for debug logs).
499
+ if (debugLogStore.isEnabled && config.realProofs) {
500
+ throw new Error('debugLogStore should never be enabled when realProofs are set');
501
+ }
484
502
  }
485
503
  async getWorldStateSyncStatus() {
486
504
  const status = await this.worldStateSynchronizer.status();
@@ -502,16 +520,27 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
502
520
  const telemetry = deps.telemetry ?? getTelemetryClient();
503
521
  const dateProvider = deps.dateProvider ?? new DateProvider();
504
522
  const ethereumChain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
505
- // Build a key store from file if given or from environment otherwise
523
+ // Build a key store from file if given or from environment otherwise.
524
+ // We keep the raw KeyStore available so we can merge with prover keys if enableProverNode is set.
506
525
  let keyStoreManager;
507
526
  const keyStoreProvided = config.keyStoreDirectory !== undefined && config.keyStoreDirectory.length > 0;
508
527
  if (keyStoreProvided) {
509
528
  const keyStores = loadKeystores(config.keyStoreDirectory);
510
529
  keyStoreManager = new KeystoreManager(mergeKeystores(keyStores));
511
530
  } else {
512
- const keyStore = createKeyStoreForValidator(config);
513
- if (keyStore) {
514
- keyStoreManager = new KeystoreManager(keyStore);
531
+ const rawKeyStores = [];
532
+ const validatorKeyStore = createKeyStoreForValidator(config);
533
+ if (validatorKeyStore) {
534
+ rawKeyStores.push(validatorKeyStore);
535
+ }
536
+ if (config.enableProverNode) {
537
+ const proverKeyStore = createKeyStoreForProver(config);
538
+ if (proverKeyStore) {
539
+ rawKeyStores.push(proverKeyStore);
540
+ }
541
+ }
542
+ if (rawKeyStores.length > 0) {
543
+ keyStoreManager = new KeystoreManager(rawKeyStores.length === 1 ? rawKeyStores[0] : mergeKeystores(rawKeyStores));
515
544
  }
516
545
  }
517
546
  await keyStoreManager?.validateSigners();
@@ -520,8 +549,8 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
520
549
  if (keyStoreManager === undefined) {
521
550
  throw new Error('Failed to create key store, a requirement for running a validator');
522
551
  }
523
- if (!keyStoreProvided) {
524
- log.warn('KEY STORE CREATED FROM ENVIRONMENT, IT IS RECOMMENDED TO USE A FILE-BASED KEY STORE IN PRODUCTION ENVIRONMENTS');
552
+ if (!keyStoreProvided && process.env.NODE_ENV !== 'test') {
553
+ log.warn("Keystore created from env: it's recommended to use a file-based key store for production");
525
554
  }
526
555
  ValidatorClient.validateKeyStoreConfiguration(keyStoreManager, log);
527
556
  }
@@ -531,9 +560,9 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
531
560
  }
532
561
  const publicClient = createPublicClient({
533
562
  chain: ethereumChain.chainInfo,
534
- transport: fallback(config.l1RpcUrls.map((url)=>http(url, {
535
- batch: false
536
- }))),
563
+ transport: makeL1HttpTransport(config.l1RpcUrls, {
564
+ timeout: config.l1HttpTimeoutMS
565
+ }),
537
566
  pollingInterval: config.viemPollingIntervalMS
538
567
  });
539
568
  const l1ContractsAddresses = await RegistryContract.collectAddresses(publicClient, config.l1Contracts.registryAddress, config.rollupVersion ?? 'canonical');
@@ -543,16 +572,17 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
543
572
  ...l1ContractsAddresses
544
573
  };
545
574
  const rollupContract = new RollupContract(publicClient, config.l1Contracts.rollupAddress.toString());
546
- const [l1GenesisTime, slotDuration, rollupVersionFromRollup] = await Promise.all([
575
+ const [l1GenesisTime, slotDuration, rollupVersionFromRollup, rollupManaLimit] = await Promise.all([
547
576
  rollupContract.getL1GenesisTime(),
548
577
  rollupContract.getSlotDuration(),
549
- rollupContract.getVersion()
578
+ rollupContract.getVersion(),
579
+ rollupContract.getManaLimit().then(Number)
550
580
  ]);
551
581
  config.rollupVersion ??= Number(rollupVersionFromRollup);
552
582
  if (config.rollupVersion !== Number(rollupVersionFromRollup)) {
553
583
  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
584
  }
555
- const blobClient = await createBlobClientWithFileStores(config, createLogger('node:blob-client:client'));
585
+ const blobClient = await createBlobClientWithFileStores(config, log.createChild('blob-client'));
556
586
  // attempt snapshot sync if possible
557
587
  await trySnapshotSync(config, log);
558
588
  const epochCache = await EpochCache.create(config.l1Contracts.rollupAddress, config, {
@@ -569,77 +599,98 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
569
599
  // now create the merkle trees and the world state synchronizer
570
600
  const worldStateSynchronizer = await createWorldStateSynchronizer(config, archiver, options.prefilledPublicData, telemetry);
571
601
  const circuitVerifier = config.realProofs || config.debugForceTxProofVerification ? await BBCircuitVerifier.new(config) : new TestCircuitVerifier(config.proverTestVerificationDelayMs);
602
+ let debugLogStore;
572
603
  if (!config.realProofs) {
573
604
  log.warn(`Aztec node is accepting fake proofs`);
605
+ debugLogStore = new InMemoryDebugLogStore();
606
+ log.info('Aztec node started in test mode (realProofs set to false) hence debug logs from public functions will be collected and served');
607
+ } else {
608
+ debugLogStore = new NullDebugLogStore();
574
609
  }
575
610
  const proofVerifier = new QueuedIVCVerifier(config, circuitVerifier);
611
+ const proverOnly = config.enableProverNode && config.disableValidator;
612
+ if (proverOnly) {
613
+ log.info('Starting in prover-only mode: skipping validator, sequencer, sentinel, and slasher subsystems');
614
+ }
576
615
  // 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
616
+ const p2pClient = await createP2PClient(config, archiver, proofVerifier, worldStateSynchronizer, epochCache, packageVersion, dateProvider, telemetry, deps.p2pClientDeps);
617
+ // We'll accumulate sentinel watchers here
618
+ const watchers = [];
619
+ // Create FullNodeCheckpointsBuilder for block proposal handling and tx validation.
620
+ // Override maxTxsPerCheckpoint with the validator-specific limit if set.
581
621
  const validatorCheckpointsBuilder = new FullNodeCheckpointsBuilder({
582
622
  ...config,
583
623
  l1GenesisTime,
584
- slotDuration: Number(slotDuration)
624
+ slotDuration: Number(slotDuration),
625
+ rollupManaLimit,
626
+ maxTxsPerCheckpoint: config.validateMaxTxsPerCheckpoint
585
627
  }, 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();
628
+ let validatorClient;
629
+ if (!proverOnly) {
630
+ // Create validator client if required
631
+ validatorClient = await createValidatorClient(config, {
632
+ checkpointsBuilder: validatorCheckpointsBuilder,
633
+ worldState: worldStateSynchronizer,
634
+ p2pClient,
635
+ telemetry,
636
+ dateProvider,
637
+ epochCache,
638
+ blockSource: archiver,
639
+ l1ToL2MessageSource: archiver,
640
+ keyStoreManager,
641
+ blobClient,
642
+ slashingProtectionDb: deps.slashingProtectionDb
643
+ });
644
+ // If we have a validator client, register it as a source of offenses for the slasher,
645
+ // and have it register callbacks on the p2p client *before* we start it, otherwise messages
646
+ // like attestations or auths will fail.
647
+ if (validatorClient) {
648
+ watchers.push(validatorClient);
649
+ if (!options.dontStartSequencer) {
650
+ await validatorClient.registerHandlers();
651
+ }
608
652
  }
609
653
  }
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, {
654
+ // If there's no validator client, create a ProposalHandler to handle block and checkpoint proposals
655
+ // for monitoring or reexecution. Reexecution (default) allows us to follow the pending chain,
656
+ // while non-reexecution is used for validating the proposals and collecting their txs.
657
+ // Checkpoint proposals are handled if the blob client can upload blobs.
658
+ if (!validatorClient) {
659
+ const reexecute = !!config.alwaysReexecuteBlockProposals;
660
+ log.info(`Setting up proposal handler` + (reexecute ? ' with reexecution of proposals' : ''));
661
+ createProposalHandler(config, {
615
662
  checkpointsBuilder: validatorCheckpointsBuilder,
616
663
  worldState: worldStateSynchronizer,
617
664
  epochCache,
618
665
  blockSource: archiver,
619
666
  l1ToL2MessageSource: archiver,
620
667
  p2pClient,
668
+ blobClient,
621
669
  dateProvider,
622
670
  telemetry
623
- }).registerForReexecution(p2pClient);
671
+ }).register(p2pClient, reexecute);
624
672
  }
625
673
  // Start world state and wait for it to sync to the archiver.
626
674
  await worldStateSynchronizer.start();
627
675
  // Start p2p. Note that it depends on world state to be running.
628
676
  await p2pClient.start();
629
- const validatorsSentinel = await createSentinel(epochCache, archiver, p2pClient, config);
630
- if (validatorsSentinel && config.slashInactivityPenalty > 0n) {
631
- watchers.push(validatorsSentinel);
632
- }
677
+ let validatorsSentinel;
633
678
  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
679
  let attestationsBlockWatcher;
640
- if (config.slashProposeInvalidAttestationsPenalty > 0n || config.slashAttestDescendantOfInvalidPenalty > 0n) {
641
- attestationsBlockWatcher = new AttestationsBlockWatcher(archiver, epochCache, config);
642
- watchers.push(attestationsBlockWatcher);
680
+ if (!proverOnly) {
681
+ validatorsSentinel = await createSentinel(epochCache, archiver, p2pClient, config);
682
+ if (validatorsSentinel && config.slashInactivityPenalty > 0n) {
683
+ watchers.push(validatorsSentinel);
684
+ }
685
+ if (config.slashPrunePenalty > 0n || config.slashDataWithholdingPenalty > 0n) {
686
+ epochPruneWatcher = new EpochPruneWatcher(archiver, archiver, epochCache, p2pClient.getTxProvider(), validatorCheckpointsBuilder, config);
687
+ watchers.push(epochPruneWatcher);
688
+ }
689
+ // We assume we want to slash for invalid attestations unless all max penalties are set to 0
690
+ if (config.slashProposeInvalidAttestationsPenalty > 0n || config.slashAttestDescendantOfInvalidPenalty > 0n) {
691
+ attestationsBlockWatcher = new AttestationsBlockWatcher(archiver, epochCache, config);
692
+ watchers.push(attestationsBlockWatcher);
693
+ }
643
694
  }
644
695
  // Start p2p-related services once the archiver has completed sync
645
696
  void archiver.waitForInitialSync().then(async ()=>{
@@ -649,6 +700,13 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
649
700
  await attestationsBlockWatcher?.start();
650
701
  log.info(`All p2p services started`);
651
702
  }).catch((err)=>log.error('Failed to start p2p services after archiver sync', err));
703
+ const globalVariableBuilder = new GlobalVariableBuilder(dateProvider, publicClient, {
704
+ l1Contracts: config.l1Contracts,
705
+ ethereumSlotDuration: config.ethereumSlotDuration,
706
+ rollupVersion: BigInt(config.rollupVersion),
707
+ l1GenesisTime,
708
+ slotDuration: Number(slotDuration)
709
+ });
652
710
  // Validator enabled, create/start relevant service
653
711
  let sequencer;
654
712
  let slasherClient;
@@ -658,27 +716,30 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
658
716
  const validatorAddresses = keyStoreManager ? NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager).getAddresses() : [];
659
717
  slasherClient = await createSlasher(config, config.l1Contracts, getPublicClient(config), watchers, dateProvider, epochCache, validatorAddresses, undefined);
660
718
  await slasherClient.start();
661
- const l1TxUtils = config.publisherForwarderAddress ? await createForwarderL1TxUtilsFromEthSigner(publicClient, keyStoreManager.createAllValidatorPublisherSigners(), config.publisherForwarderAddress, {
719
+ const l1TxUtils = config.sequencerPublisherForwarderAddress ? await createForwarderL1TxUtilsFromSigners(publicClient, keyStoreManager.createAllValidatorPublisherSigners(), config.sequencerPublisherForwarderAddress, {
662
720
  ...config,
663
721
  scope: 'sequencer'
664
722
  }, {
665
723
  telemetry,
666
724
  logger: log.createChild('l1-tx-utils'),
667
- dateProvider
668
- }) : await createL1TxUtilsWithBlobsFromEthSigner(publicClient, keyStoreManager.createAllValidatorPublisherSigners(), {
725
+ dateProvider,
726
+ kzg: Blob.getViemKzgInstance()
727
+ }) : await createL1TxUtilsFromSigners(publicClient, keyStoreManager.createAllValidatorPublisherSigners(), {
669
728
  ...config,
670
729
  scope: 'sequencer'
671
730
  }, {
672
731
  telemetry,
673
732
  logger: log.createChild('l1-tx-utils'),
674
- dateProvider
733
+ dateProvider,
734
+ kzg: Blob.getViemKzgInstance()
675
735
  });
676
736
  // Create and start the sequencer client
677
737
  const checkpointsBuilder = new CheckpointsBuilder({
678
738
  ...config,
679
739
  l1GenesisTime,
680
- slotDuration: Number(slotDuration)
681
- }, worldStateSynchronizer, archiver, dateProvider, telemetry);
740
+ slotDuration: Number(slotDuration),
741
+ rollupManaLimit
742
+ }, worldStateSynchronizer, archiver, dateProvider, telemetry, debugLogStore);
682
743
  sequencer = await SequencerClient.new(config, {
683
744
  ...deps,
684
745
  epochCache,
@@ -693,7 +754,8 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
693
754
  telemetry,
694
755
  dateProvider,
695
756
  blobClient,
696
- nodeKeyStore: keyStoreManager
757
+ nodeKeyStore: keyStoreManager,
758
+ globalVariableBuilder
697
759
  });
698
760
  }
699
761
  if (!options.dontStartSequencer && sequencer) {
@@ -702,13 +764,29 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
702
764
  } else if (sequencer) {
703
765
  log.warn(`Sequencer created but not started`);
704
766
  }
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);
767
+ // Create prover node subsystem if enabled
768
+ let proverNode;
769
+ if (config.enableProverNode) {
770
+ proverNode = await createProverNode(config, {
771
+ ...deps.proverNodeDeps,
772
+ telemetry,
773
+ dateProvider,
774
+ archiver,
775
+ worldStateSynchronizer,
776
+ p2pClient,
777
+ epochCache,
778
+ blobClient,
779
+ keyStoreManager
780
+ });
781
+ if (!options.dontStartProverNode) {
782
+ await proverNode.start();
783
+ log.info(`Prover node subsystem started`);
784
+ } else {
785
+ log.info(`Prover node subsystem created but not started`);
786
+ }
787
+ }
788
+ 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);
789
+ return node;
712
790
  }
713
791
  /**
714
792
  * Returns the sequencer client instance.
@@ -716,6 +794,9 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
716
794
  */ getSequencer() {
717
795
  return this.sequencer;
718
796
  }
797
+ /** Returns the prover node subsystem, if enabled. */ getProverNode() {
798
+ return this.proverNode;
799
+ }
719
800
  getBlockSource() {
720
801
  return this.blockSource;
721
802
  }
@@ -735,7 +816,10 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
735
816
  return Promise.resolve(this.p2pClient.getEnr()?.encodeTxt());
736
817
  }
737
818
  async getAllowedPublicSetup() {
738
- return this.config.txPublicSetupAllowList ?? await getDefaultAllowedSetupFunctions();
819
+ return [
820
+ ...await getDefaultAllowedSetupFunctions(),
821
+ ...this.config.txPublicSetupAllowListExtend ?? []
822
+ ];
739
823
  }
740
824
  /**
741
825
  * Method to determine if the node is ready to accept transactions.
@@ -758,7 +842,8 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
758
842
  rollupVersion,
759
843
  enr,
760
844
  l1ContractAddresses: contractAddresses,
761
- protocolContractAddresses: protocolContractAddresses
845
+ protocolContractAddresses: protocolContractAddresses,
846
+ realProofs: !!this.config.realProofs
762
847
  };
763
848
  return nodeInfo;
764
849
  }
@@ -812,6 +897,9 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
812
897
  async getCheckpointedBlocks(from, limit) {
813
898
  return await this.blockSource.getCheckpointedBlocks(from, limit) ?? [];
814
899
  }
900
+ getCheckpointsDataForEpoch(epochNumber) {
901
+ return this.blockSource.getCheckpointsDataForEpoch(epochNumber);
902
+ }
815
903
  /**
816
904
  * Method to fetch the current min L2 fees.
817
905
  * @returns The current min L2 fees.
@@ -839,6 +927,9 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
839
927
  async getCheckpointedBlockNumber() {
840
928
  return await this.blockSource.getCheckpointedL2BlockNumber();
841
929
  }
930
+ getCheckpointNumber() {
931
+ return this.blockSource.getCheckpointNumber();
932
+ }
842
933
  /**
843
934
  * Method to fetch the version of the package.
844
935
  * @returns The node package version
@@ -920,8 +1011,9 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
920
1011
  throw new Error(`Invalid tx: ${reason}`);
921
1012
  }
922
1013
  await this.p2pClient.sendTx(tx);
923
- this.metrics.receivedTx(timer.ms(), true);
924
- this.log.info(`Received tx ${txHash}`, {
1014
+ const duration = timer.ms();
1015
+ this.metrics.receivedTx(duration, true);
1016
+ this.log.info(`Received tx ${txHash} in ${duration}ms`, {
925
1017
  txHash
926
1018
  });
927
1019
  }
@@ -932,18 +1024,20 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
932
1024
  const isKnownToPool = txPoolStatus === 'pending' || txPoolStatus === 'mined';
933
1025
  // Then get the actual tx from the archiver, which tracks every tx in a mined block.
934
1026
  const settledTxReceipt = await this.blockSource.getSettledTxReceipt(txHash);
1027
+ let receipt;
935
1028
  if (settledTxReceipt) {
936
- // If the archiver has the receipt then return it.
937
- return settledTxReceipt;
1029
+ receipt = settledTxReceipt;
938
1030
  } else if (isKnownToPool) {
939
1031
  // If the tx is in the pool but not in the archiver, it's pending.
940
1032
  // This handles race conditions between archiver and p2p, where the archiver
941
1033
  // 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);
1034
+ receipt = new TxReceipt(txHash, TxStatus.PENDING, undefined, undefined);
943
1035
  } else {
944
1036
  // 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');
1037
+ receipt = new TxReceipt(txHash, TxStatus.DROPPED, undefined, 'Tx dropped by P2P node');
946
1038
  }
1039
+ this.debugLogStore.decorateReceiptWithLogs(txHash.toString(), receipt);
1040
+ return receipt;
947
1041
  }
948
1042
  getTxEffect(txHash) {
949
1043
  return this.blockSource.getTxEffect(txHash);
@@ -957,6 +1051,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
957
1051
  await tryStop(this.slasherClient);
958
1052
  await tryStop(this.proofVerifier);
959
1053
  await tryStop(this.sequencer);
1054
+ await tryStop(this.proverNode);
960
1055
  await tryStop(this.p2pClient);
961
1056
  await tryStop(this.worldStateSynchronizer);
962
1057
  await tryStop(this.blockSource);
@@ -996,70 +1091,88 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
996
1091
  return compactArray(await Promise.all(txHashes.map((txHash)=>this.getTxByHash(txHash))));
997
1092
  }
998
1093
  async findLeavesIndexes(referenceBlock, treeId, leafValues) {
999
- const committedDb = await this.#getWorldState(referenceBlock);
1094
+ const committedDb = await this.getWorldState(referenceBlock);
1000
1095
  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]}`);
1096
+ // Filter out undefined values to query block numbers only for found leaves
1097
+ const definedIndices = maybeIndices.filter((x)=>x !== undefined);
1098
+ // Now we find the block numbers for the defined indices
1099
+ const blockNumbers = await committedDb.getBlockNumbersForLeafIndices(treeId, definedIndices);
1100
+ // Build a map from leaf index to block number
1101
+ const indexToBlockNumber = new Map();
1102
+ for(let i = 0; i < definedIndices.length; i++){
1103
+ const blockNumber = blockNumbers[i];
1104
+ if (blockNumber === undefined) {
1105
+ throw new Error(`Block number is undefined for leaf index ${definedIndices[i]} in tree ${MerkleTreeId[treeId]}`);
1009
1106
  }
1107
+ indexToBlockNumber.set(definedIndices[i], blockNumber);
1010
1108
  }
1011
1109
  // Get unique block numbers in order to optimize num calls to getLeafValue function.
1012
1110
  const uniqueBlockNumbers = [
1013
- ...new Set(blockNumbers.filter((x)=>x !== undefined))
1111
+ ...new Set(indexToBlockNumber.values())
1014
1112
  ];
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).
1113
+ // Now we obtain the block hashes from the archive tree (block number = leaf index in archive tree).
1017
1114
  const blockHashes = await Promise.all(uniqueBlockNumbers.map((blockNumber)=>{
1018
1115
  return committedDb.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
1019
1116
  }));
1020
- // If any of the block hashes are undefined, we throw an error.
1117
+ // Build a map from block number to block hash
1118
+ const blockNumberToHash = new Map();
1021
1119
  for(let i = 0; i < uniqueBlockNumbers.length; i++){
1022
- if (blockHashes[i] === undefined) {
1120
+ const blockHash = blockHashes[i];
1121
+ if (blockHash === undefined) {
1023
1122
  throw new Error(`Block hash is undefined for block number ${uniqueBlockNumbers[i]}`);
1024
1123
  }
1124
+ blockNumberToHash.set(uniqueBlockNumbers[i], blockHash);
1025
1125
  }
1026
1126
  // Create DataInBlock objects by combining indices, blockNumbers and blockHashes and return them.
1027
- return maybeIndices.map((index, i)=>{
1127
+ return maybeIndices.map((index)=>{
1028
1128
  if (index === undefined) {
1029
1129
  return undefined;
1030
1130
  }
1031
- const blockNumber = blockNumbers[i];
1131
+ const blockNumber = indexToBlockNumber.get(index);
1032
1132
  if (blockNumber === undefined) {
1033
- return undefined;
1133
+ throw new Error(`Block number not found for leaf index ${index} in tree ${MerkleTreeId[treeId]}`);
1034
1134
  }
1035
- const blockHashIndex = uniqueBlockNumbers.indexOf(blockNumber);
1036
- const blockHash = blockHashes[blockHashIndex];
1037
- if (!blockHash) {
1038
- return undefined;
1135
+ const blockHash = blockNumberToHash.get(blockNumber);
1136
+ if (blockHash === undefined) {
1137
+ throw new Error(`Block hash not found for block number ${blockNumber}`);
1039
1138
  }
1040
1139
  return {
1041
- l2BlockNumber: BlockNumber(Number(blockNumber)),
1140
+ l2BlockNumber: blockNumber,
1042
1141
  l2BlockHash: new BlockHash(blockHash),
1043
1142
  data: index
1044
1143
  };
1045
1144
  });
1046
1145
  }
1047
1146
  async getBlockHashMembershipWitness(referenceBlock, blockHash) {
1048
- const committedDb = await this.#getWorldState(referenceBlock);
1147
+ // Block 0 (the initial block) has an empty archive, so no membership witness can exist.
1148
+ if (referenceBlock === BlockNumber.ZERO) {
1149
+ return undefined;
1150
+ }
1151
+ if (BlockHash.isBlockHash(referenceBlock)) {
1152
+ const initialBlockHash = await this.#getInitialHeaderHash();
1153
+ if (referenceBlock.equals(initialBlockHash)) {
1154
+ return undefined;
1155
+ }
1156
+ }
1157
+ // The Noir circuit checks the archive membership proof against `anchor_block_header.last_archive.root`,
1158
+ // which is the archive tree root BEFORE the anchor block was added (i.e. the state after block N-1).
1159
+ // So we need the world state at block N-1, not block N, to produce a sibling path matching that root.
1160
+ const referenceBlockNumber = await this.resolveBlockNumber(referenceBlock);
1161
+ const committedDb = await this.getWorldState(BlockNumber(referenceBlockNumber - 1));
1049
1162
  const [pathAndIndex] = await committedDb.findSiblingPaths(MerkleTreeId.ARCHIVE, [
1050
1163
  blockHash
1051
1164
  ]);
1052
1165
  return pathAndIndex === undefined ? undefined : MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
1053
1166
  }
1054
1167
  async getNoteHashMembershipWitness(referenceBlock, noteHash) {
1055
- const committedDb = await this.#getWorldState(referenceBlock);
1168
+ const committedDb = await this.getWorldState(referenceBlock);
1056
1169
  const [pathAndIndex] = await committedDb.findSiblingPaths(MerkleTreeId.NOTE_HASH_TREE, [
1057
1170
  noteHash
1058
1171
  ]);
1059
1172
  return pathAndIndex === undefined ? undefined : MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
1060
1173
  }
1061
1174
  async getL1ToL2MessageMembershipWitness(referenceBlock, l1ToL2Message) {
1062
- const db = await this.#getWorldState(referenceBlock);
1175
+ const db = await this.getWorldState(referenceBlock);
1063
1176
  const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [
1064
1177
  l1ToL2Message
1065
1178
  ]);
@@ -1072,9 +1185,9 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
1072
1185
  witness.path
1073
1186
  ];
1074
1187
  }
1075
- async getL1ToL2MessageBlock(l1ToL2Message) {
1188
+ async getL1ToL2MessageCheckpoint(l1ToL2Message) {
1076
1189
  const messageIndex = await this.l1ToL2MessageSource.getL1ToL2MessageIndex(l1ToL2Message);
1077
- return messageIndex ? BlockNumber.fromCheckpointNumber(InboxLeaf.checkpointNumberFromIndex(messageIndex)) : undefined;
1190
+ return messageIndex ? InboxLeaf.checkpointNumberFromIndex(messageIndex) : undefined;
1078
1191
  }
1079
1192
  /**
1080
1193
  * Returns whether an L1 to L2 message is synced by archiver and if it's ready to be included in a block.
@@ -1091,23 +1204,11 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
1091
1204
  */ async getL2ToL1Messages(epoch) {
1092
1205
  // Assumes `getCheckpointedBlocksForEpoch` returns blocks in ascending order of block number.
1093
1206
  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
- }
1207
+ const blocksInCheckpoints = chunkBy(checkpointedBlocks, (cb)=>cb.block.header.globalVariables.slotNumber).map((group)=>group.map((cb)=>cb.block));
1107
1208
  return blocksInCheckpoints.map((blocks)=>blocks.map((block)=>block.body.txEffects.map((txEffect)=>txEffect.l2ToL1Msgs)));
1108
1209
  }
1109
1210
  async getNullifierMembershipWitness(referenceBlock, nullifier) {
1110
- const db = await this.#getWorldState(referenceBlock);
1211
+ const db = await this.getWorldState(referenceBlock);
1111
1212
  const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [
1112
1213
  nullifier.toBuffer()
1113
1214
  ]);
@@ -1121,36 +1222,22 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
1121
1222
  }
1122
1223
  return new NullifierMembershipWitness(index, leafPreimage, path);
1123
1224
  }
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);
1225
+ async getLowNullifierMembershipWitness(referenceBlock, nullifier) {
1226
+ const committedDb = await this.getWorldState(referenceBlock);
1140
1227
  const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
1141
1228
  if (!findResult) {
1142
1229
  return undefined;
1143
1230
  }
1144
1231
  const { index, alreadyPresent } = findResult;
1145
1232
  if (alreadyPresent) {
1146
- this.log.warn(`Nullifier ${nullifier.toBigInt()} already exists in the tree`);
1233
+ throw new Error(`Cannot prove nullifier non-inclusion: nullifier ${nullifier.toBigInt()} already exists in the tree`);
1147
1234
  }
1148
1235
  const preimageData = await committedDb.getLeafPreimage(MerkleTreeId.NULLIFIER_TREE, index);
1149
1236
  const siblingPath = await committedDb.getSiblingPath(MerkleTreeId.NULLIFIER_TREE, BigInt(index));
1150
1237
  return new NullifierMembershipWitness(BigInt(index), preimageData, siblingPath);
1151
1238
  }
1152
1239
  async getPublicDataWitness(referenceBlock, leafSlot) {
1153
- const committedDb = await this.#getWorldState(referenceBlock);
1240
+ const committedDb = await this.getWorldState(referenceBlock);
1154
1241
  const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
1155
1242
  if (!lowLeafResult) {
1156
1243
  return undefined;
@@ -1161,7 +1248,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
1161
1248
  }
1162
1249
  }
1163
1250
  async getPublicStorageAt(referenceBlock, contract, slot) {
1164
- const committedDb = await this.#getWorldState(referenceBlock);
1251
+ const committedDb = await this.getWorldState(referenceBlock);
1165
1252
  const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
1166
1253
  const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
1167
1254
  if (!lowLeafResult || !lowLeafResult.alreadyPresent) {
@@ -1194,6 +1281,12 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
1194
1281
  */ async getBlockHeaderByArchive(archive) {
1195
1282
  return await this.blockSource.getBlockHeaderByArchive(archive);
1196
1283
  }
1284
+ getBlockData(number) {
1285
+ return this.blockSource.getBlockData(number);
1286
+ }
1287
+ getBlockDataByArchive(archive) {
1288
+ return this.blockSource.getBlockDataByArchive(archive);
1289
+ }
1197
1290
  /**
1198
1291
  * Simulates the public part of a transaction with the current state.
1199
1292
  * @param tx - The transaction to simulate.
@@ -1206,7 +1299,8 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
1206
1299
  throw new BadRequestError(`Transaction total gas limit ${txGasLimit + teardownGasLimit} (${txGasLimit} + ${teardownGasLimit}) exceeds maximum gas limit ${this.config.rpcSimulatePublicMaxGasLimit} for simulation`);
1207
1300
  }
1208
1301
  const txHash = tx.getTxHash();
1209
- const blockNumber = BlockNumber(await this.blockSource.getBlockNumber() + 1);
1302
+ const latestBlockNumber = await this.blockSource.getBlockNumber();
1303
+ const blockNumber = BlockNumber.add(latestBlockNumber, 1);
1210
1304
  // If sequencer is not initialized, we just set these values to zero for simulation.
1211
1305
  const coinbase = EthAddress.ZERO;
1212
1306
  const feeRecipient = AztecAddress.ZERO;
@@ -1217,6 +1311,8 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
1217
1311
  txHash,
1218
1312
  blockNumber
1219
1313
  });
1314
+ // Ensure world-state has caught up with the latest block we loaded from the archiver
1315
+ await this.worldStateSynchronizer.syncImmediate(latestBlockNumber);
1220
1316
  const merkleTreeFork = await this.worldStateSynchronizer.fork();
1221
1317
  try {
1222
1318
  const config = PublicSimulatorConfig.from({
@@ -1231,7 +1327,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
1231
1327
  });
1232
1328
  const processor = publicProcessorFactory.create(merkleTreeFork, newGlobalVariables, config);
1233
1329
  // REFACTOR: Consider merging ProcessReturnValues into ProcessedTx
1234
- const [processedTxs, failedTxs, _usedTxs, returns] = await processor.process([
1330
+ const [processedTxs, failedTxs, _usedTxs, returns, debugLogs] = await processor.process([
1235
1331
  tx
1236
1332
  ]);
1237
1333
  // REFACTOR: Consider returning the error rather than throwing
@@ -1242,7 +1338,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
1242
1338
  throw failedTxs[0].error;
1243
1339
  }
1244
1340
  const [processedTx] = processedTxs;
1245
- return new PublicSimulationOutput(processedTx.revertReason, processedTx.globalVariables, processedTx.txEffect, returns, processedTx.gasUsed);
1341
+ return new PublicSimulationOutput(processedTx.revertReason, processedTx.globalVariables, processedTx.txEffect, returns, processedTx.gasUsed, debugLogs);
1246
1342
  } finally{
1247
1343
  await merkleTreeFork.close();
1248
1344
  }
@@ -1250,18 +1346,25 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
1250
1346
  async isValidTx(tx, { isSimulation, skipFeeEnforcement } = {}) {
1251
1347
  const db = this.worldStateSynchronizer.getCommitted();
1252
1348
  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)
1349
+ // We accept transactions if they are not expired by the next slot (checked based on the ExpirationTimestamp field)
1254
1350
  const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
1255
1351
  const blockNumber = BlockNumber(await this.blockSource.getBlockNumber() + 1);
1256
- const validator = createValidatorForAcceptingTxs(db, this.contractDataSource, verifier, {
1352
+ const l1Constants = await this.blockSource.getL1Constants();
1353
+ const validator = createTxValidatorForAcceptingTxsOverRPC(db, this.contractDataSource, verifier, {
1257
1354
  timestamp: nextSlotTimestamp,
1258
1355
  blockNumber,
1259
1356
  l1ChainId: this.l1ChainId,
1260
1357
  rollupVersion: this.version,
1261
- setupAllowList: this.config.txPublicSetupAllowList ?? await getDefaultAllowedSetupFunctions(),
1358
+ setupAllowList: [
1359
+ ...await getDefaultAllowedSetupFunctions(),
1360
+ ...this.config.txPublicSetupAllowListExtend ?? []
1361
+ ],
1262
1362
  gasFees: await this.getCurrentMinFees(),
1263
1363
  skipFeeEnforcement,
1264
- txsPermitted: !this.config.disableTransactions
1364
+ txsPermitted: !this.config.disableTransactions,
1365
+ rollupManaLimit: l1Constants.rollupManaLimit,
1366
+ maxBlockL2Gas: this.config.validateMaxL2BlockGas,
1367
+ maxBlockDAGas: this.config.validateMaxDABlockGas
1265
1368
  }, this.log.getBindings());
1266
1369
  return await validator.validateTx(tx);
1267
1370
  }
@@ -1404,6 +1507,100 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
1404
1507
  return this.slasherClient.gatherOffensesForRound(round === 'current' ? undefined : BigInt(round));
1405
1508
  }
1406
1509
  }
1510
+ async reloadKeystore() {
1511
+ if (!this.config.keyStoreDirectory?.length) {
1512
+ throw new BadRequestError('Cannot reload keystore: node is not using a file-based keystore. ' + 'Set KEY_STORE_DIRECTORY to use file-based keystores.');
1513
+ }
1514
+ if (!this.validatorClient) {
1515
+ throw new BadRequestError('Cannot reload keystore: validator is not enabled.');
1516
+ }
1517
+ this.log.info('Reloading keystore from disk');
1518
+ // Re-read and validate keystore files
1519
+ const keyStores = loadKeystores(this.config.keyStoreDirectory);
1520
+ const newManager = new KeystoreManager(mergeKeystores(keyStores));
1521
+ await newManager.validateSigners();
1522
+ ValidatorClient.validateKeyStoreConfiguration(newManager, this.log);
1523
+ // Validate that every validator's publisher keys overlap with the L1 signers
1524
+ // that were initialized at startup. Publishers cannot be hot-reloaded, so a
1525
+ // validator with a publisher key that doesn't match any existing L1 signer
1526
+ // would silently fail on every proposer slot.
1527
+ if (this.keyStoreManager && this.sequencer) {
1528
+ const oldAdapter = NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager);
1529
+ const availablePublishers = new Set(oldAdapter.getAttesterAddresses().flatMap((a)=>oldAdapter.getPublisherAddresses(a).map((p)=>p.toString().toLowerCase())));
1530
+ const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
1531
+ for (const attester of newAdapter.getAttesterAddresses()){
1532
+ const pubs = newAdapter.getPublisherAddresses(attester);
1533
+ if (pubs.length > 0 && !pubs.some((p)=>availablePublishers.has(p.toString().toLowerCase()))) {
1534
+ 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 ` + `[${[
1535
+ ...availablePublishers
1536
+ ].join(', ')}]. Publishers cannot be hot-reloaded — ` + `use an existing publisher key or restart the node.`);
1537
+ }
1538
+ }
1539
+ }
1540
+ // Build adapters for old and new keystores to compute diff
1541
+ const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
1542
+ const newAddresses = newAdapter.getAttesterAddresses();
1543
+ const oldAddresses = this.keyStoreManager ? NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager).getAttesterAddresses() : [];
1544
+ const oldSet = new Set(oldAddresses.map((a)=>a.toString()));
1545
+ const newSet = new Set(newAddresses.map((a)=>a.toString()));
1546
+ const added = newAddresses.filter((a)=>!oldSet.has(a.toString()));
1547
+ const removed = oldAddresses.filter((a)=>!newSet.has(a.toString()));
1548
+ if (added.length > 0) {
1549
+ this.log.info(`Keystore reload: adding attester keys: ${added.map((a)=>a.toString()).join(', ')}`);
1550
+ }
1551
+ if (removed.length > 0) {
1552
+ this.log.info(`Keystore reload: removing attester keys: ${removed.map((a)=>a.toString()).join(', ')}`);
1553
+ }
1554
+ if (added.length === 0 && removed.length === 0) {
1555
+ this.log.info('Keystore reload: attester keys unchanged');
1556
+ }
1557
+ // Update the validator client (coinbase, feeRecipient, attester keys)
1558
+ this.validatorClient.reloadKeystore(newManager);
1559
+ // Update the publisher factory's keystore so newly-added validators
1560
+ // can be matched to existing publisher keys when proposing blocks.
1561
+ if (this.sequencer) {
1562
+ this.sequencer.updatePublisherNodeKeyStore(newAdapter);
1563
+ }
1564
+ // Update slasher's "don't-slash-self" list with new validator addresses
1565
+ if (this.slasherClient && !this.config.slashSelfAllowed) {
1566
+ const slashValidatorsNever = unique([
1567
+ ...this.config.slashValidatorsNever ?? [],
1568
+ ...newAddresses
1569
+ ].map((a)=>a.toString())).map(EthAddress.fromString);
1570
+ this.slasherClient.updateConfig({
1571
+ slashValidatorsNever
1572
+ });
1573
+ }
1574
+ this.keyStoreManager = newManager;
1575
+ this.log.info('Keystore reloaded: coinbase, feeRecipient, and attester keys updated');
1576
+ }
1577
+ async mineBlock() {
1578
+ if (!this.sequencer) {
1579
+ throw new BadRequestError('Cannot mine block: no sequencer is running');
1580
+ }
1581
+ const currentBlockNumber = await this.getBlockNumber();
1582
+ // Use slot duration + 50% buffer as the timeout so this works on running networks too
1583
+ const { slotDuration } = await this.blockSource.getL1Constants();
1584
+ const timeoutSeconds = Math.ceil(slotDuration * 1.5);
1585
+ // Temporarily set minTxsPerBlock to 0 so the sequencer produces a block even with no txs
1586
+ const originalMinTxsPerBlock = this.sequencer.getSequencer().getConfig().minTxsPerBlock;
1587
+ this.sequencer.updateConfig({
1588
+ minTxsPerBlock: 0
1589
+ });
1590
+ try {
1591
+ // Trigger the sequencer to produce a block immediately
1592
+ void this.sequencer.trigger();
1593
+ // Wait for the new L2 block to appear
1594
+ await retryUntil(async ()=>{
1595
+ const newBlockNumber = await this.getBlockNumber();
1596
+ return newBlockNumber > currentBlockNumber ? true : undefined;
1597
+ }, 'mineBlock', timeoutSeconds, 0.1);
1598
+ } finally{
1599
+ this.sequencer.updateConfig({
1600
+ minTxsPerBlock: originalMinTxsPerBlock
1601
+ });
1602
+ }
1603
+ }
1407
1604
  #getInitialHeaderHash() {
1408
1605
  if (!this.initialHeaderHashPromise) {
1409
1606
  this.initialHeaderHashPromise = this.worldStateSynchronizer.getCommitted().getInitialHeader().hash();
@@ -1414,7 +1611,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
1414
1611
  * Returns an instance of MerkleTreeOperations having first ensured the world state is fully synched
1415
1612
  * @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
1416
1613
  * @returns An instance of a committed MerkleTreeOperations
1417
- */ async #getWorldState(block) {
1614
+ */ async getWorldState(block) {
1418
1615
  let blockSyncedTo = BlockNumber.ZERO;
1419
1616
  try {
1420
1617
  // Attempt to sync the world state if necessary
@@ -1426,6 +1623,8 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
1426
1623
  this.log.debug(`Using committed db for block 'latest', world state synced upto ${blockSyncedTo}`);
1427
1624
  return this.worldStateSynchronizer.getCommitted();
1428
1625
  }
1626
+ // Get the block number, either directly from the parameter or by quering the archiver with the block hash
1627
+ let blockNumber;
1429
1628
  if (BlockHash.isBlockHash(block)) {
1430
1629
  const initialBlockHash = await this.#getInitialHeaderHash();
1431
1630
  if (block.equals(initialBlockHash)) {
@@ -1436,19 +1635,41 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
1436
1635
  if (!header) {
1437
1636
  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.`);
1438
1637
  }
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);
1442
- }
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}).`);
1638
+ blockNumber = header.getBlockNumber();
1639
+ } else {
1640
+ blockNumber = block;
1641
+ }
1642
+ // Check it's within world state sync range
1643
+ if (blockNumber > blockSyncedTo) {
1644
+ throw new Error(`Queried block ${block} not yet synced by the node (node is synced upto ${blockSyncedTo}).`);
1645
+ }
1646
+ this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
1647
+ const snapshot = this.worldStateSynchronizer.getSnapshot(blockNumber);
1648
+ // Double-check world-state synced to the same block hash as was requested
1649
+ if (BlockHash.isBlockHash(block)) {
1650
+ const blockHash = await snapshot.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
1651
+ if (!blockHash || !new BlockHash(blockHash).equals(block)) {
1652
+ throw new Error(`Block hash ${block.toString()} not found in world state at block number ${blockNumber}. If the node API has been queried with anchor block hash possibly a reorg has occurred.`);
1653
+ }
1654
+ }
1655
+ return snapshot;
1656
+ }
1657
+ /** Resolves a block parameter to a block number. */ async resolveBlockNumber(block) {
1658
+ if (block === 'latest') {
1659
+ return BlockNumber(await this.blockSource.getBlockNumber());
1660
+ }
1661
+ if (BlockHash.isBlockHash(block)) {
1662
+ const initialBlockHash = await this.#getInitialHeaderHash();
1663
+ if (block.equals(initialBlockHash)) {
1664
+ return BlockNumber.ZERO;
1665
+ }
1666
+ const header = await this.blockSource.getBlockHeaderByHash(block);
1667
+ if (!header) {
1668
+ throw new Error(`Block hash ${block.toString()} not found.`);
1448
1669
  }
1449
- this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
1450
- return this.worldStateSynchronizer.getSnapshot(blockNumber);
1670
+ return header.getBlockNumber();
1451
1671
  }
1672
+ return block;
1452
1673
  }
1453
1674
  /**
1454
1675
  * Ensure we fully sync the world state