@aztec/world-state 0.0.0-test.0 → 0.0.1-commit.0208eb9
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 +25 -41
- 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 +19 -7
- package/dest/native/merkle_trees_facade.d.ts.map +1 -1
- package/dest/native/merkle_trees_facade.js +76 -14
- package/dest/native/message.d.ts +74 -52
- package/dest/native/message.d.ts.map +1 -1
- package/dest/native/message.js +61 -61
- package/dest/native/native_world_state.d.ts +27 -19
- package/dest/native/native_world_state.d.ts.map +1 -1
- package/dest/native/native_world_state.js +103 -41
- 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 -4
- package/dest/synchronizer/config.d.ts.map +1 -1
- package/dest/synchronizer/config.js +27 -7
- 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 +11 -3
- package/dest/synchronizer/factory.d.ts.map +1 -1
- package/dest/synchronizer/factory.js +13 -8
- package/dest/synchronizer/index.d.ts +1 -1
- package/dest/synchronizer/server_world_state_synchronizer.d.ts +21 -31
- package/dest/synchronizer/server_world_state_synchronizer.d.ts.map +1 -1
- package/dest/synchronizer/server_world_state_synchronizer.js +144 -92
- package/dest/test/index.d.ts +1 -1
- package/dest/test/utils.d.ts +12 -5
- package/dest/test/utils.d.ts.map +1 -1
- package/dest/test/utils.js +54 -47
- package/dest/testing.d.ts +3 -3
- package/dest/testing.d.ts.map +1 -1
- package/dest/testing.js +7 -11
- package/dest/world-state-db/index.d.ts +1 -1
- package/dest/world-state-db/merkle_tree_db.d.ts +12 -9
- package/dest/world-state-db/merkle_tree_db.d.ts.map +1 -1
- package/package.json +24 -24
- package/src/instrumentation/instrumentation.ts +31 -43
- package/src/native/bench_metrics.ts +91 -0
- package/src/native/merkle_trees_facade.ts +83 -18
- package/src/native/message.ts +94 -74
- package/src/native/native_world_state.ts +132 -52
- package/src/native/native_world_state_instance.ts +62 -9
- package/src/native/world_state_ops_queue.ts +1 -1
- package/src/synchronizer/config.ts +48 -16
- package/src/synchronizer/errors.ts +5 -0
- package/src/synchronizer/factory.ts +38 -9
- package/src/synchronizer/server_world_state_synchronizer.ts +170 -117
- package/src/test/utils.ts +92 -82
- package/src/testing.ts +4 -8
- package/src/world-state-db/merkle_tree_db.ts +16 -8
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import type
|
|
4
|
-
import type { L2BlockSource, L2BlockStream, L2BlockStreamEvent, L2BlockStreamEventHandler, L2BlockStreamLocalDataProvider, L2Tips } from '@aztec/stdlib/block';
|
|
1
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import { type Logger } from '@aztec/foundation/log';
|
|
3
|
+
import { type L2BlockSource, L2BlockStream, type L2BlockStreamEvent, type L2BlockStreamEventHandler, type L2BlockStreamLocalDataProvider, type 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.
|
|
@@ -23,42 +24,38 @@ export declare class ServerWorldStateSynchronizer implements WorldStateSynchroni
|
|
|
23
24
|
private latestBlockNumberAtStart;
|
|
24
25
|
private historyToKeep;
|
|
25
26
|
private currentState;
|
|
26
|
-
private latestBlockHashQuery;
|
|
27
27
|
private syncPromise;
|
|
28
28
|
protected blockStream: L2BlockStream | undefined;
|
|
29
|
-
|
|
29
|
+
private provenBlockNumber;
|
|
30
|
+
constructor(merkleTreeDb: MerkleTreeAdminDatabase, l2BlockSource: L2BlockSource & L1ToL2MessageSource, config: WorldStateConfig, instrumentation?: WorldStateInstrumentation, log?: Logger);
|
|
30
31
|
getCommitted(): MerkleTreeReadOperations;
|
|
31
|
-
getSnapshot(blockNumber:
|
|
32
|
-
fork(blockNumber?:
|
|
32
|
+
getSnapshot(blockNumber: BlockNumber): MerkleTreeReadOperations;
|
|
33
|
+
fork(blockNumber?: BlockNumber, opts?: {
|
|
34
|
+
closeDelayMs?: number;
|
|
35
|
+
}): Promise<MerkleTreeWriteOperations>;
|
|
36
|
+
backupTo(dstPath: string, compact?: boolean): Promise<Record<Exclude<SnapshotDataKeys, 'archiver'>, string>>;
|
|
37
|
+
clear(): Promise<void>;
|
|
33
38
|
start(): Promise<void | import("@aztec/foundation/promise").PromiseWithResolvers<void>>;
|
|
34
39
|
protected createBlockStream(): L2BlockStream;
|
|
35
40
|
stop(): Promise<void>;
|
|
36
41
|
status(): Promise<WorldStateSynchronizerStatus>;
|
|
37
|
-
getLatestBlockNumber(): Promise<
|
|
42
|
+
getLatestBlockNumber(): Promise<BlockNumber>;
|
|
43
|
+
stopSync(): Promise<void>;
|
|
44
|
+
resumeSync(): void;
|
|
38
45
|
/**
|
|
39
46
|
* 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.
|
|
47
|
+
* @param targetBlockNumber - The target block number that we must sync to. Will download unproven blocks if needed to reach it.
|
|
48
|
+
* @param skipThrowIfTargetNotReached - Whether to skip throwing if the target block number is not reached.
|
|
41
49
|
* @returns A promise that resolves with the block number the world state was synced to
|
|
42
50
|
*/
|
|
43
|
-
syncImmediate(targetBlockNumber?:
|
|
51
|
+
syncImmediate(targetBlockNumber?: BlockNumber, skipThrowIfTargetNotReached?: boolean): Promise<BlockNumber>;
|
|
44
52
|
/** Returns the L2 block hash for a given number. Used by the L2BlockStream for detecting reorgs. */
|
|
45
|
-
getL2BlockHash(number:
|
|
53
|
+
getL2BlockHash(number: BlockNumber): Promise<string | undefined>;
|
|
46
54
|
/** Returns the latest L2 block number for each tip of the chain (latest, proven, finalized). */
|
|
47
55
|
getL2Tips(): Promise<L2Tips>;
|
|
48
56
|
/** Handles an event emitted by the block stream. */
|
|
49
57
|
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
58
|
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
59
|
private handleL2Block;
|
|
63
60
|
private handleChainFinalized;
|
|
64
61
|
private handleChainProven;
|
|
@@ -68,12 +65,5 @@ export declare class ServerWorldStateSynchronizer implements WorldStateSynchroni
|
|
|
68
65
|
* @param newState - New state value.
|
|
69
66
|
*/
|
|
70
67
|
private setCurrentState;
|
|
71
|
-
/**
|
|
72
|
-
* Verifies that the L1 to L2 messages hash to the block inHash.
|
|
73
|
-
* @param l1ToL2Messages - The L1 to L2 messages for the block.
|
|
74
|
-
* @param inHash - The inHash of the block.
|
|
75
|
-
* @throws If the L1 to L2 messages do not hash to the block inHash.
|
|
76
|
-
*/
|
|
77
|
-
protected verifyMessagesHashToInHash(l1ToL2Messages: Fr[], inHash: Buffer): Promise<void>;
|
|
78
68
|
}
|
|
79
|
-
//# sourceMappingURL=
|
|
69
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2VydmVyX3dvcmxkX3N0YXRlX3N5bmNocm9uaXplci5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3N5bmNocm9uaXplci9zZXJ2ZXJfd29ybGRfc3RhdGVfc3luY2hyb25pemVyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUNBLE9BQU8sRUFBRSxXQUFXLEVBQUUsTUFBTSxpQ0FBaUMsQ0FBQztBQUU5RCxPQUFPLEVBQUUsS0FBSyxNQUFNLEVBQWdCLE1BQU0sdUJBQXVCLENBQUM7QUFHbEUsT0FBTyxFQUlMLEtBQUssYUFBYSxFQUNsQixhQUFhLEVBQ2IsS0FBSyxrQkFBa0IsRUFDdkIsS0FBSyx5QkFBeUIsRUFDOUIsS0FBSyw4QkFBOEIsRUFDbkMsS0FBSyxNQUFNLEVBQ1osTUFBTSxxQkFBcUIsQ0FBQztBQUM3QixPQUFPLEVBR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SxXQUFXLEVBQy9CLDJCQUEyQixDQUFDLEVBQUUsT0FBTyxHQUNwQyxPQUFPLENBQUMsV0FBVyxDQUFDLENBNkN0QjtJQUVELG9HQUFvRztJQUN2RixjQUFjLENBQUMsTUFBTSxFQUFFLFdBQVcsR0FBRyxPQUFPLENBQUMsTUFBTSxHQUFHLFNBQVMsQ0FBQyxDQUs1RTtJQUVELGdHQUFnRztJQUNuRixTQUFTLElBQUksT0FBTyxDQUFDLE1BQU0sQ0FBQyxDQW1DeEM7SUFFRCxvREFBb0Q7SUFDdkMsc0JBQXNCLENBQUMsS0FBSyxFQUFFLGtCQUFrQixHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsQ0FlNUU7WUFPYSxjQUFjO1lBeUNkLGFBQWE7WUFrQmIsb0JBQW9CO0lBZWxDLE9BQU8sQ0FBQyxpQkFBaUI7WUFNWCxpQkFBaUI7SUFPL0I7OztPQUdHO0lBQ0gsT0FBTyxDQUFDLGVBQWU7Q0FJeEIifQ==
|
|
@@ -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":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAE9D,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,uBAAuB,CAAC;AAGlE,OAAO,EAIL,KAAK,aAAa,EAClB,aAAa,EACb,KAAK,kBAAkB,EACvB,KAAK,yBAAyB,EAC9B,KAAK,8BAA8B,EACnC,KAAK,MAAM,EACZ,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAGL,KAAK,sBAAsB,EAC3B,KAAK,4BAA4B,EAClC,MAAM,iCAAiC,CAAC;AACzC,OAAO,KAAK,EAAE,mBAAmB,EAAE,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AM,CAAA;KAAE,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAE3G;IAEM,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,gBAAgB,EAAE,UAAU,CAAC,EAAE,MAAM,CAAC,CAAC,CAElH;IAEM,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAE5B;IAEY,KAAK,mFA4BjB;IAED,SAAS,CAAC,iBAAiB,IAAI,aAAa,CAO3C;IAEY,IAAI,kBAOhB;IAEY,MAAM,IAAI,OAAO,CAAC,4BAA4B,CAAC,CAa3D;IAEY,oBAAoB,yBAEhC;IAEY,QAAQ,kBAIpB;IAEM,UAAU,SAOhB;IAED;;;;;OAKG;IACU,aAAa,CACxB,iBAAiB,CAAC,EAAE,WAAW,EAC/B,2BAA2B,CAAC,EAAE,OAAO,GACpC,OAAO,CAAC,WAAW,CAAC,CA6CtB;IAED,oGAAoG;IACvF,cAAc,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAK5E;IAED,gGAAgG;IACnF,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC,CAmCxC;IAED,oDAAoD;IACvC,sBAAsB,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,CAe5E;YAOa,cAAc;YAyCd,aAAa;YAkBb,oBAAoB;IAelC,OAAO,CAAC,iBAAiB;YAMX,iBAAiB;IAO/B;;;OAGG;IACH,OAAO,CAAC,eAAe;CAIxB"}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { GENESIS_BLOCK_HEADER_HASH, INITIAL_L2_BLOCK_NUM, INITIAL_L2_CHECKPOINT_NUM } from '@aztec/constants';
|
|
2
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
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
|
-
import {
|
|
6
|
-
import { SHA256Trunc } from '@aztec/merkle-tree';
|
|
6
|
+
import { GENESIS_CHECKPOINT_HEADER_HASH, L2BlockStream } from '@aztec/stdlib/block';
|
|
7
7
|
import { WorldStateRunningState } from '@aztec/stdlib/interfaces/server';
|
|
8
8
|
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
9
|
-
import {
|
|
9
|
+
import { 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.
|
|
@@ -22,18 +23,19 @@ import { WorldStateInstrumentation } from '../instrumentation/instrumentation.js
|
|
|
22
23
|
latestBlockNumberAtStart;
|
|
23
24
|
historyToKeep;
|
|
24
25
|
currentState;
|
|
25
|
-
latestBlockHashQuery;
|
|
26
26
|
syncPromise;
|
|
27
27
|
blockStream;
|
|
28
|
+
// WorldState doesn't track the proven block number, it only tracks the latest tips of the pending chain and the finalized chain
|
|
29
|
+
// store the proven block number here, in the synchronizer, so that we don't end up spamming the logs with 'chain-proved' events
|
|
30
|
+
provenBlockNumber;
|
|
28
31
|
constructor(merkleTreeDb, l2BlockSource, config, instrumentation = new WorldStateInstrumentation(getTelemetryClient()), log = createLogger('world_state')){
|
|
29
32
|
this.merkleTreeDb = merkleTreeDb;
|
|
30
33
|
this.l2BlockSource = l2BlockSource;
|
|
31
34
|
this.config = config;
|
|
32
35
|
this.instrumentation = instrumentation;
|
|
33
36
|
this.log = log;
|
|
34
|
-
this.latestBlockNumberAtStart =
|
|
37
|
+
this.latestBlockNumberAtStart = BlockNumber.ZERO;
|
|
35
38
|
this.currentState = WorldStateRunningState.IDLE;
|
|
36
|
-
this.latestBlockHashQuery = undefined;
|
|
37
39
|
this.syncPromise = promiseWithResolvers();
|
|
38
40
|
this.merkleTreeCommitted = this.merkleTreeDb.getCommitted();
|
|
39
41
|
this.historyToKeep = config.worldStateBlockHistory < 1 ? undefined : config.worldStateBlockHistory;
|
|
@@ -45,8 +47,14 @@ import { WorldStateInstrumentation } from '../instrumentation/instrumentation.js
|
|
|
45
47
|
getSnapshot(blockNumber) {
|
|
46
48
|
return this.merkleTreeDb.getSnapshot(blockNumber);
|
|
47
49
|
}
|
|
48
|
-
fork(blockNumber) {
|
|
49
|
-
return this.merkleTreeDb.fork(blockNumber);
|
|
50
|
+
fork(blockNumber, opts) {
|
|
51
|
+
return this.merkleTreeDb.fork(blockNumber, opts);
|
|
52
|
+
}
|
|
53
|
+
backupTo(dstPath, compact) {
|
|
54
|
+
return this.merkleTreeDb.backupTo(dstPath, compact);
|
|
55
|
+
}
|
|
56
|
+
clear() {
|
|
57
|
+
return this.merkleTreeDb.clear();
|
|
50
58
|
}
|
|
51
59
|
async start() {
|
|
52
60
|
if (this.currentState === WorldStateRunningState.STOPPED) {
|
|
@@ -56,7 +64,7 @@ import { WorldStateInstrumentation } from '../instrumentation/instrumentation.js
|
|
|
56
64
|
return this.syncPromise;
|
|
57
65
|
}
|
|
58
66
|
// Get the current latest block number
|
|
59
|
-
this.latestBlockNumberAtStart = await
|
|
67
|
+
this.latestBlockNumberAtStart = BlockNumber(await this.l2BlockSource.getBlockNumber());
|
|
60
68
|
const blockToDownloadFrom = await this.getLatestBlockNumber() + 1;
|
|
61
69
|
if (blockToDownloadFrom <= this.latestBlockNumberAtStart) {
|
|
62
70
|
// If there are blocks to be retrieved, go to a synching state
|
|
@@ -74,12 +82,11 @@ import { WorldStateInstrumentation } from '../instrumentation/instrumentation.js
|
|
|
74
82
|
return this.syncPromise.promise;
|
|
75
83
|
}
|
|
76
84
|
createBlockStream() {
|
|
77
|
-
const tracer = this.instrumentation.telemetry.getTracer('WorldStateL2BlockStream');
|
|
78
85
|
const logger = createLogger('world-state:block_stream');
|
|
79
|
-
return new
|
|
80
|
-
proven: this.config.worldStateProvenBlocksOnly,
|
|
86
|
+
return new L2BlockStream(this.l2BlockSource, this, this, logger, {
|
|
81
87
|
pollIntervalMS: this.config.worldStateBlockCheckIntervalMS,
|
|
82
|
-
batchSize: this.config.worldStateBlockRequestBatchSize
|
|
88
|
+
batchSize: this.config.worldStateBlockRequestBatchSize,
|
|
89
|
+
ignoreCheckpoints: true
|
|
83
90
|
});
|
|
84
91
|
}
|
|
85
92
|
async stop() {
|
|
@@ -93,10 +100,10 @@ import { WorldStateInstrumentation } from '../instrumentation/instrumentation.js
|
|
|
93
100
|
async status() {
|
|
94
101
|
const summary = await this.merkleTreeDb.getStatusSummary();
|
|
95
102
|
const status = {
|
|
96
|
-
latestBlockNumber:
|
|
97
|
-
latestBlockHash: await this.getL2BlockHash(
|
|
98
|
-
|
|
99
|
-
oldestHistoricBlockNumber:
|
|
103
|
+
latestBlockNumber: summary.unfinalizedBlockNumber,
|
|
104
|
+
latestBlockHash: await this.getL2BlockHash(summary.unfinalizedBlockNumber) ?? '',
|
|
105
|
+
finalizedBlockNumber: summary.finalizedBlockNumber,
|
|
106
|
+
oldestHistoricBlockNumber: summary.oldestHistoricalBlock,
|
|
100
107
|
treesAreSynched: summary.treesAreSynched
|
|
101
108
|
};
|
|
102
109
|
return {
|
|
@@ -105,80 +112,136 @@ import { WorldStateInstrumentation } from '../instrumentation/instrumentation.js
|
|
|
105
112
|
};
|
|
106
113
|
}
|
|
107
114
|
async getLatestBlockNumber() {
|
|
108
|
-
return (await this.getL2Tips()).
|
|
115
|
+
return (await this.getL2Tips()).proposed.number;
|
|
116
|
+
}
|
|
117
|
+
async stopSync() {
|
|
118
|
+
this.log.debug('Stopping sync...');
|
|
119
|
+
await this.blockStream?.stop();
|
|
120
|
+
this.log.info('Stopped sync');
|
|
121
|
+
}
|
|
122
|
+
resumeSync() {
|
|
123
|
+
if (!this.blockStream) {
|
|
124
|
+
throw new Error('Cannot resume sync as block stream is not initialized');
|
|
125
|
+
}
|
|
126
|
+
this.log.debug('Resuming sync...');
|
|
127
|
+
this.blockStream.start();
|
|
128
|
+
this.log.info('Resumed sync');
|
|
109
129
|
}
|
|
110
130
|
/**
|
|
111
131
|
* 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.
|
|
132
|
+
* @param targetBlockNumber - The target block number that we must sync to. Will download unproven blocks if needed to reach it.
|
|
133
|
+
* @param skipThrowIfTargetNotReached - Whether to skip throwing if the target block number is not reached.
|
|
113
134
|
* @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
|
|
135
|
+
*/ async syncImmediate(targetBlockNumber, skipThrowIfTargetNotReached) {
|
|
136
|
+
if (this.currentState !== WorldStateRunningState.RUNNING) {
|
|
116
137
|
throw new Error(`World State is not running. Unable to perform sync.`);
|
|
117
138
|
}
|
|
139
|
+
if (this.blockStream === undefined) {
|
|
140
|
+
throw new Error('Block stream is not initialized. Unable to perform sync.');
|
|
141
|
+
}
|
|
118
142
|
// If we have been given a block number to sync to and we have reached that number then return
|
|
119
143
|
const currentBlockNumber = await this.getLatestBlockNumber();
|
|
120
144
|
if (targetBlockNumber !== undefined && targetBlockNumber <= currentBlockNumber) {
|
|
121
145
|
return currentBlockNumber;
|
|
122
146
|
}
|
|
123
147
|
this.log.debug(`World State at ${currentBlockNumber} told to sync to ${targetBlockNumber ?? 'latest'}`);
|
|
148
|
+
// If the archiver is behind the target block, force an archiver sync
|
|
149
|
+
if (targetBlockNumber) {
|
|
150
|
+
const archiverLatestBlock = BlockNumber(await this.l2BlockSource.getBlockNumber());
|
|
151
|
+
if (archiverLatestBlock < targetBlockNumber) {
|
|
152
|
+
this.log.debug(`Archiver is at ${archiverLatestBlock} behind target block ${targetBlockNumber}.`);
|
|
153
|
+
await this.l2BlockSource.syncImmediate();
|
|
154
|
+
}
|
|
155
|
+
}
|
|
124
156
|
// Force the block stream to sync against the archiver now
|
|
125
157
|
await this.blockStream.sync();
|
|
126
158
|
// If we have been given a block number to sync to and we have not reached that number then fail
|
|
127
159
|
const updatedBlockNumber = await this.getLatestBlockNumber();
|
|
128
|
-
if (targetBlockNumber !== undefined && targetBlockNumber > updatedBlockNumber) {
|
|
129
|
-
throw new
|
|
160
|
+
if (!skipThrowIfTargetNotReached && targetBlockNumber !== undefined && targetBlockNumber > updatedBlockNumber) {
|
|
161
|
+
throw new WorldStateSynchronizerError(`Unable to sync to block number ${targetBlockNumber} (last synced is ${updatedBlockNumber})`, {
|
|
162
|
+
cause: {
|
|
163
|
+
reason: 'block_not_available',
|
|
164
|
+
previousBlockNumber: currentBlockNumber,
|
|
165
|
+
updatedBlockNumber,
|
|
166
|
+
targetBlockNumber
|
|
167
|
+
}
|
|
168
|
+
});
|
|
130
169
|
}
|
|
131
170
|
return updatedBlockNumber;
|
|
132
171
|
}
|
|
133
172
|
/** Returns the L2 block hash for a given number. Used by the L2BlockStream for detecting reorgs. */ async getL2BlockHash(number) {
|
|
134
|
-
if (number ===
|
|
173
|
+
if (number === BlockNumber.ZERO) {
|
|
135
174
|
return (await this.merkleTreeCommitted.getInitialHeader().hash()).toString();
|
|
136
175
|
}
|
|
137
|
-
|
|
138
|
-
this.latestBlockHashQuery = {
|
|
139
|
-
hash: await this.merkleTreeCommitted.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(number)).then((leaf)=>leaf?.toString()),
|
|
140
|
-
blockNumber: number
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
return this.latestBlockHashQuery.hash;
|
|
176
|
+
return this.merkleTreeCommitted.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(number)).then((leaf)=>leaf?.toString());
|
|
144
177
|
}
|
|
145
178
|
/** Returns the latest L2 block number for each tip of the chain (latest, proven, finalized). */ async getL2Tips() {
|
|
146
179
|
const status = await this.merkleTreeDb.getStatusSummary();
|
|
147
|
-
const
|
|
180
|
+
const unfinalizedBlockHashPromise = this.getL2BlockHash(status.unfinalizedBlockNumber);
|
|
181
|
+
const finalizedBlockHashPromise = this.getL2BlockHash(status.finalizedBlockNumber);
|
|
182
|
+
const provenBlockNumber = this.provenBlockNumber ?? status.finalizedBlockNumber;
|
|
183
|
+
const provenBlockHashPromise = this.provenBlockNumber === undefined ? finalizedBlockHashPromise : this.getL2BlockHash(this.provenBlockNumber);
|
|
184
|
+
const [unfinalizedBlockHash, finalizedBlockHash, provenBlockHash] = await Promise.all([
|
|
185
|
+
unfinalizedBlockHashPromise,
|
|
186
|
+
finalizedBlockHashPromise,
|
|
187
|
+
provenBlockHashPromise
|
|
188
|
+
]);
|
|
148
189
|
const latestBlockId = {
|
|
149
|
-
number:
|
|
150
|
-
hash:
|
|
190
|
+
number: status.unfinalizedBlockNumber,
|
|
191
|
+
hash: unfinalizedBlockHash
|
|
151
192
|
};
|
|
193
|
+
// World state doesn't track checkpointed blocks or checkpoints themselves.
|
|
194
|
+
// but we use a block stream so we need to provide 'local' L2Tips.
|
|
195
|
+
// We configure the block stream to ignore checkpoints and set checkpoint values to genesis here.
|
|
196
|
+
const genesisCheckpointHeaderHash = GENESIS_CHECKPOINT_HEADER_HASH.toString();
|
|
152
197
|
return {
|
|
153
|
-
|
|
198
|
+
proposed: latestBlockId,
|
|
199
|
+
checkpointed: {
|
|
200
|
+
block: {
|
|
201
|
+
number: INITIAL_L2_BLOCK_NUM,
|
|
202
|
+
hash: GENESIS_BLOCK_HEADER_HASH.toString()
|
|
203
|
+
},
|
|
204
|
+
checkpoint: {
|
|
205
|
+
number: INITIAL_L2_CHECKPOINT_NUM,
|
|
206
|
+
hash: genesisCheckpointHeaderHash
|
|
207
|
+
}
|
|
208
|
+
},
|
|
154
209
|
finalized: {
|
|
155
|
-
|
|
156
|
-
|
|
210
|
+
block: {
|
|
211
|
+
number: status.finalizedBlockNumber,
|
|
212
|
+
hash: finalizedBlockHash ?? ''
|
|
213
|
+
},
|
|
214
|
+
checkpoint: {
|
|
215
|
+
number: INITIAL_L2_CHECKPOINT_NUM,
|
|
216
|
+
hash: genesisCheckpointHeaderHash
|
|
217
|
+
}
|
|
157
218
|
},
|
|
158
219
|
proven: {
|
|
159
|
-
|
|
160
|
-
|
|
220
|
+
block: {
|
|
221
|
+
number: provenBlockNumber,
|
|
222
|
+
hash: provenBlockHash ?? ''
|
|
223
|
+
},
|
|
224
|
+
checkpoint: {
|
|
225
|
+
number: INITIAL_L2_CHECKPOINT_NUM,
|
|
226
|
+
hash: genesisCheckpointHeaderHash
|
|
227
|
+
}
|
|
161
228
|
}
|
|
162
229
|
};
|
|
163
230
|
}
|
|
164
231
|
/** 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);
|
|
232
|
+
switch(event.type){
|
|
233
|
+
case 'blocks-added':
|
|
234
|
+
await this.handleL2Blocks(event.blocks);
|
|
235
|
+
break;
|
|
236
|
+
case 'chain-pruned':
|
|
237
|
+
await this.handleChainPruned(event.block.number);
|
|
238
|
+
break;
|
|
239
|
+
case 'chain-proven':
|
|
240
|
+
await this.handleChainProven(event.block.number);
|
|
241
|
+
break;
|
|
242
|
+
case 'chain-finalized':
|
|
243
|
+
await this.handleChainFinalized(event.block.number);
|
|
244
|
+
break;
|
|
182
245
|
}
|
|
183
246
|
}
|
|
184
247
|
/**
|
|
@@ -186,19 +249,23 @@ import { WorldStateInstrumentation } from '../instrumentation/instrumentation.js
|
|
|
186
249
|
* @param l2Blocks - The L2 blocks to handle.
|
|
187
250
|
* @returns Whether the block handled was produced by this same node.
|
|
188
251
|
*/ async handleL2Blocks(l2Blocks) {
|
|
189
|
-
this.log.
|
|
190
|
-
|
|
191
|
-
const
|
|
252
|
+
this.log.debug(`Handling L2 blocks ${l2Blocks[0].number} to ${l2Blocks.at(-1).number}`);
|
|
253
|
+
// Fetch the L1->L2 messages for the first block in a checkpoint.
|
|
254
|
+
const messagesForBlocks = new Map();
|
|
255
|
+
await Promise.all(l2Blocks.filter((b)=>b.indexWithinCheckpoint === 0).map(async (block)=>{
|
|
256
|
+
const l1ToL2Messages = await this.l2BlockSource.getL1ToL2Messages(block.checkpointNumber);
|
|
257
|
+
messagesForBlocks.set(block.number, l1ToL2Messages);
|
|
258
|
+
}));
|
|
192
259
|
let updateStatus = undefined;
|
|
193
|
-
for(
|
|
194
|
-
const [duration, result] = await elapsed(()=>this.handleL2Block(
|
|
195
|
-
this.log.
|
|
260
|
+
for (const block of l2Blocks){
|
|
261
|
+
const [duration, result] = await elapsed(()=>this.handleL2Block(block, messagesForBlocks.get(block.number) ?? []));
|
|
262
|
+
this.log.info(`World state updated with L2 block ${block.number}`, {
|
|
196
263
|
eventName: 'l2-block-handled',
|
|
197
264
|
duration,
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
oldestHistoricBlock: result.summary.oldestHistoricalBlock,
|
|
201
|
-
...
|
|
265
|
+
unfinalizedBlockNumber: BigInt(result.summary.unfinalizedBlockNumber),
|
|
266
|
+
finalizedBlockNumber: BigInt(result.summary.finalizedBlockNumber),
|
|
267
|
+
oldestHistoricBlock: BigInt(result.summary.oldestHistoricalBlock),
|
|
268
|
+
...block.getStats()
|
|
202
269
|
});
|
|
203
270
|
updateStatus = result;
|
|
204
271
|
}
|
|
@@ -213,16 +280,12 @@ import { WorldStateInstrumentation } from '../instrumentation/instrumentation.js
|
|
|
213
280
|
* @param l1ToL2Messages - The L1 to L2 messages for the block.
|
|
214
281
|
* @returns Whether the block handled was produced by this same node.
|
|
215
282
|
*/ async handleL2Block(l2Block, l1ToL2Messages) {
|
|
216
|
-
|
|
217
|
-
// Note that we cannot optimize this check by checking the root of the subtree after inserting the messages
|
|
218
|
-
// to the real L1_TO_L2_MESSAGE_TREE (like we do in merkleTreeDb.handleL2BlockAndMessages(...)) because that
|
|
219
|
-
// tree uses pedersen and we don't have access to the converted root.
|
|
220
|
-
await this.verifyMessagesHashToInHash(l1ToL2Messages, l2Block.header.contentCommitment.inHash);
|
|
221
|
-
// If the above check succeeds, we can proceed to handle the block.
|
|
222
|
-
this.log.trace(`Pushing L2 block ${l2Block.number} to merkle tree db `, {
|
|
283
|
+
this.log.debug(`Pushing L2 block ${l2Block.number} to merkle tree db `, {
|
|
223
284
|
blockNumber: l2Block.number,
|
|
224
285
|
blockHash: await l2Block.hash().then((h)=>h.toString()),
|
|
225
|
-
l1ToL2Messages: l1ToL2Messages.map((msg)=>msg.toString())
|
|
286
|
+
l1ToL2Messages: l1ToL2Messages.map((msg)=>msg.toString()),
|
|
287
|
+
blockHeader: l2Block.header.toInspect(),
|
|
288
|
+
blockStats: l2Block.getStats()
|
|
226
289
|
});
|
|
227
290
|
const result = await this.merkleTreeDb.handleL2BlockAndMessages(l2Block, l1ToL2Messages);
|
|
228
291
|
if (this.currentState === WorldStateRunningState.SYNCHING && l2Block.number >= this.latestBlockNumberAtStart) {
|
|
@@ -233,26 +296,27 @@ import { WorldStateInstrumentation } from '../instrumentation/instrumentation.js
|
|
|
233
296
|
}
|
|
234
297
|
async handleChainFinalized(blockNumber) {
|
|
235
298
|
this.log.verbose(`Finalized chain is now at block ${blockNumber}`);
|
|
236
|
-
const summary = await this.merkleTreeDb.
|
|
299
|
+
const summary = await this.merkleTreeDb.setFinalized(blockNumber);
|
|
237
300
|
if (this.historyToKeep === undefined) {
|
|
238
301
|
return;
|
|
239
302
|
}
|
|
240
|
-
const newHistoricBlock = summary.
|
|
303
|
+
const newHistoricBlock = summary.finalizedBlockNumber - this.historyToKeep + 1;
|
|
241
304
|
if (newHistoricBlock <= 1) {
|
|
242
305
|
return;
|
|
243
306
|
}
|
|
244
307
|
this.log.verbose(`Pruning historic blocks to ${newHistoricBlock}`);
|
|
245
|
-
const status = await this.merkleTreeDb.removeHistoricalBlocks(newHistoricBlock);
|
|
308
|
+
const status = await this.merkleTreeDb.removeHistoricalBlocks(BlockNumber(newHistoricBlock));
|
|
246
309
|
this.log.debug(`World state summary `, status.summary);
|
|
247
310
|
}
|
|
248
311
|
handleChainProven(blockNumber) {
|
|
312
|
+
this.provenBlockNumber = blockNumber;
|
|
249
313
|
this.log.debug(`Proven chain is now at block ${blockNumber}`);
|
|
250
314
|
return Promise.resolve();
|
|
251
315
|
}
|
|
252
316
|
async handleChainPruned(blockNumber) {
|
|
253
317
|
this.log.warn(`Chain pruned to block ${blockNumber}`);
|
|
254
|
-
const status = await this.merkleTreeDb.unwindBlocks(
|
|
255
|
-
this.
|
|
318
|
+
const status = await this.merkleTreeDb.unwindBlocks(blockNumber);
|
|
319
|
+
this.provenBlockNumber = undefined;
|
|
256
320
|
this.instrumentation.updateWorldStateMetrics(status);
|
|
257
321
|
}
|
|
258
322
|
/**
|
|
@@ -262,16 +326,4 @@ import { WorldStateInstrumentation } from '../instrumentation/instrumentation.js
|
|
|
262
326
|
this.currentState = newState;
|
|
263
327
|
this.log.debug(`Moved to state ${WorldStateRunningState[this.currentState]}`);
|
|
264
328
|
}
|
|
265
|
-
/**
|
|
266
|
-
* Verifies that the L1 to L2 messages hash to the block inHash.
|
|
267
|
-
* @param l1ToL2Messages - The L1 to L2 messages for the block.
|
|
268
|
-
* @param inHash - The inHash of the block.
|
|
269
|
-
* @throws If the L1 to L2 messages do not hash to the block inHash.
|
|
270
|
-
*/ async verifyMessagesHashToInHash(l1ToL2Messages, inHash) {
|
|
271
|
-
const treeCalculator = await MerkleTreeCalculator.create(L1_TO_L2_MSG_SUBTREE_HEIGHT, Buffer.alloc(32), (lhs, rhs)=>Promise.resolve(new SHA256Trunc().hash(lhs, rhs)));
|
|
272
|
-
const root = await treeCalculator.computeTreeRoot(l1ToL2Messages.map((msg)=>msg.toBuffer()));
|
|
273
|
-
if (!root.equals(inHash)) {
|
|
274
|
-
throw new Error('Obtained L1 to L2 messages failed to be hashed to the block inHash');
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
329
|
}
|
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
|
@@ -1,19 +1,26 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BlockNumber, type CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
3
|
import { L2Block } from '@aztec/stdlib/block';
|
|
3
4
|
import type { MerkleTreeReadOperations, MerkleTreeWriteOperations } from '@aztec/stdlib/interfaces/server';
|
|
5
|
+
import { mockCheckpointAndMessages } from '@aztec/stdlib/testing';
|
|
4
6
|
import type { NativeWorldStateService } from '../native/native_world_state.js';
|
|
5
|
-
export declare function
|
|
7
|
+
export declare function updateBlockState(block: L2Block, l1ToL2Messages: Fr[], fork: MerkleTreeWriteOperations): Promise<void>;
|
|
8
|
+
export declare function mockBlock(blockNum: BlockNumber, size: number, fork: MerkleTreeWriteOperations, maxEffects?: number | undefined, numL1ToL2Messages?: number, isFirstBlockInCheckpoint?: boolean): Promise<{
|
|
6
9
|
block: L2Block;
|
|
7
10
|
messages: Fr[];
|
|
8
11
|
}>;
|
|
9
|
-
export declare function mockEmptyBlock(blockNum:
|
|
12
|
+
export declare function mockEmptyBlock(blockNum: BlockNumber, fork: MerkleTreeWriteOperations): Promise<{
|
|
10
13
|
block: L2Block;
|
|
11
14
|
messages: Fr[];
|
|
12
15
|
}>;
|
|
13
|
-
export declare function mockBlocks(from:
|
|
16
|
+
export declare function mockBlocks(from: BlockNumber, count: number, numTxs: number, worldState: NativeWorldStateService): Promise<{
|
|
14
17
|
blocks: L2Block[];
|
|
15
18
|
messages: Fr[][];
|
|
16
19
|
}>;
|
|
20
|
+
export declare function mockCheckpoint(checkpointNumber: CheckpointNumber, fork: MerkleTreeWriteOperations, options?: Partial<Parameters<typeof mockCheckpointAndMessages>[1]>): Promise<{
|
|
21
|
+
checkpoint: import("@aztec/stdlib/checkpoint").Checkpoint;
|
|
22
|
+
messages: Fr[];
|
|
23
|
+
}>;
|
|
17
24
|
export declare function assertSameState(forkA: MerkleTreeReadOperations, forkB: MerkleTreeReadOperations): Promise<void>;
|
|
18
25
|
export declare function compareChains(left: MerkleTreeReadOperations, right: MerkleTreeReadOperations): Promise<void>;
|
|
19
|
-
//# sourceMappingURL=
|
|
26
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXRpbHMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy90ZXN0L3V0aWxzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQU9BLE9BQU8sRUFBRSxXQUFXLEVBQUUsS0FBSyxnQkFBZ0IsRUFBeUIsTUFBTSxpQ0FBaUMsQ0FBQztBQUU1RyxPQUFPLEVBQUUsRUFBRSxFQUFFLE1BQU0sZ0NBQWdDLENBQUM7QUFDcEQsT0FBTyxFQUFFLE9BQU8sRUFBRSxNQUFNLHFCQUFxQixDQUFDO0FBQzlDLE9BQU8sS0FBSyxFQUVWLHdCQUF3QixFQUN4Qix5QkFBeUIsRUFDMUIsTUFBTSxpQ0FBaUMsQ0FBQztBQUN6Q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dCLEVBQUUsS0FBSyxFQUFFLHdCQUF3QixpQkFZbEcifQ==
|
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,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/test/utils.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,WAAW,EAAE,KAAK,gBAAgB,EAAyB,MAAM,iCAAiC,CAAC;AAE5G,OAAO,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,KAAK,EAEV,wBAAwB,EACxB,yBAAyB,EAC1B,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,yBAAyB,EAAsB,MAAM,uBAAuB,CAAC;AAItF,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAE/E,wBAAsB,gBAAgB,CAAC,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,yBAAyB,iBA8C3G;AAED,wBAAsB,SAAS,CAC7B,QAAQ,EAAE,WAAW,EACrB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,yBAAyB,EAC/B,UAAU,GAAE,MAAM,GAAG,SAAgB,EACrC,iBAAiB,GAAE,MAA4C,EAC/D,wBAAwB,GAAE,OAAc;;;GAezC;AAED,wBAAsB,cAAc,CAAC,QAAQ,EAAE,WAAW,EAAE,IAAI,EAAE,yBAAyB;;;GAY1F;AAED,wBAAsB,UAAU,CAC9B,IAAI,EAAE,WAAW,EACjB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,uBAAuB;;;GAepC;AAED,wBAAsB,cAAc,CAClC,gBAAgB,EAAE,gBAAgB,EAClC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