Skip to content

Commit

Permalink
Merge pull request #1190 from get10101/chore/improve-app-debugging-ex…
Browse files Browse the repository at this point in the history
…perience

Improve app debugging experience
  • Loading branch information
luckysori authored Aug 30, 2023
2 parents 0d5edb4 + 5c6be9a commit 80674f5
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 20 deletions.
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions mobile/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ void setupFlutterLogs() {
FieldName.TEXT,
FieldName.STACKTRACE
];
config.customClosingDivider = "";
config.customOpeningDivider = "| ";
config.customClosingDivider = " ";
config.customOpeningDivider = "";

FLog.applyConfigurations(config);
}
Expand Down
1 change: 0 additions & 1 deletion mobile/native/src/event/event_hub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 7 additions & 4 deletions mobile/native/src/ln_dlc/channel_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand All @@ -37,6 +37,7 @@ pub enum ChannelStatus {
}

pub async fn track_channel_status(node: impl Borrow<Node>) {
let mut cached_status = ChannelStatus::Unknown;
loop {
tracing::info!("Tracking channel status");

Expand All @@ -48,9 +49,11 @@ pub async fn track_channel_status(node: impl Borrow<Node>) {
})
.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;
}
Expand Down
29 changes: 17 additions & 12 deletions mobile/native/src/orderbook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)) => {
Expand Down Expand Up @@ -114,26 +117,20 @@ 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();
let found = remove_order(&mut orders, order_id);
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();
Expand All @@ -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"),
}
Expand Down Expand Up @@ -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>, order_id: Uuid) -> bool {
let mut found = false;
Expand Down

0 comments on commit 80674f5

Please sign in to comment.