Skip to content

Commit

Permalink
Refactor: fixed deadlock
Browse files Browse the repository at this point in the history
  • Loading branch information
hmoog committed Nov 7, 2023
1 parent 6172363 commit 8db794c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 deletions.
10 changes: 5 additions & 5 deletions pkg/protocol/engine/eviction/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,15 +325,15 @@ func (s *State) PopulateFromStorage(latestCommitmentSlot iotago.SlotIndex) {
}

func (s *State) Reset() {
blocksToPrune := make([]iotago.BlockID, 0)
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 {
s.RemoveRootBlock(blockID)

return true
})
blocksToPrune = append(blocksToPrune, storage.Keys()...)
}
})

// we need to prune delayed because s.rootBlocks.ForEach and s.RemoveRootBlock both lock
lo.ForEach(blocksToPrune, s.RemoveRootBlock)
}

// latestNonEmptySlot returns the latest slot that contains a rootblock.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,7 @@ func (m *SlotMutations) Evict(index iotago.SlotIndex) error {

// Reset resets the component to a clean state as if it was created at the last commitment.
func (m *SlotMutations) Reset() {
slotsToReset := make([]iotago.SlotIndex, 0)
m.acceptedBlocksBySlot.ForEachKey(func(slot iotago.SlotIndex) bool {
if slot > m.latestCommittedIndex {
slotsToReset = append(slotsToReset, slot)
}

return true
})

for _, slot := range slotsToReset {
m.acceptedBlocksBySlot.Delete(slot)
}
m.acceptedBlocksBySlot.Clear()
}

// AcceptedBlocks returns the set of accepted blocks for the given slot.
Expand Down

0 comments on commit 8db794c

Please sign in to comment.