Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(swaps): set cltvLimit correctly #1163

Merged
merged 1 commit into from
Aug 21, 2019
Merged

fix(swaps): set cltvLimit correctly #1163

merged 1 commit into from
Aug 21, 2019

Conversation

sangaman
Copy link
Collaborator

Fixes #1158.

This fixes a bug whereby the makerCltvDelta was erroneously used for the cltvLimit for the payment from maker to taker. makerCltvDelta is irrelevent to the payment to the taker. Instead, this value is set to the time lock of the route found from maker to taker for lnd, raiden currently has no equivalent to cltvLimit.

In tests, payments would still fail occasionally due to no route found. Adding 3 blocks to the cltvLimit value consistently resolved these failures - any fewer than 3 and the payments would still fail. More investigation is warranted into why this is necessary, it's possible that there is a bug in the cltvLimit implementation within lnd.

This fix makes the new multihop simulation test case in #1160 pass.

@sangaman sangaman added lightning Lightning network & lnd integration swaps critical bug labels Aug 19, 2019
@sangaman sangaman requested review from a user and offerm August 19, 2019 09:07
@sangaman sangaman self-assigned this Aug 19, 2019
@kilrau
Copy link
Contributor

kilrau commented Aug 19, 2019

Definitely needs your review @offerm

This fixes a bug whereby the `makerCltvDelta` was erroneously used for
the `cltvLimit` for the payment from maker to taker. `makerCltvDelta` is
irrelevent to the payment to the taker. Instead, this value is set to
the time lock of the route found from maker to taker for lnd, raiden
currently has no equivalent to `cltvLimit`.

In tests, payments would still fail occasionally due to no route found.
Adding 3 blocks to the `cltvLimit` value consistently resolved these
failures - any fewer than 3 and the payments would still fail. More
investigation is warranted into why this is necessary, it's possible
that there is a bug in the `cltvLimit` implementation within lnd.

Fixes #1158.
if (deal.role === SwapRole.Maker) {
// we are the maker paying the taker
amount = deal.takerUnits;
tokenAddress = this.tokenAddresses.get(deal.takerCurrency);
tokenAddress = this.tokenAddresses.get(deal.takerCurrency)!;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we also need to use lock_timout=deal.takerMaxTimeLock here to ensure that the maker's payment duration.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so, because we're using lock_timeout as the delay extended to the recipient of the payment, whereas the takerMaxTimeLock is an upper bound on the total delay for the route. Also when the maker to taker payment is raiden, we use a hardcoded value for the route total time lock of 101 (which is then set to takerMaxTimelock) so I don't think it would be of much use here anyway.

Still, this is a good point to consider going forward, if we're going to be using multihop raiden payments with variable total time locks then we need to know what the maximum time lock will be for properly executing the swap.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, right - makes sense. I forgot that we're only supporting direct channels for now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still, this is a good point to consider going forward, if we're going to be using multihop raiden payments with variable total time locks then we need to know what the maximum time lock will be for properly executing the swap.

Please open an issue for this with #1068 as dependency @sangaman

@sangaman sangaman merged commit bf870ad into master Aug 21, 2019
@sangaman sangaman deleted the fix/cltv-limit branch August 21, 2019 08:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
critical bug lightning Lightning network & lnd integration swaps
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cltvLimit is set incorrectly
2 participants