Skip to content

Commit 1c7b5d7

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 ef371be commit 1c7b5d7

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,
@@ -352,9 +350,13 @@ export class ProverNode implements L2BlockStreamEventHandler, ProverNodeApi, Tra
352350
const previousBlockNumber = BlockNumber(checkpoint.blocks[0].number - 1);
353351
const previousBlockHeader = await this.gatherPreviousBlockHeader(previousBlockNumber);
354352
const lastBlock = checkpoint.blocks.at(-1)!;
355-
// Streaming Inbox (AZIP-22 Fast Inbox): the checkpoint's consumed messages are those in the Inbox buckets between
356-
// the parent checkpoint's consumed position and this checkpoint's last block (compact leaf-count range).
357-
const l1ToL2Messages = await this.deriveCheckpointConsumedMessages(previousBlockHeader, lastBlock);
353+
// Streaming Inbox (AZIP-22 Fast Inbox): the checkpoint's consumed messages are those between the parent
354+
// checkpoint's consumed position and this checkpoint's last block, as a compact leaf-count range. The prover
355+
// slices them per block.
356+
const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2MessagesBetweenLeafCounts(
357+
BigInt(previousBlockHeader.state.l1ToL2MessageTree.nextAvailableLeafIndex),
358+
BigInt(lastBlock.header.state.l1ToL2MessageTree.nextAvailableLeafIndex),
359+
);
358360
const previousInboxRollingHash = await this.gatherPreviousInboxRollingHash(checkpoint.number);
359361
const lastBlockHash = await lastBlock.header.hash();
360362
await this.worldState.syncImmediate(lastBlock.number, lastBlockHash);
@@ -371,27 +373,6 @@ export class ProverNode implements L2BlockStreamEventHandler, ProverNodeApi, Tra
371373
};
372374
}
373375

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

0 commit comments

Comments
 (0)