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

Make tradinglimits account for lightning chan reserve #1945

Closed
kilrau opened this issue Oct 20, 2020 · 6 comments
Closed

Make tradinglimits account for lightning chan reserve #1945

kilrau opened this issue Oct 20, 2020 · 6 comments
Assignees
Labels
enhancement New feature or request lightning Lightning network & lnd integration P3 low priority

Comments

@kilrau
Copy link
Contributor

kilrau commented Oct 20, 2020

EDIT: renamed this issue, new goal below.

LND 0.12 will return inbound balance with the channelbalance call. Since this is considerably more efficient and accurate than our current "iterate through lnd's listchannels" approach, we should move to this call too once lndbtc & lndltc 0.12 are released.

Also I just double checked the following:

  • lnd's channelbalance is simply all local_balance fields of all channels accumulated
  • same way does channelbalance include all remote_balance fields of all channels accumulated with the PR above.

Here is the but: lnd's local_balance and remote_balance subtract the commit_fee, but not the channel reserve chan_reserve_sat which is essentially non-usable balance. Question is: do we want to manually subtract channel reserves from our local and remote balances to give the user a correct picture of what balance is actually usable?

@kilrau kilrau added enhancement New feature or request lightning Lightning network & lnd integration P3 low priority labels Oct 20, 2020
@raladev
Copy link
Contributor

raladev commented Oct 20, 2020

Question is: do we want to manually subtract channel reserves from our local and remote balances to give the user a correct picture of what balance is actually usable?

Im for providing this value, because it can be big enough.

@sangaman
Copy link
Collaborator

do we want to manually subtract channel reserves from our local and remote balances to give the user a correct picture of what balance is actually usable?

I think it makes sense to subtract channel reserves since it is non tradeable balance. However, to do so wouldn't we still need to iterate through the list of channels?

Also, do we actually know that this new approach would be more efficient or accurate than iterating through the list of channels? I don't know why our current approach wouldn't be accurate, and my guess would be it's at least roughly the same in terms of efficiency - either way it's not computationally expensive to iterate through a list of up to a couple dozen channels.

@kilrau
Copy link
Contributor Author

kilrau commented Oct 21, 2020

I think it makes sense to subtract channel reserves since it is non tradeable balance. However, to do so wouldn't we still need to iterate through the list of channels?

Yes, that's why I brought it up. The new lnd channelbalance doesn't include something like total inbound/outbound chan reserve fields...

Also, do we actually know that this new approach would be more efficient or accurate than iterating through the list of channels? I don't know why our current approach wouldn't be accurate, and my guess would be it's at least roughly the same in terms of efficiency - either way it's not computationally expensive to iterate through a list of up to a couple dozen channels.

Yep, for us even more accurate since we'd exclude channel reserve.

Summary of the todo's:

@kilrau kilrau changed the title Move tradinglimits maxBuy to new lnd call Make tradinglimits accurate Oct 21, 2020
@rsercano
Copy link
Collaborator

move tradinglimits' maxBuy & maxSell to iterating through channels (currently we are using lnd's channelbalance for maxSell I believe)

Currently we're already iterating through channels for lnd, correct me if I'm mistaken @sangaman.

subtract chan reserve from tradinglimits' maxBuy & maxSell

And currently that's how maxSell & maxBuy is being calculated:

const swapCapacities = await swapClient.swapCapacities(currency);
      const reservedOutbound = this.outboundReservedAmounts.get(currency) ?? 0;
      const reservedInbound = this.inboundReservedAmounts.get(currency) ?? 0;
      const availableOutboundCapacity = Math.max(0, swapCapacities.totalOutboundCapacity - reservedOutbound);
      const availableInboundCapacity = Math.max(0, swapCapacities.totalInboundCapacity - reservedInbound);

      return {
        reservedOutbound,
        reservedInbound,
        maxSell: Math.min(swapCapacities.maxOutboundChannelCapacity, availableOutboundCapacity),
        maxBuy: Math.min(swapCapacities.maxInboundChannelCapacity, availableInboundCapacity),
      };

In here while calculating available outbound & inbound capacities we're subtracting reserved amounts?

@kilrau kilrau changed the title Make tradinglimits accurate Make tradinglimits account for lightning chan reserve & routing fees Oct 21, 2020
@rsercano
Copy link
Collaborator

And for fee calculation I'm not sure how to handle it, can somebody please guide me?

@kilrau kilrau changed the title Make tradinglimits account for lightning chan reserve & routing fees Make tradinglimits account for lightning chan reserve Nov 10, 2020
@kilrau
Copy link
Contributor Author

kilrau commented Nov 10, 2020

Channel reserve is already accounted for by now (see #1988 (comment)) and pre-calculating routing fees is hardly possible so I am closing here.

@kilrau kilrau closed this as completed Nov 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request lightning Lightning network & lnd integration P3 low priority
Projects
None yet
Development

No branches or pull requests

4 participants