@aztec/world-state 0.0.1-commit.4d3c002 → 0.0.1-commit.4d9804df

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