From 0c554c4e83ae0b3b1a5ae06699a3dd1ea974c891 Mon Sep 17 00:00:00 2001 From: sebastienverreault Date: Fri, 6 May 2022 16:57:40 +0900 Subject: [PATCH] Fix: recursion loop (#94) * fix: stop condition in case of infinite failure Co-authored-by: Sebastien Verreault --- dealer/src/Dealer.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/dealer/src/Dealer.ts b/dealer/src/Dealer.ts index f68a8fa0..dc275e90 100644 --- a/dealer/src/Dealer.ts +++ b/dealer/src/Dealer.ts @@ -371,6 +371,7 @@ export class Dealer { private async depositOnExchangeCallback( onChainAddress: string, transferSizeInBtc: number, + retries = 2, ): Promise> { try { const memo = `deposit of ${transferSizeInBtc} btc to ${this.strategy.name}` @@ -411,11 +412,16 @@ export class Dealer { } else { this.logger.debug({ payOnChainResult }, "WalletOnChainPay failed.") - // try again with 50% amount in case we can work around fund limit - return this.depositOnExchangeCallback( - onChainAddress, - roundBtc(transferSizeInBtc / 2), - ) + if (retries > 0) { + // try again with 50% amount in case we can work around fund limit + return this.depositOnExchangeCallback( + onChainAddress, + roundBtc(transferSizeInBtc / 2), + retries - 1, + ) + } + + return { ok: false, error: payOnChainResult.error } } } catch (error) { return { ok: false, error: error }