Skip to content

Commit

Permalink
Merge pull request #743 from ExchangeUnion/cltvDelta-add-one-block
Browse files Browse the repository at this point in the history
fix(swap): allow one extra block to be created during swap
  • Loading branch information
sangaman authored Dec 12, 2018
2 parents d538757 + 08bf957 commit 86b6d26
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/swaps/Swaps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,10 +429,10 @@ class Swaps extends EventEmitter {
const cltvDeltaFactor = this.lndLtcClient.cltvDelta / this.lndBtcClient.cltvDelta;
switch (makerCurrency) {
case 'BTC':
deal.makerCltvDelta = this.lndBtcClient.cltvDelta + routeCltvDelta / cltvDeltaFactor;
deal.makerCltvDelta = this.lndBtcClient.cltvDelta + Math.ceil(routeCltvDelta / cltvDeltaFactor);
break;
case 'LTC':
deal.makerCltvDelta = this.lndLtcClient.cltvDelta + routeCltvDelta * cltvDeltaFactor;
deal.makerCltvDelta = this.lndLtcClient.cltvDelta + Math.ceil(routeCltvDelta * cltvDeltaFactor);
break;
}

Expand Down Expand Up @@ -569,7 +569,8 @@ class Swaps extends EventEmitter {
return false;
}

if (cltvDelta > resolveRequest.getTimeout() - resolveRequest.getHeightNow()) {
// allow 1 additional one block to be created during the swap
if (cltvDelta - 1 > resolveRequest.getTimeout() - resolveRequest.getHeightNow()) {
this.logger.error(`got timeout ${resolveRequest.getTimeout()} at height ${resolveRequest.getHeightNow()}`);
this.logger.error(`cltvDelta is ${resolveRequest.getTimeout() - resolveRequest.getHeightNow()} expected delta of ${cltvDelta}`);
this.setDealState(deal, SwapState.Error,
Expand Down

0 comments on commit 86b6d26

Please sign in to comment.