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

Prevent Raiden from being first swap leg #1072

Merged
merged 1 commit into from
Jul 8, 2019
Merged

Conversation

offerm
Copy link
Contributor

@offerm offerm commented Jun 29, 2019

This PR prevents Raiden from being first leg of swap.
It better calculates the maker CLTV by using cltv-delta of 5760 in the case of raiden.
This is only a basis for a better change

@kilrau kilrau requested review from a user and sangaman June 30, 2019 09:43
@kilrau
Copy link
Contributor

kilrau commented Jun 30, 2019

Nice! Tests need to be fixed.

@@ -5,6 +5,7 @@ class HttpService {
constructor(private service: Service) {}

public resolveHashRaiden = async (resolveRequest: RaidenResolveRequest): Promise<RaidenResolveResponse> => {
// TODO: add reveal_timeout, settle time out, token, etc
Copy link
Collaborator

Choose a reason for hiding this comment

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

Mainly curious, what will we need these for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we need to verify that we got the expected reveal_timeout (as we agreed during the swap preparation (if we are not preventing raiden to be the first leg))

We also need to check that we got the payment with the correct token.

@@ -433,6 +433,19 @@ class Swaps extends EventEmitter {

const { makerCurrency, makerAmount, takerCurrency, takerAmount } = Swaps.calculateMakerTakerAmounts(quantity, price, isBuy, requestBody.pairId);

const makerSwapClient = this.swapClientManager.get(makerCurrency)!;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks like tests are failing because of this line, we assert that maker swap client is not null but it's not necessarily the case. Previously we were calling isPairSupported before getting any swap clients, all that method does is check that we have connected swap clients for both sides of the pair. You can move that call to before this line (and use requestBody.pairId) and it should fix the test failing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree

switch (deal.role) {
case SwapRole.Maker:
expectedAmount = deal.makerAmount;
source = 'Taker';
destination = 'Maker';
if (deal.makerCltvDelta! > 50 * 2) {
this.failDeal(deal, SwapFailureReason.UnknownError, 'Wrong CLTV received on first leg');
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe use SwapFailureReason.InvalidResolveRequest instead of the unknown error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree

@offerm
Copy link
Contributor Author

offerm commented Jul 1, 2019

@sangaman I created this PR as a starting point for the change. Please take ownership and make changes as needed.

This prevents Raiden based currencies from being the first leg of
a swap. It better calculates the maker CLTV by using a cltv-delta of
5760 for raiden. This is the first step towards a more robust approach.

Co-authored-by: Daniel McNally <[email protected]>
@sangaman
Copy link
Collaborator

sangaman commented Jul 1, 2019

Gotcha, I updated the PR with some minor changes per my comments to make the tests pass.

@sangaman sangaman dismissed their stale review July 1, 2019 21:34

Authoring PR

@@ -5,6 +5,7 @@ class HttpService {
constructor(private service: Service) {}

public resolveHashRaiden = async (resolveRequest: RaidenResolveRequest): Promise<RaidenResolveResponse> => {
// TODO: add reveal_timeout, settle time out, token, etc
Copy link

Choose a reason for hiding this comment

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

nit: extra whitespace before token

lib/swaps/Swaps.ts Show resolved Hide resolved
lib/swaps/Swaps.ts Show resolved Hide resolved
@sangaman sangaman merged commit a63fec9 into master Jul 8, 2019
@sangaman sangaman deleted the raiden-first-leg branch August 15, 2019 11:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants