@aztec/aztec-node 0.0.1-commit.ff7989d6c → 0.0.1-commit.fff30aa
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 +21 -23
- package/dest/aztec-node/server.d.ts.map +1 -1
- package/dest/aztec-node/server.js +247 -151
- package/dest/sentinel/sentinel.js +3 -3
- package/package.json +27 -27
- package/src/aztec-node/server.ts +289 -157
- package/src/sentinel/sentinel.ts +3 -3
|
@@ -377,21 +377,22 @@ 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';
|
|
387
387
|
import { createLogger } from '@aztec/foundation/log';
|
|
388
|
+
import { retryUntil } from '@aztec/foundation/retry';
|
|
388
389
|
import { count } from '@aztec/foundation/string';
|
|
389
390
|
import { DateProvider, Timer } from '@aztec/foundation/timer';
|
|
390
391
|
import { MembershipWitness } from '@aztec/foundation/trees';
|
|
391
392
|
import { KeystoreManager, loadKeystores, mergeKeystores } from '@aztec/node-keystore';
|
|
392
393
|
import { trySnapshotSync, uploadSnapshot } from '@aztec/node-lib/actions';
|
|
393
394
|
import { createForwarderL1TxUtilsFromSigners, createL1TxUtilsFromSigners } from '@aztec/node-lib/factories';
|
|
394
|
-
import { createP2PClient, getDefaultAllowedSetupFunctions } from '@aztec/p2p';
|
|
395
|
+
import { createP2PClient, createTxValidatorForAcceptingTxsOverRPC, getDefaultAllowedSetupFunctions } from '@aztec/p2p';
|
|
395
396
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
396
397
|
import { createProverNode } from '@aztec/prover-node';
|
|
397
398
|
import { createKeyStoreForProver } from '@aztec/prover-node/config';
|
|
@@ -405,15 +406,15 @@ import { GasFees } from '@aztec/stdlib/gas';
|
|
|
405
406
|
import { computePublicDataTreeLeafSlot } from '@aztec/stdlib/hash';
|
|
406
407
|
import { AztecNodeAdminConfigSchema } from '@aztec/stdlib/interfaces/client';
|
|
407
408
|
import { tryStop } from '@aztec/stdlib/interfaces/server';
|
|
409
|
+
import { InMemoryDebugLogStore, NullDebugLogStore } from '@aztec/stdlib/logs';
|
|
408
410
|
import { InboxLeaf } from '@aztec/stdlib/messaging';
|
|
409
|
-
import { P2PClientType } from '@aztec/stdlib/p2p';
|
|
410
411
|
import { MerkleTreeId, NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
|
|
411
412
|
import { PublicSimulationOutput, TxReceipt, TxStatus } from '@aztec/stdlib/tx';
|
|
412
413
|
import { getPackageVersion } from '@aztec/stdlib/update-checker';
|
|
413
414
|
import { Attributes, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
|
|
414
|
-
import { FullNodeCheckpointsBuilder as CheckpointsBuilder, FullNodeCheckpointsBuilder, NodeKeystoreAdapter, ValidatorClient,
|
|
415
|
+
import { FullNodeCheckpointsBuilder as CheckpointsBuilder, FullNodeCheckpointsBuilder, NodeKeystoreAdapter, ValidatorClient, createProposalHandler, createValidatorClient } from '@aztec/validator-client';
|
|
415
416
|
import { createWorldStateSynchronizer } from '@aztec/world-state';
|
|
416
|
-
import { createPublicClient
|
|
417
|
+
import { createPublicClient } from 'viem';
|
|
417
418
|
import { createSentinel } from '../sentinel/factory.js';
|
|
418
419
|
import { createKeyStoreForValidator } from './config.js';
|
|
419
420
|
import { NodeMetrics } from './node_metrics.js';
|
|
@@ -446,6 +447,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
446
447
|
blobClient;
|
|
447
448
|
validatorClient;
|
|
448
449
|
keyStoreManager;
|
|
450
|
+
debugLogStore;
|
|
449
451
|
static{
|
|
450
452
|
({ e: [_initProto] } = _apply_decs_2203_r(this, [
|
|
451
453
|
[
|
|
@@ -460,7 +462,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
460
462
|
// Prevent two snapshot operations to happen simultaneously
|
|
461
463
|
isUploadingSnapshot;
|
|
462
464
|
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){
|
|
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()){
|
|
464
466
|
this.config = config;
|
|
465
467
|
this.p2pClient = p2pClient;
|
|
466
468
|
this.blockSource = blockSource;
|
|
@@ -484,12 +486,19 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
484
486
|
this.blobClient = blobClient;
|
|
485
487
|
this.validatorClient = validatorClient;
|
|
486
488
|
this.keyStoreManager = keyStoreManager;
|
|
489
|
+
this.debugLogStore = debugLogStore;
|
|
487
490
|
this.initialHeaderHashPromise = (_initProto(this), undefined);
|
|
488
491
|
this.isUploadingSnapshot = false;
|
|
489
492
|
this.metrics = new NodeMetrics(telemetry, 'AztecNodeService');
|
|
490
493
|
this.tracer = telemetry.getTracer('AztecNodeService');
|
|
491
494
|
this.log.info(`Aztec Node version: ${this.packageVersion}`);
|
|
492
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
|
+
}
|
|
493
502
|
}
|
|
494
503
|
async getWorldStateSyncStatus() {
|
|
495
504
|
const status = await this.worldStateSynchronizer.status();
|
|
@@ -551,9 +560,9 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
551
560
|
}
|
|
552
561
|
const publicClient = createPublicClient({
|
|
553
562
|
chain: ethereumChain.chainInfo,
|
|
554
|
-
transport:
|
|
555
|
-
|
|
556
|
-
|
|
563
|
+
transport: makeL1HttpTransport(config.l1RpcUrls, {
|
|
564
|
+
timeout: config.l1HttpTimeoutMS
|
|
565
|
+
}),
|
|
557
566
|
pollingInterval: config.viemPollingIntervalMS
|
|
558
567
|
});
|
|
559
568
|
const l1ContractsAddresses = await RegistryContract.collectAddresses(publicClient, config.l1Contracts.registryAddress, config.rollupVersion ?? 'canonical');
|
|
@@ -563,10 +572,11 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
563
572
|
...l1ContractsAddresses
|
|
564
573
|
};
|
|
565
574
|
const rollupContract = new RollupContract(publicClient, config.l1Contracts.rollupAddress.toString());
|
|
566
|
-
const [l1GenesisTime, slotDuration, rollupVersionFromRollup] = await Promise.all([
|
|
575
|
+
const [l1GenesisTime, slotDuration, rollupVersionFromRollup, rollupManaLimit] = await Promise.all([
|
|
567
576
|
rollupContract.getL1GenesisTime(),
|
|
568
577
|
rollupContract.getSlotDuration(),
|
|
569
|
-
rollupContract.getVersion()
|
|
578
|
+
rollupContract.getVersion(),
|
|
579
|
+
rollupContract.getManaLimit().then(Number)
|
|
570
580
|
]);
|
|
571
581
|
config.rollupVersion ??= Number(rollupVersionFromRollup);
|
|
572
582
|
if (config.rollupVersion !== Number(rollupVersionFromRollup)) {
|
|
@@ -589,77 +599,98 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
589
599
|
// now create the merkle trees and the world state synchronizer
|
|
590
600
|
const worldStateSynchronizer = await createWorldStateSynchronizer(config, archiver, options.prefilledPublicData, telemetry);
|
|
591
601
|
const circuitVerifier = config.realProofs || config.debugForceTxProofVerification ? await BBCircuitVerifier.new(config) : new TestCircuitVerifier(config.proverTestVerificationDelayMs);
|
|
602
|
+
let debugLogStore;
|
|
592
603
|
if (!config.realProofs) {
|
|
593
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();
|
|
594
609
|
}
|
|
595
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
|
+
}
|
|
596
615
|
// 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
|
|
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.
|
|
601
621
|
const validatorCheckpointsBuilder = new FullNodeCheckpointsBuilder({
|
|
602
622
|
...config,
|
|
603
623
|
l1GenesisTime,
|
|
604
|
-
slotDuration: Number(slotDuration)
|
|
624
|
+
slotDuration: Number(slotDuration),
|
|
625
|
+
rollupManaLimit,
|
|
626
|
+
maxTxsPerCheckpoint: config.validateMaxTxsPerCheckpoint
|
|
605
627
|
}, 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
|
-
|
|
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
|
+
}
|
|
628
652
|
}
|
|
629
653
|
}
|
|
630
|
-
// If there's no validator client
|
|
631
|
-
//
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
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, {
|
|
635
662
|
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
636
663
|
worldState: worldStateSynchronizer,
|
|
637
664
|
epochCache,
|
|
638
665
|
blockSource: archiver,
|
|
639
666
|
l1ToL2MessageSource: archiver,
|
|
640
667
|
p2pClient,
|
|
668
|
+
blobClient,
|
|
641
669
|
dateProvider,
|
|
642
670
|
telemetry
|
|
643
|
-
}).
|
|
671
|
+
}).register(p2pClient, reexecute);
|
|
644
672
|
}
|
|
645
673
|
// Start world state and wait for it to sync to the archiver.
|
|
646
674
|
await worldStateSynchronizer.start();
|
|
647
675
|
// Start p2p. Note that it depends on world state to be running.
|
|
648
676
|
await p2pClient.start();
|
|
649
|
-
|
|
650
|
-
if (validatorsSentinel && config.slashInactivityPenalty > 0n) {
|
|
651
|
-
watchers.push(validatorsSentinel);
|
|
652
|
-
}
|
|
677
|
+
let validatorsSentinel;
|
|
653
678
|
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
679
|
let attestationsBlockWatcher;
|
|
660
|
-
if (
|
|
661
|
-
|
|
662
|
-
|
|
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
|
+
}
|
|
663
694
|
}
|
|
664
695
|
// Start p2p-related services once the archiver has completed sync
|
|
665
696
|
void archiver.waitForInitialSync().then(async ()=>{
|
|
@@ -669,6 +700,13 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
669
700
|
await attestationsBlockWatcher?.start();
|
|
670
701
|
log.info(`All p2p services started`);
|
|
671
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
|
+
});
|
|
672
710
|
// Validator enabled, create/start relevant service
|
|
673
711
|
let sequencer;
|
|
674
712
|
let slasherClient;
|
|
@@ -699,8 +737,9 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
699
737
|
const checkpointsBuilder = new CheckpointsBuilder({
|
|
700
738
|
...config,
|
|
701
739
|
l1GenesisTime,
|
|
702
|
-
slotDuration: Number(slotDuration)
|
|
703
|
-
|
|
740
|
+
slotDuration: Number(slotDuration),
|
|
741
|
+
rollupManaLimit
|
|
742
|
+
}, worldStateSynchronizer, archiver, dateProvider, telemetry, debugLogStore);
|
|
704
743
|
sequencer = await SequencerClient.new(config, {
|
|
705
744
|
...deps,
|
|
706
745
|
epochCache,
|
|
@@ -715,7 +754,8 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
715
754
|
telemetry,
|
|
716
755
|
dateProvider,
|
|
717
756
|
blobClient,
|
|
718
|
-
nodeKeyStore: keyStoreManager
|
|
757
|
+
nodeKeyStore: keyStoreManager,
|
|
758
|
+
globalVariableBuilder
|
|
719
759
|
});
|
|
720
760
|
}
|
|
721
761
|
if (!options.dontStartSequencer && sequencer) {
|
|
@@ -745,13 +785,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
745
785
|
log.info(`Prover node subsystem created but not started`);
|
|
746
786
|
}
|
|
747
787
|
}
|
|
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);
|
|
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);
|
|
755
789
|
return node;
|
|
756
790
|
}
|
|
757
791
|
/**
|
|
@@ -782,7 +816,10 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
782
816
|
return Promise.resolve(this.p2pClient.getEnr()?.encodeTxt());
|
|
783
817
|
}
|
|
784
818
|
async getAllowedPublicSetup() {
|
|
785
|
-
return
|
|
819
|
+
return [
|
|
820
|
+
...await getDefaultAllowedSetupFunctions(),
|
|
821
|
+
...this.config.txPublicSetupAllowListExtend ?? []
|
|
822
|
+
];
|
|
786
823
|
}
|
|
787
824
|
/**
|
|
788
825
|
* Method to determine if the node is ready to accept transactions.
|
|
@@ -860,6 +897,9 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
860
897
|
async getCheckpointedBlocks(from, limit) {
|
|
861
898
|
return await this.blockSource.getCheckpointedBlocks(from, limit) ?? [];
|
|
862
899
|
}
|
|
900
|
+
getCheckpointsDataForEpoch(epochNumber) {
|
|
901
|
+
return this.blockSource.getCheckpointsDataForEpoch(epochNumber);
|
|
902
|
+
}
|
|
863
903
|
/**
|
|
864
904
|
* Method to fetch the current min L2 fees.
|
|
865
905
|
* @returns The current min L2 fees.
|
|
@@ -887,6 +927,9 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
887
927
|
async getCheckpointedBlockNumber() {
|
|
888
928
|
return await this.blockSource.getCheckpointedL2BlockNumber();
|
|
889
929
|
}
|
|
930
|
+
getCheckpointNumber() {
|
|
931
|
+
return this.blockSource.getCheckpointNumber();
|
|
932
|
+
}
|
|
890
933
|
/**
|
|
891
934
|
* Method to fetch the version of the package.
|
|
892
935
|
* @returns The node package version
|
|
@@ -968,8 +1011,9 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
968
1011
|
throw new Error(`Invalid tx: ${reason}`);
|
|
969
1012
|
}
|
|
970
1013
|
await this.p2pClient.sendTx(tx);
|
|
971
|
-
|
|
972
|
-
this.
|
|
1014
|
+
const duration = timer.ms();
|
|
1015
|
+
this.metrics.receivedTx(duration, true);
|
|
1016
|
+
this.log.info(`Received tx ${txHash} in ${duration}ms`, {
|
|
973
1017
|
txHash
|
|
974
1018
|
});
|
|
975
1019
|
}
|
|
@@ -980,18 +1024,20 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
980
1024
|
const isKnownToPool = txPoolStatus === 'pending' || txPoolStatus === 'mined';
|
|
981
1025
|
// Then get the actual tx from the archiver, which tracks every tx in a mined block.
|
|
982
1026
|
const settledTxReceipt = await this.blockSource.getSettledTxReceipt(txHash);
|
|
1027
|
+
let receipt;
|
|
983
1028
|
if (settledTxReceipt) {
|
|
984
|
-
|
|
985
|
-
return settledTxReceipt;
|
|
1029
|
+
receipt = settledTxReceipt;
|
|
986
1030
|
} else if (isKnownToPool) {
|
|
987
1031
|
// If the tx is in the pool but not in the archiver, it's pending.
|
|
988
1032
|
// This handles race conditions between archiver and p2p, where the archiver
|
|
989
1033
|
// has pruned the block in which a tx was mined, but p2p has not caught up yet.
|
|
990
|
-
|
|
1034
|
+
receipt = new TxReceipt(txHash, TxStatus.PENDING, undefined, undefined);
|
|
991
1035
|
} else {
|
|
992
1036
|
// Otherwise, if we don't know the tx, we consider it dropped.
|
|
993
|
-
|
|
1037
|
+
receipt = new TxReceipt(txHash, TxStatus.DROPPED, undefined, 'Tx dropped by P2P node');
|
|
994
1038
|
}
|
|
1039
|
+
this.debugLogStore.decorateReceiptWithLogs(txHash.toString(), receipt);
|
|
1040
|
+
return receipt;
|
|
995
1041
|
}
|
|
996
1042
|
getTxEffect(txHash) {
|
|
997
1043
|
return this.blockSource.getTxEffect(txHash);
|
|
@@ -1045,70 +1091,88 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1045
1091
|
return compactArray(await Promise.all(txHashes.map((txHash)=>this.getTxByHash(txHash))));
|
|
1046
1092
|
}
|
|
1047
1093
|
async findLeavesIndexes(referenceBlock, treeId, leafValues) {
|
|
1048
|
-
const committedDb = await this
|
|
1094
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1049
1095
|
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
|
-
|
|
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]}`);
|
|
1058
1106
|
}
|
|
1107
|
+
indexToBlockNumber.set(definedIndices[i], blockNumber);
|
|
1059
1108
|
}
|
|
1060
1109
|
// Get unique block numbers in order to optimize num calls to getLeafValue function.
|
|
1061
1110
|
const uniqueBlockNumbers = [
|
|
1062
|
-
...new Set(
|
|
1111
|
+
...new Set(indexToBlockNumber.values())
|
|
1063
1112
|
];
|
|
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).
|
|
1113
|
+
// Now we obtain the block hashes from the archive tree (block number = leaf index in archive tree).
|
|
1066
1114
|
const blockHashes = await Promise.all(uniqueBlockNumbers.map((blockNumber)=>{
|
|
1067
1115
|
return committedDb.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
|
|
1068
1116
|
}));
|
|
1069
|
-
//
|
|
1117
|
+
// Build a map from block number to block hash
|
|
1118
|
+
const blockNumberToHash = new Map();
|
|
1070
1119
|
for(let i = 0; i < uniqueBlockNumbers.length; i++){
|
|
1071
|
-
|
|
1120
|
+
const blockHash = blockHashes[i];
|
|
1121
|
+
if (blockHash === undefined) {
|
|
1072
1122
|
throw new Error(`Block hash is undefined for block number ${uniqueBlockNumbers[i]}`);
|
|
1073
1123
|
}
|
|
1124
|
+
blockNumberToHash.set(uniqueBlockNumbers[i], blockHash);
|
|
1074
1125
|
}
|
|
1075
1126
|
// Create DataInBlock objects by combining indices, blockNumbers and blockHashes and return them.
|
|
1076
|
-
return maybeIndices.map((index
|
|
1127
|
+
return maybeIndices.map((index)=>{
|
|
1077
1128
|
if (index === undefined) {
|
|
1078
1129
|
return undefined;
|
|
1079
1130
|
}
|
|
1080
|
-
const blockNumber =
|
|
1131
|
+
const blockNumber = indexToBlockNumber.get(index);
|
|
1081
1132
|
if (blockNumber === undefined) {
|
|
1082
|
-
|
|
1133
|
+
throw new Error(`Block number not found for leaf index ${index} in tree ${MerkleTreeId[treeId]}`);
|
|
1083
1134
|
}
|
|
1084
|
-
const
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
return undefined;
|
|
1135
|
+
const blockHash = blockNumberToHash.get(blockNumber);
|
|
1136
|
+
if (blockHash === undefined) {
|
|
1137
|
+
throw new Error(`Block hash not found for block number ${blockNumber}`);
|
|
1088
1138
|
}
|
|
1089
1139
|
return {
|
|
1090
|
-
l2BlockNumber:
|
|
1140
|
+
l2BlockNumber: blockNumber,
|
|
1091
1141
|
l2BlockHash: new BlockHash(blockHash),
|
|
1092
1142
|
data: index
|
|
1093
1143
|
};
|
|
1094
1144
|
});
|
|
1095
1145
|
}
|
|
1096
1146
|
async getBlockHashMembershipWitness(referenceBlock, blockHash) {
|
|
1097
|
-
|
|
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));
|
|
1098
1162
|
const [pathAndIndex] = await committedDb.findSiblingPaths(MerkleTreeId.ARCHIVE, [
|
|
1099
1163
|
blockHash
|
|
1100
1164
|
]);
|
|
1101
1165
|
return pathAndIndex === undefined ? undefined : MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
1102
1166
|
}
|
|
1103
1167
|
async getNoteHashMembershipWitness(referenceBlock, noteHash) {
|
|
1104
|
-
const committedDb = await this
|
|
1168
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1105
1169
|
const [pathAndIndex] = await committedDb.findSiblingPaths(MerkleTreeId.NOTE_HASH_TREE, [
|
|
1106
1170
|
noteHash
|
|
1107
1171
|
]);
|
|
1108
1172
|
return pathAndIndex === undefined ? undefined : MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
1109
1173
|
}
|
|
1110
1174
|
async getL1ToL2MessageMembershipWitness(referenceBlock, l1ToL2Message) {
|
|
1111
|
-
const db = await this
|
|
1175
|
+
const db = await this.getWorldState(referenceBlock);
|
|
1112
1176
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [
|
|
1113
1177
|
l1ToL2Message
|
|
1114
1178
|
]);
|
|
@@ -1121,9 +1185,9 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1121
1185
|
witness.path
|
|
1122
1186
|
];
|
|
1123
1187
|
}
|
|
1124
|
-
async
|
|
1188
|
+
async getL1ToL2MessageCheckpoint(l1ToL2Message) {
|
|
1125
1189
|
const messageIndex = await this.l1ToL2MessageSource.getL1ToL2MessageIndex(l1ToL2Message);
|
|
1126
|
-
return messageIndex ?
|
|
1190
|
+
return messageIndex ? InboxLeaf.checkpointNumberFromIndex(messageIndex) : undefined;
|
|
1127
1191
|
}
|
|
1128
1192
|
/**
|
|
1129
1193
|
* Returns whether an L1 to L2 message is synced by archiver and if it's ready to be included in a block.
|
|
@@ -1140,23 +1204,11 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1140
1204
|
*/ async getL2ToL1Messages(epoch) {
|
|
1141
1205
|
// Assumes `getCheckpointedBlocksForEpoch` returns blocks in ascending order of block number.
|
|
1142
1206
|
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
|
-
}
|
|
1207
|
+
const blocksInCheckpoints = chunkBy(checkpointedBlocks, (cb)=>cb.block.header.globalVariables.slotNumber).map((group)=>group.map((cb)=>cb.block));
|
|
1156
1208
|
return blocksInCheckpoints.map((blocks)=>blocks.map((block)=>block.body.txEffects.map((txEffect)=>txEffect.l2ToL1Msgs)));
|
|
1157
1209
|
}
|
|
1158
1210
|
async getNullifierMembershipWitness(referenceBlock, nullifier) {
|
|
1159
|
-
const db = await this
|
|
1211
|
+
const db = await this.getWorldState(referenceBlock);
|
|
1160
1212
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [
|
|
1161
1213
|
nullifier.toBuffer()
|
|
1162
1214
|
]);
|
|
@@ -1170,36 +1222,22 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1170
1222
|
}
|
|
1171
1223
|
return new NullifierMembershipWitness(index, leafPreimage, path);
|
|
1172
1224
|
}
|
|
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);
|
|
1225
|
+
async getLowNullifierMembershipWitness(referenceBlock, nullifier) {
|
|
1226
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1189
1227
|
const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
|
|
1190
1228
|
if (!findResult) {
|
|
1191
1229
|
return undefined;
|
|
1192
1230
|
}
|
|
1193
1231
|
const { index, alreadyPresent } = findResult;
|
|
1194
1232
|
if (alreadyPresent) {
|
|
1195
|
-
|
|
1233
|
+
throw new Error(`Cannot prove nullifier non-inclusion: nullifier ${nullifier.toBigInt()} already exists in the tree`);
|
|
1196
1234
|
}
|
|
1197
1235
|
const preimageData = await committedDb.getLeafPreimage(MerkleTreeId.NULLIFIER_TREE, index);
|
|
1198
1236
|
const siblingPath = await committedDb.getSiblingPath(MerkleTreeId.NULLIFIER_TREE, BigInt(index));
|
|
1199
1237
|
return new NullifierMembershipWitness(BigInt(index), preimageData, siblingPath);
|
|
1200
1238
|
}
|
|
1201
1239
|
async getPublicDataWitness(referenceBlock, leafSlot) {
|
|
1202
|
-
const committedDb = await this
|
|
1240
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1203
1241
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
1204
1242
|
if (!lowLeafResult) {
|
|
1205
1243
|
return undefined;
|
|
@@ -1210,7 +1248,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1210
1248
|
}
|
|
1211
1249
|
}
|
|
1212
1250
|
async getPublicStorageAt(referenceBlock, contract, slot) {
|
|
1213
|
-
const committedDb = await this
|
|
1251
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1214
1252
|
const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
|
|
1215
1253
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
1216
1254
|
if (!lowLeafResult || !lowLeafResult.alreadyPresent) {
|
|
@@ -1289,7 +1327,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1289
1327
|
});
|
|
1290
1328
|
const processor = publicProcessorFactory.create(merkleTreeFork, newGlobalVariables, config);
|
|
1291
1329
|
// REFACTOR: Consider merging ProcessReturnValues into ProcessedTx
|
|
1292
|
-
const [processedTxs, failedTxs, _usedTxs, returns,
|
|
1330
|
+
const [processedTxs, failedTxs, _usedTxs, returns, debugLogs] = await processor.process([
|
|
1293
1331
|
tx
|
|
1294
1332
|
]);
|
|
1295
1333
|
// REFACTOR: Consider returning the error rather than throwing
|
|
@@ -1311,15 +1349,22 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1311
1349
|
// We accept transactions if they are not expired by the next slot (checked based on the ExpirationTimestamp field)
|
|
1312
1350
|
const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
1313
1351
|
const blockNumber = BlockNumber(await this.blockSource.getBlockNumber() + 1);
|
|
1314
|
-
const
|
|
1352
|
+
const l1Constants = await this.blockSource.getL1Constants();
|
|
1353
|
+
const validator = createTxValidatorForAcceptingTxsOverRPC(db, this.contractDataSource, verifier, {
|
|
1315
1354
|
timestamp: nextSlotTimestamp,
|
|
1316
1355
|
blockNumber,
|
|
1317
1356
|
l1ChainId: this.l1ChainId,
|
|
1318
1357
|
rollupVersion: this.version,
|
|
1319
|
-
setupAllowList:
|
|
1358
|
+
setupAllowList: [
|
|
1359
|
+
...await getDefaultAllowedSetupFunctions(),
|
|
1360
|
+
...this.config.txPublicSetupAllowListExtend ?? []
|
|
1361
|
+
],
|
|
1320
1362
|
gasFees: await this.getCurrentMinFees(),
|
|
1321
1363
|
skipFeeEnforcement,
|
|
1322
|
-
txsPermitted: !this.config.disableTransactions
|
|
1364
|
+
txsPermitted: !this.config.disableTransactions,
|
|
1365
|
+
rollupManaLimit: l1Constants.rollupManaLimit,
|
|
1366
|
+
maxBlockL2Gas: this.config.validateMaxL2BlockGas,
|
|
1367
|
+
maxBlockDAGas: this.config.validateMaxDABlockGas
|
|
1323
1368
|
}, this.log.getBindings());
|
|
1324
1369
|
return await validator.validateTx(tx);
|
|
1325
1370
|
}
|
|
@@ -1529,6 +1574,33 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1529
1574
|
this.keyStoreManager = newManager;
|
|
1530
1575
|
this.log.info('Keystore reloaded: coinbase, feeRecipient, and attester keys updated');
|
|
1531
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
|
+
}
|
|
1532
1604
|
#getInitialHeaderHash() {
|
|
1533
1605
|
if (!this.initialHeaderHashPromise) {
|
|
1534
1606
|
this.initialHeaderHashPromise = this.worldStateSynchronizer.getCommitted().getInitialHeader().hash();
|
|
@@ -1539,7 +1611,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1539
1611
|
* Returns an instance of MerkleTreeOperations having first ensured the world state is fully synched
|
|
1540
1612
|
* @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
|
|
1541
1613
|
* @returns An instance of a committed MerkleTreeOperations
|
|
1542
|
-
*/ async
|
|
1614
|
+
*/ async getWorldState(block) {
|
|
1543
1615
|
let blockSyncedTo = BlockNumber.ZERO;
|
|
1544
1616
|
try {
|
|
1545
1617
|
// Attempt to sync the world state if necessary
|
|
@@ -1551,6 +1623,8 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1551
1623
|
this.log.debug(`Using committed db for block 'latest', world state synced upto ${blockSyncedTo}`);
|
|
1552
1624
|
return this.worldStateSynchronizer.getCommitted();
|
|
1553
1625
|
}
|
|
1626
|
+
// Get the block number, either directly from the parameter or by quering the archiver with the block hash
|
|
1627
|
+
let blockNumber;
|
|
1554
1628
|
if (BlockHash.isBlockHash(block)) {
|
|
1555
1629
|
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1556
1630
|
if (block.equals(initialBlockHash)) {
|
|
@@ -1561,19 +1635,41 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1561
1635
|
if (!header) {
|
|
1562
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.`);
|
|
1563
1637
|
}
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
}
|
|
1568
|
-
//
|
|
1569
|
-
{
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
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.`);
|
|
1573
1669
|
}
|
|
1574
|
-
|
|
1575
|
-
return this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1670
|
+
return header.getBlockNumber();
|
|
1576
1671
|
}
|
|
1672
|
+
return block;
|
|
1577
1673
|
}
|
|
1578
1674
|
/**
|
|
1579
1675
|
* Ensure we fully sync the world state
|