@aztec/world-state 0.0.0-test.0 → 0.0.1-commit.03f7ef2

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 +16 -8
  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 +62 -11
  14. package/dest/native/message.d.ts +72 -51
  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 +28 -20
  18. package/dest/native/native_world_state.d.ts.map +1 -1
  19. package/dest/native/native_world_state.js +97 -36
  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 -2
  27. package/dest/synchronizer/config.d.ts.map +1 -1
  28. package/dest/synchronizer/config.js +26 -1
  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 +9 -2
  33. package/dest/synchronizer/factory.d.ts.map +1 -1
  34. package/dest/synchronizer/factory.js +9 -4
  35. package/dest/synchronizer/index.d.ts +1 -1
  36. package/dest/synchronizer/server_world_state_synchronizer.d.ts +20 -29
  37. package/dest/synchronizer/server_world_state_synchronizer.d.ts.map +1 -1
  38. package/dest/synchronizer/server_world_state_synchronizer.js +94 -70
  39. package/dest/test/index.d.ts +1 -1
  40. package/dest/test/utils.d.ts +16 -9
  41. package/dest/test/utils.d.ts.map +1 -1
  42. package/dest/test/utils.js +56 -49
  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 +22 -10
  51. package/src/native/bench_metrics.ts +91 -0
  52. package/src/native/merkle_trees_facade.ts +73 -17
  53. package/src/native/message.ts +92 -73
  54. package/src/native/native_world_state.ts +118 -50
  55. package/src/native/native_world_state_instance.ts +59 -8
  56. package/src/native/world_state_ops_queue.ts +1 -1
  57. package/src/synchronizer/config.ts +47 -2
  58. package/src/synchronizer/errors.ts +5 -0
  59. package/src/synchronizer/factory.ts +31 -8
  60. package/src/synchronizer/server_world_state_synchronizer.ts +132 -93
  61. package/src/test/utils.ts +94 -84
  62. package/src/testing.ts +4 -8
  63. package/src/world-state-db/merkle_tree_db.ts +12 -8
@@ -1,11 +1,14 @@
1
1
  import { MAX_NOTE_HASHES_PER_TX, MAX_NULLIFIERS_PER_TX, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/constants';
2
- import { padArrayEnd } from '@aztec/foundation/collection';
2
+ import { BlockNumber } from '@aztec/foundation/branded-types';
3
+ import { fromEntries, padArrayEnd } from '@aztec/foundation/collection';
4
+ import { Fr } from '@aztec/foundation/curves/bn254';
3
5
  import { EthAddress } from '@aztec/foundation/eth-address';
4
- import { Fr } from '@aztec/foundation/fields';
6
+ import { tryRmDir } from '@aztec/foundation/fs';
5
7
  import { createLogger } from '@aztec/foundation/log';
6
8
  import { DatabaseVersionManager } from '@aztec/stdlib/database-version';
7
9
  import { MerkleTreeId, NullifierLeaf, PublicDataTreeLeaf } from '@aztec/stdlib/trees';
8
10
  import { BlockHeader, PartialStateReference, StateReference } from '@aztec/stdlib/tx';
11
+ import { WorldStateRevision } from '@aztec/stdlib/world-state';
9
12
  import { getTelemetryClient } from '@aztec/telemetry-client';
10
13
  import assert from 'assert/strict';
11
14
  import { mkdtemp, rm } from 'fs/promises';
@@ -13,11 +16,12 @@ import { tmpdir } from 'os';
13
16
  import { join } from 'path';
14
17
  import { WorldStateInstrumentation } from '../instrumentation/instrumentation.js';
15
18
  import { MerkleTreesFacade, MerkleTreesForkFacade, serializeLeaf } from './merkle_trees_facade.js';
16
- import { WorldStateMessageType, blockStateReference, sanitiseFullStatus, sanitiseSummary, treeStateReferenceToSnapshot, worldStateRevision } from './message.js';
19
+ import { WorldStateMessageType, blockStateReference, sanitizeFullStatus, sanitizeSummary, treeStateReferenceToSnapshot } from './message.js';
17
20
  import { NativeWorldState } from './native_world_state_instance.js';
18
21
  // The current version of the world state database schema
19
22
  // Increment this when making incompatible changes to the database schema
20
- export const WORLD_STATE_DB_VERSION = 1; // The initial version
23
+ export const WORLD_STATE_DB_VERSION = 2; // The initial version
24
+ export const WORLD_STATE_DIR = 'world_state';
21
25
  export class NativeWorldStateService {
22
26
  instance;
23
27
  worldStateInstrumentation;
@@ -32,18 +36,23 @@ export class NativeWorldStateService {
32
36
  this.log = log;
33
37
  this.cleanup = cleanup;
34
38
  }
35
- static async new(rollupAddress, dataDir, dbMapSizeKb, prefilledPublicData = [], instrumentation = new WorldStateInstrumentation(getTelemetryClient()), log = createLogger('world-state:database'), cleanup = ()=>Promise.resolve()) {
36
- const worldStateDirectory = join(dataDir, 'world_state');
39
+ static async new(rollupAddress, dataDir, wsTreeMapSizes, prefilledPublicData = [], instrumentation = new WorldStateInstrumentation(getTelemetryClient()), log = createLogger('world-state:database'), cleanup = ()=>Promise.resolve()) {
40
+ const worldStateDirectory = join(dataDir, WORLD_STATE_DIR);
37
41
  // Create a version manager to handle versioning
38
- const versionManager = new DatabaseVersionManager(WORLD_STATE_DB_VERSION, rollupAddress, worldStateDirectory, (dir)=>{
39
- return Promise.resolve(new NativeWorldState(dir, dbMapSizeKb, prefilledPublicData, instrumentation));
42
+ const versionManager = new DatabaseVersionManager({
43
+ schemaVersion: WORLD_STATE_DB_VERSION,
44
+ rollupAddress,
45
+ dataDirectory: worldStateDirectory,
46
+ onOpen: (dir)=>{
47
+ return Promise.resolve(new NativeWorldState(dir, wsTreeMapSizes, prefilledPublicData, instrumentation));
48
+ }
40
49
  });
41
50
  const [instance] = await versionManager.open();
42
51
  const worldState = new this(instance, instrumentation, log, cleanup);
43
52
  try {
44
53
  await worldState.init();
45
54
  } catch (e) {
46
- log.error(`Error initialising world state: ${e}`);
55
+ log.error(`Error initializing world state: ${e}`);
47
56
  throw e;
48
57
  }
49
58
  return worldState;
@@ -52,7 +61,14 @@ export class NativeWorldStateService {
52
61
  const log = createLogger('world-state:database');
53
62
  const dataDir = await mkdtemp(join(tmpdir(), 'aztec-world-state-'));
54
63
  const dbMapSizeKb = 10 * 1024 * 1024;
55
- log.debug(`Created temporary world state database at: ${dataDir} with size: ${dbMapSizeKb}`);
64
+ const worldStateTreeMapSizes = {
65
+ archiveTreeMapSizeKb: dbMapSizeKb,
66
+ nullifierTreeMapSizeKb: dbMapSizeKb,
67
+ noteHashTreeMapSizeKb: dbMapSizeKb,
68
+ messageTreeMapSizeKb: dbMapSizeKb,
69
+ publicDataTreeMapSizeKb: dbMapSizeKb
70
+ };
71
+ log.debug(`Created temporary world state database at: ${dataDir} with tree map size: ${dbMapSizeKb}`);
56
72
  // pass a cleanup callback because process.on('beforeExit', cleanup) does not work under Jest
57
73
  const cleanup = async ()=>{
58
74
  if (cleanupTmpDir) {
@@ -66,7 +82,7 @@ export class NativeWorldStateService {
66
82
  log.debug(`Leaving temporary world state database: ${dataDir}`);
67
83
  }
68
84
  };
69
- return this.new(rollupAddress, dataDir, dbMapSizeKb, prefilledPublicData, instrumentation, log, cleanup);
85
+ return this.new(rollupAddress, dataDir, worldStateTreeMapSizes, prefilledPublicData, instrumentation, log, cleanup);
70
86
  }
71
87
  async init() {
72
88
  const status = await this.getStatusSummary();
@@ -88,27 +104,38 @@ export class NativeWorldStateService {
88
104
  const initialHeaderIndex = indices[0];
89
105
  assert.strictEqual(initialHeaderIndex, 0n, 'Invalid initial archive state');
90
106
  }
107
+ async clear() {
108
+ await this.instance.close();
109
+ this.cachedStatusSummary = undefined;
110
+ await tryRmDir(this.instance.getDataDir(), this.log);
111
+ this.instance = this.instance.clone();
112
+ }
91
113
  getCommitted() {
92
- return new MerkleTreesFacade(this.instance, this.initialHeader, worldStateRevision(false, 0, 0));
114
+ return new MerkleTreesFacade(this.instance, this.initialHeader, WorldStateRevision.empty());
93
115
  }
94
116
  getSnapshot(blockNumber) {
95
- return new MerkleTreesFacade(this.instance, this.initialHeader, worldStateRevision(false, 0, blockNumber));
117
+ return new MerkleTreesFacade(this.instance, this.initialHeader, new WorldStateRevision(/*forkId=*/ 0, /* blockNumber=*/ blockNumber, /* includeUncommitted=*/ false));
96
118
  }
97
- async fork(blockNumber) {
119
+ async fork(blockNumber, opts = {}) {
98
120
  const resp = await this.instance.call(WorldStateMessageType.CREATE_FORK, {
99
121
  latest: blockNumber === undefined,
100
- blockNumber: blockNumber ?? 0,
122
+ blockNumber: blockNumber ?? BlockNumber.ZERO,
101
123
  canonical: true
102
124
  });
103
- return new MerkleTreesForkFacade(this.instance, this.initialHeader, worldStateRevision(true, resp.forkId, 0));
125
+ return new MerkleTreesForkFacade(this.instance, this.initialHeader, new WorldStateRevision(/*forkId=*/ resp.forkId, /* blockNumber=*/ BlockNumber.ZERO, /* includeUncommitted=*/ true), opts);
104
126
  }
105
127
  getInitialHeader() {
106
128
  return this.initialHeader;
107
129
  }
108
130
  async handleL2BlockAndMessages(l2Block, l1ToL2Messages) {
109
- // We have to pad both the values within tx effects because that's how the trees are built by circuits.
131
+ const isFirstBlock = l2Block.indexWithinCheckpoint === 0;
132
+ if (!isFirstBlock && l1ToL2Messages.length > 0) {
133
+ throw new Error(`L1 to L2 messages must be empty for non-first blocks, but got ${l1ToL2Messages.length} messages for block ${l2Block.number}.`);
134
+ }
135
+ // We have to pad the given l1 to l2 messages, and the note hashes and nullifiers within tx effects, because that's
136
+ // how the trees are built by circuits.
137
+ const paddedL1ToL2Messages = isFirstBlock ? padArrayEnd(l1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP) : [];
110
138
  const paddedNoteHashes = l2Block.body.txEffects.flatMap((txEffect)=>padArrayEnd(txEffect.noteHashes, Fr.ZERO, MAX_NOTE_HASHES_PER_TX));
111
- const paddedL1ToL2Messages = padArrayEnd(l1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP);
112
139
  const paddedNullifiers = l2Block.body.txEffects.flatMap((txEffect)=>padArrayEnd(txEffect.nullifiers, Fr.ZERO, MAX_NULLIFIERS_PER_TX)).map((nullifier)=>new NullifierLeaf(nullifier));
113
140
  const publicDataWrites = l2Block.body.txEffects.flatMap((txEffect)=>{
114
141
  return txEffect.publicDataWrites.map((write)=>{
@@ -121,14 +148,14 @@ export class NativeWorldStateService {
121
148
  try {
122
149
  return await this.instance.call(WorldStateMessageType.SYNC_BLOCK, {
123
150
  blockNumber: l2Block.number,
124
- blockHeaderHash: await l2Block.header.hash(),
151
+ blockHeaderHash: await l2Block.hash(),
125
152
  paddedL1ToL2Messages: paddedL1ToL2Messages.map(serializeLeaf),
126
153
  paddedNoteHashes: paddedNoteHashes.map(serializeLeaf),
127
154
  paddedNullifiers: paddedNullifiers.map(serializeLeaf),
128
155
  publicDataWrites: publicDataWrites.map(serializeLeaf),
129
156
  blockStateRef: blockStateReference(l2Block.header.state),
130
157
  canonical: true
131
- }, this.sanitiseAndCacheSummaryFromFull.bind(this), this.deleteCachedSummary.bind(this));
158
+ }, this.sanitizeAndCacheSummaryFromFull.bind(this), this.deleteCachedSummary.bind(this));
132
159
  } catch (err) {
133
160
  this.worldStateInstrumentation.incCriticalErrors('synch_pending_block');
134
161
  throw err;
@@ -144,33 +171,33 @@ export class NativeWorldStateService {
144
171
  state
145
172
  });
146
173
  }
147
- sanitiseAndCacheSummaryFromFull(response) {
148
- const sanitised = sanitiseFullStatus(response);
174
+ sanitizeAndCacheSummaryFromFull(response) {
175
+ const sanitized = sanitizeFullStatus(response);
149
176
  this.cachedStatusSummary = {
150
- ...sanitised.summary
177
+ ...sanitized.summary
151
178
  };
152
- return sanitised;
179
+ return sanitized;
153
180
  }
154
- sanitiseAndCacheSummary(response) {
155
- const sanitised = sanitiseSummary(response);
181
+ sanitizeAndCacheSummary(response) {
182
+ const sanitized = sanitizeSummary(response);
156
183
  this.cachedStatusSummary = {
157
- ...sanitised
184
+ ...sanitized
158
185
  };
159
- return sanitised;
186
+ return sanitized;
160
187
  }
161
188
  deleteCachedSummary(_) {
162
189
  this.cachedStatusSummary = undefined;
163
190
  }
164
191
  /**
165
- * Advances the finalised block number to be the number provided
166
- * @param toBlockNumber The block number that is now the tip of the finalised chain
192
+ * Advances the finalized block number to be the number provided
193
+ * @param toBlockNumber The block number that is now the tip of the finalized chain
167
194
  * @returns The new WorldStateStatus
168
- */ async setFinalised(toBlockNumber) {
195
+ */ async setFinalized(toBlockNumber) {
169
196
  try {
170
- await this.instance.call(WorldStateMessageType.FINALISE_BLOCKS, {
197
+ await this.instance.call(WorldStateMessageType.FINALIZE_BLOCKS, {
171
198
  toBlockNumber,
172
199
  canonical: true
173
- }, this.sanitiseAndCacheSummary.bind(this), this.deleteCachedSummary.bind(this));
200
+ }, this.sanitizeAndCacheSummary.bind(this), this.deleteCachedSummary.bind(this));
174
201
  } catch (err) {
175
202
  this.worldStateInstrumentation.incCriticalErrors('finalize_block');
176
203
  throw err;
@@ -186,7 +213,7 @@ export class NativeWorldStateService {
186
213
  return await this.instance.call(WorldStateMessageType.REMOVE_HISTORICAL_BLOCKS, {
187
214
  toBlockNumber,
188
215
  canonical: true
189
- }, this.sanitiseAndCacheSummaryFromFull.bind(this), this.deleteCachedSummary.bind(this));
216
+ }, this.sanitizeAndCacheSummaryFromFull.bind(this), this.deleteCachedSummary.bind(this));
190
217
  } catch (err) {
191
218
  this.worldStateInstrumentation.incCriticalErrors('prune_historical_block');
192
219
  throw err;
@@ -201,7 +228,7 @@ export class NativeWorldStateService {
201
228
  return await this.instance.call(WorldStateMessageType.UNWIND_BLOCKS, {
202
229
  toBlockNumber,
203
230
  canonical: true
204
- }, this.sanitiseAndCacheSummaryFromFull.bind(this), this.deleteCachedSummary.bind(this));
231
+ }, this.sanitizeAndCacheSummaryFromFull.bind(this), this.deleteCachedSummary.bind(this));
205
232
  } catch (err) {
206
233
  this.worldStateInstrumentation.incCriticalErrors('prune_pending_block');
207
234
  throw err;
@@ -215,7 +242,7 @@ export class NativeWorldStateService {
215
242
  }
216
243
  return await this.instance.call(WorldStateMessageType.GET_STATUS, {
217
244
  canonical: true
218
- }, this.sanitiseAndCacheSummary.bind(this));
245
+ }, this.sanitizeAndCacheSummary.bind(this));
219
246
  }
220
247
  updateLeaf(_treeId, _leaf, _index) {
221
248
  return Promise.reject(new Error('Method not implemented'));
@@ -226,4 +253,38 @@ export class NativeWorldStateService {
226
253
  });
227
254
  return new StateReference(treeStateReferenceToSnapshot(resp.state[MerkleTreeId.L1_TO_L2_MESSAGE_TREE]), new PartialStateReference(treeStateReferenceToSnapshot(resp.state[MerkleTreeId.NOTE_HASH_TREE]), treeStateReferenceToSnapshot(resp.state[MerkleTreeId.NULLIFIER_TREE]), treeStateReferenceToSnapshot(resp.state[MerkleTreeId.PUBLIC_DATA_TREE])));
228
255
  }
256
+ async backupTo(dstPath, compact = true) {
257
+ await this.instance.call(WorldStateMessageType.COPY_STORES, {
258
+ dstPath,
259
+ compact,
260
+ canonical: true
261
+ });
262
+ return fromEntries(NATIVE_WORLD_STATE_DBS.map(([name, dir])=>[
263
+ name,
264
+ join(dstPath, dir, 'data.mdb')
265
+ ]));
266
+ }
229
267
  }
268
+ // The following paths are defined in cpp-land
269
+ export const NATIVE_WORLD_STATE_DBS = [
270
+ [
271
+ 'l1-to-l2-message-tree',
272
+ 'L1ToL2MessageTree'
273
+ ],
274
+ [
275
+ 'archive-tree',
276
+ 'ArchiveTree'
277
+ ],
278
+ [
279
+ 'public-data-tree',
280
+ 'PublicDataTree'
281
+ ],
282
+ [
283
+ 'note-hash-tree',
284
+ 'NoteHashTree'
285
+ ],
286
+ [
287
+ 'nullifier-tree',
288
+ 'NullifierTree'
289
+ ]
290
+ ];
@@ -1,20 +1,36 @@
1
+ import { type Logger } from '@aztec/foundation/log';
1
2
  import type { PublicDataTreeLeaf } from '@aztec/stdlib/trees';
2
3
  import type { WorldStateInstrumentation } from '../instrumentation/instrumentation.js';
4
+ import type { WorldStateTreeMapSizes } from '../synchronizer/factory.js';
3
5
  import { WorldStateMessageType, type WorldStateRequest, type WorldStateRequestCategories, type WorldStateResponse } from './message.js';
4
6
  export interface NativeWorldStateInstance {
5
7
  call<T extends WorldStateMessageType>(messageType: T, body: WorldStateRequest[T] & WorldStateRequestCategories): Promise<WorldStateResponse[T]>;
8
+ getHandle(): any;
6
9
  }
7
10
  /**
8
11
  * Strongly-typed interface to access the WorldState class in the native world_state_napi module.
9
12
  */
10
13
  export declare class NativeWorldState implements NativeWorldStateInstance {
11
- private instrumentation;
12
- private log;
14
+ private readonly dataDir;
15
+ private readonly wsTreeMapSizes;
16
+ private readonly prefilledPublicData;
17
+ private readonly instrumentation;
18
+ private readonly log;
13
19
  private open;
14
20
  private queues;
15
21
  private instance;
16
22
  /** Creates a new native WorldState instance */
17
- constructor(dataDir: string, dbMapSizeKb: number, prefilledPublicData: PublicDataTreeLeaf[] | undefined, instrumentation: WorldStateInstrumentation, log?: import("@aztec/foundation/log").Logger);
23
+ constructor(dataDir: string, wsTreeMapSizes: WorldStateTreeMapSizes, prefilledPublicData: PublicDataTreeLeaf[] | undefined, instrumentation: WorldStateInstrumentation, log?: Logger);
24
+ getDataDir(): string;
25
+ clone(): NativeWorldState;
26
+ /**
27
+ * Gets the native WorldState handle from the underlying native instance.
28
+ * We call the getHandle() method on the native WorldState to get a NAPI External
29
+ * that wraps the underlying C++ WorldState pointer.
30
+ * @returns The NAPI External handle to the native WorldState instance,since
31
+ * the NAPI external type is opaque, we return any (we could also use an opaque symbol type)
32
+ */
33
+ getHandle(): any;
18
34
  /**
19
35
  * Sends a message to the native instance and returns the response.
20
36
  * @param messageType - The type of message to send
@@ -30,4 +46,4 @@ export declare class NativeWorldState implements NativeWorldStateInstance {
30
46
  close(): Promise<void>;
31
47
  private _sendMessage;
32
48
  }
33
- //# sourceMappingURL=native_world_state_instance.d.ts.map
49
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibmF0aXZlX3dvcmxkX3N0YXRlX2luc3RhbmNlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvbmF0aXZlL25hdGl2ZV93b3JsZF9zdGF0ZV9pbnN0YW5jZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFVQSxPQUFPLEVBQUUsS0FBSyxNQUFNLEVBQWdCLE1BQU0sdUJBQXVCLENBQUM7QUFHbEUsT0FBTyxLQUFLLEVBQUUsa0JBQWtCLEVBQUUsTUFBTSxxQkFBcUIsQ0FBQztBQUs5RCxPQUFPLEtBQUssRUFBRSx5QkFBeUIsRUFBRSxNQUFNLHVDQUF1QyxDQUFDO0FBQ3ZGLE9BQU8sS0FBSyxFQUFFLHNCQUFzQixFQUFFLE1BQU0sNEJBQTRCLENBQUM7QUFDekUsT0FBTyxFQUNMLHFCQUFxQixFQUNyQixLQUFLLGlCQUFpQixFQUN0QixLQUFLLDJCQUEyQixFQUNoQyx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XFCLEVBQy9DLFdBQVcsRUFBRSxDQUFDLEVBQ2QsSUFBSSxFQUFFLGlCQUFpQixDQUFDLENBQUMsQ0FBQyxHQUFHLDJCQUEyQixFQUV4RCxlQUFlLDZEQUF1RSxFQUN0RixZQUFZLHNCQUFvQixHQUMvQixPQUFPLENBQUMsa0JBQWtCLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FxRGhDO0lBRUQ7O09BRUc7SUFDVSxLQUFLLElBQUksT0FBTyxDQUFDLElBQUksQ0FBQyxDQWVsQztZQUVhLFlBQVk7Q0E4RDNCIn0=
@@ -1 +1 @@
1
- {"version":3,"file":"native_world_state_instance.d.ts","sourceRoot":"","sources":["../../src/native/native_world_state_instance.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAK9D,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,uCAAuC,CAAC;AACvF,OAAO,EACL,qBAAqB,EACrB,KAAK,iBAAiB,EACtB,KAAK,2BAA2B,EAChC,KAAK,kBAAkB,EAIxB,MAAM,cAAc,CAAC;AAKtB,MAAM,WAAW,wBAAwB;IACvC,IAAI,CAAC,CAAC,SAAS,qBAAqB,EAClC,WAAW,EAAE,CAAC,EACd,IAAI,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAAG,2BAA2B,GACvD,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAC;CACnC;AAED;;GAEG;AACH,qBAAa,gBAAiB,YAAW,wBAAwB;IAa7D,OAAO,CAAC,eAAe;IACvB,OAAO,CAAC,GAAG;IAbb,OAAO,CAAC,IAAI,CAAQ;IAGpB,OAAO,CAAC,MAAM,CAAyC;IAEvD,OAAO,CAAC,QAAQ,CAA+E;IAE/F,+CAA+C;gBAE7C,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,MAAM,EACnB,mBAAmB,kCAA2B,EACtC,eAAe,EAAE,yBAAyB,EAC1C,GAAG,yCAAuC;IA8BpD;;;;;;;OAOG;IACU,IAAI,CAAC,CAAC,SAAS,qBAAqB,EAC/C,WAAW,EAAE,CAAC,EACd,IAAI,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAAG,2BAA2B,EAExD,eAAe,cAAc,kBAAkB,CAAC,CAAC,CAAC,KAAG,kBAAkB,CAAC,CAAC,CAAa,EACtF,YAAY,OAAO,MAAM,SAAO,GAC/B,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC;IAuDjC;;OAEG;IACU,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;YAiBrB,YAAY;CA8D3B"}
1
+ {"version":3,"file":"native_world_state_instance.d.ts","sourceRoot":"","sources":["../../src/native/native_world_state_instance.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,uBAAuB,CAAC;AAGlE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAK9D,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,uCAAuC,CAAC;AACvF,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AACzE,OAAO,EACL,qBAAqB,EACrB,KAAK,iBAAiB,EACtB,KAAK,2BAA2B,EAChC,KAAK,kBAAkB,EAIxB,MAAM,cAAc,CAAC;AAKtB,MAAM,WAAW,wBAAwB;IACvC,IAAI,CAAC,CAAC,SAAS,qBAAqB,EAClC,WAAW,EAAE,CAAC,EACd,IAAI,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAAG,2BAA2B,GACvD,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAC;IAElC,SAAS,IAAI,GAAG,CAAC;CAClB;AAED;;GAEG;AACH,qBAAa,gBAAiB,YAAW,wBAAwB;IAU7D,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,cAAc;IAC/B,OAAO,CAAC,QAAQ,CAAC,mBAAmB;IACpC,OAAO,CAAC,QAAQ,CAAC,eAAe;IAChC,OAAO,CAAC,QAAQ,CAAC,GAAG;IAbtB,OAAO,CAAC,IAAI,CAAQ;IAGpB,OAAO,CAAC,MAAM,CAAyC;IAEvD,OAAO,CAAC,QAAQ,CAA+E;IAE/F,+CAA+C;IAC/C,YACmB,OAAO,EAAE,MAAM,EACf,cAAc,EAAE,sBAAsB,EACtC,mBAAmB,kCAA2B,EAC9C,eAAe,EAAE,yBAAyB,EAC1C,GAAG,GAAE,MAA6C,EAoCpE;IAEM,UAAU,WAEhB;IAEM,KAAK,qBAQX;IAED;;;;;;OAMG;IACI,SAAS,IAAI,GAAG,CAiBtB;IAED;;;;;;;OAOG;IACU,IAAI,CAAC,CAAC,SAAS,qBAAqB,EAC/C,WAAW,EAAE,CAAC,EACd,IAAI,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAAG,2BAA2B,EAExD,eAAe,6DAAuE,EACtF,YAAY,sBAAoB,GAC/B,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAqDhC;IAED;;OAEG;IACU,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAelC;YAEa,YAAY;CA8D3B"}
@@ -10,19 +10,25 @@ const MAX_WORLD_STATE_THREADS = +(process.env.HARDWARE_CONCURRENCY || '16');
10
10
  /**
11
11
  * Strongly-typed interface to access the WorldState class in the native world_state_napi module.
12
12
  */ export class NativeWorldState {
13
+ dataDir;
14
+ wsTreeMapSizes;
15
+ prefilledPublicData;
13
16
  instrumentation;
14
17
  log;
15
18
  open;
16
19
  // We maintain a map of queue to fork
17
20
  queues;
18
21
  instance;
19
- /** Creates a new native WorldState instance */ constructor(dataDir, dbMapSizeKb, prefilledPublicData = [], instrumentation, log = createLogger('world-state:database')){
22
+ /** Creates a new native WorldState instance */ constructor(dataDir, wsTreeMapSizes, prefilledPublicData = [], instrumentation, log = createLogger('world-state:database')){
23
+ this.dataDir = dataDir;
24
+ this.wsTreeMapSizes = wsTreeMapSizes;
25
+ this.prefilledPublicData = prefilledPublicData;
20
26
  this.instrumentation = instrumentation;
21
27
  this.log = log;
22
28
  this.open = true;
23
29
  this.queues = new Map();
24
30
  const threads = Math.min(cpus().length, MAX_WORLD_STATE_THREADS);
25
- log.info(`Creating world state data store at directory ${dataDir} with map size ${dbMapSizeKb} KB and ${threads} threads.`);
31
+ log.info(`Creating world state data store at directory ${dataDir} with map sizes ${JSON.stringify(wsTreeMapSizes)} and ${threads} threads.`);
26
32
  const prefilledPublicDataBufferArray = prefilledPublicData.map((d)=>[
27
33
  d.slot.toBuffer(),
28
34
  d.value.toBuffer()
@@ -36,11 +42,44 @@ const MAX_WORLD_STATE_THREADS = +(process.env.HARDWARE_CONCURRENCY || '16');
36
42
  }, {
37
43
  [MerkleTreeId.NULLIFIER_TREE]: 2 * MAX_NULLIFIERS_PER_TX,
38
44
  [MerkleTreeId.PUBLIC_DATA_TREE]: 2 * MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX
39
- }, prefilledPublicDataBufferArray, GeneratorIndex.BLOCK_HASH, dbMapSizeKb, threads);
45
+ }, prefilledPublicDataBufferArray, GeneratorIndex.BLOCK_HASH, {
46
+ [MerkleTreeId.NULLIFIER_TREE]: wsTreeMapSizes.nullifierTreeMapSizeKb,
47
+ [MerkleTreeId.NOTE_HASH_TREE]: wsTreeMapSizes.noteHashTreeMapSizeKb,
48
+ [MerkleTreeId.PUBLIC_DATA_TREE]: wsTreeMapSizes.publicDataTreeMapSizeKb,
49
+ [MerkleTreeId.L1_TO_L2_MESSAGE_TREE]: wsTreeMapSizes.messageTreeMapSizeKb,
50
+ [MerkleTreeId.ARCHIVE]: wsTreeMapSizes.archiveTreeMapSizeKb
51
+ }, threads);
40
52
  this.instance = new MsgpackChannel(ws);
41
53
  // Manually create the queue for the canonical fork
42
54
  this.queues.set(0, new WorldStateOpsQueue());
43
55
  }
56
+ getDataDir() {
57
+ return this.dataDir;
58
+ }
59
+ clone() {
60
+ return new NativeWorldState(this.dataDir, this.wsTreeMapSizes, this.prefilledPublicData, this.instrumentation, this.log);
61
+ }
62
+ /**
63
+ * Gets the native WorldState handle from the underlying native instance.
64
+ * We call the getHandle() method on the native WorldState to get a NAPI External
65
+ * that wraps the underlying C++ WorldState pointer.
66
+ * @returns The NAPI External handle to the native WorldState instance,since
67
+ * the NAPI external type is opaque, we return any (we could also use an opaque symbol type)
68
+ */ getHandle() {
69
+ const worldStateWrapper = this.instance.dest;
70
+ if (!worldStateWrapper) {
71
+ throw new Error('No WorldStateWrapper found');
72
+ }
73
+ if (typeof worldStateWrapper.getHandle !== 'function') {
74
+ throw new Error('WorldStateWrapper does not have getHandle method');
75
+ }
76
+ // Call getHandle() to get the NAPI External
77
+ try {
78
+ return worldStateWrapper.getHandle();
79
+ } catch (error) {
80
+ this.log.error('Failed to get native WorldState handle', error);
81
+ }
82
+ }
44
83
  /**
45
84
  * Sends a message to the native instance and returns the response.
46
85
  * @param messageType - The type of message to send
@@ -16,4 +16,4 @@ export declare class WorldStateOpsQueue {
16
16
  private sendEnqueuedRequest;
17
17
  stop(): Promise<void>;
18
18
  }
19
- //# sourceMappingURL=world_state_ops_queue.d.ts.map
19
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoid29ybGRfc3RhdGVfb3BzX3F1ZXVlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvbmF0aXZlL3dvcmxkX3N0YXRlX29wc19xdWV1ZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFFQSxPQUFPLEVBQUUscUJBQXFCLEVBQUUsTUFBTSxjQUFjLENBQUM7QUF5QnJELGVBQU8sTUFBTSxrQkFBa0IsNEJBZ0I3QixDQUFDO0FBR0gscUJBQWEsa0JBQWtCO0lBQzdCLE9BQU8sQ0FBQyxRQUFRLENBQXNCO0lBQ3RDLE9BQU8sQ0FBQyxxQkFBcUIsQ0FBSztJQUNsQyxPQUFPLENBQ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AA2B;IAUnC,OAAO,CAAC,eAAe;IAyCvB,OAAO,CAAC,mBAAmB;IAgBpB,IAAI;CAiBZ"}
1
+ {"version":3,"file":"world_state_ops_queue.d.ts","sourceRoot":"","sources":["../../src/native/world_state_ops_queue.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAyBrD,eAAO,MAAM,kBAAkB,4BAgB7B,CAAC;AAGH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,QAAQ,CAAsB;IACtC,OAAO,CAAC,qBAAqB,CAAK;IAClC,OAAO,CAAC,aAAa,CAAK;IAC1B,OAAO,CAAC,WAAW,CAAC,CAAgB;IACpC,OAAO,CAAC,WAAW,CAAC,CAAa;IACjC,OAAO,CAAC,SAAS,CAAK;IACtB,OAAO,CAAC,GAAG,CAAwC;IAI5C,OAAO,CAAC,OAAO,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC,EAAE,WAAW,EAAE,qBAAqB,EAAE,aAAa,EAAE,OAAO,gBAsBrG;IAGD,OAAO,CAAC,eAAe;IAWvB,OAAO,CAAC,6BAA6B;IAYrC,OAAO,CAAC,2BAA2B;IAUnC,OAAO,CAAC,eAAe;IAyCvB,OAAO,CAAC,mBAAmB;IAgBpB,IAAI,kBAgBV;CACF"}
@@ -12,7 +12,7 @@ export const MUTATING_MSG_TYPES = new Set([
12
12
  WorldStateMessageType.SYNC_BLOCK,
13
13
  WorldStateMessageType.CREATE_FORK,
14
14
  WorldStateMessageType.DELETE_FORK,
15
- WorldStateMessageType.FINALISE_BLOCKS,
15
+ WorldStateMessageType.FINALIZE_BLOCKS,
16
16
  WorldStateMessageType.UNWIND_BLOCKS,
17
17
  WorldStateMessageType.REMOVE_HISTORICAL_BLOCKS,
18
18
  WorldStateMessageType.CREATE_CHECKPOINT,
@@ -7,8 +7,18 @@ export interface WorldStateConfig {
7
7
  worldStateProvenBlocksOnly: boolean;
8
8
  /** Size of the batch for each get-blocks request from the synchronizer to the archiver. */
9
9
  worldStateBlockRequestBatchSize?: number;
10
- /** The map size to be provided to LMDB for each world state tree DB, optional, will inherit from the general dataStoreMapSizeKB if not specified*/
10
+ /** The map size to be provided to LMDB for each world state tree DB, optional, will inherit from the general dataStoreMapSizeKb if not specified*/
11
11
  worldStateDbMapSizeKb?: number;
12
+ /** The map size to be provided to LMDB for each world state archive tree, optional, will inherit from the general worldStateDbMapSizeKb if not specified*/
13
+ archiveTreeMapSizeKb?: number;
14
+ /** The map size to be provided to LMDB for each world state nullifier tree, optional, will inherit from the general worldStateDbMapSizeKb if not specified*/
15
+ nullifierTreeMapSizeKb?: number;
16
+ /** The map size to be provided to LMDB for each world state note hash tree, optional, will inherit from the general worldStateDbMapSizeKb if not specified*/
17
+ noteHashTreeMapSizeKb?: number;
18
+ /** The map size to be provided to LMDB for each world state message tree, optional, will inherit from the general worldStateDbMapSizeKb if not specified*/
19
+ messageTreeMapSizeKb?: number;
20
+ /** The map size to be provided to LMDB for each world state public data tree, optional, will inherit from the general worldStateDbMapSizeKb if not specified*/
21
+ publicDataTreeMapSizeKb?: number;
12
22
  /** Optional directory for the world state DB, if unspecified will default to the general data directory */
13
23
  worldStateDataDirectory?: string;
14
24
  /** The number of historic blocks to maintain */
@@ -20,4 +30,4 @@ export declare const worldStateConfigMappings: ConfigMappingsType<WorldStateConf
20
30
  * @returns The configuration values for the world state synchronizer.
21
31
  */
22
32
  export declare function getWorldStateConfigFromEnv(): WorldStateConfig;
23
- //# sourceMappingURL=config.d.ts.map
33
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29uZmlnLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvc3luY2hyb25pemVyL2NvbmZpZy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQ0wsS0FBSyxrQkFBa0IsRUFJeEIsTUFBTSwwQkFBMEIsQ0FBQztBQUVsQy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C;AAEF;;;GAGG;AACH,wBAAgB,0BAA0B,IAAI,gBAAgB,CAE7D"}
@@ -19,7 +19,32 @@ export const worldStateConfigMappings = {
19
19
  worldStateDbMapSizeKb: {
20
20
  env: 'WS_DB_MAP_SIZE_KB',
21
21
  parseEnv: (val)=>val ? +val : undefined,
22
- description: 'The maximum possible size of the world state DB'
22
+ description: 'The maximum possible size of the world state DB in KB. Overwrites the general dataStoreMapSizeKb.'
23
+ },
24
+ archiveTreeMapSizeKb: {
25
+ env: 'ARCHIVE_TREE_MAP_SIZE_KB',
26
+ parseEnv: (val)=>val ? +val : undefined,
27
+ description: 'The maximum possible size of the world state archive tree in KB. Overwrites the general worldStateDbMapSizeKb.'
28
+ },
29
+ nullifierTreeMapSizeKb: {
30
+ env: 'NULLIFIER_TREE_MAP_SIZE_KB',
31
+ parseEnv: (val)=>val ? +val : undefined,
32
+ description: 'The maximum possible size of the world state nullifier tree in KB. Overwrites the general worldStateDbMapSizeKb.'
33
+ },
34
+ noteHashTreeMapSizeKb: {
35
+ env: 'NOTE_HASH_TREE_MAP_SIZE_KB',
36
+ parseEnv: (val)=>val ? +val : undefined,
37
+ description: 'The maximum possible size of the world state note hash tree in KB. Overwrites the general worldStateDbMapSizeKb.'
38
+ },
39
+ messageTreeMapSizeKb: {
40
+ env: 'MESSAGE_TREE_MAP_SIZE_KB',
41
+ parseEnv: (val)=>val ? +val : undefined,
42
+ description: 'The maximum possible size of the world state message tree in KB. Overwrites the general worldStateDbMapSizeKb.'
43
+ },
44
+ publicDataTreeMapSizeKb: {
45
+ env: 'PUBLIC_DATA_TREE_MAP_SIZE_KB',
46
+ parseEnv: (val)=>val ? +val : undefined,
47
+ description: 'The maximum possible size of the world state public data tree in KB. Overwrites the general worldStateDbMapSizeKb.'
23
48
  },
24
49
  worldStateDataDirectory: {
25
50
  env: 'WS_DATA_DIRECTORY',
@@ -0,0 +1,4 @@
1
+ export declare class WorldStateSynchronizerError extends Error {
2
+ constructor(message: string, options?: ErrorOptions);
3
+ }
4
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZXJyb3JzLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvc3luY2hyb25pemVyL2Vycm9ycy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxxQkFBYSwyQkFBNEIsU0FBUSxLQUFLO0lBQ3BELFlBQVksT0FBTyxFQUFFLE1BQU0sRUFBRSxPQUFPLENBQUMsRUFBRSxZQUFZLEVBRWxEO0NBQ0YifQ==
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/synchronizer/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,2BAA4B,SAAQ,KAAK;IACpD,YAAY,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,EAElD;CACF"}
@@ -0,0 +1,5 @@
1
+ export class WorldStateSynchronizerError extends Error {
2
+ constructor(message, options){
3
+ super(message, options);
4
+ }
5
+ }
@@ -7,6 +7,13 @@ import { WorldStateInstrumentation } from '../instrumentation/instrumentation.js
7
7
  import { NativeWorldStateService } from '../native/native_world_state.js';
8
8
  import type { WorldStateConfig } from './config.js';
9
9
  import { ServerWorldStateSynchronizer } from './server_world_state_synchronizer.js';
10
+ export interface WorldStateTreeMapSizes {
11
+ archiveTreeMapSizeKb: number;
12
+ nullifierTreeMapSizeKb: number;
13
+ noteHashTreeMapSizeKb: number;
14
+ messageTreeMapSizeKb: number;
15
+ publicDataTreeMapSizeKb: number;
16
+ }
10
17
  export declare function createWorldStateSynchronizer(config: WorldStateConfig & DataStoreConfig, l2BlockSource: L2BlockSource & L1ToL2MessageSource, prefilledPublicData?: PublicDataTreeLeaf[], client?: TelemetryClient): Promise<ServerWorldStateSynchronizer>;
11
- export declare function createWorldState(config: WorldStateConfig & DataStoreConfig, prefilledPublicData?: PublicDataTreeLeaf[], instrumentation?: WorldStateInstrumentation): Promise<NativeWorldStateService>;
12
- //# sourceMappingURL=factory.d.ts.map
18
+ export declare function createWorldState(config: Pick<WorldStateConfig, 'worldStateDataDirectory' | 'worldStateDbMapSizeKb' | 'archiveTreeMapSizeKb' | 'nullifierTreeMapSizeKb' | 'noteHashTreeMapSizeKb' | 'messageTreeMapSizeKb' | 'publicDataTreeMapSizeKb'> & Pick<DataStoreConfig, 'dataDirectory' | 'dataStoreMapSizeKb' | 'l1Contracts'>, prefilledPublicData?: PublicDataTreeLeaf[], instrumentation?: WorldStateInstrumentation): Promise<NativeWorldStateService>;
19
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZmFjdG9yeS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3N5bmNocm9uaXplci9mYWN0b3J5LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sS0FBSyxFQUFFLGVBQWUsRUFBRSxNQUFNLHdCQUF3QixDQUFDO0FBQzlELE9BQU8sS0FBSyxFQUFFLGFBQWEsRUFBRSxNQUFNLHFCQUFxQixDQUFDO0FBQ3pELE9BQU8sS0FBSyxFQUFFLG1CQUFtQixFQUFFLE1BQU0seUJBQXlCLENBQUM7QUFDbkUsT0FBTyxLQUFLLEVBQUUsa0JBQWtCLEVBQUUsTUFBTSxxQkFBcUIsQ0FBQztBQUM5RCxPQUFPLEVBQUUsS0FBSyxlQUFlLEVBQXNCLE1BQU0seUJBQXlCLENBQUM7QUFFbkYsT0FBTyxFQUFFLHlCQUF5QixFQUFFLE1BQU0sdUNBQXVDLENBQUM7QUFDbEYsT0FBTyxFQUFFLHVCQUF1QixFQUFFLE1BQU0saUNBQWlDLENBQUM7QUFDMUUsT0FBTyxLQUFLLEVBQUUsZ0JBQWdCLEVBQUUsTUFBTSxhQUFhLENBQUM7QUFDcEQsT0FBTyxFQUFFLDRCQUE0QixFQUFFLE1BQU0sc0NBQX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AE,MAAM,CAAC;IAC7B,sBAAsB,EAAE,MAAM,CAAC;IAC/B,qBAAqB,EAAE,MAAM,CAAC;IAC9B,oBAAoB,EAAE,MAAM,CAAC;IAC7B,uBAAuB,EAAE,MAAM,CAAC;CACjC;AAED,wBAAsB,4BAA4B,CAChD,MAAM,EAAE,gBAAgB,GAAG,eAAe,EAC1C,aAAa,EAAE,aAAa,GAAG,mBAAmB,EAClD,mBAAmB,GAAE,kBAAkB,EAAO,EAC9C,MAAM,GAAE,eAAsC,yCAK/C;AAED,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,IAAI,CACV,gBAAgB,EACd,yBAAyB,GACzB,uBAAuB,GACvB,sBAAsB,GACtB,wBAAwB,GACxB,uBAAuB,GACvB,sBAAsB,GACtB,yBAAyB,CAC5B,GACC,IAAI,CAAC,eAAe,EAAE,eAAe,GAAG,oBAAoB,GAAG,aAAa,CAAC,EAC/E,mBAAmB,GAAE,kBAAkB,EAAO,EAC9C,eAAe,GAAE,yBAA+E,oCAgCjG"}
@@ -8,15 +8,20 @@ export async function createWorldStateSynchronizer(config, l2BlockSource, prefil
8
8
  return new ServerWorldStateSynchronizer(merkleTrees, l2BlockSource, config, instrumentation);
9
9
  }
10
10
  export async function createWorldState(config, prefilledPublicData = [], instrumentation = new WorldStateInstrumentation(getTelemetryClient())) {
11
- const newConfig = {
12
- dataDirectory: config.worldStateDataDirectory ?? config.dataDirectory,
13
- dataStoreMapSizeKB: config.worldStateDbMapSizeKb ?? config.dataStoreMapSizeKB
11
+ const dataDirectory = config.worldStateDataDirectory ?? config.dataDirectory;
12
+ const dataStoreMapSizeKb = config.worldStateDbMapSizeKb ?? config.dataStoreMapSizeKb;
13
+ const wsTreeMapSizes = {
14
+ archiveTreeMapSizeKb: config.archiveTreeMapSizeKb ?? dataStoreMapSizeKb,
15
+ nullifierTreeMapSizeKb: config.nullifierTreeMapSizeKb ?? dataStoreMapSizeKb,
16
+ noteHashTreeMapSizeKb: config.noteHashTreeMapSizeKb ?? dataStoreMapSizeKb,
17
+ messageTreeMapSizeKb: config.messageTreeMapSizeKb ?? dataStoreMapSizeKb,
18
+ publicDataTreeMapSizeKb: config.publicDataTreeMapSizeKb ?? dataStoreMapSizeKb
14
19
  };
15
20
  if (!config.l1Contracts?.rollupAddress) {
16
21
  throw new Error('Rollup address is required to create a world state synchronizer.');
17
22
  }
18
23
  // If a data directory is provided in config, then create a persistent store.
19
- const merkleTrees = newConfig.dataDirectory ? await NativeWorldStateService.new(config.l1Contracts.rollupAddress, newConfig.dataDirectory, newConfig.dataStoreMapSizeKB, prefilledPublicData, instrumentation) : await NativeWorldStateService.tmp(config.l1Contracts.rollupAddress, ![
24
+ const merkleTrees = dataDirectory ? await NativeWorldStateService.new(config.l1Contracts.rollupAddress, dataDirectory, wsTreeMapSizes, prefilledPublicData, instrumentation) : await NativeWorldStateService.tmp(config.l1Contracts.rollupAddress, ![
20
25
  'true',
21
26
  '1'
22
27
  ].includes(process.env.DEBUG_WORLD_STATE), prefilledPublicData);
@@ -1,3 +1,3 @@
1
1
  export * from './server_world_state_synchronizer.js';
2
2
  export * from './factory.js';
3
- //# sourceMappingURL=index.d.ts.map
3
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9zeW5jaHJvbml6ZXIvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsY0FBYyxzQ0FBc0MsQ0FBQztBQUNyRCxjQUFjLGNBQWMsQ0FBQyJ9