Skip to content
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

Disable re-processing #106

Merged
merged 3 commits into from
Dec 1, 2022
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
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