@aztec/world-state 0.0.1-commit.b2a5d0dd1 → 0.0.1-commit.b3d3157a
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.
- package/dest/instrumentation/instrumentation.d.ts +4 -3
- package/dest/instrumentation/instrumentation.d.ts.map +1 -1
- package/dest/instrumentation/instrumentation.js +4 -9
- package/dest/native/ipc_world_state_instance.d.ts +87 -0
- package/dest/native/ipc_world_state_instance.d.ts.map +1 -0
- package/dest/native/ipc_world_state_instance.js +660 -0
- package/dest/native/merkle_trees_facade.d.ts +6 -3
- package/dest/native/merkle_trees_facade.d.ts.map +1 -1
- package/dest/native/merkle_trees_facade.js +53 -113
- package/dest/native/message.d.ts +14 -229
- package/dest/native/message.d.ts.map +1 -1
- package/dest/native/message.js +0 -42
- package/dest/native/native_world_state.d.ts +15 -5
- package/dest/native/native_world_state.d.ts.map +1 -1
- package/dest/native/native_world_state.js +97 -51
- package/dest/native/native_world_state_instance.d.ts +58 -41
- package/dest/native/native_world_state_instance.d.ts.map +1 -1
- package/dest/native/native_world_state_instance.js +5 -203
- package/dest/native/world_state_operation.d.ts +7 -0
- package/dest/native/world_state_operation.d.ts.map +1 -0
- package/dest/native/world_state_operation.js +5 -0
- package/dest/synchronizer/config.d.ts +1 -1
- package/dest/synchronizer/config.d.ts.map +1 -1
- package/dest/synchronizer/config.js +9 -10
- package/dest/synchronizer/factory.d.ts +3 -3
- package/dest/synchronizer/factory.d.ts.map +1 -1
- package/dest/synchronizer/factory.js +5 -5
- package/dest/synchronizer/server_world_state_synchronizer.d.ts +1 -1
- package/dest/synchronizer/server_world_state_synchronizer.d.ts.map +1 -1
- package/dest/synchronizer/server_world_state_synchronizer.js +16 -13
- package/dest/testing.js +1 -1
- package/package.json +14 -10
- package/src/instrumentation/instrumentation.ts +6 -18
- package/src/native/ipc_world_state_instance.ts +830 -0
- package/src/native/merkle_trees_facade.ts +76 -108
- package/src/native/message.ts +13 -296
- package/src/native/native_world_state.ts +113 -79
- package/src/native/native_world_state_instance.ts +96 -284
- package/src/native/world_state_operation.ts +33 -0
- package/src/synchronizer/config.ts +14 -10
- package/src/synchronizer/factory.ts +8 -7
- package/src/synchronizer/server_world_state_synchronizer.ts +11 -14
- package/src/testing.ts +1 -1
- package/dest/native/world_state_ops_queue.d.ts +0 -19
- package/dest/native/world_state_ops_queue.d.ts.map +0 -1
- package/dest/native/world_state_ops_queue.js +0 -146
- package/src/native/world_state_ops_queue.ts +0 -190
|
@@ -1,9 +1,8 @@
|
|
|
1
|
+
var _computedKey;
|
|
1
2
|
import { MAX_NOTE_HASHES_PER_TX, MAX_NULLIFIERS_PER_TX, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/constants';
|
|
2
3
|
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
3
4
|
import { fromEntries, padArrayEnd } from '@aztec/foundation/collection';
|
|
4
5
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
5
|
-
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
6
|
-
import { tryRmDir } from '@aztec/foundation/fs';
|
|
7
6
|
import { createLogger } from '@aztec/foundation/log';
|
|
8
7
|
import { DatabaseVersionManager } from '@aztec/stdlib/database-version/manager';
|
|
9
8
|
import { MerkleTreeId, NullifierLeaf, PublicDataTreeLeaf } from '@aztec/stdlib/trees';
|
|
@@ -11,47 +10,63 @@ import { BlockHeader, GlobalVariables, PartialStateReference, StateReference } f
|
|
|
11
10
|
import { EMPTY_GENESIS_DATA, WorldStateRevision } from '@aztec/stdlib/world-state';
|
|
12
11
|
import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
13
12
|
import assert from 'assert/strict';
|
|
14
|
-
import { mkdtemp, rm } from 'fs/promises';
|
|
13
|
+
import { mkdir, mkdtemp, rm } from 'fs/promises';
|
|
15
14
|
import { tmpdir } from 'os';
|
|
16
15
|
import { join } from 'path';
|
|
17
16
|
import { WorldStateInstrumentation } from '../instrumentation/instrumentation.js';
|
|
17
|
+
import { IpcWorldState } from './ipc_world_state_instance.js';
|
|
18
18
|
import { MerkleTreesFacade, MerkleTreesForkFacade, serializeLeaf } from './merkle_trees_facade.js';
|
|
19
|
-
import {
|
|
20
|
-
import { NativeWorldState } from './native_world_state_instance.js';
|
|
19
|
+
import { blockStateReference, sanitizeFullStatus, sanitizeSummary, treeStateReferenceToSnapshot } from './message.js';
|
|
21
20
|
// The current version of the world state database schema
|
|
22
21
|
// Increment this when making incompatible changes to the database schema
|
|
23
22
|
export const WORLD_STATE_DB_VERSION = 2; // The initial version
|
|
24
23
|
export const WORLD_STATE_DIR = 'world_state';
|
|
24
|
+
_computedKey = Symbol.asyncDispose;
|
|
25
25
|
export class NativeWorldStateService {
|
|
26
26
|
instance;
|
|
27
27
|
worldStateInstrumentation;
|
|
28
28
|
log;
|
|
29
29
|
genesis;
|
|
30
30
|
cleanup;
|
|
31
|
+
recreateInstance;
|
|
31
32
|
initialHeader;
|
|
32
33
|
// This is read heavily and only changes when data is persisted, so we cache it
|
|
33
34
|
cachedStatusSummary;
|
|
34
|
-
constructor(instance, worldStateInstrumentation, log, genesis = EMPTY_GENESIS_DATA, cleanup = ()=>Promise.resolve()){
|
|
35
|
+
constructor(instance, worldStateInstrumentation, log, genesis = EMPTY_GENESIS_DATA, cleanup = ()=>Promise.resolve(), /** Factory to recreate a fresh IpcWorldState after clear(). */ recreateInstance){
|
|
35
36
|
this.instance = instance;
|
|
36
37
|
this.worldStateInstrumentation = worldStateInstrumentation;
|
|
37
38
|
this.log = log;
|
|
38
39
|
this.genesis = genesis;
|
|
39
40
|
this.cleanup = cleanup;
|
|
41
|
+
this.recreateInstance = recreateInstance;
|
|
40
42
|
}
|
|
41
43
|
static async new(rollupAddress, dataDir, wsTreeMapSizes, genesis = EMPTY_GENESIS_DATA, instrumentation = new WorldStateInstrumentation(getTelemetryClient()), bindings, cleanup = ()=>Promise.resolve()) {
|
|
44
|
+
for (const [key, value] of Object.entries(wsTreeMapSizes)){
|
|
45
|
+
if (value <= 0) {
|
|
46
|
+
throw new Error(`Map size must be a positive number, got ${value} for ${key}`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
42
49
|
const log = createLogger('world-state:database', bindings);
|
|
43
50
|
const worldStateDirectory = join(dataDir, WORLD_STATE_DIR);
|
|
44
|
-
// Create a version manager to handle versioning
|
|
45
51
|
const versionManager = new DatabaseVersionManager({
|
|
46
52
|
schemaVersion: WORLD_STATE_DB_VERSION,
|
|
47
53
|
rollupAddress,
|
|
48
54
|
dataDirectory: worldStateDirectory,
|
|
49
|
-
onOpen: (dir)=>
|
|
50
|
-
return Promise.resolve(new NativeWorldState(dir, wsTreeMapSizes, genesis, instrumentation, bindings));
|
|
51
|
-
}
|
|
55
|
+
onOpen: (dir)=>IpcWorldState.spawn(dir, wsTreeMapSizes, genesis, instrumentation, bindings)
|
|
52
56
|
});
|
|
53
57
|
const [instance] = await versionManager.open();
|
|
54
|
-
const
|
|
58
|
+
const recreateInstance = async ()=>{
|
|
59
|
+
await rm(worldStateDirectory, {
|
|
60
|
+
recursive: true,
|
|
61
|
+
force: true,
|
|
62
|
+
maxRetries: 3
|
|
63
|
+
});
|
|
64
|
+
await mkdir(worldStateDirectory, {
|
|
65
|
+
recursive: true
|
|
66
|
+
});
|
|
67
|
+
return IpcWorldState.spawn(worldStateDirectory, wsTreeMapSizes, genesis, instrumentation, bindings);
|
|
68
|
+
};
|
|
69
|
+
const worldState = new this(instance, instrumentation, log, genesis, cleanup, recreateInstance);
|
|
55
70
|
try {
|
|
56
71
|
await worldState.init();
|
|
57
72
|
} catch (e) {
|
|
@@ -60,7 +75,7 @@ export class NativeWorldStateService {
|
|
|
60
75
|
}
|
|
61
76
|
return worldState;
|
|
62
77
|
}
|
|
63
|
-
static async tmp(
|
|
78
|
+
static async tmp(cleanupTmpDir = true, genesis = EMPTY_GENESIS_DATA, instrumentation = new WorldStateInstrumentation(getTelemetryClient()), bindings) {
|
|
64
79
|
const log = createLogger('world-state:database', bindings);
|
|
65
80
|
const dataDir = await mkdtemp(join(tmpdir(), 'aztec-world-state-'));
|
|
66
81
|
const dbMapSizeKb = 10 * 1024 * 1024;
|
|
@@ -72,7 +87,7 @@ export class NativeWorldStateService {
|
|
|
72
87
|
publicDataTreeMapSizeKb: dbMapSizeKb
|
|
73
88
|
};
|
|
74
89
|
log.debug(`Created temporary world state database at: ${dataDir} with tree map size: ${dbMapSizeKb}`);
|
|
75
|
-
|
|
90
|
+
const instance = await IpcWorldState.spawn(dataDir, worldStateTreeMapSizes, genesis, instrumentation, bindings);
|
|
76
91
|
const cleanup = async ()=>{
|
|
77
92
|
if (cleanupTmpDir) {
|
|
78
93
|
await rm(dataDir, {
|
|
@@ -85,7 +100,35 @@ export class NativeWorldStateService {
|
|
|
85
100
|
log.debug(`Leaving temporary world state database: ${dataDir}`);
|
|
86
101
|
}
|
|
87
102
|
};
|
|
88
|
-
|
|
103
|
+
const recreateInstance = async ()=>{
|
|
104
|
+
await rm(dataDir, {
|
|
105
|
+
recursive: true,
|
|
106
|
+
force: true,
|
|
107
|
+
maxRetries: 3
|
|
108
|
+
});
|
|
109
|
+
await mkdir(dataDir, {
|
|
110
|
+
recursive: true
|
|
111
|
+
});
|
|
112
|
+
return IpcWorldState.spawn(dataDir, worldStateTreeMapSizes, genesis, instrumentation, bindings);
|
|
113
|
+
};
|
|
114
|
+
const worldState = new this(instance, instrumentation, log, genesis, cleanup, recreateInstance);
|
|
115
|
+
try {
|
|
116
|
+
await worldState.init();
|
|
117
|
+
} catch (e) {
|
|
118
|
+
log.error(`Error initializing tmp world state: ${e}`);
|
|
119
|
+
throw e;
|
|
120
|
+
}
|
|
121
|
+
return worldState;
|
|
122
|
+
}
|
|
123
|
+
static ephemeral(genesis = EMPTY_GENESIS_DATA, instrumentation = new WorldStateInstrumentation(getTelemetryClient()), bindings) {
|
|
124
|
+
return this.tmp(/*cleanupTmpDir=*/ true, genesis, instrumentation, bindings);
|
|
125
|
+
}
|
|
126
|
+
static async fromIpc(wsdbBackend, instrumentation = new WorldStateInstrumentation(getTelemetryClient()), bindings, genesis = EMPTY_GENESIS_DATA, cleanup = ()=>Promise.resolve(), recreateInstance) {
|
|
127
|
+
const log = createLogger('world-state:database', bindings);
|
|
128
|
+
const instance = new IpcWorldState(wsdbBackend, instrumentation, bindings);
|
|
129
|
+
const worldState = new this(instance, instrumentation, log, genesis, cleanup, recreateInstance);
|
|
130
|
+
await worldState.init();
|
|
131
|
+
return worldState;
|
|
89
132
|
}
|
|
90
133
|
async init() {
|
|
91
134
|
const status = await this.getStatusSummary();
|
|
@@ -108,10 +151,21 @@ export class NativeWorldStateService {
|
|
|
108
151
|
assert.strictEqual(initialHeaderIndex, 0n, 'Invalid initial archive state');
|
|
109
152
|
}
|
|
110
153
|
async clear() {
|
|
154
|
+
if (!this.recreateInstance) {
|
|
155
|
+
throw new Error('clear() is not available for externally-managed IPC backends');
|
|
156
|
+
}
|
|
157
|
+
this.log.warn('Clearing world state: shutting down WSDB, deleting data, and recreating');
|
|
111
158
|
await this.instance.close();
|
|
112
159
|
this.cachedStatusSummary = undefined;
|
|
113
|
-
|
|
114
|
-
|
|
160
|
+
this.instance = await this.recreateInstance();
|
|
161
|
+
await this.init();
|
|
162
|
+
this.log.info('World state cleared and reinitialized from genesis');
|
|
163
|
+
}
|
|
164
|
+
/** Returns the IPC path of the underlying IPC backend, if available. */ getIpcPath() {
|
|
165
|
+
if (this.instance instanceof IpcWorldState) {
|
|
166
|
+
return this.instance.getIpcPath();
|
|
167
|
+
}
|
|
168
|
+
throw new Error('getIpcPath() is only available with IPC world state');
|
|
115
169
|
}
|
|
116
170
|
getCommitted() {
|
|
117
171
|
return new MerkleTreesFacade(this.instance, this.initialHeader, WorldStateRevision.empty());
|
|
@@ -120,12 +174,11 @@ export class NativeWorldStateService {
|
|
|
120
174
|
return new MerkleTreesFacade(this.instance, this.initialHeader, new WorldStateRevision(/*forkId=*/ 0, /* blockNumber=*/ blockNumber, /* includeUncommitted=*/ false));
|
|
121
175
|
}
|
|
122
176
|
async fork(blockNumber, opts = {}) {
|
|
123
|
-
const
|
|
177
|
+
const forkId = await this.instance.createFork({
|
|
124
178
|
latest: blockNumber === undefined,
|
|
125
|
-
blockNumber: blockNumber ?? BlockNumber.ZERO
|
|
126
|
-
canonical: true
|
|
179
|
+
blockNumber: blockNumber ?? BlockNumber.ZERO
|
|
127
180
|
});
|
|
128
|
-
return new MerkleTreesForkFacade(this.instance, this.initialHeader, new WorldStateRevision(/*forkId=*/
|
|
181
|
+
return new MerkleTreesForkFacade(this.instance, this.initialHeader, new WorldStateRevision(/*forkId=*/ forkId, /* blockNumber=*/ WorldStateRevision.LATEST, /* includeUncommitted=*/ true), opts);
|
|
129
182
|
}
|
|
130
183
|
getInitialHeader() {
|
|
131
184
|
return this.initialHeader;
|
|
@@ -149,24 +202,31 @@ export class NativeWorldStateService {
|
|
|
149
202
|
});
|
|
150
203
|
});
|
|
151
204
|
try {
|
|
152
|
-
|
|
205
|
+
const status = await this.instance.syncBlock({
|
|
153
206
|
blockNumber: l2Block.number,
|
|
154
207
|
blockHeaderHash: (await l2Block.hash()).toBuffer(),
|
|
155
208
|
paddedL1ToL2Messages: paddedL1ToL2Messages.map(serializeLeaf),
|
|
156
209
|
paddedNoteHashes: paddedNoteHashes.map(serializeLeaf),
|
|
157
210
|
paddedNullifiers: paddedNullifiers.map(serializeLeaf),
|
|
158
211
|
publicDataWrites: publicDataWrites.map(serializeLeaf),
|
|
159
|
-
blockStateRef: blockStateReference(l2Block.header.state)
|
|
160
|
-
|
|
161
|
-
|
|
212
|
+
blockStateRef: blockStateReference(l2Block.header.state)
|
|
213
|
+
});
|
|
214
|
+
return this.sanitizeAndCacheSummaryFromFull(status);
|
|
162
215
|
} catch (err) {
|
|
216
|
+
this.deleteCachedSummary();
|
|
163
217
|
this.worldStateInstrumentation.incCriticalErrors('synch_pending_block');
|
|
164
218
|
throw err;
|
|
165
219
|
}
|
|
166
220
|
}
|
|
167
221
|
async close() {
|
|
168
|
-
|
|
169
|
-
|
|
222
|
+
try {
|
|
223
|
+
await this.instance.close();
|
|
224
|
+
} finally{
|
|
225
|
+
await this.cleanup();
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
async [_computedKey]() {
|
|
229
|
+
await this.close();
|
|
170
230
|
}
|
|
171
231
|
async buildInitialHeader() {
|
|
172
232
|
const state = await this.getInitialStateReference();
|
|
@@ -191,7 +251,7 @@ export class NativeWorldStateService {
|
|
|
191
251
|
};
|
|
192
252
|
return sanitized;
|
|
193
253
|
}
|
|
194
|
-
deleteCachedSummary(
|
|
254
|
+
deleteCachedSummary() {
|
|
195
255
|
this.cachedStatusSummary = undefined;
|
|
196
256
|
}
|
|
197
257
|
/**
|
|
@@ -200,11 +260,9 @@ export class NativeWorldStateService {
|
|
|
200
260
|
* @returns The new WorldStateStatus
|
|
201
261
|
*/ async setFinalized(toBlockNumber) {
|
|
202
262
|
try {
|
|
203
|
-
await this.instance.
|
|
204
|
-
toBlockNumber,
|
|
205
|
-
canonical: true
|
|
206
|
-
}, this.sanitizeAndCacheSummary.bind(this), this.deleteCachedSummary.bind(this));
|
|
263
|
+
this.sanitizeAndCacheSummary(await this.instance.finalizeBlocks(toBlockNumber));
|
|
207
264
|
} catch (err) {
|
|
265
|
+
this.deleteCachedSummary();
|
|
208
266
|
this.worldStateInstrumentation.incCriticalErrors('finalize_block');
|
|
209
267
|
throw err;
|
|
210
268
|
}
|
|
@@ -216,11 +274,9 @@ export class NativeWorldStateService {
|
|
|
216
274
|
* @returns The new WorldStateStatus
|
|
217
275
|
*/ async removeHistoricalBlocks(toBlockNumber) {
|
|
218
276
|
try {
|
|
219
|
-
return await this.instance.
|
|
220
|
-
toBlockNumber,
|
|
221
|
-
canonical: true
|
|
222
|
-
}, this.sanitizeAndCacheSummaryFromFull.bind(this), this.deleteCachedSummary.bind(this));
|
|
277
|
+
return this.sanitizeAndCacheSummaryFromFull(await this.instance.removeHistoricalBlocks(toBlockNumber));
|
|
223
278
|
} catch (err) {
|
|
279
|
+
this.deleteCachedSummary();
|
|
224
280
|
this.worldStateInstrumentation.incCriticalErrors('prune_historical_block');
|
|
225
281
|
throw err;
|
|
226
282
|
}
|
|
@@ -231,11 +287,9 @@ export class NativeWorldStateService {
|
|
|
231
287
|
* @returns The new WorldStateStatus
|
|
232
288
|
*/ async unwindBlocks(toBlockNumber) {
|
|
233
289
|
try {
|
|
234
|
-
return await this.instance.
|
|
235
|
-
toBlockNumber,
|
|
236
|
-
canonical: true
|
|
237
|
-
}, this.sanitizeAndCacheSummaryFromFull.bind(this), this.deleteCachedSummary.bind(this));
|
|
290
|
+
return this.sanitizeAndCacheSummaryFromFull(await this.instance.unwindBlocks(toBlockNumber));
|
|
238
291
|
} catch (err) {
|
|
292
|
+
this.deleteCachedSummary();
|
|
239
293
|
this.worldStateInstrumentation.incCriticalErrors('prune_pending_block');
|
|
240
294
|
throw err;
|
|
241
295
|
}
|
|
@@ -246,25 +300,17 @@ export class NativeWorldStateService {
|
|
|
246
300
|
...this.cachedStatusSummary
|
|
247
301
|
};
|
|
248
302
|
}
|
|
249
|
-
return await this.instance.
|
|
250
|
-
canonical: true
|
|
251
|
-
}, this.sanitizeAndCacheSummary.bind(this));
|
|
303
|
+
return this.sanitizeAndCacheSummary(await this.instance.getStatus());
|
|
252
304
|
}
|
|
253
305
|
updateLeaf(_treeId, _leaf, _index) {
|
|
254
306
|
return Promise.reject(new Error('Method not implemented'));
|
|
255
307
|
}
|
|
256
308
|
async getInitialStateReference() {
|
|
257
|
-
const
|
|
258
|
-
|
|
259
|
-
});
|
|
260
|
-
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])));
|
|
309
|
+
const state = await this.instance.getInitialStateReference();
|
|
310
|
+
return new StateReference(treeStateReferenceToSnapshot(state[MerkleTreeId.L1_TO_L2_MESSAGE_TREE]), new PartialStateReference(treeStateReferenceToSnapshot(state[MerkleTreeId.NOTE_HASH_TREE]), treeStateReferenceToSnapshot(state[MerkleTreeId.NULLIFIER_TREE]), treeStateReferenceToSnapshot(state[MerkleTreeId.PUBLIC_DATA_TREE])));
|
|
261
311
|
}
|
|
262
312
|
async backupTo(dstPath, compact = true) {
|
|
263
|
-
await this.instance.
|
|
264
|
-
dstPath,
|
|
265
|
-
compact,
|
|
266
|
-
canonical: true
|
|
267
|
-
});
|
|
313
|
+
await this.instance.copyStores(dstPath, compact);
|
|
268
314
|
return fromEntries(NATIVE_WORLD_STATE_DBS.map(([name, dir])=>[
|
|
269
315
|
name,
|
|
270
316
|
join(dstPath, dir, 'data.mdb')
|
|
@@ -1,49 +1,66 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
call<T extends WorldStateMessageType>(messageType: T, body: WorldStateRequest[T] & WorldStateRequestCategories): Promise<WorldStateResponse[T]>;
|
|
8
|
-
getHandle(): any;
|
|
9
|
-
}
|
|
1
|
+
import type { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
|
+
import type { IndexedTreeId, TreeInfo } from '@aztec/stdlib/interfaces/server';
|
|
4
|
+
import type { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
5
|
+
import type { WorldStateRevision } from '@aztec/stdlib/world-state';
|
|
6
|
+
import type { BlockStateReference, SerializedBatchInsertionResult, SerializedIndexedLeaf, SerializedLeafValue, SerializedSequentialInsertionResult, SerializedSiblingPathAndIndex, TreeStateReference, WorldStateStatusFull, WorldStateStatusSummary } from './message.js';
|
|
10
7
|
/**
|
|
11
|
-
*
|
|
8
|
+
* Backend-agnostic handle to a running aztec-wsdb world state, accessed by the TS layer.
|
|
9
|
+
*
|
|
10
|
+
* The legacy in-process NAPI implementation has been removed; the C++ AVM (NAPI) now connects to
|
|
11
|
+
* the same aztec-wsdb process using the IPC path returned by {@link getIpcPath}.
|
|
12
12
|
*/
|
|
13
|
-
export
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
13
|
+
export interface NativeWorldStateInstance {
|
|
14
|
+
getTreeInfo(treeId: MerkleTreeId, revision: WorldStateRevision): Promise<TreeInfo>;
|
|
15
|
+
getStateReference(revision: WorldStateRevision): Promise<Record<number, TreeStateReference>>;
|
|
16
|
+
getInitialStateReference(): Promise<Record<number, TreeStateReference>>;
|
|
17
|
+
getLeafValue(treeId: MerkleTreeId, revision: WorldStateRevision, leafIndex: bigint): Promise<SerializedLeafValue | undefined>;
|
|
18
|
+
getLeafPreimage(treeId: IndexedTreeId, revision: WorldStateRevision, leafIndex: bigint): Promise<SerializedIndexedLeaf | undefined>;
|
|
19
|
+
getSiblingPath(treeId: MerkleTreeId, revision: WorldStateRevision, leafIndex: bigint): Promise<Buffer[]>;
|
|
20
|
+
getBlockNumbersForLeafIndices(treeId: MerkleTreeId, revision: WorldStateRevision, leafIndices: bigint[]): Promise<(bigint | undefined)[]>;
|
|
21
|
+
findLeafIndices(treeId: MerkleTreeId, revision: WorldStateRevision, leaves: SerializedLeafValue[], startIndex: bigint): Promise<(bigint | undefined)[]>;
|
|
22
|
+
findLowLeaf(treeId: IndexedTreeId, revision: WorldStateRevision, key: Fr): Promise<{
|
|
23
|
+
index: bigint;
|
|
24
|
+
alreadyPresent: boolean;
|
|
25
|
+
}>;
|
|
26
|
+
findSiblingPaths(treeId: MerkleTreeId, revision: WorldStateRevision, leaves: SerializedLeafValue[]): Promise<(SerializedSiblingPathAndIndex | undefined)[]>;
|
|
27
|
+
updateArchive(forkId: number, blockStateRef: BlockStateReference, blockHeaderHash: Buffer): Promise<void>;
|
|
28
|
+
appendLeaves(treeId: MerkleTreeId, forkId: number, leaves: SerializedLeafValue[]): Promise<void>;
|
|
29
|
+
batchInsert(treeId: IndexedTreeId, forkId: number, leaves: SerializedLeafValue[], subtreeDepth: number): Promise<SerializedBatchInsertionResult>;
|
|
30
|
+
sequentialInsert(treeId: IndexedTreeId, forkId: number, leaves: SerializedLeafValue[]): Promise<SerializedSequentialInsertionResult>;
|
|
31
|
+
syncBlock(input: {
|
|
32
|
+
blockNumber: BlockNumber;
|
|
33
|
+
blockStateRef: BlockStateReference;
|
|
34
|
+
blockHeaderHash: Buffer;
|
|
35
|
+
paddedNoteHashes: readonly SerializedLeafValue[];
|
|
36
|
+
paddedL1ToL2Messages: readonly SerializedLeafValue[];
|
|
37
|
+
paddedNullifiers: readonly SerializedLeafValue[];
|
|
38
|
+
publicDataWrites: readonly SerializedLeafValue[];
|
|
39
|
+
}): Promise<WorldStateStatusFull>;
|
|
40
|
+
createFork(input: {
|
|
41
|
+
latest: boolean;
|
|
42
|
+
blockNumber: BlockNumber;
|
|
43
|
+
}): Promise<number>;
|
|
44
|
+
deleteFork(forkId: number): Promise<void>;
|
|
45
|
+
finalizeBlocks(toBlockNumber: BlockNumber): Promise<WorldStateStatusSummary>;
|
|
46
|
+
unwindBlocks(toBlockNumber: BlockNumber): Promise<WorldStateStatusFull>;
|
|
47
|
+
removeHistoricalBlocks(toBlockNumber: BlockNumber): Promise<WorldStateStatusFull>;
|
|
48
|
+
getStatus(): Promise<WorldStateStatusSummary>;
|
|
49
|
+
createCheckpoint(forkId: number): Promise<number>;
|
|
50
|
+
commitCheckpoint(forkId: number): Promise<void>;
|
|
51
|
+
revertCheckpoint(forkId: number): Promise<void>;
|
|
52
|
+
commitAllCheckpoints(forkId: number, depth: number): Promise<void>;
|
|
53
|
+
revertAllCheckpoints(forkId: number, depth: number): Promise<void>;
|
|
54
|
+
copyStores(dstPath: string, compact: boolean): Promise<void>;
|
|
34
55
|
/**
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
* @param body - The message body
|
|
38
|
-
* @param responseHandler - A callback accepting the response, executed on the job queue
|
|
39
|
-
* @param errorHandler - A callback called on request error, executed on the job queue
|
|
40
|
-
* @returns The response to the message
|
|
56
|
+
* IPC path the underlying aztec-wsdb process listens on. The C++ AVM uses this to attach to the
|
|
57
|
+
* same world state instance the TS layer is using.
|
|
41
58
|
*/
|
|
42
|
-
|
|
59
|
+
getIpcPath(): string;
|
|
43
60
|
/**
|
|
44
|
-
*
|
|
61
|
+
* Shut down the world state instance. Cancels any in-flight queues, closes the IPC channel, and
|
|
62
|
+
* terminates the underlying aztec-wsdb process. Idempotent.
|
|
45
63
|
*/
|
|
46
64
|
close(): Promise<void>;
|
|
47
|
-
private _sendMessage;
|
|
48
65
|
}
|
|
49
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
66
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibmF0aXZlX3dvcmxkX3N0YXRlX2luc3RhbmNlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvbmF0aXZlL25hdGl2ZV93b3JsZF9zdGF0ZV9pbnN0YW5jZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxXQUFXLEVBQUUsTUFBTSxpQ0FBaUMsQ0FBQztBQUNuRSxPQUFPLEtBQUssRUFBRSxFQUFFLEVBQUUsTUFBTSxnQ0FBZ0MsQ0FBQztBQUN6RCxPQUFPLEtBQUssRUFBRSxhQUFhLEVBQUUsUUFBUSxFQUFFLE1BQU0saUNBQWlDLENBQUM7QUFDL0UsT0FBTyxLQUFLLEVB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0FBQztJQUVyQjs7O09BR0c7SUFDSCxLQUFLLElBQUksT0FBTyxDQUFDLElBQUksQ0FBQyxDQUFDO0NBQ3hCIn0=
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"native_world_state_instance.d.ts","sourceRoot":"","sources":["../../src/native/native_world_state_instance.ts"],"names":[],"mappings":"
|
|
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,WAAW,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AACzD,OAAO,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAC/E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAEpE,OAAO,KAAK,EACV,mBAAmB,EACnB,8BAA8B,EAC9B,qBAAqB,EACrB,mBAAmB,EACnB,mCAAmC,EACnC,6BAA6B,EAC7B,kBAAkB,EAClB,oBAAoB,EACpB,uBAAuB,EACxB,MAAM,cAAc,CAAC;AAEtB;;;;;GAKG;AACH,MAAM,WAAW,wBAAwB;IACvC,WAAW,CAAC,MAAM,EAAE,YAAY,EAAE,QAAQ,EAAE,kBAAkB,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;IACnF,iBAAiB,CAAC,QAAQ,EAAE,kBAAkB,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC,CAAC;IAC7F,wBAAwB,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC,CAAC;IACxE,YAAY,CACV,MAAM,EAAE,YAAY,EACpB,QAAQ,EAAE,kBAAkB,EAC5B,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,mBA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gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAChD,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAChD,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACnE,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACnE,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE7D;;;OAGG;IACH,UAAU,IAAI,MAAM,CAAC;IAErB;;;OAGG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB"}
|
|
@@ -1,204 +1,6 @@
|
|
|
1
|
-
import { ARCHIVE_HEIGHT, DomainSeparator, L1_TO_L2_MSG_TREE_HEIGHT, MAX_NULLIFIERS_PER_TX, MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, NOTE_HASH_TREE_HEIGHT, NULLIFIER_TREE_HEIGHT, PUBLIC_DATA_TREE_HEIGHT } from '@aztec/constants';
|
|
2
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
3
|
-
import { NativeWorldState as BaseNativeWorldState, MsgpackChannel } from '@aztec/native';
|
|
4
|
-
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
5
|
-
import { EMPTY_GENESIS_DATA } from '@aztec/stdlib/world-state';
|
|
6
|
-
import assert from 'assert';
|
|
7
|
-
import { cpus } from 'os';
|
|
8
|
-
import { WorldStateMessageType, isWithCanonical, isWithForkId, isWithRevision } from './message.js';
|
|
9
|
-
import { WorldStateOpsQueue } from './world_state_ops_queue.js';
|
|
10
|
-
const MAX_WORLD_STATE_THREADS = +(process.env.HARDWARE_CONCURRENCY || '16');
|
|
11
1
|
/**
|
|
12
|
-
*
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
instrumentation;
|
|
18
|
-
log;
|
|
19
|
-
open;
|
|
20
|
-
// We maintain a map of queue to fork
|
|
21
|
-
queues;
|
|
22
|
-
instance;
|
|
23
|
-
/** Creates a new native WorldState instance */ constructor(dataDir, wsTreeMapSizes, genesis = EMPTY_GENESIS_DATA, instrumentation, bindings, log = createLogger('world-state:database', bindings)){
|
|
24
|
-
this.dataDir = dataDir;
|
|
25
|
-
this.wsTreeMapSizes = wsTreeMapSizes;
|
|
26
|
-
this.genesis = genesis;
|
|
27
|
-
this.instrumentation = instrumentation;
|
|
28
|
-
this.log = log;
|
|
29
|
-
this.open = true;
|
|
30
|
-
this.queues = new Map();
|
|
31
|
-
const threads = Math.min(cpus().length, MAX_WORLD_STATE_THREADS);
|
|
32
|
-
log.info(`Creating world state data store at directory ${dataDir} with map sizes ${JSON.stringify(wsTreeMapSizes)} and ${threads} threads.`);
|
|
33
|
-
const prefilledPublicDataBufferArray = genesis.prefilledPublicData.map((d)=>[
|
|
34
|
-
d.slot.toBuffer(),
|
|
35
|
-
d.value.toBuffer()
|
|
36
|
-
]);
|
|
37
|
-
const ws = new BaseNativeWorldState(dataDir, {
|
|
38
|
-
[MerkleTreeId.NULLIFIER_TREE]: NULLIFIER_TREE_HEIGHT,
|
|
39
|
-
[MerkleTreeId.NOTE_HASH_TREE]: NOTE_HASH_TREE_HEIGHT,
|
|
40
|
-
[MerkleTreeId.PUBLIC_DATA_TREE]: PUBLIC_DATA_TREE_HEIGHT,
|
|
41
|
-
[MerkleTreeId.L1_TO_L2_MESSAGE_TREE]: L1_TO_L2_MSG_TREE_HEIGHT,
|
|
42
|
-
[MerkleTreeId.ARCHIVE]: ARCHIVE_HEIGHT
|
|
43
|
-
}, {
|
|
44
|
-
[MerkleTreeId.NULLIFIER_TREE]: 2 * MAX_NULLIFIERS_PER_TX,
|
|
45
|
-
[MerkleTreeId.PUBLIC_DATA_TREE]: 2 * MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX
|
|
46
|
-
}, prefilledPublicDataBufferArray, DomainSeparator.BLOCK_HEADER_HASH, Number(genesis.genesisTimestamp), {
|
|
47
|
-
[MerkleTreeId.NULLIFIER_TREE]: wsTreeMapSizes.nullifierTreeMapSizeKb,
|
|
48
|
-
[MerkleTreeId.NOTE_HASH_TREE]: wsTreeMapSizes.noteHashTreeMapSizeKb,
|
|
49
|
-
[MerkleTreeId.PUBLIC_DATA_TREE]: wsTreeMapSizes.publicDataTreeMapSizeKb,
|
|
50
|
-
[MerkleTreeId.L1_TO_L2_MESSAGE_TREE]: wsTreeMapSizes.messageTreeMapSizeKb,
|
|
51
|
-
[MerkleTreeId.ARCHIVE]: wsTreeMapSizes.archiveTreeMapSizeKb
|
|
52
|
-
}, threads);
|
|
53
|
-
this.instance = new MsgpackChannel(ws);
|
|
54
|
-
// Manually create the queue for the canonical fork
|
|
55
|
-
this.queues.set(0, new WorldStateOpsQueue());
|
|
56
|
-
}
|
|
57
|
-
getDataDir() {
|
|
58
|
-
return this.dataDir;
|
|
59
|
-
}
|
|
60
|
-
clone() {
|
|
61
|
-
return new NativeWorldState(this.dataDir, this.wsTreeMapSizes, this.genesis, this.instrumentation, this.log.getBindings(), this.log);
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Gets the native WorldState handle from the underlying native instance.
|
|
65
|
-
* We call the getHandle() method on the native WorldState to get a NAPI External
|
|
66
|
-
* that wraps the underlying C++ WorldState pointer.
|
|
67
|
-
* @returns The NAPI External handle to the native WorldState instance,since
|
|
68
|
-
* the NAPI external type is opaque, we return any (we could also use an opaque symbol type)
|
|
69
|
-
*/ getHandle() {
|
|
70
|
-
const worldStateWrapper = this.instance.dest;
|
|
71
|
-
if (!worldStateWrapper) {
|
|
72
|
-
throw new Error('No WorldStateWrapper found');
|
|
73
|
-
}
|
|
74
|
-
if (typeof worldStateWrapper.getHandle !== 'function') {
|
|
75
|
-
throw new Error('WorldStateWrapper does not have getHandle method');
|
|
76
|
-
}
|
|
77
|
-
// Call getHandle() to get the NAPI External
|
|
78
|
-
try {
|
|
79
|
-
return worldStateWrapper.getHandle();
|
|
80
|
-
} catch (error) {
|
|
81
|
-
this.log.error('Failed to get native WorldState handle', error);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Sends a message to the native instance and returns the response.
|
|
86
|
-
* @param messageType - The type of message to send
|
|
87
|
-
* @param body - The message body
|
|
88
|
-
* @param responseHandler - A callback accepting the response, executed on the job queue
|
|
89
|
-
* @param errorHandler - A callback called on request error, executed on the job queue
|
|
90
|
-
* @returns The response to the message
|
|
91
|
-
*/ async call(messageType, body, // allows for the pre-processing of responses on the job queue before being passed back
|
|
92
|
-
responseHandler = (response)=>response, errorHandler = (_)=>{}) {
|
|
93
|
-
// Here we determine which fork the request is being executed against and whether it requires uncommitted data
|
|
94
|
-
// We use the fork Id to select the appropriate request queue and the uncommitted data flag to pass to the queue
|
|
95
|
-
let forkId = -1;
|
|
96
|
-
// We assume it includes uncommitted unless explicitly told otherwise
|
|
97
|
-
let committedOnly = false;
|
|
98
|
-
// Canonical requests ALWAYS go against the canonical fork
|
|
99
|
-
// These include things like block syncs/unwinds etc
|
|
100
|
-
// These requests don't contain a fork ID
|
|
101
|
-
if (isWithCanonical(body)) {
|
|
102
|
-
forkId = 0;
|
|
103
|
-
} else if (isWithForkId(body)) {
|
|
104
|
-
forkId = body.forkId;
|
|
105
|
-
} else if (isWithRevision(body)) {
|
|
106
|
-
forkId = body.revision.forkId;
|
|
107
|
-
committedOnly = body.revision.includeUncommitted === false;
|
|
108
|
-
} else {
|
|
109
|
-
const _ = body;
|
|
110
|
-
throw new Error(`Unable to determine forkId for message=${WorldStateMessageType[messageType]}`);
|
|
111
|
-
}
|
|
112
|
-
// Get the queue or create a new one
|
|
113
|
-
let requestQueue = this.queues.get(forkId);
|
|
114
|
-
if (requestQueue === undefined) {
|
|
115
|
-
requestQueue = new WorldStateOpsQueue();
|
|
116
|
-
this.queues.set(forkId, requestQueue);
|
|
117
|
-
}
|
|
118
|
-
// Enqueue the request and wait for the response
|
|
119
|
-
const response = await requestQueue.execute(async ()=>{
|
|
120
|
-
assert.notEqual(messageType, WorldStateMessageType.CLOSE, 'Use close() to close the native instance');
|
|
121
|
-
assert.equal(this.open, true, 'Native instance is closed');
|
|
122
|
-
let response;
|
|
123
|
-
try {
|
|
124
|
-
response = await this._sendMessage(messageType, body);
|
|
125
|
-
} catch (error) {
|
|
126
|
-
errorHandler(error.message);
|
|
127
|
-
throw error;
|
|
128
|
-
}
|
|
129
|
-
return responseHandler(response);
|
|
130
|
-
}, messageType, committedOnly);
|
|
131
|
-
// If the request was to delete the fork then we clean it up here
|
|
132
|
-
if (messageType === WorldStateMessageType.DELETE_FORK) {
|
|
133
|
-
await requestQueue.stop();
|
|
134
|
-
this.queues.delete(forkId);
|
|
135
|
-
}
|
|
136
|
-
return response;
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* Stops the native instance.
|
|
140
|
-
*/ async close() {
|
|
141
|
-
if (!this.open) {
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
144
|
-
this.open = false;
|
|
145
|
-
const queue = this.queues.get(0);
|
|
146
|
-
await queue.execute(async ()=>{
|
|
147
|
-
await this._sendMessage(WorldStateMessageType.CLOSE, {
|
|
148
|
-
canonical: true
|
|
149
|
-
});
|
|
150
|
-
}, WorldStateMessageType.CLOSE, false);
|
|
151
|
-
await queue.stop();
|
|
152
|
-
}
|
|
153
|
-
async _sendMessage(messageType, body) {
|
|
154
|
-
let logMetadata = {};
|
|
155
|
-
if (body) {
|
|
156
|
-
if ('treeId' in body) {
|
|
157
|
-
logMetadata['treeId'] = MerkleTreeId[body.treeId];
|
|
158
|
-
}
|
|
159
|
-
if ('revision' in body) {
|
|
160
|
-
logMetadata = {
|
|
161
|
-
...logMetadata,
|
|
162
|
-
...body.revision
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
if ('forkId' in body) {
|
|
166
|
-
logMetadata['forkId'] = body.forkId;
|
|
167
|
-
}
|
|
168
|
-
if ('blockNumber' in body) {
|
|
169
|
-
logMetadata['blockNumber'] = body.blockNumber;
|
|
170
|
-
}
|
|
171
|
-
if ('toBlockNumber' in body) {
|
|
172
|
-
logMetadata['toBlockNumber'] = body.toBlockNumber;
|
|
173
|
-
}
|
|
174
|
-
if ('leafIndex' in body) {
|
|
175
|
-
logMetadata['leafIndex'] = body.leafIndex;
|
|
176
|
-
}
|
|
177
|
-
if ('blockHeaderHash' in body) {
|
|
178
|
-
logMetadata['blockHeaderHash'] = '0x' + body.blockHeaderHash.toString('hex');
|
|
179
|
-
}
|
|
180
|
-
if ('leaves' in body) {
|
|
181
|
-
logMetadata['leavesCount'] = body.leaves.length;
|
|
182
|
-
}
|
|
183
|
-
// sync operation
|
|
184
|
-
if ('paddedNoteHashes' in body) {
|
|
185
|
-
logMetadata['notesCount'] = body.paddedNoteHashes.length;
|
|
186
|
-
logMetadata['nullifiersCount'] = body.paddedNullifiers.length;
|
|
187
|
-
logMetadata['l1ToL2MessagesCount'] = body.paddedL1ToL2Messages.length;
|
|
188
|
-
logMetadata['publicDataWritesCount'] = body.publicDataWrites.length;
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
try {
|
|
192
|
-
const { duration, response } = await this.instance.sendMessage(messageType, body);
|
|
193
|
-
this.log.trace(`Call ${WorldStateMessageType[messageType]} took (ms)`, {
|
|
194
|
-
duration,
|
|
195
|
-
...logMetadata
|
|
196
|
-
});
|
|
197
|
-
this.instrumentation.recordRoundTrip(duration.totalUs, messageType);
|
|
198
|
-
return response;
|
|
199
|
-
} catch (error) {
|
|
200
|
-
this.log.error(`Call ${WorldStateMessageType[messageType]} failed: ${error}`, error, logMetadata);
|
|
201
|
-
throw error;
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
}
|
|
2
|
+
* Backend-agnostic handle to a running aztec-wsdb world state, accessed by the TS layer.
|
|
3
|
+
*
|
|
4
|
+
* The legacy in-process NAPI implementation has been removed; the C++ AVM (NAPI) now connects to
|
|
5
|
+
* the same aztec-wsdb process using the IPC path returned by {@link getIpcPath}.
|
|
6
|
+
*/ export { };
|