@aztec/world-state 0.0.1-commit.3469e52 → 0.0.1-commit.350e0a4d

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 (68) 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 +13 -11
  4. package/dest/native/fork_checkpoint.d.ts +7 -1
  5. package/dest/native/fork_checkpoint.d.ts.map +1 -1
  6. package/dest/native/fork_checkpoint.js +15 -3
  7. package/dest/native/ipc_world_state_instance.d.ts +89 -0
  8. package/dest/native/ipc_world_state_instance.d.ts.map +1 -0
  9. package/dest/native/ipc_world_state_instance.js +662 -0
  10. package/dest/native/merkle_trees_facade.d.ts +12 -8
  11. package/dest/native/merkle_trees_facade.d.ts.map +1 -1
  12. package/dest/native/merkle_trees_facade.js +63 -115
  13. package/dest/native/message.d.ts +14 -221
  14. package/dest/native/message.d.ts.map +1 -1
  15. package/dest/native/message.js +0 -42
  16. package/dest/native/native_world_state.d.ts +22 -10
  17. package/dest/native/native_world_state.d.ts.map +1 -1
  18. package/dest/native/native_world_state.js +118 -59
  19. package/dest/native/native_world_state_instance.d.ts +60 -41
  20. package/dest/native/native_world_state_instance.d.ts.map +1 -1
  21. package/dest/native/native_world_state_instance.js +5 -202
  22. package/dest/native/world_state_operation.d.ts +7 -0
  23. package/dest/native/world_state_operation.d.ts.map +1 -0
  24. package/dest/native/world_state_operation.js +5 -0
  25. package/dest/synchronizer/config.d.ts +3 -5
  26. package/dest/synchronizer/config.d.ts.map +1 -1
  27. package/dest/synchronizer/config.js +15 -18
  28. package/dest/synchronizer/errors.d.ts +8 -1
  29. package/dest/synchronizer/errors.d.ts.map +1 -1
  30. package/dest/synchronizer/errors.js +8 -1
  31. package/dest/synchronizer/factory.d.ts +6 -5
  32. package/dest/synchronizer/factory.d.ts.map +1 -1
  33. package/dest/synchronizer/factory.js +7 -6
  34. package/dest/synchronizer/index.d.ts +2 -1
  35. package/dest/synchronizer/index.d.ts.map +1 -1
  36. package/dest/synchronizer/index.js +1 -0
  37. package/dest/synchronizer/server_world_state_synchronizer.d.ts +13 -8
  38. package/dest/synchronizer/server_world_state_synchronizer.d.ts.map +1 -1
  39. package/dest/synchronizer/server_world_state_synchronizer.js +134 -49
  40. package/dest/test/utils.d.ts +6 -6
  41. package/dest/test/utils.d.ts.map +1 -1
  42. package/dest/test/utils.js +9 -4
  43. package/dest/testing.d.ts +4 -3
  44. package/dest/testing.d.ts.map +1 -1
  45. package/dest/testing.js +14 -7
  46. package/dest/world-state-db/merkle_tree_db.d.ts +3 -12
  47. package/dest/world-state-db/merkle_tree_db.d.ts.map +1 -1
  48. package/package.json +14 -11
  49. package/src/instrumentation/instrumentation.ts +15 -19
  50. package/src/native/fork_checkpoint.ts +19 -3
  51. package/src/native/ipc_world_state_instance.ts +834 -0
  52. package/src/native/merkle_trees_facade.ts +89 -109
  53. package/src/native/message.ts +13 -286
  54. package/src/native/native_world_state.ts +140 -93
  55. package/src/native/native_world_state_instance.ts +98 -278
  56. package/src/native/world_state_operation.ts +33 -0
  57. package/src/synchronizer/config.ts +16 -23
  58. package/src/synchronizer/errors.ts +8 -0
  59. package/src/synchronizer/factory.ts +18 -11
  60. package/src/synchronizer/index.ts +1 -0
  61. package/src/synchronizer/server_world_state_synchronizer.ts +156 -51
  62. package/src/test/utils.ts +14 -5
  63. package/src/testing.ts +12 -10
  64. package/src/world-state-db/merkle_tree_db.ts +2 -12
  65. package/dest/native/world_state_ops_queue.d.ts +0 -19
  66. package/dest/native/world_state_ops_queue.d.ts.map +0 -1
  67. package/dest/native/world_state_ops_queue.js +0 -146
  68. package/src/native/world_state_ops_queue.ts +0 -190
@@ -3,10 +3,9 @@ import { BlockNumber } from '@aztec/foundation/branded-types';
3
3
  import { fromEntries, padArrayEnd } from '@aztec/foundation/collection';
4
4
  import { Fr } from '@aztec/foundation/curves/bn254';
5
5
  import { EthAddress } from '@aztec/foundation/eth-address';
6
- import { tryRmDir } from '@aztec/foundation/fs';
7
- import { type Logger, createLogger } from '@aztec/foundation/log';
8
- import type { L2BlockNew } from '@aztec/stdlib/block';
9
- import { DatabaseVersionManager } from '@aztec/stdlib/database-version';
6
+ import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
7
+ import type { L2Block } from '@aztec/stdlib/block';
8
+ import { DatabaseVersionManager } from '@aztec/stdlib/database-version/manager';
10
9
  import type {
11
10
  IndexedTreeId,
12
11
  MerkleTreeReadOperations,
@@ -14,21 +13,21 @@ import type {
14
13
  } from '@aztec/stdlib/interfaces/server';
15
14
  import type { SnapshotDataKeys } from '@aztec/stdlib/snapshots';
16
15
  import { MerkleTreeId, NullifierLeaf, type NullifierLeafPreimage, PublicDataTreeLeaf } from '@aztec/stdlib/trees';
17
- import { BlockHeader, PartialStateReference, StateReference } from '@aztec/stdlib/tx';
18
- import { WorldStateRevision } from '@aztec/stdlib/world-state';
16
+ import { BlockHeader, GlobalVariables, PartialStateReference, StateReference } from '@aztec/stdlib/tx';
17
+ import { EMPTY_GENESIS_DATA, type GenesisData, WorldStateRevision } from '@aztec/stdlib/world-state';
19
18
  import { getTelemetryClient } from '@aztec/telemetry-client';
20
19
 
21
20
  import assert from 'assert/strict';
22
- import { mkdtemp, rm } from 'fs/promises';
21
+ import { mkdir, mkdtemp, rm } from 'fs/promises';
23
22
  import { tmpdir } from 'os';
24
23
  import { join } from 'path';
25
24
 
26
25
  import { WorldStateInstrumentation } from '../instrumentation/instrumentation.js';
27
26
  import type { WorldStateTreeMapSizes } from '../synchronizer/factory.js';
28
27
  import type { MerkleTreeAdminDatabase as MerkleTreeDatabase } from '../world-state-db/merkle_tree_db.js';
28
+ import { IpcWorldState } from './ipc_world_state_instance.js';
29
29
  import { MerkleTreesFacade, MerkleTreesForkFacade, serializeLeaf } from './merkle_trees_facade.js';
30
30
  import {
31
- WorldStateMessageType,
32
31
  type WorldStateStatusFull,
33
32
  type WorldStateStatusSummary,
34
33
  blockStateReference,
@@ -36,7 +35,7 @@ import {
36
35
  sanitizeSummary,
37
36
  treeStateReferenceToSnapshot,
38
37
  } from './message.js';
39
- import { NativeWorldState } from './native_world_state_instance.js';
38
+ import type { NativeWorldStateInstance } from './native_world_state_instance.js';
40
39
 
41
40
  // The current version of the world state database schema
42
41
  // Increment this when making incompatible changes to the database schema
@@ -50,34 +49,49 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
50
49
  private cachedStatusSummary: WorldStateStatusSummary | undefined;
51
50
 
52
51
  protected constructor(
53
- protected instance: NativeWorldState,
52
+ protected instance: NativeWorldStateInstance,
54
53
  protected readonly worldStateInstrumentation: WorldStateInstrumentation,
55
- protected readonly log: Logger = createLogger('world-state:database'),
54
+ protected readonly log: Logger,
55
+ private readonly genesis: GenesisData = EMPTY_GENESIS_DATA,
56
56
  private readonly cleanup = () => Promise.resolve(),
57
+ /** Factory to recreate a fresh IpcWorldState after clear(). */
58
+ private readonly recreateInstance?: () => Promise<NativeWorldStateInstance>,
57
59
  ) {}
58
60
 
59
61
  static async new(
60
62
  rollupAddress: EthAddress,
61
63
  dataDir: string,
62
64
  wsTreeMapSizes: WorldStateTreeMapSizes,
63
- prefilledPublicData: PublicDataTreeLeaf[] = [],
65
+ genesis: GenesisData = EMPTY_GENESIS_DATA,
64
66
  instrumentation = new WorldStateInstrumentation(getTelemetryClient()),
65
- log = createLogger('world-state:database'),
67
+ bindings?: LoggerBindings,
66
68
  cleanup = () => Promise.resolve(),
67
69
  ): Promise<NativeWorldStateService> {
70
+ for (const [key, value] of Object.entries(wsTreeMapSizes)) {
71
+ if (value <= 0) {
72
+ throw new Error(`Map size must be a positive number, got ${value} for ${key}`);
73
+ }
74
+ }
75
+
76
+ const log = createLogger('world-state:database', bindings);
68
77
  const worldStateDirectory = join(dataDir, WORLD_STATE_DIR);
69
- // Create a version manager to handle versioning
78
+
70
79
  const versionManager = new DatabaseVersionManager({
71
80
  schemaVersion: WORLD_STATE_DB_VERSION,
72
81
  rollupAddress,
73
82
  dataDirectory: worldStateDirectory,
74
- onOpen: (dir: string) => {
75
- return Promise.resolve(new NativeWorldState(dir, wsTreeMapSizes, prefilledPublicData, instrumentation));
76
- },
83
+ onOpen: dir => IpcWorldState.spawn(dir, wsTreeMapSizes, genesis, instrumentation, bindings),
77
84
  });
78
85
 
79
86
  const [instance] = await versionManager.open();
80
- const worldState = new this(instance, instrumentation, log, cleanup);
87
+
88
+ const recreateInstance = async () => {
89
+ await rm(worldStateDirectory, { recursive: true, force: true, maxRetries: 3 });
90
+ await mkdir(worldStateDirectory, { recursive: true });
91
+ return IpcWorldState.spawn(worldStateDirectory, wsTreeMapSizes, genesis, instrumentation, bindings);
92
+ };
93
+
94
+ const worldState = new this(instance, instrumentation, log, genesis, cleanup, recreateInstance);
81
95
  try {
82
96
  await worldState.init();
83
97
  } catch (e) {
@@ -89,14 +103,18 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
89
103
  }
90
104
 
91
105
  static async tmp(
92
- rollupAddress = EthAddress.ZERO,
93
106
  cleanupTmpDir = true,
94
- prefilledPublicData: PublicDataTreeLeaf[] = [],
107
+ genesis: GenesisData = EMPTY_GENESIS_DATA,
95
108
  instrumentation = new WorldStateInstrumentation(getTelemetryClient()),
109
+ bindings?: LoggerBindings,
96
110
  ): Promise<NativeWorldStateService> {
97
- const log = createLogger('world-state:database');
111
+ const log = createLogger('world-state:database', bindings);
98
112
  const dataDir = await mkdtemp(join(tmpdir(), 'aztec-world-state-'));
99
- const dbMapSizeKb = 10 * 1024 * 1024;
113
+ // Temporary (test/dev) world states are small and short-lived. Keep the LMDB
114
+ // map sizes in the MB range: with the IPC backend each tmp() spawns a separate
115
+ // aztec-wsdb that maps these per tree, and oversized maps add real cold-start
116
+ // I/O under parallel CI load. 256 MB/tree is ample for tests.
117
+ const dbMapSizeKb = 256 * 1024;
100
118
  const worldStateTreeMapSizes: WorldStateTreeMapSizes = {
101
119
  archiveTreeMapSizeKb: dbMapSizeKb,
102
120
  nullifierTreeMapSizeKb: dbMapSizeKb,
@@ -106,7 +124,8 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
106
124
  };
107
125
  log.debug(`Created temporary world state database at: ${dataDir} with tree map size: ${dbMapSizeKb}`);
108
126
 
109
- // pass a cleanup callback because process.on('beforeExit', cleanup) does not work under Jest
127
+ const instance = await IpcWorldState.spawn(dataDir, worldStateTreeMapSizes, genesis, instrumentation, bindings);
128
+
110
129
  const cleanup = async () => {
111
130
  if (cleanupTmpDir) {
112
131
  await rm(dataDir, { recursive: true, force: true, maxRetries: 3 });
@@ -116,7 +135,43 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
116
135
  }
117
136
  };
118
137
 
119
- return this.new(rollupAddress, dataDir, worldStateTreeMapSizes, prefilledPublicData, instrumentation, log, cleanup);
138
+ const recreateInstance = async () => {
139
+ await rm(dataDir, { recursive: true, force: true, maxRetries: 3 });
140
+ await mkdir(dataDir, { recursive: true });
141
+ return IpcWorldState.spawn(dataDir, worldStateTreeMapSizes, genesis, instrumentation, bindings);
142
+ };
143
+
144
+ const worldState = new this(instance, instrumentation, log, genesis, cleanup, recreateInstance);
145
+ try {
146
+ await worldState.init();
147
+ } catch (e) {
148
+ log.error(`Error initializing tmp world state: ${e}`);
149
+ throw e;
150
+ }
151
+ return worldState;
152
+ }
153
+
154
+ static ephemeral(
155
+ genesis: GenesisData = EMPTY_GENESIS_DATA,
156
+ instrumentation = new WorldStateInstrumentation(getTelemetryClient()),
157
+ bindings?: LoggerBindings,
158
+ ): Promise<NativeWorldStateService> {
159
+ return this.tmp(/*cleanupTmpDir=*/ true, genesis, instrumentation, bindings);
160
+ }
161
+
162
+ static async fromIpc(
163
+ wsdbBackend: ConstructorParameters<typeof IpcWorldState>[0],
164
+ instrumentation = new WorldStateInstrumentation(getTelemetryClient()),
165
+ bindings?: LoggerBindings,
166
+ genesis: GenesisData = EMPTY_GENESIS_DATA,
167
+ cleanup = () => Promise.resolve(),
168
+ recreateInstance?: () => Promise<NativeWorldStateInstance>,
169
+ ): Promise<NativeWorldStateService> {
170
+ const log = createLogger('world-state:database', bindings);
171
+ const instance = new IpcWorldState(wsdbBackend, instrumentation, bindings);
172
+ const worldState = new this(instance, instrumentation, log, genesis, cleanup, recreateInstance);
173
+ await worldState.init();
174
+ return worldState;
120
175
  }
121
176
 
122
177
  protected async init() {
@@ -140,11 +195,24 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
140
195
  assert.strictEqual(initialHeaderIndex, 0n, 'Invalid initial archive state');
141
196
  }
142
197
 
143
- public async clear() {
198
+ public async clear(): Promise<void> {
199
+ if (!this.recreateInstance) {
200
+ throw new Error('clear() is not available for externally-managed IPC backends');
201
+ }
202
+ this.log.warn('Clearing world state: shutting down WSDB, deleting data, and recreating');
144
203
  await this.instance.close();
145
204
  this.cachedStatusSummary = undefined;
146
- await tryRmDir(this.instance.getDataDir(), this.log);
147
- this.instance = this.instance.clone();
205
+ this.instance = await this.recreateInstance();
206
+ await this.init();
207
+ this.log.info('World state cleared and reinitialized from genesis');
208
+ }
209
+
210
+ /** Returns the IPC path of the underlying IPC backend, if available. */
211
+ public getIpcPath(): string {
212
+ if (this.instance instanceof IpcWorldState) {
213
+ return this.instance.getIpcPath();
214
+ }
215
+ throw new Error('getIpcPath() is only available with IPC world state');
148
216
  }
149
217
 
150
218
  public getCommitted(): MerkleTreeReadOperations {
@@ -163,17 +231,16 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
163
231
  blockNumber?: BlockNumber,
164
232
  opts: { closeDelayMs?: number } = {},
165
233
  ): Promise<MerkleTreeWriteOperations> {
166
- const resp = await this.instance.call(WorldStateMessageType.CREATE_FORK, {
234
+ const forkId = await this.instance.createFork({
167
235
  latest: blockNumber === undefined,
168
236
  blockNumber: blockNumber ?? BlockNumber.ZERO,
169
- canonical: true,
170
237
  });
171
238
  return new MerkleTreesForkFacade(
172
239
  this.instance,
173
240
  this.initialHeader!,
174
241
  new WorldStateRevision(
175
- /*forkId=*/ resp.forkId,
176
- /* blockNumber=*/ BlockNumber.ZERO,
242
+ /*forkId=*/ forkId,
243
+ /* blockNumber=*/ WorldStateRevision.LATEST,
177
244
  /* includeUncommitted=*/ true,
178
245
  ),
179
246
  opts,
@@ -184,7 +251,7 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
184
251
  return this.initialHeader!;
185
252
  }
186
253
 
187
- public async handleL2BlockAndMessages(l2Block: L2BlockNew, l1ToL2Messages: Fr[]): Promise<WorldStateStatusFull> {
254
+ public async handleL2BlockAndMessages(l2Block: L2Block, l1ToL2Messages: Fr[]): Promise<WorldStateStatusFull> {
188
255
  const isFirstBlock = l2Block.indexWithinCheckpoint === 0;
189
256
  if (!isFirstBlock && l1ToL2Messages.length > 0) {
190
257
  throw new Error(
@@ -216,35 +283,44 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
216
283
  });
217
284
 
218
285
  try {
219
- return await this.instance.call(
220
- WorldStateMessageType.SYNC_BLOCK,
221
- {
222
- blockNumber: l2Block.number,
223
- blockHeaderHash: await l2Block.hash(),
224
- paddedL1ToL2Messages: paddedL1ToL2Messages.map(serializeLeaf),
225
- paddedNoteHashes: paddedNoteHashes.map(serializeLeaf),
226
- paddedNullifiers: paddedNullifiers.map(serializeLeaf),
227
- publicDataWrites: publicDataWrites.map(serializeLeaf),
228
- blockStateRef: blockStateReference(l2Block.header.state),
229
- canonical: true,
230
- },
231
- this.sanitizeAndCacheSummaryFromFull.bind(this),
232
- this.deleteCachedSummary.bind(this),
233
- );
286
+ const status = await this.instance.syncBlock({
287
+ blockNumber: l2Block.number,
288
+ blockHeaderHash: (await l2Block.hash()).toBuffer(),
289
+ // Forwarded so the native sync verifies the archive root against canonical and rejects a divergent tree.
290
+ expectedArchiveRoot: l2Block.archive.root.toBuffer(),
291
+ expectedPreviousArchiveRoot: l2Block.header.lastArchive.root.toBuffer(),
292
+ paddedL1ToL2Messages: paddedL1ToL2Messages.map(serializeLeaf),
293
+ paddedNoteHashes: paddedNoteHashes.map(serializeLeaf),
294
+ paddedNullifiers: paddedNullifiers.map(serializeLeaf),
295
+ publicDataWrites: publicDataWrites.map(serializeLeaf),
296
+ blockStateRef: blockStateReference(l2Block.header.state),
297
+ });
298
+ return this.sanitizeAndCacheSummaryFromFull(status);
234
299
  } catch (err) {
300
+ this.deleteCachedSummary();
235
301
  this.worldStateInstrumentation.incCriticalErrors('synch_pending_block');
236
302
  throw err;
237
303
  }
238
304
  }
239
305
 
240
306
  public async close(): Promise<void> {
241
- await this.instance.close();
242
- await this.cleanup();
307
+ try {
308
+ await this.instance.close();
309
+ } finally {
310
+ await this.cleanup();
311
+ }
312
+ }
313
+
314
+ async [Symbol.asyncDispose](): Promise<void> {
315
+ await this.close();
243
316
  }
244
317
 
245
318
  private async buildInitialHeader(): Promise<BlockHeader> {
246
319
  const state = await this.getInitialStateReference();
247
- return BlockHeader.empty({ state });
320
+ return BlockHeader.empty({
321
+ state,
322
+ globalVariables: GlobalVariables.empty({ timestamp: this.genesis.genesisTimestamp }),
323
+ });
248
324
  }
249
325
 
250
326
  private sanitizeAndCacheSummaryFromFull(response: WorldStateStatusFull) {
@@ -259,7 +335,7 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
259
335
  return sanitized;
260
336
  }
261
337
 
262
- private deleteCachedSummary(_: string) {
338
+ private deleteCachedSummary() {
263
339
  this.cachedStatusSummary = undefined;
264
340
  }
265
341
 
@@ -270,16 +346,9 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
270
346
  */
271
347
  public async setFinalized(toBlockNumber: BlockNumber) {
272
348
  try {
273
- await this.instance.call(
274
- WorldStateMessageType.FINALIZE_BLOCKS,
275
- {
276
- toBlockNumber,
277
- canonical: true,
278
- },
279
- this.sanitizeAndCacheSummary.bind(this),
280
- this.deleteCachedSummary.bind(this),
281
- );
349
+ this.sanitizeAndCacheSummary(await this.instance.finalizeBlocks(toBlockNumber));
282
350
  } catch (err) {
351
+ this.deleteCachedSummary();
283
352
  this.worldStateInstrumentation.incCriticalErrors('finalize_block');
284
353
  throw err;
285
354
  }
@@ -293,16 +362,9 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
293
362
  */
294
363
  public async removeHistoricalBlocks(toBlockNumber: BlockNumber) {
295
364
  try {
296
- return await this.instance.call(
297
- WorldStateMessageType.REMOVE_HISTORICAL_BLOCKS,
298
- {
299
- toBlockNumber,
300
- canonical: true,
301
- },
302
- this.sanitizeAndCacheSummaryFromFull.bind(this),
303
- this.deleteCachedSummary.bind(this),
304
- );
365
+ return this.sanitizeAndCacheSummaryFromFull(await this.instance.removeHistoricalBlocks(toBlockNumber));
305
366
  } catch (err) {
367
+ this.deleteCachedSummary();
306
368
  this.worldStateInstrumentation.incCriticalErrors('prune_historical_block');
307
369
  throw err;
308
370
  }
@@ -315,16 +377,9 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
315
377
  */
316
378
  public async unwindBlocks(toBlockNumber: BlockNumber) {
317
379
  try {
318
- return await this.instance.call(
319
- WorldStateMessageType.UNWIND_BLOCKS,
320
- {
321
- toBlockNumber,
322
- canonical: true,
323
- },
324
- this.sanitizeAndCacheSummaryFromFull.bind(this),
325
- this.deleteCachedSummary.bind(this),
326
- );
380
+ return this.sanitizeAndCacheSummaryFromFull(await this.instance.unwindBlocks(toBlockNumber));
327
381
  } catch (err) {
382
+ this.deleteCachedSummary();
328
383
  this.worldStateInstrumentation.incCriticalErrors('prune_pending_block');
329
384
  throw err;
330
385
  }
@@ -334,11 +389,7 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
334
389
  if (this.cachedStatusSummary !== undefined) {
335
390
  return { ...this.cachedStatusSummary };
336
391
  }
337
- return await this.instance.call(
338
- WorldStateMessageType.GET_STATUS,
339
- { canonical: true },
340
- this.sanitizeAndCacheSummary.bind(this),
341
- );
392
+ return this.sanitizeAndCacheSummary(await this.instance.getStatus());
342
393
  }
343
394
 
344
395
  updateLeaf<ID extends IndexedTreeId>(
@@ -350,14 +401,14 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
350
401
  }
351
402
 
352
403
  private async getInitialStateReference(): Promise<StateReference> {
353
- const resp = await this.instance.call(WorldStateMessageType.GET_INITIAL_STATE_REFERENCE, { canonical: true });
404
+ const state = await this.instance.getInitialStateReference();
354
405
 
355
406
  return new StateReference(
356
- treeStateReferenceToSnapshot(resp.state[MerkleTreeId.L1_TO_L2_MESSAGE_TREE]),
407
+ treeStateReferenceToSnapshot(state[MerkleTreeId.L1_TO_L2_MESSAGE_TREE]),
357
408
  new PartialStateReference(
358
- treeStateReferenceToSnapshot(resp.state[MerkleTreeId.NOTE_HASH_TREE]),
359
- treeStateReferenceToSnapshot(resp.state[MerkleTreeId.NULLIFIER_TREE]),
360
- treeStateReferenceToSnapshot(resp.state[MerkleTreeId.PUBLIC_DATA_TREE]),
409
+ treeStateReferenceToSnapshot(state[MerkleTreeId.NOTE_HASH_TREE]),
410
+ treeStateReferenceToSnapshot(state[MerkleTreeId.NULLIFIER_TREE]),
411
+ treeStateReferenceToSnapshot(state[MerkleTreeId.PUBLIC_DATA_TREE]),
361
412
  ),
362
413
  );
363
414
  }
@@ -366,11 +417,7 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
366
417
  dstPath: string,
367
418
  compact: boolean = true,
368
419
  ): Promise<Record<Exclude<SnapshotDataKeys, 'archiver'>, string>> {
369
- await this.instance.call(WorldStateMessageType.COPY_STORES, {
370
- dstPath,
371
- compact,
372
- canonical: true,
373
- });
420
+ await this.instance.copyStores(dstPath, compact);
374
421
  return fromEntries(NATIVE_WORLD_STATE_DBS.map(([name, dir]) => [name, join(dstPath, dir, 'data.mdb')] as const));
375
422
  }
376
423
  }