@aztec/aztec-node 0.0.1-commit.96bb3f7 → 0.0.1-commit.9d2bcf6d
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/node_metrics.d.ts +1 -1
- package/dest/aztec-node/node_metrics.d.ts.map +1 -1
- package/dest/aztec-node/node_metrics.js +8 -4
- package/dest/aztec-node/server.d.ts +25 -92
- package/dest/aztec-node/server.d.ts.map +1 -1
- package/dest/aztec-node/server.js +149 -158
- package/dest/sentinel/factory.d.ts +1 -1
- package/dest/sentinel/factory.d.ts.map +1 -1
- package/dest/sentinel/factory.js +1 -1
- package/dest/sentinel/sentinel.js +1 -1
- package/dest/sentinel/store.d.ts +2 -2
- package/dest/sentinel/store.d.ts.map +1 -1
- package/package.json +26 -25
- package/src/aztec-node/node_metrics.ts +12 -5
- package/src/aztec-node/server.ts +192 -221
- package/src/sentinel/factory.ts +1 -6
- package/src/sentinel/sentinel.ts +1 -1
package/src/aztec-node/server.ts
CHANGED
|
@@ -1,14 +1,7 @@
|
|
|
1
1
|
import { Archiver, createArchiver } from '@aztec/archiver';
|
|
2
2
|
import { BBCircuitVerifier, QueuedIVCVerifier, TestCircuitVerifier } from '@aztec/bb-prover';
|
|
3
3
|
import { type BlobClientInterface, createBlobClientWithFileStores } from '@aztec/blob-client/client';
|
|
4
|
-
import {
|
|
5
|
-
ARCHIVE_HEIGHT,
|
|
6
|
-
INITIAL_L2_BLOCK_NUM,
|
|
7
|
-
type L1_TO_L2_MSG_TREE_HEIGHT,
|
|
8
|
-
type NOTE_HASH_TREE_HEIGHT,
|
|
9
|
-
type NULLIFIER_TREE_HEIGHT,
|
|
10
|
-
type PUBLIC_DATA_TREE_HEIGHT,
|
|
11
|
-
} from '@aztec/constants';
|
|
4
|
+
import { ARCHIVE_HEIGHT, type L1_TO_L2_MSG_TREE_HEIGHT, type NOTE_HASH_TREE_HEIGHT } from '@aztec/constants';
|
|
12
5
|
import { EpochCache, type EpochCacheInterface } from '@aztec/epoch-cache';
|
|
13
6
|
import { createEthereumChain } from '@aztec/ethereum/chain';
|
|
14
7
|
import { getPublicClient } from '@aztec/ethereum/client';
|
|
@@ -31,7 +24,7 @@ import {
|
|
|
31
24
|
} from '@aztec/node-lib/factories';
|
|
32
25
|
import { type P2P, type P2PClientDeps, createP2PClient, getDefaultAllowedSetupFunctions } from '@aztec/p2p';
|
|
33
26
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
34
|
-
import {
|
|
27
|
+
import { GlobalVariableBuilder, SequencerClient, type SequencerPublisher } from '@aztec/sequencer-client';
|
|
35
28
|
import { PublicProcessorFactory } from '@aztec/simulator/server';
|
|
36
29
|
import {
|
|
37
30
|
AttestationsBlockWatcher,
|
|
@@ -42,15 +35,7 @@ import {
|
|
|
42
35
|
} from '@aztec/slasher';
|
|
43
36
|
import { CollectionLimitsConfig, PublicSimulatorConfig } from '@aztec/stdlib/avm';
|
|
44
37
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
45
|
-
import {
|
|
46
|
-
type BlockParameter,
|
|
47
|
-
type DataInBlock,
|
|
48
|
-
type L2Block,
|
|
49
|
-
L2BlockHash,
|
|
50
|
-
L2BlockNew,
|
|
51
|
-
type L2BlockSource,
|
|
52
|
-
type PublishedL2Block,
|
|
53
|
-
} from '@aztec/stdlib/block';
|
|
38
|
+
import { BlockHash, type BlockParameter, type DataInBlock, L2Block, type L2BlockSource } from '@aztec/stdlib/block';
|
|
54
39
|
import type { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
55
40
|
import type {
|
|
56
41
|
ContractClassPublic,
|
|
@@ -128,6 +113,7 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
128
113
|
*/
|
|
129
114
|
export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
130
115
|
private metrics: NodeMetrics;
|
|
116
|
+
private initialHeaderHashPromise: Promise<BlockHash> | undefined = undefined;
|
|
131
117
|
|
|
132
118
|
// Prevent two snapshot operations to happen simultaneously
|
|
133
119
|
private isUploadingSnapshot = false;
|
|
@@ -309,18 +295,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
309
295
|
// We should really not be modifying the config object
|
|
310
296
|
config.txPublicSetupAllowList = config.txPublicSetupAllowList ?? (await getDefaultAllowedSetupFunctions());
|
|
311
297
|
|
|
312
|
-
// Create BlockBuilder for EpochPruneWatcher (slasher functionality)
|
|
313
|
-
const blockBuilder = new BlockBuilder(
|
|
314
|
-
{ ...config, l1GenesisTime, slotDuration: Number(slotDuration) },
|
|
315
|
-
worldStateSynchronizer,
|
|
316
|
-
archiver,
|
|
317
|
-
dateProvider,
|
|
318
|
-
telemetry,
|
|
319
|
-
);
|
|
320
|
-
|
|
321
298
|
// Create FullNodeCheckpointsBuilder for validator and non-validator block proposal handling
|
|
322
299
|
const validatorCheckpointsBuilder = new FullNodeCheckpointsBuilder(
|
|
323
300
|
{ ...config, l1GenesisTime, slotDuration: Number(slotDuration) },
|
|
301
|
+
worldStateSynchronizer,
|
|
324
302
|
archiver,
|
|
325
303
|
dateProvider,
|
|
326
304
|
telemetry,
|
|
@@ -330,7 +308,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
330
308
|
const watchers: Watcher[] = [];
|
|
331
309
|
|
|
332
310
|
// Create validator client if required
|
|
333
|
-
const validatorClient = createValidatorClient(config, {
|
|
311
|
+
const validatorClient = await createValidatorClient(config, {
|
|
334
312
|
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
335
313
|
worldState: worldStateSynchronizer,
|
|
336
314
|
p2pClient,
|
|
@@ -387,7 +365,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
387
365
|
archiver,
|
|
388
366
|
epochCache,
|
|
389
367
|
p2pClient.getTxProvider(),
|
|
390
|
-
|
|
368
|
+
validatorCheckpointsBuilder,
|
|
391
369
|
config,
|
|
392
370
|
);
|
|
393
371
|
watchers.push(epochPruneWatcher);
|
|
@@ -452,6 +430,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
452
430
|
// Create and start the sequencer client
|
|
453
431
|
const checkpointsBuilder = new CheckpointsBuilder(
|
|
454
432
|
{ ...config, l1GenesisTime, slotDuration: Number(slotDuration) },
|
|
433
|
+
worldStateSynchronizer,
|
|
455
434
|
archiver,
|
|
456
435
|
dateProvider,
|
|
457
436
|
telemetry,
|
|
@@ -580,13 +559,19 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
580
559
|
}
|
|
581
560
|
|
|
582
561
|
/**
|
|
583
|
-
* Get a block specified by its number.
|
|
584
|
-
* @param
|
|
562
|
+
* Get a block specified by its block number, block hash, or 'latest'.
|
|
563
|
+
* @param block - The block parameter (block number, block hash, or 'latest').
|
|
585
564
|
* @returns The requested block.
|
|
586
565
|
*/
|
|
587
|
-
public async getBlock(
|
|
588
|
-
|
|
589
|
-
|
|
566
|
+
public async getBlock(block: BlockParameter): Promise<L2Block | undefined> {
|
|
567
|
+
if (BlockHash.isBlockHash(block)) {
|
|
568
|
+
return this.getBlockByHash(block);
|
|
569
|
+
}
|
|
570
|
+
const blockNumber = block === 'latest' ? await this.getBlockNumber() : (block as BlockNumber);
|
|
571
|
+
if (blockNumber === BlockNumber.ZERO) {
|
|
572
|
+
return this.buildInitialBlock();
|
|
573
|
+
}
|
|
574
|
+
return await this.blockSource.getL2Block(blockNumber);
|
|
590
575
|
}
|
|
591
576
|
|
|
592
577
|
/**
|
|
@@ -594,9 +579,17 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
594
579
|
* @param blockHash - The block hash being requested.
|
|
595
580
|
* @returns The requested block.
|
|
596
581
|
*/
|
|
597
|
-
public async getBlockByHash(blockHash:
|
|
598
|
-
const
|
|
599
|
-
|
|
582
|
+
public async getBlockByHash(blockHash: BlockHash): Promise<L2Block | undefined> {
|
|
583
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
584
|
+
if (blockHash.equals(initialBlockHash)) {
|
|
585
|
+
return this.buildInitialBlock();
|
|
586
|
+
}
|
|
587
|
+
return await this.blockSource.getL2BlockByHash(blockHash);
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
private buildInitialBlock(): L2Block {
|
|
591
|
+
const initialHeader = this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
592
|
+
return L2Block.empty(initialHeader);
|
|
600
593
|
}
|
|
601
594
|
|
|
602
595
|
/**
|
|
@@ -605,8 +598,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
605
598
|
* @returns The requested block.
|
|
606
599
|
*/
|
|
607
600
|
public async getBlockByArchive(archive: Fr): Promise<L2Block | undefined> {
|
|
608
|
-
|
|
609
|
-
return publishedBlock?.block;
|
|
601
|
+
return await this.blockSource.getL2BlockByArchive(archive);
|
|
610
602
|
}
|
|
611
603
|
|
|
612
604
|
/**
|
|
@@ -616,23 +608,15 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
616
608
|
* @returns The blocks requested.
|
|
617
609
|
*/
|
|
618
610
|
public async getBlocks(from: BlockNumber, limit: number): Promise<L2Block[]> {
|
|
619
|
-
return (await this.blockSource.getBlocks(from, limit)) ?? [];
|
|
620
|
-
}
|
|
621
|
-
|
|
622
|
-
public async getPublishedBlocks(from: BlockNumber, limit: number): Promise<PublishedL2Block[]> {
|
|
623
|
-
return (await this.blockSource.getPublishedBlocks(from, limit)) ?? [];
|
|
611
|
+
return (await this.blockSource.getBlocks(from, BlockNumber(limit))) ?? [];
|
|
624
612
|
}
|
|
625
613
|
|
|
626
|
-
public async
|
|
627
|
-
return (await this.blockSource.
|
|
614
|
+
public async getCheckpoints(from: CheckpointNumber, limit: number): Promise<PublishedCheckpoint[]> {
|
|
615
|
+
return (await this.blockSource.getCheckpoints(from, limit)) ?? [];
|
|
628
616
|
}
|
|
629
617
|
|
|
630
|
-
public async
|
|
631
|
-
return (await this.blockSource.
|
|
632
|
-
}
|
|
633
|
-
|
|
634
|
-
public async getCheckpointedBlocks(from: BlockNumber, limit: number, proven?: boolean) {
|
|
635
|
-
return (await this.blockSource.getCheckpointedBlocks(from, limit, proven)) ?? [];
|
|
618
|
+
public async getCheckpointedBlocks(from: BlockNumber, limit: number) {
|
|
619
|
+
return (await this.blockSource.getCheckpointedBlocks(from, limit)) ?? [];
|
|
636
620
|
}
|
|
637
621
|
|
|
638
622
|
/**
|
|
@@ -663,6 +647,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
663
647
|
return await this.blockSource.getProvenBlockNumber();
|
|
664
648
|
}
|
|
665
649
|
|
|
650
|
+
public async getCheckpointedBlockNumber(): Promise<BlockNumber> {
|
|
651
|
+
return await this.blockSource.getCheckpointedL2BlockNumber();
|
|
652
|
+
}
|
|
653
|
+
|
|
666
654
|
/**
|
|
667
655
|
* Method to fetch the version of the package.
|
|
668
656
|
* @returns The node package version
|
|
@@ -695,12 +683,43 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
695
683
|
return this.contractDataSource.getContract(address);
|
|
696
684
|
}
|
|
697
685
|
|
|
698
|
-
public getPrivateLogsByTags(
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
686
|
+
public async getPrivateLogsByTags(
|
|
687
|
+
tags: SiloedTag[],
|
|
688
|
+
page?: number,
|
|
689
|
+
referenceBlock?: BlockHash,
|
|
690
|
+
): Promise<TxScopedL2Log[][]> {
|
|
691
|
+
if (referenceBlock) {
|
|
692
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
693
|
+
if (!referenceBlock.equals(initialBlockHash)) {
|
|
694
|
+
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
695
|
+
if (!header) {
|
|
696
|
+
throw new Error(
|
|
697
|
+
`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
|
|
698
|
+
);
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
return this.logsSource.getPrivateLogsByTags(tags, page);
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
public async getPublicLogsByTagsFromContract(
|
|
706
|
+
contractAddress: AztecAddress,
|
|
707
|
+
tags: Tag[],
|
|
708
|
+
page?: number,
|
|
709
|
+
referenceBlock?: BlockHash,
|
|
710
|
+
): Promise<TxScopedL2Log[][]> {
|
|
711
|
+
if (referenceBlock) {
|
|
712
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
713
|
+
if (!referenceBlock.equals(initialBlockHash)) {
|
|
714
|
+
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
715
|
+
if (!header) {
|
|
716
|
+
throw new Error(
|
|
717
|
+
`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
|
|
718
|
+
);
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page);
|
|
704
723
|
}
|
|
705
724
|
|
|
706
725
|
/**
|
|
@@ -747,21 +766,26 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
747
766
|
}
|
|
748
767
|
|
|
749
768
|
public async getTxReceipt(txHash: TxHash): Promise<TxReceipt> {
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
// and we would incorrectly return a TxReceipt with status DROPPED
|
|
755
|
-
if ((await this.p2pClient.getTxStatus(txHash)) === 'pending') {
|
|
756
|
-
txReceipt = new TxReceipt(txHash, TxStatus.PENDING, '');
|
|
757
|
-
}
|
|
769
|
+
// Check the tx pool status first. If the tx is known to the pool (pending or mined), we'll use that
|
|
770
|
+
// as a fallback if we don't find a settled receipt in the archiver.
|
|
771
|
+
const txPoolStatus = await this.p2pClient.getTxStatus(txHash);
|
|
772
|
+
const isKnownToPool = txPoolStatus === 'pending' || txPoolStatus === 'mined';
|
|
758
773
|
|
|
774
|
+
// Then get the actual tx from the archiver, which tracks every tx in a mined block.
|
|
759
775
|
const settledTxReceipt = await this.blockSource.getSettledTxReceipt(txHash);
|
|
776
|
+
|
|
760
777
|
if (settledTxReceipt) {
|
|
761
|
-
|
|
778
|
+
// If the archiver has the receipt then return it.
|
|
779
|
+
return settledTxReceipt;
|
|
780
|
+
} else if (isKnownToPool) {
|
|
781
|
+
// If the tx is in the pool but not in the archiver, it's pending.
|
|
782
|
+
// This handles race conditions between archiver and p2p, where the archiver
|
|
783
|
+
// has pruned the block in which a tx was mined, but p2p has not caught up yet.
|
|
784
|
+
return new TxReceipt(txHash, TxStatus.PENDING, undefined, undefined);
|
|
785
|
+
} else {
|
|
786
|
+
// Otherwise, if we don't know the tx, we consider it dropped.
|
|
787
|
+
return new TxReceipt(txHash, TxStatus.DROPPED, undefined, 'Tx dropped by P2P node');
|
|
762
788
|
}
|
|
763
|
-
|
|
764
|
-
return txReceipt;
|
|
765
789
|
}
|
|
766
790
|
|
|
767
791
|
public getTxEffect(txHash: TxHash): Promise<IndexedTxEffect | undefined> {
|
|
@@ -826,20 +850,12 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
826
850
|
return compactArray(await Promise.all(txHashes.map(txHash => this.getTxByHash(txHash))));
|
|
827
851
|
}
|
|
828
852
|
|
|
829
|
-
/**
|
|
830
|
-
* Find the indexes of the given leaves in the given tree along with a block metadata pointing to the block in which
|
|
831
|
-
* the leaves were inserted.
|
|
832
|
-
* @param blockNumber - The block number at which to get the data or 'latest' for latest data.
|
|
833
|
-
* @param treeId - The tree to search in.
|
|
834
|
-
* @param leafValues - The values to search for.
|
|
835
|
-
* @returns The indices of leaves and the block metadata of a block in which the leaves were inserted.
|
|
836
|
-
*/
|
|
837
853
|
public async findLeavesIndexes(
|
|
838
|
-
|
|
854
|
+
referenceBlock: BlockParameter,
|
|
839
855
|
treeId: MerkleTreeId,
|
|
840
856
|
leafValues: Fr[],
|
|
841
857
|
): Promise<(DataInBlock<bigint> | undefined)[]> {
|
|
842
|
-
const committedDb = await this.#getWorldState(
|
|
858
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
843
859
|
const maybeIndices = await committedDb.findLeafIndices(
|
|
844
860
|
treeId,
|
|
845
861
|
leafValues.map(x => x.toBuffer()),
|
|
@@ -891,56 +907,28 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
891
907
|
}
|
|
892
908
|
return {
|
|
893
909
|
l2BlockNumber: BlockNumber(Number(blockNumber)),
|
|
894
|
-
l2BlockHash:
|
|
910
|
+
l2BlockHash: new BlockHash(blockHash),
|
|
895
911
|
data: index,
|
|
896
912
|
};
|
|
897
913
|
});
|
|
898
914
|
}
|
|
899
915
|
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
* @param leafIndex - The index of the leaf for which the sibling path is required.
|
|
904
|
-
* @returns The sibling path for the leaf index.
|
|
905
|
-
*/
|
|
906
|
-
public async getNullifierSiblingPath(
|
|
907
|
-
blockNumber: BlockParameter,
|
|
908
|
-
leafIndex: bigint,
|
|
909
|
-
): Promise<SiblingPath<typeof NULLIFIER_TREE_HEIGHT>> {
|
|
910
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
911
|
-
return committedDb.getSiblingPath(MerkleTreeId.NULLIFIER_TREE, leafIndex);
|
|
912
|
-
}
|
|
913
|
-
|
|
914
|
-
/**
|
|
915
|
-
* Returns a sibling path for the given index in the data tree.
|
|
916
|
-
* @param blockNumber - The block number at which to get the data.
|
|
917
|
-
* @param leafIndex - The index of the leaf for which the sibling path is required.
|
|
918
|
-
* @returns The sibling path for the leaf index.
|
|
919
|
-
*/
|
|
920
|
-
public async getNoteHashSiblingPath(
|
|
921
|
-
blockNumber: BlockParameter,
|
|
922
|
-
leafIndex: bigint,
|
|
923
|
-
): Promise<SiblingPath<typeof NOTE_HASH_TREE_HEIGHT>> {
|
|
924
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
925
|
-
return committedDb.getSiblingPath(MerkleTreeId.NOTE_HASH_TREE, leafIndex);
|
|
926
|
-
}
|
|
927
|
-
|
|
928
|
-
public async getArchiveMembershipWitness(
|
|
929
|
-
blockNumber: BlockParameter,
|
|
930
|
-
archive: Fr,
|
|
916
|
+
public async getBlockHashMembershipWitness(
|
|
917
|
+
referenceBlock: BlockParameter,
|
|
918
|
+
blockHash: BlockHash,
|
|
931
919
|
): Promise<MembershipWitness<typeof ARCHIVE_HEIGHT> | undefined> {
|
|
932
|
-
const committedDb = await this.#getWorldState(
|
|
933
|
-
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.ARCHIVE>(MerkleTreeId.ARCHIVE, [
|
|
920
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
921
|
+
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.ARCHIVE>(MerkleTreeId.ARCHIVE, [blockHash]);
|
|
934
922
|
return pathAndIndex === undefined
|
|
935
923
|
? undefined
|
|
936
924
|
: MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
937
925
|
}
|
|
938
926
|
|
|
939
927
|
public async getNoteHashMembershipWitness(
|
|
940
|
-
|
|
928
|
+
referenceBlock: BlockParameter,
|
|
941
929
|
noteHash: Fr,
|
|
942
930
|
): Promise<MembershipWitness<typeof NOTE_HASH_TREE_HEIGHT> | undefined> {
|
|
943
|
-
const committedDb = await this.#getWorldState(
|
|
931
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
944
932
|
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.NOTE_HASH_TREE>(
|
|
945
933
|
MerkleTreeId.NOTE_HASH_TREE,
|
|
946
934
|
[noteHash],
|
|
@@ -950,17 +938,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
950
938
|
: MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
951
939
|
}
|
|
952
940
|
|
|
953
|
-
/**
|
|
954
|
-
* Returns the index and a sibling path for a leaf in the committed l1 to l2 data tree.
|
|
955
|
-
* @param blockNumber - The block number at which to get the data.
|
|
956
|
-
* @param l1ToL2Message - The l1ToL2Message to get the index / sibling path for.
|
|
957
|
-
* @returns A tuple of the index and the sibling path of the L1ToL2Message (undefined if not found).
|
|
958
|
-
*/
|
|
959
941
|
public async getL1ToL2MessageMembershipWitness(
|
|
960
|
-
|
|
942
|
+
referenceBlock: BlockParameter,
|
|
961
943
|
l1ToL2Message: Fr,
|
|
962
944
|
): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>] | undefined> {
|
|
963
|
-
const db = await this.#getWorldState(
|
|
945
|
+
const db = await this.#getWorldState(referenceBlock);
|
|
964
946
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [l1ToL2Message]);
|
|
965
947
|
if (!witness) {
|
|
966
948
|
return undefined;
|
|
@@ -993,12 +975,13 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
993
975
|
* @returns The L2 to L1 messages (empty array if the epoch is not found).
|
|
994
976
|
*/
|
|
995
977
|
public async getL2ToL1Messages(epoch: EpochNumber): Promise<Fr[][][][]> {
|
|
996
|
-
// Assumes `
|
|
997
|
-
const
|
|
978
|
+
// Assumes `getCheckpointedBlocksForEpoch` returns blocks in ascending order of block number.
|
|
979
|
+
const checkpointedBlocks = await this.blockSource.getCheckpointedBlocksForEpoch(epoch);
|
|
998
980
|
const blocksInCheckpoints: L2Block[][] = [];
|
|
999
981
|
let previousSlotNumber = SlotNumber.ZERO;
|
|
1000
982
|
let checkpointIndex = -1;
|
|
1001
|
-
for (const
|
|
983
|
+
for (const checkpointedBlock of checkpointedBlocks) {
|
|
984
|
+
const block = checkpointedBlock.block;
|
|
1002
985
|
const slotNumber = block.header.globalVariables.slotNumber;
|
|
1003
986
|
if (slotNumber !== previousSlotNumber) {
|
|
1004
987
|
checkpointIndex++;
|
|
@@ -1012,45 +995,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1012
995
|
);
|
|
1013
996
|
}
|
|
1014
997
|
|
|
1015
|
-
/**
|
|
1016
|
-
* Returns a sibling path for a leaf in the committed blocks tree.
|
|
1017
|
-
* @param blockNumber - The block number at which to get the data.
|
|
1018
|
-
* @param leafIndex - Index of the leaf in the tree.
|
|
1019
|
-
* @returns The sibling path.
|
|
1020
|
-
*/
|
|
1021
|
-
public async getArchiveSiblingPath(
|
|
1022
|
-
blockNumber: BlockParameter,
|
|
1023
|
-
leafIndex: bigint,
|
|
1024
|
-
): Promise<SiblingPath<typeof ARCHIVE_HEIGHT>> {
|
|
1025
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
1026
|
-
return committedDb.getSiblingPath(MerkleTreeId.ARCHIVE, leafIndex);
|
|
1027
|
-
}
|
|
1028
|
-
|
|
1029
|
-
/**
|
|
1030
|
-
* Returns a sibling path for a leaf in the committed public data tree.
|
|
1031
|
-
* @param blockNumber - The block number at which to get the data.
|
|
1032
|
-
* @param leafIndex - Index of the leaf in the tree.
|
|
1033
|
-
* @returns The sibling path.
|
|
1034
|
-
*/
|
|
1035
|
-
public async getPublicDataSiblingPath(
|
|
1036
|
-
blockNumber: BlockParameter,
|
|
1037
|
-
leafIndex: bigint,
|
|
1038
|
-
): Promise<SiblingPath<typeof PUBLIC_DATA_TREE_HEIGHT>> {
|
|
1039
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
1040
|
-
return committedDb.getSiblingPath(MerkleTreeId.PUBLIC_DATA_TREE, leafIndex);
|
|
1041
|
-
}
|
|
1042
|
-
|
|
1043
|
-
/**
|
|
1044
|
-
* Returns a nullifier membership witness for a given nullifier at a given block.
|
|
1045
|
-
* @param blockNumber - The block number at which to get the index.
|
|
1046
|
-
* @param nullifier - Nullifier we try to find witness for.
|
|
1047
|
-
* @returns The nullifier membership witness (if found).
|
|
1048
|
-
*/
|
|
1049
998
|
public async getNullifierMembershipWitness(
|
|
1050
|
-
|
|
999
|
+
referenceBlock: BlockParameter,
|
|
1051
1000
|
nullifier: Fr,
|
|
1052
1001
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
1053
|
-
const db = await this.#getWorldState(
|
|
1002
|
+
const db = await this.#getWorldState(referenceBlock);
|
|
1054
1003
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [nullifier.toBuffer()]);
|
|
1055
1004
|
if (!witness) {
|
|
1056
1005
|
return undefined;
|
|
@@ -1067,7 +1016,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1067
1016
|
|
|
1068
1017
|
/**
|
|
1069
1018
|
* Returns a low nullifier membership witness for a given nullifier at a given block.
|
|
1070
|
-
* @param
|
|
1019
|
+
* @param referenceBlock - The block parameter (block number, block hash, or 'latest') at which to get the data
|
|
1020
|
+
* (which contains the root of the nullifier tree in which we are searching for the nullifier).
|
|
1071
1021
|
* @param nullifier - Nullifier we try to find the low nullifier witness for.
|
|
1072
1022
|
* @returns The low nullifier membership witness (if found).
|
|
1073
1023
|
* @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
|
|
@@ -1080,10 +1030,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1080
1030
|
* TODO: This is a confusing behavior and we should eventually address that.
|
|
1081
1031
|
*/
|
|
1082
1032
|
public async getLowNullifierMembershipWitness(
|
|
1083
|
-
|
|
1033
|
+
referenceBlock: BlockParameter,
|
|
1084
1034
|
nullifier: Fr,
|
|
1085
1035
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
1086
|
-
const committedDb = await this.#getWorldState(
|
|
1036
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
1087
1037
|
const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
|
|
1088
1038
|
if (!findResult) {
|
|
1089
1039
|
return undefined;
|
|
@@ -1098,8 +1048,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1098
1048
|
return new NullifierMembershipWitness(BigInt(index), preimageData as NullifierLeafPreimage, siblingPath);
|
|
1099
1049
|
}
|
|
1100
1050
|
|
|
1101
|
-
async getPublicDataWitness(
|
|
1102
|
-
const committedDb = await this.#getWorldState(
|
|
1051
|
+
async getPublicDataWitness(referenceBlock: BlockParameter, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
|
|
1052
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
1103
1053
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
1104
1054
|
if (!lowLeafResult) {
|
|
1105
1055
|
return undefined;
|
|
@@ -1113,19 +1063,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1113
1063
|
}
|
|
1114
1064
|
}
|
|
1115
1065
|
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
*
|
|
1119
|
-
* @remarks The storage slot here refers to the slot as it is defined in Noir not the index in the merkle tree.
|
|
1120
|
-
* Aztec's version of `eth_getStorageAt`.
|
|
1121
|
-
*
|
|
1122
|
-
* @param contract - Address of the contract to query.
|
|
1123
|
-
* @param slot - Slot to query.
|
|
1124
|
-
* @param blockNumber - The block number at which to get the data or 'latest'.
|
|
1125
|
-
* @returns Storage value at the given contract slot.
|
|
1126
|
-
*/
|
|
1127
|
-
public async getPublicStorageAt(blockNumber: BlockParameter, contract: AztecAddress, slot: Fr): Promise<Fr> {
|
|
1128
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
1066
|
+
public async getPublicStorageAt(referenceBlock: BlockParameter, contract: AztecAddress, slot: Fr): Promise<Fr> {
|
|
1067
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
1129
1068
|
const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
|
|
1130
1069
|
|
|
1131
1070
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
@@ -1139,24 +1078,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1139
1078
|
return preimage.leaf.value;
|
|
1140
1079
|
}
|
|
1141
1080
|
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
public async getBlockHeaderByHash(blockHash: Fr): Promise<BlockHeader | undefined> {
|
|
1159
|
-
return await this.blockSource.getBlockHeaderByHash(blockHash);
|
|
1081
|
+
public async getBlockHeader(block: BlockParameter = 'latest'): Promise<BlockHeader | undefined> {
|
|
1082
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1083
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1084
|
+
if (block.equals(initialBlockHash)) {
|
|
1085
|
+
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1086
|
+
return this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
1087
|
+
}
|
|
1088
|
+
return this.blockSource.getBlockHeaderByHash(block);
|
|
1089
|
+
} else {
|
|
1090
|
+
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1091
|
+
const blockNumber = block === 'latest' ? await this.getBlockNumber() : (block as BlockNumber);
|
|
1092
|
+
if (blockNumber === BlockNumber.ZERO) {
|
|
1093
|
+
return this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
1094
|
+
}
|
|
1095
|
+
return this.blockSource.getBlockHeader(block);
|
|
1096
|
+
}
|
|
1160
1097
|
}
|
|
1161
1098
|
|
|
1162
1099
|
/**
|
|
@@ -1206,6 +1143,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1206
1143
|
this.contractDataSource,
|
|
1207
1144
|
new DateProvider(),
|
|
1208
1145
|
this.telemetry,
|
|
1146
|
+
this.log.getBindings(),
|
|
1209
1147
|
);
|
|
1210
1148
|
|
|
1211
1149
|
this.log.verbose(`Simulating public calls for tx ${txHash}`, {
|
|
@@ -1259,16 +1197,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1259
1197
|
// We accept transactions if they are not expired by the next slot (checked based on the IncludeByTimestamp field)
|
|
1260
1198
|
const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
1261
1199
|
const blockNumber = BlockNumber((await this.blockSource.getBlockNumber()) + 1);
|
|
1262
|
-
const validator = createValidatorForAcceptingTxs(
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1200
|
+
const validator = createValidatorForAcceptingTxs(
|
|
1201
|
+
db,
|
|
1202
|
+
this.contractDataSource,
|
|
1203
|
+
verifier,
|
|
1204
|
+
{
|
|
1205
|
+
timestamp: nextSlotTimestamp,
|
|
1206
|
+
blockNumber,
|
|
1207
|
+
l1ChainId: this.l1ChainId,
|
|
1208
|
+
rollupVersion: this.version,
|
|
1209
|
+
setupAllowList: this.config.txPublicSetupAllowList ?? (await getDefaultAllowedSetupFunctions()),
|
|
1210
|
+
gasFees: await this.getCurrentMinFees(),
|
|
1211
|
+
skipFeeEnforcement,
|
|
1212
|
+
txsPermitted: !this.config.disableTransactions,
|
|
1213
|
+
},
|
|
1214
|
+
this.log.getBindings(),
|
|
1215
|
+
);
|
|
1272
1216
|
|
|
1273
1217
|
return await validator.validateTx(tx);
|
|
1274
1218
|
}
|
|
@@ -1432,16 +1376,19 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1432
1376
|
}
|
|
1433
1377
|
}
|
|
1434
1378
|
|
|
1379
|
+
#getInitialHeaderHash(): Promise<BlockHash> {
|
|
1380
|
+
if (!this.initialHeaderHashPromise) {
|
|
1381
|
+
this.initialHeaderHashPromise = this.worldStateSynchronizer.getCommitted().getInitialHeader().hash();
|
|
1382
|
+
}
|
|
1383
|
+
return this.initialHeaderHashPromise;
|
|
1384
|
+
}
|
|
1385
|
+
|
|
1435
1386
|
/**
|
|
1436
1387
|
* Returns an instance of MerkleTreeOperations having first ensured the world state is fully synched
|
|
1437
|
-
* @param
|
|
1388
|
+
* @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
|
|
1438
1389
|
* @returns An instance of a committed MerkleTreeOperations
|
|
1439
1390
|
*/
|
|
1440
|
-
async #getWorldState(
|
|
1441
|
-
if (typeof blockNumber === 'number' && blockNumber < INITIAL_L2_BLOCK_NUM - 1) {
|
|
1442
|
-
throw new Error('Invalid block number to get world state for: ' + blockNumber);
|
|
1443
|
-
}
|
|
1444
|
-
|
|
1391
|
+
async #getWorldState(block: BlockParameter) {
|
|
1445
1392
|
let blockSyncedTo: BlockNumber = BlockNumber.ZERO;
|
|
1446
1393
|
try {
|
|
1447
1394
|
// Attempt to sync the world state if necessary
|
|
@@ -1450,15 +1397,39 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1450
1397
|
this.log.error(`Error getting world state: ${err}`);
|
|
1451
1398
|
}
|
|
1452
1399
|
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
this.log.debug(`Using committed db for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1400
|
+
if (block === 'latest') {
|
|
1401
|
+
this.log.debug(`Using committed db for block 'latest', world state synced upto ${blockSyncedTo}`);
|
|
1456
1402
|
return this.worldStateSynchronizer.getCommitted();
|
|
1457
|
-
}
|
|
1403
|
+
}
|
|
1404
|
+
|
|
1405
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1406
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1407
|
+
if (block.equals(initialBlockHash)) {
|
|
1408
|
+
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1409
|
+
return this.worldStateSynchronizer.getSnapshot(BlockNumber.ZERO);
|
|
1410
|
+
}
|
|
1411
|
+
|
|
1412
|
+
const header = await this.blockSource.getBlockHeaderByHash(block);
|
|
1413
|
+
if (!header) {
|
|
1414
|
+
throw new Error(
|
|
1415
|
+
`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.`,
|
|
1416
|
+
);
|
|
1417
|
+
}
|
|
1418
|
+
const blockNumber = header.getBlockNumber();
|
|
1458
1419
|
this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1459
|
-
return this.worldStateSynchronizer.getSnapshot(blockNumber
|
|
1460
|
-
}
|
|
1461
|
-
|
|
1420
|
+
return this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1421
|
+
}
|
|
1422
|
+
|
|
1423
|
+
// Block number provided
|
|
1424
|
+
{
|
|
1425
|
+
const blockNumber = block as BlockNumber;
|
|
1426
|
+
|
|
1427
|
+
if (blockNumber > blockSyncedTo) {
|
|
1428
|
+
throw new Error(`Queried block ${block} not yet synced by the node (node is synced upto ${blockSyncedTo}).`);
|
|
1429
|
+
}
|
|
1430
|
+
|
|
1431
|
+
this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1432
|
+
return this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1462
1433
|
}
|
|
1463
1434
|
}
|
|
1464
1435
|
|
package/src/sentinel/factory.ts
CHANGED
|
@@ -20,12 +20,7 @@ export async function createSentinel(
|
|
|
20
20
|
if (!config.sentinelEnabled) {
|
|
21
21
|
return undefined;
|
|
22
22
|
}
|
|
23
|
-
const kvStore = await createStore(
|
|
24
|
-
'sentinel',
|
|
25
|
-
SentinelStore.SCHEMA_VERSION,
|
|
26
|
-
config,
|
|
27
|
-
createLogger('node:sentinel:lmdb'),
|
|
28
|
-
);
|
|
23
|
+
const kvStore = await createStore('sentinel', SentinelStore.SCHEMA_VERSION, config, logger.getBindings());
|
|
29
24
|
const storeHistoryLength = config.sentinelHistoryLengthInEpochs * epochCache.getL1Constants().epochDuration;
|
|
30
25
|
const storeHistoricProvenPerformanceLength = config.sentinelHistoricProvenPerformanceLengthInEpochs;
|
|
31
26
|
const sentinelStore = new SentinelStore(kvStore, {
|