@aztec/world-state 0.0.1-commit.f5d02921e → 0.0.1-commit.f650c0a5c
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/native/native_world_state.d.ts +7 -5
- package/dest/native/native_world_state.d.ts.map +1 -1
- package/dest/native/native_world_state.js +14 -9
- package/dest/native/native_world_state_instance.d.ts +4 -4
- package/dest/native/native_world_state_instance.d.ts.map +1 -1
- package/dest/native/native_world_state_instance.js +7 -6
- package/dest/native/world_state_ops_queue.js +5 -5
- package/dest/synchronizer/factory.d.ts +4 -4
- package/dest/synchronizer/factory.d.ts.map +1 -1
- package/dest/synchronizer/factory.js +6 -5
- package/dest/testing.d.ts +4 -3
- package/dest/testing.d.ts.map +1 -1
- package/dest/testing.js +10 -6
- package/package.json +9 -9
- package/src/native/native_world_state.ts +12 -18
- package/src/native/native_world_state_instance.ts +8 -4
- package/src/native/world_state_ops_queue.ts +5 -5
- package/src/synchronizer/factory.ts +6 -6
- package/src/testing.ts +8 -9
|
@@ -5,8 +5,9 @@ import { type Logger, type LoggerBindings } from '@aztec/foundation/log';
|
|
|
5
5
|
import type { L2Block } from '@aztec/stdlib/block';
|
|
6
6
|
import type { IndexedTreeId, MerkleTreeReadOperations, MerkleTreeWriteOperations } from '@aztec/stdlib/interfaces/server';
|
|
7
7
|
import type { SnapshotDataKeys } from '@aztec/stdlib/snapshots';
|
|
8
|
-
import { type NullifierLeafPreimage
|
|
8
|
+
import { type NullifierLeafPreimage } from '@aztec/stdlib/trees';
|
|
9
9
|
import { BlockHeader } from '@aztec/stdlib/tx';
|
|
10
|
+
import { type GenesisData } from '@aztec/stdlib/world-state';
|
|
10
11
|
import { WorldStateInstrumentation } from '../instrumentation/instrumentation.js';
|
|
11
12
|
import type { WorldStateTreeMapSizes } from '../synchronizer/factory.js';
|
|
12
13
|
import type { MerkleTreeAdminDatabase as MerkleTreeDatabase } from '../world-state-db/merkle_tree_db.js';
|
|
@@ -18,12 +19,13 @@ export declare class NativeWorldStateService implements MerkleTreeDatabase {
|
|
|
18
19
|
protected instance: NativeWorldState;
|
|
19
20
|
protected readonly worldStateInstrumentation: WorldStateInstrumentation;
|
|
20
21
|
protected readonly log: Logger;
|
|
22
|
+
private readonly genesis;
|
|
21
23
|
private readonly cleanup;
|
|
22
24
|
protected initialHeader: BlockHeader | undefined;
|
|
23
25
|
private cachedStatusSummary;
|
|
24
|
-
protected constructor(instance: NativeWorldState, worldStateInstrumentation: WorldStateInstrumentation, log: Logger, cleanup?: () => Promise<void>);
|
|
25
|
-
static new(rollupAddress: EthAddress, dataDir: string, wsTreeMapSizes: WorldStateTreeMapSizes,
|
|
26
|
-
static tmp(rollupAddress?: EthAddress, cleanupTmpDir?: boolean,
|
|
26
|
+
protected constructor(instance: NativeWorldState, worldStateInstrumentation: WorldStateInstrumentation, log: Logger, genesis?: GenesisData, cleanup?: () => Promise<void>);
|
|
27
|
+
static new(rollupAddress: EthAddress, dataDir: string, wsTreeMapSizes: WorldStateTreeMapSizes, genesis?: GenesisData, instrumentation?: WorldStateInstrumentation, bindings?: LoggerBindings, cleanup?: () => Promise<void>): Promise<NativeWorldStateService>;
|
|
28
|
+
static tmp(rollupAddress?: EthAddress, cleanupTmpDir?: boolean, genesis?: GenesisData, instrumentation?: WorldStateInstrumentation, bindings?: LoggerBindings): Promise<NativeWorldStateService>;
|
|
27
29
|
protected init(): Promise<void>;
|
|
28
30
|
clear(): Promise<void>;
|
|
29
31
|
getCommitted(): MerkleTreeReadOperations;
|
|
@@ -62,4 +64,4 @@ export declare class NativeWorldStateService implements MerkleTreeDatabase {
|
|
|
62
64
|
backupTo(dstPath: string, compact?: boolean): Promise<Record<Exclude<SnapshotDataKeys, 'archiver'>, string>>;
|
|
63
65
|
}
|
|
64
66
|
export declare const NATIVE_WORLD_STATE_DBS: readonly [readonly ["l1-to-l2-message-tree", "L1ToL2MessageTree"], readonly ["archive-tree", "ArchiveTree"], readonly ["public-data-tree", "PublicDataTree"], readonly ["note-hash-tree", "NoteHashTree"], readonly ["nullifier-tree", "NullifierTree"]];
|
|
65
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
67
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibmF0aXZlX3dvcmxkX3N0YXRlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvbmF0aXZlL25hdGl2ZV93b3JsZF9zdGF0ZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFDQSxPQUFPLEVBQUUsV0FBVyxFQUFFLE1BQU0saUNBQWlDLENBQUM7QUFFOUQsT0FBTyxFQUFFLEVBQUUsRUFBRSxNQUFNLGdDQUFnQyxDQUFDO0FBQ3BELE9BQU8sRUFBRSxVQUFVLEVBQUUsTUFBTSwrQkFBK0IsQ0FBQztBQUUzRCxPQUFPLEVBQUUsS0FBSyxNQUFNLEVBQUUsS0FBSyxjQUFjLEVBQWdCLE1BQU0sdUJBQXVCLENBQUM7QUFDdkYsT0FBTyxLQUFLLEVBQUUsT0FBTyxFQUFFLE1BQU0scUJBQXFCLENBQUM7QUFFbkQsT0FBTyxLQUFLLEVBQ1YsYUFBYSxFQUNiLHdCQUF3QixFQUN4Qix5QkFBeUIsRUFDMUIsTUFBTSxpQ0FBaUMsQ0FBQztBQUN6QyxPQUFPLEtBQUssRUFBRSxnQkFBZ0IsRUFBRSxNQUFNLHlCQUF5QixDQUFDO0FBQ2hFLE9BQU8sRUFBK0IsS0FBSyxxQkFBcUIsRUFBc0IsTUFBTSxxQkFBcUIsQ0FBQztBQUNsSCxPQUFPLEVBQUUsV0FBVyxFQUEwRCxNQUFNLGtCQUFrQixDQUFDO0FBQ3ZHLE9BQU8sRUFBc0IsS0FBSyxXQUFXLEVBQXNCLE1BQU0sMkJBQTJCLENBQUM7QUFRckcsT0FBTyxFQUFFLHlCQUF5QixFQUFFLE1BQU0sdUNBQXVDLENBQUM7QUFDb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AC,CAmD3G;IAEY,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAGlC;YAEa,kBAAkB;IAQhC,OAAO,CAAC,+BAA+B;IAMvC,OAAO,CAAC,uBAAuB;IAM/B,OAAO,CAAC,mBAAmB;IAI3B;;;;OAIG;IACU,YAAY,CAAC,aAAa,EAAE,WAAW,oCAgBnD;IAED;;;;OAIG;IACU,sBAAsB,CAAC,aAAa,EAAE,WAAW,iCAe7D;IAED;;;;OAIG;IACU,YAAY,CAAC,aAAa,EAAE,WAAW,iCAenD;IAEY,gBAAgB,qCAS5B;IAED,UAAU,CAAC,EAAE,SAAS,aAAa,EACjC,OAAO,EAAE,EAAE,EACX,KAAK,EAAE,qBAAqB,GAAG,MAAM,EACrC,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,CAAC,CAEf;YAEa,wBAAwB;IAazB,QAAQ,CACnB,OAAO,EAAE,MAAM,EACf,OAAO,GAAE,OAAc,GACtB,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,gBAAgB,EAAE,UAAU,CAAC,EAAE,MAAM,CAAC,CAAC,CAOhE;CACF;AAGD,eAAO,MAAM,sBAAsB,0PAMzB,CAAC"}
|
|
@@ -7,8 +7,8 @@ import { tryRmDir } from '@aztec/foundation/fs';
|
|
|
7
7
|
import { createLogger } from '@aztec/foundation/log';
|
|
8
8
|
import { DatabaseVersionManager } from '@aztec/stdlib/database-version/manager';
|
|
9
9
|
import { MerkleTreeId, NullifierLeaf, PublicDataTreeLeaf } from '@aztec/stdlib/trees';
|
|
10
|
-
import { BlockHeader, PartialStateReference, StateReference } from '@aztec/stdlib/tx';
|
|
11
|
-
import { WorldStateRevision } from '@aztec/stdlib/world-state';
|
|
10
|
+
import { BlockHeader, GlobalVariables, PartialStateReference, StateReference } from '@aztec/stdlib/tx';
|
|
11
|
+
import { EMPTY_GENESIS_DATA, WorldStateRevision } from '@aztec/stdlib/world-state';
|
|
12
12
|
import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
13
13
|
import assert from 'assert/strict';
|
|
14
14
|
import { mkdtemp, rm } from 'fs/promises';
|
|
@@ -26,17 +26,19 @@ export class NativeWorldStateService {
|
|
|
26
26
|
instance;
|
|
27
27
|
worldStateInstrumentation;
|
|
28
28
|
log;
|
|
29
|
+
genesis;
|
|
29
30
|
cleanup;
|
|
30
31
|
initialHeader;
|
|
31
32
|
// This is read heavily and only changes when data is persisted, so we cache it
|
|
32
33
|
cachedStatusSummary;
|
|
33
|
-
constructor(instance, worldStateInstrumentation, log, cleanup = ()=>Promise.resolve()){
|
|
34
|
+
constructor(instance, worldStateInstrumentation, log, genesis = EMPTY_GENESIS_DATA, cleanup = ()=>Promise.resolve()){
|
|
34
35
|
this.instance = instance;
|
|
35
36
|
this.worldStateInstrumentation = worldStateInstrumentation;
|
|
36
37
|
this.log = log;
|
|
38
|
+
this.genesis = genesis;
|
|
37
39
|
this.cleanup = cleanup;
|
|
38
40
|
}
|
|
39
|
-
static async new(rollupAddress, dataDir, wsTreeMapSizes,
|
|
41
|
+
static async new(rollupAddress, dataDir, wsTreeMapSizes, genesis = EMPTY_GENESIS_DATA, instrumentation = new WorldStateInstrumentation(getTelemetryClient()), bindings, cleanup = ()=>Promise.resolve()) {
|
|
40
42
|
const log = createLogger('world-state:database', bindings);
|
|
41
43
|
const worldStateDirectory = join(dataDir, WORLD_STATE_DIR);
|
|
42
44
|
// Create a version manager to handle versioning
|
|
@@ -45,11 +47,11 @@ export class NativeWorldStateService {
|
|
|
45
47
|
rollupAddress,
|
|
46
48
|
dataDirectory: worldStateDirectory,
|
|
47
49
|
onOpen: (dir)=>{
|
|
48
|
-
return Promise.resolve(new NativeWorldState(dir, wsTreeMapSizes,
|
|
50
|
+
return Promise.resolve(new NativeWorldState(dir, wsTreeMapSizes, genesis, instrumentation, bindings));
|
|
49
51
|
}
|
|
50
52
|
});
|
|
51
53
|
const [instance] = await versionManager.open();
|
|
52
|
-
const worldState = new this(instance, instrumentation, log, cleanup);
|
|
54
|
+
const worldState = new this(instance, instrumentation, log, genesis, cleanup);
|
|
53
55
|
try {
|
|
54
56
|
await worldState.init();
|
|
55
57
|
} catch (e) {
|
|
@@ -58,7 +60,7 @@ export class NativeWorldStateService {
|
|
|
58
60
|
}
|
|
59
61
|
return worldState;
|
|
60
62
|
}
|
|
61
|
-
static async tmp(rollupAddress = EthAddress.ZERO, cleanupTmpDir = true,
|
|
63
|
+
static async tmp(rollupAddress = EthAddress.ZERO, cleanupTmpDir = true, genesis = EMPTY_GENESIS_DATA, instrumentation = new WorldStateInstrumentation(getTelemetryClient()), bindings) {
|
|
62
64
|
const log = createLogger('world-state:database', bindings);
|
|
63
65
|
const dataDir = await mkdtemp(join(tmpdir(), 'aztec-world-state-'));
|
|
64
66
|
const dbMapSizeKb = 10 * 1024 * 1024;
|
|
@@ -83,7 +85,7 @@ export class NativeWorldStateService {
|
|
|
83
85
|
log.debug(`Leaving temporary world state database: ${dataDir}`);
|
|
84
86
|
}
|
|
85
87
|
};
|
|
86
|
-
return this.new(rollupAddress, dataDir, worldStateTreeMapSizes,
|
|
88
|
+
return this.new(rollupAddress, dataDir, worldStateTreeMapSizes, genesis, instrumentation, bindings, cleanup);
|
|
87
89
|
}
|
|
88
90
|
async init() {
|
|
89
91
|
const status = await this.getStatusSummary();
|
|
@@ -169,7 +171,10 @@ export class NativeWorldStateService {
|
|
|
169
171
|
async buildInitialHeader() {
|
|
170
172
|
const state = await this.getInitialStateReference();
|
|
171
173
|
return BlockHeader.empty({
|
|
172
|
-
state
|
|
174
|
+
state,
|
|
175
|
+
globalVariables: GlobalVariables.empty({
|
|
176
|
+
timestamp: this.genesis.genesisTimestamp
|
|
177
|
+
})
|
|
173
178
|
});
|
|
174
179
|
}
|
|
175
180
|
sanitizeAndCacheSummaryFromFull(response) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Logger, type LoggerBindings } from '@aztec/foundation/log';
|
|
2
|
-
import type
|
|
2
|
+
import { type GenesisData } from '@aztec/stdlib/world-state';
|
|
3
3
|
import type { WorldStateInstrumentation } from '../instrumentation/instrumentation.js';
|
|
4
4
|
import type { WorldStateTreeMapSizes } from '../synchronizer/factory.js';
|
|
5
5
|
import { WorldStateMessageType, type WorldStateRequest, type WorldStateRequestCategories, type WorldStateResponse } from './message.js';
|
|
@@ -13,14 +13,14 @@ export interface NativeWorldStateInstance {
|
|
|
13
13
|
export declare class NativeWorldState implements NativeWorldStateInstance {
|
|
14
14
|
private readonly dataDir;
|
|
15
15
|
private readonly wsTreeMapSizes;
|
|
16
|
-
private readonly
|
|
16
|
+
private readonly genesis;
|
|
17
17
|
private readonly instrumentation;
|
|
18
18
|
private readonly log;
|
|
19
19
|
private open;
|
|
20
20
|
private queues;
|
|
21
21
|
private instance;
|
|
22
22
|
/** Creates a new native WorldState instance */
|
|
23
|
-
constructor(dataDir: string, wsTreeMapSizes: WorldStateTreeMapSizes,
|
|
23
|
+
constructor(dataDir: string, wsTreeMapSizes: WorldStateTreeMapSizes, genesis: GenesisData | undefined, instrumentation: WorldStateInstrumentation, bindings?: LoggerBindings, log?: Logger);
|
|
24
24
|
getDataDir(): string;
|
|
25
25
|
clone(): NativeWorldState;
|
|
26
26
|
/**
|
|
@@ -46,4 +46,4 @@ export declare class NativeWorldState implements NativeWorldStateInstance {
|
|
|
46
46
|
close(): Promise<void>;
|
|
47
47
|
private _sendMessage;
|
|
48
48
|
}
|
|
49
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
49
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibmF0aXZlX3dvcmxkX3N0YXRlX2luc3RhbmNlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvbmF0aXZlL25hdGl2ZV93b3JsZF9zdGF0ZV9pbnN0YW5jZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFVQSxPQUFPLEVBQUUsS0FBSyxNQUFNLEVBQUUsS0FBSyx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LFlBQ21CLE9BQU8sRUFBRSxNQUFNLEVBQ2YsY0FBYyxFQUFFLHNCQUFzQixFQUN0QyxPQUFPLHlCQUFrQyxFQUN6QyxlQUFlLEVBQUUseUJBQXlCLEVBQzNELFFBQVEsQ0FBQyxFQUFFLGNBQWMsRUFDUixHQUFHLEdBQUUsTUFBdUQsRUF3QzlFO0lBRU0sVUFBVSxXQUVoQjtJQUVNLEtBQUsscUJBU1g7SUFFRDs7Ozs7O09BTUc7SUFDSSxTQUFTLElBQUksR0FBRyxDQWlCdEI7SUFFRDs7Ozs7OztPQU9HO0lBQ1UsSUFBSSxDQUFDLENBQUMsU0FBUyxxQkFBcUIsRUFDL0MsV0FBVyxFQUFFLENBQUMsRUFDZCxJQUFJLEVBQUUsaUJBQWlCLENBQUMsQ0FBQyxDQUFDLEdBQUcsMkJBQTJCLEVBRXhELGVBQWUsNkRBQXVFLEVBQ3RGLFlBQVksc0JBQW9CLEdBQy9CLE9BQU8sQ0FBQyxrQkFBa0IsQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQXFEaEM7SUFFRDs7T0FFRztJQUNVLEtBQUssSUFBSSxPQUFPLENBQUMsSUFBSSxDQUFDLENBZWxDO1lBRWEsWUFBWTtDQThEM0IifQ==
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"native_world_state_instance.d.ts","sourceRoot":"","sources":["../../src/native/native_world_state_instance.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,cAAc,EAAgB,MAAM,uBAAuB,CAAC;AAGvF,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"native_world_state_instance.d.ts","sourceRoot":"","sources":["../../src/native/native_world_state_instance.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,cAAc,EAAgB,MAAM,uBAAuB,CAAC;AAGvF,OAAO,EAAsB,KAAK,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAKjF,OAAO,KAAK,EA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B,GAC/B,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAqDhC;IAED;;OAEG;IACU,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAelC;YAEa,YAAY;CA8D3B"}
|
|
@@ -2,6 +2,7 @@ import { ARCHIVE_HEIGHT, DomainSeparator, L1_TO_L2_MSG_TREE_HEIGHT, MAX_NULLIFIE
|
|
|
2
2
|
import { createLogger } from '@aztec/foundation/log';
|
|
3
3
|
import { NativeWorldState as BaseNativeWorldState, MsgpackChannel } from '@aztec/native';
|
|
4
4
|
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
5
|
+
import { EMPTY_GENESIS_DATA } from '@aztec/stdlib/world-state';
|
|
5
6
|
import assert from 'assert';
|
|
6
7
|
import { cpus } from 'os';
|
|
7
8
|
import { WorldStateMessageType, isWithCanonical, isWithForkId, isWithRevision } from './message.js';
|
|
@@ -12,24 +13,24 @@ const MAX_WORLD_STATE_THREADS = +(process.env.HARDWARE_CONCURRENCY || '16');
|
|
|
12
13
|
*/ export class NativeWorldState {
|
|
13
14
|
dataDir;
|
|
14
15
|
wsTreeMapSizes;
|
|
15
|
-
|
|
16
|
+
genesis;
|
|
16
17
|
instrumentation;
|
|
17
18
|
log;
|
|
18
19
|
open;
|
|
19
20
|
// We maintain a map of queue to fork
|
|
20
21
|
queues;
|
|
21
22
|
instance;
|
|
22
|
-
/** Creates a new native WorldState instance */ constructor(dataDir, wsTreeMapSizes,
|
|
23
|
+
/** Creates a new native WorldState instance */ constructor(dataDir, wsTreeMapSizes, genesis = EMPTY_GENESIS_DATA, instrumentation, bindings, log = createLogger('world-state:database', bindings)){
|
|
23
24
|
this.dataDir = dataDir;
|
|
24
25
|
this.wsTreeMapSizes = wsTreeMapSizes;
|
|
25
|
-
this.
|
|
26
|
+
this.genesis = genesis;
|
|
26
27
|
this.instrumentation = instrumentation;
|
|
27
28
|
this.log = log;
|
|
28
29
|
this.open = true;
|
|
29
30
|
this.queues = new Map();
|
|
30
31
|
const threads = Math.min(cpus().length, MAX_WORLD_STATE_THREADS);
|
|
31
32
|
log.info(`Creating world state data store at directory ${dataDir} with map sizes ${JSON.stringify(wsTreeMapSizes)} and ${threads} threads.`);
|
|
32
|
-
const prefilledPublicDataBufferArray = prefilledPublicData.map((d)=>[
|
|
33
|
+
const prefilledPublicDataBufferArray = genesis.prefilledPublicData.map((d)=>[
|
|
33
34
|
d.slot.toBuffer(),
|
|
34
35
|
d.value.toBuffer()
|
|
35
36
|
]);
|
|
@@ -42,7 +43,7 @@ const MAX_WORLD_STATE_THREADS = +(process.env.HARDWARE_CONCURRENCY || '16');
|
|
|
42
43
|
}, {
|
|
43
44
|
[MerkleTreeId.NULLIFIER_TREE]: 2 * MAX_NULLIFIERS_PER_TX,
|
|
44
45
|
[MerkleTreeId.PUBLIC_DATA_TREE]: 2 * MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX
|
|
45
|
-
}, prefilledPublicDataBufferArray, DomainSeparator.BLOCK_HEADER_HASH, {
|
|
46
|
+
}, prefilledPublicDataBufferArray, DomainSeparator.BLOCK_HEADER_HASH, Number(genesis.genesisTimestamp), {
|
|
46
47
|
[MerkleTreeId.NULLIFIER_TREE]: wsTreeMapSizes.nullifierTreeMapSizeKb,
|
|
47
48
|
[MerkleTreeId.NOTE_HASH_TREE]: wsTreeMapSizes.noteHashTreeMapSizeKb,
|
|
48
49
|
[MerkleTreeId.PUBLIC_DATA_TREE]: wsTreeMapSizes.publicDataTreeMapSizeKb,
|
|
@@ -57,7 +58,7 @@ const MAX_WORLD_STATE_THREADS = +(process.env.HARDWARE_CONCURRENCY || '16');
|
|
|
57
58
|
return this.dataDir;
|
|
58
59
|
}
|
|
59
60
|
clone() {
|
|
60
|
-
return new NativeWorldState(this.dataDir, this.wsTreeMapSizes, this.
|
|
61
|
+
return new NativeWorldState(this.dataDir, this.wsTreeMapSizes, this.genesis, this.instrumentation, this.log.getBindings(), this.log);
|
|
61
62
|
}
|
|
62
63
|
/**
|
|
63
64
|
* Gets the native WorldState handle from the underlying native instance.
|
|
@@ -67,7 +67,7 @@ export class WorldStateOpsQueue {
|
|
|
67
67
|
// then send the request immediately
|
|
68
68
|
// If a mutating request is in flight then we must wait
|
|
69
69
|
// If a mutating request is not in flight but something is queued then it must be a mutating request
|
|
70
|
-
if (this.inFlightMutatingCount
|
|
70
|
+
if (this.inFlightMutatingCount === 0 && this.requests.length === 0) {
|
|
71
71
|
this.sendEnqueuedRequest(op);
|
|
72
72
|
} else {
|
|
73
73
|
this.requests.push(op);
|
|
@@ -88,7 +88,7 @@ export class WorldStateOpsQueue {
|
|
|
88
88
|
}
|
|
89
89
|
--this.inFlightCount;
|
|
90
90
|
// If there are still requests in flight then do nothing further
|
|
91
|
-
if (this.inFlightCount
|
|
91
|
+
if (this.inFlightCount !== 0) {
|
|
92
92
|
return;
|
|
93
93
|
}
|
|
94
94
|
// No requests in flight, send next queued requests
|
|
@@ -99,7 +99,7 @@ export class WorldStateOpsQueue {
|
|
|
99
99
|
while(this.requests.length > 0){
|
|
100
100
|
const next = this.requests[0];
|
|
101
101
|
if (next.mutating) {
|
|
102
|
-
if (this.inFlightCount
|
|
102
|
+
if (this.inFlightCount === 0) {
|
|
103
103
|
// send the mutating request
|
|
104
104
|
this.requests.shift();
|
|
105
105
|
this.sendEnqueuedRequest(next);
|
|
@@ -112,7 +112,7 @@ export class WorldStateOpsQueue {
|
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
114
|
// If the queue is empty, there is nothing in flight and we have been told to stop, then resolve the stop promise
|
|
115
|
-
if (this.inFlightCount
|
|
115
|
+
if (this.inFlightCount === 0 && this.stopResolve !== undefined) {
|
|
116
116
|
this.stopResolve();
|
|
117
117
|
}
|
|
118
118
|
}
|
|
@@ -138,7 +138,7 @@ export class WorldStateOpsQueue {
|
|
|
138
138
|
this.stopResolve = resolve;
|
|
139
139
|
});
|
|
140
140
|
// If no outstanding requests then immediately resolve the promise
|
|
141
|
-
if (this.requests.length
|
|
141
|
+
if (this.requests.length === 0 && this.inFlightCount === 0 && this.stopResolve !== undefined) {
|
|
142
142
|
this.stopResolve();
|
|
143
143
|
}
|
|
144
144
|
return this.stopPromise;
|
|
@@ -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 type
|
|
5
|
+
import { type GenesisData } from '@aztec/stdlib/world-state';
|
|
6
6
|
import { type TelemetryClient } from '@aztec/telemetry-client';
|
|
7
7
|
import { WorldStateInstrumentation } from '../instrumentation/instrumentation.js';
|
|
8
8
|
import { NativeWorldStateService } from '../native/native_world_state.js';
|
|
@@ -15,6 +15,6 @@ export interface WorldStateTreeMapSizes {
|
|
|
15
15
|
messageTreeMapSizeKb: number;
|
|
16
16
|
publicDataTreeMapSizeKb: number;
|
|
17
17
|
}
|
|
18
|
-
export declare function createWorldStateSynchronizer(config: WorldStateConfig & DataStoreConfig, l2BlockSource: L2BlockSource & L1ToL2MessageSource,
|
|
19
|
-
export declare function createWorldState(config: Pick<WorldStateConfig, 'worldStateDataDirectory' | 'worldStateDbMapSizeKb' | 'archiveTreeMapSizeKb' | 'nullifierTreeMapSizeKb' | 'noteHashTreeMapSizeKb' | 'messageTreeMapSizeKb' | 'publicDataTreeMapSizeKb'> & Pick<DataStoreConfig, 'dataDirectory' | 'dataStoreMapSizeKb' | 'l1Contracts'>,
|
|
20
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
18
|
+
export declare function createWorldStateSynchronizer(config: WorldStateConfig & DataStoreConfig, l2BlockSource: L2BlockSource & L1ToL2MessageSource, genesis?: GenesisData, client?: TelemetryClient, bindings?: LoggerBindings): Promise<ServerWorldStateSynchronizer>;
|
|
19
|
+
export declare function createWorldState(config: Pick<WorldStateConfig, 'worldStateDataDirectory' | 'worldStateDbMapSizeKb' | 'archiveTreeMapSizeKb' | 'nullifierTreeMapSizeKb' | 'noteHashTreeMapSizeKb' | 'messageTreeMapSizeKb' | 'publicDataTreeMapSizeKb'> & Pick<DataStoreConfig, 'dataDirectory' | 'dataStoreMapSizeKb' | 'l1Contracts'>, genesis?: GenesisData, instrumentation?: WorldStateInstrumentation, bindings?: LoggerBindings): Promise<NativeWorldStateService>;
|
|
20
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZmFjdG9yeS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3N5bmNocm9uaXplci9mYWN0b3J5LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sS0FBSyxFQUFFLGNBQWMsRUFBRSxNQUFNLHVCQUF1QixDQUFDO0FBQzVELE9BQU8sS0FBSyxFQUFFLGFBQWEsRUFBRSxNQUFNLHFCQUFxQixDQUFDO0FBQ3pELE9BQU8sS0FBSyxFQUFFLGVBQWUsRUFBRSxNQUFNLHdCQUF3QixDQUFDO0FBQzlELE9BQU8sS0FBSyxFQUFFLG1CQUFtQixFQUFFLE1BQU0seUJBQXlCLENBQUM7QUFDbkUsT0FBTyxFQUFzQixLQUFLLFdBQVcsRUFBRSxNQUFNLDJCQUEyQixDQUFDO0FBQ2pGLE9BQU8sRUFBRSxLQUFLLGVBQWUsRUFBc0IsTUFBTSx5QkFBeUIsQ0FBQztBQUVuRixPQUFPLEVBQUUseUJBQXlCLEVBQUUsTUFBTSx1Q0FBdUMsQ0FBQztBQUNsRixPQUFPLEVBQUUsdUJBQXVCLEVBQUUsTUFBTSxpQ0FBaUMsQ0FBQztBQUMxRSxPQUFPLEtBQUssRUFBRSxnQkFBZ0IsRUFBRSxNQUFNLGFBQWEsQ0FBQztBQUNwRCxPQUFPLEVBQUUsNEJBQTRCLEVBQUUsTUFBTSxzQ0FBc0MsQ0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AuB,GACvB,sBAAsB,GACtB,wBAAwB,GACxB,uBAAuB,GACvB,sBAAsB,GACtB,yBAAyB,CAC5B,GACC,IAAI,CAAC,eAAe,EAAE,eAAe,GAAG,oBAAoB,GAAG,aAAa,CAAC,EAC/E,OAAO,GAAE,WAAgC,EACzC,eAAe,GAAE,yBAA+E,EAChG,QAAQ,CAAC,EAAE,cAAc,oCAmC1B"}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
+
import { EMPTY_GENESIS_DATA } from '@aztec/stdlib/world-state';
|
|
1
2
|
import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
2
3
|
import { WorldStateInstrumentation } from '../instrumentation/instrumentation.js';
|
|
3
4
|
import { NativeWorldStateService } from '../native/native_world_state.js';
|
|
4
5
|
import { ServerWorldStateSynchronizer } from './server_world_state_synchronizer.js';
|
|
5
|
-
export async function createWorldStateSynchronizer(config, l2BlockSource,
|
|
6
|
+
export async function createWorldStateSynchronizer(config, l2BlockSource, genesis = EMPTY_GENESIS_DATA, client = getTelemetryClient(), bindings) {
|
|
6
7
|
const instrumentation = new WorldStateInstrumentation(client);
|
|
7
|
-
const merkleTrees = await createWorldState(config,
|
|
8
|
+
const merkleTrees = await createWorldState(config, genesis, instrumentation, bindings);
|
|
8
9
|
return new ServerWorldStateSynchronizer(merkleTrees, l2BlockSource, config, instrumentation);
|
|
9
10
|
}
|
|
10
|
-
export async function createWorldState(config,
|
|
11
|
+
export async function createWorldState(config, genesis = EMPTY_GENESIS_DATA, instrumentation = new WorldStateInstrumentation(getTelemetryClient()), bindings) {
|
|
11
12
|
const dataDirectory = config.worldStateDataDirectory ?? config.dataDirectory;
|
|
12
13
|
const dataStoreMapSizeKb = config.worldStateDbMapSizeKb ?? config.dataStoreMapSizeKb;
|
|
13
14
|
const wsTreeMapSizes = {
|
|
@@ -21,9 +22,9 @@ export async function createWorldState(config, prefilledPublicData = [], instrum
|
|
|
21
22
|
throw new Error('Rollup address is required to create a world state synchronizer.');
|
|
22
23
|
}
|
|
23
24
|
// If a data directory is provided in config, then create a persistent store.
|
|
24
|
-
const merkleTrees = dataDirectory ? await NativeWorldStateService.new(config.l1Contracts.rollupAddress, dataDirectory, wsTreeMapSizes,
|
|
25
|
+
const merkleTrees = dataDirectory ? await NativeWorldStateService.new(config.l1Contracts.rollupAddress, dataDirectory, wsTreeMapSizes, genesis, instrumentation, bindings) : await NativeWorldStateService.tmp(config.l1Contracts.rollupAddress, ![
|
|
25
26
|
'true',
|
|
26
27
|
'1'
|
|
27
|
-
].includes(process.env.DEBUG_WORLD_STATE),
|
|
28
|
+
].includes(process.env.DEBUG_WORLD_STATE), genesis, instrumentation, bindings);
|
|
28
29
|
return merkleTrees;
|
|
29
30
|
}
|
package/dest/testing.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
2
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
3
3
|
import { PublicDataTreeLeaf } from '@aztec/stdlib/trees';
|
|
4
|
+
import type { GenesisData } from '@aztec/stdlib/world-state';
|
|
4
5
|
export declare const defaultInitialAccountFeeJuice: Fr;
|
|
5
|
-
export declare function getGenesisValues(initialAccounts: AztecAddress[], initialAccountFeeJuice?: Fr, genesisPublicData?: PublicDataTreeLeaf[]): Promise<{
|
|
6
|
+
export declare function getGenesisValues(initialAccounts: AztecAddress[], initialAccountFeeJuice?: Fr, genesisPublicData?: PublicDataTreeLeaf[], genesisTimestamp?: bigint): Promise<{
|
|
6
7
|
genesisArchiveRoot: Fr;
|
|
7
|
-
|
|
8
|
+
genesis: GenesisData;
|
|
8
9
|
fundingNeeded: bigint;
|
|
9
10
|
}>;
|
|
10
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
11
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdGluZy5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL3Rlc3RpbmcudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQ0EsT0FBTyxFQUFFLEVBQUUsRUFBRSxNQUFNLGdDQUFnQyxDQUFDO0FBRXBELE9BQU8sS0FBSyxFQUFFLFlBQVksRUFBRSxNQUFNLDZCQUE2QixDQUFDO0FBQ2hFLE9BQU8sRUFBZ0Isa0JBQWtCLEVBQUUsTUFBTSxxQkFBcUIsQ0FBQztBQUN2RSxPQUFPLEtBQUssRUFBRSxXQUFXLEVBQUUsTUFBTSwyQkFBMkIsQ0FBQztBQXFCN0QsZUFBTyxNQUFNLDZCQUE2QixJQUFxQixDQUFDO0FBRWhFLHdCQUFzQixnQkFBZ0IsQ0FDcEMsZUFBZSxFQUFFLFlBQVksRUFBRSxFQUMvQixzQkFBc0IsS0FBZ0MsRUFDdEQsaUJBQWlCLEdBQUUsa0JBQWtCLEVBQU8sRUFDNUMsZ0JBQWdCLEdBQUUsTUFBVzs7OztHQXNCOUIifQ==
|
package/dest/testing.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AAEpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAgB,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AAEpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAgB,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACvE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAqB7D,eAAO,MAAM,6BAA6B,IAAqB,CAAC;AAEhE,wBAAsB,gBAAgB,CACpC,eAAe,EAAE,YAAY,EAAE,EAC/B,sBAAsB,KAAgC,EACtD,iBAAiB,GAAE,kBAAkB,EAAO,EAC5C,gBAAgB,GAAE,MAAW;;;;GAsB9B"}
|
package/dest/testing.js
CHANGED
|
@@ -3,14 +3,14 @@ import { Fr } from '@aztec/foundation/curves/bn254';
|
|
|
3
3
|
import { computeFeePayerBalanceLeafSlot } from '@aztec/protocol-contracts/fee-juice';
|
|
4
4
|
import { MerkleTreeId, PublicDataTreeLeaf } from '@aztec/stdlib/trees';
|
|
5
5
|
import { NativeWorldStateService } from './native/index.js';
|
|
6
|
-
async function generateGenesisValues(
|
|
7
|
-
if (!prefilledPublicData.length) {
|
|
6
|
+
async function generateGenesisValues(genesis) {
|
|
7
|
+
if (!genesis.prefilledPublicData.length && genesis.genesisTimestamp === 0n) {
|
|
8
8
|
return {
|
|
9
9
|
genesisArchiveRoot: new Fr(GENESIS_ARCHIVE_ROOT)
|
|
10
10
|
};
|
|
11
11
|
}
|
|
12
12
|
// Create a temporary world state to compute the genesis values.
|
|
13
|
-
const ws = await NativeWorldStateService.tmp(undefined /* rollupAddress */ , true,
|
|
13
|
+
const ws = await NativeWorldStateService.tmp(undefined /* rollupAddress */ , true, genesis);
|
|
14
14
|
const genesisArchiveRoot = new Fr((await ws.getCommitted().getTreeInfo(MerkleTreeId.ARCHIVE)).root);
|
|
15
15
|
await ws.close();
|
|
16
16
|
return {
|
|
@@ -18,16 +18,20 @@ async function generateGenesisValues(prefilledPublicData) {
|
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
20
|
export const defaultInitialAccountFeeJuice = new Fr(10n ** 22n);
|
|
21
|
-
export async function getGenesisValues(initialAccounts, initialAccountFeeJuice = defaultInitialAccountFeeJuice, genesisPublicData = []) {
|
|
21
|
+
export async function getGenesisValues(initialAccounts, initialAccountFeeJuice = defaultInitialAccountFeeJuice, genesisPublicData = [], genesisTimestamp = 0n) {
|
|
22
22
|
// Top up the accounts with fee juice.
|
|
23
23
|
let prefilledPublicData = await Promise.all(initialAccounts.map(async (address)=>new PublicDataTreeLeaf(await computeFeePayerBalanceLeafSlot(address), initialAccountFeeJuice)));
|
|
24
24
|
// Add user-defined public data
|
|
25
25
|
prefilledPublicData = prefilledPublicData.concat(genesisPublicData);
|
|
26
26
|
prefilledPublicData.sort((a, b)=>b.slot.lt(a.slot) ? 1 : -1);
|
|
27
|
-
const
|
|
27
|
+
const genesis = {
|
|
28
|
+
prefilledPublicData,
|
|
29
|
+
genesisTimestamp
|
|
30
|
+
};
|
|
31
|
+
const { genesisArchiveRoot } = await generateGenesisValues(genesis);
|
|
28
32
|
return {
|
|
29
33
|
genesisArchiveRoot,
|
|
30
|
-
|
|
34
|
+
genesis,
|
|
31
35
|
fundingNeeded: BigInt(initialAccounts.length) * initialAccountFeeJuice.toBigInt()
|
|
32
36
|
};
|
|
33
37
|
}
|
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.f650c0a5c",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dest/index.js",
|
|
@@ -64,18 +64,18 @@
|
|
|
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/native": "0.0.1-commit.
|
|
71
|
-
"@aztec/protocol-contracts": "0.0.1-commit.
|
|
72
|
-
"@aztec/stdlib": "0.0.1-commit.
|
|
73
|
-
"@aztec/telemetry-client": "0.0.1-commit.
|
|
67
|
+
"@aztec/constants": "0.0.1-commit.f650c0a5c",
|
|
68
|
+
"@aztec/foundation": "0.0.1-commit.f650c0a5c",
|
|
69
|
+
"@aztec/kv-store": "0.0.1-commit.f650c0a5c",
|
|
70
|
+
"@aztec/native": "0.0.1-commit.f650c0a5c",
|
|
71
|
+
"@aztec/protocol-contracts": "0.0.1-commit.f650c0a5c",
|
|
72
|
+
"@aztec/stdlib": "0.0.1-commit.f650c0a5c",
|
|
73
|
+
"@aztec/telemetry-client": "0.0.1-commit.f650c0a5c",
|
|
74
74
|
"tslib": "^2.4.0",
|
|
75
75
|
"zod": "^3.23.8"
|
|
76
76
|
},
|
|
77
77
|
"devDependencies": {
|
|
78
|
-
"@aztec/archiver": "0.0.1-commit.
|
|
78
|
+
"@aztec/archiver": "0.0.1-commit.f650c0a5c",
|
|
79
79
|
"@jest/globals": "^30.0.0",
|
|
80
80
|
"@types/jest": "^30.0.0",
|
|
81
81
|
"@types/node": "^22.15.17",
|
|
@@ -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';
|
|
@@ -53,6 +53,7 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
|
|
|
53
53
|
protected instance: NativeWorldState,
|
|
54
54
|
protected readonly worldStateInstrumentation: WorldStateInstrumentation,
|
|
55
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,7 +61,7 @@ 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(),
|
|
@@ -73,14 +74,12 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
|
|
|
73
74
|
rollupAddress,
|
|
74
75
|
dataDirectory: worldStateDirectory,
|
|
75
76
|
onOpen: (dir: string) => {
|
|
76
|
-
return Promise.resolve(
|
|
77
|
-
new NativeWorldState(dir, wsTreeMapSizes, prefilledPublicData, instrumentation, bindings),
|
|
78
|
-
);
|
|
77
|
+
return Promise.resolve(new NativeWorldState(dir, wsTreeMapSizes, genesis, instrumentation, bindings));
|
|
79
78
|
},
|
|
80
79
|
});
|
|
81
80
|
|
|
82
81
|
const [instance] = await versionManager.open();
|
|
83
|
-
const worldState = new this(instance, instrumentation, log, cleanup);
|
|
82
|
+
const worldState = new this(instance, instrumentation, log, genesis, cleanup);
|
|
84
83
|
try {
|
|
85
84
|
await worldState.init();
|
|
86
85
|
} catch (e) {
|
|
@@ -94,7 +93,7 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
|
|
|
94
93
|
static async tmp(
|
|
95
94
|
rollupAddress = EthAddress.ZERO,
|
|
96
95
|
cleanupTmpDir = true,
|
|
97
|
-
|
|
96
|
+
genesis: GenesisData = EMPTY_GENESIS_DATA,
|
|
98
97
|
instrumentation = new WorldStateInstrumentation(getTelemetryClient()),
|
|
99
98
|
bindings?: LoggerBindings,
|
|
100
99
|
): Promise<NativeWorldStateService> {
|
|
@@ -120,15 +119,7 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
|
|
|
120
119
|
}
|
|
121
120
|
};
|
|
122
121
|
|
|
123
|
-
return this.new(
|
|
124
|
-
rollupAddress,
|
|
125
|
-
dataDir,
|
|
126
|
-
worldStateTreeMapSizes,
|
|
127
|
-
prefilledPublicData,
|
|
128
|
-
instrumentation,
|
|
129
|
-
bindings,
|
|
130
|
-
cleanup,
|
|
131
|
-
);
|
|
122
|
+
return this.new(rollupAddress, dataDir, worldStateTreeMapSizes, genesis, instrumentation, bindings, cleanup);
|
|
132
123
|
}
|
|
133
124
|
|
|
134
125
|
protected async init() {
|
|
@@ -256,7 +247,10 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
|
|
|
256
247
|
|
|
257
248
|
private async buildInitialHeader(): Promise<BlockHeader> {
|
|
258
249
|
const state = await this.getInitialStateReference();
|
|
259
|
-
return BlockHeader.empty({
|
|
250
|
+
return BlockHeader.empty({
|
|
251
|
+
state,
|
|
252
|
+
globalVariables: GlobalVariables.empty({ timestamp: this.genesis.genesisTimestamp }),
|
|
253
|
+
});
|
|
260
254
|
}
|
|
261
255
|
|
|
262
256
|
private sanitizeAndCacheSummaryFromFull(response: WorldStateStatusFull) {
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
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,7 +55,7 @@ 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
61
|
private readonly log: Logger = createLogger('world-state:database', bindings),
|
|
@@ -66,7 +66,10 @@ export class NativeWorldState implements NativeWorldStateInstance {
|
|
|
66
66
|
wsTreeMapSizes,
|
|
67
67
|
)} and ${threads} threads.`,
|
|
68
68
|
);
|
|
69
|
-
const prefilledPublicDataBufferArray = prefilledPublicData.map(d => [
|
|
69
|
+
const prefilledPublicDataBufferArray = genesis.prefilledPublicData.map(d => [
|
|
70
|
+
d.slot.toBuffer(),
|
|
71
|
+
d.value.toBuffer(),
|
|
72
|
+
]);
|
|
70
73
|
const ws = new BaseNativeWorldState(
|
|
71
74
|
dataDir,
|
|
72
75
|
{
|
|
@@ -82,6 +85,7 @@ export class NativeWorldState implements NativeWorldStateInstance {
|
|
|
82
85
|
},
|
|
83
86
|
prefilledPublicDataBufferArray,
|
|
84
87
|
DomainSeparator.BLOCK_HEADER_HASH,
|
|
88
|
+
Number(genesis.genesisTimestamp),
|
|
85
89
|
{
|
|
86
90
|
[MerkleTreeId.NULLIFIER_TREE]: wsTreeMapSizes.nullifierTreeMapSizeKb,
|
|
87
91
|
[MerkleTreeId.NOTE_HASH_TREE]: wsTreeMapSizes.noteHashTreeMapSizeKb,
|
|
@@ -104,7 +108,7 @@ export class NativeWorldState implements NativeWorldStateInstance {
|
|
|
104
108
|
return new NativeWorldState(
|
|
105
109
|
this.dataDir,
|
|
106
110
|
this.wsTreeMapSizes,
|
|
107
|
-
this.
|
|
111
|
+
this.genesis,
|
|
108
112
|
this.instrumentation,
|
|
109
113
|
this.log.getBindings(),
|
|
110
114
|
this.log,
|
|
@@ -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;
|
|
@@ -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 type
|
|
5
|
+
import { EMPTY_GENESIS_DATA, type GenesisData } 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,12 @@ export interface WorldStateTreeMapSizes {
|
|
|
21
21
|
export async function createWorldStateSynchronizer(
|
|
22
22
|
config: WorldStateConfig & DataStoreConfig,
|
|
23
23
|
l2BlockSource: L2BlockSource & L1ToL2MessageSource,
|
|
24
|
-
|
|
24
|
+
genesis: GenesisData = EMPTY_GENESIS_DATA,
|
|
25
25
|
client: TelemetryClient = getTelemetryClient(),
|
|
26
26
|
bindings?: LoggerBindings,
|
|
27
27
|
) {
|
|
28
28
|
const instrumentation = new WorldStateInstrumentation(client);
|
|
29
|
-
const merkleTrees = await createWorldState(config,
|
|
29
|
+
const merkleTrees = await createWorldState(config, genesis, instrumentation, bindings);
|
|
30
30
|
return new ServerWorldStateSynchronizer(merkleTrees, l2BlockSource, config, instrumentation);
|
|
31
31
|
}
|
|
32
32
|
|
|
@@ -42,7 +42,7 @@ export async function createWorldState(
|
|
|
42
42
|
| 'publicDataTreeMapSizeKb'
|
|
43
43
|
> &
|
|
44
44
|
Pick<DataStoreConfig, 'dataDirectory' | 'dataStoreMapSizeKb' | 'l1Contracts'>,
|
|
45
|
-
|
|
45
|
+
genesis: GenesisData = EMPTY_GENESIS_DATA,
|
|
46
46
|
instrumentation: WorldStateInstrumentation = new WorldStateInstrumentation(getTelemetryClient()),
|
|
47
47
|
bindings?: LoggerBindings,
|
|
48
48
|
) {
|
|
@@ -66,14 +66,14 @@ export async function createWorldState(
|
|
|
66
66
|
config.l1Contracts.rollupAddress,
|
|
67
67
|
dataDirectory,
|
|
68
68
|
wsTreeMapSizes,
|
|
69
|
-
|
|
69
|
+
genesis,
|
|
70
70
|
instrumentation,
|
|
71
71
|
bindings,
|
|
72
72
|
)
|
|
73
73
|
: await NativeWorldStateService.tmp(
|
|
74
74
|
config.l1Contracts.rollupAddress,
|
|
75
75
|
!['true', '1'].includes(process.env.DEBUG_WORLD_STATE!),
|
|
76
|
-
|
|
76
|
+
genesis,
|
|
77
77
|
instrumentation,
|
|
78
78
|
bindings,
|
|
79
79
|
);
|
package/src/testing.ts
CHANGED
|
@@ -3,22 +3,19 @@ import { Fr } from '@aztec/foundation/curves/bn254';
|
|
|
3
3
|
import { computeFeePayerBalanceLeafSlot } from '@aztec/protocol-contracts/fee-juice';
|
|
4
4
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
5
5
|
import { MerkleTreeId, PublicDataTreeLeaf } from '@aztec/stdlib/trees';
|
|
6
|
+
import type { GenesisData } from '@aztec/stdlib/world-state';
|
|
6
7
|
|
|
7
8
|
import { NativeWorldStateService } from './native/index.js';
|
|
8
9
|
|
|
9
|
-
async function generateGenesisValues(
|
|
10
|
-
if (!prefilledPublicData.length) {
|
|
10
|
+
async function generateGenesisValues(genesis: GenesisData) {
|
|
11
|
+
if (!genesis.prefilledPublicData.length && genesis.genesisTimestamp === 0n) {
|
|
11
12
|
return {
|
|
12
13
|
genesisArchiveRoot: new Fr(GENESIS_ARCHIVE_ROOT),
|
|
13
14
|
};
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
// Create a temporary world state to compute the genesis values.
|
|
17
|
-
const ws = await NativeWorldStateService.tmp(
|
|
18
|
-
undefined /* rollupAddress */,
|
|
19
|
-
true /* cleanupTmpDir */,
|
|
20
|
-
prefilledPublicData,
|
|
21
|
-
);
|
|
18
|
+
const ws = await NativeWorldStateService.tmp(undefined /* rollupAddress */, true /* cleanupTmpDir */, genesis);
|
|
22
19
|
const genesisArchiveRoot = new Fr((await ws.getCommitted().getTreeInfo(MerkleTreeId.ARCHIVE)).root);
|
|
23
20
|
await ws.close();
|
|
24
21
|
|
|
@@ -33,6 +30,7 @@ export async function getGenesisValues(
|
|
|
33
30
|
initialAccounts: AztecAddress[],
|
|
34
31
|
initialAccountFeeJuice = defaultInitialAccountFeeJuice,
|
|
35
32
|
genesisPublicData: PublicDataTreeLeaf[] = [],
|
|
33
|
+
genesisTimestamp: bigint = 0n,
|
|
36
34
|
) {
|
|
37
35
|
// Top up the accounts with fee juice.
|
|
38
36
|
let prefilledPublicData = await Promise.all(
|
|
@@ -46,11 +44,12 @@ export async function getGenesisValues(
|
|
|
46
44
|
|
|
47
45
|
prefilledPublicData.sort((a, b) => (b.slot.lt(a.slot) ? 1 : -1));
|
|
48
46
|
|
|
49
|
-
const
|
|
47
|
+
const genesis: GenesisData = { prefilledPublicData, genesisTimestamp };
|
|
48
|
+
const { genesisArchiveRoot } = await generateGenesisValues(genesis);
|
|
50
49
|
|
|
51
50
|
return {
|
|
52
51
|
genesisArchiveRoot,
|
|
53
|
-
|
|
52
|
+
genesis,
|
|
54
53
|
fundingNeeded: BigInt(initialAccounts.length) * initialAccountFeeJuice.toBigInt(),
|
|
55
54
|
};
|
|
56
55
|
}
|