@aztec/world-state 0.0.0-test.1 → 0.0.1-commit.21caa21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/index.d.ts +1 -1
- package/dest/instrumentation/instrumentation.d.ts +6 -4
- package/dest/instrumentation/instrumentation.d.ts.map +1 -1
- package/dest/instrumentation/instrumentation.js +16 -8
- package/dest/native/bench_metrics.d.ts +23 -0
- package/dest/native/bench_metrics.d.ts.map +1 -0
- package/dest/native/bench_metrics.js +81 -0
- package/dest/native/fork_checkpoint.d.ts +1 -1
- package/dest/native/fork_checkpoint.d.ts.map +1 -1
- package/dest/native/index.d.ts +1 -1
- package/dest/native/merkle_trees_facade.d.ts +10 -4
- package/dest/native/merkle_trees_facade.d.ts.map +1 -1
- package/dest/native/merkle_trees_facade.js +39 -7
- package/dest/native/message.d.ts +65 -45
- package/dest/native/message.d.ts.map +1 -1
- package/dest/native/message.js +55 -56
- package/dest/native/native_world_state.d.ts +20 -15
- package/dest/native/native_world_state.d.ts.map +1 -1
- package/dest/native/native_world_state.js +90 -33
- package/dest/native/native_world_state_instance.d.ts +20 -4
- package/dest/native/native_world_state_instance.d.ts.map +1 -1
- package/dest/native/native_world_state_instance.js +42 -3
- package/dest/native/world_state_ops_queue.d.ts +1 -1
- package/dest/native/world_state_ops_queue.d.ts.map +1 -1
- package/dest/native/world_state_ops_queue.js +1 -1
- package/dest/synchronizer/config.d.ts +12 -2
- package/dest/synchronizer/config.d.ts.map +1 -1
- package/dest/synchronizer/config.js +26 -1
- package/dest/synchronizer/errors.d.ts +4 -0
- package/dest/synchronizer/errors.d.ts.map +1 -0
- package/dest/synchronizer/errors.js +5 -0
- package/dest/synchronizer/factory.d.ts +9 -2
- package/dest/synchronizer/factory.d.ts.map +1 -1
- package/dest/synchronizer/factory.js +9 -4
- package/dest/synchronizer/index.d.ts +1 -1
- package/dest/synchronizer/server_world_state_synchronizer.d.ts +14 -18
- package/dest/synchronizer/server_world_state_synchronizer.d.ts.map +1 -1
- package/dest/synchronizer/server_world_state_synchronizer.js +78 -38
- package/dest/test/index.d.ts +1 -1
- package/dest/test/utils.d.ts +2 -2
- package/dest/test/utils.d.ts.map +1 -1
- package/dest/test/utils.js +21 -18
- package/dest/testing.d.ts +2 -2
- package/dest/testing.d.ts.map +1 -1
- package/dest/testing.js +6 -10
- package/dest/world-state-db/index.d.ts +1 -1
- package/dest/world-state-db/merkle_tree_db.d.ts +10 -6
- package/dest/world-state-db/merkle_tree_db.d.ts.map +1 -1
- package/package.json +24 -24
- package/src/instrumentation/instrumentation.ts +22 -10
- package/src/native/bench_metrics.ts +91 -0
- package/src/native/merkle_trees_facade.ts +44 -13
- package/src/native/message.ts +81 -63
- package/src/native/native_world_state.ts +99 -43
- package/src/native/native_world_state_instance.ts +59 -8
- package/src/native/world_state_ops_queue.ts +1 -1
- package/src/synchronizer/config.ts +47 -2
- package/src/synchronizer/errors.ts +5 -0
- package/src/synchronizer/factory.ts +31 -8
- package/src/synchronizer/server_world_state_synchronizer.ts +93 -40
- package/src/test/utils.ts +46 -31
- package/src/testing.ts +3 -7
- package/src/world-state-db/merkle_tree_db.ts +14 -5
|
@@ -10,19 +10,25 @@ const MAX_WORLD_STATE_THREADS = +(process.env.HARDWARE_CONCURRENCY || '16');
|
|
|
10
10
|
/**
|
|
11
11
|
* Strongly-typed interface to access the WorldState class in the native world_state_napi module.
|
|
12
12
|
*/ export class NativeWorldState {
|
|
13
|
+
dataDir;
|
|
14
|
+
wsTreeMapSizes;
|
|
15
|
+
prefilledPublicData;
|
|
13
16
|
instrumentation;
|
|
14
17
|
log;
|
|
15
18
|
open;
|
|
16
19
|
// We maintain a map of queue to fork
|
|
17
20
|
queues;
|
|
18
21
|
instance;
|
|
19
|
-
/** Creates a new native WorldState instance */ constructor(dataDir,
|
|
22
|
+
/** Creates a new native WorldState instance */ constructor(dataDir, wsTreeMapSizes, prefilledPublicData = [], instrumentation, log = createLogger('world-state:database')){
|
|
23
|
+
this.dataDir = dataDir;
|
|
24
|
+
this.wsTreeMapSizes = wsTreeMapSizes;
|
|
25
|
+
this.prefilledPublicData = prefilledPublicData;
|
|
20
26
|
this.instrumentation = instrumentation;
|
|
21
27
|
this.log = log;
|
|
22
28
|
this.open = true;
|
|
23
29
|
this.queues = new Map();
|
|
24
30
|
const threads = Math.min(cpus().length, MAX_WORLD_STATE_THREADS);
|
|
25
|
-
log.info(`Creating world state data store at directory ${dataDir} with map
|
|
31
|
+
log.info(`Creating world state data store at directory ${dataDir} with map sizes ${JSON.stringify(wsTreeMapSizes)} and ${threads} threads.`);
|
|
26
32
|
const prefilledPublicDataBufferArray = prefilledPublicData.map((d)=>[
|
|
27
33
|
d.slot.toBuffer(),
|
|
28
34
|
d.value.toBuffer()
|
|
@@ -36,11 +42,44 @@ const MAX_WORLD_STATE_THREADS = +(process.env.HARDWARE_CONCURRENCY || '16');
|
|
|
36
42
|
}, {
|
|
37
43
|
[MerkleTreeId.NULLIFIER_TREE]: 2 * MAX_NULLIFIERS_PER_TX,
|
|
38
44
|
[MerkleTreeId.PUBLIC_DATA_TREE]: 2 * MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX
|
|
39
|
-
}, prefilledPublicDataBufferArray, GeneratorIndex.BLOCK_HASH,
|
|
45
|
+
}, prefilledPublicDataBufferArray, GeneratorIndex.BLOCK_HASH, {
|
|
46
|
+
[MerkleTreeId.NULLIFIER_TREE]: wsTreeMapSizes.nullifierTreeMapSizeKb,
|
|
47
|
+
[MerkleTreeId.NOTE_HASH_TREE]: wsTreeMapSizes.noteHashTreeMapSizeKb,
|
|
48
|
+
[MerkleTreeId.PUBLIC_DATA_TREE]: wsTreeMapSizes.publicDataTreeMapSizeKb,
|
|
49
|
+
[MerkleTreeId.L1_TO_L2_MESSAGE_TREE]: wsTreeMapSizes.messageTreeMapSizeKb,
|
|
50
|
+
[MerkleTreeId.ARCHIVE]: wsTreeMapSizes.archiveTreeMapSizeKb
|
|
51
|
+
}, threads);
|
|
40
52
|
this.instance = new MsgpackChannel(ws);
|
|
41
53
|
// Manually create the queue for the canonical fork
|
|
42
54
|
this.queues.set(0, new WorldStateOpsQueue());
|
|
43
55
|
}
|
|
56
|
+
getDataDir() {
|
|
57
|
+
return this.dataDir;
|
|
58
|
+
}
|
|
59
|
+
clone() {
|
|
60
|
+
return new NativeWorldState(this.dataDir, this.wsTreeMapSizes, this.prefilledPublicData, this.instrumentation, this.log);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Gets the native WorldState handle from the underlying native instance.
|
|
64
|
+
* We call the getHandle() method on the native WorldState to get a NAPI External
|
|
65
|
+
* that wraps the underlying C++ WorldState pointer.
|
|
66
|
+
* @returns The NAPI External handle to the native WorldState instance,since
|
|
67
|
+
* the NAPI external type is opaque, we return any (we could also use an opaque symbol type)
|
|
68
|
+
*/ getHandle() {
|
|
69
|
+
const worldStateWrapper = this.instance.dest;
|
|
70
|
+
if (!worldStateWrapper) {
|
|
71
|
+
throw new Error('No WorldStateWrapper found');
|
|
72
|
+
}
|
|
73
|
+
if (typeof worldStateWrapper.getHandle !== 'function') {
|
|
74
|
+
throw new Error('WorldStateWrapper does not have getHandle method');
|
|
75
|
+
}
|
|
76
|
+
// Call getHandle() to get the NAPI External
|
|
77
|
+
try {
|
|
78
|
+
return worldStateWrapper.getHandle();
|
|
79
|
+
} catch (error) {
|
|
80
|
+
this.log.error('Failed to get native WorldState handle', error);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
44
83
|
/**
|
|
45
84
|
* Sends a message to the native instance and returns the response.
|
|
46
85
|
* @param messageType - The type of message to send
|
|
@@ -16,4 +16,4 @@ export declare class WorldStateOpsQueue {
|
|
|
16
16
|
private sendEnqueuedRequest;
|
|
17
17
|
stop(): Promise<void>;
|
|
18
18
|
}
|
|
19
|
-
//# sourceMappingURL=
|
|
19
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoid29ybGRfc3RhdG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,CAAC;AAGH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,QAAQ,CAAsB;IACtC,OAAO,CAAC,qBAAqB,CAAK;IAClC,OAAO,CAAC,aAAa,CAAK;IAC1B,OAAO,CAAC,WAAW,CAAC,CAAgB;IACpC,OAAO,CAAC,WAAW,CAAC,CAAa;IACjC,OAAO,CAAC,SAAS,CAAK;IACtB,OAAO,CAAC,GAAG,CAAwC;IAI5C,OAAO,CAAC,OAAO,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC,EAAE,WAAW,EAAE,qBAAqB,EAAE,aAAa,EAAE,OAAO;
|
|
1
|
+
{"version":3,"file":"world_state_ops_queue.d.ts","sourceRoot":"","sources":["../../src/native/world_state_ops_queue.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAyBrD,eAAO,MAAM,kBAAkB,4BAgB7B,CAAC;AAGH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,QAAQ,CAAsB;IACtC,OAAO,CAAC,qBAAqB,CAAK;IAClC,OAAO,CAAC,aAAa,CAAK;IAC1B,OAAO,CAAC,WAAW,CAAC,CAAgB;IACpC,OAAO,CAAC,WAAW,CAAC,CAAa;IACjC,OAAO,CAAC,SAAS,CAAK;IACtB,OAAO,CAAC,GAAG,CAAwC;IAI5C,OAAO,CAAC,OAAO,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC,EAAE,WAAW,EAAE,qBAAqB,EAAE,aAAa,EAAE,OAAO,gBAsBrG;IAGD,OAAO,CAAC,eAAe;IAWvB,OAAO,CAAC,6BAA6B;IAYrC,OAAO,CAAC,2BAA2B;IAUnC,OAAO,CAAC,eAAe;IAyCvB,OAAO,CAAC,mBAAmB;IAgBpB,IAAI,kBAgBV;CACF"}
|
|
@@ -12,7 +12,7 @@ export const MUTATING_MSG_TYPES = new Set([
|
|
|
12
12
|
WorldStateMessageType.SYNC_BLOCK,
|
|
13
13
|
WorldStateMessageType.CREATE_FORK,
|
|
14
14
|
WorldStateMessageType.DELETE_FORK,
|
|
15
|
-
WorldStateMessageType.
|
|
15
|
+
WorldStateMessageType.FINALIZE_BLOCKS,
|
|
16
16
|
WorldStateMessageType.UNWIND_BLOCKS,
|
|
17
17
|
WorldStateMessageType.REMOVE_HISTORICAL_BLOCKS,
|
|
18
18
|
WorldStateMessageType.CREATE_CHECKPOINT,
|
|
@@ -7,8 +7,18 @@ export interface WorldStateConfig {
|
|
|
7
7
|
worldStateProvenBlocksOnly: boolean;
|
|
8
8
|
/** Size of the batch for each get-blocks request from the synchronizer to the archiver. */
|
|
9
9
|
worldStateBlockRequestBatchSize?: number;
|
|
10
|
-
/** The map size to be provided to LMDB for each world state tree DB, optional, will inherit from the general
|
|
10
|
+
/** The map size to be provided to LMDB for each world state tree DB, optional, will inherit from the general dataStoreMapSizeKb if not specified*/
|
|
11
11
|
worldStateDbMapSizeKb?: number;
|
|
12
|
+
/** The map size to be provided to LMDB for each world state archive tree, optional, will inherit from the general worldStateDbMapSizeKb if not specified*/
|
|
13
|
+
archiveTreeMapSizeKb?: number;
|
|
14
|
+
/** The map size to be provided to LMDB for each world state nullifier tree, optional, will inherit from the general worldStateDbMapSizeKb if not specified*/
|
|
15
|
+
nullifierTreeMapSizeKb?: number;
|
|
16
|
+
/** The map size to be provided to LMDB for each world state note hash tree, optional, will inherit from the general worldStateDbMapSizeKb if not specified*/
|
|
17
|
+
noteHashTreeMapSizeKb?: number;
|
|
18
|
+
/** The map size to be provided to LMDB for each world state message tree, optional, will inherit from the general worldStateDbMapSizeKb if not specified*/
|
|
19
|
+
messageTreeMapSizeKb?: number;
|
|
20
|
+
/** The map size to be provided to LMDB for each world state public data tree, optional, will inherit from the general worldStateDbMapSizeKb if not specified*/
|
|
21
|
+
publicDataTreeMapSizeKb?: number;
|
|
12
22
|
/** Optional directory for the world state DB, if unspecified will default to the general data directory */
|
|
13
23
|
worldStateDataDirectory?: string;
|
|
14
24
|
/** The number of historic blocks to maintain */
|
|
@@ -20,4 +30,4 @@ export declare const worldStateConfigMappings: ConfigMappingsType<WorldStateConf
|
|
|
20
30
|
* @returns The configuration values for the world state synchronizer.
|
|
21
31
|
*/
|
|
22
32
|
export declare function getWorldStateConfigFromEnv(): WorldStateConfig;
|
|
23
|
-
//# sourceMappingURL=
|
|
33
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29uZmlnLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvc3luY2hyb25pemVyL2NvbmZpZy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQ0wsS0FBSyxrQkFBa0IsRUFJeEIsTUFBTSwwQkFBMEIsQ0FBQztBQUVsQyxxREFBcUQ7QUFDckQsTUFBTSxXQUFXLGdCQUFnQjtJQUMvQix1Q0FBdUM7SUFDdkMsOEJBQThCLEVBQUUsTUFBTSxDQUFDO0lBRXZDLCtDQUErQztJQUMvQywwQkFBMEIsRUFBRSxPQUFPLENBQUM7SUFFcEMsMkZBQTJGO0lBQzNGLCtCQUErQixDQUFDLEVBQUUsTUFBTSxDQUFDO0lBRXpDLG1KQUFtSjtJQUNuSixxQkFBcUIsQ0FBQyxFQUFFLE1BQU0sQ0FBQztJQUUvQiwySkFBMko7SUFDM0osb0JBQW9CLENBQUMsRUFBRSxNQUFNLENBQUM7SUFFOUIsNkpBQTZKO0lBQzdKLHNCQUFzQixDQUFDLEVBQUUsTUFBTSxDQUFDO0lBRWhDLDZKQUE2SjtJQUM3SixxQkFBcUIsQ0FBQyxFQUFFLE1BQU0sQ0FBQztJQUUvQiwySkFBMko7SUFDM0osb0JBQW9CLENBQUMsRUFBRSxNQUFNLENBQUM7SUFFOUIsK0pBQStKO0lBQy9KLHVCQUF1QixDQUFDLEVBQUUsTUFBTSxDQUFDO0lBRWpDLDJHQUEyRztJQUMzRyx1QkFBdUIsQ0FBQyxFQUFFLE1BQU0sQ0FBQztJQUVqQyxnREFBZ0Q7SUFDaEQsc0JBQXNCLEVBQUUsTUFBTSxDQUFDO0NBQ2hDO0FBRUQsZUFBTyxNQUFNLHdCQUF3QixFQUFFLGtCQUFrQixDQUFDLGdCQUFnQixDQTZEekUsQ0FBQztBQUVGOzs7R0FHRztBQUNILHdCQUFnQiwwQkFBMEIsSUFBSSxnQkFBZ0IsQ0FFN0QifQ==
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/synchronizer/config.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,kBAAkB,EAIxB,MAAM,0BAA0B,CAAC;AAElC,qDAAqD;AACrD,MAAM,WAAW,gBAAgB;IAC/B,uCAAuC;IACvC,8BAA8B,EAAE,MAAM,CAAC;IAEvC,+CAA+C;IAC/C,0BAA0B,EAAE,OAAO,CAAC;IAEpC,2FAA2F;IAC3F,+BAA+B,CAAC,EAAE,MAAM,CAAC;IAEzC,mJAAmJ;IACnJ,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAE/B,2GAA2G;IAC3G,uBAAuB,CAAC,EAAE,MAAM,CAAC;IAEjC,gDAAgD;IAChD,sBAAsB,EAAE,MAAM,CAAC;CAChC;AAED,eAAO,MAAM,wBAAwB,EAAE,kBAAkB,CAAC,gBAAgB,
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/synchronizer/config.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,kBAAkB,EAIxB,MAAM,0BAA0B,CAAC;AAElC,qDAAqD;AACrD,MAAM,WAAW,gBAAgB;IAC/B,uCAAuC;IACvC,8BAA8B,EAAE,MAAM,CAAC;IAEvC,+CAA+C;IAC/C,0BAA0B,EAAE,OAAO,CAAC;IAEpC,2FAA2F;IAC3F,+BAA+B,CAAC,EAAE,MAAM,CAAC;IAEzC,mJAAmJ;IACnJ,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAE/B,2JAA2J;IAC3J,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAE9B,6JAA6J;IAC7J,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAEhC,6JAA6J;IAC7J,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAE/B,2JAA2J;IAC3J,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAE9B,+JAA+J;IAC/J,uBAAuB,CAAC,EAAE,MAAM,CAAC;IAEjC,2GAA2G;IAC3G,uBAAuB,CAAC,EAAE,MAAM,CAAC;IAEjC,gDAAgD;IAChD,sBAAsB,EAAE,MAAM,CAAC;CAChC;AAED,eAAO,MAAM,wBAAwB,EAAE,kBAAkB,CAAC,gBAAgB,CA6DzE,CAAC;AAEF;;;GAGG;AACH,wBAAgB,0BAA0B,IAAI,gBAAgB,CAE7D"}
|
|
@@ -19,7 +19,32 @@ export const worldStateConfigMappings = {
|
|
|
19
19
|
worldStateDbMapSizeKb: {
|
|
20
20
|
env: 'WS_DB_MAP_SIZE_KB',
|
|
21
21
|
parseEnv: (val)=>val ? +val : undefined,
|
|
22
|
-
description: 'The maximum possible size of the world state DB'
|
|
22
|
+
description: 'The maximum possible size of the world state DB in KB. Overwrites the general dataStoreMapSizeKb.'
|
|
23
|
+
},
|
|
24
|
+
archiveTreeMapSizeKb: {
|
|
25
|
+
env: 'ARCHIVE_TREE_MAP_SIZE_KB',
|
|
26
|
+
parseEnv: (val)=>val ? +val : undefined,
|
|
27
|
+
description: 'The maximum possible size of the world state archive tree in KB. Overwrites the general worldStateDbMapSizeKb.'
|
|
28
|
+
},
|
|
29
|
+
nullifierTreeMapSizeKb: {
|
|
30
|
+
env: 'NULLIFIER_TREE_MAP_SIZE_KB',
|
|
31
|
+
parseEnv: (val)=>val ? +val : undefined,
|
|
32
|
+
description: 'The maximum possible size of the world state nullifier tree in KB. Overwrites the general worldStateDbMapSizeKb.'
|
|
33
|
+
},
|
|
34
|
+
noteHashTreeMapSizeKb: {
|
|
35
|
+
env: 'NOTE_HASH_TREE_MAP_SIZE_KB',
|
|
36
|
+
parseEnv: (val)=>val ? +val : undefined,
|
|
37
|
+
description: 'The maximum possible size of the world state note hash tree in KB. Overwrites the general worldStateDbMapSizeKb.'
|
|
38
|
+
},
|
|
39
|
+
messageTreeMapSizeKb: {
|
|
40
|
+
env: 'MESSAGE_TREE_MAP_SIZE_KB',
|
|
41
|
+
parseEnv: (val)=>val ? +val : undefined,
|
|
42
|
+
description: 'The maximum possible size of the world state message tree in KB. Overwrites the general worldStateDbMapSizeKb.'
|
|
43
|
+
},
|
|
44
|
+
publicDataTreeMapSizeKb: {
|
|
45
|
+
env: 'PUBLIC_DATA_TREE_MAP_SIZE_KB',
|
|
46
|
+
parseEnv: (val)=>val ? +val : undefined,
|
|
47
|
+
description: 'The maximum possible size of the world state public data tree in KB. Overwrites the general worldStateDbMapSizeKb.'
|
|
23
48
|
},
|
|
24
49
|
worldStateDataDirectory: {
|
|
25
50
|
env: 'WS_DATA_DIRECTORY',
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare class WorldStateSynchronizerError extends Error {
|
|
2
|
+
constructor(message: string, options?: ErrorOptions);
|
|
3
|
+
}
|
|
4
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZXJyb3JzLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvc3luY2hyb25pemVyL2Vycm9ycy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxxQkFBYSwyQkFBNEIsU0FBUSxLQUFLO0lBQ3BELFlBQVksT0FBTyxFQUFFLE1BQU0sRUFBRSxPQUFPLENBQUMsRUFBRSxZQUFZLEVBRWxEO0NBQ0YifQ==
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/synchronizer/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,2BAA4B,SAAQ,KAAK;IACpD,YAAY,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,EAElD;CACF"}
|
|
@@ -7,6 +7,13 @@ import { WorldStateInstrumentation } from '../instrumentation/instrumentation.js
|
|
|
7
7
|
import { NativeWorldStateService } from '../native/native_world_state.js';
|
|
8
8
|
import type { WorldStateConfig } from './config.js';
|
|
9
9
|
import { ServerWorldStateSynchronizer } from './server_world_state_synchronizer.js';
|
|
10
|
+
export interface WorldStateTreeMapSizes {
|
|
11
|
+
archiveTreeMapSizeKb: number;
|
|
12
|
+
nullifierTreeMapSizeKb: number;
|
|
13
|
+
noteHashTreeMapSizeKb: number;
|
|
14
|
+
messageTreeMapSizeKb: number;
|
|
15
|
+
publicDataTreeMapSizeKb: number;
|
|
16
|
+
}
|
|
10
17
|
export declare function createWorldStateSynchronizer(config: WorldStateConfig & DataStoreConfig, l2BlockSource: L2BlockSource & L1ToL2MessageSource, prefilledPublicData?: PublicDataTreeLeaf[], client?: TelemetryClient): Promise<ServerWorldStateSynchronizer>;
|
|
11
|
-
export declare function createWorldState(config: WorldStateConfig & DataStoreConfig, prefilledPublicData?: PublicDataTreeLeaf[], instrumentation?: WorldStateInstrumentation): Promise<NativeWorldStateService>;
|
|
12
|
-
//# sourceMappingURL=
|
|
18
|
+
export declare function createWorldState(config: Pick<WorldStateConfig, 'worldStateDataDirectory' | 'worldStateDbMapSizeKb' | 'archiveTreeMapSizeKb' | 'nullifierTreeMapSizeKb' | 'noteHashTreeMapSizeKb' | 'messageTreeMapSizeKb' | 'publicDataTreeMapSizeKb'> & Pick<DataStoreConfig, 'dataDirectory' | 'dataStoreMapSizeKb' | 'l1Contracts'>, prefilledPublicData?: PublicDataTreeLeaf[], instrumentation?: WorldStateInstrumentation): Promise<NativeWorldStateService>;
|
|
19
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZmFjdG9yeS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4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,EAC/E,mBAAmB,GAAE,kBAAkB,EAAO,EAC9C,eAAe,GAAE,yBAA+E,oCAgCjG"}
|
|
@@ -8,15 +8,20 @@ export async function createWorldStateSynchronizer(config, l2BlockSource, prefil
|
|
|
8
8
|
return new ServerWorldStateSynchronizer(merkleTrees, l2BlockSource, config, instrumentation);
|
|
9
9
|
}
|
|
10
10
|
export async function createWorldState(config, prefilledPublicData = [], instrumentation = new WorldStateInstrumentation(getTelemetryClient())) {
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
const dataDirectory = config.worldStateDataDirectory ?? config.dataDirectory;
|
|
12
|
+
const dataStoreMapSizeKb = config.worldStateDbMapSizeKb ?? config.dataStoreMapSizeKb;
|
|
13
|
+
const wsTreeMapSizes = {
|
|
14
|
+
archiveTreeMapSizeKb: config.archiveTreeMapSizeKb ?? dataStoreMapSizeKb,
|
|
15
|
+
nullifierTreeMapSizeKb: config.nullifierTreeMapSizeKb ?? dataStoreMapSizeKb,
|
|
16
|
+
noteHashTreeMapSizeKb: config.noteHashTreeMapSizeKb ?? dataStoreMapSizeKb,
|
|
17
|
+
messageTreeMapSizeKb: config.messageTreeMapSizeKb ?? dataStoreMapSizeKb,
|
|
18
|
+
publicDataTreeMapSizeKb: config.publicDataTreeMapSizeKb ?? dataStoreMapSizeKb
|
|
14
19
|
};
|
|
15
20
|
if (!config.l1Contracts?.rollupAddress) {
|
|
16
21
|
throw new Error('Rollup address is required to create a world state synchronizer.');
|
|
17
22
|
}
|
|
18
23
|
// If a data directory is provided in config, then create a persistent store.
|
|
19
|
-
const merkleTrees =
|
|
24
|
+
const merkleTrees = dataDirectory ? await NativeWorldStateService.new(config.l1Contracts.rollupAddress, dataDirectory, wsTreeMapSizes, prefilledPublicData, instrumentation) : await NativeWorldStateService.tmp(config.l1Contracts.rollupAddress, ![
|
|
20
25
|
'true',
|
|
21
26
|
'1'
|
|
22
27
|
].includes(process.env.DEBUG_WORLD_STATE), prefilledPublicData);
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export * from './server_world_state_synchronizer.js';
|
|
2
2
|
export * from './factory.js';
|
|
3
|
-
//# sourceMappingURL=
|
|
3
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9zeW5jaHJvbml6ZXIvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsY0FBYyxzQ0FBc0MsQ0FBQztBQUNyRCxjQUFjLGNBQWMsQ0FBQyJ9
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
3
1
|
import type { Fr } from '@aztec/foundation/fields';
|
|
2
|
+
import { type Logger } from '@aztec/foundation/log';
|
|
4
3
|
import type { L2BlockSource, L2BlockStream, L2BlockStreamEvent, L2BlockStreamEventHandler, L2BlockStreamLocalDataProvider, L2Tips } from '@aztec/stdlib/block';
|
|
5
4
|
import { type WorldStateSynchronizer, type WorldStateSynchronizerStatus } from '@aztec/stdlib/interfaces/server';
|
|
6
5
|
import type { L1ToL2MessageSource } from '@aztec/stdlib/messaging';
|
|
6
|
+
import type { SnapshotDataKeys } from '@aztec/stdlib/snapshots';
|
|
7
7
|
import { type MerkleTreeReadOperations, type MerkleTreeWriteOperations } from '@aztec/stdlib/trees';
|
|
8
8
|
import { WorldStateInstrumentation } from '../instrumentation/instrumentation.js';
|
|
9
9
|
import type { MerkleTreeAdminDatabase } from '../world-state-db/merkle_tree_db.js';
|
|
10
10
|
import type { WorldStateConfig } from './config.js';
|
|
11
|
+
export type { SnapshotDataKeys };
|
|
11
12
|
/**
|
|
12
13
|
* Synchronizes the world state with the L2 blocks from a L2BlockSource via a block stream.
|
|
13
14
|
* The synchronizer will download the L2 blocks from the L2BlockSource and update the merkle trees.
|
|
@@ -26,39 +27,34 @@ export declare class ServerWorldStateSynchronizer implements WorldStateSynchroni
|
|
|
26
27
|
private latestBlockHashQuery;
|
|
27
28
|
private syncPromise;
|
|
28
29
|
protected blockStream: L2BlockStream | undefined;
|
|
29
|
-
|
|
30
|
+
private provenBlockNumber;
|
|
31
|
+
constructor(merkleTreeDb: MerkleTreeAdminDatabase, l2BlockSource: L2BlockSource & L1ToL2MessageSource, config: WorldStateConfig, instrumentation?: WorldStateInstrumentation, log?: Logger);
|
|
30
32
|
getCommitted(): MerkleTreeReadOperations;
|
|
31
33
|
getSnapshot(blockNumber: number): MerkleTreeReadOperations;
|
|
32
34
|
fork(blockNumber?: number): Promise<MerkleTreeWriteOperations>;
|
|
35
|
+
backupTo(dstPath: string, compact?: boolean): Promise<Record<Exclude<SnapshotDataKeys, 'archiver'>, string>>;
|
|
36
|
+
clear(): Promise<void>;
|
|
33
37
|
start(): Promise<void | import("@aztec/foundation/promise").PromiseWithResolvers<void>>;
|
|
34
38
|
protected createBlockStream(): L2BlockStream;
|
|
35
39
|
stop(): Promise<void>;
|
|
36
40
|
status(): Promise<WorldStateSynchronizerStatus>;
|
|
37
41
|
getLatestBlockNumber(): Promise<number>;
|
|
42
|
+
stopSync(): Promise<void>;
|
|
43
|
+
resumeSync(): void;
|
|
38
44
|
/**
|
|
39
45
|
* Forces an immediate sync.
|
|
40
|
-
* @param targetBlockNumber - The target block number that we must sync to. Will download unproven blocks if needed to reach it.
|
|
46
|
+
* @param targetBlockNumber - The target block number that we must sync to. Will download unproven blocks if needed to reach it.
|
|
47
|
+
* @param skipThrowIfTargetNotReached - Whether to skip throwing if the target block number is not reached.
|
|
41
48
|
* @returns A promise that resolves with the block number the world state was synced to
|
|
42
49
|
*/
|
|
43
|
-
syncImmediate(targetBlockNumber?: number): Promise<number>;
|
|
50
|
+
syncImmediate(targetBlockNumber?: number, skipThrowIfTargetNotReached?: boolean): Promise<number>;
|
|
44
51
|
/** Returns the L2 block hash for a given number. Used by the L2BlockStream for detecting reorgs. */
|
|
45
52
|
getL2BlockHash(number: number): Promise<string | undefined>;
|
|
46
53
|
/** Returns the latest L2 block number for each tip of the chain (latest, proven, finalized). */
|
|
47
54
|
getL2Tips(): Promise<L2Tips>;
|
|
48
55
|
/** Handles an event emitted by the block stream. */
|
|
49
56
|
handleBlockStreamEvent(event: L2BlockStreamEvent): Promise<void>;
|
|
50
|
-
/**
|
|
51
|
-
* Handles a list of L2 blocks (i.e. Inserts the new note hashes into the merkle tree).
|
|
52
|
-
* @param l2Blocks - The L2 blocks to handle.
|
|
53
|
-
* @returns Whether the block handled was produced by this same node.
|
|
54
|
-
*/
|
|
55
57
|
private handleL2Blocks;
|
|
56
|
-
/**
|
|
57
|
-
* Handles a single L2 block (i.e. Inserts the new note hashes into the merkle tree).
|
|
58
|
-
* @param l2Block - The L2 block to handle.
|
|
59
|
-
* @param l1ToL2Messages - The L1 to L2 messages for the block.
|
|
60
|
-
* @returns Whether the block handled was produced by this same node.
|
|
61
|
-
*/
|
|
62
58
|
private handleL2Block;
|
|
63
59
|
private handleChainFinalized;
|
|
64
60
|
private handleChainProven;
|
|
@@ -74,6 +70,6 @@ export declare class ServerWorldStateSynchronizer implements WorldStateSynchroni
|
|
|
74
70
|
* @param inHash - The inHash of the block.
|
|
75
71
|
* @throws If the L1 to L2 messages do not hash to the block inHash.
|
|
76
72
|
*/
|
|
77
|
-
protected verifyMessagesHashToInHash(l1ToL2Messages: Fr[], inHash:
|
|
73
|
+
protected verifyMessagesHashToInHash(l1ToL2Messages: Fr[], inHash: Fr): Promise<void>;
|
|
78
74
|
}
|
|
79
|
-
//# sourceMappingURL=
|
|
75
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2VydmVyX3dvcmxkX3N0YXRlX3N5bmNocm9uaXplci5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3N5bmNocm9uaXplci9zZXJ2ZXJfd29ybG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UksQ0FBQyxDQUU1QjtJQUVZLEtBQUssbUZBOEJqQjtJQUVELFNBQVMsQ0FBQyxpQkFBaUIsSUFBSSxhQUFhLENBUTNDO0lBRVksSUFBSSxrQkFPaEI7SUFFWSxNQUFNLElBQUksT0FBTyxDQUFDLDRCQUE0QixDQUFDLENBYTNEO0lBRVksb0JBQW9CLG9CQUVoQztJQUVZLFFBQVEsa0JBSXBCO0lBRU0sVUFBVSxTQU9oQjtJQUVEOzs7OztPQUtHO0lBQ1UsYUFBYSxDQUFDLGlCQUFpQixDQUFDLEVBQUUsTUFBTSxFQUFFLDJCQUEyQixDQUFDLEVBQUUsT0FBTyxHQUFHLE9BQU8sQ0FBQyxNQUFNLENBQUMsQ0E2QzdHO0lBRUQsb0dBQW9HO0lBQ3ZGLGNBQWMsQ0FBQyxNQUFNLEVBQUUsTUFBTSxHQUFHLE9BQU8sQ0FBQyxNQUFNLEdBQUcsU0FBUyxDQUFDLENBYXZFO0lBRUQsZ0dBQWdHO0lBQ25GLFNBQVMsSUFBSSxPQUFPLENBQUMsTUFBTSxDQUFDLENBVXhDO0lBRUQsb0RBQW9EO0lBQ3ZDLHNCQUFzQixDQUFDLEtBQUssRUFBRSxrQkFBa0IsR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLENBZTVFO1lBT2EsY0FBYztZQStCZCxhQUFhO1lBdUJiLG9CQUFvQjtJQWVsQyxPQUFPLENBQUMsaUJBQWlCO1lBTVgsaUJBQWlCO0lBUS9COzs7T0FHRztJQUNILE9BQU8sQ0FBQyxlQUFlO0lBS3ZCOzs7OztPQUtHO0lBQ0gsVUFBZ0IsMEJBQTBCLENBQUMsY0FBYyxFQUFFLEVBQUUsRUFBRSxFQUFFLE1BQU0sRUFBRSxFQUFFLGlCQVkxRTtDQUNGIn0=
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server_world_state_synchronizer.d.ts","sourceRoot":"","sources":["../../src/synchronizer/server_world_state_synchronizer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"server_world_state_synchronizer.d.ts","sourceRoot":"","sources":["../../src/synchronizer/server_world_state_synchronizer.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AACnD,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,uBAAuB,CAAC;AAIlE,OAAO,KAAK,EAGV,aAAa,EACb,aAAa,EACb,kBAAkB,EAClB,yBAAyB,EACzB,8BAA8B,EAC9B,MAAM,EACP,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAGL,KAAK,sBAAsB,EAC3B,KAAK,4BAA4B,EAClC,MAAM,iCAAiC,CAAC;AACzC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AACnE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAEhE,OAAO,EAAgB,KAAK,wBAAwB,EAAE,KAAK,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAGlH,OAAO,EAAE,yBAAyB,EAAE,MAAM,uCAAuC,CAAC;AAElF,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AACnF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAGpD,YAAY,EAAE,gBAAgB,EAAE,CAAC;AAEjC;;;;GAIG;AACH,qBAAa,4BACX,YAAW,sBAAsB,EAAE,8BAA8B,EAAE,yBAAyB;IAiB1F,OAAO,CAAC,QAAQ,CAAC,YAAY;IAC7B,OAAO,CAAC,QAAQ,CAAC,aAAa;IAC9B,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,eAAe;IACvB,OAAO,CAAC,QAAQ,CAAC,GAAG;IAnBtB,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAA2B;IAE/D,OAAO,CAAC,wBAAwB,CAAK;IACrC,OAAO,CAAC,aAAa,CAAqB;IAC1C,OAAO,CAAC,YAAY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KAAK,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,CAe5E;YAOa,cAAc;YA+Bd,aAAa;YAuBb,oBAAoB;IAelC,OAAO,CAAC,iBAAiB;YAMX,iBAAiB;IAQ/B;;;OAGG;IACH,OAAO,CAAC,eAAe;IAKvB;;;;;OAKG;IACH,UAAgB,0BAA0B,CAAC,cAAc,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,iBAY1E;CACF"}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { L1_TO_L2_MSG_SUBTREE_HEIGHT } from '@aztec/constants';
|
|
2
|
+
import { SHA256Trunc } from '@aztec/foundation/crypto';
|
|
2
3
|
import { createLogger } from '@aztec/foundation/log';
|
|
3
4
|
import { promiseWithResolvers } from '@aztec/foundation/promise';
|
|
4
5
|
import { elapsed } from '@aztec/foundation/timer';
|
|
5
6
|
import { MerkleTreeCalculator } from '@aztec/foundation/trees';
|
|
6
|
-
import { SHA256Trunc } from '@aztec/merkle-tree';
|
|
7
7
|
import { WorldStateRunningState } from '@aztec/stdlib/interfaces/server';
|
|
8
8
|
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
9
9
|
import { TraceableL2BlockStream, getTelemetryClient } from '@aztec/telemetry-client';
|
|
10
10
|
import { WorldStateInstrumentation } from '../instrumentation/instrumentation.js';
|
|
11
|
+
import { WorldStateSynchronizerError } from './errors.js';
|
|
11
12
|
/**
|
|
12
13
|
* Synchronizes the world state with the L2 blocks from a L2BlockSource via a block stream.
|
|
13
14
|
* The synchronizer will download the L2 blocks from the L2BlockSource and update the merkle trees.
|
|
@@ -25,6 +26,9 @@ import { WorldStateInstrumentation } from '../instrumentation/instrumentation.js
|
|
|
25
26
|
latestBlockHashQuery;
|
|
26
27
|
syncPromise;
|
|
27
28
|
blockStream;
|
|
29
|
+
// WorldState doesn't track the proven block number, it only tracks the latest tips of the pending chain and the finalized chain
|
|
30
|
+
// store the proven block number here, in the synchronizer, so that we don't end up spamming the logs with 'chain-proved' events
|
|
31
|
+
provenBlockNumber;
|
|
28
32
|
constructor(merkleTreeDb, l2BlockSource, config, instrumentation = new WorldStateInstrumentation(getTelemetryClient()), log = createLogger('world_state')){
|
|
29
33
|
this.merkleTreeDb = merkleTreeDb;
|
|
30
34
|
this.l2BlockSource = l2BlockSource;
|
|
@@ -48,6 +52,12 @@ import { WorldStateInstrumentation } from '../instrumentation/instrumentation.js
|
|
|
48
52
|
fork(blockNumber) {
|
|
49
53
|
return this.merkleTreeDb.fork(blockNumber);
|
|
50
54
|
}
|
|
55
|
+
backupTo(dstPath, compact) {
|
|
56
|
+
return this.merkleTreeDb.backupTo(dstPath, compact);
|
|
57
|
+
}
|
|
58
|
+
clear() {
|
|
59
|
+
return this.merkleTreeDb.clear();
|
|
60
|
+
}
|
|
51
61
|
async start() {
|
|
52
62
|
if (this.currentState === WorldStateRunningState.STOPPED) {
|
|
53
63
|
throw new Error('Synchronizer already stopped');
|
|
@@ -93,9 +103,9 @@ import { WorldStateInstrumentation } from '../instrumentation/instrumentation.js
|
|
|
93
103
|
async status() {
|
|
94
104
|
const summary = await this.merkleTreeDb.getStatusSummary();
|
|
95
105
|
const status = {
|
|
96
|
-
latestBlockNumber: Number(summary.
|
|
97
|
-
latestBlockHash: await this.getL2BlockHash(Number(summary.
|
|
98
|
-
|
|
106
|
+
latestBlockNumber: Number(summary.unfinalizedBlockNumber),
|
|
107
|
+
latestBlockHash: await this.getL2BlockHash(Number(summary.unfinalizedBlockNumber)) ?? '',
|
|
108
|
+
finalizedBlockNumber: Number(summary.finalizedBlockNumber),
|
|
99
109
|
oldestHistoricBlockNumber: Number(summary.oldestHistoricalBlock),
|
|
100
110
|
treesAreSynched: summary.treesAreSynched
|
|
101
111
|
};
|
|
@@ -107,26 +117,58 @@ import { WorldStateInstrumentation } from '../instrumentation/instrumentation.js
|
|
|
107
117
|
async getLatestBlockNumber() {
|
|
108
118
|
return (await this.getL2Tips()).latest.number;
|
|
109
119
|
}
|
|
120
|
+
async stopSync() {
|
|
121
|
+
this.log.debug('Stopping sync...');
|
|
122
|
+
await this.blockStream?.stop();
|
|
123
|
+
this.log.info('Stopped sync');
|
|
124
|
+
}
|
|
125
|
+
resumeSync() {
|
|
126
|
+
if (!this.blockStream) {
|
|
127
|
+
throw new Error('Cannot resume sync as block stream is not initialized');
|
|
128
|
+
}
|
|
129
|
+
this.log.debug('Resuming sync...');
|
|
130
|
+
this.blockStream.start();
|
|
131
|
+
this.log.info('Resumed sync');
|
|
132
|
+
}
|
|
110
133
|
/**
|
|
111
134
|
* Forces an immediate sync.
|
|
112
|
-
* @param targetBlockNumber - The target block number that we must sync to. Will download unproven blocks if needed to reach it.
|
|
135
|
+
* @param targetBlockNumber - The target block number that we must sync to. Will download unproven blocks if needed to reach it.
|
|
136
|
+
* @param skipThrowIfTargetNotReached - Whether to skip throwing if the target block number is not reached.
|
|
113
137
|
* @returns A promise that resolves with the block number the world state was synced to
|
|
114
|
-
*/ async syncImmediate(targetBlockNumber) {
|
|
115
|
-
if (this.currentState !== WorldStateRunningState.RUNNING
|
|
138
|
+
*/ async syncImmediate(targetBlockNumber, skipThrowIfTargetNotReached) {
|
|
139
|
+
if (this.currentState !== WorldStateRunningState.RUNNING) {
|
|
116
140
|
throw new Error(`World State is not running. Unable to perform sync.`);
|
|
117
141
|
}
|
|
142
|
+
if (this.blockStream === undefined) {
|
|
143
|
+
throw new Error('Block stream is not initialized. Unable to perform sync.');
|
|
144
|
+
}
|
|
118
145
|
// If we have been given a block number to sync to and we have reached that number then return
|
|
119
146
|
const currentBlockNumber = await this.getLatestBlockNumber();
|
|
120
147
|
if (targetBlockNumber !== undefined && targetBlockNumber <= currentBlockNumber) {
|
|
121
148
|
return currentBlockNumber;
|
|
122
149
|
}
|
|
123
150
|
this.log.debug(`World State at ${currentBlockNumber} told to sync to ${targetBlockNumber ?? 'latest'}`);
|
|
151
|
+
// If the archiver is behind the target block, force an archiver sync
|
|
152
|
+
if (targetBlockNumber) {
|
|
153
|
+
const archiverLatestBlock = await this.l2BlockSource.getBlockNumber();
|
|
154
|
+
if (archiverLatestBlock < targetBlockNumber) {
|
|
155
|
+
this.log.debug(`Archiver is at ${archiverLatestBlock} behind target block ${targetBlockNumber}.`);
|
|
156
|
+
await this.l2BlockSource.syncImmediate();
|
|
157
|
+
}
|
|
158
|
+
}
|
|
124
159
|
// Force the block stream to sync against the archiver now
|
|
125
160
|
await this.blockStream.sync();
|
|
126
161
|
// If we have been given a block number to sync to and we have not reached that number then fail
|
|
127
162
|
const updatedBlockNumber = await this.getLatestBlockNumber();
|
|
128
|
-
if (targetBlockNumber !== undefined && targetBlockNumber > updatedBlockNumber) {
|
|
129
|
-
throw new
|
|
163
|
+
if (!skipThrowIfTargetNotReached && targetBlockNumber !== undefined && targetBlockNumber > updatedBlockNumber) {
|
|
164
|
+
throw new WorldStateSynchronizerError(`Unable to sync to block number ${targetBlockNumber} (last synced is ${updatedBlockNumber})`, {
|
|
165
|
+
cause: {
|
|
166
|
+
reason: 'block_not_available',
|
|
167
|
+
previousBlockNumber: currentBlockNumber,
|
|
168
|
+
updatedBlockNumber,
|
|
169
|
+
targetBlockNumber
|
|
170
|
+
}
|
|
171
|
+
});
|
|
130
172
|
}
|
|
131
173
|
return updatedBlockNumber;
|
|
132
174
|
}
|
|
@@ -144,41 +186,37 @@ import { WorldStateInstrumentation } from '../instrumentation/instrumentation.js
|
|
|
144
186
|
}
|
|
145
187
|
/** Returns the latest L2 block number for each tip of the chain (latest, proven, finalized). */ async getL2Tips() {
|
|
146
188
|
const status = await this.merkleTreeDb.getStatusSummary();
|
|
147
|
-
const
|
|
189
|
+
const unfinalizedBlockHash = await this.getL2BlockHash(Number(status.unfinalizedBlockNumber));
|
|
148
190
|
const latestBlockId = {
|
|
149
|
-
number: Number(status.
|
|
150
|
-
hash:
|
|
191
|
+
number: Number(status.unfinalizedBlockNumber),
|
|
192
|
+
hash: unfinalizedBlockHash
|
|
151
193
|
};
|
|
152
194
|
return {
|
|
153
195
|
latest: latestBlockId,
|
|
154
196
|
finalized: {
|
|
155
|
-
number: Number(status.
|
|
197
|
+
number: Number(status.finalizedBlockNumber),
|
|
156
198
|
hash: ''
|
|
157
199
|
},
|
|
158
200
|
proven: {
|
|
159
|
-
number: Number(status.
|
|
201
|
+
number: Number(this.provenBlockNumber ?? status.finalizedBlockNumber),
|
|
160
202
|
hash: ''
|
|
161
203
|
}
|
|
162
204
|
};
|
|
163
205
|
}
|
|
164
206
|
/** Handles an event emitted by the block stream. */ async handleBlockStreamEvent(event) {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
break;
|
|
179
|
-
}
|
|
180
|
-
} catch (err) {
|
|
181
|
-
this.log.error('Error processing block stream', err);
|
|
207
|
+
switch(event.type){
|
|
208
|
+
case 'blocks-added':
|
|
209
|
+
await this.handleL2Blocks(event.blocks.map((b)=>b.block));
|
|
210
|
+
break;
|
|
211
|
+
case 'chain-pruned':
|
|
212
|
+
await this.handleChainPruned(event.block.number);
|
|
213
|
+
break;
|
|
214
|
+
case 'chain-proven':
|
|
215
|
+
await this.handleChainProven(event.block.number);
|
|
216
|
+
break;
|
|
217
|
+
case 'chain-finalized':
|
|
218
|
+
await this.handleChainFinalized(event.block.number);
|
|
219
|
+
break;
|
|
182
220
|
}
|
|
183
221
|
}
|
|
184
222
|
/**
|
|
@@ -187,16 +225,16 @@ import { WorldStateInstrumentation } from '../instrumentation/instrumentation.js
|
|
|
187
225
|
* @returns Whether the block handled was produced by this same node.
|
|
188
226
|
*/ async handleL2Blocks(l2Blocks) {
|
|
189
227
|
this.log.trace(`Handling L2 blocks ${l2Blocks[0].number} to ${l2Blocks.at(-1).number}`);
|
|
190
|
-
const messagePromises = l2Blocks.map((block)=>this.l2BlockSource.getL1ToL2Messages(
|
|
228
|
+
const messagePromises = l2Blocks.map((block)=>this.l2BlockSource.getL1ToL2Messages(block.number));
|
|
191
229
|
const l1ToL2Messages = await Promise.all(messagePromises);
|
|
192
230
|
let updateStatus = undefined;
|
|
193
231
|
for(let i = 0; i < l2Blocks.length; i++){
|
|
194
232
|
const [duration, result] = await elapsed(()=>this.handleL2Block(l2Blocks[i], l1ToL2Messages[i]));
|
|
195
|
-
this.log.
|
|
233
|
+
this.log.info(`World state updated with L2 block ${l2Blocks[i].number}`, {
|
|
196
234
|
eventName: 'l2-block-handled',
|
|
197
235
|
duration,
|
|
198
|
-
|
|
199
|
-
|
|
236
|
+
unfinalizedBlockNumber: result.summary.unfinalizedBlockNumber,
|
|
237
|
+
finalizedBlockNumber: result.summary.finalizedBlockNumber,
|
|
200
238
|
oldestHistoricBlock: result.summary.oldestHistoricalBlock,
|
|
201
239
|
...l2Blocks[i].getStats()
|
|
202
240
|
});
|
|
@@ -233,11 +271,11 @@ import { WorldStateInstrumentation } from '../instrumentation/instrumentation.js
|
|
|
233
271
|
}
|
|
234
272
|
async handleChainFinalized(blockNumber) {
|
|
235
273
|
this.log.verbose(`Finalized chain is now at block ${blockNumber}`);
|
|
236
|
-
const summary = await this.merkleTreeDb.
|
|
274
|
+
const summary = await this.merkleTreeDb.setFinalized(BigInt(blockNumber));
|
|
237
275
|
if (this.historyToKeep === undefined) {
|
|
238
276
|
return;
|
|
239
277
|
}
|
|
240
|
-
const newHistoricBlock = summary.
|
|
278
|
+
const newHistoricBlock = summary.finalizedBlockNumber - BigInt(this.historyToKeep) + 1n;
|
|
241
279
|
if (newHistoricBlock <= 1) {
|
|
242
280
|
return;
|
|
243
281
|
}
|
|
@@ -246,6 +284,7 @@ import { WorldStateInstrumentation } from '../instrumentation/instrumentation.js
|
|
|
246
284
|
this.log.debug(`World state summary `, status.summary);
|
|
247
285
|
}
|
|
248
286
|
handleChainProven(blockNumber) {
|
|
287
|
+
this.provenBlockNumber = BigInt(blockNumber);
|
|
249
288
|
this.log.debug(`Proven chain is now at block ${blockNumber}`);
|
|
250
289
|
return Promise.resolve();
|
|
251
290
|
}
|
|
@@ -253,6 +292,7 @@ import { WorldStateInstrumentation } from '../instrumentation/instrumentation.js
|
|
|
253
292
|
this.log.warn(`Chain pruned to block ${blockNumber}`);
|
|
254
293
|
const status = await this.merkleTreeDb.unwindBlocks(BigInt(blockNumber));
|
|
255
294
|
this.latestBlockHashQuery = undefined;
|
|
295
|
+
this.provenBlockNumber = undefined;
|
|
256
296
|
this.instrumentation.updateWorldStateMetrics(status);
|
|
257
297
|
}
|
|
258
298
|
/**
|
|
@@ -270,7 +310,7 @@ import { WorldStateInstrumentation } from '../instrumentation/instrumentation.js
|
|
|
270
310
|
*/ async verifyMessagesHashToInHash(l1ToL2Messages, inHash) {
|
|
271
311
|
const treeCalculator = await MerkleTreeCalculator.create(L1_TO_L2_MSG_SUBTREE_HEIGHT, Buffer.alloc(32), (lhs, rhs)=>Promise.resolve(new SHA256Trunc().hash(lhs, rhs)));
|
|
272
312
|
const root = await treeCalculator.computeTreeRoot(l1ToL2Messages.map((msg)=>msg.toBuffer()));
|
|
273
|
-
if (!root.equals(inHash)) {
|
|
313
|
+
if (!root.equals(inHash.toBuffer())) {
|
|
274
314
|
throw new Error('Obtained L1 to L2 messages failed to be hashed to the block inHash');
|
|
275
315
|
}
|
|
276
316
|
}
|
package/dest/test/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from './utils.js';
|
|
2
|
-
//# sourceMappingURL=
|
|
2
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy90ZXN0L2luZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLGNBQWMsWUFBWSxDQUFDIn0=
|
package/dest/test/utils.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Fr } from '@aztec/foundation/fields';
|
|
|
2
2
|
import { L2Block } from '@aztec/stdlib/block';
|
|
3
3
|
import type { MerkleTreeReadOperations, MerkleTreeWriteOperations } from '@aztec/stdlib/interfaces/server';
|
|
4
4
|
import type { NativeWorldStateService } from '../native/native_world_state.js';
|
|
5
|
-
export declare function mockBlock(blockNum: number, size: number, fork: MerkleTreeWriteOperations): Promise<{
|
|
5
|
+
export declare function mockBlock(blockNum: number, size: number, fork: MerkleTreeWriteOperations, maxEffects?: number | undefined): Promise<{
|
|
6
6
|
block: L2Block;
|
|
7
7
|
messages: Fr[];
|
|
8
8
|
}>;
|
|
@@ -16,4 +16,4 @@ export declare function mockBlocks(from: number, count: number, numTxs: number,
|
|
|
16
16
|
}>;
|
|
17
17
|
export declare function assertSameState(forkA: MerkleTreeReadOperations, forkB: MerkleTreeReadOperations): Promise<void>;
|
|
18
18
|
export declare function compareChains(left: MerkleTreeReadOperations, right: MerkleTreeReadOperations): Promise<void>;
|
|
19
|
-
//# sourceMappingURL=
|
|
19
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXRpbHMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy90ZXN0L3V0aWxzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQU9BLE9BQU8sRUFBRSxFQUFFLEVBQUUsTUFBTSwwQkFBMEIsQ0FBQztBQUM5QyxPQUFPLEVBQUUsT0FBTyxFQUFFLE1BQU0scUJBQXFCLENBQUM7QUFDOUMsT0FBTyxLQUFLLEVBRVYsd0JBQXdCLEVBQ3hCLHlCQUF5QixFQUMxQixNQUFNLGlDQUFpQyxDQUFDO0FBR3pDLE9BQU8sS0FBSyxFQUFFLHVCQUF1QixFQUFFLE1BQU0saUNBQWlDLENBQUM7QUFFL0Usd0JBQXNCLFNBQVMsQ0FDN0IsUUFBUSxFQUFFLE1BQU0sRUFDaEIsSUFBSSxFQUFFLE1BQU0sRUFDWixJQUFJLEVBQUUseUJBQXlCLEVBQy9CLFVBQVUsR0FBRSxNQUFNLEdBQUcsU0FBZ0I7OztHQXNEdEM7QUFFRCx3QkFBc0IsY0FBYyxDQUFDLFFBQVEsRUFBRSxNQUFNLEVBQUUsSUFBSSxFQUFFLHlCQUF5Qjs7O0dBaURyRjtBQUVELHdCQUFzQixVQUFVLENBQUMsSUFBSSxFQUFFLE1BQU0sRUFBRSxLQUFLLEVBQUUsTUFBTSxFQUFFLE1BQU0sRUFBRSxNQUFNLEVBQUUsVUFBVSxFQUFFLHVCQUF1Qjs7O0dBY2hIO0FBRUQsd0JBQXNCLGVBQWUsQ0FBQyxLQUFLLEVBQUUsd0JBQXdCLEVBQUUsS0FBSyxFQUFFLHdCQUF3QixpQkFRckc7QUFFRCx3QkFBc0IsYUFBYSxDQUFDLElBQUksRUFBRSx3QkFBd0IsRUFBRSxLQUFLLEVBQUUsd0JBQXdCLGlCQVlsRyJ9
|
package/dest/test/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/test/utils.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/test/utils.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,KAAK,EAEV,wBAAwB,EACxB,yBAAyB,EAC1B,MAAM,iCAAiC,CAAC;AAGzC,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAE/E,wBAAsB,SAAS,CAC7B,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,yBAAyB,EAC/B,UAAU,GAAE,MAAM,GAAG,SAAgB;;;GAsDtC;AAED,wBAAsB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,yBAAyB;;;GAiDrF;AAED,wBAAsB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,uBAAuB;;;GAchH;AAED,wBAAsB,eAAe,CAAC,KAAK,EAAE,wBAAwB,EAAE,KAAK,EAAE,wBAAwB,iBAQrG;AAED,wBAAsB,aAAa,CAAC,IAAI,EAAE,wBAAwB,EAAE,KAAK,EAAE,wBAAwB,iBAYlG"}
|