Skip to content

Commit bad79d0

Browse files
committed
fix(fast-inbox): register Inbox buckets in the prefilled mock archiver (A-1384)
The world-state integration test drives the streaming synchronizer through MockPrefilledArchiver, but setPrefilled only seeded the legacy per-checkpoint message map and never registered Inbox buckets. Post-flip the synchronizer reconstructs each block's consumed L1-to-L2 bundle from buckets via getInboxBucketByTotalMsgCount, which returned undefined against the empty bucket map, so every block synced with an empty bundle and its reconstructed state diverged from the committed header (block state does not match world state). Register a genesis sentinel bucket plus one bucket per message-carrying checkpoint with cumulative totalMsgCount matching the block's post-insertion leaf count.
1 parent 0898f4a commit bad79d0

1 file changed

Lines changed: 47 additions & 1 deletion

File tree

yarn-project/archiver/src/test/mock_archiver.ts

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { CheckpointNumber } from '@aztec/foundation/branded-types';
2-
import type { Fr } from '@aztec/foundation/curves/bn254';
2+
import { Fr } from '@aztec/foundation/curves/bn254';
33
import type { L2BlockSource } from '@aztec/stdlib/block';
44
import type { Checkpoint } from '@aztec/stdlib/checkpoint';
55
import type { InboxBucket, L1ToL2MessageSource } from '@aztec/stdlib/messaging';
@@ -51,6 +51,7 @@ export class MockArchiver extends MockL2BlockSource implements L2BlockSource, L1
5151
*/
5252
export class MockPrefilledArchiver extends MockArchiver {
5353
private prefilled: Checkpoint[] = [];
54+
private prefilledMessages: Fr[][] = [];
5455

5556
constructor(prefilled: { checkpoint: Checkpoint; messages: Fr[] }[]) {
5657
super();
@@ -65,6 +66,51 @@ export class MockPrefilledArchiver extends MockArchiver {
6566
}
6667
this.setL1ToL2Messages(checkpoint.number, messages);
6768
}
69+
70+
for (const { checkpoint, messages } of prefilled) {
71+
this.prefilledMessages[checkpoint.number - 1] = messages;
72+
}
73+
74+
// Register the Inbox buckets the streaming world-state synchronizer reconstructs each block's consumed
75+
// message bundle from (AZIP-22 Fast Inbox): a genesis sentinel (totalMsgCount 0) so a leaf count of 0
76+
// resolves to a bucket, plus one bucket per message-carrying checkpoint whose cumulative totalMsgCount
77+
// matches the block's post-insertion L1-to-L2 leaf count. Rebuilt from the full prefilled chain (not just
78+
// this call's checkpoints) so a reorg re-prefill that replaces a suffix keeps the cumulative aligned.
79+
// Without these the synchronizer derives an empty bundle and the reconstructed block state diverges.
80+
this.setInboxBucket(
81+
{
82+
seq: 0n,
83+
inboxRollingHash: Fr.ZERO,
84+
totalMsgCount: 0n,
85+
timestamp: 0n,
86+
msgCount: 0,
87+
lastMessageIndex: 0n,
88+
isOpen: false,
89+
},
90+
[],
91+
);
92+
let bucketSeq = 0n;
93+
let totalMsgCount = 0n;
94+
for (let i = 0; i < this.prefilled.length; i++) {
95+
const messages = this.prefilledMessages[i] ?? [];
96+
if (messages.length === 0) {
97+
continue;
98+
}
99+
bucketSeq += 1n;
100+
totalMsgCount += BigInt(messages.length);
101+
this.setInboxBucket(
102+
{
103+
seq: bucketSeq,
104+
inboxRollingHash: Fr.ZERO,
105+
totalMsgCount,
106+
timestamp: bucketSeq,
107+
msgCount: messages.length,
108+
lastMessageIndex: totalMsgCount - 1n,
109+
isOpen: false,
110+
},
111+
messages,
112+
);
113+
}
68114
}
69115

70116
public override createBlocks(numBlocks: number) {

0 commit comments

Comments
 (0)