Skip to content

Commit 9f96979

Browse files
committed
refactor(fast-inbox): source checkpoint consumed messages by leaf-count range (A-1384)
The prover node resolved the boundary Inbox buckets for a checkpoint's leaf-count range itself before asking for the messages between them. The message source now takes the leaf counts directly and reports an unresolvable boundary, so drop the two-step lookup.
1 parent 9cdfc62 commit 9f96979

1 file changed

Lines changed: 7 additions & 26 deletions

File tree

yarn-project/prover-node/src/prover-node.ts

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import { ChonkCache } from '@aztec/prover-client/orchestrator';
1414
import { type AvmSimulator, PublicProcessorFactory } from '@aztec/simulator/server';
1515
import {
1616
EventDrivenL2BlockStream,
17-
type L2Block,
1817
type L2BlockId,
1918
type L2BlockSource,
2019
type L2BlockStreamEvent,
@@ -38,7 +37,6 @@ import {
3837
import type { DataStoreConfig } from '@aztec/stdlib/kv-store';
3938
import type { L1ToL2MessageSource } from '@aztec/stdlib/messaging';
4039
import { MerkleTreeId } from '@aztec/stdlib/trees';
41-
import type { BlockHeader } from '@aztec/stdlib/tx';
4240
import {
4341
L1Metrics,
4442
type TelemetryClient,
@@ -353,9 +351,13 @@ export class ProverNode implements L2BlockStreamEventHandler, ProverNodeApi, Tra
353351
const previousBlockNumber = BlockNumber(checkpoint.blocks[0].number - 1);
354352
const previousBlockHeader = await this.gatherPreviousBlockHeader(previousBlockNumber);
355353
const lastBlock = checkpoint.blocks.at(-1)!;
356-
// Streaming Inbox (AZIP-22 Fast Inbox): the checkpoint's consumed messages are those in the Inbox buckets between
357-
// the parent checkpoint's consumed position and this checkpoint's last block (compact leaf-count range).
358-
const l1ToL2Messages = await this.deriveCheckpointConsumedMessages(previousBlockHeader, lastBlock);
354+
// Streaming Inbox (AZIP-22 Fast Inbox): the checkpoint's consumed messages are those between the parent
355+
// checkpoint's consumed position and this checkpoint's last block, as a compact leaf-count range. The prover
356+
// slices them per block.
357+
const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2MessagesBetweenLeafCounts(
358+
BigInt(previousBlockHeader.state.l1ToL2MessageTree.nextAvailableLeafIndex),
359+
BigInt(lastBlock.header.state.l1ToL2MessageTree.nextAvailableLeafIndex),
360+
);
359361
const previousInboxRollingHash = await this.gatherPreviousInboxRollingHash(checkpoint.number);
360362
const lastBlockHash = await lastBlock.header.hash();
361363
await this.worldState.syncImmediate(lastBlock.number, lastBlockHash);
@@ -372,27 +374,6 @@ export class ProverNode implements L2BlockStreamEventHandler, ProverNodeApi, Tra
372374
};
373375
}
374376

375-
/**
376-
* Derives a checkpoint's consumed L1-to-L2 messages, in order, from the Inbox buckets between the parent
377-
* checkpoint's consumed position (the block before the checkpoint's first block) and the checkpoint's last block
378-
* (compact leaf counts), for the prover to slice per block (AZIP-22 Fast Inbox).
379-
*/
380-
private async deriveCheckpointConsumedMessages(previousBlockHeader: BlockHeader, lastBlock: L2Block): Promise<Fr[]> {
381-
const startLeafCount = BigInt(previousBlockHeader.state.l1ToL2MessageTree.nextAvailableLeafIndex);
382-
const endLeafCount = BigInt(lastBlock.header.state.l1ToL2MessageTree.nextAvailableLeafIndex);
383-
if (endLeafCount <= startLeafCount) {
384-
return [];
385-
}
386-
const startBucket = await this.l1ToL2MessageSource.getInboxBucketByTotalMsgCount(startLeafCount);
387-
const endBucket = await this.l1ToL2MessageSource.getInboxBucketByTotalMsgCount(endLeafCount);
388-
if (startBucket === undefined || endBucket === undefined) {
389-
throw new Error(
390-
`Cannot resolve consumed messages for checkpoint ending at block ${lastBlock.number} from the Inbox buckets`,
391-
);
392-
}
393-
return this.l1ToL2MessageSource.getL1ToL2MessagesBetweenBuckets(startBucket.seq, endBucket.seq);
394-
}
395-
396377
/**
397378
* Sources the inbox rolling hash chain-start for a checkpoint: the previous checkpoint's `inboxRollingHash`, or zero
398379
* for the genesis checkpoint. The prover threads this into the base parity circuits so the rebuilt checkpoint header

0 commit comments

Comments
 (0)