diff --git a/beacon-chain/blockchain/chain_info.go b/beacon-chain/blockchain/chain_info.go index 6fc1d8c1ba..af09118b37 100644 --- a/beacon-chain/blockchain/chain_info.go +++ b/beacon-chain/blockchain/chain_info.go @@ -22,12 +22,6 @@ type ChainInfoFetcher interface { FinalizationFetcher } -// ChainCleaner describes an interface to clean obsolete data -// stored in the blockchain service. -type ChainCleaner interface { - ClearCachedStates() -} - // TimeFetcher retrieves the Eth2 data that's related to time. type TimeFetcher interface { GenesisTime() time.Time diff --git a/beacon-chain/blockchain/service.go b/beacon-chain/blockchain/service.go index eeee325e68..e4bf027a13 100644 --- a/beacon-chain/blockchain/service.go +++ b/beacon-chain/blockchain/service.go @@ -269,12 +269,6 @@ func (s *Service) Status() error { return nil } -// ClearCachedStates removes all stored caches states. This is done after the node -// is synced. -func (s *Service) ClearCachedStates() { - s.initSyncState = map[[32]byte]*stateTrie.BeaconState{} -} - // This gets called to update canonical root mapping. func (s *Service) saveHead(ctx context.Context, signed *ethpb.SignedBeaconBlock, r [32]byte) error { s.headLock.Lock() diff --git a/beacon-chain/blockchain/testing/mock.go b/beacon-chain/blockchain/testing/mock.go index 8aec99b9c2..0ce7f9c44f 100644 --- a/beacon-chain/blockchain/testing/mock.go +++ b/beacon-chain/blockchain/testing/mock.go @@ -231,8 +231,3 @@ func (ms *ChainService) Participation(epoch uint64) *precompute.Balance { func (ms *ChainService) IsValidAttestation(ctx context.Context, att *ethpb.Attestation) bool { return ms.ValidAttestation } - -// ClearCachedStates is a no-op. -func (ms *ChainService) ClearCachedStates() { - // no-op -} diff --git a/beacon-chain/state/setters.go b/beacon-chain/state/setters.go index 2580134e2c..c0b9bada84 100644 --- a/beacon-chain/state/setters.go +++ b/beacon-chain/state/setters.go @@ -106,9 +106,7 @@ func (b *BeaconState) UpdateBlockRootAtIndex(idx uint64, blockRoot [32]byte) err r := b.state.BlockRoots if ref := b.sharedFieldReferences[blockRoots]; ref.refs > 1 { // Copy on write since this is a shared array. - newRoots := make([][]byte, len(r)) - copy(newRoots, r) - r = newRoots + r = b.BlockRoots() ref.refs-- b.sharedFieldReferences[blockRoots] = &reference{refs: 1} @@ -152,9 +150,7 @@ func (b *BeaconState) UpdateStateRootAtIndex(idx uint64, stateRoot [32]byte) err r := b.state.StateRoots if ref := b.sharedFieldReferences[stateRoots]; ref.refs > 1 { // Perform a copy since this is a shared reference and we don't want to mutate others. - newRoots := make([][]byte, len(r)) - copy(newRoots, r) - r = newRoots + r = b.StateRoots() ref.refs-- b.sharedFieldReferences[stateRoots] = &reference{refs: 1} @@ -293,9 +289,8 @@ func (b *BeaconState) UpdateValidatorAtIndex(idx uint64, val *ethpb.Validator) e v := b.state.Validators if ref := b.sharedFieldReferences[validators]; ref.refs > 1 { // Perform a copy since this is a shared reference and we don't want to mutate others. - newVals := make([]*ethpb.Validator, len(v)) - copy(newVals, v) - v = newVals + v = b.Validators() + ref.refs-- b.sharedFieldReferences[validators] = &reference{refs: 1} } @@ -386,9 +381,7 @@ func (b *BeaconState) UpdateRandaoMixesAtIndex(val []byte, idx uint64) error { b.lock.RLock() mixes := b.state.RandaoMixes if refs := b.sharedFieldReferences[randaoMixes].refs; refs > 1 { - newSlice := make([][]byte, len(mixes)) - copy(newSlice, mixes) - mixes = newSlice + mixes = b.RandaoMixes() b.sharedFieldReferences[randaoMixes].refs-- b.sharedFieldReferences[randaoMixes] = &reference{refs: 1} } diff --git a/beacon-chain/sync/initial-sync/service.go b/beacon-chain/sync/initial-sync/service.go index 07a6f8e115..122822ff89 100644 --- a/beacon-chain/sync/initial-sync/service.go +++ b/beacon-chain/sync/initial-sync/service.go @@ -25,7 +25,6 @@ var _ = shared.Service(&Service{}) type blockchainService interface { blockchain.BlockReceiver blockchain.HeadFetcher - blockchain.ChainCleaner } const ( @@ -130,7 +129,6 @@ func (s *Service) Start() { } log.Infof("Synced up to slot %d", s.chain.HeadSlot()) s.synced = true - s.chain.ClearCachedStates() } // Stop initial sync. @@ -169,7 +167,6 @@ func (s *Service) Resync() error { log = log.WithError(err) } log.WithField("slot", s.chain.HeadSlot()).Info("Resync attempt complete") - s.chain.ClearCachedStates() return nil }