@aztec/aztec-node 0.0.1-commit.343b43af6 → 0.0.1-commit.35158ae7e
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 +145 -79
- package/dest/sentinel/sentinel.js +5 -5
- package/package.json +26 -27
- package/src/aztec-node/server.ts +144 -76
- package/src/sentinel/sentinel.ts +5 -5
package/src/aztec-node/server.ts
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { Archiver, createArchiver } from '@aztec/archiver';
|
|
2
|
-
import { BBCircuitVerifier,
|
|
2
|
+
import { BBCircuitVerifier, BatchChonkVerifier, QueuedIVCVerifier } from '@aztec/bb-prover';
|
|
3
|
+
import { TestCircuitVerifier } from '@aztec/bb-prover/test';
|
|
3
4
|
import { type BlobClientInterface, createBlobClientWithFileStores } from '@aztec/blob-client/client';
|
|
4
5
|
import { Blob } from '@aztec/blob-lib';
|
|
5
6
|
import { ARCHIVE_HEIGHT, type L1_TO_L2_MSG_TREE_HEIGHT, type NOTE_HASH_TREE_HEIGHT } from '@aztec/constants';
|
|
6
7
|
import { EpochCache, type EpochCacheInterface } from '@aztec/epoch-cache';
|
|
7
8
|
import { createEthereumChain } from '@aztec/ethereum/chain';
|
|
8
|
-
import { getPublicClient } from '@aztec/ethereum/client';
|
|
9
|
+
import { getPublicClient, makeL1HttpTransport } from '@aztec/ethereum/client';
|
|
9
10
|
import { RegistryContract, RollupContract } from '@aztec/ethereum/contracts';
|
|
10
11
|
import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
|
|
12
|
+
import type { L1TxUtils } from '@aztec/ethereum/l1-tx-utils';
|
|
11
13
|
import { BlockNumber, CheckpointNumber, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
12
|
-
import { compactArray, pick, unique } from '@aztec/foundation/collection';
|
|
14
|
+
import { chunkBy, compactArray, pick, unique } from '@aztec/foundation/collection';
|
|
13
15
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
14
16
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
15
17
|
import { BadRequestError } from '@aztec/foundation/json-rpc';
|
|
@@ -111,9 +113,10 @@ import {
|
|
|
111
113
|
createBlockProposalHandler,
|
|
112
114
|
createValidatorClient,
|
|
113
115
|
} from '@aztec/validator-client';
|
|
116
|
+
import type { SlashingProtectionDatabase } from '@aztec/validator-ha-signer/types';
|
|
114
117
|
import { createWorldStateSynchronizer } from '@aztec/world-state';
|
|
115
118
|
|
|
116
|
-
import { createPublicClient
|
|
119
|
+
import { createPublicClient } from 'viem';
|
|
117
120
|
|
|
118
121
|
import { createSentinel } from '../sentinel/factory.js';
|
|
119
122
|
import { Sentinel } from '../sentinel/sentinel.js';
|
|
@@ -150,7 +153,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
150
153
|
protected readonly globalVariableBuilder: GlobalVariableBuilderInterface,
|
|
151
154
|
protected readonly epochCache: EpochCacheInterface,
|
|
152
155
|
protected readonly packageVersion: string,
|
|
153
|
-
private
|
|
156
|
+
private peerProofVerifier: ClientProtocolCircuitVerifier,
|
|
157
|
+
private rpcProofVerifier: ClientProtocolCircuitVerifier,
|
|
154
158
|
private telemetry: TelemetryClient = getTelemetryClient(),
|
|
155
159
|
private log = createLogger('node'),
|
|
156
160
|
private blobClient?: BlobClientInterface,
|
|
@@ -172,6 +176,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
172
176
|
}
|
|
173
177
|
}
|
|
174
178
|
|
|
179
|
+
/** @internal Exposed for testing — returns the RPC proof verifier. */
|
|
180
|
+
public getProofVerifier(): ClientProtocolCircuitVerifier {
|
|
181
|
+
return this.rpcProofVerifier;
|
|
182
|
+
}
|
|
183
|
+
|
|
175
184
|
public async getWorldStateSyncStatus(): Promise<WorldStateSyncStatus> {
|
|
176
185
|
const status = await this.worldStateSynchronizer.status();
|
|
177
186
|
return status.syncSummary;
|
|
@@ -195,6 +204,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
195
204
|
dateProvider?: DateProvider;
|
|
196
205
|
p2pClientDeps?: P2PClientDeps;
|
|
197
206
|
proverNodeDeps?: Partial<ProverNodeDeps>;
|
|
207
|
+
slashingProtectionDb?: SlashingProtectionDatabase;
|
|
198
208
|
} = {},
|
|
199
209
|
options: {
|
|
200
210
|
prefilledPublicData?: PublicDataTreeLeaf[];
|
|
@@ -257,7 +267,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
257
267
|
|
|
258
268
|
const publicClient = createPublicClient({
|
|
259
269
|
chain: ethereumChain.chainInfo,
|
|
260
|
-
transport:
|
|
270
|
+
transport: makeL1HttpTransport(config.l1RpcUrls, { timeout: config.l1HttpTimeoutMS }),
|
|
261
271
|
pollingInterval: config.viemPollingIntervalMS,
|
|
262
272
|
});
|
|
263
273
|
|
|
@@ -306,10 +316,17 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
306
316
|
options.prefilledPublicData,
|
|
307
317
|
telemetry,
|
|
308
318
|
);
|
|
309
|
-
const
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
319
|
+
const useRealVerifiers = config.realProofs || config.debugForceTxProofVerification;
|
|
320
|
+
let peerProofVerifier: ClientProtocolCircuitVerifier;
|
|
321
|
+
let rpcProofVerifier: ClientProtocolCircuitVerifier;
|
|
322
|
+
if (useRealVerifiers) {
|
|
323
|
+
peerProofVerifier = await BatchChonkVerifier.new(config, config.bbChonkVerifyMaxBatch, 'peer');
|
|
324
|
+
const rpcVerifier = await BBCircuitVerifier.new(config);
|
|
325
|
+
rpcProofVerifier = new QueuedIVCVerifier(rpcVerifier, config.numConcurrentIVCVerifiers);
|
|
326
|
+
} else {
|
|
327
|
+
peerProofVerifier = new TestCircuitVerifier(config.proverTestVerificationDelayMs);
|
|
328
|
+
rpcProofVerifier = new TestCircuitVerifier(config.proverTestVerificationDelayMs);
|
|
329
|
+
}
|
|
313
330
|
|
|
314
331
|
let debugLogStore: DebugLogStore;
|
|
315
332
|
if (!config.realProofs) {
|
|
@@ -323,8 +340,6 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
323
340
|
debugLogStore = new NullDebugLogStore();
|
|
324
341
|
}
|
|
325
342
|
|
|
326
|
-
const proofVerifier = new QueuedIVCVerifier(config, circuitVerifier);
|
|
327
|
-
|
|
328
343
|
const proverOnly = config.enableProverNode && config.disableValidator;
|
|
329
344
|
if (proverOnly) {
|
|
330
345
|
log.info('Starting in prover-only mode: skipping validator, sequencer, sentinel, and slasher subsystems');
|
|
@@ -334,7 +349,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
334
349
|
const p2pClient = await createP2PClient(
|
|
335
350
|
config,
|
|
336
351
|
archiver,
|
|
337
|
-
|
|
352
|
+
peerProofVerifier,
|
|
338
353
|
worldStateSynchronizer,
|
|
339
354
|
epochCache,
|
|
340
355
|
packageVersion,
|
|
@@ -377,6 +392,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
377
392
|
l1ToL2MessageSource: archiver,
|
|
378
393
|
keyStoreManager,
|
|
379
394
|
blobClient,
|
|
395
|
+
slashingProtectionDb: deps.slashingProtectionDb,
|
|
380
396
|
});
|
|
381
397
|
|
|
382
398
|
// If we have a validator client, register it as a source of offenses for the slasher,
|
|
@@ -455,6 +471,14 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
455
471
|
})
|
|
456
472
|
.catch(err => log.error('Failed to start p2p services after archiver sync', err));
|
|
457
473
|
|
|
474
|
+
const globalVariableBuilder = new GlobalVariableBuilder(dateProvider, publicClient, {
|
|
475
|
+
l1Contracts: config.l1Contracts,
|
|
476
|
+
ethereumSlotDuration: config.ethereumSlotDuration,
|
|
477
|
+
rollupVersion: BigInt(config.rollupVersion),
|
|
478
|
+
l1GenesisTime,
|
|
479
|
+
slotDuration: Number(slotDuration),
|
|
480
|
+
});
|
|
481
|
+
|
|
458
482
|
// Validator enabled, create/start relevant service
|
|
459
483
|
let sequencer: SequencerClient | undefined;
|
|
460
484
|
let slasherClient: SlasherClientInterface | undefined;
|
|
@@ -492,6 +516,19 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
492
516
|
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
|
|
493
517
|
);
|
|
494
518
|
|
|
519
|
+
// Create a funder L1TxUtils from the keystore funding account (if configured)
|
|
520
|
+
const fundingSigner = keyStoreManager?.createFundingSigner();
|
|
521
|
+
let funderL1TxUtils: L1TxUtils | undefined;
|
|
522
|
+
if (fundingSigner) {
|
|
523
|
+
const [funder] = await createL1TxUtilsFromSigners(
|
|
524
|
+
publicClient,
|
|
525
|
+
[fundingSigner],
|
|
526
|
+
{ ...config, scope: 'sequencer' },
|
|
527
|
+
{ telemetry, logger: log.createChild('l1-tx-utils:funder'), dateProvider },
|
|
528
|
+
);
|
|
529
|
+
funderL1TxUtils = funder;
|
|
530
|
+
}
|
|
531
|
+
|
|
495
532
|
// Create and start the sequencer client
|
|
496
533
|
const checkpointsBuilder = new CheckpointsBuilder(
|
|
497
534
|
{ ...config, l1GenesisTime, slotDuration: Number(slotDuration), rollupManaLimit },
|
|
@@ -506,6 +543,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
506
543
|
...deps,
|
|
507
544
|
epochCache,
|
|
508
545
|
l1TxUtils,
|
|
546
|
+
funderL1TxUtils,
|
|
509
547
|
validatorClient,
|
|
510
548
|
p2pClient,
|
|
511
549
|
worldStateSynchronizer,
|
|
@@ -517,6 +555,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
517
555
|
dateProvider,
|
|
518
556
|
blobClient,
|
|
519
557
|
nodeKeyStore: keyStoreManager!,
|
|
558
|
+
globalVariableBuilder,
|
|
520
559
|
});
|
|
521
560
|
}
|
|
522
561
|
|
|
@@ -550,13 +589,6 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
550
589
|
}
|
|
551
590
|
}
|
|
552
591
|
|
|
553
|
-
const globalVariableBuilder = new GlobalVariableBuilder({
|
|
554
|
-
...config,
|
|
555
|
-
rollupVersion: BigInt(config.rollupVersion),
|
|
556
|
-
l1GenesisTime,
|
|
557
|
-
slotDuration: Number(slotDuration),
|
|
558
|
-
});
|
|
559
|
-
|
|
560
592
|
const node = new AztecNodeService(
|
|
561
593
|
config,
|
|
562
594
|
p2pClient,
|
|
@@ -575,7 +607,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
575
607
|
globalVariableBuilder,
|
|
576
608
|
epochCache,
|
|
577
609
|
packageVersion,
|
|
578
|
-
|
|
610
|
+
peerProofVerifier,
|
|
611
|
+
rpcProofVerifier,
|
|
579
612
|
telemetry,
|
|
580
613
|
log,
|
|
581
614
|
blobClient,
|
|
@@ -720,6 +753,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
720
753
|
return (await this.blockSource.getCheckpointedBlocks(from, limit)) ?? [];
|
|
721
754
|
}
|
|
722
755
|
|
|
756
|
+
public getCheckpointsDataForEpoch(epochNumber: EpochNumber) {
|
|
757
|
+
return this.blockSource.getCheckpointsDataForEpoch(epochNumber);
|
|
758
|
+
}
|
|
759
|
+
|
|
723
760
|
/**
|
|
724
761
|
* Method to fetch the current min L2 fees.
|
|
725
762
|
* @returns The current min L2 fees.
|
|
@@ -793,18 +830,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
793
830
|
page?: number,
|
|
794
831
|
referenceBlock?: BlockHash,
|
|
795
832
|
): Promise<TxScopedL2Log[][]> {
|
|
833
|
+
let upToBlockNumber: BlockNumber | undefined;
|
|
796
834
|
if (referenceBlock) {
|
|
797
835
|
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
798
|
-
if (
|
|
836
|
+
if (referenceBlock.equals(initialBlockHash)) {
|
|
837
|
+
upToBlockNumber = BlockNumber(0);
|
|
838
|
+
} else {
|
|
799
839
|
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
800
840
|
if (!header) {
|
|
801
841
|
throw new Error(
|
|
802
842
|
`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
|
|
803
843
|
);
|
|
804
844
|
}
|
|
845
|
+
upToBlockNumber = header.globalVariables.blockNumber;
|
|
805
846
|
}
|
|
806
847
|
}
|
|
807
|
-
return this.logsSource.getPrivateLogsByTags(tags, page);
|
|
848
|
+
return this.logsSource.getPrivateLogsByTags(tags, page, upToBlockNumber);
|
|
808
849
|
}
|
|
809
850
|
|
|
810
851
|
public async getPublicLogsByTagsFromContract(
|
|
@@ -813,18 +854,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
813
854
|
page?: number,
|
|
814
855
|
referenceBlock?: BlockHash,
|
|
815
856
|
): Promise<TxScopedL2Log[][]> {
|
|
857
|
+
let upToBlockNumber: BlockNumber | undefined;
|
|
816
858
|
if (referenceBlock) {
|
|
817
859
|
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
818
|
-
if (
|
|
860
|
+
if (referenceBlock.equals(initialBlockHash)) {
|
|
861
|
+
upToBlockNumber = BlockNumber(0);
|
|
862
|
+
} else {
|
|
819
863
|
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
820
864
|
if (!header) {
|
|
821
865
|
throw new Error(
|
|
822
866
|
`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
|
|
823
867
|
);
|
|
824
868
|
}
|
|
869
|
+
upToBlockNumber = header.globalVariables.blockNumber;
|
|
825
870
|
}
|
|
826
871
|
}
|
|
827
|
-
return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page);
|
|
872
|
+
return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page, upToBlockNumber);
|
|
828
873
|
}
|
|
829
874
|
|
|
830
875
|
/**
|
|
@@ -910,7 +955,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
910
955
|
await tryStop(this.validatorsSentinel);
|
|
911
956
|
await tryStop(this.epochPruneWatcher);
|
|
912
957
|
await tryStop(this.slasherClient);
|
|
913
|
-
await tryStop(this.
|
|
958
|
+
await Promise.all([tryStop(this.peerProofVerifier), tryStop(this.rpcProofVerifier)]);
|
|
914
959
|
await tryStop(this.sequencer);
|
|
915
960
|
await tryStop(this.proverNode);
|
|
916
961
|
await tryStop(this.p2pClient);
|
|
@@ -966,7 +1011,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
966
1011
|
treeId: MerkleTreeId,
|
|
967
1012
|
leafValues: Fr[],
|
|
968
1013
|
): Promise<(DataInBlock<bigint> | undefined)[]> {
|
|
969
|
-
const committedDb = await this
|
|
1014
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
970
1015
|
const maybeIndices = await committedDb.findLeafIndices(
|
|
971
1016
|
treeId,
|
|
972
1017
|
leafValues.map(x => x.toBuffer()),
|
|
@@ -1034,7 +1079,15 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1034
1079
|
referenceBlock: BlockParameter,
|
|
1035
1080
|
blockHash: BlockHash,
|
|
1036
1081
|
): Promise<MembershipWitness<typeof ARCHIVE_HEIGHT> | undefined> {
|
|
1037
|
-
|
|
1082
|
+
// The Noir circuit checks the archive membership proof against `anchor_block_header.last_archive.root`,
|
|
1083
|
+
// which is the archive tree root BEFORE the anchor block was added (i.e. the state after block N-1).
|
|
1084
|
+
// So we need the world state at block N-1, not block N, to produce a sibling path matching that root.
|
|
1085
|
+
const referenceBlockNumber = await this.resolveBlockNumber(referenceBlock);
|
|
1086
|
+
if (referenceBlockNumber === BlockNumber.ZERO) {
|
|
1087
|
+
// Block 0 (the initial block) has an empty archive, so no membership witness can exist.
|
|
1088
|
+
return undefined;
|
|
1089
|
+
}
|
|
1090
|
+
const committedDb = await this.getWorldState(BlockNumber(referenceBlockNumber - 1));
|
|
1038
1091
|
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.ARCHIVE>(MerkleTreeId.ARCHIVE, [blockHash]);
|
|
1039
1092
|
return pathAndIndex === undefined
|
|
1040
1093
|
? undefined
|
|
@@ -1045,7 +1098,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1045
1098
|
referenceBlock: BlockParameter,
|
|
1046
1099
|
noteHash: Fr,
|
|
1047
1100
|
): Promise<MembershipWitness<typeof NOTE_HASH_TREE_HEIGHT> | undefined> {
|
|
1048
|
-
const committedDb = await this
|
|
1101
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1049
1102
|
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.NOTE_HASH_TREE>(
|
|
1050
1103
|
MerkleTreeId.NOTE_HASH_TREE,
|
|
1051
1104
|
[noteHash],
|
|
@@ -1059,7 +1112,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1059
1112
|
referenceBlock: BlockParameter,
|
|
1060
1113
|
l1ToL2Message: Fr,
|
|
1061
1114
|
): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>] | undefined> {
|
|
1062
|
-
const db = await this
|
|
1115
|
+
const db = await this.getWorldState(referenceBlock);
|
|
1063
1116
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [l1ToL2Message]);
|
|
1064
1117
|
if (!witness) {
|
|
1065
1118
|
return undefined;
|
|
@@ -1092,19 +1145,9 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1092
1145
|
public async getL2ToL1Messages(epoch: EpochNumber): Promise<Fr[][][][]> {
|
|
1093
1146
|
// Assumes `getCheckpointedBlocksForEpoch` returns blocks in ascending order of block number.
|
|
1094
1147
|
const checkpointedBlocks = await this.blockSource.getCheckpointedBlocksForEpoch(epoch);
|
|
1095
|
-
const blocksInCheckpoints
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
for (const checkpointedBlock of checkpointedBlocks) {
|
|
1099
|
-
const block = checkpointedBlock.block;
|
|
1100
|
-
const slotNumber = block.header.globalVariables.slotNumber;
|
|
1101
|
-
if (slotNumber !== previousSlotNumber) {
|
|
1102
|
-
checkpointIndex++;
|
|
1103
|
-
blocksInCheckpoints.push([]);
|
|
1104
|
-
previousSlotNumber = slotNumber;
|
|
1105
|
-
}
|
|
1106
|
-
blocksInCheckpoints[checkpointIndex].push(block);
|
|
1107
|
-
}
|
|
1148
|
+
const blocksInCheckpoints = chunkBy(checkpointedBlocks, cb => cb.block.header.globalVariables.slotNumber).map(
|
|
1149
|
+
group => group.map(cb => cb.block),
|
|
1150
|
+
);
|
|
1108
1151
|
return blocksInCheckpoints.map(blocks =>
|
|
1109
1152
|
blocks.map(block => block.body.txEffects.map(txEffect => txEffect.l2ToL1Msgs)),
|
|
1110
1153
|
);
|
|
@@ -1114,7 +1157,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1114
1157
|
referenceBlock: BlockParameter,
|
|
1115
1158
|
nullifier: Fr,
|
|
1116
1159
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
1117
|
-
const db = await this
|
|
1160
|
+
const db = await this.getWorldState(referenceBlock);
|
|
1118
1161
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [nullifier.toBuffer()]);
|
|
1119
1162
|
if (!witness) {
|
|
1120
1163
|
return undefined;
|
|
@@ -1129,33 +1172,20 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1129
1172
|
return new NullifierMembershipWitness(index, leafPreimage as NullifierLeafPreimage, path);
|
|
1130
1173
|
}
|
|
1131
1174
|
|
|
1132
|
-
/**
|
|
1133
|
-
* Returns a low nullifier membership witness for a given nullifier at a given block.
|
|
1134
|
-
* @param referenceBlock - The block parameter (block number, block hash, or 'latest') at which to get the data
|
|
1135
|
-
* (which contains the root of the nullifier tree in which we are searching for the nullifier).
|
|
1136
|
-
* @param nullifier - Nullifier we try to find the low nullifier witness for.
|
|
1137
|
-
* @returns The low nullifier membership witness (if found).
|
|
1138
|
-
* @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
|
|
1139
|
-
* list structure" of leaves and proving that a lower nullifier is pointing to a bigger next value than the nullifier
|
|
1140
|
-
* we are trying to prove non-inclusion for.
|
|
1141
|
-
*
|
|
1142
|
-
* Note: This function returns the membership witness of the nullifier itself and not the low nullifier when
|
|
1143
|
-
* the nullifier already exists in the tree. This is because the `getPreviousValueIndex` function returns the
|
|
1144
|
-
* index of the nullifier itself when it already exists in the tree.
|
|
1145
|
-
* TODO: This is a confusing behavior and we should eventually address that.
|
|
1146
|
-
*/
|
|
1147
1175
|
public async getLowNullifierMembershipWitness(
|
|
1148
1176
|
referenceBlock: BlockParameter,
|
|
1149
1177
|
nullifier: Fr,
|
|
1150
1178
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
1151
|
-
const committedDb = await this
|
|
1179
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1152
1180
|
const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
|
|
1153
1181
|
if (!findResult) {
|
|
1154
1182
|
return undefined;
|
|
1155
1183
|
}
|
|
1156
1184
|
const { index, alreadyPresent } = findResult;
|
|
1157
1185
|
if (alreadyPresent) {
|
|
1158
|
-
|
|
1186
|
+
throw new Error(
|
|
1187
|
+
`Cannot prove nullifier non-inclusion: nullifier ${nullifier.toBigInt()} already exists in the tree`,
|
|
1188
|
+
);
|
|
1159
1189
|
}
|
|
1160
1190
|
const preimageData = (await committedDb.getLeafPreimage(MerkleTreeId.NULLIFIER_TREE, index))!;
|
|
1161
1191
|
|
|
@@ -1164,7 +1194,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1164
1194
|
}
|
|
1165
1195
|
|
|
1166
1196
|
async getPublicDataWitness(referenceBlock: BlockParameter, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
|
|
1167
|
-
const committedDb = await this
|
|
1197
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1168
1198
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
1169
1199
|
if (!lowLeafResult) {
|
|
1170
1200
|
return undefined;
|
|
@@ -1179,7 +1209,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1179
1209
|
}
|
|
1180
1210
|
|
|
1181
1211
|
public async getPublicStorageAt(referenceBlock: BlockParameter, contract: AztecAddress, slot: Fr): Promise<Fr> {
|
|
1182
|
-
const committedDb = await this
|
|
1212
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1183
1213
|
const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
|
|
1184
1214
|
|
|
1185
1215
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
@@ -1319,7 +1349,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1319
1349
|
{ isSimulation, skipFeeEnforcement }: { isSimulation?: boolean; skipFeeEnforcement?: boolean } = {},
|
|
1320
1350
|
): Promise<TxValidationResult> {
|
|
1321
1351
|
const db = this.worldStateSynchronizer.getCommitted();
|
|
1322
|
-
const verifier = isSimulation ? undefined : this.
|
|
1352
|
+
const verifier = isSimulation ? undefined : this.rpcProofVerifier;
|
|
1323
1353
|
|
|
1324
1354
|
// We accept transactions if they are not expired by the next slot (checked based on the ExpirationTimestamp field)
|
|
1325
1355
|
const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
@@ -1368,7 +1398,15 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1368
1398
|
archiver.updateConfig(config);
|
|
1369
1399
|
}
|
|
1370
1400
|
if (newConfig.realProofs !== this.config.realProofs) {
|
|
1371
|
-
|
|
1401
|
+
await Promise.all([tryStop(this.peerProofVerifier), tryStop(this.rpcProofVerifier)]);
|
|
1402
|
+
if (newConfig.realProofs) {
|
|
1403
|
+
this.peerProofVerifier = await BatchChonkVerifier.new(newConfig, newConfig.bbChonkVerifyMaxBatch, 'peer');
|
|
1404
|
+
const rpcVerifier = await BBCircuitVerifier.new(newConfig);
|
|
1405
|
+
this.rpcProofVerifier = new QueuedIVCVerifier(rpcVerifier, newConfig.numConcurrentIVCVerifiers);
|
|
1406
|
+
} else {
|
|
1407
|
+
this.peerProofVerifier = new TestCircuitVerifier();
|
|
1408
|
+
this.rpcProofVerifier = new TestCircuitVerifier();
|
|
1409
|
+
}
|
|
1372
1410
|
}
|
|
1373
1411
|
|
|
1374
1412
|
this.config = newConfig;
|
|
@@ -1610,7 +1648,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1610
1648
|
* @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
|
|
1611
1649
|
* @returns An instance of a committed MerkleTreeOperations
|
|
1612
1650
|
*/
|
|
1613
|
-
async
|
|
1651
|
+
protected async getWorldState(block: BlockParameter) {
|
|
1614
1652
|
let blockSyncedTo: BlockNumber = BlockNumber.ZERO;
|
|
1615
1653
|
try {
|
|
1616
1654
|
// Attempt to sync the world state if necessary
|
|
@@ -1624,6 +1662,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1624
1662
|
return this.worldStateSynchronizer.getCommitted();
|
|
1625
1663
|
}
|
|
1626
1664
|
|
|
1665
|
+
// Get the block number, either directly from the parameter or by quering the archiver with the block hash
|
|
1666
|
+
let blockNumber: BlockNumber;
|
|
1627
1667
|
if (BlockHash.isBlockHash(block)) {
|
|
1628
1668
|
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1629
1669
|
if (block.equals(initialBlockHash)) {
|
|
@@ -1637,22 +1677,50 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1637
1677
|
`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.`,
|
|
1638
1678
|
);
|
|
1639
1679
|
}
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1680
|
+
|
|
1681
|
+
blockNumber = header.getBlockNumber();
|
|
1682
|
+
} else {
|
|
1683
|
+
blockNumber = block as BlockNumber;
|
|
1684
|
+
}
|
|
1685
|
+
|
|
1686
|
+
// Check it's within world state sync range
|
|
1687
|
+
if (blockNumber > blockSyncedTo) {
|
|
1688
|
+
throw new Error(`Queried block ${block} not yet synced by the node (node is synced upto ${blockSyncedTo}).`);
|
|
1643
1689
|
}
|
|
1690
|
+
this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1644
1691
|
|
|
1645
|
-
|
|
1646
|
-
{
|
|
1647
|
-
const blockNumber = block as BlockNumber;
|
|
1692
|
+
const snapshot = this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1648
1693
|
|
|
1649
|
-
|
|
1650
|
-
|
|
1694
|
+
// Double-check world-state synced to the same block hash as was requested
|
|
1695
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1696
|
+
const blockHash = await snapshot.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
|
|
1697
|
+
if (!blockHash || !new BlockHash(blockHash).equals(block)) {
|
|
1698
|
+
throw new Error(
|
|
1699
|
+
`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.`,
|
|
1700
|
+
);
|
|
1651
1701
|
}
|
|
1702
|
+
}
|
|
1703
|
+
|
|
1704
|
+
return snapshot;
|
|
1705
|
+
}
|
|
1652
1706
|
|
|
1653
|
-
|
|
1654
|
-
|
|
1707
|
+
/** Resolves a block parameter to a block number. */
|
|
1708
|
+
protected async resolveBlockNumber(block: BlockParameter): Promise<BlockNumber> {
|
|
1709
|
+
if (block === 'latest') {
|
|
1710
|
+
return BlockNumber(await this.blockSource.getBlockNumber());
|
|
1711
|
+
}
|
|
1712
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1713
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1714
|
+
if (block.equals(initialBlockHash)) {
|
|
1715
|
+
return BlockNumber.ZERO;
|
|
1716
|
+
}
|
|
1717
|
+
const header = await this.blockSource.getBlockHeaderByHash(block);
|
|
1718
|
+
if (!header) {
|
|
1719
|
+
throw new Error(`Block hash ${block.toString()} not found.`);
|
|
1720
|
+
}
|
|
1721
|
+
return header.getBlockNumber();
|
|
1655
1722
|
}
|
|
1723
|
+
return block as BlockNumber;
|
|
1656
1724
|
}
|
|
1657
1725
|
|
|
1658
1726
|
/**
|
package/src/sentinel/sentinel.ts
CHANGED
|
@@ -88,7 +88,7 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
|
|
|
88
88
|
|
|
89
89
|
/** Loads initial slot and initializes blockstream. We will not process anything at or before the initial slot. */
|
|
90
90
|
protected async init() {
|
|
91
|
-
this.initialSlot = this.epochCache.
|
|
91
|
+
this.initialSlot = this.epochCache.getSlotNow();
|
|
92
92
|
const startingBlock = BlockNumber(await this.archiver.getBlockNumber());
|
|
93
93
|
this.logger.info(`Starting validator sentinel with initial slot ${this.initialSlot} and block ${startingBlock}`);
|
|
94
94
|
this.blockStream = new L2BlockStream(this.archiver, this.l2TipsStore, this, this.logger, { startingBlock });
|
|
@@ -219,7 +219,7 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
|
|
|
219
219
|
// Check that we have at least requiredConsecutiveEpochs and that all of them are above the inactivity threshold
|
|
220
220
|
return pastEpochs
|
|
221
221
|
.slice(0, requiredConsecutiveEpochs)
|
|
222
|
-
.every(p => p.missed / p.total >= this.config.slashInactivityTargetPercentage);
|
|
222
|
+
.every(p => (p.total === 0 ? false : p.missed / p.total >= this.config.slashInactivityTargetPercentage));
|
|
223
223
|
}
|
|
224
224
|
|
|
225
225
|
protected async handleProvenPerformance(epoch: EpochNumber, performance: ValidatorsEpochPerformance) {
|
|
@@ -264,7 +264,7 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
|
|
|
264
264
|
* and we don't have that data if we were offline during the period.
|
|
265
265
|
*/
|
|
266
266
|
public async work() {
|
|
267
|
-
const
|
|
267
|
+
const currentSlot = this.epochCache.getSlotNow();
|
|
268
268
|
try {
|
|
269
269
|
// Manually sync the block stream to ensure we have the latest data.
|
|
270
270
|
// Note we never `start` the blockstream, so it loops at the same pace as we do.
|
|
@@ -436,7 +436,7 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
|
|
|
436
436
|
? fromEntries(await Promise.all(validators.map(async v => [v.toString(), await this.store.getHistory(v)])))
|
|
437
437
|
: await this.store.getHistories();
|
|
438
438
|
|
|
439
|
-
const slotNow = this.epochCache.
|
|
439
|
+
const slotNow = this.epochCache.getSlotNow();
|
|
440
440
|
fromSlot ??= SlotNumber(Math.max((this.lastProcessedSlot ?? slotNow) - this.store.getHistoryLength(), 0));
|
|
441
441
|
toSlot ??= this.lastProcessedSlot ?? slotNow;
|
|
442
442
|
|
|
@@ -464,7 +464,7 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
|
|
|
464
464
|
return undefined;
|
|
465
465
|
}
|
|
466
466
|
|
|
467
|
-
const slotNow = this.epochCache.
|
|
467
|
+
const slotNow = this.epochCache.getSlotNow();
|
|
468
468
|
const effectiveFromSlot =
|
|
469
469
|
fromSlot ?? SlotNumber(Math.max((this.lastProcessedSlot ?? slotNow) - this.store.getHistoryLength(), 0));
|
|
470
470
|
const effectiveToSlot = toSlot ?? this.lastProcessedSlot ?? slotNow;
|