Skip to content

Commit

Permalink
Re-try getting status of tx in case of unstable RPC behind a load bal…
Browse files Browse the repository at this point in the history
…ancer (#106)
  • Loading branch information
Leonid Tyurin authored and lok52 committed Dec 16, 2022
1 parent e3c0e01 commit f04293d
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions zp-relayer/workers/sentTxWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ export async function createSentTxWorker<T extends EstimationType>(gasPrice: Gas
}

// Transaction was not mined, but nonce was increased
// Should send for re-processing
if (tx === null) {
logger.warn('Transaction was not mined, but nonce increased; tx should be re-processed')
return [null, true]
}

Expand All @@ -89,9 +87,9 @@ export async function createSentTxWorker<T extends EstimationType>(gasPrice: Gas
const [lastHash, lastGasPrice] = prevAttempts.at(-1) as SendAttempt

if (shouldReprocess) {
logger.info('%s sending this job for re-processing...', logPrefix)
await poolTxQueue.add('reprocess', [job.data.txPayload])
return [SentTxState.SKIPPED, lastHash, []] as SentTxResult
// TODO: handle this case later
// Error should be caught by `withLoop` to re-run job
throw new Error('Ambiguity detected: nonce increased but no respond that transaction was mined')
}

if (tx) {
Expand Down Expand Up @@ -126,6 +124,14 @@ export async function createSentTxWorker<T extends EstimationType>(gasPrice: Gas
logger.error('Commitments are not equal')
}

const rootConfirmed = pool.state.getMerkleRoot()
logger.info(`Assert roots are equal`)
if (rootConfirmed !== root) {
// TODO: Should be impossible but in such case
// we should recover from some checkpoint
logger.error('Roots are not equal: %s should be %s', rootConfirmed, root)
}

return [SentTxState.MINED, txHash, []] as SentTxResult
} else {
// Revert
Expand Down

0 comments on commit f04293d

Please sign in to comment.