From 40a94e70a0676155cb691f9d1dee676cf444afb6 Mon Sep 17 00:00:00 2001 From: Hans Moog <3293976+hmoog@users.noreply.github.com> Date: Tue, 7 Nov 2023 01:29:58 +0100 Subject: [PATCH] Refactor: addressed review comments --- pkg/protocol/engine/eviction/state.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/pkg/protocol/engine/eviction/state.go b/pkg/protocol/engine/eviction/state.go index da83bff46..7c263e685 100644 --- a/pkg/protocol/engine/eviction/state.go +++ b/pkg/protocol/engine/eviction/state.go @@ -325,20 +325,18 @@ func (s *State) PopulateFromStorage(latestCommitmentSlot iotago.SlotIndex) { } func (s *State) Reset() { - rootBlocksToClear := make([]iotago.BlockID, 0) + s.evictionMutex.Lock() + defer s.evictionMutex.Unlock() + s.rootBlocks.ForEach(func(slot iotago.SlotIndex, storage *shrinkingmap.ShrinkingMap[iotago.BlockID, iotago.CommitmentID]) { if slot > s.lastEvictedSlot { storage.ForEach(func(blockID iotago.BlockID, commitmentID iotago.CommitmentID) bool { - rootBlocksToClear = append(rootBlocksToClear, blockID) + s.RemoveRootBlock(blockID) return true }) } }) - - for _, blockID := range rootBlocksToClear { - s.RemoveRootBlock(blockID) - } } // latestNonEmptySlot returns the latest slot that contains a rootblock.