@aztec/world-state 0.0.0-test.0 → 0.0.1-commit.0208eb9

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 +25 -41
  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 +76 -14
  14. package/dest/native/message.d.ts +74 -52
  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 +27 -19
  18. package/dest/native/native_world_state.d.ts.map +1 -1
  19. package/dest/native/native_world_state.js +103 -41
  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 -4
  27. package/dest/synchronizer/config.d.ts.map +1 -1
  28. package/dest/synchronizer/config.js +27 -7
  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 +11 -3
  33. package/dest/synchronizer/factory.d.ts.map +1 -1
  34. package/dest/synchronizer/factory.js +13 -8
  35. package/dest/synchronizer/index.d.ts +1 -1
  36. package/dest/synchronizer/server_world_state_synchronizer.d.ts +21 -31
  37. package/dest/synchronizer/server_world_state_synchronizer.d.ts.map +1 -1
  38. package/dest/synchronizer/server_world_state_synchronizer.js +144 -92
  39. package/dest/test/index.d.ts +1 -1
  40. package/dest/test/utils.d.ts +12 -5
  41. package/dest/test/utils.d.ts.map +1 -1
  42. package/dest/test/utils.js +54 -47
  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 +31 -43
  51. package/src/native/bench_metrics.ts +91 -0
  52. package/src/native/merkle_trees_facade.ts +83 -18
  53. package/src/native/message.ts +94 -74
  54. package/src/native/native_world_state.ts +132 -52
  55. package/src/native/native_world_state_instance.ts +62 -9
  56. package/src/native/world_state_ops_queue.ts +1 -1
  57. package/src/synchronizer/config.ts +48 -16
  58. package/src/synchronizer/errors.ts +5 -0
  59. package/src/synchronizer/factory.ts +38 -9
  60. package/src/synchronizer/server_world_state_synchronizer.ts +170 -117
  61. package/src/test/utils.ts +92 -82
  62. package/src/testing.ts +4 -8
  63. package/src/world-state-db/merkle_tree_db.ts +16 -8
@@ -1,5 +1,8 @@
1
- import { Fr } from '@aztec/foundation/fields';
1
+ import { BlockNumber } from '@aztec/foundation/branded-types';
2
+ import { Fr } from '@aztec/foundation/curves/bn254';
3
+ import { createLogger } from '@aztec/foundation/log';
2
4
  import { serializeToBuffer } from '@aztec/foundation/serialize';
5
+ import { sleep } from '@aztec/foundation/sleep';
3
6
  import { type IndexedTreeLeafPreimage, SiblingPath } from '@aztec/foundation/trees';
4
7
  import type {
5
8
  BatchInsertionResult,
@@ -18,6 +21,7 @@ import {
18
21
  PublicDataTreeLeafPreimage,
19
22
  } from '@aztec/stdlib/trees';
20
23
  import { type BlockHeader, PartialStateReference, StateReference } from '@aztec/stdlib/tx';
24
+ import { type WorldStateRevision, WorldStateRevisionWithHandle } from '@aztec/stdlib/world-state';
21
25
 
22
26
  import assert from 'assert';
23
27
 
@@ -25,7 +29,6 @@ import {
25
29
  type SerializedIndexedLeaf,
26
30
  type SerializedLeafValue,
27
31
  WorldStateMessageType,
28
- type WorldStateRevision,
29
32
  blockStateReference,
30
33
  treeStateReferenceToSnapshot,
31
34
  } from './message.js';
@@ -42,10 +45,32 @@ export class MerkleTreesFacade implements MerkleTreeReadOperations {
42
45
  return this.initialHeader;
43
46
  }
44
47
 
48
+ getRevision(): WorldStateRevisionWithHandle {
49
+ return WorldStateRevisionWithHandle.fromWorldStateRevision(this.revision, this.instance.getHandle());
50
+ }
51
+
45
52
  findLeafIndices(treeId: MerkleTreeId, values: MerkleTreeLeafType<MerkleTreeId>[]): Promise<(bigint | undefined)[]> {
46
53
  return this.findLeafIndicesAfter(treeId, values, 0n);
47
54
  }
48
55
 
56
+ async findSiblingPaths<N extends number>(
57
+ treeId: MerkleTreeId,
58
+ values: MerkleTreeLeafType<MerkleTreeId>[],
59
+ ): Promise<({ path: SiblingPath<N>; index: bigint } | undefined)[]> {
60
+ const response = await this.instance.call(WorldStateMessageType.FIND_SIBLING_PATHS, {
61
+ leaves: values.map(leaf => serializeLeaf(hydrateLeaf(treeId, leaf))),
62
+ revision: this.revision,
63
+ treeId,
64
+ });
65
+
66
+ return response.paths.map(path => {
67
+ if (!path) {
68
+ return undefined;
69
+ }
70
+ return { path: new SiblingPath<N>(path.path.length as N, path.path), index: BigInt(path.index) };
71
+ });
72
+ }
73
+
49
74
  async findLeafIndicesAfter(
50
75
  treeId: MerkleTreeId,
51
76
  leaves: MerkleTreeLeafType<MerkleTreeId>[],
@@ -169,19 +194,26 @@ export class MerkleTreesFacade implements MerkleTreeReadOperations {
169
194
  async getBlockNumbersForLeafIndices<ID extends MerkleTreeId>(
170
195
  treeId: ID,
171
196
  leafIndices: bigint[],
172
- ): Promise<(bigint | undefined)[]> {
197
+ ): Promise<(BlockNumber | undefined)[]> {
173
198
  const response = await this.instance.call(WorldStateMessageType.GET_BLOCK_NUMBERS_FOR_LEAF_INDICES, {
174
199
  treeId,
175
200
  revision: this.revision,
176
201
  leafIndices,
177
202
  });
178
203
 
179
- return response.blockNumbers.map(x => (x === undefined || x === null ? undefined : BigInt(x)));
204
+ return response.blockNumbers.map(x => (x === undefined || x === null ? undefined : BlockNumber(Number(x))));
180
205
  }
181
206
  }
182
207
 
183
208
  export class MerkleTreesForkFacade extends MerkleTreesFacade implements MerkleTreeWriteOperations {
184
- constructor(instance: NativeWorldStateInstance, initialHeader: BlockHeader, revision: WorldStateRevision) {
209
+ private log = createLogger('world-state:merkle-trees-fork-facade');
210
+
211
+ constructor(
212
+ instance: NativeWorldStateInstance,
213
+ initialHeader: BlockHeader,
214
+ revision: WorldStateRevision,
215
+ private opts: { closeDelayMs?: number },
216
+ ) {
185
217
  assert.notEqual(revision.forkId, 0, 'Fork ID must be set');
186
218
  assert.equal(revision.includeUncommitted, true, 'Fork must include uncommitted data');
187
219
  super(instance, initialHeader, revision);
@@ -260,7 +292,31 @@ export class MerkleTreesForkFacade extends MerkleTreesFacade implements MerkleTr
260
292
 
261
293
  public async close(): Promise<void> {
262
294
  assert.notEqual(this.revision.forkId, 0, 'Fork ID must be set');
263
- await this.instance.call(WorldStateMessageType.DELETE_FORK, { forkId: this.revision.forkId });
295
+ try {
296
+ await this.instance.call(WorldStateMessageType.DELETE_FORK, { forkId: this.revision.forkId });
297
+ } catch (err: any) {
298
+ // Ignore errors due to native instance being closed during shutdown.
299
+ // This can happen when validators are still processing block proposals while the node is stopping.
300
+ if (err?.message === 'Native instance is closed') {
301
+ return;
302
+ }
303
+ throw err;
304
+ }
305
+ }
306
+
307
+ async [Symbol.dispose](): Promise<void> {
308
+ if (this.opts.closeDelayMs) {
309
+ void sleep(this.opts.closeDelayMs)
310
+ .then(() => this.close())
311
+ .catch(err => {
312
+ if (err && 'message' in err && err.message === 'Native instance is closed') {
313
+ return; // Ignore errors due to native instance being closed
314
+ }
315
+ this.log.warn('Error closing MerkleTreesForkFacade after delay', { err });
316
+ });
317
+ } else {
318
+ await this.close();
319
+ }
264
320
  }
265
321
 
266
322
  public async createCheckpoint(): Promise<void> {
@@ -277,6 +333,16 @@ export class MerkleTreesForkFacade extends MerkleTreesFacade implements MerkleTr
277
333
  assert.notEqual(this.revision.forkId, 0, 'Fork ID must be set');
278
334
  await this.instance.call(WorldStateMessageType.REVERT_CHECKPOINT, { forkId: this.revision.forkId });
279
335
  }
336
+
337
+ public async commitAllCheckpoints(): Promise<void> {
338
+ assert.notEqual(this.revision.forkId, 0, 'Fork ID must be set');
339
+ await this.instance.call(WorldStateMessageType.COMMIT_ALL_CHECKPOINTS, { forkId: this.revision.forkId });
340
+ }
341
+
342
+ public async revertAllCheckpoints(): Promise<void> {
343
+ assert.notEqual(this.revision.forkId, 0, 'Fork ID must be set');
344
+ await this.instance.call(WorldStateMessageType.REVERT_ALL_CHECKPOINTS, { forkId: this.revision.forkId });
345
+ }
280
346
  }
281
347
 
282
348
  function hydrateLeaf<ID extends MerkleTreeId>(treeId: ID, leaf: Fr | Buffer) {
@@ -295,7 +361,7 @@ export function serializeLeaf(leaf: Fr | NullifierLeaf | PublicDataTreeLeaf): Se
295
361
  if (leaf instanceof Fr) {
296
362
  return leaf.toBuffer();
297
363
  } else if (leaf instanceof NullifierLeaf) {
298
- return { value: leaf.nullifier.toBuffer() };
364
+ return { nullifier: leaf.nullifier.toBuffer() };
299
365
  } else {
300
366
  return { value: leaf.value.toBuffer(), slot: leaf.slot.toBuffer() };
301
367
  }
@@ -307,23 +373,22 @@ function deserializeLeafValue(leaf: SerializedLeafValue): Fr | NullifierLeaf | P
307
373
  } else if ('slot' in leaf) {
308
374
  return new PublicDataTreeLeaf(Fr.fromBuffer(leaf.slot), Fr.fromBuffer(leaf.value));
309
375
  } else {
310
- return new NullifierLeaf(Fr.fromBuffer(leaf.value));
376
+ return new NullifierLeaf(Fr.fromBuffer(leaf.nullifier));
311
377
  }
312
378
  }
313
379
 
314
- function deserializeIndexedLeaf(leaf: SerializedIndexedLeaf): IndexedTreeLeafPreimage {
315
- if ('slot' in leaf.value) {
380
+ function deserializeIndexedLeaf(leafPreimage: SerializedIndexedLeaf): IndexedTreeLeafPreimage {
381
+ if ('slot' in leafPreimage.leaf) {
316
382
  return new PublicDataTreeLeafPreimage(
317
- Fr.fromBuffer(leaf.value.slot),
318
- Fr.fromBuffer(leaf.value.value),
319
- Fr.fromBuffer(leaf.nextValue),
320
- BigInt(leaf.nextIndex),
383
+ new PublicDataTreeLeaf(Fr.fromBuffer(leafPreimage.leaf.slot), Fr.fromBuffer(leafPreimage.leaf.value)),
384
+ Fr.fromBuffer(leafPreimage.nextKey),
385
+ BigInt(leafPreimage.nextIndex),
321
386
  );
322
- } else if ('value' in leaf.value) {
387
+ } else if ('nullifier' in leafPreimage.leaf) {
323
388
  return new NullifierLeafPreimage(
324
- Fr.fromBuffer(leaf.value.value),
325
- Fr.fromBuffer(leaf.nextValue),
326
- BigInt(leaf.nextIndex),
389
+ new NullifierLeaf(Fr.fromBuffer(leafPreimage.leaf.nullifier)),
390
+ Fr.fromBuffer(leafPreimage.nextKey),
391
+ BigInt(leafPreimage.nextIndex),
327
392
  );
328
393
  } else {
329
394
  throw new Error('Invalid leaf type');
@@ -1,8 +1,11 @@
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';
4
+ import type { BlockHash } from '@aztec/stdlib/block';
3
5
  import { AppendOnlyTreeSnapshot, MerkleTreeId } from '@aztec/stdlib/trees';
4
6
  import type { StateReference } from '@aztec/stdlib/tx';
5
7
  import type { UInt32 } from '@aztec/stdlib/types';
8
+ import type { WorldStateRevision } from '@aztec/stdlib/world-state';
6
9
 
7
10
  export enum WorldStateMessageType {
8
11
  GET_TREE_INFO = 100,
@@ -16,6 +19,7 @@ export enum WorldStateMessageType {
16
19
 
17
20
  FIND_LEAF_INDICES,
18
21
  FIND_LOW_LEAF,
22
+ FIND_SIBLING_PATHS,
19
23
 
20
24
  APPEND_LEAVES,
21
25
  BATCH_INSERT,
@@ -31,7 +35,7 @@ export enum WorldStateMessageType {
31
35
  CREATE_FORK,
32
36
  DELETE_FORK,
33
37
 
34
- FINALISE_BLOCKS,
38
+ FINALIZE_BLOCKS,
35
39
  UNWIND_BLOCKS,
36
40
  REMOVE_HISTORICAL_BLOCKS,
37
41
 
@@ -40,6 +44,10 @@ export enum WorldStateMessageType {
40
44
  CREATE_CHECKPOINT,
41
45
  COMMIT_CHECKPOINT,
42
46
  REVERT_CHECKPOINT,
47
+ COMMIT_ALL_CHECKPOINTS,
48
+ REVERT_ALL_CHECKPOINTS,
49
+
50
+ COPY_STORES,
43
51
 
44
52
  CLOSE = 999,
45
53
  }
@@ -50,11 +58,11 @@ interface WithTreeId {
50
58
 
51
59
  export interface WorldStateStatusSummary {
52
60
  /** 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;
61
+ unfinalizedBlockNumber: BlockNumber;
62
+ /** Last block number that is finalized and cannot be unwound. */
63
+ finalizedBlockNumber: BlockNumber;
56
64
  /** Oldest block still available for historical queries and forks. */
57
- oldestHistoricalBlock: bigint;
65
+ oldestHistoricalBlock: BlockNumber;
58
66
  /** Whether the trees are in sync with each other */
59
67
  treesAreSynched: boolean;
60
68
  }
@@ -75,11 +83,11 @@ export interface TreeMeta {
75
83
  /** The tree's initial root value */
76
84
  initialRoot: Fr;
77
85
  /** 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;
86
+ oldestHistoricBlock: BlockNumber;
87
+ /** The current unfinalized block number of the tree */
88
+ unfinalizedBlockHeight: BlockNumber;
89
+ /** The current finalized block number of the tree */
90
+ finalizedBlockHeight: BlockNumber;
83
91
  }
84
92
 
85
93
  export interface DBStats {
@@ -94,6 +102,8 @@ export interface DBStats {
94
102
  export interface TreeDBStats {
95
103
  /** The configured max size of the DB mapping file (effectively the max possible size of the DB) */
96
104
  mapSize: bigint;
105
+ /** The physical file size of the database on disk */
106
+ physicalFileSize: bigint;
97
107
  /** Stats for the 'blocks' DB */
98
108
  blocksDBStats: DBStats;
99
109
  /** Stats for the 'nodes' DB */
@@ -149,6 +159,7 @@ export function buildEmptyDBStats() {
149
159
  export function buildEmptyTreeDBStats() {
150
160
  return {
151
161
  mapSize: 0n,
162
+ physicalFileSize: 0n,
152
163
  blocksDBStats: buildEmptyDBStats(),
153
164
  nodesDBStats: buildEmptyDBStats(),
154
165
  leafIndicesDBStats: buildEmptyDBStats(),
@@ -164,9 +175,9 @@ export function buildEmptyTreeMeta() {
164
175
  depth: 0,
165
176
  size: 0n,
166
177
  committedSize: 0n,
167
- unfinalisedBlockHeight: 0n,
168
- finalisedBlockHeight: 0n,
169
- oldestHistoricBlock: 0n,
178
+ unfinalizedBlockHeight: BlockNumber.ZERO,
179
+ finalizedBlockHeight: BlockNumber.ZERO,
180
+ oldestHistoricBlock: BlockNumber.ZERO,
170
181
  root: Fr.ZERO,
171
182
  initialRoot: Fr.ZERO,
172
183
  initialSize: 0n,
@@ -195,9 +206,9 @@ export function buildEmptyWorldStateDBStats() {
195
206
 
196
207
  export function buildEmptyWorldStateSummary() {
197
208
  return {
198
- unfinalisedBlockNumber: 0n,
199
- finalisedBlockNumber: 0n,
200
- oldestHistoricalBlock: 0n,
209
+ unfinalizedBlockNumber: BlockNumber.ZERO,
210
+ finalizedBlockNumber: BlockNumber.ZERO,
211
+ oldestHistoricalBlock: BlockNumber.ZERO,
201
212
  treesAreSynched: true,
202
213
  } as WorldStateStatusSummary;
203
214
  }
@@ -210,61 +221,62 @@ export function buildEmptyWorldStateStatusFull() {
210
221
  } as WorldStateStatusFull;
211
222
  }
212
223
 
213
- export function sanitiseSummary(summary: WorldStateStatusSummary) {
214
- summary.finalisedBlockNumber = BigInt(summary.finalisedBlockNumber);
215
- summary.unfinalisedBlockNumber = BigInt(summary.unfinalisedBlockNumber);
216
- summary.oldestHistoricalBlock = BigInt(summary.oldestHistoricalBlock);
224
+ export function sanitizeSummary(summary: WorldStateStatusSummary) {
225
+ summary.finalizedBlockNumber = BlockNumber.fromBigInt(BigInt(summary.finalizedBlockNumber));
226
+ summary.unfinalizedBlockNumber = BlockNumber.fromBigInt(BigInt(summary.unfinalizedBlockNumber));
227
+ summary.oldestHistoricalBlock = BlockNumber.fromBigInt(BigInt(summary.oldestHistoricalBlock));
217
228
  return summary;
218
229
  }
219
230
 
220
- export function sanitiseDBStats(stats: DBStats) {
231
+ export function sanitizeDBStats(stats: DBStats) {
221
232
  stats.numDataItems = BigInt(stats.numDataItems);
222
233
  stats.totalUsedSize = BigInt(stats.totalUsedSize);
223
234
  return stats;
224
235
  }
225
236
 
226
- export function sanitiseMeta(meta: TreeMeta) {
237
+ export function sanitizeMeta(meta: TreeMeta) {
227
238
  meta.committedSize = BigInt(meta.committedSize);
228
- meta.finalisedBlockHeight = BigInt(meta.finalisedBlockHeight);
239
+ meta.finalizedBlockHeight = BlockNumber.fromBigInt(BigInt(meta.finalizedBlockHeight));
229
240
  meta.initialSize = BigInt(meta.initialSize);
230
- meta.oldestHistoricBlock = BigInt(meta.oldestHistoricBlock);
241
+ meta.oldestHistoricBlock = BlockNumber.fromBigInt(BigInt(meta.oldestHistoricBlock));
231
242
  meta.size = BigInt(meta.size);
232
- meta.unfinalisedBlockHeight = BigInt(meta.unfinalisedBlockHeight);
243
+ meta.unfinalizedBlockHeight = BlockNumber.fromBigInt(BigInt(meta.unfinalizedBlockHeight));
233
244
  return meta;
234
245
  }
235
246
 
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);
247
+ export function sanitizeTreeDBStats(stats: TreeDBStats) {
248
+ stats.blocksDBStats = sanitizeDBStats(stats.blocksDBStats);
249
+ stats.leafIndicesDBStats = sanitizeDBStats(stats.leafIndicesDBStats);
250
+ stats.leafPreimagesDBStats = sanitizeDBStats(stats.leafPreimagesDBStats);
251
+ stats.blockIndicesDBStats = sanitizeDBStats(stats.blockIndicesDBStats);
252
+ stats.nodesDBStats = sanitizeDBStats(stats.nodesDBStats);
242
253
  stats.mapSize = BigInt(stats.mapSize);
254
+ stats.physicalFileSize = BigInt(stats.physicalFileSize);
243
255
  return stats;
244
256
  }
245
257
 
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);
258
+ export function sanitizeWorldStateDBStats(stats: WorldStateDBStats) {
259
+ stats.archiveTreeStats = sanitizeTreeDBStats(stats.archiveTreeStats);
260
+ stats.messageTreeStats = sanitizeTreeDBStats(stats.messageTreeStats);
261
+ stats.noteHashTreeStats = sanitizeTreeDBStats(stats.noteHashTreeStats);
262
+ stats.nullifierTreeStats = sanitizeTreeDBStats(stats.nullifierTreeStats);
263
+ stats.publicDataTreeStats = sanitizeTreeDBStats(stats.publicDataTreeStats);
252
264
  return stats;
253
265
  }
254
266
 
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);
267
+ export function sanitizeWorldStateTreeMeta(meta: WorldStateMeta) {
268
+ meta.archiveTreeMeta = sanitizeMeta(meta.archiveTreeMeta);
269
+ meta.messageTreeMeta = sanitizeMeta(meta.messageTreeMeta);
270
+ meta.noteHashTreeMeta = sanitizeMeta(meta.noteHashTreeMeta);
271
+ meta.nullifierTreeMeta = sanitizeMeta(meta.nullifierTreeMeta);
272
+ meta.publicDataTreeMeta = sanitizeMeta(meta.publicDataTreeMeta);
261
273
  return meta;
262
274
  }
263
275
 
264
- export function sanitiseFullStatus(status: WorldStateStatusFull) {
265
- status.dbStats = sanitiseWorldStateDBStats(status.dbStats);
266
- status.summary = sanitiseSummary(status.summary);
267
- status.meta = sanitiseWorldStateTreeMeta(status.meta);
276
+ export function sanitizeFullStatus(status: WorldStateStatusFull) {
277
+ status.dbStats = sanitizeWorldStateDBStats(status.dbStats);
278
+ status.summary = sanitizeSummary(status.summary);
279
+ status.meta = sanitizeWorldStateTreeMeta(status.meta);
268
280
  return status;
269
281
  }
270
282
 
@@ -286,13 +298,13 @@ interface WithLeafIndex {
286
298
 
287
299
  export type SerializedLeafValue =
288
300
  | Buffer // Fr
289
- | { value: Buffer } // NullifierLeaf
301
+ | { nullifier: Buffer } // NullifierLeaf
290
302
  | { value: Buffer; slot: Buffer }; // PublicDataTreeLeaf
291
303
 
292
304
  export type SerializedIndexedLeaf = {
293
- value: Exclude<SerializedLeafValue, Buffer>;
305
+ leaf: Exclude<SerializedLeafValue, Buffer>;
294
306
  nextIndex: bigint | number;
295
- nextValue: Buffer; // Fr
307
+ nextKey: Buffer; // Fr
296
308
  };
297
309
 
298
310
  interface WithLeafValues {
@@ -300,7 +312,7 @@ interface WithLeafValues {
300
312
  }
301
313
 
302
314
  interface BlockShiftRequest extends WithCanonicalForkId {
303
- toBlockNumber: bigint;
315
+ toBlockNumber: BlockNumber;
304
316
  }
305
317
 
306
318
  interface WithLeaves {
@@ -344,6 +356,16 @@ interface FindLeafIndicesResponse {
344
356
  indices: bigint[];
345
357
  }
346
358
 
359
+ interface FindSiblingPathsRequest extends WithTreeId, WithLeafValues, WithWorldStateRevision {}
360
+
361
+ interface SiblingPathAndIndex {
362
+ index: bigint;
363
+ path: Buffer[];
364
+ }
365
+ interface FindSiblingPathsResponse {
366
+ paths: (SiblingPathAndIndex | undefined)[];
367
+ }
368
+
347
369
  interface FindLowLeafRequest extends WithTreeId, WithWorldStateRevision {
348
370
  key: Fr;
349
371
  }
@@ -389,9 +411,9 @@ interface UpdateArchiveRequest extends WithForkId {
389
411
  }
390
412
 
391
413
  interface SyncBlockRequest extends WithCanonicalForkId {
392
- blockNumber: number;
414
+ blockNumber: BlockNumber;
393
415
  blockStateRef: BlockStateReference;
394
- blockHeaderHash: Fr;
416
+ blockHeaderHash: BlockHash;
395
417
  paddedNoteHashes: readonly SerializedLeafValue[];
396
418
  paddedL1ToL2Messages: readonly SerializedLeafValue[];
397
419
  paddedNullifiers: readonly SerializedLeafValue[];
@@ -400,7 +422,7 @@ interface SyncBlockRequest extends WithCanonicalForkId {
400
422
 
401
423
  interface CreateForkRequest extends WithCanonicalForkId {
402
424
  latest: boolean;
403
- blockNumber: number;
425
+ blockNumber: BlockNumber;
404
426
  }
405
427
 
406
428
  interface CreateForkResponse {
@@ -409,6 +431,11 @@ interface CreateForkResponse {
409
431
 
410
432
  interface DeleteForkRequest extends WithForkId {}
411
433
 
434
+ interface CopyStoresRequest extends WithCanonicalForkId {
435
+ dstPath: string;
436
+ compact: boolean;
437
+ }
438
+
412
439
  export type WorldStateRequestCategories = WithForkId | WithWorldStateRevision | WithCanonicalForkId;
413
440
 
414
441
  export function isWithForkId(body: WorldStateRequestCategories): body is WithForkId {
@@ -435,6 +462,7 @@ export type WorldStateRequest = {
435
462
 
436
463
  [WorldStateMessageType.FIND_LEAF_INDICES]: FindLeafIndicesRequest;
437
464
  [WorldStateMessageType.FIND_LOW_LEAF]: FindLowLeafRequest;
465
+ [WorldStateMessageType.FIND_SIBLING_PATHS]: FindSiblingPathsRequest;
438
466
 
439
467
  [WorldStateMessageType.APPEND_LEAVES]: AppendLeavesRequest;
440
468
  [WorldStateMessageType.BATCH_INSERT]: BatchInsertRequest;
@@ -452,13 +480,17 @@ export type WorldStateRequest = {
452
480
 
453
481
  [WorldStateMessageType.REMOVE_HISTORICAL_BLOCKS]: BlockShiftRequest;
454
482
  [WorldStateMessageType.UNWIND_BLOCKS]: BlockShiftRequest;
455
- [WorldStateMessageType.FINALISE_BLOCKS]: BlockShiftRequest;
483
+ [WorldStateMessageType.FINALIZE_BLOCKS]: BlockShiftRequest;
456
484
 
457
485
  [WorldStateMessageType.GET_STATUS]: WithCanonicalForkId;
458
486
 
459
487
  [WorldStateMessageType.CREATE_CHECKPOINT]: WithForkId;
460
488
  [WorldStateMessageType.COMMIT_CHECKPOINT]: WithForkId;
461
489
  [WorldStateMessageType.REVERT_CHECKPOINT]: WithForkId;
490
+ [WorldStateMessageType.COMMIT_ALL_CHECKPOINTS]: WithForkId;
491
+ [WorldStateMessageType.REVERT_ALL_CHECKPOINTS]: WithForkId;
492
+
493
+ [WorldStateMessageType.COPY_STORES]: CopyStoresRequest;
462
494
 
463
495
  [WorldStateMessageType.CLOSE]: WithCanonicalForkId;
464
496
  };
@@ -475,6 +507,7 @@ export type WorldStateResponse = {
475
507
 
476
508
  [WorldStateMessageType.FIND_LEAF_INDICES]: FindLeafIndicesResponse;
477
509
  [WorldStateMessageType.FIND_LOW_LEAF]: FindLowLeafResponse;
510
+ [WorldStateMessageType.FIND_SIBLING_PATHS]: FindSiblingPathsResponse;
478
511
 
479
512
  [WorldStateMessageType.APPEND_LEAVES]: void;
480
513
  [WorldStateMessageType.BATCH_INSERT]: BatchInsertResponse;
@@ -492,33 +525,20 @@ export type WorldStateResponse = {
492
525
 
493
526
  [WorldStateMessageType.REMOVE_HISTORICAL_BLOCKS]: WorldStateStatusFull;
494
527
  [WorldStateMessageType.UNWIND_BLOCKS]: WorldStateStatusFull;
495
- [WorldStateMessageType.FINALISE_BLOCKS]: WorldStateStatusSummary;
528
+ [WorldStateMessageType.FINALIZE_BLOCKS]: WorldStateStatusSummary;
496
529
 
497
530
  [WorldStateMessageType.GET_STATUS]: WorldStateStatusSummary;
498
531
 
499
532
  [WorldStateMessageType.CREATE_CHECKPOINT]: void;
500
533
  [WorldStateMessageType.COMMIT_CHECKPOINT]: void;
501
534
  [WorldStateMessageType.REVERT_CHECKPOINT]: void;
535
+ [WorldStateMessageType.COMMIT_ALL_CHECKPOINTS]: void;
536
+ [WorldStateMessageType.REVERT_ALL_CHECKPOINTS]: void;
502
537
 
503
- [WorldStateMessageType.CLOSE]: void;
504
- };
538
+ [WorldStateMessageType.COPY_STORES]: void;
505
539
 
506
- export type WorldStateRevision = {
507
- forkId: number;
508
- blockNumber: number;
509
- includeUncommitted: boolean;
540
+ [WorldStateMessageType.CLOSE]: void;
510
541
  };
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
542
 
523
543
  type TreeStateReference = readonly [Buffer, number | bigint];
524
544
  type BlockStateReference = Map<Exclude<MerkleTreeId, MerkleTreeId.ARCHIVE>, TreeStateReference>;