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 /eth/v2/beacon/blocks/{block_id}/attestations #14478

Merged
merged 16 commits into from
Oct 10, 2024

Conversation

saolyn
Copy link
Contributor

@saolyn saolyn commented Sep 25, 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 /eth/v2/beacon/blocks/{block_id}/attestations.
As described in the spec https://ethereum.github.io/beacon-APIs/?urls.primaryName=dev#/Beacon/getBlockAttestationsV2

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 marked this pull request as ready for review September 25, 2024 14:57
@saolyn saolyn requested a review from a team as a code owner September 25, 2024 14:57
@saolyn saolyn requested review from potuz, rkapka and nisdas September 25, 2024 14:57
@saolyn saolyn added API Api related tasks Electra electra hardfork labels Sep 25, 2024
@saolyn saolyn force-pushed the add-getBlockAttestationsV2 branch from b3c929e to 7ea8c9c Compare September 25, 2024 15:01
@saolyn saolyn requested a review from james-prysm September 25, 2024 15:06
@saolyn saolyn force-pushed the add-getBlockAttestationsV2 branch from e9031c3 to 3f00b67 Compare September 26, 2024 12:40
@saolyn saolyn force-pushed the add-getBlockAttestationsV2 branch from 75a27c3 to a6480ab Compare September 30, 2024 16:06
Version string `json:"version"`
ExecutionOptimistic bool `json:"execution_optimistic"`
Finalized bool `json:"finalized"`
Data interface{} `json:"data"` // Accepts both `Attestation` and `AttestationElectra` types
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we make this a json.RawMessage?

@@ -585,6 +585,15 @@ func (s *Service) beaconEndpoints(
handler: server.GetBlockAttestations,
methods: []string{http.MethodGet},
},
{
template: "/eth/v2/beacon/blocks/{block_id}/attestations",
name: namespace + ".GetBlockAttestations",
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
name: namespace + ".GetBlockAttestations",
name: namespace + ".GetBlockAttestationsV2",

beacon-chain/rpc/eth/beacon/handlers.go Show resolved Hide resolved
beacon-chain/rpc/eth/beacon/handlers.go Show resolved Hide resolved
@@ -515,7 +515,7 @@ func TestGetBlockAttestations(t *testing.T) {
Blocker: mockBlockFetcher,
}

request := httptest.NewRequest(http.MethodGet, "http://foo.example/eth/v2/beacon/blocks/{block_id}/attestations", nil)
request := httptest.NewRequest(http.MethodGet, "http://foo.example/eth/v1/beacon/blocks/{block_id}/attestations", nil)
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 it would be cleaner to organize tests like this:

t.Run("v1")
t.Run("v2")
    t.Run("pre-Electra")
    t.Run("post-Electra")

Blocks can be created at the top, before test runs.

if v >= version.Electra {
for i, att := range consensusAtts {
a, ok := att.(*eth.AttestationElectra)
if ok {
Copy link
Contributor

Choose a reason for hiding this comment

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

similar feedback to another PR we can avoid the else statement by reversing this

Version string `json:"version"`
ExecutionOptimistic bool `json:"execution_optimistic"`
Finalized bool `json:"finalized"`
Data []json.RawMessage `json:"data"` // Accepts both `Attestation` and `AttestationElectra` types
Copy link
Contributor

Choose a reason for hiding this comment

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

If you make this a single json.RawMessage, you can call json.Marshal just once on the entire slice.

CHANGELOG.md Outdated Show resolved Hide resolved
@saolyn saolyn enabled auto-merge October 10, 2024 10:07
@saolyn saolyn added this pull request to the merge queue Oct 10, 2024
Merged via the queue into develop with commit 57cc495 Oct 10, 2024
17 of 18 checks passed
@saolyn saolyn deleted the add-getBlockAttestationsV2 branch October 10, 2024 10:26
@syjn99 syjn99 mentioned this pull request Nov 7, 2024
3 tasks
@kasey kasey added the changelog/added Changelog Section: Added label Dec 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Api related tasks changelog/added Changelog Section: Added Electra electra hardfork
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants