From 0edb5e81b1ec5f45d8868825f48e1ac365844583 Mon Sep 17 00:00:00 2001 From: vladimir Date: Thu, 13 Jun 2024 20:14:50 +0300 Subject: [PATCH] make jobId mandatory for onFailed callback --- zp-relayer/pool/BasePool.ts | 2 +- zp-relayer/pool/RelayPool.ts | 24 ++++++++++-------------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/zp-relayer/pool/BasePool.ts b/zp-relayer/pool/BasePool.ts index b39d5d3..e7f264c 100644 --- a/zp-relayer/pool/BasePool.ts +++ b/zp-relayer/pool/BasePool.ts @@ -46,7 +46,7 @@ export abstract class BasePool { abstract onSend(p: ProcessResult, txHash: string): Promise abstract onConfirmed(p: ProcessResult, txHash: string, callback?: () => Promise, jobId?: string): Promise - async onFailed(txHash: string, jobId?: string): Promise { + async onFailed(txHash: string, jobId: string): Promise { logger.error('Transaction reverted', { txHash }) await this.clearOptimisticState() diff --git a/zp-relayer/pool/RelayPool.ts b/zp-relayer/pool/RelayPool.ts index ca098be..4ddbc01 100644 --- a/zp-relayer/pool/RelayPool.ts +++ b/zp-relayer/pool/RelayPool.ts @@ -260,7 +260,7 @@ export class RelayPool extends BasePool { async onConfirmed(res: ProcessResult, txHash: string, callback?: () => Promise, jobId?: string): Promise { logger.debug("Updating pool job %s completed, txHash %s", jobId, txHash); - if(jobId) { + if (jobId) { const poolJob = await poolTxQueue.getJob(jobId); if (!poolJob) { logger.error('Pool job not found', { jobId }); @@ -274,21 +274,17 @@ export class RelayPool extends BasePool { } } - async onFailed(txHash: string, jobId?: string): Promise { + async onFailed(txHash: string, jobId: string): Promise { super.onFailed(txHash, jobId); - this.txStore.removeAll(); - - if(jobId) { - const poolJob = await poolTxQueue.getJob(jobId); - if (!poolJob) { - logger.error('Pool job not found', { jobId }); - } else { - poolJob.data.transaction.state = JobState.REVERTED; - poolJob.data.transaction.txHash = txHash; - await poolJob.update(poolJob.data); - } + this.txStore.remove(jobId); + const poolJob = await poolTxQueue.getJob(jobId); + if (!poolJob) { + logger.error('Pool job not found', { jobId }); + } else { + poolJob.data.transaction.state = JobState.REVERTED; + poolJob.data.transaction.txHash = txHash; + await poolJob.update(poolJob.data); } - } protected async cacheTxLocally(index: number, commit: string, txHash: string, memo: string) {