@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,295 +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
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
}
|
|
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>;
|
|
117
95
|
|
|
118
96
|
/**
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
* that wraps the underlying C++ WorldState pointer.
|
|
122
|
-
* @returns The NAPI External handle to the native WorldState instance,since
|
|
123
|
-
* 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.
|
|
124
99
|
*/
|
|
125
|
-
|
|
126
|
-
const worldStateWrapper = (this.instance as any).dest;
|
|
127
|
-
|
|
128
|
-
if (!worldStateWrapper) {
|
|
129
|
-
throw new Error('No WorldStateWrapper found');
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
if (typeof worldStateWrapper.getHandle !== 'function') {
|
|
133
|
-
throw new Error('WorldStateWrapper does not have getHandle method');
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
// Call getHandle() to get the NAPI External
|
|
137
|
-
try {
|
|
138
|
-
return worldStateWrapper.getHandle();
|
|
139
|
-
} catch (error) {
|
|
140
|
-
this.log.error('Failed to get native WorldState handle', error);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
100
|
+
getIpcPath(): string;
|
|
143
101
|
|
|
144
102
|
/**
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
* @param body - The message body
|
|
148
|
-
* @param responseHandler - A callback accepting the response, executed on the job queue
|
|
149
|
-
* @param errorHandler - A callback called on request error, executed on the job queue
|
|
150
|
-
* @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.
|
|
151
105
|
*/
|
|
152
|
-
|
|
153
|
-
messageType: T,
|
|
154
|
-
body: WorldStateRequest[T] & WorldStateRequestCategories,
|
|
155
|
-
// allows for the pre-processing of responses on the job queue before being passed back
|
|
156
|
-
responseHandler = (response: WorldStateResponse[T]): WorldStateResponse[T] => response,
|
|
157
|
-
errorHandler = (_: string) => {},
|
|
158
|
-
): Promise<WorldStateResponse[T]> {
|
|
159
|
-
// Here we determine which fork the request is being executed against and whether it requires uncommitted data
|
|
160
|
-
// We use the fork Id to select the appropriate request queue and the uncommitted data flag to pass to the queue
|
|
161
|
-
let forkId = -1;
|
|
162
|
-
// We assume it includes uncommitted unless explicitly told otherwise
|
|
163
|
-
let committedOnly = false;
|
|
164
|
-
|
|
165
|
-
// Canonical requests ALWAYS go against the canonical fork
|
|
166
|
-
// These include things like block syncs/unwinds etc
|
|
167
|
-
// These requests don't contain a fork ID
|
|
168
|
-
if (isWithCanonical(body)) {
|
|
169
|
-
forkId = 0;
|
|
170
|
-
} else if (isWithForkId(body)) {
|
|
171
|
-
forkId = body.forkId;
|
|
172
|
-
} else if (isWithRevision(body)) {
|
|
173
|
-
forkId = body.revision.forkId;
|
|
174
|
-
committedOnly = body.revision.includeUncommitted === false;
|
|
175
|
-
} else {
|
|
176
|
-
const _: never = body;
|
|
177
|
-
throw new Error(`Unable to determine forkId for message=${WorldStateMessageType[messageType]}`);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
// Get the queue or create a new one
|
|
181
|
-
let requestQueue = this.queues.get(forkId);
|
|
182
|
-
if (requestQueue === undefined) {
|
|
183
|
-
requestQueue = new WorldStateOpsQueue();
|
|
184
|
-
this.queues.set(forkId, requestQueue);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
// Enqueue the request and wait for the response
|
|
188
|
-
const response = await requestQueue.execute(
|
|
189
|
-
async () => {
|
|
190
|
-
assert.notEqual(messageType, WorldStateMessageType.CLOSE, 'Use close() to close the native instance');
|
|
191
|
-
assert.equal(this.open, true, 'Native instance is closed');
|
|
192
|
-
let response: WorldStateResponse[T];
|
|
193
|
-
try {
|
|
194
|
-
response = await this._sendMessage(messageType, body);
|
|
195
|
-
} catch (error: any) {
|
|
196
|
-
errorHandler(error.message);
|
|
197
|
-
throw error;
|
|
198
|
-
}
|
|
199
|
-
return responseHandler(response);
|
|
200
|
-
},
|
|
201
|
-
messageType,
|
|
202
|
-
committedOnly,
|
|
203
|
-
);
|
|
204
|
-
|
|
205
|
-
// If the request was to delete the fork then we clean it up here
|
|
206
|
-
if (messageType === WorldStateMessageType.DELETE_FORK) {
|
|
207
|
-
await requestQueue.stop();
|
|
208
|
-
this.queues.delete(forkId);
|
|
209
|
-
}
|
|
210
|
-
return response;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
/**
|
|
214
|
-
* Stops the native instance.
|
|
215
|
-
*/
|
|
216
|
-
public async close(): Promise<void> {
|
|
217
|
-
if (!this.open) {
|
|
218
|
-
return;
|
|
219
|
-
}
|
|
220
|
-
this.open = false;
|
|
221
|
-
const queue = this.queues.get(0)!;
|
|
222
|
-
|
|
223
|
-
await queue.execute(
|
|
224
|
-
async () => {
|
|
225
|
-
await this._sendMessage(WorldStateMessageType.CLOSE, { canonical: true });
|
|
226
|
-
},
|
|
227
|
-
WorldStateMessageType.CLOSE,
|
|
228
|
-
false,
|
|
229
|
-
);
|
|
230
|
-
await queue.stop();
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
private async _sendMessage<T extends WorldStateMessageType>(
|
|
234
|
-
messageType: T,
|
|
235
|
-
body: WorldStateRequest[T] & WorldStateRequestCategories,
|
|
236
|
-
): Promise<WorldStateResponse[T]> {
|
|
237
|
-
let logMetadata: Record<string, any> = {};
|
|
238
|
-
|
|
239
|
-
if (body) {
|
|
240
|
-
if ('treeId' in body) {
|
|
241
|
-
logMetadata['treeId'] = MerkleTreeId[body.treeId];
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
if ('revision' in body) {
|
|
245
|
-
logMetadata = { ...logMetadata, ...body.revision };
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
if ('forkId' in body) {
|
|
249
|
-
logMetadata['forkId'] = body.forkId;
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
if ('blockNumber' in body) {
|
|
253
|
-
logMetadata['blockNumber'] = body.blockNumber;
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
if ('toBlockNumber' in body) {
|
|
257
|
-
logMetadata['toBlockNumber'] = body.toBlockNumber;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
if ('leafIndex' in body) {
|
|
261
|
-
logMetadata['leafIndex'] = body.leafIndex;
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
if ('blockHeaderHash' in body) {
|
|
265
|
-
logMetadata['blockHeaderHash'] = '0x' + body.blockHeaderHash.toString('hex');
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
if ('leaves' in body) {
|
|
269
|
-
logMetadata['leavesCount'] = body.leaves.length;
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
// sync operation
|
|
273
|
-
if ('paddedNoteHashes' in body) {
|
|
274
|
-
logMetadata['notesCount'] = body.paddedNoteHashes.length;
|
|
275
|
-
logMetadata['nullifiersCount'] = body.paddedNullifiers.length;
|
|
276
|
-
logMetadata['l1ToL2MessagesCount'] = body.paddedL1ToL2Messages.length;
|
|
277
|
-
logMetadata['publicDataWritesCount'] = body.publicDataWrites.length;
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
try {
|
|
282
|
-
const { duration, response } = await this.instance.sendMessage(messageType, body);
|
|
283
|
-
this.log.trace(`Call ${WorldStateMessageType[messageType]} took (ms)`, {
|
|
284
|
-
duration,
|
|
285
|
-
...logMetadata,
|
|
286
|
-
});
|
|
287
|
-
|
|
288
|
-
this.instrumentation.recordRoundTrip(duration.totalUs, messageType);
|
|
289
|
-
return response;
|
|
290
|
-
} catch (error) {
|
|
291
|
-
this.log.error(`Call ${WorldStateMessageType[messageType]} failed: ${error}`, error, logMetadata);
|
|
292
|
-
throw error;
|
|
293
|
-
}
|
|
294
|
-
}
|
|
106
|
+
close(): Promise<void>;
|
|
295
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 {
|
|
@@ -36,47 +41,46 @@ export interface WorldStateConfig {
|
|
|
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
|
},
|
|
@@ -2,7 +2,7 @@ import type { LoggerBindings } from '@aztec/foundation/log';
|
|
|
2
2
|
import type { L2BlockSource } from '@aztec/stdlib/block';
|
|
3
3
|
import type { DataStoreConfig } from '@aztec/stdlib/kv-store';
|
|
4
4
|
import type { L1ToL2MessageSource } from '@aztec/stdlib/messaging';
|
|
5
|
-
import { EMPTY_GENESIS_DATA, type GenesisData } from '@aztec/stdlib/world-state';
|
|
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,7 +43,7 @@ export async function createWorldState(
|
|
|
41
43
|
| 'messageTreeMapSizeKb'
|
|
42
44
|
| 'publicDataTreeMapSizeKb'
|
|
43
45
|
> &
|
|
44
|
-
Pick<DataStoreConfig, 'dataDirectory' | 'dataStoreMapSizeKb' | '
|
|
46
|
+
Pick<DataStoreConfig, 'dataDirectory' | 'dataStoreMapSizeKb' | 'rollupAddress'>,
|
|
45
47
|
genesis: GenesisData = EMPTY_GENESIS_DATA,
|
|
46
48
|
instrumentation: WorldStateInstrumentation = new WorldStateInstrumentation(getTelemetryClient()),
|
|
47
49
|
bindings?: LoggerBindings,
|
|
@@ -56,14 +58,14 @@ 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,
|
|
@@ -71,7 +73,6 @@ export async function createWorldState(
|
|
|
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,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { INITIAL_CHECKPOINT_NUMBER
|
|
1
|
+
import { INITIAL_CHECKPOINT_NUMBER } from '@aztec/constants';
|
|
2
2
|
import { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
3
3
|
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
4
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
@@ -6,7 +6,6 @@ import { promiseWithResolvers } from '@aztec/foundation/promise';
|
|
|
6
6
|
import { elapsed } from '@aztec/foundation/timer';
|
|
7
7
|
import {
|
|
8
8
|
type BlockHash,
|
|
9
|
-
GENESIS_BLOCK_HEADER_HASH,
|
|
10
9
|
GENESIS_CHECKPOINT_HEADER_HASH,
|
|
11
10
|
type L2Block,
|
|
12
11
|
type L2BlockId,
|
|
@@ -288,14 +287,15 @@ export class ServerWorldStateSynchronizer
|
|
|
288
287
|
// but we use a block stream so we need to provide 'local' L2Tips.
|
|
289
288
|
// We configure the block stream to ignore checkpoints and set checkpoint values to genesis here.
|
|
290
289
|
const genesisCheckpointHeaderHash = GENESIS_CHECKPOINT_HEADER_HASH.toString();
|
|
290
|
+
const initialBlockHash = (await this.merkleTreeCommitted.getInitialHeader().hash()).toString();
|
|
291
291
|
return {
|
|
292
292
|
proposed: latestBlockId,
|
|
293
293
|
checkpointed: {
|
|
294
|
-
block: { number:
|
|
294
|
+
block: { number: BlockNumber.ZERO, hash: initialBlockHash },
|
|
295
295
|
checkpoint: { number: INITIAL_CHECKPOINT_NUMBER, hash: genesisCheckpointHeaderHash },
|
|
296
296
|
},
|
|
297
297
|
proposedCheckpoint: {
|
|
298
|
-
block: { number:
|
|
298
|
+
block: { number: BlockNumber.ZERO, hash: initialBlockHash },
|
|
299
299
|
checkpoint: { number: INITIAL_CHECKPOINT_NUMBER, hash: genesisCheckpointHeaderHash },
|
|
300
300
|
},
|
|
301
301
|
finalized: {
|
|
@@ -409,29 +409,26 @@ export class ServerWorldStateSynchronizer
|
|
|
409
409
|
if (this.historyToKeep === undefined) {
|
|
410
410
|
return;
|
|
411
411
|
}
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
if (finalisedCheckpoint === undefined) {
|
|
412
|
+
const finalisedBlockData = await this.l2BlockSource.getBlockData({ number: summary.finalizedBlockNumber });
|
|
413
|
+
if (finalisedBlockData === undefined) {
|
|
415
414
|
this.log.warn(
|
|
416
415
|
`Failed to retrieve checkpointed block for finalized block number: ${summary.finalizedBlockNumber}`,
|
|
417
416
|
);
|
|
418
417
|
return;
|
|
419
418
|
}
|
|
420
419
|
// Compute the required historic checkpoint number
|
|
421
|
-
const newHistoricCheckpointNumber =
|
|
420
|
+
const newHistoricCheckpointNumber = finalisedBlockData.checkpointNumber - this.historyToKeep + 1;
|
|
422
421
|
if (newHistoricCheckpointNumber <= 1) {
|
|
423
422
|
return;
|
|
424
423
|
}
|
|
425
424
|
// Retrieve the historic checkpoint
|
|
426
|
-
const
|
|
427
|
-
CheckpointNumber(newHistoricCheckpointNumber),
|
|
428
|
-
|
|
429
|
-
)
|
|
430
|
-
if (historicCheckpoints.length === 0 || historicCheckpoints[0] === undefined) {
|
|
425
|
+
const historicCheckpoint = await this.l2BlockSource.getCheckpoint({
|
|
426
|
+
number: CheckpointNumber(newHistoricCheckpointNumber),
|
|
427
|
+
});
|
|
428
|
+
if (!historicCheckpoint) {
|
|
431
429
|
this.log.warn(`Failed to retrieve checkpoint number ${newHistoricCheckpointNumber} from Archiver`);
|
|
432
430
|
return;
|
|
433
431
|
}
|
|
434
|
-
const historicCheckpoint = historicCheckpoints[0];
|
|
435
432
|
if (historicCheckpoint.checkpoint.blocks.length === 0 || historicCheckpoint.checkpoint.blocks[0] === undefined) {
|
|
436
433
|
this.log.warn(`Retrieved checkpoint number ${newHistoricCheckpointNumber} has no blocks!`);
|
|
437
434
|
return;
|
package/src/testing.ts
CHANGED
|
@@ -15,7 +15,7 @@ async function generateGenesisValues(genesis: GenesisData) {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
// Create a temporary world state to compute the genesis values.
|
|
18
|
-
const ws = await NativeWorldStateService.tmp(
|
|
18
|
+
const ws = await NativeWorldStateService.tmp(/*cleanupTmpDir=*/ true, genesis);
|
|
19
19
|
const genesisArchiveRoot = new Fr((await ws.getCommitted().getTreeInfo(MerkleTreeId.ARCHIVE)).root);
|
|
20
20
|
await ws.close();
|
|
21
21
|
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { WorldStateMessageType } from './message.js';
|
|
2
|
-
export declare const MUTATING_MSG_TYPES: Set<WorldStateMessageType>;
|
|
3
|
-
export declare class WorldStateOpsQueue {
|
|
4
|
-
private requests;
|
|
5
|
-
private inFlightMutatingCount;
|
|
6
|
-
private inFlightCount;
|
|
7
|
-
private stopPromise?;
|
|
8
|
-
private stopResolve?;
|
|
9
|
-
private requestId;
|
|
10
|
-
private ops;
|
|
11
|
-
execute(request: () => Promise<any>, messageType: WorldStateMessageType, committedOnly: boolean): Promise<any>;
|
|
12
|
-
private executeMutating;
|
|
13
|
-
private executeNonMutatingUncommitted;
|
|
14
|
-
private executeNonMutatingCommitted;
|
|
15
|
-
private checkAndEnqueue;
|
|
16
|
-
private sendEnqueuedRequest;
|
|
17
|
-
stop(): Promise<void>;
|
|
18
|
-
}
|
|
19
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoid29ybGRfc3RhdGVfb3BzX3F1ZXVlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvbmF0aXZlL3dvcmxkX3N0YXRlX29wc19xdWV1ZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFFQSxPQUFPLEVBQUUscUJBQXFCLEVBQUUsTUFBTSxjQUFjLENBQUM7QUF5QnJELGVBQU8sTUFBTSxrQkFBa0IsNEJBZ0I3QixDQUFDO0FBR0gscUJBQWEsa0JBQWtCO0lBQzdCLE9BQU8sQ0FBQyxRQUFRLENBQXNCO0lBQ3RDLE9BQU8sQ0FBQyxxQkFBcUIsQ0FBSztJQUNsQyxPQUFPLENBQUMsYUFBYSxDQUFLO0lBQzFCLE9BQU8sQ0FBQyxXQUFXLENBQUMsQ0FBZ0I7SUFDcEMsT0FBTyxDQUFDLFdBQVcsQ0FBQyxDQUFhO0lBQ2pDLE9BQU8sQ0FBQyxTQUFTLENBQUs7SUFDdEIsT0FBTyxDQUFDLEdBQUcsQ0FBd0M7SUFJNUMsT0FBTyxDQUFDLE9BQU8sRUFBRSxNQUFNLE9BQU8sQ0FBQyxHQUFHLENBQUMsRUFBRSxXQUFXLEVBQUUscUJBQXFCLEVBQUUsYUFBYSxFQUFFLE9BQU8sZ0JBc0JyRztJQUdELE9BQU8sQ0FBQyxlQUFlO0lBV3ZCLE9BQU8sQ0FBQyw2QkFBNkI7SUFZckMsT0FBTyxDQUFDLDJCQUEyQjtJQVVuQyxPQUFPLENBQUMsZUFBZTtJQXlDdkIsT0FBTyxDQUFDLG1CQUFtQjtJQWdCcEIsSUFBSSxrQkFnQlY7Q0FDRiJ9
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|