Skip to content

Commit

Permalink
account for race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
mouseless0x committed Feb 16, 2025
1 parent b8d1503 commit daf8fdc
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/store/createRedisStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Logger, Metrics } from "@alto/utils"
import { AltoConfig } from "../createConfig"
import { Store, createMemoryStore } from "."
import { UserOpInfo, SubmittedUserOp } from "../types/mempool"
import { HexData32 } from "../types/schemas"
import { HexData32, userOperationSchema } from "../types/schemas"
import Queue, { type Queue as QueueType } from "bull"
import Redis from "ioredis"

Expand Down Expand Up @@ -84,7 +84,7 @@ const removeOutstanding = async ({
outstanding: QueueType<UserOpInfo>
}) => {
const jobs = await outstanding.getWaiting()
const job = jobs.find((job) => job.data.userOpHash === userOpHash)
const job = jobs.find((job) => job && job.data.userOpHash === userOpHash)

if (job) {
await job.remove()
Expand Down Expand Up @@ -125,7 +125,20 @@ const dumpOutstanding = async ({
"dumping mempool"
)

return awaitingJobs.map((job) => job.data)
return awaitingJobs
.map((job) => {
// job has already been removed from the queue.
if (!job) {
return undefined
}

return {
...job.data,
// userOp contains bigint fields, so we use zod to serialize/parse
userOp: userOperationSchema.parse(job.data.userOp)
}
})
.filter((op) => op !== undefined)
}

export const createRedisStore = ({
Expand Down

0 comments on commit daf8fdc

Please sign in to comment.