Skip to content

Commit b32e629

Browse files
committed
test(fast-inbox): reconstruct L1-to-L2 messages in the l1 publisher integration mock (A-1388)
The streaming flip makes world-state sync reconstruct L1-to-L2 messages per block via the archiver's bucket queries, but the integration test's block-source mock did not implement them, so block 1 committed with zero messages and the next fork threw. Back the mock with MockL1ToL2MessageSource and register a bucket per published block.
1 parent 0939931 commit b32e629

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

yarn-project/sequencer-client/src/publisher/l1_publisher.integration.test.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { ArchiverDataSource } from '@aztec/archiver';
2+
import { MockL1ToL2MessageSource } from '@aztec/archiver/test';
23
import { AztecAddress } from '@aztec/aztec.js/addresses';
34
import { Fr } from '@aztec/aztec.js/fields';
45
import { createLogger } from '@aztec/aztec.js/log';
@@ -144,6 +145,11 @@ describe('L1Publisher integration', () => {
144145

145146
let builderDb: NativeWorldStateService;
146147

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+
147153
// The header of the last block
148154
let prevHeader: BlockHeader;
149155

@@ -280,6 +286,21 @@ describe('L1Publisher integration', () => {
280286
checkpointNumber: CheckpointNumber.ZERO,
281287
indexWithinCheckpoint: IndexWithinCheckpoint(0),
282288
};
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+
);
283304
blockSource = mock<ArchiverDataSource>({
284305
getBlocks(query: BlocksQuery) {
285306
if (!('from' in query)) {
@@ -355,6 +376,14 @@ describe('L1Publisher integration', () => {
355376
getBlockNumber(): Promise<BlockNumber> {
356377
return Promise.resolve(BlockNumber(blocks.at(-1)?.number ?? BlockNumber.ZERO));
357378
},
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+
},
358387
});
359388

360389
const worldStateConfig: WorldStateConfig = {
@@ -594,6 +623,24 @@ describe('L1Publisher integration', () => {
594623
previousInboxRollingHash = checkpoint.header.inboxRollingHash;
595624
const block = checkpoint.blocks[0];
596625

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+
597644
const totalManaUsed = txs.reduce((acc, tx) => acc.add(new Fr(tx.gasUsed.billedGas.l2Gas)), Fr.ZERO);
598645
expect(totalManaUsed.toBigInt()).toEqual(block.header.totalManaUsed.toBigInt());
599646

0 commit comments

Comments
 (0)