Skip to content

swaps: Improve accuracy of swapserver liquidity announcement. #9740

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

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

Conversation

f321x
Copy link
Member

@f321x f321x commented Apr 16, 2025

Adds event handler and more calls to the liquidity update trigger to ensure that changes in liquidity will get published more reliably right after the transitions changing the liquidity happen.

@@ -479,6 +484,7 @@ async def hold_invoice_callback(self, payment_hash: bytes) -> None:
output = self.create_funding_output(swap)
self.wallet.txbatcher.add_payment_output('swaps', output, self.config.FEE_POLICY_SWAPS)
swap._payment_pending = True
self.server_maybe_trigger_liquidity_update()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be triggered by htlc added/settled in lnwatcher?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this would make sense yes, however i intended to keep the liquidity update logic contained in submarine_swaps.py. I now found a more accurate solution by using the event callbacks on_event_channel and on_event_new_transaction.
on_event_channels triggers for essentially all interesting channel changes that could change the available liquidity.

async def trigger_update():
# some sleep makes this more reliable as the trigger may is called close to the
# action that is supposed to change the liquidity, but the action can take some time to
# complete and change the available liquidity data (e.g. settling htlcs after preimage got added)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this sounds like a reason to trigger the update on channel htlc changes...

Copy link
Member Author

@f321x f321x May 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, see fix in other comment. I would still keep the sleep though as the liquidity update is not very time critical and it allows to call server_maybe_trigger_liquidity_update() on any changes without risking to get rate limited by relays or wasting resources on recalculating the amounts very often.

Adds event handler and more calls to the liquidity update trigger to
ensure that changes in liquidity will get published more reliably.
@f321x f321x force-pushed the update_swap_liquidity_on_events branch from 5247551 to 0f75cc1 Compare May 8, 2025 09:51
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.

2 participants