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

Run DLC channels checks during wallet refresh #2197

Merged
merged 1 commit into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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