Revert "Add Fast Copy of Trie" (#5228)

* Revert "new fixes (#5221)"

This reverts commit 4118fa5242.
This commit is contained in:
Nishant Das 2020-03-27 09:06:30 +08:00 committed by GitHub
parent 1a0a399bed
commit 33f6c22607
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 33 deletions

View File

@ -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") return errors.Wrap(err, "could not retrieve head state in DB")
} }
} else { } else {
s.initSyncStateLock.RLock() headState, err = s.beaconDB.State(ctx, r)
cachedHeadState, ok := s.initSyncState[r] if err != nil {
if ok { return errors.Wrap(err, "could not retrieve head state in DB")
headState = cachedHeadState
} }
s.initSyncStateLock.RUnlock()
if headState == nil { if headState == nil {
headState, err = s.beaconDB.State(ctx, r) s.initSyncStateLock.RLock()
if err != nil { cachedHeadState, ok := s.initSyncState[r]
return errors.Wrap(err, "could not retrieve head state in DB") if ok {
headState = cachedHeadState
} }
s.initSyncStateLock.RUnlock()
} }
} }
if headState == nil { if headState == nil {

View File

@ -229,7 +229,7 @@ func (s *Service) onBlockInitialSyncStateTransition(ctx context.Context, signed
} else { } else {
s.initSyncStateLock.Lock() s.initSyncStateLock.Lock()
defer s.initSyncStateLock.Unlock() defer s.initSyncStateLock.Unlock()
s.initSyncState[root] = postState.FastCopy() s.initSyncState[root] = postState.Copy()
s.filterBoundaryCandidates(ctx, root, postState) s.filterBoundaryCandidates(ctx, root, postState)
} }

View File

@ -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, 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 // verifyBlkDescendant validates input block root is a descendant of the

View File

@ -177,29 +177,6 @@ func (b *BeaconState) Copy() *BeaconState {
return dst 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 // HashTreeRoot of the beacon state retrieves the Merkle root of the trie
// representation of the beacon state based on the eth2 Simple Serialize specification. // representation of the beacon state based on the eth2 Simple Serialize specification.
func (b *BeaconState) HashTreeRoot(ctx context.Context) ([32]byte, error) { func (b *BeaconState) HashTreeRoot(ctx context.Context) ([32]byte, error) {