@aztec/world-state 0.0.1-commit.fce3e4f → 0.0.1-commit.fffb133c
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/instrumentation/instrumentation.d.ts +1 -1
- package/dest/instrumentation/instrumentation.d.ts.map +1 -1
- package/dest/instrumentation/instrumentation.js +11 -42
- package/dest/native/merkle_trees_facade.d.ts +10 -4
- package/dest/native/merkle_trees_facade.d.ts.map +1 -1
- package/dest/native/merkle_trees_facade.js +37 -7
- package/dest/native/message.d.ts +12 -11
- package/dest/native/message.d.ts.map +1 -1
- package/dest/native/message.js +14 -13
- package/dest/native/native_world_state.d.ts +12 -9
- package/dest/native/native_world_state.d.ts.map +1 -1
- package/dest/native/native_world_state.js +14 -10
- package/dest/synchronizer/config.d.ts +1 -3
- package/dest/synchronizer/config.d.ts.map +1 -1
- package/dest/synchronizer/config.js +1 -6
- package/dest/synchronizer/server_world_state_synchronizer.d.ts +10 -16
- package/dest/synchronizer/server_world_state_synchronizer.d.ts.map +1 -1
- package/dest/synchronizer/server_world_state_synchronizer.js +79 -69
- package/dest/test/utils.d.ts +12 -5
- package/dest/test/utils.d.ts.map +1 -1
- package/dest/test/utils.js +54 -50
- package/dest/testing.d.ts +2 -2
- package/dest/testing.d.ts.map +1 -1
- package/dest/testing.js +1 -1
- package/dest/world-state-db/merkle_tree_db.d.ts +10 -11
- package/dest/world-state-db/merkle_tree_db.d.ts.map +1 -1
- package/package.json +13 -13
- package/src/instrumentation/instrumentation.ts +10 -42
- package/src/native/merkle_trees_facade.ts +39 -5
- package/src/native/message.ts +23 -22
- package/src/native/native_world_state.ts +35 -21
- package/src/synchronizer/config.ts +1 -14
- package/src/synchronizer/server_world_state_synchronizer.ts +94 -96
- package/src/test/utils.ts +86 -91
- package/src/testing.ts +1 -1
- package/src/world-state-db/merkle_tree_db.ts +13 -14
package/dest/testing.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { GENESIS_ARCHIVE_ROOT } from '@aztec/constants';
|
|
2
|
-
import { Fr } from '@aztec/foundation/
|
|
2
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
3
|
import { computeFeePayerBalanceLeafSlot } from '@aztec/protocol-contracts/fee-juice';
|
|
4
4
|
import { MerkleTreeId, PublicDataTreeLeaf } from '@aztec/stdlib/trees';
|
|
5
5
|
import { NativeWorldStateService } from './native/index.js';
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
3
|
import type { IndexedTreeSnapshot, TreeSnapshot } from '@aztec/merkle-tree';
|
|
3
|
-
import type { L2Block
|
|
4
|
-
import type { ForkMerkleTreeOperations, MerkleTreeReadOperations } from '@aztec/stdlib/interfaces/server';
|
|
4
|
+
import type { L2Block } from '@aztec/stdlib/block';
|
|
5
|
+
import type { ForkMerkleTreeOperations, MerkleTreeReadOperations, ReadonlyWorldStateAccess } from '@aztec/stdlib/interfaces/server';
|
|
5
6
|
import type { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
6
7
|
import type { WorldStateStatusFull, WorldStateStatusSummary } from '../native/message.js';
|
|
7
8
|
/**
|
|
@@ -28,15 +29,13 @@ export type TreeSnapshots = {
|
|
|
28
29
|
[MerkleTreeId.L1_TO_L2_MESSAGE_TREE]: TreeSnapshot<Fr>;
|
|
29
30
|
[MerkleTreeId.ARCHIVE]: TreeSnapshot<Fr>;
|
|
30
31
|
};
|
|
31
|
-
export interface MerkleTreeAdminDatabase extends ForkMerkleTreeOperations {
|
|
32
|
+
export interface MerkleTreeAdminDatabase extends ForkMerkleTreeOperations, ReadonlyWorldStateAccess {
|
|
32
33
|
/**
|
|
33
34
|
* Handles a single L2 block (i.e. Inserts the new note hashes into the merkle tree).
|
|
34
35
|
* @param block - The L2 block to handle.
|
|
35
36
|
* @param l1ToL2Messages - The L1 to L2 messages for the block.
|
|
36
|
-
* @param isFirstBlock - Whether the block is the first block in a checkpoint. Temporary hack to only insert l1 to l2
|
|
37
|
-
* messages for the first block in a checkpoint. TODO(#17027) Remove this.
|
|
38
37
|
*/
|
|
39
|
-
handleL2BlockAndMessages(block: L2Block
|
|
38
|
+
handleL2BlockAndMessages(block: L2Block, l1ToL2Messages: Fr[]): Promise<WorldStateStatusFull>;
|
|
40
39
|
/**
|
|
41
40
|
* Gets a handle that allows reading the latest committed state
|
|
42
41
|
*/
|
|
@@ -46,19 +45,19 @@ export interface MerkleTreeAdminDatabase extends ForkMerkleTreeOperations {
|
|
|
46
45
|
* @param toBlockNumber The block number of the new oldest historical block
|
|
47
46
|
* @returns The new WorldStateStatus
|
|
48
47
|
*/
|
|
49
|
-
removeHistoricalBlocks(toBlockNumber:
|
|
48
|
+
removeHistoricalBlocks(toBlockNumber: BlockNumber): Promise<WorldStateStatusFull>;
|
|
50
49
|
/**
|
|
51
50
|
* Removes all pending blocks down to but not including the given block number
|
|
52
51
|
* @param toBlockNumber The block number of the new tip of the pending chain,
|
|
53
52
|
* @returns The new WorldStateStatus
|
|
54
53
|
*/
|
|
55
|
-
unwindBlocks(toBlockNumber:
|
|
54
|
+
unwindBlocks(toBlockNumber: BlockNumber): Promise<WorldStateStatusFull>;
|
|
56
55
|
/**
|
|
57
56
|
* Advances the finalized block number to be the number provided
|
|
58
57
|
* @param toBlockNumber The block number that is now the tip of the finalized chain
|
|
59
58
|
* @returns The new WorldStateStatus
|
|
60
59
|
*/
|
|
61
|
-
setFinalized(toBlockNumber:
|
|
60
|
+
setFinalized(toBlockNumber: BlockNumber): Promise<WorldStateStatusSummary>;
|
|
62
61
|
/**
|
|
63
62
|
* Gets the current status summary of the database.
|
|
64
63
|
* @returns The current WorldStateStatus.
|
|
@@ -69,4 +68,4 @@ export interface MerkleTreeAdminDatabase extends ForkMerkleTreeOperations {
|
|
|
69
68
|
/** Deletes the db. */
|
|
70
69
|
clear(): Promise<void>;
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UksQ0FBQyxDQUFDO0NBQ3hCIn0=
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"merkle_tree_db.d.ts","sourceRoot":"","sources":["../../src/world-state-db/merkle_tree_db.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"merkle_tree_db.d.ts","sourceRoot":"","sources":["../../src/world-state-db/merkle_tree_db.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AACzD,OAAO,KAAK,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC5E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,KAAK,EACV,wBAAwB,EACxB,wBAAwB,EACxB,wBAAwB,EACzB,MAAM,iCAAiC,CAAC;AACzC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAExD,OAAO,KAAK,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAE1F;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,2BAA2B,QAA4B,CAAC;AAErE,eAAO,MAAM,6BAA6B,QAAmD,CAAC;AAE9F,MAAM,MAAM,aAAa,GAAG;IAC1B,CAAC,YAAY,CAAC,cAAc,CAAC,EAAE,mBAAmB,CAAC;IACnD,CAAC,YAAY,CAAC,cAAc,CAAC,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,EAAE,wBAAwB;IACjG;;;;OAIG;IACH,wBAAwB,CAAC,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;IAE9F;;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": "0.0.1-commit.
|
|
3
|
+
"version": "0.0.1-commit.fffb133c",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dest/index.js",
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
"tsconfig": "./tsconfig.json"
|
|
19
19
|
},
|
|
20
20
|
"scripts": {
|
|
21
|
-
"build": "yarn clean &&
|
|
22
|
-
"build:dev": "
|
|
21
|
+
"build": "yarn clean && ../scripts/tsc.sh",
|
|
22
|
+
"build:dev": "../scripts/tsc.sh --watch",
|
|
23
23
|
"clean": "rm -rf ./dest .tsbuildinfo",
|
|
24
24
|
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
|
|
25
25
|
},
|
|
@@ -64,23 +64,23 @@
|
|
|
64
64
|
]
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
|
-
"@aztec/constants": "0.0.1-commit.
|
|
68
|
-
"@aztec/foundation": "0.0.1-commit.
|
|
69
|
-
"@aztec/kv-store": "0.0.1-commit.
|
|
70
|
-
"@aztec/merkle-tree": "0.0.1-commit.
|
|
71
|
-
"@aztec/native": "0.0.1-commit.
|
|
72
|
-
"@aztec/protocol-contracts": "0.0.1-commit.
|
|
73
|
-
"@aztec/stdlib": "0.0.1-commit.
|
|
74
|
-
"@aztec/telemetry-client": "0.0.1-commit.
|
|
67
|
+
"@aztec/constants": "0.0.1-commit.fffb133c",
|
|
68
|
+
"@aztec/foundation": "0.0.1-commit.fffb133c",
|
|
69
|
+
"@aztec/kv-store": "0.0.1-commit.fffb133c",
|
|
70
|
+
"@aztec/merkle-tree": "0.0.1-commit.fffb133c",
|
|
71
|
+
"@aztec/native": "0.0.1-commit.fffb133c",
|
|
72
|
+
"@aztec/protocol-contracts": "0.0.1-commit.fffb133c",
|
|
73
|
+
"@aztec/stdlib": "0.0.1-commit.fffb133c",
|
|
74
|
+
"@aztec/telemetry-client": "0.0.1-commit.fffb133c",
|
|
75
75
|
"tslib": "^2.4.0",
|
|
76
76
|
"zod": "^3.23.8"
|
|
77
77
|
},
|
|
78
78
|
"devDependencies": {
|
|
79
|
-
"@aztec/archiver": "0.0.1-commit.
|
|
79
|
+
"@aztec/archiver": "0.0.1-commit.fffb133c",
|
|
80
80
|
"@jest/globals": "^30.0.0",
|
|
81
81
|
"@types/jest": "^30.0.0",
|
|
82
82
|
"@types/node": "^22.15.17",
|
|
83
|
-
"@typescript/native-preview": "7.0.0-dev.
|
|
83
|
+
"@typescript/native-preview": "7.0.0-dev.20260113.1",
|
|
84
84
|
"jest": "^30.0.0",
|
|
85
85
|
"jest-mock-extended": "^4.0.0",
|
|
86
86
|
"ts-node": "^10.9.1",
|
|
@@ -7,7 +7,6 @@ import {
|
|
|
7
7
|
Metrics,
|
|
8
8
|
type TelemetryClient,
|
|
9
9
|
type UpDownCounter,
|
|
10
|
-
ValueType,
|
|
11
10
|
} from '@aztec/telemetry-client';
|
|
12
11
|
|
|
13
12
|
import {
|
|
@@ -46,56 +45,25 @@ export class WorldStateInstrumentation {
|
|
|
46
45
|
private log: Logger = createLogger('world-state:instrumentation'),
|
|
47
46
|
) {
|
|
48
47
|
const meter = telemetry.getMeter('World State');
|
|
49
|
-
this.dbMapSize = meter.createGauge(Metrics.WORLD_STATE_DB_MAP_SIZE
|
|
50
|
-
description: `The current configured map size for each merkle tree`,
|
|
51
|
-
valueType: ValueType.INT,
|
|
52
|
-
});
|
|
48
|
+
this.dbMapSize = meter.createGauge(Metrics.WORLD_STATE_DB_MAP_SIZE);
|
|
53
49
|
|
|
54
|
-
this.dbPhysicalSize = meter.createGauge(Metrics.WORLD_STATE_DB_PHYSICAL_SIZE
|
|
55
|
-
description: `The current physical disk space used for each database`,
|
|
56
|
-
valueType: ValueType.INT,
|
|
57
|
-
});
|
|
50
|
+
this.dbPhysicalSize = meter.createGauge(Metrics.WORLD_STATE_DB_PHYSICAL_SIZE);
|
|
58
51
|
|
|
59
|
-
this.treeSize = meter.createGauge(Metrics.WORLD_STATE_TREE_SIZE
|
|
60
|
-
description: `The current number of leaves in each merkle tree`,
|
|
61
|
-
valueType: ValueType.INT,
|
|
62
|
-
});
|
|
52
|
+
this.treeSize = meter.createGauge(Metrics.WORLD_STATE_TREE_SIZE);
|
|
63
53
|
|
|
64
|
-
this.unfinalizedHeight = meter.createGauge(Metrics.WORLD_STATE_UNFINALIZED_HEIGHT
|
|
65
|
-
description: `The unfinalized block height of each merkle tree`,
|
|
66
|
-
valueType: ValueType.INT,
|
|
67
|
-
});
|
|
54
|
+
this.unfinalizedHeight = meter.createGauge(Metrics.WORLD_STATE_UNFINALIZED_HEIGHT);
|
|
68
55
|
|
|
69
|
-
this.finalizedHeight = meter.createGauge(Metrics.WORLD_STATE_FINALIZED_HEIGHT
|
|
70
|
-
description: `The finalized block height of each merkle tree`,
|
|
71
|
-
valueType: ValueType.INT,
|
|
72
|
-
});
|
|
56
|
+
this.finalizedHeight = meter.createGauge(Metrics.WORLD_STATE_FINALIZED_HEIGHT);
|
|
73
57
|
|
|
74
|
-
this.oldestBlock = meter.createGauge(Metrics.WORLD_STATE_OLDEST_BLOCK
|
|
75
|
-
description: `The oldest historical block of each merkle tree`,
|
|
76
|
-
valueType: ValueType.INT,
|
|
77
|
-
});
|
|
58
|
+
this.oldestBlock = meter.createGauge(Metrics.WORLD_STATE_OLDEST_BLOCK);
|
|
78
59
|
|
|
79
|
-
this.dbUsedSize = meter.createGauge(Metrics.WORLD_STATE_DB_USED_SIZE
|
|
80
|
-
description: `The current used database size for each db of each merkle tree`,
|
|
81
|
-
valueType: ValueType.INT,
|
|
82
|
-
});
|
|
60
|
+
this.dbUsedSize = meter.createGauge(Metrics.WORLD_STATE_DB_USED_SIZE);
|
|
83
61
|
|
|
84
|
-
this.dbNumItems = meter.createGauge(Metrics.WORLD_STATE_DB_NUM_ITEMS
|
|
85
|
-
description: `The current number of items in each database of each merkle tree`,
|
|
86
|
-
valueType: ValueType.INT,
|
|
87
|
-
});
|
|
62
|
+
this.dbNumItems = meter.createGauge(Metrics.WORLD_STATE_DB_NUM_ITEMS);
|
|
88
63
|
|
|
89
|
-
this.requestHistogram = meter.createHistogram(Metrics.WORLD_STATE_REQUEST_TIME
|
|
90
|
-
description: 'The round trip time of world state requests',
|
|
91
|
-
unit: 'us',
|
|
92
|
-
valueType: ValueType.INT,
|
|
93
|
-
});
|
|
64
|
+
this.requestHistogram = meter.createHistogram(Metrics.WORLD_STATE_REQUEST_TIME);
|
|
94
65
|
|
|
95
|
-
this.criticalErrors = meter.createUpDownCounter(Metrics.WORLD_STATE_CRITICAL_ERROR_COUNT
|
|
96
|
-
description: 'The number of critical errors in the world state',
|
|
97
|
-
valueType: ValueType.INT,
|
|
98
|
-
});
|
|
66
|
+
this.criticalErrors = meter.createUpDownCounter(Metrics.WORLD_STATE_CRITICAL_ERROR_COUNT);
|
|
99
67
|
}
|
|
100
68
|
|
|
101
69
|
private updateTreeStats(treeDbStats: TreeDBStats, treeMeta: TreeMeta, tree: MerkleTreeId) {
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
2
4
|
import { serializeToBuffer } from '@aztec/foundation/serialize';
|
|
5
|
+
import { sleep } from '@aztec/foundation/sleep';
|
|
3
6
|
import { type IndexedTreeLeafPreimage, SiblingPath } from '@aztec/foundation/trees';
|
|
4
7
|
import type {
|
|
5
8
|
BatchInsertionResult,
|
|
@@ -191,19 +194,26 @@ export class MerkleTreesFacade implements MerkleTreeReadOperations {
|
|
|
191
194
|
async getBlockNumbersForLeafIndices<ID extends MerkleTreeId>(
|
|
192
195
|
treeId: ID,
|
|
193
196
|
leafIndices: bigint[],
|
|
194
|
-
): Promise<(
|
|
197
|
+
): Promise<(BlockNumber | undefined)[]> {
|
|
195
198
|
const response = await this.instance.call(WorldStateMessageType.GET_BLOCK_NUMBERS_FOR_LEAF_INDICES, {
|
|
196
199
|
treeId,
|
|
197
200
|
revision: this.revision,
|
|
198
201
|
leafIndices,
|
|
199
202
|
});
|
|
200
203
|
|
|
201
|
-
return response.blockNumbers.map(x => (x === undefined || x === null ? undefined :
|
|
204
|
+
return response.blockNumbers.map(x => (x === undefined || x === null ? undefined : BlockNumber(Number(x))));
|
|
202
205
|
}
|
|
203
206
|
}
|
|
204
207
|
|
|
205
208
|
export class MerkleTreesForkFacade extends MerkleTreesFacade implements MerkleTreeWriteOperations {
|
|
206
|
-
|
|
209
|
+
private log = createLogger('world-state:merkle-trees-fork-facade');
|
|
210
|
+
|
|
211
|
+
constructor(
|
|
212
|
+
instance: NativeWorldStateInstance,
|
|
213
|
+
initialHeader: BlockHeader,
|
|
214
|
+
revision: WorldStateRevision,
|
|
215
|
+
private opts: { closeDelayMs?: number },
|
|
216
|
+
) {
|
|
207
217
|
assert.notEqual(revision.forkId, 0, 'Fork ID must be set');
|
|
208
218
|
assert.equal(revision.includeUncommitted, true, 'Fork must include uncommitted data');
|
|
209
219
|
super(instance, initialHeader, revision);
|
|
@@ -282,7 +292,31 @@ export class MerkleTreesForkFacade extends MerkleTreesFacade implements MerkleTr
|
|
|
282
292
|
|
|
283
293
|
public async close(): Promise<void> {
|
|
284
294
|
assert.notEqual(this.revision.forkId, 0, 'Fork ID must be set');
|
|
285
|
-
|
|
295
|
+
try {
|
|
296
|
+
await this.instance.call(WorldStateMessageType.DELETE_FORK, { forkId: this.revision.forkId });
|
|
297
|
+
} catch (err: any) {
|
|
298
|
+
// Ignore errors due to native instance being closed during shutdown.
|
|
299
|
+
// This can happen when validators are still processing block proposals while the node is stopping.
|
|
300
|
+
if (err?.message === 'Native instance is closed') {
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
throw err;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
async [Symbol.dispose](): Promise<void> {
|
|
308
|
+
if (this.opts.closeDelayMs) {
|
|
309
|
+
void sleep(this.opts.closeDelayMs)
|
|
310
|
+
.then(() => this.close())
|
|
311
|
+
.catch(err => {
|
|
312
|
+
if (err && 'message' in err && err.message === 'Native instance is closed') {
|
|
313
|
+
return; // Ignore errors due to native instance being closed
|
|
314
|
+
}
|
|
315
|
+
this.log.warn('Error closing MerkleTreesForkFacade after delay', { err });
|
|
316
|
+
});
|
|
317
|
+
} else {
|
|
318
|
+
await this.close();
|
|
319
|
+
}
|
|
286
320
|
}
|
|
287
321
|
|
|
288
322
|
public async createCheckpoint(): Promise<void> {
|
package/src/native/message.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
3
|
import type { Tuple } from '@aztec/foundation/serialize';
|
|
3
4
|
import { AppendOnlyTreeSnapshot, MerkleTreeId } from '@aztec/stdlib/trees';
|
|
4
5
|
import type { StateReference } from '@aztec/stdlib/tx';
|
|
@@ -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,10 +1,11 @@
|
|
|
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';
|
|
4
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
5
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
4
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
5
6
|
import { tryRmDir } from '@aztec/foundation/fs';
|
|
6
7
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
7
|
-
import type { L2Block
|
|
8
|
+
import type { L2Block } from '@aztec/stdlib/block';
|
|
8
9
|
import { DatabaseVersionManager } from '@aztec/stdlib/database-version';
|
|
9
10
|
import type {
|
|
10
11
|
IndexedTreeId,
|
|
@@ -134,7 +135,9 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
|
|
|
134
135
|
|
|
135
136
|
// the initial header _must_ be the first element in the archive tree
|
|
136
137
|
// if this assertion fails, check that the hashing done in Header in yarn-project matches the initial header hash done in world_state.cpp
|
|
137
|
-
const indices = await committed.findLeafIndices(MerkleTreeId.ARCHIVE, [
|
|
138
|
+
const indices = await committed.findLeafIndices(MerkleTreeId.ARCHIVE, [
|
|
139
|
+
(await this.initialHeader.hash()).toField(),
|
|
140
|
+
]);
|
|
138
141
|
const initialHeaderIndex = indices[0];
|
|
139
142
|
assert.strictEqual(initialHeaderIndex, 0n, 'Invalid initial archive state');
|
|
140
143
|
}
|
|
@@ -150,7 +153,7 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
|
|
|
150
153
|
return new MerkleTreesFacade(this.instance, this.initialHeader!, WorldStateRevision.empty());
|
|
151
154
|
}
|
|
152
155
|
|
|
153
|
-
public getSnapshot(blockNumber:
|
|
156
|
+
public getSnapshot(blockNumber: BlockNumber): MerkleTreeReadOperations {
|
|
154
157
|
return new MerkleTreesFacade(
|
|
155
158
|
this.instance,
|
|
156
159
|
this.initialHeader!,
|
|
@@ -158,16 +161,24 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
|
|
|
158
161
|
);
|
|
159
162
|
}
|
|
160
163
|
|
|
161
|
-
public async fork(
|
|
164
|
+
public async fork(
|
|
165
|
+
blockNumber?: BlockNumber,
|
|
166
|
+
opts: { closeDelayMs?: number } = {},
|
|
167
|
+
): Promise<MerkleTreeWriteOperations> {
|
|
162
168
|
const resp = await this.instance.call(WorldStateMessageType.CREATE_FORK, {
|
|
163
169
|
latest: blockNumber === undefined,
|
|
164
|
-
blockNumber: blockNumber ??
|
|
170
|
+
blockNumber: blockNumber ?? BlockNumber.ZERO,
|
|
165
171
|
canonical: true,
|
|
166
172
|
});
|
|
167
173
|
return new MerkleTreesForkFacade(
|
|
168
174
|
this.instance,
|
|
169
175
|
this.initialHeader!,
|
|
170
|
-
new WorldStateRevision(
|
|
176
|
+
new WorldStateRevision(
|
|
177
|
+
/*forkId=*/ resp.forkId,
|
|
178
|
+
/* blockNumber=*/ BlockNumber.ZERO,
|
|
179
|
+
/* includeUncommitted=*/ true,
|
|
180
|
+
),
|
|
181
|
+
opts,
|
|
171
182
|
);
|
|
172
183
|
}
|
|
173
184
|
|
|
@@ -175,21 +186,24 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
|
|
|
175
186
|
return this.initialHeader!;
|
|
176
187
|
}
|
|
177
188
|
|
|
178
|
-
public async handleL2BlockAndMessages(
|
|
179
|
-
l2Block
|
|
180
|
-
l1ToL2Messages
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
);
|
|
189
|
+
public async handleL2BlockAndMessages(l2Block: L2Block, l1ToL2Messages: Fr[]): Promise<WorldStateStatusFull> {
|
|
190
|
+
const isFirstBlock = l2Block.indexWithinCheckpoint === 0;
|
|
191
|
+
if (!isFirstBlock && l1ToL2Messages.length > 0) {
|
|
192
|
+
throw new Error(
|
|
193
|
+
`L1 to L2 messages must be empty for non-first blocks, but got ${l1ToL2Messages.length} messages for block ${l2Block.number}.`,
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// We have to pad the given l1 to l2 messages, and the note hashes and nullifiers within tx effects, because that's
|
|
198
|
+
// how the trees are built by circuits.
|
|
189
199
|
const paddedL1ToL2Messages = isFirstBlock
|
|
190
200
|
? padArrayEnd<Fr, number>(l1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP)
|
|
191
201
|
: [];
|
|
192
202
|
|
|
203
|
+
const paddedNoteHashes = l2Block.body.txEffects.flatMap(txEffect =>
|
|
204
|
+
padArrayEnd(txEffect.noteHashes, Fr.ZERO, MAX_NOTE_HASHES_PER_TX),
|
|
205
|
+
);
|
|
206
|
+
|
|
193
207
|
const paddedNullifiers = l2Block.body.txEffects
|
|
194
208
|
.flatMap(txEffect => padArrayEnd(txEffect.nullifiers, Fr.ZERO, MAX_NULLIFIERS_PER_TX))
|
|
195
209
|
.map(nullifier => new NullifierLeaf(nullifier));
|
|
@@ -256,7 +270,7 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
|
|
|
256
270
|
* @param toBlockNumber The block number that is now the tip of the finalized chain
|
|
257
271
|
* @returns The new WorldStateStatus
|
|
258
272
|
*/
|
|
259
|
-
public async setFinalized(toBlockNumber:
|
|
273
|
+
public async setFinalized(toBlockNumber: BlockNumber) {
|
|
260
274
|
try {
|
|
261
275
|
await this.instance.call(
|
|
262
276
|
WorldStateMessageType.FINALIZE_BLOCKS,
|
|
@@ -279,7 +293,7 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
|
|
|
279
293
|
* @param toBlockNumber The block number of the new oldest historical block
|
|
280
294
|
* @returns The new WorldStateStatus
|
|
281
295
|
*/
|
|
282
|
-
public async removeHistoricalBlocks(toBlockNumber:
|
|
296
|
+
public async removeHistoricalBlocks(toBlockNumber: BlockNumber) {
|
|
283
297
|
try {
|
|
284
298
|
return await this.instance.call(
|
|
285
299
|
WorldStateMessageType.REMOVE_HISTORICAL_BLOCKS,
|
|
@@ -301,7 +315,7 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
|
|
|
301
315
|
* @param toBlockNumber The block number of the new tip of the pending chain,
|
|
302
316
|
* @returns The new WorldStateStatus
|
|
303
317
|
*/
|
|
304
|
-
public async unwindBlocks(toBlockNumber:
|
|
318
|
+
public async unwindBlocks(toBlockNumber: BlockNumber) {
|
|
305
319
|
try {
|
|
306
320
|
return await this.instance.call(
|
|
307
321
|
WorldStateMessageType.UNWIND_BLOCKS,
|
|
@@ -1,18 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type ConfigMappingsType,
|
|
3
|
-
booleanConfigHelper,
|
|
4
|
-
getConfigFromMappings,
|
|
5
|
-
numberConfigHelper,
|
|
6
|
-
} from '@aztec/foundation/config';
|
|
1
|
+
import { type ConfigMappingsType, getConfigFromMappings, numberConfigHelper } from '@aztec/foundation/config';
|
|
7
2
|
|
|
8
3
|
/** World State synchronizer configuration values. */
|
|
9
4
|
export interface WorldStateConfig {
|
|
10
5
|
/** The frequency in which to check. */
|
|
11
6
|
worldStateBlockCheckIntervalMS: number;
|
|
12
7
|
|
|
13
|
-
/** Whether to follow only the proven chain. */
|
|
14
|
-
worldStateProvenBlocksOnly: boolean;
|
|
15
|
-
|
|
16
8
|
/** Size of the batch for each get-blocks request from the synchronizer to the archiver. */
|
|
17
9
|
worldStateBlockRequestBatchSize?: number;
|
|
18
10
|
|
|
@@ -48,11 +40,6 @@ export const worldStateConfigMappings: ConfigMappingsType<WorldStateConfig> = {
|
|
|
48
40
|
defaultValue: 100,
|
|
49
41
|
description: 'The frequency in which to check.',
|
|
50
42
|
},
|
|
51
|
-
worldStateProvenBlocksOnly: {
|
|
52
|
-
env: 'WS_PROVEN_BLOCKS_ONLY',
|
|
53
|
-
description: 'Whether to follow only the proven chain.',
|
|
54
|
-
...booleanConfigHelper(),
|
|
55
|
-
},
|
|
56
43
|
worldStateBlockRequestBatchSize: {
|
|
57
44
|
env: 'WS_BLOCK_REQUEST_BATCH_SIZE',
|
|
58
45
|
parseEnv: (val: string | undefined) => (val ? +val : undefined),
|