From daf8fdccfe2cec503f7ce70835d72e0befdf3df8 Mon Sep 17 00:00:00 2001 From: mouseless <97399882+mouseless-eth@users.noreply.github.com> Date: Sun, 16 Feb 2025 23:38:43 +0000 Subject: [PATCH] account for race condition --- src/store/createRedisStore.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/store/createRedisStore.ts b/src/store/createRedisStore.ts index c7cf829d..8c198c3d 100644 --- a/src/store/createRedisStore.ts +++ b/src/store/createRedisStore.ts @@ -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" @@ -84,7 +84,7 @@ const removeOutstanding = async ({ outstanding: QueueType }) => { 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() @@ -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 = ({