Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

swaps: Announce available liquidity instead of static maximum value #9660

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

f321x
Copy link
Member

@f321x f321x commented Mar 21, 2025

Makes swap provider announce the actual available liquidity for forward and reverse swaps instead of a static hardcoded max value. This should increase reliability of swaps as clients will know upfront if the provider even has enough liquidity to fulfill their request.

@ecdsa ecdsa added this to the 4.6.0 milestone Mar 21, 2025
@f321x f321x force-pushed the swap_announce_liquidity branch 3 times, most recently from 5cf215d to e1a4453 Compare March 22, 2025 11:26
@accumulator
Copy link
Member

using the exact onchain balance as available liquidity might pose a privacy risk, as it might correlate UTXOs to the swap provider without initiating a swap (passive observers)

@f321x
Copy link
Member Author

f321x commented Mar 25, 2025

In server_update_pairs() i round down to the next 1000 sat:

        oc_balance = sum([coin.value_sats() for coin in self.wallet.get_spendable_coins()])
        max_forward = min(int(self.lnworker.num_sats_can_receive()), oc_balance, 10000000)
        max_reverse = min(int(self.lnworker.num_sats_can_send()), 10000000)
        self._max_forward = (max_forward // 1000) * 1000
        self._max_reverse = (max_reverse // 1000) * 1000

e.g. changing 984323 to 984000. We could also randomly round down in a specified range... Let me know if you have any more ideas how we could improve privacy for providers without reducing functionality.

@accumulator
Copy link
Member

Maybe zero out after 1 or 2 significant numbers, e.g. 984323 -> 900000 or 980000

Also, maybe there's also a case to be made to offer at most 50% of available balance, to be able to service 2 clients if balance is below 10Msat cutoff point.

Maybe the anchors UTXO reserve also should be taken into account? (haven't checked)

@f321x f321x force-pushed the swap_announce_liquidity branch from e1a4453 to 94b1d5c Compare March 26, 2025 10:51
@f321x
Copy link
Member Author

f321x commented Mar 26, 2025

I changed it to reduce the precision of the announced amounts to 2 leading digits, and deduct the anchor reserve, if required, when calculating the available onchain amount.

Also, maybe there's also a case to be made to offer at most 50% of available balance, to be able to service 2 clients if balance is below 10Msat cutoff point.

I'm not sure how this improves the usability, the provider announces the new liquidity as soon as it changed, so the other clients see what is still available. I imagine it could prevent one rejected swap if two clients request a swap > 50% of the available liquidity at the same time (which should happen rarely), but at the same time it would also prevent clients from requesting swaps > 50% even if the provider could satisfy the swap easily (which probably happens more often in practice).

@accumulator
Copy link
Member

I'm not sure how this improves the usability, the provider announces the new liquidity as soon as it changed, so the other clients see what is still available. I imagine it could prevent one rejected swap if two clients request a swap > 50% of the available liquidity at the same time (which should happen rarely), but at the same time it would also prevent clients from requesting swaps > 50% even if the provider could satisfy the swap easily (which probably happens more often in practice).

Yeah I agree it's probably not that useful. The thinking was, as the available liquidity is fetched once before entering the swap dialog, there might be a liquidity reduction in the time between liquidity info fetch and doing the actual swap (it's not live-updated)..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants