Skip to content
This repository has been archived by the owner on Jan 24, 2025. It is now read-only.

Commit

Permalink
Fix evictionMutex handling to avoid deadlock and lock correctly.
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrm50 committed Jan 17, 2024
1 parent b29b174 commit c662016
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions pkg/protocol/engine/mempool/v1/mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,13 @@ func (m *MemPool[VoteRank]) TransactionMetadataByAttachment(blockID iotago.Block

// StateDiff returns the state diff for the given slot.
func (m *MemPool[VoteRank]) StateDiff(slot iotago.SlotIndex) (mempool.StateDiff, error) {
m.evictionMutex.RLock()
defer m.evictionMutex.RUnlock()

return m.stateDiff(slot)
}

func (m *MemPool[VoteRank]) stateDiff(slot iotago.SlotIndex) (*StateDiff, error) {
m.evictionMutex.RLock()
defer m.evictionMutex.RUnlock()

if m.lastEvictedSlot >= slot {
return nil, ierrors.Errorf("slot %d is older than last evicted slot %d", slot, m.lastEvictedSlot)
}
Expand Down Expand Up @@ -470,6 +470,9 @@ func (m *MemPool[VoteRank]) setupTransaction(transaction *TransactionMetadata) {
transaction.OnAccepted(func() {
// Transactions can only become accepted if there is at least one attachment included.
if slot := transaction.EarliestIncludedAttachment().Slot(); slot != 0 {
m.evictionMutex.RLock()
defer m.evictionMutex.RUnlock()

stateDiff, err := m.stateDiff(slot)
if err != nil {
m.errorHandler(ierrors.Wrapf(err, "failed to get state diff for slot %d", slot))
Expand Down

0 comments on commit c662016

Please sign in to comment.