Skip to content

Commit

Permalink
Handle Nil State Object (#5575)
Browse files Browse the repository at this point in the history
* handle panic
* Merge branch 'master' into handlePanic
* Merge refs/heads/master into handlePanic
* Merge refs/heads/master into handlePanic
  • Loading branch information
nisdas authored Apr 22, 2020
1 parent 1480d2b commit 482a054
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion beacon-chain/state/getters.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (b *BeaconState) CloneInnerState() *pbp2p.BeaconState {
// HasInnerState detects if the internal reference to the state data structure
// is populated correctly. Returns false if nil.
func (b *BeaconState) HasInnerState() bool {
return b.state != nil
return b != nil && b.state != nil
}

// GenesisTime of the beacon state as a uint64.
Expand Down
12 changes: 12 additions & 0 deletions beacon-chain/state/getters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,15 @@ func TestBeaconState_SlotDataRace(t *testing.T) {

wg.Wait()
}

func TestNilState_NoPanic(t *testing.T) {
var st *BeaconState
defer func() {
if r := recover(); r != nil {
t.Errorf("Method panicked when it was not supposed to: %v", r)
}
}()
// retrieve elements from nil state
_ = st.GenesisValidatorRoot()
_ = st.Eth1Data()
}

0 comments on commit 482a054

Please sign in to comment.