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

Add GET /eth/v2/beacon/pool/attestations endpoint #14560

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from

Conversation

saolyn
Copy link
Contributor

@saolyn saolyn commented Oct 21, 2024

What type of PR is this?

Other

What does this PR do? Why is it needed?

Beacon API Electra alignment, add missing endpoint for GET /eth/v2/beacon/pool/attestations.
As described in the spec https://ethereum.github.io/beacon-APIs/?urls.primaryName=dev#/Beacon/getPoolAttestationsV2

Which issues(s) does this PR fix?

Part of #14476

Other notes for review

Acknowledgements

  • I have read CONTRIBUTING.md.
  • I have made an appropriate entry to CHANGELOG.md.
  • I have added a description to this PR with sufficient context for reviewers to understand this PR.

@saolyn saolyn changed the title add ListAttestationsV2 endpoint Add /eth/v2/beacon/pool/attestations endpoint Oct 21, 2024
@saolyn saolyn changed the title Add /eth/v2/beacon/pool/attestations endpoint Add GET /eth/v2/beacon/pool/attestations endpoint Oct 22, 2024
@saolyn saolyn marked this pull request as ready for review October 22, 2024 15:11
@saolyn saolyn requested a review from a team as a code owner October 22, 2024 15:11
@saolyn saolyn added API Api related tasks Electra electra hardfork labels Oct 22, 2024
case *eth.AttestationElectra:
allAtts[i] = structs.AttElectraFromConsensus(a)
if !versionSet {
firstVersion = a.Version()
Copy link
Contributor

Choose a reason for hiding this comment

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

instead of doing this first version set etc, can't we get the fork from the slot?

Copy link
Contributor

Choose a reason for hiding this comment

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

same with the other function

} else {
bothDefined := rawSlot != "" && rawCommitteeIndex != ""
filteredAtts := make([]interface{}, 0, len(attestations))
for _, att := range attestations {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think there should be a way to merge these two loops and just append based on these checks right?

Comment on lines 81 to 84
committeeIndexMatch := rawCommitteeIndex != "" && att.GetData().CommitteeIndex == primitives.CommitteeIndex(committeeIndex)
slotMatch := rawSlot != "" && att.GetData().Slot == primitives.Slot(slot)
shouldAppend := (bothDefined && committeeIndexMatch && slotMatch) || (!bothDefined && (committeeIndexMatch || slotMatch))
if shouldAppend {
Copy link
Contributor

@rkapka rkapka Oct 23, 2024

Choose a reason for hiding this comment

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

I think this can be simplified like this:

committeeIndexMatch := true
slotMatch := true
if rawCommitteeIndex != "" && att.GetData().CommitteeIndex != primitives.CommitteeIndex(committeeIndex) {
    committeeIndexMatch = false
}
if rawSlot != "" && att.GetData().Slot != primitives.Slot(slot) {
    slotMatch = false
}

if committeeIndexMatch && slotMatch {

} else {
httputil.HandleError(w, fmt.Sprintf("unable to convert attestations of type %T", att), http.StatusInternalServerError)
if !ok {
httputil.HandleError(w, fmt.Sprintf("Unable to convert attestations of type %T", att), http.StatusInternalServerError)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
httputil.HandleError(w, fmt.Sprintf("Unable to convert attestations of type %T", att), http.StatusInternalServerError)
httputil.HandleError(w, fmt.Sprintf("Unable to convert attestation of type %T", att), http.StatusInternalServerError)

if shouldAppend {
a, ok := att.(*eth.Attestation)
if !ok {
httputil.HandleError(w, fmt.Sprintf("Unable to convert attestations of type %T", att), http.StatusInternalServerError)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
httputil.HandleError(w, fmt.Sprintf("Unable to convert attestations of type %T", att), http.StatusInternalServerError)
httputil.HandleError(w, fmt.Sprintf("Unable to convert attestation of type %T", att), http.StatusInternalServerError)

}
httputil.WriteJson(w, &structs.ListAttestationsResponse{Data: filteredAtts})
w.Header().Set(api.VersionHeader, version.String(firstVersion))
Copy link
Contributor

Choose a reason for hiding this comment

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

Same idea as for slashings: we should use the head state or current slot to determine the version and only return attestations for that version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Api related tasks Electra electra hardfork
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants