From 03cc4b8f6453f16a81efb649ede93480b772361e Mon Sep 17 00:00:00 2001 From: Hans Moog <3293976+hmoog@users.noreply.github.com> Date: Tue, 7 Nov 2023 16:00:23 +0100 Subject: [PATCH 1/2] Refactor: fix race condition by not overwriting the properties --- pkg/protocol/engine/tipmanager/v1/tipmanager.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/protocol/engine/tipmanager/v1/tipmanager.go b/pkg/protocol/engine/tipmanager/v1/tipmanager.go index c6bb685c6..6ba8b6e6f 100644 --- a/pkg/protocol/engine/tipmanager/v1/tipmanager.go +++ b/pkg/protocol/engine/tipmanager/v1/tipmanager.go @@ -108,9 +108,9 @@ func (t *TipManager) Reset() { t.evictionMutex.Lock() defer t.evictionMutex.Unlock() - t.tipMetadataStorage = shrinkingmap.New[iotago.SlotIndex, *shrinkingmap.ShrinkingMap[iotago.BlockID, *TipMetadata]]() - t.strongTipSet = randommap.New[iotago.BlockID, *TipMetadata]() - t.weakTipSet = randommap.New[iotago.BlockID, *TipMetadata]() + t.tipMetadataStorage.Clear() + lo.ForEach(t.strongTipSet.Keys(), func(id iotago.BlockID) { t.strongTipSet.Delete(id) }) + lo.ForEach(t.weakTipSet.Keys(), func(id iotago.BlockID) { t.strongTipSet.Delete(id) }) } // Shutdown marks the TipManager as shutdown. From b3c7bf192126f5cdb5863d7b1ab7cb29c861a813 Mon Sep 17 00:00:00 2001 From: Hans Moog <3293976+hmoog@users.noreply.github.com> Date: Tue, 7 Nov 2023 16:17:25 +0100 Subject: [PATCH 2/2] Refactor: reverted changes --- pkg/protocol/engine/tipmanager/v1/tipmanager.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pkg/protocol/engine/tipmanager/v1/tipmanager.go b/pkg/protocol/engine/tipmanager/v1/tipmanager.go index 6ba8b6e6f..dd223783e 100644 --- a/pkg/protocol/engine/tipmanager/v1/tipmanager.go +++ b/pkg/protocol/engine/tipmanager/v1/tipmanager.go @@ -44,11 +44,13 @@ type TipManager struct { // New creates a new TipManager. func New(blockRetriever func(blockID iotago.BlockID) (block *blocks.Block, exists bool)) *TipManager { t := &TipManager{ - retrieveBlock: blockRetriever, - blockAdded: event.New1[tipmanager.TipMetadata](), + retrieveBlock: blockRetriever, + tipMetadataStorage: shrinkingmap.New[iotago.SlotIndex, *shrinkingmap.ShrinkingMap[iotago.BlockID, *TipMetadata]](), + strongTipSet: randommap.New[iotago.BlockID, *TipMetadata](), + weakTipSet: randommap.New[iotago.BlockID, *TipMetadata](), + blockAdded: event.New1[tipmanager.TipMetadata](), } - t.Reset() t.TriggerConstructed() t.TriggerInitialized()