Skip to content

Commit

Permalink
feat: error tracker to not spam transcation error
Browse files Browse the repository at this point in the history
  • Loading branch information
Benzbeeb committed Feb 18, 2025
1 parent 4286b96 commit 09dfcb9
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/workers/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export class WalletWorker {
private sequence?: number
private accountNumber?: number
private logger: Logger
private errorTracker = new Map<string, number>()

constructor(
public chain: ChainWorker,
Expand Down Expand Up @@ -68,6 +69,15 @@ export class WalletWorker {
this.accountNumber = accInfo.getAccountNumber()
}

private async checkAndStoreError(code: string, error: Error) {
const now = Date.now()
const lastErrorTime = this.errorTracker.get(code) ?? 0
if (now - lastErrorTime > 10 * 60 * 1000) {
this.errorTracker.set(code, now)
await captureException(error)
}
}

private async handlePackets() {
if (this.chain.latestHeight === undefined) return

Expand Down Expand Up @@ -395,7 +405,7 @@ export class WalletWorker {
`Tx failed. raw log - ${result.raw_log}, code - ${result.code}`
)

await captureException(error)
await this.checkAndStoreError(result.code.toString(), error)
this.logger.error(error)
throw error
}
Expand Down

0 comments on commit 09dfcb9

Please sign in to comment.