@aztec/aztec-node 0.0.1-commit.3895657bc → 0.0.1-commit.3a4ae741b
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 +171 -101
- package/dest/sentinel/sentinel.js +8 -8
- package/package.json +26 -27
- package/src/aztec-node/server.ts +171 -97
- 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';
|
|
@@ -413,7 +414,7 @@ import { getPackageVersion } from '@aztec/stdlib/update-checker';
|
|
|
413
414
|
import { Attributes, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
|
|
414
415
|
import { FullNodeCheckpointsBuilder as CheckpointsBuilder, FullNodeCheckpointsBuilder, NodeKeystoreAdapter, ValidatorClient, createBlockProposalHandler, 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,7 +652,8 @@ _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
|
|
@@ -696,6 +712,13 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
696
712
|
await attestationsBlockWatcher?.start();
|
|
697
713
|
log.info(`All p2p services started`);
|
|
698
714
|
}).catch((err)=>log.error('Failed to start p2p services after archiver sync', err));
|
|
715
|
+
const globalVariableBuilder = new GlobalVariableBuilder(dateProvider, publicClient, {
|
|
716
|
+
l1Contracts: config.l1Contracts,
|
|
717
|
+
ethereumSlotDuration: config.ethereumSlotDuration,
|
|
718
|
+
rollupVersion: BigInt(config.rollupVersion),
|
|
719
|
+
l1GenesisTime,
|
|
720
|
+
slotDuration: Number(slotDuration)
|
|
721
|
+
});
|
|
699
722
|
// Validator enabled, create/start relevant service
|
|
700
723
|
let sequencer;
|
|
701
724
|
let slasherClient;
|
|
@@ -722,6 +745,22 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
722
745
|
dateProvider,
|
|
723
746
|
kzg: Blob.getViemKzgInstance()
|
|
724
747
|
});
|
|
748
|
+
// Create a funder L1TxUtils from the keystore funding account (if configured)
|
|
749
|
+
const fundingSigner = keyStoreManager?.createFundingSigner();
|
|
750
|
+
let funderL1TxUtils;
|
|
751
|
+
if (fundingSigner) {
|
|
752
|
+
const [funder] = await createL1TxUtilsFromSigners(publicClient, [
|
|
753
|
+
fundingSigner
|
|
754
|
+
], {
|
|
755
|
+
...config,
|
|
756
|
+
scope: 'sequencer'
|
|
757
|
+
}, {
|
|
758
|
+
telemetry,
|
|
759
|
+
logger: log.createChild('l1-tx-utils:funder'),
|
|
760
|
+
dateProvider
|
|
761
|
+
});
|
|
762
|
+
funderL1TxUtils = funder;
|
|
763
|
+
}
|
|
725
764
|
// Create and start the sequencer client
|
|
726
765
|
const checkpointsBuilder = new CheckpointsBuilder({
|
|
727
766
|
...config,
|
|
@@ -733,6 +772,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
733
772
|
...deps,
|
|
734
773
|
epochCache,
|
|
735
774
|
l1TxUtils,
|
|
775
|
+
funderL1TxUtils,
|
|
736
776
|
validatorClient,
|
|
737
777
|
p2pClient,
|
|
738
778
|
worldStateSynchronizer,
|
|
@@ -743,7 +783,8 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
743
783
|
telemetry,
|
|
744
784
|
dateProvider,
|
|
745
785
|
blobClient,
|
|
746
|
-
nodeKeyStore: keyStoreManager
|
|
786
|
+
nodeKeyStore: keyStoreManager,
|
|
787
|
+
globalVariableBuilder
|
|
747
788
|
});
|
|
748
789
|
}
|
|
749
790
|
if (!options.dontStartSequencer && sequencer) {
|
|
@@ -773,13 +814,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
773
814
|
log.info(`Prover node subsystem created but not started`);
|
|
774
815
|
}
|
|
775
816
|
}
|
|
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);
|
|
817
|
+
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
818
|
return node;
|
|
784
819
|
}
|
|
785
820
|
/**
|
|
@@ -891,6 +926,9 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
891
926
|
async getCheckpointedBlocks(from, limit) {
|
|
892
927
|
return await this.blockSource.getCheckpointedBlocks(from, limit) ?? [];
|
|
893
928
|
}
|
|
929
|
+
getCheckpointsDataForEpoch(epochNumber) {
|
|
930
|
+
return this.blockSource.getCheckpointsDataForEpoch(epochNumber);
|
|
931
|
+
}
|
|
894
932
|
/**
|
|
895
933
|
* Method to fetch the current min L2 fees.
|
|
896
934
|
* @returns The current min L2 fees.
|
|
@@ -946,28 +984,36 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
946
984
|
return this.contractDataSource.getContract(address);
|
|
947
985
|
}
|
|
948
986
|
async getPrivateLogsByTags(tags, page, referenceBlock) {
|
|
987
|
+
let upToBlockNumber;
|
|
949
988
|
if (referenceBlock) {
|
|
950
989
|
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
951
|
-
if (
|
|
990
|
+
if (referenceBlock.equals(initialBlockHash)) {
|
|
991
|
+
upToBlockNumber = BlockNumber(0);
|
|
992
|
+
} else {
|
|
952
993
|
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
953
994
|
if (!header) {
|
|
954
995
|
throw new Error(`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`);
|
|
955
996
|
}
|
|
997
|
+
upToBlockNumber = header.globalVariables.blockNumber;
|
|
956
998
|
}
|
|
957
999
|
}
|
|
958
|
-
return this.logsSource.getPrivateLogsByTags(tags, page);
|
|
1000
|
+
return this.logsSource.getPrivateLogsByTags(tags, page, upToBlockNumber);
|
|
959
1001
|
}
|
|
960
1002
|
async getPublicLogsByTagsFromContract(contractAddress, tags, page, referenceBlock) {
|
|
1003
|
+
let upToBlockNumber;
|
|
961
1004
|
if (referenceBlock) {
|
|
962
1005
|
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
963
|
-
if (
|
|
1006
|
+
if (referenceBlock.equals(initialBlockHash)) {
|
|
1007
|
+
upToBlockNumber = BlockNumber(0);
|
|
1008
|
+
} else {
|
|
964
1009
|
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
965
1010
|
if (!header) {
|
|
966
1011
|
throw new Error(`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`);
|
|
967
1012
|
}
|
|
1013
|
+
upToBlockNumber = header.globalVariables.blockNumber;
|
|
968
1014
|
}
|
|
969
1015
|
}
|
|
970
|
-
return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page);
|
|
1016
|
+
return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page, upToBlockNumber);
|
|
971
1017
|
}
|
|
972
1018
|
/**
|
|
973
1019
|
* Gets public logs based on the provided filter.
|
|
@@ -1040,7 +1086,10 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1040
1086
|
await tryStop(this.validatorsSentinel);
|
|
1041
1087
|
await tryStop(this.epochPruneWatcher);
|
|
1042
1088
|
await tryStop(this.slasherClient);
|
|
1043
|
-
await
|
|
1089
|
+
await Promise.all([
|
|
1090
|
+
tryStop(this.peerProofVerifier),
|
|
1091
|
+
tryStop(this.rpcProofVerifier)
|
|
1092
|
+
]);
|
|
1044
1093
|
await tryStop(this.sequencer);
|
|
1045
1094
|
await tryStop(this.proverNode);
|
|
1046
1095
|
await tryStop(this.p2pClient);
|
|
@@ -1082,70 +1131,78 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1082
1131
|
return compactArray(await Promise.all(txHashes.map((txHash)=>this.getTxByHash(txHash))));
|
|
1083
1132
|
}
|
|
1084
1133
|
async findLeavesIndexes(referenceBlock, treeId, leafValues) {
|
|
1085
|
-
const committedDb = await this
|
|
1134
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1086
1135
|
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
|
-
|
|
1136
|
+
// Filter out undefined values to query block numbers only for found leaves
|
|
1137
|
+
const definedIndices = maybeIndices.filter((x)=>x !== undefined);
|
|
1138
|
+
// Now we find the block numbers for the defined indices
|
|
1139
|
+
const blockNumbers = await committedDb.getBlockNumbersForLeafIndices(treeId, definedIndices);
|
|
1140
|
+
// Build a map from leaf index to block number
|
|
1141
|
+
const indexToBlockNumber = new Map();
|
|
1142
|
+
for(let i = 0; i < definedIndices.length; i++){
|
|
1143
|
+
const blockNumber = blockNumbers[i];
|
|
1144
|
+
if (blockNumber === undefined) {
|
|
1145
|
+
throw new Error(`Block number is undefined for leaf index ${definedIndices[i]} in tree ${MerkleTreeId[treeId]}`);
|
|
1095
1146
|
}
|
|
1147
|
+
indexToBlockNumber.set(definedIndices[i], blockNumber);
|
|
1096
1148
|
}
|
|
1097
1149
|
// Get unique block numbers in order to optimize num calls to getLeafValue function.
|
|
1098
1150
|
const uniqueBlockNumbers = [
|
|
1099
|
-
...new Set(
|
|
1151
|
+
...new Set(indexToBlockNumber.values())
|
|
1100
1152
|
];
|
|
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).
|
|
1153
|
+
// Now we obtain the block hashes from the archive tree (block number = leaf index in archive tree).
|
|
1103
1154
|
const blockHashes = await Promise.all(uniqueBlockNumbers.map((blockNumber)=>{
|
|
1104
1155
|
return committedDb.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
|
|
1105
1156
|
}));
|
|
1106
|
-
//
|
|
1157
|
+
// Build a map from block number to block hash
|
|
1158
|
+
const blockNumberToHash = new Map();
|
|
1107
1159
|
for(let i = 0; i < uniqueBlockNumbers.length; i++){
|
|
1108
|
-
|
|
1160
|
+
const blockHash = blockHashes[i];
|
|
1161
|
+
if (blockHash === undefined) {
|
|
1109
1162
|
throw new Error(`Block hash is undefined for block number ${uniqueBlockNumbers[i]}`);
|
|
1110
1163
|
}
|
|
1164
|
+
blockNumberToHash.set(uniqueBlockNumbers[i], blockHash);
|
|
1111
1165
|
}
|
|
1112
1166
|
// Create DataInBlock objects by combining indices, blockNumbers and blockHashes and return them.
|
|
1113
|
-
return maybeIndices.map((index
|
|
1167
|
+
return maybeIndices.map((index)=>{
|
|
1114
1168
|
if (index === undefined) {
|
|
1115
1169
|
return undefined;
|
|
1116
1170
|
}
|
|
1117
|
-
const blockNumber =
|
|
1171
|
+
const blockNumber = indexToBlockNumber.get(index);
|
|
1118
1172
|
if (blockNumber === undefined) {
|
|
1119
|
-
|
|
1173
|
+
throw new Error(`Block number not found for leaf index ${index} in tree ${MerkleTreeId[treeId]}`);
|
|
1120
1174
|
}
|
|
1121
|
-
const
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
return undefined;
|
|
1175
|
+
const blockHash = blockNumberToHash.get(blockNumber);
|
|
1176
|
+
if (blockHash === undefined) {
|
|
1177
|
+
throw new Error(`Block hash not found for block number ${blockNumber}`);
|
|
1125
1178
|
}
|
|
1126
1179
|
return {
|
|
1127
|
-
l2BlockNumber:
|
|
1180
|
+
l2BlockNumber: blockNumber,
|
|
1128
1181
|
l2BlockHash: new BlockHash(blockHash),
|
|
1129
1182
|
data: index
|
|
1130
1183
|
};
|
|
1131
1184
|
});
|
|
1132
1185
|
}
|
|
1133
1186
|
async getBlockHashMembershipWitness(referenceBlock, blockHash) {
|
|
1134
|
-
|
|
1187
|
+
// The Noir circuit checks the archive membership proof against `anchor_block_header.last_archive.root`,
|
|
1188
|
+
// which is the archive tree root BEFORE the anchor block was added (i.e. the state after block N-1).
|
|
1189
|
+
// So we need the world state at block N-1, not block N, to produce a sibling path matching that root.
|
|
1190
|
+
const referenceBlockNumber = await this.resolveBlockNumber(referenceBlock);
|
|
1191
|
+
const committedDb = await this.getWorldState(BlockNumber(referenceBlockNumber - 1));
|
|
1135
1192
|
const [pathAndIndex] = await committedDb.findSiblingPaths(MerkleTreeId.ARCHIVE, [
|
|
1136
1193
|
blockHash
|
|
1137
1194
|
]);
|
|
1138
1195
|
return pathAndIndex === undefined ? undefined : MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
1139
1196
|
}
|
|
1140
1197
|
async getNoteHashMembershipWitness(referenceBlock, noteHash) {
|
|
1141
|
-
const committedDb = await this
|
|
1198
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1142
1199
|
const [pathAndIndex] = await committedDb.findSiblingPaths(MerkleTreeId.NOTE_HASH_TREE, [
|
|
1143
1200
|
noteHash
|
|
1144
1201
|
]);
|
|
1145
1202
|
return pathAndIndex === undefined ? undefined : MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
1146
1203
|
}
|
|
1147
1204
|
async getL1ToL2MessageMembershipWitness(referenceBlock, l1ToL2Message) {
|
|
1148
|
-
const db = await this
|
|
1205
|
+
const db = await this.getWorldState(referenceBlock);
|
|
1149
1206
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [
|
|
1150
1207
|
l1ToL2Message
|
|
1151
1208
|
]);
|
|
@@ -1177,23 +1234,11 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1177
1234
|
*/ async getL2ToL1Messages(epoch) {
|
|
1178
1235
|
// Assumes `getCheckpointedBlocksForEpoch` returns blocks in ascending order of block number.
|
|
1179
1236
|
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
|
-
}
|
|
1237
|
+
const blocksInCheckpoints = chunkBy(checkpointedBlocks, (cb)=>cb.block.header.globalVariables.slotNumber).map((group)=>group.map((cb)=>cb.block));
|
|
1193
1238
|
return blocksInCheckpoints.map((blocks)=>blocks.map((block)=>block.body.txEffects.map((txEffect)=>txEffect.l2ToL1Msgs)));
|
|
1194
1239
|
}
|
|
1195
1240
|
async getNullifierMembershipWitness(referenceBlock, nullifier) {
|
|
1196
|
-
const db = await this
|
|
1241
|
+
const db = await this.getWorldState(referenceBlock);
|
|
1197
1242
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [
|
|
1198
1243
|
nullifier.toBuffer()
|
|
1199
1244
|
]);
|
|
@@ -1207,36 +1252,22 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1207
1252
|
}
|
|
1208
1253
|
return new NullifierMembershipWitness(index, leafPreimage, path);
|
|
1209
1254
|
}
|
|
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);
|
|
1255
|
+
async getLowNullifierMembershipWitness(referenceBlock, nullifier) {
|
|
1256
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1226
1257
|
const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
|
|
1227
1258
|
if (!findResult) {
|
|
1228
1259
|
return undefined;
|
|
1229
1260
|
}
|
|
1230
1261
|
const { index, alreadyPresent } = findResult;
|
|
1231
1262
|
if (alreadyPresent) {
|
|
1232
|
-
|
|
1263
|
+
throw new Error(`Cannot prove nullifier non-inclusion: nullifier ${nullifier.toBigInt()} already exists in the tree`);
|
|
1233
1264
|
}
|
|
1234
1265
|
const preimageData = await committedDb.getLeafPreimage(MerkleTreeId.NULLIFIER_TREE, index);
|
|
1235
1266
|
const siblingPath = await committedDb.getSiblingPath(MerkleTreeId.NULLIFIER_TREE, BigInt(index));
|
|
1236
1267
|
return new NullifierMembershipWitness(BigInt(index), preimageData, siblingPath);
|
|
1237
1268
|
}
|
|
1238
1269
|
async getPublicDataWitness(referenceBlock, leafSlot) {
|
|
1239
|
-
const committedDb = await this
|
|
1270
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1240
1271
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
1241
1272
|
if (!lowLeafResult) {
|
|
1242
1273
|
return undefined;
|
|
@@ -1247,7 +1278,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1247
1278
|
}
|
|
1248
1279
|
}
|
|
1249
1280
|
async getPublicStorageAt(referenceBlock, contract, slot) {
|
|
1250
|
-
const committedDb = await this
|
|
1281
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1251
1282
|
const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
|
|
1252
1283
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
1253
1284
|
if (!lowLeafResult || !lowLeafResult.alreadyPresent) {
|
|
@@ -1344,10 +1375,11 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1344
1375
|
}
|
|
1345
1376
|
async isValidTx(tx, { isSimulation, skipFeeEnforcement } = {}) {
|
|
1346
1377
|
const db = this.worldStateSynchronizer.getCommitted();
|
|
1347
|
-
const verifier = isSimulation ? undefined : this.
|
|
1378
|
+
const verifier = isSimulation ? undefined : this.rpcProofVerifier;
|
|
1348
1379
|
// We accept transactions if they are not expired by the next slot (checked based on the ExpirationTimestamp field)
|
|
1349
1380
|
const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
1350
1381
|
const blockNumber = BlockNumber(await this.blockSource.getBlockNumber() + 1);
|
|
1382
|
+
const l1Constants = await this.blockSource.getL1Constants();
|
|
1351
1383
|
const validator = createTxValidatorForAcceptingTxsOverRPC(db, this.contractDataSource, verifier, {
|
|
1352
1384
|
timestamp: nextSlotTimestamp,
|
|
1353
1385
|
blockNumber,
|
|
@@ -1359,7 +1391,10 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1359
1391
|
],
|
|
1360
1392
|
gasFees: await this.getCurrentMinFees(),
|
|
1361
1393
|
skipFeeEnforcement,
|
|
1362
|
-
txsPermitted: !this.config.disableTransactions
|
|
1394
|
+
txsPermitted: !this.config.disableTransactions,
|
|
1395
|
+
rollupManaLimit: l1Constants.rollupManaLimit,
|
|
1396
|
+
maxBlockL2Gas: this.config.validateMaxL2BlockGas,
|
|
1397
|
+
maxBlockDAGas: this.config.validateMaxDABlockGas
|
|
1363
1398
|
}, this.log.getBindings());
|
|
1364
1399
|
return await validator.validateTx(tx);
|
|
1365
1400
|
}
|
|
@@ -1382,7 +1417,18 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1382
1417
|
archiver.updateConfig(config);
|
|
1383
1418
|
}
|
|
1384
1419
|
if (newConfig.realProofs !== this.config.realProofs) {
|
|
1385
|
-
|
|
1420
|
+
await Promise.all([
|
|
1421
|
+
tryStop(this.peerProofVerifier),
|
|
1422
|
+
tryStop(this.rpcProofVerifier)
|
|
1423
|
+
]);
|
|
1424
|
+
if (newConfig.realProofs) {
|
|
1425
|
+
this.peerProofVerifier = await BatchChonkVerifier.new(newConfig, newConfig.bbChonkVerifyMaxBatch, 'peer');
|
|
1426
|
+
const rpcVerifier = await BBCircuitVerifier.new(newConfig);
|
|
1427
|
+
this.rpcProofVerifier = new QueuedIVCVerifier(rpcVerifier, newConfig.numConcurrentIVCVerifiers);
|
|
1428
|
+
} else {
|
|
1429
|
+
this.peerProofVerifier = new TestCircuitVerifier();
|
|
1430
|
+
this.rpcProofVerifier = new TestCircuitVerifier();
|
|
1431
|
+
}
|
|
1386
1432
|
}
|
|
1387
1433
|
this.config = newConfig;
|
|
1388
1434
|
}
|
|
@@ -1579,7 +1625,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1579
1625
|
* Returns an instance of MerkleTreeOperations having first ensured the world state is fully synched
|
|
1580
1626
|
* @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
|
|
1581
1627
|
* @returns An instance of a committed MerkleTreeOperations
|
|
1582
|
-
*/ async
|
|
1628
|
+
*/ async getWorldState(block) {
|
|
1583
1629
|
let blockSyncedTo = BlockNumber.ZERO;
|
|
1584
1630
|
try {
|
|
1585
1631
|
// Attempt to sync the world state if necessary
|
|
@@ -1591,6 +1637,8 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1591
1637
|
this.log.debug(`Using committed db for block 'latest', world state synced upto ${blockSyncedTo}`);
|
|
1592
1638
|
return this.worldStateSynchronizer.getCommitted();
|
|
1593
1639
|
}
|
|
1640
|
+
// Get the block number, either directly from the parameter or by quering the archiver with the block hash
|
|
1641
|
+
let blockNumber;
|
|
1594
1642
|
if (BlockHash.isBlockHash(block)) {
|
|
1595
1643
|
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1596
1644
|
if (block.equals(initialBlockHash)) {
|
|
@@ -1601,19 +1649,41 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1601
1649
|
if (!header) {
|
|
1602
1650
|
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
1651
|
}
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
}
|
|
1608
|
-
//
|
|
1609
|
-
{
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1652
|
+
blockNumber = header.getBlockNumber();
|
|
1653
|
+
} else {
|
|
1654
|
+
blockNumber = block;
|
|
1655
|
+
}
|
|
1656
|
+
// Check it's within world state sync range
|
|
1657
|
+
if (blockNumber > blockSyncedTo) {
|
|
1658
|
+
throw new Error(`Queried block ${block} not yet synced by the node (node is synced upto ${blockSyncedTo}).`);
|
|
1659
|
+
}
|
|
1660
|
+
this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1661
|
+
const snapshot = this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1662
|
+
// Double-check world-state synced to the same block hash as was requested
|
|
1663
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1664
|
+
const blockHash = await snapshot.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
|
|
1665
|
+
if (!blockHash || !new BlockHash(blockHash).equals(block)) {
|
|
1666
|
+
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.`);
|
|
1667
|
+
}
|
|
1668
|
+
}
|
|
1669
|
+
return snapshot;
|
|
1670
|
+
}
|
|
1671
|
+
/** Resolves a block parameter to a block number. */ async resolveBlockNumber(block) {
|
|
1672
|
+
if (block === 'latest') {
|
|
1673
|
+
return BlockNumber(await this.blockSource.getBlockNumber());
|
|
1674
|
+
}
|
|
1675
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1676
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1677
|
+
if (block.equals(initialBlockHash)) {
|
|
1678
|
+
return BlockNumber.ZERO;
|
|
1679
|
+
}
|
|
1680
|
+
const header = await this.blockSource.getBlockHeaderByHash(block);
|
|
1681
|
+
if (!header) {
|
|
1682
|
+
throw new Error(`Block hash ${block.toString()} not found.`);
|
|
1613
1683
|
}
|
|
1614
|
-
|
|
1615
|
-
return this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1684
|
+
return header.getBlockNumber();
|
|
1616
1685
|
}
|
|
1686
|
+
return block;
|
|
1617
1687
|
}
|
|
1618
1688
|
/**
|
|
1619
1689
|
* 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());
|