@aztec/world-state 0.0.0-test.1 → 0.0.1-commit.21caa21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/index.d.ts +1 -1
- package/dest/instrumentation/instrumentation.d.ts +6 -4
- package/dest/instrumentation/instrumentation.d.ts.map +1 -1
- package/dest/instrumentation/instrumentation.js +16 -8
- package/dest/native/bench_metrics.d.ts +23 -0
- package/dest/native/bench_metrics.d.ts.map +1 -0
- package/dest/native/bench_metrics.js +81 -0
- package/dest/native/fork_checkpoint.d.ts +1 -1
- package/dest/native/fork_checkpoint.d.ts.map +1 -1
- package/dest/native/index.d.ts +1 -1
- package/dest/native/merkle_trees_facade.d.ts +10 -4
- package/dest/native/merkle_trees_facade.d.ts.map +1 -1
- package/dest/native/merkle_trees_facade.js +39 -7
- package/dest/native/message.d.ts +65 -45
- package/dest/native/message.d.ts.map +1 -1
- package/dest/native/message.js +55 -56
- package/dest/native/native_world_state.d.ts +20 -15
- package/dest/native/native_world_state.d.ts.map +1 -1
- package/dest/native/native_world_state.js +90 -33
- package/dest/native/native_world_state_instance.d.ts +20 -4
- package/dest/native/native_world_state_instance.d.ts.map +1 -1
- package/dest/native/native_world_state_instance.js +42 -3
- package/dest/native/world_state_ops_queue.d.ts +1 -1
- package/dest/native/world_state_ops_queue.d.ts.map +1 -1
- package/dest/native/world_state_ops_queue.js +1 -1
- package/dest/synchronizer/config.d.ts +12 -2
- package/dest/synchronizer/config.d.ts.map +1 -1
- package/dest/synchronizer/config.js +26 -1
- package/dest/synchronizer/errors.d.ts +4 -0
- package/dest/synchronizer/errors.d.ts.map +1 -0
- package/dest/synchronizer/errors.js +5 -0
- package/dest/synchronizer/factory.d.ts +9 -2
- package/dest/synchronizer/factory.d.ts.map +1 -1
- package/dest/synchronizer/factory.js +9 -4
- package/dest/synchronizer/index.d.ts +1 -1
- package/dest/synchronizer/server_world_state_synchronizer.d.ts +14 -18
- package/dest/synchronizer/server_world_state_synchronizer.d.ts.map +1 -1
- package/dest/synchronizer/server_world_state_synchronizer.js +78 -38
- package/dest/test/index.d.ts +1 -1
- package/dest/test/utils.d.ts +2 -2
- package/dest/test/utils.d.ts.map +1 -1
- package/dest/test/utils.js +21 -18
- package/dest/testing.d.ts +2 -2
- package/dest/testing.d.ts.map +1 -1
- package/dest/testing.js +6 -10
- package/dest/world-state-db/index.d.ts +1 -1
- package/dest/world-state-db/merkle_tree_db.d.ts +10 -6
- package/dest/world-state-db/merkle_tree_db.d.ts.map +1 -1
- package/package.json +24 -24
- package/src/instrumentation/instrumentation.ts +22 -10
- package/src/native/bench_metrics.ts +91 -0
- package/src/native/merkle_trees_facade.ts +44 -13
- package/src/native/message.ts +81 -63
- package/src/native/native_world_state.ts +99 -43
- package/src/native/native_world_state_instance.ts +59 -8
- package/src/native/world_state_ops_queue.ts +1 -1
- package/src/synchronizer/config.ts +47 -2
- package/src/synchronizer/errors.ts +5 -0
- package/src/synchronizer/factory.ts +31 -8
- package/src/synchronizer/server_world_state_synchronizer.ts +93 -40
- package/src/test/utils.ts +46 -31
- package/src/testing.ts +3 -7
- package/src/world-state-db/merkle_tree_db.ts +14 -5
package/dest/test/utils.js
CHANGED
|
@@ -3,28 +3,31 @@ import { padArrayEnd } from '@aztec/foundation/collection';
|
|
|
3
3
|
import { Fr } from '@aztec/foundation/fields';
|
|
4
4
|
import { L2Block } from '@aztec/stdlib/block';
|
|
5
5
|
import { AppendOnlyTreeSnapshot, MerkleTreeId } from '@aztec/stdlib/trees';
|
|
6
|
-
export async function mockBlock(blockNum, size, fork) {
|
|
7
|
-
const l2Block = await L2Block.random(blockNum, size);
|
|
8
|
-
const l1ToL2Messages = Array(
|
|
9
|
-
// Sync the append only trees
|
|
6
|
+
export async function mockBlock(blockNum, size, fork, maxEffects = 1000) {
|
|
7
|
+
const l2Block = await L2Block.random(blockNum, size, undefined, undefined, undefined, undefined, maxEffects);
|
|
8
|
+
const l1ToL2Messages = Array(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP).fill(0).map(Fr.random);
|
|
10
9
|
{
|
|
10
|
+
const insertData = async (treeId, data, subTreeHeight, fork)=>{
|
|
11
|
+
for (const dataBatch of data){
|
|
12
|
+
await fork.batchInsert(treeId, dataBatch, subTreeHeight);
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
const publicDataInsert = insertData(MerkleTreeId.PUBLIC_DATA_TREE, l2Block.body.txEffects.map((txEffect)=>txEffect.publicDataWrites.map((write)=>write.toBuffer())), 0, fork);
|
|
16
|
+
const nullifierInsert = insertData(MerkleTreeId.NULLIFIER_TREE, l2Block.body.txEffects.map((txEffect)=>padArrayEnd(txEffect.nullifiers, Fr.ZERO, MAX_NULLIFIERS_PER_TX).map((nullifier)=>nullifier.toBuffer())), NULLIFIER_SUBTREE_HEIGHT, fork);
|
|
11
17
|
const noteHashesPadded = l2Block.body.txEffects.flatMap((txEffect)=>padArrayEnd(txEffect.noteHashes, Fr.ZERO, MAX_NOTE_HASHES_PER_TX));
|
|
12
|
-
await fork.appendLeaves(MerkleTreeId.NOTE_HASH_TREE, noteHashesPadded);
|
|
13
18
|
const l1ToL2MessagesPadded = padArrayEnd(l1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP);
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
await fork.batchInsert(MerkleTreeId.NULLIFIER_TREE, nullifiersPadded.map((nullifier)=>nullifier.toBuffer()), NULLIFIER_SUBTREE_HEIGHT);
|
|
23
|
-
}
|
|
19
|
+
const noteHashInsert = fork.appendLeaves(MerkleTreeId.NOTE_HASH_TREE, noteHashesPadded);
|
|
20
|
+
const messageInsert = fork.appendLeaves(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, l1ToL2MessagesPadded);
|
|
21
|
+
await Promise.all([
|
|
22
|
+
publicDataInsert,
|
|
23
|
+
nullifierInsert,
|
|
24
|
+
noteHashInsert,
|
|
25
|
+
messageInsert
|
|
26
|
+
]);
|
|
24
27
|
}
|
|
25
28
|
const state = await fork.getStateReference();
|
|
26
29
|
l2Block.header.state = state;
|
|
27
|
-
await fork.updateArchive(l2Block.
|
|
30
|
+
await fork.updateArchive(l2Block.getBlockHeader());
|
|
28
31
|
const archiveState = await fork.getTreeInfo(MerkleTreeId.ARCHIVE);
|
|
29
32
|
l2Block.archive = new AppendOnlyTreeSnapshot(Fr.fromBuffer(archiveState.root), Number(archiveState.size));
|
|
30
33
|
return {
|
|
@@ -35,7 +38,7 @@ export async function mockBlock(blockNum, size, fork) {
|
|
|
35
38
|
export async function mockEmptyBlock(blockNum, fork) {
|
|
36
39
|
const l2Block = L2Block.empty();
|
|
37
40
|
const l1ToL2Messages = Array(16).fill(0).map(Fr.zero);
|
|
38
|
-
l2Block.header.globalVariables.blockNumber =
|
|
41
|
+
l2Block.header.globalVariables.blockNumber = blockNum;
|
|
39
42
|
// Sync the append only trees
|
|
40
43
|
{
|
|
41
44
|
const noteHashesPadded = l2Block.body.txEffects.flatMap((txEffect)=>padArrayEnd(txEffect.noteHashes, Fr.ZERO, MAX_NOTE_HASHES_PER_TX));
|
|
@@ -54,7 +57,7 @@ export async function mockEmptyBlock(blockNum, fork) {
|
|
|
54
57
|
}
|
|
55
58
|
const state = await fork.getStateReference();
|
|
56
59
|
l2Block.header.state = state;
|
|
57
|
-
await fork.updateArchive(l2Block.
|
|
60
|
+
await fork.updateArchive(l2Block.getBlockHeader());
|
|
58
61
|
const archiveState = await fork.getTreeInfo(MerkleTreeId.ARCHIVE);
|
|
59
62
|
l2Block.archive = new AppendOnlyTreeSnapshot(Fr.fromBuffer(archiveState.root), Number(archiveState.size));
|
|
60
63
|
return {
|
package/dest/testing.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { PublicDataTreeLeaf } from '@aztec/stdlib/trees';
|
|
|
4
4
|
export declare const defaultInitialAccountFeeJuice: Fr;
|
|
5
5
|
export declare function getGenesisValues(initialAccounts: AztecAddress[], initialAccountFeeJuice?: Fr, genesisPublicData?: PublicDataTreeLeaf[]): Promise<{
|
|
6
6
|
genesisArchiveRoot: Fr;
|
|
7
|
-
genesisBlockHash: Fr;
|
|
8
7
|
prefilledPublicData: PublicDataTreeLeaf[];
|
|
8
|
+
fundingNeeded: bigint;
|
|
9
9
|
}>;
|
|
10
|
-
//# sourceMappingURL=
|
|
10
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdGluZy5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL3Rlc3RpbmcudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQ0EsT0FBTyxFQUFFLEVBQUUsRUFBRSxNQUFNLDBCQUEwQixDQUFDO0FBRTlDLE9BQU8sS0FBSyxFQUFFLFlBQVksRUFBRSxNQUFNLDZCQUE2QixDQUFDO0FBQ2hFLE9BQU8sRUFBZ0Isa0JBQWtCLEVBQUUsTUFBTSxxQkFBcUIsQ0FBQztBQXlCdkUsZUFBTyxNQUFNLDZCQUE2QixJQUFxQixDQUFDO0FBRWhFLHdCQUFzQixnQkFBZ0IsQ0FDcEMsZUFBZSxFQUFFLFlBQVksRUFBRSxFQUMvQixzQkFBc0IsS0FBZ0MsRUFDdEQsaUJBQWlCLEdBQUUsa0JBQWtCLEVBQU87Ozs7R0FxQjdDIn0=
|
package/dest/testing.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAE9C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAgB,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAE9C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAgB,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAyBvE,eAAO,MAAM,6BAA6B,IAAqB,CAAC;AAEhE,wBAAsB,gBAAgB,CACpC,eAAe,EAAE,YAAY,EAAE,EAC/B,sBAAsB,KAAgC,EACtD,iBAAiB,GAAE,kBAAkB,EAAO;;;;GAqB7C"}
|
package/dest/testing.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GENESIS_ARCHIVE_ROOT
|
|
1
|
+
import { GENESIS_ARCHIVE_ROOT } from '@aztec/constants';
|
|
2
2
|
import { Fr } from '@aztec/foundation/fields';
|
|
3
3
|
import { computeFeePayerBalanceLeafSlot } from '@aztec/protocol-contracts/fee-juice';
|
|
4
4
|
import { MerkleTreeId, PublicDataTreeLeaf } from '@aztec/stdlib/trees';
|
|
@@ -6,19 +6,15 @@ import { NativeWorldStateService } from './native/index.js';
|
|
|
6
6
|
async function generateGenesisValues(prefilledPublicData) {
|
|
7
7
|
if (!prefilledPublicData.length) {
|
|
8
8
|
return {
|
|
9
|
-
genesisArchiveRoot: new Fr(GENESIS_ARCHIVE_ROOT)
|
|
10
|
-
genesisBlockHash: new Fr(GENESIS_BLOCK_HASH)
|
|
9
|
+
genesisArchiveRoot: new Fr(GENESIS_ARCHIVE_ROOT)
|
|
11
10
|
};
|
|
12
11
|
}
|
|
13
12
|
// Create a temporary world state to compute the genesis values.
|
|
14
13
|
const ws = await NativeWorldStateService.tmp(undefined /* rollupAddress */ , true, prefilledPublicData);
|
|
15
|
-
const initialHeader = ws.getInitialHeader();
|
|
16
|
-
const genesisBlockHash = await initialHeader.hash();
|
|
17
14
|
const genesisArchiveRoot = new Fr((await ws.getCommitted().getTreeInfo(MerkleTreeId.ARCHIVE)).root);
|
|
18
15
|
await ws.close();
|
|
19
16
|
return {
|
|
20
|
-
genesisArchiveRoot
|
|
21
|
-
genesisBlockHash
|
|
17
|
+
genesisArchiveRoot
|
|
22
18
|
};
|
|
23
19
|
}
|
|
24
20
|
export const defaultInitialAccountFeeJuice = new Fr(10n ** 22n);
|
|
@@ -28,10 +24,10 @@ export async function getGenesisValues(initialAccounts, initialAccountFeeJuice =
|
|
|
28
24
|
// Add user-defined public data
|
|
29
25
|
prefilledPublicData = prefilledPublicData.concat(genesisPublicData);
|
|
30
26
|
prefilledPublicData.sort((a, b)=>b.slot.lt(a.slot) ? 1 : -1);
|
|
31
|
-
const {
|
|
27
|
+
const { genesisArchiveRoot } = await generateGenesisValues(prefilledPublicData);
|
|
32
28
|
return {
|
|
33
29
|
genesisArchiveRoot,
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
prefilledPublicData,
|
|
31
|
+
fundingNeeded: BigInt(initialAccounts.length) * initialAccountFeeJuice.toBigInt()
|
|
36
32
|
};
|
|
37
33
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export * from './merkle_tree_db.js';
|
|
2
2
|
export type { MerkleTreeReadOperations } from '@aztec/stdlib/interfaces/server';
|
|
3
|
-
//# sourceMappingURL=
|
|
3
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy93b3JsZC1zdGF0ZS1kYi9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxjQUFjLHFCQUFxQixDQUFDO0FBRXBDLFlBQVksRUFBRSx3QkFBd0IsRUFBRSxNQUFNLGlDQUFpQyxDQUFDIn0=
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Fr } from '@aztec/foundation/fields';
|
|
2
2
|
import type { IndexedTreeSnapshot, TreeSnapshot } from '@aztec/merkle-tree';
|
|
3
|
-
import type { L2Block } from '@aztec/stdlib/block';
|
|
3
|
+
import type { L2Block, L2BlockNew } from '@aztec/stdlib/block';
|
|
4
4
|
import type { ForkMerkleTreeOperations, MerkleTreeReadOperations } from '@aztec/stdlib/interfaces/server';
|
|
5
5
|
import type { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
6
6
|
import type { WorldStateStatusFull, WorldStateStatusSummary } from '../native/message.js';
|
|
@@ -33,8 +33,10 @@ export interface MerkleTreeAdminDatabase extends ForkMerkleTreeOperations {
|
|
|
33
33
|
* Handles a single L2 block (i.e. Inserts the new note hashes into the merkle tree).
|
|
34
34
|
* @param block - The L2 block to handle.
|
|
35
35
|
* @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.
|
|
36
38
|
*/
|
|
37
|
-
handleL2BlockAndMessages(block: L2Block, l1ToL2Messages: Fr[]): Promise<WorldStateStatusFull>;
|
|
39
|
+
handleL2BlockAndMessages(block: L2Block | L2BlockNew, l1ToL2Messages: Fr[], isFirstBlock?: boolean): Promise<WorldStateStatusFull>;
|
|
38
40
|
/**
|
|
39
41
|
* Gets a handle that allows reading the latest committed state
|
|
40
42
|
*/
|
|
@@ -52,11 +54,11 @@ export interface MerkleTreeAdminDatabase extends ForkMerkleTreeOperations {
|
|
|
52
54
|
*/
|
|
53
55
|
unwindBlocks(toBlockNumber: bigint): Promise<WorldStateStatusFull>;
|
|
54
56
|
/**
|
|
55
|
-
* Advances the
|
|
56
|
-
* @param toBlockNumber The block number that is now the tip of the
|
|
57
|
+
* Advances the finalized block number to be the number provided
|
|
58
|
+
* @param toBlockNumber The block number that is now the tip of the finalized chain
|
|
57
59
|
* @returns The new WorldStateStatus
|
|
58
60
|
*/
|
|
59
|
-
|
|
61
|
+
setFinalized(toBlockNumber: bigint): Promise<WorldStateStatusSummary>;
|
|
60
62
|
/**
|
|
61
63
|
* Gets the current status summary of the database.
|
|
62
64
|
* @returns The current WorldStateStatus.
|
|
@@ -64,5 +66,7 @@ export interface MerkleTreeAdminDatabase extends ForkMerkleTreeOperations {
|
|
|
64
66
|
getStatusSummary(): Promise<WorldStateStatusSummary>;
|
|
65
67
|
/** Stops the database */
|
|
66
68
|
close(): Promise<void>;
|
|
69
|
+
/** Deletes the db. */
|
|
70
|
+
clear(): Promise<void>;
|
|
67
71
|
}
|
|
68
|
-
//# sourceMappingURL=
|
|
72
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWVya2xlX3RyZWVfZGIuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy93b3JsZC1zdGF0ZS1kYi9tZXJrbGVfdHJlZV9kYi50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFDQSxPQUFPLEtBQUssRUFBRSxFQUFFLEVBQUUsTUFBTSwwQkFBMEIsQ0FBQztBQUNuRCxPQUFPLEtBQUssRUFBRSxtQkFBbUIsRUFBRSxZQUFZLEVBQUUsTUFBTSxvQkFBb0IsQ0FBQztBQUM1RSxPQUFPLEtBQUssRUFBRSxPQUFPLEVBQUUsVUFBVSxFQUFFLE1BQU0scUJBQXFCLENBQUM7QUFDL0QsT0FBTyxLQUFLLEVBQUUsd0JBQXdCLEVBQUUsd0JBQXdCLEVBQUUsTUFBTSxpQ0FBaUMsQ0FBQztBQUMxRyxPQUFPLEtBQUssRUFBRSxZQUFZLEVBQUUsTUFBTSxxQkFBcUIsQ0FBQztBQUV4RCxPQUFPLEtBQUssRUFBRSxvQkFBb0IsRUFBRSx1QkFBdUIsRUFBRSxNQUFNLHNCQUFzQixDQUFDO0FBRTFGOzs7Ozs7Ozs7Ozs7OztHQWNHO0FBQ0gsZUFBTyxNQUFNLDJCQUEyQixRQUE0QixDQUFDO0FBRXJFLGVBQU8sTUFBTSw2QkFBNkIsUUFBbUQsQ0FBQztBQUU5RixNQUFNLE1BQU0sYUFBYSxHQUFHO0lBQzFCLENBQUMsWUFBWSxDQUFDLGNBQWMsQ0FBQyxFQUFFLG1CQUFtQixDQUFDO0lBQ25ELENBQUMsWUFBWSxDQUFDLGNBQWMsQ0FBQyxFQUFFLFlBQVksQ0FBQyxFQUFFLENBQUMsQ0FBQztJQUNoRCxDQUFDLFlBQVksQ0FBQyxnQkFBZ0IsQ0FBQyxFQUFFLG1CQUFtQixDQUFDO0lBQ3JELENBQUMsWUFBWSxDQUFDLHFCQUFxQixDQUFDLEVBQUUsWUFBWSxDQUFDLEVBQUUsQ0FBQyxDQUFDO0lBQ3ZELENBQUMsWUFBWSxDQUFDLE9BQU8sQ0FBQyxFQUFFLFlBQVksQ0FBQyxFQUFFLENBQUMsQ0FBQztDQUMxQyxDQUFDO0FBRUYsTUFBTSxXQUFXLHVCQUF3QixTQUFRLHdCQUF3QjtJQUN2RTs7Ozs7O09BTUc7SUFDSCx3QkFBd0IsQ0FDdEIsS0FBSyxFQUFFLE9BQU8sR0FBRyxVQUFVLEVBQzNCLGNBQWMsRUFBRSxFQUFFLEVBQUUsRUFDcEIsWUFBWSxDQUFDLEVBQUUsT0FBTyxHQUNyQixPQUFPLENBQUMsb0JBQW9CLENBQUMsQ0FBQztJQUVqQzs7T0FFRztJQUNILFlBQVksSUFBSSx3QkFBd0IsQ0FBQztJQUV6Qzs7OztPQUlHO0lBQ0gsc0JBQXNCLENBQUMsYUFBYSxFQUFFLE1BQU0sR0FBRyxPQUFPLENBQUMsb0JBQW9CLENBQUMsQ0FBQztJQUU3RTs7OztPQUlHO0lBQ0gsWUFBWSxDQUFDLGFBQWEsRUFBRSxNQUFNLEdBQUcsT0FBTyxDQUFDLG9CQUFvQixDQUFDLENBQUM7SUFFbkU7Ozs7T0FJRztJQUNILFlBQVksQ0FBQyxhQUFhLEVBQUUsTUFBTSxHQUFHLE9BQU8sQ0FBQyx1QkFBdUIsQ0FBQyxDQUFDO0lBRXRFOzs7T0FHRztJQUNILGdCQUFnQixJQUFJLE9BQU8sQ0FBQyx1QkFBdUIsQ0FBQyxDQUFDO0lBRXJELHlCQUF5QjtJQUN6QixLQUFLLElBQUksT0FBTyxDQUFDLElBQUksQ0FBQyxDQUFDO0lBRXZCLHNCQUFzQjtJQUN0QixLQUFLLElBQUksT0FBTyxDQUFDLElBQUksQ0FBQyxDQUFDO0NBQ3hCIn0=
|
|
@@ -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,0BAA0B,CAAC;AACnD,OAAO,KAAK,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC5E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;
|
|
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,0BAA0B,CAAC;AACnD,OAAO,KAAK,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC5E,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAC/D,OAAO,KAAK,EAAE,wBAAwB,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AAC1G,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;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,MAAM,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;IAE7E;;;;OAIG;IACH,YAAY,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;IAEnE;;;;OAIG;IACH,YAAY,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAAC;IAEtE;;;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.
|
|
3
|
+
"version": "0.0.1-commit.21caa21",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dest/index.js",
|
|
@@ -18,11 +18,9 @@
|
|
|
18
18
|
"tsconfig": "./tsconfig.json"
|
|
19
19
|
},
|
|
20
20
|
"scripts": {
|
|
21
|
-
"build": "yarn clean &&
|
|
22
|
-
"build:dev": "
|
|
21
|
+
"build": "yarn clean && tsgo -b",
|
|
22
|
+
"build:dev": "tsgo -b --watch",
|
|
23
23
|
"clean": "rm -rf ./dest .tsbuildinfo",
|
|
24
|
-
"formatting": "run -T prettier --check ./src && run -T eslint ./src",
|
|
25
|
-
"formatting:fix": "run -T eslint --fix ./src && run -T prettier -w ./src",
|
|
26
24
|
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
|
|
27
25
|
},
|
|
28
26
|
"inherits": [
|
|
@@ -59,32 +57,34 @@
|
|
|
59
57
|
"testTimeout": 120000,
|
|
60
58
|
"setupFiles": [
|
|
61
59
|
"../../foundation/src/jest/setup.mjs"
|
|
60
|
+
],
|
|
61
|
+
"testEnvironment": "../../foundation/src/jest/env.mjs",
|
|
62
|
+
"setupFilesAfterEnv": [
|
|
63
|
+
"../../foundation/src/jest/setupAfterEnv.mjs"
|
|
62
64
|
]
|
|
63
65
|
},
|
|
64
66
|
"dependencies": {
|
|
65
|
-
"@aztec/constants": "0.0.
|
|
66
|
-
"@aztec/foundation": "0.0.
|
|
67
|
-
"@aztec/kv-store": "0.0.
|
|
68
|
-
"@aztec/merkle-tree": "0.0.
|
|
69
|
-
"@aztec/native": "0.0.
|
|
70
|
-
"@aztec/protocol-contracts": "0.0.
|
|
71
|
-
"@aztec/stdlib": "0.0.
|
|
72
|
-
"@aztec/telemetry-client": "0.0.
|
|
67
|
+
"@aztec/constants": "0.0.1-commit.21caa21",
|
|
68
|
+
"@aztec/foundation": "0.0.1-commit.21caa21",
|
|
69
|
+
"@aztec/kv-store": "0.0.1-commit.21caa21",
|
|
70
|
+
"@aztec/merkle-tree": "0.0.1-commit.21caa21",
|
|
71
|
+
"@aztec/native": "0.0.1-commit.21caa21",
|
|
72
|
+
"@aztec/protocol-contracts": "0.0.1-commit.21caa21",
|
|
73
|
+
"@aztec/stdlib": "0.0.1-commit.21caa21",
|
|
74
|
+
"@aztec/telemetry-client": "0.0.1-commit.21caa21",
|
|
73
75
|
"tslib": "^2.4.0",
|
|
74
76
|
"zod": "^3.23.8"
|
|
75
77
|
},
|
|
76
78
|
"devDependencies": {
|
|
77
|
-
"@aztec/archiver": "0.0.
|
|
78
|
-
"@jest/globals": "^
|
|
79
|
-
"@types/jest": "^
|
|
80
|
-
"@types/
|
|
81
|
-
"@
|
|
82
|
-
"
|
|
83
|
-
"jest": "^
|
|
84
|
-
"jest-mock-extended": "^3.0.5",
|
|
85
|
-
"memdown": "^6.1.1",
|
|
79
|
+
"@aztec/archiver": "0.0.1-commit.21caa21",
|
|
80
|
+
"@jest/globals": "^30.0.0",
|
|
81
|
+
"@types/jest": "^30.0.0",
|
|
82
|
+
"@types/node": "^22.15.17",
|
|
83
|
+
"@typescript/native-preview": "7.0.0-dev.20251126.1",
|
|
84
|
+
"jest": "^30.0.0",
|
|
85
|
+
"jest-mock-extended": "^4.0.0",
|
|
86
86
|
"ts-node": "^10.9.1",
|
|
87
|
-
"typescript": "^5.
|
|
87
|
+
"typescript": "^5.3.3"
|
|
88
88
|
},
|
|
89
89
|
"files": [
|
|
90
90
|
"dest",
|
|
@@ -93,6 +93,6 @@
|
|
|
93
93
|
],
|
|
94
94
|
"types": "./dest/index.d.ts",
|
|
95
95
|
"engines": {
|
|
96
|
-
"node": ">=
|
|
96
|
+
"node": ">=20.10"
|
|
97
97
|
}
|
|
98
98
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
1
|
+
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
2
2
|
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
3
3
|
import {
|
|
4
4
|
Attributes,
|
|
@@ -31,34 +31,43 @@ const durationTrackDenylist = new Set<WorldStateMessageType>([
|
|
|
31
31
|
|
|
32
32
|
export class WorldStateInstrumentation {
|
|
33
33
|
private dbMapSize: Gauge;
|
|
34
|
+
private dbPhysicalSize: Gauge;
|
|
34
35
|
private treeSize: Gauge;
|
|
35
|
-
private
|
|
36
|
-
private
|
|
36
|
+
private unfinalizedHeight: Gauge;
|
|
37
|
+
private finalizedHeight: Gauge;
|
|
37
38
|
private oldestBlock: Gauge;
|
|
38
39
|
private dbNumItems: Gauge;
|
|
39
40
|
private dbUsedSize: Gauge;
|
|
40
41
|
private requestHistogram: Histogram;
|
|
41
42
|
private criticalErrors: UpDownCounter;
|
|
42
43
|
|
|
43
|
-
constructor(
|
|
44
|
+
constructor(
|
|
45
|
+
public readonly telemetry: TelemetryClient,
|
|
46
|
+
private log: Logger = createLogger('world-state:instrumentation'),
|
|
47
|
+
) {
|
|
44
48
|
const meter = telemetry.getMeter('World State');
|
|
45
49
|
this.dbMapSize = meter.createGauge(Metrics.WORLD_STATE_DB_MAP_SIZE, {
|
|
46
50
|
description: `The current configured map size for each merkle tree`,
|
|
47
51
|
valueType: ValueType.INT,
|
|
48
52
|
});
|
|
49
53
|
|
|
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
|
+
});
|
|
58
|
+
|
|
50
59
|
this.treeSize = meter.createGauge(Metrics.WORLD_STATE_TREE_SIZE, {
|
|
51
60
|
description: `The current number of leaves in each merkle tree`,
|
|
52
61
|
valueType: ValueType.INT,
|
|
53
62
|
});
|
|
54
63
|
|
|
55
|
-
this.
|
|
56
|
-
description: `The
|
|
64
|
+
this.unfinalizedHeight = meter.createGauge(Metrics.WORLD_STATE_UNFINALIZED_HEIGHT, {
|
|
65
|
+
description: `The unfinalized block height of each merkle tree`,
|
|
57
66
|
valueType: ValueType.INT,
|
|
58
67
|
});
|
|
59
68
|
|
|
60
|
-
this.
|
|
61
|
-
description: `The
|
|
69
|
+
this.finalizedHeight = meter.createGauge(Metrics.WORLD_STATE_FINALIZED_HEIGHT, {
|
|
70
|
+
description: `The finalized block height of each merkle tree`,
|
|
62
71
|
valueType: ValueType.INT,
|
|
63
72
|
});
|
|
64
73
|
|
|
@@ -93,13 +102,16 @@ export class WorldStateInstrumentation {
|
|
|
93
102
|
this.dbMapSize.record(Number(treeDbStats.mapSize), {
|
|
94
103
|
[Attributes.MERKLE_TREE_NAME]: MerkleTreeId[tree],
|
|
95
104
|
});
|
|
105
|
+
this.dbPhysicalSize.record(Number(treeDbStats.physicalFileSize), {
|
|
106
|
+
[Attributes.MERKLE_TREE_NAME]: MerkleTreeId[tree],
|
|
107
|
+
});
|
|
96
108
|
this.treeSize.record(Number(treeMeta.size), {
|
|
97
109
|
[Attributes.MERKLE_TREE_NAME]: MerkleTreeId[tree],
|
|
98
110
|
});
|
|
99
|
-
this.
|
|
111
|
+
this.unfinalizedHeight.record(Number(treeMeta.unfinalizedBlockHeight), {
|
|
100
112
|
[Attributes.MERKLE_TREE_NAME]: MerkleTreeId[tree],
|
|
101
113
|
});
|
|
102
|
-
this.
|
|
114
|
+
this.finalizedHeight.record(Number(treeMeta.finalizedBlockHeight), {
|
|
103
115
|
[Attributes.MERKLE_TREE_NAME]: MerkleTreeId[tree],
|
|
104
116
|
});
|
|
105
117
|
this.oldestBlock.record(Number(treeMeta.oldestHistoricBlock), {
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
2
|
+
|
|
3
|
+
type BlockSyncMetrics = {
|
|
4
|
+
numTxs: number;
|
|
5
|
+
numLeaves: number;
|
|
6
|
+
value: number;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export enum InsertionType {
|
|
10
|
+
BATCH,
|
|
11
|
+
SEQUENTIAL,
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
type InsertionMetrics = {
|
|
15
|
+
treeType: MerkleTreeId;
|
|
16
|
+
insertionType: InsertionType;
|
|
17
|
+
numLeaves: number;
|
|
18
|
+
value: number;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export enum DataRetrievalType {
|
|
22
|
+
SIBLING_PATH,
|
|
23
|
+
LEAF_PREIMAGE,
|
|
24
|
+
LEAF_VALUE,
|
|
25
|
+
LEAF_INDICES,
|
|
26
|
+
LOW_LEAF,
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
type DataRetrievalMetrics = {
|
|
30
|
+
retrievalType: DataRetrievalType;
|
|
31
|
+
value: number;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export class NativeBenchMetics {
|
|
35
|
+
private blockSyncMetrics: BlockSyncMetrics[] = [];
|
|
36
|
+
private insertionMetrics: InsertionMetrics[] = [];
|
|
37
|
+
private dataRetrievalMetrics: DataRetrievalMetrics[] = [];
|
|
38
|
+
|
|
39
|
+
public toPrettyString() {
|
|
40
|
+
let pretty = '';
|
|
41
|
+
pretty += `Block sync metrics:\n`;
|
|
42
|
+
for (const metric of this.blockSyncMetrics) {
|
|
43
|
+
pretty += ` ${metric.numTxs} txs, ${metric.numLeaves} leaves: ${metric.value} ms\n`;
|
|
44
|
+
}
|
|
45
|
+
pretty += `Insertion metrics:\n`;
|
|
46
|
+
for (const metric of this.insertionMetrics) {
|
|
47
|
+
pretty += ` ${MerkleTreeId[metric.treeType]}: ${InsertionType[metric.insertionType]} (${metric.numLeaves} leaves): ${metric.value} ms\n`;
|
|
48
|
+
}
|
|
49
|
+
pretty += `Data retrieval metrics:\n`;
|
|
50
|
+
for (const metric of this.dataRetrievalMetrics) {
|
|
51
|
+
pretty += ` ${DataRetrievalType[metric.retrievalType]}: ${metric.value} us\n`;
|
|
52
|
+
}
|
|
53
|
+
return pretty;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
public addBlockSyncMetric(numTxs: number, numLeaves: number, value: number) {
|
|
57
|
+
this.blockSyncMetrics.push({ numTxs, numLeaves, value });
|
|
58
|
+
}
|
|
59
|
+
public addInsertionMetric(treeId: MerkleTreeId, insertionType: InsertionType, numLeaves: number, value: number) {
|
|
60
|
+
this.insertionMetrics.push({ treeType: treeId, insertionType, numLeaves, value });
|
|
61
|
+
}
|
|
62
|
+
public addDataRetrievalMetric(retrievalType: DataRetrievalType, value: number) {
|
|
63
|
+
this.dataRetrievalMetrics.push({ retrievalType, value: value });
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
public toGithubActionBenchmarkJSON(indent = 2) {
|
|
67
|
+
const data = [];
|
|
68
|
+
for (const blockSync of this.blockSyncMetrics) {
|
|
69
|
+
data.push({
|
|
70
|
+
name: `Block Sync/${blockSync.numTxs} txs/${blockSync.numLeaves} leaves per tx`,
|
|
71
|
+
value: blockSync.value,
|
|
72
|
+
unit: 'ms',
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
for (const insertion of this.insertionMetrics) {
|
|
76
|
+
data.push({
|
|
77
|
+
name: `Tree Insertion/${MerkleTreeId[insertion.treeType]}/${InsertionType[insertion.insertionType]}/${insertion.numLeaves} leaves`,
|
|
78
|
+
value: insertion.value,
|
|
79
|
+
unit: 'ms',
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
for (const retrieval of this.dataRetrievalMetrics) {
|
|
83
|
+
data.push({
|
|
84
|
+
name: `Data Retrieval/${DataRetrievalType[retrieval.retrievalType]}`,
|
|
85
|
+
value: retrieval.value,
|
|
86
|
+
unit: 'us',
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
return JSON.stringify(data, null, indent);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
PublicDataTreeLeafPreimage,
|
|
19
19
|
} from '@aztec/stdlib/trees';
|
|
20
20
|
import { type BlockHeader, PartialStateReference, StateReference } from '@aztec/stdlib/tx';
|
|
21
|
+
import { type WorldStateRevision, WorldStateRevisionWithHandle } from '@aztec/stdlib/world-state';
|
|
21
22
|
|
|
22
23
|
import assert from 'assert';
|
|
23
24
|
|
|
@@ -25,7 +26,6 @@ import {
|
|
|
25
26
|
type SerializedIndexedLeaf,
|
|
26
27
|
type SerializedLeafValue,
|
|
27
28
|
WorldStateMessageType,
|
|
28
|
-
type WorldStateRevision,
|
|
29
29
|
blockStateReference,
|
|
30
30
|
treeStateReferenceToSnapshot,
|
|
31
31
|
} from './message.js';
|
|
@@ -42,10 +42,32 @@ export class MerkleTreesFacade implements MerkleTreeReadOperations {
|
|
|
42
42
|
return this.initialHeader;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
getRevision(): WorldStateRevisionWithHandle {
|
|
46
|
+
return WorldStateRevisionWithHandle.fromWorldStateRevision(this.revision, this.instance.getHandle());
|
|
47
|
+
}
|
|
48
|
+
|
|
45
49
|
findLeafIndices(treeId: MerkleTreeId, values: MerkleTreeLeafType<MerkleTreeId>[]): Promise<(bigint | undefined)[]> {
|
|
46
50
|
return this.findLeafIndicesAfter(treeId, values, 0n);
|
|
47
51
|
}
|
|
48
52
|
|
|
53
|
+
async findSiblingPaths<N extends number>(
|
|
54
|
+
treeId: MerkleTreeId,
|
|
55
|
+
values: MerkleTreeLeafType<MerkleTreeId>[],
|
|
56
|
+
): Promise<({ path: SiblingPath<N>; index: bigint } | undefined)[]> {
|
|
57
|
+
const response = await this.instance.call(WorldStateMessageType.FIND_SIBLING_PATHS, {
|
|
58
|
+
leaves: values.map(leaf => serializeLeaf(hydrateLeaf(treeId, leaf))),
|
|
59
|
+
revision: this.revision,
|
|
60
|
+
treeId,
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
return response.paths.map(path => {
|
|
64
|
+
if (!path) {
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
67
|
+
return { path: new SiblingPath<N>(path.path.length as N, path.path), index: BigInt(path.index) };
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
49
71
|
async findLeafIndicesAfter(
|
|
50
72
|
treeId: MerkleTreeId,
|
|
51
73
|
leaves: MerkleTreeLeafType<MerkleTreeId>[],
|
|
@@ -277,6 +299,16 @@ export class MerkleTreesForkFacade extends MerkleTreesFacade implements MerkleTr
|
|
|
277
299
|
assert.notEqual(this.revision.forkId, 0, 'Fork ID must be set');
|
|
278
300
|
await this.instance.call(WorldStateMessageType.REVERT_CHECKPOINT, { forkId: this.revision.forkId });
|
|
279
301
|
}
|
|
302
|
+
|
|
303
|
+
public async commitAllCheckpoints(): Promise<void> {
|
|
304
|
+
assert.notEqual(this.revision.forkId, 0, 'Fork ID must be set');
|
|
305
|
+
await this.instance.call(WorldStateMessageType.COMMIT_ALL_CHECKPOINTS, { forkId: this.revision.forkId });
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
public async revertAllCheckpoints(): Promise<void> {
|
|
309
|
+
assert.notEqual(this.revision.forkId, 0, 'Fork ID must be set');
|
|
310
|
+
await this.instance.call(WorldStateMessageType.REVERT_ALL_CHECKPOINTS, { forkId: this.revision.forkId });
|
|
311
|
+
}
|
|
280
312
|
}
|
|
281
313
|
|
|
282
314
|
function hydrateLeaf<ID extends MerkleTreeId>(treeId: ID, leaf: Fr | Buffer) {
|
|
@@ -295,7 +327,7 @@ export function serializeLeaf(leaf: Fr | NullifierLeaf | PublicDataTreeLeaf): Se
|
|
|
295
327
|
if (leaf instanceof Fr) {
|
|
296
328
|
return leaf.toBuffer();
|
|
297
329
|
} else if (leaf instanceof NullifierLeaf) {
|
|
298
|
-
return {
|
|
330
|
+
return { nullifier: leaf.nullifier.toBuffer() };
|
|
299
331
|
} else {
|
|
300
332
|
return { value: leaf.value.toBuffer(), slot: leaf.slot.toBuffer() };
|
|
301
333
|
}
|
|
@@ -307,23 +339,22 @@ function deserializeLeafValue(leaf: SerializedLeafValue): Fr | NullifierLeaf | P
|
|
|
307
339
|
} else if ('slot' in leaf) {
|
|
308
340
|
return new PublicDataTreeLeaf(Fr.fromBuffer(leaf.slot), Fr.fromBuffer(leaf.value));
|
|
309
341
|
} else {
|
|
310
|
-
return new NullifierLeaf(Fr.fromBuffer(leaf.
|
|
342
|
+
return new NullifierLeaf(Fr.fromBuffer(leaf.nullifier));
|
|
311
343
|
}
|
|
312
344
|
}
|
|
313
345
|
|
|
314
|
-
function deserializeIndexedLeaf(
|
|
315
|
-
if ('slot' in leaf
|
|
346
|
+
function deserializeIndexedLeaf(leafPreimage: SerializedIndexedLeaf): IndexedTreeLeafPreimage {
|
|
347
|
+
if ('slot' in leafPreimage.leaf) {
|
|
316
348
|
return new PublicDataTreeLeafPreimage(
|
|
317
|
-
Fr.fromBuffer(leaf.
|
|
318
|
-
Fr.fromBuffer(
|
|
319
|
-
|
|
320
|
-
BigInt(leaf.nextIndex),
|
|
349
|
+
new PublicDataTreeLeaf(Fr.fromBuffer(leafPreimage.leaf.slot), Fr.fromBuffer(leafPreimage.leaf.value)),
|
|
350
|
+
Fr.fromBuffer(leafPreimage.nextKey),
|
|
351
|
+
BigInt(leafPreimage.nextIndex),
|
|
321
352
|
);
|
|
322
|
-
} else if ('
|
|
353
|
+
} else if ('nullifier' in leafPreimage.leaf) {
|
|
323
354
|
return new NullifierLeafPreimage(
|
|
324
|
-
Fr.fromBuffer(leaf.
|
|
325
|
-
Fr.fromBuffer(
|
|
326
|
-
BigInt(
|
|
355
|
+
new NullifierLeaf(Fr.fromBuffer(leafPreimage.leaf.nullifier)),
|
|
356
|
+
Fr.fromBuffer(leafPreimage.nextKey),
|
|
357
|
+
BigInt(leafPreimage.nextIndex),
|
|
327
358
|
);
|
|
328
359
|
} else {
|
|
329
360
|
throw new Error('Invalid leaf type');
|