@aztec/world-state 0.0.0-test.0 → 0.0.1-commit.023c3e5

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 (63) 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 +1 -1
  9. package/dest/native/fork_checkpoint.d.ts.map +1 -1
  10. package/dest/native/index.d.ts +1 -1
  11. package/dest/native/merkle_trees_facade.d.ts +19 -7
  12. package/dest/native/merkle_trees_facade.d.ts.map +1 -1
  13. package/dest/native/merkle_trees_facade.js +76 -14
  14. package/dest/native/message.d.ts +74 -52
  15. package/dest/native/message.d.ts.map +1 -1
  16. package/dest/native/message.js +61 -61
  17. package/dest/native/native_world_state.d.ts +27 -19
  18. package/dest/native/native_world_state.d.ts.map +1 -1
  19. package/dest/native/native_world_state.js +103 -41
  20. package/dest/native/native_world_state_instance.d.ts +20 -4
  21. package/dest/native/native_world_state_instance.d.ts.map +1 -1
  22. package/dest/native/native_world_state_instance.js +42 -3
  23. package/dest/native/world_state_ops_queue.d.ts +1 -1
  24. package/dest/native/world_state_ops_queue.d.ts.map +1 -1
  25. package/dest/native/world_state_ops_queue.js +1 -1
  26. package/dest/synchronizer/config.d.ts +12 -4
  27. package/dest/synchronizer/config.d.ts.map +1 -1
  28. package/dest/synchronizer/config.js +27 -7
  29. package/dest/synchronizer/errors.d.ts +4 -0
  30. package/dest/synchronizer/errors.d.ts.map +1 -0
  31. package/dest/synchronizer/errors.js +5 -0
  32. package/dest/synchronizer/factory.d.ts +11 -3
  33. package/dest/synchronizer/factory.d.ts.map +1 -1
  34. package/dest/synchronizer/factory.js +13 -8
  35. package/dest/synchronizer/index.d.ts +1 -1
  36. package/dest/synchronizer/server_world_state_synchronizer.d.ts +21 -31
  37. package/dest/synchronizer/server_world_state_synchronizer.d.ts.map +1 -1
  38. package/dest/synchronizer/server_world_state_synchronizer.js +144 -92
  39. package/dest/test/index.d.ts +1 -1
  40. package/dest/test/utils.d.ts +12 -5
  41. package/dest/test/utils.d.ts.map +1 -1
  42. package/dest/test/utils.js +54 -47
  43. package/dest/testing.d.ts +3 -3
  44. package/dest/testing.d.ts.map +1 -1
  45. package/dest/testing.js +7 -11
  46. package/dest/world-state-db/index.d.ts +1 -1
  47. package/dest/world-state-db/merkle_tree_db.d.ts +12 -9
  48. package/dest/world-state-db/merkle_tree_db.d.ts.map +1 -1
  49. package/package.json +24 -24
  50. package/src/instrumentation/instrumentation.ts +31 -43
  51. package/src/native/bench_metrics.ts +91 -0
  52. package/src/native/merkle_trees_facade.ts +83 -18
  53. package/src/native/message.ts +94 -74
  54. package/src/native/native_world_state.ts +132 -52
  55. package/src/native/native_world_state_instance.ts +62 -9
  56. package/src/native/world_state_ops_queue.ts +1 -1
  57. package/src/synchronizer/config.ts +48 -16
  58. package/src/synchronizer/errors.ts +5 -0
  59. package/src/synchronizer/factory.ts +38 -9
  60. package/src/synchronizer/server_world_state_synchronizer.ts +170 -117
  61. package/src/test/utils.ts +92 -82
  62. package/src/testing.ts +4 -8
  63. package/src/world-state-db/merkle_tree_db.ts +16 -8
@@ -1,73 +1,70 @@
1
1
  import { MAX_NOTE_HASHES_PER_TX, MAX_NULLIFIERS_PER_TX, NULLIFIER_SUBTREE_HEIGHT, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/constants';
2
+ import { asyncMap } from '@aztec/foundation/async-map';
3
+ import { BlockNumber, IndexWithinCheckpoint } from '@aztec/foundation/branded-types';
2
4
  import { padArrayEnd } from '@aztec/foundation/collection';
3
- import { Fr } from '@aztec/foundation/fields';
5
+ import { Fr } from '@aztec/foundation/curves/bn254';
4
6
  import { L2Block } from '@aztec/stdlib/block';
7
+ import { mockCheckpointAndMessages, mockL1ToL2Messages } from '@aztec/stdlib/testing';
5
8
  import { AppendOnlyTreeSnapshot, MerkleTreeId } from '@aztec/stdlib/trees';
6
- export async function mockBlock(blockNum, size, fork) {
7
- const l2Block = await L2Block.random(blockNum, size);
8
- const l1ToL2Messages = Array(16).fill(0).map(Fr.random);
9
- // Sync the append only trees
10
- {
11
- const noteHashesPadded = l2Block.body.txEffects.flatMap((txEffect)=>padArrayEnd(txEffect.noteHashes, Fr.ZERO, MAX_NOTE_HASHES_PER_TX));
12
- await fork.appendLeaves(MerkleTreeId.NOTE_HASH_TREE, noteHashesPadded);
13
- const l1ToL2MessagesPadded = padArrayEnd(l1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP);
14
- await fork.appendLeaves(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, l1ToL2MessagesPadded);
15
- }
16
- // Sync the indexed trees
17
- {
18
- // We insert the public data tree leaves with one batch per tx to avoid updating the same key twice
19
- for (const txEffect of l2Block.body.txEffects){
20
- await fork.batchInsert(MerkleTreeId.PUBLIC_DATA_TREE, txEffect.publicDataWrites.map((write)=>write.toBuffer()), 0);
21
- const nullifiersPadded = padArrayEnd(txEffect.nullifiers, Fr.ZERO, MAX_NULLIFIERS_PER_TX);
22
- await fork.batchInsert(MerkleTreeId.NULLIFIER_TREE, nullifiersPadded.map((nullifier)=>nullifier.toBuffer()), NULLIFIER_SUBTREE_HEIGHT);
9
+ import { BlockHeader } from '@aztec/stdlib/tx';
10
+ export async function updateBlockState(block, l1ToL2Messages, fork) {
11
+ const insertData = async (treeId, data, subTreeHeight, fork)=>{
12
+ for (const dataBatch of data){
13
+ await fork.batchInsert(treeId, dataBatch, subTreeHeight);
23
14
  }
24
- }
15
+ };
16
+ const publicDataInsert = insertData(MerkleTreeId.PUBLIC_DATA_TREE, block.body.txEffects.map((txEffect)=>txEffect.publicDataWrites.map((write)=>write.toBuffer())), 0, fork);
17
+ const nullifierInsert = insertData(MerkleTreeId.NULLIFIER_TREE, block.body.txEffects.map((txEffect)=>padArrayEnd(txEffect.nullifiers, Fr.ZERO, MAX_NULLIFIERS_PER_TX).map((nullifier)=>nullifier.toBuffer())), NULLIFIER_SUBTREE_HEIGHT, fork);
18
+ const noteHashesPadded = block.body.txEffects.flatMap((txEffect)=>padArrayEnd(txEffect.noteHashes, Fr.ZERO, MAX_NOTE_HASHES_PER_TX));
19
+ const l1ToL2MessagesPadded = block.indexWithinCheckpoint === 0 ? padArrayEnd(l1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP) : l1ToL2Messages;
20
+ const noteHashInsert = fork.appendLeaves(MerkleTreeId.NOTE_HASH_TREE, noteHashesPadded);
21
+ const messageInsert = fork.appendLeaves(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, l1ToL2MessagesPadded);
22
+ await Promise.all([
23
+ publicDataInsert,
24
+ nullifierInsert,
25
+ noteHashInsert,
26
+ messageInsert
27
+ ]);
25
28
  const state = await fork.getStateReference();
26
- l2Block.header.state = state;
27
- await fork.updateArchive(l2Block.header);
29
+ block.header = BlockHeader.from({
30
+ ...block.header,
31
+ state
32
+ });
33
+ await fork.updateArchive(block.header);
28
34
  const archiveState = await fork.getTreeInfo(MerkleTreeId.ARCHIVE);
29
- l2Block.archive = new AppendOnlyTreeSnapshot(Fr.fromBuffer(archiveState.root), Number(archiveState.size));
35
+ block.archive = new AppendOnlyTreeSnapshot(Fr.fromBuffer(archiveState.root), Number(archiveState.size));
36
+ }
37
+ export async function mockBlock(blockNum, size, fork, maxEffects = 1000, numL1ToL2Messages = NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP, isFirstBlockInCheckpoint = true) {
38
+ const block = await L2Block.random(blockNum, {
39
+ indexWithinCheckpoint: isFirstBlockInCheckpoint ? IndexWithinCheckpoint(0) : IndexWithinCheckpoint(1),
40
+ txsPerBlock: size,
41
+ txOptions: {
42
+ maxEffects
43
+ }
44
+ });
45
+ const l1ToL2Messages = mockL1ToL2Messages(numL1ToL2Messages);
46
+ await updateBlockState(block, l1ToL2Messages, fork);
30
47
  return {
31
- block: l2Block,
48
+ block,
32
49
  messages: l1ToL2Messages
33
50
  };
34
51
  }
35
52
  export async function mockEmptyBlock(blockNum, fork) {
36
53
  const l2Block = L2Block.empty();
37
54
  const l1ToL2Messages = Array(16).fill(0).map(Fr.zero);
38
- l2Block.header.globalVariables.blockNumber = new Fr(blockNum);
39
- // Sync the append only trees
40
- {
41
- const noteHashesPadded = l2Block.body.txEffects.flatMap((txEffect)=>padArrayEnd(txEffect.noteHashes, Fr.ZERO, MAX_NOTE_HASHES_PER_TX));
42
- await fork.appendLeaves(MerkleTreeId.NOTE_HASH_TREE, noteHashesPadded);
43
- const l1ToL2MessagesPadded = padArrayEnd(l1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP);
44
- await fork.appendLeaves(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, l1ToL2MessagesPadded);
45
- }
46
- // Sync the indexed trees
47
- {
48
- // We insert the public data tree leaves with one batch per tx to avoid updating the same key twice
49
- for (const txEffect of l2Block.body.txEffects){
50
- await fork.batchInsert(MerkleTreeId.PUBLIC_DATA_TREE, txEffect.publicDataWrites.map((write)=>write.toBuffer()), 0);
51
- const nullifiersPadded = padArrayEnd(txEffect.nullifiers, Fr.ZERO, MAX_NULLIFIERS_PER_TX);
52
- await fork.batchInsert(MerkleTreeId.NULLIFIER_TREE, nullifiersPadded.map((nullifier)=>nullifier.toBuffer()), NULLIFIER_SUBTREE_HEIGHT);
53
- }
54
- }
55
- const state = await fork.getStateReference();
56
- l2Block.header.state = state;
57
- await fork.updateArchive(l2Block.header);
58
- const archiveState = await fork.getTreeInfo(MerkleTreeId.ARCHIVE);
59
- l2Block.archive = new AppendOnlyTreeSnapshot(Fr.fromBuffer(archiveState.root), Number(archiveState.size));
55
+ l2Block.header.globalVariables.blockNumber = blockNum;
56
+ await updateBlockState(l2Block, l1ToL2Messages, fork);
60
57
  return {
61
58
  block: l2Block,
62
59
  messages: l1ToL2Messages
63
60
  };
64
61
  }
65
62
  export async function mockBlocks(from, count, numTxs, worldState) {
66
- const tempFork = await worldState.fork(from - 1);
63
+ const tempFork = await worldState.fork(BlockNumber(from - 1));
67
64
  const blocks = [];
68
65
  const messagesArray = [];
69
66
  for(let blockNumber = from; blockNumber < from + count; blockNumber++){
70
- const { block, messages } = await mockBlock(blockNumber, numTxs, tempFork);
67
+ const { block, messages } = await mockBlock(BlockNumber(blockNumber), numTxs, tempFork);
71
68
  blocks.push(block);
72
69
  messagesArray.push(messages);
73
70
  }
@@ -77,6 +74,16 @@ export async function mockBlocks(from, count, numTxs, worldState) {
77
74
  messages: messagesArray
78
75
  };
79
76
  }
77
+ export async function mockCheckpoint(checkpointNumber, fork, options = {}) {
78
+ const { checkpoint, messages } = await mockCheckpointAndMessages(checkpointNumber, options);
79
+ await asyncMap(checkpoint.blocks, async (block, i)=>{
80
+ await updateBlockState(block, i === 0 ? messages : [], fork);
81
+ });
82
+ return {
83
+ checkpoint,
84
+ messages
85
+ };
86
+ }
80
87
  export async function assertSameState(forkA, forkB) {
81
88
  const nativeStateRef = await forkA.getStateReference();
82
89
  const nativeArchive = await forkA.getTreeInfo(MerkleTreeId.ARCHIVE);
package/dest/testing.d.ts CHANGED
@@ -1,10 +1,10 @@
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
4
  export declare const defaultInitialAccountFeeJuice: Fr;
5
5
  export declare function getGenesisValues(initialAccounts: AztecAddress[], initialAccountFeeJuice?: Fr, genesisPublicData?: PublicDataTreeLeaf[]): Promise<{
6
6
  genesisArchiveRoot: Fr;
7
- genesisBlockHash: Fr;
8
7
  prefilledPublicData: PublicDataTreeLeaf[];
8
+ fundingNeeded: bigint;
9
9
  }>;
10
- //# sourceMappingURL=testing.d.ts.map
10
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdGluZy5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL3Rlc3RpbmcudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQ0EsT0FBTyxFQUFFLEVBQUUsRUFBRSxNQUFNLGdDQUFnQyxDQUFDO0FBRXBELE9BQU8sS0FBSyxFQUFFLFlBQVksRUFBRSxNQUFNLDZCQUE2QixDQUFDO0FBQ2hFLE9BQU8sRUFBZ0Isa0JBQWtCLEVBQUUsTUFBTSxxQkFBcUIsQ0FBQztBQXlCdkUsZUFBTyxNQUFNLDZCQUE2QixJQUFxQixDQUFDO0FBRWhFLHdCQUFzQixnQkFBZ0IsQ0FDcEMsZUFBZSxFQUFFLFlBQVksRUFBRSxFQUMvQixzQkFBc0IsS0FBZ0MsRUFDdEQsaUJBQWlCLEdBQUUsa0JBQWtCLEVBQU87Ozs7R0FxQjdDIn0=
@@ -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;AAyBvE,eAAO,MAAM,6BAA6B,IAAqB,CAAC;AAEhE,wBAAsB,gBAAgB,CACpC,eAAe,EAAE,YAAY,EAAE,EAC/B,sBAAsB,KAAgC,EACtD,iBAAiB,GAAE,kBAAkB,EAAO;;;;GAqB7C"}
package/dest/testing.js CHANGED
@@ -1,24 +1,20 @@
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
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 { genesisBlockHash, genesisArchiveRoot } = await generateGenesisValues(prefilledPublicData);
27
+ const { genesisArchiveRoot } = await generateGenesisValues(prefilledPublicData);
32
28
  return {
33
29
  genesisArchiveRoot,
34
- genesisBlockHash,
35
- prefilledPublicData
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=index.d.ts.map
3
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy93b3JsZC1zdGF0ZS1kYi9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxjQUFjLHFCQUFxQixDQUFDO0FBRXBDLFlBQVksRUFBRSx3QkFBd0IsRUFBRSxNQUFNLGlDQUFpQyxDQUFDIn0=
@@ -1,7 +1,8 @@
1
- import type { Fr } from '@aztec/foundation/fields';
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
4
  import type { L2Block } from '@aztec/stdlib/block';
4
- import type { ForkMerkleTreeOperations, MerkleTreeReadOperations } from '@aztec/stdlib/interfaces/server';
5
+ import type { ForkMerkleTreeOperations, MerkleTreeReadOperations, ReadonlyWorldStateAccess } from '@aztec/stdlib/interfaces/server';
5
6
  import type { MerkleTreeId } from '@aztec/stdlib/trees';
6
7
  import type { WorldStateStatusFull, WorldStateStatusSummary } from '../native/message.js';
7
8
  /**
@@ -28,7 +29,7 @@ export type TreeSnapshots = {
28
29
  [MerkleTreeId.L1_TO_L2_MESSAGE_TREE]: TreeSnapshot<Fr>;
29
30
  [MerkleTreeId.ARCHIVE]: TreeSnapshot<Fr>;
30
31
  };
31
- export interface MerkleTreeAdminDatabase extends ForkMerkleTreeOperations {
32
+ export interface MerkleTreeAdminDatabase extends ForkMerkleTreeOperations, ReadonlyWorldStateAccess {
32
33
  /**
33
34
  * Handles a single L2 block (i.e. Inserts the new note hashes into the merkle tree).
34
35
  * @param block - The L2 block to handle.
@@ -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: bigint): Promise<WorldStateStatusFull>;
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: bigint): Promise<WorldStateStatusFull>;
54
+ unwindBlocks(toBlockNumber: BlockNumber): Promise<WorldStateStatusFull>;
54
55
  /**
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
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
- setFinalised(toBlockNumber: bigint): Promise<WorldStateStatusSummary>;
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=merkle_tree_db.d.ts.map
71
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWVya2xlX3RyZWVfZGIuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy93b3JsZC1zdGF0ZS1kYi9tZXJrbGVfdHJlZV9kYi50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFDQSxPQUFPLEtBQUssRUFBRSxXQUFXLEVBQUUsTUFBTSxpQ0FBaUMsQ0FBQztBQUNuRSxPQUFPLEtBQUssRUFBRSxFQUFFLEVBQUUsTUFBTSxnQ0FBZ0MsQ0FBQztBQUN6RCxPQUFPLEtBQUssRUFBRSxtQkFBbUIsRUFBRSxZQUFZLEVBQUUsTUFBTSxvQkFBb0IsQ0FBQztBQUM1RSxPQUFPLEtBQUssRUFBRSxPQUFPLEVBQUUsTUFBTSxxQkFBcUIsQ0FBQztBQUNuRCxPQUFPLEtBQUssRUFDVix3QkFBd0IsRUFDeEIsd0JBQXdCLEVBQ3hCLHdCQUF3QixFQUN6QixNQUFNLGlDQUFpQyxDQUFDO0FBQ3pDLE9BQU8sS0FBSyxFQUFFLFlBQVksRUFBRSxNQUFNLHFCQUFxQixDQUFDO0FBRXhELE9BQU8sS0FBSyxFQUFFLG9CQUFvQixFQUFFLHVCQUF1QixFQUFFLE1BQU0sc0JBQXNCLENBQUM7QUFFMUY7Ozs7Ozs7Ozs7Ozs7O0dBY0c7QUFDSCxlQUFPLE1BQU0sMkJBQTJCLFFBQTRCLENBQUM7QUFFckUsZUFBTyxNQUFNLDZCQUE2QixRQUFtRCxDQUFDO0FBRTlGLE1BQU0sTUFBTSxhQUFhLEdBQUc7SUFDMUIsQ0FB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AC,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,EAAE,wBAAwB;IACjG;;;;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,WAAW,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;IAElF;;;;OAIG;IACH,YAAY,CAAC,aAAa,EAAE,WAAW,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;IAExE;;;;OAIG;IACH,YAAY,CAAC,aAAa,EAAE,WAAW,GAAG,OAAO,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.0-test.0",
3
+ "version": "0.0.1-commit.023c3e5",
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,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.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",
67
+ "@aztec/constants": "0.0.1-commit.023c3e5",
68
+ "@aztec/foundation": "0.0.1-commit.023c3e5",
69
+ "@aztec/kv-store": "0.0.1-commit.023c3e5",
70
+ "@aztec/merkle-tree": "0.0.1-commit.023c3e5",
71
+ "@aztec/native": "0.0.1-commit.023c3e5",
72
+ "@aztec/protocol-contracts": "0.0.1-commit.023c3e5",
73
+ "@aztec/stdlib": "0.0.1-commit.023c3e5",
74
+ "@aztec/telemetry-client": "0.0.1-commit.023c3e5",
73
75
  "tslib": "^2.4.0",
74
76
  "zod": "^3.23.8"
75
77
  },
76
78
  "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",
79
+ "@aztec/archiver": "0.0.1-commit.023c3e5",
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.20260113.1",
84
+ "jest": "^30.0.0",
85
+ "jest-mock-extended": "^4.0.0",
86
86
  "ts-node": "^10.9.1",
87
- "typescript": "^5.0.4"
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": ">=18"
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,
@@ -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
+ }