@aztec/world-state 0.0.1-commit.9b94fc1 → 0.0.1-commit.d3ec352c
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 +3 -2
- package/dest/native/merkle_trees_facade.d.ts.map +1 -1
- package/dest/native/merkle_trees_facade.js +2 -1
- package/dest/native/message.d.ts +11 -10
- package/dest/native/message.d.ts.map +1 -1
- package/dest/native/message.js +13 -12
- package/dest/native/native_world_state.d.ts +9 -8
- package/dest/native/native_world_state.d.ts.map +1 -1
- package/dest/native/native_world_state.js +10 -7
- package/dest/synchronizer/server_world_state_synchronizer.d.ts +7 -14
- package/dest/synchronizer/server_world_state_synchronizer.d.ts.map +1 -1
- package/dest/synchronizer/server_world_state_synchronizer.js +35 -52
- package/dest/synchronizer/utils.d.ts +11 -0
- package/dest/synchronizer/utils.d.ts.map +1 -0
- package/dest/synchronizer/utils.js +59 -0
- package/dest/test/utils.d.ts +21 -8
- package/dest/test/utils.d.ts.map +1 -1
- package/dest/test/utils.js +51 -10
- package/dest/world-state-db/merkle_tree_db.d.ts +9 -8
- package/dest/world-state-db/merkle_tree_db.d.ts.map +1 -1
- package/package.json +12 -12
- package/src/native/merkle_trees_facade.ts +3 -2
- package/src/native/message.ts +22 -21
- package/src/native/native_world_state.ts +27 -16
- package/src/synchronizer/server_world_state_synchronizer.ts +58 -75
- package/src/synchronizer/utils.ts +83 -0
- package/src/test/utils.ts +65 -12
- package/src/world-state-db/merkle_tree_db.ts +9 -8
package/src/test/utils.ts
CHANGED
|
@@ -4,26 +4,31 @@ import {
|
|
|
4
4
|
NULLIFIER_SUBTREE_HEIGHT,
|
|
5
5
|
NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP,
|
|
6
6
|
} from '@aztec/constants';
|
|
7
|
+
import { BlockNumber, type CheckpointNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
7
8
|
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
8
9
|
import { Fr } from '@aztec/foundation/fields';
|
|
9
|
-
import {
|
|
10
|
+
import { L2BlockNew } from '@aztec/stdlib/block';
|
|
11
|
+
import { Checkpoint } from '@aztec/stdlib/checkpoint';
|
|
10
12
|
import type {
|
|
11
13
|
IndexedTreeId,
|
|
12
14
|
MerkleTreeReadOperations,
|
|
13
15
|
MerkleTreeWriteOperations,
|
|
14
16
|
} from '@aztec/stdlib/interfaces/server';
|
|
17
|
+
import { computeInHashFromL1ToL2Messages } from '@aztec/stdlib/messaging';
|
|
15
18
|
import { AppendOnlyTreeSnapshot, MerkleTreeId } from '@aztec/stdlib/trees';
|
|
16
19
|
|
|
17
20
|
import type { NativeWorldStateService } from '../native/native_world_state.js';
|
|
18
21
|
|
|
19
22
|
export async function mockBlock(
|
|
20
|
-
blockNum:
|
|
23
|
+
blockNum: BlockNumber,
|
|
21
24
|
size: number,
|
|
22
25
|
fork: MerkleTreeWriteOperations,
|
|
23
26
|
maxEffects: number | undefined = 1000, // Defaults to the maximum tx effects.
|
|
27
|
+
numL1ToL2Messages: number = NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP,
|
|
28
|
+
isFirstBlock: boolean = true,
|
|
24
29
|
) {
|
|
25
|
-
const l2Block = await
|
|
26
|
-
const l1ToL2Messages =
|
|
30
|
+
const l2Block = await L2BlockNew.random(blockNum, { txsPerBlock: size, txOptions: { maxEffects } });
|
|
31
|
+
const l1ToL2Messages = mockL1ToL2Messages(numL1ToL2Messages);
|
|
27
32
|
|
|
28
33
|
{
|
|
29
34
|
const insertData = async (
|
|
@@ -55,7 +60,9 @@ export async function mockBlock(
|
|
|
55
60
|
padArrayEnd(txEffect.noteHashes, Fr.ZERO, MAX_NOTE_HASHES_PER_TX),
|
|
56
61
|
);
|
|
57
62
|
|
|
58
|
-
const l1ToL2MessagesPadded =
|
|
63
|
+
const l1ToL2MessagesPadded = isFirstBlock
|
|
64
|
+
? padArrayEnd<Fr, number>(l1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP)
|
|
65
|
+
: l1ToL2Messages;
|
|
59
66
|
|
|
60
67
|
const noteHashInsert = fork.appendLeaves(MerkleTreeId.NOTE_HASH_TREE, noteHashesPadded);
|
|
61
68
|
const messageInsert = fork.appendLeaves(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, l1ToL2MessagesPadded);
|
|
@@ -64,7 +71,7 @@ export async function mockBlock(
|
|
|
64
71
|
|
|
65
72
|
const state = await fork.getStateReference();
|
|
66
73
|
l2Block.header.state = state;
|
|
67
|
-
await fork.updateArchive(l2Block.
|
|
74
|
+
await fork.updateArchive(l2Block.header);
|
|
68
75
|
|
|
69
76
|
const archiveState = await fork.getTreeInfo(MerkleTreeId.ARCHIVE);
|
|
70
77
|
|
|
@@ -76,8 +83,8 @@ export async function mockBlock(
|
|
|
76
83
|
};
|
|
77
84
|
}
|
|
78
85
|
|
|
79
|
-
export async function mockEmptyBlock(blockNum:
|
|
80
|
-
const l2Block =
|
|
86
|
+
export async function mockEmptyBlock(blockNum: BlockNumber, fork: MerkleTreeWriteOperations) {
|
|
87
|
+
const l2Block = L2BlockNew.empty();
|
|
81
88
|
const l1ToL2Messages = Array(16).fill(0).map(Fr.zero);
|
|
82
89
|
|
|
83
90
|
l2Block.header.globalVariables.blockNumber = blockNum;
|
|
@@ -115,7 +122,7 @@ export async function mockEmptyBlock(blockNum: number, fork: MerkleTreeWriteOper
|
|
|
115
122
|
|
|
116
123
|
const state = await fork.getStateReference();
|
|
117
124
|
l2Block.header.state = state;
|
|
118
|
-
await fork.updateArchive(l2Block.
|
|
125
|
+
await fork.updateArchive(l2Block.header);
|
|
119
126
|
|
|
120
127
|
const archiveState = await fork.getTreeInfo(MerkleTreeId.ARCHIVE);
|
|
121
128
|
|
|
@@ -127,13 +134,18 @@ export async function mockEmptyBlock(blockNum: number, fork: MerkleTreeWriteOper
|
|
|
127
134
|
};
|
|
128
135
|
}
|
|
129
136
|
|
|
130
|
-
export async function mockBlocks(
|
|
131
|
-
|
|
137
|
+
export async function mockBlocks(
|
|
138
|
+
from: BlockNumber,
|
|
139
|
+
count: number,
|
|
140
|
+
numTxs: number,
|
|
141
|
+
worldState: NativeWorldStateService,
|
|
142
|
+
) {
|
|
143
|
+
const tempFork = await worldState.fork(BlockNumber(from - 1));
|
|
132
144
|
|
|
133
145
|
const blocks = [];
|
|
134
146
|
const messagesArray = [];
|
|
135
147
|
for (let blockNumber = from; blockNumber < from + count; blockNumber++) {
|
|
136
|
-
const { block, messages } = await mockBlock(blockNumber, numTxs, tempFork);
|
|
148
|
+
const { block, messages } = await mockBlock(BlockNumber(blockNumber), numTxs, tempFork);
|
|
137
149
|
blocks.push(block);
|
|
138
150
|
messagesArray.push(messages);
|
|
139
151
|
}
|
|
@@ -143,6 +155,47 @@ export async function mockBlocks(from: number, count: number, numTxs: number, wo
|
|
|
143
155
|
return { blocks, messages: messagesArray };
|
|
144
156
|
}
|
|
145
157
|
|
|
158
|
+
export function mockL1ToL2Messages(numL1ToL2Messages: number) {
|
|
159
|
+
return Array(numL1ToL2Messages).fill(0).map(Fr.random);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export async function mockCheckpoint(
|
|
163
|
+
checkpointNumber: CheckpointNumber,
|
|
164
|
+
{
|
|
165
|
+
startBlockNumber = BlockNumber(1),
|
|
166
|
+
numBlocks = 1,
|
|
167
|
+
numTxsPerBlock = 1,
|
|
168
|
+
numL1ToL2Messages = 1,
|
|
169
|
+
fork,
|
|
170
|
+
}: {
|
|
171
|
+
startBlockNumber?: BlockNumber;
|
|
172
|
+
numBlocks?: number;
|
|
173
|
+
numTxsPerBlock?: number;
|
|
174
|
+
numL1ToL2Messages?: number;
|
|
175
|
+
fork?: MerkleTreeWriteOperations;
|
|
176
|
+
} = {},
|
|
177
|
+
) {
|
|
178
|
+
const slotNumber = SlotNumber(checkpointNumber * 10);
|
|
179
|
+
const blocksAndMessages = [];
|
|
180
|
+
for (let i = 0; i < numBlocks; i++) {
|
|
181
|
+
const blockNumber = BlockNumber(startBlockNumber + i);
|
|
182
|
+
const { block, messages } = fork
|
|
183
|
+
? await mockBlock(blockNumber, numTxsPerBlock, fork, blockNumber === startBlockNumber ? numL1ToL2Messages : 0)
|
|
184
|
+
: {
|
|
185
|
+
block: await L2BlockNew.random(blockNumber, { txsPerBlock: numTxsPerBlock, slotNumber }),
|
|
186
|
+
messages: mockL1ToL2Messages(numL1ToL2Messages),
|
|
187
|
+
};
|
|
188
|
+
blocksAndMessages.push({ block, messages });
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const messages = blocksAndMessages[0].messages;
|
|
192
|
+
const inHash = computeInHashFromL1ToL2Messages(messages);
|
|
193
|
+
const checkpoint = await Checkpoint.random(checkpointNumber, { numBlocks: 0, slotNumber, inHash });
|
|
194
|
+
checkpoint.blocks = blocksAndMessages.map(({ block }) => block);
|
|
195
|
+
|
|
196
|
+
return { checkpoint, messages };
|
|
197
|
+
}
|
|
198
|
+
|
|
146
199
|
export async function assertSameState(forkA: MerkleTreeReadOperations, forkB: MerkleTreeReadOperations) {
|
|
147
200
|
const nativeStateRef = await forkA.getStateReference();
|
|
148
201
|
const nativeArchive = await forkA.getTreeInfo(MerkleTreeId.ARCHIVE);
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { MAX_NULLIFIERS_PER_TX, MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX } from '@aztec/constants';
|
|
2
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
3
|
import type { Fr } from '@aztec/foundation/fields';
|
|
3
4
|
import type { IndexedTreeSnapshot, TreeSnapshot } from '@aztec/merkle-tree';
|
|
4
|
-
import type {
|
|
5
|
+
import type { L2BlockNew } from '@aztec/stdlib/block';
|
|
5
6
|
import type { ForkMerkleTreeOperations, MerkleTreeReadOperations } from '@aztec/stdlib/interfaces/server';
|
|
6
7
|
import type { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
7
8
|
|
|
@@ -39,13 +40,13 @@ export interface MerkleTreeAdminDatabase extends ForkMerkleTreeOperations {
|
|
|
39
40
|
* Handles a single L2 block (i.e. Inserts the new note hashes into the merkle tree).
|
|
40
41
|
* @param block - The L2 block to handle.
|
|
41
42
|
* @param l1ToL2Messages - The L1 to L2 messages for the block.
|
|
42
|
-
* @param isFirstBlock - Whether the block is the first block in a checkpoint.
|
|
43
|
-
*
|
|
43
|
+
* @param isFirstBlock - Whether the block is the first block in a checkpoint. The messages are padded and inserted
|
|
44
|
+
* to the tree for the first block in a checkpoint.
|
|
44
45
|
*/
|
|
45
46
|
handleL2BlockAndMessages(
|
|
46
|
-
block:
|
|
47
|
+
block: L2BlockNew,
|
|
47
48
|
l1ToL2Messages: Fr[],
|
|
48
|
-
isFirstBlock
|
|
49
|
+
isFirstBlock: boolean,
|
|
49
50
|
): Promise<WorldStateStatusFull>;
|
|
50
51
|
|
|
51
52
|
/**
|
|
@@ -58,21 +59,21 @@ export interface MerkleTreeAdminDatabase extends ForkMerkleTreeOperations {
|
|
|
58
59
|
* @param toBlockNumber The block number of the new oldest historical block
|
|
59
60
|
* @returns The new WorldStateStatus
|
|
60
61
|
*/
|
|
61
|
-
removeHistoricalBlocks(toBlockNumber:
|
|
62
|
+
removeHistoricalBlocks(toBlockNumber: BlockNumber): Promise<WorldStateStatusFull>;
|
|
62
63
|
|
|
63
64
|
/**
|
|
64
65
|
* Removes all pending blocks down to but not including the given block number
|
|
65
66
|
* @param toBlockNumber The block number of the new tip of the pending chain,
|
|
66
67
|
* @returns The new WorldStateStatus
|
|
67
68
|
*/
|
|
68
|
-
unwindBlocks(toBlockNumber:
|
|
69
|
+
unwindBlocks(toBlockNumber: BlockNumber): Promise<WorldStateStatusFull>;
|
|
69
70
|
|
|
70
71
|
/**
|
|
71
72
|
* Advances the finalized block number to be the number provided
|
|
72
73
|
* @param toBlockNumber The block number that is now the tip of the finalized chain
|
|
73
74
|
* @returns The new WorldStateStatus
|
|
74
75
|
*/
|
|
75
|
-
setFinalized(toBlockNumber:
|
|
76
|
+
setFinalized(toBlockNumber: BlockNumber): Promise<WorldStateStatusSummary>;
|
|
76
77
|
|
|
77
78
|
/**
|
|
78
79
|
* Gets the current status summary of the database.
|