Browse Source

swaps: (fix) for forward swaps, correctly consider num_sats_can_receive

Previously the min() was passed lightning amounts and on-chain amounts mixed;
which is conceptually a type error. It is now only passed on-chain amounts.
Due to the bug, we did not allow a swap to fully exhaust out "LN receive" capacity.
Now the max amt can be slighly larger.
patch-4
SomberNight 4 years ago
parent
commit
9e62d1d763
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 4
      electrum/gui/kivy/uix/dialogs/lightning_channels.py
  2. 5
      electrum/gui/qt/swap_dialog.py

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

@ -726,7 +726,9 @@ 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.swap_manager.num_sats_can_receive(),
max_recv_amt_ln = int(self.swap_manager.num_sats_can_receive())
max_recv_amt_oc = self.swap_manager.get_send_amount(max_recv_amt_ln, is_reverse=False) or float('inf')
forward = int(min(max_recv_amt_oc,
# maximally supported swap amount by provider
self.swap_manager.get_max_amount(),
max_onchain_spend))

5
electrum/gui/qt/swap_dialog.py

@ -126,8 +126,9 @@ 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.swap_manager.num_sats_can_receive())
max_amt = min(max_swap_amt, max_recv_amt)
max_recv_amt_ln = int(self.swap_manager.num_sats_can_receive())
max_recv_amt_oc = self.swap_manager.get_send_amount(max_recv_amt_ln, is_reverse=False) or float('inf')
max_amt = int(min(max_swap_amt, max_recv_amt_oc))
if amount > max_amt:
amount = max_amt
self._update_tx(amount)

Loading…
Cancel
Save