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