Skip to content

Commit

Permalink
Merge branch 'feat/cache-reset' of github.com:iotaledger/iota-core in…
Browse files Browse the repository at this point in the history
…to feat/reactive-chainmanager
  • Loading branch information
hmoog committed Nov 7, 2023
2 parents df283fb + b3c7bf1 commit 551007a
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions pkg/protocol/engine/tipmanager/v1/tipmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -108,9 +110,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.
Expand Down

0 comments on commit 551007a

Please sign in to comment.