Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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`,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reduces log lines to minimize memory usage

);

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