@aztec/world-state 0.0.0-test.0 → 0.0.1-commit.001888fc
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 +25 -41
- 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 +7 -1
- package/dest/native/fork_checkpoint.d.ts.map +1 -1
- package/dest/native/fork_checkpoint.js +15 -3
- package/dest/native/index.d.ts +1 -1
- package/dest/native/merkle_trees_facade.d.ts +20 -8
- package/dest/native/merkle_trees_facade.d.ts.map +1 -1
- package/dest/native/merkle_trees_facade.js +80 -15
- package/dest/native/message.d.ts +83 -53
- package/dest/native/message.d.ts.map +1 -1
- package/dest/native/message.js +61 -61
- package/dest/native/native_world_state.d.ts +27 -19
- package/dest/native/native_world_state.d.ts.map +1 -1
- package/dest/native/native_world_state.js +103 -41
- 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 +43 -4
- 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 +14 -6
- package/dest/synchronizer/config.d.ts.map +1 -1
- package/dest/synchronizer/config.js +33 -10
- 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 +12 -4
- package/dest/synchronizer/factory.d.ts.map +1 -1
- package/dest/synchronizer/factory.js +13 -8
- package/dest/synchronizer/index.d.ts +1 -1
- package/dest/synchronizer/server_world_state_synchronizer.d.ts +21 -31
- package/dest/synchronizer/server_world_state_synchronizer.d.ts.map +1 -1
- package/dest/synchronizer/server_world_state_synchronizer.js +191 -96
- package/dest/test/index.d.ts +1 -1
- package/dest/test/utils.d.ts +12 -5
- package/dest/test/utils.d.ts.map +1 -1
- package/dest/test/utils.js +54 -47
- 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 +12 -18
- package/dest/world-state-db/merkle_tree_db.d.ts.map +1 -1
- package/package.json +23 -24
- package/src/instrumentation/instrumentation.ts +31 -43
- package/src/native/bench_metrics.ts +91 -0
- package/src/native/fork_checkpoint.ts +19 -3
- package/src/native/merkle_trees_facade.ts +92 -20
- package/src/native/message.ts +105 -75
- package/src/native/native_world_state.ts +132 -52
- package/src/native/native_world_state_instance.ts +63 -10
- package/src/native/world_state_ops_queue.ts +1 -1
- package/src/synchronizer/config.ts +55 -21
- package/src/synchronizer/errors.ts +5 -0
- package/src/synchronizer/factory.ts +39 -10
- package/src/synchronizer/server_world_state_synchronizer.ts +227 -121
- package/src/test/utils.ts +92 -82
- package/src/testing.ts +4 -8
- package/src/world-state-db/merkle_tree_db.ts +16 -18
|
@@ -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);
|
|
@@ -260,12 +292,37 @@ export class MerkleTreesForkFacade extends MerkleTreesFacade implements MerkleTr
|
|
|
260
292
|
|
|
261
293
|
public async close(): Promise<void> {
|
|
262
294
|
assert.notEqual(this.revision.forkId, 0, 'Fork ID must be set');
|
|
263
|
-
|
|
295
|
+
try {
|
|
296
|
+
await this.instance.call(WorldStateMessageType.DELETE_FORK, { forkId: this.revision.forkId });
|
|
297
|
+
} catch (err: any) {
|
|
298
|
+
// Ignore errors due to native instance being closed during shutdown.
|
|
299
|
+
// This can happen when validators are still processing block proposals while the node is stopping.
|
|
300
|
+
if (err?.message === 'Native instance is closed') {
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
throw err;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
async [Symbol.asyncDispose](): Promise<void> {
|
|
308
|
+
if (this.opts.closeDelayMs) {
|
|
309
|
+
void sleep(this.opts.closeDelayMs)
|
|
310
|
+
.then(() => this.close())
|
|
311
|
+
.catch(err => {
|
|
312
|
+
if (err && 'message' in err && err.message === 'Native instance is closed') {
|
|
313
|
+
return; // Ignore errors due to native instance being closed
|
|
314
|
+
}
|
|
315
|
+
this.log.warn('Error closing MerkleTreesForkFacade after delay', { err });
|
|
316
|
+
});
|
|
317
|
+
} else {
|
|
318
|
+
await this.close();
|
|
319
|
+
}
|
|
264
320
|
}
|
|
265
321
|
|
|
266
|
-
public async createCheckpoint(): Promise<
|
|
322
|
+
public async createCheckpoint(): Promise<number> {
|
|
267
323
|
assert.notEqual(this.revision.forkId, 0, 'Fork ID must be set');
|
|
268
|
-
await this.instance.call(WorldStateMessageType.CREATE_CHECKPOINT, { forkId: this.revision.forkId });
|
|
324
|
+
const resp = await this.instance.call(WorldStateMessageType.CREATE_CHECKPOINT, { forkId: this.revision.forkId });
|
|
325
|
+
return resp.depth;
|
|
269
326
|
}
|
|
270
327
|
|
|
271
328
|
public async commitCheckpoint(): Promise<void> {
|
|
@@ -277,6 +334,22 @@ export class MerkleTreesForkFacade extends MerkleTreesFacade implements MerkleTr
|
|
|
277
334
|
assert.notEqual(this.revision.forkId, 0, 'Fork ID must be set');
|
|
278
335
|
await this.instance.call(WorldStateMessageType.REVERT_CHECKPOINT, { forkId: this.revision.forkId });
|
|
279
336
|
}
|
|
337
|
+
|
|
338
|
+
public async commitAllCheckpointsTo(depth: number): Promise<void> {
|
|
339
|
+
assert.notEqual(this.revision.forkId, 0, 'Fork ID must be set');
|
|
340
|
+
await this.instance.call(WorldStateMessageType.COMMIT_ALL_CHECKPOINTS, {
|
|
341
|
+
forkId: this.revision.forkId,
|
|
342
|
+
depth,
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
public async revertAllCheckpointsTo(depth: number): Promise<void> {
|
|
347
|
+
assert.notEqual(this.revision.forkId, 0, 'Fork ID must be set');
|
|
348
|
+
await this.instance.call(WorldStateMessageType.REVERT_ALL_CHECKPOINTS, {
|
|
349
|
+
forkId: this.revision.forkId,
|
|
350
|
+
depth,
|
|
351
|
+
});
|
|
352
|
+
}
|
|
280
353
|
}
|
|
281
354
|
|
|
282
355
|
function hydrateLeaf<ID extends MerkleTreeId>(treeId: ID, leaf: Fr | Buffer) {
|
|
@@ -295,7 +368,7 @@ export function serializeLeaf(leaf: Fr | NullifierLeaf | PublicDataTreeLeaf): Se
|
|
|
295
368
|
if (leaf instanceof Fr) {
|
|
296
369
|
return leaf.toBuffer();
|
|
297
370
|
} else if (leaf instanceof NullifierLeaf) {
|
|
298
|
-
return {
|
|
371
|
+
return { nullifier: leaf.nullifier.toBuffer() };
|
|
299
372
|
} else {
|
|
300
373
|
return { value: leaf.value.toBuffer(), slot: leaf.slot.toBuffer() };
|
|
301
374
|
}
|
|
@@ -307,23 +380,22 @@ function deserializeLeafValue(leaf: SerializedLeafValue): Fr | NullifierLeaf | P
|
|
|
307
380
|
} else if ('slot' in leaf) {
|
|
308
381
|
return new PublicDataTreeLeaf(Fr.fromBuffer(leaf.slot), Fr.fromBuffer(leaf.value));
|
|
309
382
|
} else {
|
|
310
|
-
return new NullifierLeaf(Fr.fromBuffer(leaf.
|
|
383
|
+
return new NullifierLeaf(Fr.fromBuffer(leaf.nullifier));
|
|
311
384
|
}
|
|
312
385
|
}
|
|
313
386
|
|
|
314
|
-
function deserializeIndexedLeaf(
|
|
315
|
-
if ('slot' in leaf
|
|
387
|
+
function deserializeIndexedLeaf(leafPreimage: SerializedIndexedLeaf): IndexedTreeLeafPreimage {
|
|
388
|
+
if ('slot' in leafPreimage.leaf) {
|
|
316
389
|
return new PublicDataTreeLeafPreimage(
|
|
317
|
-
Fr.fromBuffer(leaf.
|
|
318
|
-
Fr.fromBuffer(
|
|
319
|
-
|
|
320
|
-
BigInt(leaf.nextIndex),
|
|
390
|
+
new PublicDataTreeLeaf(Fr.fromBuffer(leafPreimage.leaf.slot), Fr.fromBuffer(leafPreimage.leaf.value)),
|
|
391
|
+
Fr.fromBuffer(leafPreimage.nextKey),
|
|
392
|
+
BigInt(leafPreimage.nextIndex),
|
|
321
393
|
);
|
|
322
|
-
} else if ('
|
|
394
|
+
} else if ('nullifier' in leafPreimage.leaf) {
|
|
323
395
|
return new NullifierLeafPreimage(
|
|
324
|
-
Fr.fromBuffer(leaf.
|
|
325
|
-
Fr.fromBuffer(
|
|
326
|
-
BigInt(
|
|
396
|
+
new NullifierLeaf(Fr.fromBuffer(leafPreimage.leaf.nullifier)),
|
|
397
|
+
Fr.fromBuffer(leafPreimage.nextKey),
|
|
398
|
+
BigInt(leafPreimage.nextIndex),
|
|
327
399
|
);
|
|
328
400
|
} else {
|
|
329
401
|
throw new Error('Invalid leaf type');
|
package/src/native/message.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
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';
|
|
4
|
+
import type { BlockHash } from '@aztec/stdlib/block';
|
|
3
5
|
import { AppendOnlyTreeSnapshot, MerkleTreeId } from '@aztec/stdlib/trees';
|
|
4
6
|
import type { StateReference } from '@aztec/stdlib/tx';
|
|
5
7
|
import type { UInt32 } from '@aztec/stdlib/types';
|
|
8
|
+
import type { WorldStateRevision } from '@aztec/stdlib/world-state';
|
|
6
9
|
|
|
7
10
|
export enum WorldStateMessageType {
|
|
8
11
|
GET_TREE_INFO = 100,
|
|
@@ -16,6 +19,7 @@ export enum WorldStateMessageType {
|
|
|
16
19
|
|
|
17
20
|
FIND_LEAF_INDICES,
|
|
18
21
|
FIND_LOW_LEAF,
|
|
22
|
+
FIND_SIBLING_PATHS,
|
|
19
23
|
|
|
20
24
|
APPEND_LEAVES,
|
|
21
25
|
BATCH_INSERT,
|
|
@@ -31,7 +35,7 @@ export enum WorldStateMessageType {
|
|
|
31
35
|
CREATE_FORK,
|
|
32
36
|
DELETE_FORK,
|
|
33
37
|
|
|
34
|
-
|
|
38
|
+
FINALIZE_BLOCKS,
|
|
35
39
|
UNWIND_BLOCKS,
|
|
36
40
|
REMOVE_HISTORICAL_BLOCKS,
|
|
37
41
|
|
|
@@ -40,6 +44,10 @@ export enum WorldStateMessageType {
|
|
|
40
44
|
CREATE_CHECKPOINT,
|
|
41
45
|
COMMIT_CHECKPOINT,
|
|
42
46
|
REVERT_CHECKPOINT,
|
|
47
|
+
COMMIT_ALL_CHECKPOINTS,
|
|
48
|
+
REVERT_ALL_CHECKPOINTS,
|
|
49
|
+
|
|
50
|
+
COPY_STORES,
|
|
43
51
|
|
|
44
52
|
CLOSE = 999,
|
|
45
53
|
}
|
|
@@ -50,11 +58,11 @@ interface WithTreeId {
|
|
|
50
58
|
|
|
51
59
|
export interface WorldStateStatusSummary {
|
|
52
60
|
/** Last block number that can still be unwound. */
|
|
53
|
-
|
|
54
|
-
/** Last block number that is
|
|
55
|
-
|
|
61
|
+
unfinalizedBlockNumber: BlockNumber;
|
|
62
|
+
/** Last block number that is finalized and cannot be unwound. */
|
|
63
|
+
finalizedBlockNumber: BlockNumber;
|
|
56
64
|
/** Oldest block still available for historical queries and forks. */
|
|
57
|
-
oldestHistoricalBlock:
|
|
65
|
+
oldestHistoricalBlock: BlockNumber;
|
|
58
66
|
/** Whether the trees are in sync with each other */
|
|
59
67
|
treesAreSynched: boolean;
|
|
60
68
|
}
|
|
@@ -75,11 +83,11 @@ export interface TreeMeta {
|
|
|
75
83
|
/** The tree's initial root value */
|
|
76
84
|
initialRoot: Fr;
|
|
77
85
|
/** The current oldest historical block number of the tree */
|
|
78
|
-
oldestHistoricBlock:
|
|
79
|
-
/** The current
|
|
80
|
-
|
|
81
|
-
/** The current
|
|
82
|
-
|
|
86
|
+
oldestHistoricBlock: BlockNumber;
|
|
87
|
+
/** The current unfinalized block number of the tree */
|
|
88
|
+
unfinalizedBlockHeight: BlockNumber;
|
|
89
|
+
/** The current finalized block number of the tree */
|
|
90
|
+
finalizedBlockHeight: BlockNumber;
|
|
83
91
|
}
|
|
84
92
|
|
|
85
93
|
export interface DBStats {
|
|
@@ -94,6 +102,8 @@ export interface DBStats {
|
|
|
94
102
|
export interface TreeDBStats {
|
|
95
103
|
/** The configured max size of the DB mapping file (effectively the max possible size of the DB) */
|
|
96
104
|
mapSize: bigint;
|
|
105
|
+
/** The physical file size of the database on disk */
|
|
106
|
+
physicalFileSize: bigint;
|
|
97
107
|
/** Stats for the 'blocks' DB */
|
|
98
108
|
blocksDBStats: DBStats;
|
|
99
109
|
/** Stats for the 'nodes' DB */
|
|
@@ -149,6 +159,7 @@ export function buildEmptyDBStats() {
|
|
|
149
159
|
export function buildEmptyTreeDBStats() {
|
|
150
160
|
return {
|
|
151
161
|
mapSize: 0n,
|
|
162
|
+
physicalFileSize: 0n,
|
|
152
163
|
blocksDBStats: buildEmptyDBStats(),
|
|
153
164
|
nodesDBStats: buildEmptyDBStats(),
|
|
154
165
|
leafIndicesDBStats: buildEmptyDBStats(),
|
|
@@ -164,9 +175,9 @@ export function buildEmptyTreeMeta() {
|
|
|
164
175
|
depth: 0,
|
|
165
176
|
size: 0n,
|
|
166
177
|
committedSize: 0n,
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
oldestHistoricBlock:
|
|
178
|
+
unfinalizedBlockHeight: BlockNumber.ZERO,
|
|
179
|
+
finalizedBlockHeight: BlockNumber.ZERO,
|
|
180
|
+
oldestHistoricBlock: BlockNumber.ZERO,
|
|
170
181
|
root: Fr.ZERO,
|
|
171
182
|
initialRoot: Fr.ZERO,
|
|
172
183
|
initialSize: 0n,
|
|
@@ -195,9 +206,9 @@ export function buildEmptyWorldStateDBStats() {
|
|
|
195
206
|
|
|
196
207
|
export function buildEmptyWorldStateSummary() {
|
|
197
208
|
return {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
oldestHistoricalBlock:
|
|
209
|
+
unfinalizedBlockNumber: BlockNumber.ZERO,
|
|
210
|
+
finalizedBlockNumber: BlockNumber.ZERO,
|
|
211
|
+
oldestHistoricalBlock: BlockNumber.ZERO,
|
|
201
212
|
treesAreSynched: true,
|
|
202
213
|
} as WorldStateStatusSummary;
|
|
203
214
|
}
|
|
@@ -210,61 +221,62 @@ export function buildEmptyWorldStateStatusFull() {
|
|
|
210
221
|
} as WorldStateStatusFull;
|
|
211
222
|
}
|
|
212
223
|
|
|
213
|
-
export function
|
|
214
|
-
summary.
|
|
215
|
-
summary.
|
|
216
|
-
summary.oldestHistoricalBlock = BigInt(summary.oldestHistoricalBlock);
|
|
224
|
+
export function sanitizeSummary(summary: WorldStateStatusSummary) {
|
|
225
|
+
summary.finalizedBlockNumber = BlockNumber.fromBigInt(BigInt(summary.finalizedBlockNumber));
|
|
226
|
+
summary.unfinalizedBlockNumber = BlockNumber.fromBigInt(BigInt(summary.unfinalizedBlockNumber));
|
|
227
|
+
summary.oldestHistoricalBlock = BlockNumber.fromBigInt(BigInt(summary.oldestHistoricalBlock));
|
|
217
228
|
return summary;
|
|
218
229
|
}
|
|
219
230
|
|
|
220
|
-
export function
|
|
231
|
+
export function sanitizeDBStats(stats: DBStats) {
|
|
221
232
|
stats.numDataItems = BigInt(stats.numDataItems);
|
|
222
233
|
stats.totalUsedSize = BigInt(stats.totalUsedSize);
|
|
223
234
|
return stats;
|
|
224
235
|
}
|
|
225
236
|
|
|
226
|
-
export function
|
|
237
|
+
export function sanitizeMeta(meta: TreeMeta) {
|
|
227
238
|
meta.committedSize = BigInt(meta.committedSize);
|
|
228
|
-
meta.
|
|
239
|
+
meta.finalizedBlockHeight = BlockNumber.fromBigInt(BigInt(meta.finalizedBlockHeight));
|
|
229
240
|
meta.initialSize = BigInt(meta.initialSize);
|
|
230
|
-
meta.oldestHistoricBlock = BigInt(meta.oldestHistoricBlock);
|
|
241
|
+
meta.oldestHistoricBlock = BlockNumber.fromBigInt(BigInt(meta.oldestHistoricBlock));
|
|
231
242
|
meta.size = BigInt(meta.size);
|
|
232
|
-
meta.
|
|
243
|
+
meta.unfinalizedBlockHeight = BlockNumber.fromBigInt(BigInt(meta.unfinalizedBlockHeight));
|
|
233
244
|
return meta;
|
|
234
245
|
}
|
|
235
246
|
|
|
236
|
-
export function
|
|
237
|
-
stats.blocksDBStats =
|
|
238
|
-
stats.leafIndicesDBStats =
|
|
239
|
-
stats.leafPreimagesDBStats =
|
|
240
|
-
stats.blockIndicesDBStats =
|
|
241
|
-
stats.nodesDBStats =
|
|
247
|
+
export function sanitizeTreeDBStats(stats: TreeDBStats) {
|
|
248
|
+
stats.blocksDBStats = sanitizeDBStats(stats.blocksDBStats);
|
|
249
|
+
stats.leafIndicesDBStats = sanitizeDBStats(stats.leafIndicesDBStats);
|
|
250
|
+
stats.leafPreimagesDBStats = sanitizeDBStats(stats.leafPreimagesDBStats);
|
|
251
|
+
stats.blockIndicesDBStats = sanitizeDBStats(stats.blockIndicesDBStats);
|
|
252
|
+
stats.nodesDBStats = sanitizeDBStats(stats.nodesDBStats);
|
|
242
253
|
stats.mapSize = BigInt(stats.mapSize);
|
|
254
|
+
stats.physicalFileSize = BigInt(stats.physicalFileSize);
|
|
243
255
|
return stats;
|
|
244
256
|
}
|
|
245
257
|
|
|
246
|
-
export function
|
|
247
|
-
stats.archiveTreeStats =
|
|
248
|
-
stats.messageTreeStats =
|
|
249
|
-
stats.noteHashTreeStats =
|
|
250
|
-
stats.nullifierTreeStats =
|
|
251
|
-
stats.publicDataTreeStats =
|
|
258
|
+
export function sanitizeWorldStateDBStats(stats: WorldStateDBStats) {
|
|
259
|
+
stats.archiveTreeStats = sanitizeTreeDBStats(stats.archiveTreeStats);
|
|
260
|
+
stats.messageTreeStats = sanitizeTreeDBStats(stats.messageTreeStats);
|
|
261
|
+
stats.noteHashTreeStats = sanitizeTreeDBStats(stats.noteHashTreeStats);
|
|
262
|
+
stats.nullifierTreeStats = sanitizeTreeDBStats(stats.nullifierTreeStats);
|
|
263
|
+
stats.publicDataTreeStats = sanitizeTreeDBStats(stats.publicDataTreeStats);
|
|
252
264
|
return stats;
|
|
253
265
|
}
|
|
254
266
|
|
|
255
|
-
export function
|
|
256
|
-
meta.archiveTreeMeta =
|
|
257
|
-
meta.messageTreeMeta =
|
|
258
|
-
meta.noteHashTreeMeta =
|
|
259
|
-
meta.nullifierTreeMeta =
|
|
260
|
-
meta.publicDataTreeMeta =
|
|
267
|
+
export function sanitizeWorldStateTreeMeta(meta: WorldStateMeta) {
|
|
268
|
+
meta.archiveTreeMeta = sanitizeMeta(meta.archiveTreeMeta);
|
|
269
|
+
meta.messageTreeMeta = sanitizeMeta(meta.messageTreeMeta);
|
|
270
|
+
meta.noteHashTreeMeta = sanitizeMeta(meta.noteHashTreeMeta);
|
|
271
|
+
meta.nullifierTreeMeta = sanitizeMeta(meta.nullifierTreeMeta);
|
|
272
|
+
meta.publicDataTreeMeta = sanitizeMeta(meta.publicDataTreeMeta);
|
|
261
273
|
return meta;
|
|
262
274
|
}
|
|
263
275
|
|
|
264
|
-
export function
|
|
265
|
-
status.dbStats =
|
|
266
|
-
status.summary =
|
|
267
|
-
status.meta =
|
|
276
|
+
export function sanitizeFullStatus(status: WorldStateStatusFull) {
|
|
277
|
+
status.dbStats = sanitizeWorldStateDBStats(status.dbStats);
|
|
278
|
+
status.summary = sanitizeSummary(status.summary);
|
|
279
|
+
status.meta = sanitizeWorldStateTreeMeta(status.meta);
|
|
268
280
|
return status;
|
|
269
281
|
}
|
|
270
282
|
|
|
@@ -272,6 +284,16 @@ interface WithForkId {
|
|
|
272
284
|
forkId: number;
|
|
273
285
|
}
|
|
274
286
|
|
|
287
|
+
interface CreateCheckpointResponse {
|
|
288
|
+
depth: number;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/** Request to commit/revert all checkpoints down to a target depth. The resulting depth after the operation equals the given depth. */
|
|
292
|
+
interface CheckpointDepthRequest extends WithForkId {
|
|
293
|
+
/** The target depth after the operation. All checkpoints above this depth are committed/reverted. */
|
|
294
|
+
depth: number;
|
|
295
|
+
}
|
|
296
|
+
|
|
275
297
|
interface WithWorldStateRevision {
|
|
276
298
|
revision: WorldStateRevision;
|
|
277
299
|
}
|
|
@@ -286,13 +308,13 @@ interface WithLeafIndex {
|
|
|
286
308
|
|
|
287
309
|
export type SerializedLeafValue =
|
|
288
310
|
| Buffer // Fr
|
|
289
|
-
| {
|
|
311
|
+
| { nullifier: Buffer } // NullifierLeaf
|
|
290
312
|
| { value: Buffer; slot: Buffer }; // PublicDataTreeLeaf
|
|
291
313
|
|
|
292
314
|
export type SerializedIndexedLeaf = {
|
|
293
|
-
|
|
315
|
+
leaf: Exclude<SerializedLeafValue, Buffer>;
|
|
294
316
|
nextIndex: bigint | number;
|
|
295
|
-
|
|
317
|
+
nextKey: Buffer; // Fr
|
|
296
318
|
};
|
|
297
319
|
|
|
298
320
|
interface WithLeafValues {
|
|
@@ -300,7 +322,7 @@ interface WithLeafValues {
|
|
|
300
322
|
}
|
|
301
323
|
|
|
302
324
|
interface BlockShiftRequest extends WithCanonicalForkId {
|
|
303
|
-
toBlockNumber:
|
|
325
|
+
toBlockNumber: BlockNumber;
|
|
304
326
|
}
|
|
305
327
|
|
|
306
328
|
interface WithLeaves {
|
|
@@ -344,6 +366,16 @@ interface FindLeafIndicesResponse {
|
|
|
344
366
|
indices: bigint[];
|
|
345
367
|
}
|
|
346
368
|
|
|
369
|
+
interface FindSiblingPathsRequest extends WithTreeId, WithLeafValues, WithWorldStateRevision {}
|
|
370
|
+
|
|
371
|
+
interface SiblingPathAndIndex {
|
|
372
|
+
index: bigint;
|
|
373
|
+
path: Buffer[];
|
|
374
|
+
}
|
|
375
|
+
interface FindSiblingPathsResponse {
|
|
376
|
+
paths: (SiblingPathAndIndex | undefined)[];
|
|
377
|
+
}
|
|
378
|
+
|
|
347
379
|
interface FindLowLeafRequest extends WithTreeId, WithWorldStateRevision {
|
|
348
380
|
key: Fr;
|
|
349
381
|
}
|
|
@@ -389,9 +421,9 @@ interface UpdateArchiveRequest extends WithForkId {
|
|
|
389
421
|
}
|
|
390
422
|
|
|
391
423
|
interface SyncBlockRequest extends WithCanonicalForkId {
|
|
392
|
-
blockNumber:
|
|
424
|
+
blockNumber: BlockNumber;
|
|
393
425
|
blockStateRef: BlockStateReference;
|
|
394
|
-
blockHeaderHash:
|
|
426
|
+
blockHeaderHash: BlockHash;
|
|
395
427
|
paddedNoteHashes: readonly SerializedLeafValue[];
|
|
396
428
|
paddedL1ToL2Messages: readonly SerializedLeafValue[];
|
|
397
429
|
paddedNullifiers: readonly SerializedLeafValue[];
|
|
@@ -400,7 +432,7 @@ interface SyncBlockRequest extends WithCanonicalForkId {
|
|
|
400
432
|
|
|
401
433
|
interface CreateForkRequest extends WithCanonicalForkId {
|
|
402
434
|
latest: boolean;
|
|
403
|
-
blockNumber:
|
|
435
|
+
blockNumber: BlockNumber;
|
|
404
436
|
}
|
|
405
437
|
|
|
406
438
|
interface CreateForkResponse {
|
|
@@ -409,6 +441,11 @@ interface CreateForkResponse {
|
|
|
409
441
|
|
|
410
442
|
interface DeleteForkRequest extends WithForkId {}
|
|
411
443
|
|
|
444
|
+
interface CopyStoresRequest extends WithCanonicalForkId {
|
|
445
|
+
dstPath: string;
|
|
446
|
+
compact: boolean;
|
|
447
|
+
}
|
|
448
|
+
|
|
412
449
|
export type WorldStateRequestCategories = WithForkId | WithWorldStateRevision | WithCanonicalForkId;
|
|
413
450
|
|
|
414
451
|
export function isWithForkId(body: WorldStateRequestCategories): body is WithForkId {
|
|
@@ -435,6 +472,7 @@ export type WorldStateRequest = {
|
|
|
435
472
|
|
|
436
473
|
[WorldStateMessageType.FIND_LEAF_INDICES]: FindLeafIndicesRequest;
|
|
437
474
|
[WorldStateMessageType.FIND_LOW_LEAF]: FindLowLeafRequest;
|
|
475
|
+
[WorldStateMessageType.FIND_SIBLING_PATHS]: FindSiblingPathsRequest;
|
|
438
476
|
|
|
439
477
|
[WorldStateMessageType.APPEND_LEAVES]: AppendLeavesRequest;
|
|
440
478
|
[WorldStateMessageType.BATCH_INSERT]: BatchInsertRequest;
|
|
@@ -452,13 +490,17 @@ export type WorldStateRequest = {
|
|
|
452
490
|
|
|
453
491
|
[WorldStateMessageType.REMOVE_HISTORICAL_BLOCKS]: BlockShiftRequest;
|
|
454
492
|
[WorldStateMessageType.UNWIND_BLOCKS]: BlockShiftRequest;
|
|
455
|
-
[WorldStateMessageType.
|
|
493
|
+
[WorldStateMessageType.FINALIZE_BLOCKS]: BlockShiftRequest;
|
|
456
494
|
|
|
457
495
|
[WorldStateMessageType.GET_STATUS]: WithCanonicalForkId;
|
|
458
496
|
|
|
459
497
|
[WorldStateMessageType.CREATE_CHECKPOINT]: WithForkId;
|
|
460
498
|
[WorldStateMessageType.COMMIT_CHECKPOINT]: WithForkId;
|
|
461
499
|
[WorldStateMessageType.REVERT_CHECKPOINT]: WithForkId;
|
|
500
|
+
[WorldStateMessageType.COMMIT_ALL_CHECKPOINTS]: CheckpointDepthRequest;
|
|
501
|
+
[WorldStateMessageType.REVERT_ALL_CHECKPOINTS]: CheckpointDepthRequest;
|
|
502
|
+
|
|
503
|
+
[WorldStateMessageType.COPY_STORES]: CopyStoresRequest;
|
|
462
504
|
|
|
463
505
|
[WorldStateMessageType.CLOSE]: WithCanonicalForkId;
|
|
464
506
|
};
|
|
@@ -475,6 +517,7 @@ export type WorldStateResponse = {
|
|
|
475
517
|
|
|
476
518
|
[WorldStateMessageType.FIND_LEAF_INDICES]: FindLeafIndicesResponse;
|
|
477
519
|
[WorldStateMessageType.FIND_LOW_LEAF]: FindLowLeafResponse;
|
|
520
|
+
[WorldStateMessageType.FIND_SIBLING_PATHS]: FindSiblingPathsResponse;
|
|
478
521
|
|
|
479
522
|
[WorldStateMessageType.APPEND_LEAVES]: void;
|
|
480
523
|
[WorldStateMessageType.BATCH_INSERT]: BatchInsertResponse;
|
|
@@ -492,33 +535,20 @@ export type WorldStateResponse = {
|
|
|
492
535
|
|
|
493
536
|
[WorldStateMessageType.REMOVE_HISTORICAL_BLOCKS]: WorldStateStatusFull;
|
|
494
537
|
[WorldStateMessageType.UNWIND_BLOCKS]: WorldStateStatusFull;
|
|
495
|
-
[WorldStateMessageType.
|
|
538
|
+
[WorldStateMessageType.FINALIZE_BLOCKS]: WorldStateStatusSummary;
|
|
496
539
|
|
|
497
540
|
[WorldStateMessageType.GET_STATUS]: WorldStateStatusSummary;
|
|
498
541
|
|
|
499
|
-
[WorldStateMessageType.CREATE_CHECKPOINT]:
|
|
542
|
+
[WorldStateMessageType.CREATE_CHECKPOINT]: CreateCheckpointResponse;
|
|
500
543
|
[WorldStateMessageType.COMMIT_CHECKPOINT]: void;
|
|
501
544
|
[WorldStateMessageType.REVERT_CHECKPOINT]: void;
|
|
545
|
+
[WorldStateMessageType.COMMIT_ALL_CHECKPOINTS]: void;
|
|
546
|
+
[WorldStateMessageType.REVERT_ALL_CHECKPOINTS]: void;
|
|
502
547
|
|
|
503
|
-
[WorldStateMessageType.
|
|
504
|
-
};
|
|
548
|
+
[WorldStateMessageType.COPY_STORES]: void;
|
|
505
549
|
|
|
506
|
-
|
|
507
|
-
forkId: number;
|
|
508
|
-
blockNumber: number;
|
|
509
|
-
includeUncommitted: boolean;
|
|
550
|
+
[WorldStateMessageType.CLOSE]: void;
|
|
510
551
|
};
|
|
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
552
|
|
|
523
553
|
type TreeStateReference = readonly [Buffer, number | bigint];
|
|
524
554
|
type BlockStateReference = Map<Exclude<MerkleTreeId, MerkleTreeId.ARCHIVE>, TreeStateReference>;
|