-
Notifications
You must be signed in to change notification settings - Fork 1k
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
base: develop
Are you sure you want to change the base?
Conversation
@@ -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() |
There was a problem hiding this comment.
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.
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 | ||
} | ||
} | ||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added
There was a problem hiding this 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 { |
There was a problem hiding this comment.
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?
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