Skip to content

Commit

Permalink
Don't save nil head state (#4799)
Browse files Browse the repository at this point in the history
* Don't save nil head state
* Update head
  • Loading branch information
terencechain committed Feb 9, 2020
1 parent 70cb06d commit 16a0c9f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
7 changes: 6 additions & 1 deletion beacon-chain/blockchain/chain_info.go
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions beacon-chain/blockchain/head.go
Expand Up @@ -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()
Expand Down

0 comments on commit 16a0c9f

Please sign in to comment.