@aztec/world-state 0.7.10 → 0.8.6
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/README.md +3 -3
- package/dest/index.d.ts +2 -2
- package/dest/index.js +2 -2
- package/dest/merkle-tree/merkle_tree_operations_facade.d.ts +3 -3
- package/dest/merkle-tree/merkle_tree_operations_facade.d.ts.map +1 -1
- package/dest/merkle-tree/merkle_tree_operations_facade.js +2 -2
- package/dest/{synchroniser → synchronizer}/config.d.ts +3 -3
- package/dest/{synchroniser → synchronizer}/config.d.ts.map +1 -1
- package/dest/{synchroniser → synchronizer}/config.js +3 -3
- package/dest/synchronizer/index.d.ts +3 -0
- package/dest/synchronizer/index.d.ts.map +1 -0
- package/dest/{synchroniser → synchronizer}/index.js +3 -3
- package/dest/{synchroniser/server_world_state_synchroniser.d.ts → synchronizer/server_world_state_synchronizer.d.ts} +13 -6
- package/dest/synchronizer/server_world_state_synchronizer.d.ts.map +1 -0
- package/dest/synchronizer/server_world_state_synchronizer.js +203 -0
- package/dest/{synchroniser/world_state_synchroniser.d.ts → synchronizer/world_state_synchronizer.d.ts} +11 -11
- package/dest/{synchroniser/world_state_synchroniser.d.ts.map → synchronizer/world_state_synchronizer.d.ts.map} +1 -1
- package/dest/{synchroniser/world_state_synchroniser.js → synchronizer/world_state_synchronizer.js} +2 -2
- package/dest/world-state-db/index.d.ts +5 -1
- package/dest/world-state-db/index.d.ts.map +1 -1
- package/dest/world-state-db/index.js +1 -1
- package/dest/world-state-db/merkle_trees.d.ts +9 -8
- package/dest/world-state-db/merkle_trees.d.ts.map +1 -1
- package/dest/world-state-db/merkle_trees.js +55 -44
- package/package.json +56 -6
- package/src/index.ts +2 -2
- package/src/merkle-tree/merkle_tree_operations_facade.ts +10 -3
- package/src/{synchroniser → synchronizer}/config.ts +3 -3
- package/src/synchronizer/index.ts +2 -0
- package/src/{synchroniser/server_world_state_synchroniser.ts → synchronizer/server_world_state_synchronizer.ts} +60 -10
- package/src/{synchroniser/world_state_synchroniser.ts → synchronizer/world_state_synchronizer.ts} +10 -10
- package/src/world-state-db/index.ts +6 -1
- package/src/world-state-db/merkle_trees.ts +61 -46
- package/.eslintrc.cjs +0 -1
- package/.tsbuildinfo +0 -1
- package/dest/synchroniser/index.d.ts +0 -3
- package/dest/synchroniser/index.d.ts.map +0 -1
- package/dest/synchroniser/server_world_state_synchroniser.d.ts.map +0 -1
- package/dest/synchroniser/server_world_state_synchroniser.js +0 -163
- package/dest/synchroniser/server_world_state_synchroniser.test.d.ts +0 -2
- package/dest/synchroniser/server_world_state_synchroniser.test.d.ts.map +0 -1
- package/dest/synchroniser/server_world_state_synchroniser.test.js +0 -317
- package/src/synchroniser/index.ts +0 -2
- package/src/synchroniser/server_world_state_synchroniser.test.ts +0 -428
- package/tsconfig.json +0 -23
package/src/{synchroniser/world_state_synchroniser.ts → synchronizer/world_state_synchronizer.ts}
RENAMED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { MerkleTreeOperations } from '../index.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Defines the possible states of the world state
|
|
4
|
+
* Defines the possible states of the world state synchronizer.
|
|
5
5
|
*/
|
|
6
6
|
export enum WorldStateRunningState {
|
|
7
7
|
IDLE,
|
|
@@ -11,37 +11,37 @@ export enum WorldStateRunningState {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
|
-
* Defines the status of the world state
|
|
14
|
+
* Defines the status of the world state synchronizer.
|
|
15
15
|
*/
|
|
16
16
|
export interface WorldStateStatus {
|
|
17
17
|
/**
|
|
18
|
-
* The current state of the world state
|
|
18
|
+
* The current state of the world state synchronizer.
|
|
19
19
|
*/
|
|
20
20
|
state: WorldStateRunningState;
|
|
21
21
|
/**
|
|
22
|
-
* The block number that the world state
|
|
22
|
+
* The block number that the world state synchronizer is synced to.
|
|
23
23
|
*/
|
|
24
24
|
syncedToL2Block: number;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
|
-
* Defines the interface for a world state
|
|
28
|
+
* Defines the interface for a world state synchronizer.
|
|
29
29
|
*/
|
|
30
|
-
export interface
|
|
30
|
+
export interface WorldStateSynchronizer {
|
|
31
31
|
/**
|
|
32
|
-
* Starts the
|
|
32
|
+
* Starts the synchronizer.
|
|
33
33
|
* @returns A promise that resolves once the initial sync is completed.
|
|
34
34
|
*/
|
|
35
35
|
start(): void;
|
|
36
36
|
|
|
37
37
|
/**
|
|
38
|
-
* Returns the current status of the
|
|
39
|
-
* @returns The current status of the
|
|
38
|
+
* Returns the current status of the synchronizer.
|
|
39
|
+
* @returns The current status of the synchronizer.
|
|
40
40
|
*/
|
|
41
41
|
status(): Promise<WorldStateStatus>;
|
|
42
42
|
|
|
43
43
|
/**
|
|
44
|
-
* Stops the
|
|
44
|
+
* Stops the synchronizer.
|
|
45
45
|
*/
|
|
46
46
|
stop(): Promise<void>;
|
|
47
47
|
|
|
@@ -208,7 +208,7 @@ export interface MerkleTreeOperations {
|
|
|
208
208
|
* Handles a single L2 block (i.e. Inserts the new commitments into the merkle tree).
|
|
209
209
|
* @param block - The L2 block to handle.
|
|
210
210
|
*/
|
|
211
|
-
handleL2Block(block: L2Block): Promise<
|
|
211
|
+
handleL2Block(block: L2Block): Promise<HandleL2BlockResult>;
|
|
212
212
|
|
|
213
213
|
/**
|
|
214
214
|
* Commits pending changes to the underlying store.
|
|
@@ -221,6 +221,11 @@ export interface MerkleTreeOperations {
|
|
|
221
221
|
rollback(): Promise<void>;
|
|
222
222
|
}
|
|
223
223
|
|
|
224
|
+
/** Return type for handleL2Block */
|
|
225
|
+
export type HandleL2BlockResult = {
|
|
226
|
+
/** Whether the block processed was emitted by our sequencer */ isBlockOurs: boolean;
|
|
227
|
+
};
|
|
228
|
+
|
|
224
229
|
/**
|
|
225
230
|
* Outputs a tree leaves using for debugging purposes.
|
|
226
231
|
*/
|
|
@@ -28,7 +28,7 @@ import {
|
|
|
28
28
|
loadTree,
|
|
29
29
|
newTree,
|
|
30
30
|
} from '@aztec/merkle-tree';
|
|
31
|
-
import { L2Block, MerkleTreeId, SiblingPath
|
|
31
|
+
import { L2Block, MerkleTreeId, SiblingPath } from '@aztec/types';
|
|
32
32
|
|
|
33
33
|
import { default as levelup } from 'levelup';
|
|
34
34
|
|
|
@@ -36,6 +36,7 @@ import { MerkleTreeOperationsFacade } from '../merkle-tree/merkle_tree_operation
|
|
|
36
36
|
import { computeGlobalVariablesHash } from '../utils.js';
|
|
37
37
|
import {
|
|
38
38
|
CurrentTreeRoots,
|
|
39
|
+
HandleL2BlockResult,
|
|
39
40
|
INITIAL_NULLIFIER_TREE_SIZE,
|
|
40
41
|
IndexedTreeId,
|
|
41
42
|
MerkleTreeDb,
|
|
@@ -45,7 +46,7 @@ import {
|
|
|
45
46
|
} from './index.js';
|
|
46
47
|
|
|
47
48
|
/**
|
|
48
|
-
* Data necessary to
|
|
49
|
+
* Data necessary to reinitialize the merkle trees from Db.
|
|
49
50
|
*/
|
|
50
51
|
interface FromDbOptions {
|
|
51
52
|
/**
|
|
@@ -67,24 +68,24 @@ export class MerkleTrees implements MerkleTreeDb {
|
|
|
67
68
|
}
|
|
68
69
|
|
|
69
70
|
/**
|
|
70
|
-
*
|
|
71
|
+
* initializes the collection of Merkle Trees.
|
|
71
72
|
* @param optionalWasm - WASM instance to use for hashing (if not provided PrimitivesWasm will be used).
|
|
72
|
-
* @param fromDbOptions - Options to
|
|
73
|
+
* @param fromDbOptions - Options to initialize the trees from the database.
|
|
73
74
|
*/
|
|
74
75
|
public async init(optionalWasm?: IWasmModule, fromDbOptions?: FromDbOptions) {
|
|
75
76
|
const fromDb = fromDbOptions !== undefined;
|
|
76
|
-
const
|
|
77
|
+
const initializeTree = fromDb ? loadTree : newTree;
|
|
77
78
|
|
|
78
79
|
const wasm = optionalWasm ?? (await CircuitsWasm.get());
|
|
79
80
|
const hasher = new Pedersen(wasm);
|
|
80
|
-
const contractTree: AppendOnlyTree = await
|
|
81
|
+
const contractTree: AppendOnlyTree = await initializeTree(
|
|
81
82
|
StandardTree,
|
|
82
83
|
this.db,
|
|
83
84
|
hasher,
|
|
84
85
|
`${MerkleTreeId[MerkleTreeId.CONTRACT_TREE]}`,
|
|
85
86
|
CONTRACT_TREE_HEIGHT,
|
|
86
87
|
);
|
|
87
|
-
const nullifierTree = await
|
|
88
|
+
const nullifierTree = await initializeTree(
|
|
88
89
|
StandardIndexedTree,
|
|
89
90
|
this.db,
|
|
90
91
|
hasher,
|
|
@@ -92,28 +93,28 @@ export class MerkleTrees implements MerkleTreeDb {
|
|
|
92
93
|
NULLIFIER_TREE_HEIGHT,
|
|
93
94
|
INITIAL_NULLIFIER_TREE_SIZE,
|
|
94
95
|
);
|
|
95
|
-
const privateDataTree: AppendOnlyTree = await
|
|
96
|
+
const privateDataTree: AppendOnlyTree = await initializeTree(
|
|
96
97
|
StandardTree,
|
|
97
98
|
this.db,
|
|
98
99
|
hasher,
|
|
99
100
|
`${MerkleTreeId[MerkleTreeId.PRIVATE_DATA_TREE]}`,
|
|
100
101
|
PRIVATE_DATA_TREE_HEIGHT,
|
|
101
102
|
);
|
|
102
|
-
const publicDataTree: UpdateOnlyTree = await
|
|
103
|
+
const publicDataTree: UpdateOnlyTree = await initializeTree(
|
|
103
104
|
SparseTree,
|
|
104
105
|
this.db,
|
|
105
106
|
hasher,
|
|
106
107
|
`${MerkleTreeId[MerkleTreeId.PUBLIC_DATA_TREE]}`,
|
|
107
108
|
PUBLIC_DATA_TREE_HEIGHT,
|
|
108
109
|
);
|
|
109
|
-
const l1Tol2MessagesTree: AppendOnlyTree = await
|
|
110
|
+
const l1Tol2MessagesTree: AppendOnlyTree = await initializeTree(
|
|
110
111
|
StandardTree,
|
|
111
112
|
this.db,
|
|
112
113
|
hasher,
|
|
113
114
|
`${MerkleTreeId[MerkleTreeId.L1_TO_L2_MESSAGES_TREE]}`,
|
|
114
115
|
L1_TO_L2_MSG_TREE_HEIGHT,
|
|
115
116
|
);
|
|
116
|
-
const historicBlocksTree: AppendOnlyTree = await
|
|
117
|
+
const historicBlocksTree: AppendOnlyTree = await initializeTree(
|
|
117
118
|
StandardTree,
|
|
118
119
|
this.db,
|
|
119
120
|
hasher,
|
|
@@ -136,10 +137,10 @@ export class MerkleTrees implements MerkleTreeDb {
|
|
|
136
137
|
}
|
|
137
138
|
|
|
138
139
|
/**
|
|
139
|
-
* Method to asynchronously create and
|
|
140
|
+
* Method to asynchronously create and initialize a MerkleTrees instance.
|
|
140
141
|
* @param db - The db instance to use for data persistance.
|
|
141
142
|
* @param wasm - WASM instance to use for hashing (if not provided PrimitivesWasm will be used).
|
|
142
|
-
* @returns - A fully
|
|
143
|
+
* @returns - A fully initialized MerkleTrees instance.
|
|
143
144
|
*/
|
|
144
145
|
public static async new(db: levelup.LevelUp, wasm?: IWasmModule) {
|
|
145
146
|
const merkleTrees = new MerkleTrees(db);
|
|
@@ -177,7 +178,7 @@ export class MerkleTrees implements MerkleTreeDb {
|
|
|
177
178
|
* @param includeUncommitted - Indicates whether to include uncommitted data.
|
|
178
179
|
*/
|
|
179
180
|
public async updateHistoricBlocksTree(globalsHash: Fr, includeUncommitted: boolean) {
|
|
180
|
-
await this.
|
|
181
|
+
await this.synchronize(() => this._updateHistoricBlocksTree(globalsHash, includeUncommitted));
|
|
181
182
|
}
|
|
182
183
|
|
|
183
184
|
/**
|
|
@@ -185,7 +186,7 @@ export class MerkleTrees implements MerkleTreeDb {
|
|
|
185
186
|
* @param globalVariablesHash - The latest global variables hash
|
|
186
187
|
*/
|
|
187
188
|
public async updateLatestGlobalVariablesHash(globalVariablesHash: Fr) {
|
|
188
|
-
return await this.
|
|
189
|
+
return await this.synchronize(() => this._updateLatestGlobalVariablesHash(globalVariablesHash));
|
|
189
190
|
}
|
|
190
191
|
|
|
191
192
|
/**
|
|
@@ -193,7 +194,7 @@ export class MerkleTrees implements MerkleTreeDb {
|
|
|
193
194
|
* @param includeUncommitted - Indicates whether to include uncommitted data.
|
|
194
195
|
*/
|
|
195
196
|
public async getLatestGlobalVariablesHash(includeUncommitted: boolean): Promise<Fr> {
|
|
196
|
-
return await this.
|
|
197
|
+
return await this.synchronize(() => this._getGlobalVariablesHash(includeUncommitted));
|
|
197
198
|
}
|
|
198
199
|
|
|
199
200
|
/**
|
|
@@ -203,7 +204,7 @@ export class MerkleTrees implements MerkleTreeDb {
|
|
|
203
204
|
* @returns The tree info for the specified tree.
|
|
204
205
|
*/
|
|
205
206
|
public async getTreeInfo(treeId: MerkleTreeId, includeUncommitted: boolean): Promise<TreeInfo> {
|
|
206
|
-
return await this.
|
|
207
|
+
return await this.synchronize(() => this._getTreeInfo(treeId, includeUncommitted));
|
|
207
208
|
}
|
|
208
209
|
|
|
209
210
|
/**
|
|
@@ -212,7 +213,7 @@ export class MerkleTrees implements MerkleTreeDb {
|
|
|
212
213
|
* @returns The current roots of the trees.
|
|
213
214
|
*/
|
|
214
215
|
public async getTreeRoots(includeUncommitted: boolean): Promise<CurrentTreeRoots> {
|
|
215
|
-
const roots = await this.
|
|
216
|
+
const roots = await this.synchronize(() => Promise.resolve(this._getAllTreeRoots(includeUncommitted)));
|
|
216
217
|
|
|
217
218
|
return {
|
|
218
219
|
privateDataTreeRoot: roots[0],
|
|
@@ -255,7 +256,7 @@ export class MerkleTrees implements MerkleTreeDb {
|
|
|
255
256
|
index: bigint,
|
|
256
257
|
includeUncommitted: boolean,
|
|
257
258
|
): Promise<Buffer | undefined> {
|
|
258
|
-
return await this.
|
|
259
|
+
return await this.synchronize(() => this.trees[treeId].getLeafValue(index, includeUncommitted));
|
|
259
260
|
}
|
|
260
261
|
|
|
261
262
|
/**
|
|
@@ -270,7 +271,7 @@ export class MerkleTrees implements MerkleTreeDb {
|
|
|
270
271
|
index: bigint,
|
|
271
272
|
includeUncommitted: boolean,
|
|
272
273
|
): Promise<SiblingPath<N>> {
|
|
273
|
-
return await this.
|
|
274
|
+
return await this.synchronize(() => this._getSiblingPath(treeId, index, includeUncommitted));
|
|
274
275
|
}
|
|
275
276
|
|
|
276
277
|
/**
|
|
@@ -280,7 +281,7 @@ export class MerkleTrees implements MerkleTreeDb {
|
|
|
280
281
|
* @returns Empty promise.
|
|
281
282
|
*/
|
|
282
283
|
public async appendLeaves(treeId: MerkleTreeId, leaves: Buffer[]): Promise<void> {
|
|
283
|
-
return await this.
|
|
284
|
+
return await this.synchronize(() => this._appendLeaves(treeId, leaves));
|
|
284
285
|
}
|
|
285
286
|
|
|
286
287
|
/**
|
|
@@ -288,7 +289,7 @@ export class MerkleTrees implements MerkleTreeDb {
|
|
|
288
289
|
* @returns Empty promise.
|
|
289
290
|
*/
|
|
290
291
|
public async commit(): Promise<void> {
|
|
291
|
-
return await this.
|
|
292
|
+
return await this.synchronize(() => this._commit());
|
|
292
293
|
}
|
|
293
294
|
|
|
294
295
|
/**
|
|
@@ -296,7 +297,7 @@ export class MerkleTrees implements MerkleTreeDb {
|
|
|
296
297
|
* @returns Empty promise.
|
|
297
298
|
*/
|
|
298
299
|
public async rollback(): Promise<void> {
|
|
299
|
-
return await this.
|
|
300
|
+
return await this.synchronize(() => this._rollback());
|
|
300
301
|
}
|
|
301
302
|
|
|
302
303
|
/**
|
|
@@ -320,7 +321,7 @@ export class MerkleTrees implements MerkleTreeDb {
|
|
|
320
321
|
*/
|
|
321
322
|
alreadyPresent: boolean;
|
|
322
323
|
}> {
|
|
323
|
-
return await this.
|
|
324
|
+
return await this.synchronize(() =>
|
|
324
325
|
Promise.resolve(this._getIndexedTree(treeId).findIndexOfPreviousValue(value, includeUncommitted)),
|
|
325
326
|
);
|
|
326
327
|
}
|
|
@@ -337,7 +338,7 @@ export class MerkleTrees implements MerkleTreeDb {
|
|
|
337
338
|
index: number,
|
|
338
339
|
includeUncommitted: boolean,
|
|
339
340
|
): Promise<LeafData | undefined> {
|
|
340
|
-
return await this.
|
|
341
|
+
return await this.synchronize(() =>
|
|
341
342
|
Promise.resolve(this._getIndexedTree(treeId).getLatestLeafDataCopy(index, includeUncommitted)),
|
|
342
343
|
);
|
|
343
344
|
}
|
|
@@ -354,7 +355,7 @@ export class MerkleTrees implements MerkleTreeDb {
|
|
|
354
355
|
value: Buffer,
|
|
355
356
|
includeUncommitted: boolean,
|
|
356
357
|
): Promise<bigint | undefined> {
|
|
357
|
-
return await this.
|
|
358
|
+
return await this.synchronize(async () => {
|
|
358
359
|
const tree = this.trees[treeId];
|
|
359
360
|
for (let i = 0n; i < tree.getNumLeaves(includeUncommitted); i++) {
|
|
360
361
|
const currentValue = await tree.getLeafValue(i, includeUncommitted);
|
|
@@ -374,15 +375,16 @@ export class MerkleTrees implements MerkleTreeDb {
|
|
|
374
375
|
* @returns Empty promise.
|
|
375
376
|
*/
|
|
376
377
|
public async updateLeaf(treeId: IndexedTreeId | PublicTreeId, leaf: LeafData | Buffer, index: bigint): Promise<void> {
|
|
377
|
-
return await this.
|
|
378
|
+
return await this.synchronize(() => this._updateLeaf(treeId, leaf, index));
|
|
378
379
|
}
|
|
379
380
|
|
|
380
381
|
/**
|
|
381
382
|
* Handles a single L2 block (i.e. Inserts the new commitments into the merkle tree).
|
|
382
383
|
* @param block - The L2 block to handle.
|
|
384
|
+
* @returns Whether the block handled was produced by this same node.
|
|
383
385
|
*/
|
|
384
|
-
public async handleL2Block(block: L2Block): Promise<
|
|
385
|
-
await this.
|
|
386
|
+
public async handleL2Block(block: L2Block): Promise<HandleL2BlockResult> {
|
|
387
|
+
return await this.synchronize(() => this._handleL2Block(block));
|
|
386
388
|
}
|
|
387
389
|
|
|
388
390
|
/**
|
|
@@ -408,7 +410,7 @@ export class MerkleTrees implements MerkleTreeDb {
|
|
|
408
410
|
if (!('batchInsert' in tree)) {
|
|
409
411
|
throw new Error('Tree does not support `batchInsert` method');
|
|
410
412
|
}
|
|
411
|
-
return await this.
|
|
413
|
+
return await this.synchronize(() => tree.batchInsert(leaves, subtreeHeight));
|
|
412
414
|
}
|
|
413
415
|
|
|
414
416
|
/**
|
|
@@ -416,7 +418,7 @@ export class MerkleTrees implements MerkleTreeDb {
|
|
|
416
418
|
* @param fn - The function to execute.
|
|
417
419
|
* @returns Promise containing the result of the function.
|
|
418
420
|
*/
|
|
419
|
-
private async
|
|
421
|
+
private async synchronize<T>(fn: () => Promise<T>): Promise<T> {
|
|
420
422
|
return await this.jobQueue.put(fn);
|
|
421
423
|
}
|
|
422
424
|
|
|
@@ -526,25 +528,25 @@ export class MerkleTrees implements MerkleTreeDb {
|
|
|
526
528
|
* Handles a single L2 block (i.e. Inserts the new commitments into the merkle tree).
|
|
527
529
|
* @param l2Block - The L2 block to handle.
|
|
528
530
|
*/
|
|
529
|
-
private async _handleL2Block(l2Block: L2Block) {
|
|
531
|
+
private async _handleL2Block(l2Block: L2Block): Promise<HandleL2BlockResult> {
|
|
532
|
+
const treeRootWithIdPairs = [
|
|
533
|
+
[l2Block.endContractTreeSnapshot.root, MerkleTreeId.CONTRACT_TREE],
|
|
534
|
+
[l2Block.endNullifierTreeSnapshot.root, MerkleTreeId.NULLIFIER_TREE],
|
|
535
|
+
[l2Block.endPrivateDataTreeSnapshot.root, MerkleTreeId.PRIVATE_DATA_TREE],
|
|
536
|
+
[l2Block.endPublicDataTreeRoot, MerkleTreeId.PUBLIC_DATA_TREE],
|
|
537
|
+
[l2Block.endL1ToL2MessagesTreeSnapshot.root, MerkleTreeId.L1_TO_L2_MESSAGES_TREE],
|
|
538
|
+
[l2Block.endHistoricBlocksTreeSnapshot.root, MerkleTreeId.BLOCKS_TREE],
|
|
539
|
+
] as const;
|
|
530
540
|
const compareRoot = (root: Fr, treeId: MerkleTreeId) => {
|
|
531
541
|
const treeRoot = this.trees[treeId].getRoot(true);
|
|
532
542
|
return treeRoot.equals(root.toBuffer());
|
|
533
543
|
};
|
|
534
|
-
const
|
|
535
|
-
compareRoot(l2Block.endContractTreeSnapshot.root, MerkleTreeId.CONTRACT_TREE),
|
|
536
|
-
compareRoot(l2Block.endNullifierTreeSnapshot.root, MerkleTreeId.NULLIFIER_TREE),
|
|
537
|
-
compareRoot(l2Block.endPrivateDataTreeSnapshot.root, MerkleTreeId.PRIVATE_DATA_TREE),
|
|
538
|
-
compareRoot(l2Block.endPublicDataTreeRoot, MerkleTreeId.PUBLIC_DATA_TREE),
|
|
539
|
-
compareRoot(l2Block.endL1ToL2MessagesTreeSnapshot.root, MerkleTreeId.L1_TO_L2_MESSAGES_TREE),
|
|
540
|
-
compareRoot(l2Block.endHistoricBlocksTreeSnapshot.root, MerkleTreeId.BLOCKS_TREE),
|
|
541
|
-
];
|
|
542
|
-
const ourBlock = rootChecks.every(x => x);
|
|
544
|
+
const ourBlock = treeRootWithIdPairs.every(([root, id]) => compareRoot(root, id));
|
|
543
545
|
if (ourBlock) {
|
|
544
|
-
this.log(`Block ${l2Block.number} is ours, committing world state
|
|
546
|
+
this.log(`Block ${l2Block.number} is ours, committing world state`);
|
|
545
547
|
await this._commit();
|
|
546
548
|
} else {
|
|
547
|
-
this.log(`Block ${l2Block.number} is not ours, rolling back world state and committing state from chain
|
|
549
|
+
this.log(`Block ${l2Block.number} is not ours, rolling back world state and committing state from chain`);
|
|
548
550
|
await this._rollback();
|
|
549
551
|
|
|
550
552
|
// Sync the append only trees
|
|
@@ -575,16 +577,29 @@ export class MerkleTrees implements MerkleTreeDb {
|
|
|
575
577
|
// Sync and add the block to the historic blocks tree
|
|
576
578
|
const globalVariablesHash = await computeGlobalVariablesHash(l2Block.globalVariables);
|
|
577
579
|
await this._updateLatestGlobalVariablesHash(globalVariablesHash);
|
|
578
|
-
this.log(`Synced global variables with hash ${
|
|
580
|
+
this.log(`Synced global variables with hash ${globalVariablesHash}`);
|
|
579
581
|
|
|
580
582
|
const blockHash = await this._getCurrentBlockHash(globalVariablesHash, true);
|
|
581
583
|
await this._appendLeaves(MerkleTreeId.BLOCKS_TREE, [blockHash.toBuffer()]);
|
|
582
584
|
|
|
583
585
|
await this._commit();
|
|
584
586
|
}
|
|
585
|
-
|
|
587
|
+
|
|
588
|
+
for (const [root, treeId] of treeRootWithIdPairs) {
|
|
589
|
+
const treeName = MerkleTreeId[treeId];
|
|
586
590
|
const info = await this._getTreeInfo(treeId, false);
|
|
587
|
-
|
|
591
|
+
const syncedStr = '0x' + info.root.toString('hex');
|
|
592
|
+
const rootStr = root.toString();
|
|
593
|
+
// Sanity check that the rebuilt trees match the roots published by the L2 block
|
|
594
|
+
if (!info.root.equals(root.toBuffer())) {
|
|
595
|
+
throw new Error(
|
|
596
|
+
`Synced tree root ${treeName} does not match published L2 block root: ${syncedStr} != ${rootStr}`,
|
|
597
|
+
);
|
|
598
|
+
} else {
|
|
599
|
+
this.log(`Tree ${treeName} synched with size ${info.size} root ${rootStr}`);
|
|
600
|
+
}
|
|
588
601
|
}
|
|
602
|
+
|
|
603
|
+
return { isBlockOurs: ourBlock };
|
|
589
604
|
}
|
|
590
605
|
}
|
package/.eslintrc.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require('@aztec/foundation/eslint');
|