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

Use slot to determine fork version #14653

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

Conversation

saolyn
Copy link
Contributor

@saolyn saolyn commented Nov 21, 2024

What type of PR is this?

Other

What does this PR do? Why is it needed?

This PR updates the logic to use the slot instead of the head state version to determine the fork version.

This approach reduces the risk of errors in cases where the block for the first slot of a new fork is delayed or not proposed, which could result in the head state still reflecting the previous fork.

Which issues(s) does this PR fix?
N/A

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 added the API Api related tasks label Nov 21, 2024
@saolyn saolyn requested a review from a team as a code owner November 21, 2024 00:16
@saolyn saolyn requested a review from dB2510 November 21, 2024 00:16
james-prysm
james-prysm previously approved these changes Nov 21, 2024
@@ -726,18 +720,19 @@ func (s *Server) GetAttesterSlashingsV2(w http.ResponseWriter, r *http.Request)
ctx, span := trace.StartSpan(r.Context(), "beacon.GetAttesterSlashingsV2")
defer span.End()

slot := s.HeadFetcher.HeadSlot()
Copy link
Contributor

Choose a reason for hiding this comment

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

Head slot is the slot of the most recent block, not the current slot. There is a TimeFetcher interface that can give you the current slot.

@james-prysm james-prysm dismissed their stale review November 21, 2024 14:04

radek's comment

Comment on lines +86 to +103
func ToForkVersion(slot primitives.Slot) int {
epoch := ToEpoch(slot)
switch {
case epoch >= params.BeaconConfig().ElectraForkEpoch:
return version.Electra
case epoch >= params.BeaconConfig().DenebForkEpoch:
return version.Deneb
case epoch >= params.BeaconConfig().CapellaForkEpoch:
return version.Capella
case epoch >= params.BeaconConfig().BellatrixForkEpoch:
return version.Bellatrix
case epoch >= params.BeaconConfig().AltairForkEpoch:
return version.Altair
default:
return version.Phase0
}
}

Copy link
Member

Choose a reason for hiding this comment

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

This is a good candidate for a unit test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added

Copy link
Member

@prestonvanloon prestonvanloon left a comment

Choose a reason for hiding this comment

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

Looks like a big improvement to avoid reading from the state. I am a bit concerned that there are no unit tests added or changed. Could you add some tests for this logic change?

httputil.HandleError(w, "Could not get head state: "+err.Error(), http.StatusInternalServerError)
return
v := slots.ToForkVersion(primitives.Slot(slot))
if slot == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't this be based on rawSlot instead of slot?

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

Successfully merging this pull request may close these issues.

4 participants