Skip to content

Commit b2a0b1a

Browse files
authored
fix: add fallback resend timer if block is stuck (#809)
1 parent 71fb8b0 commit b2a0b1a

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,18 +165,21 @@ const _mineTransaction = async (
165165
}
166166

167167
// Else the transaction is not mined yet.
168-
const ellapsedMs = Date.now() - sentTransaction.queuedAt.getTime();
168+
const elapsedSeconds = msSince(sentTransaction.sentAt) / 1000;
169169
job.log(
170-
`Transaction is not mined yet. Check again later. elapsed=${ellapsedMs / 1000}s`,
170+
`Transaction is not mined yet. Check again later. elapsed=${elapsedSeconds}s`,
171171
);
172172

173-
// Resend the transaction (after some initial delay).
173+
// Resend the transaction if `minEllapsedBlocksBeforeRetry` blocks or 120 seconds have passed since the last send attempt.
174174
const config = await getConfig();
175175
const blockNumber = await getBlockNumberish(sentTransaction.chainId);
176-
const ellapsedBlocks = blockNumber - sentTransaction.sentAtBlock;
177-
if (ellapsedBlocks >= config.minEllapsedBlocksBeforeRetry) {
176+
const elapsedBlocks = blockNumber - sentTransaction.sentAtBlock;
177+
const shouldResend =
178+
elapsedBlocks >= config.minEllapsedBlocksBeforeRetry ||
179+
elapsedSeconds > 120;
180+
if (shouldResend) {
178181
job.log(
179-
`Resending transaction after ${ellapsedBlocks} blocks. blockNumber=${blockNumber} sentAtBlock=${sentTransaction.sentAtBlock}`,
182+
`Resending transaction after ${elapsedBlocks} blocks. blockNumber=${blockNumber} sentAtBlock=${sentTransaction.sentAtBlock}`,
180183
);
181184
await SendTransactionQueue.add({
182185
queueId: sentTransaction.queueId,

0 commit comments

Comments
 (0)