@aztec/world-state 0.0.0-test.0
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/README.md +40 -0
- package/dest/index.d.ts +5 -0
- package/dest/index.d.ts.map +1 -0
- package/dest/index.js +4 -0
- package/dest/instrumentation/instrumentation.d.ts +22 -0
- package/dest/instrumentation/instrumentation.d.ts.map +1 -0
- package/dest/instrumentation/instrumentation.js +117 -0
- package/dest/native/fork_checkpoint.d.ts +10 -0
- package/dest/native/fork_checkpoint.d.ts.map +1 -0
- package/dest/native/fork_checkpoint.js +26 -0
- package/dest/native/index.d.ts +3 -0
- package/dest/native/index.d.ts.map +1 -0
- package/dest/native/index.js +2 -0
- package/dest/native/merkle_trees_facade.d.ts +42 -0
- package/dest/native/merkle_trees_facade.d.ts.map +1 -0
- package/dest/native/merkle_trees_facade.js +240 -0
- package/dest/native/message.d.ts +331 -0
- package/dest/native/message.d.ts.map +1 -0
- package/dest/native/message.js +192 -0
- package/dest/native/native_world_state.d.ts +57 -0
- package/dest/native/native_world_state.d.ts.map +1 -0
- package/dest/native/native_world_state.js +229 -0
- package/dest/native/native_world_state_instance.d.ts +33 -0
- package/dest/native/native_world_state_instance.d.ts.map +1 -0
- package/dest/native/native_world_state_instance.js +164 -0
- package/dest/native/world_state_ops_queue.d.ts +19 -0
- package/dest/native/world_state_ops_queue.d.ts.map +1 -0
- package/dest/native/world_state_ops_queue.js +146 -0
- package/dest/synchronizer/config.d.ts +23 -0
- package/dest/synchronizer/config.d.ts.map +1 -0
- package/dest/synchronizer/config.js +39 -0
- package/dest/synchronizer/factory.d.ts +12 -0
- package/dest/synchronizer/factory.d.ts.map +1 -0
- package/dest/synchronizer/factory.js +24 -0
- package/dest/synchronizer/index.d.ts +3 -0
- package/dest/synchronizer/index.d.ts.map +1 -0
- package/dest/synchronizer/index.js +2 -0
- package/dest/synchronizer/server_world_state_synchronizer.d.ts +79 -0
- package/dest/synchronizer/server_world_state_synchronizer.d.ts.map +1 -0
- package/dest/synchronizer/server_world_state_synchronizer.js +277 -0
- package/dest/test/index.d.ts +2 -0
- package/dest/test/index.d.ts.map +1 -0
- package/dest/test/index.js +1 -0
- package/dest/test/utils.d.ts +19 -0
- package/dest/test/utils.d.ts.map +1 -0
- package/dest/test/utils.js +99 -0
- package/dest/testing.d.ts +10 -0
- package/dest/testing.d.ts.map +1 -0
- package/dest/testing.js +37 -0
- package/dest/world-state-db/index.d.ts +3 -0
- package/dest/world-state-db/index.d.ts.map +1 -0
- package/dest/world-state-db/index.js +1 -0
- package/dest/world-state-db/merkle_tree_db.d.ts +68 -0
- package/dest/world-state-db/merkle_tree_db.d.ts.map +1 -0
- package/dest/world-state-db/merkle_tree_db.js +17 -0
- package/package.json +98 -0
- package/src/index.ts +4 -0
- package/src/instrumentation/instrumentation.ts +174 -0
- package/src/native/fork_checkpoint.ts +30 -0
- package/src/native/index.ts +2 -0
- package/src/native/merkle_trees_facade.ts +331 -0
- package/src/native/message.ts +541 -0
- package/src/native/native_world_state.ts +317 -0
- package/src/native/native_world_state_instance.ts +238 -0
- package/src/native/world_state_ops_queue.ts +190 -0
- package/src/synchronizer/config.ts +68 -0
- package/src/synchronizer/factory.ts +53 -0
- package/src/synchronizer/index.ts +2 -0
- package/src/synchronizer/server_world_state_synchronizer.ts +344 -0
- package/src/test/index.ts +1 -0
- package/src/test/utils.ts +153 -0
- package/src/testing.ts +60 -0
- package/src/world-state-db/index.ts +3 -0
- package/src/world-state-db/merkle_tree_db.ts +79 -0
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { Fr } from '@aztec/foundation/fields';
|
|
2
|
+
import type { IndexedTreeSnapshot, TreeSnapshot } from '@aztec/merkle-tree';
|
|
3
|
+
import type { L2Block } from '@aztec/stdlib/block';
|
|
4
|
+
import type { ForkMerkleTreeOperations, MerkleTreeReadOperations } from '@aztec/stdlib/interfaces/server';
|
|
5
|
+
import type { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
6
|
+
import type { WorldStateStatusFull, WorldStateStatusSummary } from '../native/message.js';
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
* @remarks Short explanation:
|
|
10
|
+
* The nullifier tree must be initially padded as the pre-populated 0 index prevents efficient subtree insertion.
|
|
11
|
+
* Padding with some values solves this issue.
|
|
12
|
+
*
|
|
13
|
+
* @remarks Thorough explanation:
|
|
14
|
+
* There needs to be an initial (0,0,0) leaf in the tree, so that when we insert the first 'proper' leaf, we can
|
|
15
|
+
* prove that any value greater than 0 doesn't exist in the tree yet. We prefill/pad the tree with "the number of
|
|
16
|
+
* leaves that are added by one block" so that the first 'proper' block can insert a full subtree.
|
|
17
|
+
*
|
|
18
|
+
* Without this padding, there would be a leaf (0,0,0) at leaf index 0, making it really difficult to insert e.g.
|
|
19
|
+
* 1024 leaves for the first block, because there's only neat space for 1023 leaves after 0. By padding with 1023
|
|
20
|
+
* more leaves, we can then insert the first block of 1024 leaves into indices 1024:2047.
|
|
21
|
+
*/
|
|
22
|
+
export declare const INITIAL_NULLIFIER_TREE_SIZE: number;
|
|
23
|
+
export declare const INITIAL_PUBLIC_DATA_TREE_SIZE: number;
|
|
24
|
+
export type TreeSnapshots = {
|
|
25
|
+
[MerkleTreeId.NULLIFIER_TREE]: IndexedTreeSnapshot;
|
|
26
|
+
[MerkleTreeId.NOTE_HASH_TREE]: TreeSnapshot<Fr>;
|
|
27
|
+
[MerkleTreeId.PUBLIC_DATA_TREE]: IndexedTreeSnapshot;
|
|
28
|
+
[MerkleTreeId.L1_TO_L2_MESSAGE_TREE]: TreeSnapshot<Fr>;
|
|
29
|
+
[MerkleTreeId.ARCHIVE]: TreeSnapshot<Fr>;
|
|
30
|
+
};
|
|
31
|
+
export interface MerkleTreeAdminDatabase extends ForkMerkleTreeOperations {
|
|
32
|
+
/**
|
|
33
|
+
* Handles a single L2 block (i.e. Inserts the new note hashes into the merkle tree).
|
|
34
|
+
* @param block - The L2 block to handle.
|
|
35
|
+
* @param l1ToL2Messages - The L1 to L2 messages for the block.
|
|
36
|
+
*/
|
|
37
|
+
handleL2BlockAndMessages(block: L2Block, l1ToL2Messages: Fr[]): Promise<WorldStateStatusFull>;
|
|
38
|
+
/**
|
|
39
|
+
* Gets a handle that allows reading the latest committed state
|
|
40
|
+
*/
|
|
41
|
+
getCommitted(): MerkleTreeReadOperations;
|
|
42
|
+
/**
|
|
43
|
+
* Removes all historical snapshots up to but not including the given block number
|
|
44
|
+
* @param toBlockNumber The block number of the new oldest historical block
|
|
45
|
+
* @returns The new WorldStateStatus
|
|
46
|
+
*/
|
|
47
|
+
removeHistoricalBlocks(toBlockNumber: bigint): Promise<WorldStateStatusFull>;
|
|
48
|
+
/**
|
|
49
|
+
* Removes all pending blocks down to but not including the given block number
|
|
50
|
+
* @param toBlockNumber The block number of the new tip of the pending chain,
|
|
51
|
+
* @returns The new WorldStateStatus
|
|
52
|
+
*/
|
|
53
|
+
unwindBlocks(toBlockNumber: bigint): Promise<WorldStateStatusFull>;
|
|
54
|
+
/**
|
|
55
|
+
* Advances the finalised block number to be the number provided
|
|
56
|
+
* @param toBlockNumber The block number that is now the tip of the finalised chain
|
|
57
|
+
* @returns The new WorldStateStatus
|
|
58
|
+
*/
|
|
59
|
+
setFinalised(toBlockNumber: bigint): Promise<WorldStateStatusSummary>;
|
|
60
|
+
/**
|
|
61
|
+
* Gets the current status summary of the database.
|
|
62
|
+
* @returns The current WorldStateStatus.
|
|
63
|
+
*/
|
|
64
|
+
getStatusSummary(): Promise<WorldStateStatusSummary>;
|
|
65
|
+
/** Stops the database */
|
|
66
|
+
close(): Promise<void>;
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=merkle_tree_db.d.ts.map
|
|
@@ -0,0 +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,0BAA0B,CAAC;AACnD,OAAO,KAAK,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC5E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,KAAK,EAAE,wBAAwB,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AAC1G,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAExD,OAAO,KAAK,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAE1F;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,2BAA2B,QAA4B,CAAC;AAErE,eAAO,MAAM,6BAA6B,QAAmD,CAAC;AAE9F,MAAM,MAAM,aAAa,GAAG;IAC1B,CAAC,YAAY,CAAC,cAAc,CAAC,EAAE,mBAAmB,CAAC;IACnD,CAAC,YAAY,CAAC,cAAc,CAAC,EAAE,YAAY,CAAC,EAAE,CAAC,CAAC;IAChD,CAAC,YAAY,CAAC,gBAAgB,CAAC,EAAE,mBAAmB,CAAC;IACrD,CAAC,YAAY,CAAC,qBAAqB,CAAC,EAAE,YAAY,CAAC,EAAE,CAAC,CAAC;IACvD,CAAC,YAAY,CAAC,OAAO,CAAC,EAAE,YAAY,CAAC,EAAE,CAAC,CAAC;CAC1C,CAAC;AAEF,MAAM,WAAW,uBAAwB,SAAQ,wBAAwB;IACvE;;;;OAIG;IACH,wBAAwB,CAAC,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;IAE9F;;OAEG;IACH,YAAY,IAAI,wBAAwB,CAAC;IAEzC;;;;OAIG;IACH,sBAAsB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;IAE7E;;;;OAIG;IACH,YAAY,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;IAEnE;;;;OAIG;IACH,YAAY,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAAC;IAEtE;;;OAGG;IACH,gBAAgB,IAAI,OAAO,CAAC,uBAAuB,CAAC,CAAC;IAErD,yBAAyB;IACzB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { MAX_NULLIFIERS_PER_TX, MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX } from '@aztec/constants';
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* @remarks Short explanation:
|
|
5
|
+
* The nullifier tree must be initially padded as the pre-populated 0 index prevents efficient subtree insertion.
|
|
6
|
+
* Padding with some values solves this issue.
|
|
7
|
+
*
|
|
8
|
+
* @remarks Thorough explanation:
|
|
9
|
+
* There needs to be an initial (0,0,0) leaf in the tree, so that when we insert the first 'proper' leaf, we can
|
|
10
|
+
* prove that any value greater than 0 doesn't exist in the tree yet. We prefill/pad the tree with "the number of
|
|
11
|
+
* leaves that are added by one block" so that the first 'proper' block can insert a full subtree.
|
|
12
|
+
*
|
|
13
|
+
* Without this padding, there would be a leaf (0,0,0) at leaf index 0, making it really difficult to insert e.g.
|
|
14
|
+
* 1024 leaves for the first block, because there's only neat space for 1023 leaves after 0. By padding with 1023
|
|
15
|
+
* more leaves, we can then insert the first block of 1024 leaves into indices 1024:2047.
|
|
16
|
+
*/ export const INITIAL_NULLIFIER_TREE_SIZE = 2 * MAX_NULLIFIERS_PER_TX;
|
|
17
|
+
export const INITIAL_PUBLIC_DATA_TREE_SIZE = 2 * MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX;
|
package/package.json
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@aztec/world-state",
|
|
3
|
+
"version": "0.0.0-test.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"exports": {
|
|
6
|
+
".": "./dest/index.js",
|
|
7
|
+
"./native": "./dest/native/index.js",
|
|
8
|
+
"./test": "./dest/test/index.js",
|
|
9
|
+
"./testing": "./dest/testing.js",
|
|
10
|
+
"./config": "./dest/synchronizer/config.js"
|
|
11
|
+
},
|
|
12
|
+
"typedocOptions": {
|
|
13
|
+
"entryPoints": [
|
|
14
|
+
"./src/index.ts",
|
|
15
|
+
"./src/testing.ts"
|
|
16
|
+
],
|
|
17
|
+
"name": "World State",
|
|
18
|
+
"tsconfig": "./tsconfig.json"
|
|
19
|
+
},
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "yarn clean && tsc -b",
|
|
22
|
+
"build:dev": "tsc -b --watch",
|
|
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
|
+
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
|
|
27
|
+
},
|
|
28
|
+
"inherits": [
|
|
29
|
+
"../package.common.json"
|
|
30
|
+
],
|
|
31
|
+
"jest": {
|
|
32
|
+
"moduleNameMapper": {
|
|
33
|
+
"^(\\.{1,2}/.*)\\.[cm]?js$": "$1"
|
|
34
|
+
},
|
|
35
|
+
"testRegex": "./src/.*\\.test\\.(js|mjs|ts)$",
|
|
36
|
+
"rootDir": "./src",
|
|
37
|
+
"transform": {
|
|
38
|
+
"^.+\\.tsx?$": [
|
|
39
|
+
"@swc/jest",
|
|
40
|
+
{
|
|
41
|
+
"jsc": {
|
|
42
|
+
"parser": {
|
|
43
|
+
"syntax": "typescript",
|
|
44
|
+
"decorators": true
|
|
45
|
+
},
|
|
46
|
+
"transform": {
|
|
47
|
+
"decoratorVersion": "2022-03"
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
]
|
|
52
|
+
},
|
|
53
|
+
"extensionsToTreatAsEsm": [
|
|
54
|
+
".ts"
|
|
55
|
+
],
|
|
56
|
+
"reporters": [
|
|
57
|
+
"default"
|
|
58
|
+
],
|
|
59
|
+
"testTimeout": 120000,
|
|
60
|
+
"setupFiles": [
|
|
61
|
+
"../../foundation/src/jest/setup.mjs"
|
|
62
|
+
]
|
|
63
|
+
},
|
|
64
|
+
"dependencies": {
|
|
65
|
+
"@aztec/constants": "0.0.0-test.0",
|
|
66
|
+
"@aztec/foundation": "0.0.0-test.0",
|
|
67
|
+
"@aztec/kv-store": "0.0.0-test.0",
|
|
68
|
+
"@aztec/merkle-tree": "0.0.0-test.0",
|
|
69
|
+
"@aztec/native": "0.0.0-test.0",
|
|
70
|
+
"@aztec/protocol-contracts": "0.0.0-test.0",
|
|
71
|
+
"@aztec/stdlib": "0.0.0-test.0",
|
|
72
|
+
"@aztec/telemetry-client": "0.0.0-test.0",
|
|
73
|
+
"tslib": "^2.4.0",
|
|
74
|
+
"zod": "^3.23.8"
|
|
75
|
+
},
|
|
76
|
+
"devDependencies": {
|
|
77
|
+
"@aztec/archiver": "0.0.0-test.0",
|
|
78
|
+
"@jest/globals": "^29.5.0",
|
|
79
|
+
"@types/jest": "^29.5.0",
|
|
80
|
+
"@types/levelup": "^5.1.2",
|
|
81
|
+
"@types/memdown": "^3.0.0",
|
|
82
|
+
"@types/node": "^18.7.23",
|
|
83
|
+
"jest": "^29.5.0",
|
|
84
|
+
"jest-mock-extended": "^3.0.5",
|
|
85
|
+
"memdown": "^6.1.1",
|
|
86
|
+
"ts-node": "^10.9.1",
|
|
87
|
+
"typescript": "^5.0.4"
|
|
88
|
+
},
|
|
89
|
+
"files": [
|
|
90
|
+
"dest",
|
|
91
|
+
"src",
|
|
92
|
+
"!*.test.*"
|
|
93
|
+
],
|
|
94
|
+
"types": "./dest/index.d.ts",
|
|
95
|
+
"engines": {
|
|
96
|
+
"node": ">=18"
|
|
97
|
+
}
|
|
98
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
2
|
+
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
3
|
+
import {
|
|
4
|
+
Attributes,
|
|
5
|
+
type Gauge,
|
|
6
|
+
type Histogram,
|
|
7
|
+
Metrics,
|
|
8
|
+
type TelemetryClient,
|
|
9
|
+
type UpDownCounter,
|
|
10
|
+
ValueType,
|
|
11
|
+
} from '@aztec/telemetry-client';
|
|
12
|
+
|
|
13
|
+
import {
|
|
14
|
+
type DBStats,
|
|
15
|
+
type TreeDBStats,
|
|
16
|
+
type TreeMeta,
|
|
17
|
+
WorldStateMessageType,
|
|
18
|
+
type WorldStateStatusFull,
|
|
19
|
+
} from '../native/message.js';
|
|
20
|
+
|
|
21
|
+
type DBTypeString = 'leaf_preimage' | 'leaf_indices' | 'nodes' | 'blocks' | 'block_indices';
|
|
22
|
+
|
|
23
|
+
const durationTrackDenylist = new Set<WorldStateMessageType>([
|
|
24
|
+
WorldStateMessageType.GET_INITIAL_STATE_REFERENCE,
|
|
25
|
+
WorldStateMessageType.CLOSE,
|
|
26
|
+
|
|
27
|
+
// these aren't used anymore, should be removed from the API
|
|
28
|
+
WorldStateMessageType.COMMIT,
|
|
29
|
+
WorldStateMessageType.ROLLBACK,
|
|
30
|
+
]);
|
|
31
|
+
|
|
32
|
+
export class WorldStateInstrumentation {
|
|
33
|
+
private dbMapSize: Gauge;
|
|
34
|
+
private treeSize: Gauge;
|
|
35
|
+
private unfinalisedHeight: Gauge;
|
|
36
|
+
private finalisedHeight: Gauge;
|
|
37
|
+
private oldestBlock: Gauge;
|
|
38
|
+
private dbNumItems: Gauge;
|
|
39
|
+
private dbUsedSize: Gauge;
|
|
40
|
+
private requestHistogram: Histogram;
|
|
41
|
+
private criticalErrors: UpDownCounter;
|
|
42
|
+
|
|
43
|
+
constructor(public readonly telemetry: TelemetryClient, private log = createLogger('world-state:instrumentation')) {
|
|
44
|
+
const meter = telemetry.getMeter('World State');
|
|
45
|
+
this.dbMapSize = meter.createGauge(Metrics.WORLD_STATE_DB_MAP_SIZE, {
|
|
46
|
+
description: `The current configured map size for each merkle tree`,
|
|
47
|
+
valueType: ValueType.INT,
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
this.treeSize = meter.createGauge(Metrics.WORLD_STATE_TREE_SIZE, {
|
|
51
|
+
description: `The current number of leaves in each merkle tree`,
|
|
52
|
+
valueType: ValueType.INT,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
this.unfinalisedHeight = meter.createGauge(Metrics.WORLD_STATE_UNFINALISED_HEIGHT, {
|
|
56
|
+
description: `The unfinalised block height of each merkle tree`,
|
|
57
|
+
valueType: ValueType.INT,
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
this.finalisedHeight = meter.createGauge(Metrics.WORLD_STATE_FINALISED_HEIGHT, {
|
|
61
|
+
description: `The finalised block height of each merkle tree`,
|
|
62
|
+
valueType: ValueType.INT,
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
this.oldestBlock = meter.createGauge(Metrics.WORLD_STATE_OLDEST_BLOCK, {
|
|
66
|
+
description: `The oldest historical block of each merkle tree`,
|
|
67
|
+
valueType: ValueType.INT,
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
this.dbUsedSize = meter.createGauge(Metrics.WORLD_STATE_DB_USED_SIZE, {
|
|
71
|
+
description: `The current used database size for each db of each merkle tree`,
|
|
72
|
+
valueType: ValueType.INT,
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
this.dbNumItems = meter.createGauge(Metrics.WORLD_STATE_DB_NUM_ITEMS, {
|
|
76
|
+
description: `The current number of items in each database of each merkle tree`,
|
|
77
|
+
valueType: ValueType.INT,
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
this.requestHistogram = meter.createHistogram(Metrics.WORLD_STATE_REQUEST_TIME, {
|
|
81
|
+
description: 'The round trip time of world state requests',
|
|
82
|
+
unit: 'us',
|
|
83
|
+
valueType: ValueType.INT,
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
this.criticalErrors = meter.createUpDownCounter(Metrics.WORLD_STATE_CRITICAL_ERROR_COUNT, {
|
|
87
|
+
description: 'The number of critical errors in the world state',
|
|
88
|
+
valueType: ValueType.INT,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
private updateTreeStats(treeDbStats: TreeDBStats, treeMeta: TreeMeta, tree: MerkleTreeId) {
|
|
93
|
+
this.dbMapSize.record(Number(treeDbStats.mapSize), {
|
|
94
|
+
[Attributes.MERKLE_TREE_NAME]: MerkleTreeId[tree],
|
|
95
|
+
});
|
|
96
|
+
this.treeSize.record(Number(treeMeta.size), {
|
|
97
|
+
[Attributes.MERKLE_TREE_NAME]: MerkleTreeId[tree],
|
|
98
|
+
});
|
|
99
|
+
this.unfinalisedHeight.record(Number(treeMeta.unfinalisedBlockHeight), {
|
|
100
|
+
[Attributes.MERKLE_TREE_NAME]: MerkleTreeId[tree],
|
|
101
|
+
});
|
|
102
|
+
this.finalisedHeight.record(Number(treeMeta.finalisedBlockHeight), {
|
|
103
|
+
[Attributes.MERKLE_TREE_NAME]: MerkleTreeId[tree],
|
|
104
|
+
});
|
|
105
|
+
this.oldestBlock.record(Number(treeMeta.oldestHistoricBlock), {
|
|
106
|
+
[Attributes.MERKLE_TREE_NAME]: MerkleTreeId[tree],
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
this.updateTreeDBStats(treeDbStats.blockIndicesDBStats, 'block_indices', tree);
|
|
110
|
+
this.updateTreeDBStats(treeDbStats.blocksDBStats, 'blocks', tree);
|
|
111
|
+
this.updateTreeDBStats(treeDbStats.leafIndicesDBStats, 'leaf_indices', tree);
|
|
112
|
+
this.updateTreeDBStats(treeDbStats.leafPreimagesDBStats, 'leaf_preimage', tree);
|
|
113
|
+
this.updateTreeDBStats(treeDbStats.nodesDBStats, 'nodes', tree);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
private updateTreeDBStats(dbStats: DBStats, dbType: DBTypeString, tree: MerkleTreeId) {
|
|
117
|
+
this.dbNumItems.record(Number(dbStats.numDataItems), {
|
|
118
|
+
[Attributes.WS_DB_DATA_TYPE]: dbType,
|
|
119
|
+
[Attributes.MERKLE_TREE_NAME]: MerkleTreeId[tree],
|
|
120
|
+
});
|
|
121
|
+
this.dbUsedSize.record(Number(dbStats.totalUsedSize), {
|
|
122
|
+
[Attributes.WS_DB_DATA_TYPE]: dbType,
|
|
123
|
+
[Attributes.MERKLE_TREE_NAME]: MerkleTreeId[tree],
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
public updateWorldStateMetrics(worldStateStatus: WorldStateStatusFull) {
|
|
128
|
+
this.updateTreeStats(
|
|
129
|
+
worldStateStatus.dbStats.archiveTreeStats,
|
|
130
|
+
worldStateStatus.meta.archiveTreeMeta,
|
|
131
|
+
MerkleTreeId.ARCHIVE,
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
this.updateTreeStats(
|
|
135
|
+
worldStateStatus.dbStats.messageTreeStats,
|
|
136
|
+
worldStateStatus.meta.messageTreeMeta,
|
|
137
|
+
MerkleTreeId.L1_TO_L2_MESSAGE_TREE,
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
this.updateTreeStats(
|
|
141
|
+
worldStateStatus.dbStats.noteHashTreeStats,
|
|
142
|
+
worldStateStatus.meta.noteHashTreeMeta,
|
|
143
|
+
MerkleTreeId.NOTE_HASH_TREE,
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
this.updateTreeStats(
|
|
147
|
+
worldStateStatus.dbStats.nullifierTreeStats,
|
|
148
|
+
worldStateStatus.meta.nullifierTreeMeta,
|
|
149
|
+
MerkleTreeId.NULLIFIER_TREE,
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
this.updateTreeStats(
|
|
153
|
+
worldStateStatus.dbStats.publicDataTreeStats,
|
|
154
|
+
worldStateStatus.meta.publicDataTreeMeta,
|
|
155
|
+
MerkleTreeId.PUBLIC_DATA_TREE,
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
public recordRoundTrip(timeUs: number, request: WorldStateMessageType) {
|
|
160
|
+
if (!durationTrackDenylist.has(request)) {
|
|
161
|
+
this.requestHistogram.record(Math.ceil(timeUs), {
|
|
162
|
+
[Attributes.WORLD_STATE_REQUEST_TYPE]: WorldStateMessageType[request],
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
public incCriticalErrors(
|
|
168
|
+
errorType: 'synch_pending_block' | 'finalize_block' | 'prune_pending_block' | 'prune_historical_block',
|
|
169
|
+
) {
|
|
170
|
+
this.criticalErrors.add(1, {
|
|
171
|
+
[Attributes.ERROR_TYPE]: errorType,
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { MerkleTreeCheckpointOperations } from '@aztec/stdlib/interfaces/server';
|
|
2
|
+
|
|
3
|
+
export class ForkCheckpoint {
|
|
4
|
+
private completed = false;
|
|
5
|
+
|
|
6
|
+
private constructor(private readonly fork: MerkleTreeCheckpointOperations) {}
|
|
7
|
+
|
|
8
|
+
static async new(fork: MerkleTreeCheckpointOperations): Promise<ForkCheckpoint> {
|
|
9
|
+
await fork.createCheckpoint();
|
|
10
|
+
return new ForkCheckpoint(fork);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async commit(): Promise<void> {
|
|
14
|
+
if (this.completed) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
await this.fork.commitCheckpoint();
|
|
19
|
+
this.completed = true;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async revert(): Promise<void> {
|
|
23
|
+
if (this.completed) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
await this.fork.revertCheckpoint();
|
|
28
|
+
this.completed = true;
|
|
29
|
+
}
|
|
30
|
+
}
|