Skip to content

apollo_staking,apollo_consensus_manager: read mock epoch height from batcher first (#14698)#14761

Open
matanl-starkware wants to merge 1 commit into
matanl/bp-14689-next-epoch-windowfrom
matanl/bp-14698-mock-epoch-height
Open

apollo_staking,apollo_consensus_manager: read mock epoch height from batcher first (#14698)#14761
matanl-starkware wants to merge 1 commit into
matanl/bp-14689-next-epoch-windowfrom
matanl/bp-14698-mock-epoch-height

Conversation

@matanl-starkware

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

Copy link
Copy Markdown
Collaborator

Backport of #14698 to main-v0.14.3.

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

Stacked on matanl/bp-14689-next-epoch-window — merge that first.

…batcher first (#14698)

The mock staking contract derives the current epoch from the chain's latest
block number. It read this solely from state sync, which is a downstream reader
that can lag the commit tip significantly. Because committee resolution can only
look ahead MIN_EPOCH_LENGTH (150) blocks past the epoch boundary implied by that
height, a state-sync lag approaching ~150 blocks pushes the consensus height
beyond the resolvable window: get_committee returns InvalidHeight, and consensus
falls back to waiting for sync instead of producing blocks.

Read the height from the batcher first (its storage marker tracks the commit
tip), falling back to state sync on error, mirroring get_block_hash_with_fallback.
The batcher get_height marker is the next-to-build height, so the latest
committed block is one below it. Epoch math is unchanged; only the height source
moves closer to the tip. This also aligns the mock with CairoStakingContract,
which already reads epoch data via the batcher.

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
(cherry picked from commit 6cfff03)
@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 how consensus committee epochs are computed in the mock staking path; incorrect height would still stall block production, though behavior is narrowed with batcher-first logic and an existing state-sync fallback.

Overview
Mock staking epoch resolution now uses the batcher’s committed chain tip instead of state sync’s latest block when computing the current (and thus previous) epoch.

MockStakingContract takes a SharedBatcherClient and resolves height via latest_committed_block: get_height() minus one (next-to-build marker), with a warn and fallback to state sync on batcher failure. create_committee_provider passes the batcher client into the mock contract constructor.

Tests were rewired to mock batcher height markers and add coverage for epoch-boundary markers and batcher-error fallback. The MIN_EPOCH_LENGTH comment in staking_manager was updated to describe lag relative to the batcher height source.

Reviewed by Cursor Bugbot for commit 163e4fc. 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