Don't save nil head state (#4799)

* Don't save nil head state
* Update head
This commit is contained in:
terence tsao 2020-02-08 21:08:21 -08:00 committed by GitHub
parent 70cb06d50f
commit 16a0c9f463
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -155,7 +155,12 @@ func (s *Service) HeadState(ctx context.Context) (*state.BeaconState, error) {
defer s.headLock.RUnlock()
if s.headState == nil {
return s.beaconDB.HeadState(ctx)
headState, err := s.beaconDB.HeadState(ctx)
if err != nil {
return nil, err
}
s.headState = headState
return headState, nil
}
return s.headState.Copy(), nil

View File

@ -64,6 +64,9 @@ func (s *Service) saveHead(ctx context.Context, headRoot [32]byte) error {
if err != nil {
return errors.Wrap(err, "could not retrieve head state in DB")
}
if headState == nil {
return errors.New("cannot save nil head state")
}
s.headLock.Lock()
defer s.headLock.Unlock()