Copy head state to ensure it is never mutated (#4715)

* Copy head state to ensure it is never mutated
* Merge refs/heads/master into copy-head-state
* fix tests
* Merge branch 'copy-head-state' of github.com:prysmaticlabs/prysm into copy-head-state
This commit is contained in:
Preston Van Loon 2020-02-01 19:19:51 -08:00 committed by GitHub
parent d6bd389d5c
commit 4f38333e54
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 3 additions and 3 deletions

View File

@ -158,7 +158,7 @@ func (s *Service) HeadState(ctx context.Context) (*state.BeaconState, error) {
return s.beaconDB.HeadState(ctx)
}
return s.headState, nil
return s.headState.Copy(), nil
}
// HeadValidatorsIndices returns a list of active validator indices from the head view of a given epoch.

View File

@ -164,7 +164,7 @@ func TestHeadState_CanRetrieve(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(s, headState) {
if !reflect.DeepEqual(s.InnerStateUnsafe(), headState.InnerStateUnsafe()) {
t.Error("incorrect head state received")
}
}

View File

@ -342,7 +342,7 @@ func TestChainService_InitializeChainInfo(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(s, headState) {
if !reflect.DeepEqual(s.InnerStateUnsafe(), headState.InnerStateUnsafe()) {
t.Error("head state incorrect")
}
if headBlock.Block.Slot != c.HeadSlot() {