diff --git a/justfile b/justfile index 0b8f5edad..b3cd58773 100644 --- a/justfile +++ b/justfile @@ -270,7 +270,7 @@ all args="": services gen native all-ios: services gen ios run # Run iOS on public regtest (useful for device testing, where local regtest is not available) -all-ios-regtest: services gen ios run-regtest +ios-regtest: gen ios run-regtest # Run everything at once, tailored for Android development (rebuilds Android) all-android: services gen android run-local-android diff --git a/mobile/lib/main.dart b/mobile/lib/main.dart index 0661b234a..8dfa2c0d7 100644 --- a/mobile/lib/main.dart +++ b/mobile/lib/main.dart @@ -104,8 +104,8 @@ void setupFlutterLogs() { FieldName.TEXT, FieldName.STACKTRACE ]; - config.customClosingDivider = ""; - config.customOpeningDivider = "| "; + config.customClosingDivider = " "; + config.customOpeningDivider = ""; FLog.applyConfigurations(config); } diff --git a/mobile/native/src/event/event_hub.rs b/mobile/native/src/event/event_hub.rs index cee378e56..a17ea7d2a 100644 --- a/mobile/native/src/event/event_hub.rs +++ b/mobile/native/src/event/event_hub.rs @@ -44,7 +44,6 @@ impl EventHub { /// Publishes the given event to all subscribers. Note, that this will be executed in a loop. pub fn publish(&self, event: &EventInternal) { - tracing::debug!(event = %event, "Publishing an internal event"); if let Some(subscribers) = self.subscribers.get(&EventType::from(event.clone())) { for subscriber in subscribers { // todo: we should tokio spawn here. diff --git a/mobile/native/src/ln_dlc/channel_status.rs b/mobile/native/src/ln_dlc/channel_status.rs index 6107bc91b..eaa09967d 100644 --- a/mobile/native/src/ln_dlc/channel_status.rs +++ b/mobile/native/src/ln_dlc/channel_status.rs @@ -11,7 +11,7 @@ use std::time::Duration; const UPDATE_CHANNEL_STATUS_INTERVAL: Duration = Duration::from_secs(5); /// The status of the app channel -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum ChannelStatus { /// No channel is open. /// @@ -37,6 +37,7 @@ pub enum ChannelStatus { } pub async fn track_channel_status(node: impl Borrow) { + let mut cached_status = ChannelStatus::Unknown; loop { tracing::info!("Tracking channel status"); @@ -48,9 +49,11 @@ pub async fn track_channel_status(node: impl Borrow) { }) .into(); - tracing::info!(?status, "Channel status udpate"); - - event::publish(&event::EventInternal::ChannelStatusUpdate(status)); + if status != cached_status { + tracing::info!(?status, "Channel status update"); + event::publish(&event::EventInternal::ChannelStatusUpdate(status)); + cached_status = status; + } tokio::time::sleep(UPDATE_CHANNEL_STATUS_INTERVAL).await; } diff --git a/mobile/native/src/orderbook.rs b/mobile/native/src/orderbook.rs index 827a9d519..eb75cab68 100644 --- a/mobile/native/src/orderbook.rs +++ b/mobile/native/src/orderbook.rs @@ -8,8 +8,10 @@ use futures::TryStreamExt; use orderbook_commons::best_current_price; use orderbook_commons::Order; use orderbook_commons::OrderbookMsg; +use orderbook_commons::Prices; use orderbook_commons::Signature; use parking_lot::Mutex; +use std::collections::HashMap; use std::sync::Arc; use std::time::Duration; use time::OffsetDateTime; @@ -82,6 +84,7 @@ pub fn subscribe( tracing::warn!("Cannot update orderbook status: {e:#}"); }; + let mut cached_best_price : Prices = HashMap::new(); loop { match stream.try_next().await { Ok(Some(msg)) => { @@ -114,16 +117,12 @@ pub fn subscribe( tracing::debug!(?orders, "Received all orders from orderbook"); } *orders = initial_orders; - if let Err(e) = position::handler::price_update(best_current_price(&orders)) { - tracing::error!("Price update from the orderbook failed. Error: {e:#}"); - } + update_prices_if_needed(&mut cached_best_price, &orders); }, OrderbookMsg::NewOrder(order) => { let mut orders = orders.lock(); orders.push(order); - if let Err(e) = position::handler::price_update(best_current_price(&orders)) { - tracing::error!("Price update from the orderbook failed. Error: {e:#}"); - } + update_prices_if_needed(&mut cached_best_price, &orders); } OrderbookMsg::DeleteOrder(order_id) => { let mut orders = orders.lock(); @@ -131,9 +130,7 @@ pub fn subscribe( if !found { tracing::warn!(%order_id, "Could not remove non-existing order"); } - if let Err(e) = position::handler::price_update(best_current_price(&orders)) { - tracing::error!("Price update from the orderbook failed. Error: {e:#}"); - } + update_prices_if_needed(&mut cached_best_price, &orders); }, OrderbookMsg::Update(updated_order) => { let mut orders = orders.lock(); @@ -142,9 +139,7 @@ pub fn subscribe( tracing::warn!(?updated_order, "Update without prior knowledge of order"); } orders.push(updated_order); - if let Err(e) = position::handler::price_update(best_current_price(&orders)) { - tracing::error!("Price update from the orderbook failed. Error: {e:#}"); - } + update_prices_if_needed(&mut cached_best_price, &orders); }, _ => tracing::debug!(?msg, "Skipping message from orderbook"), } @@ -173,6 +168,16 @@ pub fn subscribe( Ok(()) } +fn update_prices_if_needed(cached_best_price: &mut Prices, orders: &[Order]) { + let best_price = best_current_price(orders); + if *cached_best_price != best_price { + if let Err(e) = position::handler::price_update(best_price.clone()) { + tracing::error!("Price update from the orderbook failed. Error: {e:#}"); + } + *cached_best_price = best_price; + } +} + // Returns true if the order was found and removed fn remove_order(orders: &mut Vec, order_id: Uuid) -> bool { let mut found = false;