@aztec/world-state 3.0.0-nightly.20251202 → 3.0.0-nightly.20251204
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/native/merkle_trees_facade.d.ts +3 -2
- package/dest/native/merkle_trees_facade.d.ts.map +1 -1
- package/dest/native/merkle_trees_facade.js +2 -1
- package/dest/native/message.d.ts +11 -10
- package/dest/native/message.d.ts.map +1 -1
- package/dest/native/message.js +13 -12
- package/dest/native/native_world_state.d.ts +7 -6
- package/dest/native/native_world_state.d.ts.map +1 -1
- package/dest/native/native_world_state.js +3 -2
- package/dest/synchronizer/server_world_state_synchronizer.d.ts +7 -6
- package/dest/synchronizer/server_world_state_synchronizer.d.ts.map +1 -1
- package/dest/synchronizer/server_world_state_synchronizer.js +24 -23
- package/dest/test/utils.d.ts +5 -4
- package/dest/test/utils.d.ts.map +1 -1
- package/dest/test/utils.js +4 -3
- package/dest/world-state-db/merkle_tree_db.d.ts +5 -4
- package/dest/world-state-db/merkle_tree_db.d.ts.map +1 -1
- package/package.json +10 -10
- package/src/native/merkle_trees_facade.ts +3 -2
- package/src/native/message.ts +22 -21
- package/src/native/native_world_state.ts +12 -7
- package/src/synchronizer/server_world_state_synchronizer.ts +40 -34
- package/src/test/utils.ts +20 -6
- package/src/world-state-db/merkle_tree_db.ts +4 -3
package/dest/test/utils.d.ts
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
1
2
|
import { Fr } from '@aztec/foundation/fields';
|
|
2
3
|
import { L2Block } from '@aztec/stdlib/block';
|
|
3
4
|
import type { MerkleTreeReadOperations, MerkleTreeWriteOperations } from '@aztec/stdlib/interfaces/server';
|
|
4
5
|
import type { NativeWorldStateService } from '../native/native_world_state.js';
|
|
5
|
-
export declare function mockBlock(blockNum:
|
|
6
|
+
export declare function mockBlock(blockNum: BlockNumber, size: number, fork: MerkleTreeWriteOperations, maxEffects?: number | undefined): Promise<{
|
|
6
7
|
block: L2Block;
|
|
7
8
|
messages: Fr[];
|
|
8
9
|
}>;
|
|
9
|
-
export declare function mockEmptyBlock(blockNum:
|
|
10
|
+
export declare function mockEmptyBlock(blockNum: BlockNumber, fork: MerkleTreeWriteOperations): Promise<{
|
|
10
11
|
block: L2Block;
|
|
11
12
|
messages: Fr[];
|
|
12
13
|
}>;
|
|
13
|
-
export declare function mockBlocks(from:
|
|
14
|
+
export declare function mockBlocks(from: BlockNumber, count: number, numTxs: number, worldState: NativeWorldStateService): Promise<{
|
|
14
15
|
blocks: L2Block[];
|
|
15
16
|
messages: Fr[][];
|
|
16
17
|
}>;
|
|
17
18
|
export declare function assertSameState(forkA: MerkleTreeReadOperations, forkB: MerkleTreeReadOperations): Promise<void>;
|
|
18
19
|
export declare function compareChains(left: MerkleTreeReadOperations, right: MerkleTreeReadOperations): Promise<void>;
|
|
19
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
20
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXRpbHMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy90ZXN0L3V0aWxzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQU1BLE9BQU8sRUFBRSxXQUFXLEVBQUUsTUFBTSxpQ0FBaUMsQ0FBQztBQUU5RCxPQUFPLEVBQUUsRUFBRSxFQUFFLE1BQU0sMEJBQTBCLENBQUM7QUFDOUMsT0FBTyxFQUFFLE9BQU8sRUFBRSxNQUFNLHFCQUFxQixDQUFDO0FBQzlDLE9BQU8sS0FBSyxFQUVWLHdCQUF3QixFQUN4Qix5QkFBeUIsRUFDMUIsTUFBTSxpQ0FBaUMsQ0FBQztBQUd6QyxPQUFPLEtBQUssRUFBRSx1QkFBdUIsRUFBRSxNQUFNLGlDQUFpQyxDQUFDO0FBRS9FLHdCQUFzQixTQUFTLENBQzdCLFFBQVEsRUFBRSxXQUFXLEVBQ3JCLElBQUksRUFBRSxNQUFNLEVBQ1osSUFBSSxFQUFFLHlCQUF5QixFQUMvQixVQUFVLEdBQUUsTUFBTSxHQUFHLFNBQWdCOzs7R0E4RHRDO0FBRUQsd0JBQXNCLGNBQWMsQ0FBQyxRQUFRLEVBQUUsV0FBVyxFQUFFLElBQUksRUFBRSx5QkFBeUI7OztHQWlEMUY7QUFFRCx3QkFBc0IsVUFBVSxDQUM5QixJQUFJLEVBQUUsV0FBVyxFQUNqQixLQUFLLEVBQUUsTUFBTSxFQUNiLE1BQU0sRUFBRSxNQUFNLEVBQ2QsVUFBVSxFQUFFLHVCQUF1Qjs7O0dBZXBDO0FBRUQsd0JBQXNCLGVBQWUsQ0FBQyxLQUFLLEVBQUUsd0JBQXdCLEVBQUUsS0FBSyxFQUFFLHdCQUF3QixpQkFRckc7QUFFRCx3QkFBc0IsYUFBYSxDQUFDLElBQUksRUFBRSx3QkFBd0IsRUFBRSxLQUFLLEVBQUUsd0JBQXdCLGlCQVlsRyJ9
|
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":"
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/test/utils.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAE9D,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,WAAW,EACrB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,yBAAyB,EAC/B,UAAU,GAAE,MAAM,GAAG,SAAgB;;;GA8DtC;AAED,wBAAsB,cAAc,CAAC,QAAQ,EAAE,WAAW,EAAE,IAAI,EAAE,yBAAyB;;;GAiD1F;AAED,wBAAsB,UAAU,CAC9B,IAAI,EAAE,WAAW,EACjB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,uBAAuB;;;GAepC;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,10 +1,11 @@
|
|
|
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 { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
3
|
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
3
4
|
import { Fr } from '@aztec/foundation/fields';
|
|
4
5
|
import { L2Block } from '@aztec/stdlib/block';
|
|
5
6
|
import { AppendOnlyTreeSnapshot, MerkleTreeId } from '@aztec/stdlib/trees';
|
|
6
7
|
export async function mockBlock(blockNum, size, fork, maxEffects = 1000) {
|
|
7
|
-
const l2Block = await L2Block.random(blockNum, size, undefined, undefined, undefined, undefined, maxEffects);
|
|
8
|
+
const l2Block = await L2Block.random(BlockNumber(Number(blockNum)), size, undefined, undefined, undefined, undefined, maxEffects);
|
|
8
9
|
const l1ToL2Messages = Array(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP).fill(0).map(Fr.random);
|
|
9
10
|
{
|
|
10
11
|
const insertData = async (treeId, data, subTreeHeight, fork)=>{
|
|
@@ -66,11 +67,11 @@ export async function mockEmptyBlock(blockNum, fork) {
|
|
|
66
67
|
};
|
|
67
68
|
}
|
|
68
69
|
export async function mockBlocks(from, count, numTxs, worldState) {
|
|
69
|
-
const tempFork = await worldState.fork(from - 1);
|
|
70
|
+
const tempFork = await worldState.fork(BlockNumber(from - 1));
|
|
70
71
|
const blocks = [];
|
|
71
72
|
const messagesArray = [];
|
|
72
73
|
for(let blockNumber = from; blockNumber < from + count; blockNumber++){
|
|
73
|
-
const { block, messages } = await mockBlock(blockNumber, numTxs, tempFork);
|
|
74
|
+
const { block, messages } = await mockBlock(BlockNumber(blockNumber), numTxs, tempFork);
|
|
74
75
|
blocks.push(block);
|
|
75
76
|
messagesArray.push(messages);
|
|
76
77
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
1
2
|
import type { Fr } from '@aztec/foundation/fields';
|
|
2
3
|
import type { IndexedTreeSnapshot, TreeSnapshot } from '@aztec/merkle-tree';
|
|
3
4
|
import type { L2Block, L2BlockNew } from '@aztec/stdlib/block';
|
|
@@ -46,19 +47,19 @@ export interface MerkleTreeAdminDatabase extends ForkMerkleTreeOperations {
|
|
|
46
47
|
* @param toBlockNumber The block number of the new oldest historical block
|
|
47
48
|
* @returns The new WorldStateStatus
|
|
48
49
|
*/
|
|
49
|
-
removeHistoricalBlocks(toBlockNumber:
|
|
50
|
+
removeHistoricalBlocks(toBlockNumber: BlockNumber): Promise<WorldStateStatusFull>;
|
|
50
51
|
/**
|
|
51
52
|
* Removes all pending blocks down to but not including the given block number
|
|
52
53
|
* @param toBlockNumber The block number of the new tip of the pending chain,
|
|
53
54
|
* @returns The new WorldStateStatus
|
|
54
55
|
*/
|
|
55
|
-
unwindBlocks(toBlockNumber:
|
|
56
|
+
unwindBlocks(toBlockNumber: BlockNumber): Promise<WorldStateStatusFull>;
|
|
56
57
|
/**
|
|
57
58
|
* Advances the finalized block number to be the number provided
|
|
58
59
|
* @param toBlockNumber The block number that is now the tip of the finalized chain
|
|
59
60
|
* @returns The new WorldStateStatus
|
|
60
61
|
*/
|
|
61
|
-
setFinalized(toBlockNumber:
|
|
62
|
+
setFinalized(toBlockNumber: BlockNumber): Promise<WorldStateStatusSummary>;
|
|
62
63
|
/**
|
|
63
64
|
* Gets the current status summary of the database.
|
|
64
65
|
* @returns The current WorldStateStatus.
|
|
@@ -69,4 +70,4 @@ export interface MerkleTreeAdminDatabase extends ForkMerkleTreeOperations {
|
|
|
69
70
|
/** Deletes the db. */
|
|
70
71
|
clear(): Promise<void>;
|
|
71
72
|
}
|
|
72
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
73
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWVya2xlX3RyZWVfZGIuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy93b3JsZC1zdGF0ZS1kYi9tZXJrbGVfdHJlZV9kYi50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFDQSxPQUFPLEVBQUUsV0FBVyxFQUFFLE1BQU0saUNBQWlDLENBQUM7QUFDOUQsT0FBTyxLQUFLLEVBQUUsRUFBRSxFQUFFLE1BQU0sMEJBQTBCLENBQUM7QUFDbkQsT0FBTyxLQUFLLEVBQUUsbUJBQW1CLEVBQUUsWUFBWSxFQUFFLE1BQU0sb0JBQW9CLENBQUM7QUFDNUUsT0FBTyxLQUFLLEVBQUUsT0FBTyxFQUFFLFVBQVUsRUFBRSxNQUFNLHFCQUFxQixDQUFDO0FBQy9ELE9BQU8sS0FBSyxFQUFFLHdCQUF3QixFQUFFLHdCQUF3QixFQUFFLE1BQU0saUNBQWlDLENBQUM7QUFDMUcsT0FBTyxLQUFLLEVBQUUsWUFBWSxFQUFFLE1BQU0scUJBQXFCLENBQUM7QUFFeEQsT0FBTyxLQUFLLEVBQUUsb0JBQW9CLEVBQUUsdUJBQXVCLEVBQUUsTUFBTSxzQkFBc0IsQ0FBQztBQUUxRjs7Ozs7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AAC,EAAE,YAAY,CAAC,EAAE,CAAC,CAAC;IAChD,CAAC,YAAY,CAAC,gBAAgB,CAAC,EAAE,mBAAmB,CAAC;IACrD,CAAC,YAAY,CAAC,qBAAqB,CAAC,EAAE,YAAY,CAAC,EAAE,CAAC,CAAC;IACvD,CAAC,YAAY,CAAC,OAAO,CAAC,EAAE,YAAY,CAAC,EAAE,CAAC,CAAC;CAC1C,CAAC;AAEF,MAAM,WAAW,uBAAwB,SAAQ,wBAAwB;IACvE;;;;;;OAMG;IACH,wBAAwB,CACtB,KAAK,EAAE,OAAO,GAAG,UAAU,EAC3B,cAAc,EAAE,EAAE,EAAE,EACpB,YAAY,CAAC,EAAE,OAAO,GACrB,OAAO,CAAC,oBAAoB,CAAC,CAAC;IAEjC;;OAEG;IACH,YAAY,IAAI,wBAAwB,CAAC;IAEzC;;;;OAIG;IACH,sBAAsB,CAAC,aAAa,EAAE,WAAW,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;IAElF;;;;OAIG;IACH,YAAY,CAAC,aAAa,EAAE,WAAW,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;IAExE;;;;OAIG;IACH,YAAY,CAAC,aAAa,EAAE,WAAW,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAAC;IAE3E;;;OAGG;IACH,gBAAgB,IAAI,OAAO,CAAC,uBAAuB,CAAC,CAAC;IAErD,yBAAyB;IACzB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEvB,sBAAsB;IACtB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/world-state",
|
|
3
|
-
"version": "3.0.0-nightly.
|
|
3
|
+
"version": "3.0.0-nightly.20251204",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dest/index.js",
|
|
@@ -64,19 +64,19 @@
|
|
|
64
64
|
]
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
|
-
"@aztec/constants": "3.0.0-nightly.
|
|
68
|
-
"@aztec/foundation": "3.0.0-nightly.
|
|
69
|
-
"@aztec/kv-store": "3.0.0-nightly.
|
|
70
|
-
"@aztec/merkle-tree": "3.0.0-nightly.
|
|
71
|
-
"@aztec/native": "3.0.0-nightly.
|
|
72
|
-
"@aztec/protocol-contracts": "3.0.0-nightly.
|
|
73
|
-
"@aztec/stdlib": "3.0.0-nightly.
|
|
74
|
-
"@aztec/telemetry-client": "3.0.0-nightly.
|
|
67
|
+
"@aztec/constants": "3.0.0-nightly.20251204",
|
|
68
|
+
"@aztec/foundation": "3.0.0-nightly.20251204",
|
|
69
|
+
"@aztec/kv-store": "3.0.0-nightly.20251204",
|
|
70
|
+
"@aztec/merkle-tree": "3.0.0-nightly.20251204",
|
|
71
|
+
"@aztec/native": "3.0.0-nightly.20251204",
|
|
72
|
+
"@aztec/protocol-contracts": "3.0.0-nightly.20251204",
|
|
73
|
+
"@aztec/stdlib": "3.0.0-nightly.20251204",
|
|
74
|
+
"@aztec/telemetry-client": "3.0.0-nightly.20251204",
|
|
75
75
|
"tslib": "^2.4.0",
|
|
76
76
|
"zod": "^3.23.8"
|
|
77
77
|
},
|
|
78
78
|
"devDependencies": {
|
|
79
|
-
"@aztec/archiver": "3.0.0-nightly.
|
|
79
|
+
"@aztec/archiver": "3.0.0-nightly.20251204",
|
|
80
80
|
"@jest/globals": "^30.0.0",
|
|
81
81
|
"@types/jest": "^30.0.0",
|
|
82
82
|
"@types/node": "^22.15.17",
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
1
2
|
import { Fr } from '@aztec/foundation/fields';
|
|
2
3
|
import { serializeToBuffer } from '@aztec/foundation/serialize';
|
|
3
4
|
import { type IndexedTreeLeafPreimage, SiblingPath } from '@aztec/foundation/trees';
|
|
@@ -191,14 +192,14 @@ export class MerkleTreesFacade implements MerkleTreeReadOperations {
|
|
|
191
192
|
async getBlockNumbersForLeafIndices<ID extends MerkleTreeId>(
|
|
192
193
|
treeId: ID,
|
|
193
194
|
leafIndices: bigint[],
|
|
194
|
-
): Promise<(
|
|
195
|
+
): Promise<(BlockNumber | undefined)[]> {
|
|
195
196
|
const response = await this.instance.call(WorldStateMessageType.GET_BLOCK_NUMBERS_FOR_LEAF_INDICES, {
|
|
196
197
|
treeId,
|
|
197
198
|
revision: this.revision,
|
|
198
199
|
leafIndices,
|
|
199
200
|
});
|
|
200
201
|
|
|
201
|
-
return response.blockNumbers.map(x => (x === undefined || x === null ? undefined :
|
|
202
|
+
return response.blockNumbers.map(x => (x === undefined || x === null ? undefined : BlockNumber(Number(x))));
|
|
202
203
|
}
|
|
203
204
|
}
|
|
204
205
|
|
package/src/native/message.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
1
2
|
import { Fr } from '@aztec/foundation/fields';
|
|
2
3
|
import type { Tuple } from '@aztec/foundation/serialize';
|
|
3
4
|
import { AppendOnlyTreeSnapshot, MerkleTreeId } from '@aztec/stdlib/trees';
|
|
@@ -56,11 +57,11 @@ interface WithTreeId {
|
|
|
56
57
|
|
|
57
58
|
export interface WorldStateStatusSummary {
|
|
58
59
|
/** Last block number that can still be unwound. */
|
|
59
|
-
unfinalizedBlockNumber:
|
|
60
|
+
unfinalizedBlockNumber: BlockNumber;
|
|
60
61
|
/** Last block number that is finalized and cannot be unwound. */
|
|
61
|
-
finalizedBlockNumber:
|
|
62
|
+
finalizedBlockNumber: BlockNumber;
|
|
62
63
|
/** Oldest block still available for historical queries and forks. */
|
|
63
|
-
oldestHistoricalBlock:
|
|
64
|
+
oldestHistoricalBlock: BlockNumber;
|
|
64
65
|
/** Whether the trees are in sync with each other */
|
|
65
66
|
treesAreSynched: boolean;
|
|
66
67
|
}
|
|
@@ -81,11 +82,11 @@ export interface TreeMeta {
|
|
|
81
82
|
/** The tree's initial root value */
|
|
82
83
|
initialRoot: Fr;
|
|
83
84
|
/** The current oldest historical block number of the tree */
|
|
84
|
-
oldestHistoricBlock:
|
|
85
|
+
oldestHistoricBlock: BlockNumber;
|
|
85
86
|
/** The current unfinalized block number of the tree */
|
|
86
|
-
unfinalizedBlockHeight:
|
|
87
|
+
unfinalizedBlockHeight: BlockNumber;
|
|
87
88
|
/** The current finalized block number of the tree */
|
|
88
|
-
finalizedBlockHeight:
|
|
89
|
+
finalizedBlockHeight: BlockNumber;
|
|
89
90
|
}
|
|
90
91
|
|
|
91
92
|
export interface DBStats {
|
|
@@ -173,9 +174,9 @@ export function buildEmptyTreeMeta() {
|
|
|
173
174
|
depth: 0,
|
|
174
175
|
size: 0n,
|
|
175
176
|
committedSize: 0n,
|
|
176
|
-
unfinalizedBlockHeight:
|
|
177
|
-
finalizedBlockHeight:
|
|
178
|
-
oldestHistoricBlock:
|
|
177
|
+
unfinalizedBlockHeight: BlockNumber.ZERO,
|
|
178
|
+
finalizedBlockHeight: BlockNumber.ZERO,
|
|
179
|
+
oldestHistoricBlock: BlockNumber.ZERO,
|
|
179
180
|
root: Fr.ZERO,
|
|
180
181
|
initialRoot: Fr.ZERO,
|
|
181
182
|
initialSize: 0n,
|
|
@@ -204,9 +205,9 @@ export function buildEmptyWorldStateDBStats() {
|
|
|
204
205
|
|
|
205
206
|
export function buildEmptyWorldStateSummary() {
|
|
206
207
|
return {
|
|
207
|
-
unfinalizedBlockNumber:
|
|
208
|
-
finalizedBlockNumber:
|
|
209
|
-
oldestHistoricalBlock:
|
|
208
|
+
unfinalizedBlockNumber: BlockNumber.ZERO,
|
|
209
|
+
finalizedBlockNumber: BlockNumber.ZERO,
|
|
210
|
+
oldestHistoricalBlock: BlockNumber.ZERO,
|
|
210
211
|
treesAreSynched: true,
|
|
211
212
|
} as WorldStateStatusSummary;
|
|
212
213
|
}
|
|
@@ -220,9 +221,9 @@ export function buildEmptyWorldStateStatusFull() {
|
|
|
220
221
|
}
|
|
221
222
|
|
|
222
223
|
export function sanitizeSummary(summary: WorldStateStatusSummary) {
|
|
223
|
-
summary.finalizedBlockNumber = BigInt(summary.finalizedBlockNumber);
|
|
224
|
-
summary.unfinalizedBlockNumber = BigInt(summary.unfinalizedBlockNumber);
|
|
225
|
-
summary.oldestHistoricalBlock = BigInt(summary.oldestHistoricalBlock);
|
|
224
|
+
summary.finalizedBlockNumber = BlockNumber.fromBigInt(BigInt(summary.finalizedBlockNumber));
|
|
225
|
+
summary.unfinalizedBlockNumber = BlockNumber.fromBigInt(BigInt(summary.unfinalizedBlockNumber));
|
|
226
|
+
summary.oldestHistoricalBlock = BlockNumber.fromBigInt(BigInt(summary.oldestHistoricalBlock));
|
|
226
227
|
return summary;
|
|
227
228
|
}
|
|
228
229
|
|
|
@@ -234,11 +235,11 @@ export function sanitizeDBStats(stats: DBStats) {
|
|
|
234
235
|
|
|
235
236
|
export function sanitizeMeta(meta: TreeMeta) {
|
|
236
237
|
meta.committedSize = BigInt(meta.committedSize);
|
|
237
|
-
meta.finalizedBlockHeight = BigInt(meta.finalizedBlockHeight);
|
|
238
|
+
meta.finalizedBlockHeight = BlockNumber.fromBigInt(BigInt(meta.finalizedBlockHeight));
|
|
238
239
|
meta.initialSize = BigInt(meta.initialSize);
|
|
239
|
-
meta.oldestHistoricBlock = BigInt(meta.oldestHistoricBlock);
|
|
240
|
+
meta.oldestHistoricBlock = BlockNumber.fromBigInt(BigInt(meta.oldestHistoricBlock));
|
|
240
241
|
meta.size = BigInt(meta.size);
|
|
241
|
-
meta.unfinalizedBlockHeight = BigInt(meta.unfinalizedBlockHeight);
|
|
242
|
+
meta.unfinalizedBlockHeight = BlockNumber.fromBigInt(BigInt(meta.unfinalizedBlockHeight));
|
|
242
243
|
return meta;
|
|
243
244
|
}
|
|
244
245
|
|
|
@@ -310,7 +311,7 @@ interface WithLeafValues {
|
|
|
310
311
|
}
|
|
311
312
|
|
|
312
313
|
interface BlockShiftRequest extends WithCanonicalForkId {
|
|
313
|
-
toBlockNumber:
|
|
314
|
+
toBlockNumber: BlockNumber;
|
|
314
315
|
}
|
|
315
316
|
|
|
316
317
|
interface WithLeaves {
|
|
@@ -409,7 +410,7 @@ interface UpdateArchiveRequest extends WithForkId {
|
|
|
409
410
|
}
|
|
410
411
|
|
|
411
412
|
interface SyncBlockRequest extends WithCanonicalForkId {
|
|
412
|
-
blockNumber:
|
|
413
|
+
blockNumber: BlockNumber;
|
|
413
414
|
blockStateRef: BlockStateReference;
|
|
414
415
|
blockHeaderHash: Fr;
|
|
415
416
|
paddedNoteHashes: readonly SerializedLeafValue[];
|
|
@@ -420,7 +421,7 @@ interface SyncBlockRequest extends WithCanonicalForkId {
|
|
|
420
421
|
|
|
421
422
|
interface CreateForkRequest extends WithCanonicalForkId {
|
|
422
423
|
latest: boolean;
|
|
423
|
-
blockNumber:
|
|
424
|
+
blockNumber: BlockNumber;
|
|
424
425
|
}
|
|
425
426
|
|
|
426
427
|
interface CreateForkResponse {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { MAX_NOTE_HASHES_PER_TX, MAX_NULLIFIERS_PER_TX, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/constants';
|
|
2
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
3
|
import { fromEntries, padArrayEnd } from '@aztec/foundation/collection';
|
|
3
4
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
4
5
|
import { Fr } from '@aztec/foundation/fields';
|
|
@@ -150,7 +151,7 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
|
|
|
150
151
|
return new MerkleTreesFacade(this.instance, this.initialHeader!, WorldStateRevision.empty());
|
|
151
152
|
}
|
|
152
153
|
|
|
153
|
-
public getSnapshot(blockNumber:
|
|
154
|
+
public getSnapshot(blockNumber: BlockNumber): MerkleTreeReadOperations {
|
|
154
155
|
return new MerkleTreesFacade(
|
|
155
156
|
this.instance,
|
|
156
157
|
this.initialHeader!,
|
|
@@ -158,16 +159,20 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
|
|
|
158
159
|
);
|
|
159
160
|
}
|
|
160
161
|
|
|
161
|
-
public async fork(blockNumber?:
|
|
162
|
+
public async fork(blockNumber?: BlockNumber): Promise<MerkleTreeWriteOperations> {
|
|
162
163
|
const resp = await this.instance.call(WorldStateMessageType.CREATE_FORK, {
|
|
163
164
|
latest: blockNumber === undefined,
|
|
164
|
-
blockNumber: blockNumber ??
|
|
165
|
+
blockNumber: blockNumber ?? BlockNumber.ZERO,
|
|
165
166
|
canonical: true,
|
|
166
167
|
});
|
|
167
168
|
return new MerkleTreesForkFacade(
|
|
168
169
|
this.instance,
|
|
169
170
|
this.initialHeader!,
|
|
170
|
-
new WorldStateRevision(
|
|
171
|
+
new WorldStateRevision(
|
|
172
|
+
/*forkId=*/ resp.forkId,
|
|
173
|
+
/* blockNumber=*/ BlockNumber.ZERO,
|
|
174
|
+
/* includeUncommitted=*/ true,
|
|
175
|
+
),
|
|
171
176
|
);
|
|
172
177
|
}
|
|
173
178
|
|
|
@@ -256,7 +261,7 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
|
|
|
256
261
|
* @param toBlockNumber The block number that is now the tip of the finalized chain
|
|
257
262
|
* @returns The new WorldStateStatus
|
|
258
263
|
*/
|
|
259
|
-
public async setFinalized(toBlockNumber:
|
|
264
|
+
public async setFinalized(toBlockNumber: BlockNumber) {
|
|
260
265
|
try {
|
|
261
266
|
await this.instance.call(
|
|
262
267
|
WorldStateMessageType.FINALIZE_BLOCKS,
|
|
@@ -279,7 +284,7 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
|
|
|
279
284
|
* @param toBlockNumber The block number of the new oldest historical block
|
|
280
285
|
* @returns The new WorldStateStatus
|
|
281
286
|
*/
|
|
282
|
-
public async removeHistoricalBlocks(toBlockNumber:
|
|
287
|
+
public async removeHistoricalBlocks(toBlockNumber: BlockNumber) {
|
|
283
288
|
try {
|
|
284
289
|
return await this.instance.call(
|
|
285
290
|
WorldStateMessageType.REMOVE_HISTORICAL_BLOCKS,
|
|
@@ -301,7 +306,7 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
|
|
|
301
306
|
* @param toBlockNumber The block number of the new tip of the pending chain,
|
|
302
307
|
* @returns The new WorldStateStatus
|
|
303
308
|
*/
|
|
304
|
-
public async unwindBlocks(toBlockNumber:
|
|
309
|
+
public async unwindBlocks(toBlockNumber: BlockNumber) {
|
|
305
310
|
try {
|
|
306
311
|
return await this.instance.call(
|
|
307
312
|
WorldStateMessageType.UNWIND_BLOCKS,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { L1_TO_L2_MSG_SUBTREE_HEIGHT } from '@aztec/constants';
|
|
2
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
3
|
import { SHA256Trunc } from '@aztec/foundation/crypto';
|
|
3
4
|
import type { Fr } from '@aztec/foundation/fields';
|
|
4
5
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
@@ -45,17 +46,17 @@ export class ServerWorldStateSynchronizer
|
|
|
45
46
|
{
|
|
46
47
|
private readonly merkleTreeCommitted: MerkleTreeReadOperations;
|
|
47
48
|
|
|
48
|
-
private latestBlockNumberAtStart =
|
|
49
|
+
private latestBlockNumberAtStart = BlockNumber.ZERO;
|
|
49
50
|
private historyToKeep: number | undefined;
|
|
50
51
|
private currentState: WorldStateRunningState = WorldStateRunningState.IDLE;
|
|
51
|
-
private latestBlockHashQuery: { blockNumber:
|
|
52
|
+
private latestBlockHashQuery: { blockNumber: BlockNumber; hash: string | undefined } | undefined = undefined;
|
|
52
53
|
|
|
53
54
|
private syncPromise = promiseWithResolvers<void>();
|
|
54
55
|
protected blockStream: L2BlockStream | undefined;
|
|
55
56
|
|
|
56
57
|
// WorldState doesn't track the proven block number, it only tracks the latest tips of the pending chain and the finalized chain
|
|
57
58
|
// store the proven block number here, in the synchronizer, so that we don't end up spamming the logs with 'chain-proved' events
|
|
58
|
-
private provenBlockNumber:
|
|
59
|
+
private provenBlockNumber: BlockNumber | undefined;
|
|
59
60
|
|
|
60
61
|
constructor(
|
|
61
62
|
private readonly merkleTreeDb: MerkleTreeAdminDatabase,
|
|
@@ -77,11 +78,11 @@ export class ServerWorldStateSynchronizer
|
|
|
77
78
|
return this.merkleTreeDb.getCommitted();
|
|
78
79
|
}
|
|
79
80
|
|
|
80
|
-
public getSnapshot(blockNumber:
|
|
81
|
+
public getSnapshot(blockNumber: BlockNumber): MerkleTreeReadOperations {
|
|
81
82
|
return this.merkleTreeDb.getSnapshot(blockNumber);
|
|
82
83
|
}
|
|
83
84
|
|
|
84
|
-
public fork(blockNumber?:
|
|
85
|
+
public fork(blockNumber?: BlockNumber): Promise<MerkleTreeWriteOperations> {
|
|
85
86
|
return this.merkleTreeDb.fork(blockNumber);
|
|
86
87
|
}
|
|
87
88
|
|
|
@@ -102,9 +103,11 @@ export class ServerWorldStateSynchronizer
|
|
|
102
103
|
}
|
|
103
104
|
|
|
104
105
|
// Get the current latest block number
|
|
105
|
-
this.latestBlockNumberAtStart =
|
|
106
|
-
|
|
107
|
-
|
|
106
|
+
this.latestBlockNumberAtStart = BlockNumber(
|
|
107
|
+
await (this.config.worldStateProvenBlocksOnly
|
|
108
|
+
? this.l2BlockSource.getProvenBlockNumber()
|
|
109
|
+
: this.l2BlockSource.getBlockNumber()),
|
|
110
|
+
);
|
|
108
111
|
|
|
109
112
|
const blockToDownloadFrom = (await this.getLatestBlockNumber()) + 1;
|
|
110
113
|
|
|
@@ -147,10 +150,10 @@ export class ServerWorldStateSynchronizer
|
|
|
147
150
|
public async status(): Promise<WorldStateSynchronizerStatus> {
|
|
148
151
|
const summary = await this.merkleTreeDb.getStatusSummary();
|
|
149
152
|
const status: WorldStateSyncStatus = {
|
|
150
|
-
latestBlockNumber:
|
|
151
|
-
latestBlockHash: (await this.getL2BlockHash(
|
|
152
|
-
finalizedBlockNumber:
|
|
153
|
-
oldestHistoricBlockNumber:
|
|
153
|
+
latestBlockNumber: summary.unfinalizedBlockNumber,
|
|
154
|
+
latestBlockHash: (await this.getL2BlockHash(summary.unfinalizedBlockNumber)) ?? '',
|
|
155
|
+
finalizedBlockNumber: summary.finalizedBlockNumber,
|
|
156
|
+
oldestHistoricBlockNumber: summary.oldestHistoricalBlock,
|
|
154
157
|
treesAreSynched: summary.treesAreSynched,
|
|
155
158
|
};
|
|
156
159
|
return {
|
|
@@ -184,7 +187,10 @@ export class ServerWorldStateSynchronizer
|
|
|
184
187
|
* @param skipThrowIfTargetNotReached - Whether to skip throwing if the target block number is not reached.
|
|
185
188
|
* @returns A promise that resolves with the block number the world state was synced to
|
|
186
189
|
*/
|
|
187
|
-
public async syncImmediate(
|
|
190
|
+
public async syncImmediate(
|
|
191
|
+
targetBlockNumber?: BlockNumber,
|
|
192
|
+
skipThrowIfTargetNotReached?: boolean,
|
|
193
|
+
): Promise<BlockNumber> {
|
|
188
194
|
if (this.currentState !== WorldStateRunningState.RUNNING) {
|
|
189
195
|
throw new Error(`World State is not running. Unable to perform sync.`);
|
|
190
196
|
}
|
|
@@ -202,7 +208,7 @@ export class ServerWorldStateSynchronizer
|
|
|
202
208
|
|
|
203
209
|
// If the archiver is behind the target block, force an archiver sync
|
|
204
210
|
if (targetBlockNumber) {
|
|
205
|
-
const archiverLatestBlock = await this.l2BlockSource.getBlockNumber();
|
|
211
|
+
const archiverLatestBlock = BlockNumber(await this.l2BlockSource.getBlockNumber());
|
|
206
212
|
if (archiverLatestBlock < targetBlockNumber) {
|
|
207
213
|
this.log.debug(`Archiver is at ${archiverLatestBlock} behind target block ${targetBlockNumber}.`);
|
|
208
214
|
await this.l2BlockSource.syncImmediate();
|
|
@@ -232,8 +238,8 @@ export class ServerWorldStateSynchronizer
|
|
|
232
238
|
}
|
|
233
239
|
|
|
234
240
|
/** Returns the L2 block hash for a given number. Used by the L2BlockStream for detecting reorgs. */
|
|
235
|
-
public async getL2BlockHash(number:
|
|
236
|
-
if (number ===
|
|
241
|
+
public async getL2BlockHash(number: BlockNumber): Promise<string | undefined> {
|
|
242
|
+
if (number === BlockNumber.ZERO) {
|
|
237
243
|
return (await this.merkleTreeCommitted.getInitialHeader().hash()).toString();
|
|
238
244
|
}
|
|
239
245
|
if (this.latestBlockHashQuery?.hash === undefined || number !== this.latestBlockHashQuery.blockNumber) {
|
|
@@ -250,13 +256,13 @@ export class ServerWorldStateSynchronizer
|
|
|
250
256
|
/** Returns the latest L2 block number for each tip of the chain (latest, proven, finalized). */
|
|
251
257
|
public async getL2Tips(): Promise<L2Tips> {
|
|
252
258
|
const status = await this.merkleTreeDb.getStatusSummary();
|
|
253
|
-
const unfinalizedBlockHash = await this.getL2BlockHash(
|
|
254
|
-
const latestBlockId: L2BlockId = { number:
|
|
259
|
+
const unfinalizedBlockHash = await this.getL2BlockHash(status.unfinalizedBlockNumber);
|
|
260
|
+
const latestBlockId: L2BlockId = { number: status.unfinalizedBlockNumber, hash: unfinalizedBlockHash! };
|
|
255
261
|
|
|
256
262
|
return {
|
|
257
263
|
latest: latestBlockId,
|
|
258
|
-
finalized: { number:
|
|
259
|
-
proven: { number:
|
|
264
|
+
finalized: { number: status.finalizedBlockNumber, hash: '' },
|
|
265
|
+
proven: { number: this.provenBlockNumber ?? status.finalizedBlockNumber, hash: '' }, // TODO(palla/reorg): Using finalized as proven for now
|
|
260
266
|
};
|
|
261
267
|
}
|
|
262
268
|
|
|
@@ -267,13 +273,13 @@ export class ServerWorldStateSynchronizer
|
|
|
267
273
|
await this.handleL2Blocks(event.blocks.map(b => b.block));
|
|
268
274
|
break;
|
|
269
275
|
case 'chain-pruned':
|
|
270
|
-
await this.handleChainPruned(event.block.number);
|
|
276
|
+
await this.handleChainPruned(BlockNumber(event.block.number));
|
|
271
277
|
break;
|
|
272
278
|
case 'chain-proven':
|
|
273
|
-
await this.handleChainProven(event.block.number);
|
|
279
|
+
await this.handleChainProven(BlockNumber(event.block.number));
|
|
274
280
|
break;
|
|
275
281
|
case 'chain-finalized':
|
|
276
|
-
await this.handleChainFinalized(event.block.number);
|
|
282
|
+
await this.handleChainFinalized(BlockNumber(event.block.number));
|
|
277
283
|
break;
|
|
278
284
|
}
|
|
279
285
|
}
|
|
@@ -295,9 +301,9 @@ export class ServerWorldStateSynchronizer
|
|
|
295
301
|
this.log.info(`World state updated with L2 block ${l2Blocks[i].number}`, {
|
|
296
302
|
eventName: 'l2-block-handled',
|
|
297
303
|
duration,
|
|
298
|
-
unfinalizedBlockNumber: result.summary.unfinalizedBlockNumber,
|
|
299
|
-
finalizedBlockNumber: result.summary.finalizedBlockNumber,
|
|
300
|
-
oldestHistoricBlock: result.summary.oldestHistoricalBlock,
|
|
304
|
+
unfinalizedBlockNumber: BigInt(result.summary.unfinalizedBlockNumber),
|
|
305
|
+
finalizedBlockNumber: BigInt(result.summary.finalizedBlockNumber),
|
|
306
|
+
oldestHistoricBlock: BigInt(result.summary.oldestHistoricalBlock),
|
|
301
307
|
...l2Blocks[i].getStats(),
|
|
302
308
|
} satisfies L2BlockHandledStats);
|
|
303
309
|
updateStatus = result;
|
|
@@ -337,14 +343,14 @@ export class ServerWorldStateSynchronizer
|
|
|
337
343
|
return result;
|
|
338
344
|
}
|
|
339
345
|
|
|
340
|
-
private async handleChainFinalized(blockNumber:
|
|
346
|
+
private async handleChainFinalized(blockNumber: BlockNumber) {
|
|
341
347
|
this.log.verbose(`Finalized chain is now at block ${blockNumber}`);
|
|
342
|
-
const summary = await this.merkleTreeDb.setFinalized(
|
|
348
|
+
const summary = await this.merkleTreeDb.setFinalized(blockNumber);
|
|
343
349
|
if (this.historyToKeep === undefined) {
|
|
344
350
|
return;
|
|
345
351
|
}
|
|
346
|
-
const newHistoricBlock = summary.finalizedBlockNumber -
|
|
347
|
-
if (newHistoricBlock <= 1) {
|
|
352
|
+
const newHistoricBlock = BlockNumber(summary.finalizedBlockNumber - this.historyToKeep + 1);
|
|
353
|
+
if (newHistoricBlock <= BlockNumber(1)) {
|
|
348
354
|
return;
|
|
349
355
|
}
|
|
350
356
|
this.log.verbose(`Pruning historic blocks to ${newHistoricBlock}`);
|
|
@@ -352,15 +358,15 @@ export class ServerWorldStateSynchronizer
|
|
|
352
358
|
this.log.debug(`World state summary `, status.summary);
|
|
353
359
|
}
|
|
354
360
|
|
|
355
|
-
private handleChainProven(blockNumber:
|
|
356
|
-
this.provenBlockNumber =
|
|
361
|
+
private handleChainProven(blockNumber: BlockNumber) {
|
|
362
|
+
this.provenBlockNumber = blockNumber;
|
|
357
363
|
this.log.debug(`Proven chain is now at block ${blockNumber}`);
|
|
358
364
|
return Promise.resolve();
|
|
359
365
|
}
|
|
360
366
|
|
|
361
|
-
private async handleChainPruned(blockNumber:
|
|
367
|
+
private async handleChainPruned(blockNumber: BlockNumber) {
|
|
362
368
|
this.log.warn(`Chain pruned to block ${blockNumber}`);
|
|
363
|
-
const status = await this.merkleTreeDb.unwindBlocks(
|
|
369
|
+
const status = await this.merkleTreeDb.unwindBlocks(blockNumber);
|
|
364
370
|
this.latestBlockHashQuery = undefined;
|
|
365
371
|
this.provenBlockNumber = undefined;
|
|
366
372
|
this.instrumentation.updateWorldStateMetrics(status);
|
package/src/test/utils.ts
CHANGED
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
NULLIFIER_SUBTREE_HEIGHT,
|
|
5
5
|
NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP,
|
|
6
6
|
} from '@aztec/constants';
|
|
7
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
7
8
|
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
8
9
|
import { Fr } from '@aztec/foundation/fields';
|
|
9
10
|
import { L2Block } from '@aztec/stdlib/block';
|
|
@@ -17,12 +18,20 @@ import { AppendOnlyTreeSnapshot, MerkleTreeId } from '@aztec/stdlib/trees';
|
|
|
17
18
|
import type { NativeWorldStateService } from '../native/native_world_state.js';
|
|
18
19
|
|
|
19
20
|
export async function mockBlock(
|
|
20
|
-
blockNum:
|
|
21
|
+
blockNum: BlockNumber,
|
|
21
22
|
size: number,
|
|
22
23
|
fork: MerkleTreeWriteOperations,
|
|
23
24
|
maxEffects: number | undefined = 1000, // Defaults to the maximum tx effects.
|
|
24
25
|
) {
|
|
25
|
-
const l2Block = await L2Block.random(
|
|
26
|
+
const l2Block = await L2Block.random(
|
|
27
|
+
BlockNumber(Number(blockNum)),
|
|
28
|
+
size,
|
|
29
|
+
undefined,
|
|
30
|
+
undefined,
|
|
31
|
+
undefined,
|
|
32
|
+
undefined,
|
|
33
|
+
maxEffects,
|
|
34
|
+
);
|
|
26
35
|
const l1ToL2Messages = Array(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP).fill(0).map(Fr.random);
|
|
27
36
|
|
|
28
37
|
{
|
|
@@ -76,7 +85,7 @@ export async function mockBlock(
|
|
|
76
85
|
};
|
|
77
86
|
}
|
|
78
87
|
|
|
79
|
-
export async function mockEmptyBlock(blockNum:
|
|
88
|
+
export async function mockEmptyBlock(blockNum: BlockNumber, fork: MerkleTreeWriteOperations) {
|
|
80
89
|
const l2Block = L2Block.empty();
|
|
81
90
|
const l1ToL2Messages = Array(16).fill(0).map(Fr.zero);
|
|
82
91
|
|
|
@@ -127,13 +136,18 @@ export async function mockEmptyBlock(blockNum: number, fork: MerkleTreeWriteOper
|
|
|
127
136
|
};
|
|
128
137
|
}
|
|
129
138
|
|
|
130
|
-
export async function mockBlocks(
|
|
131
|
-
|
|
139
|
+
export async function mockBlocks(
|
|
140
|
+
from: BlockNumber,
|
|
141
|
+
count: number,
|
|
142
|
+
numTxs: number,
|
|
143
|
+
worldState: NativeWorldStateService,
|
|
144
|
+
) {
|
|
145
|
+
const tempFork = await worldState.fork(BlockNumber(from - 1));
|
|
132
146
|
|
|
133
147
|
const blocks = [];
|
|
134
148
|
const messagesArray = [];
|
|
135
149
|
for (let blockNumber = from; blockNumber < from + count; blockNumber++) {
|
|
136
|
-
const { block, messages } = await mockBlock(blockNumber, numTxs, tempFork);
|
|
150
|
+
const { block, messages } = await mockBlock(BlockNumber(blockNumber), numTxs, tempFork);
|
|
137
151
|
blocks.push(block);
|
|
138
152
|
messagesArray.push(messages);
|
|
139
153
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { MAX_NULLIFIERS_PER_TX, MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX } from '@aztec/constants';
|
|
2
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
3
|
import type { Fr } from '@aztec/foundation/fields';
|
|
3
4
|
import type { IndexedTreeSnapshot, TreeSnapshot } from '@aztec/merkle-tree';
|
|
4
5
|
import type { L2Block, L2BlockNew } from '@aztec/stdlib/block';
|
|
@@ -58,21 +59,21 @@ export interface MerkleTreeAdminDatabase extends ForkMerkleTreeOperations {
|
|
|
58
59
|
* @param toBlockNumber The block number of the new oldest historical block
|
|
59
60
|
* @returns The new WorldStateStatus
|
|
60
61
|
*/
|
|
61
|
-
removeHistoricalBlocks(toBlockNumber:
|
|
62
|
+
removeHistoricalBlocks(toBlockNumber: BlockNumber): Promise<WorldStateStatusFull>;
|
|
62
63
|
|
|
63
64
|
/**
|
|
64
65
|
* Removes all pending blocks down to but not including the given block number
|
|
65
66
|
* @param toBlockNumber The block number of the new tip of the pending chain,
|
|
66
67
|
* @returns The new WorldStateStatus
|
|
67
68
|
*/
|
|
68
|
-
unwindBlocks(toBlockNumber:
|
|
69
|
+
unwindBlocks(toBlockNumber: BlockNumber): Promise<WorldStateStatusFull>;
|
|
69
70
|
|
|
70
71
|
/**
|
|
71
72
|
* Advances the finalized block number to be the number provided
|
|
72
73
|
* @param toBlockNumber The block number that is now the tip of the finalized chain
|
|
73
74
|
* @returns The new WorldStateStatus
|
|
74
75
|
*/
|
|
75
|
-
setFinalized(toBlockNumber:
|
|
76
|
+
setFinalized(toBlockNumber: BlockNumber): Promise<WorldStateStatusSummary>;
|
|
76
77
|
|
|
77
78
|
/**
|
|
78
79
|
* Gets the current status summary of the database.
|