Skip to content

Commit

Permalink
feat(experimental): configure mine worker timeout (#797)
Browse files Browse the repository at this point in the history
* feat(experimental): configure mine worker timeout

* reduce log length
  • Loading branch information
arcoraven authored Dec 8, 2024
1 parent a802d87 commit 1719e0a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/utils/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ export const env = createEnv({
QUEUE_FAIL_HISTORY_COUNT: z.coerce.number().default(10_000),
// Sets the number of recent nonces to map to queue IDs.
NONCE_MAP_COUNT: z.coerce.number().default(10_000),

/**
* Experimental env vars. These may be renamed or removed in future non-major releases.
*/
// Sets how long the mine worker waits for a transaction receipt before considering the transaction dropped (default: 30 minutes).
EXPERIMENTAL__MINE_WORKER_TIMEOUT_SECONDS: z.coerce
.number()
.default(30 * 60),
},
clientPrefix: "NEVER_USED",
client: {},
Expand Down Expand Up @@ -134,6 +142,8 @@ export const env = createEnv({
QUEUE_COMPLETE_HISTORY_COUNT: process.env.QUEUE_COMPLETE_HISTORY_COUNT,
QUEUE_FAIL_HISTORY_COUNT: process.env.QUEUE_FAIL_HISTORY_COUNT,
NONCE_MAP_COUNT: process.env.NONCE_MAP_COUNT,
EXPERIMENTAL__MINE_WORKER_TIMEOUT_SECONDS:
process.env.EXPERIMENTAL__MINE_WORKER_TIMEOUT_SECONDS,
METRICS_PORT: process.env.METRICS_PORT,
METRICS_ENABLED: process.env.METRICS_ENABLED,
},
Expand Down
6 changes: 5 additions & 1 deletion src/worker/queues/mineTransactionQueue.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { Queue } from "bullmq";
import superjson from "superjson";
import { env } from "../../utils/env";
import { redis } from "../../utils/redis/redis";
import { defaultJobOptions } from "./queues";

export type MineTransactionData = {
queueId: string;
};

// Attempts are made every ~20 seconds. See backoffStrategy in initMineTransactionWorker().
const NUM_ATTEMPTS = env.EXPERIMENTAL__MINE_WORKER_TIMEOUT_SECONDS / 20;

export class MineTransactionQueue {
static q = new Queue<string>("transactions-2-mine", {
connection: redis,
Expand All @@ -23,7 +27,7 @@ export class MineTransactionQueue {
const jobId = this.jobId(data);
await this.q.add(jobId, serialized, {
jobId,
attempts: 100, // > 30 minutes with the backoffStrategy defined on the worker
attempts: NUM_ATTEMPTS,
backoff: { type: "custom" },
});
};
Expand Down
3 changes: 2 additions & 1 deletion src/worker/tasks/mineTransactionWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,9 @@ const _mineTransaction = async (
}

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

// Resend the transaction (after some initial delay).
Expand Down

0 comments on commit 1719e0a

Please sign in to comment.