@aztec/world-state 0.0.0-test.1 → 0.0.1-commit.017a351

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.
Files changed (69) hide show
  1. package/dest/index.d.ts +1 -1
  2. package/dest/instrumentation/instrumentation.d.ts +6 -4
  3. package/dest/instrumentation/instrumentation.d.ts.map +1 -1
  4. package/dest/instrumentation/instrumentation.js +25 -41
  5. package/dest/native/bench_metrics.d.ts +23 -0
  6. package/dest/native/bench_metrics.d.ts.map +1 -0
  7. package/dest/native/bench_metrics.js +81 -0
  8. package/dest/native/fork_checkpoint.d.ts +7 -1
  9. package/dest/native/fork_checkpoint.d.ts.map +1 -1
  10. package/dest/native/fork_checkpoint.js +15 -3
  11. package/dest/native/index.d.ts +1 -1
  12. package/dest/native/ipc_world_state_instance.d.ts +45 -0
  13. package/dest/native/ipc_world_state_instance.d.ts.map +1 -0
  14. package/dest/native/ipc_world_state_instance.js +750 -0
  15. package/dest/native/merkle_trees_facade.d.ts +25 -9
  16. package/dest/native/merkle_trees_facade.d.ts.map +1 -1
  17. package/dest/native/merkle_trees_facade.js +109 -25
  18. package/dest/native/message.d.ts +87 -58
  19. package/dest/native/message.d.ts.map +1 -1
  20. package/dest/native/message.js +61 -61
  21. package/dest/native/native_world_state.d.ts +41 -21
  22. package/dest/native/native_world_state.d.ts.map +1 -1
  23. package/dest/native/native_world_state.js +177 -50
  24. package/dest/native/native_world_state_instance.d.ts +23 -25
  25. package/dest/native/native_world_state_instance.d.ts.map +1 -1
  26. package/dest/native/native_world_state_instance.js +8 -163
  27. package/dest/native/world_state_ops_queue.d.ts +1 -1
  28. package/dest/native/world_state_ops_queue.d.ts.map +1 -1
  29. package/dest/native/world_state_ops_queue.js +6 -6
  30. package/dest/synchronizer/config.d.ts +14 -6
  31. package/dest/synchronizer/config.d.ts.map +1 -1
  32. package/dest/synchronizer/config.js +36 -14
  33. package/dest/synchronizer/errors.d.ts +4 -0
  34. package/dest/synchronizer/errors.d.ts.map +1 -0
  35. package/dest/synchronizer/errors.js +5 -0
  36. package/dest/synchronizer/factory.d.ts +13 -5
  37. package/dest/synchronizer/factory.d.ts.map +1 -1
  38. package/dest/synchronizer/factory.js +15 -9
  39. package/dest/synchronizer/index.d.ts +1 -1
  40. package/dest/synchronizer/server_world_state_synchronizer.d.ts +21 -31
  41. package/dest/synchronizer/server_world_state_synchronizer.d.ts.map +1 -1
  42. package/dest/synchronizer/server_world_state_synchronizer.js +220 -96
  43. package/dest/test/index.d.ts +1 -1
  44. package/dest/test/utils.d.ts +12 -5
  45. package/dest/test/utils.d.ts.map +1 -1
  46. package/dest/test/utils.js +54 -47
  47. package/dest/testing.d.ts +6 -5
  48. package/dest/testing.d.ts.map +1 -1
  49. package/dest/testing.js +15 -15
  50. package/dest/world-state-db/index.d.ts +1 -1
  51. package/dest/world-state-db/merkle_tree_db.d.ts +12 -18
  52. package/dest/world-state-db/merkle_tree_db.d.ts.map +1 -1
  53. package/package.json +27 -25
  54. package/src/instrumentation/instrumentation.ts +31 -43
  55. package/src/native/bench_metrics.ts +91 -0
  56. package/src/native/fork_checkpoint.ts +19 -3
  57. package/src/native/ipc_world_state_instance.ts +863 -0
  58. package/src/native/merkle_trees_facade.ts +127 -33
  59. package/src/native/message.ts +109 -80
  60. package/src/native/native_world_state.ts +207 -64
  61. package/src/native/native_world_state_instance.ts +28 -223
  62. package/src/native/world_state_ops_queue.ts +6 -6
  63. package/src/synchronizer/config.ts +58 -20
  64. package/src/synchronizer/errors.ts +5 -0
  65. package/src/synchronizer/factory.ts +48 -18
  66. package/src/synchronizer/server_world_state_synchronizer.ts +249 -121
  67. package/src/test/utils.ts +92 -82
  68. package/src/testing.ts +11 -16
  69. package/src/world-state-db/merkle_tree_db.ts +16 -18
package/dest/testing.d.ts CHANGED
@@ -1,10 +1,11 @@
1
- import { Fr } from '@aztec/foundation/fields';
1
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
2
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
3
3
  import { PublicDataTreeLeaf } from '@aztec/stdlib/trees';
4
+ import type { GenesisData } from '@aztec/stdlib/world-state';
4
5
  export declare const defaultInitialAccountFeeJuice: Fr;
5
- export declare function getGenesisValues(initialAccounts: AztecAddress[], initialAccountFeeJuice?: Fr, genesisPublicData?: PublicDataTreeLeaf[]): Promise<{
6
+ export declare function getGenesisValues(initialAccounts: AztecAddress[], initialAccountFeeJuice?: Fr, genesisPublicData?: PublicDataTreeLeaf[], genesisTimestamp?: bigint): Promise<{
6
7
  genesisArchiveRoot: Fr;
7
- genesisBlockHash: Fr;
8
- prefilledPublicData: PublicDataTreeLeaf[];
8
+ genesis: GenesisData;
9
+ fundingNeeded: bigint;
9
10
  }>;
10
- //# sourceMappingURL=testing.d.ts.map
11
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdGluZy5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL3Rlc3RpbmcudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQ0EsT0FBTyxFQUFFLEVBQUUsRUFBRSxNQUFNLGdDQUFnQyxDQUFDO0FBRXBELE9BQU8sS0FBSyxFQUFFLFlBQVksRUFBRSxNQUFNLDZCQUE2QixDQUFDO0FBQ2hFLE9BQU8sRUFBZ0Isa0JBQWtCLEVBQUUsTUFBTSxxQkFBcUIsQ0FBQztBQUN2RSxPQUFPLEtBQUssRUFBRSxXQUFXLEVBQUUsTUFBTSwyQkFBMkIsQ0FBQztBQXFCN0QsZUFBTyxNQUFNLDZCQUE2QixJQUFxQixDQUFDO0FBRWhFLHdCQUFzQixnQkFBZ0IsQ0FDcEMsZUFBZSxFQUFFLFlBQVksRUFBRSxFQUMvQixzQkFBc0IsS0FBZ0MsRUFDdEQsaUJBQWlCLEdBQUUsa0JBQWtCLEVBQU8sRUFDNUMsZ0JBQWdCLEdBQUUsTUFBVzs7OztHQXNCOUIifQ==
@@ -1 +1 @@
1
- {"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAE9C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAgB,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AA6BvE,eAAO,MAAM,6BAA6B,IAAqB,CAAC;AAEhE,wBAAsB,gBAAgB,CACpC,eAAe,EAAE,YAAY,EAAE,EAC/B,sBAAsB,KAAgC,EACtD,iBAAiB,GAAE,kBAAkB,EAAO;;;;GAqB7C"}
1
+ {"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AAEpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAgB,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACvE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAqB7D,eAAO,MAAM,6BAA6B,IAAqB,CAAC;AAEhE,wBAAsB,gBAAgB,CACpC,eAAe,EAAE,YAAY,EAAE,EAC/B,sBAAsB,KAAgC,EACtD,iBAAiB,GAAE,kBAAkB,EAAO,EAC5C,gBAAgB,GAAE,MAAW;;;;GAsB9B"}
package/dest/testing.js CHANGED
@@ -1,37 +1,37 @@
1
- import { GENESIS_ARCHIVE_ROOT, GENESIS_BLOCK_HASH } from '@aztec/constants';
2
- import { Fr } from '@aztec/foundation/fields';
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
- async function generateGenesisValues(prefilledPublicData) {
7
- if (!prefilledPublicData.length) {
6
+ async function generateGenesisValues(genesis) {
7
+ if (!genesis.prefilledPublicData.length && genesis.genesisTimestamp === 0n) {
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
- const ws = await NativeWorldStateService.tmp(undefined /* rollupAddress */ , true, prefilledPublicData);
15
- const initialHeader = ws.getInitialHeader();
16
- const genesisBlockHash = await initialHeader.hash();
13
+ const ws = await NativeWorldStateService.tmp(/*cleanupTmpDir=*/ true, genesis);
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);
25
- export async function getGenesisValues(initialAccounts, initialAccountFeeJuice = defaultInitialAccountFeeJuice, genesisPublicData = []) {
21
+ export async function getGenesisValues(initialAccounts, initialAccountFeeJuice = defaultInitialAccountFeeJuice, genesisPublicData = [], genesisTimestamp = 0n) {
26
22
  // Top up the accounts with fee juice.
27
23
  let prefilledPublicData = await Promise.all(initialAccounts.map(async (address)=>new PublicDataTreeLeaf(await computeFeePayerBalanceLeafSlot(address), 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 { genesisBlockHash, genesisArchiveRoot } = await generateGenesisValues(prefilledPublicData);
27
+ const genesis = {
28
+ prefilledPublicData,
29
+ genesisTimestamp
30
+ };
31
+ const { genesisArchiveRoot } = await generateGenesisValues(genesis);
32
32
  return {
33
33
  genesisArchiveRoot,
34
- genesisBlockHash,
35
- prefilledPublicData
34
+ genesis,
35
+ fundingNeeded: BigInt(initialAccounts.length) * initialAccountFeeJuice.toBigInt()
36
36
  };
37
37
  }
@@ -1,3 +1,3 @@
1
1
  export * from './merkle_tree_db.js';
2
2
  export type { MerkleTreeReadOperations } from '@aztec/stdlib/interfaces/server';
3
- //# sourceMappingURL=index.d.ts.map
3
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy93b3JsZC1zdGF0ZS1kYi9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxjQUFjLHFCQUFxQixDQUFDO0FBRXBDLFlBQVksRUFBRSx3QkFBd0IsRUFBRSxNQUFNLGlDQUFpQyxDQUFDIn0=
@@ -1,8 +1,7 @@
1
- import type { Fr } from '@aztec/foundation/fields';
2
- import type { IndexedTreeSnapshot, TreeSnapshot } from '@aztec/merkle-tree';
1
+ import type { BlockNumber } from '@aztec/foundation/branded-types';
2
+ import type { Fr } from '@aztec/foundation/curves/bn254';
3
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';
4
+ import type { ForkMerkleTreeOperations, MerkleTreeReadOperations, ReadonlyWorldStateAccess } from '@aztec/stdlib/interfaces/server';
6
5
  import type { WorldStateStatusFull, WorldStateStatusSummary } from '../native/message.js';
7
6
  /**
8
7
  *
@@ -21,14 +20,7 @@ import type { WorldStateStatusFull, WorldStateStatusSummary } from '../native/me
21
20
  */
22
21
  export declare const INITIAL_NULLIFIER_TREE_SIZE: number;
23
22
  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 {
23
+ export interface MerkleTreeAdminDatabase extends ForkMerkleTreeOperations, ReadonlyWorldStateAccess {
32
24
  /**
33
25
  * Handles a single L2 block (i.e. Inserts the new note hashes into the merkle tree).
34
26
  * @param block - The L2 block to handle.
@@ -44,19 +36,19 @@ export interface MerkleTreeAdminDatabase extends ForkMerkleTreeOperations {
44
36
  * @param toBlockNumber The block number of the new oldest historical block
45
37
  * @returns The new WorldStateStatus
46
38
  */
47
- removeHistoricalBlocks(toBlockNumber: bigint): Promise<WorldStateStatusFull>;
39
+ removeHistoricalBlocks(toBlockNumber: BlockNumber): Promise<WorldStateStatusFull>;
48
40
  /**
49
41
  * Removes all pending blocks down to but not including the given block number
50
42
  * @param toBlockNumber The block number of the new tip of the pending chain,
51
43
  * @returns The new WorldStateStatus
52
44
  */
53
- unwindBlocks(toBlockNumber: bigint): Promise<WorldStateStatusFull>;
45
+ unwindBlocks(toBlockNumber: BlockNumber): Promise<WorldStateStatusFull>;
54
46
  /**
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
47
+ * Advances the finalized block number to be the number provided
48
+ * @param toBlockNumber The block number that is now the tip of the finalized chain
57
49
  * @returns The new WorldStateStatus
58
50
  */
59
- setFinalised(toBlockNumber: bigint): Promise<WorldStateStatusSummary>;
51
+ setFinalized(toBlockNumber: BlockNumber): Promise<WorldStateStatusSummary>;
60
52
  /**
61
53
  * Gets the current status summary of the database.
62
54
  * @returns The current WorldStateStatus.
@@ -64,5 +56,7 @@ export interface MerkleTreeAdminDatabase extends ForkMerkleTreeOperations {
64
56
  getStatusSummary(): Promise<WorldStateStatusSummary>;
65
57
  /** Stops the database */
66
58
  close(): Promise<void>;
59
+ /** Deletes the db. */
60
+ clear(): Promise<void>;
67
61
  }
68
- //# sourceMappingURL=merkle_tree_db.d.ts.map
62
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWVya2xlX3RyZWVfZGIuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy93b3JsZC1zdGF0ZS1kYi9tZXJrbGVfdHJlZV9kYi50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFDQSxPQUFPLEtBQUssRUFBRSxXQUFXLEVBQUUsTUFBTSxpQ0FBaUMsQ0FBQztBQUNuRSxPQUFPLEtBQUssRUFBRSxFQUFFLEVBQUUsTUFBTSxnQ0FBZ0MsQ0FBQztBQUN6RCxPQUFPLEtBQUssRUFBRSxPQUFPLEVBQUUsTUFBTSxxQkFBcUIsQ0FBQztBQUNuRCxPQUFPLEtBQUssRUFDVix3QkFBd0IsRUFDeEIsd0JBQXdCLEVBQ3hCLHdCQUF3QixFQUN6QixNQUFNLGlDQUFpQyxDQUFDO0FBRXpDLE9BQU8sS0FBSyxFQUFFLG9CQUFvQixFQUFFLHVCQUF1QixFQUFFLE1BQU0sc0JBQXNCLENBQUM7QUFFMUY7Ozs7Ozs7Ozs7Ozs7O0dBY0c7QUFDSCxlQUFPLE1BQU0sMkJBQTJCLFFBQTRCLENBQUM7QUFFckUsZUFBTyxNQUFNLDZCQUE2QixRQUFtRCxDQUFDO0FBRTlGLE1BQU0sV0FBVyx1QkFBd0IsU0FBUSx3QkFBd0IsRUFBRSx3QkFBd0I7SUFDakc7Ozs7T0FJRztJQUNILHdCQUF3QixDQUFDLEtBQUssRUFBRSxPQUFPLEVBQUUsY0FBYyxFQUFFLEVBQ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
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 -b",
22
- "build:dev": "tsc -b --watch",
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,36 @@
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.0-test.1",
66
- "@aztec/foundation": "0.0.0-test.1",
67
- "@aztec/kv-store": "0.0.0-test.1",
68
- "@aztec/merkle-tree": "0.0.0-test.1",
69
- "@aztec/native": "0.0.0-test.1",
70
- "@aztec/protocol-contracts": "0.0.0-test.1",
71
- "@aztec/stdlib": "0.0.0-test.1",
72
- "@aztec/telemetry-client": "0.0.0-test.1",
67
+ "@aztec/bb.js": "0.0.1-commit.017a351",
68
+ "@aztec/constants": "0.0.1-commit.017a351",
69
+ "@aztec/foundation": "0.0.1-commit.017a351",
70
+ "@aztec/kv-store": "0.0.1-commit.017a351",
71
+ "@aztec/native": "0.0.1-commit.017a351",
72
+ "@aztec/protocol-contracts": "0.0.1-commit.017a351",
73
+ "@aztec/stdlib": "0.0.1-commit.017a351",
74
+ "@aztec/telemetry-client": "0.0.1-commit.017a351",
75
+ "@aztec/wsdb": "0.0.1-commit.017a351",
76
+ "msgpackr": "^1.11.2",
73
77
  "tslib": "^2.4.0",
74
- "zod": "^3.23.8"
78
+ "zod": "^4"
75
79
  },
76
80
  "devDependencies": {
77
- "@aztec/archiver": "0.0.0-test.1",
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",
81
+ "@aztec/archiver": "0.0.1-commit.017a351",
82
+ "@jest/globals": "^30.0.0",
83
+ "@types/jest": "^30.0.0",
84
+ "@types/node": "^22.15.17",
85
+ "@typescript/native-preview": "7.0.0-dev.20260113.1",
86
+ "jest": "^30.0.0",
87
+ "jest-mock-extended": "^4.0.0",
86
88
  "ts-node": "^10.9.1",
87
- "typescript": "^5.0.4"
89
+ "typescript": "^5.3.3"
88
90
  },
89
91
  "files": [
90
92
  "dest",
@@ -93,6 +95,6 @@
93
95
  ],
94
96
  "types": "./dest/index.d.ts",
95
97
  "engines": {
96
- "node": ">=18"
98
+ "node": ">=20.10"
97
99
  }
98
100
  }
@@ -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,
@@ -7,7 +7,7 @@ import {
7
7
  Metrics,
8
8
  type TelemetryClient,
9
9
  type UpDownCounter,
10
- ValueType,
10
+ createUpDownCounterWithDefault,
11
11
  } from '@aztec/telemetry-client';
12
12
 
13
13
  import {
@@ -31,61 +31,46 @@ 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 unfinalisedHeight: Gauge;
36
- private finalisedHeight: Gauge;
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(public readonly telemetry: TelemetryClient, private log = createLogger('world-state:instrumentation')) {
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
- 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
+ this.dbMapSize = meter.createGauge(Metrics.WORLD_STATE_DB_MAP_SIZE);
49
50
 
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
- });
51
+ this.dbPhysicalSize = meter.createGauge(Metrics.WORLD_STATE_DB_PHYSICAL_SIZE);
54
52
 
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
- });
53
+ this.treeSize = meter.createGauge(Metrics.WORLD_STATE_TREE_SIZE);
59
54
 
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
- });
55
+ this.unfinalizedHeight = meter.createGauge(Metrics.WORLD_STATE_UNFINALIZED_HEIGHT);
64
56
 
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
- });
57
+ this.finalizedHeight = meter.createGauge(Metrics.WORLD_STATE_FINALIZED_HEIGHT);
69
58
 
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
- });
59
+ this.oldestBlock = meter.createGauge(Metrics.WORLD_STATE_OLDEST_BLOCK);
74
60
 
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
- });
61
+ this.dbUsedSize = meter.createGauge(Metrics.WORLD_STATE_DB_USED_SIZE);
79
62
 
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
- });
63
+ this.dbNumItems = meter.createGauge(Metrics.WORLD_STATE_DB_NUM_ITEMS);
85
64
 
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,
65
+ this.requestHistogram = meter.createHistogram(Metrics.WORLD_STATE_REQUEST_TIME);
66
+
67
+ this.criticalErrors = createUpDownCounterWithDefault(meter, Metrics.WORLD_STATE_CRITICAL_ERROR_COUNT, {
68
+ [Attributes.ERROR_TYPE]: [
69
+ 'synch_pending_block',
70
+ 'finalize_block',
71
+ 'prune_pending_block',
72
+ 'prune_historical_block',
73
+ ],
89
74
  });
90
75
  }
91
76
 
@@ -93,13 +78,16 @@ export class WorldStateInstrumentation {
93
78
  this.dbMapSize.record(Number(treeDbStats.mapSize), {
94
79
  [Attributes.MERKLE_TREE_NAME]: MerkleTreeId[tree],
95
80
  });
81
+ this.dbPhysicalSize.record(Number(treeDbStats.physicalFileSize), {
82
+ [Attributes.MERKLE_TREE_NAME]: MerkleTreeId[tree],
83
+ });
96
84
  this.treeSize.record(Number(treeMeta.size), {
97
85
  [Attributes.MERKLE_TREE_NAME]: MerkleTreeId[tree],
98
86
  });
99
- this.unfinalisedHeight.record(Number(treeMeta.unfinalisedBlockHeight), {
87
+ this.unfinalizedHeight.record(Number(treeMeta.unfinalizedBlockHeight), {
100
88
  [Attributes.MERKLE_TREE_NAME]: MerkleTreeId[tree],
101
89
  });
102
- this.finalisedHeight.record(Number(treeMeta.finalisedBlockHeight), {
90
+ this.finalizedHeight.record(Number(treeMeta.finalizedBlockHeight), {
103
91
  [Attributes.MERKLE_TREE_NAME]: MerkleTreeId[tree],
104
92
  });
105
93
  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
+ }
@@ -3,11 +3,14 @@ import type { MerkleTreeCheckpointOperations } from '@aztec/stdlib/interfaces/se
3
3
  export class ForkCheckpoint {
4
4
  private completed = false;
5
5
 
6
- private constructor(private readonly fork: MerkleTreeCheckpointOperations) {}
6
+ private constructor(
7
+ private readonly fork: MerkleTreeCheckpointOperations,
8
+ public readonly depth: number,
9
+ ) {}
7
10
 
8
11
  static async new(fork: MerkleTreeCheckpointOperations): Promise<ForkCheckpoint> {
9
- await fork.createCheckpoint();
10
- return new ForkCheckpoint(fork);
12
+ const depth = await fork.createCheckpoint();
13
+ return new ForkCheckpoint(fork, depth);
11
14
  }
12
15
 
13
16
  async commit(): Promise<void> {
@@ -27,4 +30,17 @@ export class ForkCheckpoint {
27
30
  await this.fork.revertCheckpoint();
28
31
  this.completed = true;
29
32
  }
33
+
34
+ /**
35
+ * Reverts this checkpoint and any nested checkpoints created on top of it,
36
+ * leaving the checkpoint depth at the level it was before this checkpoint was created.
37
+ */
38
+ async revertToCheckpoint(): Promise<void> {
39
+ if (this.completed) {
40
+ return;
41
+ }
42
+
43
+ await this.fork.revertAllCheckpointsTo(this.depth - 1);
44
+ this.completed = true;
45
+ }
30
46
  }