@aztec/world-state 0.0.1-commit.3100065 → 0.0.1-commit.330febf
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/index.d.ts +2 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -0
- package/dest/instrumentation/instrumentation.d.ts +4 -3
- package/dest/instrumentation/instrumentation.d.ts.map +1 -1
- package/dest/instrumentation/instrumentation.js +4 -9
- package/dest/native/index.d.ts +2 -1
- package/dest/native/index.d.ts.map +1 -1
- package/dest/native/index.js +1 -0
- package/dest/native/ipc_world_state_instance.d.ts +61 -22
- package/dest/native/ipc_world_state_instance.d.ts.map +1 -1
- package/dest/native/ipc_world_state_instance.js +530 -495
- package/dest/native/merkle_trees_facade.d.ts +4 -3
- package/dest/native/merkle_trees_facade.d.ts.map +1 -1
- package/dest/native/merkle_trees_facade.js +37 -109
- package/dest/native/message.d.ts +14 -233
- package/dest/native/message.d.ts.map +1 -1
- package/dest/native/message.js +0 -42
- package/dest/native/native_world_state.d.ts +14 -28
- package/dest/native/native_world_state.d.ts.map +1 -1
- package/dest/native/native_world_state.js +105 -99
- package/dest/native/native_world_state_instance.d.ts +56 -43
- package/dest/native/native_world_state_instance.d.ts.map +1 -1
- package/dest/native/native_world_state_instance.js +1 -223
- package/dest/native/world_state_operation.d.ts +7 -0
- package/dest/native/world_state_operation.d.ts.map +1 -0
- package/dest/native/world_state_operation.js +5 -0
- package/dest/synchronizer/factory.d.ts +1 -1
- package/dest/synchronizer/factory.d.ts.map +1 -1
- package/dest/synchronizer/factory.js +1 -1
- package/package.json +11 -10
- package/src/index.ts +1 -0
- package/src/instrumentation/instrumentation.ts +6 -18
- package/src/native/index.ts +1 -0
- package/src/native/ipc_world_state_instance.ts +625 -503
- package/src/native/merkle_trees_facade.ts +59 -104
- package/src/native/message.ts +13 -300
- package/src/native/native_world_state.ts +136 -156
- package/src/native/native_world_state_instance.ts +94 -308
- package/src/native/world_state_operation.ts +33 -0
- package/src/synchronizer/factory.ts +0 -1
- package/dest/native/world_state_ops_queue.d.ts +0 -19
- package/dest/native/world_state_ops_queue.d.ts.map +0 -1
- package/dest/native/world_state_ops_queue.js +0 -146
- package/src/native/world_state_ops_queue.ts +0 -190
|
@@ -22,14 +22,13 @@ import {
|
|
|
22
22
|
PublicDataTreeLeafPreimage,
|
|
23
23
|
} from '@aztec/stdlib/trees';
|
|
24
24
|
import { type BlockHeader, PartialStateReference, StateReference } from '@aztec/stdlib/tx';
|
|
25
|
-
import {
|
|
25
|
+
import type { WorldStateRevision } from '@aztec/stdlib/world-state';
|
|
26
26
|
|
|
27
27
|
import assert from 'assert';
|
|
28
28
|
|
|
29
29
|
import {
|
|
30
30
|
type SerializedIndexedLeaf,
|
|
31
31
|
type SerializedLeafValue,
|
|
32
|
-
WorldStateMessageType,
|
|
33
32
|
blockStateReference,
|
|
34
33
|
treeStateReferenceToSnapshot,
|
|
35
34
|
} from './message.js';
|
|
@@ -46,8 +45,12 @@ export class MerkleTreesFacade implements MerkleTreeReadOperations {
|
|
|
46
45
|
return this.initialHeader;
|
|
47
46
|
}
|
|
48
47
|
|
|
49
|
-
getRevision():
|
|
50
|
-
return
|
|
48
|
+
getRevision(): WorldStateRevision {
|
|
49
|
+
return this.revision;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
getIpcPath(): string {
|
|
53
|
+
return this.instance.getIpcPath();
|
|
51
54
|
}
|
|
52
55
|
|
|
53
56
|
findLeafIndices(treeId: MerkleTreeId, values: MerkleTreeLeafType<MerkleTreeId>[]): Promise<(bigint | undefined)[]> {
|
|
@@ -58,13 +61,13 @@ export class MerkleTreesFacade implements MerkleTreeReadOperations {
|
|
|
58
61
|
treeId: MerkleTreeId,
|
|
59
62
|
values: MerkleTreeLeafType<MerkleTreeId>[],
|
|
60
63
|
): Promise<({ path: SiblingPath<N>; index: bigint } | undefined)[]> {
|
|
61
|
-
const
|
|
62
|
-
leaves: values.map(leaf => serializeLeaf(hydrateLeaf(treeId, leaf))),
|
|
63
|
-
revision: this.revision,
|
|
64
|
+
const paths = await this.instance.findSiblingPaths(
|
|
64
65
|
treeId,
|
|
65
|
-
|
|
66
|
+
this.revision,
|
|
67
|
+
values.map(leaf => serializeLeaf(hydrateLeaf(treeId, leaf))),
|
|
68
|
+
);
|
|
66
69
|
|
|
67
|
-
return
|
|
70
|
+
return paths.map(path => {
|
|
68
71
|
if (!path) {
|
|
69
72
|
return undefined;
|
|
70
73
|
}
|
|
@@ -77,14 +80,14 @@ export class MerkleTreesFacade implements MerkleTreeReadOperations {
|
|
|
77
80
|
leaves: MerkleTreeLeafType<MerkleTreeId>[],
|
|
78
81
|
startIndex: bigint,
|
|
79
82
|
): Promise<(bigint | undefined)[]> {
|
|
80
|
-
const
|
|
81
|
-
leaves: leaves.map(leaf => serializeLeaf(hydrateLeaf(treeId, leaf))),
|
|
82
|
-
revision: this.revision,
|
|
83
|
+
const indices = await this.instance.findLeafIndices(
|
|
83
84
|
treeId,
|
|
85
|
+
this.revision,
|
|
86
|
+
leaves.map(leaf => serializeLeaf(hydrateLeaf(treeId, leaf))),
|
|
84
87
|
startIndex,
|
|
85
|
-
|
|
88
|
+
);
|
|
86
89
|
|
|
87
|
-
return
|
|
90
|
+
return indices.map(index => {
|
|
88
91
|
if (typeof index === 'number' || typeof index === 'bigint') {
|
|
89
92
|
return BigInt(index);
|
|
90
93
|
} else {
|
|
@@ -94,11 +97,7 @@ export class MerkleTreesFacade implements MerkleTreeReadOperations {
|
|
|
94
97
|
}
|
|
95
98
|
|
|
96
99
|
async getLeafPreimage(treeId: IndexedTreeId, leafIndex: bigint): Promise<IndexedTreeLeafPreimage | undefined> {
|
|
97
|
-
const resp = await this.instance.
|
|
98
|
-
leafIndex,
|
|
99
|
-
revision: this.revision,
|
|
100
|
-
treeId,
|
|
101
|
-
});
|
|
100
|
+
const resp = await this.instance.getLeafPreimage(treeId, this.revision, leafIndex);
|
|
102
101
|
|
|
103
102
|
return resp ? deserializeIndexedLeaf(resp) : undefined;
|
|
104
103
|
}
|
|
@@ -107,11 +106,7 @@ export class MerkleTreesFacade implements MerkleTreeReadOperations {
|
|
|
107
106
|
treeId: ID,
|
|
108
107
|
leafIndex: bigint,
|
|
109
108
|
): Promise<MerkleTreeLeafType<ID> | undefined> {
|
|
110
|
-
const resp = await this.instance.
|
|
111
|
-
leafIndex,
|
|
112
|
-
revision: this.revision,
|
|
113
|
-
treeId,
|
|
114
|
-
});
|
|
109
|
+
const resp = await this.instance.getLeafValue(treeId, this.revision, leafIndex);
|
|
115
110
|
|
|
116
111
|
if (!resp) {
|
|
117
112
|
return undefined;
|
|
@@ -129,11 +124,7 @@ export class MerkleTreesFacade implements MerkleTreeReadOperations {
|
|
|
129
124
|
treeId: IndexedTreeId,
|
|
130
125
|
value: bigint,
|
|
131
126
|
): Promise<{ index: bigint; alreadyPresent: boolean } | undefined> {
|
|
132
|
-
const resp = await this.instance.
|
|
133
|
-
key: new Fr(value),
|
|
134
|
-
revision: this.revision,
|
|
135
|
-
treeId,
|
|
136
|
-
});
|
|
127
|
+
const resp = await this.instance.findLowLeaf(treeId, this.revision, new Fr(value));
|
|
137
128
|
return {
|
|
138
129
|
alreadyPresent: resp.alreadyPresent,
|
|
139
130
|
index: BigInt(resp.index),
|
|
@@ -141,68 +132,48 @@ export class MerkleTreesFacade implements MerkleTreeReadOperations {
|
|
|
141
132
|
}
|
|
142
133
|
|
|
143
134
|
async getSiblingPath<N extends number>(treeId: MerkleTreeId, leafIndex: bigint): Promise<SiblingPath<N>> {
|
|
144
|
-
const siblingPath = await this.instance.
|
|
145
|
-
leafIndex,
|
|
146
|
-
revision: this.revision,
|
|
147
|
-
treeId,
|
|
148
|
-
});
|
|
135
|
+
const siblingPath = await this.instance.getSiblingPath(treeId, this.revision, leafIndex);
|
|
149
136
|
|
|
150
137
|
return new SiblingPath(siblingPath.length, siblingPath) as any;
|
|
151
138
|
}
|
|
152
139
|
|
|
153
140
|
async getStateReference(): Promise<StateReference> {
|
|
154
|
-
const
|
|
155
|
-
revision: this.revision,
|
|
156
|
-
});
|
|
141
|
+
const state = await this.instance.getStateReference(this.revision);
|
|
157
142
|
|
|
158
143
|
return new StateReference(
|
|
159
|
-
treeStateReferenceToSnapshot(
|
|
144
|
+
treeStateReferenceToSnapshot(state[MerkleTreeId.L1_TO_L2_MESSAGE_TREE]),
|
|
160
145
|
new PartialStateReference(
|
|
161
|
-
treeStateReferenceToSnapshot(
|
|
162
|
-
treeStateReferenceToSnapshot(
|
|
163
|
-
treeStateReferenceToSnapshot(
|
|
146
|
+
treeStateReferenceToSnapshot(state[MerkleTreeId.NOTE_HASH_TREE]),
|
|
147
|
+
treeStateReferenceToSnapshot(state[MerkleTreeId.NULLIFIER_TREE]),
|
|
148
|
+
treeStateReferenceToSnapshot(state[MerkleTreeId.PUBLIC_DATA_TREE]),
|
|
164
149
|
),
|
|
165
150
|
);
|
|
166
151
|
}
|
|
167
152
|
|
|
168
153
|
async getInitialStateReference(): Promise<StateReference> {
|
|
169
|
-
const
|
|
154
|
+
const state = await this.instance.getInitialStateReference();
|
|
170
155
|
|
|
171
156
|
return new StateReference(
|
|
172
|
-
treeStateReferenceToSnapshot(
|
|
157
|
+
treeStateReferenceToSnapshot(state[MerkleTreeId.L1_TO_L2_MESSAGE_TREE]),
|
|
173
158
|
new PartialStateReference(
|
|
174
|
-
treeStateReferenceToSnapshot(
|
|
175
|
-
treeStateReferenceToSnapshot(
|
|
176
|
-
treeStateReferenceToSnapshot(
|
|
159
|
+
treeStateReferenceToSnapshot(state[MerkleTreeId.NOTE_HASH_TREE]),
|
|
160
|
+
treeStateReferenceToSnapshot(state[MerkleTreeId.NULLIFIER_TREE]),
|
|
161
|
+
treeStateReferenceToSnapshot(state[MerkleTreeId.PUBLIC_DATA_TREE]),
|
|
177
162
|
),
|
|
178
163
|
);
|
|
179
164
|
}
|
|
180
165
|
|
|
181
166
|
async getTreeInfo(treeId: MerkleTreeId): Promise<TreeInfo> {
|
|
182
|
-
|
|
183
|
-
treeId: treeId,
|
|
184
|
-
revision: this.revision,
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
return {
|
|
188
|
-
depth: resp.depth,
|
|
189
|
-
root: resp.root,
|
|
190
|
-
size: BigInt(resp.size),
|
|
191
|
-
treeId,
|
|
192
|
-
};
|
|
167
|
+
return await this.instance.getTreeInfo(treeId, this.revision);
|
|
193
168
|
}
|
|
194
169
|
|
|
195
170
|
async getBlockNumbersForLeafIndices<ID extends MerkleTreeId>(
|
|
196
171
|
treeId: ID,
|
|
197
172
|
leafIndices: bigint[],
|
|
198
173
|
): Promise<(BlockNumber | undefined)[]> {
|
|
199
|
-
const
|
|
200
|
-
treeId,
|
|
201
|
-
revision: this.revision,
|
|
202
|
-
leafIndices,
|
|
203
|
-
});
|
|
174
|
+
const blockNumbers = await this.instance.getBlockNumbersForLeafIndices(treeId, this.revision, leafIndices);
|
|
204
175
|
|
|
205
|
-
return
|
|
176
|
+
return blockNumbers.map(x => (x === undefined || x === null ? undefined : BlockNumber(Number(x))));
|
|
206
177
|
}
|
|
207
178
|
}
|
|
208
179
|
|
|
@@ -221,19 +192,19 @@ export class MerkleTreesForkFacade extends MerkleTreesFacade implements MerkleTr
|
|
|
221
192
|
super(instance, initialHeader, revision);
|
|
222
193
|
}
|
|
223
194
|
async updateArchive(header: BlockHeader): Promise<void> {
|
|
224
|
-
await this.instance.
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
195
|
+
await this.instance.updateArchive(
|
|
196
|
+
this.revision.forkId,
|
|
197
|
+
blockStateReference(header.state),
|
|
198
|
+
(await header.hash()).toBuffer(),
|
|
199
|
+
);
|
|
229
200
|
}
|
|
230
201
|
|
|
231
202
|
async appendLeaves<ID extends MerkleTreeId>(treeId: ID, leaves: MerkleTreeLeafType<ID>[]): Promise<void> {
|
|
232
|
-
await this.instance.
|
|
233
|
-
leaves: leaves.map(leaf => serializeLeaf(hydrateLeaf(treeId, leaf as any))),
|
|
234
|
-
forkId: this.revision.forkId,
|
|
203
|
+
await this.instance.appendLeaves(
|
|
235
204
|
treeId,
|
|
236
|
-
|
|
205
|
+
this.revision.forkId,
|
|
206
|
+
leaves.map(leaf => serializeLeaf(hydrateLeaf(treeId, leaf as any))),
|
|
207
|
+
);
|
|
237
208
|
}
|
|
238
209
|
|
|
239
210
|
async batchInsert<TreeHeight extends number, SubtreeSiblingPathHeight extends number, ID extends IndexedTreeId>(
|
|
@@ -242,24 +213,19 @@ export class MerkleTreesForkFacade extends MerkleTreesFacade implements MerkleTr
|
|
|
242
213
|
subtreeHeight: number,
|
|
243
214
|
): Promise<BatchInsertionResult<TreeHeight, SubtreeSiblingPathHeight>> {
|
|
244
215
|
const leaves = rawLeaves.map((leaf: Buffer) => hydrateLeaf(treeId, leaf)).map(serializeLeaf);
|
|
245
|
-
const resp = await this.instance.
|
|
246
|
-
leaves,
|
|
247
|
-
treeId,
|
|
248
|
-
forkId: this.revision.forkId,
|
|
249
|
-
subtreeDepth: subtreeHeight,
|
|
250
|
-
});
|
|
216
|
+
const resp = await this.instance.batchInsert(treeId, this.revision.forkId, leaves, subtreeHeight);
|
|
251
217
|
|
|
252
218
|
return {
|
|
253
219
|
newSubtreeSiblingPath: new SiblingPath<SubtreeSiblingPathHeight>(
|
|
254
|
-
resp.
|
|
255
|
-
resp.
|
|
220
|
+
resp.subtreePath.length as any,
|
|
221
|
+
resp.subtreePath,
|
|
256
222
|
),
|
|
257
|
-
sortedNewLeaves: resp.
|
|
223
|
+
sortedNewLeaves: resp.sortedLeaves
|
|
258
224
|
.map(([leaf]) => leaf)
|
|
259
225
|
.map(deserializeLeafValue)
|
|
260
226
|
.map(serializeToBuffer),
|
|
261
|
-
sortedNewLeavesIndexes: resp.
|
|
262
|
-
lowLeavesWitnessData: resp.
|
|
227
|
+
sortedNewLeavesIndexes: resp.sortedLeaves.map(([, index]) => index),
|
|
228
|
+
lowLeavesWitnessData: resp.lowLeafWitnessData.map(data => ({
|
|
263
229
|
index: BigInt(data.index),
|
|
264
230
|
leafPreimage: deserializeIndexedLeaf(data.leaf),
|
|
265
231
|
siblingPath: new SiblingPath<TreeHeight>(data.path.length as any, data.path),
|
|
@@ -272,19 +238,15 @@ export class MerkleTreesForkFacade extends MerkleTreesFacade implements MerkleTr
|
|
|
272
238
|
rawLeaves: Buffer[],
|
|
273
239
|
): Promise<SequentialInsertionResult<TreeHeight>> {
|
|
274
240
|
const leaves = rawLeaves.map((leaf: Buffer) => hydrateLeaf(treeId, leaf)).map(serializeLeaf);
|
|
275
|
-
const resp = await this.instance.
|
|
276
|
-
leaves,
|
|
277
|
-
treeId,
|
|
278
|
-
forkId: this.revision.forkId,
|
|
279
|
-
});
|
|
241
|
+
const resp = await this.instance.sequentialInsert(treeId, this.revision.forkId, leaves);
|
|
280
242
|
|
|
281
243
|
return {
|
|
282
|
-
lowLeavesWitnessData: resp.
|
|
244
|
+
lowLeavesWitnessData: resp.lowLeafWitnessData.map(data => ({
|
|
283
245
|
index: BigInt(data.index),
|
|
284
246
|
leafPreimage: deserializeIndexedLeaf(data.leaf),
|
|
285
247
|
siblingPath: new SiblingPath<TreeHeight>(data.path.length as any, data.path),
|
|
286
248
|
})),
|
|
287
|
-
insertionWitnessData: resp.
|
|
249
|
+
insertionWitnessData: resp.insertionWitnessData.map(data => ({
|
|
288
250
|
index: BigInt(data.index),
|
|
289
251
|
leafPreimage: deserializeIndexedLeaf(data.leaf),
|
|
290
252
|
siblingPath: new SiblingPath<TreeHeight>(data.path.length as any, data.path),
|
|
@@ -304,11 +266,11 @@ export class MerkleTreesForkFacade extends MerkleTreesFacade implements MerkleTr
|
|
|
304
266
|
|
|
305
267
|
private async doClose(): Promise<void> {
|
|
306
268
|
try {
|
|
307
|
-
await this.instance.
|
|
269
|
+
await this.instance.deleteFork(this.revision.forkId);
|
|
308
270
|
} catch (err: any) {
|
|
309
271
|
// Ignore errors due to native instance being closed during shutdown.
|
|
310
272
|
// This can happen when validators are still processing block proposals while the node is stopping.
|
|
311
|
-
if (err?.message === 'Native instance is closed') {
|
|
273
|
+
if (err?.message === 'Native instance is closed' || err?.message === 'IPC instance is closed') {
|
|
312
274
|
return;
|
|
313
275
|
}
|
|
314
276
|
// Ignore "Fork not found": the native fork was already destroyed by a pending-chain unwind or a
|
|
@@ -335,34 +297,27 @@ export class MerkleTreesForkFacade extends MerkleTreesFacade implements MerkleTr
|
|
|
335
297
|
|
|
336
298
|
public async createCheckpoint(): Promise<number> {
|
|
337
299
|
assert.notEqual(this.revision.forkId, 0, 'Fork ID must be set');
|
|
338
|
-
|
|
339
|
-
return resp.depth;
|
|
300
|
+
return await this.instance.createCheckpoint(this.revision.forkId);
|
|
340
301
|
}
|
|
341
302
|
|
|
342
303
|
public async commitCheckpoint(): Promise<void> {
|
|
343
304
|
assert.notEqual(this.revision.forkId, 0, 'Fork ID must be set');
|
|
344
|
-
await this.instance.
|
|
305
|
+
await this.instance.commitCheckpoint(this.revision.forkId);
|
|
345
306
|
}
|
|
346
307
|
|
|
347
308
|
public async revertCheckpoint(): Promise<void> {
|
|
348
309
|
assert.notEqual(this.revision.forkId, 0, 'Fork ID must be set');
|
|
349
|
-
await this.instance.
|
|
310
|
+
await this.instance.revertCheckpoint(this.revision.forkId);
|
|
350
311
|
}
|
|
351
312
|
|
|
352
313
|
public async commitAllCheckpointsTo(depth: number): Promise<void> {
|
|
353
314
|
assert.notEqual(this.revision.forkId, 0, 'Fork ID must be set');
|
|
354
|
-
await this.instance.
|
|
355
|
-
forkId: this.revision.forkId,
|
|
356
|
-
depth,
|
|
357
|
-
});
|
|
315
|
+
await this.instance.commitAllCheckpoints(this.revision.forkId, depth);
|
|
358
316
|
}
|
|
359
317
|
|
|
360
318
|
public async revertAllCheckpointsTo(depth: number): Promise<void> {
|
|
361
319
|
assert.notEqual(this.revision.forkId, 0, 'Fork ID must be set');
|
|
362
|
-
await this.instance.
|
|
363
|
-
forkId: this.revision.forkId,
|
|
364
|
-
depth,
|
|
365
|
-
});
|
|
320
|
+
await this.instance.revertAllCheckpoints(this.revision.forkId, depth);
|
|
366
321
|
}
|
|
367
322
|
}
|
|
368
323
|
|
package/src/native/message.ts
CHANGED
|
@@ -1,59 +1,7 @@
|
|
|
1
1
|
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
2
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
|
-
import type { Tuple } from '@aztec/foundation/serialize';
|
|
4
3
|
import { AppendOnlyTreeSnapshot, MerkleTreeId } from '@aztec/stdlib/trees';
|
|
5
4
|
import type { StateReference } from '@aztec/stdlib/tx';
|
|
6
|
-
import type { UInt32 } from '@aztec/stdlib/types';
|
|
7
|
-
import type { WorldStateRevision } from '@aztec/stdlib/world-state';
|
|
8
|
-
|
|
9
|
-
export enum WorldStateMessageType {
|
|
10
|
-
GET_TREE_INFO = 100,
|
|
11
|
-
GET_STATE_REFERENCE,
|
|
12
|
-
GET_INITIAL_STATE_REFERENCE,
|
|
13
|
-
|
|
14
|
-
GET_LEAF_VALUE,
|
|
15
|
-
GET_LEAF_PREIMAGE,
|
|
16
|
-
GET_SIBLING_PATH,
|
|
17
|
-
GET_BLOCK_NUMBERS_FOR_LEAF_INDICES,
|
|
18
|
-
|
|
19
|
-
FIND_LEAF_INDICES,
|
|
20
|
-
FIND_LOW_LEAF,
|
|
21
|
-
FIND_SIBLING_PATHS,
|
|
22
|
-
|
|
23
|
-
APPEND_LEAVES,
|
|
24
|
-
BATCH_INSERT,
|
|
25
|
-
SEQUENTIAL_INSERT,
|
|
26
|
-
|
|
27
|
-
UPDATE_ARCHIVE,
|
|
28
|
-
|
|
29
|
-
COMMIT,
|
|
30
|
-
ROLLBACK,
|
|
31
|
-
|
|
32
|
-
SYNC_BLOCK,
|
|
33
|
-
|
|
34
|
-
CREATE_FORK,
|
|
35
|
-
DELETE_FORK,
|
|
36
|
-
|
|
37
|
-
FINALIZE_BLOCKS,
|
|
38
|
-
UNWIND_BLOCKS,
|
|
39
|
-
REMOVE_HISTORICAL_BLOCKS,
|
|
40
|
-
|
|
41
|
-
GET_STATUS,
|
|
42
|
-
|
|
43
|
-
CREATE_CHECKPOINT,
|
|
44
|
-
COMMIT_CHECKPOINT,
|
|
45
|
-
REVERT_CHECKPOINT,
|
|
46
|
-
COMMIT_ALL_CHECKPOINTS,
|
|
47
|
-
REVERT_ALL_CHECKPOINTS,
|
|
48
|
-
|
|
49
|
-
COPY_STORES,
|
|
50
|
-
|
|
51
|
-
CLOSE = 999,
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
interface WithTreeId {
|
|
55
|
-
treeId: MerkleTreeId;
|
|
56
|
-
}
|
|
57
5
|
|
|
58
6
|
export interface WorldStateStatusSummary {
|
|
59
7
|
/** Last block number that can still be unwound. */
|
|
@@ -279,32 +227,6 @@ export function sanitizeFullStatus(status: WorldStateStatusFull) {
|
|
|
279
227
|
return status;
|
|
280
228
|
}
|
|
281
229
|
|
|
282
|
-
interface WithForkId {
|
|
283
|
-
forkId: number;
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
interface CreateCheckpointResponse {
|
|
287
|
-
depth: number;
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
/** Request to commit/revert all checkpoints down to a target depth. The resulting depth after the operation equals the given depth. */
|
|
291
|
-
interface CheckpointDepthRequest extends WithForkId {
|
|
292
|
-
/** The target depth after the operation. All checkpoints above this depth are committed/reverted. */
|
|
293
|
-
depth: number;
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
interface WithWorldStateRevision {
|
|
297
|
-
revision: WorldStateRevision;
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
interface WithCanonicalForkId {
|
|
301
|
-
canonical: true;
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
interface WithLeafIndex {
|
|
305
|
-
leafIndex: bigint;
|
|
306
|
-
}
|
|
307
|
-
|
|
308
230
|
export type SerializedLeafValue =
|
|
309
231
|
| Buffer // Fr
|
|
310
232
|
| { nullifier: Buffer } // NullifierLeaf
|
|
@@ -316,245 +238,36 @@ export type SerializedIndexedLeaf = {
|
|
|
316
238
|
nextKey: Buffer; // Fr
|
|
317
239
|
};
|
|
318
240
|
|
|
319
|
-
interface
|
|
320
|
-
leaves: SerializedLeafValue[];
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
interface BlockShiftRequest extends WithCanonicalForkId {
|
|
324
|
-
toBlockNumber: BlockNumber;
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
interface WithLeaves {
|
|
328
|
-
leaves: SerializedLeafValue[];
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
interface GetTreeInfoRequest extends WithTreeId, WithWorldStateRevision {}
|
|
332
|
-
interface GetTreeInfoResponse {
|
|
333
|
-
treeId: MerkleTreeId;
|
|
334
|
-
depth: UInt32;
|
|
335
|
-
size: bigint | number;
|
|
336
|
-
root: Buffer;
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
interface GetBlockNumbersForLeafIndicesRequest extends WithTreeId, WithWorldStateRevision {
|
|
340
|
-
leafIndices: bigint[];
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
interface GetBlockNumbersForLeafIndicesResponse {
|
|
344
|
-
blockNumbers: bigint[];
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
interface GetSiblingPathRequest extends WithTreeId, WithLeafIndex, WithWorldStateRevision {}
|
|
348
|
-
type GetSiblingPathResponse = Buffer[];
|
|
349
|
-
|
|
350
|
-
interface GetStateReferenceRequest extends WithWorldStateRevision {}
|
|
351
|
-
interface GetStateReferenceResponse {
|
|
352
|
-
state: Record<MerkleTreeId, TreeStateReference>;
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
interface GetLeafRequest extends WithTreeId, WithWorldStateRevision, WithLeafIndex {}
|
|
356
|
-
type GetLeafResponse = SerializedLeafValue | undefined;
|
|
357
|
-
|
|
358
|
-
interface GetLeafPreImageRequest extends WithTreeId, WithLeafIndex, WithWorldStateRevision {}
|
|
359
|
-
type GetLeafPreImageResponse = SerializedIndexedLeaf | undefined;
|
|
360
|
-
|
|
361
|
-
interface FindLeafIndicesRequest extends WithTreeId, WithLeafValues, WithWorldStateRevision {
|
|
362
|
-
startIndex: bigint;
|
|
363
|
-
}
|
|
364
|
-
interface FindLeafIndicesResponse {
|
|
365
|
-
indices: bigint[];
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
interface FindSiblingPathsRequest extends WithTreeId, WithLeafValues, WithWorldStateRevision {}
|
|
369
|
-
|
|
370
|
-
interface SiblingPathAndIndex {
|
|
241
|
+
export interface SerializedSiblingPathAndIndex {
|
|
371
242
|
index: bigint;
|
|
372
243
|
path: Buffer[];
|
|
373
244
|
}
|
|
374
|
-
interface FindSiblingPathsResponse {
|
|
375
|
-
paths: (SiblingPathAndIndex | undefined)[];
|
|
376
|
-
}
|
|
377
245
|
|
|
378
|
-
interface
|
|
379
|
-
|
|
380
|
-
}
|
|
381
|
-
interface FindLowLeafResponse {
|
|
382
|
-
index: bigint | number;
|
|
383
|
-
alreadyPresent: boolean;
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
interface AppendLeavesRequest extends WithTreeId, WithForkId, WithLeaves {}
|
|
387
|
-
|
|
388
|
-
interface BatchInsertRequest extends WithTreeId, WithForkId, WithLeaves {
|
|
389
|
-
subtreeDepth: number;
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
interface BatchInsertResponse {
|
|
393
|
-
low_leaf_witness_data: ReadonlyArray<{
|
|
246
|
+
export interface SerializedBatchInsertionResult {
|
|
247
|
+
lowLeafWitnessData: ReadonlyArray<{
|
|
394
248
|
leaf: SerializedIndexedLeaf;
|
|
395
249
|
index: bigint | number;
|
|
396
|
-
path:
|
|
250
|
+
path: Buffer[];
|
|
397
251
|
}>;
|
|
398
|
-
|
|
399
|
-
|
|
252
|
+
sortedLeaves: ReadonlyArray<readonly [SerializedLeafValue, number]>;
|
|
253
|
+
subtreePath: Buffer[];
|
|
400
254
|
}
|
|
401
255
|
|
|
402
|
-
interface
|
|
403
|
-
|
|
404
|
-
interface SequentialInsertResponse {
|
|
405
|
-
low_leaf_witness_data: ReadonlyArray<{
|
|
256
|
+
export interface SerializedSequentialInsertionResult {
|
|
257
|
+
lowLeafWitnessData: ReadonlyArray<{
|
|
406
258
|
leaf: SerializedIndexedLeaf;
|
|
407
259
|
index: bigint | number;
|
|
408
|
-
path:
|
|
260
|
+
path: Buffer[];
|
|
409
261
|
}>;
|
|
410
|
-
|
|
262
|
+
insertionWitnessData: ReadonlyArray<{
|
|
411
263
|
leaf: SerializedIndexedLeaf;
|
|
412
264
|
index: bigint | number;
|
|
413
|
-
path:
|
|
265
|
+
path: Buffer[];
|
|
414
266
|
}>;
|
|
415
267
|
}
|
|
416
268
|
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
blockHeaderHash: Buffer;
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
interface SyncBlockRequest extends WithCanonicalForkId {
|
|
423
|
-
blockNumber: BlockNumber;
|
|
424
|
-
blockStateRef: BlockStateReference;
|
|
425
|
-
blockHeaderHash: Buffer;
|
|
426
|
-
/** Canonical archive root after this block; world state rejects the sync if its computed root differs. */
|
|
427
|
-
expectedArchiveRoot: Buffer;
|
|
428
|
-
/** Canonical archive root before this block (the block's lastArchive); verified against the local root. */
|
|
429
|
-
expectedPreviousArchiveRoot: Buffer;
|
|
430
|
-
paddedNoteHashes: readonly SerializedLeafValue[];
|
|
431
|
-
paddedL1ToL2Messages: readonly SerializedLeafValue[];
|
|
432
|
-
paddedNullifiers: readonly SerializedLeafValue[];
|
|
433
|
-
publicDataWrites: readonly SerializedLeafValue[];
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
interface CreateForkRequest extends WithCanonicalForkId {
|
|
437
|
-
latest: boolean;
|
|
438
|
-
blockNumber: BlockNumber;
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
interface CreateForkResponse {
|
|
442
|
-
forkId: number;
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
interface DeleteForkRequest extends WithForkId {}
|
|
446
|
-
|
|
447
|
-
interface CopyStoresRequest extends WithCanonicalForkId {
|
|
448
|
-
dstPath: string;
|
|
449
|
-
compact: boolean;
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
export type WorldStateRequestCategories = WithForkId | WithWorldStateRevision | WithCanonicalForkId;
|
|
453
|
-
|
|
454
|
-
export function isWithForkId(body: WorldStateRequestCategories): body is WithForkId {
|
|
455
|
-
return body && 'forkId' in body;
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
export function isWithRevision(body: WorldStateRequestCategories): body is WithWorldStateRevision {
|
|
459
|
-
return body && 'revision' in body;
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
export function isWithCanonical(body: WorldStateRequestCategories): body is WithCanonicalForkId {
|
|
463
|
-
return body && 'canonical' in body;
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
export type WorldStateRequest = {
|
|
467
|
-
[WorldStateMessageType.GET_TREE_INFO]: GetTreeInfoRequest;
|
|
468
|
-
[WorldStateMessageType.GET_STATE_REFERENCE]: GetStateReferenceRequest;
|
|
469
|
-
[WorldStateMessageType.GET_INITIAL_STATE_REFERENCE]: WithCanonicalForkId;
|
|
470
|
-
|
|
471
|
-
[WorldStateMessageType.GET_LEAF_VALUE]: GetLeafRequest;
|
|
472
|
-
[WorldStateMessageType.GET_LEAF_PREIMAGE]: GetLeafPreImageRequest;
|
|
473
|
-
[WorldStateMessageType.GET_SIBLING_PATH]: GetSiblingPathRequest;
|
|
474
|
-
[WorldStateMessageType.GET_BLOCK_NUMBERS_FOR_LEAF_INDICES]: GetBlockNumbersForLeafIndicesRequest;
|
|
475
|
-
|
|
476
|
-
[WorldStateMessageType.FIND_LEAF_INDICES]: FindLeafIndicesRequest;
|
|
477
|
-
[WorldStateMessageType.FIND_LOW_LEAF]: FindLowLeafRequest;
|
|
478
|
-
[WorldStateMessageType.FIND_SIBLING_PATHS]: FindSiblingPathsRequest;
|
|
479
|
-
|
|
480
|
-
[WorldStateMessageType.APPEND_LEAVES]: AppendLeavesRequest;
|
|
481
|
-
[WorldStateMessageType.BATCH_INSERT]: BatchInsertRequest;
|
|
482
|
-
[WorldStateMessageType.SEQUENTIAL_INSERT]: SequentialInsertRequest;
|
|
483
|
-
|
|
484
|
-
[WorldStateMessageType.UPDATE_ARCHIVE]: UpdateArchiveRequest;
|
|
485
|
-
|
|
486
|
-
[WorldStateMessageType.COMMIT]: WithCanonicalForkId;
|
|
487
|
-
[WorldStateMessageType.ROLLBACK]: WithCanonicalForkId;
|
|
488
|
-
|
|
489
|
-
[WorldStateMessageType.SYNC_BLOCK]: SyncBlockRequest;
|
|
490
|
-
|
|
491
|
-
[WorldStateMessageType.CREATE_FORK]: CreateForkRequest;
|
|
492
|
-
[WorldStateMessageType.DELETE_FORK]: DeleteForkRequest;
|
|
493
|
-
|
|
494
|
-
[WorldStateMessageType.REMOVE_HISTORICAL_BLOCKS]: BlockShiftRequest;
|
|
495
|
-
[WorldStateMessageType.UNWIND_BLOCKS]: BlockShiftRequest;
|
|
496
|
-
[WorldStateMessageType.FINALIZE_BLOCKS]: BlockShiftRequest;
|
|
497
|
-
|
|
498
|
-
[WorldStateMessageType.GET_STATUS]: WithCanonicalForkId;
|
|
499
|
-
|
|
500
|
-
[WorldStateMessageType.CREATE_CHECKPOINT]: WithForkId;
|
|
501
|
-
[WorldStateMessageType.COMMIT_CHECKPOINT]: WithForkId;
|
|
502
|
-
[WorldStateMessageType.REVERT_CHECKPOINT]: WithForkId;
|
|
503
|
-
[WorldStateMessageType.COMMIT_ALL_CHECKPOINTS]: CheckpointDepthRequest;
|
|
504
|
-
[WorldStateMessageType.REVERT_ALL_CHECKPOINTS]: CheckpointDepthRequest;
|
|
505
|
-
|
|
506
|
-
[WorldStateMessageType.COPY_STORES]: CopyStoresRequest;
|
|
507
|
-
|
|
508
|
-
[WorldStateMessageType.CLOSE]: WithCanonicalForkId;
|
|
509
|
-
};
|
|
510
|
-
|
|
511
|
-
export type WorldStateResponse = {
|
|
512
|
-
[WorldStateMessageType.GET_TREE_INFO]: GetTreeInfoResponse;
|
|
513
|
-
[WorldStateMessageType.GET_STATE_REFERENCE]: GetStateReferenceResponse;
|
|
514
|
-
[WorldStateMessageType.GET_INITIAL_STATE_REFERENCE]: GetStateReferenceResponse;
|
|
515
|
-
|
|
516
|
-
[WorldStateMessageType.GET_LEAF_VALUE]: GetLeafResponse;
|
|
517
|
-
[WorldStateMessageType.GET_LEAF_PREIMAGE]: GetLeafPreImageResponse;
|
|
518
|
-
[WorldStateMessageType.GET_SIBLING_PATH]: GetSiblingPathResponse;
|
|
519
|
-
[WorldStateMessageType.GET_BLOCK_NUMBERS_FOR_LEAF_INDICES]: GetBlockNumbersForLeafIndicesResponse;
|
|
520
|
-
|
|
521
|
-
[WorldStateMessageType.FIND_LEAF_INDICES]: FindLeafIndicesResponse;
|
|
522
|
-
[WorldStateMessageType.FIND_LOW_LEAF]: FindLowLeafResponse;
|
|
523
|
-
[WorldStateMessageType.FIND_SIBLING_PATHS]: FindSiblingPathsResponse;
|
|
524
|
-
|
|
525
|
-
[WorldStateMessageType.APPEND_LEAVES]: void;
|
|
526
|
-
[WorldStateMessageType.BATCH_INSERT]: BatchInsertResponse;
|
|
527
|
-
[WorldStateMessageType.SEQUENTIAL_INSERT]: SequentialInsertResponse;
|
|
528
|
-
|
|
529
|
-
[WorldStateMessageType.UPDATE_ARCHIVE]: void;
|
|
530
|
-
|
|
531
|
-
[WorldStateMessageType.COMMIT]: void;
|
|
532
|
-
[WorldStateMessageType.ROLLBACK]: void;
|
|
533
|
-
|
|
534
|
-
[WorldStateMessageType.SYNC_BLOCK]: WorldStateStatusFull;
|
|
535
|
-
|
|
536
|
-
[WorldStateMessageType.CREATE_FORK]: CreateForkResponse;
|
|
537
|
-
[WorldStateMessageType.DELETE_FORK]: void;
|
|
538
|
-
|
|
539
|
-
[WorldStateMessageType.REMOVE_HISTORICAL_BLOCKS]: WorldStateStatusFull;
|
|
540
|
-
[WorldStateMessageType.UNWIND_BLOCKS]: WorldStateStatusFull;
|
|
541
|
-
[WorldStateMessageType.FINALIZE_BLOCKS]: WorldStateStatusSummary;
|
|
542
|
-
|
|
543
|
-
[WorldStateMessageType.GET_STATUS]: WorldStateStatusSummary;
|
|
544
|
-
|
|
545
|
-
[WorldStateMessageType.CREATE_CHECKPOINT]: CreateCheckpointResponse;
|
|
546
|
-
[WorldStateMessageType.COMMIT_CHECKPOINT]: void;
|
|
547
|
-
[WorldStateMessageType.REVERT_CHECKPOINT]: void;
|
|
548
|
-
[WorldStateMessageType.COMMIT_ALL_CHECKPOINTS]: void;
|
|
549
|
-
[WorldStateMessageType.REVERT_ALL_CHECKPOINTS]: void;
|
|
550
|
-
|
|
551
|
-
[WorldStateMessageType.COPY_STORES]: void;
|
|
552
|
-
|
|
553
|
-
[WorldStateMessageType.CLOSE]: void;
|
|
554
|
-
};
|
|
555
|
-
|
|
556
|
-
type TreeStateReference = readonly [Buffer, number | bigint];
|
|
557
|
-
type BlockStateReference = Map<Exclude<MerkleTreeId, MerkleTreeId.ARCHIVE>, TreeStateReference>;
|
|
269
|
+
export type TreeStateReference = readonly [Buffer, number | bigint];
|
|
270
|
+
export type BlockStateReference = Map<Exclude<MerkleTreeId, MerkleTreeId.ARCHIVE>, TreeStateReference>;
|
|
558
271
|
|
|
559
272
|
export function treeStateReferenceToSnapshot([root, size]: TreeStateReference): AppendOnlyTreeSnapshot {
|
|
560
273
|
return new AppendOnlyTreeSnapshot(Fr.fromBuffer(root), Number(size));
|