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/attester_slashings #14479

Merged
merged 14 commits into from
Oct 16, 2024
Merged

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/pool/attester_slashings.
As described in the spec https://ethereum.github.io/beacon-APIs/?urls.primaryName=dev#/Beacon/getPoolAttesterSlashingsV2

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 /eth/v2/beacon/pool/attester_slashings Add GET /eth/v2/beacon/pool/attester_slashings Sep 25, 2024
@saolyn saolyn marked this pull request as ready for review September 25, 2024 15:00
@saolyn saolyn requested a review from a team as a code owner September 25, 2024 15:00
ss := make([]*eth.AttesterSlashingElectra, len(sourceSlashings))
for i, slashing := range sourceSlashings {
a, ok := slashing.(*eth.AttesterSlashingElectra)
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.

you could do the reverse here and avoid the else

@@ -172,6 +172,11 @@ type GetAttesterSlashingsResponse struct {
Data []*AttesterSlashing `json:"data"`
}

type GetAttesterSlashingsV2Response struct {
Version string `json:"version"`
Data []json.RawMessage `json:"data"` // Accepts both `[]*AttesterSlashing` and `[]*AttesterSlashingElectra` types
Copy link
Contributor

Choose a reason for hiding this comment

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

Single json.RawMessage will make the code more compact

}
v := version.String(headState.Version())
Copy link
Contributor

Choose a reason for hiding this comment

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

The version should be based on the version of the slashing, not the state. This is because (1) the only possible slashing versions are Phase0 and Electra, and (2) the state here can be after a fork with the slashing being before the fork.

beacon-chain/rpc/eth/beacon/handlers_pool.go Outdated Show resolved Hide resolved
@@ -169,7 +169,8 @@ type BLSToExecutionChangesPoolResponse struct {
}

type GetAttesterSlashingsResponse struct {
Data []*AttesterSlashing `json:"data"`
Version string `json:"version"`
Copy link
Contributor

Choose a reason for hiding this comment

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

In https://github.com/prysmaticlabs/prysm/pull/14481/files#diff-b7de0123b995294eb1e799afb080f62c9a4a08195f9ed1f387a9071922b1ec97 the Version field has the omitifempty tag. I believe this is required for v1 to work correctly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It does seem to work correctly but for the sake of accuracy we should definitely add the field

beacon-chain/rpc/eth/beacon/handlers_pool.go Outdated Show resolved Hide resolved
beacon-chain/rpc/eth/beacon/handlers_pool.go Outdated Show resolved Hide resolved
beacon-chain/rpc/eth/beacon/handlers_pool.go Outdated Show resolved Hide resolved
beacon-chain/rpc/eth/beacon/handlers_pool.go Outdated Show resolved Hide resolved
attStruct := structs.AttesterSlashingFromConsensus(a)
attStructs = append(attStructs, attStruct)
}
resp.Version = version.String(slashing.Version())
Copy link
Contributor

Choose a reason for hiding this comment

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

It doesn't make sense to rewrite this value in a loop. The effect of this will be that the version will be taken from the last slashing. How to correctly treat different types of slashings post-Electra is still something that I have to think about, but for now let's use the current slot to determine the version.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Then it's probably fine for now to add the version using the first slashing:
sourceSlashings[0].Version()

require.DeepEqual(t, slashing1, ss[0])
require.DeepEqual(t, slashing2, ss[1])
})
t.Run("V2", func(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

can you add a pre-Electra v2 test case?

@rkapka rkapka added this pull request to the merge queue Oct 16, 2024
Merged via the queue into develop with commit 2afa63b Oct 16, 2024
17 of 18 checks passed
@rkapka rkapka deleted the add-getAttesterSlashingsV2 branch October 16, 2024 09:30
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