Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
hansieodendaal committed Sep 7, 2021
1 parent 5852a65 commit 6a4e072
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 22 deletions.
4 changes: 4 additions & 0 deletions applications/tari_console_wallet/src/ui/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -152,6 +153,9 @@ impl<B: Backend> App<B> {
}

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);
}
Expand Down
12 changes: 7 additions & 5 deletions applications/tari_console_wallet/src/ui/state/app_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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?;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
}
7 changes: 4 additions & 3 deletions base_layer/wallet/src/base_node_service/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl<T: WalletBackend + 'static> BaseNodeMonitor<T> {
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() {
Expand All @@ -135,7 +135,8 @@ impl<T: WalletBackend + 'static> BaseNodeMonitor<T> {
// 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!(
Expand All @@ -160,7 +161,7 @@ impl<T: WalletBackend + 'static> BaseNodeMonitor<T> {
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
Expand Down
6 changes: 4 additions & 2 deletions common/config/presets/tari_config_example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 4 additions & 2 deletions common/config/presets/tari_igor_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion common/src/configuration/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 6a4e072

Please sign in to comment.