mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 12:57:18 +00:00
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:
parent
d6bd389d5c
commit
4f38333e54
@ -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.
|
||||
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
@ -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() {
|
||||
|
Loading…
Reference in New Issue
Block a user