@aztec/world-state 0.0.1-commit.6d3c34e → 0.0.1-commit.7035c9bd6
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 +5 -5
- package/dest/native/merkle_trees_facade.d.ts.map +1 -1
- package/dest/native/merkle_trees_facade.js +21 -9
- package/dest/native/message.d.ts +14 -5
- package/dest/native/message.d.ts.map +1 -1
- package/dest/native/native_world_state.d.ts +7 -7
- package/dest/native/native_world_state.d.ts.map +1 -1
- package/dest/native/native_world_state.js +9 -8
- package/dest/native/native_world_state_instance.d.ts +3 -3
- package/dest/native/native_world_state_instance.d.ts.map +1 -1
- package/dest/native/native_world_state_instance.js +4 -4
- package/dest/synchronizer/config.d.ts +3 -5
- package/dest/synchronizer/config.d.ts.map +1 -1
- package/dest/synchronizer/config.js +7 -9
- package/dest/synchronizer/factory.d.ts +5 -4
- 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 +4 -5
- package/dest/synchronizer/server_world_state_synchronizer.d.ts.map +1 -1
- package/dest/synchronizer/server_world_state_synchronizer.js +91 -34
- 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/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 +24 -8
- package/src/native/message.ts +15 -4
- package/src/native/native_world_state.ts +22 -10
- package/src/native/native_world_state_instance.ts +6 -4
- package/src/synchronizer/config.ts +8 -19
- package/src/synchronizer/factory.ts +8 -2
- package/src/synchronizer/server_world_state_synchronizer.ts +113 -44
- package/src/test/utils.ts +6 -6
- package/src/world-state-db/merkle_tree_db.ts +2 -12
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/world-state",
|
|
3
|
-
"version": "0.0.1-commit.
|
|
3
|
+
"version": "0.0.1-commit.7035c9bd6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dest/index.js",
|
|
@@ -64,23 +64,22 @@
|
|
|
64
64
|
]
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
|
-
"@aztec/constants": "0.0.1-commit.
|
|
68
|
-
"@aztec/foundation": "0.0.1-commit.
|
|
69
|
-
"@aztec/kv-store": "0.0.1-commit.
|
|
70
|
-
"@aztec/
|
|
71
|
-
"@aztec/
|
|
72
|
-
"@aztec/
|
|
73
|
-
"@aztec/
|
|
74
|
-
"@aztec/telemetry-client": "0.0.1-commit.6d3c34e",
|
|
67
|
+
"@aztec/constants": "0.0.1-commit.7035c9bd6",
|
|
68
|
+
"@aztec/foundation": "0.0.1-commit.7035c9bd6",
|
|
69
|
+
"@aztec/kv-store": "0.0.1-commit.7035c9bd6",
|
|
70
|
+
"@aztec/native": "0.0.1-commit.7035c9bd6",
|
|
71
|
+
"@aztec/protocol-contracts": "0.0.1-commit.7035c9bd6",
|
|
72
|
+
"@aztec/stdlib": "0.0.1-commit.7035c9bd6",
|
|
73
|
+
"@aztec/telemetry-client": "0.0.1-commit.7035c9bd6",
|
|
75
74
|
"tslib": "^2.4.0",
|
|
76
75
|
"zod": "^3.23.8"
|
|
77
76
|
},
|
|
78
77
|
"devDependencies": {
|
|
79
|
-
"@aztec/archiver": "0.0.1-commit.
|
|
78
|
+
"@aztec/archiver": "0.0.1-commit.7035c9bd6",
|
|
80
79
|
"@jest/globals": "^30.0.0",
|
|
81
80
|
"@types/jest": "^30.0.0",
|
|
82
81
|
"@types/node": "^22.15.17",
|
|
83
|
-
"@typescript/native-preview": "7.0.0-dev.
|
|
82
|
+
"@typescript/native-preview": "7.0.0-dev.20260113.1",
|
|
84
83
|
"jest": "^30.0.0",
|
|
85
84
|
"jest-mock-extended": "^4.0.0",
|
|
86
85
|
"ts-node": "^10.9.1",
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
Metrics,
|
|
8
8
|
type TelemetryClient,
|
|
9
9
|
type UpDownCounter,
|
|
10
|
+
createUpDownCounterWithDefault,
|
|
10
11
|
} from '@aztec/telemetry-client';
|
|
11
12
|
|
|
12
13
|
import {
|
|
@@ -63,7 +64,14 @@ export class WorldStateInstrumentation {
|
|
|
63
64
|
|
|
64
65
|
this.requestHistogram = meter.createHistogram(Metrics.WORLD_STATE_REQUEST_TIME);
|
|
65
66
|
|
|
66
|
-
this.criticalErrors = meter
|
|
67
|
+
this.criticalErrors = createUpDownCounterWithDefault(meter, Metrics.WORLD_STATE_CRITICAL_ERROR_COUNT, {
|
|
68
|
+
[Attributes.ERROR_TYPE]: [
|
|
69
|
+
'synch_pending_block',
|
|
70
|
+
'finalize_block',
|
|
71
|
+
'prune_pending_block',
|
|
72
|
+
'prune_historical_block',
|
|
73
|
+
],
|
|
74
|
+
});
|
|
67
75
|
}
|
|
68
76
|
|
|
69
77
|
private updateTreeStats(treeDbStats: TreeDBStats, treeMeta: TreeMeta, tree: MerkleTreeId) {
|
|
@@ -3,11 +3,14 @@ import type { MerkleTreeCheckpointOperations } from '@aztec/stdlib/interfaces/se
|
|
|
3
3
|
export class ForkCheckpoint {
|
|
4
4
|
private completed = false;
|
|
5
5
|
|
|
6
|
-
private constructor(
|
|
6
|
+
private constructor(
|
|
7
|
+
private readonly fork: MerkleTreeCheckpointOperations,
|
|
8
|
+
public readonly depth: number,
|
|
9
|
+
) {}
|
|
7
10
|
|
|
8
11
|
static async new(fork: MerkleTreeCheckpointOperations): Promise<ForkCheckpoint> {
|
|
9
|
-
await fork.createCheckpoint();
|
|
10
|
-
return new ForkCheckpoint(fork);
|
|
12
|
+
const depth = await fork.createCheckpoint();
|
|
13
|
+
return new ForkCheckpoint(fork, depth);
|
|
11
14
|
}
|
|
12
15
|
|
|
13
16
|
async commit(): Promise<void> {
|
|
@@ -27,4 +30,17 @@ export class ForkCheckpoint {
|
|
|
27
30
|
await this.fork.revertCheckpoint();
|
|
28
31
|
this.completed = true;
|
|
29
32
|
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Reverts this checkpoint and any nested checkpoints created on top of it,
|
|
36
|
+
* leaving the checkpoint depth at the level it was before this checkpoint was created.
|
|
37
|
+
*/
|
|
38
|
+
async revertToCheckpoint(): Promise<void> {
|
|
39
|
+
if (this.completed) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
await this.fork.revertAllCheckpointsTo(this.depth - 1);
|
|
44
|
+
this.completed = true;
|
|
45
|
+
}
|
|
30
46
|
}
|
|
@@ -292,10 +292,19 @@ export class MerkleTreesForkFacade extends MerkleTreesFacade implements MerkleTr
|
|
|
292
292
|
|
|
293
293
|
public async close(): Promise<void> {
|
|
294
294
|
assert.notEqual(this.revision.forkId, 0, 'Fork ID must be set');
|
|
295
|
-
|
|
295
|
+
try {
|
|
296
|
+
await this.instance.call(WorldStateMessageType.DELETE_FORK, { forkId: this.revision.forkId });
|
|
297
|
+
} catch (err: any) {
|
|
298
|
+
// Ignore errors due to native instance being closed during shutdown.
|
|
299
|
+
// This can happen when validators are still processing block proposals while the node is stopping.
|
|
300
|
+
if (err?.message === 'Native instance is closed') {
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
throw err;
|
|
304
|
+
}
|
|
296
305
|
}
|
|
297
306
|
|
|
298
|
-
async [Symbol.
|
|
307
|
+
async [Symbol.asyncDispose](): Promise<void> {
|
|
299
308
|
if (this.opts.closeDelayMs) {
|
|
300
309
|
void sleep(this.opts.closeDelayMs)
|
|
301
310
|
.then(() => this.close())
|
|
@@ -310,9 +319,10 @@ export class MerkleTreesForkFacade extends MerkleTreesFacade implements MerkleTr
|
|
|
310
319
|
}
|
|
311
320
|
}
|
|
312
321
|
|
|
313
|
-
public async createCheckpoint(): Promise<
|
|
322
|
+
public async createCheckpoint(): Promise<number> {
|
|
314
323
|
assert.notEqual(this.revision.forkId, 0, 'Fork ID must be set');
|
|
315
|
-
await this.instance.call(WorldStateMessageType.CREATE_CHECKPOINT, { forkId: this.revision.forkId });
|
|
324
|
+
const resp = await this.instance.call(WorldStateMessageType.CREATE_CHECKPOINT, { forkId: this.revision.forkId });
|
|
325
|
+
return resp.depth;
|
|
316
326
|
}
|
|
317
327
|
|
|
318
328
|
public async commitCheckpoint(): Promise<void> {
|
|
@@ -325,14 +335,20 @@ export class MerkleTreesForkFacade extends MerkleTreesFacade implements MerkleTr
|
|
|
325
335
|
await this.instance.call(WorldStateMessageType.REVERT_CHECKPOINT, { forkId: this.revision.forkId });
|
|
326
336
|
}
|
|
327
337
|
|
|
328
|
-
public async
|
|
338
|
+
public async commitAllCheckpointsTo(depth: number): Promise<void> {
|
|
329
339
|
assert.notEqual(this.revision.forkId, 0, 'Fork ID must be set');
|
|
330
|
-
await this.instance.call(WorldStateMessageType.COMMIT_ALL_CHECKPOINTS, {
|
|
340
|
+
await this.instance.call(WorldStateMessageType.COMMIT_ALL_CHECKPOINTS, {
|
|
341
|
+
forkId: this.revision.forkId,
|
|
342
|
+
depth,
|
|
343
|
+
});
|
|
331
344
|
}
|
|
332
345
|
|
|
333
|
-
public async
|
|
346
|
+
public async revertAllCheckpointsTo(depth: number): Promise<void> {
|
|
334
347
|
assert.notEqual(this.revision.forkId, 0, 'Fork ID must be set');
|
|
335
|
-
await this.instance.call(WorldStateMessageType.REVERT_ALL_CHECKPOINTS, {
|
|
348
|
+
await this.instance.call(WorldStateMessageType.REVERT_ALL_CHECKPOINTS, {
|
|
349
|
+
forkId: this.revision.forkId,
|
|
350
|
+
depth,
|
|
351
|
+
});
|
|
336
352
|
}
|
|
337
353
|
}
|
|
338
354
|
|
package/src/native/message.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
2
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
3
|
import type { Tuple } from '@aztec/foundation/serialize';
|
|
4
|
+
import type { BlockHash } from '@aztec/stdlib/block';
|
|
4
5
|
import { AppendOnlyTreeSnapshot, MerkleTreeId } from '@aztec/stdlib/trees';
|
|
5
6
|
import type { StateReference } from '@aztec/stdlib/tx';
|
|
6
7
|
import type { UInt32 } from '@aztec/stdlib/types';
|
|
@@ -283,6 +284,16 @@ interface WithForkId {
|
|
|
283
284
|
forkId: number;
|
|
284
285
|
}
|
|
285
286
|
|
|
287
|
+
interface CreateCheckpointResponse {
|
|
288
|
+
depth: number;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/** Request to commit/revert all checkpoints down to a target depth. The resulting depth after the operation equals the given depth. */
|
|
292
|
+
interface CheckpointDepthRequest extends WithForkId {
|
|
293
|
+
/** The target depth after the operation. All checkpoints above this depth are committed/reverted. */
|
|
294
|
+
depth: number;
|
|
295
|
+
}
|
|
296
|
+
|
|
286
297
|
interface WithWorldStateRevision {
|
|
287
298
|
revision: WorldStateRevision;
|
|
288
299
|
}
|
|
@@ -412,7 +423,7 @@ interface UpdateArchiveRequest extends WithForkId {
|
|
|
412
423
|
interface SyncBlockRequest extends WithCanonicalForkId {
|
|
413
424
|
blockNumber: BlockNumber;
|
|
414
425
|
blockStateRef: BlockStateReference;
|
|
415
|
-
blockHeaderHash:
|
|
426
|
+
blockHeaderHash: BlockHash;
|
|
416
427
|
paddedNoteHashes: readonly SerializedLeafValue[];
|
|
417
428
|
paddedL1ToL2Messages: readonly SerializedLeafValue[];
|
|
418
429
|
paddedNullifiers: readonly SerializedLeafValue[];
|
|
@@ -486,8 +497,8 @@ export type WorldStateRequest = {
|
|
|
486
497
|
[WorldStateMessageType.CREATE_CHECKPOINT]: WithForkId;
|
|
487
498
|
[WorldStateMessageType.COMMIT_CHECKPOINT]: WithForkId;
|
|
488
499
|
[WorldStateMessageType.REVERT_CHECKPOINT]: WithForkId;
|
|
489
|
-
[WorldStateMessageType.COMMIT_ALL_CHECKPOINTS]:
|
|
490
|
-
[WorldStateMessageType.REVERT_ALL_CHECKPOINTS]:
|
|
500
|
+
[WorldStateMessageType.COMMIT_ALL_CHECKPOINTS]: CheckpointDepthRequest;
|
|
501
|
+
[WorldStateMessageType.REVERT_ALL_CHECKPOINTS]: CheckpointDepthRequest;
|
|
491
502
|
|
|
492
503
|
[WorldStateMessageType.COPY_STORES]: CopyStoresRequest;
|
|
493
504
|
|
|
@@ -528,7 +539,7 @@ export type WorldStateResponse = {
|
|
|
528
539
|
|
|
529
540
|
[WorldStateMessageType.GET_STATUS]: WorldStateStatusSummary;
|
|
530
541
|
|
|
531
|
-
[WorldStateMessageType.CREATE_CHECKPOINT]:
|
|
542
|
+
[WorldStateMessageType.CREATE_CHECKPOINT]: CreateCheckpointResponse;
|
|
532
543
|
[WorldStateMessageType.COMMIT_CHECKPOINT]: void;
|
|
533
544
|
[WorldStateMessageType.REVERT_CHECKPOINT]: void;
|
|
534
545
|
[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,
|
|
@@ -52,7 +52,7 @@ 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
56
|
private readonly cleanup = () => Promise.resolve(),
|
|
57
57
|
) {}
|
|
58
58
|
|
|
@@ -62,9 +62,10 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
|
|
|
62
62
|
wsTreeMapSizes: WorldStateTreeMapSizes,
|
|
63
63
|
prefilledPublicData: PublicDataTreeLeaf[] = [],
|
|
64
64
|
instrumentation = new WorldStateInstrumentation(getTelemetryClient()),
|
|
65
|
-
|
|
65
|
+
bindings?: LoggerBindings,
|
|
66
66
|
cleanup = () => Promise.resolve(),
|
|
67
67
|
): Promise<NativeWorldStateService> {
|
|
68
|
+
const log = createLogger('world-state:database', bindings);
|
|
68
69
|
const worldStateDirectory = join(dataDir, WORLD_STATE_DIR);
|
|
69
70
|
// Create a version manager to handle versioning
|
|
70
71
|
const versionManager = new DatabaseVersionManager({
|
|
@@ -72,7 +73,9 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
|
|
|
72
73
|
rollupAddress,
|
|
73
74
|
dataDirectory: worldStateDirectory,
|
|
74
75
|
onOpen: (dir: string) => {
|
|
75
|
-
return Promise.resolve(
|
|
76
|
+
return Promise.resolve(
|
|
77
|
+
new NativeWorldState(dir, wsTreeMapSizes, prefilledPublicData, instrumentation, bindings),
|
|
78
|
+
);
|
|
76
79
|
},
|
|
77
80
|
});
|
|
78
81
|
|
|
@@ -93,8 +96,9 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
|
|
|
93
96
|
cleanupTmpDir = true,
|
|
94
97
|
prefilledPublicData: PublicDataTreeLeaf[] = [],
|
|
95
98
|
instrumentation = new WorldStateInstrumentation(getTelemetryClient()),
|
|
99
|
+
bindings?: LoggerBindings,
|
|
96
100
|
): Promise<NativeWorldStateService> {
|
|
97
|
-
const log = createLogger('world-state:database');
|
|
101
|
+
const log = createLogger('world-state:database', bindings);
|
|
98
102
|
const dataDir = await mkdtemp(join(tmpdir(), 'aztec-world-state-'));
|
|
99
103
|
const dbMapSizeKb = 10 * 1024 * 1024;
|
|
100
104
|
const worldStateTreeMapSizes: WorldStateTreeMapSizes = {
|
|
@@ -116,7 +120,15 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
|
|
|
116
120
|
}
|
|
117
121
|
};
|
|
118
122
|
|
|
119
|
-
return this.new(
|
|
123
|
+
return this.new(
|
|
124
|
+
rollupAddress,
|
|
125
|
+
dataDir,
|
|
126
|
+
worldStateTreeMapSizes,
|
|
127
|
+
prefilledPublicData,
|
|
128
|
+
instrumentation,
|
|
129
|
+
bindings,
|
|
130
|
+
cleanup,
|
|
131
|
+
);
|
|
120
132
|
}
|
|
121
133
|
|
|
122
134
|
protected async init() {
|
|
@@ -135,7 +147,7 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
|
|
|
135
147
|
|
|
136
148
|
// the initial header _must_ be the first element in the archive tree
|
|
137
149
|
// if this assertion fails, check that the hashing done in Header in yarn-project matches the initial header hash done in world_state.cpp
|
|
138
|
-
const indices = await committed.findLeafIndices(MerkleTreeId.ARCHIVE, [await this.initialHeader.hash()]);
|
|
150
|
+
const indices = await committed.findLeafIndices(MerkleTreeId.ARCHIVE, [(await this.initialHeader.hash()).toFr()]);
|
|
139
151
|
const initialHeaderIndex = indices[0];
|
|
140
152
|
assert.strictEqual(initialHeaderIndex, 0n, 'Invalid initial archive state');
|
|
141
153
|
}
|
|
@@ -184,7 +196,7 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
|
|
|
184
196
|
return this.initialHeader!;
|
|
185
197
|
}
|
|
186
198
|
|
|
187
|
-
public async handleL2BlockAndMessages(l2Block:
|
|
199
|
+
public async handleL2BlockAndMessages(l2Block: L2Block, l1ToL2Messages: Fr[]): Promise<WorldStateStatusFull> {
|
|
188
200
|
const isFirstBlock = l2Block.indexWithinCheckpoint === 0;
|
|
189
201
|
if (!isFirstBlock && l1ToL2Messages.length > 0) {
|
|
190
202
|
throw new Error(
|
|
@@ -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,7 +8,7 @@ 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
14
|
import type { PublicDataTreeLeaf } from '@aztec/stdlib/trees';
|
|
@@ -57,7 +57,8 @@ export class NativeWorldState implements NativeWorldStateInstance {
|
|
|
57
57
|
private readonly wsTreeMapSizes: WorldStateTreeMapSizes,
|
|
58
58
|
private readonly prefilledPublicData: PublicDataTreeLeaf[] = [],
|
|
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(
|
|
@@ -80,7 +81,7 @@ export class NativeWorldState implements NativeWorldStateInstance {
|
|
|
80
81
|
[MerkleTreeId.PUBLIC_DATA_TREE]: 2 * MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
|
|
81
82
|
},
|
|
82
83
|
prefilledPublicDataBufferArray,
|
|
83
|
-
|
|
84
|
+
DomainSeparator.BLOCK_HEADER_HASH,
|
|
84
85
|
{
|
|
85
86
|
[MerkleTreeId.NULLIFIER_TREE]: wsTreeMapSizes.nullifierTreeMapSizeKb,
|
|
86
87
|
[MerkleTreeId.NOTE_HASH_TREE]: wsTreeMapSizes.noteHashTreeMapSizeKb,
|
|
@@ -105,6 +106,7 @@ export class NativeWorldState implements NativeWorldStateInstance {
|
|
|
105
106
|
this.wsTreeMapSizes,
|
|
106
107
|
this.prefilledPublicData,
|
|
107
108
|
this.instrumentation,
|
|
109
|
+
this.log.getBindings(),
|
|
108
110
|
this.log,
|
|
109
111
|
);
|
|
110
112
|
}
|
|
@@ -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,11 +40,6 @@ 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
45
|
parseEnv: (val: string | undefined) => (val ? +val : undefined),
|
|
@@ -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,5 +1,6 @@
|
|
|
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
5
|
import type { PublicDataTreeLeaf } from '@aztec/stdlib/trees';
|
|
5
6
|
import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
|
|
@@ -22,9 +23,10 @@ export async function createWorldStateSynchronizer(
|
|
|
22
23
|
l2BlockSource: L2BlockSource & L1ToL2MessageSource,
|
|
23
24
|
prefilledPublicData: PublicDataTreeLeaf[] = [],
|
|
24
25
|
client: TelemetryClient = getTelemetryClient(),
|
|
26
|
+
bindings?: LoggerBindings,
|
|
25
27
|
) {
|
|
26
28
|
const instrumentation = new WorldStateInstrumentation(client);
|
|
27
|
-
const merkleTrees = await createWorldState(config, prefilledPublicData, instrumentation);
|
|
29
|
+
const merkleTrees = await createWorldState(config, prefilledPublicData, instrumentation, bindings);
|
|
28
30
|
return new ServerWorldStateSynchronizer(merkleTrees, l2BlockSource, config, instrumentation);
|
|
29
31
|
}
|
|
30
32
|
|
|
@@ -42,6 +44,7 @@ export async function createWorldState(
|
|
|
42
44
|
Pick<DataStoreConfig, 'dataDirectory' | 'dataStoreMapSizeKb' | 'l1Contracts'>,
|
|
43
45
|
prefilledPublicData: PublicDataTreeLeaf[] = [],
|
|
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;
|
|
@@ -65,11 +68,14 @@ export async function createWorldState(
|
|
|
65
68
|
wsTreeMapSizes,
|
|
66
69
|
prefilledPublicData,
|
|
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
|
prefilledPublicData,
|
|
77
|
+
instrumentation,
|
|
78
|
+
bindings,
|
|
73
79
|
);
|
|
74
80
|
|
|
75
81
|
return merkleTrees;
|