Skip to content

Commit 1915c53

Browse files
authored
feat: add experimental retry for prepareUserOp errors in transaction processing (#916)
Introduced a new environment variable EXPERIMENTAL__RETRY_PREPARE_USEROP_ERRORS to enable retrying on prepareUserOp errors instead of failing the transaction immediately. Updated transaction handling logic to support this feature.
1 parent de9c9df commit 1915c53

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

src/shared/utils/env.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ export const env = createEnv({
115115
.number()
116116
.gt(0.0, "scaling factor must be greater than 0")
117117
.default(1.0),
118+
// Retry prepareUserOp errors instead of immediately failing the transaction
119+
EXPERIMENTAL__RETRY_PREPARE_USEROP_ERRORS: boolEnvSchema(false),
118120
},
119121
clientPrefix: "NEVER_USED",
120122
client: {},
@@ -169,6 +171,8 @@ export const env = createEnv({
169171
process.env.EXPERIMENTAL__MINE_WORKER_MAX_POLL_INTERVAL_SECONDS,
170172
EXPERIMENTAL__MINE_WORKER_POLL_INTERVAL_SCALING_FACTOR:
171173
process.env.EXPERIMENTAL__MINE_WORKER_POLL_INTERVAL_SCALING_FACTOR,
174+
EXPERIMENTAL__RETRY_PREPARE_USEROP_ERRORS:
175+
process.env.EXPERIMENTAL__RETRY_PREPARE_USEROP_ERRORS,
172176
SEND_WEBHOOK_QUEUE_CONCURRENCY: process.env.SEND_WEBHOOK_QUEUE_CONCURRENCY,
173177
},
174178
onValidationError: (error: ZodError) => {

src/worker/tasks/send-transaction-worker.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,12 +295,19 @@ const _sendUserOp = async (
295295
});
296296
} catch (error) {
297297
const errorMessage = wrapError(error, "Bundler").message;
298+
job.log(`Failed to populate transaction: ${errorMessage}`);
299+
300+
// If retry is enabled for prepareUserOp errors, throw to trigger job retry
301+
if (env.EXPERIMENTAL__RETRY_PREPARE_USEROP_ERRORS) {
302+
throw error;
303+
}
304+
305+
// Otherwise, return errored transaction as before
298306
const erroredTransaction: ErroredTransaction = {
299307
...queuedTransaction,
300308
status: "errored",
301309
errorMessage,
302310
};
303-
job.log(`Failed to populate transaction: ${errorMessage}`);
304311
return erroredTransaction;
305312
}
306313

@@ -356,12 +363,19 @@ const _sendUserOp = async (
356363
const errorMessage = `${
357364
wrapError(error, "Bundler").message
358365
} Failed to sign prepared userop`;
366+
job.log(`Failed to sign userop: ${errorMessage}`);
367+
368+
// If retry is enabled for prepareUserOp errors, throw to trigger job retry
369+
if (env.EXPERIMENTAL__RETRY_PREPARE_USEROP_ERRORS) {
370+
throw error;
371+
}
372+
373+
// Otherwise, return errored transaction as before
359374
const erroredTransaction: ErroredTransaction = {
360375
...queuedTransaction,
361376
status: "errored",
362377
errorMessage,
363378
};
364-
job.log(`Failed to sign userop: ${errorMessage}`);
365379
return erroredTransaction;
366380
}
367381

@@ -383,12 +397,19 @@ const _sendUserOp = async (
383397
const errorMessage = `${
384398
wrapError(error, "Bundler").message
385399
} Failed to bundle userop`;
400+
job.log(`Failed to bundle userop: ${errorMessage}`);
401+
402+
// If retry is enabled for prepareUserOp errors, throw to trigger job retry
403+
if (env.EXPERIMENTAL__RETRY_PREPARE_USEROP_ERRORS) {
404+
throw error;
405+
}
406+
407+
// Otherwise, return errored transaction as before
386408
const erroredTransaction: ErroredTransaction = {
387409
...queuedTransaction,
388410
status: "errored",
389411
errorMessage,
390412
};
391-
job.log(`Failed to bundle userop: ${errorMessage}`);
392413
return erroredTransaction;
393414
}
394415

0 commit comments

Comments
 (0)