diff --git a/beacon-chain/state/fieldtrie/field_trie.go b/beacon-chain/state/fieldtrie/field_trie.go index c97f85970..0cbfd7f5b 100644 --- a/beacon-chain/state/fieldtrie/field_trie.go +++ b/beacon-chain/state/fieldtrie/field_trie.go @@ -185,13 +185,14 @@ func (f *FieldTrie) CopyTrie() *FieldTrie { copy(dstFieldTrie[i], layer) } return &FieldTrie{ - fieldLayers: dstFieldTrie, - field: f.field, - dataType: f.dataType, - reference: stateutil.NewRef(1), - RWMutex: new(sync.RWMutex), - length: f.length, - numOfElems: f.numOfElems, + fieldLayers: dstFieldTrie, + field: f.field, + dataType: f.dataType, + reference: stateutil.NewRef(1), + RWMutex: new(sync.RWMutex), + length: f.length, + numOfElems: f.numOfElems, + isTransferred: f.isTransferred, } } diff --git a/beacon-chain/state/state-native/state_trie.go b/beacon-chain/state/state-native/state_trie.go index 9b064b470..03ec6d770 100644 --- a/beacon-chain/state/state-native/state_trie.go +++ b/beacon-chain/state/state-native/state_trie.go @@ -1158,8 +1158,16 @@ func (b *BeaconState) recomputeFieldTrie(index types.FieldIndex, elements interf } if fTrie.FieldReference().Refs() > 1 { + var newTrie *fieldtrie.FieldTrie + // We choose to only copy the validator + // trie as it is pretty expensive to regenerate + // in the event of late blocks. + if index == types.Validators { + newTrie = fTrie.CopyTrie() + } else { + newTrie = fTrie.TransferTrie() + } fTrie.FieldReference().MinusRef() - newTrie := fTrie.TransferTrie() b.stateFieldLeaves[index] = newTrie fTrie = newTrie }