1
0

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.
This commit is contained in:
SomberNight
2021-03-26 20:43:26 +01:00
parent 63ea5587a2
commit 9e62d1d763
2 changed files with 6 additions and 3 deletions

View File

@@ -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))

View File

@@ -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)