@aztec/world-state 0.0.0-test.0 → 0.0.1-commit.03f7ef2
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 +19 -7
- package/dest/native/merkle_trees_facade.d.ts.map +1 -1
- package/dest/native/merkle_trees_facade.js +62 -11
- package/dest/native/message.d.ts +72 -51
- package/dest/native/message.d.ts.map +1 -1
- package/dest/native/message.js +61 -61
- package/dest/native/native_world_state.d.ts +28 -20
- package/dest/native/native_world_state.d.ts.map +1 -1
- package/dest/native/native_world_state.js +97 -36
- 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 +20 -29
- package/dest/synchronizer/server_world_state_synchronizer.d.ts.map +1 -1
- package/dest/synchronizer/server_world_state_synchronizer.js +94 -70
- package/dest/test/index.d.ts +1 -1
- package/dest/test/utils.d.ts +16 -9
- package/dest/test/utils.d.ts.map +1 -1
- package/dest/test/utils.js +56 -49
- 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 +22 -10
- package/src/native/bench_metrics.ts +91 -0
- package/src/native/merkle_trees_facade.ts +73 -17
- package/src/native/message.ts +92 -73
- package/src/native/native_world_state.ts +118 -50
- 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 +132 -93
- package/src/test/utils.ts +94 -84
- package/src/testing.ts +4 -8
- package/src/world-state-db/merkle_tree_db.ts +12 -8
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import type { Fr } from '@aztec/foundation/fields';
|
|
1
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
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,36 @@ 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
|
-
getSnapshot(blockNumber:
|
|
32
|
-
fork(blockNumber?:
|
|
33
|
+
getSnapshot(blockNumber: BlockNumber): MerkleTreeReadOperations;
|
|
34
|
+
fork(blockNumber?: BlockNumber, opts?: {
|
|
35
|
+
closeDelayMs?: number;
|
|
36
|
+
}): Promise<MerkleTreeWriteOperations>;
|
|
37
|
+
backupTo(dstPath: string, compact?: boolean): Promise<Record<Exclude<SnapshotDataKeys, 'archiver'>, string>>;
|
|
38
|
+
clear(): Promise<void>;
|
|
33
39
|
start(): Promise<void | import("@aztec/foundation/promise").PromiseWithResolvers<void>>;
|
|
34
40
|
protected createBlockStream(): L2BlockStream;
|
|
35
41
|
stop(): Promise<void>;
|
|
36
42
|
status(): Promise<WorldStateSynchronizerStatus>;
|
|
37
|
-
getLatestBlockNumber(): Promise<
|
|
43
|
+
getLatestBlockNumber(): Promise<BlockNumber>;
|
|
44
|
+
stopSync(): Promise<void>;
|
|
45
|
+
resumeSync(): void;
|
|
38
46
|
/**
|
|
39
47
|
* 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.
|
|
48
|
+
* @param targetBlockNumber - The target block number that we must sync to. Will download unproven blocks if needed to reach it.
|
|
49
|
+
* @param skipThrowIfTargetNotReached - Whether to skip throwing if the target block number is not reached.
|
|
41
50
|
* @returns A promise that resolves with the block number the world state was synced to
|
|
42
51
|
*/
|
|
43
|
-
syncImmediate(targetBlockNumber?:
|
|
52
|
+
syncImmediate(targetBlockNumber?: BlockNumber, skipThrowIfTargetNotReached?: boolean): Promise<BlockNumber>;
|
|
44
53
|
/** Returns the L2 block hash for a given number. Used by the L2BlockStream for detecting reorgs. */
|
|
45
|
-
getL2BlockHash(number:
|
|
54
|
+
getL2BlockHash(number: BlockNumber): Promise<string | undefined>;
|
|
46
55
|
/** Returns the latest L2 block number for each tip of the chain (latest, proven, finalized). */
|
|
47
56
|
getL2Tips(): Promise<L2Tips>;
|
|
48
57
|
/** Handles an event emitted by the block stream. */
|
|
49
58
|
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
59
|
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
60
|
private handleL2Block;
|
|
63
61
|
private handleChainFinalized;
|
|
64
62
|
private handleChainProven;
|
|
@@ -68,12 +66,5 @@ export declare class ServerWorldStateSynchronizer implements WorldStateSynchroni
|
|
|
68
66
|
* @param newState - New state value.
|
|
69
67
|
*/
|
|
70
68
|
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
69
|
}
|
|
79
|
-
//# sourceMappingURL=
|
|
70
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2VydmVyX3dvcmxkX3N0YXRlX3N5bmNocm9uaXplci5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3N5bmNocm9uaXplci9zZXJ2ZXJfd29ybGRfc3RhdGVfc3luY2hyb25pemVyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxXQUFXLEVBQUUsTUFBTSxpQ0FBaUMsQ0FBQztBQUU5RCxPQUFPLEVBQUUsS0FBSyxNQUFNLEVBQWdCLE1BQU0sdUJBQXVCLENBQUM7QUFHbEUsT0FBTyxLQUFLLEVBR1YsYUFBYSxFQUNiLGFBQWEsRUFDYixrQkFBa0IsRUFDbEIseUJBQXlCLEVBQ3pCLDhCQUE4QixFQUM5QixNQUFNLEVBQ1AsTUFBTSxxQkFBcUIsQ0FBQztBQUM3QixPQUFPLEVBR0wsS0FBSyxzQkFBc0IsRUFDM0IsS0FBSyw0QkFBNEIsRUFDbEMsTUFBTSxpQ0FBaUMsQ0FBQztBQUN6QyxPQUFPLEtBQUssRUFBRSxtQkFBbUIsRUFBRSxNQUFNLHlCQUF5QixDQUFDO0FBQ25FLE9BQU8sS0FBSyxFQUFF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BQyxNQUFNLEVBQUUsV0FBVyxHQUFHLE9BQU8sQ0FBQyxNQUFNLEdBQUcsU0FBUyxDQUFDLENBYTVFO0lBRUQsZ0dBQWdHO0lBQ25GLFNBQVMsSUFBSSxPQUFPLENBQUMsTUFBTSxDQUFDLENBVXhDO0lBRUQsb0RBQW9EO0lBQ3ZDLHNCQUFzQixDQUFDLEtBQUssRUFBRSxrQkFBa0IsR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLENBZTVFO1lBT2EsY0FBYztZQXlDZCxhQUFhO1lBZ0JiLG9CQUFvQjtJQWVsQyxPQUFPLENBQUMsaUJBQWlCO1lBTVgsaUJBQWlCO0lBUS9COzs7T0FHRztJQUNILE9BQU8sQ0FBQyxlQUFlO0NBSXhCIn0=
|
|
@@ -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":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAE9D,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,uBAAuB,CAAC;AAGlE,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,OA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AAC,MAAM,CAAC,OAAO,CAAC,gBAAgB,EAAE,UAAU,CAAC,EAAE,MAAM,CAAC,CAAC,CAElH;IAEM,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAE5B;IAEY,KAAK,mFAgCjB;IAED,SAAS,CAAC,iBAAiB,IAAI,aAAa,CAQ3C;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,CAa5E;IAED,gGAAgG;IACnF,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC,CAUxC;IAED,oDAAoD;IACvC,sBAAsB,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,CAe5E;YAOa,cAAc;YAyCd,aAAa;YAgBb,oBAAoB;IAelC,OAAO,CAAC,iBAAiB;YAMX,iBAAiB;IAQ/B;;;OAGG;IACH,OAAO,CAAC,eAAe;CAIxB"}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
2
|
import { createLogger } from '@aztec/foundation/log';
|
|
3
3
|
import { promiseWithResolvers } from '@aztec/foundation/promise';
|
|
4
4
|
import { elapsed } from '@aztec/foundation/timer';
|
|
5
|
-
import { MerkleTreeCalculator } from '@aztec/foundation/trees';
|
|
6
|
-
import { SHA256Trunc } from '@aztec/merkle-tree';
|
|
7
5
|
import { WorldStateRunningState } from '@aztec/stdlib/interfaces/server';
|
|
8
6
|
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
9
7
|
import { TraceableL2BlockStream, getTelemetryClient } from '@aztec/telemetry-client';
|
|
10
8
|
import { WorldStateInstrumentation } from '../instrumentation/instrumentation.js';
|
|
9
|
+
import { WorldStateSynchronizerError } from './errors.js';
|
|
11
10
|
/**
|
|
12
11
|
* Synchronizes the world state with the L2 blocks from a L2BlockSource via a block stream.
|
|
13
12
|
* The synchronizer will download the L2 blocks from the L2BlockSource and update the merkle trees.
|
|
@@ -25,13 +24,16 @@ import { WorldStateInstrumentation } from '../instrumentation/instrumentation.js
|
|
|
25
24
|
latestBlockHashQuery;
|
|
26
25
|
syncPromise;
|
|
27
26
|
blockStream;
|
|
27
|
+
// WorldState doesn't track the proven block number, it only tracks the latest tips of the pending chain and the finalized chain
|
|
28
|
+
// store the proven block number here, in the synchronizer, so that we don't end up spamming the logs with 'chain-proved' events
|
|
29
|
+
provenBlockNumber;
|
|
28
30
|
constructor(merkleTreeDb, l2BlockSource, config, instrumentation = new WorldStateInstrumentation(getTelemetryClient()), log = createLogger('world_state')){
|
|
29
31
|
this.merkleTreeDb = merkleTreeDb;
|
|
30
32
|
this.l2BlockSource = l2BlockSource;
|
|
31
33
|
this.config = config;
|
|
32
34
|
this.instrumentation = instrumentation;
|
|
33
35
|
this.log = log;
|
|
34
|
-
this.latestBlockNumberAtStart =
|
|
36
|
+
this.latestBlockNumberAtStart = BlockNumber.ZERO;
|
|
35
37
|
this.currentState = WorldStateRunningState.IDLE;
|
|
36
38
|
this.latestBlockHashQuery = undefined;
|
|
37
39
|
this.syncPromise = promiseWithResolvers();
|
|
@@ -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 (this.config.worldStateProvenBlocksOnly ? this.l2BlockSource.getProvenBlockNumber() : this.l2BlockSource.getBlockNumber());
|
|
67
|
+
this.latestBlockNumberAtStart = BlockNumber(await (this.config.worldStateProvenBlocksOnly ? this.l2BlockSource.getProvenBlockNumber() : 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
|
|
@@ -93,10 +101,10 @@ import { WorldStateInstrumentation } from '../instrumentation/instrumentation.js
|
|
|
93
101
|
async status() {
|
|
94
102
|
const summary = await this.merkleTreeDb.getStatusSummary();
|
|
95
103
|
const status = {
|
|
96
|
-
latestBlockNumber:
|
|
97
|
-
latestBlockHash: await this.getL2BlockHash(
|
|
98
|
-
|
|
99
|
-
oldestHistoricBlockNumber:
|
|
104
|
+
latestBlockNumber: summary.unfinalizedBlockNumber,
|
|
105
|
+
latestBlockHash: await this.getL2BlockHash(summary.unfinalizedBlockNumber) ?? '',
|
|
106
|
+
finalizedBlockNumber: summary.finalizedBlockNumber,
|
|
107
|
+
oldestHistoricBlockNumber: summary.oldestHistoricalBlock,
|
|
100
108
|
treesAreSynched: summary.treesAreSynched
|
|
101
109
|
};
|
|
102
110
|
return {
|
|
@@ -107,31 +115,63 @@ import { WorldStateInstrumentation } from '../instrumentation/instrumentation.js
|
|
|
107
115
|
async getLatestBlockNumber() {
|
|
108
116
|
return (await this.getL2Tips()).latest.number;
|
|
109
117
|
}
|
|
118
|
+
async stopSync() {
|
|
119
|
+
this.log.debug('Stopping sync...');
|
|
120
|
+
await this.blockStream?.stop();
|
|
121
|
+
this.log.info('Stopped sync');
|
|
122
|
+
}
|
|
123
|
+
resumeSync() {
|
|
124
|
+
if (!this.blockStream) {
|
|
125
|
+
throw new Error('Cannot resume sync as block stream is not initialized');
|
|
126
|
+
}
|
|
127
|
+
this.log.debug('Resuming sync...');
|
|
128
|
+
this.blockStream.start();
|
|
129
|
+
this.log.info('Resumed sync');
|
|
130
|
+
}
|
|
110
131
|
/**
|
|
111
132
|
* 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.
|
|
133
|
+
* @param targetBlockNumber - The target block number that we must sync to. Will download unproven blocks if needed to reach it.
|
|
134
|
+
* @param skipThrowIfTargetNotReached - Whether to skip throwing if the target block number is not reached.
|
|
113
135
|
* @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
|
|
136
|
+
*/ async syncImmediate(targetBlockNumber, skipThrowIfTargetNotReached) {
|
|
137
|
+
if (this.currentState !== WorldStateRunningState.RUNNING) {
|
|
116
138
|
throw new Error(`World State is not running. Unable to perform sync.`);
|
|
117
139
|
}
|
|
140
|
+
if (this.blockStream === undefined) {
|
|
141
|
+
throw new Error('Block stream is not initialized. Unable to perform sync.');
|
|
142
|
+
}
|
|
118
143
|
// If we have been given a block number to sync to and we have reached that number then return
|
|
119
144
|
const currentBlockNumber = await this.getLatestBlockNumber();
|
|
120
145
|
if (targetBlockNumber !== undefined && targetBlockNumber <= currentBlockNumber) {
|
|
121
146
|
return currentBlockNumber;
|
|
122
147
|
}
|
|
123
148
|
this.log.debug(`World State at ${currentBlockNumber} told to sync to ${targetBlockNumber ?? 'latest'}`);
|
|
149
|
+
// If the archiver is behind the target block, force an archiver sync
|
|
150
|
+
if (targetBlockNumber) {
|
|
151
|
+
const archiverLatestBlock = BlockNumber(await this.l2BlockSource.getBlockNumber());
|
|
152
|
+
if (archiverLatestBlock < targetBlockNumber) {
|
|
153
|
+
this.log.debug(`Archiver is at ${archiverLatestBlock} behind target block ${targetBlockNumber}.`);
|
|
154
|
+
await this.l2BlockSource.syncImmediate();
|
|
155
|
+
}
|
|
156
|
+
}
|
|
124
157
|
// Force the block stream to sync against the archiver now
|
|
125
158
|
await this.blockStream.sync();
|
|
126
159
|
// If we have been given a block number to sync to and we have not reached that number then fail
|
|
127
160
|
const updatedBlockNumber = await this.getLatestBlockNumber();
|
|
128
|
-
if (targetBlockNumber !== undefined && targetBlockNumber > updatedBlockNumber) {
|
|
129
|
-
throw new
|
|
161
|
+
if (!skipThrowIfTargetNotReached && targetBlockNumber !== undefined && targetBlockNumber > updatedBlockNumber) {
|
|
162
|
+
throw new WorldStateSynchronizerError(`Unable to sync to block number ${targetBlockNumber} (last synced is ${updatedBlockNumber})`, {
|
|
163
|
+
cause: {
|
|
164
|
+
reason: 'block_not_available',
|
|
165
|
+
previousBlockNumber: currentBlockNumber,
|
|
166
|
+
updatedBlockNumber,
|
|
167
|
+
targetBlockNumber
|
|
168
|
+
}
|
|
169
|
+
});
|
|
130
170
|
}
|
|
131
171
|
return updatedBlockNumber;
|
|
132
172
|
}
|
|
133
173
|
/** Returns the L2 block hash for a given number. Used by the L2BlockStream for detecting reorgs. */ async getL2BlockHash(number) {
|
|
134
|
-
if (number ===
|
|
174
|
+
if (number === BlockNumber.ZERO) {
|
|
135
175
|
return (await this.merkleTreeCommitted.getInitialHeader().hash()).toString();
|
|
136
176
|
}
|
|
137
177
|
if (this.latestBlockHashQuery?.hash === undefined || number !== this.latestBlockHashQuery.blockNumber) {
|
|
@@ -144,41 +184,37 @@ import { WorldStateInstrumentation } from '../instrumentation/instrumentation.js
|
|
|
144
184
|
}
|
|
145
185
|
/** Returns the latest L2 block number for each tip of the chain (latest, proven, finalized). */ async getL2Tips() {
|
|
146
186
|
const status = await this.merkleTreeDb.getStatusSummary();
|
|
147
|
-
const
|
|
187
|
+
const unfinalizedBlockHash = await this.getL2BlockHash(status.unfinalizedBlockNumber);
|
|
148
188
|
const latestBlockId = {
|
|
149
|
-
number:
|
|
150
|
-
hash:
|
|
189
|
+
number: status.unfinalizedBlockNumber,
|
|
190
|
+
hash: unfinalizedBlockHash
|
|
151
191
|
};
|
|
152
192
|
return {
|
|
153
193
|
latest: latestBlockId,
|
|
154
194
|
finalized: {
|
|
155
|
-
number:
|
|
195
|
+
number: status.finalizedBlockNumber,
|
|
156
196
|
hash: ''
|
|
157
197
|
},
|
|
158
198
|
proven: {
|
|
159
|
-
number:
|
|
199
|
+
number: this.provenBlockNumber ?? status.finalizedBlockNumber,
|
|
160
200
|
hash: ''
|
|
161
201
|
}
|
|
162
202
|
};
|
|
163
203
|
}
|
|
164
204
|
/** 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);
|
|
205
|
+
switch(event.type){
|
|
206
|
+
case 'blocks-added':
|
|
207
|
+
await this.handleL2Blocks(event.blocks.map((b)=>b.block.toL2Block()));
|
|
208
|
+
break;
|
|
209
|
+
case 'chain-pruned':
|
|
210
|
+
await this.handleChainPruned(event.block.number);
|
|
211
|
+
break;
|
|
212
|
+
case 'chain-proven':
|
|
213
|
+
await this.handleChainProven(event.block.number);
|
|
214
|
+
break;
|
|
215
|
+
case 'chain-finalized':
|
|
216
|
+
await this.handleChainFinalized(event.block.number);
|
|
217
|
+
break;
|
|
182
218
|
}
|
|
183
219
|
}
|
|
184
220
|
/**
|
|
@@ -187,18 +223,22 @@ import { WorldStateInstrumentation } from '../instrumentation/instrumentation.js
|
|
|
187
223
|
* @returns Whether the block handled was produced by this same node.
|
|
188
224
|
*/ async handleL2Blocks(l2Blocks) {
|
|
189
225
|
this.log.trace(`Handling L2 blocks ${l2Blocks[0].number} to ${l2Blocks.at(-1).number}`);
|
|
190
|
-
|
|
191
|
-
const
|
|
226
|
+
// Fetch the L1->L2 messages for the first block in a checkpoint.
|
|
227
|
+
const messagesForBlocks = new Map();
|
|
228
|
+
await Promise.all(l2Blocks.filter((b)=>b.indexWithinCheckpoint === 0).map(async (block)=>{
|
|
229
|
+
const l1ToL2Messages = await this.l2BlockSource.getL1ToL2Messages(block.checkpointNumber);
|
|
230
|
+
messagesForBlocks.set(block.number, l1ToL2Messages);
|
|
231
|
+
}));
|
|
192
232
|
let updateStatus = undefined;
|
|
193
|
-
for(
|
|
194
|
-
const [duration, result] = await elapsed(()=>this.handleL2Block(
|
|
195
|
-
this.log.
|
|
233
|
+
for (const block of l2Blocks){
|
|
234
|
+
const [duration, result] = await elapsed(()=>this.handleL2Block(block, messagesForBlocks.get(block.number) ?? []));
|
|
235
|
+
this.log.info(`World state updated with L2 block ${block.number}`, {
|
|
196
236
|
eventName: 'l2-block-handled',
|
|
197
237
|
duration,
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
oldestHistoricBlock: result.summary.oldestHistoricalBlock,
|
|
201
|
-
...
|
|
238
|
+
unfinalizedBlockNumber: BigInt(result.summary.unfinalizedBlockNumber),
|
|
239
|
+
finalizedBlockNumber: BigInt(result.summary.finalizedBlockNumber),
|
|
240
|
+
oldestHistoricBlock: BigInt(result.summary.oldestHistoricalBlock),
|
|
241
|
+
...block.getStats()
|
|
202
242
|
});
|
|
203
243
|
updateStatus = result;
|
|
204
244
|
}
|
|
@@ -213,12 +253,6 @@ import { WorldStateInstrumentation } from '../instrumentation/instrumentation.js
|
|
|
213
253
|
* @param l1ToL2Messages - The L1 to L2 messages for the block.
|
|
214
254
|
* @returns Whether the block handled was produced by this same node.
|
|
215
255
|
*/ async handleL2Block(l2Block, l1ToL2Messages) {
|
|
216
|
-
// First we check that the L1 to L2 messages hash to the block inHash.
|
|
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
256
|
this.log.trace(`Pushing L2 block ${l2Block.number} to merkle tree db `, {
|
|
223
257
|
blockNumber: l2Block.number,
|
|
224
258
|
blockHash: await l2Block.hash().then((h)=>h.toString()),
|
|
@@ -233,26 +267,28 @@ import { WorldStateInstrumentation } from '../instrumentation/instrumentation.js
|
|
|
233
267
|
}
|
|
234
268
|
async handleChainFinalized(blockNumber) {
|
|
235
269
|
this.log.verbose(`Finalized chain is now at block ${blockNumber}`);
|
|
236
|
-
const summary = await this.merkleTreeDb.
|
|
270
|
+
const summary = await this.merkleTreeDb.setFinalized(blockNumber);
|
|
237
271
|
if (this.historyToKeep === undefined) {
|
|
238
272
|
return;
|
|
239
273
|
}
|
|
240
|
-
const newHistoricBlock = summary.
|
|
274
|
+
const newHistoricBlock = summary.finalizedBlockNumber - this.historyToKeep + 1;
|
|
241
275
|
if (newHistoricBlock <= 1) {
|
|
242
276
|
return;
|
|
243
277
|
}
|
|
244
278
|
this.log.verbose(`Pruning historic blocks to ${newHistoricBlock}`);
|
|
245
|
-
const status = await this.merkleTreeDb.removeHistoricalBlocks(newHistoricBlock);
|
|
279
|
+
const status = await this.merkleTreeDb.removeHistoricalBlocks(BlockNumber(newHistoricBlock));
|
|
246
280
|
this.log.debug(`World state summary `, status.summary);
|
|
247
281
|
}
|
|
248
282
|
handleChainProven(blockNumber) {
|
|
283
|
+
this.provenBlockNumber = blockNumber;
|
|
249
284
|
this.log.debug(`Proven chain is now at block ${blockNumber}`);
|
|
250
285
|
return Promise.resolve();
|
|
251
286
|
}
|
|
252
287
|
async handleChainPruned(blockNumber) {
|
|
253
288
|
this.log.warn(`Chain pruned to block ${blockNumber}`);
|
|
254
|
-
const status = await this.merkleTreeDb.unwindBlocks(
|
|
289
|
+
const status = await this.merkleTreeDb.unwindBlocks(blockNumber);
|
|
255
290
|
this.latestBlockHashQuery = undefined;
|
|
291
|
+
this.provenBlockNumber = undefined;
|
|
256
292
|
this.instrumentation.updateWorldStateMetrics(status);
|
|
257
293
|
}
|
|
258
294
|
/**
|
|
@@ -262,16 +298,4 @@ import { WorldStateInstrumentation } from '../instrumentation/instrumentation.js
|
|
|
262
298
|
this.currentState = newState;
|
|
263
299
|
this.log.debug(`Moved to state ${WorldStateRunningState[this.currentState]}`);
|
|
264
300
|
}
|
|
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
301
|
}
|
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 {
|
|
2
|
-
import {
|
|
1
|
+
import { BlockNumber, type CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
|
+
import { L2BlockNew } 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
|
|
6
|
-
|
|
7
|
+
export declare function updateBlockState(block: L2BlockNew, 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<{
|
|
9
|
+
block: L2BlockNew;
|
|
7
10
|
messages: Fr[];
|
|
8
11
|
}>;
|
|
9
|
-
export declare function mockEmptyBlock(blockNum:
|
|
10
|
-
block:
|
|
12
|
+
export declare function mockEmptyBlock(blockNum: BlockNumber, fork: MerkleTreeWriteOperations): Promise<{
|
|
13
|
+
block: L2BlockNew;
|
|
11
14
|
messages: Fr[];
|
|
12
15
|
}>;
|
|
13
|
-
export declare function mockBlocks(from:
|
|
14
|
-
blocks:
|
|
16
|
+
export declare function mockBlocks(from: BlockNumber, count: number, numTxs: number, worldState: NativeWorldStateService): Promise<{
|
|
17
|
+
blocks: L2BlockNew[];
|
|
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("../../../stdlib/dest/checkpoint/checkpoint.js").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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXRpbHMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy90ZXN0L3V0aWxzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQU9BLE9BQU8sRUFBRSxXQUFXLEVBQUUsS0FBSyxnQkFBZ0IsRUFBRSxNQUFNLGlDQUFpQyxDQUFDO0FBRXJGLE9BQU8sRUFBRSxFQUFFLEVBQUUsTUFBTSxnQ0FBZ0MsQ0FBQztBQUNwRCxPQUFPLEVBQUUsVUFBVSxFQUFFLE1BQU0scUJBQXFCLENBQUM7QUFDakQsT0FBTyxLQUFLLEVBRVYsd0JBQXdCLEVBQ3hCLHlCQUF5QixFQUMxQixNQUFNLGlDQUFpQyxDQUFDO0FBQ3pDLE9BQU8sRUFBRSx5QkFBeUIsRUFBc0IsTUFBTSx1QkFBdUIsQ0FBQztBQUl0RixP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ANGED
|
@@ -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,EAAE,MAAM,iCAAiC,CAAC;AAErF,OAAO,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,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,UAAU,EAAE,cAAc,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,yBAAyB,iBA8C9G;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,IAAI,EAAE,yBAAyB,EAC/B,OAAO,GAAE,OAAO,CAAC,UAAU,CAAC,OAAO,yBAAyB,CAAC,CAAC,CAAC,CAAC,CAAM;;;GAOvE;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
|
@@ -1,73 +1,70 @@
|
|
|
1
1
|
import { MAX_NOTE_HASHES_PER_TX, MAX_NULLIFIERS_PER_TX, NULLIFIER_SUBTREE_HEIGHT, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/constants';
|
|
2
|
+
import { asyncMap } from '@aztec/foundation/async-map';
|
|
3
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
4
|
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
3
|
-
import { Fr } from '@aztec/foundation/
|
|
4
|
-
import {
|
|
5
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
6
|
+
import { L2BlockNew } from '@aztec/stdlib/block';
|
|
7
|
+
import { mockCheckpointAndMessages, mockL1ToL2Messages } from '@aztec/stdlib/testing';
|
|
5
8
|
import { AppendOnlyTreeSnapshot, MerkleTreeId } from '@aztec/stdlib/trees';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
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
|
-
const l1ToL2MessagesPadded = padArrayEnd(l1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP);
|
|
14
|
-
await fork.appendLeaves(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, l1ToL2MessagesPadded);
|
|
15
|
-
}
|
|
16
|
-
// Sync the indexed trees
|
|
17
|
-
{
|
|
18
|
-
// We insert the public data tree leaves with one batch per tx to avoid updating the same key twice
|
|
19
|
-
for (const txEffect of l2Block.body.txEffects){
|
|
20
|
-
await fork.batchInsert(MerkleTreeId.PUBLIC_DATA_TREE, txEffect.publicDataWrites.map((write)=>write.toBuffer()), 0);
|
|
21
|
-
const nullifiersPadded = padArrayEnd(txEffect.nullifiers, Fr.ZERO, MAX_NULLIFIERS_PER_TX);
|
|
22
|
-
await fork.batchInsert(MerkleTreeId.NULLIFIER_TREE, nullifiersPadded.map((nullifier)=>nullifier.toBuffer()), NULLIFIER_SUBTREE_HEIGHT);
|
|
9
|
+
import { BlockHeader } from '@aztec/stdlib/tx';
|
|
10
|
+
export async function updateBlockState(block, l1ToL2Messages, fork) {
|
|
11
|
+
const insertData = async (treeId, data, subTreeHeight, fork)=>{
|
|
12
|
+
for (const dataBatch of data){
|
|
13
|
+
await fork.batchInsert(treeId, dataBatch, subTreeHeight);
|
|
23
14
|
}
|
|
24
|
-
}
|
|
15
|
+
};
|
|
16
|
+
const publicDataInsert = insertData(MerkleTreeId.PUBLIC_DATA_TREE, block.body.txEffects.map((txEffect)=>txEffect.publicDataWrites.map((write)=>write.toBuffer())), 0, fork);
|
|
17
|
+
const nullifierInsert = insertData(MerkleTreeId.NULLIFIER_TREE, block.body.txEffects.map((txEffect)=>padArrayEnd(txEffect.nullifiers, Fr.ZERO, MAX_NULLIFIERS_PER_TX).map((nullifier)=>nullifier.toBuffer())), NULLIFIER_SUBTREE_HEIGHT, fork);
|
|
18
|
+
const noteHashesPadded = block.body.txEffects.flatMap((txEffect)=>padArrayEnd(txEffect.noteHashes, Fr.ZERO, MAX_NOTE_HASHES_PER_TX));
|
|
19
|
+
const l1ToL2MessagesPadded = block.indexWithinCheckpoint === 0 ? padArrayEnd(l1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP) : l1ToL2Messages;
|
|
20
|
+
const noteHashInsert = fork.appendLeaves(MerkleTreeId.NOTE_HASH_TREE, noteHashesPadded);
|
|
21
|
+
const messageInsert = fork.appendLeaves(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, l1ToL2MessagesPadded);
|
|
22
|
+
await Promise.all([
|
|
23
|
+
publicDataInsert,
|
|
24
|
+
nullifierInsert,
|
|
25
|
+
noteHashInsert,
|
|
26
|
+
messageInsert
|
|
27
|
+
]);
|
|
25
28
|
const state = await fork.getStateReference();
|
|
26
|
-
|
|
27
|
-
|
|
29
|
+
block.header = BlockHeader.from({
|
|
30
|
+
...block.header,
|
|
31
|
+
state
|
|
32
|
+
});
|
|
33
|
+
await fork.updateArchive(block.header);
|
|
28
34
|
const archiveState = await fork.getTreeInfo(MerkleTreeId.ARCHIVE);
|
|
29
|
-
|
|
35
|
+
block.archive = new AppendOnlyTreeSnapshot(Fr.fromBuffer(archiveState.root), Number(archiveState.size));
|
|
36
|
+
}
|
|
37
|
+
export async function mockBlock(blockNum, size, fork, maxEffects = 1000, numL1ToL2Messages = NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP, isFirstBlockInCheckpoint = true) {
|
|
38
|
+
const block = await L2BlockNew.random(blockNum, {
|
|
39
|
+
indexWithinCheckpoint: isFirstBlockInCheckpoint ? 0 : 1,
|
|
40
|
+
txsPerBlock: size,
|
|
41
|
+
txOptions: {
|
|
42
|
+
maxEffects
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
const l1ToL2Messages = mockL1ToL2Messages(numL1ToL2Messages);
|
|
46
|
+
await updateBlockState(block, l1ToL2Messages, fork);
|
|
30
47
|
return {
|
|
31
|
-
block
|
|
48
|
+
block,
|
|
32
49
|
messages: l1ToL2Messages
|
|
33
50
|
};
|
|
34
51
|
}
|
|
35
52
|
export async function mockEmptyBlock(blockNum, fork) {
|
|
36
|
-
const l2Block =
|
|
53
|
+
const l2Block = L2BlockNew.empty();
|
|
37
54
|
const l1ToL2Messages = Array(16).fill(0).map(Fr.zero);
|
|
38
|
-
l2Block.header.globalVariables.blockNumber =
|
|
39
|
-
|
|
40
|
-
{
|
|
41
|
-
const noteHashesPadded = l2Block.body.txEffects.flatMap((txEffect)=>padArrayEnd(txEffect.noteHashes, Fr.ZERO, MAX_NOTE_HASHES_PER_TX));
|
|
42
|
-
await fork.appendLeaves(MerkleTreeId.NOTE_HASH_TREE, noteHashesPadded);
|
|
43
|
-
const l1ToL2MessagesPadded = padArrayEnd(l1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP);
|
|
44
|
-
await fork.appendLeaves(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, l1ToL2MessagesPadded);
|
|
45
|
-
}
|
|
46
|
-
// Sync the indexed trees
|
|
47
|
-
{
|
|
48
|
-
// We insert the public data tree leaves with one batch per tx to avoid updating the same key twice
|
|
49
|
-
for (const txEffect of l2Block.body.txEffects){
|
|
50
|
-
await fork.batchInsert(MerkleTreeId.PUBLIC_DATA_TREE, txEffect.publicDataWrites.map((write)=>write.toBuffer()), 0);
|
|
51
|
-
const nullifiersPadded = padArrayEnd(txEffect.nullifiers, Fr.ZERO, MAX_NULLIFIERS_PER_TX);
|
|
52
|
-
await fork.batchInsert(MerkleTreeId.NULLIFIER_TREE, nullifiersPadded.map((nullifier)=>nullifier.toBuffer()), NULLIFIER_SUBTREE_HEIGHT);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
const state = await fork.getStateReference();
|
|
56
|
-
l2Block.header.state = state;
|
|
57
|
-
await fork.updateArchive(l2Block.header);
|
|
58
|
-
const archiveState = await fork.getTreeInfo(MerkleTreeId.ARCHIVE);
|
|
59
|
-
l2Block.archive = new AppendOnlyTreeSnapshot(Fr.fromBuffer(archiveState.root), Number(archiveState.size));
|
|
55
|
+
l2Block.header.globalVariables.blockNumber = blockNum;
|
|
56
|
+
await updateBlockState(l2Block, l1ToL2Messages, fork);
|
|
60
57
|
return {
|
|
61
58
|
block: l2Block,
|
|
62
59
|
messages: l1ToL2Messages
|
|
63
60
|
};
|
|
64
61
|
}
|
|
65
62
|
export async function mockBlocks(from, count, numTxs, worldState) {
|
|
66
|
-
const tempFork = await worldState.fork(from - 1);
|
|
63
|
+
const tempFork = await worldState.fork(BlockNumber(from - 1));
|
|
67
64
|
const blocks = [];
|
|
68
65
|
const messagesArray = [];
|
|
69
66
|
for(let blockNumber = from; blockNumber < from + count; blockNumber++){
|
|
70
|
-
const { block, messages } = await mockBlock(blockNumber, numTxs, tempFork);
|
|
67
|
+
const { block, messages } = await mockBlock(BlockNumber(blockNumber), numTxs, tempFork);
|
|
71
68
|
blocks.push(block);
|
|
72
69
|
messagesArray.push(messages);
|
|
73
70
|
}
|
|
@@ -77,6 +74,16 @@ export async function mockBlocks(from, count, numTxs, worldState) {
|
|
|
77
74
|
messages: messagesArray
|
|
78
75
|
};
|
|
79
76
|
}
|
|
77
|
+
export async function mockCheckpoint(checkpointNumber, fork, options = {}) {
|
|
78
|
+
const { checkpoint, messages } = await mockCheckpointAndMessages(checkpointNumber, options);
|
|
79
|
+
await asyncMap(checkpoint.blocks, async (block, i)=>{
|
|
80
|
+
await updateBlockState(block, i === 0 ? messages : [], fork);
|
|
81
|
+
});
|
|
82
|
+
return {
|
|
83
|
+
checkpoint,
|
|
84
|
+
messages
|
|
85
|
+
};
|
|
86
|
+
}
|
|
80
87
|
export async function assertSameState(forkA, forkB) {
|
|
81
88
|
const nativeStateRef = await forkA.getStateReference();
|
|
82
89
|
const nativeArchive = await forkA.getTreeInfo(MerkleTreeId.ARCHIVE);
|
package/dest/testing.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Fr } from '@aztec/foundation/
|
|
1
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
2
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
3
3
|
import { PublicDataTreeLeaf } from '@aztec/stdlib/trees';
|
|
4
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
|
-
//# sourceMappingURL=
|
|
10
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdGluZy5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL3Rlc3RpbmcudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQ0EsT0FBTyxFQUFFLEVBQUUsRUFBRSxNQUFNLGdDQUFnQyxDQUFDO0FBRXBELE9BQU8sS0FBSyxFQUFFLFlBQVksRUFBRSxNQUFNLDZCQUE2QixDQUFDO0FBQ2hFLE9BQU8sRUFBZ0Isa0JBQWtCLEVBQUUsTUFBTSxxQkFBcUIsQ0FBQztBQXlCdkUsZUFBTyxNQUFNLDZCQUE2QixJQUFxQixDQUFDO0FBRWhFLHdCQUFzQixnQkFBZ0IsQ0FDcEMsZUFBZSxFQUFFLFlBQVksRUFBRSxFQUMvQixzQkFBc0IsS0FBZ0MsRUFDdEQsaUJBQWlCLEdBQUUsa0JBQWtCLEVBQU87Ozs7R0FxQjdDIn0=
|
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,
|
|
1
|
+
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AAEpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAgB,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAyBvE,eAAO,MAAM,6BAA6B,IAAqB,CAAC;AAEhE,wBAAsB,gBAAgB,CACpC,eAAe,EAAE,YAAY,EAAE,EAC/B,sBAAsB,KAAgC,EACtD,iBAAiB,GAAE,kBAAkB,EAAO;;;;GAqB7C"}
|