-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
base: master
Are you sure you want to change the base?
Conversation
electrum/submarine_swaps.py
Outdated
@@ -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() |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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.
5247551
to
0f75cc1
Compare
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.