From 1461a0a343809a244ca22d694f9d8c013c49a96c Mon Sep 17 00:00:00 2001 From: Quentin McGaw Date: Sat, 15 Jan 2022 11:45:04 +0000 Subject: [PATCH] Remove storage state syncing field --- dot/state/storage.go | 15 --------------- dot/state/storage_test.go | 16 ---------------- dot/sync/interface.go | 1 - 3 files changed, 32 deletions(-) diff --git a/dot/state/storage.go b/dot/state/storage.go index 5b71fa4592..f9f1328412 100644 --- a/dot/state/storage.go +++ b/dot/state/storage.go @@ -39,7 +39,6 @@ type StorageState struct { changedLock sync.RWMutex observerList []Observer pruner pruner.Pruner - syncing bool } // NewStorageState creates a new StorageState backed by the given trie and database located at basePath. @@ -78,11 +77,6 @@ func NewStorageState(db chaindb.Database, blockState *BlockState, }, nil } -// SetSyncing sets whether the node is currently syncing or not -func (s *StorageState) SetSyncing(syncing bool) { - s.syncing = syncing -} - func (s *StorageState) pruneKey(keyHeader *types.Header) { s.tries.Delete(keyHeader.StateRoot) } @@ -91,15 +85,6 @@ func (s *StorageState) pruneKey(keyHeader *types.Header) { func (s *StorageState) StoreTrie(ts *rtstorage.TrieState, header *types.Header) error { root := ts.MustRoot() - if s.syncing { - // keep only the trie at the head of the chain when syncing - // TODO: probably remove this when memory usage improves (#1494) - s.tries.Range(func(k, _ interface{}) bool { - s.tries.Delete(k) - return true - }) - } - _, _ = s.tries.LoadOrStore(root, ts.Trie()) if _, ok := s.pruner.(*pruner.FullNode); header == nil && ok { diff --git a/dot/state/storage_test.go b/dot/state/storage_test.go index 8e61eefd1d..7679329ad1 100644 --- a/dot/state/storage_test.go +++ b/dot/state/storage_test.go @@ -159,21 +159,6 @@ func syncMapLen(m *sync.Map) int { return l } -func TestStorage_StoreTrie_Syncing(t *testing.T) { - storage := newTestStorageState(t) - ts, err := storage.TrieState(&trie.EmptyHash) - require.NoError(t, err) - - key := []byte("testkey") - value := []byte("testvalue") - ts.Set(key, value) - - storage.SetSyncing(true) - err = storage.StoreTrie(ts, nil) - require.NoError(t, err) - require.Equal(t, 1, syncMapLen(storage.tries)) -} - func TestStorage_StoreTrie_NotSyncing(t *testing.T) { storage := newTestStorageState(t) ts, err := storage.TrieState(&trie.EmptyHash) @@ -183,7 +168,6 @@ func TestStorage_StoreTrie_NotSyncing(t *testing.T) { value := []byte("testvalue") ts.Set(key, value) - storage.SetSyncing(false) err = storage.StoreTrie(ts, nil) require.NoError(t, err) require.Equal(t, 2, syncMapLen(storage.tries)) diff --git a/dot/sync/interface.go b/dot/sync/interface.go index 7d22b6a812..79bff4e5bb 100644 --- a/dot/sync/interface.go +++ b/dot/sync/interface.go @@ -53,7 +53,6 @@ type BlockState interface { type StorageState interface { TrieState(root *common.Hash) (*rtstorage.TrieState, error) LoadCodeHash(*common.Hash) (common.Hash, error) - SetSyncing(bool) sync.Locker }