Skip to content

Commit

Permalink
make jobId mandatory for onFailed callback
Browse files Browse the repository at this point in the history
  • Loading branch information
r0wdy1 committed Jun 13, 2024
1 parent a312043 commit 0edb5e8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 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, jobId?: string): Promise<void> {
async onFailed(txHash: string, jobId: string): Promise<void> {
logger.error('Transaction reverted', { txHash })

await this.clearOptimisticState()
Expand Down
24 changes: 10 additions & 14 deletions zp-relayer/pool/RelayPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ export class RelayPool extends BasePool<Network> {

async onConfirmed(res: ProcessResult<RelayPool>, txHash: string, callback?: () => Promise<void>, jobId?: string): Promise<void> {
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 });
Expand All @@ -274,21 +274,17 @@ export class RelayPool extends BasePool<Network> {
}
}

async onFailed(txHash: string, jobId?: string): Promise<void> {
async onFailed(txHash: string, jobId: string): Promise<void> {
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) {
Expand Down

0 comments on commit 0edb5e8

Please sign in to comment.