@aztec/world-state 0.0.0-test.0 → 0.0.1-commit.001888fc

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 (65) 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 +7 -1
  9. package/dest/native/fork_checkpoint.d.ts.map +1 -1
  10. package/dest/native/fork_checkpoint.js +15 -3
  11. package/dest/native/index.d.ts +1 -1
  12. package/dest/native/merkle_trees_facade.d.ts +20 -8
  13. package/dest/native/merkle_trees_facade.d.ts.map +1 -1
  14. package/dest/native/merkle_trees_facade.js +80 -15
  15. package/dest/native/message.d.ts +83 -53
  16. package/dest/native/message.d.ts.map +1 -1
  17. package/dest/native/message.js +61 -61
  18. package/dest/native/native_world_state.d.ts +27 -19
  19. package/dest/native/native_world_state.d.ts.map +1 -1
  20. package/dest/native/native_world_state.js +103 -41
  21. package/dest/native/native_world_state_instance.d.ts +20 -4
  22. package/dest/native/native_world_state_instance.d.ts.map +1 -1
  23. package/dest/native/native_world_state_instance.js +43 -4
  24. package/dest/native/world_state_ops_queue.d.ts +1 -1
  25. package/dest/native/world_state_ops_queue.d.ts.map +1 -1
  26. package/dest/native/world_state_ops_queue.js +1 -1
  27. package/dest/synchronizer/config.d.ts +14 -6
  28. package/dest/synchronizer/config.d.ts.map +1 -1
  29. package/dest/synchronizer/config.js +33 -10
  30. package/dest/synchronizer/errors.d.ts +4 -0
  31. package/dest/synchronizer/errors.d.ts.map +1 -0
  32. package/dest/synchronizer/errors.js +5 -0
  33. package/dest/synchronizer/factory.d.ts +12 -4
  34. package/dest/synchronizer/factory.d.ts.map +1 -1
  35. package/dest/synchronizer/factory.js +13 -8
  36. package/dest/synchronizer/index.d.ts +1 -1
  37. package/dest/synchronizer/server_world_state_synchronizer.d.ts +21 -31
  38. package/dest/synchronizer/server_world_state_synchronizer.d.ts.map +1 -1
  39. package/dest/synchronizer/server_world_state_synchronizer.js +191 -96
  40. package/dest/test/index.d.ts +1 -1
  41. package/dest/test/utils.d.ts +12 -5
  42. package/dest/test/utils.d.ts.map +1 -1
  43. package/dest/test/utils.js +54 -47
  44. package/dest/testing.d.ts +3 -3
  45. package/dest/testing.d.ts.map +1 -1
  46. package/dest/testing.js +7 -11
  47. package/dest/world-state-db/index.d.ts +1 -1
  48. package/dest/world-state-db/merkle_tree_db.d.ts +12 -18
  49. package/dest/world-state-db/merkle_tree_db.d.ts.map +1 -1
  50. package/package.json +23 -24
  51. package/src/instrumentation/instrumentation.ts +31 -43
  52. package/src/native/bench_metrics.ts +91 -0
  53. package/src/native/fork_checkpoint.ts +19 -3
  54. package/src/native/merkle_trees_facade.ts +92 -20
  55. package/src/native/message.ts +105 -75
  56. package/src/native/native_world_state.ts +132 -52
  57. package/src/native/native_world_state_instance.ts +63 -10
  58. package/src/native/world_state_ops_queue.ts +1 -1
  59. package/src/synchronizer/config.ts +55 -21
  60. package/src/synchronizer/errors.ts +5 -0
  61. package/src/synchronizer/factory.ts +39 -10
  62. package/src/synchronizer/server_world_state_synchronizer.ts +227 -121
  63. package/src/test/utils.ts +92 -82
  64. package/src/testing.ts +4 -8
  65. package/src/world-state-db/merkle_tree_db.ts +16 -18
@@ -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,12 +292,37 @@ 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.asyncDispose](): 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
- public async createCheckpoint(): Promise<void> {
322
+ public async createCheckpoint(): Promise<number> {
267
323
  assert.notEqual(this.revision.forkId, 0, 'Fork ID must be set');
268
- await this.instance.call(WorldStateMessageType.CREATE_CHECKPOINT, { forkId: this.revision.forkId });
324
+ const resp = await this.instance.call(WorldStateMessageType.CREATE_CHECKPOINT, { forkId: this.revision.forkId });
325
+ return resp.depth;
269
326
  }
270
327
 
271
328
  public async commitCheckpoint(): Promise<void> {
@@ -277,6 +334,22 @@ export class MerkleTreesForkFacade extends MerkleTreesFacade implements MerkleTr
277
334
  assert.notEqual(this.revision.forkId, 0, 'Fork ID must be set');
278
335
  await this.instance.call(WorldStateMessageType.REVERT_CHECKPOINT, { forkId: this.revision.forkId });
279
336
  }
337
+
338
+ public async commitAllCheckpointsTo(depth: number): Promise<void> {
339
+ assert.notEqual(this.revision.forkId, 0, 'Fork ID must be set');
340
+ await this.instance.call(WorldStateMessageType.COMMIT_ALL_CHECKPOINTS, {
341
+ forkId: this.revision.forkId,
342
+ depth,
343
+ });
344
+ }
345
+
346
+ public async revertAllCheckpointsTo(depth: number): Promise<void> {
347
+ assert.notEqual(this.revision.forkId, 0, 'Fork ID must be set');
348
+ await this.instance.call(WorldStateMessageType.REVERT_ALL_CHECKPOINTS, {
349
+ forkId: this.revision.forkId,
350
+ depth,
351
+ });
352
+ }
280
353
  }
281
354
 
282
355
  function hydrateLeaf<ID extends MerkleTreeId>(treeId: ID, leaf: Fr | Buffer) {
@@ -295,7 +368,7 @@ export function serializeLeaf(leaf: Fr | NullifierLeaf | PublicDataTreeLeaf): Se
295
368
  if (leaf instanceof Fr) {
296
369
  return leaf.toBuffer();
297
370
  } else if (leaf instanceof NullifierLeaf) {
298
- return { value: leaf.nullifier.toBuffer() };
371
+ return { nullifier: leaf.nullifier.toBuffer() };
299
372
  } else {
300
373
  return { value: leaf.value.toBuffer(), slot: leaf.slot.toBuffer() };
301
374
  }
@@ -307,23 +380,22 @@ function deserializeLeafValue(leaf: SerializedLeafValue): Fr | NullifierLeaf | P
307
380
  } else if ('slot' in leaf) {
308
381
  return new PublicDataTreeLeaf(Fr.fromBuffer(leaf.slot), Fr.fromBuffer(leaf.value));
309
382
  } else {
310
- return new NullifierLeaf(Fr.fromBuffer(leaf.value));
383
+ return new NullifierLeaf(Fr.fromBuffer(leaf.nullifier));
311
384
  }
312
385
  }
313
386
 
314
- function deserializeIndexedLeaf(leaf: SerializedIndexedLeaf): IndexedTreeLeafPreimage {
315
- if ('slot' in leaf.value) {
387
+ function deserializeIndexedLeaf(leafPreimage: SerializedIndexedLeaf): IndexedTreeLeafPreimage {
388
+ if ('slot' in leafPreimage.leaf) {
316
389
  return new PublicDataTreeLeafPreimage(
317
- Fr.fromBuffer(leaf.value.slot),
318
- Fr.fromBuffer(leaf.value.value),
319
- Fr.fromBuffer(leaf.nextValue),
320
- BigInt(leaf.nextIndex),
390
+ new PublicDataTreeLeaf(Fr.fromBuffer(leafPreimage.leaf.slot), Fr.fromBuffer(leafPreimage.leaf.value)),
391
+ Fr.fromBuffer(leafPreimage.nextKey),
392
+ BigInt(leafPreimage.nextIndex),
321
393
  );
322
- } else if ('value' in leaf.value) {
394
+ } else if ('nullifier' in leafPreimage.leaf) {
323
395
  return new NullifierLeafPreimage(
324
- Fr.fromBuffer(leaf.value.value),
325
- Fr.fromBuffer(leaf.nextValue),
326
- BigInt(leaf.nextIndex),
396
+ new NullifierLeaf(Fr.fromBuffer(leafPreimage.leaf.nullifier)),
397
+ Fr.fromBuffer(leafPreimage.nextKey),
398
+ BigInt(leafPreimage.nextIndex),
327
399
  );
328
400
  } else {
329
401
  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
 
@@ -272,6 +284,16 @@ interface WithForkId {
272
284
  forkId: number;
273
285
  }
274
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
+
275
297
  interface WithWorldStateRevision {
276
298
  revision: WorldStateRevision;
277
299
  }
@@ -286,13 +308,13 @@ interface WithLeafIndex {
286
308
 
287
309
  export type SerializedLeafValue =
288
310
  | Buffer // Fr
289
- | { value: Buffer } // NullifierLeaf
311
+ | { nullifier: Buffer } // NullifierLeaf
290
312
  | { value: Buffer; slot: Buffer }; // PublicDataTreeLeaf
291
313
 
292
314
  export type SerializedIndexedLeaf = {
293
- value: Exclude<SerializedLeafValue, Buffer>;
315
+ leaf: Exclude<SerializedLeafValue, Buffer>;
294
316
  nextIndex: bigint | number;
295
- nextValue: Buffer; // Fr
317
+ nextKey: Buffer; // Fr
296
318
  };
297
319
 
298
320
  interface WithLeafValues {
@@ -300,7 +322,7 @@ interface WithLeafValues {
300
322
  }
301
323
 
302
324
  interface BlockShiftRequest extends WithCanonicalForkId {
303
- toBlockNumber: bigint;
325
+ toBlockNumber: BlockNumber;
304
326
  }
305
327
 
306
328
  interface WithLeaves {
@@ -344,6 +366,16 @@ interface FindLeafIndicesResponse {
344
366
  indices: bigint[];
345
367
  }
346
368
 
369
+ interface FindSiblingPathsRequest extends WithTreeId, WithLeafValues, WithWorldStateRevision {}
370
+
371
+ interface SiblingPathAndIndex {
372
+ index: bigint;
373
+ path: Buffer[];
374
+ }
375
+ interface FindSiblingPathsResponse {
376
+ paths: (SiblingPathAndIndex | undefined)[];
377
+ }
378
+
347
379
  interface FindLowLeafRequest extends WithTreeId, WithWorldStateRevision {
348
380
  key: Fr;
349
381
  }
@@ -389,9 +421,9 @@ interface UpdateArchiveRequest extends WithForkId {
389
421
  }
390
422
 
391
423
  interface SyncBlockRequest extends WithCanonicalForkId {
392
- blockNumber: number;
424
+ blockNumber: BlockNumber;
393
425
  blockStateRef: BlockStateReference;
394
- blockHeaderHash: Fr;
426
+ blockHeaderHash: BlockHash;
395
427
  paddedNoteHashes: readonly SerializedLeafValue[];
396
428
  paddedL1ToL2Messages: readonly SerializedLeafValue[];
397
429
  paddedNullifiers: readonly SerializedLeafValue[];
@@ -400,7 +432,7 @@ interface SyncBlockRequest extends WithCanonicalForkId {
400
432
 
401
433
  interface CreateForkRequest extends WithCanonicalForkId {
402
434
  latest: boolean;
403
- blockNumber: number;
435
+ blockNumber: BlockNumber;
404
436
  }
405
437
 
406
438
  interface CreateForkResponse {
@@ -409,6 +441,11 @@ interface CreateForkResponse {
409
441
 
410
442
  interface DeleteForkRequest extends WithForkId {}
411
443
 
444
+ interface CopyStoresRequest extends WithCanonicalForkId {
445
+ dstPath: string;
446
+ compact: boolean;
447
+ }
448
+
412
449
  export type WorldStateRequestCategories = WithForkId | WithWorldStateRevision | WithCanonicalForkId;
413
450
 
414
451
  export function isWithForkId(body: WorldStateRequestCategories): body is WithForkId {
@@ -435,6 +472,7 @@ export type WorldStateRequest = {
435
472
 
436
473
  [WorldStateMessageType.FIND_LEAF_INDICES]: FindLeafIndicesRequest;
437
474
  [WorldStateMessageType.FIND_LOW_LEAF]: FindLowLeafRequest;
475
+ [WorldStateMessageType.FIND_SIBLING_PATHS]: FindSiblingPathsRequest;
438
476
 
439
477
  [WorldStateMessageType.APPEND_LEAVES]: AppendLeavesRequest;
440
478
  [WorldStateMessageType.BATCH_INSERT]: BatchInsertRequest;
@@ -452,13 +490,17 @@ export type WorldStateRequest = {
452
490
 
453
491
  [WorldStateMessageType.REMOVE_HISTORICAL_BLOCKS]: BlockShiftRequest;
454
492
  [WorldStateMessageType.UNWIND_BLOCKS]: BlockShiftRequest;
455
- [WorldStateMessageType.FINALISE_BLOCKS]: BlockShiftRequest;
493
+ [WorldStateMessageType.FINALIZE_BLOCKS]: BlockShiftRequest;
456
494
 
457
495
  [WorldStateMessageType.GET_STATUS]: WithCanonicalForkId;
458
496
 
459
497
  [WorldStateMessageType.CREATE_CHECKPOINT]: WithForkId;
460
498
  [WorldStateMessageType.COMMIT_CHECKPOINT]: WithForkId;
461
499
  [WorldStateMessageType.REVERT_CHECKPOINT]: WithForkId;
500
+ [WorldStateMessageType.COMMIT_ALL_CHECKPOINTS]: CheckpointDepthRequest;
501
+ [WorldStateMessageType.REVERT_ALL_CHECKPOINTS]: CheckpointDepthRequest;
502
+
503
+ [WorldStateMessageType.COPY_STORES]: CopyStoresRequest;
462
504
 
463
505
  [WorldStateMessageType.CLOSE]: WithCanonicalForkId;
464
506
  };
@@ -475,6 +517,7 @@ export type WorldStateResponse = {
475
517
 
476
518
  [WorldStateMessageType.FIND_LEAF_INDICES]: FindLeafIndicesResponse;
477
519
  [WorldStateMessageType.FIND_LOW_LEAF]: FindLowLeafResponse;
520
+ [WorldStateMessageType.FIND_SIBLING_PATHS]: FindSiblingPathsResponse;
478
521
 
479
522
  [WorldStateMessageType.APPEND_LEAVES]: void;
480
523
  [WorldStateMessageType.BATCH_INSERT]: BatchInsertResponse;
@@ -492,33 +535,20 @@ export type WorldStateResponse = {
492
535
 
493
536
  [WorldStateMessageType.REMOVE_HISTORICAL_BLOCKS]: WorldStateStatusFull;
494
537
  [WorldStateMessageType.UNWIND_BLOCKS]: WorldStateStatusFull;
495
- [WorldStateMessageType.FINALISE_BLOCKS]: WorldStateStatusSummary;
538
+ [WorldStateMessageType.FINALIZE_BLOCKS]: WorldStateStatusSummary;
496
539
 
497
540
  [WorldStateMessageType.GET_STATUS]: WorldStateStatusSummary;
498
541
 
499
- [WorldStateMessageType.CREATE_CHECKPOINT]: void;
542
+ [WorldStateMessageType.CREATE_CHECKPOINT]: CreateCheckpointResponse;
500
543
  [WorldStateMessageType.COMMIT_CHECKPOINT]: void;
501
544
  [WorldStateMessageType.REVERT_CHECKPOINT]: void;
545
+ [WorldStateMessageType.COMMIT_ALL_CHECKPOINTS]: void;
546
+ [WorldStateMessageType.REVERT_ALL_CHECKPOINTS]: void;
502
547
 
503
- [WorldStateMessageType.CLOSE]: void;
504
- };
548
+ [WorldStateMessageType.COPY_STORES]: void;
505
549
 
506
- export type WorldStateRevision = {
507
- forkId: number;
508
- blockNumber: number;
509
- includeUncommitted: boolean;
550
+ [WorldStateMessageType.CLOSE]: void;
510
551
  };
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
552
 
523
553
  type TreeStateReference = readonly [Buffer, number | bigint];
524
554
  type BlockStateReference = Map<Exclude<MerkleTreeId, MerkleTreeId.ARCHIVE>, TreeStateReference>;