Skip to content

Commit

Permalink
Setting reverted state to failed txs
Browse files Browse the repository at this point in the history
  • Loading branch information
EvgenKor committed May 30, 2024
1 parent 179dc44 commit 95227b1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion zp-relayer/pool/BasePool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export abstract class BasePool<N extends Network = Network> {
abstract onSend(p: ProcessResult<any>, txHash: string): Promise<void>
abstract onConfirmed( p: ProcessResult<any>, txHash: string, callback?: () => Promise<void>,jobId?: string): Promise<void>

async onFailed(txHash: string): Promise<void> {
async onFailed(txHash: string, jobId?: string): Promise<void> {
logger.error('Transaction reverted', { txHash })

await this.clearOptimisticState()
Expand Down
17 changes: 17 additions & 0 deletions zp-relayer/pool/RelayPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,23 @@ export class RelayPool extends BasePool<Network> {
}
}

async onFailed(txHash: string, jobId?: string): Promise<void> {
super.onFailed(txHash, jobId);

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);
}
}

// TODO: remove cached tx from txStore
}

protected async cacheTxLocally(index: number, commit: string, txHash: string, memo: string) {
// store or updating local tx store
// (we should keep sent transaction until the indexer grab them)
Expand Down
4 changes: 2 additions & 2 deletions zp-relayer/workers/sentTxWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ export async function createSentTxWorker({ redis, mutex, pool, txManager }: ISen

await pool.onConfirmed(processResult, txHash, updatePoolJobState,poolJobId)
} else {
await pool.onFailed(txHash)
await updatePoolJobState()
await pool.onFailed(txHash, poolJobId);
//await updatePoolJobState()
}
}

Expand Down

0 comments on commit 95227b1

Please sign in to comment.