Browse Source

MPP: can_send/can_receive is now the sum, no longer the max

patch-4
ThomasV 4 years ago
parent
commit
0369829e5e
  1. 17
      electrum/gui/qt/channels_list.py
  2. 3
      electrum/lnchannel.py
  3. 14
      electrum/lnworker.py

17
electrum/gui/qt/channels_list.py

@ -32,15 +32,17 @@ class ChannelsList(MyTreeView):
class Columns(IntEnum):
SHORT_CHANID = 0
NODE_ALIAS = 1
LOCAL_BALANCE = 2
REMOTE_BALANCE = 3
CHANNEL_STATUS = 4
CAPACITY = 2
LOCAL_BALANCE = 3
REMOTE_BALANCE = 4
CHANNEL_STATUS = 5
headers = {
Columns.SHORT_CHANID: _('Short Channel ID'),
Columns.NODE_ALIAS: _('Node alias'),
Columns.LOCAL_BALANCE: _('Local'),
Columns.REMOTE_BALANCE: _('Remote'),
Columns.CAPACITY: _('Capacity'),
Columns.LOCAL_BALANCE: _('Can send'),
Columns.REMOTE_BALANCE: _('Can receive'),
Columns.CHANNEL_STATUS: _('Status'),
}
@ -69,8 +71,8 @@ class ChannelsList(MyTreeView):
def format_fields(self, chan):
labels = {}
for subject in (REMOTE, LOCAL):
bal_minus_htlcs = chan.balance_minus_outgoing_htlcs(subject)//1000
label = self.parent.format_amount(bal_minus_htlcs)
can_send = chan.available_to_spend(subject) / 1000
label = self.parent.format_amount(can_send)
other = subject.inverted()
bal_other = chan.balance(other)//1000
bal_minus_htlcs_other = chan.balance_minus_outgoing_htlcs(other)//1000
@ -83,6 +85,7 @@ class ChannelsList(MyTreeView):
return [
chan.short_id_for_GUI(),
node_alias,
self.parent.format_amount(chan.constraints.capacity),
'' if closed else labels[LOCAL],
'' if closed else labels[REMOTE],
status

3
electrum/lnchannel.py

@ -1086,9 +1086,6 @@ class Channel(AbstractChannel):
sender = subject
receiver = subject.inverted()
initiator = LOCAL if self.constraints.is_initiator else REMOTE # the initiator/funder pays on-chain fees
is_frozen = self.is_frozen_for_sending() if subject == LOCAL else self.is_frozen_for_receiving()
if not self.is_active() or is_frozen:
return 0
def consider_ctx(*, ctx_owner: HTLCOwner, is_htlc_dust: bool) -> int:
ctn = self.get_next_ctn(ctx_owner)

14
electrum/lnworker.py

@ -1774,20 +1774,22 @@ class LNWallet(LNWorker):
for chan in self.channels.values())) / 1000
def num_sats_can_send(self) -> Decimal:
send_values = [Decimal(0)]
can_send = Decimal(0)
with self.lock:
if self.channels:
for c in self.channels.values():
send_values.append(Decimal(c.available_to_spend(LOCAL)) / 1000)
return max(send_values)
if c.is_active() and not c.is_frozen_for_sending():
can_send += Decimal(c.available_to_spend(LOCAL)) / 1000
return can_send
def num_sats_can_receive(self) -> Decimal:
receive_values = [Decimal(0)]
can_receive = Decimal(0)
with self.lock:
if self.channels:
for c in self.channels.values():
receive_values.append(Decimal(c.available_to_spend(REMOTE)) / 1000)
return max(receive_values)
if c.is_active() and not c.is_frozen_for_receiving():
can_receive += Decimal(c.available_to_spend(REMOTE)) / 1000
return can_receive
def can_pay_invoice(self, invoice: LNInvoice) -> bool:
return invoice.get_amount_sat() <= self.num_sats_can_send()

Loading…
Cancel
Save