@aztec/world-state 0.0.1-commit.d3ec352c → 0.0.1-commit.fcb71a6
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 +8 -3
- package/dest/native/merkle_trees_facade.d.ts.map +1 -1
- package/dest/native/merkle_trees_facade.js +21 -3
- package/dest/native/message.d.ts +2 -2
- package/dest/native/message.d.ts.map +1 -1
- package/dest/native/message.js +1 -1
- package/dest/native/native_world_state.d.ts +6 -4
- package/dest/native/native_world_state.d.ts.map +1 -1
- package/dest/native/native_world_state.js +5 -4
- package/dest/synchronizer/server_world_state_synchronizer.d.ts +4 -2
- package/dest/synchronizer/server_world_state_synchronizer.d.ts.map +1 -1
- package/dest/synchronizer/server_world_state_synchronizer.js +17 -16
- package/dest/test/utils.d.ts +7 -13
- package/dest/test/utils.d.ts.map +1 -1
- package/dest/test/utils.js +42 -79
- 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 +6 -8
- package/dest/world-state-db/merkle_tree_db.d.ts.map +1 -1
- package/package.json +10 -10
- package/src/native/merkle_trees_facade.ts +26 -2
- package/src/native/message.ts +1 -1
- package/src/native/native_world_state.ts +8 -7
- package/src/synchronizer/server_world_state_synchronizer.ts +24 -21
- package/src/test/utils.ts +68 -126
- package/src/testing.ts +1 -1
- package/src/world-state-db/merkle_tree_db.ts +9 -11
- package/dest/synchronizer/utils.d.ts +0 -11
- package/dest/synchronizer/utils.d.ts.map +0 -1
- package/dest/synchronizer/utils.js +0 -59
- package/src/synchronizer/utils.ts +0 -83
package/dest/test/utils.js
CHANGED
|
@@ -1,45 +1,51 @@
|
|
|
1
1
|
import { MAX_NOTE_HASHES_PER_TX, MAX_NULLIFIERS_PER_TX, NULLIFIER_SUBTREE_HEIGHT, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/constants';
|
|
2
|
-
import {
|
|
2
|
+
import { asyncMap } from '@aztec/foundation/async-map';
|
|
3
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
3
4
|
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
4
|
-
import { Fr } from '@aztec/foundation/
|
|
5
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
5
6
|
import { L2BlockNew } from '@aztec/stdlib/block';
|
|
6
|
-
import {
|
|
7
|
-
import { computeInHashFromL1ToL2Messages } from '@aztec/stdlib/messaging';
|
|
7
|
+
import { mockCheckpointAndMessages, mockL1ToL2Messages } from '@aztec/stdlib/testing';
|
|
8
8
|
import { AppendOnlyTreeSnapshot, MerkleTreeId } from '@aztec/stdlib/trees';
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
import { BlockHeader } from '@aztec/stdlib/tx';
|
|
10
|
+
export async function updateBlockState(block, l1ToL2Messages, fork) {
|
|
11
|
+
const insertData = async (treeId, data, subTreeHeight, fork)=>{
|
|
12
|
+
for (const dataBatch of data){
|
|
13
|
+
await fork.batchInsert(treeId, dataBatch, subTreeHeight);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
const publicDataInsert = insertData(MerkleTreeId.PUBLIC_DATA_TREE, block.body.txEffects.map((txEffect)=>txEffect.publicDataWrites.map((write)=>write.toBuffer())), 0, fork);
|
|
17
|
+
const nullifierInsert = insertData(MerkleTreeId.NULLIFIER_TREE, block.body.txEffects.map((txEffect)=>padArrayEnd(txEffect.nullifiers, Fr.ZERO, MAX_NULLIFIERS_PER_TX).map((nullifier)=>nullifier.toBuffer())), NULLIFIER_SUBTREE_HEIGHT, fork);
|
|
18
|
+
const noteHashesPadded = block.body.txEffects.flatMap((txEffect)=>padArrayEnd(txEffect.noteHashes, Fr.ZERO, MAX_NOTE_HASHES_PER_TX));
|
|
19
|
+
const l1ToL2MessagesPadded = block.indexWithinCheckpoint === 0 ? padArrayEnd(l1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP) : l1ToL2Messages;
|
|
20
|
+
const noteHashInsert = fork.appendLeaves(MerkleTreeId.NOTE_HASH_TREE, noteHashesPadded);
|
|
21
|
+
const messageInsert = fork.appendLeaves(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, l1ToL2MessagesPadded);
|
|
22
|
+
await Promise.all([
|
|
23
|
+
publicDataInsert,
|
|
24
|
+
nullifierInsert,
|
|
25
|
+
noteHashInsert,
|
|
26
|
+
messageInsert
|
|
27
|
+
]);
|
|
28
|
+
const state = await fork.getStateReference();
|
|
29
|
+
block.header = BlockHeader.from({
|
|
30
|
+
...block.header,
|
|
31
|
+
state
|
|
32
|
+
});
|
|
33
|
+
await fork.updateArchive(block.header);
|
|
34
|
+
const archiveState = await fork.getTreeInfo(MerkleTreeId.ARCHIVE);
|
|
35
|
+
block.archive = new AppendOnlyTreeSnapshot(Fr.fromBuffer(archiveState.root), Number(archiveState.size));
|
|
36
|
+
}
|
|
37
|
+
export async function mockBlock(blockNum, size, fork, maxEffects = 1000, numL1ToL2Messages = NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP, isFirstBlockInCheckpoint = true) {
|
|
38
|
+
const block = await L2BlockNew.random(blockNum, {
|
|
39
|
+
indexWithinCheckpoint: isFirstBlockInCheckpoint ? 0 : 1,
|
|
11
40
|
txsPerBlock: size,
|
|
12
41
|
txOptions: {
|
|
13
42
|
maxEffects
|
|
14
43
|
}
|
|
15
44
|
});
|
|
16
45
|
const l1ToL2Messages = mockL1ToL2Messages(numL1ToL2Messages);
|
|
17
|
-
|
|
18
|
-
const insertData = async (treeId, data, subTreeHeight, fork)=>{
|
|
19
|
-
for (const dataBatch of data){
|
|
20
|
-
await fork.batchInsert(treeId, dataBatch, subTreeHeight);
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
const publicDataInsert = insertData(MerkleTreeId.PUBLIC_DATA_TREE, l2Block.body.txEffects.map((txEffect)=>txEffect.publicDataWrites.map((write)=>write.toBuffer())), 0, fork);
|
|
24
|
-
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);
|
|
25
|
-
const noteHashesPadded = l2Block.body.txEffects.flatMap((txEffect)=>padArrayEnd(txEffect.noteHashes, Fr.ZERO, MAX_NOTE_HASHES_PER_TX));
|
|
26
|
-
const l1ToL2MessagesPadded = isFirstBlock ? padArrayEnd(l1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP) : l1ToL2Messages;
|
|
27
|
-
const noteHashInsert = fork.appendLeaves(MerkleTreeId.NOTE_HASH_TREE, noteHashesPadded);
|
|
28
|
-
const messageInsert = fork.appendLeaves(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, l1ToL2MessagesPadded);
|
|
29
|
-
await Promise.all([
|
|
30
|
-
publicDataInsert,
|
|
31
|
-
nullifierInsert,
|
|
32
|
-
noteHashInsert,
|
|
33
|
-
messageInsert
|
|
34
|
-
]);
|
|
35
|
-
}
|
|
36
|
-
const state = await fork.getStateReference();
|
|
37
|
-
l2Block.header.state = state;
|
|
38
|
-
await fork.updateArchive(l2Block.header);
|
|
39
|
-
const archiveState = await fork.getTreeInfo(MerkleTreeId.ARCHIVE);
|
|
40
|
-
l2Block.archive = new AppendOnlyTreeSnapshot(Fr.fromBuffer(archiveState.root), Number(archiveState.size));
|
|
46
|
+
await updateBlockState(block, l1ToL2Messages, fork);
|
|
41
47
|
return {
|
|
42
|
-
block
|
|
48
|
+
block,
|
|
43
49
|
messages: l1ToL2Messages
|
|
44
50
|
};
|
|
45
51
|
}
|
|
@@ -47,27 +53,7 @@ export async function mockEmptyBlock(blockNum, fork) {
|
|
|
47
53
|
const l2Block = L2BlockNew.empty();
|
|
48
54
|
const l1ToL2Messages = Array(16).fill(0).map(Fr.zero);
|
|
49
55
|
l2Block.header.globalVariables.blockNumber = blockNum;
|
|
50
|
-
|
|
51
|
-
{
|
|
52
|
-
const noteHashesPadded = l2Block.body.txEffects.flatMap((txEffect)=>padArrayEnd(txEffect.noteHashes, Fr.ZERO, MAX_NOTE_HASHES_PER_TX));
|
|
53
|
-
await fork.appendLeaves(MerkleTreeId.NOTE_HASH_TREE, noteHashesPadded);
|
|
54
|
-
const l1ToL2MessagesPadded = padArrayEnd(l1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP);
|
|
55
|
-
await fork.appendLeaves(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, l1ToL2MessagesPadded);
|
|
56
|
-
}
|
|
57
|
-
// Sync the indexed trees
|
|
58
|
-
{
|
|
59
|
-
// We insert the public data tree leaves with one batch per tx to avoid updating the same key twice
|
|
60
|
-
for (const txEffect of l2Block.body.txEffects){
|
|
61
|
-
await fork.batchInsert(MerkleTreeId.PUBLIC_DATA_TREE, txEffect.publicDataWrites.map((write)=>write.toBuffer()), 0);
|
|
62
|
-
const nullifiersPadded = padArrayEnd(txEffect.nullifiers, Fr.ZERO, MAX_NULLIFIERS_PER_TX);
|
|
63
|
-
await fork.batchInsert(MerkleTreeId.NULLIFIER_TREE, nullifiersPadded.map((nullifier)=>nullifier.toBuffer()), NULLIFIER_SUBTREE_HEIGHT);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
const state = await fork.getStateReference();
|
|
67
|
-
l2Block.header.state = state;
|
|
68
|
-
await fork.updateArchive(l2Block.header);
|
|
69
|
-
const archiveState = await fork.getTreeInfo(MerkleTreeId.ARCHIVE);
|
|
70
|
-
l2Block.archive = new AppendOnlyTreeSnapshot(Fr.fromBuffer(archiveState.root), Number(archiveState.size));
|
|
56
|
+
await updateBlockState(l2Block, l1ToL2Messages, fork);
|
|
71
57
|
return {
|
|
72
58
|
block: l2Block,
|
|
73
59
|
messages: l1ToL2Messages
|
|
@@ -88,34 +74,11 @@ export async function mockBlocks(from, count, numTxs, worldState) {
|
|
|
88
74
|
messages: messagesArray
|
|
89
75
|
};
|
|
90
76
|
}
|
|
91
|
-
export function
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
const slotNumber = SlotNumber(checkpointNumber * 10);
|
|
96
|
-
const blocksAndMessages = [];
|
|
97
|
-
for(let i = 0; i < numBlocks; i++){
|
|
98
|
-
const blockNumber = BlockNumber(startBlockNumber + i);
|
|
99
|
-
const { block, messages } = fork ? await mockBlock(blockNumber, numTxsPerBlock, fork, blockNumber === startBlockNumber ? numL1ToL2Messages : 0) : {
|
|
100
|
-
block: await L2BlockNew.random(blockNumber, {
|
|
101
|
-
txsPerBlock: numTxsPerBlock,
|
|
102
|
-
slotNumber
|
|
103
|
-
}),
|
|
104
|
-
messages: mockL1ToL2Messages(numL1ToL2Messages)
|
|
105
|
-
};
|
|
106
|
-
blocksAndMessages.push({
|
|
107
|
-
block,
|
|
108
|
-
messages
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
const messages = blocksAndMessages[0].messages;
|
|
112
|
-
const inHash = computeInHashFromL1ToL2Messages(messages);
|
|
113
|
-
const checkpoint = await Checkpoint.random(checkpointNumber, {
|
|
114
|
-
numBlocks: 0,
|
|
115
|
-
slotNumber,
|
|
116
|
-
inHash
|
|
77
|
+
export async function mockCheckpoint(checkpointNumber, fork, options = {}) {
|
|
78
|
+
const { checkpoint, messages } = await mockCheckpointAndMessages(checkpointNumber, options);
|
|
79
|
+
await asyncMap(checkpoint.blocks, async (block, i)=>{
|
|
80
|
+
await updateBlockState(block, i === 0 ? messages : [], fork);
|
|
117
81
|
});
|
|
118
|
-
checkpoint.blocks = blocksAndMessages.map(({ block })=>block);
|
|
119
82
|
return {
|
|
120
83
|
checkpoint,
|
|
121
84
|
messages
|
package/dest/testing.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Fr } from '@aztec/foundation/
|
|
1
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
2
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
3
3
|
import { PublicDataTreeLeaf } from '@aztec/stdlib/trees';
|
|
4
4
|
export declare const defaultInitialAccountFeeJuice: Fr;
|
|
@@ -7,4 +7,4 @@ export declare function getGenesisValues(initialAccounts: AztecAddress[], initia
|
|
|
7
7
|
prefilledPublicData: PublicDataTreeLeaf[];
|
|
8
8
|
fundingNeeded: bigint;
|
|
9
9
|
}>;
|
|
10
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
10
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdGluZy5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL3Rlc3RpbmcudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQ0EsT0FBTyxFQUFFLEVBQUUsRUFBRSxNQUFNLGdDQUFnQyxDQUFDO0FBRXBELE9BQU8sS0FBSyxFQUFFLFlBQVksRUFBRSxNQUFNLDZCQUE2QixDQUFDO0FBQ2hFLE9BQU8sRUFBZ0Isa0JBQWtCLEVBQUUsTUFBTSxxQkFBcUIsQ0FBQztBQXlCdkUsZUFBTyxNQUFNLDZCQUE2QixJQUFxQixDQUFDO0FBRWhFLHdCQUFzQixnQkFBZ0IsQ0FDcEMsZUFBZSxFQUFFLFlBQVksRUFBRSxFQUMvQixzQkFBc0IsS0FBZ0MsRUFDdEQsaUJBQWlCLEdBQUUsa0JBQWtCLEVBQU87Ozs7R0FxQjdDIn0=
|
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,
|
|
1
|
+
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AAEpD,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,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,8 +1,8 @@
|
|
|
1
|
-
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
|
-
import type { Fr } from '@aztec/foundation/
|
|
1
|
+
import type { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
3
|
import type { IndexedTreeSnapshot, TreeSnapshot } from '@aztec/merkle-tree';
|
|
4
4
|
import type { L2BlockNew } from '@aztec/stdlib/block';
|
|
5
|
-
import type { ForkMerkleTreeOperations, MerkleTreeReadOperations } from '@aztec/stdlib/interfaces/server';
|
|
5
|
+
import type { ForkMerkleTreeOperations, MerkleTreeReadOperations, ReadonlyWorldStateAccess } from '@aztec/stdlib/interfaces/server';
|
|
6
6
|
import type { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
7
7
|
import type { WorldStateStatusFull, WorldStateStatusSummary } from '../native/message.js';
|
|
8
8
|
/**
|
|
@@ -29,15 +29,13 @@ export type TreeSnapshots = {
|
|
|
29
29
|
[MerkleTreeId.L1_TO_L2_MESSAGE_TREE]: TreeSnapshot<Fr>;
|
|
30
30
|
[MerkleTreeId.ARCHIVE]: TreeSnapshot<Fr>;
|
|
31
31
|
};
|
|
32
|
-
export interface MerkleTreeAdminDatabase extends ForkMerkleTreeOperations {
|
|
32
|
+
export interface MerkleTreeAdminDatabase extends ForkMerkleTreeOperations, ReadonlyWorldStateAccess {
|
|
33
33
|
/**
|
|
34
34
|
* Handles a single L2 block (i.e. Inserts the new note hashes into the merkle tree).
|
|
35
35
|
* @param block - The L2 block to handle.
|
|
36
36
|
* @param l1ToL2Messages - The L1 to L2 messages for the block.
|
|
37
|
-
* @param isFirstBlock - Whether the block is the first block in a checkpoint. The messages are padded and inserted
|
|
38
|
-
* to the tree for the first block in a checkpoint.
|
|
39
37
|
*/
|
|
40
|
-
handleL2BlockAndMessages(block: L2BlockNew, l1ToL2Messages: Fr[]
|
|
38
|
+
handleL2BlockAndMessages(block: L2BlockNew, l1ToL2Messages: Fr[]): Promise<WorldStateStatusFull>;
|
|
41
39
|
/**
|
|
42
40
|
* Gets a handle that allows reading the latest committed state
|
|
43
41
|
*/
|
|
@@ -70,4 +68,4 @@ export interface MerkleTreeAdminDatabase extends ForkMerkleTreeOperations {
|
|
|
70
68
|
/** Deletes the db. */
|
|
71
69
|
clear(): Promise<void>;
|
|
72
70
|
}
|
|
73
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
71
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWVya2xlX3RyZWVfZGIuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy93b3JsZC1zdGF0ZS1kYi9tZXJrbGVfdHJlZV9kYi50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFDQSxPQUFPLEtBQUssRUFBRSxXQUFXLEVBQ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UFNLFdBQVcsdUJBQXdCLFNBQVEsd0JBQXdCLEVBQUUsd0JBQXdCO0lBQ2pHOzs7O09BSUc7SUFDSCx3QkFBd0IsQ0FBQyxLQUFLLEVBQUUsVUFBVSxFQUFFLGNBQWMsRUFBRSxFQUFFLEVBQUUsR0FBRyxPQUFPLENBQUMsb0JBQW9CLENBQUMsQ0FBQztJQUVqRzs7T0FFRztJQUNILFlBQVksSUFBSSx3QkFBd0IsQ0FBQztJQUV6Qzs7OztPQUlHO0lBQ0gsc0JBQXNCLENBQUMsYUFBYSxFQUFFLFdBQVcsR0FBRyxPQUFPLENBQUMsb0JBQW9CLENBQUMsQ0FBQztJQUVsRjs7OztPQUlHO0lBQ0gsWUFBWSxDQUFDLGFBQWEsRUFBRSxXQUFXLEdBQUcsT0FBTyxDQUFDLG9CQUFvQixDQUFDLENBQUM7SUFFeEU7Ozs7T0FJRztJQUNILFlBQVksQ0FBQyxhQUFhLEVBQUUsV0FBVyxHQUFHLE9BQU8sQ0FBQyx1QkFBdUIsQ0FBQyxDQUFDO0lBRTNFOzs7T0FHRztJQUNILGdCQUFnQixJQUFJLE9BQU8sQ0FBQyx1QkFBdUIsQ0FBQyxDQUFDO0lBRXJELHlCQUF5QjtJQUN6QixLQUFLLElBQUksT0FBTyxDQUFDLElBQUksQ0FBQyxDQUFDO0lBRXZCLHNCQUFzQjtJQUN0QixLQUFLLElBQUksT0FBTyxDQUFDLElBQUksQ0FBQyxDQUFDO0NBQ3hCIn0=
|
|
@@ -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,EAAE,WAAW,EAAE,MAAM,iCAAiC,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,WAAW,EAAE,MAAM,iCAA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ACH,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.fcb71a6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dest/index.js",
|
|
@@ -64,19 +64,19 @@
|
|
|
64
64
|
]
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
|
-
"@aztec/constants": "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.fcb71a6",
|
|
68
|
+
"@aztec/foundation": "0.0.1-commit.fcb71a6",
|
|
69
|
+
"@aztec/kv-store": "0.0.1-commit.fcb71a6",
|
|
70
|
+
"@aztec/merkle-tree": "0.0.1-commit.fcb71a6",
|
|
71
|
+
"@aztec/native": "0.0.1-commit.fcb71a6",
|
|
72
|
+
"@aztec/protocol-contracts": "0.0.1-commit.fcb71a6",
|
|
73
|
+
"@aztec/stdlib": "0.0.1-commit.fcb71a6",
|
|
74
|
+
"@aztec/telemetry-client": "0.0.1-commit.fcb71a6",
|
|
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.fcb71a6",
|
|
80
80
|
"@jest/globals": "^30.0.0",
|
|
81
81
|
"@types/jest": "^30.0.0",
|
|
82
82
|
"@types/node": "^22.15.17",
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
|
-
import { Fr } from '@aztec/foundation/
|
|
2
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
3
4
|
import { serializeToBuffer } from '@aztec/foundation/serialize';
|
|
5
|
+
import { sleep } from '@aztec/foundation/sleep';
|
|
4
6
|
import { type IndexedTreeLeafPreimage, SiblingPath } from '@aztec/foundation/trees';
|
|
5
7
|
import type {
|
|
6
8
|
BatchInsertionResult,
|
|
@@ -204,7 +206,14 @@ export class MerkleTreesFacade implements MerkleTreeReadOperations {
|
|
|
204
206
|
}
|
|
205
207
|
|
|
206
208
|
export class MerkleTreesForkFacade extends MerkleTreesFacade implements MerkleTreeWriteOperations {
|
|
207
|
-
|
|
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
|
+
) {
|
|
208
217
|
assert.notEqual(revision.forkId, 0, 'Fork ID must be set');
|
|
209
218
|
assert.equal(revision.includeUncommitted, true, 'Fork must include uncommitted data');
|
|
210
219
|
super(instance, initialHeader, revision);
|
|
@@ -286,6 +295,21 @@ export class MerkleTreesForkFacade extends MerkleTreesFacade implements MerkleTr
|
|
|
286
295
|
await this.instance.call(WorldStateMessageType.DELETE_FORK, { forkId: this.revision.forkId });
|
|
287
296
|
}
|
|
288
297
|
|
|
298
|
+
async [Symbol.dispose](): Promise<void> {
|
|
299
|
+
if (this.opts.closeDelayMs) {
|
|
300
|
+
void sleep(this.opts.closeDelayMs)
|
|
301
|
+
.then(() => this.close())
|
|
302
|
+
.catch(err => {
|
|
303
|
+
if (err && 'message' in err && err.message === 'Native instance is closed') {
|
|
304
|
+
return; // Ignore errors due to native instance being closed
|
|
305
|
+
}
|
|
306
|
+
this.log.warn('Error closing MerkleTreesForkFacade after delay', { err });
|
|
307
|
+
});
|
|
308
|
+
} else {
|
|
309
|
+
await this.close();
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
289
313
|
public async createCheckpoint(): Promise<void> {
|
|
290
314
|
assert.notEqual(this.revision.forkId, 0, 'Fork ID must be set');
|
|
291
315
|
await this.instance.call(WorldStateMessageType.CREATE_CHECKPOINT, { forkId: this.revision.forkId });
|
package/src/native/message.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
|
-
import { Fr } from '@aztec/foundation/
|
|
2
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
3
|
import type { Tuple } from '@aztec/foundation/serialize';
|
|
4
4
|
import { AppendOnlyTreeSnapshot, MerkleTreeId } from '@aztec/stdlib/trees';
|
|
5
5
|
import type { StateReference } from '@aztec/stdlib/tx';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { MAX_NOTE_HASHES_PER_TX, MAX_NULLIFIERS_PER_TX, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/constants';
|
|
2
2
|
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
3
3
|
import { fromEntries, padArrayEnd } from '@aztec/foundation/collection';
|
|
4
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
5
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
5
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
6
6
|
import { tryRmDir } from '@aztec/foundation/fs';
|
|
7
7
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
8
8
|
import type { L2BlockNew } from '@aztec/stdlib/block';
|
|
@@ -159,7 +159,10 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
|
|
|
159
159
|
);
|
|
160
160
|
}
|
|
161
161
|
|
|
162
|
-
public async fork(
|
|
162
|
+
public async fork(
|
|
163
|
+
blockNumber?: BlockNumber,
|
|
164
|
+
opts: { closeDelayMs?: number } = {},
|
|
165
|
+
): Promise<MerkleTreeWriteOperations> {
|
|
163
166
|
const resp = await this.instance.call(WorldStateMessageType.CREATE_FORK, {
|
|
164
167
|
latest: blockNumber === undefined,
|
|
165
168
|
blockNumber: blockNumber ?? BlockNumber.ZERO,
|
|
@@ -173,6 +176,7 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
|
|
|
173
176
|
/* blockNumber=*/ BlockNumber.ZERO,
|
|
174
177
|
/* includeUncommitted=*/ true,
|
|
175
178
|
),
|
|
179
|
+
opts,
|
|
176
180
|
);
|
|
177
181
|
}
|
|
178
182
|
|
|
@@ -180,11 +184,8 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
|
|
|
180
184
|
return this.initialHeader!;
|
|
181
185
|
}
|
|
182
186
|
|
|
183
|
-
public async handleL2BlockAndMessages(
|
|
184
|
-
l2Block
|
|
185
|
-
l1ToL2Messages: Fr[],
|
|
186
|
-
isFirstBlock: boolean,
|
|
187
|
-
): Promise<WorldStateStatusFull> {
|
|
187
|
+
public async handleL2BlockAndMessages(l2Block: L2BlockNew, l1ToL2Messages: Fr[]): Promise<WorldStateStatusFull> {
|
|
188
|
+
const isFirstBlock = l2Block.indexWithinCheckpoint === 0;
|
|
188
189
|
if (!isFirstBlock && l1ToL2Messages.length > 0) {
|
|
189
190
|
throw new Error(
|
|
190
191
|
`L1 to L2 messages must be empty for non-first blocks, but got ${l1ToL2Messages.length} messages for block ${l2Block.number}.`,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
|
-
import type { Fr } from '@aztec/foundation/
|
|
2
|
+
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
3
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
4
4
|
import { promiseWithResolvers } from '@aztec/foundation/promise';
|
|
5
5
|
import { elapsed } from '@aztec/foundation/timer';
|
|
@@ -30,7 +30,6 @@ import type { WorldStateStatusFull } from '../native/message.js';
|
|
|
30
30
|
import type { MerkleTreeAdminDatabase } from '../world-state-db/merkle_tree_db.js';
|
|
31
31
|
import type { WorldStateConfig } from './config.js';
|
|
32
32
|
import { WorldStateSynchronizerError } from './errors.js';
|
|
33
|
-
import { findFirstBlocksInCheckpoints } from './utils.js';
|
|
34
33
|
|
|
35
34
|
export type { SnapshotDataKeys };
|
|
36
35
|
|
|
@@ -80,8 +79,8 @@ export class ServerWorldStateSynchronizer
|
|
|
80
79
|
return this.merkleTreeDb.getSnapshot(blockNumber);
|
|
81
80
|
}
|
|
82
81
|
|
|
83
|
-
public fork(blockNumber?: BlockNumber): Promise<MerkleTreeWriteOperations> {
|
|
84
|
-
return this.merkleTreeDb.fork(blockNumber);
|
|
82
|
+
public fork(blockNumber?: BlockNumber, opts?: { closeDelayMs?: number }): Promise<MerkleTreeWriteOperations> {
|
|
83
|
+
return this.merkleTreeDb.fork(blockNumber, opts);
|
|
85
84
|
}
|
|
86
85
|
|
|
87
86
|
public backupTo(dstPath: string, compact?: boolean): Promise<Record<Exclude<SnapshotDataKeys, 'archiver'>, string>> {
|
|
@@ -271,13 +270,13 @@ export class ServerWorldStateSynchronizer
|
|
|
271
270
|
await this.handleL2Blocks(event.blocks.map(b => b.block.toL2Block()));
|
|
272
271
|
break;
|
|
273
272
|
case 'chain-pruned':
|
|
274
|
-
await this.handleChainPruned(
|
|
273
|
+
await this.handleChainPruned(event.block.number);
|
|
275
274
|
break;
|
|
276
275
|
case 'chain-proven':
|
|
277
|
-
await this.handleChainProven(
|
|
276
|
+
await this.handleChainProven(event.block.number);
|
|
278
277
|
break;
|
|
279
278
|
case 'chain-finalized':
|
|
280
|
-
await this.handleChainFinalized(
|
|
279
|
+
await this.handleChainFinalized(event.block.number);
|
|
281
280
|
break;
|
|
282
281
|
}
|
|
283
282
|
}
|
|
@@ -290,13 +289,22 @@ export class ServerWorldStateSynchronizer
|
|
|
290
289
|
private async handleL2Blocks(l2Blocks: L2BlockNew[]) {
|
|
291
290
|
this.log.trace(`Handling L2 blocks ${l2Blocks[0].number} to ${l2Blocks.at(-1)!.number}`);
|
|
292
291
|
|
|
293
|
-
|
|
292
|
+
// Fetch the L1->L2 messages for the first block in a checkpoint.
|
|
293
|
+
const messagesForBlocks = new Map<BlockNumber, Fr[]>();
|
|
294
|
+
await Promise.all(
|
|
295
|
+
l2Blocks
|
|
296
|
+
.filter(b => b.indexWithinCheckpoint === 0)
|
|
297
|
+
.map(async block => {
|
|
298
|
+
const l1ToL2Messages = await this.l2BlockSource.getL1ToL2Messages(block.checkpointNumber);
|
|
299
|
+
messagesForBlocks.set(block.number, l1ToL2Messages);
|
|
300
|
+
}),
|
|
301
|
+
);
|
|
294
302
|
|
|
295
303
|
let updateStatus: WorldStateStatusFull | undefined = undefined;
|
|
296
304
|
for (const block of l2Blocks) {
|
|
297
|
-
const
|
|
298
|
-
|
|
299
|
-
|
|
305
|
+
const [duration, result] = await elapsed(() =>
|
|
306
|
+
this.handleL2Block(block, messagesForBlocks.get(block.number) ?? []),
|
|
307
|
+
);
|
|
300
308
|
this.log.info(`World state updated with L2 block ${block.number}`, {
|
|
301
309
|
eventName: 'l2-block-handled',
|
|
302
310
|
duration,
|
|
@@ -319,18 +327,13 @@ export class ServerWorldStateSynchronizer
|
|
|
319
327
|
* @param l1ToL2Messages - The L1 to L2 messages for the block.
|
|
320
328
|
* @returns Whether the block handled was produced by this same node.
|
|
321
329
|
*/
|
|
322
|
-
private async handleL2Block(
|
|
323
|
-
l2Block: L2BlockNew,
|
|
324
|
-
l1ToL2Messages: Fr[],
|
|
325
|
-
isFirstBlock: boolean,
|
|
326
|
-
): Promise<WorldStateStatusFull> {
|
|
327
|
-
// If the above check succeeds, we can proceed to handle the block.
|
|
330
|
+
private async handleL2Block(l2Block: L2BlockNew, l1ToL2Messages: Fr[]): Promise<WorldStateStatusFull> {
|
|
328
331
|
this.log.trace(`Pushing L2 block ${l2Block.number} to merkle tree db `, {
|
|
329
332
|
blockNumber: l2Block.number,
|
|
330
333
|
blockHash: await l2Block.hash().then(h => h.toString()),
|
|
331
334
|
l1ToL2Messages: l1ToL2Messages.map(msg => msg.toString()),
|
|
332
335
|
});
|
|
333
|
-
const result = await this.merkleTreeDb.handleL2BlockAndMessages(l2Block, l1ToL2Messages
|
|
336
|
+
const result = await this.merkleTreeDb.handleL2BlockAndMessages(l2Block, l1ToL2Messages);
|
|
334
337
|
|
|
335
338
|
if (this.currentState === WorldStateRunningState.SYNCHING && l2Block.number >= this.latestBlockNumberAtStart) {
|
|
336
339
|
this.setCurrentState(WorldStateRunningState.RUNNING);
|
|
@@ -346,12 +349,12 @@ export class ServerWorldStateSynchronizer
|
|
|
346
349
|
if (this.historyToKeep === undefined) {
|
|
347
350
|
return;
|
|
348
351
|
}
|
|
349
|
-
const newHistoricBlock =
|
|
350
|
-
if (newHistoricBlock <=
|
|
352
|
+
const newHistoricBlock = summary.finalizedBlockNumber - this.historyToKeep + 1;
|
|
353
|
+
if (newHistoricBlock <= 1) {
|
|
351
354
|
return;
|
|
352
355
|
}
|
|
353
356
|
this.log.verbose(`Pruning historic blocks to ${newHistoricBlock}`);
|
|
354
|
-
const status = await this.merkleTreeDb.removeHistoricalBlocks(newHistoricBlock);
|
|
357
|
+
const status = await this.merkleTreeDb.removeHistoricalBlocks(BlockNumber(newHistoricBlock));
|
|
355
358
|
this.log.debug(`World state summary `, status.summary);
|
|
356
359
|
}
|
|
357
360
|
|