Skip to content

apollo_staking: bound next-epoch resolution window by the epoch length (#14689)#14760

Open
matanl-starkware wants to merge 1 commit into
matanl/bp-14528-validate-staker-setfrom
matanl/bp-14689-next-epoch-window
Open

apollo_staking: bound next-epoch resolution window by the epoch length (#14689)#14760
matanl-starkware wants to merge 1 commit into
matanl/bp-14528-validate-staker-setfrom
matanl/bp-14689-next-epoch-window

Conversation

@matanl-starkware

@matanl-starkware matanl-starkware commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator

Backport of #14689 to main-v0.14.3.

Clean git cherry-pick -x of b95564ff15. No starknet_version change (V0_14_3 preserved).

Stacked on matanl/bp-14528-validate-staker-set — merge that first.

#14689)

Heights were resolved to "current epoch + 1" for up to MIN_EPOCH_LENGTH blocks
past the current epoch's end. When epochs are shorter than MIN_EPOCH_LENGTH,
this attributed heights of later epochs to a stale epoch ID, so epoch-gated
committee changes took effect at a different height on each node. Bound the
window by min(MIN_EPOCH_LENGTH, epoch_length) so the resolved epoch is always
exact; behavior is unchanged for epochs of at least MIN_EPOCH_LENGTH.

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
(cherry picked from commit 86e00e8)
@reviewable-StarkWare

Copy link
Copy Markdown

This change is Reviewable

@matanl-starkware matanl-starkware marked this pull request as ready for review July 10, 2026 21:42
@cursor

cursor Bot commented Jul 10, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes epoch-to-height mapping used for committee lookup and dynamic overrides; incorrect bounds could cause wrong committees at epoch boundaries, though the change narrows resolution to a safer window.

Overview
Tightens when a block height may be treated as belonging to the next epoch (epoch_id + 1) while the next epoch’s length is still unknown.

within_next_epoch_min_bounds no longer always uses MIN_EPOCH_LENGTH as the lookahead window. It now uses min(MIN_EPOCH_LENGTH, self.epoch_length), so when the current epoch is shorter than MIN_EPOCH_LENGTH, only heights that are guaranteed to fall inside that shorter next-epoch window can resolve to the next epoch ID. That avoids mis-assigning heights (and serving the wrong committee / stale override config) on networks with short epochs.

Tests add short-epoch fixtures, assert the last in-bounds height before InvalidHeight, and add a regression where a committee override must apply from the override epoch’s first block even when the epoch cache was primed a few short epochs earlier.

Reviewed by Cursor Bugbot for commit b95564f. Bugbot is set up for automated code reviews on this repo. Configure here.

@matanl-starkware matanl-starkware requested review from dafnamatsry and removed request for ron-starkware July 11, 2026 06:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants