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

GetValidatorPerformance only return its status info if the validator is active #5568

Merged
merged 14 commits into from Apr 23, 2020
Merged

GetValidatorPerformance only return its status info if the validator is active #5568

merged 14 commits into from Apr 23, 2020

Conversation

ShawkiS
Copy link
Contributor

@ShawkiS ShawkiS commented Apr 21, 2020

Resolves #5485

Description
Write why you are making the changes in this pull request:

The problem here is that the user has 5 validator keys. Only 2 of these are active. The feature request is to only log "previous epoch voting summary" for activated validators as this log is not helpful for pending ones. A pending validator had no duties in the last epoch and there is really nothing to report on their performance.

Write a summary of the changes you are making:
This PR changes one file that is rpc/beacon/validators.go and it adds a condition to the GetValidatorPerformance to make sure it only returns its status info if the validator is active

@ShawkiS ShawkiS requested a review from a team as a code owner April 21, 2020 19:03
@CLAassistant
Copy link

CLAassistant commented Apr 21, 2020

CLA assistant check
All committers have signed the CLA.

@prestonvanloon
Copy link
Member

Please fix build


/root/.cache/bazel/_bazel_root/5c04516d923b21f838ef18b7f8ed7f88/execroot/prysm/beacon-chain/rpc/beacon/validators.go:817:16: undefined: errors
--
  | /root/.cache/bazel/_bazel_root/5c04516d923b21f838ef18b7f8ed7f88/execroot/prysm/beacon-chain/rpc/beacon/validators.go:819:32: not enough arguments in call to helpers.IsActiveValidator
  | have (*eth.Validator)
  | want (*eth.Validator, uint64)


return nil, errors.Wrap(err, "could not get validator")
}
if !helpers.IsActiveValidator(val) {
// If the validator isn't active, no need to get its performance
Copy link
Member

Choose a reason for hiding this comment

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

Not sure if the comment here is necessary. It's pretty self explanatory imo

@terencechain
Copy link
Member

Please also add a description to the PR

@ShawkiS
Copy link
Contributor Author

ShawkiS commented Apr 22, 2020

@prestonvanloon Okay will fix it,

I saw two exapmples: one passing currentEpoch as helpers.SlotToEpoch(currentSlot) and the other helpers.PrevEpoch(state)

What shall I pass in our current example?

@terencechain okay will remove it

if err != nil {
return nil, status.Error(codes.Internal, "Could not get head state")
}
headState, err := bs.HeadFetcher.HeadState(ctx)
Copy link
Member

Choose a reason for hiding this comment

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

please use gofmt here the indentation is off.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay

val, err := headState.ValidatorAtIndex(idx)
currentEpoch := helpers.CurrentEpoch(headState)
if err != nil {
return nil, status.Errorf(codes.Internal, "could not get validator: %v", err)
Copy link
Member

Choose a reason for hiding this comment

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

fix the error here

could not get current epoch

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, why that is happening I saw this code working in other places?
Is the way I am getting it wrong?

Copy link
Member

Choose a reason for hiding this comment

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

ok so your order of code here is vulnerable to errors here. if you look at

		idx, ok := headState.ValidatorIndexByPubkey(pubkeyBytes)

you need to handle the case where the index doesn't exist.
so immediately after that you need to do:

		if !ok {
			missingValidators = append(missingValidators, key)
			continue
		}

Then doing this:

		val, err := headState.ValidatorAtIndex(idx)
		currentEpoch := helpers.CurrentEpoch(headState)
		if err != nil {

is wrong you need to handle the error first

		val, err := headState.ValidatorAtIndex(idx)
		if err != nil {
                        return nil, status.Errorf(codes.Internal, "could not get validator: %v", err)
                }		
               currentEpoch := helpers.CurrentEpoch(headState)

@@ -804,8 +804,9 @@ func (bs *Server) GetValidatorPerformance(

headState, err := bs.HeadFetcher.HeadState(ctx)
if err != nil {
return nil, status.Error(codes.Internal, "Could not get head state")
return nil, status.Errorf(codes.Internal, "could not get head state: %v", err)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return nil, status.Errorf(codes.Internal, "could not get head state: %v", err)
return nil, status.Errorf(codes.Internal, "Could not get head state: %v", err)

This is a server error returned to our rpc clients, so it should be capitalized.

@codecov
Copy link

codecov bot commented Apr 22, 2020

Codecov Report

Merging #5568 into master will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##           master    #5568   +/-   ##
=======================================
  Coverage   27.46%   27.46%           
=======================================
  Files         239      239           
  Lines       20771    20771           
=======================================
  Hits         5705     5705           
  Misses      14070    14070           
  Partials      996      996           

@rauljordan
Copy link
Contributor

Hi @ShawkiS would also recommend always adding a PR description and a good title that gives us enough context about why this is needed (if it solves an open issue, type resolves #ISSUE_NUM or mention the issue it is related to in the description). Also use labels as needed, such as when the PR is ready for review or when it is still in progress.

@ShawkiS ShawkiS changed the title Only active validators log resolves #5485 Apr 22, 2020
@ShawkiS
Copy link
Contributor Author

ShawkiS commented Apr 22, 2020

Hey @rauljordan, okay will make sure to do that next time because it seems that I can't edit the description now, yeah that's better I changed the name. Does it seem that I can't set a label?

Copy link
Member

@nisdas nisdas left a comment

Choose a reason for hiding this comment

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

@ShawkiS Please add in a proper title with a PR description.

@ShawkiS ShawkiS changed the title resolves #5485 GetValidatorPerformance only return its status info if the validator is active Apr 23, 2020
@prylabs-bulldozer prylabs-bulldozer bot merged commit 49ca075 into prysmaticlabs:master Apr 23, 2020
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.

Validators with PENDING status included in Previous epoch voting summary
6 participants