@aztec/world-state 0.65.2 → 0.67.0
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 +7 -6
- package/dest/native/merkle_trees_facade.d.ts.map +1 -1
- package/dest/native/merkle_trees_facade.js +9 -1
- package/dest/native/message.d.ts +26 -15
- package/dest/native/message.d.ts.map +1 -1
- package/dest/native/message.js +19 -16
- package/dest/native/native_world_state.d.ts +3 -3
- package/dest/native/native_world_state.d.ts.map +1 -1
- package/dest/native/native_world_state.js +7 -7
- package/dest/native/native_world_state_instance.d.ts.map +1 -1
- package/dest/native/native_world_state_instance.js +7 -7
- package/dest/synchronizer/factory.d.ts.map +1 -1
- package/dest/synchronizer/factory.js +8 -4
- package/dest/synchronizer/instrumentation.d.ts +8 -1
- package/dest/synchronizer/instrumentation.d.ts.map +1 -1
- package/dest/synchronizer/instrumentation.js +51 -70
- package/dest/synchronizer/server_world_state_synchronizer.d.ts.map +1 -1
- package/dest/synchronizer/server_world_state_synchronizer.js +8 -9
- package/dest/world-state-db/merkle_tree_db.d.ts +2 -12
- package/dest/world-state-db/merkle_tree_db.d.ts.map +1 -1
- package/dest/world-state-db/merkle_tree_operations_facade.d.ts +4 -3
- package/dest/world-state-db/merkle_tree_operations_facade.d.ts.map +1 -1
- package/dest/world-state-db/merkle_tree_operations_facade.js +4 -1
- package/dest/world-state-db/merkle_tree_snapshot_operations_facade.d.ts +3 -2
- package/dest/world-state-db/merkle_tree_snapshot_operations_facade.d.ts.map +1 -1
- package/dest/world-state-db/merkle_tree_snapshot_operations_facade.js +5 -2
- package/dest/world-state-db/merkle_trees.d.ts +5 -4
- package/dest/world-state-db/merkle_trees.d.ts.map +1 -1
- package/dest/world-state-db/merkle_trees.js +7 -7
- package/package.json +12 -8
- package/src/native/merkle_trees_facade.ts +18 -5
- package/src/native/message.ts +15 -0
- package/src/native/native_world_state.ts +9 -9
- package/src/native/native_world_state_instance.ts +10 -12
- package/src/synchronizer/factory.ts +9 -6
- package/src/synchronizer/instrumentation.ts +55 -83
- package/src/synchronizer/server_world_state_synchronizer.ts +7 -8
- package/src/world-state-db/merkle_tree_db.ts +2 -14
- package/src/world-state-db/merkle_tree_operations_facade.ts +10 -3
- package/src/world-state-db/merkle_tree_snapshot_operations_facade.ts +12 -2
- package/src/world-state-db/merkle_trees.ts +14 -10
|
@@ -1,119 +1,91 @@
|
|
|
1
1
|
import { MerkleTreeId } from '@aztec/circuit-types';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
3
|
+
import { Attributes, type Gauge, type TelemetryClient, ValueType } from '@aztec/telemetry-client';
|
|
4
4
|
|
|
5
5
|
import { type DBStats, type TreeDBStats, type TreeMeta, type WorldStateStatusFull } from '../native/message.js';
|
|
6
6
|
|
|
7
|
-
type
|
|
8
|
-
type DBTypeString = 'leaf_preimage' | 'leaf_indices' | 'nodes' | 'blocks';
|
|
7
|
+
type DBTypeString = 'leaf_preimage' | 'leaf_indices' | 'nodes' | 'blocks' | 'block_indices';
|
|
9
8
|
|
|
10
|
-
class
|
|
9
|
+
export class WorldStateInstrumentation {
|
|
10
|
+
private dbMapSize: Gauge;
|
|
11
|
+
private treeSize: Gauge;
|
|
12
|
+
private unfinalisedHeight: Gauge;
|
|
13
|
+
private finalisedHeight: Gauge;
|
|
14
|
+
private oldestBlock: Gauge;
|
|
11
15
|
private dbNumItems: Gauge;
|
|
12
16
|
private dbUsedSize: Gauge;
|
|
13
17
|
|
|
14
|
-
constructor(
|
|
15
|
-
|
|
16
|
-
|
|
18
|
+
constructor(telemetry: TelemetryClient, private log = createLogger('world-state:instrumentation')) {
|
|
19
|
+
const meter = telemetry.getMeter('World State');
|
|
20
|
+
this.dbMapSize = meter.createGauge(`aztec.world_state.db_map_size`, {
|
|
21
|
+
description: `The current configured map size for each merkle tree`,
|
|
17
22
|
valueType: ValueType.INT,
|
|
18
23
|
});
|
|
19
24
|
|
|
20
|
-
this.
|
|
21
|
-
description: `The current number of
|
|
25
|
+
this.treeSize = meter.createGauge(`aztec.world_state.tree_size`, {
|
|
26
|
+
description: `The current number of leaves in each merkle tree`,
|
|
22
27
|
valueType: ValueType.INT,
|
|
23
28
|
});
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
public updateMetrics(treeDbStats: DBStats) {
|
|
27
|
-
this.dbNumItems.record(Number(treeDbStats.numDataItems));
|
|
28
|
-
this.dbUsedSize.record(Number(treeDbStats.totalUsedSize));
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
class TreeInstrumentation {
|
|
33
|
-
private treeDbInstrumentation: Map<DBTypeString, TreeDBInstrumentation> = new Map<
|
|
34
|
-
DBTypeString,
|
|
35
|
-
TreeDBInstrumentation
|
|
36
|
-
>();
|
|
37
|
-
private dbMapSize: Gauge;
|
|
38
|
-
private treeSize: Gauge;
|
|
39
|
-
private unfinalisedHeight: Gauge;
|
|
40
|
-
private finalisedHeight: Gauge;
|
|
41
|
-
private oldestBlock: Gauge;
|
|
42
29
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
description: `The current configured map size for the ${treeName} tree`,
|
|
30
|
+
this.unfinalisedHeight = meter.createGauge(`aztec.world_state.unfinalised_height`, {
|
|
31
|
+
description: `The unfinalised block height of each merkle tree`,
|
|
46
32
|
valueType: ValueType.INT,
|
|
47
33
|
});
|
|
48
34
|
|
|
49
|
-
this.
|
|
50
|
-
description: `The
|
|
35
|
+
this.finalisedHeight = meter.createGauge(`aztec.world_state.finalised_height`, {
|
|
36
|
+
description: `The finalised block height of each merkle tree`,
|
|
51
37
|
valueType: ValueType.INT,
|
|
52
38
|
});
|
|
53
39
|
|
|
54
|
-
this.
|
|
55
|
-
description: `The
|
|
40
|
+
this.oldestBlock = meter.createGauge(`aztec.world_state.oldest_block`, {
|
|
41
|
+
description: `The oldest historical block of each merkle tree`,
|
|
56
42
|
valueType: ValueType.INT,
|
|
57
43
|
});
|
|
58
44
|
|
|
59
|
-
this.
|
|
60
|
-
description: `The
|
|
45
|
+
this.dbUsedSize = meter.createGauge(`aztec.world_state.db_used_size`, {
|
|
46
|
+
description: `The current used database size for each db of each merkle tree`,
|
|
61
47
|
valueType: ValueType.INT,
|
|
62
48
|
});
|
|
63
49
|
|
|
64
|
-
this.
|
|
65
|
-
description: `The
|
|
50
|
+
this.dbNumItems = meter.createGauge(`aztec.world_state.db_num_items`, {
|
|
51
|
+
description: `The current number of items in each database of each merkle tree`,
|
|
66
52
|
valueType: ValueType.INT,
|
|
67
53
|
});
|
|
68
|
-
|
|
69
|
-
this.treeDbInstrumentation.set('blocks', new TreeDBInstrumentation(meter, treeName, 'blocks'));
|
|
70
|
-
this.treeDbInstrumentation.set('nodes', new TreeDBInstrumentation(meter, treeName, 'nodes'));
|
|
71
|
-
this.treeDbInstrumentation.set('leaf_preimage', new TreeDBInstrumentation(meter, treeName, 'leaf_preimage'));
|
|
72
|
-
this.treeDbInstrumentation.set('leaf_indices', new TreeDBInstrumentation(meter, treeName, 'leaf_indices'));
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
private updateDBMetrics(dbName: DBTypeString, dbStats: DBStats) {
|
|
76
|
-
const inst = this.treeDbInstrumentation.get(dbName);
|
|
77
|
-
if (!inst) {
|
|
78
|
-
this.log.error(`Failed to find instrumentation for ${dbName}`);
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
inst.updateMetrics(dbStats);
|
|
82
54
|
}
|
|
83
55
|
|
|
84
|
-
|
|
85
|
-
this.dbMapSize.record(Number(treeDbStats.mapSize)
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
this.
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
this.
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
this.
|
|
95
|
-
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
56
|
+
private updateTreeStats(treeDbStats: TreeDBStats, treeMeta: TreeMeta, tree: MerkleTreeId) {
|
|
57
|
+
this.dbMapSize.record(Number(treeDbStats.mapSize), {
|
|
58
|
+
[Attributes.MERKLE_TREE_NAME]: MerkleTreeId[tree],
|
|
59
|
+
});
|
|
60
|
+
this.treeSize.record(Number(treeMeta.size), {
|
|
61
|
+
[Attributes.MERKLE_TREE_NAME]: MerkleTreeId[tree],
|
|
62
|
+
});
|
|
63
|
+
this.unfinalisedHeight.record(Number(treeMeta.unfinalisedBlockHeight), {
|
|
64
|
+
[Attributes.MERKLE_TREE_NAME]: MerkleTreeId[tree],
|
|
65
|
+
});
|
|
66
|
+
this.finalisedHeight.record(Number(treeMeta.finalisedBlockHeight), {
|
|
67
|
+
[Attributes.MERKLE_TREE_NAME]: MerkleTreeId[tree],
|
|
68
|
+
});
|
|
69
|
+
this.oldestBlock.record(Number(treeMeta.oldestHistoricBlock), {
|
|
70
|
+
[Attributes.MERKLE_TREE_NAME]: MerkleTreeId[tree],
|
|
71
|
+
});
|
|
100
72
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
this.
|
|
104
|
-
this.
|
|
105
|
-
this.
|
|
106
|
-
this.treeInstrumentation.set(MerkleTreeId.NULLIFIER_TREE, new TreeInstrumentation(meter, 'nullifier', log));
|
|
107
|
-
this.treeInstrumentation.set(MerkleTreeId.PUBLIC_DATA_TREE, new TreeInstrumentation(meter, 'public_data', log));
|
|
73
|
+
this.updateTreeDBStats(treeDbStats.blockIndicesDBStats, 'block_indices', tree);
|
|
74
|
+
this.updateTreeDBStats(treeDbStats.blocksDBStats, 'blocks', tree);
|
|
75
|
+
this.updateTreeDBStats(treeDbStats.leafIndicesDBStats, 'leaf_indices', tree);
|
|
76
|
+
this.updateTreeDBStats(treeDbStats.leafPreimagesDBStats, 'leaf_preimage', tree);
|
|
77
|
+
this.updateTreeDBStats(treeDbStats.nodesDBStats, 'nodes', tree);
|
|
108
78
|
}
|
|
109
79
|
|
|
110
|
-
private
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
80
|
+
private updateTreeDBStats(dbStats: DBStats, dbType: DBTypeString, tree: MerkleTreeId) {
|
|
81
|
+
this.dbNumItems.record(Number(dbStats.numDataItems), {
|
|
82
|
+
[Attributes.WS_DB_DATA_TYPE]: dbType,
|
|
83
|
+
[Attributes.MERKLE_TREE_NAME]: MerkleTreeId[tree],
|
|
84
|
+
});
|
|
85
|
+
this.dbUsedSize.record(Number(dbStats.totalUsedSize), {
|
|
86
|
+
[Attributes.WS_DB_DATA_TYPE]: dbType,
|
|
87
|
+
[Attributes.MERKLE_TREE_NAME]: MerkleTreeId[tree],
|
|
88
|
+
});
|
|
117
89
|
}
|
|
118
90
|
|
|
119
91
|
public updateWorldStateMetrics(worldStateStatus: WorldStateStatusFull) {
|
|
@@ -19,7 +19,7 @@ import { type L2BlockHandledStats } from '@aztec/circuit-types/stats';
|
|
|
19
19
|
import { MerkleTreeCalculator } from '@aztec/circuits.js';
|
|
20
20
|
import { L1_TO_L2_MSG_SUBTREE_HEIGHT } from '@aztec/circuits.js/constants';
|
|
21
21
|
import { type Fr } from '@aztec/foundation/fields';
|
|
22
|
-
import {
|
|
22
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
23
23
|
import { promiseWithResolvers } from '@aztec/foundation/promise';
|
|
24
24
|
import { elapsed } from '@aztec/foundation/timer';
|
|
25
25
|
import { SHA256Trunc } from '@aztec/merkle-tree';
|
|
@@ -54,7 +54,7 @@ export class ServerWorldStateSynchronizer
|
|
|
54
54
|
private readonly l2BlockSource: L2BlockSource & L1ToL2MessageSource,
|
|
55
55
|
private readonly config: WorldStateConfig,
|
|
56
56
|
telemetry: TelemetryClient,
|
|
57
|
-
private readonly log =
|
|
57
|
+
private readonly log = createLogger('world_state'),
|
|
58
58
|
) {
|
|
59
59
|
this.instrumentation = new WorldStateInstrumentation(telemetry);
|
|
60
60
|
this.merkleTreeCommitted = this.merkleTreeDb.getCommitted();
|
|
@@ -111,7 +111,7 @@ export class ServerWorldStateSynchronizer
|
|
|
111
111
|
}
|
|
112
112
|
|
|
113
113
|
protected createBlockStream() {
|
|
114
|
-
return new L2BlockStream(this.l2BlockSource, this, this, {
|
|
114
|
+
return new L2BlockStream(this.l2BlockSource, this, this, createLogger('world_state:block_stream'), {
|
|
115
115
|
proven: this.config.worldStateProvenBlocksOnly,
|
|
116
116
|
pollIntervalMS: this.config.worldStateBlockCheckIntervalMS,
|
|
117
117
|
batchSize: this.config.worldStateBlockRequestBatchSize,
|
|
@@ -224,14 +224,13 @@ export class ServerWorldStateSynchronizer
|
|
|
224
224
|
* @returns Whether the block handled was produced by this same node.
|
|
225
225
|
*/
|
|
226
226
|
private async handleL2Blocks(l2Blocks: L2Block[]) {
|
|
227
|
-
this.log.verbose(`Handling new L2 blocks from ${l2Blocks[0].number} to ${l2Blocks[l2Blocks.length - 1].number}`);
|
|
228
227
|
const messagePromises = l2Blocks.map(block => this.l2BlockSource.getL1ToL2Messages(BigInt(block.number)));
|
|
229
228
|
const l1ToL2Messages: Fr[][] = await Promise.all(messagePromises);
|
|
230
229
|
let updateStatus: WorldStateStatusFull | undefined = undefined;
|
|
231
230
|
|
|
232
231
|
for (let i = 0; i < l2Blocks.length; i++) {
|
|
233
232
|
const [duration, result] = await elapsed(() => this.handleL2Block(l2Blocks[i], l1ToL2Messages[i]));
|
|
234
|
-
this.log.verbose(`
|
|
233
|
+
this.log.verbose(`World state updated with L2 block ${l2Blocks[i].number}`, {
|
|
235
234
|
eventName: 'l2-block-handled',
|
|
236
235
|
duration,
|
|
237
236
|
unfinalisedBlockNumber: result.summary.unfinalisedBlockNumber,
|
|
@@ -272,7 +271,7 @@ export class ServerWorldStateSynchronizer
|
|
|
272
271
|
}
|
|
273
272
|
|
|
274
273
|
private async handleChainFinalized(blockNumber: number) {
|
|
275
|
-
this.log.verbose(`
|
|
274
|
+
this.log.verbose(`Finalized chain is now at block ${blockNumber}`);
|
|
276
275
|
const summary = await this.merkleTreeDb.setFinalised(BigInt(blockNumber));
|
|
277
276
|
if (this.historyToKeep === undefined) {
|
|
278
277
|
return;
|
|
@@ -286,12 +285,12 @@ export class ServerWorldStateSynchronizer
|
|
|
286
285
|
}
|
|
287
286
|
|
|
288
287
|
private handleChainProven(blockNumber: number) {
|
|
289
|
-
this.log.
|
|
288
|
+
this.log.debug(`Proven chain is now at block ${blockNumber}`);
|
|
290
289
|
return Promise.resolve();
|
|
291
290
|
}
|
|
292
291
|
|
|
293
292
|
private async handleChainPruned(blockNumber: number) {
|
|
294
|
-
this.log.
|
|
293
|
+
this.log.warn(`Chain pruned to block ${blockNumber}`);
|
|
295
294
|
const status = await this.merkleTreeDb.unwindBlocks(BigInt(blockNumber));
|
|
296
295
|
this.latestBlockHashQuery = undefined;
|
|
297
296
|
this.instrumentation.updateWorldStateMetrics(status);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type L2Block, type MerkleTreeId } from '@aztec/circuit-types';
|
|
2
|
-
import { type
|
|
2
|
+
import { type ForkMerkleTreeOperations, type MerkleTreeReadOperations } from '@aztec/circuit-types/interfaces';
|
|
3
3
|
import { type Fr, MAX_NULLIFIERS_PER_TX, MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX } from '@aztec/circuits.js';
|
|
4
4
|
import { type IndexedTreeSnapshot, type TreeSnapshot } from '@aztec/merkle-tree';
|
|
5
5
|
|
|
@@ -32,7 +32,7 @@ export type TreeSnapshots = {
|
|
|
32
32
|
[MerkleTreeId.ARCHIVE]: TreeSnapshot<Fr>;
|
|
33
33
|
};
|
|
34
34
|
|
|
35
|
-
export interface MerkleTreeAdminDatabase {
|
|
35
|
+
export interface MerkleTreeAdminDatabase extends ForkMerkleTreeOperations {
|
|
36
36
|
/**
|
|
37
37
|
* Handles a single L2 block (i.e. Inserts the new note hashes into the merkle tree).
|
|
38
38
|
* @param block - The L2 block to handle.
|
|
@@ -45,18 +45,6 @@ export interface MerkleTreeAdminDatabase {
|
|
|
45
45
|
*/
|
|
46
46
|
getCommitted(): MerkleTreeReadOperations;
|
|
47
47
|
|
|
48
|
-
/**
|
|
49
|
-
* Gets a handle that allows reading the state as it was at the given block number
|
|
50
|
-
* @param blockNumber - The block number to get the snapshot for
|
|
51
|
-
*/
|
|
52
|
-
getSnapshot(blockNumber: number): MerkleTreeReadOperations;
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Forks the database at its current state.
|
|
56
|
-
* @param blockNumber - The block number to fork at. If not provided, the current block number is used.
|
|
57
|
-
*/
|
|
58
|
-
fork(blockNumber?: number): Promise<MerkleTreeWriteOperations>;
|
|
59
|
-
|
|
60
48
|
/**
|
|
61
49
|
* Removes all historical snapshots up to but not including the given block number
|
|
62
50
|
* @param toBlockNumber The block number of the new oldest historical block
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
type SequentialInsertionResult,
|
|
7
7
|
type TreeInfo,
|
|
8
8
|
} from '@aztec/circuit-types/interfaces';
|
|
9
|
-
import { type
|
|
9
|
+
import { type BlockHeader, type StateReference } from '@aztec/circuits.js';
|
|
10
10
|
import { type IndexedTreeLeafPreimage } from '@aztec/foundation/trees';
|
|
11
11
|
|
|
12
12
|
import { type MerkleTrees } from './merkle_trees.js';
|
|
@@ -39,7 +39,7 @@ export class MerkleTreeReadOperationsFacade implements MerkleTreeWriteOperations
|
|
|
39
39
|
* Returns the initial header for the chain before the first block.
|
|
40
40
|
* @returns The initial header.
|
|
41
41
|
*/
|
|
42
|
-
getInitialHeader():
|
|
42
|
+
getInitialHeader(): BlockHeader {
|
|
43
43
|
return this.trees.getInitialHeader();
|
|
44
44
|
}
|
|
45
45
|
|
|
@@ -149,7 +149,7 @@ export class MerkleTreeReadOperationsFacade implements MerkleTreeWriteOperations
|
|
|
149
149
|
* This includes all of the current roots of all of the data trees and the current blocks global vars.
|
|
150
150
|
* @param header - The header to insert into the archive.
|
|
151
151
|
*/
|
|
152
|
-
public updateArchive(header:
|
|
152
|
+
public updateArchive(header: BlockHeader): Promise<void> {
|
|
153
153
|
return this.trees.updateArchive(header);
|
|
154
154
|
}
|
|
155
155
|
|
|
@@ -181,6 +181,13 @@ export class MerkleTreeReadOperationsFacade implements MerkleTreeWriteOperations
|
|
|
181
181
|
throw new Error('Method not implemented in legacy merkle tree');
|
|
182
182
|
}
|
|
183
183
|
|
|
184
|
+
getBlockNumbersForLeafIndices<ID extends MerkleTreeId>(
|
|
185
|
+
_treeId: ID,
|
|
186
|
+
_leafIndices: bigint[],
|
|
187
|
+
): Promise<(bigint | undefined)[]> {
|
|
188
|
+
throw new Error('Method not implemented in legacy merkle tree');
|
|
189
|
+
}
|
|
190
|
+
|
|
184
191
|
close(): Promise<void> {
|
|
185
192
|
return Promise.resolve();
|
|
186
193
|
}
|
|
@@ -5,7 +5,13 @@ import {
|
|
|
5
5
|
type MerkleTreeReadOperations,
|
|
6
6
|
type TreeInfo,
|
|
7
7
|
} from '@aztec/circuit-types/interfaces';
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
AppendOnlyTreeSnapshot,
|
|
10
|
+
type BlockHeader,
|
|
11
|
+
Fr,
|
|
12
|
+
PartialStateReference,
|
|
13
|
+
StateReference,
|
|
14
|
+
} from '@aztec/circuits.js';
|
|
9
15
|
import { type IndexedTreeLeafPreimage } from '@aztec/foundation/trees';
|
|
10
16
|
import { type IndexedTreeSnapshot } from '@aztec/merkle-tree';
|
|
11
17
|
|
|
@@ -101,6 +107,10 @@ export class MerkleTreeSnapshotOperationsFacade implements MerkleTreeReadOperati
|
|
|
101
107
|
};
|
|
102
108
|
}
|
|
103
109
|
|
|
110
|
+
getBlockNumbersForLeafIndices<ID extends MerkleTreeId>(_a: ID, _b: bigint[]): Promise<(bigint | undefined)[]> {
|
|
111
|
+
throw new Error('Not implemented');
|
|
112
|
+
}
|
|
113
|
+
|
|
104
114
|
async getStateReference(): Promise<StateReference> {
|
|
105
115
|
const snapshots = await Promise.all([
|
|
106
116
|
this.#getTreeSnapshot(MerkleTreeId.NULLIFIER_TREE),
|
|
@@ -132,7 +142,7 @@ export class MerkleTreeSnapshotOperationsFacade implements MerkleTreeReadOperati
|
|
|
132
142
|
);
|
|
133
143
|
}
|
|
134
144
|
|
|
135
|
-
getInitialHeader():
|
|
145
|
+
getInitialHeader(): BlockHeader {
|
|
136
146
|
throw new Error('Getting initial header not supported on snapshot.');
|
|
137
147
|
}
|
|
138
148
|
}
|
|
@@ -10,8 +10,8 @@ import {
|
|
|
10
10
|
import {
|
|
11
11
|
ARCHIVE_HEIGHT,
|
|
12
12
|
AppendOnlyTreeSnapshot,
|
|
13
|
+
BlockHeader,
|
|
13
14
|
Fr,
|
|
14
|
-
Header,
|
|
15
15
|
L1_TO_L2_MSG_TREE_HEIGHT,
|
|
16
16
|
MAX_NOTE_HASHES_PER_TX,
|
|
17
17
|
MAX_NULLIFIERS_PER_TX,
|
|
@@ -31,12 +31,12 @@ import {
|
|
|
31
31
|
StateReference,
|
|
32
32
|
} from '@aztec/circuits.js';
|
|
33
33
|
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
34
|
-
import { type
|
|
34
|
+
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
35
35
|
import { SerialQueue } from '@aztec/foundation/queue';
|
|
36
36
|
import { Timer, elapsed } from '@aztec/foundation/timer';
|
|
37
37
|
import { type IndexedTreeLeafPreimage } from '@aztec/foundation/trees';
|
|
38
38
|
import { type AztecKVStore, type AztecSingleton } from '@aztec/kv-store';
|
|
39
|
-
import { openTmpStore } from '@aztec/kv-store/
|
|
39
|
+
import { openTmpStore } from '@aztec/kv-store/lmdb';
|
|
40
40
|
import {
|
|
41
41
|
type AppendOnlyTree,
|
|
42
42
|
type IndexedTree,
|
|
@@ -111,7 +111,7 @@ export class MerkleTrees implements MerkleTreeAdminDatabase {
|
|
|
111
111
|
private initialStateReference: AztecSingleton<Buffer>;
|
|
112
112
|
private metrics: WorldStateMetrics;
|
|
113
113
|
|
|
114
|
-
private constructor(private store: AztecKVStore, private telemetryClient: TelemetryClient, private log:
|
|
114
|
+
private constructor(private store: AztecKVStore, private telemetryClient: TelemetryClient, private log: Logger) {
|
|
115
115
|
this.initialStateReference = store.openSingleton('merkle_trees_initial_state_reference');
|
|
116
116
|
this.metrics = new WorldStateMetrics(telemetryClient);
|
|
117
117
|
}
|
|
@@ -121,7 +121,11 @@ export class MerkleTrees implements MerkleTreeAdminDatabase {
|
|
|
121
121
|
* @param store - The db instance to use for data persistance.
|
|
122
122
|
* @returns - A fully initialized MerkleTrees instance.
|
|
123
123
|
*/
|
|
124
|
-
public static async new(
|
|
124
|
+
public static async new(
|
|
125
|
+
store: AztecKVStore,
|
|
126
|
+
client: TelemetryClient,
|
|
127
|
+
log = createLogger('world-state:merkle_trees'),
|
|
128
|
+
) {
|
|
125
129
|
const merkleTrees = new MerkleTrees(store, client, log);
|
|
126
130
|
await merkleTrees.#init();
|
|
127
131
|
return merkleTrees;
|
|
@@ -239,7 +243,7 @@ export class MerkleTrees implements MerkleTreeAdminDatabase {
|
|
|
239
243
|
const forked = new MerkleTrees(
|
|
240
244
|
this.store,
|
|
241
245
|
this.telemetryClient,
|
|
242
|
-
|
|
246
|
+
createLogger('world-state:merkle_trees:ephemeral_fork'),
|
|
243
247
|
);
|
|
244
248
|
await forked.#init(true);
|
|
245
249
|
return new MerkleTreeReadOperationsFacade(forked, true);
|
|
@@ -249,8 +253,8 @@ export class MerkleTrees implements MerkleTreeAdminDatabase {
|
|
|
249
253
|
await this.store.delete();
|
|
250
254
|
}
|
|
251
255
|
|
|
252
|
-
public getInitialHeader():
|
|
253
|
-
return
|
|
256
|
+
public getInitialHeader(): BlockHeader {
|
|
257
|
+
return BlockHeader.empty({ state: this.#loadInitialStateReference() });
|
|
254
258
|
}
|
|
255
259
|
|
|
256
260
|
/**
|
|
@@ -285,7 +289,7 @@ export class MerkleTrees implements MerkleTreeAdminDatabase {
|
|
|
285
289
|
* @param header - The header whose hash to insert into the archive.
|
|
286
290
|
* @param includeUncommitted - Indicates whether to include uncommitted data.
|
|
287
291
|
*/
|
|
288
|
-
public async updateArchive(header:
|
|
292
|
+
public async updateArchive(header: BlockHeader) {
|
|
289
293
|
await this.synchronize(() => this.#updateArchive(header));
|
|
290
294
|
}
|
|
291
295
|
|
|
@@ -519,7 +523,7 @@ export class MerkleTrees implements MerkleTreeAdminDatabase {
|
|
|
519
523
|
return StateReference.fromBuffer(serialized);
|
|
520
524
|
}
|
|
521
525
|
|
|
522
|
-
async #updateArchive(header:
|
|
526
|
+
async #updateArchive(header: BlockHeader) {
|
|
523
527
|
const state = await this.getStateReference(true);
|
|
524
528
|
|
|
525
529
|
// This method should be called only when the block builder already updated the state so we sanity check that it's
|