From 284ef128afbfabd0b08ff5d6c23541b343ce6220 Mon Sep 17 00:00:00 2001 From: Richard Holzeis Date: Wed, 30 Aug 2023 13:22:57 +0200 Subject: [PATCH] fix: Add buffer delay after outbound capacity is ready It could happen that the channel already shows outbound capacity due to the received payment, but the channel updates are not completely finished yet. We suspect that this could lead to issues when trying to pay the JIT channel opening fees at the same time. Resulting in force closures or worst case and unresponsive app (deadlock?). By waiting additional 500 milliseconds after the outbound capacity is set, we hopefully prevent paying an invoice while the channel is still updated. --- mobile/native/src/channel_fee.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/mobile/native/src/channel_fee.rs b/mobile/native/src/channel_fee.rs index fec790c29..13dbe26f2 100644 --- a/mobile/native/src/channel_fee.rs +++ b/mobile/native/src/channel_fee.rs @@ -79,8 +79,15 @@ impl ChannelFeePaymentSubscriber { funding_tx_fees_msats, "Waiting for outbound capacity on channel to pay jit channel opening fee.", ); - Handle::current() - .block_on(self.wait_for_outbound_capacity(channel_id, funding_tx_fees_msats)) + Handle::current().block_on(async { + self.wait_for_outbound_capacity(channel_id, funding_tx_fees_msats) + .await?; + // We add another sleep to ensure that the channel has actually been updated after + // receiving the payment. Note, this is by no means ideal and should + // be revisited some other time. + tokio::time::sleep(Duration::from_millis(500)).await; + anyhow::Ok(()) + }) }) .context("Failed during wait for outbound capacity")?;