@aztec/world-state 0.0.1-commit.1142ef1 → 0.0.1-commit.11bf3dd6e
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 +1 -1
- package/dest/instrumentation/instrumentation.d.ts.map +1 -1
- package/dest/instrumentation/instrumentation.js +9 -2
- 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/merkle_trees_facade.d.ts +7 -6
- package/dest/native/merkle_trees_facade.d.ts.map +1 -1
- package/dest/native/merkle_trees_facade.js +29 -12
- package/dest/native/message.d.ts +13 -5
- package/dest/native/message.d.ts.map +1 -1
- package/dest/native/native_world_state.d.ts +10 -8
- package/dest/native/native_world_state.d.ts.map +1 -1
- package/dest/native/native_world_state.js +18 -12
- package/dest/native/native_world_state_instance.d.ts +5 -5
- package/dest/native/native_world_state_instance.d.ts.map +1 -1
- package/dest/native/native_world_state_instance.js +8 -7
- package/dest/native/world_state_ops_queue.js +5 -5
- package/dest/synchronizer/config.d.ts +3 -5
- package/dest/synchronizer/config.d.ts.map +1 -1
- package/dest/synchronizer/config.js +14 -16
- package/dest/synchronizer/factory.d.ts +6 -5
- package/dest/synchronizer/factory.d.ts.map +1 -1
- package/dest/synchronizer/factory.js +6 -5
- package/dest/synchronizer/server_world_state_synchronizer.d.ts +4 -5
- package/dest/synchronizer/server_world_state_synchronizer.d.ts.map +1 -1
- package/dest/synchronizer/server_world_state_synchronizer.js +105 -36
- package/dest/test/utils.d.ts +7 -7
- package/dest/test/utils.d.ts.map +1 -1
- package/dest/test/utils.js +5 -5
- 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 +3 -12
- package/dest/world-state-db/merkle_tree_db.d.ts.map +1 -1
- package/package.json +10 -11
- package/src/instrumentation/instrumentation.ts +9 -1
- package/src/native/fork_checkpoint.ts +19 -3
- package/src/native/merkle_trees_facade.ts +34 -13
- package/src/native/message.ts +14 -4
- package/src/native/native_world_state.ts +22 -16
- package/src/native/native_world_state_instance.ts +14 -8
- package/src/native/world_state_ops_queue.ts +5 -5
- package/src/synchronizer/config.ts +15 -26
- package/src/synchronizer/factory.ts +13 -7
- package/src/synchronizer/server_world_state_synchronizer.ts +121 -45
- package/src/test/utils.ts +6 -6
- package/src/testing.ts +8 -9
- package/src/world-state-db/merkle_tree_db.ts +2 -12
|
@@ -4,6 +4,7 @@ import { createLogger } from '@aztec/foundation/log';
|
|
|
4
4
|
import { serializeToBuffer } from '@aztec/foundation/serialize';
|
|
5
5
|
import { sleep } from '@aztec/foundation/sleep';
|
|
6
6
|
import { type IndexedTreeLeafPreimage, SiblingPath } from '@aztec/foundation/trees';
|
|
7
|
+
import { BlockHash } from '@aztec/stdlib/block';
|
|
7
8
|
import type {
|
|
8
9
|
BatchInsertionResult,
|
|
9
10
|
IndexedTreeId,
|
|
@@ -118,7 +119,7 @@ export class MerkleTreesFacade implements MerkleTreeReadOperations {
|
|
|
118
119
|
|
|
119
120
|
const leaf = deserializeLeafValue(resp);
|
|
120
121
|
if (leaf instanceof Fr) {
|
|
121
|
-
return leaf as any;
|
|
122
|
+
return treeId === MerkleTreeId.ARCHIVE ? (new BlockHash(leaf) as any) : (leaf as any);
|
|
122
123
|
} else {
|
|
123
124
|
return leaf.toBuffer() as any;
|
|
124
125
|
}
|
|
@@ -228,7 +229,7 @@ export class MerkleTreesForkFacade extends MerkleTreesFacade implements MerkleTr
|
|
|
228
229
|
|
|
229
230
|
async appendLeaves<ID extends MerkleTreeId>(treeId: ID, leaves: MerkleTreeLeafType<ID>[]): Promise<void> {
|
|
230
231
|
await this.instance.call(WorldStateMessageType.APPEND_LEAVES, {
|
|
231
|
-
leaves: leaves.map(leaf => leaf as any),
|
|
232
|
+
leaves: leaves.map(leaf => serializeLeaf(hydrateLeaf(treeId, leaf as any))),
|
|
232
233
|
forkId: this.revision.forkId,
|
|
233
234
|
treeId,
|
|
234
235
|
});
|
|
@@ -292,10 +293,19 @@ export class MerkleTreesForkFacade extends MerkleTreesFacade implements MerkleTr
|
|
|
292
293
|
|
|
293
294
|
public async close(): Promise<void> {
|
|
294
295
|
assert.notEqual(this.revision.forkId, 0, 'Fork ID must be set');
|
|
295
|
-
|
|
296
|
+
try {
|
|
297
|
+
await this.instance.call(WorldStateMessageType.DELETE_FORK, { forkId: this.revision.forkId });
|
|
298
|
+
} catch (err: any) {
|
|
299
|
+
// Ignore errors due to native instance being closed during shutdown.
|
|
300
|
+
// This can happen when validators are still processing block proposals while the node is stopping.
|
|
301
|
+
if (err?.message === 'Native instance is closed') {
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
throw err;
|
|
305
|
+
}
|
|
296
306
|
}
|
|
297
307
|
|
|
298
|
-
async [Symbol.
|
|
308
|
+
async [Symbol.asyncDispose](): Promise<void> {
|
|
299
309
|
if (this.opts.closeDelayMs) {
|
|
300
310
|
void sleep(this.opts.closeDelayMs)
|
|
301
311
|
.then(() => this.close())
|
|
@@ -310,9 +320,10 @@ export class MerkleTreesForkFacade extends MerkleTreesFacade implements MerkleTr
|
|
|
310
320
|
}
|
|
311
321
|
}
|
|
312
322
|
|
|
313
|
-
public async createCheckpoint(): Promise<
|
|
323
|
+
public async createCheckpoint(): Promise<number> {
|
|
314
324
|
assert.notEqual(this.revision.forkId, 0, 'Fork ID must be set');
|
|
315
|
-
await this.instance.call(WorldStateMessageType.CREATE_CHECKPOINT, { forkId: this.revision.forkId });
|
|
325
|
+
const resp = await this.instance.call(WorldStateMessageType.CREATE_CHECKPOINT, { forkId: this.revision.forkId });
|
|
326
|
+
return resp.depth;
|
|
316
327
|
}
|
|
317
328
|
|
|
318
329
|
public async commitCheckpoint(): Promise<void> {
|
|
@@ -325,20 +336,28 @@ export class MerkleTreesForkFacade extends MerkleTreesFacade implements MerkleTr
|
|
|
325
336
|
await this.instance.call(WorldStateMessageType.REVERT_CHECKPOINT, { forkId: this.revision.forkId });
|
|
326
337
|
}
|
|
327
338
|
|
|
328
|
-
public async
|
|
339
|
+
public async commitAllCheckpointsTo(depth: number): Promise<void> {
|
|
329
340
|
assert.notEqual(this.revision.forkId, 0, 'Fork ID must be set');
|
|
330
|
-
await this.instance.call(WorldStateMessageType.COMMIT_ALL_CHECKPOINTS, {
|
|
341
|
+
await this.instance.call(WorldStateMessageType.COMMIT_ALL_CHECKPOINTS, {
|
|
342
|
+
forkId: this.revision.forkId,
|
|
343
|
+
depth,
|
|
344
|
+
});
|
|
331
345
|
}
|
|
332
346
|
|
|
333
|
-
public async
|
|
347
|
+
public async revertAllCheckpointsTo(depth: number): Promise<void> {
|
|
334
348
|
assert.notEqual(this.revision.forkId, 0, 'Fork ID must be set');
|
|
335
|
-
await this.instance.call(WorldStateMessageType.REVERT_ALL_CHECKPOINTS, {
|
|
349
|
+
await this.instance.call(WorldStateMessageType.REVERT_ALL_CHECKPOINTS, {
|
|
350
|
+
forkId: this.revision.forkId,
|
|
351
|
+
depth,
|
|
352
|
+
});
|
|
336
353
|
}
|
|
337
354
|
}
|
|
338
355
|
|
|
339
|
-
function hydrateLeaf
|
|
356
|
+
function hydrateLeaf(treeId: MerkleTreeId, leaf: Fr | BlockHash | Buffer) {
|
|
340
357
|
if (leaf instanceof Fr) {
|
|
341
358
|
return leaf;
|
|
359
|
+
} else if (leaf instanceof BlockHash) {
|
|
360
|
+
return leaf.toFr();
|
|
342
361
|
} else if (treeId === MerkleTreeId.NULLIFIER_TREE) {
|
|
343
362
|
return NullifierLeaf.fromBuffer(leaf);
|
|
344
363
|
} else if (treeId === MerkleTreeId.PUBLIC_DATA_TREE) {
|
|
@@ -348,8 +367,10 @@ function hydrateLeaf<ID extends MerkleTreeId>(treeId: ID, leaf: Fr | Buffer) {
|
|
|
348
367
|
}
|
|
349
368
|
}
|
|
350
369
|
|
|
351
|
-
export function serializeLeaf(leaf: Fr | NullifierLeaf | PublicDataTreeLeaf): SerializedLeafValue {
|
|
352
|
-
if (leaf instanceof
|
|
370
|
+
export function serializeLeaf(leaf: Fr | BlockHash | NullifierLeaf | PublicDataTreeLeaf): SerializedLeafValue {
|
|
371
|
+
if (leaf instanceof BlockHash) {
|
|
372
|
+
return leaf.toBuffer();
|
|
373
|
+
} else if (leaf instanceof Fr) {
|
|
353
374
|
return leaf.toBuffer();
|
|
354
375
|
} else if (leaf instanceof NullifierLeaf) {
|
|
355
376
|
return { nullifier: leaf.nullifier.toBuffer() };
|
package/src/native/message.ts
CHANGED
|
@@ -283,6 +283,16 @@ interface WithForkId {
|
|
|
283
283
|
forkId: number;
|
|
284
284
|
}
|
|
285
285
|
|
|
286
|
+
interface CreateCheckpointResponse {
|
|
287
|
+
depth: number;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/** Request to commit/revert all checkpoints down to a target depth. The resulting depth after the operation equals the given depth. */
|
|
291
|
+
interface CheckpointDepthRequest extends WithForkId {
|
|
292
|
+
/** The target depth after the operation. All checkpoints above this depth are committed/reverted. */
|
|
293
|
+
depth: number;
|
|
294
|
+
}
|
|
295
|
+
|
|
286
296
|
interface WithWorldStateRevision {
|
|
287
297
|
revision: WorldStateRevision;
|
|
288
298
|
}
|
|
@@ -412,7 +422,7 @@ interface UpdateArchiveRequest extends WithForkId {
|
|
|
412
422
|
interface SyncBlockRequest extends WithCanonicalForkId {
|
|
413
423
|
blockNumber: BlockNumber;
|
|
414
424
|
blockStateRef: BlockStateReference;
|
|
415
|
-
blockHeaderHash:
|
|
425
|
+
blockHeaderHash: Buffer;
|
|
416
426
|
paddedNoteHashes: readonly SerializedLeafValue[];
|
|
417
427
|
paddedL1ToL2Messages: readonly SerializedLeafValue[];
|
|
418
428
|
paddedNullifiers: readonly SerializedLeafValue[];
|
|
@@ -486,8 +496,8 @@ export type WorldStateRequest = {
|
|
|
486
496
|
[WorldStateMessageType.CREATE_CHECKPOINT]: WithForkId;
|
|
487
497
|
[WorldStateMessageType.COMMIT_CHECKPOINT]: WithForkId;
|
|
488
498
|
[WorldStateMessageType.REVERT_CHECKPOINT]: WithForkId;
|
|
489
|
-
[WorldStateMessageType.COMMIT_ALL_CHECKPOINTS]:
|
|
490
|
-
[WorldStateMessageType.REVERT_ALL_CHECKPOINTS]:
|
|
499
|
+
[WorldStateMessageType.COMMIT_ALL_CHECKPOINTS]: CheckpointDepthRequest;
|
|
500
|
+
[WorldStateMessageType.REVERT_ALL_CHECKPOINTS]: CheckpointDepthRequest;
|
|
491
501
|
|
|
492
502
|
[WorldStateMessageType.COPY_STORES]: CopyStoresRequest;
|
|
493
503
|
|
|
@@ -528,7 +538,7 @@ export type WorldStateResponse = {
|
|
|
528
538
|
|
|
529
539
|
[WorldStateMessageType.GET_STATUS]: WorldStateStatusSummary;
|
|
530
540
|
|
|
531
|
-
[WorldStateMessageType.CREATE_CHECKPOINT]:
|
|
541
|
+
[WorldStateMessageType.CREATE_CHECKPOINT]: CreateCheckpointResponse;
|
|
532
542
|
[WorldStateMessageType.COMMIT_CHECKPOINT]: void;
|
|
533
543
|
[WorldStateMessageType.REVERT_CHECKPOINT]: void;
|
|
534
544
|
[WorldStateMessageType.COMMIT_ALL_CHECKPOINTS]: void;
|
|
@@ -4,9 +4,9 @@ import { fromEntries, padArrayEnd } from '@aztec/foundation/collection';
|
|
|
4
4
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
5
5
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
6
6
|
import { tryRmDir } from '@aztec/foundation/fs';
|
|
7
|
-
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
8
|
-
import type {
|
|
9
|
-
import { DatabaseVersionManager } from '@aztec/stdlib/database-version';
|
|
7
|
+
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
8
|
+
import type { L2Block } from '@aztec/stdlib/block';
|
|
9
|
+
import { DatabaseVersionManager } from '@aztec/stdlib/database-version/manager';
|
|
10
10
|
import type {
|
|
11
11
|
IndexedTreeId,
|
|
12
12
|
MerkleTreeReadOperations,
|
|
@@ -14,8 +14,8 @@ import type {
|
|
|
14
14
|
} from '@aztec/stdlib/interfaces/server';
|
|
15
15
|
import type { SnapshotDataKeys } from '@aztec/stdlib/snapshots';
|
|
16
16
|
import { MerkleTreeId, NullifierLeaf, type NullifierLeafPreimage, PublicDataTreeLeaf } from '@aztec/stdlib/trees';
|
|
17
|
-
import { BlockHeader, PartialStateReference, StateReference } from '@aztec/stdlib/tx';
|
|
18
|
-
import { WorldStateRevision } from '@aztec/stdlib/world-state';
|
|
17
|
+
import { BlockHeader, GlobalVariables, PartialStateReference, StateReference } from '@aztec/stdlib/tx';
|
|
18
|
+
import { EMPTY_GENESIS_DATA, type GenesisData, WorldStateRevision } from '@aztec/stdlib/world-state';
|
|
19
19
|
import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
20
20
|
|
|
21
21
|
import assert from 'assert/strict';
|
|
@@ -52,7 +52,8 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
|
|
|
52
52
|
protected constructor(
|
|
53
53
|
protected instance: NativeWorldState,
|
|
54
54
|
protected readonly worldStateInstrumentation: WorldStateInstrumentation,
|
|
55
|
-
protected readonly log: Logger
|
|
55
|
+
protected readonly log: Logger,
|
|
56
|
+
private readonly genesis: GenesisData = EMPTY_GENESIS_DATA,
|
|
56
57
|
private readonly cleanup = () => Promise.resolve(),
|
|
57
58
|
) {}
|
|
58
59
|
|
|
@@ -60,11 +61,12 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
|
|
|
60
61
|
rollupAddress: EthAddress,
|
|
61
62
|
dataDir: string,
|
|
62
63
|
wsTreeMapSizes: WorldStateTreeMapSizes,
|
|
63
|
-
|
|
64
|
+
genesis: GenesisData = EMPTY_GENESIS_DATA,
|
|
64
65
|
instrumentation = new WorldStateInstrumentation(getTelemetryClient()),
|
|
65
|
-
|
|
66
|
+
bindings?: LoggerBindings,
|
|
66
67
|
cleanup = () => Promise.resolve(),
|
|
67
68
|
): Promise<NativeWorldStateService> {
|
|
69
|
+
const log = createLogger('world-state:database', bindings);
|
|
68
70
|
const worldStateDirectory = join(dataDir, WORLD_STATE_DIR);
|
|
69
71
|
// Create a version manager to handle versioning
|
|
70
72
|
const versionManager = new DatabaseVersionManager({
|
|
@@ -72,12 +74,12 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
|
|
|
72
74
|
rollupAddress,
|
|
73
75
|
dataDirectory: worldStateDirectory,
|
|
74
76
|
onOpen: (dir: string) => {
|
|
75
|
-
return Promise.resolve(new NativeWorldState(dir, wsTreeMapSizes,
|
|
77
|
+
return Promise.resolve(new NativeWorldState(dir, wsTreeMapSizes, genesis, instrumentation, bindings));
|
|
76
78
|
},
|
|
77
79
|
});
|
|
78
80
|
|
|
79
81
|
const [instance] = await versionManager.open();
|
|
80
|
-
const worldState = new this(instance, instrumentation, log, cleanup);
|
|
82
|
+
const worldState = new this(instance, instrumentation, log, genesis, cleanup);
|
|
81
83
|
try {
|
|
82
84
|
await worldState.init();
|
|
83
85
|
} catch (e) {
|
|
@@ -91,10 +93,11 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
|
|
|
91
93
|
static async tmp(
|
|
92
94
|
rollupAddress = EthAddress.ZERO,
|
|
93
95
|
cleanupTmpDir = true,
|
|
94
|
-
|
|
96
|
+
genesis: GenesisData = EMPTY_GENESIS_DATA,
|
|
95
97
|
instrumentation = new WorldStateInstrumentation(getTelemetryClient()),
|
|
98
|
+
bindings?: LoggerBindings,
|
|
96
99
|
): Promise<NativeWorldStateService> {
|
|
97
|
-
const log = createLogger('world-state:database');
|
|
100
|
+
const log = createLogger('world-state:database', bindings);
|
|
98
101
|
const dataDir = await mkdtemp(join(tmpdir(), 'aztec-world-state-'));
|
|
99
102
|
const dbMapSizeKb = 10 * 1024 * 1024;
|
|
100
103
|
const worldStateTreeMapSizes: WorldStateTreeMapSizes = {
|
|
@@ -116,7 +119,7 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
|
|
|
116
119
|
}
|
|
117
120
|
};
|
|
118
121
|
|
|
119
|
-
return this.new(rollupAddress, dataDir, worldStateTreeMapSizes,
|
|
122
|
+
return this.new(rollupAddress, dataDir, worldStateTreeMapSizes, genesis, instrumentation, bindings, cleanup);
|
|
120
123
|
}
|
|
121
124
|
|
|
122
125
|
protected async init() {
|
|
@@ -184,7 +187,7 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
|
|
|
184
187
|
return this.initialHeader!;
|
|
185
188
|
}
|
|
186
189
|
|
|
187
|
-
public async handleL2BlockAndMessages(l2Block:
|
|
190
|
+
public async handleL2BlockAndMessages(l2Block: L2Block, l1ToL2Messages: Fr[]): Promise<WorldStateStatusFull> {
|
|
188
191
|
const isFirstBlock = l2Block.indexWithinCheckpoint === 0;
|
|
189
192
|
if (!isFirstBlock && l1ToL2Messages.length > 0) {
|
|
190
193
|
throw new Error(
|
|
@@ -220,7 +223,7 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
|
|
|
220
223
|
WorldStateMessageType.SYNC_BLOCK,
|
|
221
224
|
{
|
|
222
225
|
blockNumber: l2Block.number,
|
|
223
|
-
blockHeaderHash: await l2Block.hash(),
|
|
226
|
+
blockHeaderHash: (await l2Block.hash()).toBuffer(),
|
|
224
227
|
paddedL1ToL2Messages: paddedL1ToL2Messages.map(serializeLeaf),
|
|
225
228
|
paddedNoteHashes: paddedNoteHashes.map(serializeLeaf),
|
|
226
229
|
paddedNullifiers: paddedNullifiers.map(serializeLeaf),
|
|
@@ -244,7 +247,10 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
|
|
|
244
247
|
|
|
245
248
|
private async buildInitialHeader(): Promise<BlockHeader> {
|
|
246
249
|
const state = await this.getInitialStateReference();
|
|
247
|
-
return BlockHeader.empty({
|
|
250
|
+
return BlockHeader.empty({
|
|
251
|
+
state,
|
|
252
|
+
globalVariables: GlobalVariables.empty({ timestamp: this.genesis.genesisTimestamp }),
|
|
253
|
+
});
|
|
248
254
|
}
|
|
249
255
|
|
|
250
256
|
private sanitizeAndCacheSummaryFromFull(response: WorldStateStatusFull) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ARCHIVE_HEIGHT,
|
|
3
|
-
|
|
3
|
+
DomainSeparator,
|
|
4
4
|
L1_TO_L2_MSG_TREE_HEIGHT,
|
|
5
5
|
MAX_NULLIFIERS_PER_TX,
|
|
6
6
|
MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
|
|
@@ -8,10 +8,10 @@ import {
|
|
|
8
8
|
NULLIFIER_TREE_HEIGHT,
|
|
9
9
|
PUBLIC_DATA_TREE_HEIGHT,
|
|
10
10
|
} from '@aztec/constants';
|
|
11
|
-
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
11
|
+
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
12
12
|
import { NativeWorldState as BaseNativeWorldState, MsgpackChannel } from '@aztec/native';
|
|
13
13
|
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
14
|
-
import type
|
|
14
|
+
import { EMPTY_GENESIS_DATA, type GenesisData } from '@aztec/stdlib/world-state';
|
|
15
15
|
|
|
16
16
|
import assert from 'assert';
|
|
17
17
|
import { cpus } from 'os';
|
|
@@ -55,9 +55,10 @@ export class NativeWorldState implements NativeWorldStateInstance {
|
|
|
55
55
|
constructor(
|
|
56
56
|
private readonly dataDir: string,
|
|
57
57
|
private readonly wsTreeMapSizes: WorldStateTreeMapSizes,
|
|
58
|
-
private readonly
|
|
58
|
+
private readonly genesis: GenesisData = EMPTY_GENESIS_DATA,
|
|
59
59
|
private readonly instrumentation: WorldStateInstrumentation,
|
|
60
|
-
|
|
60
|
+
bindings?: LoggerBindings,
|
|
61
|
+
private readonly log: Logger = createLogger('world-state:database', bindings),
|
|
61
62
|
) {
|
|
62
63
|
const threads = Math.min(cpus().length, MAX_WORLD_STATE_THREADS);
|
|
63
64
|
log.info(
|
|
@@ -65,7 +66,10 @@ export class NativeWorldState implements NativeWorldStateInstance {
|
|
|
65
66
|
wsTreeMapSizes,
|
|
66
67
|
)} and ${threads} threads.`,
|
|
67
68
|
);
|
|
68
|
-
const prefilledPublicDataBufferArray = prefilledPublicData.map(d => [
|
|
69
|
+
const prefilledPublicDataBufferArray = genesis.prefilledPublicData.map(d => [
|
|
70
|
+
d.slot.toBuffer(),
|
|
71
|
+
d.value.toBuffer(),
|
|
72
|
+
]);
|
|
69
73
|
const ws = new BaseNativeWorldState(
|
|
70
74
|
dataDir,
|
|
71
75
|
{
|
|
@@ -80,7 +84,8 @@ export class NativeWorldState implements NativeWorldStateInstance {
|
|
|
80
84
|
[MerkleTreeId.PUBLIC_DATA_TREE]: 2 * MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
|
|
81
85
|
},
|
|
82
86
|
prefilledPublicDataBufferArray,
|
|
83
|
-
|
|
87
|
+
DomainSeparator.BLOCK_HEADER_HASH,
|
|
88
|
+
Number(genesis.genesisTimestamp),
|
|
84
89
|
{
|
|
85
90
|
[MerkleTreeId.NULLIFIER_TREE]: wsTreeMapSizes.nullifierTreeMapSizeKb,
|
|
86
91
|
[MerkleTreeId.NOTE_HASH_TREE]: wsTreeMapSizes.noteHashTreeMapSizeKb,
|
|
@@ -103,8 +108,9 @@ export class NativeWorldState implements NativeWorldStateInstance {
|
|
|
103
108
|
return new NativeWorldState(
|
|
104
109
|
this.dataDir,
|
|
105
110
|
this.wsTreeMapSizes,
|
|
106
|
-
this.
|
|
111
|
+
this.genesis,
|
|
107
112
|
this.instrumentation,
|
|
113
|
+
this.log.getBindings(),
|
|
108
114
|
this.log,
|
|
109
115
|
);
|
|
110
116
|
}
|
|
@@ -96,7 +96,7 @@ export class WorldStateOpsQueue {
|
|
|
96
96
|
// then send the request immediately
|
|
97
97
|
// If a mutating request is in flight then we must wait
|
|
98
98
|
// If a mutating request is not in flight but something is queued then it must be a mutating request
|
|
99
|
-
if (this.inFlightMutatingCount
|
|
99
|
+
if (this.inFlightMutatingCount === 0 && this.requests.length === 0) {
|
|
100
100
|
this.sendEnqueuedRequest(op);
|
|
101
101
|
} else {
|
|
102
102
|
this.requests.push(op);
|
|
@@ -122,7 +122,7 @@ export class WorldStateOpsQueue {
|
|
|
122
122
|
--this.inFlightCount;
|
|
123
123
|
|
|
124
124
|
// If there are still requests in flight then do nothing further
|
|
125
|
-
if (this.inFlightCount
|
|
125
|
+
if (this.inFlightCount !== 0) {
|
|
126
126
|
return;
|
|
127
127
|
}
|
|
128
128
|
|
|
@@ -134,7 +134,7 @@ export class WorldStateOpsQueue {
|
|
|
134
134
|
while (this.requests.length > 0) {
|
|
135
135
|
const next = this.requests[0];
|
|
136
136
|
if (next.mutating) {
|
|
137
|
-
if (this.inFlightCount
|
|
137
|
+
if (this.inFlightCount === 0) {
|
|
138
138
|
// send the mutating request
|
|
139
139
|
this.requests.shift();
|
|
140
140
|
this.sendEnqueuedRequest(next);
|
|
@@ -149,7 +149,7 @@ export class WorldStateOpsQueue {
|
|
|
149
149
|
}
|
|
150
150
|
|
|
151
151
|
// If the queue is empty, there is nothing in flight and we have been told to stop, then resolve the stop promise
|
|
152
|
-
if (this.inFlightCount
|
|
152
|
+
if (this.inFlightCount === 0 && this.stopResolve !== undefined) {
|
|
153
153
|
this.stopResolve();
|
|
154
154
|
}
|
|
155
155
|
}
|
|
@@ -182,7 +182,7 @@ export class WorldStateOpsQueue {
|
|
|
182
182
|
});
|
|
183
183
|
|
|
184
184
|
// If no outstanding requests then immediately resolve the promise
|
|
185
|
-
if (this.requests.length
|
|
185
|
+
if (this.requests.length === 0 && this.inFlightCount === 0 && this.stopResolve !== undefined) {
|
|
186
186
|
this.stopResolve();
|
|
187
187
|
}
|
|
188
188
|
return this.stopPromise;
|
|
@@ -1,18 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type ConfigMappingsType,
|
|
3
|
-
booleanConfigHelper,
|
|
4
|
-
getConfigFromMappings,
|
|
5
|
-
numberConfigHelper,
|
|
6
|
-
} from '@aztec/foundation/config';
|
|
1
|
+
import { type ConfigMappingsType, getConfigFromMappings, numberConfigHelper } from '@aztec/foundation/config';
|
|
7
2
|
|
|
8
3
|
/** World State synchronizer configuration values. */
|
|
9
4
|
export interface WorldStateConfig {
|
|
10
5
|
/** The frequency in which to check. */
|
|
11
6
|
worldStateBlockCheckIntervalMS: number;
|
|
12
7
|
|
|
13
|
-
/** Whether to follow only the proven chain. */
|
|
14
|
-
worldStateProvenBlocksOnly: boolean;
|
|
15
|
-
|
|
16
8
|
/** Size of the batch for each get-blocks request from the synchronizer to the archiver. */
|
|
17
9
|
worldStateBlockRequestBatchSize?: number;
|
|
18
10
|
|
|
@@ -37,8 +29,8 @@ export interface WorldStateConfig {
|
|
|
37
29
|
/** Optional directory for the world state DB, if unspecified will default to the general data directory */
|
|
38
30
|
worldStateDataDirectory?: string;
|
|
39
31
|
|
|
40
|
-
/** The number of historic blocks to maintain */
|
|
41
|
-
|
|
32
|
+
/** The number of historic checkpoints worth of blocks to maintain */
|
|
33
|
+
worldStateCheckpointHistory: number;
|
|
42
34
|
}
|
|
43
35
|
|
|
44
36
|
export const worldStateConfigMappings: ConfigMappingsType<WorldStateConfig> = {
|
|
@@ -48,48 +40,43 @@ export const worldStateConfigMappings: ConfigMappingsType<WorldStateConfig> = {
|
|
|
48
40
|
defaultValue: 100,
|
|
49
41
|
description: 'The frequency in which to check.',
|
|
50
42
|
},
|
|
51
|
-
worldStateProvenBlocksOnly: {
|
|
52
|
-
env: 'WS_PROVEN_BLOCKS_ONLY',
|
|
53
|
-
description: 'Whether to follow only the proven chain.',
|
|
54
|
-
...booleanConfigHelper(),
|
|
55
|
-
},
|
|
56
43
|
worldStateBlockRequestBatchSize: {
|
|
57
44
|
env: 'WS_BLOCK_REQUEST_BATCH_SIZE',
|
|
58
|
-
parseEnv: (val: string
|
|
45
|
+
parseEnv: (val: string) => +val,
|
|
59
46
|
description: 'Size of the batch for each get-blocks request from the synchronizer to the archiver.',
|
|
60
47
|
},
|
|
61
48
|
worldStateDbMapSizeKb: {
|
|
62
49
|
env: 'WS_DB_MAP_SIZE_KB',
|
|
63
|
-
parseEnv: (val: string
|
|
50
|
+
parseEnv: (val: string) => +val,
|
|
64
51
|
description: 'The maximum possible size of the world state DB in KB. Overwrites the general dataStoreMapSizeKb.',
|
|
65
52
|
},
|
|
66
53
|
archiveTreeMapSizeKb: {
|
|
67
54
|
env: 'ARCHIVE_TREE_MAP_SIZE_KB',
|
|
68
|
-
parseEnv: (val: string
|
|
55
|
+
parseEnv: (val: string) => +val,
|
|
69
56
|
description:
|
|
70
57
|
'The maximum possible size of the world state archive tree in KB. Overwrites the general worldStateDbMapSizeKb.',
|
|
71
58
|
},
|
|
72
59
|
nullifierTreeMapSizeKb: {
|
|
73
60
|
env: 'NULLIFIER_TREE_MAP_SIZE_KB',
|
|
74
|
-
parseEnv: (val: string
|
|
61
|
+
parseEnv: (val: string) => +val,
|
|
75
62
|
description:
|
|
76
63
|
'The maximum possible size of the world state nullifier tree in KB. Overwrites the general worldStateDbMapSizeKb.',
|
|
77
64
|
},
|
|
78
65
|
noteHashTreeMapSizeKb: {
|
|
79
66
|
env: 'NOTE_HASH_TREE_MAP_SIZE_KB',
|
|
80
|
-
parseEnv: (val: string
|
|
67
|
+
parseEnv: (val: string) => +val,
|
|
81
68
|
description:
|
|
82
69
|
'The maximum possible size of the world state note hash tree in KB. Overwrites the general worldStateDbMapSizeKb.',
|
|
83
70
|
},
|
|
84
71
|
messageTreeMapSizeKb: {
|
|
85
72
|
env: 'MESSAGE_TREE_MAP_SIZE_KB',
|
|
86
|
-
parseEnv: (val: string
|
|
73
|
+
parseEnv: (val: string) => +val,
|
|
87
74
|
description:
|
|
88
75
|
'The maximum possible size of the world state message tree in KB. Overwrites the general worldStateDbMapSizeKb.',
|
|
89
76
|
},
|
|
90
77
|
publicDataTreeMapSizeKb: {
|
|
91
78
|
env: 'PUBLIC_DATA_TREE_MAP_SIZE_KB',
|
|
92
|
-
parseEnv: (val: string
|
|
79
|
+
parseEnv: (val: string) => +val,
|
|
93
80
|
description:
|
|
94
81
|
'The maximum possible size of the world state public data tree in KB. Overwrites the general worldStateDbMapSizeKb.',
|
|
95
82
|
},
|
|
@@ -97,9 +84,11 @@ export const worldStateConfigMappings: ConfigMappingsType<WorldStateConfig> = {
|
|
|
97
84
|
env: 'WS_DATA_DIRECTORY',
|
|
98
85
|
description: 'Optional directory for the world state database',
|
|
99
86
|
},
|
|
100
|
-
|
|
101
|
-
env: '
|
|
102
|
-
description:
|
|
87
|
+
worldStateCheckpointHistory: {
|
|
88
|
+
env: 'WS_NUM_HISTORIC_CHECKPOINTS',
|
|
89
|
+
description:
|
|
90
|
+
'The number of historic checkpoints worth of blocks to maintain. Values less than 1 mean all history is maintained',
|
|
91
|
+
fallback: ['WS_NUM_HISTORIC_BLOCKS'],
|
|
103
92
|
...numberConfigHelper(64),
|
|
104
93
|
},
|
|
105
94
|
};
|
|
@@ -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 } 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,12 @@ export interface WorldStateTreeMapSizes {
|
|
|
20
21
|
export async function createWorldStateSynchronizer(
|
|
21
22
|
config: WorldStateConfig & DataStoreConfig,
|
|
22
23
|
l2BlockSource: L2BlockSource & L1ToL2MessageSource,
|
|
23
|
-
|
|
24
|
+
genesis: GenesisData = EMPTY_GENESIS_DATA,
|
|
24
25
|
client: TelemetryClient = getTelemetryClient(),
|
|
26
|
+
bindings?: LoggerBindings,
|
|
25
27
|
) {
|
|
26
28
|
const instrumentation = new WorldStateInstrumentation(client);
|
|
27
|
-
const merkleTrees = await createWorldState(config,
|
|
29
|
+
const merkleTrees = await createWorldState(config, genesis, instrumentation, bindings);
|
|
28
30
|
return new ServerWorldStateSynchronizer(merkleTrees, l2BlockSource, config, instrumentation);
|
|
29
31
|
}
|
|
30
32
|
|
|
@@ -40,8 +42,9 @@ export async function createWorldState(
|
|
|
40
42
|
| 'publicDataTreeMapSizeKb'
|
|
41
43
|
> &
|
|
42
44
|
Pick<DataStoreConfig, 'dataDirectory' | 'dataStoreMapSizeKb' | 'l1Contracts'>,
|
|
43
|
-
|
|
45
|
+
genesis: GenesisData = EMPTY_GENESIS_DATA,
|
|
44
46
|
instrumentation: WorldStateInstrumentation = new WorldStateInstrumentation(getTelemetryClient()),
|
|
47
|
+
bindings?: LoggerBindings,
|
|
45
48
|
) {
|
|
46
49
|
const dataDirectory = config.worldStateDataDirectory ?? config.dataDirectory;
|
|
47
50
|
const dataStoreMapSizeKb = config.worldStateDbMapSizeKb ?? config.dataStoreMapSizeKb;
|
|
@@ -63,13 +66,16 @@ export async function createWorldState(
|
|
|
63
66
|
config.l1Contracts.rollupAddress,
|
|
64
67
|
dataDirectory,
|
|
65
68
|
wsTreeMapSizes,
|
|
66
|
-
|
|
69
|
+
genesis,
|
|
67
70
|
instrumentation,
|
|
71
|
+
bindings,
|
|
68
72
|
)
|
|
69
73
|
: await NativeWorldStateService.tmp(
|
|
70
74
|
config.l1Contracts.rollupAddress,
|
|
71
75
|
!['true', '1'].includes(process.env.DEBUG_WORLD_STATE!),
|
|
72
|
-
|
|
76
|
+
genesis,
|
|
77
|
+
instrumentation,
|
|
78
|
+
bindings,
|
|
73
79
|
);
|
|
74
80
|
|
|
75
81
|
return merkleTrees;
|