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

Filter Errored Keys from Returned Slashing Protection History in Standard API #9968

Merged
merged 2 commits into from
Dec 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions validator/rpc/standard_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,14 @@ func (s *Server) DeleteKeystores(
if err != nil {
return nil, status.Errorf(codes.Internal, "Could not delete keys: %v", err)
}
keysToFilter := req.PublicKeys
exportedHistory, err := slashingprotection.ExportStandardProtectionJSON(ctx, s.valDB, keysToFilter...)
// We select keys that were deleted for retrieving slashing protection history.
Copy link
Member

Choose a reason for hiding this comment

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

Should we add a unit test for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In description: The Prysm delete keystores underlying logic never returns an error, so it is not possible to add a unit test for this logic, unfortunately. Nevertheless, we should still implement the expected behavior.. So we cant add tests for this that would test this code branch, but it's important to have this logic

filteredKeys := make([][]byte, 0, len(req.PublicKeys))
for i, st := range statuses {
if st.Status != ethpbservice.DeletedKeystoreStatus_ERROR {
filteredKeys = append(filteredKeys, req.PublicKeys[i])
}
}
exportedHistory, err := slashingprotection.ExportStandardProtectionJSON(ctx, s.valDB, filteredKeys...)
if err != nil {
return nil, status.Errorf(
codes.Internal,
Expand Down
10 changes: 5 additions & 5 deletions validator/slashing-protection-history/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ import (
func ExportStandardProtectionJSON(
ctx context.Context,
validatorDB db.Database,
keysToFilter ...[]byte,
filteredKeys ...[]byte,
) (*format.EIPSlashingProtectionFormat, error) {
keysFilterMap := make(map[string]bool, len(keysToFilter))
for _, k := range keysToFilter {
keysFilterMap := make(map[string]bool, len(filteredKeys))
for _, k := range filteredKeys {
keysFilterMap[string(k)] = true
}
interchangeJSON := &format.EIPSlashingProtectionFormat{}
Expand Down Expand Up @@ -58,7 +58,7 @@ func ExportStandardProtectionJSON(
len(proposedPublicKeys), "Extracting signed blocks by validator public key",
)
for _, pubKey := range proposedPublicKeys {
if _, ok := keysFilterMap[string(pubKey[:])]; len(keysToFilter) > 0 && !ok {
if _, ok := keysFilterMap[string(pubKey[:])]; len(filteredKeys) > 0 && !ok {
continue
}
pubKeyHex, err := pubKeyToHexString(pubKey[:])
Expand All @@ -84,7 +84,7 @@ func ExportStandardProtectionJSON(
len(attestedPublicKeys), "Extracting signed attestations by validator public key",
)
for _, pubKey := range attestedPublicKeys {
if _, ok := keysFilterMap[string(pubKey[:])]; len(keysToFilter) > 0 && !ok {
if _, ok := keysFilterMap[string(pubKey[:])]; len(filteredKeys) > 0 && !ok {
continue
}
pubKeyHex, err := pubKeyToHexString(pubKey[:])
Expand Down