Skip to content

Commit

Permalink
Merge pull request #1207 from ExchangeUnion/fix/resolve-request-valid…
Browse files Browse the repository at this point in the history
…ation-slippage

fix(swaps): add resolve request validation slippage
  • Loading branch information
Karl Ranna authored Sep 9, 2019
2 parents 69962db + 99600c4 commit b761bf2
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/swaps/Swaps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -739,8 +739,17 @@ class Swaps extends EventEmitter {
source = 'Taker';
destination = 'Maker';
const lockExpirationDelta = expiration - chain_height;
if (deal.makerCltvDelta! > lockExpirationDelta) {
this.logger.error(`cltvDelta of ${lockExpirationDelta} does not meet ${deal.makerCltvDelta!} minimum`);
// We relax the validation by LOCK_EXPIRATION_SLIPPAGE blocks because
// new blocks could be mined during the time it takes from taker's
// payment to reach the maker for validation.
// This usually happens in simulated environments with fast mining enabled.
const LOCK_EXPIRATION_SLIPPAGE = 3;
if (deal.makerCltvDelta! - LOCK_EXPIRATION_SLIPPAGE > lockExpirationDelta) {
this.logger.error(`
lockExpirationDelta of ${lockExpirationDelta} does not meet
makerCltvDelta ${deal.makerCltvDelta!} - LOCK_EXPIRATION_SLIPPAGE ${LOCK_EXPIRATION_SLIPPAGE}
= ${deal.makerCltvDelta! - LOCK_EXPIRATION_SLIPPAGE} minimum
`);
this.failDeal(deal, SwapFailureReason.InvalidResolveRequest, 'Insufficient CLTV received on first leg');
return false;
}
Expand Down

0 comments on commit b761bf2

Please sign in to comment.