@aztec/world-state 0.0.1-commit.c2eed6949 → 0.0.1-commit.c52d6e7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/dest/index.d.ts +2 -1
  2. package/dest/index.d.ts.map +1 -1
  3. package/dest/index.js +1 -0
  4. package/dest/instrumentation/instrumentation.d.ts +4 -3
  5. package/dest/instrumentation/instrumentation.d.ts.map +1 -1
  6. package/dest/instrumentation/instrumentation.js +4 -9
  7. package/dest/native/index.d.ts +2 -1
  8. package/dest/native/index.d.ts.map +1 -1
  9. package/dest/native/index.js +1 -0
  10. package/dest/native/ipc_world_state_instance.d.ts +89 -0
  11. package/dest/native/ipc_world_state_instance.d.ts.map +1 -0
  12. package/dest/native/ipc_world_state_instance.js +670 -0
  13. package/dest/native/merkle_trees_facade.d.ts +8 -4
  14. package/dest/native/merkle_trees_facade.d.ts.map +1 -1
  15. package/dest/native/merkle_trees_facade.js +60 -115
  16. package/dest/native/message.d.ts +14 -230
  17. package/dest/native/message.d.ts.map +1 -1
  18. package/dest/native/message.js +0 -42
  19. package/dest/native/native_world_state.d.ts +19 -7
  20. package/dest/native/native_world_state.d.ts.map +1 -1
  21. package/dest/native/native_world_state.js +120 -58
  22. package/dest/native/native_world_state_instance.d.ts +56 -42
  23. package/dest/native/native_world_state_instance.d.ts.map +1 -1
  24. package/dest/native/native_world_state_instance.js +1 -203
  25. package/dest/native/world_state_operation.d.ts +7 -0
  26. package/dest/native/world_state_operation.d.ts.map +1 -0
  27. package/dest/native/world_state_operation.js +5 -0
  28. package/dest/synchronizer/config.d.ts +1 -1
  29. package/dest/synchronizer/config.d.ts.map +1 -1
  30. package/dest/synchronizer/config.js +9 -10
  31. package/dest/synchronizer/errors.d.ts +8 -1
  32. package/dest/synchronizer/errors.d.ts.map +1 -1
  33. package/dest/synchronizer/errors.js +8 -1
  34. package/dest/synchronizer/factory.d.ts +4 -4
  35. package/dest/synchronizer/factory.d.ts.map +1 -1
  36. package/dest/synchronizer/factory.js +7 -6
  37. package/dest/synchronizer/index.d.ts +2 -1
  38. package/dest/synchronizer/index.d.ts.map +1 -1
  39. package/dest/synchronizer/index.js +1 -0
  40. package/dest/synchronizer/server_world_state_synchronizer.d.ts +11 -6
  41. package/dest/synchronizer/server_world_state_synchronizer.d.ts.map +1 -1
  42. package/dest/synchronizer/server_world_state_synchronizer.js +67 -40
  43. package/dest/test/utils.d.ts +1 -1
  44. package/dest/test/utils.d.ts.map +1 -1
  45. package/dest/test/utils.js +6 -1
  46. package/dest/testing.d.ts +4 -3
  47. package/dest/testing.d.ts.map +1 -1
  48. package/dest/testing.js +22 -7
  49. package/package.json +13 -10
  50. package/src/index.ts +1 -0
  51. package/src/instrumentation/instrumentation.ts +6 -18
  52. package/src/native/index.ts +1 -0
  53. package/src/native/ipc_world_state_instance.ts +847 -0
  54. package/src/native/merkle_trees_facade.ts +85 -112
  55. package/src/native/message.ts +13 -297
  56. package/src/native/native_world_state.ts +144 -97
  57. package/src/native/native_world_state_instance.ts +94 -281
  58. package/src/native/world_state_operation.ts +33 -0
  59. package/src/synchronizer/config.ts +14 -10
  60. package/src/synchronizer/errors.ts +8 -0
  61. package/src/synchronizer/factory.ts +11 -10
  62. package/src/synchronizer/index.ts +1 -0
  63. package/src/synchronizer/server_world_state_synchronizer.ts +73 -36
  64. package/src/test/utils.ts +10 -1
  65. package/src/testing.ts +19 -10
  66. package/dest/native/world_state_ops_queue.d.ts +0 -19
  67. package/dest/native/world_state_ops_queue.d.ts.map +0 -1
  68. package/dest/native/world_state_ops_queue.js +0 -146
  69. package/src/native/world_state_ops_queue.ts +0 -190
@@ -3,7 +3,6 @@ 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
6
  import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
8
7
  import type { L2Block } from '@aztec/stdlib/block';
9
8
  import { DatabaseVersionManager } from '@aztec/stdlib/database-version/manager';
@@ -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,37 +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
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
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
+
68
76
  const log = createLogger('world-state:database', bindings);
69
77
  const worldStateDirectory = join(dataDir, WORLD_STATE_DIR);
70
- // Create a version manager to handle versioning
78
+
71
79
  const versionManager = new DatabaseVersionManager({
72
80
  schemaVersion: WORLD_STATE_DB_VERSION,
73
81
  rollupAddress,
74
82
  dataDirectory: worldStateDirectory,
75
- onOpen: (dir: string) => {
76
- return Promise.resolve(
77
- new NativeWorldState(dir, wsTreeMapSizes, prefilledPublicData, instrumentation, bindings),
78
- );
79
- },
83
+ onOpen: dir => IpcWorldState.spawn(dir, wsTreeMapSizes, genesis, instrumentation, bindings),
80
84
  });
81
85
 
82
86
  const [instance] = await versionManager.open();
83
- 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);
84
95
  try {
85
96
  await worldState.init();
86
97
  } catch (e) {
@@ -92,15 +103,19 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
92
103
  }
93
104
 
94
105
  static async tmp(
95
- rollupAddress = EthAddress.ZERO,
96
106
  cleanupTmpDir = true,
97
- prefilledPublicData: PublicDataTreeLeaf[] = [],
107
+ genesis: GenesisData = EMPTY_GENESIS_DATA,
98
108
  instrumentation = new WorldStateInstrumentation(getTelemetryClient()),
99
109
  bindings?: LoggerBindings,
110
+ threads?: number,
100
111
  ): Promise<NativeWorldStateService> {
101
112
  const log = createLogger('world-state:database', bindings);
102
113
  const dataDir = await mkdtemp(join(tmpdir(), 'aztec-world-state-'));
103
- const dbMapSizeKb = 10 * 1024 * 1024;
114
+ // Temporary (test/dev) world states are small and short-lived. Keep the LMDB
115
+ // map sizes in the MB range: with the IPC backend each tmp() spawns a separate
116
+ // aztec-wsdb that maps these per tree, and oversized maps add real cold-start
117
+ // I/O under parallel CI load. 256 MB/tree is ample for tests.
118
+ const dbMapSizeKb = 256 * 1024;
104
119
  const worldStateTreeMapSizes: WorldStateTreeMapSizes = {
105
120
  archiveTreeMapSizeKb: dbMapSizeKb,
106
121
  nullifierTreeMapSizeKb: dbMapSizeKb,
@@ -110,7 +125,15 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
110
125
  };
111
126
  log.debug(`Created temporary world state database at: ${dataDir} with tree map size: ${dbMapSizeKb}`);
112
127
 
113
- // pass a cleanup callback because process.on('beforeExit', cleanup) does not work under Jest
128
+ const instance = await IpcWorldState.spawn(
129
+ dataDir,
130
+ worldStateTreeMapSizes,
131
+ genesis,
132
+ instrumentation,
133
+ bindings,
134
+ threads,
135
+ );
136
+
114
137
  const cleanup = async () => {
115
138
  if (cleanupTmpDir) {
116
139
  await rm(dataDir, { recursive: true, force: true, maxRetries: 3 });
@@ -120,15 +143,47 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
120
143
  }
121
144
  };
122
145
 
123
- return this.new(
124
- rollupAddress,
125
- dataDir,
126
- worldStateTreeMapSizes,
127
- prefilledPublicData,
128
- instrumentation,
129
- bindings,
130
- cleanup,
131
- );
146
+ const recreateInstance = async () => {
147
+ await rm(dataDir, { recursive: true, force: true, maxRetries: 3 });
148
+ await mkdir(dataDir, { recursive: true });
149
+ return IpcWorldState.spawn(dataDir, worldStateTreeMapSizes, genesis, instrumentation, bindings, threads);
150
+ };
151
+
152
+ const worldState = new this(instance, instrumentation, log, genesis, cleanup, recreateInstance);
153
+ try {
154
+ await worldState.init();
155
+ } catch (e) {
156
+ log.error(`Error initializing tmp world state: ${e}`);
157
+ throw e;
158
+ }
159
+ return worldState;
160
+ }
161
+
162
+ static ephemeral(
163
+ genesis: GenesisData = EMPTY_GENESIS_DATA,
164
+ instrumentation = new WorldStateInstrumentation(getTelemetryClient()),
165
+ bindings?: LoggerBindings,
166
+ ): Promise<NativeWorldStateService> {
167
+ // The TXE spins up one tiny, short-lived world state per test, many concurrently. Cap the wsdb thread
168
+ // usage to the minimum: a single tree-op thread instead of one per core (the C++ IPC dispatcher pool
169
+ // still floors at 2). This avoids ~32 threads per wsdb multiplied across dozens of concurrent test
170
+ // world states — the trees are cache-sized (see tmp's map-size note), so extra threads buy nothing.
171
+ return this.tmp(/*cleanupTmpDir=*/ true, genesis, instrumentation, bindings, /*threads=*/ 1);
172
+ }
173
+
174
+ static async fromIpc(
175
+ wsdbBackend: ConstructorParameters<typeof IpcWorldState>[0],
176
+ instrumentation = new WorldStateInstrumentation(getTelemetryClient()),
177
+ bindings?: LoggerBindings,
178
+ genesis: GenesisData = EMPTY_GENESIS_DATA,
179
+ cleanup = () => Promise.resolve(),
180
+ recreateInstance?: () => Promise<NativeWorldStateInstance>,
181
+ ): Promise<NativeWorldStateService> {
182
+ const log = createLogger('world-state:database', bindings);
183
+ const instance = new IpcWorldState(wsdbBackend, instrumentation, bindings);
184
+ const worldState = new this(instance, instrumentation, log, genesis, cleanup, recreateInstance);
185
+ await worldState.init();
186
+ return worldState;
132
187
  }
133
188
 
134
189
  protected async init() {
@@ -147,16 +202,29 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
147
202
 
148
203
  // the initial header _must_ be the first element in the archive tree
149
204
  // if this assertion fails, check that the hashing done in Header in yarn-project matches the initial header hash done in world_state.cpp
150
- const indices = await committed.findLeafIndices(MerkleTreeId.ARCHIVE, [(await this.initialHeader.hash()).toFr()]);
205
+ const indices = await committed.findLeafIndices(MerkleTreeId.ARCHIVE, [await this.initialHeader.hash()]);
151
206
  const initialHeaderIndex = indices[0];
152
207
  assert.strictEqual(initialHeaderIndex, 0n, 'Invalid initial archive state');
153
208
  }
154
209
 
155
- public async clear() {
210
+ public async clear(): Promise<void> {
211
+ if (!this.recreateInstance) {
212
+ throw new Error('clear() is not available for externally-managed IPC backends');
213
+ }
214
+ this.log.warn('Clearing world state: shutting down WSDB, deleting data, and recreating');
156
215
  await this.instance.close();
157
216
  this.cachedStatusSummary = undefined;
158
- await tryRmDir(this.instance.getDataDir(), this.log);
159
- this.instance = this.instance.clone();
217
+ this.instance = await this.recreateInstance();
218
+ await this.init();
219
+ this.log.info('World state cleared and reinitialized from genesis');
220
+ }
221
+
222
+ /** Returns the IPC path of the underlying IPC backend, if available. */
223
+ public getIpcPath(): string {
224
+ if (this.instance instanceof IpcWorldState) {
225
+ return this.instance.getIpcPath();
226
+ }
227
+ throw new Error('getIpcPath() is only available with IPC world state');
160
228
  }
161
229
 
162
230
  public getCommitted(): MerkleTreeReadOperations {
@@ -175,17 +243,16 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
175
243
  blockNumber?: BlockNumber,
176
244
  opts: { closeDelayMs?: number } = {},
177
245
  ): Promise<MerkleTreeWriteOperations> {
178
- const resp = await this.instance.call(WorldStateMessageType.CREATE_FORK, {
246
+ const forkId = await this.instance.createFork({
179
247
  latest: blockNumber === undefined,
180
248
  blockNumber: blockNumber ?? BlockNumber.ZERO,
181
- canonical: true,
182
249
  });
183
250
  return new MerkleTreesForkFacade(
184
251
  this.instance,
185
252
  this.initialHeader!,
186
253
  new WorldStateRevision(
187
- /*forkId=*/ resp.forkId,
188
- /* blockNumber=*/ BlockNumber.ZERO,
254
+ /*forkId=*/ forkId,
255
+ /* blockNumber=*/ WorldStateRevision.LATEST,
189
256
  /* includeUncommitted=*/ true,
190
257
  ),
191
258
  opts,
@@ -228,35 +295,44 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
228
295
  });
229
296
 
230
297
  try {
231
- return await this.instance.call(
232
- WorldStateMessageType.SYNC_BLOCK,
233
- {
234
- blockNumber: l2Block.number,
235
- blockHeaderHash: await l2Block.hash(),
236
- paddedL1ToL2Messages: paddedL1ToL2Messages.map(serializeLeaf),
237
- paddedNoteHashes: paddedNoteHashes.map(serializeLeaf),
238
- paddedNullifiers: paddedNullifiers.map(serializeLeaf),
239
- publicDataWrites: publicDataWrites.map(serializeLeaf),
240
- blockStateRef: blockStateReference(l2Block.header.state),
241
- canonical: true,
242
- },
243
- this.sanitizeAndCacheSummaryFromFull.bind(this),
244
- this.deleteCachedSummary.bind(this),
245
- );
298
+ const status = await this.instance.syncBlock({
299
+ blockNumber: l2Block.number,
300
+ blockHeaderHash: (await l2Block.hash()).toBuffer(),
301
+ // Forwarded so the native sync verifies the archive root against canonical and rejects a divergent tree.
302
+ expectedArchiveRoot: l2Block.archive.root.toBuffer(),
303
+ expectedPreviousArchiveRoot: l2Block.header.lastArchive.root.toBuffer(),
304
+ paddedL1ToL2Messages: paddedL1ToL2Messages.map(serializeLeaf),
305
+ paddedNoteHashes: paddedNoteHashes.map(serializeLeaf),
306
+ paddedNullifiers: paddedNullifiers.map(serializeLeaf),
307
+ publicDataWrites: publicDataWrites.map(serializeLeaf),
308
+ blockStateRef: blockStateReference(l2Block.header.state),
309
+ });
310
+ return this.sanitizeAndCacheSummaryFromFull(status);
246
311
  } catch (err) {
312
+ this.deleteCachedSummary();
247
313
  this.worldStateInstrumentation.incCriticalErrors('synch_pending_block');
248
314
  throw err;
249
315
  }
250
316
  }
251
317
 
252
318
  public async close(): Promise<void> {
253
- await this.instance.close();
254
- await this.cleanup();
319
+ try {
320
+ await this.instance.close();
321
+ } finally {
322
+ await this.cleanup();
323
+ }
324
+ }
325
+
326
+ async [Symbol.asyncDispose](): Promise<void> {
327
+ await this.close();
255
328
  }
256
329
 
257
330
  private async buildInitialHeader(): Promise<BlockHeader> {
258
331
  const state = await this.getInitialStateReference();
259
- return BlockHeader.empty({ state });
332
+ return BlockHeader.empty({
333
+ state,
334
+ globalVariables: GlobalVariables.empty({ timestamp: this.genesis.genesisTimestamp }),
335
+ });
260
336
  }
261
337
 
262
338
  private sanitizeAndCacheSummaryFromFull(response: WorldStateStatusFull) {
@@ -271,7 +347,7 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
271
347
  return sanitized;
272
348
  }
273
349
 
274
- private deleteCachedSummary(_: string) {
350
+ private deleteCachedSummary() {
275
351
  this.cachedStatusSummary = undefined;
276
352
  }
277
353
 
@@ -282,16 +358,9 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
282
358
  */
283
359
  public async setFinalized(toBlockNumber: BlockNumber) {
284
360
  try {
285
- await this.instance.call(
286
- WorldStateMessageType.FINALIZE_BLOCKS,
287
- {
288
- toBlockNumber,
289
- canonical: true,
290
- },
291
- this.sanitizeAndCacheSummary.bind(this),
292
- this.deleteCachedSummary.bind(this),
293
- );
361
+ this.sanitizeAndCacheSummary(await this.instance.finalizeBlocks(toBlockNumber));
294
362
  } catch (err) {
363
+ this.deleteCachedSummary();
295
364
  this.worldStateInstrumentation.incCriticalErrors('finalize_block');
296
365
  throw err;
297
366
  }
@@ -305,16 +374,9 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
305
374
  */
306
375
  public async removeHistoricalBlocks(toBlockNumber: BlockNumber) {
307
376
  try {
308
- return await this.instance.call(
309
- WorldStateMessageType.REMOVE_HISTORICAL_BLOCKS,
310
- {
311
- toBlockNumber,
312
- canonical: true,
313
- },
314
- this.sanitizeAndCacheSummaryFromFull.bind(this),
315
- this.deleteCachedSummary.bind(this),
316
- );
377
+ return this.sanitizeAndCacheSummaryFromFull(await this.instance.removeHistoricalBlocks(toBlockNumber));
317
378
  } catch (err) {
379
+ this.deleteCachedSummary();
318
380
  this.worldStateInstrumentation.incCriticalErrors('prune_historical_block');
319
381
  throw err;
320
382
  }
@@ -327,16 +389,9 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
327
389
  */
328
390
  public async unwindBlocks(toBlockNumber: BlockNumber) {
329
391
  try {
330
- return await this.instance.call(
331
- WorldStateMessageType.UNWIND_BLOCKS,
332
- {
333
- toBlockNumber,
334
- canonical: true,
335
- },
336
- this.sanitizeAndCacheSummaryFromFull.bind(this),
337
- this.deleteCachedSummary.bind(this),
338
- );
392
+ return this.sanitizeAndCacheSummaryFromFull(await this.instance.unwindBlocks(toBlockNumber));
339
393
  } catch (err) {
394
+ this.deleteCachedSummary();
340
395
  this.worldStateInstrumentation.incCriticalErrors('prune_pending_block');
341
396
  throw err;
342
397
  }
@@ -346,11 +401,7 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
346
401
  if (this.cachedStatusSummary !== undefined) {
347
402
  return { ...this.cachedStatusSummary };
348
403
  }
349
- return await this.instance.call(
350
- WorldStateMessageType.GET_STATUS,
351
- { canonical: true },
352
- this.sanitizeAndCacheSummary.bind(this),
353
- );
404
+ return this.sanitizeAndCacheSummary(await this.instance.getStatus());
354
405
  }
355
406
 
356
407
  updateLeaf<ID extends IndexedTreeId>(
@@ -362,14 +413,14 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
362
413
  }
363
414
 
364
415
  private async getInitialStateReference(): Promise<StateReference> {
365
- const resp = await this.instance.call(WorldStateMessageType.GET_INITIAL_STATE_REFERENCE, { canonical: true });
416
+ const state = await this.instance.getInitialStateReference();
366
417
 
367
418
  return new StateReference(
368
- treeStateReferenceToSnapshot(resp.state[MerkleTreeId.L1_TO_L2_MESSAGE_TREE]),
419
+ treeStateReferenceToSnapshot(state[MerkleTreeId.L1_TO_L2_MESSAGE_TREE]),
369
420
  new PartialStateReference(
370
- treeStateReferenceToSnapshot(resp.state[MerkleTreeId.NOTE_HASH_TREE]),
371
- treeStateReferenceToSnapshot(resp.state[MerkleTreeId.NULLIFIER_TREE]),
372
- treeStateReferenceToSnapshot(resp.state[MerkleTreeId.PUBLIC_DATA_TREE]),
421
+ treeStateReferenceToSnapshot(state[MerkleTreeId.NOTE_HASH_TREE]),
422
+ treeStateReferenceToSnapshot(state[MerkleTreeId.NULLIFIER_TREE]),
423
+ treeStateReferenceToSnapshot(state[MerkleTreeId.PUBLIC_DATA_TREE]),
373
424
  ),
374
425
  );
375
426
  }
@@ -378,11 +429,7 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
378
429
  dstPath: string,
379
430
  compact: boolean = true,
380
431
  ): Promise<Record<Exclude<SnapshotDataKeys, 'archiver'>, string>> {
381
- await this.instance.call(WorldStateMessageType.COPY_STORES, {
382
- dstPath,
383
- compact,
384
- canonical: true,
385
- });
432
+ await this.instance.copyStores(dstPath, compact);
386
433
  return fromEntries(NATIVE_WORLD_STATE_DBS.map(([name, dir]) => [name, join(dstPath, dir, 'data.mdb')] as const));
387
434
  }
388
435
  }