Skip to content

Commit 1719e0a

Browse files
authored
feat(experimental): configure mine worker timeout (#797)
* feat(experimental): configure mine worker timeout * reduce log length
1 parent a802d87 commit 1719e0a

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

src/utils/env.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,14 @@ export const env = createEnv({
9898
QUEUE_FAIL_HISTORY_COUNT: z.coerce.number().default(10_000),
9999
// Sets the number of recent nonces to map to queue IDs.
100100
NONCE_MAP_COUNT: z.coerce.number().default(10_000),
101+
102+
/**
103+
* Experimental env vars. These may be renamed or removed in future non-major releases.
104+
*/
105+
// Sets how long the mine worker waits for a transaction receipt before considering the transaction dropped (default: 30 minutes).
106+
EXPERIMENTAL__MINE_WORKER_TIMEOUT_SECONDS: z.coerce
107+
.number()
108+
.default(30 * 60),
101109
},
102110
clientPrefix: "NEVER_USED",
103111
client: {},
@@ -134,6 +142,8 @@ export const env = createEnv({
134142
QUEUE_COMPLETE_HISTORY_COUNT: process.env.QUEUE_COMPLETE_HISTORY_COUNT,
135143
QUEUE_FAIL_HISTORY_COUNT: process.env.QUEUE_FAIL_HISTORY_COUNT,
136144
NONCE_MAP_COUNT: process.env.NONCE_MAP_COUNT,
145+
EXPERIMENTAL__MINE_WORKER_TIMEOUT_SECONDS:
146+
process.env.EXPERIMENTAL__MINE_WORKER_TIMEOUT_SECONDS,
137147
METRICS_PORT: process.env.METRICS_PORT,
138148
METRICS_ENABLED: process.env.METRICS_ENABLED,
139149
},

src/worker/queues/mineTransactionQueue.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import { Queue } from "bullmq";
22
import superjson from "superjson";
3+
import { env } from "../../utils/env";
34
import { redis } from "../../utils/redis/redis";
45
import { defaultJobOptions } from "./queues";
56

67
export type MineTransactionData = {
78
queueId: string;
89
};
910

11+
// Attempts are made every ~20 seconds. See backoffStrategy in initMineTransactionWorker().
12+
const NUM_ATTEMPTS = env.EXPERIMENTAL__MINE_WORKER_TIMEOUT_SECONDS / 20;
13+
1014
export class MineTransactionQueue {
1115
static q = new Queue<string>("transactions-2-mine", {
1216
connection: redis,
@@ -23,7 +27,7 @@ export class MineTransactionQueue {
2327
const jobId = this.jobId(data);
2428
await this.q.add(jobId, serialized, {
2529
jobId,
26-
attempts: 100, // > 30 minutes with the backoffStrategy defined on the worker
30+
attempts: NUM_ATTEMPTS,
2731
backoff: { type: "custom" },
2832
});
2933
};

src/worker/tasks/mineTransactionWorker.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,9 @@ const _mineTransaction = async (
162162
}
163163

164164
// Else the transaction is not mined yet.
165+
const ellapsedMs = Date.now() - sentTransaction.queuedAt.getTime();
165166
job.log(
166-
`Transaction is not mined yet. Check again later. sentTransactionHashes=${sentTransaction.sentTransactionHashes}`,
167+
`Transaction is not mined yet. Check again later. elapsed=${ellapsedMs / 1000}s`,
167168
);
168169

169170
// Resend the transaction (after some initial delay).

0 commit comments

Comments
 (0)