@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.
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 +16 -8
  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 +62 -11
  14. package/dest/native/message.d.ts +72 -51
  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 +28 -20
  18. package/dest/native/native_world_state.d.ts.map +1 -1
  19. package/dest/native/native_world_state.js +97 -36
  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 -2
  27. package/dest/synchronizer/config.d.ts.map +1 -1
  28. package/dest/synchronizer/config.js +26 -1
  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 +9 -2
  33. package/dest/synchronizer/factory.d.ts.map +1 -1
  34. package/dest/synchronizer/factory.js +9 -4
  35. package/dest/synchronizer/index.d.ts +1 -1
  36. package/dest/synchronizer/server_world_state_synchronizer.d.ts +20 -29
  37. package/dest/synchronizer/server_world_state_synchronizer.d.ts.map +1 -1
  38. package/dest/synchronizer/server_world_state_synchronizer.js +94 -70
  39. package/dest/test/index.d.ts +1 -1
  40. package/dest/test/utils.d.ts +16 -9
  41. package/dest/test/utils.d.ts.map +1 -1
  42. package/dest/test/utils.js +56 -49
  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 +22 -10
  51. package/src/native/bench_metrics.ts +91 -0
  52. package/src/native/merkle_trees_facade.ts +73 -17
  53. package/src/native/message.ts +92 -73
  54. package/src/native/native_world_state.ts +118 -50
  55. package/src/native/native_world_state_instance.ts +59 -8
  56. package/src/native/world_state_ops_queue.ts +1 -1
  57. package/src/synchronizer/config.ts +47 -2
  58. package/src/synchronizer/errors.ts +5 -0
  59. package/src/synchronizer/factory.ts +31 -8
  60. package/src/synchronizer/server_world_state_synchronizer.ts +132 -93
  61. package/src/test/utils.ts +94 -84
  62. package/src/testing.ts +4 -8
  63. package/src/world-state-db/merkle_tree_db.ts +12 -8
@@ -1,8 +1,10 @@
1
- import { Fr } from '@aztec/foundation/fields';
1
+ import { BlockNumber } from '@aztec/foundation/branded-types';
2
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
3
  import type { Tuple } from '@aztec/foundation/serialize';
3
4
  import { AppendOnlyTreeSnapshot, MerkleTreeId } from '@aztec/stdlib/trees';
4
5
  import type { StateReference } from '@aztec/stdlib/tx';
5
6
  import type { UInt32 } from '@aztec/stdlib/types';
7
+ import type { WorldStateRevision } from '@aztec/stdlib/world-state';
6
8
 
7
9
  export enum WorldStateMessageType {
8
10
  GET_TREE_INFO = 100,
@@ -16,6 +18,7 @@ export enum WorldStateMessageType {
16
18
 
17
19
  FIND_LEAF_INDICES,
18
20
  FIND_LOW_LEAF,
21
+ FIND_SIBLING_PATHS,
19
22
 
20
23
  APPEND_LEAVES,
21
24
  BATCH_INSERT,
@@ -31,7 +34,7 @@ export enum WorldStateMessageType {
31
34
  CREATE_FORK,
32
35
  DELETE_FORK,
33
36
 
34
- FINALISE_BLOCKS,
37
+ FINALIZE_BLOCKS,
35
38
  UNWIND_BLOCKS,
36
39
  REMOVE_HISTORICAL_BLOCKS,
37
40
 
@@ -40,6 +43,10 @@ export enum WorldStateMessageType {
40
43
  CREATE_CHECKPOINT,
41
44
  COMMIT_CHECKPOINT,
42
45
  REVERT_CHECKPOINT,
46
+ COMMIT_ALL_CHECKPOINTS,
47
+ REVERT_ALL_CHECKPOINTS,
48
+
49
+ COPY_STORES,
43
50
 
44
51
  CLOSE = 999,
45
52
  }
@@ -50,11 +57,11 @@ interface WithTreeId {
50
57
 
51
58
  export interface WorldStateStatusSummary {
52
59
  /** Last block number that can still be unwound. */
53
- unfinalisedBlockNumber: bigint;
54
- /** Last block number that is finalised and cannot be unwound. */
55
- finalisedBlockNumber: bigint;
60
+ unfinalizedBlockNumber: BlockNumber;
61
+ /** Last block number that is finalized and cannot be unwound. */
62
+ finalizedBlockNumber: BlockNumber;
56
63
  /** Oldest block still available for historical queries and forks. */
57
- oldestHistoricalBlock: bigint;
64
+ oldestHistoricalBlock: BlockNumber;
58
65
  /** Whether the trees are in sync with each other */
59
66
  treesAreSynched: boolean;
60
67
  }
@@ -75,11 +82,11 @@ export interface TreeMeta {
75
82
  /** The tree's initial root value */
76
83
  initialRoot: Fr;
77
84
  /** The current oldest historical block number of the tree */
78
- oldestHistoricBlock: bigint;
79
- /** The current unfinalised block number of the tree */
80
- unfinalisedBlockHeight: bigint;
81
- /** The current finalised block number of the tree */
82
- finalisedBlockHeight: bigint;
85
+ oldestHistoricBlock: BlockNumber;
86
+ /** The current unfinalized block number of the tree */
87
+ unfinalizedBlockHeight: BlockNumber;
88
+ /** The current finalized block number of the tree */
89
+ finalizedBlockHeight: BlockNumber;
83
90
  }
84
91
 
85
92
  export interface DBStats {
@@ -94,6 +101,8 @@ export interface DBStats {
94
101
  export interface TreeDBStats {
95
102
  /** The configured max size of the DB mapping file (effectively the max possible size of the DB) */
96
103
  mapSize: bigint;
104
+ /** The physical file size of the database on disk */
105
+ physicalFileSize: bigint;
97
106
  /** Stats for the 'blocks' DB */
98
107
  blocksDBStats: DBStats;
99
108
  /** Stats for the 'nodes' DB */
@@ -149,6 +158,7 @@ export function buildEmptyDBStats() {
149
158
  export function buildEmptyTreeDBStats() {
150
159
  return {
151
160
  mapSize: 0n,
161
+ physicalFileSize: 0n,
152
162
  blocksDBStats: buildEmptyDBStats(),
153
163
  nodesDBStats: buildEmptyDBStats(),
154
164
  leafIndicesDBStats: buildEmptyDBStats(),
@@ -164,9 +174,9 @@ export function buildEmptyTreeMeta() {
164
174
  depth: 0,
165
175
  size: 0n,
166
176
  committedSize: 0n,
167
- unfinalisedBlockHeight: 0n,
168
- finalisedBlockHeight: 0n,
169
- oldestHistoricBlock: 0n,
177
+ unfinalizedBlockHeight: BlockNumber.ZERO,
178
+ finalizedBlockHeight: BlockNumber.ZERO,
179
+ oldestHistoricBlock: BlockNumber.ZERO,
170
180
  root: Fr.ZERO,
171
181
  initialRoot: Fr.ZERO,
172
182
  initialSize: 0n,
@@ -195,9 +205,9 @@ export function buildEmptyWorldStateDBStats() {
195
205
 
196
206
  export function buildEmptyWorldStateSummary() {
197
207
  return {
198
- unfinalisedBlockNumber: 0n,
199
- finalisedBlockNumber: 0n,
200
- oldestHistoricalBlock: 0n,
208
+ unfinalizedBlockNumber: BlockNumber.ZERO,
209
+ finalizedBlockNumber: BlockNumber.ZERO,
210
+ oldestHistoricalBlock: BlockNumber.ZERO,
201
211
  treesAreSynched: true,
202
212
  } as WorldStateStatusSummary;
203
213
  }
@@ -210,61 +220,62 @@ export function buildEmptyWorldStateStatusFull() {
210
220
  } as WorldStateStatusFull;
211
221
  }
212
222
 
213
- export function sanitiseSummary(summary: WorldStateStatusSummary) {
214
- summary.finalisedBlockNumber = BigInt(summary.finalisedBlockNumber);
215
- summary.unfinalisedBlockNumber = BigInt(summary.unfinalisedBlockNumber);
216
- summary.oldestHistoricalBlock = BigInt(summary.oldestHistoricalBlock);
223
+ export function sanitizeSummary(summary: WorldStateStatusSummary) {
224
+ summary.finalizedBlockNumber = BlockNumber.fromBigInt(BigInt(summary.finalizedBlockNumber));
225
+ summary.unfinalizedBlockNumber = BlockNumber.fromBigInt(BigInt(summary.unfinalizedBlockNumber));
226
+ summary.oldestHistoricalBlock = BlockNumber.fromBigInt(BigInt(summary.oldestHistoricalBlock));
217
227
  return summary;
218
228
  }
219
229
 
220
- export function sanitiseDBStats(stats: DBStats) {
230
+ export function sanitizeDBStats(stats: DBStats) {
221
231
  stats.numDataItems = BigInt(stats.numDataItems);
222
232
  stats.totalUsedSize = BigInt(stats.totalUsedSize);
223
233
  return stats;
224
234
  }
225
235
 
226
- export function sanitiseMeta(meta: TreeMeta) {
236
+ export function sanitizeMeta(meta: TreeMeta) {
227
237
  meta.committedSize = BigInt(meta.committedSize);
228
- meta.finalisedBlockHeight = BigInt(meta.finalisedBlockHeight);
238
+ meta.finalizedBlockHeight = BlockNumber.fromBigInt(BigInt(meta.finalizedBlockHeight));
229
239
  meta.initialSize = BigInt(meta.initialSize);
230
- meta.oldestHistoricBlock = BigInt(meta.oldestHistoricBlock);
240
+ meta.oldestHistoricBlock = BlockNumber.fromBigInt(BigInt(meta.oldestHistoricBlock));
231
241
  meta.size = BigInt(meta.size);
232
- meta.unfinalisedBlockHeight = BigInt(meta.unfinalisedBlockHeight);
242
+ meta.unfinalizedBlockHeight = BlockNumber.fromBigInt(BigInt(meta.unfinalizedBlockHeight));
233
243
  return meta;
234
244
  }
235
245
 
236
- export function sanitiseTreeDBStats(stats: TreeDBStats) {
237
- stats.blocksDBStats = sanitiseDBStats(stats.blocksDBStats);
238
- stats.leafIndicesDBStats = sanitiseDBStats(stats.leafIndicesDBStats);
239
- stats.leafPreimagesDBStats = sanitiseDBStats(stats.leafPreimagesDBStats);
240
- stats.blockIndicesDBStats = sanitiseDBStats(stats.blockIndicesDBStats);
241
- stats.nodesDBStats = sanitiseDBStats(stats.nodesDBStats);
246
+ export function sanitizeTreeDBStats(stats: TreeDBStats) {
247
+ stats.blocksDBStats = sanitizeDBStats(stats.blocksDBStats);
248
+ stats.leafIndicesDBStats = sanitizeDBStats(stats.leafIndicesDBStats);
249
+ stats.leafPreimagesDBStats = sanitizeDBStats(stats.leafPreimagesDBStats);
250
+ stats.blockIndicesDBStats = sanitizeDBStats(stats.blockIndicesDBStats);
251
+ stats.nodesDBStats = sanitizeDBStats(stats.nodesDBStats);
242
252
  stats.mapSize = BigInt(stats.mapSize);
253
+ stats.physicalFileSize = BigInt(stats.physicalFileSize);
243
254
  return stats;
244
255
  }
245
256
 
246
- export function sanitiseWorldStateDBStats(stats: WorldStateDBStats) {
247
- stats.archiveTreeStats = sanitiseTreeDBStats(stats.archiveTreeStats);
248
- stats.messageTreeStats = sanitiseTreeDBStats(stats.messageTreeStats);
249
- stats.noteHashTreeStats = sanitiseTreeDBStats(stats.noteHashTreeStats);
250
- stats.nullifierTreeStats = sanitiseTreeDBStats(stats.nullifierTreeStats);
251
- stats.publicDataTreeStats = sanitiseTreeDBStats(stats.publicDataTreeStats);
257
+ export function sanitizeWorldStateDBStats(stats: WorldStateDBStats) {
258
+ stats.archiveTreeStats = sanitizeTreeDBStats(stats.archiveTreeStats);
259
+ stats.messageTreeStats = sanitizeTreeDBStats(stats.messageTreeStats);
260
+ stats.noteHashTreeStats = sanitizeTreeDBStats(stats.noteHashTreeStats);
261
+ stats.nullifierTreeStats = sanitizeTreeDBStats(stats.nullifierTreeStats);
262
+ stats.publicDataTreeStats = sanitizeTreeDBStats(stats.publicDataTreeStats);
252
263
  return stats;
253
264
  }
254
265
 
255
- export function sanitiseWorldStateTreeMeta(meta: WorldStateMeta) {
256
- meta.archiveTreeMeta = sanitiseMeta(meta.archiveTreeMeta);
257
- meta.messageTreeMeta = sanitiseMeta(meta.messageTreeMeta);
258
- meta.noteHashTreeMeta = sanitiseMeta(meta.noteHashTreeMeta);
259
- meta.nullifierTreeMeta = sanitiseMeta(meta.nullifierTreeMeta);
260
- meta.publicDataTreeMeta = sanitiseMeta(meta.publicDataTreeMeta);
266
+ export function sanitizeWorldStateTreeMeta(meta: WorldStateMeta) {
267
+ meta.archiveTreeMeta = sanitizeMeta(meta.archiveTreeMeta);
268
+ meta.messageTreeMeta = sanitizeMeta(meta.messageTreeMeta);
269
+ meta.noteHashTreeMeta = sanitizeMeta(meta.noteHashTreeMeta);
270
+ meta.nullifierTreeMeta = sanitizeMeta(meta.nullifierTreeMeta);
271
+ meta.publicDataTreeMeta = sanitizeMeta(meta.publicDataTreeMeta);
261
272
  return meta;
262
273
  }
263
274
 
264
- export function sanitiseFullStatus(status: WorldStateStatusFull) {
265
- status.dbStats = sanitiseWorldStateDBStats(status.dbStats);
266
- status.summary = sanitiseSummary(status.summary);
267
- status.meta = sanitiseWorldStateTreeMeta(status.meta);
275
+ export function sanitizeFullStatus(status: WorldStateStatusFull) {
276
+ status.dbStats = sanitizeWorldStateDBStats(status.dbStats);
277
+ status.summary = sanitizeSummary(status.summary);
278
+ status.meta = sanitizeWorldStateTreeMeta(status.meta);
268
279
  return status;
269
280
  }
270
281
 
@@ -286,13 +297,13 @@ interface WithLeafIndex {
286
297
 
287
298
  export type SerializedLeafValue =
288
299
  | Buffer // Fr
289
- | { value: Buffer } // NullifierLeaf
300
+ | { nullifier: Buffer } // NullifierLeaf
290
301
  | { value: Buffer; slot: Buffer }; // PublicDataTreeLeaf
291
302
 
292
303
  export type SerializedIndexedLeaf = {
293
- value: Exclude<SerializedLeafValue, Buffer>;
304
+ leaf: Exclude<SerializedLeafValue, Buffer>;
294
305
  nextIndex: bigint | number;
295
- nextValue: Buffer; // Fr
306
+ nextKey: Buffer; // Fr
296
307
  };
297
308
 
298
309
  interface WithLeafValues {
@@ -300,7 +311,7 @@ interface WithLeafValues {
300
311
  }
301
312
 
302
313
  interface BlockShiftRequest extends WithCanonicalForkId {
303
- toBlockNumber: bigint;
314
+ toBlockNumber: BlockNumber;
304
315
  }
305
316
 
306
317
  interface WithLeaves {
@@ -344,6 +355,16 @@ interface FindLeafIndicesResponse {
344
355
  indices: bigint[];
345
356
  }
346
357
 
358
+ interface FindSiblingPathsRequest extends WithTreeId, WithLeafValues, WithWorldStateRevision {}
359
+
360
+ interface SiblingPathAndIndex {
361
+ index: bigint;
362
+ path: Buffer[];
363
+ }
364
+ interface FindSiblingPathsResponse {
365
+ paths: (SiblingPathAndIndex | undefined)[];
366
+ }
367
+
347
368
  interface FindLowLeafRequest extends WithTreeId, WithWorldStateRevision {
348
369
  key: Fr;
349
370
  }
@@ -389,7 +410,7 @@ interface UpdateArchiveRequest extends WithForkId {
389
410
  }
390
411
 
391
412
  interface SyncBlockRequest extends WithCanonicalForkId {
392
- blockNumber: number;
413
+ blockNumber: BlockNumber;
393
414
  blockStateRef: BlockStateReference;
394
415
  blockHeaderHash: Fr;
395
416
  paddedNoteHashes: readonly SerializedLeafValue[];
@@ -400,7 +421,7 @@ interface SyncBlockRequest extends WithCanonicalForkId {
400
421
 
401
422
  interface CreateForkRequest extends WithCanonicalForkId {
402
423
  latest: boolean;
403
- blockNumber: number;
424
+ blockNumber: BlockNumber;
404
425
  }
405
426
 
406
427
  interface CreateForkResponse {
@@ -409,6 +430,11 @@ interface CreateForkResponse {
409
430
 
410
431
  interface DeleteForkRequest extends WithForkId {}
411
432
 
433
+ interface CopyStoresRequest extends WithCanonicalForkId {
434
+ dstPath: string;
435
+ compact: boolean;
436
+ }
437
+
412
438
  export type WorldStateRequestCategories = WithForkId | WithWorldStateRevision | WithCanonicalForkId;
413
439
 
414
440
  export function isWithForkId(body: WorldStateRequestCategories): body is WithForkId {
@@ -435,6 +461,7 @@ export type WorldStateRequest = {
435
461
 
436
462
  [WorldStateMessageType.FIND_LEAF_INDICES]: FindLeafIndicesRequest;
437
463
  [WorldStateMessageType.FIND_LOW_LEAF]: FindLowLeafRequest;
464
+ [WorldStateMessageType.FIND_SIBLING_PATHS]: FindSiblingPathsRequest;
438
465
 
439
466
  [WorldStateMessageType.APPEND_LEAVES]: AppendLeavesRequest;
440
467
  [WorldStateMessageType.BATCH_INSERT]: BatchInsertRequest;
@@ -452,13 +479,17 @@ export type WorldStateRequest = {
452
479
 
453
480
  [WorldStateMessageType.REMOVE_HISTORICAL_BLOCKS]: BlockShiftRequest;
454
481
  [WorldStateMessageType.UNWIND_BLOCKS]: BlockShiftRequest;
455
- [WorldStateMessageType.FINALISE_BLOCKS]: BlockShiftRequest;
482
+ [WorldStateMessageType.FINALIZE_BLOCKS]: BlockShiftRequest;
456
483
 
457
484
  [WorldStateMessageType.GET_STATUS]: WithCanonicalForkId;
458
485
 
459
486
  [WorldStateMessageType.CREATE_CHECKPOINT]: WithForkId;
460
487
  [WorldStateMessageType.COMMIT_CHECKPOINT]: WithForkId;
461
488
  [WorldStateMessageType.REVERT_CHECKPOINT]: WithForkId;
489
+ [WorldStateMessageType.COMMIT_ALL_CHECKPOINTS]: WithForkId;
490
+ [WorldStateMessageType.REVERT_ALL_CHECKPOINTS]: WithForkId;
491
+
492
+ [WorldStateMessageType.COPY_STORES]: CopyStoresRequest;
462
493
 
463
494
  [WorldStateMessageType.CLOSE]: WithCanonicalForkId;
464
495
  };
@@ -475,6 +506,7 @@ export type WorldStateResponse = {
475
506
 
476
507
  [WorldStateMessageType.FIND_LEAF_INDICES]: FindLeafIndicesResponse;
477
508
  [WorldStateMessageType.FIND_LOW_LEAF]: FindLowLeafResponse;
509
+ [WorldStateMessageType.FIND_SIBLING_PATHS]: FindSiblingPathsResponse;
478
510
 
479
511
  [WorldStateMessageType.APPEND_LEAVES]: void;
480
512
  [WorldStateMessageType.BATCH_INSERT]: BatchInsertResponse;
@@ -492,33 +524,20 @@ export type WorldStateResponse = {
492
524
 
493
525
  [WorldStateMessageType.REMOVE_HISTORICAL_BLOCKS]: WorldStateStatusFull;
494
526
  [WorldStateMessageType.UNWIND_BLOCKS]: WorldStateStatusFull;
495
- [WorldStateMessageType.FINALISE_BLOCKS]: WorldStateStatusSummary;
527
+ [WorldStateMessageType.FINALIZE_BLOCKS]: WorldStateStatusSummary;
496
528
 
497
529
  [WorldStateMessageType.GET_STATUS]: WorldStateStatusSummary;
498
530
 
499
531
  [WorldStateMessageType.CREATE_CHECKPOINT]: void;
500
532
  [WorldStateMessageType.COMMIT_CHECKPOINT]: void;
501
533
  [WorldStateMessageType.REVERT_CHECKPOINT]: void;
534
+ [WorldStateMessageType.COMMIT_ALL_CHECKPOINTS]: void;
535
+ [WorldStateMessageType.REVERT_ALL_CHECKPOINTS]: void;
502
536
 
503
- [WorldStateMessageType.CLOSE]: void;
504
- };
537
+ [WorldStateMessageType.COPY_STORES]: void;
505
538
 
506
- export type WorldStateRevision = {
507
- forkId: number;
508
- blockNumber: number;
509
- includeUncommitted: boolean;
539
+ [WorldStateMessageType.CLOSE]: void;
510
540
  };
511
- export function worldStateRevision(
512
- includeUncommitted: boolean,
513
- forkId: number | undefined,
514
- blockNumber: number | undefined,
515
- ): WorldStateRevision {
516
- return {
517
- forkId: forkId ?? 0,
518
- blockNumber: blockNumber ?? 0,
519
- includeUncommitted,
520
- };
521
- }
522
541
 
523
542
  type TreeStateReference = readonly [Buffer, number | bigint];
524
543
  type BlockStateReference = Map<Exclude<MerkleTreeId, MerkleTreeId.ARCHIVE>, TreeStateReference>;