@@ -27,21 +27,22 @@ func New(db *badger.DB) (*Mempool, error) {
27
27
return & Mempool {db , queue }, nil
28
28
}
29
29
30
- // GetOp checks if a UserOperation is in the mempool and returns it .
31
- func (m * Mempool ) GetOp (entryPoint common.Address , sender common.Address ) (* userop.UserOperation , error ) {
32
- op := m .queue .GetOp (entryPoint , sender )
33
- return op , nil
30
+ // GetOps returns all the UserOperations associated with an EntryPoint and Sender address .
31
+ func (m * Mempool ) GetOps (entryPoint common.Address , sender common.Address ) ([] * userop.UserOperation , error ) {
32
+ ops := m .queue .GetOps (entryPoint , sender )
33
+ return ops , nil
34
34
}
35
35
36
- // AddOp adds a UserOperation to the mempool.
36
+ // AddOp adds a UserOperation to the mempool or replace an existing one with the same EntryPoint, Sender, and
37
+ // Nonce values.
37
38
func (m * Mempool ) AddOp (entryPoint common.Address , op * userop.UserOperation ) error {
38
39
data , err := op .MarshalJSON ()
39
40
if err != nil {
40
41
return err
41
42
}
42
43
43
44
err = m .db .Update (func (txn * badger.Txn ) error {
44
- return txn .Set (getDBKey (entryPoint , op .Sender ), data )
45
+ return txn .Set (getUniqueKey (entryPoint , op .Sender , op . Nonce ), data )
45
46
})
46
47
if err != nil {
47
48
return err
@@ -51,16 +52,16 @@ func (m *Mempool) AddOp(entryPoint common.Address, op *userop.UserOperation) err
51
52
return nil
52
53
}
53
54
54
- // BundleOps builds a bundle of ops from the mempool to be sent to the EntryPoint.
55
+ // BundleOps builds a bundle of UserOperations from the mempool to be sent to the EntryPoint.
55
56
func (m * Mempool ) BundleOps (entryPoint common.Address ) ([]* userop.UserOperation , error ) {
56
57
return m .queue .Next (entryPoint ), nil
57
58
}
58
59
59
- // RemoveOps removes a list of UserOperations from the mempool by sender address .
60
- func (m * Mempool ) RemoveOps (entryPoint common.Address , senders ... common. Address ) error {
60
+ // RemoveOps removes a list of UserOperations from the mempool by EntryPoint, Sender, and Nonce values .
61
+ func (m * Mempool ) RemoveOps (entryPoint common.Address , ops ... * userop. UserOperation ) error {
61
62
err := m .db .Update (func (txn * badger.Txn ) error {
62
- for _ , s := range senders {
63
- err := txn .Delete (getDBKey (entryPoint , s ))
63
+ for _ , op := range ops {
64
+ err := txn .Delete (getUniqueKey (entryPoint , op . Sender , op . Nonce ))
64
65
if err != nil {
65
66
return err
66
67
}
@@ -72,6 +73,6 @@ func (m *Mempool) RemoveOps(entryPoint common.Address, senders ...common.Address
72
73
return err
73
74
}
74
75
75
- m .queue .RemoveOps (entryPoint , senders )
76
+ m .queue .RemoveOps (entryPoint , ops ... )
76
77
return nil
77
78
}
0 commit comments