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

reduce code duplication in process_attestations #4141

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from

Conversation

james-prysm
Copy link
Contributor

I noticed some differences in the implementation of process attestations for Prysm but still passed spec tests. We can reduce code duplication in process_attestations by replacing the component with get_attesting_indicies and moving some checks there. The proposed change as well as test updates are below. As far as I could tell it should be ok to have those validations in get_attesting_indicies but please let me know if I am off base.

a thank you to @jtraglia for the guidance

…ttesting_indicies, moving validation checks from process_attestation to get_attesting_indicies

reverting print

removing more prints
@@ -603,18 +603,23 @@ def get_attesting_indices(state: BeaconState, attestation: Attestation) -> Set[V
Return the set of attesting indices corresponding to ``aggregation_bits`` and ``committee_bits``.
"""
output: Set[ValidatorIndex] = set()
assert attestation.data.index == 0 # [Modified in Electra:EIP7549]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

do i need these markers? # [Modified in Electra:EIP7549]

@@ -32,8 +31,6 @@ def test_invalid_attestation_data_index_not_zero(spec, state):
assert committee_index == spec.get_committee_indices(attestation.committee_bits)[0]
attestation.data.index = committee_index

sign_attestation(spec, state, attestation)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

sign_attestation calls get_attesting_indicies internally and fails here with it

@mkalinin
Copy link
Contributor

Note that get_attesting_indices is called in several places of the state transition code. It was a pure getter previously and the intention was to preserve that semantics and run all checks inside of process_attestation as it was before Electra.

@james-prysm
Copy link
Contributor Author

james-prysm commented Feb 26, 2025

Note that get_attesting_indices is called in several places of the state transition code. It was a pure getter previously and the intention was to preserve that semantics and run all checks inside of process_attestation as it was before Electra.

@mkalinin Are there potentially several unintended consequences in client implementations using a non pure getter in this case?
should clients maintain a pure getter implementation or as close to it as we can? I don't think this is the current situation, and we should update if that's the case

@jtraglia
Copy link
Member

James: We can reduce code duplication in process_attestations by replacing the component with get_attesting_indicies and moving some checks there.

Yes, I see the appeal to this. It does make process_attestations easier to read and maintain.

Mikhail: Note that get_attesting_indices is called in several places of the state transition code. It was a pure getter previously and the intention was to preserve that semantics and run all checks inside of process_attestation as it was before Electra.

This is a good point. These checks are pretty minimal, but they are unnecessary in the accessor. The most efficient thing would be to only perform these checks once in process_attestation like we currently do.

I'm a bit torn on what I think we should do. I think I'm slightly in favor of leaving it how it is, just so that it's clear to clients that they do not need to perform these checks in the beacon state accessor.

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.

3 participants