@aztec/aztec-node 0.0.1-commit.6d3c34e → 0.0.1-commit.7ac86ea28
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.
- package/dest/aztec-node/config.d.ts +7 -4
- package/dest/aztec-node/config.d.ts.map +1 -1
- package/dest/aztec-node/config.js +10 -2
- package/dest/aztec-node/node_metrics.d.ts +1 -1
- package/dest/aztec-node/node_metrics.d.ts.map +1 -1
- package/dest/aztec-node/node_metrics.js +8 -4
- package/dest/aztec-node/server.d.ts +39 -93
- package/dest/aztec-node/server.d.ts.map +1 -1
- package/dest/aztec-node/server.js +294 -178
- package/dest/sentinel/factory.d.ts +1 -1
- package/dest/sentinel/factory.d.ts.map +1 -1
- package/dest/sentinel/factory.js +1 -1
- package/dest/sentinel/sentinel.d.ts +2 -2
- package/dest/sentinel/sentinel.d.ts.map +1 -1
- package/dest/sentinel/sentinel.js +53 -27
- package/dest/sentinel/store.d.ts +2 -2
- package/dest/sentinel/store.d.ts.map +1 -1
- package/dest/sentinel/store.js +11 -7
- package/package.json +28 -25
- package/src/aztec-node/config.ts +24 -8
- package/src/aztec-node/node_metrics.ts +12 -5
- package/src/aztec-node/server.ts +370 -241
- package/src/sentinel/factory.ts +1 -6
- package/src/sentinel/sentinel.ts +56 -23
- package/src/sentinel/store.ts +12 -12
|
@@ -374,13 +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 {
|
|
377
|
+
import { Blob } from '@aztec/blob-lib';
|
|
378
378
|
import { EpochCache } from '@aztec/epoch-cache';
|
|
379
379
|
import { createEthereumChain } from '@aztec/ethereum/chain';
|
|
380
380
|
import { getPublicClient } from '@aztec/ethereum/client';
|
|
381
381
|
import { RegistryContract, RollupContract } from '@aztec/ethereum/contracts';
|
|
382
382
|
import { BlockNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
383
|
-
import { compactArray, pick } from '@aztec/foundation/collection';
|
|
383
|
+
import { compactArray, pick, unique } from '@aztec/foundation/collection';
|
|
384
384
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
385
385
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
386
386
|
import { BadRequestError } from '@aztec/foundation/json-rpc';
|
|
@@ -390,15 +390,17 @@ import { DateProvider, Timer } from '@aztec/foundation/timer';
|
|
|
390
390
|
import { MembershipWitness } from '@aztec/foundation/trees';
|
|
391
391
|
import { KeystoreManager, loadKeystores, mergeKeystores } from '@aztec/node-keystore';
|
|
392
392
|
import { trySnapshotSync, uploadSnapshot } from '@aztec/node-lib/actions';
|
|
393
|
-
import {
|
|
393
|
+
import { createForwarderL1TxUtilsFromSigners, createL1TxUtilsFromSigners } from '@aztec/node-lib/factories';
|
|
394
394
|
import { createP2PClient, getDefaultAllowedSetupFunctions } from '@aztec/p2p';
|
|
395
395
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
396
|
-
import {
|
|
396
|
+
import { createProverNode } from '@aztec/prover-node';
|
|
397
|
+
import { createKeyStoreForProver } from '@aztec/prover-node/config';
|
|
398
|
+
import { GlobalVariableBuilder, SequencerClient } from '@aztec/sequencer-client';
|
|
397
399
|
import { PublicProcessorFactory } from '@aztec/simulator/server';
|
|
398
400
|
import { AttestationsBlockWatcher, EpochPruneWatcher, createSlasher } from '@aztec/slasher';
|
|
399
401
|
import { CollectionLimitsConfig, PublicSimulatorConfig } from '@aztec/stdlib/avm';
|
|
400
402
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
401
|
-
import {
|
|
403
|
+
import { BlockHash, L2Block } from '@aztec/stdlib/block';
|
|
402
404
|
import { GasFees } from '@aztec/stdlib/gas';
|
|
403
405
|
import { computePublicDataTreeLeafSlot } from '@aztec/stdlib/hash';
|
|
404
406
|
import { AztecNodeAdminConfigSchema } from '@aztec/stdlib/interfaces/client';
|
|
@@ -429,6 +431,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
429
431
|
l1ToL2MessageSource;
|
|
430
432
|
worldStateSynchronizer;
|
|
431
433
|
sequencer;
|
|
434
|
+
proverNode;
|
|
432
435
|
slasherClient;
|
|
433
436
|
validatorsSentinel;
|
|
434
437
|
epochPruneWatcher;
|
|
@@ -441,6 +444,8 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
441
444
|
telemetry;
|
|
442
445
|
log;
|
|
443
446
|
blobClient;
|
|
447
|
+
validatorClient;
|
|
448
|
+
keyStoreManager;
|
|
444
449
|
static{
|
|
445
450
|
({ e: [_initProto] } = _apply_decs_2203_r(this, [
|
|
446
451
|
[
|
|
@@ -451,10 +456,11 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
451
456
|
], []));
|
|
452
457
|
}
|
|
453
458
|
metrics;
|
|
459
|
+
initialHeaderHashPromise;
|
|
454
460
|
// Prevent two snapshot operations to happen simultaneously
|
|
455
461
|
isUploadingSnapshot;
|
|
456
462
|
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){
|
|
463
|
+
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){
|
|
458
464
|
this.config = config;
|
|
459
465
|
this.p2pClient = p2pClient;
|
|
460
466
|
this.blockSource = blockSource;
|
|
@@ -463,6 +469,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
463
469
|
this.l1ToL2MessageSource = l1ToL2MessageSource;
|
|
464
470
|
this.worldStateSynchronizer = worldStateSynchronizer;
|
|
465
471
|
this.sequencer = sequencer;
|
|
472
|
+
this.proverNode = proverNode;
|
|
466
473
|
this.slasherClient = slasherClient;
|
|
467
474
|
this.validatorsSentinel = validatorsSentinel;
|
|
468
475
|
this.epochPruneWatcher = epochPruneWatcher;
|
|
@@ -475,7 +482,10 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
475
482
|
this.telemetry = telemetry;
|
|
476
483
|
this.log = log;
|
|
477
484
|
this.blobClient = blobClient;
|
|
478
|
-
this.
|
|
485
|
+
this.validatorClient = validatorClient;
|
|
486
|
+
this.keyStoreManager = keyStoreManager;
|
|
487
|
+
this.initialHeaderHashPromise = (_initProto(this), undefined);
|
|
488
|
+
this.isUploadingSnapshot = false;
|
|
479
489
|
this.metrics = new NodeMetrics(telemetry, 'AztecNodeService');
|
|
480
490
|
this.tracer = telemetry.getTracer('AztecNodeService');
|
|
481
491
|
this.log.info(`Aztec Node version: ${this.packageVersion}`);
|
|
@@ -501,16 +511,27 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
501
511
|
const telemetry = deps.telemetry ?? getTelemetryClient();
|
|
502
512
|
const dateProvider = deps.dateProvider ?? new DateProvider();
|
|
503
513
|
const ethereumChain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
|
|
504
|
-
// Build a key store from file if given or from environment otherwise
|
|
514
|
+
// Build a key store from file if given or from environment otherwise.
|
|
515
|
+
// We keep the raw KeyStore available so we can merge with prover keys if enableProverNode is set.
|
|
505
516
|
let keyStoreManager;
|
|
506
517
|
const keyStoreProvided = config.keyStoreDirectory !== undefined && config.keyStoreDirectory.length > 0;
|
|
507
518
|
if (keyStoreProvided) {
|
|
508
519
|
const keyStores = loadKeystores(config.keyStoreDirectory);
|
|
509
520
|
keyStoreManager = new KeystoreManager(mergeKeystores(keyStores));
|
|
510
521
|
} else {
|
|
511
|
-
const
|
|
512
|
-
|
|
513
|
-
|
|
522
|
+
const rawKeyStores = [];
|
|
523
|
+
const validatorKeyStore = createKeyStoreForValidator(config);
|
|
524
|
+
if (validatorKeyStore) {
|
|
525
|
+
rawKeyStores.push(validatorKeyStore);
|
|
526
|
+
}
|
|
527
|
+
if (config.enableProverNode) {
|
|
528
|
+
const proverKeyStore = createKeyStoreForProver(config);
|
|
529
|
+
if (proverKeyStore) {
|
|
530
|
+
rawKeyStores.push(proverKeyStore);
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
if (rawKeyStores.length > 0) {
|
|
534
|
+
keyStoreManager = new KeystoreManager(rawKeyStores.length === 1 ? rawKeyStores[0] : mergeKeystores(rawKeyStores));
|
|
514
535
|
}
|
|
515
536
|
}
|
|
516
537
|
await keyStoreManager?.validateSigners();
|
|
@@ -519,8 +540,8 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
519
540
|
if (keyStoreManager === undefined) {
|
|
520
541
|
throw new Error('Failed to create key store, a requirement for running a validator');
|
|
521
542
|
}
|
|
522
|
-
if (!keyStoreProvided) {
|
|
523
|
-
log.warn(
|
|
543
|
+
if (!keyStoreProvided && process.env.NODE_ENV !== 'test') {
|
|
544
|
+
log.warn("Keystore created from env: it's recommended to use a file-based key store for production");
|
|
524
545
|
}
|
|
525
546
|
ValidatorClient.validateKeyStoreConfiguration(keyStoreManager, log);
|
|
526
547
|
}
|
|
@@ -551,7 +572,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
551
572
|
if (config.rollupVersion !== Number(rollupVersionFromRollup)) {
|
|
552
573
|
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}).`);
|
|
553
574
|
}
|
|
554
|
-
const blobClient = await createBlobClientWithFileStores(config,
|
|
575
|
+
const blobClient = await createBlobClientWithFileStores(config, log.createChild('blob-client'));
|
|
555
576
|
// attempt snapshot sync if possible
|
|
556
577
|
await trySnapshotSync(config, log);
|
|
557
578
|
const epochCache = await EpochCache.create(config.l1Contracts.rollupAddress, config, {
|
|
@@ -576,22 +597,16 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
576
597
|
const p2pClient = await createP2PClient(P2PClientType.Full, config, archiver, proofVerifier, worldStateSynchronizer, epochCache, packageVersion, dateProvider, telemetry, deps.p2pClientDeps);
|
|
577
598
|
// We should really not be modifying the config object
|
|
578
599
|
config.txPublicSetupAllowList = config.txPublicSetupAllowList ?? await getDefaultAllowedSetupFunctions();
|
|
579
|
-
// Create BlockBuilder for EpochPruneWatcher (slasher functionality)
|
|
580
|
-
const blockBuilder = new BlockBuilder({
|
|
581
|
-
...config,
|
|
582
|
-
l1GenesisTime,
|
|
583
|
-
slotDuration: Number(slotDuration)
|
|
584
|
-
}, worldStateSynchronizer, archiver, dateProvider, telemetry);
|
|
585
600
|
// Create FullNodeCheckpointsBuilder for validator and non-validator block proposal handling
|
|
586
601
|
const validatorCheckpointsBuilder = new FullNodeCheckpointsBuilder({
|
|
587
602
|
...config,
|
|
588
603
|
l1GenesisTime,
|
|
589
604
|
slotDuration: Number(slotDuration)
|
|
590
|
-
}, archiver, dateProvider, telemetry);
|
|
605
|
+
}, worldStateSynchronizer, archiver, dateProvider, telemetry);
|
|
591
606
|
// We'll accumulate sentinel watchers here
|
|
592
607
|
const watchers = [];
|
|
593
608
|
// Create validator client if required
|
|
594
|
-
const validatorClient = createValidatorClient(config, {
|
|
609
|
+
const validatorClient = await createValidatorClient(config, {
|
|
595
610
|
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
596
611
|
worldState: worldStateSynchronizer,
|
|
597
612
|
p2pClient,
|
|
@@ -637,7 +652,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
637
652
|
}
|
|
638
653
|
let epochPruneWatcher;
|
|
639
654
|
if (config.slashPrunePenalty > 0n || config.slashDataWithholdingPenalty > 0n) {
|
|
640
|
-
epochPruneWatcher = new EpochPruneWatcher(archiver, archiver, epochCache, p2pClient.getTxProvider(),
|
|
655
|
+
epochPruneWatcher = new EpochPruneWatcher(archiver, archiver, epochCache, p2pClient.getTxProvider(), validatorCheckpointsBuilder, config);
|
|
641
656
|
watchers.push(epochPruneWatcher);
|
|
642
657
|
}
|
|
643
658
|
// We assume we want to slash for invalid attestations unless all max penalties are set to 0
|
|
@@ -663,27 +678,29 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
663
678
|
const validatorAddresses = keyStoreManager ? NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager).getAddresses() : [];
|
|
664
679
|
slasherClient = await createSlasher(config, config.l1Contracts, getPublicClient(config), watchers, dateProvider, epochCache, validatorAddresses, undefined);
|
|
665
680
|
await slasherClient.start();
|
|
666
|
-
const l1TxUtils = config.
|
|
681
|
+
const l1TxUtils = config.sequencerPublisherForwarderAddress ? await createForwarderL1TxUtilsFromSigners(publicClient, keyStoreManager.createAllValidatorPublisherSigners(), config.sequencerPublisherForwarderAddress, {
|
|
667
682
|
...config,
|
|
668
683
|
scope: 'sequencer'
|
|
669
684
|
}, {
|
|
670
685
|
telemetry,
|
|
671
686
|
logger: log.createChild('l1-tx-utils'),
|
|
672
|
-
dateProvider
|
|
673
|
-
|
|
687
|
+
dateProvider,
|
|
688
|
+
kzg: Blob.getViemKzgInstance()
|
|
689
|
+
}) : await createL1TxUtilsFromSigners(publicClient, keyStoreManager.createAllValidatorPublisherSigners(), {
|
|
674
690
|
...config,
|
|
675
691
|
scope: 'sequencer'
|
|
676
692
|
}, {
|
|
677
693
|
telemetry,
|
|
678
694
|
logger: log.createChild('l1-tx-utils'),
|
|
679
|
-
dateProvider
|
|
695
|
+
dateProvider,
|
|
696
|
+
kzg: Blob.getViemKzgInstance()
|
|
680
697
|
});
|
|
681
698
|
// Create and start the sequencer client
|
|
682
699
|
const checkpointsBuilder = new CheckpointsBuilder({
|
|
683
700
|
...config,
|
|
684
701
|
l1GenesisTime,
|
|
685
702
|
slotDuration: Number(slotDuration)
|
|
686
|
-
}, archiver, dateProvider, telemetry);
|
|
703
|
+
}, worldStateSynchronizer, archiver, dateProvider, telemetry);
|
|
687
704
|
sequencer = await SequencerClient.new(config, {
|
|
688
705
|
...deps,
|
|
689
706
|
epochCache,
|
|
@@ -707,13 +724,35 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
707
724
|
} else if (sequencer) {
|
|
708
725
|
log.warn(`Sequencer created but not started`);
|
|
709
726
|
}
|
|
727
|
+
// Create prover node subsystem if enabled
|
|
728
|
+
let proverNode;
|
|
729
|
+
if (config.enableProverNode) {
|
|
730
|
+
proverNode = await createProverNode(config, {
|
|
731
|
+
...deps.proverNodeDeps,
|
|
732
|
+
telemetry,
|
|
733
|
+
dateProvider,
|
|
734
|
+
archiver,
|
|
735
|
+
worldStateSynchronizer,
|
|
736
|
+
p2pClient,
|
|
737
|
+
epochCache,
|
|
738
|
+
blobClient,
|
|
739
|
+
keyStoreManager
|
|
740
|
+
});
|
|
741
|
+
if (!options.dontStartProverNode) {
|
|
742
|
+
await proverNode.start();
|
|
743
|
+
log.info(`Prover node subsystem started`);
|
|
744
|
+
} else {
|
|
745
|
+
log.info(`Prover node subsystem created but not started`);
|
|
746
|
+
}
|
|
747
|
+
}
|
|
710
748
|
const globalVariableBuilder = new GlobalVariableBuilder({
|
|
711
749
|
...config,
|
|
712
750
|
rollupVersion: BigInt(config.rollupVersion),
|
|
713
751
|
l1GenesisTime,
|
|
714
752
|
slotDuration: Number(slotDuration)
|
|
715
753
|
});
|
|
716
|
-
|
|
754
|
+
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);
|
|
755
|
+
return node;
|
|
717
756
|
}
|
|
718
757
|
/**
|
|
719
758
|
* Returns the sequencer client instance.
|
|
@@ -721,6 +760,9 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
721
760
|
*/ getSequencer() {
|
|
722
761
|
return this.sequencer;
|
|
723
762
|
}
|
|
763
|
+
/** Returns the prover node subsystem, if enabled. */ getProverNode() {
|
|
764
|
+
return this.proverNode;
|
|
765
|
+
}
|
|
724
766
|
getBlockSource() {
|
|
725
767
|
return this.blockSource;
|
|
726
768
|
}
|
|
@@ -763,33 +805,46 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
763
805
|
rollupVersion,
|
|
764
806
|
enr,
|
|
765
807
|
l1ContractAddresses: contractAddresses,
|
|
766
|
-
protocolContractAddresses: protocolContractAddresses
|
|
808
|
+
protocolContractAddresses: protocolContractAddresses,
|
|
809
|
+
realProofs: !!this.config.realProofs
|
|
767
810
|
};
|
|
768
811
|
return nodeInfo;
|
|
769
812
|
}
|
|
770
813
|
/**
|
|
771
|
-
* Get a block specified by its number.
|
|
772
|
-
* @param
|
|
814
|
+
* Get a block specified by its block number, block hash, or 'latest'.
|
|
815
|
+
* @param block - The block parameter (block number, block hash, or 'latest').
|
|
773
816
|
* @returns The requested block.
|
|
774
|
-
*/ async getBlock(
|
|
775
|
-
|
|
776
|
-
|
|
817
|
+
*/ async getBlock(block) {
|
|
818
|
+
if (BlockHash.isBlockHash(block)) {
|
|
819
|
+
return this.getBlockByHash(block);
|
|
820
|
+
}
|
|
821
|
+
const blockNumber = block === 'latest' ? await this.getBlockNumber() : block;
|
|
822
|
+
if (blockNumber === BlockNumber.ZERO) {
|
|
823
|
+
return this.buildInitialBlock();
|
|
824
|
+
}
|
|
825
|
+
return await this.blockSource.getL2Block(blockNumber);
|
|
777
826
|
}
|
|
778
827
|
/**
|
|
779
828
|
* Get a block specified by its hash.
|
|
780
829
|
* @param blockHash - The block hash being requested.
|
|
781
830
|
* @returns The requested block.
|
|
782
831
|
*/ async getBlockByHash(blockHash) {
|
|
783
|
-
const
|
|
784
|
-
|
|
832
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
833
|
+
if (blockHash.equals(initialBlockHash)) {
|
|
834
|
+
return this.buildInitialBlock();
|
|
835
|
+
}
|
|
836
|
+
return await this.blockSource.getL2BlockByHash(blockHash);
|
|
837
|
+
}
|
|
838
|
+
buildInitialBlock() {
|
|
839
|
+
const initialHeader = this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
840
|
+
return L2Block.empty(initialHeader);
|
|
785
841
|
}
|
|
786
842
|
/**
|
|
787
843
|
* Get a block specified by its archive root.
|
|
788
844
|
* @param archive - The archive root being requested.
|
|
789
845
|
* @returns The requested block.
|
|
790
846
|
*/ async getBlockByArchive(archive) {
|
|
791
|
-
|
|
792
|
-
return publishedBlock?.block;
|
|
847
|
+
return await this.blockSource.getL2BlockByArchive(archive);
|
|
793
848
|
}
|
|
794
849
|
/**
|
|
795
850
|
* Method to request blocks. Will attempt to return all requested blocks but will return only those available.
|
|
@@ -797,19 +852,13 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
797
852
|
* @param limit - The maximum number of blocks to obtain.
|
|
798
853
|
* @returns The blocks requested.
|
|
799
854
|
*/ async getBlocks(from, limit) {
|
|
800
|
-
return await this.blockSource.getBlocks(from, limit) ?? [];
|
|
855
|
+
return await this.blockSource.getBlocks(from, BlockNumber(limit)) ?? [];
|
|
801
856
|
}
|
|
802
|
-
async
|
|
803
|
-
return await this.blockSource.
|
|
857
|
+
async getCheckpoints(from, limit) {
|
|
858
|
+
return await this.blockSource.getCheckpoints(from, limit) ?? [];
|
|
804
859
|
}
|
|
805
|
-
async
|
|
806
|
-
return await this.blockSource.
|
|
807
|
-
}
|
|
808
|
-
async getL2BlocksNew(from, limit) {
|
|
809
|
-
return await this.blockSource.getL2BlocksNew(from, limit) ?? [];
|
|
810
|
-
}
|
|
811
|
-
async getCheckpointedBlocks(from, limit, proven) {
|
|
812
|
-
return await this.blockSource.getCheckpointedBlocks(from, limit, proven) ?? [];
|
|
860
|
+
async getCheckpointedBlocks(from, limit) {
|
|
861
|
+
return await this.blockSource.getCheckpointedBlocks(from, limit) ?? [];
|
|
813
862
|
}
|
|
814
863
|
/**
|
|
815
864
|
* Method to fetch the current min L2 fees.
|
|
@@ -835,6 +884,9 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
835
884
|
async getProvenBlockNumber() {
|
|
836
885
|
return await this.blockSource.getProvenBlockNumber();
|
|
837
886
|
}
|
|
887
|
+
async getCheckpointedBlockNumber() {
|
|
888
|
+
return await this.blockSource.getCheckpointedL2BlockNumber();
|
|
889
|
+
}
|
|
838
890
|
/**
|
|
839
891
|
* Method to fetch the version of the package.
|
|
840
892
|
* @returns The node package version
|
|
@@ -859,11 +911,29 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
859
911
|
getContract(address) {
|
|
860
912
|
return this.contractDataSource.getContract(address);
|
|
861
913
|
}
|
|
862
|
-
getPrivateLogsByTags(tags) {
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
914
|
+
async getPrivateLogsByTags(tags, page, referenceBlock) {
|
|
915
|
+
if (referenceBlock) {
|
|
916
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
917
|
+
if (!referenceBlock.equals(initialBlockHash)) {
|
|
918
|
+
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
919
|
+
if (!header) {
|
|
920
|
+
throw new Error(`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`);
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
return this.logsSource.getPrivateLogsByTags(tags, page);
|
|
925
|
+
}
|
|
926
|
+
async getPublicLogsByTagsFromContract(contractAddress, tags, page, referenceBlock) {
|
|
927
|
+
if (referenceBlock) {
|
|
928
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
929
|
+
if (!referenceBlock.equals(initialBlockHash)) {
|
|
930
|
+
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
931
|
+
if (!header) {
|
|
932
|
+
throw new Error(`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`);
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page);
|
|
867
937
|
}
|
|
868
938
|
/**
|
|
869
939
|
* Gets public logs based on the provided filter.
|
|
@@ -904,18 +974,24 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
904
974
|
});
|
|
905
975
|
}
|
|
906
976
|
async getTxReceipt(txHash) {
|
|
907
|
-
|
|
908
|
-
//
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
txReceipt = new TxReceipt(txHash, TxStatus.PENDING, '');
|
|
913
|
-
}
|
|
977
|
+
// Check the tx pool status first. If the tx is known to the pool (pending or mined), we'll use that
|
|
978
|
+
// as a fallback if we don't find a settled receipt in the archiver.
|
|
979
|
+
const txPoolStatus = await this.p2pClient.getTxStatus(txHash);
|
|
980
|
+
const isKnownToPool = txPoolStatus === 'pending' || txPoolStatus === 'mined';
|
|
981
|
+
// Then get the actual tx from the archiver, which tracks every tx in a mined block.
|
|
914
982
|
const settledTxReceipt = await this.blockSource.getSettledTxReceipt(txHash);
|
|
915
983
|
if (settledTxReceipt) {
|
|
916
|
-
|
|
984
|
+
// If the archiver has the receipt then return it.
|
|
985
|
+
return settledTxReceipt;
|
|
986
|
+
} else if (isKnownToPool) {
|
|
987
|
+
// If the tx is in the pool but not in the archiver, it's pending.
|
|
988
|
+
// This handles race conditions between archiver and p2p, where the archiver
|
|
989
|
+
// has pruned the block in which a tx was mined, but p2p has not caught up yet.
|
|
990
|
+
return new TxReceipt(txHash, TxStatus.PENDING, undefined, undefined);
|
|
991
|
+
} else {
|
|
992
|
+
// Otherwise, if we don't know the tx, we consider it dropped.
|
|
993
|
+
return new TxReceipt(txHash, TxStatus.DROPPED, undefined, 'Tx dropped by P2P node');
|
|
917
994
|
}
|
|
918
|
-
return txReceipt;
|
|
919
995
|
}
|
|
920
996
|
getTxEffect(txHash) {
|
|
921
997
|
return this.blockSource.getTxEffect(txHash);
|
|
@@ -929,6 +1005,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
929
1005
|
await tryStop(this.slasherClient);
|
|
930
1006
|
await tryStop(this.proofVerifier);
|
|
931
1007
|
await tryStop(this.sequencer);
|
|
1008
|
+
await tryStop(this.proverNode);
|
|
932
1009
|
await tryStop(this.p2pClient);
|
|
933
1010
|
await tryStop(this.worldStateSynchronizer);
|
|
934
1011
|
await tryStop(this.blockSource);
|
|
@@ -967,15 +1044,8 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
967
1044
|
*/ async getTxsByHash(txHashes) {
|
|
968
1045
|
return compactArray(await Promise.all(txHashes.map((txHash)=>this.getTxByHash(txHash))));
|
|
969
1046
|
}
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
* the leaves were inserted.
|
|
973
|
-
* @param blockNumber - The block number at which to get the data or 'latest' for latest data.
|
|
974
|
-
* @param treeId - The tree to search in.
|
|
975
|
-
* @param leafValues - The values to search for.
|
|
976
|
-
* @returns The indices of leaves and the block metadata of a block in which the leaves were inserted.
|
|
977
|
-
*/ async findLeavesIndexes(blockNumber, treeId, leafValues) {
|
|
978
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
1047
|
+
async findLeavesIndexes(referenceBlock, treeId, leafValues) {
|
|
1048
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
979
1049
|
const maybeIndices = await committedDb.findLeafIndices(treeId, leafValues.map((x)=>x.toBuffer()));
|
|
980
1050
|
// We filter out undefined values
|
|
981
1051
|
const indices = maybeIndices.filter((x)=>x !== undefined);
|
|
@@ -1018,50 +1088,27 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1018
1088
|
}
|
|
1019
1089
|
return {
|
|
1020
1090
|
l2BlockNumber: BlockNumber(Number(blockNumber)),
|
|
1021
|
-
l2BlockHash:
|
|
1091
|
+
l2BlockHash: new BlockHash(blockHash),
|
|
1022
1092
|
data: index
|
|
1023
1093
|
};
|
|
1024
1094
|
});
|
|
1025
1095
|
}
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
* @param blockNumber - The block number at which to get the data.
|
|
1029
|
-
* @param leafIndex - The index of the leaf for which the sibling path is required.
|
|
1030
|
-
* @returns The sibling path for the leaf index.
|
|
1031
|
-
*/ async getNullifierSiblingPath(blockNumber, leafIndex) {
|
|
1032
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
1033
|
-
return committedDb.getSiblingPath(MerkleTreeId.NULLIFIER_TREE, leafIndex);
|
|
1034
|
-
}
|
|
1035
|
-
/**
|
|
1036
|
-
* Returns a sibling path for the given index in the data tree.
|
|
1037
|
-
* @param blockNumber - The block number at which to get the data.
|
|
1038
|
-
* @param leafIndex - The index of the leaf for which the sibling path is required.
|
|
1039
|
-
* @returns The sibling path for the leaf index.
|
|
1040
|
-
*/ async getNoteHashSiblingPath(blockNumber, leafIndex) {
|
|
1041
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
1042
|
-
return committedDb.getSiblingPath(MerkleTreeId.NOTE_HASH_TREE, leafIndex);
|
|
1043
|
-
}
|
|
1044
|
-
async getArchiveMembershipWitness(blockNumber, archive) {
|
|
1045
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
1096
|
+
async getBlockHashMembershipWitness(referenceBlock, blockHash) {
|
|
1097
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
1046
1098
|
const [pathAndIndex] = await committedDb.findSiblingPaths(MerkleTreeId.ARCHIVE, [
|
|
1047
|
-
|
|
1099
|
+
blockHash
|
|
1048
1100
|
]);
|
|
1049
1101
|
return pathAndIndex === undefined ? undefined : MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
1050
1102
|
}
|
|
1051
|
-
async getNoteHashMembershipWitness(
|
|
1052
|
-
const committedDb = await this.#getWorldState(
|
|
1103
|
+
async getNoteHashMembershipWitness(referenceBlock, noteHash) {
|
|
1104
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
1053
1105
|
const [pathAndIndex] = await committedDb.findSiblingPaths(MerkleTreeId.NOTE_HASH_TREE, [
|
|
1054
1106
|
noteHash
|
|
1055
1107
|
]);
|
|
1056
1108
|
return pathAndIndex === undefined ? undefined : MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
1057
1109
|
}
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
* @param blockNumber - The block number at which to get the data.
|
|
1061
|
-
* @param l1ToL2Message - The l1ToL2Message to get the index / sibling path for.
|
|
1062
|
-
* @returns A tuple of the index and the sibling path of the L1ToL2Message (undefined if not found).
|
|
1063
|
-
*/ async getL1ToL2MessageMembershipWitness(blockNumber, l1ToL2Message) {
|
|
1064
|
-
const db = await this.#getWorldState(blockNumber);
|
|
1110
|
+
async getL1ToL2MessageMembershipWitness(referenceBlock, l1ToL2Message) {
|
|
1111
|
+
const db = await this.#getWorldState(referenceBlock);
|
|
1065
1112
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [
|
|
1066
1113
|
l1ToL2Message
|
|
1067
1114
|
]);
|
|
@@ -1091,12 +1138,13 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1091
1138
|
* @param epoch - The epoch at which to get the data.
|
|
1092
1139
|
* @returns The L2 to L1 messages (empty array if the epoch is not found).
|
|
1093
1140
|
*/ async getL2ToL1Messages(epoch) {
|
|
1094
|
-
// Assumes `
|
|
1095
|
-
const
|
|
1141
|
+
// Assumes `getCheckpointedBlocksForEpoch` returns blocks in ascending order of block number.
|
|
1142
|
+
const checkpointedBlocks = await this.blockSource.getCheckpointedBlocksForEpoch(epoch);
|
|
1096
1143
|
const blocksInCheckpoints = [];
|
|
1097
1144
|
let previousSlotNumber = SlotNumber.ZERO;
|
|
1098
1145
|
let checkpointIndex = -1;
|
|
1099
|
-
for (const
|
|
1146
|
+
for (const checkpointedBlock of checkpointedBlocks){
|
|
1147
|
+
const block = checkpointedBlock.block;
|
|
1100
1148
|
const slotNumber = block.header.globalVariables.slotNumber;
|
|
1101
1149
|
if (slotNumber !== previousSlotNumber) {
|
|
1102
1150
|
checkpointIndex++;
|
|
@@ -1107,31 +1155,8 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1107
1155
|
}
|
|
1108
1156
|
return blocksInCheckpoints.map((blocks)=>blocks.map((block)=>block.body.txEffects.map((txEffect)=>txEffect.l2ToL1Msgs)));
|
|
1109
1157
|
}
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
* @param blockNumber - The block number at which to get the data.
|
|
1113
|
-
* @param leafIndex - Index of the leaf in the tree.
|
|
1114
|
-
* @returns The sibling path.
|
|
1115
|
-
*/ async getArchiveSiblingPath(blockNumber, leafIndex) {
|
|
1116
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
1117
|
-
return committedDb.getSiblingPath(MerkleTreeId.ARCHIVE, leafIndex);
|
|
1118
|
-
}
|
|
1119
|
-
/**
|
|
1120
|
-
* Returns a sibling path for a leaf in the committed public data tree.
|
|
1121
|
-
* @param blockNumber - The block number at which to get the data.
|
|
1122
|
-
* @param leafIndex - Index of the leaf in the tree.
|
|
1123
|
-
* @returns The sibling path.
|
|
1124
|
-
*/ async getPublicDataSiblingPath(blockNumber, leafIndex) {
|
|
1125
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
1126
|
-
return committedDb.getSiblingPath(MerkleTreeId.PUBLIC_DATA_TREE, leafIndex);
|
|
1127
|
-
}
|
|
1128
|
-
/**
|
|
1129
|
-
* Returns a nullifier membership witness for a given nullifier at a given block.
|
|
1130
|
-
* @param blockNumber - The block number at which to get the index.
|
|
1131
|
-
* @param nullifier - Nullifier we try to find witness for.
|
|
1132
|
-
* @returns The nullifier membership witness (if found).
|
|
1133
|
-
*/ async getNullifierMembershipWitness(blockNumber, nullifier) {
|
|
1134
|
-
const db = await this.#getWorldState(blockNumber);
|
|
1158
|
+
async getNullifierMembershipWitness(referenceBlock, nullifier) {
|
|
1159
|
+
const db = await this.#getWorldState(referenceBlock);
|
|
1135
1160
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [
|
|
1136
1161
|
nullifier.toBuffer()
|
|
1137
1162
|
]);
|
|
@@ -1147,7 +1172,8 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1147
1172
|
}
|
|
1148
1173
|
/**
|
|
1149
1174
|
* Returns a low nullifier membership witness for a given nullifier at a given block.
|
|
1150
|
-
* @param
|
|
1175
|
+
* @param referenceBlock - The block parameter (block number, block hash, or 'latest') at which to get the data
|
|
1176
|
+
* (which contains the root of the nullifier tree in which we are searching for the nullifier).
|
|
1151
1177
|
* @param nullifier - Nullifier we try to find the low nullifier witness for.
|
|
1152
1178
|
* @returns The low nullifier membership witness (if found).
|
|
1153
1179
|
* @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
|
|
@@ -1158,8 +1184,8 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1158
1184
|
* the nullifier already exists in the tree. This is because the `getPreviousValueIndex` function returns the
|
|
1159
1185
|
* index of the nullifier itself when it already exists in the tree.
|
|
1160
1186
|
* TODO: This is a confusing behavior and we should eventually address that.
|
|
1161
|
-
*/ async getLowNullifierMembershipWitness(
|
|
1162
|
-
const committedDb = await this.#getWorldState(
|
|
1187
|
+
*/ async getLowNullifierMembershipWitness(referenceBlock, nullifier) {
|
|
1188
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
1163
1189
|
const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
|
|
1164
1190
|
if (!findResult) {
|
|
1165
1191
|
return undefined;
|
|
@@ -1172,8 +1198,8 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1172
1198
|
const siblingPath = await committedDb.getSiblingPath(MerkleTreeId.NULLIFIER_TREE, BigInt(index));
|
|
1173
1199
|
return new NullifierMembershipWitness(BigInt(index), preimageData, siblingPath);
|
|
1174
1200
|
}
|
|
1175
|
-
async getPublicDataWitness(
|
|
1176
|
-
const committedDb = await this.#getWorldState(
|
|
1201
|
+
async getPublicDataWitness(referenceBlock, leafSlot) {
|
|
1202
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
1177
1203
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
1178
1204
|
if (!lowLeafResult) {
|
|
1179
1205
|
return undefined;
|
|
@@ -1183,18 +1209,8 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1183
1209
|
return new PublicDataWitness(lowLeafResult.index, preimage, path);
|
|
1184
1210
|
}
|
|
1185
1211
|
}
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
*
|
|
1189
|
-
* @remarks The storage slot here refers to the slot as it is defined in Noir not the index in the merkle tree.
|
|
1190
|
-
* Aztec's version of `eth_getStorageAt`.
|
|
1191
|
-
*
|
|
1192
|
-
* @param contract - Address of the contract to query.
|
|
1193
|
-
* @param slot - Slot to query.
|
|
1194
|
-
* @param blockNumber - The block number at which to get the data or 'latest'.
|
|
1195
|
-
* @returns Storage value at the given contract slot.
|
|
1196
|
-
*/ async getPublicStorageAt(blockNumber, contract, slot) {
|
|
1197
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
1212
|
+
async getPublicStorageAt(referenceBlock, contract, slot) {
|
|
1213
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
1198
1214
|
const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
|
|
1199
1215
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
1200
1216
|
if (!lowLeafResult || !lowLeafResult.alreadyPresent) {
|
|
@@ -1203,18 +1219,22 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1203
1219
|
const preimage = await committedDb.getLeafPreimage(MerkleTreeId.PUBLIC_DATA_TREE, lowLeafResult.index);
|
|
1204
1220
|
return preimage.leaf.value;
|
|
1205
1221
|
}
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1222
|
+
async getBlockHeader(block = 'latest') {
|
|
1223
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1224
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1225
|
+
if (block.equals(initialBlockHash)) {
|
|
1226
|
+
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1227
|
+
return this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
1228
|
+
}
|
|
1229
|
+
return this.blockSource.getBlockHeaderByHash(block);
|
|
1230
|
+
} else {
|
|
1231
|
+
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1232
|
+
const blockNumber = block === 'latest' ? await this.getBlockNumber() : block;
|
|
1233
|
+
if (blockNumber === BlockNumber.ZERO) {
|
|
1234
|
+
return this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
1235
|
+
}
|
|
1236
|
+
return this.blockSource.getBlockHeader(block);
|
|
1237
|
+
}
|
|
1218
1238
|
}
|
|
1219
1239
|
/**
|
|
1220
1240
|
* Get a block header specified by its archive root.
|
|
@@ -1223,6 +1243,12 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1223
1243
|
*/ async getBlockHeaderByArchive(archive) {
|
|
1224
1244
|
return await this.blockSource.getBlockHeaderByArchive(archive);
|
|
1225
1245
|
}
|
|
1246
|
+
getBlockData(number) {
|
|
1247
|
+
return this.blockSource.getBlockData(number);
|
|
1248
|
+
}
|
|
1249
|
+
getBlockDataByArchive(archive) {
|
|
1250
|
+
return this.blockSource.getBlockDataByArchive(archive);
|
|
1251
|
+
}
|
|
1226
1252
|
/**
|
|
1227
1253
|
* Simulates the public part of a transaction with the current state.
|
|
1228
1254
|
* @param tx - The transaction to simulate.
|
|
@@ -1235,17 +1261,20 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1235
1261
|
throw new BadRequestError(`Transaction total gas limit ${txGasLimit + teardownGasLimit} (${txGasLimit} + ${teardownGasLimit}) exceeds maximum gas limit ${this.config.rpcSimulatePublicMaxGasLimit} for simulation`);
|
|
1236
1262
|
}
|
|
1237
1263
|
const txHash = tx.getTxHash();
|
|
1238
|
-
const
|
|
1264
|
+
const latestBlockNumber = await this.blockSource.getBlockNumber();
|
|
1265
|
+
const blockNumber = BlockNumber.add(latestBlockNumber, 1);
|
|
1239
1266
|
// If sequencer is not initialized, we just set these values to zero for simulation.
|
|
1240
1267
|
const coinbase = EthAddress.ZERO;
|
|
1241
1268
|
const feeRecipient = AztecAddress.ZERO;
|
|
1242
1269
|
const newGlobalVariables = await this.globalVariableBuilder.buildGlobalVariables(blockNumber, coinbase, feeRecipient);
|
|
1243
|
-
const publicProcessorFactory = new PublicProcessorFactory(this.contractDataSource, new DateProvider(), this.telemetry);
|
|
1270
|
+
const publicProcessorFactory = new PublicProcessorFactory(this.contractDataSource, new DateProvider(), this.telemetry, this.log.getBindings());
|
|
1244
1271
|
this.log.verbose(`Simulating public calls for tx ${txHash}`, {
|
|
1245
1272
|
globalVariables: newGlobalVariables.toInspect(),
|
|
1246
1273
|
txHash,
|
|
1247
1274
|
blockNumber
|
|
1248
1275
|
});
|
|
1276
|
+
// Ensure world-state has caught up with the latest block we loaded from the archiver
|
|
1277
|
+
await this.worldStateSynchronizer.syncImmediate(latestBlockNumber);
|
|
1249
1278
|
const merkleTreeFork = await this.worldStateSynchronizer.fork();
|
|
1250
1279
|
try {
|
|
1251
1280
|
const config = PublicSimulatorConfig.from({
|
|
@@ -1260,7 +1289,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1260
1289
|
});
|
|
1261
1290
|
const processor = publicProcessorFactory.create(merkleTreeFork, newGlobalVariables, config);
|
|
1262
1291
|
// REFACTOR: Consider merging ProcessReturnValues into ProcessedTx
|
|
1263
|
-
const [processedTxs, failedTxs, _usedTxs, returns] = await processor.process([
|
|
1292
|
+
const [processedTxs, failedTxs, _usedTxs, returns, _blobFields, debugLogs] = await processor.process([
|
|
1264
1293
|
tx
|
|
1265
1294
|
]);
|
|
1266
1295
|
// REFACTOR: Consider returning the error rather than throwing
|
|
@@ -1271,7 +1300,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1271
1300
|
throw failedTxs[0].error;
|
|
1272
1301
|
}
|
|
1273
1302
|
const [processedTx] = processedTxs;
|
|
1274
|
-
return new PublicSimulationOutput(processedTx.revertReason, processedTx.globalVariables, processedTx.txEffect, returns, processedTx.gasUsed);
|
|
1303
|
+
return new PublicSimulationOutput(processedTx.revertReason, processedTx.globalVariables, processedTx.txEffect, returns, processedTx.gasUsed, debugLogs);
|
|
1275
1304
|
} finally{
|
|
1276
1305
|
await merkleTreeFork.close();
|
|
1277
1306
|
}
|
|
@@ -1279,7 +1308,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1279
1308
|
async isValidTx(tx, { isSimulation, skipFeeEnforcement } = {}) {
|
|
1280
1309
|
const db = this.worldStateSynchronizer.getCommitted();
|
|
1281
1310
|
const verifier = isSimulation ? undefined : this.proofVerifier;
|
|
1282
|
-
// We accept transactions if they are not expired by the next slot (checked based on the
|
|
1311
|
+
// We accept transactions if they are not expired by the next slot (checked based on the ExpirationTimestamp field)
|
|
1283
1312
|
const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
1284
1313
|
const blockNumber = BlockNumber(await this.blockSource.getBlockNumber() + 1);
|
|
1285
1314
|
const validator = createValidatorForAcceptingTxs(db, this.contractDataSource, verifier, {
|
|
@@ -1291,7 +1320,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1291
1320
|
gasFees: await this.getCurrentMinFees(),
|
|
1292
1321
|
skipFeeEnforcement,
|
|
1293
1322
|
txsPermitted: !this.config.disableTransactions
|
|
1294
|
-
});
|
|
1323
|
+
}, this.log.getBindings());
|
|
1295
1324
|
return await validator.validateTx(tx);
|
|
1296
1325
|
}
|
|
1297
1326
|
getConfig() {
|
|
@@ -1433,14 +1462,84 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1433
1462
|
return this.slasherClient.gatherOffensesForRound(round === 'current' ? undefined : BigInt(round));
|
|
1434
1463
|
}
|
|
1435
1464
|
}
|
|
1465
|
+
async reloadKeystore() {
|
|
1466
|
+
if (!this.config.keyStoreDirectory?.length) {
|
|
1467
|
+
throw new BadRequestError('Cannot reload keystore: node is not using a file-based keystore. ' + 'Set KEY_STORE_DIRECTORY to use file-based keystores.');
|
|
1468
|
+
}
|
|
1469
|
+
if (!this.validatorClient) {
|
|
1470
|
+
throw new BadRequestError('Cannot reload keystore: validator is not enabled.');
|
|
1471
|
+
}
|
|
1472
|
+
this.log.info('Reloading keystore from disk');
|
|
1473
|
+
// Re-read and validate keystore files
|
|
1474
|
+
const keyStores = loadKeystores(this.config.keyStoreDirectory);
|
|
1475
|
+
const newManager = new KeystoreManager(mergeKeystores(keyStores));
|
|
1476
|
+
await newManager.validateSigners();
|
|
1477
|
+
ValidatorClient.validateKeyStoreConfiguration(newManager, this.log);
|
|
1478
|
+
// Validate that every validator's publisher keys overlap with the L1 signers
|
|
1479
|
+
// that were initialized at startup. Publishers cannot be hot-reloaded, so a
|
|
1480
|
+
// validator with a publisher key that doesn't match any existing L1 signer
|
|
1481
|
+
// would silently fail on every proposer slot.
|
|
1482
|
+
if (this.keyStoreManager && this.sequencer) {
|
|
1483
|
+
const oldAdapter = NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager);
|
|
1484
|
+
const availablePublishers = new Set(oldAdapter.getAttesterAddresses().flatMap((a)=>oldAdapter.getPublisherAddresses(a).map((p)=>p.toString().toLowerCase())));
|
|
1485
|
+
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
1486
|
+
for (const attester of newAdapter.getAttesterAddresses()){
|
|
1487
|
+
const pubs = newAdapter.getPublisherAddresses(attester);
|
|
1488
|
+
if (pubs.length > 0 && !pubs.some((p)=>availablePublishers.has(p.toString().toLowerCase()))) {
|
|
1489
|
+
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 ` + `[${[
|
|
1490
|
+
...availablePublishers
|
|
1491
|
+
].join(', ')}]. Publishers cannot be hot-reloaded — ` + `use an existing publisher key or restart the node.`);
|
|
1492
|
+
}
|
|
1493
|
+
}
|
|
1494
|
+
}
|
|
1495
|
+
// Build adapters for old and new keystores to compute diff
|
|
1496
|
+
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
1497
|
+
const newAddresses = newAdapter.getAttesterAddresses();
|
|
1498
|
+
const oldAddresses = this.keyStoreManager ? NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager).getAttesterAddresses() : [];
|
|
1499
|
+
const oldSet = new Set(oldAddresses.map((a)=>a.toString()));
|
|
1500
|
+
const newSet = new Set(newAddresses.map((a)=>a.toString()));
|
|
1501
|
+
const added = newAddresses.filter((a)=>!oldSet.has(a.toString()));
|
|
1502
|
+
const removed = oldAddresses.filter((a)=>!newSet.has(a.toString()));
|
|
1503
|
+
if (added.length > 0) {
|
|
1504
|
+
this.log.info(`Keystore reload: adding attester keys: ${added.map((a)=>a.toString()).join(', ')}`);
|
|
1505
|
+
}
|
|
1506
|
+
if (removed.length > 0) {
|
|
1507
|
+
this.log.info(`Keystore reload: removing attester keys: ${removed.map((a)=>a.toString()).join(', ')}`);
|
|
1508
|
+
}
|
|
1509
|
+
if (added.length === 0 && removed.length === 0) {
|
|
1510
|
+
this.log.info('Keystore reload: attester keys unchanged');
|
|
1511
|
+
}
|
|
1512
|
+
// Update the validator client (coinbase, feeRecipient, attester keys)
|
|
1513
|
+
this.validatorClient.reloadKeystore(newManager);
|
|
1514
|
+
// Update the publisher factory's keystore so newly-added validators
|
|
1515
|
+
// can be matched to existing publisher keys when proposing blocks.
|
|
1516
|
+
if (this.sequencer) {
|
|
1517
|
+
this.sequencer.updatePublisherNodeKeyStore(newAdapter);
|
|
1518
|
+
}
|
|
1519
|
+
// Update slasher's "don't-slash-self" list with new validator addresses
|
|
1520
|
+
if (this.slasherClient && !this.config.slashSelfAllowed) {
|
|
1521
|
+
const slashValidatorsNever = unique([
|
|
1522
|
+
...this.config.slashValidatorsNever ?? [],
|
|
1523
|
+
...newAddresses
|
|
1524
|
+
].map((a)=>a.toString())).map(EthAddress.fromString);
|
|
1525
|
+
this.slasherClient.updateConfig({
|
|
1526
|
+
slashValidatorsNever
|
|
1527
|
+
});
|
|
1528
|
+
}
|
|
1529
|
+
this.keyStoreManager = newManager;
|
|
1530
|
+
this.log.info('Keystore reloaded: coinbase, feeRecipient, and attester keys updated');
|
|
1531
|
+
}
|
|
1532
|
+
#getInitialHeaderHash() {
|
|
1533
|
+
if (!this.initialHeaderHashPromise) {
|
|
1534
|
+
this.initialHeaderHashPromise = this.worldStateSynchronizer.getCommitted().getInitialHeader().hash();
|
|
1535
|
+
}
|
|
1536
|
+
return this.initialHeaderHashPromise;
|
|
1537
|
+
}
|
|
1436
1538
|
/**
|
|
1437
1539
|
* Returns an instance of MerkleTreeOperations having first ensured the world state is fully synched
|
|
1438
|
-
* @param
|
|
1540
|
+
* @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
|
|
1439
1541
|
* @returns An instance of a committed MerkleTreeOperations
|
|
1440
|
-
*/ async #getWorldState(
|
|
1441
|
-
if (typeof blockNumber === 'number' && blockNumber < INITIAL_L2_BLOCK_NUM - 1) {
|
|
1442
|
-
throw new Error('Invalid block number to get world state for: ' + blockNumber);
|
|
1443
|
-
}
|
|
1542
|
+
*/ async #getWorldState(block) {
|
|
1444
1543
|
let blockSyncedTo = BlockNumber.ZERO;
|
|
1445
1544
|
try {
|
|
1446
1545
|
// Attempt to sync the world state if necessary
|
|
@@ -1448,15 +1547,32 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1448
1547
|
} catch (err) {
|
|
1449
1548
|
this.log.error(`Error getting world state: ${err}`);
|
|
1450
1549
|
}
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
this.log.debug(`Using committed db for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1550
|
+
if (block === 'latest') {
|
|
1551
|
+
this.log.debug(`Using committed db for block 'latest', world state synced upto ${blockSyncedTo}`);
|
|
1454
1552
|
return this.worldStateSynchronizer.getCommitted();
|
|
1455
|
-
}
|
|
1553
|
+
}
|
|
1554
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1555
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1556
|
+
if (block.equals(initialBlockHash)) {
|
|
1557
|
+
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1558
|
+
return this.worldStateSynchronizer.getSnapshot(BlockNumber.ZERO);
|
|
1559
|
+
}
|
|
1560
|
+
const header = await this.blockSource.getBlockHeaderByHash(block);
|
|
1561
|
+
if (!header) {
|
|
1562
|
+
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.`);
|
|
1563
|
+
}
|
|
1564
|
+
const blockNumber = header.getBlockNumber();
|
|
1565
|
+
this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1566
|
+
return this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1567
|
+
}
|
|
1568
|
+
// Block number provided
|
|
1569
|
+
{
|
|
1570
|
+
const blockNumber = block;
|
|
1571
|
+
if (blockNumber > blockSyncedTo) {
|
|
1572
|
+
throw new Error(`Queried block ${block} not yet synced by the node (node is synced upto ${blockSyncedTo}).`);
|
|
1573
|
+
}
|
|
1456
1574
|
this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1457
1575
|
return this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1458
|
-
} else {
|
|
1459
|
-
throw new Error(`Block ${blockNumber} not yet synced`);
|
|
1460
1576
|
}
|
|
1461
1577
|
}
|
|
1462
1578
|
/**
|