From 338c7e3e0a40bba98c97b529da68c5acd76f4867 Mon Sep 17 00:00:00 2001 From: Mariusz Klochowicz Date: Tue, 29 Aug 2023 16:17:15 -0700 Subject: [PATCH 1/4] chore: Make FLogs export look like normal logs Without this, the exports are not parsed as logs by log viewers, e.g. `lnav`, which makes in needlessly more difficult --- mobile/lib/main.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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); } From 4618ed9fb5e9d815b4e174008bde8e7c82facbf9 Mon Sep 17 00:00:00 2001 From: Mariusz Klochowicz Date: Tue, 29 Aug 2023 16:43:32 -0700 Subject: [PATCH 2/4] chore(justfile): Improve iOS regtest running command We don't need to run all the services, including funding etc; we don't use them when testing against public regtest. Rename the command to `ios-regtest` --- justfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 7af87db34c2965f216189471c4d9eb2d6287ffa3 Mon Sep 17 00:00:00 2001 From: Mariusz Klochowicz Date: Tue, 29 Aug 2023 17:57:25 -0700 Subject: [PATCH 3/4] chore: Don't send Event updates if nothing changed Prevent unneeded channel state and price update events by caching the last values and comparing them before sending an update. --- mobile/native/src/ln_dlc/channel_status.rs | 11 +++++--- mobile/native/src/orderbook.rs | 29 +++++++++++++--------- 2 files changed, 24 insertions(+), 16 deletions(-) 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; From 5c6be9a78252027e61655df5b760761324a8e26f Mon Sep 17 00:00:00 2001 From: Mariusz Klochowicz Date: Tue, 29 Aug 2023 18:04:47 -0700 Subject: [PATCH 4/4] chore: Remove log spam This log didn't add anything. --- mobile/native/src/event/event_hub.rs | 1 - 1 file changed, 1 deletion(-) 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.