From 72fb43f950815ef7a655c39f47610c835ac155d0 Mon Sep 17 00:00:00 2001 From: ThomasV Date: Sat, 25 Feb 2023 12:23:34 +0100 Subject: [PATCH] lnworker: do not assume MPP in num_sats_can_receive --- electrum/lnworker.py | 23 +++++------------------ electrum/submarine_swaps.py | 7 +------ 2 files changed, 6 insertions(+), 24 deletions(-) diff --git a/electrum/lnworker.py b/electrum/lnworker.py index f83166df3..6dc9b32c6 100644 --- a/electrum/lnworker.py +++ b/electrum/lnworker.py @@ -2161,11 +2161,9 @@ class LNWallet(LNWorker): return channels def num_sats_can_receive(self, deltas=None) -> Decimal: - """Return a conservative estimate of max sat value we can realistically receive - in a single payment. (MPP is allowed) - - The theoretical max would be `sum(chan.available_to_spend(REMOTE) for chan in self.channels)`, - but that would require a sender using MPP to magically guess all our channel liquidities. + """ + We no longer assume the sender to send MPP on different channels, + because channel liquidities are hard to guess """ if deltas is None: deltas = {} @@ -2182,12 +2180,10 @@ class LNWallet(LNWorker): recv_chan_msats = [recv_capacity(chan) for chan in recv_channels] if not recv_chan_msats: return Decimal(0) - can_receive_msat = max( - max(recv_chan_msats), # single-part payment baseline - sum(recv_chan_msats) // 2, # heuristic for MPP - ) + can_receive_msat = max(recv_chan_msats) return Decimal(can_receive_msat) / 1000 + def _suggest_channels_for_rebalance(self, direction, amount_sat) -> Sequence[Tuple[Channel, int]]: """ Suggest a channel and amount to send/receive with that channel, so that we will be able to receive/send amount_sat @@ -2297,15 +2293,6 @@ class LNWallet(LNWorker): return await self.pay_invoice( invoice, channels=[chan1]) - def num_sats_can_receive_no_mpp(self) -> Decimal: - with self.lock: - channels = [ - c for c in self.channels.values() - if c.is_active() and not c.is_frozen_for_receiving() - ] - can_receive = max([c.available_to_spend(REMOTE) for c in channels]) if channels else 0 - return Decimal(can_receive) / 1000 - def can_receive_invoice(self, invoice: Invoice) -> bool: assert invoice.is_lightning() return (invoice.get_amount_sat() or 0) <= self.num_sats_can_receive() diff --git a/electrum/submarine_swaps.py b/electrum/submarine_swaps.py index cd62f98d8..55defd265 100644 --- a/electrum/submarine_swaps.py +++ b/electrum/submarine_swaps.py @@ -241,11 +241,6 @@ class SwapManager(Logger): callback = lambda: self._claim_swap(swap) self.lnwatcher.add_callback(swap.lockup_address, callback) - def num_sats_can_receive(self): - # finding how to do MPP is too hard for sender, - # might result in our coins being locked - return self.lnworker.num_sats_can_receive_no_mpp() - async def normal_swap( self, *, @@ -678,7 +673,7 @@ class SwapManager(Logger): def max_amount_forward_swap(self) -> Optional[int]: """ returns None if we cannot swap """ max_swap_amt_ln = self.get_max_amount() - max_recv_amt_ln = int(self.num_sats_can_receive()) + max_recv_amt_ln = int(self.lnworker.num_sats_can_receive()) max_amt_ln = int(min(max_swap_amt_ln, max_recv_amt_ln)) max_amt_oc = self.get_send_amount(max_amt_ln, is_reverse=False) or 0 min_amt_oc = self.get_send_amount(self.get_min_amount(), is_reverse=False) or 0