mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 23:48:06 -05:00
Copy All Field Tries For Late Blocks (#12461)
* add new thing * only have it for late blocks * comments * change to lock * add test * Update beacon-chain/state/state-native/state_test.go --------- Co-authored-by: Radosław Kapka <rkapka@wp.pl>
This commit is contained in:
@@ -840,6 +840,26 @@ func (b *BeaconState) rootSelector(ctx context.Context, field types.FieldIndex)
|
||||
return [32]byte{}, errors.New("invalid field index provided")
|
||||
}
|
||||
|
||||
// CopyAllTries copies our field tries from the state. This is used to
|
||||
// remove shared field tries which have references to other states and
|
||||
// only have this copied set referencing to the current state.
|
||||
func (b *BeaconState) CopyAllTries() {
|
||||
b.lock.Lock()
|
||||
defer b.lock.Unlock()
|
||||
|
||||
for fldIdx, fieldTrie := range b.stateFieldLeaves {
|
||||
if fieldTrie.FieldReference() != nil {
|
||||
fieldTrie.Lock()
|
||||
if fieldTrie.FieldReference().Refs() > 1 {
|
||||
fieldTrie.FieldReference().MinusRef()
|
||||
newTrie := fieldTrie.CopyTrie()
|
||||
b.stateFieldLeaves[fldIdx] = newTrie
|
||||
}
|
||||
fieldTrie.Unlock()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (b *BeaconState) recomputeFieldTrie(index types.FieldIndex, elements interface{}) ([32]byte, error) {
|
||||
fTrie := b.stateFieldLeaves[index]
|
||||
fTrieMutex := fTrie.RWMutex
|
||||
|
||||
Reference in New Issue
Block a user