Skip to content

Commit 7ec2f33

Browse files
committedMar 13, 2025·
remove from outstanding when found conflicting
1 parent b41f2a1 commit 7ec2f33

File tree

4 files changed

+42
-32
lines changed

4 files changed

+42
-32
lines changed
 

‎src/mempool/mempool.ts

+19-20
Original file line numberDiff line numberDiff line change
@@ -287,40 +287,39 @@ export class Mempool {
287287
})
288288

289289
if (conflicting) {
290-
const oldOp = conflicting.userOp
291-
const newOp = userOp
290+
const { userOpInfo, reason } = conflicting
291+
const conflictingUserOp = userOpInfo.userOp
292292

293293
const hasHigherPriorityFee =
294-
newOp.maxPriorityFeePerGas >=
295-
scaleBigIntByPercent(oldOp.maxPriorityFeePerGas, 110n)
294+
userOp.maxPriorityFeePerGas >=
295+
scaleBigIntByPercent(
296+
conflictingUserOp.maxPriorityFeePerGas,
297+
110n
298+
)
296299

297300
const hasHigherMaxFee =
298-
newOp.maxFeePerGas >=
299-
scaleBigIntByPercent(oldOp.maxFeePerGas, 110n)
301+
userOp.maxFeePerGas >=
302+
scaleBigIntByPercent(conflictingUserOp.maxFeePerGas, 110n)
300303

301304
const hasHigherFees = hasHigherPriorityFee && hasHigherMaxFee
302305

303306
if (!hasHigherFees) {
304-
const reason =
305-
conflicting.reason === "conflicting_deployment"
307+
const message =
308+
reason === "conflicting_deployment"
306309
? "AA10 sender already constructed: A conflicting userOperation with initCode for this sender is already in the mempool"
307310
: "AA25 invalid account nonce: User operation already present in mempool"
308311

309-
await this.store.addOutstanding(conflicting)
310-
return [false, `${reason}, bump the gas price by minimum 10%`]
311-
}
312-
313-
await this.store.removeOutstanding({
314-
entryPoint,
315-
userOpHash: getUserOperationHash(
316-
conflicting.userOp,
312+
// Re-add to outstanding as it wasn't replaced
313+
await this.store.addOutstanding({
317314
entryPoint,
318-
this.config.chainId
319-
)
320-
})
315+
userOpInfo: conflicting.userOpInfo
316+
})
317+
318+
return [false, `${message}, bump the gas price by minimum 10%`]
319+
}
321320

322321
await this.reputationManager.replaceUserOperationSeenStatus(
323-
oldOp,
322+
conflictingUserOp,
324323
entryPoint
325324
)
326325
}

‎src/store/createMemoryOutstandingStore.ts

+10-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
} from "../utils/userop"
66
import { AltoConfig } from "../createConfig"
77
import { HexData32, UserOpInfo, UserOperation } from "@alto/types"
8-
import { ConflictingType, OutstandingStore } from "."
8+
import { ConflictingOutstandingType, OutstandingStore } from "."
99
import { Logger } from "@alto/utils"
1010

1111
const senderNonceSlot = (userOp: UserOperation) => {
@@ -82,10 +82,12 @@ export class MemoryOutstanding implements OutstandingStore {
8282
return true
8383
}
8484

85-
async popConflicting(userOp: UserOperation): Promise<ConflictingType> {
85+
async popConflicting(
86+
userOp: UserOperation
87+
): Promise<ConflictingOutstandingType> {
8688
const outstandingOps = this.dump()
8789

88-
let conflictingReason: ConflictingType = undefined
90+
let conflictingReason: ConflictingOutstandingType = undefined
8991

9092
for (const userOpInfo of outstandingOps) {
9193
const { userOp: mempoolUserOp } = userOpInfo
@@ -95,7 +97,7 @@ export class MemoryOutstanding implements OutstandingStore {
9597
this.remove(userOpInfo.userOpHash)
9698
conflictingReason = {
9799
reason: "conflicting_nonce",
98-
userOp: userOpInfo.userOp
100+
userOpInfo
99101
}
100102
break
101103
}
@@ -125,7 +127,7 @@ export class MemoryOutstanding implements OutstandingStore {
125127
this.remove(userOpInfo.userOpHash)
126128
conflictingReason = {
127129
reason: "conflicting_deployment",
128-
userOp: userOpInfo.userOp
130+
userOpInfo
129131
}
130132
break
131133
}
@@ -305,7 +307,9 @@ export class MemoryOutstanding implements OutstandingStore {
305307
}
306308

307309
// Adding findConflicting method to maintain compatibility with Store interface
308-
async findConflicting(userOp: UserOperation): Promise<ConflictingType> {
310+
async findConflicting(
311+
userOp: UserOperation
312+
): Promise<ConflictingOutstandingType> {
309313
return this.popConflicting(userOp)
310314
}
311315
}

‎src/store/createRedisOutstandingStore.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ class RedisOutstandingQueue implements OutstandingStore {
237237
await this.remove(conflicting.userOpHash)
238238
return {
239239
reason: "conflicting_nonce" as const,
240-
userOp: conflicting.userOp
240+
userOpInfo: conflicting
241241
}
242242
}
243243

@@ -271,7 +271,7 @@ class RedisOutstandingQueue implements OutstandingStore {
271271
await this.remove(conflictingUserOp.userOpHash)
272272
return {
273273
reason: "conflicting_deployment" as const,
274-
userOp: conflictingUserOp.userOp
274+
userOpInfo: conflictingUserOp
275275
}
276276
}
277277
}

‎src/store/index.ts

+11-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,14 @@ import type {
1010
export type StoreType = "outstanding" | "processing" | "submitted"
1111
export type UserOpType = UserOpInfo | SubmittedUserOp
1212

13-
export type ConflictingType =
13+
export type ConflictingOutstandingType =
14+
| {
15+
reason: "conflicting_nonce" | "conflicting_deployment"
16+
userOpInfo: UserOpInfo
17+
}
18+
| undefined
19+
20+
export type ConflictingStoreType =
1421
| {
1522
reason: "conflicting_nonce" | "conflicting_deployment"
1623
userOp: UserOperation
@@ -70,7 +77,7 @@ export type MempoolStore = {
7077
popConflictingOustanding: (args: {
7178
entryPoint: Address
7279
userOp: UserOperation
73-
}) => Promise<ConflictingType>
80+
}) => Promise<ConflictingOutstandingType>
7481
validateSubmittedOrProcessing: (
7582
args: EntryPointUserOpParam
7683
) => Promise<ValidationResult>
@@ -95,13 +102,13 @@ export type BaseStore<T extends UserOpType = UserOpType> = {
95102
}
96103

97104
export type Store<T extends UserOpType> = BaseStore<T> & {
98-
findConflicting: (args: UserOperation) => Promise<ConflictingType>
105+
findConflicting: (args: UserOperation) => Promise<ConflictingStoreType>
99106
}
100107

101108
export type OutstandingStore = BaseStore<UserOpInfo> & {
102109
clear: () => Promise<void>
103110
// Will remove and return the first conflicting userOpInfo
104-
popConflicting: (args: UserOperation) => Promise<ConflictingType>
111+
popConflicting: (args: UserOperation) => Promise<ConflictingOutstandingType>
105112
validateQueuedLimit: (userOp: UserOperation) => boolean
106113
validateParallelLimit: (userOp: UserOperation) => boolean
107114
getQueuedUserOps: (userOp: UserOperation) => Promise<UserOperation[]>

0 commit comments

Comments
 (0)
Please sign in to comment.