submarine swaps: use num_sats_can_receive_no_mpp, to prevent funds being locked
This commit is contained in:
@@ -726,7 +726,7 @@ class SwapDialog(Factory.Popup):
|
|||||||
max_onchain_spend = 0
|
max_onchain_spend = 0
|
||||||
reverse = int(min(self.lnworker.num_sats_can_send(),
|
reverse = int(min(self.lnworker.num_sats_can_send(),
|
||||||
self.swap_manager.get_max_amount()))
|
self.swap_manager.get_max_amount()))
|
||||||
forward = int(min(self.lnworker.num_sats_can_receive(),
|
forward = int(min(self.swap_manager.num_sats_can_receive(),
|
||||||
# maximally supported swap amount by provider
|
# maximally supported swap amount by provider
|
||||||
self.swap_manager.get_max_amount(),
|
self.swap_manager.get_max_amount(),
|
||||||
max_onchain_spend))
|
max_onchain_spend))
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ class SwapDialog(WindowModalDialog):
|
|||||||
if self.tx:
|
if self.tx:
|
||||||
amount = self.tx.output_value_for_address(ln_dummy_address())
|
amount = self.tx.output_value_for_address(ln_dummy_address())
|
||||||
max_swap_amt = self.swap_manager.get_max_amount()
|
max_swap_amt = self.swap_manager.get_max_amount()
|
||||||
max_recv_amt = int(self.lnworker.num_sats_can_receive())
|
max_recv_amt = int(self.swap_manager.num_sats_can_receive())
|
||||||
max_amt = min(max_swap_amt, max_recv_amt)
|
max_amt = min(max_swap_amt, max_recv_amt)
|
||||||
if amount > max_amt:
|
if amount > max_amt:
|
||||||
amount = max_amt
|
amount = max_amt
|
||||||
@@ -149,7 +149,7 @@ class SwapDialog(WindowModalDialog):
|
|||||||
if self.is_reverse and send_amount and send_amount > self.lnworker.num_sats_can_send():
|
if self.is_reverse and send_amount and send_amount > self.lnworker.num_sats_can_send():
|
||||||
# cannot send this much on lightning
|
# cannot send this much on lightning
|
||||||
recv_amount = None
|
recv_amount = None
|
||||||
if (not self.is_reverse) and recv_amount and recv_amount > self.lnworker.num_sats_can_receive():
|
if (not self.is_reverse) and recv_amount and recv_amount > self.swap_manager.num_sats_can_receive():
|
||||||
# cannot receive this much on lightning
|
# cannot receive this much on lightning
|
||||||
recv_amount = None
|
recv_amount = None
|
||||||
self.recv_amount_e.follows = True
|
self.recv_amount_e.follows = True
|
||||||
@@ -228,7 +228,7 @@ class SwapDialog(WindowModalDialog):
|
|||||||
onchain_amount = self.send_amount_e.get_amount()
|
onchain_amount = self.send_amount_e.get_amount()
|
||||||
if lightning_amount is None or onchain_amount is None:
|
if lightning_amount is None or onchain_amount is None:
|
||||||
return
|
return
|
||||||
if lightning_amount > self.lnworker.num_sats_can_receive():
|
if lightning_amount > self.swap_manager.num_sats_can_receive():
|
||||||
if not self.window.question(CANNOT_RECEIVE_WARNING):
|
if not self.window.question(CANNOT_RECEIVE_WARNING):
|
||||||
return
|
return
|
||||||
self.window.protect(self.do_normal_swap, (lightning_amount, onchain_amount))
|
self.window.protect(self.do_normal_swap, (lightning_amount, onchain_amount))
|
||||||
|
|||||||
@@ -1951,6 +1951,15 @@ class LNWallet(LNWorker):
|
|||||||
can_receive += c.available_to_spend(REMOTE)
|
can_receive += c.available_to_spend(REMOTE)
|
||||||
return Decimal(can_receive) / 1000
|
return Decimal(can_receive) / 1000
|
||||||
|
|
||||||
|
def num_sats_can_receive_no_mpp(self) -> Decimal:
|
||||||
|
with self.lock:
|
||||||
|
if self.channels:
|
||||||
|
can_receive = max([
|
||||||
|
c.available_to_spend(REMOTE) for c in self.channels.values()
|
||||||
|
if c.is_active() and not c.is_frozen_for_receiving()
|
||||||
|
])
|
||||||
|
return Decimal(can_receive) / 1000
|
||||||
|
|
||||||
def can_pay_invoice(self, invoice: LNInvoice) -> bool:
|
def can_pay_invoice(self, invoice: LNInvoice) -> bool:
|
||||||
return invoice.get_amount_sat() <= self.num_sats_can_send()
|
return invoice.get_amount_sat() <= self.num_sats_can_send()
|
||||||
|
|
||||||
|
|||||||
@@ -225,6 +225,11 @@ 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,
|
||||||
*,
|
*,
|
||||||
|
|||||||
Reference in New Issue
Block a user