Skip to content

Commit

Permalink
Merge pull request #2197 from get10101/feat/sync-app-channels-during-…
Browse files Browse the repository at this point in the history
…wallet-refresh

Run DLC channels checks during wallet refresh
  • Loading branch information
luckysori committed Mar 8, 2024
2 parents 94a85cd + 7c0cc5d commit 80c315e
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 24 deletions.
10 changes: 0 additions & 10 deletions crates/tests-e2e/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,6 @@ pub fn refresh_wallet_info() {
block_in_place(move || api::refresh_wallet_info().unwrap());
}

/// Run periodic checks on the DLC channels, including syncing them with the blockchain.
///
/// To call this make sure that you are either outside of a runtime or in a multi-threaded runtime
/// (i.e. use `flavor = "multi_thread"` in a `tokio::test`).
pub fn sync_dlc_channels() {
// We must `block_in_place` because calling `sync_dlc_channels` starts a new runtime and that
// cannot happen within another runtime.
block_in_place(move || api::sync_dlc_channels().unwrap());
}

/// Force close DLC channel.
///
/// To call this make sure that you are either outside of a runtime or in a multi-threaded runtime
Expand Down
6 changes: 1 addition & 5 deletions crates/tests-e2e/src/setup.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::app::refresh_wallet_info;
use crate::app::run_app;
use crate::app::submit_channel_opening_order;
use crate::app::sync_dlc_channels;
use crate::app::AppHandle;
use crate::bitcoind::Bitcoind;
use crate::coordinator::Coordinator;
Expand Down Expand Up @@ -141,12 +140,9 @@ impl TestSetup {

tokio::time::sleep(std::time::Duration::from_secs(10)).await;

// Includes an on-chain sync.
// Includes on-chain sync and DLC channels sync.
refresh_wallet_info();

// Relies on the on-chain sync to be able to detect the publication of the fund transaction.
sync_dlc_channels();

setup.sync_coordinator().await;

setup
Expand Down
2 changes: 0 additions & 2 deletions crates/tests-e2e/tests/e2e_collaborative_revert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use native::api::WalletHistoryItemType;
use rust_decimal_macros::dec;
use tests_e2e::app::get_dlc_channel_id;
use tests_e2e::app::refresh_wallet_info;
use tests_e2e::app::sync_dlc_channels;
use tests_e2e::coordinator::CollaborativeRevertCoordinatorRequest;
use tests_e2e::setup;
use tests_e2e::wait_until;
Expand Down Expand Up @@ -47,7 +46,6 @@ async fn can_revert_channel() {
wait_until!({
bitcoin.mine(1).await.unwrap();

sync_dlc_channels();
refresh_wallet_info();

let app_balance = app.rx.wallet_info().unwrap().balances.on_chain;
Expand Down
7 changes: 0 additions & 7 deletions mobile/native/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,6 @@ pub async fn refresh_wallet_info() -> Result<()> {
Ok(())
}

#[tokio::main(flavor = "current_thread")]
pub async fn sync_dlc_channels() -> Result<()> {
ln_dlc::sync_dlc_channels().await?;

Ok(())
}

#[tokio::main(flavor = "current_thread")]
pub async fn full_sync(stop_gap: usize) -> Result<()> {
ln_dlc::full_sync(stop_gap).await?;
Expand Down
4 changes: 4 additions & 0 deletions mobile/native/src/ln_dlc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ pub async fn refresh_wallet_info() -> Result<()> {
tracing::error!("On-chain sync failed: {e:#}");
}

if let Err(e) = sync_dlc_channels().await {
tracing::error!("Failed to sync DLC channels: {e:#}");
}

// Spawn into the blocking thread pool of the dedicated backend runtime to avoid blocking the UI
// thread.
let runtime = state::get_or_create_tokio_runtime()?;
Expand Down

0 comments on commit 80c315e

Please sign in to comment.