Skip to content

Gate churn-limit helpers by fork - #9880

Open
NikhilSharmaWe wants to merge 6 commits into
sigp:unstablefrom
NikhilSharmaWe:gate-churn-limit-helpers
Open

NikhilSharmaWe wants to merge 6 commits into
sigp:unstablefrom
NikhilSharmaWe:gate-churn-limit-helpers

Conversation

@NikhilSharmaWe

Copy link
Copy Markdown
Contributor

Issue Addressed

#9218

Proposed Changes

  • Fork-gate churn-limit helpers on BeaconState so pre-Electra validator-count functions error if called after Electra.
  • Rename the old Deneb helper to get_validator_activation_churn_limit. get_activation_churn_limit is now the Gloas spec function (Gwei).
  • Single-pass epoch processing only computes the limits that apply to the current fork. Churn formulas are unchanged.

Signed-off-by: Nikhil Sharma <nikhilsharma230303@gmail.com>
@michaelsproul michaelsproul added code-quality consensus An issue/PR that touches consensus code, such as state_processing or block verification. labels Aug 25, 2026
@chong-he chong-he added the ready-for-review The code is ready for review label Sep 11, 2026

@chong-he chong-he left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty good, some comments below. I thought it would also be great to have a few tests covering the *_churn_limit functions and their applicability to different forks to prevent regression.

let activation_churn_limit = state.get_activation_churn_limit(spec)?;
let finalized_checkpoint = state.finalized_checkpoint();
let fork_name = state.fork_name_unchecked();
let (validator_churn_limit, activation_churn_limit) = if !fork_name.electra_enabled() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the activation_churn_limit needs to be an Option? It looks like it can just be u64, which is simpler. Also maybe can move the let activation_churn_limit to a bit after this just before it's used

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, now a u64, computed just before use (before the state split)

Comment on lines +86 to +89
/// Pre-Electra validator-count exit churn.
validator_churn_limit: Option<u64>,
/// Electra+ Gwei exit churn.
exit_churn_limit: Option<u64>,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that we have 2 types of churn limits, and they are both Option, which cause a bit of ambiguity. Maybe we can define an enum:

enum ExitChurnLimit {
    // Pre-Electra, number of validators per epoch
    ValidatorCount(u64),
    /// Electra onwards: Gwei per epoch.
    Balance(u64),
}

so that it is explicitly clear that we refer to the number of validators that can exit or the balance/Gwei that can exit per epoch

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced the two Option with an ExitChurnLimit enum.

Comment on lines 2543 to +2544
pub fn get_validator_churn_limit(&self, spec: &ChainSpec) -> Result<u64, BeaconStateError> {
if self.fork_name_unchecked().electra_enabled() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: there are so many *_churn_limit functions now, and it will be helpful to have a comment at the top of functions as to where the fork they applies (although one can deduced from the function itself, but it is a nice to have at the comment for clarity).

For example, this is Pre-Electra only, others can be Electra-onwards, Electra/Fulu, or Gloas-onwards etc

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added the comments

@chong-he chong-he added waiting-on-author The reviewer has suggested changes and awaits thier implementation. and removed ready-for-review The code is ready for review labels Sep 14, 2026
Signed-off-by: Nikhil Sharma <nikhilsharma230303@gmail.com>
@NikhilSharmaWe

Copy link
Copy Markdown
Contributor Author

Looks pretty good, some comments below. I thought it would also be great to have a few tests covering the *_churn_limit functions and their applicability to different forks to prevent regression.

added a fork-gate test for the *_churn_limit helpers.

@chong-he chong-he added ready-for-review The code is ready for review and removed waiting-on-author The reviewer has suggested changes and awaits thier implementation. labels Sep 17, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code-quality consensus An issue/PR that touches consensus code, such as state_processing or block verification. ready-for-review The code is ready for review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants