From 6a4e072f6e3fd7a67e85186a11fb6729d281622a Mon Sep 17 00:00:00 2001 From: Hansie Odendaal Date: Mon, 6 Sep 2021 15:21:57 +0200 Subject: [PATCH] review comments --- applications/tari_console_wallet/src/ui/app.rs | 4 ++++ .../tari_console_wallet/src/ui/state/app_state.rs | 12 +++++++----- .../src/ui/state/wallet_event_monitor.rs | 9 --------- base_layer/wallet/src/base_node_service/monitor.rs | 7 ++++--- common/config/presets/tari_config_example.toml | 6 ++++-- common/config/presets/tari_igor_config.toml | 6 ++++-- common/src/configuration/utils.rs | 2 +- 7 files changed, 24 insertions(+), 22 deletions(-) diff --git a/applications/tari_console_wallet/src/ui/app.rs b/applications/tari_console_wallet/src/ui/app.rs index 3cc3a80075..a87fbee01c 100644 --- a/applications/tari_console_wallet/src/ui/app.rs +++ b/applications/tari_console_wallet/src/ui/app.rs @@ -40,6 +40,7 @@ use crate::{ }, wallet_modes::PeerConfig, }; +use log::*; use tari_common::{configuration::Network, GlobalConfig}; use tari_comms::peer_manager::Peer; use tari_wallet::WalletSqlite; @@ -152,6 +153,9 @@ impl App { } pub fn on_tick(&mut self) { + if let Err(e) = Handle::current().block_on(self.app_state.refresh_balance_check()) { + warn!(target: LOG_TARGET, "Error refresh balance check: {}", e); + } Handle::current().block_on(self.app_state.update_cache()); self.tabs.on_tick(&mut self.app_state); } diff --git a/applications/tari_console_wallet/src/ui/state/app_state.rs b/applications/tari_console_wallet/src/ui/state/app_state.rs index 34b90273ac..406082bd4c 100644 --- a/applications/tari_console_wallet/src/ui/state/app_state.rs +++ b/applications/tari_console_wallet/src/ui/state/app_state.rs @@ -149,6 +149,13 @@ impl AppState { Ok(()) } + pub async fn refresh_balance_check(&self) -> Result<(), UiError> { + let mut inner = self.inner.write().await; + inner.refresh_balance_check().await?; + drop(inner); + Ok(()) + } + pub async fn update_cache(&mut self) { let update = match self.cache_update_cooldown { Some(last_update) => last_update.elapsed() > self.config.cache_update_cooldown, @@ -675,11 +682,6 @@ impl AppStateInner { pub async fn refresh_balance_check(&mut self) -> Result<(), UiError> { if self.balance_enquiry_cooldown_infringement { - trace!( - target: LOG_TARGET, - "Balance enquiry cooldown period ({}s) was infringed; trying to update balance again now", - self.balance_enquiry_cooldown_period - ); self.refresh_balance().await?; }; diff --git a/applications/tari_console_wallet/src/ui/state/wallet_event_monitor.rs b/applications/tari_console_wallet/src/ui/state/wallet_event_monitor.rs index c4b325b5da..9c5b724b10 100644 --- a/applications/tari_console_wallet/src/ui/state/wallet_event_monitor.rs +++ b/applications/tari_console_wallet/src/ui/state/wallet_event_monitor.rs @@ -160,7 +160,6 @@ impl WalletEventMonitor { match (*msg).clone() { BaseNodeEvent::BaseNodeStateChanged(state) => { self.trigger_base_node_state_refresh(state).await; - self.trigger_balance_refresh_check().await; } BaseNodeEvent::BaseNodePeerSet(peer) => { self.trigger_base_node_peer_refresh(*peer).await; @@ -263,12 +262,4 @@ impl WalletEventMonitor { let mut inner = self.app_state_inner.write().await; inner.add_notification(notification); } - - async fn trigger_balance_refresh_check(&mut self) { - let mut inner = self.app_state_inner.write().await; - - if let Err(e) = inner.refresh_balance_check().await { - warn!(target: LOG_TARGET, "Error refresh app_state: {}", e); - } - } } diff --git a/base_layer/wallet/src/base_node_service/monitor.rs b/base_layer/wallet/src/base_node_service/monitor.rs index 5267c5986c..71c8ddafb3 100644 --- a/base_layer/wallet/src/base_node_service/monitor.rs +++ b/base_layer/wallet/src/base_node_service/monitor.rs @@ -115,7 +115,7 @@ impl BaseNodeMonitor { trace!( target: LOG_TARGET, "Obtain RPC client {} ms", - Instant::now().duration_since(start).as_millis(), + start.elapsed().as_millis() ); let base_node_id = match self.wallet_connectivity.get_current_base_node_id() { @@ -135,7 +135,8 @@ impl BaseNodeMonitor { // the time it takes for the metadata call, which is evident as well when the base node gets busy and will // often take longer than the metadata call itself. Having two longish RPC calls with no added value // results in more RPC request timeouts than is necessary. - let latency = Instant::now().duration_since(start); + // TODO: Find root cause of RPC ping calls taking approximately as long as RPC fetch meta data calls + let latency = start.elapsed(); let is_synced = tip_info.is_synced; debug!( @@ -160,7 +161,7 @@ impl BaseNodeMonitor { trace!( target: LOG_TARGET, "Update metadata in db and publish event {} ms", - Instant::now().duration_since(start).as_millis(), + start.elapsed().as_millis() ); time::sleep(self.interval).await diff --git a/common/config/presets/tari_config_example.toml b/common/config/presets/tari_config_example.toml index 50c580cb7d..58d45a9736 100644 --- a/common/config/presets/tari_config_example.toml +++ b/common/config/presets/tari_config_example.toml @@ -178,8 +178,10 @@ scan_for_utxo_interval = 180 base_node_service_refresh_interval = 30 # The maximum age of service requests in seconds, requests older than this are discarded base_node_service_request_max_age = 180 -# The cooldown period between balance enquiry checks in seconds, requests faster than this will be ignored -balance_enquiry_cooldown_period = 60 +# The cooldown period between balance enquiry checks in seconds; requests faster than this will be ignored. +# For specialized wallets processing many batch transactions this setting could be increased to 60 s to retain +# responsiveness of the wallet with slightly delayed balance updates (default: 1) +#balance_enquiry_cooldown_period = 1 #[base_node.transport.tor] #control_address = "/ip4/127.0.0.1/tcp/9051" diff --git a/common/config/presets/tari_igor_config.toml b/common/config/presets/tari_igor_config.toml index 44df6073ce..eb77e625be 100644 --- a/common/config/presets/tari_igor_config.toml +++ b/common/config/presets/tari_igor_config.toml @@ -178,8 +178,10 @@ scan_for_utxo_interval = 180 base_node_service_refresh_interval = 30 # The maximum age of service requests in seconds, requests older than this are discarded base_node_service_request_max_age = 180 -# The cooldown period between balance enquiry checks in seconds, requests faster than this will be ignored (defaul: 5) -balance_enquiry_cooldown_period = 60 +# The cooldown period between balance enquiry checks in seconds; requests faster than this will be ignored. +# For specialized wallets processing many batch transactions this setting could be increased to 60 s to retain +# responsiveness of the wallet with slightly delayed balance updates (default: 1) +#balance_enquiry_cooldown_period = 1 #[base_node.transport.tor] #control_address = "/ip4/127.0.0.1/tcp/9051" diff --git a/common/src/configuration/utils.rs b/common/src/configuration/utils.rs index 75e119b103..ed56663f2e 100644 --- a/common/src/configuration/utils.rs +++ b/common/src/configuration/utils.rs @@ -100,7 +100,7 @@ pub fn default_config(bootstrap: &ConfigBootstrap) -> Config { cfg.set_default("wallet.base_node_query_timeout", 60).unwrap(); cfg.set_default("wallet.base_node_service_refresh_interval", 5).unwrap(); cfg.set_default("wallet.base_node_service_request_max_age", 60).unwrap(); - cfg.set_default("wallet.balance_enquiry_cooldown_period", 5).unwrap(); + cfg.set_default("wallet.balance_enquiry_cooldown_period", 1).unwrap(); cfg.set_default("wallet.scan_for_utxo_interval", 60 * 60 * 12).unwrap(); cfg.set_default("wallet.transaction_broadcast_monitoring_timeout", 60) .unwrap();