Skip to content

Commit 7ac515b

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 eeabc7d commit 7ac515b

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';
@@ -55,6 +55,7 @@ export class MockArchiver extends MockL2BlockSource implements L2BlockSource, L1
5555
*/
5656
export class MockPrefilledArchiver extends MockArchiver {
5757
private prefilled: Checkpoint[] = [];
58+
private prefilledMessages: Fr[][] = [];
5859

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

74120
public override createBlocks(numBlocks: number) {

0 commit comments

Comments
 (0)