@aztec/world-state 0.0.1-commit.c31f2472 → 0.0.1-commit.c52d6e7

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 (76) hide show
  1. package/dest/index.d.ts +2 -1
  2. package/dest/index.d.ts.map +1 -1
  3. package/dest/index.js +1 -0
  4. package/dest/instrumentation/instrumentation.d.ts +4 -3
  5. package/dest/instrumentation/instrumentation.d.ts.map +1 -1
  6. package/dest/instrumentation/instrumentation.js +4 -9
  7. package/dest/native/fork_checkpoint.d.ts +7 -1
  8. package/dest/native/fork_checkpoint.d.ts.map +1 -1
  9. package/dest/native/fork_checkpoint.js +15 -3
  10. package/dest/native/index.d.ts +2 -1
  11. package/dest/native/index.d.ts.map +1 -1
  12. package/dest/native/index.js +1 -0
  13. package/dest/native/ipc_world_state_instance.d.ts +89 -0
  14. package/dest/native/ipc_world_state_instance.d.ts.map +1 -0
  15. package/dest/native/ipc_world_state_instance.js +670 -0
  16. package/dest/native/merkle_trees_facade.d.ts +12 -8
  17. package/dest/native/merkle_trees_facade.d.ts.map +1 -1
  18. package/dest/native/merkle_trees_facade.js +63 -115
  19. package/dest/native/message.d.ts +14 -221
  20. package/dest/native/message.d.ts.map +1 -1
  21. package/dest/native/message.js +0 -42
  22. package/dest/native/native_world_state.d.ts +19 -7
  23. package/dest/native/native_world_state.d.ts.map +1 -1
  24. package/dest/native/native_world_state.js +121 -59
  25. package/dest/native/native_world_state_instance.d.ts +56 -42
  26. package/dest/native/native_world_state_instance.d.ts.map +1 -1
  27. package/dest/native/native_world_state_instance.js +1 -203
  28. package/dest/native/world_state_operation.d.ts +7 -0
  29. package/dest/native/world_state_operation.d.ts.map +1 -0
  30. package/dest/native/world_state_operation.js +5 -0
  31. package/dest/synchronizer/config.d.ts +3 -3
  32. package/dest/synchronizer/config.d.ts.map +1 -1
  33. package/dest/synchronizer/config.js +15 -13
  34. package/dest/synchronizer/errors.d.ts +8 -1
  35. package/dest/synchronizer/errors.d.ts.map +1 -1
  36. package/dest/synchronizer/errors.js +8 -1
  37. package/dest/synchronizer/factory.d.ts +5 -5
  38. package/dest/synchronizer/factory.d.ts.map +1 -1
  39. package/dest/synchronizer/factory.js +7 -6
  40. package/dest/synchronizer/index.d.ts +2 -1
  41. package/dest/synchronizer/index.d.ts.map +1 -1
  42. package/dest/synchronizer/index.js +1 -0
  43. package/dest/synchronizer/server_world_state_synchronizer.d.ts +13 -8
  44. package/dest/synchronizer/server_world_state_synchronizer.d.ts.map +1 -1
  45. package/dest/synchronizer/server_world_state_synchronizer.js +133 -47
  46. package/dest/test/utils.d.ts +1 -1
  47. package/dest/test/utils.d.ts.map +1 -1
  48. package/dest/test/utils.js +6 -1
  49. package/dest/testing.d.ts +4 -3
  50. package/dest/testing.d.ts.map +1 -1
  51. package/dest/testing.js +22 -7
  52. package/dest/world-state-db/merkle_tree_db.d.ts +1 -10
  53. package/dest/world-state-db/merkle_tree_db.d.ts.map +1 -1
  54. package/package.json +13 -11
  55. package/src/index.ts +1 -0
  56. package/src/instrumentation/instrumentation.ts +6 -18
  57. package/src/native/fork_checkpoint.ts +19 -3
  58. package/src/native/index.ts +1 -0
  59. package/src/native/ipc_world_state_instance.ts +847 -0
  60. package/src/native/merkle_trees_facade.ts +89 -109
  61. package/src/native/message.ts +13 -286
  62. package/src/native/native_world_state.ts +145 -100
  63. package/src/native/native_world_state_instance.ts +94 -281
  64. package/src/native/world_state_operation.ts +33 -0
  65. package/src/synchronizer/config.ts +21 -15
  66. package/src/synchronizer/errors.ts +8 -0
  67. package/src/synchronizer/factory.ts +12 -11
  68. package/src/synchronizer/index.ts +1 -0
  69. package/src/synchronizer/server_world_state_synchronizer.ts +152 -42
  70. package/src/test/utils.ts +10 -1
  71. package/src/testing.ts +19 -10
  72. package/src/world-state-db/merkle_tree_db.ts +0 -10
  73. package/dest/native/world_state_ops_queue.d.ts +0 -19
  74. package/dest/native/world_state_ops_queue.d.ts.map +0 -1
  75. package/dest/native/world_state_ops_queue.js +0 -146
  76. package/src/native/world_state_ops_queue.ts +0 -190
@@ -1,59 +1,7 @@
1
1
  import { BlockNumber } from '@aztec/foundation/branded-types';
2
2
  import { Fr } from '@aztec/foundation/curves/bn254';
3
- import type { Tuple } from '@aztec/foundation/serialize';
4
3
  import { AppendOnlyTreeSnapshot, MerkleTreeId } from '@aztec/stdlib/trees';
5
4
  import type { StateReference } from '@aztec/stdlib/tx';
6
- import type { UInt32 } from '@aztec/stdlib/types';
7
- import type { WorldStateRevision } from '@aztec/stdlib/world-state';
8
-
9
- export enum WorldStateMessageType {
10
- GET_TREE_INFO = 100,
11
- GET_STATE_REFERENCE,
12
- GET_INITIAL_STATE_REFERENCE,
13
-
14
- GET_LEAF_VALUE,
15
- GET_LEAF_PREIMAGE,
16
- GET_SIBLING_PATH,
17
- GET_BLOCK_NUMBERS_FOR_LEAF_INDICES,
18
-
19
- FIND_LEAF_INDICES,
20
- FIND_LOW_LEAF,
21
- FIND_SIBLING_PATHS,
22
-
23
- APPEND_LEAVES,
24
- BATCH_INSERT,
25
- SEQUENTIAL_INSERT,
26
-
27
- UPDATE_ARCHIVE,
28
-
29
- COMMIT,
30
- ROLLBACK,
31
-
32
- SYNC_BLOCK,
33
-
34
- CREATE_FORK,
35
- DELETE_FORK,
36
-
37
- FINALIZE_BLOCKS,
38
- UNWIND_BLOCKS,
39
- REMOVE_HISTORICAL_BLOCKS,
40
-
41
- GET_STATUS,
42
-
43
- CREATE_CHECKPOINT,
44
- COMMIT_CHECKPOINT,
45
- REVERT_CHECKPOINT,
46
- COMMIT_ALL_CHECKPOINTS,
47
- REVERT_ALL_CHECKPOINTS,
48
-
49
- COPY_STORES,
50
-
51
- CLOSE = 999,
52
- }
53
-
54
- interface WithTreeId {
55
- treeId: MerkleTreeId;
56
- }
57
5
 
58
6
  export interface WorldStateStatusSummary {
59
7
  /** Last block number that can still be unwound. */
@@ -279,22 +227,6 @@ export function sanitizeFullStatus(status: WorldStateStatusFull) {
279
227
  return status;
280
228
  }
281
229
 
282
- interface WithForkId {
283
- forkId: number;
284
- }
285
-
286
- interface WithWorldStateRevision {
287
- revision: WorldStateRevision;
288
- }
289
-
290
- interface WithCanonicalForkId {
291
- canonical: true;
292
- }
293
-
294
- interface WithLeafIndex {
295
- leafIndex: bigint;
296
- }
297
-
298
230
  export type SerializedLeafValue =
299
231
  | Buffer // Fr
300
232
  | { nullifier: Buffer } // NullifierLeaf
@@ -306,241 +238,36 @@ export type SerializedIndexedLeaf = {
306
238
  nextKey: Buffer; // Fr
307
239
  };
308
240
 
309
- interface WithLeafValues {
310
- leaves: SerializedLeafValue[];
311
- }
312
-
313
- interface BlockShiftRequest extends WithCanonicalForkId {
314
- toBlockNumber: BlockNumber;
315
- }
316
-
317
- interface WithLeaves {
318
- leaves: SerializedLeafValue[];
319
- }
320
-
321
- interface GetTreeInfoRequest extends WithTreeId, WithWorldStateRevision {}
322
- interface GetTreeInfoResponse {
323
- treeId: MerkleTreeId;
324
- depth: UInt32;
325
- size: bigint | number;
326
- root: Buffer;
327
- }
328
-
329
- interface GetBlockNumbersForLeafIndicesRequest extends WithTreeId, WithWorldStateRevision {
330
- leafIndices: bigint[];
331
- }
332
-
333
- interface GetBlockNumbersForLeafIndicesResponse {
334
- blockNumbers: bigint[];
335
- }
336
-
337
- interface GetSiblingPathRequest extends WithTreeId, WithLeafIndex, WithWorldStateRevision {}
338
- type GetSiblingPathResponse = Buffer[];
339
-
340
- interface GetStateReferenceRequest extends WithWorldStateRevision {}
341
- interface GetStateReferenceResponse {
342
- state: Record<MerkleTreeId, TreeStateReference>;
343
- }
344
-
345
- interface GetLeafRequest extends WithTreeId, WithWorldStateRevision, WithLeafIndex {}
346
- type GetLeafResponse = SerializedLeafValue | undefined;
347
-
348
- interface GetLeafPreImageRequest extends WithTreeId, WithLeafIndex, WithWorldStateRevision {}
349
- type GetLeafPreImageResponse = SerializedIndexedLeaf | undefined;
350
-
351
- interface FindLeafIndicesRequest extends WithTreeId, WithLeafValues, WithWorldStateRevision {
352
- startIndex: bigint;
353
- }
354
- interface FindLeafIndicesResponse {
355
- indices: bigint[];
356
- }
357
-
358
- interface FindSiblingPathsRequest extends WithTreeId, WithLeafValues, WithWorldStateRevision {}
359
-
360
- interface SiblingPathAndIndex {
241
+ export interface SerializedSiblingPathAndIndex {
361
242
  index: bigint;
362
243
  path: Buffer[];
363
244
  }
364
- interface FindSiblingPathsResponse {
365
- paths: (SiblingPathAndIndex | undefined)[];
366
- }
367
-
368
- interface FindLowLeafRequest extends WithTreeId, WithWorldStateRevision {
369
- key: Fr;
370
- }
371
- interface FindLowLeafResponse {
372
- index: bigint | number;
373
- alreadyPresent: boolean;
374
- }
375
-
376
- interface AppendLeavesRequest extends WithTreeId, WithForkId, WithLeaves {}
377
245
 
378
- interface BatchInsertRequest extends WithTreeId, WithForkId, WithLeaves {
379
- subtreeDepth: number;
380
- }
381
-
382
- interface BatchInsertResponse {
383
- low_leaf_witness_data: ReadonlyArray<{
246
+ export interface SerializedBatchInsertionResult {
247
+ lowLeafWitnessData: ReadonlyArray<{
384
248
  leaf: SerializedIndexedLeaf;
385
249
  index: bigint | number;
386
- path: Tuple<Buffer, number>;
250
+ path: Buffer[];
387
251
  }>;
388
- sorted_leaves: ReadonlyArray<[SerializedLeafValue, UInt32]>;
389
- subtree_path: Tuple<Buffer, number>;
252
+ sortedLeaves: ReadonlyArray<readonly [SerializedLeafValue, number]>;
253
+ subtreePath: Buffer[];
390
254
  }
391
255
 
392
- interface SequentialInsertRequest extends WithTreeId, WithForkId, WithLeaves {}
393
-
394
- interface SequentialInsertResponse {
395
- low_leaf_witness_data: ReadonlyArray<{
256
+ export interface SerializedSequentialInsertionResult {
257
+ lowLeafWitnessData: ReadonlyArray<{
396
258
  leaf: SerializedIndexedLeaf;
397
259
  index: bigint | number;
398
- path: Tuple<Buffer, number>;
260
+ path: Buffer[];
399
261
  }>;
400
- insertion_witness_data: ReadonlyArray<{
262
+ insertionWitnessData: ReadonlyArray<{
401
263
  leaf: SerializedIndexedLeaf;
402
264
  index: bigint | number;
403
- path: Tuple<Buffer, number>;
265
+ path: Buffer[];
404
266
  }>;
405
267
  }
406
268
 
407
- interface UpdateArchiveRequest extends WithForkId {
408
- blockStateRef: BlockStateReference;
409
- blockHeaderHash: Buffer;
410
- }
411
-
412
- interface SyncBlockRequest extends WithCanonicalForkId {
413
- blockNumber: BlockNumber;
414
- blockStateRef: BlockStateReference;
415
- blockHeaderHash: Fr;
416
- paddedNoteHashes: readonly SerializedLeafValue[];
417
- paddedL1ToL2Messages: readonly SerializedLeafValue[];
418
- paddedNullifiers: readonly SerializedLeafValue[];
419
- publicDataWrites: readonly SerializedLeafValue[];
420
- }
421
-
422
- interface CreateForkRequest extends WithCanonicalForkId {
423
- latest: boolean;
424
- blockNumber: BlockNumber;
425
- }
426
-
427
- interface CreateForkResponse {
428
- forkId: number;
429
- }
430
-
431
- interface DeleteForkRequest extends WithForkId {}
432
-
433
- interface CopyStoresRequest extends WithCanonicalForkId {
434
- dstPath: string;
435
- compact: boolean;
436
- }
437
-
438
- export type WorldStateRequestCategories = WithForkId | WithWorldStateRevision | WithCanonicalForkId;
439
-
440
- export function isWithForkId(body: WorldStateRequestCategories): body is WithForkId {
441
- return body && 'forkId' in body;
442
- }
443
-
444
- export function isWithRevision(body: WorldStateRequestCategories): body is WithWorldStateRevision {
445
- return body && 'revision' in body;
446
- }
447
-
448
- export function isWithCanonical(body: WorldStateRequestCategories): body is WithCanonicalForkId {
449
- return body && 'canonical' in body;
450
- }
451
-
452
- export type WorldStateRequest = {
453
- [WorldStateMessageType.GET_TREE_INFO]: GetTreeInfoRequest;
454
- [WorldStateMessageType.GET_STATE_REFERENCE]: GetStateReferenceRequest;
455
- [WorldStateMessageType.GET_INITIAL_STATE_REFERENCE]: WithCanonicalForkId;
456
-
457
- [WorldStateMessageType.GET_LEAF_VALUE]: GetLeafRequest;
458
- [WorldStateMessageType.GET_LEAF_PREIMAGE]: GetLeafPreImageRequest;
459
- [WorldStateMessageType.GET_SIBLING_PATH]: GetSiblingPathRequest;
460
- [WorldStateMessageType.GET_BLOCK_NUMBERS_FOR_LEAF_INDICES]: GetBlockNumbersForLeafIndicesRequest;
461
-
462
- [WorldStateMessageType.FIND_LEAF_INDICES]: FindLeafIndicesRequest;
463
- [WorldStateMessageType.FIND_LOW_LEAF]: FindLowLeafRequest;
464
- [WorldStateMessageType.FIND_SIBLING_PATHS]: FindSiblingPathsRequest;
465
-
466
- [WorldStateMessageType.APPEND_LEAVES]: AppendLeavesRequest;
467
- [WorldStateMessageType.BATCH_INSERT]: BatchInsertRequest;
468
- [WorldStateMessageType.SEQUENTIAL_INSERT]: SequentialInsertRequest;
469
-
470
- [WorldStateMessageType.UPDATE_ARCHIVE]: UpdateArchiveRequest;
471
-
472
- [WorldStateMessageType.COMMIT]: WithCanonicalForkId;
473
- [WorldStateMessageType.ROLLBACK]: WithCanonicalForkId;
474
-
475
- [WorldStateMessageType.SYNC_BLOCK]: SyncBlockRequest;
476
-
477
- [WorldStateMessageType.CREATE_FORK]: CreateForkRequest;
478
- [WorldStateMessageType.DELETE_FORK]: DeleteForkRequest;
479
-
480
- [WorldStateMessageType.REMOVE_HISTORICAL_BLOCKS]: BlockShiftRequest;
481
- [WorldStateMessageType.UNWIND_BLOCKS]: BlockShiftRequest;
482
- [WorldStateMessageType.FINALIZE_BLOCKS]: BlockShiftRequest;
483
-
484
- [WorldStateMessageType.GET_STATUS]: WithCanonicalForkId;
485
-
486
- [WorldStateMessageType.CREATE_CHECKPOINT]: WithForkId;
487
- [WorldStateMessageType.COMMIT_CHECKPOINT]: WithForkId;
488
- [WorldStateMessageType.REVERT_CHECKPOINT]: WithForkId;
489
- [WorldStateMessageType.COMMIT_ALL_CHECKPOINTS]: WithForkId;
490
- [WorldStateMessageType.REVERT_ALL_CHECKPOINTS]: WithForkId;
491
-
492
- [WorldStateMessageType.COPY_STORES]: CopyStoresRequest;
493
-
494
- [WorldStateMessageType.CLOSE]: WithCanonicalForkId;
495
- };
496
-
497
- export type WorldStateResponse = {
498
- [WorldStateMessageType.GET_TREE_INFO]: GetTreeInfoResponse;
499
- [WorldStateMessageType.GET_STATE_REFERENCE]: GetStateReferenceResponse;
500
- [WorldStateMessageType.GET_INITIAL_STATE_REFERENCE]: GetStateReferenceResponse;
501
-
502
- [WorldStateMessageType.GET_LEAF_VALUE]: GetLeafResponse;
503
- [WorldStateMessageType.GET_LEAF_PREIMAGE]: GetLeafPreImageResponse;
504
- [WorldStateMessageType.GET_SIBLING_PATH]: GetSiblingPathResponse;
505
- [WorldStateMessageType.GET_BLOCK_NUMBERS_FOR_LEAF_INDICES]: GetBlockNumbersForLeafIndicesResponse;
506
-
507
- [WorldStateMessageType.FIND_LEAF_INDICES]: FindLeafIndicesResponse;
508
- [WorldStateMessageType.FIND_LOW_LEAF]: FindLowLeafResponse;
509
- [WorldStateMessageType.FIND_SIBLING_PATHS]: FindSiblingPathsResponse;
510
-
511
- [WorldStateMessageType.APPEND_LEAVES]: void;
512
- [WorldStateMessageType.BATCH_INSERT]: BatchInsertResponse;
513
- [WorldStateMessageType.SEQUENTIAL_INSERT]: SequentialInsertResponse;
514
-
515
- [WorldStateMessageType.UPDATE_ARCHIVE]: void;
516
-
517
- [WorldStateMessageType.COMMIT]: void;
518
- [WorldStateMessageType.ROLLBACK]: void;
519
-
520
- [WorldStateMessageType.SYNC_BLOCK]: WorldStateStatusFull;
521
-
522
- [WorldStateMessageType.CREATE_FORK]: CreateForkResponse;
523
- [WorldStateMessageType.DELETE_FORK]: void;
524
-
525
- [WorldStateMessageType.REMOVE_HISTORICAL_BLOCKS]: WorldStateStatusFull;
526
- [WorldStateMessageType.UNWIND_BLOCKS]: WorldStateStatusFull;
527
- [WorldStateMessageType.FINALIZE_BLOCKS]: WorldStateStatusSummary;
528
-
529
- [WorldStateMessageType.GET_STATUS]: WorldStateStatusSummary;
530
-
531
- [WorldStateMessageType.CREATE_CHECKPOINT]: void;
532
- [WorldStateMessageType.COMMIT_CHECKPOINT]: void;
533
- [WorldStateMessageType.REVERT_CHECKPOINT]: void;
534
- [WorldStateMessageType.COMMIT_ALL_CHECKPOINTS]: void;
535
- [WorldStateMessageType.REVERT_ALL_CHECKPOINTS]: void;
536
-
537
- [WorldStateMessageType.COPY_STORES]: void;
538
-
539
- [WorldStateMessageType.CLOSE]: void;
540
- };
541
-
542
- type TreeStateReference = readonly [Buffer, number | bigint];
543
- type BlockStateReference = Map<Exclude<MerkleTreeId, MerkleTreeId.ARCHIVE>, TreeStateReference>;
269
+ export type TreeStateReference = readonly [Buffer, number | bigint];
270
+ export type BlockStateReference = Map<Exclude<MerkleTreeId, MerkleTreeId.ARCHIVE>, TreeStateReference>;
544
271
 
545
272
  export function treeStateReferenceToSnapshot([root, size]: TreeStateReference): AppendOnlyTreeSnapshot {
546
273
  return new AppendOnlyTreeSnapshot(Fr.fromBuffer(root), Number(size));