@aztec/aztec-node 4.0.0-devnet.2-patch.4 → 4.0.0-devnet.3-patch.1
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/server.d.ts +18 -21
- package/dest/aztec-node/server.d.ts.map +1 -1
- package/dest/aztec-node/server.js +220 -152
- package/dest/sentinel/sentinel.js +3 -3
- package/package.json +27 -27
- package/src/aztec-node/server.ts +253 -156
- package/src/sentinel/sentinel.ts +3 -3
|
@@ -377,10 +377,10 @@ import { createBlobClientWithFileStores } from '@aztec/blob-client/client';
|
|
|
377
377
|
import { Blob } from '@aztec/blob-lib';
|
|
378
378
|
import { EpochCache } from '@aztec/epoch-cache';
|
|
379
379
|
import { createEthereumChain } from '@aztec/ethereum/chain';
|
|
380
|
-
import { getPublicClient } from '@aztec/ethereum/client';
|
|
380
|
+
import { getPublicClient, makeL1HttpTransport } from '@aztec/ethereum/client';
|
|
381
381
|
import { RegistryContract, RollupContract } from '@aztec/ethereum/contracts';
|
|
382
|
-
import { BlockNumber
|
|
383
|
-
import { compactArray, pick, unique } from '@aztec/foundation/collection';
|
|
382
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
383
|
+
import { chunkBy, 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';
|
|
@@ -391,7 +391,7 @@ 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
393
|
import { createForwarderL1TxUtilsFromSigners, createL1TxUtilsFromSigners } from '@aztec/node-lib/factories';
|
|
394
|
-
import { createP2PClient, getDefaultAllowedSetupFunctions } from '@aztec/p2p';
|
|
394
|
+
import { createP2PClient, createTxValidatorForAcceptingTxsOverRPC, getDefaultAllowedSetupFunctions } from '@aztec/p2p';
|
|
395
395
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
396
396
|
import { createProverNode } from '@aztec/prover-node';
|
|
397
397
|
import { createKeyStoreForProver } from '@aztec/prover-node/config';
|
|
@@ -405,15 +405,15 @@ import { GasFees } from '@aztec/stdlib/gas';
|
|
|
405
405
|
import { computePublicDataTreeLeafSlot } from '@aztec/stdlib/hash';
|
|
406
406
|
import { AztecNodeAdminConfigSchema } from '@aztec/stdlib/interfaces/client';
|
|
407
407
|
import { tryStop } from '@aztec/stdlib/interfaces/server';
|
|
408
|
+
import { InMemoryDebugLogStore, NullDebugLogStore } from '@aztec/stdlib/logs';
|
|
408
409
|
import { InboxLeaf } from '@aztec/stdlib/messaging';
|
|
409
|
-
import { P2PClientType } from '@aztec/stdlib/p2p';
|
|
410
410
|
import { MerkleTreeId, NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
|
|
411
411
|
import { PublicSimulationOutput, TxReceipt, TxStatus } from '@aztec/stdlib/tx';
|
|
412
412
|
import { getPackageVersion } from '@aztec/stdlib/update-checker';
|
|
413
413
|
import { Attributes, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
|
|
414
|
-
import { FullNodeCheckpointsBuilder as CheckpointsBuilder, FullNodeCheckpointsBuilder, NodeKeystoreAdapter, ValidatorClient,
|
|
414
|
+
import { FullNodeCheckpointsBuilder as CheckpointsBuilder, FullNodeCheckpointsBuilder, NodeKeystoreAdapter, ValidatorClient, createProposalHandler, createValidatorClient } from '@aztec/validator-client';
|
|
415
415
|
import { createWorldStateSynchronizer } from '@aztec/world-state';
|
|
416
|
-
import { createPublicClient
|
|
416
|
+
import { createPublicClient } from 'viem';
|
|
417
417
|
import { createSentinel } from '../sentinel/factory.js';
|
|
418
418
|
import { createKeyStoreForValidator } from './config.js';
|
|
419
419
|
import { NodeMetrics } from './node_metrics.js';
|
|
@@ -446,6 +446,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
446
446
|
blobClient;
|
|
447
447
|
validatorClient;
|
|
448
448
|
keyStoreManager;
|
|
449
|
+
debugLogStore;
|
|
449
450
|
static{
|
|
450
451
|
({ e: [_initProto] } = _apply_decs_2203_r(this, [
|
|
451
452
|
[
|
|
@@ -460,7 +461,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
460
461
|
// Prevent two snapshot operations to happen simultaneously
|
|
461
462
|
isUploadingSnapshot;
|
|
462
463
|
tracer;
|
|
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){
|
|
464
|
+
constructor(config, p2pClient, blockSource, logsSource, contractDataSource, l1ToL2MessageSource, worldStateSynchronizer, sequencer, proverNode, slasherClient, validatorsSentinel, epochPruneWatcher, l1ChainId, version, globalVariableBuilder, epochCache, packageVersion, proofVerifier, telemetry = getTelemetryClient(), log = createLogger('node'), blobClient, validatorClient, keyStoreManager, debugLogStore = new NullDebugLogStore()){
|
|
464
465
|
this.config = config;
|
|
465
466
|
this.p2pClient = p2pClient;
|
|
466
467
|
this.blockSource = blockSource;
|
|
@@ -484,12 +485,19 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
484
485
|
this.blobClient = blobClient;
|
|
485
486
|
this.validatorClient = validatorClient;
|
|
486
487
|
this.keyStoreManager = keyStoreManager;
|
|
488
|
+
this.debugLogStore = debugLogStore;
|
|
487
489
|
this.initialHeaderHashPromise = (_initProto(this), undefined);
|
|
488
490
|
this.isUploadingSnapshot = false;
|
|
489
491
|
this.metrics = new NodeMetrics(telemetry, 'AztecNodeService');
|
|
490
492
|
this.tracer = telemetry.getTracer('AztecNodeService');
|
|
491
493
|
this.log.info(`Aztec Node version: ${this.packageVersion}`);
|
|
492
494
|
this.log.info(`Aztec Node started on chain 0x${l1ChainId.toString(16)}`, config.l1Contracts);
|
|
495
|
+
// A defensive check that protects us against introducing a bug in the complex `createAndSync` function. We must
|
|
496
|
+
// never have debugLogStore enabled when not in test mode because then we would be accumulating debug logs in
|
|
497
|
+
// memory which could be a DoS vector on the sequencer (since no fees are paid for debug logs).
|
|
498
|
+
if (debugLogStore.isEnabled && config.realProofs) {
|
|
499
|
+
throw new Error('debugLogStore should never be enabled when realProofs are set');
|
|
500
|
+
}
|
|
493
501
|
}
|
|
494
502
|
async getWorldStateSyncStatus() {
|
|
495
503
|
const status = await this.worldStateSynchronizer.status();
|
|
@@ -551,9 +559,9 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
551
559
|
}
|
|
552
560
|
const publicClient = createPublicClient({
|
|
553
561
|
chain: ethereumChain.chainInfo,
|
|
554
|
-
transport:
|
|
555
|
-
|
|
556
|
-
|
|
562
|
+
transport: makeL1HttpTransport(config.l1RpcUrls, {
|
|
563
|
+
timeout: config.l1HttpTimeoutMS
|
|
564
|
+
}),
|
|
557
565
|
pollingInterval: config.viemPollingIntervalMS
|
|
558
566
|
});
|
|
559
567
|
const l1ContractsAddresses = await RegistryContract.collectAddresses(publicClient, config.l1Contracts.registryAddress, config.rollupVersion ?? 'canonical');
|
|
@@ -563,10 +571,11 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
563
571
|
...l1ContractsAddresses
|
|
564
572
|
};
|
|
565
573
|
const rollupContract = new RollupContract(publicClient, config.l1Contracts.rollupAddress.toString());
|
|
566
|
-
const [l1GenesisTime, slotDuration, rollupVersionFromRollup] = await Promise.all([
|
|
574
|
+
const [l1GenesisTime, slotDuration, rollupVersionFromRollup, rollupManaLimit] = await Promise.all([
|
|
567
575
|
rollupContract.getL1GenesisTime(),
|
|
568
576
|
rollupContract.getSlotDuration(),
|
|
569
|
-
rollupContract.getVersion()
|
|
577
|
+
rollupContract.getVersion(),
|
|
578
|
+
rollupContract.getManaLimit().then(Number)
|
|
570
579
|
]);
|
|
571
580
|
config.rollupVersion ??= Number(rollupVersionFromRollup);
|
|
572
581
|
if (config.rollupVersion !== Number(rollupVersionFromRollup)) {
|
|
@@ -589,77 +598,98 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
589
598
|
// now create the merkle trees and the world state synchronizer
|
|
590
599
|
const worldStateSynchronizer = await createWorldStateSynchronizer(config, archiver, options.prefilledPublicData, telemetry);
|
|
591
600
|
const circuitVerifier = config.realProofs || config.debugForceTxProofVerification ? await BBCircuitVerifier.new(config) : new TestCircuitVerifier(config.proverTestVerificationDelayMs);
|
|
601
|
+
let debugLogStore;
|
|
592
602
|
if (!config.realProofs) {
|
|
593
603
|
log.warn(`Aztec node is accepting fake proofs`);
|
|
604
|
+
debugLogStore = new InMemoryDebugLogStore();
|
|
605
|
+
log.info('Aztec node started in test mode (realProofs set to false) hence debug logs from public functions will be collected and served');
|
|
606
|
+
} else {
|
|
607
|
+
debugLogStore = new NullDebugLogStore();
|
|
594
608
|
}
|
|
595
609
|
const proofVerifier = new QueuedIVCVerifier(config, circuitVerifier);
|
|
610
|
+
const proverOnly = config.enableProverNode && config.disableValidator;
|
|
611
|
+
if (proverOnly) {
|
|
612
|
+
log.info('Starting in prover-only mode: skipping validator, sequencer, sentinel, and slasher subsystems');
|
|
613
|
+
}
|
|
596
614
|
// create the tx pool and the p2p client, which will need the l2 block source
|
|
597
|
-
const p2pClient = await createP2PClient(
|
|
598
|
-
// We
|
|
599
|
-
|
|
600
|
-
// Create FullNodeCheckpointsBuilder for
|
|
615
|
+
const p2pClient = await createP2PClient(config, archiver, proofVerifier, worldStateSynchronizer, epochCache, packageVersion, dateProvider, telemetry, deps.p2pClientDeps);
|
|
616
|
+
// We'll accumulate sentinel watchers here
|
|
617
|
+
const watchers = [];
|
|
618
|
+
// Create FullNodeCheckpointsBuilder for block proposal handling and tx validation.
|
|
619
|
+
// Override maxTxsPerCheckpoint with the validator-specific limit if set.
|
|
601
620
|
const validatorCheckpointsBuilder = new FullNodeCheckpointsBuilder({
|
|
602
621
|
...config,
|
|
603
622
|
l1GenesisTime,
|
|
604
|
-
slotDuration: Number(slotDuration)
|
|
623
|
+
slotDuration: Number(slotDuration),
|
|
624
|
+
rollupManaLimit,
|
|
625
|
+
maxTxsPerCheckpoint: config.validateMaxTxsPerCheckpoint
|
|
605
626
|
}, worldStateSynchronizer, archiver, dateProvider, telemetry);
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
627
|
+
let validatorClient;
|
|
628
|
+
if (!proverOnly) {
|
|
629
|
+
// Create validator client if required
|
|
630
|
+
validatorClient = await createValidatorClient(config, {
|
|
631
|
+
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
632
|
+
worldState: worldStateSynchronizer,
|
|
633
|
+
p2pClient,
|
|
634
|
+
telemetry,
|
|
635
|
+
dateProvider,
|
|
636
|
+
epochCache,
|
|
637
|
+
blockSource: archiver,
|
|
638
|
+
l1ToL2MessageSource: archiver,
|
|
639
|
+
keyStoreManager,
|
|
640
|
+
blobClient,
|
|
641
|
+
slashingProtectionDb: deps.slashingProtectionDb
|
|
642
|
+
});
|
|
643
|
+
// If we have a validator client, register it as a source of offenses for the slasher,
|
|
644
|
+
// and have it register callbacks on the p2p client *before* we start it, otherwise messages
|
|
645
|
+
// like attestations or auths will fail.
|
|
646
|
+
if (validatorClient) {
|
|
647
|
+
watchers.push(validatorClient);
|
|
648
|
+
if (!options.dontStartSequencer) {
|
|
649
|
+
await validatorClient.registerHandlers();
|
|
650
|
+
}
|
|
628
651
|
}
|
|
629
652
|
}
|
|
630
|
-
// If there's no validator client
|
|
631
|
-
//
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
653
|
+
// If there's no validator client, create a ProposalHandler to handle block and checkpoint proposals
|
|
654
|
+
// for monitoring or reexecution. Reexecution (default) allows us to follow the pending chain,
|
|
655
|
+
// while non-reexecution is used for validating the proposals and collecting their txs.
|
|
656
|
+
// Checkpoint proposals are handled if the blob client can upload blobs.
|
|
657
|
+
if (!validatorClient) {
|
|
658
|
+
const reexecute = !!config.alwaysReexecuteBlockProposals;
|
|
659
|
+
log.info(`Setting up proposal handler` + (reexecute ? ' with reexecution of proposals' : ''));
|
|
660
|
+
createProposalHandler(config, {
|
|
635
661
|
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
636
662
|
worldState: worldStateSynchronizer,
|
|
637
663
|
epochCache,
|
|
638
664
|
blockSource: archiver,
|
|
639
665
|
l1ToL2MessageSource: archiver,
|
|
640
666
|
p2pClient,
|
|
667
|
+
blobClient,
|
|
641
668
|
dateProvider,
|
|
642
669
|
telemetry
|
|
643
|
-
}).
|
|
670
|
+
}).register(p2pClient, reexecute);
|
|
644
671
|
}
|
|
645
672
|
// Start world state and wait for it to sync to the archiver.
|
|
646
673
|
await worldStateSynchronizer.start();
|
|
647
674
|
// Start p2p. Note that it depends on world state to be running.
|
|
648
675
|
await p2pClient.start();
|
|
649
|
-
|
|
650
|
-
if (validatorsSentinel && config.slashInactivityPenalty > 0n) {
|
|
651
|
-
watchers.push(validatorsSentinel);
|
|
652
|
-
}
|
|
676
|
+
let validatorsSentinel;
|
|
653
677
|
let epochPruneWatcher;
|
|
654
|
-
if (config.slashPrunePenalty > 0n || config.slashDataWithholdingPenalty > 0n) {
|
|
655
|
-
epochPruneWatcher = new EpochPruneWatcher(archiver, archiver, epochCache, p2pClient.getTxProvider(), validatorCheckpointsBuilder, config);
|
|
656
|
-
watchers.push(epochPruneWatcher);
|
|
657
|
-
}
|
|
658
|
-
// We assume we want to slash for invalid attestations unless all max penalties are set to 0
|
|
659
678
|
let attestationsBlockWatcher;
|
|
660
|
-
if (
|
|
661
|
-
|
|
662
|
-
|
|
679
|
+
if (!proverOnly) {
|
|
680
|
+
validatorsSentinel = await createSentinel(epochCache, archiver, p2pClient, config);
|
|
681
|
+
if (validatorsSentinel && config.slashInactivityPenalty > 0n) {
|
|
682
|
+
watchers.push(validatorsSentinel);
|
|
683
|
+
}
|
|
684
|
+
if (config.slashPrunePenalty > 0n || config.slashDataWithholdingPenalty > 0n) {
|
|
685
|
+
epochPruneWatcher = new EpochPruneWatcher(archiver, archiver, epochCache, p2pClient.getTxProvider(), validatorCheckpointsBuilder, config);
|
|
686
|
+
watchers.push(epochPruneWatcher);
|
|
687
|
+
}
|
|
688
|
+
// We assume we want to slash for invalid attestations unless all max penalties are set to 0
|
|
689
|
+
if (config.slashProposeInvalidAttestationsPenalty > 0n || config.slashAttestDescendantOfInvalidPenalty > 0n) {
|
|
690
|
+
attestationsBlockWatcher = new AttestationsBlockWatcher(archiver, epochCache, config);
|
|
691
|
+
watchers.push(attestationsBlockWatcher);
|
|
692
|
+
}
|
|
663
693
|
}
|
|
664
694
|
// Start p2p-related services once the archiver has completed sync
|
|
665
695
|
void archiver.waitForInitialSync().then(async ()=>{
|
|
@@ -669,6 +699,13 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
669
699
|
await attestationsBlockWatcher?.start();
|
|
670
700
|
log.info(`All p2p services started`);
|
|
671
701
|
}).catch((err)=>log.error('Failed to start p2p services after archiver sync', err));
|
|
702
|
+
const globalVariableBuilder = new GlobalVariableBuilder(dateProvider, publicClient, {
|
|
703
|
+
l1Contracts: config.l1Contracts,
|
|
704
|
+
ethereumSlotDuration: config.ethereumSlotDuration,
|
|
705
|
+
rollupVersion: BigInt(config.rollupVersion),
|
|
706
|
+
l1GenesisTime,
|
|
707
|
+
slotDuration: Number(slotDuration)
|
|
708
|
+
});
|
|
672
709
|
// Validator enabled, create/start relevant service
|
|
673
710
|
let sequencer;
|
|
674
711
|
let slasherClient;
|
|
@@ -699,8 +736,9 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
699
736
|
const checkpointsBuilder = new CheckpointsBuilder({
|
|
700
737
|
...config,
|
|
701
738
|
l1GenesisTime,
|
|
702
|
-
slotDuration: Number(slotDuration)
|
|
703
|
-
|
|
739
|
+
slotDuration: Number(slotDuration),
|
|
740
|
+
rollupManaLimit
|
|
741
|
+
}, worldStateSynchronizer, archiver, dateProvider, telemetry, debugLogStore);
|
|
704
742
|
sequencer = await SequencerClient.new(config, {
|
|
705
743
|
...deps,
|
|
706
744
|
epochCache,
|
|
@@ -715,7 +753,8 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
715
753
|
telemetry,
|
|
716
754
|
dateProvider,
|
|
717
755
|
blobClient,
|
|
718
|
-
nodeKeyStore: keyStoreManager
|
|
756
|
+
nodeKeyStore: keyStoreManager,
|
|
757
|
+
globalVariableBuilder
|
|
719
758
|
});
|
|
720
759
|
}
|
|
721
760
|
if (!options.dontStartSequencer && sequencer) {
|
|
@@ -745,13 +784,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
745
784
|
log.info(`Prover node subsystem created but not started`);
|
|
746
785
|
}
|
|
747
786
|
}
|
|
748
|
-
const
|
|
749
|
-
...config,
|
|
750
|
-
rollupVersion: BigInt(config.rollupVersion),
|
|
751
|
-
l1GenesisTime,
|
|
752
|
-
slotDuration: Number(slotDuration)
|
|
753
|
-
});
|
|
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);
|
|
787
|
+
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);
|
|
755
788
|
return node;
|
|
756
789
|
}
|
|
757
790
|
/**
|
|
@@ -782,7 +815,10 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
782
815
|
return Promise.resolve(this.p2pClient.getEnr()?.encodeTxt());
|
|
783
816
|
}
|
|
784
817
|
async getAllowedPublicSetup() {
|
|
785
|
-
return
|
|
818
|
+
return [
|
|
819
|
+
...await getDefaultAllowedSetupFunctions(),
|
|
820
|
+
...this.config.txPublicSetupAllowListExtend ?? []
|
|
821
|
+
];
|
|
786
822
|
}
|
|
787
823
|
/**
|
|
788
824
|
* Method to determine if the node is ready to accept transactions.
|
|
@@ -860,6 +896,9 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
860
896
|
async getCheckpointedBlocks(from, limit) {
|
|
861
897
|
return await this.blockSource.getCheckpointedBlocks(from, limit) ?? [];
|
|
862
898
|
}
|
|
899
|
+
getCheckpointsDataForEpoch(epochNumber) {
|
|
900
|
+
return this.blockSource.getCheckpointsDataForEpoch(epochNumber);
|
|
901
|
+
}
|
|
863
902
|
/**
|
|
864
903
|
* Method to fetch the current min L2 fees.
|
|
865
904
|
* @returns The current min L2 fees.
|
|
@@ -887,6 +926,9 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
887
926
|
async getCheckpointedBlockNumber() {
|
|
888
927
|
return await this.blockSource.getCheckpointedL2BlockNumber();
|
|
889
928
|
}
|
|
929
|
+
getCheckpointNumber() {
|
|
930
|
+
return this.blockSource.getCheckpointNumber();
|
|
931
|
+
}
|
|
890
932
|
/**
|
|
891
933
|
* Method to fetch the version of the package.
|
|
892
934
|
* @returns The node package version
|
|
@@ -968,8 +1010,9 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
968
1010
|
throw new Error(`Invalid tx: ${reason}`);
|
|
969
1011
|
}
|
|
970
1012
|
await this.p2pClient.sendTx(tx);
|
|
971
|
-
|
|
972
|
-
this.
|
|
1013
|
+
const duration = timer.ms();
|
|
1014
|
+
this.metrics.receivedTx(duration, true);
|
|
1015
|
+
this.log.info(`Received tx ${txHash} in ${duration}ms`, {
|
|
973
1016
|
txHash
|
|
974
1017
|
});
|
|
975
1018
|
}
|
|
@@ -980,18 +1023,20 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
980
1023
|
const isKnownToPool = txPoolStatus === 'pending' || txPoolStatus === 'mined';
|
|
981
1024
|
// Then get the actual tx from the archiver, which tracks every tx in a mined block.
|
|
982
1025
|
const settledTxReceipt = await this.blockSource.getSettledTxReceipt(txHash);
|
|
1026
|
+
let receipt;
|
|
983
1027
|
if (settledTxReceipt) {
|
|
984
|
-
|
|
985
|
-
return settledTxReceipt;
|
|
1028
|
+
receipt = settledTxReceipt;
|
|
986
1029
|
} else if (isKnownToPool) {
|
|
987
1030
|
// If the tx is in the pool but not in the archiver, it's pending.
|
|
988
1031
|
// This handles race conditions between archiver and p2p, where the archiver
|
|
989
1032
|
// has pruned the block in which a tx was mined, but p2p has not caught up yet.
|
|
990
|
-
|
|
1033
|
+
receipt = new TxReceipt(txHash, TxStatus.PENDING, undefined, undefined);
|
|
991
1034
|
} else {
|
|
992
1035
|
// Otherwise, if we don't know the tx, we consider it dropped.
|
|
993
|
-
|
|
1036
|
+
receipt = new TxReceipt(txHash, TxStatus.DROPPED, undefined, 'Tx dropped by P2P node');
|
|
994
1037
|
}
|
|
1038
|
+
this.debugLogStore.decorateReceiptWithLogs(txHash.toString(), receipt);
|
|
1039
|
+
return receipt;
|
|
995
1040
|
}
|
|
996
1041
|
getTxEffect(txHash) {
|
|
997
1042
|
return this.blockSource.getTxEffect(txHash);
|
|
@@ -1045,70 +1090,88 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1045
1090
|
return compactArray(await Promise.all(txHashes.map((txHash)=>this.getTxByHash(txHash))));
|
|
1046
1091
|
}
|
|
1047
1092
|
async findLeavesIndexes(referenceBlock, treeId, leafValues) {
|
|
1048
|
-
const committedDb = await this
|
|
1093
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1049
1094
|
const maybeIndices = await committedDb.findLeafIndices(treeId, leafValues.map((x)=>x.toBuffer()));
|
|
1050
|
-
//
|
|
1051
|
-
const
|
|
1052
|
-
// Now we find the block numbers for the indices
|
|
1053
|
-
const blockNumbers = await committedDb.getBlockNumbersForLeafIndices(treeId,
|
|
1054
|
-
//
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1095
|
+
// Filter out undefined values to query block numbers only for found leaves
|
|
1096
|
+
const definedIndices = maybeIndices.filter((x)=>x !== undefined);
|
|
1097
|
+
// Now we find the block numbers for the defined indices
|
|
1098
|
+
const blockNumbers = await committedDb.getBlockNumbersForLeafIndices(treeId, definedIndices);
|
|
1099
|
+
// Build a map from leaf index to block number
|
|
1100
|
+
const indexToBlockNumber = new Map();
|
|
1101
|
+
for(let i = 0; i < definedIndices.length; i++){
|
|
1102
|
+
const blockNumber = blockNumbers[i];
|
|
1103
|
+
if (blockNumber === undefined) {
|
|
1104
|
+
throw new Error(`Block number is undefined for leaf index ${definedIndices[i]} in tree ${MerkleTreeId[treeId]}`);
|
|
1058
1105
|
}
|
|
1106
|
+
indexToBlockNumber.set(definedIndices[i], blockNumber);
|
|
1059
1107
|
}
|
|
1060
1108
|
// Get unique block numbers in order to optimize num calls to getLeafValue function.
|
|
1061
1109
|
const uniqueBlockNumbers = [
|
|
1062
|
-
...new Set(
|
|
1110
|
+
...new Set(indexToBlockNumber.values())
|
|
1063
1111
|
];
|
|
1064
|
-
// Now we obtain the block hashes from the archive tree
|
|
1065
|
-
// (note that block number corresponds to the leaf index in the archive tree).
|
|
1112
|
+
// Now we obtain the block hashes from the archive tree (block number = leaf index in archive tree).
|
|
1066
1113
|
const blockHashes = await Promise.all(uniqueBlockNumbers.map((blockNumber)=>{
|
|
1067
1114
|
return committedDb.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
|
|
1068
1115
|
}));
|
|
1069
|
-
//
|
|
1116
|
+
// Build a map from block number to block hash
|
|
1117
|
+
const blockNumberToHash = new Map();
|
|
1070
1118
|
for(let i = 0; i < uniqueBlockNumbers.length; i++){
|
|
1071
|
-
|
|
1119
|
+
const blockHash = blockHashes[i];
|
|
1120
|
+
if (blockHash === undefined) {
|
|
1072
1121
|
throw new Error(`Block hash is undefined for block number ${uniqueBlockNumbers[i]}`);
|
|
1073
1122
|
}
|
|
1123
|
+
blockNumberToHash.set(uniqueBlockNumbers[i], blockHash);
|
|
1074
1124
|
}
|
|
1075
1125
|
// Create DataInBlock objects by combining indices, blockNumbers and blockHashes and return them.
|
|
1076
|
-
return maybeIndices.map((index
|
|
1126
|
+
return maybeIndices.map((index)=>{
|
|
1077
1127
|
if (index === undefined) {
|
|
1078
1128
|
return undefined;
|
|
1079
1129
|
}
|
|
1080
|
-
const blockNumber =
|
|
1130
|
+
const blockNumber = indexToBlockNumber.get(index);
|
|
1081
1131
|
if (blockNumber === undefined) {
|
|
1082
|
-
|
|
1132
|
+
throw new Error(`Block number not found for leaf index ${index} in tree ${MerkleTreeId[treeId]}`);
|
|
1083
1133
|
}
|
|
1084
|
-
const
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
return undefined;
|
|
1134
|
+
const blockHash = blockNumberToHash.get(blockNumber);
|
|
1135
|
+
if (blockHash === undefined) {
|
|
1136
|
+
throw new Error(`Block hash not found for block number ${blockNumber}`);
|
|
1088
1137
|
}
|
|
1089
1138
|
return {
|
|
1090
|
-
l2BlockNumber:
|
|
1139
|
+
l2BlockNumber: blockNumber,
|
|
1091
1140
|
l2BlockHash: new BlockHash(blockHash),
|
|
1092
1141
|
data: index
|
|
1093
1142
|
};
|
|
1094
1143
|
});
|
|
1095
1144
|
}
|
|
1096
1145
|
async getBlockHashMembershipWitness(referenceBlock, blockHash) {
|
|
1097
|
-
|
|
1146
|
+
// Block 0 (the initial block) has an empty archive, so no membership witness can exist.
|
|
1147
|
+
if (referenceBlock === BlockNumber.ZERO) {
|
|
1148
|
+
return undefined;
|
|
1149
|
+
}
|
|
1150
|
+
if (BlockHash.isBlockHash(referenceBlock)) {
|
|
1151
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1152
|
+
if (referenceBlock.equals(initialBlockHash)) {
|
|
1153
|
+
return undefined;
|
|
1154
|
+
}
|
|
1155
|
+
}
|
|
1156
|
+
// The Noir circuit checks the archive membership proof against `anchor_block_header.last_archive.root`,
|
|
1157
|
+
// which is the archive tree root BEFORE the anchor block was added (i.e. the state after block N-1).
|
|
1158
|
+
// So we need the world state at block N-1, not block N, to produce a sibling path matching that root.
|
|
1159
|
+
const referenceBlockNumber = await this.resolveBlockNumber(referenceBlock);
|
|
1160
|
+
const committedDb = await this.getWorldState(BlockNumber(referenceBlockNumber - 1));
|
|
1098
1161
|
const [pathAndIndex] = await committedDb.findSiblingPaths(MerkleTreeId.ARCHIVE, [
|
|
1099
1162
|
blockHash
|
|
1100
1163
|
]);
|
|
1101
1164
|
return pathAndIndex === undefined ? undefined : MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
1102
1165
|
}
|
|
1103
1166
|
async getNoteHashMembershipWitness(referenceBlock, noteHash) {
|
|
1104
|
-
const committedDb = await this
|
|
1167
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1105
1168
|
const [pathAndIndex] = await committedDb.findSiblingPaths(MerkleTreeId.NOTE_HASH_TREE, [
|
|
1106
1169
|
noteHash
|
|
1107
1170
|
]);
|
|
1108
1171
|
return pathAndIndex === undefined ? undefined : MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
1109
1172
|
}
|
|
1110
1173
|
async getL1ToL2MessageMembershipWitness(referenceBlock, l1ToL2Message) {
|
|
1111
|
-
const db = await this
|
|
1174
|
+
const db = await this.getWorldState(referenceBlock);
|
|
1112
1175
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [
|
|
1113
1176
|
l1ToL2Message
|
|
1114
1177
|
]);
|
|
@@ -1121,9 +1184,9 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1121
1184
|
witness.path
|
|
1122
1185
|
];
|
|
1123
1186
|
}
|
|
1124
|
-
async
|
|
1187
|
+
async getL1ToL2MessageCheckpoint(l1ToL2Message) {
|
|
1125
1188
|
const messageIndex = await this.l1ToL2MessageSource.getL1ToL2MessageIndex(l1ToL2Message);
|
|
1126
|
-
return messageIndex ?
|
|
1189
|
+
return messageIndex ? InboxLeaf.checkpointNumberFromIndex(messageIndex) : undefined;
|
|
1127
1190
|
}
|
|
1128
1191
|
/**
|
|
1129
1192
|
* Returns whether an L1 to L2 message is synced by archiver and if it's ready to be included in a block.
|
|
@@ -1140,23 +1203,11 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1140
1203
|
*/ async getL2ToL1Messages(epoch) {
|
|
1141
1204
|
// Assumes `getCheckpointedBlocksForEpoch` returns blocks in ascending order of block number.
|
|
1142
1205
|
const checkpointedBlocks = await this.blockSource.getCheckpointedBlocksForEpoch(epoch);
|
|
1143
|
-
const blocksInCheckpoints =
|
|
1144
|
-
let previousSlotNumber = SlotNumber.ZERO;
|
|
1145
|
-
let checkpointIndex = -1;
|
|
1146
|
-
for (const checkpointedBlock of checkpointedBlocks){
|
|
1147
|
-
const block = checkpointedBlock.block;
|
|
1148
|
-
const slotNumber = block.header.globalVariables.slotNumber;
|
|
1149
|
-
if (slotNumber !== previousSlotNumber) {
|
|
1150
|
-
checkpointIndex++;
|
|
1151
|
-
blocksInCheckpoints.push([]);
|
|
1152
|
-
previousSlotNumber = slotNumber;
|
|
1153
|
-
}
|
|
1154
|
-
blocksInCheckpoints[checkpointIndex].push(block);
|
|
1155
|
-
}
|
|
1206
|
+
const blocksInCheckpoints = chunkBy(checkpointedBlocks, (cb)=>cb.block.header.globalVariables.slotNumber).map((group)=>group.map((cb)=>cb.block));
|
|
1156
1207
|
return blocksInCheckpoints.map((blocks)=>blocks.map((block)=>block.body.txEffects.map((txEffect)=>txEffect.l2ToL1Msgs)));
|
|
1157
1208
|
}
|
|
1158
1209
|
async getNullifierMembershipWitness(referenceBlock, nullifier) {
|
|
1159
|
-
const db = await this
|
|
1210
|
+
const db = await this.getWorldState(referenceBlock);
|
|
1160
1211
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [
|
|
1161
1212
|
nullifier.toBuffer()
|
|
1162
1213
|
]);
|
|
@@ -1170,36 +1221,22 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1170
1221
|
}
|
|
1171
1222
|
return new NullifierMembershipWitness(index, leafPreimage, path);
|
|
1172
1223
|
}
|
|
1173
|
-
|
|
1174
|
-
|
|
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).
|
|
1177
|
-
* @param nullifier - Nullifier we try to find the low nullifier witness for.
|
|
1178
|
-
* @returns The low nullifier membership witness (if found).
|
|
1179
|
-
* @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
|
|
1180
|
-
* list structure" of leaves and proving that a lower nullifier is pointing to a bigger next value than the nullifier
|
|
1181
|
-
* we are trying to prove non-inclusion for.
|
|
1182
|
-
*
|
|
1183
|
-
* Note: This function returns the membership witness of the nullifier itself and not the low nullifier when
|
|
1184
|
-
* the nullifier already exists in the tree. This is because the `getPreviousValueIndex` function returns the
|
|
1185
|
-
* index of the nullifier itself when it already exists in the tree.
|
|
1186
|
-
* TODO: This is a confusing behavior and we should eventually address that.
|
|
1187
|
-
*/ async getLowNullifierMembershipWitness(referenceBlock, nullifier) {
|
|
1188
|
-
const committedDb = await this.#getWorldState(referenceBlock);
|
|
1224
|
+
async getLowNullifierMembershipWitness(referenceBlock, nullifier) {
|
|
1225
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1189
1226
|
const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
|
|
1190
1227
|
if (!findResult) {
|
|
1191
1228
|
return undefined;
|
|
1192
1229
|
}
|
|
1193
1230
|
const { index, alreadyPresent } = findResult;
|
|
1194
1231
|
if (alreadyPresent) {
|
|
1195
|
-
|
|
1232
|
+
throw new Error(`Cannot prove nullifier non-inclusion: nullifier ${nullifier.toBigInt()} already exists in the tree`);
|
|
1196
1233
|
}
|
|
1197
1234
|
const preimageData = await committedDb.getLeafPreimage(MerkleTreeId.NULLIFIER_TREE, index);
|
|
1198
1235
|
const siblingPath = await committedDb.getSiblingPath(MerkleTreeId.NULLIFIER_TREE, BigInt(index));
|
|
1199
1236
|
return new NullifierMembershipWitness(BigInt(index), preimageData, siblingPath);
|
|
1200
1237
|
}
|
|
1201
1238
|
async getPublicDataWitness(referenceBlock, leafSlot) {
|
|
1202
|
-
const committedDb = await this
|
|
1239
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1203
1240
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
1204
1241
|
if (!lowLeafResult) {
|
|
1205
1242
|
return undefined;
|
|
@@ -1210,7 +1247,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1210
1247
|
}
|
|
1211
1248
|
}
|
|
1212
1249
|
async getPublicStorageAt(referenceBlock, contract, slot) {
|
|
1213
|
-
const committedDb = await this
|
|
1250
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1214
1251
|
const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
|
|
1215
1252
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
1216
1253
|
if (!lowLeafResult || !lowLeafResult.alreadyPresent) {
|
|
@@ -1289,7 +1326,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1289
1326
|
});
|
|
1290
1327
|
const processor = publicProcessorFactory.create(merkleTreeFork, newGlobalVariables, config);
|
|
1291
1328
|
// REFACTOR: Consider merging ProcessReturnValues into ProcessedTx
|
|
1292
|
-
const [processedTxs, failedTxs, _usedTxs, returns] = await processor.process([
|
|
1329
|
+
const [processedTxs, failedTxs, _usedTxs, returns, debugLogs] = await processor.process([
|
|
1293
1330
|
tx
|
|
1294
1331
|
]);
|
|
1295
1332
|
// REFACTOR: Consider returning the error rather than throwing
|
|
@@ -1300,7 +1337,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1300
1337
|
throw failedTxs[0].error;
|
|
1301
1338
|
}
|
|
1302
1339
|
const [processedTx] = processedTxs;
|
|
1303
|
-
return new PublicSimulationOutput(processedTx.revertReason, processedTx.globalVariables, processedTx.txEffect, returns, processedTx.gasUsed);
|
|
1340
|
+
return new PublicSimulationOutput(processedTx.revertReason, processedTx.globalVariables, processedTx.txEffect, returns, processedTx.gasUsed, debugLogs);
|
|
1304
1341
|
} finally{
|
|
1305
1342
|
await merkleTreeFork.close();
|
|
1306
1343
|
}
|
|
@@ -1311,15 +1348,22 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1311
1348
|
// We accept transactions if they are not expired by the next slot (checked based on the ExpirationTimestamp field)
|
|
1312
1349
|
const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
1313
1350
|
const blockNumber = BlockNumber(await this.blockSource.getBlockNumber() + 1);
|
|
1314
|
-
const
|
|
1351
|
+
const l1Constants = await this.blockSource.getL1Constants();
|
|
1352
|
+
const validator = createTxValidatorForAcceptingTxsOverRPC(db, this.contractDataSource, verifier, {
|
|
1315
1353
|
timestamp: nextSlotTimestamp,
|
|
1316
1354
|
blockNumber,
|
|
1317
1355
|
l1ChainId: this.l1ChainId,
|
|
1318
1356
|
rollupVersion: this.version,
|
|
1319
|
-
setupAllowList:
|
|
1357
|
+
setupAllowList: [
|
|
1358
|
+
...await getDefaultAllowedSetupFunctions(),
|
|
1359
|
+
...this.config.txPublicSetupAllowListExtend ?? []
|
|
1360
|
+
],
|
|
1320
1361
|
gasFees: await this.getCurrentMinFees(),
|
|
1321
1362
|
skipFeeEnforcement,
|
|
1322
|
-
txsPermitted: !this.config.disableTransactions
|
|
1363
|
+
txsPermitted: !this.config.disableTransactions,
|
|
1364
|
+
rollupManaLimit: l1Constants.rollupManaLimit,
|
|
1365
|
+
maxBlockL2Gas: this.config.validateMaxL2BlockGas,
|
|
1366
|
+
maxBlockDAGas: this.config.validateMaxDABlockGas
|
|
1323
1367
|
}, this.log.getBindings());
|
|
1324
1368
|
return await validator.validateTx(tx);
|
|
1325
1369
|
}
|
|
@@ -1539,7 +1583,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1539
1583
|
* Returns an instance of MerkleTreeOperations having first ensured the world state is fully synched
|
|
1540
1584
|
* @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
|
|
1541
1585
|
* @returns An instance of a committed MerkleTreeOperations
|
|
1542
|
-
*/ async
|
|
1586
|
+
*/ async getWorldState(block) {
|
|
1543
1587
|
let blockSyncedTo = BlockNumber.ZERO;
|
|
1544
1588
|
try {
|
|
1545
1589
|
// Attempt to sync the world state if necessary
|
|
@@ -1551,6 +1595,8 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1551
1595
|
this.log.debug(`Using committed db for block 'latest', world state synced upto ${blockSyncedTo}`);
|
|
1552
1596
|
return this.worldStateSynchronizer.getCommitted();
|
|
1553
1597
|
}
|
|
1598
|
+
// Get the block number, either directly from the parameter or by quering the archiver with the block hash
|
|
1599
|
+
let blockNumber;
|
|
1554
1600
|
if (BlockHash.isBlockHash(block)) {
|
|
1555
1601
|
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1556
1602
|
if (block.equals(initialBlockHash)) {
|
|
@@ -1561,19 +1607,41 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1561
1607
|
if (!header) {
|
|
1562
1608
|
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
1609
|
}
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
}
|
|
1568
|
-
//
|
|
1569
|
-
{
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1610
|
+
blockNumber = header.getBlockNumber();
|
|
1611
|
+
} else {
|
|
1612
|
+
blockNumber = block;
|
|
1613
|
+
}
|
|
1614
|
+
// Check it's within world state sync range
|
|
1615
|
+
if (blockNumber > blockSyncedTo) {
|
|
1616
|
+
throw new Error(`Queried block ${block} not yet synced by the node (node is synced upto ${blockSyncedTo}).`);
|
|
1617
|
+
}
|
|
1618
|
+
this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1619
|
+
const snapshot = this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1620
|
+
// Double-check world-state synced to the same block hash as was requested
|
|
1621
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1622
|
+
const blockHash = await snapshot.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
|
|
1623
|
+
if (!blockHash || !new BlockHash(blockHash).equals(block)) {
|
|
1624
|
+
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.`);
|
|
1625
|
+
}
|
|
1626
|
+
}
|
|
1627
|
+
return snapshot;
|
|
1628
|
+
}
|
|
1629
|
+
/** Resolves a block parameter to a block number. */ async resolveBlockNumber(block) {
|
|
1630
|
+
if (block === 'latest') {
|
|
1631
|
+
return BlockNumber(await this.blockSource.getBlockNumber());
|
|
1632
|
+
}
|
|
1633
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1634
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1635
|
+
if (block.equals(initialBlockHash)) {
|
|
1636
|
+
return BlockNumber.ZERO;
|
|
1637
|
+
}
|
|
1638
|
+
const header = await this.blockSource.getBlockHeaderByHash(block);
|
|
1639
|
+
if (!header) {
|
|
1640
|
+
throw new Error(`Block hash ${block.toString()} not found.`);
|
|
1573
1641
|
}
|
|
1574
|
-
|
|
1575
|
-
return this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1642
|
+
return header.getBlockNumber();
|
|
1576
1643
|
}
|
|
1644
|
+
return block;
|
|
1577
1645
|
}
|
|
1578
1646
|
/**
|
|
1579
1647
|
* Ensure we fully sync the world state
|