@aztec/world-state 0.0.1-commit.d3ec352c → 0.0.1-commit.e310a4c8

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 (48) hide show
  1. package/dest/instrumentation/instrumentation.d.ts +1 -1
  2. package/dest/instrumentation/instrumentation.d.ts.map +1 -1
  3. package/dest/instrumentation/instrumentation.js +17 -41
  4. package/dest/native/merkle_trees_facade.d.ts +8 -3
  5. package/dest/native/merkle_trees_facade.d.ts.map +1 -1
  6. package/dest/native/merkle_trees_facade.js +35 -6
  7. package/dest/native/message.d.ts +4 -3
  8. package/dest/native/message.d.ts.map +1 -1
  9. package/dest/native/message.js +1 -1
  10. package/dest/native/native_world_state.d.ts +11 -9
  11. package/dest/native/native_world_state.d.ts.map +1 -1
  12. package/dest/native/native_world_state.js +14 -12
  13. package/dest/native/native_world_state_instance.d.ts +3 -3
  14. package/dest/native/native_world_state_instance.d.ts.map +1 -1
  15. package/dest/native/native_world_state_instance.js +3 -3
  16. package/dest/synchronizer/config.d.ts +1 -3
  17. package/dest/synchronizer/config.d.ts.map +1 -1
  18. package/dest/synchronizer/config.js +1 -6
  19. package/dest/synchronizer/factory.d.ts +4 -3
  20. package/dest/synchronizer/factory.d.ts.map +1 -1
  21. package/dest/synchronizer/factory.js +5 -5
  22. package/dest/synchronizer/server_world_state_synchronizer.d.ts +5 -4
  23. package/dest/synchronizer/server_world_state_synchronizer.d.ts.map +1 -1
  24. package/dest/synchronizer/server_world_state_synchronizer.js +72 -43
  25. package/dest/test/utils.d.ts +11 -17
  26. package/dest/test/utils.d.ts.map +1 -1
  27. package/dest/test/utils.js +44 -81
  28. package/dest/testing.d.ts +2 -2
  29. package/dest/testing.d.ts.map +1 -1
  30. package/dest/testing.js +1 -1
  31. package/dest/world-state-db/merkle_tree_db.d.ts +7 -9
  32. package/dest/world-state-db/merkle_tree_db.d.ts.map +1 -1
  33. package/package.json +11 -11
  34. package/src/instrumentation/instrumentation.ts +17 -41
  35. package/src/native/merkle_trees_facade.ts +36 -3
  36. package/src/native/message.ts +3 -2
  37. package/src/native/native_world_state.ts +29 -16
  38. package/src/native/native_world_state_instance.ts +5 -3
  39. package/src/synchronizer/config.ts +1 -14
  40. package/src/synchronizer/factory.ts +7 -1
  41. package/src/synchronizer/server_world_state_synchronizer.ts +76 -59
  42. package/src/test/utils.ts +70 -128
  43. package/src/testing.ts +1 -1
  44. package/src/world-state-db/merkle_tree_db.ts +10 -12
  45. package/dest/synchronizer/utils.d.ts +0 -11
  46. package/dest/synchronizer/utils.d.ts.map +0 -1
  47. package/dest/synchronizer/utils.js +0 -59
  48. package/src/synchronizer/utils.ts +0 -83
@@ -1,83 +0,0 @@
1
- import { BlockNumber, type SlotNumber } from '@aztec/foundation/branded-types';
2
- import type { Fr } from '@aztec/foundation/fields';
3
- import type { L2BlockNew, L2BlockSource } from '@aztec/stdlib/block';
4
- import type { Checkpoint } from '@aztec/stdlib/checkpoint';
5
- import { type L1ToL2MessageSource, computeInHashFromL1ToL2Messages } from '@aztec/stdlib/messaging';
6
-
7
- /**
8
- * Determine which blocks in the given array are the first block in a checkpoint.
9
- * @param blocks - The candidate blocks, sorted by block number in ascending order.
10
- * @param l2BlockSource - The L2 block source to use to fetch the checkpoints, block headers and L1->L2 messages.
11
- * @returns A map of block numbers that begin a checkpoint to the L1->L2 messages for that checkpoint.
12
- */
13
- export async function findFirstBlocksInCheckpoints(
14
- blocks: L2BlockNew[],
15
- l2BlockSource: L2BlockSource & L1ToL2MessageSource,
16
- ): Promise<Map<number, Fr[]>> {
17
- // Select the blocks that are the final block within each group of identical slot numbers.
18
- let seenSlot: SlotNumber | undefined;
19
- const maybeLastBlocks = [...blocks]
20
- .reverse()
21
- .filter(b => {
22
- if (b.header.globalVariables.slotNumber !== seenSlot) {
23
- seenSlot = b.header.globalVariables.slotNumber;
24
- return true;
25
- }
26
- return false;
27
- })
28
- .reverse();
29
-
30
- // Try to fetch the checkpoints for those blocks. If undefined (which should only occur for blocks.at(-1)),
31
- // then the block is not the last one in a checkpoint.
32
- // If we are not checking the inHashes below, only blocks.at(-1) would need its checkpoint header fetched.
33
- const checkpointedBlocks = (
34
- await Promise.all(
35
- maybeLastBlocks.map(async b => ({
36
- blockNumber: b.number,
37
- // A checkpoint's archive root is the archive root of its last block.
38
- checkpoint: await l2BlockSource.getCheckpointByArchive(b.archive.root),
39
- })),
40
- )
41
- ).filter(b => b.checkpoint !== undefined) as { blockNumber: BlockNumber; checkpoint: Checkpoint }[];
42
-
43
- // Verify that the L1->L2 messages hash to the checkpoint's inHash.
44
- const checkpointedL1ToL2Messages: Fr[][] = await Promise.all(
45
- checkpointedBlocks.map(b => l2BlockSource.getL1ToL2MessagesForCheckpoint(b.checkpoint!.number)),
46
- );
47
- checkpointedBlocks.forEach((b, i) => {
48
- const computedInHash = computeInHashFromL1ToL2Messages(checkpointedL1ToL2Messages[i]);
49
- const inHash = b.checkpoint.header.contentCommitment.inHash;
50
- if (!computedInHash.equals(inHash)) {
51
- throw new Error('Obtained L1 to L2 messages failed to be hashed to the checkpoint inHash');
52
- }
53
- });
54
-
55
- // Compute the first block numbers, which should be right after each checkpointed block. Exclude blocks that haven't
56
- // been added yet.
57
- const firstBlockNumbers = checkpointedBlocks
58
- .map(b => BlockNumber(b.blockNumber + 1))
59
- .filter(n => n <= blocks.at(-1)!.number);
60
- // Check if blocks[0] is the first block in a checkpoint.
61
- if (blocks[0].number === 1) {
62
- firstBlockNumbers.push(blocks[0].number);
63
- } else {
64
- const lastBlockHeader = await l2BlockSource.getBlockHeader(BlockNumber(blocks[0].number - 1));
65
- if (!lastBlockHeader) {
66
- throw new Error(`Failed to get block ${blocks[0].number - 1}`);
67
- }
68
- if (lastBlockHeader.globalVariables.slotNumber !== blocks[0].header.globalVariables.slotNumber) {
69
- firstBlockNumbers.push(blocks[0].number);
70
- }
71
- }
72
-
73
- // Fetch the L1->L2 messages for the first blocks and assign them to the map.
74
- const messagesByBlockNumber = new Map<BlockNumber, Fr[]>();
75
- await Promise.all(
76
- firstBlockNumbers.map(async blockNumber => {
77
- const l1ToL2Messages = await l2BlockSource.getL1ToL2Messages(blockNumber);
78
- messagesByBlockNumber.set(blockNumber, l1ToL2Messages);
79
- }),
80
- );
81
-
82
- return messagesByBlockNumber;
83
- }