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

What exactly to do when lnd or raiden is disconnected #684

Closed
kilrau opened this issue Nov 18, 2018 · 21 comments
Closed

What exactly to do when lnd or raiden is disconnected #684

kilrau opened this issue Nov 18, 2018 · 21 comments
Assignees
Labels
lightning Lightning network & lnd integration P2 mid priority

Comments

@kilrau
Copy link
Contributor

kilrau commented Nov 18, 2018

Prerequisite: #573

This issue is about answering the question: What should we do if we xud identifies via #573 that it is not properly connected to LND?

Current opinions:
a) disconnect from all peers
Good: easy
Bad: doesn't differentiate between e.g. LND and Raiden
b) Throw an error through gRPC and revoke all trading pairs with swap protocol LND. Also disable all peerOrders with swap protocol LND. Same with Raiden.
Good: considers different swap clients (LND, Raiden)
Bad: Complicated

@kilrau kilrau added question/tbd Further information or discussion needed lightning Lightning network & lnd integration raiden labels Nov 18, 2018
@kilrau kilrau added this to the 1.0.0-alpha.6 milestone Nov 18, 2018
@kilrau kilrau assigned ghost , sangaman and offerm Nov 18, 2018
@sangaman
Copy link
Collaborator

We shouldn't disconnect from peers, as losing connectivity to lnd only means that one currency is impacted, so I think the better route is to temporarily disable all affected trading pairs. That would update the handshake with our peers to let them know we aren't supporting that pair (which in turn would make them drop all our orders for that pair) and would fail any rpc calls to place an order (or execute a swap) for that trading pair. We would also want to drop orders for that trading pair locally.

@kilrau
Copy link
Contributor Author

kilrau commented Nov 26, 2018

Other opinions? @offerm @erkarl @moshababo ?

@kilrau
Copy link
Contributor Author

kilrau commented Dec 18, 2018

  • don't block xud start when lnd or raiden fails to connect
  • how to denounce a pair / protocol
  • how to reannounce a pari / protocol

@kilrau kilrau unassigned ghost Dec 18, 2018
@sangaman
Copy link
Collaborator

I verified that we actually do connect to peers on startup even without a connection to lnd, however we are advertising the trading pair that we don't have an lnd connection for and that needs to change.

@sangaman
Copy link
Collaborator

how to denounce a pair / protocol
how to reannounce a pari / protocol

We already have the ability to add and remove trading pairs (see addPair and removePair in OrderBook.ts`) so we just need to call these methods, this part should be simple actually.

@kilrau kilrau modified the milestones: 1.0.0-alpha.6, 1.0.0-alpha.8 Dec 25, 2018
@kilrau kilrau removed the question/tbd Further information or discussion needed label Dec 25, 2018
@kilrau kilrau changed the title [Concept] What exactly to do when lnd or raiden is disconnected What exactly to do when lnd or raiden is disconnected Dec 25, 2018
@kilrau
Copy link
Contributor Author

kilrau commented Dec 25, 2018

Great, anything that still needs to be defined?

@kilrau
Copy link
Contributor Author

kilrau commented Jan 2, 2019

Good to go? @sangaman

@kilrau
Copy link
Contributor Author

kilrau commented Jan 2, 2019

Dependency: #762

@kilrau kilrau modified the milestones: 1.0.0-alpha.7, 1.0.0-alpha.8 Jan 23, 2019
@kilrau kilrau modified the milestones: 1.0.0-alpha.8, 1.0.0-alpha.9 Feb 5, 2019
@kilrau kilrau modified the milestones: 1.0.0-alpha.9, 1.0.0-alpha.10 Feb 20, 2019
@kilrau
Copy link
Contributor Author

kilrau commented Apr 15, 2019

Great that we have most of it! As far as I understand we still have to handle:

  1. Invalidation of affected OwnOrders with peers, triggered by an disconnected swap client (lnd/raiden). Agree to only do that after a certain timeout. Local environment issues can cause a couple of seconds of disconnection which shouldn't trigger this. Is 30s a reasonable timeout?

I would use the regular OrderInvalidation package to invalidate all open OwnOrders of an affected pair, nothing new to tell peers to disable per swap client. When the swap client is available again, we simply broadcast all orders again. I know that's rather inefficient, but I believe events where swap clients get disconnected are rather exceptions and I wouldn't want to have another "disable all orders for this swap client" be handled by the peer. This will cause new issues when reenabling with oudated orders etc. I'd prefer the local client selecting all order to be invalidated and send the corresponding packet to the peer. We can think of making the OrderInvalidation packet multi-order capable to make this process more efficient.

Added testing this to the TODO's for xud-simulation tests:
https://github.com/ExchangeUnion/xud/blob/simulation-readme/test/simulation/README.md

  1. Throw an alert after timeout via the gRPC so that the platform operator can act (dependent on SubscribeAlerts discussion: SubscribeAlerts #864 (comment))

@sangaman
Copy link
Collaborator

Invalidation of affected OwnOrders with peers, triggered by an disconnected swap client (lnd/raiden). Agree to only do that after a certain timeout. Local environment issues can cause a couple of seconds of disconnection which shouldn't trigger this. Is 30s a reasonable timeout?

I was thinking 30s or a minute, either is fine with me. We already have the logic in place to invalidate all own orders for an affected pair, so that's no big deal.

Broadcasting all orders again is a new feature though. This would require us to track invalidated own orders separately within xud (currently we just get rid of them). It also means that we could have a lot of re-validated orders match immediately - would the re-validated orders become the takers in that case? It's certainly doable, but I'm thinking that it might just be better to expect exchanges to resend their orders to xud when a trading pair comes back online.

@kilrau
Copy link
Contributor Author

kilrau commented Apr 15, 2019

Broadcasting all orders again is a new feature though. This would require us to track invalidated own orders separately within xud (currently we just get rid of them)

Yes, I believe we need to take the orders out of the order book and store them somewhere else.

It also means that we could have a lot of re-validated orders match immediately - would the re-validated orders become the takers in that case? It's certainly doable, but I'm thinking that it might just be better to expect exchanges to resend their orders to xud when a trading pair comes back online.

Exchanges in no-matching mode track orders on their own. Any other node in matching mode would permanently loose all these orders - not good. Also, how would the exchange re-sending orders to xud and xud in turn immediately sending it to the order book be any different from xud doing that directly? Exchanges would have to implement a separate logic to handle these cases. Let's do it for them!

would the re-validated orders become the takers in that case?

Good point, this has to be avoided. The taker/maker side should never change before and after the swap client disconnect event. As a matter of fact, all own orders residing in the order book are maker orders and that's how the situation should be after the disconnect event.

An idea how to do this:

  • Alert event + log entry: Swap client LND disconnected. Caching own orders for trading pairs X, Y, Z and temporarily invalidating these on the network until swap client LND is back.
  • take OwnOrders out of order book, store them somewhere else in the same order they were in the order book priority queue. Drop PeerOrders for the pair in the same step. This has to be "blocking" and from start of the procedure we don't accept and attempt any swaps for that pair.
  • invalidate all own orders for an affected pair on the network
  • Alert event + log entry: Successfully cached & invalidated own orders for trading pairs X, Y, Z on the network. Waiting for swap client LND.
  • throw Swap client LND disconnected error for PlaceOrder on pairs X, Y, Z in the meanwhile. Drop incoming peer order for pairs X, Y, Z.
  • Alert event + log entry: Swap client LND back, reinserting own orders for trading pairs X, Y, Z into order book.
  • Reinsert own orders for X, Y, Z. Since they didn't match before and the order books of X, Y, Z are empty (!) there can't be a match = they cannot become taker orders. let order broadcast automatically as usual, once all are added stop dropping peer orders for X, Y, Z.
  • Alert event + log entry: Successfully reinserted own orders for trading pairs X, Y, Z into order book.

@sangaman
Copy link
Collaborator

OK, I think that can be done. But the way you described it there could be orders that overlap in price but don't "match" because they are both treated as makers, but I guess that's the desired outcome in this case?

@kilrau
Copy link
Contributor Author

kilrau commented Apr 16, 2019

All own orders in the order book are maker orders. So that's what these were before and that's what they should be after swap client disconnect.

there could be orders that overlap in price but don't "match" because they are both treated as makers

don't see how this can happen, then they should have matched before already. Note: as I described it, we don't allow any old or new peer orders or new own orders (place orders) while swap client is disconnected.

but I guess that's the desired outcome in this case?

Anyways, yes that's the desired outcome. Still would be interested in how a price overlap of two own orders which were like this in the order book before can occur.

@kilrau kilrau modified the milestones: 1.0.0-sprint.13, 1.0.0-sprint.14 Apr 16, 2019
@sangaman
Copy link
Collaborator

don't see how this can happen, then they should have matched before already. Note: as I described it, we don't allow any old or new peer orders or new own orders (place orders) while swap client is disconnected.

When we request the orders from peers that we missed while we weren't accepting orders, we could get orders that match the orders we put aside. But they will both be "maker" orders in this case.

@kilrau
Copy link
Contributor Author

kilrau commented Apr 19, 2019

But they will both be "maker" orders in this case.

Now I understand what you mean. Yes there can be a price match but there won't be a match/swap triggered, because OwnOrder maker orders are already in the order book before we start accept peer orders again. So all good I guess?

@sangaman
Copy link
Collaborator

Yup I think so.

@kilrau
Copy link
Contributor Author

kilrau commented Apr 27, 2019

Dependent on @erkarl 's SubscribeAlerts call to be available: #864 (comment)

@kilrau kilrau modified the milestones: 1.0.0-sprint.14, 1.0.0-sprint.15, 1.0.0-sprint.16 Apr 29, 2019
@kilrau kilrau modified the milestones: 1.0.0-sprint.16, 1.0.0 May 8, 2019
@kilrau
Copy link
Contributor Author

kilrau commented May 8, 2019

Ensuring lnd and raiden are up can be done by docker, above dependency SubscribeAlerts moved to post-1.0.0, this one should be one in conjunction with https://github.com/ExchangeUnion/xud/issues/891 in post-1.0.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lightning Lightning network & lnd integration P2 mid priority
Projects
None yet
Development

No branches or pull requests

3 participants