@aztec/world-state 0.0.0-test.0 → 0.0.1-commit.24de95ac
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/instrumentation/instrumentation.d.ts +5 -3
- package/dest/instrumentation/instrumentation.d.ts.map +1 -1
- package/dest/instrumentation/instrumentation.js +16 -8
- 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/merkle_trees_facade.d.ts +9 -3
- package/dest/native/merkle_trees_facade.d.ts.map +1 -1
- package/dest/native/merkle_trees_facade.js +38 -7
- package/dest/native/message.d.ts +64 -44
- package/dest/native/message.d.ts.map +1 -1
- package/dest/native/message.js +55 -56
- package/dest/native/native_world_state.d.ts +18 -13
- package/dest/native/native_world_state.d.ts.map +1 -1
- package/dest/native/native_world_state.js +90 -33
- package/dest/native/native_world_state_instance.d.ts +10 -3
- package/dest/native/native_world_state_instance.d.ts.map +1 -1
- package/dest/native/native_world_state_instance.js +21 -3
- package/dest/native/world_state_ops_queue.js +1 -1
- package/dest/synchronizer/config.d.ts +11 -1
- 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 +8 -1
- package/dest/synchronizer/factory.d.ts.map +1 -1
- package/dest/synchronizer/factory.js +9 -4
- package/dest/synchronizer/server_world_state_synchronizer.d.ts +13 -6
- package/dest/synchronizer/server_world_state_synchronizer.d.ts.map +1 -1
- package/dest/synchronizer/server_world_state_synchronizer.js +78 -38
- package/dest/test/utils.d.ts +1 -1
- package/dest/test/utils.d.ts.map +1 -1
- package/dest/test/utils.js +21 -18
- package/dest/testing.d.ts +1 -1
- package/dest/testing.d.ts.map +1 -1
- package/dest/testing.js +6 -10
- package/dest/world-state-db/merkle_tree_db.d.ts +8 -4
- package/dest/world-state-db/merkle_tree_db.d.ts.map +1 -1
- package/package.json +21 -22
- package/src/instrumentation/instrumentation.ts +22 -10
- package/src/native/bench_metrics.ts +91 -0
- package/src/native/merkle_trees_facade.ts +44 -13
- package/src/native/message.ts +81 -63
- package/src/native/native_world_state.ts +98 -42
- package/src/native/native_world_state_instance.ts +31 -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 +93 -40
- package/src/test/utils.ts +46 -31
- package/src/testing.ts +3 -7
- package/src/world-state-db/merkle_tree_db.ts +9 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/world-state",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.1-commit.24de95ac",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dest/index.js",
|
|
@@ -21,8 +21,6 @@
|
|
|
21
21
|
"build": "yarn clean && tsc -b",
|
|
22
22
|
"build:dev": "tsc -b --watch",
|
|
23
23
|
"clean": "rm -rf ./dest .tsbuildinfo",
|
|
24
|
-
"formatting": "run -T prettier --check ./src && run -T eslint ./src",
|
|
25
|
-
"formatting:fix": "run -T eslint --fix ./src && run -T prettier -w ./src",
|
|
26
24
|
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
|
|
27
25
|
},
|
|
28
26
|
"inherits": [
|
|
@@ -59,32 +57,33 @@
|
|
|
59
57
|
"testTimeout": 120000,
|
|
60
58
|
"setupFiles": [
|
|
61
59
|
"../../foundation/src/jest/setup.mjs"
|
|
60
|
+
],
|
|
61
|
+
"testEnvironment": "../../foundation/src/jest/env.mjs",
|
|
62
|
+
"setupFilesAfterEnv": [
|
|
63
|
+
"../../foundation/src/jest/setupAfterEnv.mjs"
|
|
62
64
|
]
|
|
63
65
|
},
|
|
64
66
|
"dependencies": {
|
|
65
|
-
"@aztec/constants": "0.0.
|
|
66
|
-
"@aztec/foundation": "0.0.
|
|
67
|
-
"@aztec/kv-store": "0.0.
|
|
68
|
-
"@aztec/merkle-tree": "0.0.
|
|
69
|
-
"@aztec/native": "0.0.
|
|
70
|
-
"@aztec/protocol-contracts": "0.0.
|
|
71
|
-
"@aztec/stdlib": "0.0.
|
|
72
|
-
"@aztec/telemetry-client": "0.0.
|
|
67
|
+
"@aztec/constants": "0.0.1-commit.24de95ac",
|
|
68
|
+
"@aztec/foundation": "0.0.1-commit.24de95ac",
|
|
69
|
+
"@aztec/kv-store": "0.0.1-commit.24de95ac",
|
|
70
|
+
"@aztec/merkle-tree": "0.0.1-commit.24de95ac",
|
|
71
|
+
"@aztec/native": "0.0.1-commit.24de95ac",
|
|
72
|
+
"@aztec/protocol-contracts": "0.0.1-commit.24de95ac",
|
|
73
|
+
"@aztec/stdlib": "0.0.1-commit.24de95ac",
|
|
74
|
+
"@aztec/telemetry-client": "0.0.1-commit.24de95ac",
|
|
73
75
|
"tslib": "^2.4.0",
|
|
74
76
|
"zod": "^3.23.8"
|
|
75
77
|
},
|
|
76
78
|
"devDependencies": {
|
|
77
|
-
"@aztec/archiver": "0.0.
|
|
78
|
-
"@jest/globals": "^
|
|
79
|
-
"@types/jest": "^
|
|
80
|
-
"@types/
|
|
81
|
-
"
|
|
82
|
-
"
|
|
83
|
-
"jest": "^29.5.0",
|
|
84
|
-
"jest-mock-extended": "^3.0.5",
|
|
85
|
-
"memdown": "^6.1.1",
|
|
79
|
+
"@aztec/archiver": "0.0.1-commit.24de95ac",
|
|
80
|
+
"@jest/globals": "^30.0.0",
|
|
81
|
+
"@types/jest": "^30.0.0",
|
|
82
|
+
"@types/node": "^22.15.17",
|
|
83
|
+
"jest": "^30.0.0",
|
|
84
|
+
"jest-mock-extended": "^4.0.0",
|
|
86
85
|
"ts-node": "^10.9.1",
|
|
87
|
-
"typescript": "^5.
|
|
86
|
+
"typescript": "^5.3.3"
|
|
88
87
|
},
|
|
89
88
|
"files": [
|
|
90
89
|
"dest",
|
|
@@ -93,6 +92,6 @@
|
|
|
93
92
|
],
|
|
94
93
|
"types": "./dest/index.d.ts",
|
|
95
94
|
"engines": {
|
|
96
|
-
"node": ">=
|
|
95
|
+
"node": ">=20.10"
|
|
97
96
|
}
|
|
98
97
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
1
|
+
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
2
2
|
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
3
3
|
import {
|
|
4
4
|
Attributes,
|
|
@@ -31,34 +31,43 @@ const durationTrackDenylist = new Set<WorldStateMessageType>([
|
|
|
31
31
|
|
|
32
32
|
export class WorldStateInstrumentation {
|
|
33
33
|
private dbMapSize: Gauge;
|
|
34
|
+
private dbPhysicalSize: Gauge;
|
|
34
35
|
private treeSize: Gauge;
|
|
35
|
-
private
|
|
36
|
-
private
|
|
36
|
+
private unfinalizedHeight: Gauge;
|
|
37
|
+
private finalizedHeight: Gauge;
|
|
37
38
|
private oldestBlock: Gauge;
|
|
38
39
|
private dbNumItems: Gauge;
|
|
39
40
|
private dbUsedSize: Gauge;
|
|
40
41
|
private requestHistogram: Histogram;
|
|
41
42
|
private criticalErrors: UpDownCounter;
|
|
42
43
|
|
|
43
|
-
constructor(
|
|
44
|
+
constructor(
|
|
45
|
+
public readonly telemetry: TelemetryClient,
|
|
46
|
+
private log: Logger = createLogger('world-state:instrumentation'),
|
|
47
|
+
) {
|
|
44
48
|
const meter = telemetry.getMeter('World State');
|
|
45
49
|
this.dbMapSize = meter.createGauge(Metrics.WORLD_STATE_DB_MAP_SIZE, {
|
|
46
50
|
description: `The current configured map size for each merkle tree`,
|
|
47
51
|
valueType: ValueType.INT,
|
|
48
52
|
});
|
|
49
53
|
|
|
54
|
+
this.dbPhysicalSize = meter.createGauge(Metrics.WORLD_STATE_DB_PHYSICAL_SIZE, {
|
|
55
|
+
description: `The current physical disk space used for each database`,
|
|
56
|
+
valueType: ValueType.INT,
|
|
57
|
+
});
|
|
58
|
+
|
|
50
59
|
this.treeSize = meter.createGauge(Metrics.WORLD_STATE_TREE_SIZE, {
|
|
51
60
|
description: `The current number of leaves in each merkle tree`,
|
|
52
61
|
valueType: ValueType.INT,
|
|
53
62
|
});
|
|
54
63
|
|
|
55
|
-
this.
|
|
56
|
-
description: `The
|
|
64
|
+
this.unfinalizedHeight = meter.createGauge(Metrics.WORLD_STATE_UNFINALIZED_HEIGHT, {
|
|
65
|
+
description: `The unfinalized block height of each merkle tree`,
|
|
57
66
|
valueType: ValueType.INT,
|
|
58
67
|
});
|
|
59
68
|
|
|
60
|
-
this.
|
|
61
|
-
description: `The
|
|
69
|
+
this.finalizedHeight = meter.createGauge(Metrics.WORLD_STATE_FINALIZED_HEIGHT, {
|
|
70
|
+
description: `The finalized block height of each merkle tree`,
|
|
62
71
|
valueType: ValueType.INT,
|
|
63
72
|
});
|
|
64
73
|
|
|
@@ -93,13 +102,16 @@ export class WorldStateInstrumentation {
|
|
|
93
102
|
this.dbMapSize.record(Number(treeDbStats.mapSize), {
|
|
94
103
|
[Attributes.MERKLE_TREE_NAME]: MerkleTreeId[tree],
|
|
95
104
|
});
|
|
105
|
+
this.dbPhysicalSize.record(Number(treeDbStats.physicalFileSize), {
|
|
106
|
+
[Attributes.MERKLE_TREE_NAME]: MerkleTreeId[tree],
|
|
107
|
+
});
|
|
96
108
|
this.treeSize.record(Number(treeMeta.size), {
|
|
97
109
|
[Attributes.MERKLE_TREE_NAME]: MerkleTreeId[tree],
|
|
98
110
|
});
|
|
99
|
-
this.
|
|
111
|
+
this.unfinalizedHeight.record(Number(treeMeta.unfinalizedBlockHeight), {
|
|
100
112
|
[Attributes.MERKLE_TREE_NAME]: MerkleTreeId[tree],
|
|
101
113
|
});
|
|
102
|
-
this.
|
|
114
|
+
this.finalizedHeight.record(Number(treeMeta.finalizedBlockHeight), {
|
|
103
115
|
[Attributes.MERKLE_TREE_NAME]: MerkleTreeId[tree],
|
|
104
116
|
});
|
|
105
117
|
this.oldestBlock.record(Number(treeMeta.oldestHistoricBlock), {
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
2
|
+
|
|
3
|
+
type BlockSyncMetrics = {
|
|
4
|
+
numTxs: number;
|
|
5
|
+
numLeaves: number;
|
|
6
|
+
value: number;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export enum InsertionType {
|
|
10
|
+
BATCH,
|
|
11
|
+
SEQUENTIAL,
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
type InsertionMetrics = {
|
|
15
|
+
treeType: MerkleTreeId;
|
|
16
|
+
insertionType: InsertionType;
|
|
17
|
+
numLeaves: number;
|
|
18
|
+
value: number;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export enum DataRetrievalType {
|
|
22
|
+
SIBLING_PATH,
|
|
23
|
+
LEAF_PREIMAGE,
|
|
24
|
+
LEAF_VALUE,
|
|
25
|
+
LEAF_INDICES,
|
|
26
|
+
LOW_LEAF,
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
type DataRetrievalMetrics = {
|
|
30
|
+
retrievalType: DataRetrievalType;
|
|
31
|
+
value: number;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export class NativeBenchMetics {
|
|
35
|
+
private blockSyncMetrics: BlockSyncMetrics[] = [];
|
|
36
|
+
private insertionMetrics: InsertionMetrics[] = [];
|
|
37
|
+
private dataRetrievalMetrics: DataRetrievalMetrics[] = [];
|
|
38
|
+
|
|
39
|
+
public toPrettyString() {
|
|
40
|
+
let pretty = '';
|
|
41
|
+
pretty += `Block sync metrics:\n`;
|
|
42
|
+
for (const metric of this.blockSyncMetrics) {
|
|
43
|
+
pretty += ` ${metric.numTxs} txs, ${metric.numLeaves} leaves: ${metric.value} ms\n`;
|
|
44
|
+
}
|
|
45
|
+
pretty += `Insertion metrics:\n`;
|
|
46
|
+
for (const metric of this.insertionMetrics) {
|
|
47
|
+
pretty += ` ${MerkleTreeId[metric.treeType]}: ${InsertionType[metric.insertionType]} (${metric.numLeaves} leaves): ${metric.value} ms\n`;
|
|
48
|
+
}
|
|
49
|
+
pretty += `Data retrieval metrics:\n`;
|
|
50
|
+
for (const metric of this.dataRetrievalMetrics) {
|
|
51
|
+
pretty += ` ${DataRetrievalType[metric.retrievalType]}: ${metric.value} us\n`;
|
|
52
|
+
}
|
|
53
|
+
return pretty;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
public addBlockSyncMetric(numTxs: number, numLeaves: number, value: number) {
|
|
57
|
+
this.blockSyncMetrics.push({ numTxs, numLeaves, value });
|
|
58
|
+
}
|
|
59
|
+
public addInsertionMetric(treeId: MerkleTreeId, insertionType: InsertionType, numLeaves: number, value: number) {
|
|
60
|
+
this.insertionMetrics.push({ treeType: treeId, insertionType, numLeaves, value });
|
|
61
|
+
}
|
|
62
|
+
public addDataRetrievalMetric(retrievalType: DataRetrievalType, value: number) {
|
|
63
|
+
this.dataRetrievalMetrics.push({ retrievalType, value: value });
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
public toGithubActionBenchmarkJSON(indent = 2) {
|
|
67
|
+
const data = [];
|
|
68
|
+
for (const blockSync of this.blockSyncMetrics) {
|
|
69
|
+
data.push({
|
|
70
|
+
name: `Block Sync/${blockSync.numTxs} txs/${blockSync.numLeaves} leaves per tx`,
|
|
71
|
+
value: blockSync.value,
|
|
72
|
+
unit: 'ms',
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
for (const insertion of this.insertionMetrics) {
|
|
76
|
+
data.push({
|
|
77
|
+
name: `Tree Insertion/${MerkleTreeId[insertion.treeType]}/${InsertionType[insertion.insertionType]}/${insertion.numLeaves} leaves`,
|
|
78
|
+
value: insertion.value,
|
|
79
|
+
unit: 'ms',
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
for (const retrieval of this.dataRetrievalMetrics) {
|
|
83
|
+
data.push({
|
|
84
|
+
name: `Data Retrieval/${DataRetrievalType[retrieval.retrievalType]}`,
|
|
85
|
+
value: retrieval.value,
|
|
86
|
+
unit: 'us',
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
return JSON.stringify(data, null, indent);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
PublicDataTreeLeafPreimage,
|
|
19
19
|
} from '@aztec/stdlib/trees';
|
|
20
20
|
import { type BlockHeader, PartialStateReference, StateReference } from '@aztec/stdlib/tx';
|
|
21
|
+
import type { WorldStateRevision } from '@aztec/stdlib/world-state';
|
|
21
22
|
|
|
22
23
|
import assert from 'assert';
|
|
23
24
|
|
|
@@ -25,7 +26,6 @@ import {
|
|
|
25
26
|
type SerializedIndexedLeaf,
|
|
26
27
|
type SerializedLeafValue,
|
|
27
28
|
WorldStateMessageType,
|
|
28
|
-
type WorldStateRevision,
|
|
29
29
|
blockStateReference,
|
|
30
30
|
treeStateReferenceToSnapshot,
|
|
31
31
|
} from './message.js';
|
|
@@ -42,10 +42,32 @@ export class MerkleTreesFacade implements MerkleTreeReadOperations {
|
|
|
42
42
|
return this.initialHeader;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
getRevision(): WorldStateRevision {
|
|
46
|
+
return this.revision;
|
|
47
|
+
}
|
|
48
|
+
|
|
45
49
|
findLeafIndices(treeId: MerkleTreeId, values: MerkleTreeLeafType<MerkleTreeId>[]): Promise<(bigint | undefined)[]> {
|
|
46
50
|
return this.findLeafIndicesAfter(treeId, values, 0n);
|
|
47
51
|
}
|
|
48
52
|
|
|
53
|
+
async findSiblingPaths<N extends number>(
|
|
54
|
+
treeId: MerkleTreeId,
|
|
55
|
+
values: MerkleTreeLeafType<MerkleTreeId>[],
|
|
56
|
+
): Promise<({ path: SiblingPath<N>; index: bigint } | undefined)[]> {
|
|
57
|
+
const response = await this.instance.call(WorldStateMessageType.FIND_SIBLING_PATHS, {
|
|
58
|
+
leaves: values.map(leaf => serializeLeaf(hydrateLeaf(treeId, leaf))),
|
|
59
|
+
revision: this.revision,
|
|
60
|
+
treeId,
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
return response.paths.map(path => {
|
|
64
|
+
if (!path) {
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
67
|
+
return { path: new SiblingPath<N>(path.path.length as N, path.path), index: BigInt(path.index) };
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
49
71
|
async findLeafIndicesAfter(
|
|
50
72
|
treeId: MerkleTreeId,
|
|
51
73
|
leaves: MerkleTreeLeafType<MerkleTreeId>[],
|
|
@@ -277,6 +299,16 @@ export class MerkleTreesForkFacade extends MerkleTreesFacade implements MerkleTr
|
|
|
277
299
|
assert.notEqual(this.revision.forkId, 0, 'Fork ID must be set');
|
|
278
300
|
await this.instance.call(WorldStateMessageType.REVERT_CHECKPOINT, { forkId: this.revision.forkId });
|
|
279
301
|
}
|
|
302
|
+
|
|
303
|
+
public async commitAllCheckpoints(): Promise<void> {
|
|
304
|
+
assert.notEqual(this.revision.forkId, 0, 'Fork ID must be set');
|
|
305
|
+
await this.instance.call(WorldStateMessageType.COMMIT_ALL_CHECKPOINTS, { forkId: this.revision.forkId });
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
public async revertAllCheckpoints(): Promise<void> {
|
|
309
|
+
assert.notEqual(this.revision.forkId, 0, 'Fork ID must be set');
|
|
310
|
+
await this.instance.call(WorldStateMessageType.REVERT_ALL_CHECKPOINTS, { forkId: this.revision.forkId });
|
|
311
|
+
}
|
|
280
312
|
}
|
|
281
313
|
|
|
282
314
|
function hydrateLeaf<ID extends MerkleTreeId>(treeId: ID, leaf: Fr | Buffer) {
|
|
@@ -295,7 +327,7 @@ export function serializeLeaf(leaf: Fr | NullifierLeaf | PublicDataTreeLeaf): Se
|
|
|
295
327
|
if (leaf instanceof Fr) {
|
|
296
328
|
return leaf.toBuffer();
|
|
297
329
|
} else if (leaf instanceof NullifierLeaf) {
|
|
298
|
-
return {
|
|
330
|
+
return { nullifier: leaf.nullifier.toBuffer() };
|
|
299
331
|
} else {
|
|
300
332
|
return { value: leaf.value.toBuffer(), slot: leaf.slot.toBuffer() };
|
|
301
333
|
}
|
|
@@ -307,23 +339,22 @@ function deserializeLeafValue(leaf: SerializedLeafValue): Fr | NullifierLeaf | P
|
|
|
307
339
|
} else if ('slot' in leaf) {
|
|
308
340
|
return new PublicDataTreeLeaf(Fr.fromBuffer(leaf.slot), Fr.fromBuffer(leaf.value));
|
|
309
341
|
} else {
|
|
310
|
-
return new NullifierLeaf(Fr.fromBuffer(leaf.
|
|
342
|
+
return new NullifierLeaf(Fr.fromBuffer(leaf.nullifier));
|
|
311
343
|
}
|
|
312
344
|
}
|
|
313
345
|
|
|
314
|
-
function deserializeIndexedLeaf(
|
|
315
|
-
if ('slot' in leaf
|
|
346
|
+
function deserializeIndexedLeaf(leafPreimage: SerializedIndexedLeaf): IndexedTreeLeafPreimage {
|
|
347
|
+
if ('slot' in leafPreimage.leaf) {
|
|
316
348
|
return new PublicDataTreeLeafPreimage(
|
|
317
|
-
Fr.fromBuffer(leaf.
|
|
318
|
-
Fr.fromBuffer(
|
|
319
|
-
|
|
320
|
-
BigInt(leaf.nextIndex),
|
|
349
|
+
new PublicDataTreeLeaf(Fr.fromBuffer(leafPreimage.leaf.slot), Fr.fromBuffer(leafPreimage.leaf.value)),
|
|
350
|
+
Fr.fromBuffer(leafPreimage.nextKey),
|
|
351
|
+
BigInt(leafPreimage.nextIndex),
|
|
321
352
|
);
|
|
322
|
-
} else if ('
|
|
353
|
+
} else if ('nullifier' in leafPreimage.leaf) {
|
|
323
354
|
return new NullifierLeafPreimage(
|
|
324
|
-
Fr.fromBuffer(leaf.
|
|
325
|
-
Fr.fromBuffer(
|
|
326
|
-
BigInt(
|
|
355
|
+
new NullifierLeaf(Fr.fromBuffer(leafPreimage.leaf.nullifier)),
|
|
356
|
+
Fr.fromBuffer(leafPreimage.nextKey),
|
|
357
|
+
BigInt(leafPreimage.nextIndex),
|
|
327
358
|
);
|
|
328
359
|
} else {
|
|
329
360
|
throw new Error('Invalid leaf type');
|
package/src/native/message.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { Tuple } from '@aztec/foundation/serialize';
|
|
|
3
3
|
import { AppendOnlyTreeSnapshot, MerkleTreeId } from '@aztec/stdlib/trees';
|
|
4
4
|
import type { StateReference } from '@aztec/stdlib/tx';
|
|
5
5
|
import type { UInt32 } from '@aztec/stdlib/types';
|
|
6
|
+
import type { WorldStateRevision } from '@aztec/stdlib/world-state';
|
|
6
7
|
|
|
7
8
|
export enum WorldStateMessageType {
|
|
8
9
|
GET_TREE_INFO = 100,
|
|
@@ -16,6 +17,7 @@ export enum WorldStateMessageType {
|
|
|
16
17
|
|
|
17
18
|
FIND_LEAF_INDICES,
|
|
18
19
|
FIND_LOW_LEAF,
|
|
20
|
+
FIND_SIBLING_PATHS,
|
|
19
21
|
|
|
20
22
|
APPEND_LEAVES,
|
|
21
23
|
BATCH_INSERT,
|
|
@@ -31,7 +33,7 @@ export enum WorldStateMessageType {
|
|
|
31
33
|
CREATE_FORK,
|
|
32
34
|
DELETE_FORK,
|
|
33
35
|
|
|
34
|
-
|
|
36
|
+
FINALIZE_BLOCKS,
|
|
35
37
|
UNWIND_BLOCKS,
|
|
36
38
|
REMOVE_HISTORICAL_BLOCKS,
|
|
37
39
|
|
|
@@ -40,6 +42,10 @@ export enum WorldStateMessageType {
|
|
|
40
42
|
CREATE_CHECKPOINT,
|
|
41
43
|
COMMIT_CHECKPOINT,
|
|
42
44
|
REVERT_CHECKPOINT,
|
|
45
|
+
COMMIT_ALL_CHECKPOINTS,
|
|
46
|
+
REVERT_ALL_CHECKPOINTS,
|
|
47
|
+
|
|
48
|
+
COPY_STORES,
|
|
43
49
|
|
|
44
50
|
CLOSE = 999,
|
|
45
51
|
}
|
|
@@ -50,9 +56,9 @@ interface WithTreeId {
|
|
|
50
56
|
|
|
51
57
|
export interface WorldStateStatusSummary {
|
|
52
58
|
/** Last block number that can still be unwound. */
|
|
53
|
-
|
|
54
|
-
/** Last block number that is
|
|
55
|
-
|
|
59
|
+
unfinalizedBlockNumber: bigint;
|
|
60
|
+
/** Last block number that is finalized and cannot be unwound. */
|
|
61
|
+
finalizedBlockNumber: bigint;
|
|
56
62
|
/** Oldest block still available for historical queries and forks. */
|
|
57
63
|
oldestHistoricalBlock: bigint;
|
|
58
64
|
/** Whether the trees are in sync with each other */
|
|
@@ -76,10 +82,10 @@ export interface TreeMeta {
|
|
|
76
82
|
initialRoot: Fr;
|
|
77
83
|
/** The current oldest historical block number of the tree */
|
|
78
84
|
oldestHistoricBlock: bigint;
|
|
79
|
-
/** The current
|
|
80
|
-
|
|
81
|
-
/** The current
|
|
82
|
-
|
|
85
|
+
/** The current unfinalized block number of the tree */
|
|
86
|
+
unfinalizedBlockHeight: bigint;
|
|
87
|
+
/** The current finalized block number of the tree */
|
|
88
|
+
finalizedBlockHeight: bigint;
|
|
83
89
|
}
|
|
84
90
|
|
|
85
91
|
export interface DBStats {
|
|
@@ -94,6 +100,8 @@ export interface DBStats {
|
|
|
94
100
|
export interface TreeDBStats {
|
|
95
101
|
/** The configured max size of the DB mapping file (effectively the max possible size of the DB) */
|
|
96
102
|
mapSize: bigint;
|
|
103
|
+
/** The physical file size of the database on disk */
|
|
104
|
+
physicalFileSize: bigint;
|
|
97
105
|
/** Stats for the 'blocks' DB */
|
|
98
106
|
blocksDBStats: DBStats;
|
|
99
107
|
/** Stats for the 'nodes' DB */
|
|
@@ -149,6 +157,7 @@ export function buildEmptyDBStats() {
|
|
|
149
157
|
export function buildEmptyTreeDBStats() {
|
|
150
158
|
return {
|
|
151
159
|
mapSize: 0n,
|
|
160
|
+
physicalFileSize: 0n,
|
|
152
161
|
blocksDBStats: buildEmptyDBStats(),
|
|
153
162
|
nodesDBStats: buildEmptyDBStats(),
|
|
154
163
|
leafIndicesDBStats: buildEmptyDBStats(),
|
|
@@ -164,8 +173,8 @@ export function buildEmptyTreeMeta() {
|
|
|
164
173
|
depth: 0,
|
|
165
174
|
size: 0n,
|
|
166
175
|
committedSize: 0n,
|
|
167
|
-
|
|
168
|
-
|
|
176
|
+
unfinalizedBlockHeight: 0n,
|
|
177
|
+
finalizedBlockHeight: 0n,
|
|
169
178
|
oldestHistoricBlock: 0n,
|
|
170
179
|
root: Fr.ZERO,
|
|
171
180
|
initialRoot: Fr.ZERO,
|
|
@@ -195,8 +204,8 @@ export function buildEmptyWorldStateDBStats() {
|
|
|
195
204
|
|
|
196
205
|
export function buildEmptyWorldStateSummary() {
|
|
197
206
|
return {
|
|
198
|
-
|
|
199
|
-
|
|
207
|
+
unfinalizedBlockNumber: 0n,
|
|
208
|
+
finalizedBlockNumber: 0n,
|
|
200
209
|
oldestHistoricalBlock: 0n,
|
|
201
210
|
treesAreSynched: true,
|
|
202
211
|
} as WorldStateStatusSummary;
|
|
@@ -210,61 +219,62 @@ export function buildEmptyWorldStateStatusFull() {
|
|
|
210
219
|
} as WorldStateStatusFull;
|
|
211
220
|
}
|
|
212
221
|
|
|
213
|
-
export function
|
|
214
|
-
summary.
|
|
215
|
-
summary.
|
|
222
|
+
export function sanitizeSummary(summary: WorldStateStatusSummary) {
|
|
223
|
+
summary.finalizedBlockNumber = BigInt(summary.finalizedBlockNumber);
|
|
224
|
+
summary.unfinalizedBlockNumber = BigInt(summary.unfinalizedBlockNumber);
|
|
216
225
|
summary.oldestHistoricalBlock = BigInt(summary.oldestHistoricalBlock);
|
|
217
226
|
return summary;
|
|
218
227
|
}
|
|
219
228
|
|
|
220
|
-
export function
|
|
229
|
+
export function sanitizeDBStats(stats: DBStats) {
|
|
221
230
|
stats.numDataItems = BigInt(stats.numDataItems);
|
|
222
231
|
stats.totalUsedSize = BigInt(stats.totalUsedSize);
|
|
223
232
|
return stats;
|
|
224
233
|
}
|
|
225
234
|
|
|
226
|
-
export function
|
|
235
|
+
export function sanitizeMeta(meta: TreeMeta) {
|
|
227
236
|
meta.committedSize = BigInt(meta.committedSize);
|
|
228
|
-
meta.
|
|
237
|
+
meta.finalizedBlockHeight = BigInt(meta.finalizedBlockHeight);
|
|
229
238
|
meta.initialSize = BigInt(meta.initialSize);
|
|
230
239
|
meta.oldestHistoricBlock = BigInt(meta.oldestHistoricBlock);
|
|
231
240
|
meta.size = BigInt(meta.size);
|
|
232
|
-
meta.
|
|
241
|
+
meta.unfinalizedBlockHeight = BigInt(meta.unfinalizedBlockHeight);
|
|
233
242
|
return meta;
|
|
234
243
|
}
|
|
235
244
|
|
|
236
|
-
export function
|
|
237
|
-
stats.blocksDBStats =
|
|
238
|
-
stats.leafIndicesDBStats =
|
|
239
|
-
stats.leafPreimagesDBStats =
|
|
240
|
-
stats.blockIndicesDBStats =
|
|
241
|
-
stats.nodesDBStats =
|
|
245
|
+
export function sanitizeTreeDBStats(stats: TreeDBStats) {
|
|
246
|
+
stats.blocksDBStats = sanitizeDBStats(stats.blocksDBStats);
|
|
247
|
+
stats.leafIndicesDBStats = sanitizeDBStats(stats.leafIndicesDBStats);
|
|
248
|
+
stats.leafPreimagesDBStats = sanitizeDBStats(stats.leafPreimagesDBStats);
|
|
249
|
+
stats.blockIndicesDBStats = sanitizeDBStats(stats.blockIndicesDBStats);
|
|
250
|
+
stats.nodesDBStats = sanitizeDBStats(stats.nodesDBStats);
|
|
242
251
|
stats.mapSize = BigInt(stats.mapSize);
|
|
252
|
+
stats.physicalFileSize = BigInt(stats.physicalFileSize);
|
|
243
253
|
return stats;
|
|
244
254
|
}
|
|
245
255
|
|
|
246
|
-
export function
|
|
247
|
-
stats.archiveTreeStats =
|
|
248
|
-
stats.messageTreeStats =
|
|
249
|
-
stats.noteHashTreeStats =
|
|
250
|
-
stats.nullifierTreeStats =
|
|
251
|
-
stats.publicDataTreeStats =
|
|
256
|
+
export function sanitizeWorldStateDBStats(stats: WorldStateDBStats) {
|
|
257
|
+
stats.archiveTreeStats = sanitizeTreeDBStats(stats.archiveTreeStats);
|
|
258
|
+
stats.messageTreeStats = sanitizeTreeDBStats(stats.messageTreeStats);
|
|
259
|
+
stats.noteHashTreeStats = sanitizeTreeDBStats(stats.noteHashTreeStats);
|
|
260
|
+
stats.nullifierTreeStats = sanitizeTreeDBStats(stats.nullifierTreeStats);
|
|
261
|
+
stats.publicDataTreeStats = sanitizeTreeDBStats(stats.publicDataTreeStats);
|
|
252
262
|
return stats;
|
|
253
263
|
}
|
|
254
264
|
|
|
255
|
-
export function
|
|
256
|
-
meta.archiveTreeMeta =
|
|
257
|
-
meta.messageTreeMeta =
|
|
258
|
-
meta.noteHashTreeMeta =
|
|
259
|
-
meta.nullifierTreeMeta =
|
|
260
|
-
meta.publicDataTreeMeta =
|
|
265
|
+
export function sanitizeWorldStateTreeMeta(meta: WorldStateMeta) {
|
|
266
|
+
meta.archiveTreeMeta = sanitizeMeta(meta.archiveTreeMeta);
|
|
267
|
+
meta.messageTreeMeta = sanitizeMeta(meta.messageTreeMeta);
|
|
268
|
+
meta.noteHashTreeMeta = sanitizeMeta(meta.noteHashTreeMeta);
|
|
269
|
+
meta.nullifierTreeMeta = sanitizeMeta(meta.nullifierTreeMeta);
|
|
270
|
+
meta.publicDataTreeMeta = sanitizeMeta(meta.publicDataTreeMeta);
|
|
261
271
|
return meta;
|
|
262
272
|
}
|
|
263
273
|
|
|
264
|
-
export function
|
|
265
|
-
status.dbStats =
|
|
266
|
-
status.summary =
|
|
267
|
-
status.meta =
|
|
274
|
+
export function sanitizeFullStatus(status: WorldStateStatusFull) {
|
|
275
|
+
status.dbStats = sanitizeWorldStateDBStats(status.dbStats);
|
|
276
|
+
status.summary = sanitizeSummary(status.summary);
|
|
277
|
+
status.meta = sanitizeWorldStateTreeMeta(status.meta);
|
|
268
278
|
return status;
|
|
269
279
|
}
|
|
270
280
|
|
|
@@ -286,13 +296,13 @@ interface WithLeafIndex {
|
|
|
286
296
|
|
|
287
297
|
export type SerializedLeafValue =
|
|
288
298
|
| Buffer // Fr
|
|
289
|
-
| {
|
|
299
|
+
| { nullifier: Buffer } // NullifierLeaf
|
|
290
300
|
| { value: Buffer; slot: Buffer }; // PublicDataTreeLeaf
|
|
291
301
|
|
|
292
302
|
export type SerializedIndexedLeaf = {
|
|
293
|
-
|
|
303
|
+
leaf: Exclude<SerializedLeafValue, Buffer>;
|
|
294
304
|
nextIndex: bigint | number;
|
|
295
|
-
|
|
305
|
+
nextKey: Buffer; // Fr
|
|
296
306
|
};
|
|
297
307
|
|
|
298
308
|
interface WithLeafValues {
|
|
@@ -344,6 +354,16 @@ interface FindLeafIndicesResponse {
|
|
|
344
354
|
indices: bigint[];
|
|
345
355
|
}
|
|
346
356
|
|
|
357
|
+
interface FindSiblingPathsRequest extends WithTreeId, WithLeafValues, WithWorldStateRevision {}
|
|
358
|
+
|
|
359
|
+
interface SiblingPathAndIndex {
|
|
360
|
+
index: bigint;
|
|
361
|
+
path: Buffer[];
|
|
362
|
+
}
|
|
363
|
+
interface FindSiblingPathsResponse {
|
|
364
|
+
paths: (SiblingPathAndIndex | undefined)[];
|
|
365
|
+
}
|
|
366
|
+
|
|
347
367
|
interface FindLowLeafRequest extends WithTreeId, WithWorldStateRevision {
|
|
348
368
|
key: Fr;
|
|
349
369
|
}
|
|
@@ -409,6 +429,11 @@ interface CreateForkResponse {
|
|
|
409
429
|
|
|
410
430
|
interface DeleteForkRequest extends WithForkId {}
|
|
411
431
|
|
|
432
|
+
interface CopyStoresRequest extends WithCanonicalForkId {
|
|
433
|
+
dstPath: string;
|
|
434
|
+
compact: boolean;
|
|
435
|
+
}
|
|
436
|
+
|
|
412
437
|
export type WorldStateRequestCategories = WithForkId | WithWorldStateRevision | WithCanonicalForkId;
|
|
413
438
|
|
|
414
439
|
export function isWithForkId(body: WorldStateRequestCategories): body is WithForkId {
|
|
@@ -435,6 +460,7 @@ export type WorldStateRequest = {
|
|
|
435
460
|
|
|
436
461
|
[WorldStateMessageType.FIND_LEAF_INDICES]: FindLeafIndicesRequest;
|
|
437
462
|
[WorldStateMessageType.FIND_LOW_LEAF]: FindLowLeafRequest;
|
|
463
|
+
[WorldStateMessageType.FIND_SIBLING_PATHS]: FindSiblingPathsRequest;
|
|
438
464
|
|
|
439
465
|
[WorldStateMessageType.APPEND_LEAVES]: AppendLeavesRequest;
|
|
440
466
|
[WorldStateMessageType.BATCH_INSERT]: BatchInsertRequest;
|
|
@@ -452,13 +478,17 @@ export type WorldStateRequest = {
|
|
|
452
478
|
|
|
453
479
|
[WorldStateMessageType.REMOVE_HISTORICAL_BLOCKS]: BlockShiftRequest;
|
|
454
480
|
[WorldStateMessageType.UNWIND_BLOCKS]: BlockShiftRequest;
|
|
455
|
-
[WorldStateMessageType.
|
|
481
|
+
[WorldStateMessageType.FINALIZE_BLOCKS]: BlockShiftRequest;
|
|
456
482
|
|
|
457
483
|
[WorldStateMessageType.GET_STATUS]: WithCanonicalForkId;
|
|
458
484
|
|
|
459
485
|
[WorldStateMessageType.CREATE_CHECKPOINT]: WithForkId;
|
|
460
486
|
[WorldStateMessageType.COMMIT_CHECKPOINT]: WithForkId;
|
|
461
487
|
[WorldStateMessageType.REVERT_CHECKPOINT]: WithForkId;
|
|
488
|
+
[WorldStateMessageType.COMMIT_ALL_CHECKPOINTS]: WithForkId;
|
|
489
|
+
[WorldStateMessageType.REVERT_ALL_CHECKPOINTS]: WithForkId;
|
|
490
|
+
|
|
491
|
+
[WorldStateMessageType.COPY_STORES]: CopyStoresRequest;
|
|
462
492
|
|
|
463
493
|
[WorldStateMessageType.CLOSE]: WithCanonicalForkId;
|
|
464
494
|
};
|
|
@@ -475,6 +505,7 @@ export type WorldStateResponse = {
|
|
|
475
505
|
|
|
476
506
|
[WorldStateMessageType.FIND_LEAF_INDICES]: FindLeafIndicesResponse;
|
|
477
507
|
[WorldStateMessageType.FIND_LOW_LEAF]: FindLowLeafResponse;
|
|
508
|
+
[WorldStateMessageType.FIND_SIBLING_PATHS]: FindSiblingPathsResponse;
|
|
478
509
|
|
|
479
510
|
[WorldStateMessageType.APPEND_LEAVES]: void;
|
|
480
511
|
[WorldStateMessageType.BATCH_INSERT]: BatchInsertResponse;
|
|
@@ -492,33 +523,20 @@ export type WorldStateResponse = {
|
|
|
492
523
|
|
|
493
524
|
[WorldStateMessageType.REMOVE_HISTORICAL_BLOCKS]: WorldStateStatusFull;
|
|
494
525
|
[WorldStateMessageType.UNWIND_BLOCKS]: WorldStateStatusFull;
|
|
495
|
-
[WorldStateMessageType.
|
|
526
|
+
[WorldStateMessageType.FINALIZE_BLOCKS]: WorldStateStatusSummary;
|
|
496
527
|
|
|
497
528
|
[WorldStateMessageType.GET_STATUS]: WorldStateStatusSummary;
|
|
498
529
|
|
|
499
530
|
[WorldStateMessageType.CREATE_CHECKPOINT]: void;
|
|
500
531
|
[WorldStateMessageType.COMMIT_CHECKPOINT]: void;
|
|
501
532
|
[WorldStateMessageType.REVERT_CHECKPOINT]: void;
|
|
533
|
+
[WorldStateMessageType.COMMIT_ALL_CHECKPOINTS]: void;
|
|
534
|
+
[WorldStateMessageType.REVERT_ALL_CHECKPOINTS]: void;
|
|
502
535
|
|
|
503
|
-
[WorldStateMessageType.
|
|
504
|
-
};
|
|
536
|
+
[WorldStateMessageType.COPY_STORES]: void;
|
|
505
537
|
|
|
506
|
-
|
|
507
|
-
forkId: number;
|
|
508
|
-
blockNumber: number;
|
|
509
|
-
includeUncommitted: boolean;
|
|
538
|
+
[WorldStateMessageType.CLOSE]: void;
|
|
510
539
|
};
|
|
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
540
|
|
|
523
541
|
type TreeStateReference = readonly [Buffer, number | bigint];
|
|
524
542
|
type BlockStateReference = Map<Exclude<MerkleTreeId, MerkleTreeId.ARCHIVE>, TreeStateReference>;
|