@aztec/world-state 0.0.1-commit.993d52e → 0.0.1-commit.9a89641

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