Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions epochStart/bootstrap/disabled/disabledAccountsAdapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ func (a *accountsAdapter) RecreateTrieIfNeeded(_ common.RootHashHolder) error {
func (a *accountsAdapter) CancelPrune(_ []byte, _ state.TriePruningIdentifier) {
}

// ResetPruning -
func (a *accountsAdapter) ResetPruning() {
}

// SnapshotState -
func (a *accountsAdapter) SnapshotState(_ []byte, _ uint32) {
}
Expand Down
4 changes: 4 additions & 0 deletions process/transactionEvaluator/simulationAccountsDB.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ func (r *simulationAccountsDB) PruneTrie(_ []byte, _ state.TriePruningIdentifier
func (r *simulationAccountsDB) CancelPrune(_ []byte, _ state.TriePruningIdentifier) {
}

// ResetPruning won't do anything as write operations are disabled on this component
func (r *simulationAccountsDB) ResetPruning() {
}

// SnapshotState won't do anything as write operations are disabled on this component
func (r *simulationAccountsDB) SnapshotState(_ []byte, _ uint32) {
}
Expand Down
8 changes: 8 additions & 0 deletions state/accountsDB.go
Original file line number Diff line number Diff line change
Expand Up @@ -1230,6 +1230,14 @@ func (adb *AccountsDB) CancelPrune(rootHash []byte, identifier TriePruningIdenti
adb.storagePruningManager.CancelPrune(rootHash, identifier, adb.mainTrie.GetStorageManager())
}

// ResetPruning will reset all collected data needed for pruning
func (adb *AccountsDB) ResetPruning() {
adb.mutOp.Lock()
defer adb.mutOp.Unlock()

adb.storagePruningManager.Reset()
}

// SnapshotState triggers the snapshotting process of the state trie
func (adb *AccountsDB) SnapshotState(rootHash []byte, epoch uint32) {
adb.snapshotsManger.SnapshotState(rootHash, epoch, adb.getMainTrie().GetStorageManager())
Expand Down
4 changes: 4 additions & 0 deletions state/accountsDBApi.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ func (accountsDB *accountsDBApi) PruneTrie(_ []byte, _ TriePruningIdentifier, _
func (accountsDB *accountsDBApi) CancelPrune(_ []byte, _ TriePruningIdentifier) {
}

// ResetPruning is a not permitted operation in this implementation and thus, does nothing
func (accountsDB *accountsDBApi) ResetPruning() {
}

// SnapshotState is a not permitted operation in this implementation and thus, does nothing
func (accountsDB *accountsDBApi) SnapshotState(_ []byte, _ uint32) {
}
Expand Down
4 changes: 4 additions & 0 deletions state/accountsDBApiWithHistory.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ func (accountsDB *accountsDBApiWithHistory) PruneTrie(_ []byte, _ TriePruningIde
func (accountsDB *accountsDBApiWithHistory) CancelPrune(_ []byte, _ TriePruningIdentifier) {
}

// ResetPruning is a not permitted operation in this implementation and thus, does nothing
func (accountsDB *accountsDBApiWithHistory) ResetPruning() {
}

// SnapshotState is a not permitted operation in this implementation and thus, does nothing
func (accountsDB *accountsDBApiWithHistory) SnapshotState(_ []byte, _ uint32) {
}
Expand Down
3 changes: 3 additions & 0 deletions state/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ type AccountsAdapter interface {
RecreateTrieIfNeeded(options common.RootHashHolder) error
PruneTrie(rootHash []byte, identifier TriePruningIdentifier, handler PruningHandler)
CancelPrune(rootHash []byte, identifier TriePruningIdentifier)
ResetPruning()
SnapshotState(rootHash []byte, epoch uint32)
IsPruningEnabled() bool
GetAllLeaves(leavesChannels *common.TrieIteratorChannels, ctx context.Context, rootHash []byte, trieLeafParser common.TrieLeafParser) error
Expand Down Expand Up @@ -178,6 +179,7 @@ type DBRemoveCacher interface {
Put([]byte, common.ModifiedHashes) error
Evict([]byte) (common.ModifiedHashes, error)
ShouldKeepHash(hash string, identifier TriePruningIdentifier) (bool, error)
Reset()
IsInterfaceNil() bool
Close() error
}
Expand All @@ -194,6 +196,7 @@ type StoragePruningManager interface {
MarkForEviction([]byte, []byte, common.ModifiedHashes, common.ModifiedHashes) error
PruneTrie(rootHash []byte, identifier TriePruningIdentifier, tsm common.StorageManager, handler PruningHandler)
CancelPrune(rootHash []byte, identifier TriePruningIdentifier, tsm common.StorageManager)
Reset()
Close() error
IsInterfaceNil() bool
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ func (i *disabledStoragePruningManager) PruneTrie(_ []byte, _ state.TriePruningI
func (i *disabledStoragePruningManager) CancelPrune(_ []byte, _ state.TriePruningIdentifier, _ common.StorageManager) {
}

// Reset does nothing for this implementation
func (i *disabledStoragePruningManager) Reset() {}

// Close does nothing for this implementation
func (i *disabledStoragePruningManager) Close() error {
return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,19 @@ func (mewl *memoryEvictionWaitingList) ShouldKeepHash(hash string, identifier st
return false, nil
}

// Reset will reinitialize the eviction waiting list, by emptying the cache and reversed cache. It will not change the sizes of the caches.
func (mewl *memoryEvictionWaitingList) Reset() {
mewl.opMutex.Lock()

for key := range mewl.cache {
log.Debug("trie nodes eviction waiting list reset", "rootHash", []byte(key))
}

mewl.cache = make(map[string]*rootHashData)
mewl.reversedCache = make(map[string]*hashInfo)
mewl.opMutex.Unlock()
}

// Close returns nil
func (mewl *memoryEvictionWaitingList) Close() error {
return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,3 +359,18 @@ func TestMemoryEvictionWaitingList_RemoveFromInversedCache(t *testing.T) {
assert.Nil(t, info)
assert.False(t, exists)
}

func TestMemoryEvictionWaitingList_Reset(t *testing.T) {
t.Parallel()

mewl, _ := NewMemoryEvictionWaitingList(getDefaultArgsForMemoryEvictionWaitingList())

_ = mewl.Put([]byte("root1"), common.ModifiedHashes{"hash1": {}, "hash2": {}})
_ = mewl.Put([]byte("root2"), common.ModifiedHashes{"hash3": {}, "hash4": {}})

assert.Equal(t, 2, len(mewl.cache))
assert.Equal(t, 4, len(mewl.reversedCache))
mewl.Reset()
assert.Equal(t, 0, len(mewl.cache))
assert.Equal(t, 0, len(mewl.reversedCache))
}
8 changes: 8 additions & 0 deletions state/storagePruningManager/storagePruningManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,14 @@ func (spm *storagePruningManager) removeFromDb(
return nil
}

func (spm *storagePruningManager) Reset() {
bufferedHashes := spm.pruningBuffer.RemoveAll()
for _, hash := range bufferedHashes {
log.Trace("trie storage manager reset", "hash", hash)
}
spm.dbEvictionWaitingList.Reset()
}

// Close will handle the closing of the underlying components
func (spm *storagePruningManager) Close() error {
return spm.dbEvictionWaitingList.Close()
Expand Down
34 changes: 34 additions & 0 deletions state/storagePruningManager/storagePruningManager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,3 +260,37 @@ func TestStoragePruningManager_MarkForEviction_removeDuplicatedKeys(t *testing.T
_, ok = map2["hash4"]
assert.False(t, ok)
}

func TestStoragePruningManager_Reset(t *testing.T) {
t.Parallel()

args := storage.GetStorageManagerArgs()
trieStorage, _ := trie.NewTrieStorageManager(args)
ewlArgs := evictionWaitingList.MemoryEvictionWaitingListArgs{
RootHashesSize: 100,
HashesSize: 10000,
}
ewl, _ := evictionWaitingList.NewMemoryEvictionWaitingList(ewlArgs)
spm, _ := NewStoragePruningManager(ewl, 1000)

err := spm.MarkForEviction([]byte("rootHash"), []byte("newRootHash"), map[string]struct{}{"hash1": {}, "hash2": {}}, map[string]struct{}{"hash3": {}, "hash4": {}})
assert.Nil(t, err)
err = spm.markForEviction([]byte("rootHash2"), map[string]struct{}{"hash5": {}, "hash6": {}}, state.NewRoot)
assert.Nil(t, err)

trieStorage.EnterPruningBufferingMode()
spm.PruneTrie([]byte("rootHash"), state.OldRoot, trieStorage, state.NewPruningHandler(state.EnableDataRemoval))
spm.CancelPrune([]byte("newRootHash"), state.NewRoot, trieStorage)
trieStorage.ExitPruningBufferingMode()

assert.Equal(t, 2, spm.pruningBuffer.Len())

spm.Reset()
assert.Equal(t, 0, spm.pruningBuffer.Len())

// rootHash2 should not be added to the pruning buffer because ewl was also reset when spm.Reset() was called
trieStorage.EnterPruningBufferingMode()
spm.PruneTrie([]byte("rootHash2"), state.NewRoot, trieStorage, state.NewPruningHandler(state.EnableDataRemoval))
trieStorage.ExitPruningBufferingMode()
assert.Equal(t, 0, spm.pruningBuffer.Len())
}
8 changes: 8 additions & 0 deletions testscommon/state/accountsAdapterStub.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type AccountsStub struct {
RecreateTrieIfNeededCalled func(options common.RootHashHolder) error
PruneTrieCalled func(rootHash []byte, identifier state.TriePruningIdentifier, handler state.PruningHandler)
CancelPruneCalled func(rootHash []byte, identifier state.TriePruningIdentifier)
ResetPruningCalled func()
SnapshotStateCalled func(rootHash []byte, epoch uint32)
IsPruningEnabledCalled func() bool
GetAllLeavesCalled func(leavesChannels *common.TrieIteratorChannels, ctx context.Context, rootHash []byte, trieLeafParser common.TrieLeafParser) error
Expand Down Expand Up @@ -208,6 +209,13 @@ func (as *AccountsStub) CancelPrune(rootHash []byte, identifier state.TriePrunin
}
}

// ResetPruning -
func (as *AccountsStub) ResetPruning() {
if as.ResetPruningCalled != nil {
as.ResetPruningCalled()
}
}

// SnapshotState -
func (as *AccountsStub) SnapshotState(rootHash []byte, epoch uint32) {
if as.SnapshotStateCalled != nil {
Expand Down
7 changes: 7 additions & 0 deletions testscommon/state/evictionWaitingListMock.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ func (ewl *EvictionWaitingListMock) ShouldKeepHash(hash string, identifier state
return false, nil
}

// Reset will reinitialize the cache
func (ewl *EvictionWaitingListMock) Reset() {
ewl.OpMutex.Lock()
ewl.Cache = make(map[string]common.ModifiedHashes)
ewl.OpMutex.Unlock()
}

// Close -
func (ewl *EvictionWaitingListMock) Close() error {
return nil
Expand Down
8 changes: 8 additions & 0 deletions testscommon/state/storagePruningManagerStub.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type StoragePruningManagerStub struct {
MarkForEvictionCalled func(bytes []byte, bytes2 []byte, hashes common.ModifiedHashes, hashes2 common.ModifiedHashes) error
PruneTrieCalled func(rootHash []byte, identifier state.TriePruningIdentifier, tsm common.StorageManager, handler state.PruningHandler)
CancelPruneCalled func(rootHash []byte, identifier state.TriePruningIdentifier, tsm common.StorageManager)
ResetCalled func()
CloseCalled func() error
}

Expand All @@ -36,6 +37,13 @@ func (stub *StoragePruningManagerStub) CancelPrune(rootHash []byte, identifier s
}
}

// Reset -
func (stub *StoragePruningManagerStub) Reset() {
if stub.ResetCalled != nil {
stub.ResetCalled()
}
}

// Close -
func (stub *StoragePruningManagerStub) Close() error {
if stub.CloseCalled != nil {
Expand Down
Loading