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

Commit 01a01ab

Browse files
authored
Fix race condition in mempool (#163)
1 parent 226b98f commit 01a01ab

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

pkg/mempool/queue.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package mempool
22

33
import (
4+
"sync"
45
"sync/atomic"
56

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

3334
func (q *userOpQueues) getEntryPointSet(entryPoint common.Address) *set {
34-
if _, ok := q.setsByEntryPoint[entryPoint]; !ok {
35-
q.setsByEntryPoint[entryPoint] = &set{
35+
val, ok := q.setsByEntryPoint.Load(entryPoint)
36+
if !ok {
37+
val = &set{
3638
all: sortedset.New(),
3739
arrival: sortedset.New(),
3840
senders: make(map[common.Address]*sortedset.SortedSet),
3941
}
42+
q.setsByEntryPoint.Store(entryPoint, val)
4043
}
4144

42-
return q.setsByEntryPoint[entryPoint]
45+
return val.(*set)
4346
}
4447

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

111114
func newUserOpQueue() *userOpQueues {
112115
return &userOpQueues{
113-
maxBatchSize: defaultMaxBatchSize,
114-
setsByEntryPoint: make(map[common.Address]*set),
116+
maxBatchSize: defaultMaxBatchSize,
115117
}
116118
}

0 commit comments

Comments
 (0)