Closed kilrau closed 4 years ago
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.
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.
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:
maxBuy
& maxSell
to iterating through channels (currently we are using lnd's channelbalance
for maxSell
I believe)maxBuy
& maxSell
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?
And for fee calculation I'm not sure how to handle it, can somebody please guide me?
Channel reserve is already accounted for by now (see https://github.com/ExchangeUnion/xud/pull/1988#issuecomment-724897010) and pre-calculating routing fees is hardly possible so I am closing here.
EDIT: renamed this issue, new goal below.
LND
0.12
will return inbound balance with thechannelbalance
call. Since this is considerably more efficient and accurate than our current "iterate through lnd'slistchannels
" approach, we should move to this call too once lndbtc & lndltc 0.12 are released.Also I just double checked the following:
channelbalance
is simply alllocal_balance
fields of all channels accumulatedchannelbalance
include allremote_balance
fields of all channels accumulated with the PR above.Here is the but: lnd's
local_balance
andremote_balance
subtract thecommit_fee
, but not the channel reservechan_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?