Skip to content

Commit aa1822c

Browse files
committed
refactor(fast-inbox): dedupe block L1-to-L2 leaf-count read in the validator (A-1383)
Consolidate the three `BigInt(block.header.state.l1ToL2MessageTree.nextAvailableLeafIndex)` reads into a single `blockLeafCount` helper.
1 parent ff9c26c commit aa1822c

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

yarn-project/validator-client/src/proposal_handler.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -949,9 +949,14 @@ export class ProposalHandler {
949949
});
950950
}
951951

952+
/** A block's L1-to-L2 message tree leaf count: the cumulative Inbox message count it consumed through. */
953+
private blockLeafCount(block: BlockData | L2Block): bigint {
954+
return BigInt(block.header.state.l1ToL2MessageTree.nextAvailableLeafIndex);
955+
}
956+
952957
/** The cumulative Inbox message count consumed through a block: its L1-to-L2 tree leaf count (0 at genesis). */
953958
private getConsumedMsgTotal(block: 'genesis' | BlockData): bigint {
954-
return block === 'genesis' ? 0n : BigInt(block.header.state.l1ToL2MessageTree.nextAvailableLeafIndex);
959+
return block === 'genesis' ? 0n : this.blockLeafCount(block);
955960
}
956961

957962
/**
@@ -979,7 +984,7 @@ export class ProposalHandler {
979984
return 0n;
980985
}
981986
const preBlock = await this.blockSource.getBlockData({ number: BlockNumber(preBlockNumber) });
982-
return preBlock === undefined ? undefined : BigInt(preBlock.header.state.l1ToL2MessageTree.nextAvailableLeafIndex);
987+
return preBlock === undefined ? undefined : this.blockLeafCount(preBlock);
983988
}
984989

985990
/**
@@ -990,7 +995,7 @@ export class ProposalHandler {
990995
* authoritative reject pre-flip; the flip (A-1384) removes the padding so the check resolves.
991996
*/
992997
private async isLastBlockConsumptionSufficient(slot: SlotNumber, blocks: L2Block[]): Promise<boolean> {
993-
const lastBlockTotal = BigInt(blocks[blocks.length - 1].header.state.l1ToL2MessageTree.nextAvailableLeafIndex);
998+
const lastBlockTotal = this.blockLeafCount(blocks[blocks.length - 1]);
994999
const checkpointStartTotal = await this.getPreBlockConsumedTotal(blocks[0].number);
9951000
const lastConsumedBucket = await this.l1ToL2MessageSource.getInboxBucketByTotalMsgCount(lastBlockTotal);
9961001
if (checkpointStartTotal === undefined || lastConsumedBucket === undefined) {

0 commit comments

Comments
 (0)