commit c65974b7d0f908d9e1fb893963a001cb4d9177cf
parent b08f9f3581794b32c5c34a1a8433a47beb20c152
Author: ThomasV <thomasv@electrum.org>
Date: Fri, 18 Dec 2020 11:25:10 +0100
Merge pull request #6865 from bitromortac/num-sats-can-send-receive
lnchannel: reflect frozen amounts and disconnected peers
Diffstat:
2 files changed, 18 insertions(+), 7 deletions(-)
diff --git a/electrum/lnchannel.py b/electrum/lnchannel.py
@@ -530,6 +530,9 @@ class Channel(AbstractChannel):
def is_initiator(self):
return self.constraints.is_initiator
+ def is_active(self):
+ return self.get_state() == ChannelState.OPEN and self.peer_state == PeerState.GOOD
+
def funding_txn_minimum_depth(self):
return self.constraints.funding_txn_minimum_depth
diff --git a/electrum/lnworker.py b/electrum/lnworker.py
@@ -1376,15 +1376,23 @@ class LNWallet(LNWorker):
return Decimal(sum(chan.balance(LOCAL) if not chan.is_closed() else 0
for chan in self.channels.values())) / 1000
- def num_sats_can_send(self) -> Union[Decimal, int]:
+ def num_sats_can_send(self) -> Decimal:
+ send_values = [Decimal(0)]
with self.lock:
- return Decimal(max(chan.available_to_spend(LOCAL) if chan.is_open() else 0
- for chan in self.channels.values()))/1000 if self.channels else 0
-
- def num_sats_can_receive(self) -> Union[Decimal, int]:
+ if self.channels:
+ for c in self.channels.values():
+ if c.is_active() and not c.is_frozen_for_sending():
+ send_values.append(Decimal(c.available_to_spend(LOCAL)) / 1000)
+ return max(send_values)
+
+ def num_sats_can_receive(self) -> Decimal:
+ receive_values = [Decimal(0)]
with self.lock:
- return Decimal(max(chan.available_to_spend(REMOTE) if chan.is_open() else 0
- for chan in self.channels.values()))/1000 if self.channels else 0
+ if self.channels:
+ for c in self.channels.values():
+ if c.is_active() and not c.is_frozen_for_receiving():
+ receive_values.append(Decimal(c.available_to_spend(REMOTE)) / 1000)
+ return max(receive_values)
def can_pay_invoice(self, invoice: LNInvoice) -> bool:
return invoice.get_amount_sat() <= self.num_sats_can_send()