Skip to content
This repository has been archived by the owner on Oct 20, 2024. It is now read-only.

Commit

Permalink
Fix race condition in mempool (#163)
Browse files Browse the repository at this point in the history
  • Loading branch information
hazim-j authored May 1, 2023
1 parent 226b98f commit 01a01ab
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions pkg/mempool/queue.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package mempool

import (
"sync"
"sync/atomic"

"github.com/ethereum/go-ethereum/common"
Expand All @@ -27,19 +28,21 @@ func (s *set) getSenderSortedSet(sender common.Address) *sortedset.SortedSet {
type userOpQueues struct {
maxBatchSize int
opCount uint64
setsByEntryPoint map[common.Address]*set
setsByEntryPoint sync.Map
}

func (q *userOpQueues) getEntryPointSet(entryPoint common.Address) *set {
if _, ok := q.setsByEntryPoint[entryPoint]; !ok {
q.setsByEntryPoint[entryPoint] = &set{
val, ok := q.setsByEntryPoint.Load(entryPoint)
if !ok {
val = &set{
all: sortedset.New(),
arrival: sortedset.New(),
senders: make(map[common.Address]*sortedset.SortedSet),
}
q.setsByEntryPoint.Store(entryPoint, val)
}

return q.setsByEntryPoint[entryPoint]
return val.(*set)
}

func (q *userOpQueues) AddOp(entryPoint common.Address, op *userop.UserOperation) {
Expand Down Expand Up @@ -110,7 +113,6 @@ func (q *userOpQueues) RemoveOps(entryPoint common.Address, ops ...*userop.UserO

func newUserOpQueue() *userOpQueues {
return &userOpQueues{
maxBatchSize: defaultMaxBatchSize,
setsByEntryPoint: make(map[common.Address]*set),
maxBatchSize: defaultMaxBatchSize,
}
}

0 comments on commit 01a01ab

Please sign in to comment.