@aztec/world-state 0.0.1-commit.2eb6648a → 0.0.1-commit.2f68f620
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/fork_checkpoint.d.ts +7 -1
- package/dest/native/fork_checkpoint.d.ts.map +1 -1
- package/dest/native/fork_checkpoint.js +15 -3
- 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 +12 -8
- package/dest/native/merkle_trees_facade.d.ts.map +1 -1
- package/dest/native/merkle_trees_facade.js +63 -115
- package/dest/native/message.d.ts +14 -222
- package/dest/native/message.d.ts.map +1 -1
- package/dest/native/message.js +0 -42
- package/dest/native/native_world_state.d.ts +19 -7
- package/dest/native/native_world_state.d.ts.map +1 -1
- package/dest/native/native_world_state.js +113 -58
- 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 -202
- 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 +3 -3
- package/dest/synchronizer/config.d.ts.map +1 -1
- package/dest/synchronizer/config.js +15 -13
- package/dest/synchronizer/factory.d.ts +5 -5
- package/dest/synchronizer/factory.d.ts.map +1 -1
- package/dest/synchronizer/factory.js +7 -6
- package/dest/synchronizer/server_world_state_synchronizer.d.ts +4 -4
- package/dest/synchronizer/server_world_state_synchronizer.d.ts.map +1 -1
- package/dest/synchronizer/server_world_state_synchronizer.js +90 -18
- package/dest/testing.d.ts +4 -3
- package/dest/testing.d.ts.map +1 -1
- package/dest/testing.js +10 -6
- package/dest/world-state-db/merkle_tree_db.d.ts +1 -10
- package/dest/world-state-db/merkle_tree_db.d.ts.map +1 -1
- package/package.json +14 -11
- package/src/instrumentation/instrumentation.ts +6 -18
- package/src/native/fork_checkpoint.ts +19 -3
- package/src/native/ipc_world_state_instance.ts +830 -0
- package/src/native/merkle_trees_facade.ts +89 -109
- package/src/native/message.ts +13 -287
- package/src/native/native_world_state.ts +129 -97
- package/src/native/native_world_state_instance.ts +96 -280
- package/src/native/world_state_operation.ts +33 -0
- package/src/synchronizer/config.ts +21 -15
- package/src/synchronizer/factory.ts +12 -11
- package/src/synchronizer/server_world_state_synchronizer.ts +95 -20
- package/src/testing.ts +8 -9
- package/src/world-state-db/merkle_tree_db.ts +0 -10
- 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,291 +1,107 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
import { cpus } from 'os';
|
|
18
|
-
|
|
19
|
-
import type { WorldStateInstrumentation } from '../instrumentation/instrumentation.js';
|
|
20
|
-
import type { WorldStateTreeMapSizes } from '../synchronizer/factory.js';
|
|
21
|
-
import {
|
|
22
|
-
WorldStateMessageType,
|
|
23
|
-
type WorldStateRequest,
|
|
24
|
-
type WorldStateRequestCategories,
|
|
25
|
-
type WorldStateResponse,
|
|
26
|
-
isWithCanonical,
|
|
27
|
-
isWithForkId,
|
|
28
|
-
isWithRevision,
|
|
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
|
+
|
|
7
|
+
import type {
|
|
8
|
+
BlockStateReference,
|
|
9
|
+
SerializedBatchInsertionResult,
|
|
10
|
+
SerializedIndexedLeaf,
|
|
11
|
+
SerializedLeafValue,
|
|
12
|
+
SerializedSequentialInsertionResult,
|
|
13
|
+
SerializedSiblingPathAndIndex,
|
|
14
|
+
TreeStateReference,
|
|
15
|
+
WorldStateStatusFull,
|
|
16
|
+
WorldStateStatusSummary,
|
|
29
17
|
} from './message.js';
|
|
30
|
-
import { WorldStateOpsQueue } from './world_state_ops_queue.js';
|
|
31
|
-
|
|
32
|
-
const MAX_WORLD_STATE_THREADS = +(process.env.HARDWARE_CONCURRENCY || '16');
|
|
33
|
-
|
|
34
|
-
export interface NativeWorldStateInstance {
|
|
35
|
-
call<T extends WorldStateMessageType>(
|
|
36
|
-
messageType: T,
|
|
37
|
-
body: WorldStateRequest[T] & WorldStateRequestCategories,
|
|
38
|
-
): Promise<WorldStateResponse[T]>;
|
|
39
|
-
// TODO(dbanks12): this returns any type, but we should strongly type it
|
|
40
|
-
getHandle(): any;
|
|
41
|
-
}
|
|
42
18
|
|
|
43
19
|
/**
|
|
44
|
-
*
|
|
20
|
+
* Backend-agnostic handle to a running aztec-wsdb world state, accessed by the TS layer.
|
|
21
|
+
*
|
|
22
|
+
* The legacy in-process NAPI implementation has been removed; the C++ AVM (NAPI) now connects to
|
|
23
|
+
* the same aztec-wsdb process using the IPC path returned by {@link getIpcPath}.
|
|
45
24
|
*/
|
|
46
|
-
export
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
25
|
+
export interface NativeWorldStateInstance {
|
|
26
|
+
getTreeInfo(treeId: MerkleTreeId, revision: WorldStateRevision): Promise<TreeInfo>;
|
|
27
|
+
getStateReference(revision: WorldStateRevision): Promise<Record<number, TreeStateReference>>;
|
|
28
|
+
getInitialStateReference(): Promise<Record<number, TreeStateReference>>;
|
|
29
|
+
getLeafValue(
|
|
30
|
+
treeId: MerkleTreeId,
|
|
31
|
+
revision: WorldStateRevision,
|
|
32
|
+
leafIndex: bigint,
|
|
33
|
+
): Promise<SerializedLeafValue | undefined>;
|
|
34
|
+
getLeafPreimage(
|
|
35
|
+
treeId: IndexedTreeId,
|
|
36
|
+
revision: WorldStateRevision,
|
|
37
|
+
leafIndex: bigint,
|
|
38
|
+
): Promise<SerializedIndexedLeaf | undefined>;
|
|
39
|
+
getSiblingPath(treeId: MerkleTreeId, revision: WorldStateRevision, leafIndex: bigint): Promise<Buffer[]>;
|
|
40
|
+
getBlockNumbersForLeafIndices(
|
|
41
|
+
treeId: MerkleTreeId,
|
|
42
|
+
revision: WorldStateRevision,
|
|
43
|
+
leafIndices: bigint[],
|
|
44
|
+
): Promise<(bigint | undefined)[]>;
|
|
45
|
+
findLeafIndices(
|
|
46
|
+
treeId: MerkleTreeId,
|
|
47
|
+
revision: WorldStateRevision,
|
|
48
|
+
leaves: SerializedLeafValue[],
|
|
49
|
+
startIndex: bigint,
|
|
50
|
+
): Promise<(bigint | undefined)[]>;
|
|
51
|
+
findLowLeaf(
|
|
52
|
+
treeId: IndexedTreeId,
|
|
53
|
+
revision: WorldStateRevision,
|
|
54
|
+
key: Fr,
|
|
55
|
+
): Promise<{ index: bigint; alreadyPresent: boolean }>;
|
|
56
|
+
findSiblingPaths(
|
|
57
|
+
treeId: MerkleTreeId,
|
|
58
|
+
revision: WorldStateRevision,
|
|
59
|
+
leaves: SerializedLeafValue[],
|
|
60
|
+
): Promise<(SerializedSiblingPathAndIndex | undefined)[]>;
|
|
61
|
+
updateArchive(forkId: number, blockStateRef: BlockStateReference, blockHeaderHash: Buffer): Promise<void>;
|
|
62
|
+
appendLeaves(treeId: MerkleTreeId, forkId: number, leaves: SerializedLeafValue[]): Promise<void>;
|
|
63
|
+
batchInsert(
|
|
64
|
+
treeId: IndexedTreeId,
|
|
65
|
+
forkId: number,
|
|
66
|
+
leaves: SerializedLeafValue[],
|
|
67
|
+
subtreeDepth: number,
|
|
68
|
+
): Promise<SerializedBatchInsertionResult>;
|
|
69
|
+
sequentialInsert(
|
|
70
|
+
treeId: IndexedTreeId,
|
|
71
|
+
forkId: number,
|
|
72
|
+
leaves: SerializedLeafValue[],
|
|
73
|
+
): Promise<SerializedSequentialInsertionResult>;
|
|
74
|
+
syncBlock(input: {
|
|
75
|
+
blockNumber: BlockNumber;
|
|
76
|
+
blockStateRef: BlockStateReference;
|
|
77
|
+
blockHeaderHash: Buffer;
|
|
78
|
+
paddedNoteHashes: readonly SerializedLeafValue[];
|
|
79
|
+
paddedL1ToL2Messages: readonly SerializedLeafValue[];
|
|
80
|
+
paddedNullifiers: readonly SerializedLeafValue[];
|
|
81
|
+
publicDataWrites: readonly SerializedLeafValue[];
|
|
82
|
+
}): Promise<WorldStateStatusFull>;
|
|
83
|
+
createFork(input: { latest: boolean; blockNumber: BlockNumber }): Promise<number>;
|
|
84
|
+
deleteFork(forkId: number): Promise<void>;
|
|
85
|
+
finalizeBlocks(toBlockNumber: BlockNumber): Promise<WorldStateStatusSummary>;
|
|
86
|
+
unwindBlocks(toBlockNumber: BlockNumber): Promise<WorldStateStatusFull>;
|
|
87
|
+
removeHistoricalBlocks(toBlockNumber: BlockNumber): Promise<WorldStateStatusFull>;
|
|
88
|
+
getStatus(): Promise<WorldStateStatusSummary>;
|
|
89
|
+
createCheckpoint(forkId: number): Promise<number>;
|
|
90
|
+
commitCheckpoint(forkId: number): Promise<void>;
|
|
91
|
+
revertCheckpoint(forkId: number): Promise<void>;
|
|
92
|
+
commitAllCheckpoints(forkId: number, depth: number): Promise<void>;
|
|
93
|
+
revertAllCheckpoints(forkId: number, depth: number): Promise<void>;
|
|
94
|
+
copyStores(dstPath: string, compact: boolean): Promise<void>;
|
|
113
95
|
|
|
114
96
|
/**
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
* that wraps the underlying C++ WorldState pointer.
|
|
118
|
-
* @returns The NAPI External handle to the native WorldState instance,since
|
|
119
|
-
* the NAPI external type is opaque, we return any (we could also use an opaque symbol type)
|
|
97
|
+
* IPC path the underlying aztec-wsdb process listens on. The C++ AVM uses this to attach to the
|
|
98
|
+
* same world state instance the TS layer is using.
|
|
120
99
|
*/
|
|
121
|
-
|
|
122
|
-
const worldStateWrapper = (this.instance as any).dest;
|
|
123
|
-
|
|
124
|
-
if (!worldStateWrapper) {
|
|
125
|
-
throw new Error('No WorldStateWrapper found');
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
if (typeof worldStateWrapper.getHandle !== 'function') {
|
|
129
|
-
throw new Error('WorldStateWrapper does not have getHandle method');
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// Call getHandle() to get the NAPI External
|
|
133
|
-
try {
|
|
134
|
-
return worldStateWrapper.getHandle();
|
|
135
|
-
} catch (error) {
|
|
136
|
-
this.log.error('Failed to get native WorldState handle', error);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
100
|
+
getIpcPath(): string;
|
|
139
101
|
|
|
140
102
|
/**
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
* @param body - The message body
|
|
144
|
-
* @param responseHandler - A callback accepting the response, executed on the job queue
|
|
145
|
-
* @param errorHandler - A callback called on request error, executed on the job queue
|
|
146
|
-
* @returns The response to the message
|
|
103
|
+
* Shut down the world state instance. Cancels any in-flight queues, closes the IPC channel, and
|
|
104
|
+
* terminates the underlying aztec-wsdb process. Idempotent.
|
|
147
105
|
*/
|
|
148
|
-
|
|
149
|
-
messageType: T,
|
|
150
|
-
body: WorldStateRequest[T] & WorldStateRequestCategories,
|
|
151
|
-
// allows for the pre-processing of responses on the job queue before being passed back
|
|
152
|
-
responseHandler = (response: WorldStateResponse[T]): WorldStateResponse[T] => response,
|
|
153
|
-
errorHandler = (_: string) => {},
|
|
154
|
-
): Promise<WorldStateResponse[T]> {
|
|
155
|
-
// Here we determine which fork the request is being executed against and whether it requires uncommitted data
|
|
156
|
-
// We use the fork Id to select the appropriate request queue and the uncommitted data flag to pass to the queue
|
|
157
|
-
let forkId = -1;
|
|
158
|
-
// We assume it includes uncommitted unless explicitly told otherwise
|
|
159
|
-
let committedOnly = false;
|
|
160
|
-
|
|
161
|
-
// Canonical requests ALWAYS go against the canonical fork
|
|
162
|
-
// These include things like block syncs/unwinds etc
|
|
163
|
-
// These requests don't contain a fork ID
|
|
164
|
-
if (isWithCanonical(body)) {
|
|
165
|
-
forkId = 0;
|
|
166
|
-
} else if (isWithForkId(body)) {
|
|
167
|
-
forkId = body.forkId;
|
|
168
|
-
} else if (isWithRevision(body)) {
|
|
169
|
-
forkId = body.revision.forkId;
|
|
170
|
-
committedOnly = body.revision.includeUncommitted === false;
|
|
171
|
-
} else {
|
|
172
|
-
const _: never = body;
|
|
173
|
-
throw new Error(`Unable to determine forkId for message=${WorldStateMessageType[messageType]}`);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
// Get the queue or create a new one
|
|
177
|
-
let requestQueue = this.queues.get(forkId);
|
|
178
|
-
if (requestQueue === undefined) {
|
|
179
|
-
requestQueue = new WorldStateOpsQueue();
|
|
180
|
-
this.queues.set(forkId, requestQueue);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
// Enqueue the request and wait for the response
|
|
184
|
-
const response = await requestQueue.execute(
|
|
185
|
-
async () => {
|
|
186
|
-
assert.notEqual(messageType, WorldStateMessageType.CLOSE, 'Use close() to close the native instance');
|
|
187
|
-
assert.equal(this.open, true, 'Native instance is closed');
|
|
188
|
-
let response: WorldStateResponse[T];
|
|
189
|
-
try {
|
|
190
|
-
response = await this._sendMessage(messageType, body);
|
|
191
|
-
} catch (error: any) {
|
|
192
|
-
errorHandler(error.message);
|
|
193
|
-
throw error;
|
|
194
|
-
}
|
|
195
|
-
return responseHandler(response);
|
|
196
|
-
},
|
|
197
|
-
messageType,
|
|
198
|
-
committedOnly,
|
|
199
|
-
);
|
|
200
|
-
|
|
201
|
-
// If the request was to delete the fork then we clean it up here
|
|
202
|
-
if (messageType === WorldStateMessageType.DELETE_FORK) {
|
|
203
|
-
await requestQueue.stop();
|
|
204
|
-
this.queues.delete(forkId);
|
|
205
|
-
}
|
|
206
|
-
return response;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
/**
|
|
210
|
-
* Stops the native instance.
|
|
211
|
-
*/
|
|
212
|
-
public async close(): Promise<void> {
|
|
213
|
-
if (!this.open) {
|
|
214
|
-
return;
|
|
215
|
-
}
|
|
216
|
-
this.open = false;
|
|
217
|
-
const queue = this.queues.get(0)!;
|
|
218
|
-
|
|
219
|
-
await queue.execute(
|
|
220
|
-
async () => {
|
|
221
|
-
await this._sendMessage(WorldStateMessageType.CLOSE, { canonical: true });
|
|
222
|
-
},
|
|
223
|
-
WorldStateMessageType.CLOSE,
|
|
224
|
-
false,
|
|
225
|
-
);
|
|
226
|
-
await queue.stop();
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
private async _sendMessage<T extends WorldStateMessageType>(
|
|
230
|
-
messageType: T,
|
|
231
|
-
body: WorldStateRequest[T] & WorldStateRequestCategories,
|
|
232
|
-
): Promise<WorldStateResponse[T]> {
|
|
233
|
-
let logMetadata: Record<string, any> = {};
|
|
234
|
-
|
|
235
|
-
if (body) {
|
|
236
|
-
if ('treeId' in body) {
|
|
237
|
-
logMetadata['treeId'] = MerkleTreeId[body.treeId];
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
if ('revision' in body) {
|
|
241
|
-
logMetadata = { ...logMetadata, ...body.revision };
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
if ('forkId' in body) {
|
|
245
|
-
logMetadata['forkId'] = body.forkId;
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
if ('blockNumber' in body) {
|
|
249
|
-
logMetadata['blockNumber'] = body.blockNumber;
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
if ('toBlockNumber' in body) {
|
|
253
|
-
logMetadata['toBlockNumber'] = body.toBlockNumber;
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
if ('leafIndex' in body) {
|
|
257
|
-
logMetadata['leafIndex'] = body.leafIndex;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
if ('blockHeaderHash' in body) {
|
|
261
|
-
logMetadata['blockHeaderHash'] = '0x' + body.blockHeaderHash.toString('hex');
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
if ('leaves' in body) {
|
|
265
|
-
logMetadata['leavesCount'] = body.leaves.length;
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
// sync operation
|
|
269
|
-
if ('paddedNoteHashes' in body) {
|
|
270
|
-
logMetadata['notesCount'] = body.paddedNoteHashes.length;
|
|
271
|
-
logMetadata['nullifiersCount'] = body.paddedNullifiers.length;
|
|
272
|
-
logMetadata['l1ToL2MessagesCount'] = body.paddedL1ToL2Messages.length;
|
|
273
|
-
logMetadata['publicDataWritesCount'] = body.publicDataWrites.length;
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
try {
|
|
278
|
-
const { duration, response } = await this.instance.sendMessage(messageType, body);
|
|
279
|
-
this.log.trace(`Call ${WorldStateMessageType[messageType]} took (ms)`, {
|
|
280
|
-
duration,
|
|
281
|
-
...logMetadata,
|
|
282
|
-
});
|
|
283
|
-
|
|
284
|
-
this.instrumentation.recordRoundTrip(duration.totalUs, messageType);
|
|
285
|
-
return response;
|
|
286
|
-
} catch (error) {
|
|
287
|
-
this.log.error(`Call ${WorldStateMessageType[messageType]} failed: ${error}`, error, logMetadata);
|
|
288
|
-
throw error;
|
|
289
|
-
}
|
|
290
|
-
}
|
|
106
|
+
close(): Promise<void>;
|
|
291
107
|
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Names of the world-state operations, used as labels for instrumentation and
|
|
3
|
+
* logging. (Read/write ordering is enforced server-side by the wsdb scheduler,
|
|
4
|
+
* so there is no longer a client-side operation queue.)
|
|
5
|
+
*/
|
|
6
|
+
export type WorldStateOperationName =
|
|
7
|
+
| 'getTreeInfo'
|
|
8
|
+
| 'getStateReference'
|
|
9
|
+
| 'getInitialStateReference'
|
|
10
|
+
| 'getLeafValue'
|
|
11
|
+
| 'getLeafPreimage'
|
|
12
|
+
| 'getSiblingPath'
|
|
13
|
+
| 'getBlockNumbersForLeafIndices'
|
|
14
|
+
| 'findLeafIndices'
|
|
15
|
+
| 'findLowLeaf'
|
|
16
|
+
| 'findSiblingPaths'
|
|
17
|
+
| 'appendLeaves'
|
|
18
|
+
| 'batchInsert'
|
|
19
|
+
| 'sequentialInsert'
|
|
20
|
+
| 'updateArchive'
|
|
21
|
+
| 'syncBlock'
|
|
22
|
+
| 'createFork'
|
|
23
|
+
| 'deleteFork'
|
|
24
|
+
| 'finalizeBlocks'
|
|
25
|
+
| 'unwindBlocks'
|
|
26
|
+
| 'removeHistoricalBlocks'
|
|
27
|
+
| 'getStatus'
|
|
28
|
+
| 'createCheckpoint'
|
|
29
|
+
| 'commitCheckpoint'
|
|
30
|
+
| 'revertCheckpoint'
|
|
31
|
+
| 'commitAllCheckpoints'
|
|
32
|
+
| 'revertAllCheckpoints'
|
|
33
|
+
| 'copyStores';
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
type ConfigMappingsType,
|
|
3
|
+
getConfigFromMappings,
|
|
4
|
+
numberConfigHelper,
|
|
5
|
+
optionalNumberConfigHelper,
|
|
6
|
+
} from '@aztec/foundation/config';
|
|
2
7
|
|
|
3
8
|
/** World State synchronizer configuration values. */
|
|
4
9
|
export interface WorldStateConfig {
|
|
@@ -29,54 +34,53 @@ export interface WorldStateConfig {
|
|
|
29
34
|
/** Optional directory for the world state DB, if unspecified will default to the general data directory */
|
|
30
35
|
worldStateDataDirectory?: string;
|
|
31
36
|
|
|
32
|
-
/** The number of historic blocks to maintain */
|
|
33
|
-
|
|
37
|
+
/** The number of historic checkpoints worth of blocks to maintain */
|
|
38
|
+
worldStateCheckpointHistory: number;
|
|
34
39
|
}
|
|
35
40
|
|
|
36
41
|
export const worldStateConfigMappings: ConfigMappingsType<WorldStateConfig> = {
|
|
37
42
|
worldStateBlockCheckIntervalMS: {
|
|
38
43
|
env: 'WS_BLOCK_CHECK_INTERVAL_MS',
|
|
39
|
-
|
|
40
|
-
defaultValue: 100,
|
|
44
|
+
...numberConfigHelper(100),
|
|
41
45
|
description: 'The frequency in which to check.',
|
|
42
46
|
},
|
|
43
47
|
worldStateBlockRequestBatchSize: {
|
|
44
48
|
env: 'WS_BLOCK_REQUEST_BATCH_SIZE',
|
|
45
|
-
|
|
49
|
+
...optionalNumberConfigHelper(),
|
|
46
50
|
description: 'Size of the batch for each get-blocks request from the synchronizer to the archiver.',
|
|
47
51
|
},
|
|
48
52
|
worldStateDbMapSizeKb: {
|
|
49
53
|
env: 'WS_DB_MAP_SIZE_KB',
|
|
50
|
-
|
|
54
|
+
...optionalNumberConfigHelper(),
|
|
51
55
|
description: 'The maximum possible size of the world state DB in KB. Overwrites the general dataStoreMapSizeKb.',
|
|
52
56
|
},
|
|
53
57
|
archiveTreeMapSizeKb: {
|
|
54
58
|
env: 'ARCHIVE_TREE_MAP_SIZE_KB',
|
|
55
|
-
|
|
59
|
+
...optionalNumberConfigHelper(),
|
|
56
60
|
description:
|
|
57
61
|
'The maximum possible size of the world state archive tree in KB. Overwrites the general worldStateDbMapSizeKb.',
|
|
58
62
|
},
|
|
59
63
|
nullifierTreeMapSizeKb: {
|
|
60
64
|
env: 'NULLIFIER_TREE_MAP_SIZE_KB',
|
|
61
|
-
|
|
65
|
+
...optionalNumberConfigHelper(),
|
|
62
66
|
description:
|
|
63
67
|
'The maximum possible size of the world state nullifier tree in KB. Overwrites the general worldStateDbMapSizeKb.',
|
|
64
68
|
},
|
|
65
69
|
noteHashTreeMapSizeKb: {
|
|
66
70
|
env: 'NOTE_HASH_TREE_MAP_SIZE_KB',
|
|
67
|
-
|
|
71
|
+
...optionalNumberConfigHelper(),
|
|
68
72
|
description:
|
|
69
73
|
'The maximum possible size of the world state note hash tree in KB. Overwrites the general worldStateDbMapSizeKb.',
|
|
70
74
|
},
|
|
71
75
|
messageTreeMapSizeKb: {
|
|
72
76
|
env: 'MESSAGE_TREE_MAP_SIZE_KB',
|
|
73
|
-
|
|
77
|
+
...optionalNumberConfigHelper(),
|
|
74
78
|
description:
|
|
75
79
|
'The maximum possible size of the world state message tree in KB. Overwrites the general worldStateDbMapSizeKb.',
|
|
76
80
|
},
|
|
77
81
|
publicDataTreeMapSizeKb: {
|
|
78
82
|
env: 'PUBLIC_DATA_TREE_MAP_SIZE_KB',
|
|
79
|
-
|
|
83
|
+
...optionalNumberConfigHelper(),
|
|
80
84
|
description:
|
|
81
85
|
'The maximum possible size of the world state public data tree in KB. Overwrites the general worldStateDbMapSizeKb.',
|
|
82
86
|
},
|
|
@@ -84,9 +88,11 @@ export const worldStateConfigMappings: ConfigMappingsType<WorldStateConfig> = {
|
|
|
84
88
|
env: 'WS_DATA_DIRECTORY',
|
|
85
89
|
description: 'Optional directory for the world state database',
|
|
86
90
|
},
|
|
87
|
-
|
|
88
|
-
env: '
|
|
89
|
-
description:
|
|
91
|
+
worldStateCheckpointHistory: {
|
|
92
|
+
env: 'WS_NUM_HISTORIC_CHECKPOINTS',
|
|
93
|
+
description:
|
|
94
|
+
'The number of historic checkpoints worth of blocks to maintain. Values less than 1 mean all history is maintained',
|
|
95
|
+
fallback: ['WS_NUM_HISTORIC_BLOCKS'],
|
|
90
96
|
...numberConfigHelper(64),
|
|
91
97
|
},
|
|
92
98
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { LoggerBindings } from '@aztec/foundation/log';
|
|
2
|
-
import type { DataStoreConfig } from '@aztec/kv-store/config';
|
|
3
2
|
import type { L2BlockSource } from '@aztec/stdlib/block';
|
|
3
|
+
import type { DataStoreConfig } from '@aztec/stdlib/kv-store';
|
|
4
4
|
import type { L1ToL2MessageSource } from '@aztec/stdlib/messaging';
|
|
5
|
-
import type
|
|
5
|
+
import { EMPTY_GENESIS_DATA, type GenesisData, isGenesisData } from '@aztec/stdlib/world-state';
|
|
6
6
|
import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
|
|
7
7
|
|
|
8
8
|
import { WorldStateInstrumentation } from '../instrumentation/instrumentation.js';
|
|
@@ -21,12 +21,14 @@ export interface WorldStateTreeMapSizes {
|
|
|
21
21
|
export async function createWorldStateSynchronizer(
|
|
22
22
|
config: WorldStateConfig & DataStoreConfig,
|
|
23
23
|
l2BlockSource: L2BlockSource & L1ToL2MessageSource,
|
|
24
|
-
|
|
24
|
+
genesisOrNativeWorldState: GenesisData | NativeWorldStateService,
|
|
25
25
|
client: TelemetryClient = getTelemetryClient(),
|
|
26
26
|
bindings?: LoggerBindings,
|
|
27
27
|
) {
|
|
28
28
|
const instrumentation = new WorldStateInstrumentation(client);
|
|
29
|
-
const merkleTrees =
|
|
29
|
+
const merkleTrees = isGenesisData(genesisOrNativeWorldState)
|
|
30
|
+
? await createWorldState(config, genesisOrNativeWorldState, instrumentation, bindings)
|
|
31
|
+
: genesisOrNativeWorldState;
|
|
30
32
|
return new ServerWorldStateSynchronizer(merkleTrees, l2BlockSource, config, instrumentation);
|
|
31
33
|
}
|
|
32
34
|
|
|
@@ -41,8 +43,8 @@ export async function createWorldState(
|
|
|
41
43
|
| 'messageTreeMapSizeKb'
|
|
42
44
|
| 'publicDataTreeMapSizeKb'
|
|
43
45
|
> &
|
|
44
|
-
Pick<DataStoreConfig, 'dataDirectory' | 'dataStoreMapSizeKb' | '
|
|
45
|
-
|
|
46
|
+
Pick<DataStoreConfig, 'dataDirectory' | 'dataStoreMapSizeKb' | 'rollupAddress'>,
|
|
47
|
+
genesis: GenesisData = EMPTY_GENESIS_DATA,
|
|
46
48
|
instrumentation: WorldStateInstrumentation = new WorldStateInstrumentation(getTelemetryClient()),
|
|
47
49
|
bindings?: LoggerBindings,
|
|
48
50
|
) {
|
|
@@ -56,24 +58,23 @@ export async function createWorldState(
|
|
|
56
58
|
publicDataTreeMapSizeKb: config.publicDataTreeMapSizeKb ?? dataStoreMapSizeKb,
|
|
57
59
|
};
|
|
58
60
|
|
|
59
|
-
if (!config.
|
|
61
|
+
if (!config.rollupAddress) {
|
|
60
62
|
throw new Error('Rollup address is required to create a world state synchronizer.');
|
|
61
63
|
}
|
|
62
64
|
|
|
63
65
|
// If a data directory is provided in config, then create a persistent store.
|
|
64
66
|
const merkleTrees = dataDirectory
|
|
65
67
|
? await NativeWorldStateService.new(
|
|
66
|
-
config.
|
|
68
|
+
config.rollupAddress,
|
|
67
69
|
dataDirectory,
|
|
68
70
|
wsTreeMapSizes,
|
|
69
|
-
|
|
71
|
+
genesis,
|
|
70
72
|
instrumentation,
|
|
71
73
|
bindings,
|
|
72
74
|
)
|
|
73
75
|
: await NativeWorldStateService.tmp(
|
|
74
|
-
config.l1Contracts.rollupAddress,
|
|
75
76
|
!['true', '1'].includes(process.env.DEBUG_WORLD_STATE!),
|
|
76
|
-
|
|
77
|
+
genesis,
|
|
77
78
|
instrumentation,
|
|
78
79
|
bindings,
|
|
79
80
|
);
|