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

Try swap-in on liquidity policy changes #548

Merged
merged 2 commits into from
Oct 19, 2023

Conversation

t-bast
Copy link
Member

@t-bast t-bast commented Oct 2, 2023

We previously tried swapping funds in:

  • at start-up
  • when our wallet state was updated
  • when a new block was found

We now also check for swaps when the liquidity policy changes or the swap feerate changes.

Since this all happens inside the Peer, we don't have good ways of unit testing it. Should we start refactoring the Peer to allow more unit testing? This will be a bit painful because of all the internal channels and flows, but may be beneficial?

We previously tried swapping funds in:

- at start-up
- when our wallet state was updated
- when a new block was found

We now also check for swaps when the liquidity policy changes or the swap
feerate changes.
@t-bast t-bast requested review from pm47 and dpad85 October 2, 2023 09:56
We can use the `replyTo` field to explicitly handle every failure in the
splice negotiation.
Comment on lines +1028 to +1033
// If the splice fails, we immediately unlock the utxos to reuse them in the next attempt.
spliceCommand.replyTo.invokeOnCompletion { ex ->
if (ex == null && spliceCommand.replyTo.getCompleted() is ChannelCommand.Commitment.Splice.Response.Failure) {
swapInCommands.trySend(SwapInCommand.UnlockWalletInputs(cmd.walletInputs.map { it.outPoint }.toSet()))
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Nice, I envisoned something more like:

launch {
  val res = spliceCommand.replyTo.await()
  if (res is ChannelCommand.Commitment.Splice.Response.Failure) {
    swapInCommands.trySend(SwapInCommand.UnlockWalletInputs(cmd.walletInputs.map { it.outPoint }.toSet()))
  }
}

But your approach has the advantage of being synchronous and removes complications around the CoroutineScope.

@t-bast t-bast merged commit 56ade7e into master Oct 19, 2023
2 checks passed
@t-bast t-bast deleted the try-swap-liquidity-policy-change branch October 19, 2023 15:29
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