Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify/optimize process_registry_updates #4081

Merged
merged 1 commit into from
Jan 15, 2025

Conversation

jtraglia
Copy link
Member

When reviewing Prysm's implementation of process_registry_updates I noticed that they were processing registry changes in a single loop, rather than two like the spec does. After evaluating it, I came to the conclusion that it is safe. Since this is a simplification and an optimization that clients should implement, it would be best to include it in the specifications.

These operations can be done in the same loop because they do not impact each other. For example, if a validator is added to the activation queue (validator.activation_eligibility_epoch = current_epoch + 1) it will not be eligible for activation until validator.activation_eligibility_epoch is finalized, which is not this epoch.

def is_eligible_for_activation(state: BeaconState, validator: Validator) -> bool:
"""
Check if ``validator`` is eligible for activation.
"""
return (
# Placement in queue is finalized
validator.activation_eligibility_epoch <= state.finalized_checkpoint.epoch
# Has not yet been activated
and validator.activation_epoch == FAR_FUTURE_EPOCH
)

This PR makes the following changes:

  • Compute the current epoch once at the beginning of the function.
  • Replace instances of get_current_epoch(state) with current_epoch.
  • Combine the two loops into one.

@rolfyone
Copy link
Contributor

Looks good!

Copy link
Contributor

@mkalinin mkalinin left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Contributor

@potuz potuz left a comment

Choose a reason for hiding this comment

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

LGTM

@jtraglia jtraglia merged commit fd87b46 into ethereum:dev Jan 15, 2025
23 checks passed
@jtraglia jtraglia deleted the simplify-registry-updates branch January 15, 2025 19:23
# Activate all eligible validators
# [Modified in Electra:EIP7251]
activation_epoch = compute_activation_exit_epoch(get_current_epoch(state))
for validator in state.validators:
if is_eligible_for_activation(state, validator):
Copy link
Contributor

Choose a reason for hiding this comment

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

these three ifs could also be elifs couldn't they, as they are mutually exclusive?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm yes they are mutually exclusive. Making those elif conditions is a good idea.

Copy link
Member Author

Choose a reason for hiding this comment

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

mergify bot pushed a commit to sigp/lighthouse that referenced this pull request Jan 28, 2025
No substantial changes in v1.5.0-beta.1, this PR just updates the tests.

The optimisation described in this PR is already implemented in our single-pass epoch processing:

- ethereum/consensus-specs#4081
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants