lnworker: do not assume MPP in num_sats_can_receive
This commit is contained in:
@@ -2161,11 +2161,9 @@ class LNWallet(LNWorker):
|
|||||||
return channels
|
return channels
|
||||||
|
|
||||||
def num_sats_can_receive(self, deltas=None) -> Decimal:
|
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)
|
We no longer assume the sender to send MPP on different channels,
|
||||||
|
because channel liquidities are hard to guess
|
||||||
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.
|
|
||||||
"""
|
"""
|
||||||
if deltas is None:
|
if deltas is None:
|
||||||
deltas = {}
|
deltas = {}
|
||||||
@@ -2182,12 +2180,10 @@ class LNWallet(LNWorker):
|
|||||||
recv_chan_msats = [recv_capacity(chan) for chan in recv_channels]
|
recv_chan_msats = [recv_capacity(chan) for chan in recv_channels]
|
||||||
if not recv_chan_msats:
|
if not recv_chan_msats:
|
||||||
return Decimal(0)
|
return Decimal(0)
|
||||||
can_receive_msat = max(
|
can_receive_msat = max(recv_chan_msats)
|
||||||
max(recv_chan_msats), # single-part payment baseline
|
|
||||||
sum(recv_chan_msats) // 2, # heuristic for MPP
|
|
||||||
)
|
|
||||||
return Decimal(can_receive_msat) / 1000
|
return Decimal(can_receive_msat) / 1000
|
||||||
|
|
||||||
|
|
||||||
def _suggest_channels_for_rebalance(self, direction, amount_sat) -> Sequence[Tuple[Channel, int]]:
|
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
|
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(
|
return await self.pay_invoice(
|
||||||
invoice, channels=[chan1])
|
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:
|
def can_receive_invoice(self, invoice: Invoice) -> bool:
|
||||||
assert invoice.is_lightning()
|
assert invoice.is_lightning()
|
||||||
return (invoice.get_amount_sat() or 0) <= self.num_sats_can_receive()
|
return (invoice.get_amount_sat() or 0) <= self.num_sats_can_receive()
|
||||||
|
|||||||
@@ -241,11 +241,6 @@ class SwapManager(Logger):
|
|||||||
callback = lambda: self._claim_swap(swap)
|
callback = lambda: self._claim_swap(swap)
|
||||||
self.lnwatcher.add_callback(swap.lockup_address, callback)
|
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(
|
async def normal_swap(
|
||||||
self,
|
self,
|
||||||
*,
|
*,
|
||||||
@@ -678,7 +673,7 @@ class SwapManager(Logger):
|
|||||||
def max_amount_forward_swap(self) -> Optional[int]:
|
def max_amount_forward_swap(self) -> Optional[int]:
|
||||||
""" returns None if we cannot swap """
|
""" returns None if we cannot swap """
|
||||||
max_swap_amt_ln = self.get_max_amount()
|
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_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
|
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
|
min_amt_oc = self.get_send_amount(self.get_min_amount(), is_reverse=False) or 0
|
||||||
|
|||||||
Reference in New Issue
Block a user