From ddb321e0ce2736455ec38ac8be365f007851ef4b Mon Sep 17 00:00:00 2001 From: Nishant Das Date: Mon, 26 Feb 2024 21:45:17 +0800 Subject: [PATCH] add changes (#13661) --- beacon-chain/state/fieldtrie/field_trie.go | 15 ++++++++------- beacon-chain/state/state-native/state_trie.go | 10 +++++++++- 2 files changed, 17 insertions(+), 8 deletions(-) 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 }