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:
Nishant Das
2023-05-30 17:57:20 +08:00
committed by GitHub
parent 8aa688729d
commit 70152bf476
4 changed files with 115 additions and 35 deletions

View File

@@ -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