@aztec/world-state 0.0.0-test.0 → 0.0.1-commit.24de95ac
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 +5 -3
- 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/merkle_trees_facade.d.ts +9 -3
- package/dest/native/merkle_trees_facade.d.ts.map +1 -1
- package/dest/native/merkle_trees_facade.js +38 -7
- package/dest/native/message.d.ts +64 -44
- package/dest/native/message.d.ts.map +1 -1
- package/dest/native/message.js +55 -56
- package/dest/native/native_world_state.d.ts +18 -13
- 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 +10 -3
- package/dest/native/native_world_state_instance.d.ts.map +1 -1
- package/dest/native/native_world_state_instance.js +21 -3
- package/dest/native/world_state_ops_queue.js +1 -1
- package/dest/synchronizer/config.d.ts +11 -1
- 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 +8 -1
- package/dest/synchronizer/factory.d.ts.map +1 -1
- package/dest/synchronizer/factory.js +9 -4
- package/dest/synchronizer/server_world_state_synchronizer.d.ts +13 -6
- 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/utils.d.ts +1 -1
- package/dest/test/utils.d.ts.map +1 -1
- package/dest/test/utils.js +21 -18
- package/dest/testing.d.ts +1 -1
- package/dest/testing.d.ts.map +1 -1
- package/dest/testing.js +6 -10
- package/dest/world-state-db/merkle_tree_db.d.ts +8 -4
- package/dest/world-state-db/merkle_tree_db.d.ts.map +1 -1
- package/package.json +21 -22
- 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 +98 -42
- package/src/native/native_world_state_instance.ts +31 -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 +9 -4
|
@@ -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 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/synchronizer/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,2BAA4B,SAAQ,KAAK;gBACxC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAGpD"}
|
|
@@ -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>;
|
|
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>;
|
|
12
19
|
//# sourceMappingURL=factory.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../src/synchronizer/factory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AACnE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,EAAE,KAAK,eAAe,EAAsB,MAAM,yBAAyB,CAAC;AAEnF,OAA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B,4BAA4B,CAChD,MAAM,EAAE,gBAAgB,GAAG,eAAe,EAC1C,aAAa,EAAE,aAAa,GAAG,mBAAmB,EAClD,mBAAmB,GAAE,kBAAkB,EAAO,EAC9C,MAAM,GAAE,eAAsC,yCAK/C;AAED,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,IAAI,CACV,gBAAgB,EACd,yBAAyB,GACzB,uBAAuB,GACvB,sBAAsB,GACtB,wBAAwB,GACxB,uBAAuB,GACvB,sBAAsB,GACtB,yBAAyB,CAC5B,GACC,IAAI,CAAC,eAAe,EAAE,eAAe,GAAG,oBAAoB,GAAG,aAAa,CAAC,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,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,21 +27,27 @@ 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). */
|
|
@@ -74,6 +81,6 @@ export declare class ServerWorldStateSynchronizer implements WorldStateSynchroni
|
|
|
74
81
|
* @param inHash - The inHash of the block.
|
|
75
82
|
* @throws If the L1 to L2 messages do not hash to the block inHash.
|
|
76
83
|
*/
|
|
77
|
-
protected verifyMessagesHashToInHash(l1ToL2Messages: Fr[], inHash:
|
|
84
|
+
protected verifyMessagesHashToInHash(l1ToL2Messages: Fr[], inHash: Fr): Promise<void>;
|
|
78
85
|
}
|
|
79
86
|
//# sourceMappingURL=server_world_state_synchronizer.d.ts.map
|
|
@@ -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,uCA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KAAK;IAgClB,SAAS,CAAC,iBAAiB,IAAI,aAAa;IAU/B,IAAI;IASJ,MAAM,IAAI,OAAO,CAAC,4BAA4B,CAAC;IAe/C,oBAAoB;IAIpB,QAAQ;IAMd,UAAU;IASjB;;;;;OAKG;IACU,aAAa,CAAC,iBAAiB,CAAC,EAAE,MAAM,EAAE,2BAA2B,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC;IA+C9G,oGAAoG;IACvF,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAexE,gGAAgG;IACnF,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC;IAYzC,oDAAoD;IACvC,sBAAsB,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;IAiB7E;;;;OAIG;YACW,cAAc;IAyB5B;;;;;OAKG;YACW,aAAa;YAuBb,oBAAoB;IAelC,OAAO,CAAC,iBAAiB;YAMX,iBAAiB;IAQ/B;;;OAGG;IACH,OAAO,CAAC,eAAe;IAKvB;;;;;OAKG;cACa,0BAA0B,CAAC,cAAc,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE;CAa5E"}
|
|
@@ -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/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
|
}>;
|
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,SAAqB;;;GAsD3C;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"}
|
package/dest/test/utils.js
CHANGED
|
@@ -3,28 +3,31 @@ import { padArrayEnd } from '@aztec/foundation/collection';
|
|
|
3
3
|
import { Fr } from '@aztec/foundation/fields';
|
|
4
4
|
import { L2Block } from '@aztec/stdlib/block';
|
|
5
5
|
import { AppendOnlyTreeSnapshot, MerkleTreeId } from '@aztec/stdlib/trees';
|
|
6
|
-
export async function mockBlock(blockNum, size, fork) {
|
|
7
|
-
const l2Block = await L2Block.random(blockNum, size);
|
|
8
|
-
const l1ToL2Messages = Array(
|
|
9
|
-
// Sync the append only trees
|
|
6
|
+
export async function mockBlock(blockNum, size, fork, maxEffects = undefined) {
|
|
7
|
+
const l2Block = await L2Block.random(blockNum, size, maxEffects);
|
|
8
|
+
const l1ToL2Messages = Array(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP).fill(0).map(Fr.random);
|
|
10
9
|
{
|
|
10
|
+
const insertData = async (treeId, data, subTreeHeight, fork)=>{
|
|
11
|
+
for (const dataBatch of data){
|
|
12
|
+
await fork.batchInsert(treeId, dataBatch, subTreeHeight);
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
const publicDataInsert = insertData(MerkleTreeId.PUBLIC_DATA_TREE, l2Block.body.txEffects.map((txEffect)=>txEffect.publicDataWrites.map((write)=>write.toBuffer())), 0, fork);
|
|
16
|
+
const nullifierInsert = insertData(MerkleTreeId.NULLIFIER_TREE, l2Block.body.txEffects.map((txEffect)=>padArrayEnd(txEffect.nullifiers, Fr.ZERO, MAX_NULLIFIERS_PER_TX).map((nullifier)=>nullifier.toBuffer())), NULLIFIER_SUBTREE_HEIGHT, fork);
|
|
11
17
|
const noteHashesPadded = l2Block.body.txEffects.flatMap((txEffect)=>padArrayEnd(txEffect.noteHashes, Fr.ZERO, MAX_NOTE_HASHES_PER_TX));
|
|
12
|
-
await fork.appendLeaves(MerkleTreeId.NOTE_HASH_TREE, noteHashesPadded);
|
|
13
18
|
const l1ToL2MessagesPadded = padArrayEnd(l1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP);
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
await fork.batchInsert(MerkleTreeId.NULLIFIER_TREE, nullifiersPadded.map((nullifier)=>nullifier.toBuffer()), NULLIFIER_SUBTREE_HEIGHT);
|
|
23
|
-
}
|
|
19
|
+
const noteHashInsert = fork.appendLeaves(MerkleTreeId.NOTE_HASH_TREE, noteHashesPadded);
|
|
20
|
+
const messageInsert = fork.appendLeaves(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, l1ToL2MessagesPadded);
|
|
21
|
+
await Promise.all([
|
|
22
|
+
publicDataInsert,
|
|
23
|
+
nullifierInsert,
|
|
24
|
+
noteHashInsert,
|
|
25
|
+
messageInsert
|
|
26
|
+
]);
|
|
24
27
|
}
|
|
25
28
|
const state = await fork.getStateReference();
|
|
26
29
|
l2Block.header.state = state;
|
|
27
|
-
await fork.updateArchive(l2Block.
|
|
30
|
+
await fork.updateArchive(l2Block.getBlockHeader());
|
|
28
31
|
const archiveState = await fork.getTreeInfo(MerkleTreeId.ARCHIVE);
|
|
29
32
|
l2Block.archive = new AppendOnlyTreeSnapshot(Fr.fromBuffer(archiveState.root), Number(archiveState.size));
|
|
30
33
|
return {
|
|
@@ -35,7 +38,7 @@ export async function mockBlock(blockNum, size, fork) {
|
|
|
35
38
|
export async function mockEmptyBlock(blockNum, fork) {
|
|
36
39
|
const l2Block = L2Block.empty();
|
|
37
40
|
const l1ToL2Messages = Array(16).fill(0).map(Fr.zero);
|
|
38
|
-
l2Block.header.globalVariables.blockNumber =
|
|
41
|
+
l2Block.header.globalVariables.blockNumber = blockNum;
|
|
39
42
|
// Sync the append only trees
|
|
40
43
|
{
|
|
41
44
|
const noteHashesPadded = l2Block.body.txEffects.flatMap((txEffect)=>padArrayEnd(txEffect.noteHashes, Fr.ZERO, MAX_NOTE_HASHES_PER_TX));
|
|
@@ -54,7 +57,7 @@ export async function mockEmptyBlock(blockNum, fork) {
|
|
|
54
57
|
}
|
|
55
58
|
const state = await fork.getStateReference();
|
|
56
59
|
l2Block.header.state = state;
|
|
57
|
-
await fork.updateArchive(l2Block.
|
|
60
|
+
await fork.updateArchive(l2Block.getBlockHeader());
|
|
58
61
|
const archiveState = await fork.getTreeInfo(MerkleTreeId.ARCHIVE);
|
|
59
62
|
l2Block.archive = new AppendOnlyTreeSnapshot(Fr.fromBuffer(archiveState.root), Number(archiveState.size));
|
|
60
63
|
return {
|
package/dest/testing.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { PublicDataTreeLeaf } from '@aztec/stdlib/trees';
|
|
|
4
4
|
export declare const defaultInitialAccountFeeJuice: Fr;
|
|
5
5
|
export declare function getGenesisValues(initialAccounts: AztecAddress[], initialAccountFeeJuice?: Fr, genesisPublicData?: PublicDataTreeLeaf[]): Promise<{
|
|
6
6
|
genesisArchiveRoot: Fr;
|
|
7
|
-
genesisBlockHash: Fr;
|
|
8
7
|
prefilledPublicData: PublicDataTreeLeaf[];
|
|
8
|
+
fundingNeeded: bigint;
|
|
9
9
|
}>;
|
|
10
10
|
//# sourceMappingURL=testing.d.ts.map
|
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,0BAA0B,CAAC;AAE9C,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,0BAA0B,CAAC;AAE9C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAgB,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAyBvE,eAAO,MAAM,6BAA6B,IAAqB,CAAC;AAEhE,wBAAsB,gBAAgB,CACpC,eAAe,EAAE,YAAY,EAAE,EAC/B,sBAAsB,KAAgC,EACtD,iBAAiB,GAAE,kBAAkB,EAAO;;;;GAqB7C"}
|
package/dest/testing.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GENESIS_ARCHIVE_ROOT
|
|
1
|
+
import { GENESIS_ARCHIVE_ROOT } from '@aztec/constants';
|
|
2
2
|
import { Fr } from '@aztec/foundation/fields';
|
|
3
3
|
import { computeFeePayerBalanceLeafSlot } from '@aztec/protocol-contracts/fee-juice';
|
|
4
4
|
import { MerkleTreeId, PublicDataTreeLeaf } from '@aztec/stdlib/trees';
|
|
@@ -6,19 +6,15 @@ import { NativeWorldStateService } from './native/index.js';
|
|
|
6
6
|
async function generateGenesisValues(prefilledPublicData) {
|
|
7
7
|
if (!prefilledPublicData.length) {
|
|
8
8
|
return {
|
|
9
|
-
genesisArchiveRoot: new Fr(GENESIS_ARCHIVE_ROOT)
|
|
10
|
-
genesisBlockHash: new Fr(GENESIS_BLOCK_HASH)
|
|
9
|
+
genesisArchiveRoot: new Fr(GENESIS_ARCHIVE_ROOT)
|
|
11
10
|
};
|
|
12
11
|
}
|
|
13
12
|
// Create a temporary world state to compute the genesis values.
|
|
14
13
|
const ws = await NativeWorldStateService.tmp(undefined /* rollupAddress */ , true, prefilledPublicData);
|
|
15
|
-
const initialHeader = ws.getInitialHeader();
|
|
16
|
-
const genesisBlockHash = await initialHeader.hash();
|
|
17
14
|
const genesisArchiveRoot = new Fr((await ws.getCommitted().getTreeInfo(MerkleTreeId.ARCHIVE)).root);
|
|
18
15
|
await ws.close();
|
|
19
16
|
return {
|
|
20
|
-
genesisArchiveRoot
|
|
21
|
-
genesisBlockHash
|
|
17
|
+
genesisArchiveRoot
|
|
22
18
|
};
|
|
23
19
|
}
|
|
24
20
|
export const defaultInitialAccountFeeJuice = new Fr(10n ** 22n);
|
|
@@ -28,10 +24,10 @@ export async function getGenesisValues(initialAccounts, initialAccountFeeJuice =
|
|
|
28
24
|
// Add user-defined public data
|
|
29
25
|
prefilledPublicData = prefilledPublicData.concat(genesisPublicData);
|
|
30
26
|
prefilledPublicData.sort((a, b)=>b.slot.lt(a.slot) ? 1 : -1);
|
|
31
|
-
const {
|
|
27
|
+
const { genesisArchiveRoot } = await generateGenesisValues(prefilledPublicData);
|
|
32
28
|
return {
|
|
33
29
|
genesisArchiveRoot,
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
prefilledPublicData,
|
|
31
|
+
fundingNeeded: BigInt(initialAccounts.length) * initialAccountFeeJuice.toBigInt()
|
|
36
32
|
};
|
|
37
33
|
}
|
|
@@ -33,8 +33,10 @@ export interface MerkleTreeAdminDatabase extends ForkMerkleTreeOperations {
|
|
|
33
33
|
* Handles a single L2 block (i.e. Inserts the new note hashes into the merkle tree).
|
|
34
34
|
* @param block - The L2 block to handle.
|
|
35
35
|
* @param l1ToL2Messages - The L1 to L2 messages for the block.
|
|
36
|
+
* @param isFirstBlock - Whether the block is the first block in a checkpoint. Temporary hack to only insert l1 to l2
|
|
37
|
+
* messages for the first block in a checkpoint. TODO(#17027) Remove this.
|
|
36
38
|
*/
|
|
37
|
-
handleL2BlockAndMessages(block: L2Block, l1ToL2Messages: Fr[]): Promise<WorldStateStatusFull>;
|
|
39
|
+
handleL2BlockAndMessages(block: L2Block, l1ToL2Messages: Fr[], isFirstBlock?: boolean): Promise<WorldStateStatusFull>;
|
|
38
40
|
/**
|
|
39
41
|
* Gets a handle that allows reading the latest committed state
|
|
40
42
|
*/
|
|
@@ -52,11 +54,11 @@ export interface MerkleTreeAdminDatabase extends ForkMerkleTreeOperations {
|
|
|
52
54
|
*/
|
|
53
55
|
unwindBlocks(toBlockNumber: bigint): Promise<WorldStateStatusFull>;
|
|
54
56
|
/**
|
|
55
|
-
* Advances the
|
|
56
|
-
* @param toBlockNumber The block number that is now the tip of the
|
|
57
|
+
* Advances the finalized block number to be the number provided
|
|
58
|
+
* @param toBlockNumber The block number that is now the tip of the finalized chain
|
|
57
59
|
* @returns The new WorldStateStatus
|
|
58
60
|
*/
|
|
59
|
-
|
|
61
|
+
setFinalized(toBlockNumber: bigint): Promise<WorldStateStatusSummary>;
|
|
60
62
|
/**
|
|
61
63
|
* Gets the current status summary of the database.
|
|
62
64
|
* @returns The current WorldStateStatus.
|
|
@@ -64,5 +66,7 @@ export interface MerkleTreeAdminDatabase extends ForkMerkleTreeOperations {
|
|
|
64
66
|
getStatusSummary(): Promise<WorldStateStatusSummary>;
|
|
65
67
|
/** Stops the database */
|
|
66
68
|
close(): Promise<void>;
|
|
69
|
+
/** Deletes the db. */
|
|
70
|
+
clear(): Promise<void>;
|
|
67
71
|
}
|
|
68
72
|
//# sourceMappingURL=merkle_tree_db.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"merkle_tree_db.d.ts","sourceRoot":"","sources":["../../src/world-state-db/merkle_tree_db.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AACnD,OAAO,KAAK,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC5E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,q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