@aztec/aztec-node 0.0.1-commit.2c85e299c → 0.0.1-commit.2d9cb6034
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 +17 -18
- package/dest/aztec-node/server.d.ts.map +1 -1
- package/dest/aztec-node/server.js +185 -106
- package/dest/sentinel/sentinel.js +8 -8
- package/package.json +26 -27
- package/src/aztec-node/server.ts +187 -102
- package/src/sentinel/sentinel.ts +8 -8
|
@@ -372,15 +372,16 @@ function _apply_decs_2203_r(targetClass, memberDecs, classDecs, parentClass) {
|
|
|
372
372
|
}
|
|
373
373
|
var _dec, _initProto;
|
|
374
374
|
import { createArchiver } from '@aztec/archiver';
|
|
375
|
-
import { BBCircuitVerifier,
|
|
375
|
+
import { BBCircuitVerifier, BatchChonkVerifier, QueuedIVCVerifier } from '@aztec/bb-prover';
|
|
376
|
+
import { TestCircuitVerifier } from '@aztec/bb-prover/test';
|
|
376
377
|
import { createBlobClientWithFileStores } from '@aztec/blob-client/client';
|
|
377
378
|
import { Blob } from '@aztec/blob-lib';
|
|
378
379
|
import { EpochCache } from '@aztec/epoch-cache';
|
|
379
380
|
import { createEthereumChain } from '@aztec/ethereum/chain';
|
|
380
|
-
import { getPublicClient } from '@aztec/ethereum/client';
|
|
381
|
+
import { getPublicClient, makeL1HttpTransport } from '@aztec/ethereum/client';
|
|
381
382
|
import { RegistryContract, RollupContract } from '@aztec/ethereum/contracts';
|
|
382
|
-
import { BlockNumber
|
|
383
|
-
import { compactArray, pick, unique } from '@aztec/foundation/collection';
|
|
383
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
384
|
+
import { chunkBy, compactArray, pick, unique } from '@aztec/foundation/collection';
|
|
384
385
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
385
386
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
386
387
|
import { BadRequestError } from '@aztec/foundation/json-rpc';
|
|
@@ -411,9 +412,9 @@ import { MerkleTreeId, NullifierMembershipWitness, PublicDataWitness } from '@az
|
|
|
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';
|
|
@@ -440,7 +441,8 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
440
441
|
globalVariableBuilder;
|
|
441
442
|
epochCache;
|
|
442
443
|
packageVersion;
|
|
443
|
-
|
|
444
|
+
peerProofVerifier;
|
|
445
|
+
rpcProofVerifier;
|
|
444
446
|
telemetry;
|
|
445
447
|
log;
|
|
446
448
|
blobClient;
|
|
@@ -461,7 +463,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
461
463
|
// Prevent two snapshot operations to happen simultaneously
|
|
462
464
|
isUploadingSnapshot;
|
|
463
465
|
tracer;
|
|
464
|
-
constructor(config, p2pClient, blockSource, logsSource, contractDataSource, l1ToL2MessageSource, worldStateSynchronizer, sequencer, proverNode, slasherClient, validatorsSentinel, epochPruneWatcher, l1ChainId, version, globalVariableBuilder, epochCache, packageVersion,
|
|
466
|
+
constructor(config, p2pClient, blockSource, logsSource, contractDataSource, l1ToL2MessageSource, worldStateSynchronizer, sequencer, proverNode, slasherClient, validatorsSentinel, epochPruneWatcher, l1ChainId, version, globalVariableBuilder, epochCache, packageVersion, peerProofVerifier, rpcProofVerifier, telemetry = getTelemetryClient(), log = createLogger('node'), blobClient, validatorClient, keyStoreManager, debugLogStore = new NullDebugLogStore()){
|
|
465
467
|
this.config = config;
|
|
466
468
|
this.p2pClient = p2pClient;
|
|
467
469
|
this.blockSource = blockSource;
|
|
@@ -479,7 +481,8 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
479
481
|
this.globalVariableBuilder = globalVariableBuilder;
|
|
480
482
|
this.epochCache = epochCache;
|
|
481
483
|
this.packageVersion = packageVersion;
|
|
482
|
-
this.
|
|
484
|
+
this.peerProofVerifier = peerProofVerifier;
|
|
485
|
+
this.rpcProofVerifier = rpcProofVerifier;
|
|
483
486
|
this.telemetry = telemetry;
|
|
484
487
|
this.log = log;
|
|
485
488
|
this.blobClient = blobClient;
|
|
@@ -499,6 +502,9 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
499
502
|
throw new Error('debugLogStore should never be enabled when realProofs are set');
|
|
500
503
|
}
|
|
501
504
|
}
|
|
505
|
+
/** @internal Exposed for testing — returns the RPC proof verifier. */ getProofVerifier() {
|
|
506
|
+
return this.rpcProofVerifier;
|
|
507
|
+
}
|
|
502
508
|
async getWorldStateSyncStatus() {
|
|
503
509
|
const status = await this.worldStateSynchronizer.status();
|
|
504
510
|
return status.syncSummary;
|
|
@@ -559,9 +565,9 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
559
565
|
}
|
|
560
566
|
const publicClient = createPublicClient({
|
|
561
567
|
chain: ethereumChain.chainInfo,
|
|
562
|
-
transport:
|
|
563
|
-
|
|
564
|
-
|
|
568
|
+
transport: makeL1HttpTransport(config.l1RpcUrls, {
|
|
569
|
+
timeout: config.l1HttpTimeoutMS
|
|
570
|
+
}),
|
|
565
571
|
pollingInterval: config.viemPollingIntervalMS
|
|
566
572
|
});
|
|
567
573
|
const l1ContractsAddresses = await RegistryContract.collectAddresses(publicClient, config.l1Contracts.registryAddress, config.rollupVersion ?? 'canonical');
|
|
@@ -597,7 +603,17 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
597
603
|
});
|
|
598
604
|
// now create the merkle trees and the world state synchronizer
|
|
599
605
|
const worldStateSynchronizer = await createWorldStateSynchronizer(config, archiver, options.prefilledPublicData, telemetry);
|
|
600
|
-
const
|
|
606
|
+
const useRealVerifiers = config.realProofs || config.debugForceTxProofVerification;
|
|
607
|
+
let peerProofVerifier;
|
|
608
|
+
let rpcProofVerifier;
|
|
609
|
+
if (useRealVerifiers) {
|
|
610
|
+
peerProofVerifier = await BatchChonkVerifier.new(config, config.bbChonkVerifyMaxBatch, 'peer');
|
|
611
|
+
const rpcVerifier = await BBCircuitVerifier.new(config);
|
|
612
|
+
rpcProofVerifier = new QueuedIVCVerifier(rpcVerifier, config.numConcurrentIVCVerifiers);
|
|
613
|
+
} else {
|
|
614
|
+
peerProofVerifier = new TestCircuitVerifier(config.proverTestVerificationDelayMs);
|
|
615
|
+
rpcProofVerifier = new TestCircuitVerifier(config.proverTestVerificationDelayMs);
|
|
616
|
+
}
|
|
601
617
|
let debugLogStore;
|
|
602
618
|
if (!config.realProofs) {
|
|
603
619
|
log.warn(`Aztec node is accepting fake proofs`);
|
|
@@ -606,13 +622,12 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
606
622
|
} else {
|
|
607
623
|
debugLogStore = new NullDebugLogStore();
|
|
608
624
|
}
|
|
609
|
-
const proofVerifier = new QueuedIVCVerifier(config, circuitVerifier);
|
|
610
625
|
const proverOnly = config.enableProverNode && config.disableValidator;
|
|
611
626
|
if (proverOnly) {
|
|
612
627
|
log.info('Starting in prover-only mode: skipping validator, sequencer, sentinel, and slasher subsystems');
|
|
613
628
|
}
|
|
614
629
|
// create the tx pool and the p2p client, which will need the l2 block source
|
|
615
|
-
const p2pClient = await createP2PClient(config, archiver,
|
|
630
|
+
const p2pClient = await createP2PClient(config, archiver, peerProofVerifier, worldStateSynchronizer, epochCache, packageVersion, dateProvider, telemetry, deps.p2pClientDeps);
|
|
616
631
|
// We'll accumulate sentinel watchers here
|
|
617
632
|
const watchers = [];
|
|
618
633
|
// Create FullNodeCheckpointsBuilder for block proposal handling and tx validation.
|
|
@@ -637,34 +652,40 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
637
652
|
blockSource: archiver,
|
|
638
653
|
l1ToL2MessageSource: archiver,
|
|
639
654
|
keyStoreManager,
|
|
640
|
-
blobClient
|
|
655
|
+
blobClient,
|
|
656
|
+
slashingProtectionDb: deps.slashingProtectionDb
|
|
641
657
|
});
|
|
642
658
|
// If we have a validator client, register it as a source of offenses for the slasher,
|
|
643
659
|
// and have it register callbacks on the p2p client *before* we start it, otherwise messages
|
|
644
660
|
// like attestations or auths will fail.
|
|
645
661
|
if (validatorClient) {
|
|
646
662
|
watchers.push(validatorClient);
|
|
663
|
+
const vc = validatorClient;
|
|
664
|
+
const getValidatorAddresses = ()=>vc.getValidatorAddresses().map((a)=>a.toString());
|
|
665
|
+
validatorClient.getProposalHandler().register(p2pClient, true, archiver, getValidatorAddresses);
|
|
647
666
|
if (!options.dontStartSequencer) {
|
|
648
667
|
await validatorClient.registerHandlers();
|
|
649
668
|
}
|
|
650
669
|
}
|
|
651
670
|
}
|
|
652
|
-
// If there's no validator client, create a
|
|
671
|
+
// If there's no validator client, create a ProposalHandler to handle block and checkpoint proposals
|
|
653
672
|
// for monitoring or reexecution. Reexecution (default) allows us to follow the pending chain,
|
|
654
673
|
// while non-reexecution is used for validating the proposals and collecting their txs.
|
|
674
|
+
// Checkpoint proposals rebuild blobs if the blob client can upload blobs.
|
|
655
675
|
if (!validatorClient) {
|
|
656
676
|
const reexecute = !!config.alwaysReexecuteBlockProposals;
|
|
657
|
-
log.info(`Setting up
|
|
658
|
-
|
|
677
|
+
log.info(`Setting up proposal handler` + (reexecute ? ' with reexecution of proposals' : ''));
|
|
678
|
+
createProposalHandler(config, {
|
|
659
679
|
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
660
680
|
worldState: worldStateSynchronizer,
|
|
661
681
|
epochCache,
|
|
662
682
|
blockSource: archiver,
|
|
663
683
|
l1ToL2MessageSource: archiver,
|
|
664
684
|
p2pClient,
|
|
685
|
+
blobClient,
|
|
665
686
|
dateProvider,
|
|
666
687
|
telemetry
|
|
667
|
-
}).register(p2pClient, reexecute);
|
|
688
|
+
}).register(p2pClient, reexecute, archiver);
|
|
668
689
|
}
|
|
669
690
|
// Start world state and wait for it to sync to the archiver.
|
|
670
691
|
await worldStateSynchronizer.start();
|
|
@@ -696,6 +717,13 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
696
717
|
await attestationsBlockWatcher?.start();
|
|
697
718
|
log.info(`All p2p services started`);
|
|
698
719
|
}).catch((err)=>log.error('Failed to start p2p services after archiver sync', err));
|
|
720
|
+
const globalVariableBuilder = new GlobalVariableBuilder(dateProvider, publicClient, {
|
|
721
|
+
l1Contracts: config.l1Contracts,
|
|
722
|
+
ethereumSlotDuration: config.ethereumSlotDuration,
|
|
723
|
+
rollupVersion: BigInt(config.rollupVersion),
|
|
724
|
+
l1GenesisTime,
|
|
725
|
+
slotDuration: Number(slotDuration)
|
|
726
|
+
});
|
|
699
727
|
// Validator enabled, create/start relevant service
|
|
700
728
|
let sequencer;
|
|
701
729
|
let slasherClient;
|
|
@@ -722,6 +750,22 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
722
750
|
dateProvider,
|
|
723
751
|
kzg: Blob.getViemKzgInstance()
|
|
724
752
|
});
|
|
753
|
+
// Create a funder L1TxUtils from the keystore funding account (if configured)
|
|
754
|
+
const fundingSigner = keyStoreManager?.createFundingSigner();
|
|
755
|
+
let funderL1TxUtils;
|
|
756
|
+
if (fundingSigner) {
|
|
757
|
+
const [funder] = await createL1TxUtilsFromSigners(publicClient, [
|
|
758
|
+
fundingSigner
|
|
759
|
+
], {
|
|
760
|
+
...config,
|
|
761
|
+
scope: 'sequencer'
|
|
762
|
+
}, {
|
|
763
|
+
telemetry,
|
|
764
|
+
logger: log.createChild('l1-tx-utils:funder'),
|
|
765
|
+
dateProvider
|
|
766
|
+
});
|
|
767
|
+
funderL1TxUtils = funder;
|
|
768
|
+
}
|
|
725
769
|
// Create and start the sequencer client
|
|
726
770
|
const checkpointsBuilder = new CheckpointsBuilder({
|
|
727
771
|
...config,
|
|
@@ -733,6 +777,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
733
777
|
...deps,
|
|
734
778
|
epochCache,
|
|
735
779
|
l1TxUtils,
|
|
780
|
+
funderL1TxUtils,
|
|
736
781
|
validatorClient,
|
|
737
782
|
p2pClient,
|
|
738
783
|
worldStateSynchronizer,
|
|
@@ -743,7 +788,8 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
743
788
|
telemetry,
|
|
744
789
|
dateProvider,
|
|
745
790
|
blobClient,
|
|
746
|
-
nodeKeyStore: keyStoreManager
|
|
791
|
+
nodeKeyStore: keyStoreManager,
|
|
792
|
+
globalVariableBuilder
|
|
747
793
|
});
|
|
748
794
|
}
|
|
749
795
|
if (!options.dontStartSequencer && sequencer) {
|
|
@@ -773,13 +819,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
773
819
|
log.info(`Prover node subsystem created but not started`);
|
|
774
820
|
}
|
|
775
821
|
}
|
|
776
|
-
const
|
|
777
|
-
...config,
|
|
778
|
-
rollupVersion: BigInt(config.rollupVersion),
|
|
779
|
-
l1GenesisTime,
|
|
780
|
-
slotDuration: Number(slotDuration)
|
|
781
|
-
});
|
|
782
|
-
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);
|
|
822
|
+
const node = new AztecNodeService(config, p2pClient, archiver, archiver, archiver, archiver, worldStateSynchronizer, sequencer, proverNode, slasherClient, validatorsSentinel, epochPruneWatcher, ethereumChain.chainInfo.id, config.rollupVersion, globalVariableBuilder, epochCache, packageVersion, peerProofVerifier, rpcProofVerifier, telemetry, log, blobClient, validatorClient, keyStoreManager, debugLogStore);
|
|
783
823
|
return node;
|
|
784
824
|
}
|
|
785
825
|
/**
|
|
@@ -891,6 +931,9 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
891
931
|
async getCheckpointedBlocks(from, limit) {
|
|
892
932
|
return await this.blockSource.getCheckpointedBlocks(from, limit) ?? [];
|
|
893
933
|
}
|
|
934
|
+
getCheckpointsDataForEpoch(epochNumber) {
|
|
935
|
+
return this.blockSource.getCheckpointsDataForEpoch(epochNumber);
|
|
936
|
+
}
|
|
894
937
|
/**
|
|
895
938
|
* Method to fetch the current min L2 fees.
|
|
896
939
|
* @returns The current min L2 fees.
|
|
@@ -946,28 +989,36 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
946
989
|
return this.contractDataSource.getContract(address);
|
|
947
990
|
}
|
|
948
991
|
async getPrivateLogsByTags(tags, page, referenceBlock) {
|
|
992
|
+
let upToBlockNumber;
|
|
949
993
|
if (referenceBlock) {
|
|
950
994
|
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
951
|
-
if (
|
|
995
|
+
if (referenceBlock.equals(initialBlockHash)) {
|
|
996
|
+
upToBlockNumber = BlockNumber(0);
|
|
997
|
+
} else {
|
|
952
998
|
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
953
999
|
if (!header) {
|
|
954
1000
|
throw new Error(`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`);
|
|
955
1001
|
}
|
|
1002
|
+
upToBlockNumber = header.globalVariables.blockNumber;
|
|
956
1003
|
}
|
|
957
1004
|
}
|
|
958
|
-
return this.logsSource.getPrivateLogsByTags(tags, page);
|
|
1005
|
+
return this.logsSource.getPrivateLogsByTags(tags, page, upToBlockNumber);
|
|
959
1006
|
}
|
|
960
1007
|
async getPublicLogsByTagsFromContract(contractAddress, tags, page, referenceBlock) {
|
|
1008
|
+
let upToBlockNumber;
|
|
961
1009
|
if (referenceBlock) {
|
|
962
1010
|
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
963
|
-
if (
|
|
1011
|
+
if (referenceBlock.equals(initialBlockHash)) {
|
|
1012
|
+
upToBlockNumber = BlockNumber(0);
|
|
1013
|
+
} else {
|
|
964
1014
|
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
965
1015
|
if (!header) {
|
|
966
1016
|
throw new Error(`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`);
|
|
967
1017
|
}
|
|
1018
|
+
upToBlockNumber = header.globalVariables.blockNumber;
|
|
968
1019
|
}
|
|
969
1020
|
}
|
|
970
|
-
return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page);
|
|
1021
|
+
return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page, upToBlockNumber);
|
|
971
1022
|
}
|
|
972
1023
|
/**
|
|
973
1024
|
* Gets public logs based on the provided filter.
|
|
@@ -1040,7 +1091,10 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1040
1091
|
await tryStop(this.validatorsSentinel);
|
|
1041
1092
|
await tryStop(this.epochPruneWatcher);
|
|
1042
1093
|
await tryStop(this.slasherClient);
|
|
1043
|
-
await
|
|
1094
|
+
await Promise.all([
|
|
1095
|
+
tryStop(this.peerProofVerifier),
|
|
1096
|
+
tryStop(this.rpcProofVerifier)
|
|
1097
|
+
]);
|
|
1044
1098
|
await tryStop(this.sequencer);
|
|
1045
1099
|
await tryStop(this.proverNode);
|
|
1046
1100
|
await tryStop(this.p2pClient);
|
|
@@ -1082,70 +1136,82 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1082
1136
|
return compactArray(await Promise.all(txHashes.map((txHash)=>this.getTxByHash(txHash))));
|
|
1083
1137
|
}
|
|
1084
1138
|
async findLeavesIndexes(referenceBlock, treeId, leafValues) {
|
|
1085
|
-
const committedDb = await this
|
|
1139
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1086
1140
|
const maybeIndices = await committedDb.findLeafIndices(treeId, leafValues.map((x)=>x.toBuffer()));
|
|
1087
|
-
//
|
|
1088
|
-
const
|
|
1089
|
-
// Now we find the block numbers for the indices
|
|
1090
|
-
const blockNumbers = await committedDb.getBlockNumbersForLeafIndices(treeId,
|
|
1091
|
-
//
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1141
|
+
// Filter out undefined values to query block numbers only for found leaves
|
|
1142
|
+
const definedIndices = maybeIndices.filter((x)=>x !== undefined);
|
|
1143
|
+
// Now we find the block numbers for the defined indices
|
|
1144
|
+
const blockNumbers = await committedDb.getBlockNumbersForLeafIndices(treeId, definedIndices);
|
|
1145
|
+
// Build a map from leaf index to block number
|
|
1146
|
+
const indexToBlockNumber = new Map();
|
|
1147
|
+
for(let i = 0; i < definedIndices.length; i++){
|
|
1148
|
+
const blockNumber = blockNumbers[i];
|
|
1149
|
+
if (blockNumber === undefined) {
|
|
1150
|
+
throw new Error(`Block number is undefined for leaf index ${definedIndices[i]} in tree ${MerkleTreeId[treeId]}`);
|
|
1095
1151
|
}
|
|
1152
|
+
indexToBlockNumber.set(definedIndices[i], blockNumber);
|
|
1096
1153
|
}
|
|
1097
1154
|
// Get unique block numbers in order to optimize num calls to getLeafValue function.
|
|
1098
1155
|
const uniqueBlockNumbers = [
|
|
1099
|
-
...new Set(
|
|
1156
|
+
...new Set(indexToBlockNumber.values())
|
|
1100
1157
|
];
|
|
1101
|
-
// Now we obtain the block hashes from the archive tree
|
|
1102
|
-
// (note that block number corresponds to the leaf index in the archive tree).
|
|
1158
|
+
// Now we obtain the block hashes from the archive tree (block number = leaf index in archive tree).
|
|
1103
1159
|
const blockHashes = await Promise.all(uniqueBlockNumbers.map((blockNumber)=>{
|
|
1104
1160
|
return committedDb.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
|
|
1105
1161
|
}));
|
|
1106
|
-
//
|
|
1162
|
+
// Build a map from block number to block hash
|
|
1163
|
+
const blockNumberToHash = new Map();
|
|
1107
1164
|
for(let i = 0; i < uniqueBlockNumbers.length; i++){
|
|
1108
|
-
|
|
1165
|
+
const blockHash = blockHashes[i];
|
|
1166
|
+
if (blockHash === undefined) {
|
|
1109
1167
|
throw new Error(`Block hash is undefined for block number ${uniqueBlockNumbers[i]}`);
|
|
1110
1168
|
}
|
|
1169
|
+
blockNumberToHash.set(uniqueBlockNumbers[i], blockHash);
|
|
1111
1170
|
}
|
|
1112
1171
|
// Create DataInBlock objects by combining indices, blockNumbers and blockHashes and return them.
|
|
1113
|
-
return maybeIndices.map((index
|
|
1172
|
+
return maybeIndices.map((index)=>{
|
|
1114
1173
|
if (index === undefined) {
|
|
1115
1174
|
return undefined;
|
|
1116
1175
|
}
|
|
1117
|
-
const blockNumber =
|
|
1176
|
+
const blockNumber = indexToBlockNumber.get(index);
|
|
1118
1177
|
if (blockNumber === undefined) {
|
|
1119
|
-
|
|
1178
|
+
throw new Error(`Block number not found for leaf index ${index} in tree ${MerkleTreeId[treeId]}`);
|
|
1120
1179
|
}
|
|
1121
|
-
const
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
return undefined;
|
|
1180
|
+
const blockHash = blockNumberToHash.get(blockNumber);
|
|
1181
|
+
if (blockHash === undefined) {
|
|
1182
|
+
throw new Error(`Block hash not found for block number ${blockNumber}`);
|
|
1125
1183
|
}
|
|
1126
1184
|
return {
|
|
1127
|
-
l2BlockNumber:
|
|
1185
|
+
l2BlockNumber: blockNumber,
|
|
1128
1186
|
l2BlockHash: new BlockHash(blockHash),
|
|
1129
1187
|
data: index
|
|
1130
1188
|
};
|
|
1131
1189
|
});
|
|
1132
1190
|
}
|
|
1133
1191
|
async getBlockHashMembershipWitness(referenceBlock, blockHash) {
|
|
1134
|
-
|
|
1192
|
+
// The Noir circuit checks the archive membership proof against `anchor_block_header.last_archive.root`,
|
|
1193
|
+
// which is the archive tree root BEFORE the anchor block was added (i.e. the state after block N-1).
|
|
1194
|
+
// So we need the world state at block N-1, not block N, to produce a sibling path matching that root.
|
|
1195
|
+
const referenceBlockNumber = await this.resolveBlockNumber(referenceBlock);
|
|
1196
|
+
if (referenceBlockNumber === BlockNumber.ZERO) {
|
|
1197
|
+
// Block 0 (the initial block) has an empty archive, so no membership witness can exist.
|
|
1198
|
+
return undefined;
|
|
1199
|
+
}
|
|
1200
|
+
const committedDb = await this.getWorldState(BlockNumber(referenceBlockNumber - 1));
|
|
1135
1201
|
const [pathAndIndex] = await committedDb.findSiblingPaths(MerkleTreeId.ARCHIVE, [
|
|
1136
1202
|
blockHash
|
|
1137
1203
|
]);
|
|
1138
1204
|
return pathAndIndex === undefined ? undefined : MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
1139
1205
|
}
|
|
1140
1206
|
async getNoteHashMembershipWitness(referenceBlock, noteHash) {
|
|
1141
|
-
const committedDb = await this
|
|
1207
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1142
1208
|
const [pathAndIndex] = await committedDb.findSiblingPaths(MerkleTreeId.NOTE_HASH_TREE, [
|
|
1143
1209
|
noteHash
|
|
1144
1210
|
]);
|
|
1145
1211
|
return pathAndIndex === undefined ? undefined : MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
1146
1212
|
}
|
|
1147
1213
|
async getL1ToL2MessageMembershipWitness(referenceBlock, l1ToL2Message) {
|
|
1148
|
-
const db = await this
|
|
1214
|
+
const db = await this.getWorldState(referenceBlock);
|
|
1149
1215
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [
|
|
1150
1216
|
l1ToL2Message
|
|
1151
1217
|
]);
|
|
@@ -1177,23 +1243,11 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1177
1243
|
*/ async getL2ToL1Messages(epoch) {
|
|
1178
1244
|
// Assumes `getCheckpointedBlocksForEpoch` returns blocks in ascending order of block number.
|
|
1179
1245
|
const checkpointedBlocks = await this.blockSource.getCheckpointedBlocksForEpoch(epoch);
|
|
1180
|
-
const blocksInCheckpoints =
|
|
1181
|
-
let previousSlotNumber = SlotNumber.ZERO;
|
|
1182
|
-
let checkpointIndex = -1;
|
|
1183
|
-
for (const checkpointedBlock of checkpointedBlocks){
|
|
1184
|
-
const block = checkpointedBlock.block;
|
|
1185
|
-
const slotNumber = block.header.globalVariables.slotNumber;
|
|
1186
|
-
if (slotNumber !== previousSlotNumber) {
|
|
1187
|
-
checkpointIndex++;
|
|
1188
|
-
blocksInCheckpoints.push([]);
|
|
1189
|
-
previousSlotNumber = slotNumber;
|
|
1190
|
-
}
|
|
1191
|
-
blocksInCheckpoints[checkpointIndex].push(block);
|
|
1192
|
-
}
|
|
1246
|
+
const blocksInCheckpoints = chunkBy(checkpointedBlocks, (cb)=>cb.block.header.globalVariables.slotNumber).map((group)=>group.map((cb)=>cb.block));
|
|
1193
1247
|
return blocksInCheckpoints.map((blocks)=>blocks.map((block)=>block.body.txEffects.map((txEffect)=>txEffect.l2ToL1Msgs)));
|
|
1194
1248
|
}
|
|
1195
1249
|
async getNullifierMembershipWitness(referenceBlock, nullifier) {
|
|
1196
|
-
const db = await this
|
|
1250
|
+
const db = await this.getWorldState(referenceBlock);
|
|
1197
1251
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [
|
|
1198
1252
|
nullifier.toBuffer()
|
|
1199
1253
|
]);
|
|
@@ -1207,36 +1261,22 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1207
1261
|
}
|
|
1208
1262
|
return new NullifierMembershipWitness(index, leafPreimage, path);
|
|
1209
1263
|
}
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
* @param referenceBlock - The block parameter (block number, block hash, or 'latest') at which to get the data
|
|
1213
|
-
* (which contains the root of the nullifier tree in which we are searching for the nullifier).
|
|
1214
|
-
* @param nullifier - Nullifier we try to find the low nullifier witness for.
|
|
1215
|
-
* @returns The low nullifier membership witness (if found).
|
|
1216
|
-
* @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
|
|
1217
|
-
* list structure" of leaves and proving that a lower nullifier is pointing to a bigger next value than the nullifier
|
|
1218
|
-
* we are trying to prove non-inclusion for.
|
|
1219
|
-
*
|
|
1220
|
-
* Note: This function returns the membership witness of the nullifier itself and not the low nullifier when
|
|
1221
|
-
* the nullifier already exists in the tree. This is because the `getPreviousValueIndex` function returns the
|
|
1222
|
-
* index of the nullifier itself when it already exists in the tree.
|
|
1223
|
-
* TODO: This is a confusing behavior and we should eventually address that.
|
|
1224
|
-
*/ async getLowNullifierMembershipWitness(referenceBlock, nullifier) {
|
|
1225
|
-
const committedDb = await this.#getWorldState(referenceBlock);
|
|
1264
|
+
async getLowNullifierMembershipWitness(referenceBlock, nullifier) {
|
|
1265
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1226
1266
|
const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
|
|
1227
1267
|
if (!findResult) {
|
|
1228
1268
|
return undefined;
|
|
1229
1269
|
}
|
|
1230
1270
|
const { index, alreadyPresent } = findResult;
|
|
1231
1271
|
if (alreadyPresent) {
|
|
1232
|
-
|
|
1272
|
+
throw new Error(`Cannot prove nullifier non-inclusion: nullifier ${nullifier.toBigInt()} already exists in the tree`);
|
|
1233
1273
|
}
|
|
1234
1274
|
const preimageData = await committedDb.getLeafPreimage(MerkleTreeId.NULLIFIER_TREE, index);
|
|
1235
1275
|
const siblingPath = await committedDb.getSiblingPath(MerkleTreeId.NULLIFIER_TREE, BigInt(index));
|
|
1236
1276
|
return new NullifierMembershipWitness(BigInt(index), preimageData, siblingPath);
|
|
1237
1277
|
}
|
|
1238
1278
|
async getPublicDataWitness(referenceBlock, leafSlot) {
|
|
1239
|
-
const committedDb = await this
|
|
1279
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1240
1280
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
1241
1281
|
if (!lowLeafResult) {
|
|
1242
1282
|
return undefined;
|
|
@@ -1247,7 +1287,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1247
1287
|
}
|
|
1248
1288
|
}
|
|
1249
1289
|
async getPublicStorageAt(referenceBlock, contract, slot) {
|
|
1250
|
-
const committedDb = await this
|
|
1290
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1251
1291
|
const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
|
|
1252
1292
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
1253
1293
|
if (!lowLeafResult || !lowLeafResult.alreadyPresent) {
|
|
@@ -1344,10 +1384,11 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1344
1384
|
}
|
|
1345
1385
|
async isValidTx(tx, { isSimulation, skipFeeEnforcement } = {}) {
|
|
1346
1386
|
const db = this.worldStateSynchronizer.getCommitted();
|
|
1347
|
-
const verifier = isSimulation ? undefined : this.
|
|
1387
|
+
const verifier = isSimulation ? undefined : this.rpcProofVerifier;
|
|
1348
1388
|
// We accept transactions if they are not expired by the next slot (checked based on the ExpirationTimestamp field)
|
|
1349
1389
|
const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
1350
1390
|
const blockNumber = BlockNumber(await this.blockSource.getBlockNumber() + 1);
|
|
1391
|
+
const l1Constants = await this.blockSource.getL1Constants();
|
|
1351
1392
|
const validator = createTxValidatorForAcceptingTxsOverRPC(db, this.contractDataSource, verifier, {
|
|
1352
1393
|
timestamp: nextSlotTimestamp,
|
|
1353
1394
|
blockNumber,
|
|
@@ -1359,7 +1400,10 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1359
1400
|
],
|
|
1360
1401
|
gasFees: await this.getCurrentMinFees(),
|
|
1361
1402
|
skipFeeEnforcement,
|
|
1362
|
-
txsPermitted: !this.config.disableTransactions
|
|
1403
|
+
txsPermitted: !this.config.disableTransactions,
|
|
1404
|
+
rollupManaLimit: l1Constants.rollupManaLimit,
|
|
1405
|
+
maxBlockL2Gas: this.config.validateMaxL2BlockGas,
|
|
1406
|
+
maxBlockDAGas: this.config.validateMaxDABlockGas
|
|
1363
1407
|
}, this.log.getBindings());
|
|
1364
1408
|
return await validator.validateTx(tx);
|
|
1365
1409
|
}
|
|
@@ -1382,7 +1426,18 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1382
1426
|
archiver.updateConfig(config);
|
|
1383
1427
|
}
|
|
1384
1428
|
if (newConfig.realProofs !== this.config.realProofs) {
|
|
1385
|
-
|
|
1429
|
+
await Promise.all([
|
|
1430
|
+
tryStop(this.peerProofVerifier),
|
|
1431
|
+
tryStop(this.rpcProofVerifier)
|
|
1432
|
+
]);
|
|
1433
|
+
if (newConfig.realProofs) {
|
|
1434
|
+
this.peerProofVerifier = await BatchChonkVerifier.new(newConfig, newConfig.bbChonkVerifyMaxBatch, 'peer');
|
|
1435
|
+
const rpcVerifier = await BBCircuitVerifier.new(newConfig);
|
|
1436
|
+
this.rpcProofVerifier = new QueuedIVCVerifier(rpcVerifier, newConfig.numConcurrentIVCVerifiers);
|
|
1437
|
+
} else {
|
|
1438
|
+
this.peerProofVerifier = new TestCircuitVerifier();
|
|
1439
|
+
this.rpcProofVerifier = new TestCircuitVerifier();
|
|
1440
|
+
}
|
|
1386
1441
|
}
|
|
1387
1442
|
this.config = newConfig;
|
|
1388
1443
|
}
|
|
@@ -1579,7 +1634,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1579
1634
|
* Returns an instance of MerkleTreeOperations having first ensured the world state is fully synched
|
|
1580
1635
|
* @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
|
|
1581
1636
|
* @returns An instance of a committed MerkleTreeOperations
|
|
1582
|
-
*/ async
|
|
1637
|
+
*/ async getWorldState(block) {
|
|
1583
1638
|
let blockSyncedTo = BlockNumber.ZERO;
|
|
1584
1639
|
try {
|
|
1585
1640
|
// Attempt to sync the world state if necessary
|
|
@@ -1591,6 +1646,8 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1591
1646
|
this.log.debug(`Using committed db for block 'latest', world state synced upto ${blockSyncedTo}`);
|
|
1592
1647
|
return this.worldStateSynchronizer.getCommitted();
|
|
1593
1648
|
}
|
|
1649
|
+
// Get the block number, either directly from the parameter or by quering the archiver with the block hash
|
|
1650
|
+
let blockNumber;
|
|
1594
1651
|
if (BlockHash.isBlockHash(block)) {
|
|
1595
1652
|
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1596
1653
|
if (block.equals(initialBlockHash)) {
|
|
@@ -1601,19 +1658,41 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1601
1658
|
if (!header) {
|
|
1602
1659
|
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.`);
|
|
1603
1660
|
}
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
}
|
|
1608
|
-
//
|
|
1609
|
-
{
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1661
|
+
blockNumber = header.getBlockNumber();
|
|
1662
|
+
} else {
|
|
1663
|
+
blockNumber = block;
|
|
1664
|
+
}
|
|
1665
|
+
// Check it's within world state sync range
|
|
1666
|
+
if (blockNumber > blockSyncedTo) {
|
|
1667
|
+
throw new Error(`Queried block ${block} not yet synced by the node (node is synced upto ${blockSyncedTo}).`);
|
|
1668
|
+
}
|
|
1669
|
+
this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1670
|
+
const snapshot = this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1671
|
+
// Double-check world-state synced to the same block hash as was requested
|
|
1672
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1673
|
+
const blockHash = await snapshot.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
|
|
1674
|
+
if (!blockHash || !new BlockHash(blockHash).equals(block)) {
|
|
1675
|
+
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.`);
|
|
1676
|
+
}
|
|
1677
|
+
}
|
|
1678
|
+
return snapshot;
|
|
1679
|
+
}
|
|
1680
|
+
/** Resolves a block parameter to a block number. */ async resolveBlockNumber(block) {
|
|
1681
|
+
if (block === 'latest') {
|
|
1682
|
+
return BlockNumber(await this.blockSource.getBlockNumber());
|
|
1683
|
+
}
|
|
1684
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1685
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1686
|
+
if (block.equals(initialBlockHash)) {
|
|
1687
|
+
return BlockNumber.ZERO;
|
|
1688
|
+
}
|
|
1689
|
+
const header = await this.blockSource.getBlockHeaderByHash(block);
|
|
1690
|
+
if (!header) {
|
|
1691
|
+
throw new Error(`Block hash ${block.toString()} not found.`);
|
|
1613
1692
|
}
|
|
1614
|
-
|
|
1615
|
-
return this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1693
|
+
return header.getBlockNumber();
|
|
1616
1694
|
}
|
|
1695
|
+
return block;
|
|
1617
1696
|
}
|
|
1618
1697
|
/**
|
|
1619
1698
|
* Ensure we fully sync the world state
|
|
@@ -48,7 +48,7 @@ export class Sentinel extends EventEmitter {
|
|
|
48
48
|
this.runningPromise.start();
|
|
49
49
|
}
|
|
50
50
|
/** Loads initial slot and initializes blockstream. We will not process anything at or before the initial slot. */ async init() {
|
|
51
|
-
this.initialSlot = this.epochCache.
|
|
51
|
+
this.initialSlot = this.epochCache.getSlotNow();
|
|
52
52
|
const startingBlock = BlockNumber(await this.archiver.getBlockNumber());
|
|
53
53
|
this.logger.info(`Starting validator sentinel with initial slot ${this.initialSlot} and block ${startingBlock}`);
|
|
54
54
|
this.blockStream = new L2BlockStream(this.archiver, this.l2TipsStore, this, this.logger, {
|
|
@@ -157,7 +157,7 @@ export class Sentinel extends EventEmitter {
|
|
|
157
157
|
return false;
|
|
158
158
|
}
|
|
159
159
|
// Check that we have at least requiredConsecutiveEpochs and that all of them are above the inactivity threshold
|
|
160
|
-
return pastEpochs.slice(0, requiredConsecutiveEpochs).every((p)=>p.missed / p.total >= this.config.slashInactivityTargetPercentage);
|
|
160
|
+
return pastEpochs.slice(0, requiredConsecutiveEpochs).every((p)=>p.total === 0 ? false : p.missed / p.total >= this.config.slashInactivityTargetPercentage);
|
|
161
161
|
}
|
|
162
162
|
async handleProvenPerformance(epoch, performance) {
|
|
163
163
|
if (this.config.slashInactivityPenalty === 0n) {
|
|
@@ -190,7 +190,7 @@ export class Sentinel extends EventEmitter {
|
|
|
190
190
|
* Note that we do not process historical data, since we rely on p2p data for processing,
|
|
191
191
|
* and we don't have that data if we were offline during the period.
|
|
192
192
|
*/ async work() {
|
|
193
|
-
const
|
|
193
|
+
const currentSlot = this.epochCache.getSlotNow();
|
|
194
194
|
try {
|
|
195
195
|
// Manually sync the block stream to ensure we have the latest data.
|
|
196
196
|
// Note we never `start` the blockstream, so it loops at the same pace as we do.
|
|
@@ -229,10 +229,10 @@ export class Sentinel extends EventEmitter {
|
|
|
229
229
|
this.logger.trace(`Refusing to process slot ${targetSlot} given initial slot ${this.initialSlot}`);
|
|
230
230
|
return false;
|
|
231
231
|
}
|
|
232
|
-
const
|
|
233
|
-
if (
|
|
232
|
+
const syncedSlot = await this.archiver.getSyncedL2SlotNumber();
|
|
233
|
+
if (syncedSlot === undefined || syncedSlot < targetSlot) {
|
|
234
234
|
this.logger.debug(`Waiting for archiver to sync with L2 slot ${targetSlot}`, {
|
|
235
|
-
|
|
235
|
+
syncedSlot,
|
|
236
236
|
targetSlot
|
|
237
237
|
});
|
|
238
238
|
return false;
|
|
@@ -351,7 +351,7 @@ export class Sentinel extends EventEmitter {
|
|
|
351
351
|
v.toString(),
|
|
352
352
|
await this.store.getHistory(v)
|
|
353
353
|
]))) : await this.store.getHistories();
|
|
354
|
-
const slotNow = this.epochCache.
|
|
354
|
+
const slotNow = this.epochCache.getSlotNow();
|
|
355
355
|
fromSlot ??= SlotNumber(Math.max((this.lastProcessedSlot ?? slotNow) - this.store.getHistoryLength(), 0));
|
|
356
356
|
toSlot ??= this.lastProcessedSlot ?? slotNow;
|
|
357
357
|
const stats = mapValues(histories, (history, address)=>this.computeStatsForValidator(address, history ?? [], fromSlot, toSlot));
|
|
@@ -367,7 +367,7 @@ export class Sentinel extends EventEmitter {
|
|
|
367
367
|
if (!history || history.length === 0) {
|
|
368
368
|
return undefined;
|
|
369
369
|
}
|
|
370
|
-
const slotNow = this.epochCache.
|
|
370
|
+
const slotNow = this.epochCache.getSlotNow();
|
|
371
371
|
const effectiveFromSlot = fromSlot ?? SlotNumber(Math.max((this.lastProcessedSlot ?? slotNow) - this.store.getHistoryLength(), 0));
|
|
372
372
|
const effectiveToSlot = toSlot ?? this.lastProcessedSlot ?? slotNow;
|
|
373
373
|
const historyLength = BigInt(this.store.getHistoryLength());
|