@aztec/world-state 0.0.0-test.0 → 0.0.1-commit.03f7ef2
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 +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/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 +62 -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 +20 -29
- package/dest/synchronizer/server_world_state_synchronizer.d.ts.map +1 -1
- package/dest/synchronizer/server_world_state_synchronizer.js +94 -70
- 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 +12 -9
- package/dest/world-state-db/merkle_tree_db.d.ts.map +1 -1
- package/package.json +24 -24
- package/src/instrumentation/instrumentation.ts +22 -10
- 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 +132 -93
- package/src/test/utils.ts +94 -84
- package/src/testing.ts +4 -8
- package/src/world-state-db/merkle_tree_db.ts +12 -8
package/dest/testing.js
CHANGED
|
@@ -1,24 +1,20 @@
|
|
|
1
|
-
import { GENESIS_ARCHIVE_ROOT
|
|
2
|
-
import { Fr } from '@aztec/foundation/
|
|
1
|
+
import { GENESIS_ARCHIVE_ROOT } from '@aztec/constants';
|
|
2
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
3
|
import { computeFeePayerBalanceLeafSlot } from '@aztec/protocol-contracts/fee-juice';
|
|
4
4
|
import { MerkleTreeId, PublicDataTreeLeaf } from '@aztec/stdlib/trees';
|
|
5
5
|
import { NativeWorldStateService } from './native/index.js';
|
|
6
6
|
async function generateGenesisValues(prefilledPublicData) {
|
|
7
7
|
if (!prefilledPublicData.length) {
|
|
8
8
|
return {
|
|
9
|
-
genesisArchiveRoot: new Fr(GENESIS_ARCHIVE_ROOT)
|
|
10
|
-
genesisBlockHash: new Fr(GENESIS_BLOCK_HASH)
|
|
9
|
+
genesisArchiveRoot: new Fr(GENESIS_ARCHIVE_ROOT)
|
|
11
10
|
};
|
|
12
11
|
}
|
|
13
12
|
// Create a temporary world state to compute the genesis values.
|
|
14
13
|
const ws = await NativeWorldStateService.tmp(undefined /* rollupAddress */ , true, prefilledPublicData);
|
|
15
|
-
const initialHeader = ws.getInitialHeader();
|
|
16
|
-
const genesisBlockHash = await initialHeader.hash();
|
|
17
14
|
const genesisArchiveRoot = new Fr((await ws.getCommitted().getTreeInfo(MerkleTreeId.ARCHIVE)).root);
|
|
18
15
|
await ws.close();
|
|
19
16
|
return {
|
|
20
|
-
genesisArchiveRoot
|
|
21
|
-
genesisBlockHash
|
|
17
|
+
genesisArchiveRoot
|
|
22
18
|
};
|
|
23
19
|
}
|
|
24
20
|
export const defaultInitialAccountFeeJuice = new Fr(10n ** 22n);
|
|
@@ -28,10 +24,10 @@ export async function getGenesisValues(initialAccounts, initialAccountFeeJuice =
|
|
|
28
24
|
// Add user-defined public data
|
|
29
25
|
prefilledPublicData = prefilledPublicData.concat(genesisPublicData);
|
|
30
26
|
prefilledPublicData.sort((a, b)=>b.slot.lt(a.slot) ? 1 : -1);
|
|
31
|
-
const {
|
|
27
|
+
const { genesisArchiveRoot } = await generateGenesisValues(prefilledPublicData);
|
|
32
28
|
return {
|
|
33
29
|
genesisArchiveRoot,
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
prefilledPublicData,
|
|
31
|
+
fundingNeeded: BigInt(initialAccounts.length) * initialAccountFeeJuice.toBigInt()
|
|
36
32
|
};
|
|
37
33
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export * from './merkle_tree_db.js';
|
|
2
2
|
export type { MerkleTreeReadOperations } from '@aztec/stdlib/interfaces/server';
|
|
3
|
-
//# sourceMappingURL=
|
|
3
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy93b3JsZC1zdGF0ZS1kYi9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxjQUFjLHFCQUFxQixDQUFDO0FBRXBDLFlBQVksRUFBRSx3QkFBd0IsRUFBRSxNQUFNLGlDQUFpQyxDQUFDIn0=
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
3
|
import type { IndexedTreeSnapshot, TreeSnapshot } from '@aztec/merkle-tree';
|
|
3
|
-
import type {
|
|
4
|
+
import type { L2BlockNew } from '@aztec/stdlib/block';
|
|
4
5
|
import type { ForkMerkleTreeOperations, MerkleTreeReadOperations } from '@aztec/stdlib/interfaces/server';
|
|
5
6
|
import type { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
6
7
|
import type { WorldStateStatusFull, WorldStateStatusSummary } from '../native/message.js';
|
|
@@ -34,7 +35,7 @@ export interface MerkleTreeAdminDatabase extends ForkMerkleTreeOperations {
|
|
|
34
35
|
* @param block - The L2 block to handle.
|
|
35
36
|
* @param l1ToL2Messages - The L1 to L2 messages for the block.
|
|
36
37
|
*/
|
|
37
|
-
handleL2BlockAndMessages(block:
|
|
38
|
+
handleL2BlockAndMessages(block: L2BlockNew, l1ToL2Messages: Fr[]): Promise<WorldStateStatusFull>;
|
|
38
39
|
/**
|
|
39
40
|
* Gets a handle that allows reading the latest committed state
|
|
40
41
|
*/
|
|
@@ -44,19 +45,19 @@ export interface MerkleTreeAdminDatabase extends ForkMerkleTreeOperations {
|
|
|
44
45
|
* @param toBlockNumber The block number of the new oldest historical block
|
|
45
46
|
* @returns The new WorldStateStatus
|
|
46
47
|
*/
|
|
47
|
-
removeHistoricalBlocks(toBlockNumber:
|
|
48
|
+
removeHistoricalBlocks(toBlockNumber: BlockNumber): Promise<WorldStateStatusFull>;
|
|
48
49
|
/**
|
|
49
50
|
* Removes all pending blocks down to but not including the given block number
|
|
50
51
|
* @param toBlockNumber The block number of the new tip of the pending chain,
|
|
51
52
|
* @returns The new WorldStateStatus
|
|
52
53
|
*/
|
|
53
|
-
unwindBlocks(toBlockNumber:
|
|
54
|
+
unwindBlocks(toBlockNumber: BlockNumber): Promise<WorldStateStatusFull>;
|
|
54
55
|
/**
|
|
55
|
-
* Advances the
|
|
56
|
-
* @param toBlockNumber The block number that is now the tip of the
|
|
56
|
+
* Advances the finalized block number to be the number provided
|
|
57
|
+
* @param toBlockNumber The block number that is now the tip of the finalized chain
|
|
57
58
|
* @returns The new WorldStateStatus
|
|
58
59
|
*/
|
|
59
|
-
|
|
60
|
+
setFinalized(toBlockNumber: BlockNumber): Promise<WorldStateStatusSummary>;
|
|
60
61
|
/**
|
|
61
62
|
* Gets the current status summary of the database.
|
|
62
63
|
* @returns The current WorldStateStatus.
|
|
@@ -64,5 +65,7 @@ export interface MerkleTreeAdminDatabase extends ForkMerkleTreeOperations {
|
|
|
64
65
|
getStatusSummary(): Promise<WorldStateStatusSummary>;
|
|
65
66
|
/** Stops the database */
|
|
66
67
|
close(): Promise<void>;
|
|
68
|
+
/** Deletes the db. */
|
|
69
|
+
clear(): Promise<void>;
|
|
67
70
|
}
|
|
68
|
-
//# sourceMappingURL=
|
|
71
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWVya2xlX3RyZWVfZGIuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy93b3JsZC1zdGF0ZS1kYi9tZXJrbGVfdHJlZV9kYi50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFDQSxPQUFPLEtBQUssRUFBRSxXQUFXLEVBQUUsTUFBTSxpQ0FBaUMsQ0FBQztBQUNuRSxPQUFPLEtBQU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kFBd0IsQ0FBQyxLQUFLLEVBQUUsVUFBVSxFQUFFLGNBQWMsRUFBRSxFQUFFLEVBQUUsR0FBRyxPQUFPLENBQUMsb0JBQW9CLENBQUMsQ0FBQztJQUVqRzs7T0FFRztJQUNILFlBQVksSUFBSSx3QkFBd0IsQ0FBQztJQUV6Qzs7OztPQUlHO0lBQ0gsc0JBQXNCLENBQUMsYUFBYSxFQUFFLFdBQVcsR0FBRyxPQUFPLENBQUMsb0JBQW9CLENBQUMsQ0FBQztJQUVsRjs7OztPQUlHO0lBQ0gsWUFBWSxDQUFDLGFBQWEsRUFBRSxXQUFXLEdBQUcsT0FBTyxDQUFDLG9CQUFvQixDQUFDLENBQUM7SUFFeEU7Ozs7T0FJRztJQUNILFlBQVksQ0FBQyxhQUFhLEVBQUUsV0FBVyxHQUFHLE9BQU8sQ0FBQyx1QkFBdUIsQ0FBQyxDQUFDO0lBRTNFOzs7T0FHRztJQUNILGdCQUFnQixJQUFJLE9BQU8sQ0FBQyx1QkFBdUIsQ0FBQyxDQUFDO0lBRXJELHlCQUF5QjtJQUN6QixLQUFLLElBQUksT0FBTyxDQUFDLElBQUksQ0FBQyxDQUFDO0lBRXZCLHNCQUFzQjtJQUN0QixLQUFLLElBQUksT0FBTyxDQUFDLElBQUksQ0FBQyxDQUFDO0NBQ3hCIn0=
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"merkle_tree_db.d.ts","sourceRoot":"","sources":["../../src/world-state-db/merkle_tree_db.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"merkle_tree_db.d.ts","sourceRoot":"","sources":["../../src/world-state-db/merkle_tree_db.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AACzD,OAAO,KAAK,EAAE,mBAAmB,EAAE,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AO,CAAC,uBAAuB,CAAC,CAAC;IAE3E;;;OAGG;IACH,gBAAgB,IAAI,OAAO,CAAC,uBAAuB,CAAC,CAAC;IAErD,yBAAyB;IACzB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEvB,sBAAsB;IACtB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB"}
|
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.03f7ef2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dest/index.js",
|
|
@@ -18,11 +18,9 @@
|
|
|
18
18
|
"tsconfig": "./tsconfig.json"
|
|
19
19
|
},
|
|
20
20
|
"scripts": {
|
|
21
|
-
"build": "yarn clean && tsc
|
|
22
|
-
"build:dev": "tsc
|
|
21
|
+
"build": "yarn clean && ../scripts/tsc.sh",
|
|
22
|
+
"build:dev": "../scripts/tsc.sh --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,34 @@
|
|
|
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.03f7ef2",
|
|
68
|
+
"@aztec/foundation": "0.0.1-commit.03f7ef2",
|
|
69
|
+
"@aztec/kv-store": "0.0.1-commit.03f7ef2",
|
|
70
|
+
"@aztec/merkle-tree": "0.0.1-commit.03f7ef2",
|
|
71
|
+
"@aztec/native": "0.0.1-commit.03f7ef2",
|
|
72
|
+
"@aztec/protocol-contracts": "0.0.1-commit.03f7ef2",
|
|
73
|
+
"@aztec/stdlib": "0.0.1-commit.03f7ef2",
|
|
74
|
+
"@aztec/telemetry-client": "0.0.1-commit.03f7ef2",
|
|
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": "^
|
|
84
|
-
"jest-mock-extended": "^3.0.5",
|
|
85
|
-
"memdown": "^6.1.1",
|
|
79
|
+
"@aztec/archiver": "0.0.1-commit.03f7ef2",
|
|
80
|
+
"@jest/globals": "^30.0.0",
|
|
81
|
+
"@types/jest": "^30.0.0",
|
|
82
|
+
"@types/node": "^22.15.17",
|
|
83
|
+
"@typescript/native-preview": "7.0.0-dev.20251126.1",
|
|
84
|
+
"jest": "^30.0.0",
|
|
85
|
+
"jest-mock-extended": "^4.0.0",
|
|
86
86
|
"ts-node": "^10.9.1",
|
|
87
|
-
"typescript": "^5.
|
|
87
|
+
"typescript": "^5.3.3"
|
|
88
88
|
},
|
|
89
89
|
"files": [
|
|
90
90
|
"dest",
|
|
@@ -93,6 +93,6 @@
|
|
|
93
93
|
],
|
|
94
94
|
"types": "./dest/index.d.ts",
|
|
95
95
|
"engines": {
|
|
96
|
-
"node": ">=
|
|
96
|
+
"node": ">=20.10"
|
|
97
97
|
}
|
|
98
98
|
}
|
|
@@ -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
|
+
}
|
|
@@ -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');
|