Browse Source

submarine swaps: use num_sats_can_receive_no_mpp, to prevent funds being locked

patch-4
ThomasV 4 years ago
parent
commit
41f22df26b
  1. 2
      electrum/gui/kivy/uix/dialogs/lightning_channels.py
  2. 6
      electrum/gui/qt/swap_dialog.py
  3. 9
      electrum/lnworker.py
  4. 5
      electrum/submarine_swaps.py

2
electrum/gui/kivy/uix/dialogs/lightning_channels.py

@ -726,7 +726,7 @@ class SwapDialog(Factory.Popup):
max_onchain_spend = 0
reverse = int(min(self.lnworker.num_sats_can_send(),
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
self.swap_manager.get_max_amount(),
max_onchain_spend))

6
electrum/gui/qt/swap_dialog.py

@ -126,7 +126,7 @@ class SwapDialog(WindowModalDialog):
if self.tx:
amount = self.tx.output_value_for_address(ln_dummy_address())
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)
if 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():
# cannot send this much on lightning
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
recv_amount = None
self.recv_amount_e.follows = True
@ -228,7 +228,7 @@ class SwapDialog(WindowModalDialog):
onchain_amount = self.send_amount_e.get_amount()
if lightning_amount is None or onchain_amount is None:
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):
return
self.window.protect(self.do_normal_swap, (lightning_amount, onchain_amount))

9
electrum/lnworker.py

@ -1951,6 +1951,15 @@ class LNWallet(LNWorker):
can_receive += c.available_to_spend(REMOTE)
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:
return invoice.get_amount_sat() <= self.num_sats_can_send()

5
electrum/submarine_swaps.py

@ -225,6 +225,11 @@ 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,
*,

Loading…
Cancel
Save