@aztec/world-state 0.0.0-test.1 → 0.0.1-commit.1142ef1
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 +1 -1
- package/dest/instrumentation/instrumentation.d.ts +6 -4
- package/dest/instrumentation/instrumentation.d.ts.map +1 -1
- package/dest/instrumentation/instrumentation.js +19 -42
- package/dest/native/bench_metrics.d.ts +23 -0
- package/dest/native/bench_metrics.d.ts.map +1 -0
- package/dest/native/bench_metrics.js +81 -0
- package/dest/native/fork_checkpoint.d.ts +1 -1
- package/dest/native/fork_checkpoint.d.ts.map +1 -1
- package/dest/native/index.d.ts +1 -1
- package/dest/native/merkle_trees_facade.d.ts +19 -7
- package/dest/native/merkle_trees_facade.d.ts.map +1 -1
- package/dest/native/merkle_trees_facade.js +64 -11
- package/dest/native/message.d.ts +72 -51
- package/dest/native/message.d.ts.map +1 -1
- package/dest/native/message.js +61 -61
- package/dest/native/native_world_state.d.ts +28 -20
- package/dest/native/native_world_state.d.ts.map +1 -1
- package/dest/native/native_world_state.js +97 -36
- package/dest/native/native_world_state_instance.d.ts +20 -4
- package/dest/native/native_world_state_instance.d.ts.map +1 -1
- package/dest/native/native_world_state_instance.js +42 -3
- package/dest/native/world_state_ops_queue.d.ts +1 -1
- package/dest/native/world_state_ops_queue.d.ts.map +1 -1
- package/dest/native/world_state_ops_queue.js +1 -1
- package/dest/synchronizer/config.d.ts +12 -2
- package/dest/synchronizer/config.d.ts.map +1 -1
- package/dest/synchronizer/config.js +26 -1
- package/dest/synchronizer/errors.d.ts +4 -0
- package/dest/synchronizer/errors.d.ts.map +1 -0
- package/dest/synchronizer/errors.js +5 -0
- package/dest/synchronizer/factory.d.ts +9 -2
- package/dest/synchronizer/factory.d.ts.map +1 -1
- package/dest/synchronizer/factory.js +9 -4
- package/dest/synchronizer/index.d.ts +1 -1
- package/dest/synchronizer/server_world_state_synchronizer.d.ts +21 -30
- package/dest/synchronizer/server_world_state_synchronizer.d.ts.map +1 -1
- package/dest/synchronizer/server_world_state_synchronizer.js +130 -78
- package/dest/test/index.d.ts +1 -1
- package/dest/test/utils.d.ts +16 -9
- package/dest/test/utils.d.ts.map +1 -1
- package/dest/test/utils.js +56 -49
- package/dest/testing.d.ts +3 -3
- package/dest/testing.d.ts.map +1 -1
- package/dest/testing.js +7 -11
- package/dest/world-state-db/index.d.ts +1 -1
- package/dest/world-state-db/merkle_tree_db.d.ts +14 -11
- package/dest/world-state-db/merkle_tree_db.d.ts.map +1 -1
- package/package.json +24 -24
- package/src/instrumentation/instrumentation.ts +24 -44
- package/src/native/bench_metrics.ts +91 -0
- package/src/native/merkle_trees_facade.ts +73 -17
- package/src/native/message.ts +92 -73
- package/src/native/native_world_state.ts +118 -50
- package/src/native/native_world_state_instance.ts +59 -8
- package/src/native/world_state_ops_queue.ts +1 -1
- package/src/synchronizer/config.ts +47 -2
- package/src/synchronizer/errors.ts +5 -0
- package/src/synchronizer/factory.ts +31 -8
- package/src/synchronizer/server_world_state_synchronizer.ts +160 -105
- package/src/test/utils.ts +94 -84
- package/src/testing.ts +4 -8
- package/src/world-state-db/merkle_tree_db.ts +18 -10
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
2
4
|
import { serializeToBuffer } from '@aztec/foundation/serialize';
|
|
5
|
+
import { sleep } from '@aztec/foundation/sleep';
|
|
3
6
|
import { type IndexedTreeLeafPreimage, SiblingPath } from '@aztec/foundation/trees';
|
|
4
7
|
import type {
|
|
5
8
|
BatchInsertionResult,
|
|
@@ -18,6 +21,7 @@ import {
|
|
|
18
21
|
PublicDataTreeLeafPreimage,
|
|
19
22
|
} from '@aztec/stdlib/trees';
|
|
20
23
|
import { type BlockHeader, PartialStateReference, StateReference } from '@aztec/stdlib/tx';
|
|
24
|
+
import { type WorldStateRevision, WorldStateRevisionWithHandle } from '@aztec/stdlib/world-state';
|
|
21
25
|
|
|
22
26
|
import assert from 'assert';
|
|
23
27
|
|
|
@@ -25,7 +29,6 @@ import {
|
|
|
25
29
|
type SerializedIndexedLeaf,
|
|
26
30
|
type SerializedLeafValue,
|
|
27
31
|
WorldStateMessageType,
|
|
28
|
-
type WorldStateRevision,
|
|
29
32
|
blockStateReference,
|
|
30
33
|
treeStateReferenceToSnapshot,
|
|
31
34
|
} from './message.js';
|
|
@@ -42,10 +45,32 @@ export class MerkleTreesFacade implements MerkleTreeReadOperations {
|
|
|
42
45
|
return this.initialHeader;
|
|
43
46
|
}
|
|
44
47
|
|
|
48
|
+
getRevision(): WorldStateRevisionWithHandle {
|
|
49
|
+
return WorldStateRevisionWithHandle.fromWorldStateRevision(this.revision, this.instance.getHandle());
|
|
50
|
+
}
|
|
51
|
+
|
|
45
52
|
findLeafIndices(treeId: MerkleTreeId, values: MerkleTreeLeafType<MerkleTreeId>[]): Promise<(bigint | undefined)[]> {
|
|
46
53
|
return this.findLeafIndicesAfter(treeId, values, 0n);
|
|
47
54
|
}
|
|
48
55
|
|
|
56
|
+
async findSiblingPaths<N extends number>(
|
|
57
|
+
treeId: MerkleTreeId,
|
|
58
|
+
values: MerkleTreeLeafType<MerkleTreeId>[],
|
|
59
|
+
): Promise<({ path: SiblingPath<N>; index: bigint } | undefined)[]> {
|
|
60
|
+
const response = await this.instance.call(WorldStateMessageType.FIND_SIBLING_PATHS, {
|
|
61
|
+
leaves: values.map(leaf => serializeLeaf(hydrateLeaf(treeId, leaf))),
|
|
62
|
+
revision: this.revision,
|
|
63
|
+
treeId,
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
return response.paths.map(path => {
|
|
67
|
+
if (!path) {
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
return { path: new SiblingPath<N>(path.path.length as N, path.path), index: BigInt(path.index) };
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
49
74
|
async findLeafIndicesAfter(
|
|
50
75
|
treeId: MerkleTreeId,
|
|
51
76
|
leaves: MerkleTreeLeafType<MerkleTreeId>[],
|
|
@@ -169,19 +194,26 @@ export class MerkleTreesFacade implements MerkleTreeReadOperations {
|
|
|
169
194
|
async getBlockNumbersForLeafIndices<ID extends MerkleTreeId>(
|
|
170
195
|
treeId: ID,
|
|
171
196
|
leafIndices: bigint[],
|
|
172
|
-
): Promise<(
|
|
197
|
+
): Promise<(BlockNumber | undefined)[]> {
|
|
173
198
|
const response = await this.instance.call(WorldStateMessageType.GET_BLOCK_NUMBERS_FOR_LEAF_INDICES, {
|
|
174
199
|
treeId,
|
|
175
200
|
revision: this.revision,
|
|
176
201
|
leafIndices,
|
|
177
202
|
});
|
|
178
203
|
|
|
179
|
-
return response.blockNumbers.map(x => (x === undefined || x === null ? undefined :
|
|
204
|
+
return response.blockNumbers.map(x => (x === undefined || x === null ? undefined : BlockNumber(Number(x))));
|
|
180
205
|
}
|
|
181
206
|
}
|
|
182
207
|
|
|
183
208
|
export class MerkleTreesForkFacade extends MerkleTreesFacade implements MerkleTreeWriteOperations {
|
|
184
|
-
|
|
209
|
+
private log = createLogger('world-state:merkle-trees-fork-facade');
|
|
210
|
+
|
|
211
|
+
constructor(
|
|
212
|
+
instance: NativeWorldStateInstance,
|
|
213
|
+
initialHeader: BlockHeader,
|
|
214
|
+
revision: WorldStateRevision,
|
|
215
|
+
private opts: { closeDelayMs?: number },
|
|
216
|
+
) {
|
|
185
217
|
assert.notEqual(revision.forkId, 0, 'Fork ID must be set');
|
|
186
218
|
assert.equal(revision.includeUncommitted, true, 'Fork must include uncommitted data');
|
|
187
219
|
super(instance, initialHeader, revision);
|
|
@@ -263,6 +295,21 @@ export class MerkleTreesForkFacade extends MerkleTreesFacade implements MerkleTr
|
|
|
263
295
|
await this.instance.call(WorldStateMessageType.DELETE_FORK, { forkId: this.revision.forkId });
|
|
264
296
|
}
|
|
265
297
|
|
|
298
|
+
async [Symbol.dispose](): Promise<void> {
|
|
299
|
+
if (this.opts.closeDelayMs) {
|
|
300
|
+
void sleep(this.opts.closeDelayMs)
|
|
301
|
+
.then(() => this.close())
|
|
302
|
+
.catch(err => {
|
|
303
|
+
if (err && 'message' in err && err.message === 'Native instance is closed') {
|
|
304
|
+
return; // Ignore errors due to native instance being closed
|
|
305
|
+
}
|
|
306
|
+
this.log.warn('Error closing MerkleTreesForkFacade after delay', { err });
|
|
307
|
+
});
|
|
308
|
+
} else {
|
|
309
|
+
await this.close();
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
266
313
|
public async createCheckpoint(): Promise<void> {
|
|
267
314
|
assert.notEqual(this.revision.forkId, 0, 'Fork ID must be set');
|
|
268
315
|
await this.instance.call(WorldStateMessageType.CREATE_CHECKPOINT, { forkId: this.revision.forkId });
|
|
@@ -277,6 +324,16 @@ export class MerkleTreesForkFacade extends MerkleTreesFacade implements MerkleTr
|
|
|
277
324
|
assert.notEqual(this.revision.forkId, 0, 'Fork ID must be set');
|
|
278
325
|
await this.instance.call(WorldStateMessageType.REVERT_CHECKPOINT, { forkId: this.revision.forkId });
|
|
279
326
|
}
|
|
327
|
+
|
|
328
|
+
public async commitAllCheckpoints(): Promise<void> {
|
|
329
|
+
assert.notEqual(this.revision.forkId, 0, 'Fork ID must be set');
|
|
330
|
+
await this.instance.call(WorldStateMessageType.COMMIT_ALL_CHECKPOINTS, { forkId: this.revision.forkId });
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
public async revertAllCheckpoints(): Promise<void> {
|
|
334
|
+
assert.notEqual(this.revision.forkId, 0, 'Fork ID must be set');
|
|
335
|
+
await this.instance.call(WorldStateMessageType.REVERT_ALL_CHECKPOINTS, { forkId: this.revision.forkId });
|
|
336
|
+
}
|
|
280
337
|
}
|
|
281
338
|
|
|
282
339
|
function hydrateLeaf<ID extends MerkleTreeId>(treeId: ID, leaf: Fr | Buffer) {
|
|
@@ -295,7 +352,7 @@ export function serializeLeaf(leaf: Fr | NullifierLeaf | PublicDataTreeLeaf): Se
|
|
|
295
352
|
if (leaf instanceof Fr) {
|
|
296
353
|
return leaf.toBuffer();
|
|
297
354
|
} else if (leaf instanceof NullifierLeaf) {
|
|
298
|
-
return {
|
|
355
|
+
return { nullifier: leaf.nullifier.toBuffer() };
|
|
299
356
|
} else {
|
|
300
357
|
return { value: leaf.value.toBuffer(), slot: leaf.slot.toBuffer() };
|
|
301
358
|
}
|
|
@@ -307,23 +364,22 @@ function deserializeLeafValue(leaf: SerializedLeafValue): Fr | NullifierLeaf | P
|
|
|
307
364
|
} else if ('slot' in leaf) {
|
|
308
365
|
return new PublicDataTreeLeaf(Fr.fromBuffer(leaf.slot), Fr.fromBuffer(leaf.value));
|
|
309
366
|
} else {
|
|
310
|
-
return new NullifierLeaf(Fr.fromBuffer(leaf.
|
|
367
|
+
return new NullifierLeaf(Fr.fromBuffer(leaf.nullifier));
|
|
311
368
|
}
|
|
312
369
|
}
|
|
313
370
|
|
|
314
|
-
function deserializeIndexedLeaf(
|
|
315
|
-
if ('slot' in leaf
|
|
371
|
+
function deserializeIndexedLeaf(leafPreimage: SerializedIndexedLeaf): IndexedTreeLeafPreimage {
|
|
372
|
+
if ('slot' in leafPreimage.leaf) {
|
|
316
373
|
return new PublicDataTreeLeafPreimage(
|
|
317
|
-
Fr.fromBuffer(leaf.
|
|
318
|
-
Fr.fromBuffer(
|
|
319
|
-
|
|
320
|
-
BigInt(leaf.nextIndex),
|
|
374
|
+
new PublicDataTreeLeaf(Fr.fromBuffer(leafPreimage.leaf.slot), Fr.fromBuffer(leafPreimage.leaf.value)),
|
|
375
|
+
Fr.fromBuffer(leafPreimage.nextKey),
|
|
376
|
+
BigInt(leafPreimage.nextIndex),
|
|
321
377
|
);
|
|
322
|
-
} else if ('
|
|
378
|
+
} else if ('nullifier' in leafPreimage.leaf) {
|
|
323
379
|
return new NullifierLeafPreimage(
|
|
324
|
-
Fr.fromBuffer(leaf.
|
|
325
|
-
Fr.fromBuffer(
|
|
326
|
-
BigInt(
|
|
380
|
+
new NullifierLeaf(Fr.fromBuffer(leafPreimage.leaf.nullifier)),
|
|
381
|
+
Fr.fromBuffer(leafPreimage.nextKey),
|
|
382
|
+
BigInt(leafPreimage.nextIndex),
|
|
327
383
|
);
|
|
328
384
|
} else {
|
|
329
385
|
throw new Error('Invalid leaf type');
|
package/src/native/message.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
3
|
import type { Tuple } from '@aztec/foundation/serialize';
|
|
3
4
|
import { AppendOnlyTreeSnapshot, MerkleTreeId } from '@aztec/stdlib/trees';
|
|
4
5
|
import type { StateReference } from '@aztec/stdlib/tx';
|
|
5
6
|
import type { UInt32 } from '@aztec/stdlib/types';
|
|
7
|
+
import type { WorldStateRevision } from '@aztec/stdlib/world-state';
|
|
6
8
|
|
|
7
9
|
export enum WorldStateMessageType {
|
|
8
10
|
GET_TREE_INFO = 100,
|
|
@@ -16,6 +18,7 @@ export enum WorldStateMessageType {
|
|
|
16
18
|
|
|
17
19
|
FIND_LEAF_INDICES,
|
|
18
20
|
FIND_LOW_LEAF,
|
|
21
|
+
FIND_SIBLING_PATHS,
|
|
19
22
|
|
|
20
23
|
APPEND_LEAVES,
|
|
21
24
|
BATCH_INSERT,
|
|
@@ -31,7 +34,7 @@ export enum WorldStateMessageType {
|
|
|
31
34
|
CREATE_FORK,
|
|
32
35
|
DELETE_FORK,
|
|
33
36
|
|
|
34
|
-
|
|
37
|
+
FINALIZE_BLOCKS,
|
|
35
38
|
UNWIND_BLOCKS,
|
|
36
39
|
REMOVE_HISTORICAL_BLOCKS,
|
|
37
40
|
|
|
@@ -40,6 +43,10 @@ export enum WorldStateMessageType {
|
|
|
40
43
|
CREATE_CHECKPOINT,
|
|
41
44
|
COMMIT_CHECKPOINT,
|
|
42
45
|
REVERT_CHECKPOINT,
|
|
46
|
+
COMMIT_ALL_CHECKPOINTS,
|
|
47
|
+
REVERT_ALL_CHECKPOINTS,
|
|
48
|
+
|
|
49
|
+
COPY_STORES,
|
|
43
50
|
|
|
44
51
|
CLOSE = 999,
|
|
45
52
|
}
|
|
@@ -50,11 +57,11 @@ interface WithTreeId {
|
|
|
50
57
|
|
|
51
58
|
export interface WorldStateStatusSummary {
|
|
52
59
|
/** Last block number that can still be unwound. */
|
|
53
|
-
|
|
54
|
-
/** Last block number that is
|
|
55
|
-
|
|
60
|
+
unfinalizedBlockNumber: BlockNumber;
|
|
61
|
+
/** Last block number that is finalized and cannot be unwound. */
|
|
62
|
+
finalizedBlockNumber: BlockNumber;
|
|
56
63
|
/** Oldest block still available for historical queries and forks. */
|
|
57
|
-
oldestHistoricalBlock:
|
|
64
|
+
oldestHistoricalBlock: BlockNumber;
|
|
58
65
|
/** Whether the trees are in sync with each other */
|
|
59
66
|
treesAreSynched: boolean;
|
|
60
67
|
}
|
|
@@ -75,11 +82,11 @@ export interface TreeMeta {
|
|
|
75
82
|
/** The tree's initial root value */
|
|
76
83
|
initialRoot: Fr;
|
|
77
84
|
/** The current oldest historical block number of the tree */
|
|
78
|
-
oldestHistoricBlock:
|
|
79
|
-
/** The current
|
|
80
|
-
|
|
81
|
-
/** The current
|
|
82
|
-
|
|
85
|
+
oldestHistoricBlock: BlockNumber;
|
|
86
|
+
/** The current unfinalized block number of the tree */
|
|
87
|
+
unfinalizedBlockHeight: BlockNumber;
|
|
88
|
+
/** The current finalized block number of the tree */
|
|
89
|
+
finalizedBlockHeight: BlockNumber;
|
|
83
90
|
}
|
|
84
91
|
|
|
85
92
|
export interface DBStats {
|
|
@@ -94,6 +101,8 @@ export interface DBStats {
|
|
|
94
101
|
export interface TreeDBStats {
|
|
95
102
|
/** The configured max size of the DB mapping file (effectively the max possible size of the DB) */
|
|
96
103
|
mapSize: bigint;
|
|
104
|
+
/** The physical file size of the database on disk */
|
|
105
|
+
physicalFileSize: bigint;
|
|
97
106
|
/** Stats for the 'blocks' DB */
|
|
98
107
|
blocksDBStats: DBStats;
|
|
99
108
|
/** Stats for the 'nodes' DB */
|
|
@@ -149,6 +158,7 @@ export function buildEmptyDBStats() {
|
|
|
149
158
|
export function buildEmptyTreeDBStats() {
|
|
150
159
|
return {
|
|
151
160
|
mapSize: 0n,
|
|
161
|
+
physicalFileSize: 0n,
|
|
152
162
|
blocksDBStats: buildEmptyDBStats(),
|
|
153
163
|
nodesDBStats: buildEmptyDBStats(),
|
|
154
164
|
leafIndicesDBStats: buildEmptyDBStats(),
|
|
@@ -164,9 +174,9 @@ export function buildEmptyTreeMeta() {
|
|
|
164
174
|
depth: 0,
|
|
165
175
|
size: 0n,
|
|
166
176
|
committedSize: 0n,
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
oldestHistoricBlock:
|
|
177
|
+
unfinalizedBlockHeight: BlockNumber.ZERO,
|
|
178
|
+
finalizedBlockHeight: BlockNumber.ZERO,
|
|
179
|
+
oldestHistoricBlock: BlockNumber.ZERO,
|
|
170
180
|
root: Fr.ZERO,
|
|
171
181
|
initialRoot: Fr.ZERO,
|
|
172
182
|
initialSize: 0n,
|
|
@@ -195,9 +205,9 @@ export function buildEmptyWorldStateDBStats() {
|
|
|
195
205
|
|
|
196
206
|
export function buildEmptyWorldStateSummary() {
|
|
197
207
|
return {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
oldestHistoricalBlock:
|
|
208
|
+
unfinalizedBlockNumber: BlockNumber.ZERO,
|
|
209
|
+
finalizedBlockNumber: BlockNumber.ZERO,
|
|
210
|
+
oldestHistoricalBlock: BlockNumber.ZERO,
|
|
201
211
|
treesAreSynched: true,
|
|
202
212
|
} as WorldStateStatusSummary;
|
|
203
213
|
}
|
|
@@ -210,61 +220,62 @@ export function buildEmptyWorldStateStatusFull() {
|
|
|
210
220
|
} as WorldStateStatusFull;
|
|
211
221
|
}
|
|
212
222
|
|
|
213
|
-
export function
|
|
214
|
-
summary.
|
|
215
|
-
summary.
|
|
216
|
-
summary.oldestHistoricalBlock = BigInt(summary.oldestHistoricalBlock);
|
|
223
|
+
export function sanitizeSummary(summary: WorldStateStatusSummary) {
|
|
224
|
+
summary.finalizedBlockNumber = BlockNumber.fromBigInt(BigInt(summary.finalizedBlockNumber));
|
|
225
|
+
summary.unfinalizedBlockNumber = BlockNumber.fromBigInt(BigInt(summary.unfinalizedBlockNumber));
|
|
226
|
+
summary.oldestHistoricalBlock = BlockNumber.fromBigInt(BigInt(summary.oldestHistoricalBlock));
|
|
217
227
|
return summary;
|
|
218
228
|
}
|
|
219
229
|
|
|
220
|
-
export function
|
|
230
|
+
export function sanitizeDBStats(stats: DBStats) {
|
|
221
231
|
stats.numDataItems = BigInt(stats.numDataItems);
|
|
222
232
|
stats.totalUsedSize = BigInt(stats.totalUsedSize);
|
|
223
233
|
return stats;
|
|
224
234
|
}
|
|
225
235
|
|
|
226
|
-
export function
|
|
236
|
+
export function sanitizeMeta(meta: TreeMeta) {
|
|
227
237
|
meta.committedSize = BigInt(meta.committedSize);
|
|
228
|
-
meta.
|
|
238
|
+
meta.finalizedBlockHeight = BlockNumber.fromBigInt(BigInt(meta.finalizedBlockHeight));
|
|
229
239
|
meta.initialSize = BigInt(meta.initialSize);
|
|
230
|
-
meta.oldestHistoricBlock = BigInt(meta.oldestHistoricBlock);
|
|
240
|
+
meta.oldestHistoricBlock = BlockNumber.fromBigInt(BigInt(meta.oldestHistoricBlock));
|
|
231
241
|
meta.size = BigInt(meta.size);
|
|
232
|
-
meta.
|
|
242
|
+
meta.unfinalizedBlockHeight = BlockNumber.fromBigInt(BigInt(meta.unfinalizedBlockHeight));
|
|
233
243
|
return meta;
|
|
234
244
|
}
|
|
235
245
|
|
|
236
|
-
export function
|
|
237
|
-
stats.blocksDBStats =
|
|
238
|
-
stats.leafIndicesDBStats =
|
|
239
|
-
stats.leafPreimagesDBStats =
|
|
240
|
-
stats.blockIndicesDBStats =
|
|
241
|
-
stats.nodesDBStats =
|
|
246
|
+
export function sanitizeTreeDBStats(stats: TreeDBStats) {
|
|
247
|
+
stats.blocksDBStats = sanitizeDBStats(stats.blocksDBStats);
|
|
248
|
+
stats.leafIndicesDBStats = sanitizeDBStats(stats.leafIndicesDBStats);
|
|
249
|
+
stats.leafPreimagesDBStats = sanitizeDBStats(stats.leafPreimagesDBStats);
|
|
250
|
+
stats.blockIndicesDBStats = sanitizeDBStats(stats.blockIndicesDBStats);
|
|
251
|
+
stats.nodesDBStats = sanitizeDBStats(stats.nodesDBStats);
|
|
242
252
|
stats.mapSize = BigInt(stats.mapSize);
|
|
253
|
+
stats.physicalFileSize = BigInt(stats.physicalFileSize);
|
|
243
254
|
return stats;
|
|
244
255
|
}
|
|
245
256
|
|
|
246
|
-
export function
|
|
247
|
-
stats.archiveTreeStats =
|
|
248
|
-
stats.messageTreeStats =
|
|
249
|
-
stats.noteHashTreeStats =
|
|
250
|
-
stats.nullifierTreeStats =
|
|
251
|
-
stats.publicDataTreeStats =
|
|
257
|
+
export function sanitizeWorldStateDBStats(stats: WorldStateDBStats) {
|
|
258
|
+
stats.archiveTreeStats = sanitizeTreeDBStats(stats.archiveTreeStats);
|
|
259
|
+
stats.messageTreeStats = sanitizeTreeDBStats(stats.messageTreeStats);
|
|
260
|
+
stats.noteHashTreeStats = sanitizeTreeDBStats(stats.noteHashTreeStats);
|
|
261
|
+
stats.nullifierTreeStats = sanitizeTreeDBStats(stats.nullifierTreeStats);
|
|
262
|
+
stats.publicDataTreeStats = sanitizeTreeDBStats(stats.publicDataTreeStats);
|
|
252
263
|
return stats;
|
|
253
264
|
}
|
|
254
265
|
|
|
255
|
-
export function
|
|
256
|
-
meta.archiveTreeMeta =
|
|
257
|
-
meta.messageTreeMeta =
|
|
258
|
-
meta.noteHashTreeMeta =
|
|
259
|
-
meta.nullifierTreeMeta =
|
|
260
|
-
meta.publicDataTreeMeta =
|
|
266
|
+
export function sanitizeWorldStateTreeMeta(meta: WorldStateMeta) {
|
|
267
|
+
meta.archiveTreeMeta = sanitizeMeta(meta.archiveTreeMeta);
|
|
268
|
+
meta.messageTreeMeta = sanitizeMeta(meta.messageTreeMeta);
|
|
269
|
+
meta.noteHashTreeMeta = sanitizeMeta(meta.noteHashTreeMeta);
|
|
270
|
+
meta.nullifierTreeMeta = sanitizeMeta(meta.nullifierTreeMeta);
|
|
271
|
+
meta.publicDataTreeMeta = sanitizeMeta(meta.publicDataTreeMeta);
|
|
261
272
|
return meta;
|
|
262
273
|
}
|
|
263
274
|
|
|
264
|
-
export function
|
|
265
|
-
status.dbStats =
|
|
266
|
-
status.summary =
|
|
267
|
-
status.meta =
|
|
275
|
+
export function sanitizeFullStatus(status: WorldStateStatusFull) {
|
|
276
|
+
status.dbStats = sanitizeWorldStateDBStats(status.dbStats);
|
|
277
|
+
status.summary = sanitizeSummary(status.summary);
|
|
278
|
+
status.meta = sanitizeWorldStateTreeMeta(status.meta);
|
|
268
279
|
return status;
|
|
269
280
|
}
|
|
270
281
|
|
|
@@ -286,13 +297,13 @@ interface WithLeafIndex {
|
|
|
286
297
|
|
|
287
298
|
export type SerializedLeafValue =
|
|
288
299
|
| Buffer // Fr
|
|
289
|
-
| {
|
|
300
|
+
| { nullifier: Buffer } // NullifierLeaf
|
|
290
301
|
| { value: Buffer; slot: Buffer }; // PublicDataTreeLeaf
|
|
291
302
|
|
|
292
303
|
export type SerializedIndexedLeaf = {
|
|
293
|
-
|
|
304
|
+
leaf: Exclude<SerializedLeafValue, Buffer>;
|
|
294
305
|
nextIndex: bigint | number;
|
|
295
|
-
|
|
306
|
+
nextKey: Buffer; // Fr
|
|
296
307
|
};
|
|
297
308
|
|
|
298
309
|
interface WithLeafValues {
|
|
@@ -300,7 +311,7 @@ interface WithLeafValues {
|
|
|
300
311
|
}
|
|
301
312
|
|
|
302
313
|
interface BlockShiftRequest extends WithCanonicalForkId {
|
|
303
|
-
toBlockNumber:
|
|
314
|
+
toBlockNumber: BlockNumber;
|
|
304
315
|
}
|
|
305
316
|
|
|
306
317
|
interface WithLeaves {
|
|
@@ -344,6 +355,16 @@ interface FindLeafIndicesResponse {
|
|
|
344
355
|
indices: bigint[];
|
|
345
356
|
}
|
|
346
357
|
|
|
358
|
+
interface FindSiblingPathsRequest extends WithTreeId, WithLeafValues, WithWorldStateRevision {}
|
|
359
|
+
|
|
360
|
+
interface SiblingPathAndIndex {
|
|
361
|
+
index: bigint;
|
|
362
|
+
path: Buffer[];
|
|
363
|
+
}
|
|
364
|
+
interface FindSiblingPathsResponse {
|
|
365
|
+
paths: (SiblingPathAndIndex | undefined)[];
|
|
366
|
+
}
|
|
367
|
+
|
|
347
368
|
interface FindLowLeafRequest extends WithTreeId, WithWorldStateRevision {
|
|
348
369
|
key: Fr;
|
|
349
370
|
}
|
|
@@ -389,7 +410,7 @@ interface UpdateArchiveRequest extends WithForkId {
|
|
|
389
410
|
}
|
|
390
411
|
|
|
391
412
|
interface SyncBlockRequest extends WithCanonicalForkId {
|
|
392
|
-
blockNumber:
|
|
413
|
+
blockNumber: BlockNumber;
|
|
393
414
|
blockStateRef: BlockStateReference;
|
|
394
415
|
blockHeaderHash: Fr;
|
|
395
416
|
paddedNoteHashes: readonly SerializedLeafValue[];
|
|
@@ -400,7 +421,7 @@ interface SyncBlockRequest extends WithCanonicalForkId {
|
|
|
400
421
|
|
|
401
422
|
interface CreateForkRequest extends WithCanonicalForkId {
|
|
402
423
|
latest: boolean;
|
|
403
|
-
blockNumber:
|
|
424
|
+
blockNumber: BlockNumber;
|
|
404
425
|
}
|
|
405
426
|
|
|
406
427
|
interface CreateForkResponse {
|
|
@@ -409,6 +430,11 @@ interface CreateForkResponse {
|
|
|
409
430
|
|
|
410
431
|
interface DeleteForkRequest extends WithForkId {}
|
|
411
432
|
|
|
433
|
+
interface CopyStoresRequest extends WithCanonicalForkId {
|
|
434
|
+
dstPath: string;
|
|
435
|
+
compact: boolean;
|
|
436
|
+
}
|
|
437
|
+
|
|
412
438
|
export type WorldStateRequestCategories = WithForkId | WithWorldStateRevision | WithCanonicalForkId;
|
|
413
439
|
|
|
414
440
|
export function isWithForkId(body: WorldStateRequestCategories): body is WithForkId {
|
|
@@ -435,6 +461,7 @@ export type WorldStateRequest = {
|
|
|
435
461
|
|
|
436
462
|
[WorldStateMessageType.FIND_LEAF_INDICES]: FindLeafIndicesRequest;
|
|
437
463
|
[WorldStateMessageType.FIND_LOW_LEAF]: FindLowLeafRequest;
|
|
464
|
+
[WorldStateMessageType.FIND_SIBLING_PATHS]: FindSiblingPathsRequest;
|
|
438
465
|
|
|
439
466
|
[WorldStateMessageType.APPEND_LEAVES]: AppendLeavesRequest;
|
|
440
467
|
[WorldStateMessageType.BATCH_INSERT]: BatchInsertRequest;
|
|
@@ -452,13 +479,17 @@ export type WorldStateRequest = {
|
|
|
452
479
|
|
|
453
480
|
[WorldStateMessageType.REMOVE_HISTORICAL_BLOCKS]: BlockShiftRequest;
|
|
454
481
|
[WorldStateMessageType.UNWIND_BLOCKS]: BlockShiftRequest;
|
|
455
|
-
[WorldStateMessageType.
|
|
482
|
+
[WorldStateMessageType.FINALIZE_BLOCKS]: BlockShiftRequest;
|
|
456
483
|
|
|
457
484
|
[WorldStateMessageType.GET_STATUS]: WithCanonicalForkId;
|
|
458
485
|
|
|
459
486
|
[WorldStateMessageType.CREATE_CHECKPOINT]: WithForkId;
|
|
460
487
|
[WorldStateMessageType.COMMIT_CHECKPOINT]: WithForkId;
|
|
461
488
|
[WorldStateMessageType.REVERT_CHECKPOINT]: WithForkId;
|
|
489
|
+
[WorldStateMessageType.COMMIT_ALL_CHECKPOINTS]: WithForkId;
|
|
490
|
+
[WorldStateMessageType.REVERT_ALL_CHECKPOINTS]: WithForkId;
|
|
491
|
+
|
|
492
|
+
[WorldStateMessageType.COPY_STORES]: CopyStoresRequest;
|
|
462
493
|
|
|
463
494
|
[WorldStateMessageType.CLOSE]: WithCanonicalForkId;
|
|
464
495
|
};
|
|
@@ -475,6 +506,7 @@ export type WorldStateResponse = {
|
|
|
475
506
|
|
|
476
507
|
[WorldStateMessageType.FIND_LEAF_INDICES]: FindLeafIndicesResponse;
|
|
477
508
|
[WorldStateMessageType.FIND_LOW_LEAF]: FindLowLeafResponse;
|
|
509
|
+
[WorldStateMessageType.FIND_SIBLING_PATHS]: FindSiblingPathsResponse;
|
|
478
510
|
|
|
479
511
|
[WorldStateMessageType.APPEND_LEAVES]: void;
|
|
480
512
|
[WorldStateMessageType.BATCH_INSERT]: BatchInsertResponse;
|
|
@@ -492,33 +524,20 @@ export type WorldStateResponse = {
|
|
|
492
524
|
|
|
493
525
|
[WorldStateMessageType.REMOVE_HISTORICAL_BLOCKS]: WorldStateStatusFull;
|
|
494
526
|
[WorldStateMessageType.UNWIND_BLOCKS]: WorldStateStatusFull;
|
|
495
|
-
[WorldStateMessageType.
|
|
527
|
+
[WorldStateMessageType.FINALIZE_BLOCKS]: WorldStateStatusSummary;
|
|
496
528
|
|
|
497
529
|
[WorldStateMessageType.GET_STATUS]: WorldStateStatusSummary;
|
|
498
530
|
|
|
499
531
|
[WorldStateMessageType.CREATE_CHECKPOINT]: void;
|
|
500
532
|
[WorldStateMessageType.COMMIT_CHECKPOINT]: void;
|
|
501
533
|
[WorldStateMessageType.REVERT_CHECKPOINT]: void;
|
|
534
|
+
[WorldStateMessageType.COMMIT_ALL_CHECKPOINTS]: void;
|
|
535
|
+
[WorldStateMessageType.REVERT_ALL_CHECKPOINTS]: void;
|
|
502
536
|
|
|
503
|
-
[WorldStateMessageType.
|
|
504
|
-
};
|
|
537
|
+
[WorldStateMessageType.COPY_STORES]: void;
|
|
505
538
|
|
|
506
|
-
|
|
507
|
-
forkId: number;
|
|
508
|
-
blockNumber: number;
|
|
509
|
-
includeUncommitted: boolean;
|
|
539
|
+
[WorldStateMessageType.CLOSE]: void;
|
|
510
540
|
};
|
|
511
|
-
export function worldStateRevision(
|
|
512
|
-
includeUncommitted: boolean,
|
|
513
|
-
forkId: number | undefined,
|
|
514
|
-
blockNumber: number | undefined,
|
|
515
|
-
): WorldStateRevision {
|
|
516
|
-
return {
|
|
517
|
-
forkId: forkId ?? 0,
|
|
518
|
-
blockNumber: blockNumber ?? 0,
|
|
519
|
-
includeUncommitted,
|
|
520
|
-
};
|
|
521
|
-
}
|
|
522
541
|
|
|
523
542
|
type TreeStateReference = readonly [Buffer, number | bigint];
|
|
524
543
|
type BlockStateReference = Map<Exclude<MerkleTreeId, MerkleTreeId.ARCHIVE>, TreeStateReference>;
|