@aztec/world-state 0.72.1 → 0.74.0

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.
Files changed (47) hide show
  1. package/dest/native/merkle_trees_facade.js +2 -2
  2. package/dest/native/message.d.ts +0 -30
  3. package/dest/native/message.d.ts.map +1 -1
  4. package/dest/native/message.js +1 -23
  5. package/dest/native/native_world_state.js +3 -3
  6. package/dest/native/native_world_state_instance.d.ts +1 -13
  7. package/dest/native/native_world_state_instance.d.ts.map +1 -1
  8. package/dest/native/native_world_state_instance.js +27 -94
  9. package/dest/native/world_state_version.js +2 -2
  10. package/dest/synchronizer/server_world_state_synchronizer.d.ts +1 -1
  11. package/dest/synchronizer/server_world_state_synchronizer.d.ts.map +1 -1
  12. package/dest/synchronizer/server_world_state_synchronizer.js +6 -6
  13. package/dest/test/index.d.ts +2 -0
  14. package/dest/test/index.d.ts.map +1 -0
  15. package/dest/test/index.js +2 -0
  16. package/dest/world-state-db/index.d.ts +0 -3
  17. package/dest/world-state-db/index.d.ts.map +1 -1
  18. package/dest/world-state-db/index.js +1 -4
  19. package/package.json +13 -17
  20. package/src/native/merkle_trees_facade.ts +1 -1
  21. package/src/native/message.ts +0 -44
  22. package/src/native/native_world_state.ts +2 -2
  23. package/src/native/native_world_state_instance.ts +28 -124
  24. package/src/native/world_state_version.ts +1 -1
  25. package/src/synchronizer/server_world_state_synchronizer.ts +6 -6
  26. package/src/test/index.ts +1 -0
  27. package/src/world-state-db/index.ts +0 -3
  28. package/dest/world-state-db/merkle_tree_map.d.ts +0 -11
  29. package/dest/world-state-db/merkle_tree_map.d.ts.map +0 -1
  30. package/dest/world-state-db/merkle_tree_map.js +0 -2
  31. package/dest/world-state-db/merkle_tree_operations_facade.d.ts +0 -116
  32. package/dest/world-state-db/merkle_tree_operations_facade.d.ts.map +0 -1
  33. package/dest/world-state-db/merkle_tree_operations_facade.js +0 -133
  34. package/dest/world-state-db/merkle_tree_snapshot_operations_facade.d.ts +0 -32
  35. package/dest/world-state-db/merkle_tree_snapshot_operations_facade.d.ts.map +0 -1
  36. package/dest/world-state-db/merkle_tree_snapshot_operations_facade.js +0 -76
  37. package/dest/world-state-db/merkle_trees.d.ts +0 -174
  38. package/dest/world-state-db/merkle_trees.d.ts.map +0 -1
  39. package/dest/world-state-db/merkle_trees.js +0 -461
  40. package/dest/world-state-db/metrics.d.ts +0 -14
  41. package/dest/world-state-db/metrics.d.ts.map +0 -1
  42. package/dest/world-state-db/metrics.js +0 -44
  43. package/src/world-state-db/merkle_tree_map.ts +0 -11
  44. package/src/world-state-db/merkle_tree_operations_facade.ts +0 -199
  45. package/src/world-state-db/merkle_tree_snapshot_operations_facade.ts +0 -151
  46. package/src/world-state-db/merkle_trees.ts +0 -727
  47. package/src/world-state-db/metrics.ts +0 -64
@@ -1,199 +0,0 @@
1
- import { type BatchInsertionResult, type MerkleTreeId, type SiblingPath } from '@aztec/circuit-types';
2
- import {
3
- type IndexedTreeId,
4
- type MerkleTreeLeafType,
5
- type MerkleTreeWriteOperations,
6
- type SequentialInsertionResult,
7
- type TreeInfo,
8
- } from '@aztec/circuit-types/interfaces';
9
- import { type BlockHeader, type StateReference } from '@aztec/circuits.js';
10
- import { type IndexedTreeLeafPreimage } from '@aztec/foundation/trees';
11
-
12
- import { type MerkleTrees } from './merkle_trees.js';
13
-
14
- /**
15
- * Wraps a MerkleTreeDbOperations to call all functions with a preset includeUncommitted flag.
16
- */
17
- export class MerkleTreeReadOperationsFacade implements MerkleTreeWriteOperations {
18
- constructor(protected trees: MerkleTrees, protected includeUncommitted: boolean) {}
19
-
20
- /**
21
- * Returns the tree info for the specified tree id.
22
- * @param treeId - Id of the tree to get information from.
23
- * @param includeUncommitted - Indicates whether to include uncommitted data.
24
- * @returns The tree info for the specified tree.
25
- */
26
- getTreeInfo(treeId: MerkleTreeId): Promise<TreeInfo> {
27
- return this.trees.getTreeInfo(treeId, this.includeUncommitted);
28
- }
29
-
30
- /**
31
- * Get the current state reference.
32
- * @returns The current state reference.
33
- */
34
- getStateReference(): Promise<StateReference> {
35
- return this.trees.getStateReference(this.includeUncommitted);
36
- }
37
-
38
- /**
39
- * Returns the initial header for the chain before the first block.
40
- * @returns The initial header.
41
- */
42
- getInitialHeader(): BlockHeader {
43
- return this.trees.getInitialHeader();
44
- }
45
-
46
- /**
47
- * Appends a set of leaf values to the tree.
48
- * @param treeId - Id of the tree to append leaves to.
49
- * @param leaves - The set of leaves to be appended.
50
- * @returns The tree info of the specified tree.
51
- */
52
- appendLeaves<ID extends MerkleTreeId>(treeId: ID, leaves: MerkleTreeLeafType<ID>[]): Promise<void> {
53
- return this.trees.appendLeaves(treeId, leaves);
54
- }
55
-
56
- /**
57
- * Returns the sibling path for a requested leaf index.
58
- * @param treeId - Id of the tree to get the sibling path from.
59
- * @param index - The index of the leaf for which a sibling path is required.
60
- * @returns A promise with the sibling path of the specified leaf index.
61
- */
62
- async getSiblingPath<N extends number>(treeId: MerkleTreeId, index: bigint): Promise<SiblingPath<N>> {
63
- const path = await this.trees.getSiblingPath(treeId, index, this.includeUncommitted);
64
- return path as unknown as SiblingPath<N>;
65
- }
66
-
67
- /**
68
- * Finds the index of the largest leaf whose value is less than or equal to the provided value.
69
- * @param treeId - The ID of the tree to search.
70
- * @param value - The value to be inserted into the tree.
71
- * @param includeUncommitted - If true, the uncommitted changes are included in the search.
72
- * @returns The found leaf index and a flag indicating if the corresponding leaf's value is equal to `newValue`.
73
- */
74
- getPreviousValueIndex<ID extends IndexedTreeId>(
75
- treeId: ID,
76
- value: bigint,
77
- ): Promise<
78
- | {
79
- /**
80
- * The index of the found leaf.
81
- */
82
- index: bigint;
83
- /**
84
- * A flag indicating if the corresponding leaf's value is equal to `newValue`.
85
- */
86
- alreadyPresent: boolean;
87
- }
88
- | undefined
89
- > {
90
- return this.trees.getPreviousValueIndex(treeId, value, this.includeUncommitted);
91
- }
92
-
93
- /**
94
- * Gets the leaf data at a given index and tree.
95
- * @param treeId - The ID of the tree get the leaf from.
96
- * @param index - The index of the leaf to get.
97
- * @returns Leaf preimage.
98
- */
99
- async getLeafPreimage<ID extends IndexedTreeId>(
100
- treeId: ID,
101
- index: bigint,
102
- ): Promise<IndexedTreeLeafPreimage | undefined> {
103
- const preimage = await this.trees.getLeafPreimage(treeId, index, this.includeUncommitted);
104
- return preimage as IndexedTreeLeafPreimage | undefined;
105
- }
106
-
107
- /**
108
- * Returns the index of a leaf given its value, or undefined if no leaf with that value is found.
109
- * @param treeId - The ID of the tree.
110
- * @param value - The leaf value to look for.
111
- * @returns The index of the first leaf found with a given value (undefined if not found).
112
- */
113
- findLeafIndices<ID extends MerkleTreeId>(
114
- treeId: ID,
115
- values: MerkleTreeLeafType<ID>[],
116
- ): Promise<(bigint | undefined)[]> {
117
- return Promise.all(values.map(leaf => this.trees.findLeafIndex(treeId, leaf, this.includeUncommitted)));
118
- }
119
-
120
- /**
121
- * Returns the first index containing a leaf value after `startIndex`.
122
- * @param treeId - The tree for which the index should be returned.
123
- * @param value - The value to search for in the tree.
124
- * @param startIndex - The index to start searching from (used when skipping nullified messages)
125
- */
126
- findLeafIndicesAfter<ID extends MerkleTreeId>(
127
- treeId: ID,
128
- values: MerkleTreeLeafType<ID>[],
129
- startIndex: bigint,
130
- ): Promise<(bigint | undefined)[]> {
131
- return Promise.all(
132
- values.map(leaf => this.trees.findLeafIndexAfter(treeId, leaf, startIndex, this.includeUncommitted)),
133
- );
134
- }
135
-
136
- /**
137
- * Gets the value at the given index.
138
- * @param treeId - The ID of the tree to get the leaf value from.
139
- * @param index - The index of the leaf.
140
- * @param includeUncommitted - Indicates whether to include uncommitted changes.
141
- * @returns Leaf value at the given index (undefined if not found).
142
- */
143
- getLeafValue<ID extends MerkleTreeId>(
144
- treeId: ID,
145
- index: bigint,
146
- ): Promise<MerkleTreeLeafType<typeof treeId> | undefined> {
147
- return this.trees.getLeafValue(treeId, index, this.includeUncommitted) as Promise<
148
- MerkleTreeLeafType<typeof treeId> | undefined
149
- >;
150
- }
151
-
152
- /**
153
- * Inserts the new block hash into the archive.
154
- * This includes all of the current roots of all of the data trees and the current blocks global vars.
155
- * @param header - The header to insert into the archive.
156
- */
157
- public updateArchive(header: BlockHeader): Promise<void> {
158
- return this.trees.updateArchive(header);
159
- }
160
-
161
- /**
162
- * Batch insert multiple leaves into the tree.
163
- * @param treeId - The ID of the tree.
164
- * @param leaves - Leaves to insert into the tree.
165
- * @param subtreeHeight - Height of the subtree.
166
- * @returns The data for the leaves to be updated when inserting the new ones.
167
- */
168
- public batchInsert<TreeHeight extends number, SubtreeSiblingPathHeight extends number>(
169
- treeId: IndexedTreeId,
170
- leaves: Buffer[],
171
- subtreeHeight: number,
172
- ): Promise<BatchInsertionResult<TreeHeight, SubtreeSiblingPathHeight>> {
173
- return this.trees.batchInsert(treeId, leaves, subtreeHeight);
174
- }
175
-
176
- /**
177
- * Sequentially inserts multiple leaves into the tree.
178
- * @param treeId - The ID of the tree.
179
- * @param leaves - Leaves to insert into the tree.
180
- * @returns Witnesses for the operations performed.
181
- */
182
- public sequentialInsert<TreeHeight extends number>(
183
- _treeId: IndexedTreeId,
184
- _leaves: Buffer[],
185
- ): Promise<SequentialInsertionResult<TreeHeight>> {
186
- throw new Error('Method not implemented in legacy merkle tree');
187
- }
188
-
189
- getBlockNumbersForLeafIndices<ID extends MerkleTreeId>(
190
- _treeId: ID,
191
- _leafIndices: bigint[],
192
- ): Promise<(bigint | undefined)[]> {
193
- throw new Error('Method not implemented in legacy merkle tree');
194
- }
195
-
196
- close(): Promise<void> {
197
- return Promise.resolve();
198
- }
199
- }
@@ -1,151 +0,0 @@
1
- import { MerkleTreeId, type SiblingPath } from '@aztec/circuit-types';
2
- import {
3
- type IndexedTreeId,
4
- type MerkleTreeLeafType,
5
- type MerkleTreeReadOperations,
6
- type TreeInfo,
7
- } from '@aztec/circuit-types/interfaces';
8
- import {
9
- AppendOnlyTreeSnapshot,
10
- type BlockHeader,
11
- Fr,
12
- PartialStateReference,
13
- StateReference,
14
- } from '@aztec/circuits.js';
15
- import { type IndexedTreeLeafPreimage } from '@aztec/foundation/trees';
16
- import { type IndexedTreeSnapshot } from '@aztec/merkle-tree';
17
-
18
- import { type TreeSnapshots } from './merkle_tree_db.js';
19
- import { type MerkleTrees } from './merkle_trees.js';
20
-
21
- /**
22
- * Merkle tree operations on readonly tree snapshots.
23
- */
24
- export class MerkleTreeSnapshotOperationsFacade implements MerkleTreeReadOperations {
25
- #treesDb: MerkleTrees;
26
- #blockNumber: number;
27
- #treeSnapshots: TreeSnapshots = {} as any;
28
-
29
- constructor(trees: MerkleTrees, blockNumber: number) {
30
- this.#treesDb = trees;
31
- this.#blockNumber = blockNumber;
32
- }
33
-
34
- async #getTreeSnapshot(treeId: MerkleTreeId): Promise<TreeSnapshots[typeof treeId]> {
35
- if (this.#treeSnapshots[treeId]) {
36
- return this.#treeSnapshots[treeId];
37
- }
38
-
39
- this.#treeSnapshots = await this.#treesDb.getTreeSnapshots(this.#blockNumber);
40
- return this.#treeSnapshots[treeId]!;
41
- }
42
-
43
- async findLeafIndices<ID extends MerkleTreeId>(
44
- treeId: ID,
45
- values: MerkleTreeLeafType<ID>[],
46
- ): Promise<(bigint | undefined)[]> {
47
- const tree = await this.#getTreeSnapshot(treeId);
48
- // TODO #5448 fix "as any"
49
- return values.map(leaf => tree.findLeafIndex(leaf as any));
50
- }
51
-
52
- async findLeafIndicesAfter<ID extends MerkleTreeId>(
53
- treeId: MerkleTreeId,
54
- values: MerkleTreeLeafType<ID>[],
55
- startIndex: bigint,
56
- ): Promise<(bigint | undefined)[]> {
57
- const tree = await this.#getTreeSnapshot(treeId);
58
- // TODO #5448 fix "as any"
59
- return values.map(leaf => tree.findLeafIndexAfter(leaf as any, startIndex));
60
- }
61
-
62
- async getLeafPreimage<ID extends IndexedTreeId>(
63
- treeId: ID,
64
- index: bigint,
65
- ): Promise<IndexedTreeLeafPreimage | undefined> {
66
- const snapshot = (await this.#getTreeSnapshot(treeId)) as IndexedTreeSnapshot;
67
- return snapshot.getLatestLeafPreimageCopy(BigInt(index));
68
- }
69
-
70
- async getLeafValue<ID extends MerkleTreeId>(
71
- treeId: ID,
72
- index: bigint,
73
- ): Promise<MerkleTreeLeafType<typeof treeId> | undefined> {
74
- const snapshot = await this.#getTreeSnapshot(treeId);
75
- return snapshot.getLeafValue(BigInt(index)) as MerkleTreeLeafType<typeof treeId> | undefined;
76
- }
77
-
78
- async getPreviousValueIndex(
79
- treeId: IndexedTreeId,
80
- value: bigint,
81
- ): Promise<
82
- | {
83
- /**
84
- * The index of the found leaf.
85
- */
86
- index: bigint;
87
- /**
88
- * A flag indicating if the corresponding leaf's value is equal to `newValue`.
89
- */
90
- alreadyPresent: boolean;
91
- }
92
- | undefined
93
- > {
94
- const snapshot = (await this.#getTreeSnapshot(treeId)) as IndexedTreeSnapshot;
95
- return snapshot.findIndexOfPreviousKey(value);
96
- }
97
-
98
- async getSiblingPath<N extends number>(treeId: MerkleTreeId, index: bigint): Promise<SiblingPath<N>> {
99
- const snapshot = await this.#getTreeSnapshot(treeId);
100
- return snapshot.getSiblingPath(index);
101
- }
102
-
103
- async getTreeInfo(treeId: MerkleTreeId): Promise<TreeInfo> {
104
- const snapshot = await this.#getTreeSnapshot(treeId);
105
- return {
106
- depth: snapshot.getDepth(),
107
- root: snapshot.getRoot(),
108
- size: snapshot.getNumLeaves(),
109
- treeId,
110
- };
111
- }
112
-
113
- getBlockNumbersForLeafIndices<ID extends MerkleTreeId>(_a: ID, _b: bigint[]): Promise<(bigint | undefined)[]> {
114
- throw new Error('Not implemented');
115
- }
116
-
117
- async getStateReference(): Promise<StateReference> {
118
- const snapshots = await Promise.all([
119
- this.#getTreeSnapshot(MerkleTreeId.NULLIFIER_TREE),
120
- this.#getTreeSnapshot(MerkleTreeId.NOTE_HASH_TREE),
121
- this.#getTreeSnapshot(MerkleTreeId.PUBLIC_DATA_TREE),
122
- this.#getTreeSnapshot(MerkleTreeId.L1_TO_L2_MESSAGE_TREE),
123
- this.#getTreeSnapshot(MerkleTreeId.ARCHIVE),
124
- ]);
125
-
126
- return new StateReference(
127
- new AppendOnlyTreeSnapshot(
128
- Fr.fromBuffer(snapshots[MerkleTreeId.L1_TO_L2_MESSAGE_TREE].getRoot()),
129
- Number(snapshots[MerkleTreeId.L1_TO_L2_MESSAGE_TREE].getNumLeaves()),
130
- ),
131
- new PartialStateReference(
132
- new AppendOnlyTreeSnapshot(
133
- Fr.fromBuffer(snapshots[MerkleTreeId.NOTE_HASH_TREE].getRoot()),
134
- Number(snapshots[MerkleTreeId.NOTE_HASH_TREE].getNumLeaves()),
135
- ),
136
- new AppendOnlyTreeSnapshot(
137
- Fr.fromBuffer(snapshots[MerkleTreeId.NULLIFIER_TREE].getRoot()),
138
- Number(snapshots[MerkleTreeId.NULLIFIER_TREE].getNumLeaves()),
139
- ),
140
- new AppendOnlyTreeSnapshot(
141
- Fr.fromBuffer(snapshots[MerkleTreeId.PUBLIC_DATA_TREE].getRoot()),
142
- Number(snapshots[MerkleTreeId.PUBLIC_DATA_TREE].getNumLeaves()),
143
- ),
144
- ),
145
- );
146
- }
147
-
148
- getInitialHeader(): BlockHeader {
149
- throw new Error('Getting initial header not supported on snapshot.');
150
- }
151
- }