@aztec/world-state 3.0.0-nightly.20251209 → 3.0.0-nightly.20251211
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 +2 -2
- package/dest/native/merkle_trees_facade.d.ts.map +1 -1
- package/dest/native/merkle_trees_facade.js +1 -1
- 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 +3 -3
- package/dest/native/native_world_state.d.ts.map +1 -1
- package/dest/native/native_world_state.js +3 -2
- package/dest/synchronizer/server_world_state_synchronizer.d.ts +1 -1
- package/dest/synchronizer/server_world_state_synchronizer.d.ts.map +1 -1
- package/dest/synchronizer/server_world_state_synchronizer.js +15 -14
- package/dest/test/utils.d.ts +7 -13
- package/dest/test/utils.d.ts.map +1 -1
- package/dest/test/utils.js +38 -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 +4 -6
- 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 +1 -1
- package/src/native/message.ts +1 -1
- package/src/native/native_world_state.ts +3 -6
- package/src/synchronizer/server_world_state_synchronizer.ts +22 -19
- package/src/test/utils.ts +67 -126
- package/src/testing.ts +1 -1
- package/src/world-state-db/merkle_tree_db.ts +3 -9
- 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/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,5 +1,5 @@
|
|
|
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
5
|
import type { ForkMerkleTreeOperations, MerkleTreeReadOperations } from '@aztec/stdlib/interfaces/server';
|
|
@@ -34,10 +34,8 @@ export interface MerkleTreeAdminDatabase extends ForkMerkleTreeOperations {
|
|
|
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,eyJ2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AO,CAAC,oBAAoB,CAAC,CAAC;IAEjG;;OAEG;IACH,YAAY,IAAI,wBAAwB,CAAC;IAEzC;;;;OAIG;IACH,sBAAsB,CAAC,aAAa,EAAE,WAAW,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;IAElF;;;;OAIG;IACH,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": "3.0.0-nightly.
|
|
3
|
+
"version": "3.0.0-nightly.20251211",
|
|
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": "3.0.0-nightly.
|
|
68
|
-
"@aztec/foundation": "3.0.0-nightly.
|
|
69
|
-
"@aztec/kv-store": "3.0.0-nightly.
|
|
70
|
-
"@aztec/merkle-tree": "3.0.0-nightly.
|
|
71
|
-
"@aztec/native": "3.0.0-nightly.
|
|
72
|
-
"@aztec/protocol-contracts": "3.0.0-nightly.
|
|
73
|
-
"@aztec/stdlib": "3.0.0-nightly.
|
|
74
|
-
"@aztec/telemetry-client": "3.0.0-nightly.
|
|
67
|
+
"@aztec/constants": "3.0.0-nightly.20251211",
|
|
68
|
+
"@aztec/foundation": "3.0.0-nightly.20251211",
|
|
69
|
+
"@aztec/kv-store": "3.0.0-nightly.20251211",
|
|
70
|
+
"@aztec/merkle-tree": "3.0.0-nightly.20251211",
|
|
71
|
+
"@aztec/native": "3.0.0-nightly.20251211",
|
|
72
|
+
"@aztec/protocol-contracts": "3.0.0-nightly.20251211",
|
|
73
|
+
"@aztec/stdlib": "3.0.0-nightly.20251211",
|
|
74
|
+
"@aztec/telemetry-client": "3.0.0-nightly.20251211",
|
|
75
75
|
"tslib": "^2.4.0",
|
|
76
76
|
"zod": "^3.23.8"
|
|
77
77
|
},
|
|
78
78
|
"devDependencies": {
|
|
79
|
-
"@aztec/archiver": "3.0.0-nightly.
|
|
79
|
+
"@aztec/archiver": "3.0.0-nightly.20251211",
|
|
80
80
|
"@jest/globals": "^30.0.0",
|
|
81
81
|
"@types/jest": "^30.0.0",
|
|
82
82
|
"@types/node": "^22.15.17",
|
|
@@ -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 { serializeToBuffer } from '@aztec/foundation/serialize';
|
|
4
4
|
import { type IndexedTreeLeafPreimage, SiblingPath } from '@aztec/foundation/trees';
|
|
5
5
|
import type {
|
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';
|
|
@@ -180,11 +180,8 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
|
|
|
180
180
|
return this.initialHeader!;
|
|
181
181
|
}
|
|
182
182
|
|
|
183
|
-
public async handleL2BlockAndMessages(
|
|
184
|
-
l2Block
|
|
185
|
-
l1ToL2Messages: Fr[],
|
|
186
|
-
isFirstBlock: boolean,
|
|
187
|
-
): Promise<WorldStateStatusFull> {
|
|
183
|
+
public async handleL2BlockAndMessages(l2Block: L2BlockNew, l1ToL2Messages: Fr[]): Promise<WorldStateStatusFull> {
|
|
184
|
+
const isFirstBlock = l2Block.indexWithinCheckpoint === 0;
|
|
188
185
|
if (!isFirstBlock && l1ToL2Messages.length > 0) {
|
|
189
186
|
throw new Error(
|
|
190
187
|
`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
|
|
|
@@ -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
|
|
package/src/test/utils.ts
CHANGED
|
@@ -4,81 +4,88 @@ import {
|
|
|
4
4
|
NULLIFIER_SUBTREE_HEIGHT,
|
|
5
5
|
NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP,
|
|
6
6
|
} from '@aztec/constants';
|
|
7
|
-
import {
|
|
7
|
+
import { asyncMap } from '@aztec/foundation/async-map';
|
|
8
|
+
import { BlockNumber, type CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
8
9
|
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
9
|
-
import { Fr } from '@aztec/foundation/
|
|
10
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
10
11
|
import { L2BlockNew } from '@aztec/stdlib/block';
|
|
11
|
-
import { Checkpoint } from '@aztec/stdlib/checkpoint';
|
|
12
12
|
import type {
|
|
13
13
|
IndexedTreeId,
|
|
14
14
|
MerkleTreeReadOperations,
|
|
15
15
|
MerkleTreeWriteOperations,
|
|
16
16
|
} from '@aztec/stdlib/interfaces/server';
|
|
17
|
-
import {
|
|
17
|
+
import { mockCheckpointAndMessages, mockL1ToL2Messages } from '@aztec/stdlib/testing';
|
|
18
18
|
import { AppendOnlyTreeSnapshot, MerkleTreeId } from '@aztec/stdlib/trees';
|
|
19
19
|
|
|
20
20
|
import type { NativeWorldStateService } from '../native/native_world_state.js';
|
|
21
21
|
|
|
22
|
-
export async function
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
) {
|
|
30
|
-
|
|
31
|
-
|
|
22
|
+
export async function updateBlockState(block: L2BlockNew, l1ToL2Messages: Fr[], fork: MerkleTreeWriteOperations) {
|
|
23
|
+
const insertData = async (
|
|
24
|
+
treeId: IndexedTreeId,
|
|
25
|
+
data: Buffer[][],
|
|
26
|
+
subTreeHeight: number,
|
|
27
|
+
fork: MerkleTreeWriteOperations,
|
|
28
|
+
) => {
|
|
29
|
+
for (const dataBatch of data) {
|
|
30
|
+
await fork.batchInsert(treeId, dataBatch, subTreeHeight);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
32
33
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
l2Block.body.txEffects.map(txEffect =>
|
|
54
|
-
padArrayEnd(txEffect.nullifiers, Fr.ZERO, MAX_NULLIFIERS_PER_TX).map(nullifier => nullifier.toBuffer()),
|
|
55
|
-
),
|
|
56
|
-
NULLIFIER_SUBTREE_HEIGHT,
|
|
57
|
-
fork,
|
|
58
|
-
);
|
|
59
|
-
const noteHashesPadded = l2Block.body.txEffects.flatMap(txEffect =>
|
|
60
|
-
padArrayEnd(txEffect.noteHashes, Fr.ZERO, MAX_NOTE_HASHES_PER_TX),
|
|
61
|
-
);
|
|
62
|
-
|
|
63
|
-
const l1ToL2MessagesPadded = isFirstBlock
|
|
34
|
+
const publicDataInsert = insertData(
|
|
35
|
+
MerkleTreeId.PUBLIC_DATA_TREE,
|
|
36
|
+
block.body.txEffects.map(txEffect => txEffect.publicDataWrites.map(write => write.toBuffer())),
|
|
37
|
+
0,
|
|
38
|
+
fork,
|
|
39
|
+
);
|
|
40
|
+
const nullifierInsert = insertData(
|
|
41
|
+
MerkleTreeId.NULLIFIER_TREE,
|
|
42
|
+
block.body.txEffects.map(txEffect =>
|
|
43
|
+
padArrayEnd(txEffect.nullifiers, Fr.ZERO, MAX_NULLIFIERS_PER_TX).map(nullifier => nullifier.toBuffer()),
|
|
44
|
+
),
|
|
45
|
+
NULLIFIER_SUBTREE_HEIGHT,
|
|
46
|
+
fork,
|
|
47
|
+
);
|
|
48
|
+
const noteHashesPadded = block.body.txEffects.flatMap(txEffect =>
|
|
49
|
+
padArrayEnd(txEffect.noteHashes, Fr.ZERO, MAX_NOTE_HASHES_PER_TX),
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
const l1ToL2MessagesPadded =
|
|
53
|
+
block.indexWithinCheckpoint === 0
|
|
64
54
|
? padArrayEnd<Fr, number>(l1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP)
|
|
65
55
|
: l1ToL2Messages;
|
|
66
56
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
57
|
+
const noteHashInsert = fork.appendLeaves(MerkleTreeId.NOTE_HASH_TREE, noteHashesPadded);
|
|
58
|
+
const messageInsert = fork.appendLeaves(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, l1ToL2MessagesPadded);
|
|
59
|
+
await Promise.all([publicDataInsert, nullifierInsert, noteHashInsert, messageInsert]);
|
|
71
60
|
|
|
72
61
|
const state = await fork.getStateReference();
|
|
73
|
-
|
|
74
|
-
await fork.updateArchive(
|
|
62
|
+
block.header.state = state;
|
|
63
|
+
await fork.updateArchive(block.header);
|
|
75
64
|
|
|
76
65
|
const archiveState = await fork.getTreeInfo(MerkleTreeId.ARCHIVE);
|
|
77
66
|
|
|
78
|
-
|
|
67
|
+
block.archive = new AppendOnlyTreeSnapshot(Fr.fromBuffer(archiveState.root), Number(archiveState.size));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export async function mockBlock(
|
|
71
|
+
blockNum: BlockNumber,
|
|
72
|
+
size: number,
|
|
73
|
+
fork: MerkleTreeWriteOperations,
|
|
74
|
+
maxEffects: number | undefined = 1000, // Defaults to the maximum tx effects.
|
|
75
|
+
numL1ToL2Messages: number = NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP,
|
|
76
|
+
isFirstBlockInCheckpoint: boolean = true,
|
|
77
|
+
) {
|
|
78
|
+
const block = await L2BlockNew.random(blockNum, {
|
|
79
|
+
indexWithinCheckpoint: isFirstBlockInCheckpoint ? 0 : 1,
|
|
80
|
+
txsPerBlock: size,
|
|
81
|
+
txOptions: { maxEffects },
|
|
82
|
+
});
|
|
83
|
+
const l1ToL2Messages = mockL1ToL2Messages(numL1ToL2Messages);
|
|
84
|
+
|
|
85
|
+
await updateBlockState(block, l1ToL2Messages, fork);
|
|
79
86
|
|
|
80
87
|
return {
|
|
81
|
-
block
|
|
88
|
+
block,
|
|
82
89
|
messages: l1ToL2Messages,
|
|
83
90
|
};
|
|
84
91
|
}
|
|
@@ -89,44 +96,7 @@ export async function mockEmptyBlock(blockNum: BlockNumber, fork: MerkleTreeWrit
|
|
|
89
96
|
|
|
90
97
|
l2Block.header.globalVariables.blockNumber = blockNum;
|
|
91
98
|
|
|
92
|
-
|
|
93
|
-
{
|
|
94
|
-
const noteHashesPadded = l2Block.body.txEffects.flatMap(txEffect =>
|
|
95
|
-
padArrayEnd(txEffect.noteHashes, Fr.ZERO, MAX_NOTE_HASHES_PER_TX),
|
|
96
|
-
);
|
|
97
|
-
await fork.appendLeaves(MerkleTreeId.NOTE_HASH_TREE, noteHashesPadded);
|
|
98
|
-
|
|
99
|
-
const l1ToL2MessagesPadded = padArrayEnd<Fr, number>(l1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP);
|
|
100
|
-
await fork.appendLeaves(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, l1ToL2MessagesPadded);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// Sync the indexed trees
|
|
104
|
-
{
|
|
105
|
-
// We insert the public data tree leaves with one batch per tx to avoid updating the same key twice
|
|
106
|
-
for (const txEffect of l2Block.body.txEffects) {
|
|
107
|
-
await fork.batchInsert(
|
|
108
|
-
MerkleTreeId.PUBLIC_DATA_TREE,
|
|
109
|
-
txEffect.publicDataWrites.map(write => write.toBuffer()),
|
|
110
|
-
0,
|
|
111
|
-
);
|
|
112
|
-
|
|
113
|
-
const nullifiersPadded = padArrayEnd(txEffect.nullifiers, Fr.ZERO, MAX_NULLIFIERS_PER_TX);
|
|
114
|
-
|
|
115
|
-
await fork.batchInsert(
|
|
116
|
-
MerkleTreeId.NULLIFIER_TREE,
|
|
117
|
-
nullifiersPadded.map(nullifier => nullifier.toBuffer()),
|
|
118
|
-
NULLIFIER_SUBTREE_HEIGHT,
|
|
119
|
-
);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
const state = await fork.getStateReference();
|
|
124
|
-
l2Block.header.state = state;
|
|
125
|
-
await fork.updateArchive(l2Block.header);
|
|
126
|
-
|
|
127
|
-
const archiveState = await fork.getTreeInfo(MerkleTreeId.ARCHIVE);
|
|
128
|
-
|
|
129
|
-
l2Block.archive = new AppendOnlyTreeSnapshot(Fr.fromBuffer(archiveState.root), Number(archiveState.size));
|
|
99
|
+
await updateBlockState(l2Block, l1ToL2Messages, fork);
|
|
130
100
|
|
|
131
101
|
return {
|
|
132
102
|
block: l2Block,
|
|
@@ -155,44 +125,15 @@ export async function mockBlocks(
|
|
|
155
125
|
return { blocks, messages: messagesArray };
|
|
156
126
|
}
|
|
157
127
|
|
|
158
|
-
export function mockL1ToL2Messages(numL1ToL2Messages: number) {
|
|
159
|
-
return Array(numL1ToL2Messages).fill(0).map(Fr.random);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
128
|
export async function mockCheckpoint(
|
|
163
129
|
checkpointNumber: CheckpointNumber,
|
|
164
|
-
|
|
165
|
-
|
|
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
|
-
} = {},
|
|
130
|
+
fork: MerkleTreeWriteOperations,
|
|
131
|
+
options: Partial<Parameters<typeof mockCheckpointAndMessages>[1]> = {},
|
|
177
132
|
) {
|
|
178
|
-
const
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
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
|
-
|
|
133
|
+
const { checkpoint, messages } = await mockCheckpointAndMessages(checkpointNumber, options);
|
|
134
|
+
await asyncMap(checkpoint.blocks, async (block, i) => {
|
|
135
|
+
await updateBlockState(block, i === 0 ? messages : [], fork);
|
|
136
|
+
});
|
|
196
137
|
return { checkpoint, messages };
|
|
197
138
|
}
|
|
198
139
|
|
package/src/testing.ts
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 type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
5
5
|
import { MerkleTreeId, PublicDataTreeLeaf } from '@aztec/stdlib/trees';
|
|
@@ -1,6 +1,6 @@
|
|
|
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';
|
|
3
|
-
import type { Fr } from '@aztec/foundation/
|
|
2
|
+
import type { BlockNumber } from '@aztec/foundation/branded-types';
|
|
3
|
+
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
4
|
import type { IndexedTreeSnapshot, TreeSnapshot } from '@aztec/merkle-tree';
|
|
5
5
|
import type { L2BlockNew } from '@aztec/stdlib/block';
|
|
6
6
|
import type { ForkMerkleTreeOperations, MerkleTreeReadOperations } from '@aztec/stdlib/interfaces/server';
|
|
@@ -40,14 +40,8 @@ export interface MerkleTreeAdminDatabase extends ForkMerkleTreeOperations {
|
|
|
40
40
|
* Handles a single L2 block (i.e. Inserts the new note hashes into the merkle tree).
|
|
41
41
|
* @param block - The L2 block to handle.
|
|
42
42
|
* @param l1ToL2Messages - The L1 to L2 messages for the block.
|
|
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.
|
|
45
43
|
*/
|
|
46
|
-
handleL2BlockAndMessages(
|
|
47
|
-
block: L2BlockNew,
|
|
48
|
-
l1ToL2Messages: Fr[],
|
|
49
|
-
isFirstBlock: boolean,
|
|
50
|
-
): Promise<WorldStateStatusFull>;
|
|
44
|
+
handleL2BlockAndMessages(block: L2BlockNew, l1ToL2Messages: Fr[]): Promise<WorldStateStatusFull>;
|
|
51
45
|
|
|
52
46
|
/**
|
|
53
47
|
* Gets a handle that allows reading the latest committed state
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { Fr } from '@aztec/foundation/fields';
|
|
2
|
-
import type { L2BlockNew, L2BlockSource } from '@aztec/stdlib/block';
|
|
3
|
-
import { type L1ToL2MessageSource } from '@aztec/stdlib/messaging';
|
|
4
|
-
/**
|
|
5
|
-
* Determine which blocks in the given array are the first block in a checkpoint.
|
|
6
|
-
* @param blocks - The candidate blocks, sorted by block number in ascending order.
|
|
7
|
-
* @param l2BlockSource - The L2 block source to use to fetch the checkpoints, block headers and L1->L2 messages.
|
|
8
|
-
* @returns A map of block numbers that begin a checkpoint to the L1->L2 messages for that checkpoint.
|
|
9
|
-
*/
|
|
10
|
-
export declare function findFirstBlocksInCheckpoints(blocks: L2BlockNew[], l2BlockSource: L2BlockSource & L1ToL2MessageSource): Promise<Map<number, Fr[]>>;
|
|
11
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXRpbHMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9zeW5jaHJvbml6ZXIvdXRpbHMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQ0EsT0FBTyxLQUFLLEVBQUUsRUFBRSxFQUFFLE1BQU0sMEJBQTBCLENBQUM7QUFDbkQsT0FBTyxLQUFLLEVBQUUsVUFBVSxFQUFFLGFBQWEsRUFBRSxNQUFNLHFCQUFxQixDQUFDO0FBRXJFLE9BQU8sRUFBRSxLQUFLLG1CQUFtQixFQUFtQyxNQUFNLHlCQUF5QixDQUFDO0FBRXBHOzs7OztHQUtHO0FBQ0gsd0JBQXNCLDRCQUE0QixDQUNoRCxNQUFNLEVBQUUsVUFBVSxFQUFFLEVBQ3BCLGFBQWEsRUFBRSxhQUFhLEdBQUcsbUJBQW1CLEdBQ2pELE9BQU8sQ0FBQyxHQUFHLENBQUMsTUFBTSxFQUFFLEVBQUUsRUFBRSxDQUFDLENBQUMsQ0FtRTVCIn0=
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/synchronizer/utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AACnD,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAErE,OAAO,EAAE,KAAK,mBAAmB,EAAmC,MAAM,yBAAyB,CAAC;AAEpG;;;;;GAKG;AACH,wBAAsB,4BAA4B,CAChD,MAAM,EAAE,UAAU,EAAE,EACpB,aAAa,EAAE,aAAa,GAAG,mBAAmB,GACjD,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC,CAmE5B"}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
|
-
import { computeInHashFromL1ToL2Messages } from '@aztec/stdlib/messaging';
|
|
3
|
-
/**
|
|
4
|
-
* Determine which blocks in the given array are the first block in a checkpoint.
|
|
5
|
-
* @param blocks - The candidate blocks, sorted by block number in ascending order.
|
|
6
|
-
* @param l2BlockSource - The L2 block source to use to fetch the checkpoints, block headers and L1->L2 messages.
|
|
7
|
-
* @returns A map of block numbers that begin a checkpoint to the L1->L2 messages for that checkpoint.
|
|
8
|
-
*/ export async function findFirstBlocksInCheckpoints(blocks, l2BlockSource) {
|
|
9
|
-
// Select the blocks that are the final block within each group of identical slot numbers.
|
|
10
|
-
let seenSlot;
|
|
11
|
-
const maybeLastBlocks = [
|
|
12
|
-
...blocks
|
|
13
|
-
].reverse().filter((b)=>{
|
|
14
|
-
if (b.header.globalVariables.slotNumber !== seenSlot) {
|
|
15
|
-
seenSlot = b.header.globalVariables.slotNumber;
|
|
16
|
-
return true;
|
|
17
|
-
}
|
|
18
|
-
return false;
|
|
19
|
-
}).reverse();
|
|
20
|
-
// Try to fetch the checkpoints for those blocks. If undefined (which should only occur for blocks.at(-1)),
|
|
21
|
-
// then the block is not the last one in a checkpoint.
|
|
22
|
-
// If we are not checking the inHashes below, only blocks.at(-1) would need its checkpoint header fetched.
|
|
23
|
-
const checkpointedBlocks = (await Promise.all(maybeLastBlocks.map(async (b)=>({
|
|
24
|
-
blockNumber: b.number,
|
|
25
|
-
// A checkpoint's archive root is the archive root of its last block.
|
|
26
|
-
checkpoint: await l2BlockSource.getCheckpointByArchive(b.archive.root)
|
|
27
|
-
})))).filter((b)=>b.checkpoint !== undefined);
|
|
28
|
-
// Verify that the L1->L2 messages hash to the checkpoint's inHash.
|
|
29
|
-
const checkpointedL1ToL2Messages = await Promise.all(checkpointedBlocks.map((b)=>l2BlockSource.getL1ToL2MessagesForCheckpoint(b.checkpoint.number)));
|
|
30
|
-
checkpointedBlocks.forEach((b, i)=>{
|
|
31
|
-
const computedInHash = computeInHashFromL1ToL2Messages(checkpointedL1ToL2Messages[i]);
|
|
32
|
-
const inHash = b.checkpoint.header.contentCommitment.inHash;
|
|
33
|
-
if (!computedInHash.equals(inHash)) {
|
|
34
|
-
throw new Error('Obtained L1 to L2 messages failed to be hashed to the checkpoint inHash');
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
// Compute the first block numbers, which should be right after each checkpointed block. Exclude blocks that haven't
|
|
38
|
-
// been added yet.
|
|
39
|
-
const firstBlockNumbers = checkpointedBlocks.map((b)=>BlockNumber(b.blockNumber + 1)).filter((n)=>n <= blocks.at(-1).number);
|
|
40
|
-
// Check if blocks[0] is the first block in a checkpoint.
|
|
41
|
-
if (blocks[0].number === 1) {
|
|
42
|
-
firstBlockNumbers.push(blocks[0].number);
|
|
43
|
-
} else {
|
|
44
|
-
const lastBlockHeader = await l2BlockSource.getBlockHeader(BlockNumber(blocks[0].number - 1));
|
|
45
|
-
if (!lastBlockHeader) {
|
|
46
|
-
throw new Error(`Failed to get block ${blocks[0].number - 1}`);
|
|
47
|
-
}
|
|
48
|
-
if (lastBlockHeader.globalVariables.slotNumber !== blocks[0].header.globalVariables.slotNumber) {
|
|
49
|
-
firstBlockNumbers.push(blocks[0].number);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
// Fetch the L1->L2 messages for the first blocks and assign them to the map.
|
|
53
|
-
const messagesByBlockNumber = new Map();
|
|
54
|
-
await Promise.all(firstBlockNumbers.map(async (blockNumber)=>{
|
|
55
|
-
const l1ToL2Messages = await l2BlockSource.getL1ToL2Messages(blockNumber);
|
|
56
|
-
messagesByBlockNumber.set(blockNumber, l1ToL2Messages);
|
|
57
|
-
}));
|
|
58
|
-
return messagesByBlockNumber;
|
|
59
|
-
}
|