add changes (#13661)

This commit is contained in:
Nishant Das 2024-02-26 21:45:17 +08:00 committed by GitHub
parent 5735379963
commit ddb321e0ce
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 8 deletions

View File

@ -185,13 +185,14 @@ func (f *FieldTrie) CopyTrie() *FieldTrie {
copy(dstFieldTrie[i], layer) copy(dstFieldTrie[i], layer)
} }
return &FieldTrie{ return &FieldTrie{
fieldLayers: dstFieldTrie, fieldLayers: dstFieldTrie,
field: f.field, field: f.field,
dataType: f.dataType, dataType: f.dataType,
reference: stateutil.NewRef(1), reference: stateutil.NewRef(1),
RWMutex: new(sync.RWMutex), RWMutex: new(sync.RWMutex),
length: f.length, length: f.length,
numOfElems: f.numOfElems, numOfElems: f.numOfElems,
isTransferred: f.isTransferred,
} }
} }

View File

@ -1158,8 +1158,16 @@ func (b *BeaconState) recomputeFieldTrie(index types.FieldIndex, elements interf
} }
if fTrie.FieldReference().Refs() > 1 { 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() fTrie.FieldReference().MinusRef()
newTrie := fTrie.TransferTrie()
b.stateFieldLeaves[index] = newTrie b.stateFieldLeaves[index] = newTrie
fTrie = newTrie fTrie = newTrie
} }