@aztec/world-state 0.0.0-test.0 → 0.0.1-commit.0208eb9
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/index.d.ts +1 -1
- package/dest/instrumentation/instrumentation.d.ts +6 -4
- package/dest/instrumentation/instrumentation.d.ts.map +1 -1
- package/dest/instrumentation/instrumentation.js +25 -41
- package/dest/native/bench_metrics.d.ts +23 -0
- package/dest/native/bench_metrics.d.ts.map +1 -0
- package/dest/native/bench_metrics.js +81 -0
- package/dest/native/fork_checkpoint.d.ts +1 -1
- package/dest/native/fork_checkpoint.d.ts.map +1 -1
- package/dest/native/index.d.ts +1 -1
- package/dest/native/merkle_trees_facade.d.ts +19 -7
- package/dest/native/merkle_trees_facade.d.ts.map +1 -1
- package/dest/native/merkle_trees_facade.js +76 -14
- package/dest/native/message.d.ts +74 -52
- package/dest/native/message.d.ts.map +1 -1
- package/dest/native/message.js +61 -61
- package/dest/native/native_world_state.d.ts +27 -19
- package/dest/native/native_world_state.d.ts.map +1 -1
- package/dest/native/native_world_state.js +103 -41
- package/dest/native/native_world_state_instance.d.ts +20 -4
- package/dest/native/native_world_state_instance.d.ts.map +1 -1
- package/dest/native/native_world_state_instance.js +42 -3
- package/dest/native/world_state_ops_queue.d.ts +1 -1
- package/dest/native/world_state_ops_queue.d.ts.map +1 -1
- package/dest/native/world_state_ops_queue.js +1 -1
- package/dest/synchronizer/config.d.ts +12 -4
- package/dest/synchronizer/config.d.ts.map +1 -1
- package/dest/synchronizer/config.js +27 -7
- package/dest/synchronizer/errors.d.ts +4 -0
- package/dest/synchronizer/errors.d.ts.map +1 -0
- package/dest/synchronizer/errors.js +5 -0
- package/dest/synchronizer/factory.d.ts +11 -3
- package/dest/synchronizer/factory.d.ts.map +1 -1
- package/dest/synchronizer/factory.js +13 -8
- package/dest/synchronizer/index.d.ts +1 -1
- package/dest/synchronizer/server_world_state_synchronizer.d.ts +21 -31
- package/dest/synchronizer/server_world_state_synchronizer.d.ts.map +1 -1
- package/dest/synchronizer/server_world_state_synchronizer.js +144 -92
- package/dest/test/index.d.ts +1 -1
- package/dest/test/utils.d.ts +12 -5
- package/dest/test/utils.d.ts.map +1 -1
- package/dest/test/utils.js +54 -47
- package/dest/testing.d.ts +3 -3
- package/dest/testing.d.ts.map +1 -1
- package/dest/testing.js +7 -11
- package/dest/world-state-db/index.d.ts +1 -1
- package/dest/world-state-db/merkle_tree_db.d.ts +12 -9
- package/dest/world-state-db/merkle_tree_db.d.ts.map +1 -1
- package/package.json +24 -24
- package/src/instrumentation/instrumentation.ts +31 -43
- package/src/native/bench_metrics.ts +91 -0
- package/src/native/merkle_trees_facade.ts +83 -18
- package/src/native/message.ts +94 -74
- package/src/native/native_world_state.ts +132 -52
- package/src/native/native_world_state_instance.ts +62 -9
- package/src/native/world_state_ops_queue.ts +1 -1
- package/src/synchronizer/config.ts +48 -16
- package/src/synchronizer/errors.ts +5 -0
- package/src/synchronizer/factory.ts +38 -9
- package/src/synchronizer/server_world_state_synchronizer.ts +170 -117
- package/src/test/utils.ts +92 -82
- package/src/testing.ts +4 -8
- package/src/world-state-db/merkle_tree_db.ts +16 -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 {
|
|
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 {
|
|
6
|
+
import { tryRmDir } from '@aztec/foundation/fs';
|
|
5
7
|
import { createLogger } from '@aztec/foundation/log';
|
|
6
|
-
import { DatabaseVersionManager } from '@aztec/stdlib/database-version';
|
|
8
|
+
import { DatabaseVersionManager } from '@aztec/stdlib/database-version/manager';
|
|
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,
|
|
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 =
|
|
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;
|
|
@@ -26,33 +30,46 @@ export class NativeWorldStateService {
|
|
|
26
30
|
initialHeader;
|
|
27
31
|
// This is read heavily and only changes when data is persisted, so we cache it
|
|
28
32
|
cachedStatusSummary;
|
|
29
|
-
constructor(instance, worldStateInstrumentation, log
|
|
33
|
+
constructor(instance, worldStateInstrumentation, log, cleanup = ()=>Promise.resolve()){
|
|
30
34
|
this.instance = instance;
|
|
31
35
|
this.worldStateInstrumentation = worldStateInstrumentation;
|
|
32
36
|
this.log = log;
|
|
33
37
|
this.cleanup = cleanup;
|
|
34
38
|
}
|
|
35
|
-
static async new(rollupAddress, dataDir,
|
|
36
|
-
const
|
|
39
|
+
static async new(rollupAddress, dataDir, wsTreeMapSizes, prefilledPublicData = [], instrumentation = new WorldStateInstrumentation(getTelemetryClient()), bindings, cleanup = ()=>Promise.resolve()) {
|
|
40
|
+
const log = createLogger('world-state:database', bindings);
|
|
41
|
+
const worldStateDirectory = join(dataDir, WORLD_STATE_DIR);
|
|
37
42
|
// Create a version manager to handle versioning
|
|
38
|
-
const versionManager = new DatabaseVersionManager(
|
|
39
|
-
|
|
43
|
+
const versionManager = new DatabaseVersionManager({
|
|
44
|
+
schemaVersion: WORLD_STATE_DB_VERSION,
|
|
45
|
+
rollupAddress,
|
|
46
|
+
dataDirectory: worldStateDirectory,
|
|
47
|
+
onOpen: (dir)=>{
|
|
48
|
+
return Promise.resolve(new NativeWorldState(dir, wsTreeMapSizes, prefilledPublicData, instrumentation, bindings));
|
|
49
|
+
}
|
|
40
50
|
});
|
|
41
51
|
const [instance] = await versionManager.open();
|
|
42
52
|
const worldState = new this(instance, instrumentation, log, cleanup);
|
|
43
53
|
try {
|
|
44
54
|
await worldState.init();
|
|
45
55
|
} catch (e) {
|
|
46
|
-
log.error(`Error
|
|
56
|
+
log.error(`Error initializing world state: ${e}`);
|
|
47
57
|
throw e;
|
|
48
58
|
}
|
|
49
59
|
return worldState;
|
|
50
60
|
}
|
|
51
|
-
static async tmp(rollupAddress = EthAddress.ZERO, cleanupTmpDir = true, prefilledPublicData = [], instrumentation = new WorldStateInstrumentation(getTelemetryClient())) {
|
|
52
|
-
const log = createLogger('world-state:database');
|
|
61
|
+
static async tmp(rollupAddress = EthAddress.ZERO, cleanupTmpDir = true, prefilledPublicData = [], instrumentation = new WorldStateInstrumentation(getTelemetryClient()), bindings) {
|
|
62
|
+
const log = createLogger('world-state:database', bindings);
|
|
53
63
|
const dataDir = await mkdtemp(join(tmpdir(), 'aztec-world-state-'));
|
|
54
64
|
const dbMapSizeKb = 10 * 1024 * 1024;
|
|
55
|
-
|
|
65
|
+
const worldStateTreeMapSizes = {
|
|
66
|
+
archiveTreeMapSizeKb: dbMapSizeKb,
|
|
67
|
+
nullifierTreeMapSizeKb: dbMapSizeKb,
|
|
68
|
+
noteHashTreeMapSizeKb: dbMapSizeKb,
|
|
69
|
+
messageTreeMapSizeKb: dbMapSizeKb,
|
|
70
|
+
publicDataTreeMapSizeKb: dbMapSizeKb
|
|
71
|
+
};
|
|
72
|
+
log.debug(`Created temporary world state database at: ${dataDir} with tree map size: ${dbMapSizeKb}`);
|
|
56
73
|
// pass a cleanup callback because process.on('beforeExit', cleanup) does not work under Jest
|
|
57
74
|
const cleanup = async ()=>{
|
|
58
75
|
if (cleanupTmpDir) {
|
|
@@ -66,7 +83,7 @@ export class NativeWorldStateService {
|
|
|
66
83
|
log.debug(`Leaving temporary world state database: ${dataDir}`);
|
|
67
84
|
}
|
|
68
85
|
};
|
|
69
|
-
return this.new(rollupAddress, dataDir,
|
|
86
|
+
return this.new(rollupAddress, dataDir, worldStateTreeMapSizes, prefilledPublicData, instrumentation, bindings, cleanup);
|
|
70
87
|
}
|
|
71
88
|
async init() {
|
|
72
89
|
const status = await this.getStatusSummary();
|
|
@@ -83,32 +100,43 @@ export class NativeWorldStateService {
|
|
|
83
100
|
// the initial header _must_ be the first element in the archive tree
|
|
84
101
|
// if this assertion fails, check that the hashing done in Header in yarn-project matches the initial header hash done in world_state.cpp
|
|
85
102
|
const indices = await committed.findLeafIndices(MerkleTreeId.ARCHIVE, [
|
|
86
|
-
await this.initialHeader.hash()
|
|
103
|
+
(await this.initialHeader.hash()).toFr()
|
|
87
104
|
]);
|
|
88
105
|
const initialHeaderIndex = indices[0];
|
|
89
106
|
assert.strictEqual(initialHeaderIndex, 0n, 'Invalid initial archive state');
|
|
90
107
|
}
|
|
108
|
+
async clear() {
|
|
109
|
+
await this.instance.close();
|
|
110
|
+
this.cachedStatusSummary = undefined;
|
|
111
|
+
await tryRmDir(this.instance.getDataDir(), this.log);
|
|
112
|
+
this.instance = this.instance.clone();
|
|
113
|
+
}
|
|
91
114
|
getCommitted() {
|
|
92
|
-
return new MerkleTreesFacade(this.instance, this.initialHeader,
|
|
115
|
+
return new MerkleTreesFacade(this.instance, this.initialHeader, WorldStateRevision.empty());
|
|
93
116
|
}
|
|
94
117
|
getSnapshot(blockNumber) {
|
|
95
|
-
return new MerkleTreesFacade(this.instance, this.initialHeader,
|
|
118
|
+
return new MerkleTreesFacade(this.instance, this.initialHeader, new WorldStateRevision(/*forkId=*/ 0, /* blockNumber=*/ blockNumber, /* includeUncommitted=*/ false));
|
|
96
119
|
}
|
|
97
|
-
async fork(blockNumber) {
|
|
120
|
+
async fork(blockNumber, opts = {}) {
|
|
98
121
|
const resp = await this.instance.call(WorldStateMessageType.CREATE_FORK, {
|
|
99
122
|
latest: blockNumber === undefined,
|
|
100
|
-
blockNumber: blockNumber ??
|
|
123
|
+
blockNumber: blockNumber ?? BlockNumber.ZERO,
|
|
101
124
|
canonical: true
|
|
102
125
|
});
|
|
103
|
-
return new MerkleTreesForkFacade(this.instance, this.initialHeader,
|
|
126
|
+
return new MerkleTreesForkFacade(this.instance, this.initialHeader, new WorldStateRevision(/*forkId=*/ resp.forkId, /* blockNumber=*/ BlockNumber.ZERO, /* includeUncommitted=*/ true), opts);
|
|
104
127
|
}
|
|
105
128
|
getInitialHeader() {
|
|
106
129
|
return this.initialHeader;
|
|
107
130
|
}
|
|
108
131
|
async handleL2BlockAndMessages(l2Block, l1ToL2Messages) {
|
|
109
|
-
|
|
132
|
+
const isFirstBlock = l2Block.indexWithinCheckpoint === 0;
|
|
133
|
+
if (!isFirstBlock && l1ToL2Messages.length > 0) {
|
|
134
|
+
throw new Error(`L1 to L2 messages must be empty for non-first blocks, but got ${l1ToL2Messages.length} messages for block ${l2Block.number}.`);
|
|
135
|
+
}
|
|
136
|
+
// We have to pad the given l1 to l2 messages, and the note hashes and nullifiers within tx effects, because that's
|
|
137
|
+
// how the trees are built by circuits.
|
|
138
|
+
const paddedL1ToL2Messages = isFirstBlock ? padArrayEnd(l1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP) : [];
|
|
110
139
|
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
140
|
const paddedNullifiers = l2Block.body.txEffects.flatMap((txEffect)=>padArrayEnd(txEffect.nullifiers, Fr.ZERO, MAX_NULLIFIERS_PER_TX)).map((nullifier)=>new NullifierLeaf(nullifier));
|
|
113
141
|
const publicDataWrites = l2Block.body.txEffects.flatMap((txEffect)=>{
|
|
114
142
|
return txEffect.publicDataWrites.map((write)=>{
|
|
@@ -121,14 +149,14 @@ export class NativeWorldStateService {
|
|
|
121
149
|
try {
|
|
122
150
|
return await this.instance.call(WorldStateMessageType.SYNC_BLOCK, {
|
|
123
151
|
blockNumber: l2Block.number,
|
|
124
|
-
blockHeaderHash: await l2Block.
|
|
152
|
+
blockHeaderHash: await l2Block.hash(),
|
|
125
153
|
paddedL1ToL2Messages: paddedL1ToL2Messages.map(serializeLeaf),
|
|
126
154
|
paddedNoteHashes: paddedNoteHashes.map(serializeLeaf),
|
|
127
155
|
paddedNullifiers: paddedNullifiers.map(serializeLeaf),
|
|
128
156
|
publicDataWrites: publicDataWrites.map(serializeLeaf),
|
|
129
157
|
blockStateRef: blockStateReference(l2Block.header.state),
|
|
130
158
|
canonical: true
|
|
131
|
-
}, this.
|
|
159
|
+
}, this.sanitizeAndCacheSummaryFromFull.bind(this), this.deleteCachedSummary.bind(this));
|
|
132
160
|
} catch (err) {
|
|
133
161
|
this.worldStateInstrumentation.incCriticalErrors('synch_pending_block');
|
|
134
162
|
throw err;
|
|
@@ -144,33 +172,33 @@ export class NativeWorldStateService {
|
|
|
144
172
|
state
|
|
145
173
|
});
|
|
146
174
|
}
|
|
147
|
-
|
|
148
|
-
const
|
|
175
|
+
sanitizeAndCacheSummaryFromFull(response) {
|
|
176
|
+
const sanitized = sanitizeFullStatus(response);
|
|
149
177
|
this.cachedStatusSummary = {
|
|
150
|
-
...
|
|
178
|
+
...sanitized.summary
|
|
151
179
|
};
|
|
152
|
-
return
|
|
180
|
+
return sanitized;
|
|
153
181
|
}
|
|
154
|
-
|
|
155
|
-
const
|
|
182
|
+
sanitizeAndCacheSummary(response) {
|
|
183
|
+
const sanitized = sanitizeSummary(response);
|
|
156
184
|
this.cachedStatusSummary = {
|
|
157
|
-
...
|
|
185
|
+
...sanitized
|
|
158
186
|
};
|
|
159
|
-
return
|
|
187
|
+
return sanitized;
|
|
160
188
|
}
|
|
161
189
|
deleteCachedSummary(_) {
|
|
162
190
|
this.cachedStatusSummary = undefined;
|
|
163
191
|
}
|
|
164
192
|
/**
|
|
165
|
-
* Advances the
|
|
166
|
-
* @param toBlockNumber The block number that is now the tip of the
|
|
193
|
+
* Advances the finalized block number to be the number provided
|
|
194
|
+
* @param toBlockNumber The block number that is now the tip of the finalized chain
|
|
167
195
|
* @returns The new WorldStateStatus
|
|
168
|
-
*/ async
|
|
196
|
+
*/ async setFinalized(toBlockNumber) {
|
|
169
197
|
try {
|
|
170
|
-
await this.instance.call(WorldStateMessageType.
|
|
198
|
+
await this.instance.call(WorldStateMessageType.FINALIZE_BLOCKS, {
|
|
171
199
|
toBlockNumber,
|
|
172
200
|
canonical: true
|
|
173
|
-
}, this.
|
|
201
|
+
}, this.sanitizeAndCacheSummary.bind(this), this.deleteCachedSummary.bind(this));
|
|
174
202
|
} catch (err) {
|
|
175
203
|
this.worldStateInstrumentation.incCriticalErrors('finalize_block');
|
|
176
204
|
throw err;
|
|
@@ -186,7 +214,7 @@ export class NativeWorldStateService {
|
|
|
186
214
|
return await this.instance.call(WorldStateMessageType.REMOVE_HISTORICAL_BLOCKS, {
|
|
187
215
|
toBlockNumber,
|
|
188
216
|
canonical: true
|
|
189
|
-
}, this.
|
|
217
|
+
}, this.sanitizeAndCacheSummaryFromFull.bind(this), this.deleteCachedSummary.bind(this));
|
|
190
218
|
} catch (err) {
|
|
191
219
|
this.worldStateInstrumentation.incCriticalErrors('prune_historical_block');
|
|
192
220
|
throw err;
|
|
@@ -201,7 +229,7 @@ export class NativeWorldStateService {
|
|
|
201
229
|
return await this.instance.call(WorldStateMessageType.UNWIND_BLOCKS, {
|
|
202
230
|
toBlockNumber,
|
|
203
231
|
canonical: true
|
|
204
|
-
}, this.
|
|
232
|
+
}, this.sanitizeAndCacheSummaryFromFull.bind(this), this.deleteCachedSummary.bind(this));
|
|
205
233
|
} catch (err) {
|
|
206
234
|
this.worldStateInstrumentation.incCriticalErrors('prune_pending_block');
|
|
207
235
|
throw err;
|
|
@@ -215,7 +243,7 @@ export class NativeWorldStateService {
|
|
|
215
243
|
}
|
|
216
244
|
return await this.instance.call(WorldStateMessageType.GET_STATUS, {
|
|
217
245
|
canonical: true
|
|
218
|
-
}, this.
|
|
246
|
+
}, this.sanitizeAndCacheSummary.bind(this));
|
|
219
247
|
}
|
|
220
248
|
updateLeaf(_treeId, _leaf, _index) {
|
|
221
249
|
return Promise.reject(new Error('Method not implemented'));
|
|
@@ -226,4 +254,38 @@ export class NativeWorldStateService {
|
|
|
226
254
|
});
|
|
227
255
|
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
256
|
}
|
|
257
|
+
async backupTo(dstPath, compact = true) {
|
|
258
|
+
await this.instance.call(WorldStateMessageType.COPY_STORES, {
|
|
259
|
+
dstPath,
|
|
260
|
+
compact,
|
|
261
|
+
canonical: true
|
|
262
|
+
});
|
|
263
|
+
return fromEntries(NATIVE_WORLD_STATE_DBS.map(([name, dir])=>[
|
|
264
|
+
name,
|
|
265
|
+
join(dstPath, dir, 'data.mdb')
|
|
266
|
+
]));
|
|
267
|
+
}
|
|
229
268
|
}
|
|
269
|
+
// The following paths are defined in cpp-land
|
|
270
|
+
export const NATIVE_WORLD_STATE_DBS = [
|
|
271
|
+
[
|
|
272
|
+
'l1-to-l2-message-tree',
|
|
273
|
+
'L1ToL2MessageTree'
|
|
274
|
+
],
|
|
275
|
+
[
|
|
276
|
+
'archive-tree',
|
|
277
|
+
'ArchiveTree'
|
|
278
|
+
],
|
|
279
|
+
[
|
|
280
|
+
'public-data-tree',
|
|
281
|
+
'PublicDataTree'
|
|
282
|
+
],
|
|
283
|
+
[
|
|
284
|
+
'note-hash-tree',
|
|
285
|
+
'NoteHashTree'
|
|
286
|
+
],
|
|
287
|
+
[
|
|
288
|
+
'nullifier-tree',
|
|
289
|
+
'NullifierTree'
|
|
290
|
+
]
|
|
291
|
+
];
|
|
@@ -1,20 +1,36 @@
|
|
|
1
|
+
import { type Logger, type LoggerBindings } 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
|
|
12
|
-
private
|
|
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,
|
|
23
|
+
constructor(dataDir: string, wsTreeMapSizes: WorldStateTreeMapSizes, prefilledPublicData: PublicDataTreeLeaf[] | undefined, instrumentation: WorldStateInstrumentation, bindings?: LoggerBindings, 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=
|
|
49
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibmF0aXZlX3dvcmxkX3N0YXRlX2luc3RhbmNlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvbmF0aXZlL25hdGl2ZV93b3JsZF9zdGF0ZV9pbnN0YW5jZS50cyJdLCJuYW1lcyI6W10sIm1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SUFFdkQsT0FBTyxDQUFDLFFBQVEsQ0FBK0U7SUFFL0YsK0NBQStDO0lBQy9DLFlBQ21CLE9BQU8sRUFBRSxNQUFNLEVBQ2YsY0FBYyxFQUFFLHNCQUFzQixFQUN0QyxtQkFBbUIsa0NBQTJCLEVBQzlDLGVBQWUsRUFBRSx5QkFBeUIsRUFDM0QsUUFBUSxDQUFDLEVBQUUsY0FBYyxFQUNSLEdBQUcsR0FBRSxNQUF1RCxFQW9DOUU7SUFFTSxVQUFVLFdBRWhCO0lBRU0sS0FBSyxxQkFTWDtJQUVEOzs7Ozs7T0FNRztJQUNJLFNBQVMsSUFBSSxHQUFHLENBaUJ0QjtJQUVEOzs7Ozs7O09BT0c7SUFDVSxJQUFJLENBQUMsQ0FBQyxTQUFTLHFCQUFxQixFQUMvQyxXQUFXLEVBQUUsQ0FBQyxFQUNkLElBQUksRUFBRSxpQkFBaUIsQ0FBQyxDQUFDLENBQUMsR0FBRywyQkFBMkIsRUFFeEQsZUFBZSw2REFBdUUsRUFDdEYsWUFBWSxzQkFBb0IsR0FDL0IsT0FBTyxDQUFDLGtCQUFrQixDQUFDLENBQUMsQ0FBQyxDQUFDLENBcURoQztJQUVEOztPQUVHO0lBQ1UsS0FBSyxJQUFJLE9BQU8sQ0FBQyxJQUFJLENBQUMsQ0FlbEM7WUFFYSxZQUFZO0NBOEQzQiJ9
|
|
@@ -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":"AAUA,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,cAAc,EAAgB,MAAM,uBAAuB,CAAC;AAGvF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAK9D,OAAO,KAAK,EAAE,yBAAyB,EAA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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,
|
|
22
|
+
/** Creates a new native WorldState instance */ constructor(dataDir, wsTreeMapSizes, prefilledPublicData = [], instrumentation, bindings, log = createLogger('world-state:database', bindings)){
|
|
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
|
|
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.
|
|
45
|
+
}, prefilledPublicDataBufferArray, GeneratorIndex.BLOCK_HEADER_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.getBindings(), 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=
|
|
19
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoid29ybGRfc3RhdGVfb3BzX3F1ZXVlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvbmF0aXZlL3dvcmxkX3N0YXRlX29wc19xdWV1ZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFFQSxPQUFPLEVBQUUscUJBQXFCLEVBQUUsTUFBTSxjQUFjLENBQUM7QUF5QnJELGVBQU8sTUFBTSxrQkFBa0IsNEJBZ0I3QixDQUFDO0FBR0gscUJBQWEsa0JBQWtCO0lBQzdCLE9BQU8sQ0FBQyxRQUFRLENBQXNCO0lBQ3RDLE9BQU8sQ0FBQyxxQkFBcUIsQ0FBSztJQUNsQyxPQUFPLENBQUMsYUFBYSxDQUFLO0lBQzFCLE9BQU8sQ0FBQyxXQUFXLENBQUMsQ0FBZ0I7SUFDcEMsT0FBTyxDQUFDLFdBQVcsQ0FBQyxDQUFhO0lBQ2pDLE9BQU8sQ0FBQyxTQUFTLENBQUs7SUFDdEIsT0FBTyxDQUFDLEdBQUcsQ0FBd0M7SUFJNUMsT0FBTyxDQUFDLE9BQU8sRUFBRSxNQUFNLE9BQU8sQ0FBQyxHQUFHLENBQUMsRUFBRSxXQUFXLEVBQUUscUJBQXFCLEVBQUUsYUFBYSxFQUFFLE9BQU8sZ0JBc0JyRztJQUdELE9BQU8sQ0FBQyxlQUFlO0lBV3ZCLE9BQU8sQ0FBQyw2QkFBNkI7SUFZckMsT0FBTyxDQUFDLDJCQUEyQjtJQVVuQyxPQUFPLENBQUMsZUFBZTtJQXlDdkIsT0FBTyxDQUFDLG1CQUFtQjtJQWdCcEIsSUFBSSxrQkFnQlY7Q0FDRiJ9
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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.
|
|
15
|
+
WorldStateMessageType.FINALIZE_BLOCKS,
|
|
16
16
|
WorldStateMessageType.UNWIND_BLOCKS,
|
|
17
17
|
WorldStateMessageType.REMOVE_HISTORICAL_BLOCKS,
|
|
18
18
|
WorldStateMessageType.CREATE_CHECKPOINT,
|
|
@@ -3,12 +3,20 @@ import { type ConfigMappingsType } from '@aztec/foundation/config';
|
|
|
3
3
|
export interface WorldStateConfig {
|
|
4
4
|
/** The frequency in which to check. */
|
|
5
5
|
worldStateBlockCheckIntervalMS: number;
|
|
6
|
-
/** Whether to follow only the proven chain. */
|
|
7
|
-
worldStateProvenBlocksOnly: boolean;
|
|
8
6
|
/** Size of the batch for each get-blocks request from the synchronizer to the archiver. */
|
|
9
7
|
worldStateBlockRequestBatchSize?: number;
|
|
10
|
-
/** The map size to be provided to LMDB for each world state tree DB, optional, will inherit from the general
|
|
8
|
+
/** 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
9
|
worldStateDbMapSizeKb?: number;
|
|
10
|
+
/** The map size to be provided to LMDB for each world state archive tree, optional, will inherit from the general worldStateDbMapSizeKb if not specified*/
|
|
11
|
+
archiveTreeMapSizeKb?: number;
|
|
12
|
+
/** The map size to be provided to LMDB for each world state nullifier tree, optional, will inherit from the general worldStateDbMapSizeKb if not specified*/
|
|
13
|
+
nullifierTreeMapSizeKb?: number;
|
|
14
|
+
/** 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*/
|
|
15
|
+
noteHashTreeMapSizeKb?: number;
|
|
16
|
+
/** The map size to be provided to LMDB for each world state message tree, optional, will inherit from the general worldStateDbMapSizeKb if not specified*/
|
|
17
|
+
messageTreeMapSizeKb?: number;
|
|
18
|
+
/** 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*/
|
|
19
|
+
publicDataTreeMapSizeKb?: number;
|
|
12
20
|
/** Optional directory for the world state DB, if unspecified will default to the general data directory */
|
|
13
21
|
worldStateDataDirectory?: string;
|
|
14
22
|
/** The number of historic blocks to maintain */
|
|
@@ -20,4 +28,4 @@ export declare const worldStateConfigMappings: ConfigMappingsType<WorldStateConf
|
|
|
20
28
|
* @returns The configuration values for the world state synchronizer.
|
|
21
29
|
*/
|
|
22
30
|
export declare function getWorldStateConfigFromEnv(): WorldStateConfig;
|
|
23
|
-
//# sourceMappingURL=
|
|
31
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29uZmlnLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvc3luY2hyb25pemVyL2NvbmZpZy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsS0FBSyxrQkFBa0IsRUFBNkMsTUFBTSwwQkFBMEIsQ0FBQztBQUU5RyxxREFBcUQ7QUFDckQsTUFBTSxXQUFXLGdCQUFnQjtJQUMvQix1Q0FBdUM7SUFDdkMsOEJBQThCLEVBQUUsTUFBTSxDQUFDO0lBRXZDLDJGQUEyRjtJQUMzRiwrQkFBK0IsQ0FBQyxFQUFFLE1BQU0sQ0FBQztJQUV6QyxtSkFBbUo7SUFDbkoscUJBQXFCLENBQUMsRUFBRSxNQUFNLENBQUM7SUFFL0IsMkpBQTJKO0lBQzNKLG9CQUFvQixDQUFDLEVBQUUsTUFBTSxDQUFDO0lBRTlCLDZKQUE2SjtJQUM3SixzQkFBc0IsQ0FBQyxFQUFFLE1BQU0sQ0FBQztJQUVoQyw2SkFBNko7SUFDN0oscUJBQXFCLENBQUMsRUFBRSxNQUFNLENBQUM7SUFFL0IsMkpBQTJKO0lBQzNKLG9CQUFvQixDQUFDLEVBQUUsTUFBTSxDQUFDO0lBRTlCLCtKQUErSjtJQUMvSix1QkFBdUIsQ0FBQyxFQUFFLE1BQU0sQ0FBQztJQUVqQywyR0FBMkc7SUFDM0csdUJBQXVCLENBQUMsRUFBRSxNQUFNLENBQUM7SUFFakMsZ0RBQWdEO0lBQ2hELHNCQUFzQixFQUFFLE1BQU0sQ0FBQztDQUNoQztBQUVELGVBQU8sTUFBTSx3QkFBd0IsRUFBRSxrQkFBa0IsQ0FBQyxnQkFBZ0IsQ0F3RHpFLENBQUM7QUFFRjs7O0dBR0c7QUFDSCx3QkFBZ0IsMEJBQTBCLElBQUksZ0JBQWdCLENBRTdEIn0=
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/synchronizer/config.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/synchronizer/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,kBAAkB,EAA6C,MAAM,0BAA0B,CAAC;AAE9G,qDAAqD;AACrD,MAAM,WAAW,gBAAgB;IAC/B,uCAAuC;IACvC,8BAA8B,EAAE,MAAM,CAAC;IAEvC,2FAA2F;IAC3F,+BAA+B,CAAC,EAAE,MAAM,CAAC;IAEzC,mJAAmJ;IACnJ,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAE/B,2JAA2J;IAC3J,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAE9B,6JAA6J;IAC7J,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAEhC,6JAA6J;IAC7J,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAE/B,2JAA2J;IAC3J,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAE9B,+JAA+J;IAC/J,uBAAuB,CAAC,EAAE,MAAM,CAAC;IAEjC,2GAA2G;IAC3G,uBAAuB,CAAC,EAAE,MAAM,CAAC;IAEjC,gDAAgD;IAChD,sBAAsB,EAAE,MAAM,CAAC;CAChC;AAED,eAAO,MAAM,wBAAwB,EAAE,kBAAkB,CAAC,gBAAgB,CAwDzE,CAAC;AAEF;;;GAGG;AACH,wBAAgB,0BAA0B,IAAI,gBAAgB,CAE7D"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getConfigFromMappings, numberConfigHelper } from '@aztec/foundation/config';
|
|
2
2
|
export const worldStateConfigMappings = {
|
|
3
3
|
worldStateBlockCheckIntervalMS: {
|
|
4
4
|
env: 'WS_BLOCK_CHECK_INTERVAL_MS',
|
|
@@ -6,11 +6,6 @@ export const worldStateConfigMappings = {
|
|
|
6
6
|
defaultValue: 100,
|
|
7
7
|
description: 'The frequency in which to check.'
|
|
8
8
|
},
|
|
9
|
-
worldStateProvenBlocksOnly: {
|
|
10
|
-
env: 'WS_PROVEN_BLOCKS_ONLY',
|
|
11
|
-
description: 'Whether to follow only the proven chain.',
|
|
12
|
-
...booleanConfigHelper()
|
|
13
|
-
},
|
|
14
9
|
worldStateBlockRequestBatchSize: {
|
|
15
10
|
env: 'WS_BLOCK_REQUEST_BATCH_SIZE',
|
|
16
11
|
parseEnv: (val)=>val ? +val : undefined,
|
|
@@ -19,7 +14,32 @@ export const worldStateConfigMappings = {
|
|
|
19
14
|
worldStateDbMapSizeKb: {
|
|
20
15
|
env: 'WS_DB_MAP_SIZE_KB',
|
|
21
16
|
parseEnv: (val)=>val ? +val : undefined,
|
|
22
|
-
description: 'The maximum possible size of the world state DB'
|
|
17
|
+
description: 'The maximum possible size of the world state DB in KB. Overwrites the general dataStoreMapSizeKb.'
|
|
18
|
+
},
|
|
19
|
+
archiveTreeMapSizeKb: {
|
|
20
|
+
env: 'ARCHIVE_TREE_MAP_SIZE_KB',
|
|
21
|
+
parseEnv: (val)=>val ? +val : undefined,
|
|
22
|
+
description: 'The maximum possible size of the world state archive tree in KB. Overwrites the general worldStateDbMapSizeKb.'
|
|
23
|
+
},
|
|
24
|
+
nullifierTreeMapSizeKb: {
|
|
25
|
+
env: 'NULLIFIER_TREE_MAP_SIZE_KB',
|
|
26
|
+
parseEnv: (val)=>val ? +val : undefined,
|
|
27
|
+
description: 'The maximum possible size of the world state nullifier tree in KB. Overwrites the general worldStateDbMapSizeKb.'
|
|
28
|
+
},
|
|
29
|
+
noteHashTreeMapSizeKb: {
|
|
30
|
+
env: 'NOTE_HASH_TREE_MAP_SIZE_KB',
|
|
31
|
+
parseEnv: (val)=>val ? +val : undefined,
|
|
32
|
+
description: 'The maximum possible size of the world state note hash tree in KB. Overwrites the general worldStateDbMapSizeKb.'
|
|
33
|
+
},
|
|
34
|
+
messageTreeMapSizeKb: {
|
|
35
|
+
env: 'MESSAGE_TREE_MAP_SIZE_KB',
|
|
36
|
+
parseEnv: (val)=>val ? +val : undefined,
|
|
37
|
+
description: 'The maximum possible size of the world state message tree in KB. Overwrites the general worldStateDbMapSizeKb.'
|
|
38
|
+
},
|
|
39
|
+
publicDataTreeMapSizeKb: {
|
|
40
|
+
env: 'PUBLIC_DATA_TREE_MAP_SIZE_KB',
|
|
41
|
+
parseEnv: (val)=>val ? +val : undefined,
|
|
42
|
+
description: 'The maximum possible size of the world state public data tree in KB. Overwrites the general worldStateDbMapSizeKb.'
|
|
23
43
|
},
|
|
24
44
|
worldStateDataDirectory: {
|
|
25
45
|
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"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { LoggerBindings } from '@aztec/foundation/log';
|
|
1
2
|
import type { DataStoreConfig } from '@aztec/kv-store/config';
|
|
2
3
|
import type { L2BlockSource } from '@aztec/stdlib/block';
|
|
3
4
|
import type { L1ToL2MessageSource } from '@aztec/stdlib/messaging';
|
|
@@ -7,6 +8,13 @@ import { WorldStateInstrumentation } from '../instrumentation/instrumentation.js
|
|
|
7
8
|
import { NativeWorldStateService } from '../native/native_world_state.js';
|
|
8
9
|
import type { WorldStateConfig } from './config.js';
|
|
9
10
|
import { ServerWorldStateSynchronizer } from './server_world_state_synchronizer.js';
|
|
10
|
-
export
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
export interface WorldStateTreeMapSizes {
|
|
12
|
+
archiveTreeMapSizeKb: number;
|
|
13
|
+
nullifierTreeMapSizeKb: number;
|
|
14
|
+
noteHashTreeMapSizeKb: number;
|
|
15
|
+
messageTreeMapSizeKb: number;
|
|
16
|
+
publicDataTreeMapSizeKb: number;
|
|
17
|
+
}
|
|
18
|
+
export declare function createWorldStateSynchronizer(config: WorldStateConfig & DataStoreConfig, l2BlockSource: L2BlockSource & L1ToL2MessageSource, prefilledPublicData?: PublicDataTreeLeaf[], client?: TelemetryClient, bindings?: LoggerBindings): Promise<ServerWorldStateSynchronizer>;
|
|
19
|
+
export declare function createWorldState(config: Pick<WorldStateConfig, 'worldStateDataDirectory' | 'worldStateDbMapSizeKb' | 'archiveTreeMapSizeKb' | 'nullifierTreeMapSizeKb' | 'noteHashTreeMapSizeKb' | 'messageTreeMapSizeKb' | 'publicDataTreeMapSizeKb'> & Pick<DataStoreConfig, 'dataDirectory' | 'dataStoreMapSizeKb' | 'l1Contracts'>, prefilledPublicData?: PublicDataTreeLeaf[], instrumentation?: WorldStateInstrumentation, bindings?: LoggerBindings): Promise<NativeWorldStateService>;
|
|
20
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZmFjdG9yeS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3N5bmNocm9uaXplci9mYWN0b3J5LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sS0FBSyxFQUFFLGNBQWMsRUFBRSxNQUFNLHVCQUF1QixDQUFDO0FBQzVELE9BQU8sS0FBSyxFQUFFLGVBQWUsRUFBRSxNQUFNLHdCQUF3QixDQUFDO0FBQzlELE9BQU8sS0FBSyxFQUFFLGFBQWEsRUFBRSx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FDdEIsd0JBQXdCLEdBQ3hCLHVCQUF1QixHQUN2QixzQkFBc0IsR0FDdEIseUJBQXlCLENBQzVCLEdBQ0MsSUFBSSxDQUFDLGVBQWUsRUFBRSxlQUFlLEdBQUcsb0JBQW9CLEdBQUcsYUFBYSxDQUFDLEVBQy9FLG1CQUFtQixHQUFFLGtCQUFrQixFQUFPLEVBQzlDLGVBQWUsR0FBRSx5QkFBK0UsRUFDaEcsUUFBUSxDQUFDLEVBQUUsY0FBYyxvQ0FtQzFCIn0=
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../src/synchronizer/factory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AACnE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,EAAE,KAAK,eAAe,EAAsB,MAAM,yBAAyB,CAAC;AAEnF,OAAO,EAAE,yBAAyB,EAAE,MAAM,uCAAuC,CAAC;AAClF,OAAO,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAC1E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,4BAA4B,EAAE,MAAM,sCAAsC,CAAC;AAEpF,wBAAsB,4BAA4B,CAChD,MAAM,EAAE,gBAAgB,GAAG,eAAe,EAC1C,aAAa,EAAE,aAAa,GAAG,mBAAmB,EAClD,mBAAmB,GAAE,kBAAkB,EAAO,EAC9C,MAAM,GAAE,eAAsC,
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../src/synchronizer/factory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAu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CAAC,EAAE,cAAc,oCAmC1B"}
|
|
@@ -2,23 +2,28 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
2
2
|
import { WorldStateInstrumentation } from '../instrumentation/instrumentation.js';
|
|
3
3
|
import { NativeWorldStateService } from '../native/native_world_state.js';
|
|
4
4
|
import { ServerWorldStateSynchronizer } from './server_world_state_synchronizer.js';
|
|
5
|
-
export async function createWorldStateSynchronizer(config, l2BlockSource, prefilledPublicData = [], client = getTelemetryClient()) {
|
|
5
|
+
export async function createWorldStateSynchronizer(config, l2BlockSource, prefilledPublicData = [], client = getTelemetryClient(), bindings) {
|
|
6
6
|
const instrumentation = new WorldStateInstrumentation(client);
|
|
7
|
-
const merkleTrees = await createWorldState(config, prefilledPublicData, instrumentation);
|
|
7
|
+
const merkleTrees = await createWorldState(config, prefilledPublicData, instrumentation, bindings);
|
|
8
8
|
return new ServerWorldStateSynchronizer(merkleTrees, l2BlockSource, config, instrumentation);
|
|
9
9
|
}
|
|
10
|
-
export async function createWorldState(config, prefilledPublicData = [], instrumentation = new WorldStateInstrumentation(getTelemetryClient())) {
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
export async function createWorldState(config, prefilledPublicData = [], instrumentation = new WorldStateInstrumentation(getTelemetryClient()), bindings) {
|
|
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 =
|
|
24
|
+
const merkleTrees = dataDirectory ? await NativeWorldStateService.new(config.l1Contracts.rollupAddress, dataDirectory, wsTreeMapSizes, prefilledPublicData, instrumentation, bindings) : await NativeWorldStateService.tmp(config.l1Contracts.rollupAddress, ![
|
|
20
25
|
'true',
|
|
21
26
|
'1'
|
|
22
|
-
].includes(process.env.DEBUG_WORLD_STATE), prefilledPublicData);
|
|
27
|
+
].includes(process.env.DEBUG_WORLD_STATE), prefilledPublicData, instrumentation, bindings);
|
|
23
28
|
return merkleTrees;
|
|
24
29
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export * from './server_world_state_synchronizer.js';
|
|
2
2
|
export * from './factory.js';
|
|
3
|
-
//# sourceMappingURL=
|
|
3
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9zeW5jaHJvbml6ZXIvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsY0FBYyxzQ0FBc0MsQ0FBQztBQUNyRCxjQUFjLGNBQWMsQ0FBQyJ9
|