Skip to content

Commit

Permalink
Ensure all fields are dirty on initialization (#4735)
Browse files Browse the repository at this point in the history
  • Loading branch information
prestonvanloon committed Feb 4, 2020
1 parent e63119b commit ce0b55d
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions beacon-chain/state/types.go
Expand Up @@ -44,6 +44,11 @@ func InitializeFromProtoUnsafe(st *pbp2p.BeaconState) (*BeaconState, error) {
dirtyFields: make(map[fieldIndex]interface{}, 20),
valIdxMap: coreutils.ValidatorIndexMap(st.Validators),
}

for i := 0; i < 20; i++ {
b.dirtyFields[fieldIndex(i)] = true
}

return b, nil
}

Expand Down Expand Up @@ -94,12 +99,14 @@ func (b *BeaconState) Copy() *BeaconState {
dst.dirtyFields[i] = true
}

dst.merkleLayers = make([][][]byte, len(b.merkleLayers))
for i, layer := range b.merkleLayers {
dst.merkleLayers[i] = make([][]byte, len(layer))
for j, content := range layer {
dst.merkleLayers[i][j] = make([]byte, len(content))
copy(dst.merkleLayers[i][j], content)
if b.merkleLayers != nil {
dst.merkleLayers = make([][][]byte, len(b.merkleLayers))
for i, layer := range b.merkleLayers {
dst.merkleLayers[i] = make([][]byte, len(layer))
for j, content := range layer {
dst.merkleLayers[i][j] = make([]byte, len(content))
copy(dst.merkleLayers[i][j], content)
}
}
}

Expand Down

0 comments on commit ce0b55d

Please sign in to comment.