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): add resolve request validation slippage #1207

Merged
1 commit merged into from
Sep 9, 2019

Conversation

ghost
Copy link

@ghost ghost commented Sep 7, 2019

In this commit we're relaxing raiden's resolve request validation by 3 blocks in order to prevent an issue where new blocks are mined during the payment.

This is a quick fix to the issue described in: #1184 (comment)

As a follow-up I'd like to add a simulation test scenario to make sure maker still has sufficient buffer.

@ghost ghost requested review from sangaman and offerm September 7, 2019 18:33
@kilrau kilrau assigned sangaman and ghost Sep 7, 2019
@@ -739,7 +739,8 @@ class Swaps extends EventEmitter {
source = 'Taker';
destination = 'Maker';
const lockExpirationDelta = expiration - chain_height;
if (deal.makerCltvDelta! > lockExpirationDelta) {
const LOCK_EXPIRATION_SLIPPAGE = 3;
if (deal.makerCltvDelta! - LOCK_EXPIRATION_SLIPPAGE > lockExpirationDelta) {
Copy link
Contributor

Choose a reason for hiding this comment

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

consider to add the LOCK_EXPIRATION_SLIPPAGE to the maker's final_cltv_delta and here just check without the LOCK_EXPIRATION_SLIPPAGE.

Copy link
Author

Choose a reason for hiding this comment

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

I don't understand. In the case of raiden there's no concept of final_cltv_delta. The way I understand it is that we only want to add the slippage for raiden payments from taker to maker.

@offerm
Copy link
Contributor

offerm commented Sep 8, 2019 via email

@ghost
Copy link
Author

ghost commented Sep 8, 2019

There can also be a slippage on the LN payment. Same reason.

The cltv_expiry for LN payment is relative. How can there be slippage?

Copy link
Collaborator

@sangaman sangaman left a comment

Choose a reason for hiding this comment

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

Looks good to me, I'd only recommend a line or two of comments explaining what the slippage is and why we must account for it, so in the future it's not a mystery to someone reading the code that's unfamiliar with the concept.

As for applying this to the lnd invoices, I'm also under the impression that it's not necessary since the values are relative. Ultimately the check that we have sufficient cltv delay happens within lnd code as I understand it, not xud (we just pass lnd the relative value when adding an invoice).

@kilrau
Copy link
Contributor

kilrau commented Sep 9, 2019

Looks good to me, I'd only recommend a line or two of comments explaining what the slippage is and why we must account for it, so in the future it's not a mystery to someone reading the code that's unfamiliar with the concept.

Agree, these comments would be very nice :)

As for applying this to the lnd invoices, I'm also under the impression that it's not necessary since the values are relative. Ultimately the check that we have sufficient cltv delay happens within lnd code as I understand it, not xud (we just pass lnd the relative value when adding an invoice).

That's also my understanding, could you confirm or explain what you mean so that this can be merged asap? @offerm

@kilrau
Copy link
Contributor

kilrau commented Sep 9, 2019

I just tested this branch with a native simnet setup. 1. leg lightning, 2. leg raiden orders (xucli buy 1 btc/dai 10000) still not working. Error same: 09/09/2019 12:44:46.856 [SWAPS] debug: deal 92521de004cd68ff57f8854d895b25f62b6775bf101d70ba135de4d502bd57bc failed due to SwapTimedOut: undefined

Isn't this supposed to fix this or am I missing something?

@kilrau
Copy link
Contributor

kilrau commented Sep 9, 2019

Oh, the xud1.simnet.exchangeunion.com would need to be updated too I guess. Here the log from xud1.simnet side: https://paste.ubuntu.com/p/vpv3MT7RYK/ . Shows, that the cltv delta is off by one block.

@kilrau
Copy link
Contributor

kilrau commented Sep 9, 2019

There are some other weird entries with the node key being replaced by undefined. Do we know why is that?

@sangaman
Copy link
Collaborator

sangaman commented Sep 9, 2019

Those logs show 09/09/2019 10:44:18.393 [SWAPS] error: cltvDelta of 7359 does not meet 7360 minimum which indicates that it's failing due to the bug that's fixed here, so we're all good on that front.

I'll look into that node key being replaced by undefined issue, definitely separate from this though.

In this commit we're relaxing raiden's resolve request validation by 3
blocks in order to prevent an issue where new blocks are mined during the
payment.
@ghost ghost force-pushed the fix/resolve-request-validation-slippage branch from 31bc63b to 99600c4 Compare September 9, 2019 13:55
@ghost ghost merged commit b761bf2 into master Sep 9, 2019
@ghost ghost deleted the fix/resolve-request-validation-slippage branch September 9, 2019 14:38
@sangaman sangaman removed their assignment Sep 10, 2019
@sangaman sangaman added bug Something isn't working raiden swaps labels Sep 10, 2019
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working swaps
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants