@aztec/world-state 0.0.1-commit.b2a5d0dd1 → 0.0.1-commit.b3d3157a

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