Skip to content

Commit

Permalink
Check swap-in wallet at each block (#515)
Browse files Browse the repository at this point in the history
The `WalletState` class contains absolute blockheights for utxos, and does not contain the current block height, so it is constant as soon as an utxo confirms. Even if `ElectrumMiniWallet` explicitly updated  `_walletStateFlow` (which it doesn't), it would be ignored because `MutableStateFlow` deduplicates events.

We need to look for swap-ins when either the wallet state or the current blockheight changes, otherwise we will only call `TrySwapIn` when the utxo reaches `weak` confirmation, and not when it graduates from `weak` to `deep` confirmation.
  • Loading branch information
pm47 authored Aug 18, 2023
1 parent fa58d67 commit ca32ad7
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/commonMain/kotlin/fr/acinq/lightning/io/Peer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -388,11 +388,10 @@ class Peer(
}

private suspend fun watchSwapInWallet() {
swapInWallet.walletStateFlow
.filter { it.consistent }
.collect {
val currentBlockHeight = currentTipFlow.filterNotNull().first().first
swapInCommands.send(SwapInCommand.TrySwapIn(currentBlockHeight, it, walletParams.swapInConfirmations, trustedSwapInTxs))
swapInWallet.walletStateFlow.combine(currentTipFlow.filterNotNull()) { walletState, currentTip -> currentTip.first to walletState }
.filter { (_, walletState) -> walletState.consistent }
.collect { (currentBlockHeight, walletState) ->
swapInCommands.send(SwapInCommand.TrySwapIn(currentBlockHeight, walletState, walletParams.swapInConfirmations, trustedSwapInTxs))
}
}

Expand Down

0 comments on commit ca32ad7

Please sign in to comment.