Skip to content

Commit

Permalink
Resolve Nil Validator Panic (#6218)
Browse files Browse the repository at this point in the history
* resolve proposer panic
* Merge refs/heads/master into panic-proposer-slashed
  • Loading branch information
rauljordan authored Jun 11, 2020
1 parent cf3260b commit 2fb4855
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions beacon-chain/state/getters.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,17 @@ func (v *ReadOnlyValidator) WithdrawalCredentials() []byte {

// Slashed returns the read only validator is slashed.
func (v *ReadOnlyValidator) Slashed() bool {
if v == nil || v.validator == nil {
return false
}
return v.validator.Slashed
}

// CopyValidator returns the copy of the read only validator.
func (v *ReadOnlyValidator) CopyValidator() *ethpb.Validator {
if v == nil || v.validator == nil {
return nil
}
return CopyValidator(v.validator)
}

Expand Down
10 changes: 10 additions & 0 deletions beacon-chain/state/getters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,13 @@ func TestNilState_NoPanic(t *testing.T) {
_ = st.FinalizedCheckpoint()
_ = err
}

func TestReadOnlyValidator_NoPanic(t *testing.T) {
v := &ReadOnlyValidator{}
if v.Slashed() == true {
t.Error("Expected not slashed")
}
if v.CopyValidator() != nil {
t.Error("Expected nil result")
}
}

0 comments on commit 2fb4855

Please sign in to comment.