From 33f6c22607c9d338ca2fb4e38666efe382504311 Mon Sep 17 00:00:00 2001 From: Nishant Das Date: Fri, 27 Mar 2020 09:06:30 +0800 Subject: [PATCH] Revert "Add Fast Copy of Trie" (#5228) * Revert "new fixes (#5221)" This reverts commit 4118fa52420eb104bdb10881379a3e99cec66571. --- beacon-chain/blockchain/head.go | 16 ++++++------- beacon-chain/blockchain/process_block.go | 2 +- .../blockchain/process_block_helpers.go | 2 +- beacon-chain/state/state_trie.go | 23 ------------------- 4 files changed, 10 insertions(+), 33 deletions(-) diff --git a/beacon-chain/blockchain/head.go b/beacon-chain/blockchain/head.go index 618e6f355af3..7c70d0616908 100644 --- a/beacon-chain/blockchain/head.go +++ b/beacon-chain/blockchain/head.go @@ -127,17 +127,17 @@ func (s *Service) saveHeadNoDB(ctx context.Context, b *ethpb.SignedBeaconBlock, return errors.Wrap(err, "could not retrieve head state in DB") } } else { - s.initSyncStateLock.RLock() - cachedHeadState, ok := s.initSyncState[r] - if ok { - headState = cachedHeadState + headState, err = s.beaconDB.State(ctx, r) + if err != nil { + return errors.Wrap(err, "could not retrieve head state in DB") } - s.initSyncStateLock.RUnlock() if headState == nil { - headState, err = s.beaconDB.State(ctx, r) - if err != nil { - return errors.Wrap(err, "could not retrieve head state in DB") + s.initSyncStateLock.RLock() + cachedHeadState, ok := s.initSyncState[r] + if ok { + headState = cachedHeadState } + s.initSyncStateLock.RUnlock() } } if headState == nil { diff --git a/beacon-chain/blockchain/process_block.go b/beacon-chain/blockchain/process_block.go index 60a1fa2e468b..313f406c20cf 100644 --- a/beacon-chain/blockchain/process_block.go +++ b/beacon-chain/blockchain/process_block.go @@ -229,7 +229,7 @@ func (s *Service) onBlockInitialSyncStateTransition(ctx context.Context, signed } else { s.initSyncStateLock.Lock() defer s.initSyncStateLock.Unlock() - s.initSyncState[root] = postState.FastCopy() + s.initSyncState[root] = postState.Copy() s.filterBoundaryCandidates(ctx, root, postState) } diff --git a/beacon-chain/blockchain/process_block_helpers.go b/beacon-chain/blockchain/process_block_helpers.go index 7d6e59a8dabe..9c9d211b425b 100644 --- a/beacon-chain/blockchain/process_block_helpers.go +++ b/beacon-chain/blockchain/process_block_helpers.go @@ -99,7 +99,7 @@ func (s *Service) verifyBlkPreState(ctx context.Context, b *ethpb.BeaconBlock) ( } return preState, nil // No copy needed from newly hydrated DB object. } - return preState.FastCopy(), nil + return preState.Copy(), nil } // verifyBlkDescendant validates input block root is a descendant of the diff --git a/beacon-chain/state/state_trie.go b/beacon-chain/state/state_trie.go index 0ad1f9c0ccae..a73587b7902e 100644 --- a/beacon-chain/state/state_trie.go +++ b/beacon-chain/state/state_trie.go @@ -177,29 +177,6 @@ func (b *BeaconState) Copy() *BeaconState { return dst } -// FastCopy is used to copy all the field trie contents and -// empty out the references to it in the source state. This -// is used when we have a state that we know will most -// likely not be used anytime in the future. -func (b *BeaconState) FastCopy() *BeaconState { - newState := b.Copy() - for fldIdx, fieldTrie := range b.stateFieldLeaves { - if fieldTrie.reference != nil { - fieldTrie.Lock() - fieldTrie.MinusRef() - fieldTrie.Unlock() - b.rebuildTrie[fldIdx] = true - b.dirtyFields[fldIdx] = true - b.stateFieldLeaves[fldIdx] = &FieldTrie{ - field: fldIdx, - reference: &reference{1}, - Mutex: new(sync.Mutex), - } - } - } - return newState -} - // HashTreeRoot of the beacon state retrieves the Merkle root of the trie // representation of the beacon state based on the eth2 Simple Serialize specification. func (b *BeaconState) HashTreeRoot(ctx context.Context) ([32]byte, error) {