|
1 | 1 | import type { ArchiverDataSource } from '@aztec/archiver'; |
| 2 | +import { MockL1ToL2MessageSource } from '@aztec/archiver/test'; |
2 | 3 | import { AztecAddress } from '@aztec/aztec.js/addresses'; |
3 | 4 | import { Fr } from '@aztec/aztec.js/fields'; |
4 | 5 | import { createLogger } from '@aztec/aztec.js/log'; |
@@ -144,6 +145,11 @@ describe('L1Publisher integration', () => { |
144 | 145 |
|
145 | 146 | let builderDb: NativeWorldStateService; |
146 | 147 |
|
| 148 | + // Backs the blockSource mock's streaming L1->L2 message queries. The world-state synchronizer reconstructs each |
| 149 | + // block's consumed message bundle from Inbox buckets (AZIP-22 Fast Inbox) when it syncs a block back, so the test |
| 150 | + // registers one bucket per published block here (see buildAndPublishBlock). |
| 151 | + let messageSource: MockL1ToL2MessageSource; |
| 152 | + |
147 | 153 | // The header of the last block |
148 | 154 | let prevHeader: BlockHeader; |
149 | 155 |
|
@@ -280,6 +286,21 @@ describe('L1Publisher integration', () => { |
280 | 286 | checkpointNumber: CheckpointNumber.ZERO, |
281 | 287 | indexWithinCheckpoint: IndexWithinCheckpoint(0), |
282 | 288 | }; |
| 289 | + // Seed the genesis sentinel bucket (seq 0, no messages) so the world-state synchronizer can resolve a |
| 290 | + // totalMsgCount of 0 to a bucket when reconstructing the first block's message bundle. |
| 291 | + messageSource = new MockL1ToL2MessageSource(0); |
| 292 | + messageSource.setInboxBucket( |
| 293 | + { |
| 294 | + seq: 0n, |
| 295 | + inboxRollingHash: Fr.ZERO, |
| 296 | + totalMsgCount: 0n, |
| 297 | + timestamp: 0n, |
| 298 | + msgCount: 0, |
| 299 | + lastMessageIndex: 0n, |
| 300 | + isOpen: false, |
| 301 | + }, |
| 302 | + [], |
| 303 | + ); |
283 | 304 | blockSource = mock<ArchiverDataSource>({ |
284 | 305 | getBlocks(query: BlocksQuery) { |
285 | 306 | if (!('from' in query)) { |
@@ -355,6 +376,14 @@ describe('L1Publisher integration', () => { |
355 | 376 | getBlockNumber(): Promise<BlockNumber> { |
356 | 377 | return Promise.resolve(BlockNumber(blocks.at(-1)?.number ?? BlockNumber.ZERO)); |
357 | 378 | }, |
| 379 | + // Streaming L1->L2 message reconstruction (AZIP-22 Fast Inbox): the world-state synchronizer resolves each |
| 380 | + // block's consumed message bundle from the Inbox buckets registered per published block in buildAndPublishBlock. |
| 381 | + getInboxBucketByTotalMsgCount(totalMsgCount: bigint) { |
| 382 | + return messageSource.getInboxBucketByTotalMsgCount(totalMsgCount); |
| 383 | + }, |
| 384 | + getL1ToL2MessagesBetweenBuckets(fromExclusive: bigint, toInclusive: bigint) { |
| 385 | + return messageSource.getL1ToL2MessagesBetweenBuckets(fromExclusive, toInclusive); |
| 386 | + }, |
358 | 387 | }); |
359 | 388 |
|
360 | 389 | const worldStateConfig: WorldStateConfig = { |
@@ -594,6 +623,24 @@ describe('L1Publisher integration', () => { |
594 | 623 | previousInboxRollingHash = checkpoint.header.inboxRollingHash; |
595 | 624 | const block = checkpoint.blocks[0]; |
596 | 625 |
|
| 626 | + // Register this block's consumed messages as an Inbox bucket so the world-state synchronizer can rebuild the |
| 627 | + // per-block bundle when it syncs the block back on the next iteration. One bucket per block: its sequence is |
| 628 | + // the block number and its cumulative total is the block's L1->L2 tree leaf count, which is exactly the value |
| 629 | + // world-state looks the bucket up by (AZIP-22 Fast Inbox streaming reconstruction). |
| 630 | + const cumulativeMsgCount = BigInt(block.header.state.l1ToL2MessageTree.nextAvailableLeafIndex); |
| 631 | + messageSource.setInboxBucket( |
| 632 | + { |
| 633 | + seq: BigInt(block.number), |
| 634 | + inboxRollingHash: checkpoint.header.inboxRollingHash, |
| 635 | + totalMsgCount: cumulativeMsgCount, |
| 636 | + timestamp, |
| 637 | + msgCount: currentL1ToL2Messages.length, |
| 638 | + lastMessageIndex: cumulativeMsgCount - 1n, |
| 639 | + isOpen: false, |
| 640 | + }, |
| 641 | + currentL1ToL2Messages, |
| 642 | + ); |
| 643 | + |
597 | 644 | const totalManaUsed = txs.reduce((acc, tx) => acc.add(new Fr(tx.gasUsed.billedGas.l2Gas)), Fr.ZERO); |
598 | 645 | expect(totalManaUsed.toBigInt()).toEqual(block.header.totalManaUsed.toBigInt()); |
599 | 646 |
|
|
0 commit comments