Skip to content

fix: fallback to resending every 120s latest if current RPC block is stuck #809

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 11, 2024
Merged
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
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
Loading