Skip to content

Commit

Permalink
fix: add fallback resend timer if block is stuck
Browse files Browse the repository at this point in the history
  • Loading branch information
arcoraven committed Dec 11, 2024
1 parent 04fdca0 commit 5e4f46b
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/worker/tasks/mine-transaction-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,18 +165,21 @@ const _mineTransaction = async (
}

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

// Resend the transaction (after some initial delay).
// Resend the transaction if `minEllapsedBlocksBeforeRetry` blocks or 120 seconds have passed since the last send attempt.
const config = await getConfig();
const blockNumber = await getBlockNumberish(sentTransaction.chainId);
const ellapsedBlocks = blockNumber - sentTransaction.sentAtBlock;
if (ellapsedBlocks >= config.minEllapsedBlocksBeforeRetry) {
const elapsedBlocks = blockNumber - sentTransaction.sentAtBlock;
const shouldResend =
elapsedBlocks >= config.minEllapsedBlocksBeforeRetry ||
elapsedSeconds > 120;
if (shouldResend) {
job.log(
`Resending transaction after ${ellapsedBlocks} blocks. blockNumber=${blockNumber} sentAtBlock=${sentTransaction.sentAtBlock}`,
`Resending transaction after ${elapsedBlocks} blocks. blockNumber=${blockNumber} sentAtBlock=${sentTransaction.sentAtBlock}`,
);
await SendTransactionQueue.add({
queueId: sentTransaction.queueId,
Expand Down

0 comments on commit 5e4f46b

Please sign in to comment.