@aztec/world-state 0.47.0 → 0.48.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 (40) hide show
  1. package/dest/synchronizer/config.d.ts +2 -0
  2. package/dest/synchronizer/config.d.ts.map +1 -1
  3. package/dest/synchronizer/config.js +22 -8
  4. package/dest/synchronizer/server_world_state_synchronizer.d.ts +10 -3
  5. package/dest/synchronizer/server_world_state_synchronizer.d.ts.map +1 -1
  6. package/dest/synchronizer/server_world_state_synchronizer.js +50 -17
  7. package/dest/synchronizer/world_state_synchronizer.d.ts +7 -0
  8. package/dest/synchronizer/world_state_synchronizer.d.ts.map +1 -1
  9. package/dest/world-state-db/index.d.ts +1 -1
  10. package/dest/world-state-db/index.d.ts.map +1 -1
  11. package/dest/world-state-db/index.js +1 -2
  12. package/dest/world-state-db/merkle_tree_db.d.ts +5 -1
  13. package/dest/world-state-db/merkle_tree_db.d.ts.map +1 -1
  14. package/dest/world-state-db/merkle_tree_db.js +1 -1
  15. package/dest/world-state-db/merkle_tree_map.d.ts +11 -0
  16. package/dest/world-state-db/merkle_tree_map.d.ts.map +1 -0
  17. package/dest/world-state-db/merkle_tree_map.js +2 -0
  18. package/dest/world-state-db/merkle_tree_operations_facade.d.ts +2 -3
  19. package/dest/world-state-db/merkle_tree_operations_facade.d.ts.map +1 -1
  20. package/dest/world-state-db/merkle_tree_operations_facade.js +1 -1
  21. package/dest/world-state-db/merkle_tree_snapshot_operations_facade.d.ts +1 -2
  22. package/dest/world-state-db/merkle_tree_snapshot_operations_facade.d.ts.map +1 -1
  23. package/dest/world-state-db/merkle_tree_snapshot_operations_facade.js +1 -1
  24. package/dest/world-state-db/merkle_trees.d.ts +2 -2
  25. package/dest/world-state-db/merkle_trees.d.ts.map +1 -1
  26. package/dest/world-state-db/merkle_trees.js +12 -4
  27. package/package.json +7 -7
  28. package/src/synchronizer/config.ts +23 -7
  29. package/src/synchronizer/server_world_state_synchronizer.ts +65 -21
  30. package/src/synchronizer/world_state_synchronizer.ts +8 -0
  31. package/src/world-state-db/index.ts +2 -1
  32. package/src/world-state-db/merkle_tree_db.ts +6 -2
  33. package/src/world-state-db/merkle_tree_map.ts +11 -0
  34. package/src/world-state-db/merkle_tree_operations_facade.ts +6 -7
  35. package/src/world-state-db/merkle_tree_snapshot_operations_facade.ts +7 -6
  36. package/src/world-state-db/merkle_trees.ts +21 -12
  37. package/dest/world-state-db/merkle_tree_operations.d.ts +0 -160
  38. package/dest/world-state-db/merkle_tree_operations.d.ts.map +0 -1
  39. package/dest/world-state-db/merkle_tree_operations.js +0 -13
  40. package/src/world-state-db/merkle_tree_operations.ts +0 -212
@@ -1,160 +0,0 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
- import { type L2Block, type MerkleTreeId, type SiblingPath } from '@aztec/circuit-types';
3
- import { type Fr, type Header, type NullifierLeafPreimage, type StateReference } from '@aztec/circuits.js';
4
- import { type IndexedTreeLeafPreimage } from '@aztec/foundation/trees';
5
- import { type AppendOnlyTree, type BatchInsertionResult, type IndexedTree } from '@aztec/merkle-tree';
6
- /**
7
- * Type alias for the nullifier tree ID.
8
- */
9
- export type IndexedTreeId = MerkleTreeId.NULLIFIER_TREE | MerkleTreeId.PUBLIC_DATA_TREE;
10
- /**
11
- * Defines tree information.
12
- */
13
- export interface TreeInfo {
14
- /**
15
- * The tree ID.
16
- */
17
- treeId: MerkleTreeId;
18
- /**
19
- * The tree root.
20
- */
21
- root: Buffer;
22
- /**
23
- * The number of leaves in the tree.
24
- */
25
- size: bigint;
26
- /**
27
- * The depth of the tree.
28
- */
29
- depth: number;
30
- }
31
- export type MerkleTreeMap = {
32
- [MerkleTreeId.NULLIFIER_TREE]: IndexedTree;
33
- [MerkleTreeId.NOTE_HASH_TREE]: AppendOnlyTree<Fr>;
34
- [MerkleTreeId.PUBLIC_DATA_TREE]: IndexedTree;
35
- [MerkleTreeId.L1_TO_L2_MESSAGE_TREE]: AppendOnlyTree<Fr>;
36
- [MerkleTreeId.ARCHIVE]: AppendOnlyTree<Fr>;
37
- };
38
- type LeafTypes = {
39
- [MerkleTreeId.NULLIFIER_TREE]: Buffer;
40
- [MerkleTreeId.NOTE_HASH_TREE]: Fr;
41
- [MerkleTreeId.PUBLIC_DATA_TREE]: Buffer;
42
- [MerkleTreeId.L1_TO_L2_MESSAGE_TREE]: Fr;
43
- [MerkleTreeId.ARCHIVE]: Fr;
44
- };
45
- export type MerkleTreeLeafType<ID extends MerkleTreeId> = LeafTypes[ID];
46
- /**
47
- * Defines the interface for operations on a set of Merkle Trees.
48
- */
49
- export interface MerkleTreeOperations {
50
- /**
51
- * Appends leaves to a given tree.
52
- * @param treeId - The tree to be updated.
53
- * @param leaves - The set of leaves to be appended.
54
- */
55
- appendLeaves<ID extends MerkleTreeId>(treeId: ID, leaves: MerkleTreeLeafType<ID>[]): Promise<void>;
56
- /**
57
- * Returns information about the given tree.
58
- * @param treeId - The tree to be queried.
59
- */
60
- getTreeInfo(treeId: MerkleTreeId): Promise<TreeInfo>;
61
- /**
62
- * Gets the current state reference.
63
- */
64
- getStateReference(): Promise<StateReference>;
65
- /**
66
- * Gets the initial header.
67
- */
68
- getInitialHeader(): Header;
69
- /**
70
- * Gets sibling path for a leaf.
71
- * @param treeId - The tree to be queried for a sibling path.
72
- * @param index - The index of the leaf for which a sibling path should be returned.
73
- */
74
- getSiblingPath<N extends number>(treeId: MerkleTreeId, index: bigint): Promise<SiblingPath<N>>;
75
- /**
76
- * Returns the previous index for a given value in an indexed tree.
77
- * @param treeId - The tree for which the previous value index is required.
78
- * @param value - The value to be queried.
79
- */
80
- getPreviousValueIndex<ID extends IndexedTreeId>(treeId: ID, value: bigint): Promise<{
81
- /**
82
- * The index of the found leaf.
83
- */
84
- index: bigint;
85
- /**
86
- * A flag indicating if the corresponding leaf's value is equal to `newValue`.
87
- */
88
- alreadyPresent: boolean;
89
- } | undefined>;
90
- /**
91
- * Returns the data at a specific leaf.
92
- * @param treeId - The tree for which leaf data should be returned.
93
- * @param index - The index of the leaf required.
94
- */
95
- getLeafPreimage<ID extends IndexedTreeId>(treeId: ID, index: bigint): Promise<IndexedTreeLeafPreimage | undefined>;
96
- /**
97
- * Update the leaf data at the given index.
98
- * @param treeId - The tree for which leaf data should be edited.
99
- * @param leaf - The updated leaf value.
100
- * @param index - The index of the leaf to be updated.
101
- */
102
- updateLeaf<ID extends IndexedTreeId>(treeId: ID, leaf: NullifierLeafPreimage | Buffer, index: bigint): Promise<void>;
103
- /**
104
- * Returns the index containing a leaf value.
105
- * @param treeId - The tree for which the index should be returned.
106
- * @param value - The value to search for in the tree.
107
- */
108
- findLeafIndex<ID extends MerkleTreeId>(treeId: ID, value: MerkleTreeLeafType<ID>): Promise<bigint | undefined>;
109
- /**
110
- * Returns the first index containing a leaf value after `startIndex`.
111
- * @param treeId - The tree for which the index should be returned.
112
- * @param value - The value to search for in the tree.
113
- * @param startIndex - The index to start searching from (used when skipping nullified messages)
114
- */
115
- findLeafIndexAfter<ID extends MerkleTreeId>(treeId: ID, value: MerkleTreeLeafType<ID>, startIndex: bigint): Promise<bigint | undefined>;
116
- /**
117
- * Gets the value for a leaf in the tree.
118
- * @param treeId - The tree for which the index should be returned.
119
- * @param index - The index of the leaf.
120
- */
121
- getLeafValue<ID extends MerkleTreeId>(treeId: ID, index: bigint): Promise<MerkleTreeLeafType<typeof treeId> | undefined>;
122
- /**
123
- * Inserts the block hash into the archive.
124
- * This includes all of the current roots of all of the data trees and the current blocks global vars.
125
- * @param header - The header to insert into the archive.
126
- */
127
- updateArchive(header: Header): Promise<void>;
128
- /**
129
- * Batch insert multiple leaves into the tree.
130
- * @param leaves - Leaves to insert into the tree.
131
- * @param treeId - The tree on which to insert.
132
- * @param subtreeHeight - Height of the subtree.
133
- * @returns The witness data for the leaves to be updated when inserting the new ones.
134
- */
135
- batchInsert<TreeHeight extends number, SubtreeSiblingPathHeight extends number, ID extends IndexedTreeId>(treeId: ID, leaves: Buffer[], subtreeHeight: number): Promise<BatchInsertionResult<TreeHeight, SubtreeSiblingPathHeight>>;
136
- /**
137
- * Handles a single L2 block (i.e. Inserts the new note hashes into the merkle tree).
138
- * @param block - The L2 block to handle.
139
- * @param l1ToL2Messages - The L1 to L2 messages for the block.
140
- */
141
- handleL2BlockAndMessages(block: L2Block, l1ToL2Messages: Fr[]): Promise<HandleL2BlockAndMessagesResult>;
142
- /**
143
- * Commits pending changes to the underlying store.
144
- */
145
- commit(): Promise<void>;
146
- /**
147
- * Rolls back pending changes.
148
- */
149
- rollback(): Promise<void>;
150
- }
151
- /** Return type for handleL2BlockAndMessages */
152
- export type HandleL2BlockAndMessagesResult = {
153
- /** Whether the block processed was emitted by our sequencer */ isBlockOurs: boolean;
154
- };
155
- /**
156
- * Outputs a tree leaves using for debugging purposes.
157
- */
158
- export declare function inspectTree(db: MerkleTreeOperations, treeId: MerkleTreeId, log?: import("@aztec/foundation/log").Logger): Promise<void>;
159
- export {};
160
- //# sourceMappingURL=merkle_tree_operations.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"merkle_tree_operations.d.ts","sourceRoot":"","sources":["../../src/world-state-db/merkle_tree_operations.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACzF,OAAO,EAAE,KAAK,EAAE,EAAE,KAAK,MAAM,EAAE,KAAK,qBAAqB,EAAE,KAAK,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAE3G,OAAO,EAAE,KAAK,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AACvE,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,oBAAoB,EAAE,KAAK,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEtG;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,YAAY,CAAC,cAAc,GAAG,YAAY,CAAC,gBAAgB,CAAC;AAExF;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB;;OAEG;IACH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E,EAAE,EACV,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,kBAAkB,CAAC,OAAO,MAAM,CAAC,GAAG,SAAS,CAAC,CAAC;IAE1D;;;;OAIG;IACH,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE7C;;;;;;OAMG;IACH,WAAW,CAAC,UAAU,SAAS,MAAM,EAAE,wBAAwB,SAAS,MAAM,EAAE,EAAE,SAAS,aAAa,EACtG,MAAM,EAAE,EAAE,EACV,MAAM,EAAE,MAAM,EAAE,EAChB,aAAa,EAAE,MAAM,GACpB,OAAO,CAAC,oBAAoB,CAAC,UAAU,EAAE,wBAAwB,CAAC,CAAC,CAAC;IAEvE;;;;OAIG;IACH,wBAAwB,CAAC,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,8BAA8B,CAAC,CAAC;IAExG;;OAEG;IACH,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAExB;;OAEG;IACH,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3B;AAED,+CAA+C;AAC/C,MAAM,MAAM,8BAA8B,GAAG;IAC3C,+DAA+D,CAAC,WAAW,EAAE,OAAO,CAAC;CACtF,CAAC;AAEF;;GAEG;AACH,wBAAsB,WAAW,CAC/B,EAAE,EAAE,oBAAoB,EACxB,MAAM,EAAE,YAAY,EACpB,GAAG,yCAA0C,iBAU9C"}
@@ -1,13 +0,0 @@
1
- import { createDebugLogger } from '@aztec/foundation/log';
2
- /**
3
- * Outputs a tree leaves using for debugging purposes.
4
- */
5
- export async function inspectTree(db, treeId, log = createDebugLogger('aztec:inspect-tree')) {
6
- const info = await db.getTreeInfo(treeId);
7
- const output = [`Tree id=${treeId} size=${info.size} root=0x${info.root.toString('hex')}`];
8
- for (let i = 0; i < info.size; i++) {
9
- output.push(` Leaf ${i}: ${await db.getLeafValue(treeId, BigInt(i)).then(x => x?.toString('hex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SSxhQUFhLENBQUMsRUFBRSxDQUN6RyxDQUFDO0lBQ0osQ0FBQztJQUNELEdBQUcsQ0FBQyxJQUFJLENBQUMsTUFBTSxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsQ0FBQyxDQUFDO0FBQzlCLENBQUMifQ==
@@ -1,212 +0,0 @@
1
- import { type L2Block, type MerkleTreeId, type SiblingPath } from '@aztec/circuit-types';
2
- import { type Fr, type Header, type NullifierLeafPreimage, type StateReference } from '@aztec/circuits.js';
3
- import { createDebugLogger } from '@aztec/foundation/log';
4
- import { type IndexedTreeLeafPreimage } from '@aztec/foundation/trees';
5
- import { type AppendOnlyTree, type BatchInsertionResult, type IndexedTree } from '@aztec/merkle-tree';
6
-
7
- /**
8
- * Type alias for the nullifier tree ID.
9
- */
10
- export type IndexedTreeId = MerkleTreeId.NULLIFIER_TREE | MerkleTreeId.PUBLIC_DATA_TREE;
11
-
12
- /**
13
- * Defines tree information.
14
- */
15
- export interface TreeInfo {
16
- /**
17
- * The tree ID.
18
- */
19
- treeId: MerkleTreeId;
20
- /**
21
- * The tree root.
22
- */
23
- root: Buffer;
24
- /**
25
- * The number of leaves in the tree.
26
- */
27
- size: bigint;
28
-
29
- /**
30
- * The depth of the tree.
31
- */
32
- depth: number;
33
- }
34
-
35
- export type MerkleTreeMap = {
36
- [MerkleTreeId.NULLIFIER_TREE]: IndexedTree;
37
- [MerkleTreeId.NOTE_HASH_TREE]: AppendOnlyTree<Fr>;
38
- [MerkleTreeId.PUBLIC_DATA_TREE]: IndexedTree;
39
- [MerkleTreeId.L1_TO_L2_MESSAGE_TREE]: AppendOnlyTree<Fr>;
40
- [MerkleTreeId.ARCHIVE]: AppendOnlyTree<Fr>;
41
- };
42
-
43
- type LeafTypes = {
44
- [MerkleTreeId.NULLIFIER_TREE]: Buffer;
45
- [MerkleTreeId.NOTE_HASH_TREE]: Fr;
46
- [MerkleTreeId.PUBLIC_DATA_TREE]: Buffer;
47
- [MerkleTreeId.L1_TO_L2_MESSAGE_TREE]: Fr;
48
- [MerkleTreeId.ARCHIVE]: Fr;
49
- };
50
-
51
- export type MerkleTreeLeafType<ID extends MerkleTreeId> = LeafTypes[ID];
52
-
53
- /**
54
- * Defines the interface for operations on a set of Merkle Trees.
55
- */
56
- export interface MerkleTreeOperations {
57
- /**
58
- * Appends leaves to a given tree.
59
- * @param treeId - The tree to be updated.
60
- * @param leaves - The set of leaves to be appended.
61
- */
62
- appendLeaves<ID extends MerkleTreeId>(treeId: ID, leaves: MerkleTreeLeafType<ID>[]): Promise<void>;
63
-
64
- /**
65
- * Returns information about the given tree.
66
- * @param treeId - The tree to be queried.
67
- */
68
- getTreeInfo(treeId: MerkleTreeId): Promise<TreeInfo>;
69
-
70
- /**
71
- * Gets the current state reference.
72
- */
73
- getStateReference(): Promise<StateReference>;
74
-
75
- /**
76
- * Gets the initial header.
77
- */
78
- getInitialHeader(): Header;
79
-
80
- /**
81
- * Gets sibling path for a leaf.
82
- * @param treeId - The tree to be queried for a sibling path.
83
- * @param index - The index of the leaf for which a sibling path should be returned.
84
- */
85
- getSiblingPath<N extends number>(treeId: MerkleTreeId, index: bigint): Promise<SiblingPath<N>>;
86
-
87
- /**
88
- * Returns the previous index for a given value in an indexed tree.
89
- * @param treeId - The tree for which the previous value index is required.
90
- * @param value - The value to be queried.
91
- */
92
- getPreviousValueIndex<ID extends IndexedTreeId>(
93
- treeId: ID,
94
- value: bigint,
95
- ): Promise<
96
- | {
97
- /**
98
- * The index of the found leaf.
99
- */
100
- index: bigint;
101
- /**
102
- * A flag indicating if the corresponding leaf's value is equal to `newValue`.
103
- */
104
- alreadyPresent: boolean;
105
- }
106
- | undefined
107
- >;
108
-
109
- /**
110
- * Returns the data at a specific leaf.
111
- * @param treeId - The tree for which leaf data should be returned.
112
- * @param index - The index of the leaf required.
113
- */
114
- getLeafPreimage<ID extends IndexedTreeId>(treeId: ID, index: bigint): Promise<IndexedTreeLeafPreimage | undefined>;
115
-
116
- /**
117
- * Update the leaf data at the given index.
118
- * @param treeId - The tree for which leaf data should be edited.
119
- * @param leaf - The updated leaf value.
120
- * @param index - The index of the leaf to be updated.
121
- */
122
- updateLeaf<ID extends IndexedTreeId>(treeId: ID, leaf: NullifierLeafPreimage | Buffer, index: bigint): Promise<void>;
123
-
124
- /**
125
- * Returns the index containing a leaf value.
126
- * @param treeId - The tree for which the index should be returned.
127
- * @param value - The value to search for in the tree.
128
- */
129
- findLeafIndex<ID extends MerkleTreeId>(treeId: ID, value: MerkleTreeLeafType<ID>): Promise<bigint | undefined>;
130
-
131
- /**
132
- * Returns the first index containing a leaf value after `startIndex`.
133
- * @param treeId - The tree for which the index should be returned.
134
- * @param value - The value to search for in the tree.
135
- * @param startIndex - The index to start searching from (used when skipping nullified messages)
136
- */
137
- findLeafIndexAfter<ID extends MerkleTreeId>(
138
- treeId: ID,
139
- value: MerkleTreeLeafType<ID>,
140
- startIndex: bigint,
141
- ): Promise<bigint | undefined>;
142
-
143
- /**
144
- * Gets the value for a leaf in the tree.
145
- * @param treeId - The tree for which the index should be returned.
146
- * @param index - The index of the leaf.
147
- */
148
- getLeafValue<ID extends MerkleTreeId>(
149
- treeId: ID,
150
- index: bigint,
151
- ): Promise<MerkleTreeLeafType<typeof treeId> | undefined>;
152
-
153
- /**
154
- * Inserts the block hash into the archive.
155
- * This includes all of the current roots of all of the data trees and the current blocks global vars.
156
- * @param header - The header to insert into the archive.
157
- */
158
- updateArchive(header: Header): Promise<void>;
159
-
160
- /**
161
- * Batch insert multiple leaves into the tree.
162
- * @param leaves - Leaves to insert into the tree.
163
- * @param treeId - The tree on which to insert.
164
- * @param subtreeHeight - Height of the subtree.
165
- * @returns The witness data for the leaves to be updated when inserting the new ones.
166
- */
167
- batchInsert<TreeHeight extends number, SubtreeSiblingPathHeight extends number, ID extends IndexedTreeId>(
168
- treeId: ID,
169
- leaves: Buffer[],
170
- subtreeHeight: number,
171
- ): Promise<BatchInsertionResult<TreeHeight, SubtreeSiblingPathHeight>>;
172
-
173
- /**
174
- * Handles a single L2 block (i.e. Inserts the new note hashes into the merkle tree).
175
- * @param block - The L2 block to handle.
176
- * @param l1ToL2Messages - The L1 to L2 messages for the block.
177
- */
178
- handleL2BlockAndMessages(block: L2Block, l1ToL2Messages: Fr[]): Promise<HandleL2BlockAndMessagesResult>;
179
-
180
- /**
181
- * Commits pending changes to the underlying store.
182
- */
183
- commit(): Promise<void>;
184
-
185
- /**
186
- * Rolls back pending changes.
187
- */
188
- rollback(): Promise<void>;
189
- }
190
-
191
- /** Return type for handleL2BlockAndMessages */
192
- export type HandleL2BlockAndMessagesResult = {
193
- /** Whether the block processed was emitted by our sequencer */ isBlockOurs: boolean;
194
- };
195
-
196
- /**
197
- * Outputs a tree leaves using for debugging purposes.
198
- */
199
- export async function inspectTree(
200
- db: MerkleTreeOperations,
201
- treeId: MerkleTreeId,
202
- log = createDebugLogger('aztec:inspect-tree'),
203
- ) {
204
- const info = await db.getTreeInfo(treeId);
205
- const output = [`Tree id=${treeId} size=${info.size} root=0x${info.root.toString('hex')}`];
206
- for (let i = 0; i < info.size; i++) {
207
- output.push(
208
- ` Leaf ${i}: ${await db.getLeafValue(treeId, BigInt(i)).then(x => x?.toString('hex') ?? '[undefined]')}`,
209
- );
210
- }
211
- log.info(output.join('\n'));
212
- }