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

Refactor swap-in trigger mechanism #483

Merged
merged 2 commits into from
Jun 23, 2023
Merged

Refactor swap-in trigger mechanism #483

merged 2 commits into from
Jun 23, 2023

Conversation

t-bast
Copy link
Member

@t-bast t-bast commented Jun 20, 2023

We create a new SwapInManager that checks the wallet state and decides whether to initiate a channel funding attempt, while keeping track of utxos that are currently being used.

We allow unlocking those utxos once a channel funding attempt fails because of a liquidity policy restriction.

src/commonMain/kotlin/fr/acinq/lightning/io/Peer.kt Outdated Show resolved Hide resolved
@@ -774,6 +773,7 @@ class Peer(
nodeParams.liquidityPolicy.value.maybeReject(request.walletInputs.balance.toMilliSatoshi(), totalFee, LiquidityEvents.Source.OnChainWallet, logger)?.let { rejected ->
logger.info { "rejecting open_channel2: reason=${rejected.reason}" }
nodeParams._nodeEvents.emit(rejected)
input.send(WalletCommand.UnlockWalletInputs(request.walletInputs.map { it.outPoint }.toSet()))
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm currently only unlocking utxos when funding attempts are rejected by our liquidity policy, but we could also unlock them if the funding fails later in the process, by having the corresponding channel state add a new action to unlock the inputs it was using. Do you think it's worth doing in this PR?

@dpad85
Copy link
Member

dpad85 commented Jun 20, 2023

I could test this successfully. However the UX is still not optimal on Phoenix's side even with these changes, and since we are not able to test properly, I think the best course of action is to pause this PR and come back later, when we have more time.

In the meantime, on Phoenix we can simply provide instructions that the app needs to be restarted. It's not ideal, but it's safe.

@t-bast
Copy link
Member Author

t-bast commented Jun 21, 2023

However the UX is still not optimal on Phoenix's side even with these changes, and since we are not able to test properly, I think the best course of action is to pause this PR and come back later, when we have more time.

That sounds reasonable. I removed the part where we retry on liquidity policy changes in a0b96b8: the PR is now a simple refactoring of the swap-in triggering mechanism, with the addition of unlocking utxos that were not used because of a liquidity policy rejection.

I think we should merge this PR, as it lets us unit test the SwapInManager, and the utxo unlock is desirable in the following scenario:

  • the user sends two transactions to his swap address, a small one and a large one
  • once the first one confirms, its amount is too small and the liquidity policy stops the splice attempt
  • once the second one confirms, the sum of both transactions should be allowed by the liquidity policy
  • without the change in this PR, the first transaction will be ignored and we will only attempt to splice with the second one, which is wasteful and hard to understand for the user

What do you think?

@t-bast t-bast changed the title Retry swaps on liquidity policy update Refactor swap-in trigger mechanism Jun 21, 2023
We create a new `SwapInManager` that checks the wallet state and decides
whether to initiate a channel funding attempt, while keeping track of
utxos that are currently being used.

We allow unlocking those utxos once a channel funding attempt fails,
which ensures that if we retry later (because another input is confirmed)
we will reuse the previously failed inputs (instead of waiting for a
restart to use them).
pm47
pm47 previously approved these changes Jun 23, 2023
@t-bast t-bast merged commit 3b8f8ef into master Jun 23, 2023
2 checks passed
@t-bast t-bast deleted the swap-in-retry branch June 23, 2023 11:44
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