wallet: optimization of integrated node sync error case
This commit is contained in:
parent
8af7ed95d3
commit
4f2a247719
2 changed files with 14 additions and 18 deletions
|
@ -426,7 +426,7 @@ impl WalletContent {
|
||||||
ui.add_space(8.0);
|
ui.add_space(8.0);
|
||||||
let retry_text = format!("{} {}", REPEAT, t!("retry"));
|
let retry_text = format!("{} {}", REPEAT, t!("retry"));
|
||||||
View::button(ui, retry_text, Colors::GOLD, || {
|
View::button(ui, retry_text, Colors::GOLD, || {
|
||||||
wallet.retry_sync();
|
wallet.set_sync_error(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -283,7 +283,7 @@ impl Wallet {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get external connection id applied to [`WalletInstance`]
|
/// Get external connection id applied to [`WalletInstance`]
|
||||||
/// after opening if sync is running or take it from config.
|
/// after wallet opening if sync is running or get it from config.
|
||||||
pub fn get_current_ext_conn_id(&self) -> Option<i64> {
|
pub fn get_current_ext_conn_id(&self) -> Option<i64> {
|
||||||
if self.sync_thread.read().unwrap().is_some() {
|
if self.sync_thread.read().unwrap().is_some() {
|
||||||
let ext_conn_id = self.instance_ext_conn_id.load(Ordering::Relaxed);
|
let ext_conn_id = self.instance_ext_conn_id.load(Ordering::Relaxed);
|
||||||
|
@ -412,19 +412,8 @@ impl Wallet {
|
||||||
self.sync_error.load(Ordering::Relaxed)
|
self.sync_error.load(Ordering::Relaxed)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Retry synchronization on error.
|
|
||||||
pub fn retry_sync(&self) {
|
|
||||||
self.set_sync_error(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Set an error for wallet on synchronization.
|
/// Set an error for wallet on synchronization.
|
||||||
fn set_sync_error(&self, error: bool) {
|
pub fn set_sync_error(&self, error: bool) {
|
||||||
// Clear wallet info on error.
|
|
||||||
if error {
|
|
||||||
let mut w_data = self.data.write().unwrap();
|
|
||||||
*w_data = None;
|
|
||||||
}
|
|
||||||
|
|
||||||
self.sync_error.store(error, Ordering::Relaxed);
|
self.sync_error.store(error, Ordering::Relaxed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -452,7 +441,7 @@ impl Wallet {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Wake up wallet thread to sync wallet data and update statuses.
|
/// Wake up wallet thread to sync wallet data and update statuses.
|
||||||
fn sync(&self) {
|
pub fn sync(&self) {
|
||||||
let thread_r = self.sync_thread.read().unwrap();
|
let thread_r = self.sync_thread.read().unwrap();
|
||||||
if let Some(thread) = thread_r.as_ref() {
|
if let Some(thread) = thread_r.as_ref() {
|
||||||
thread.unpark();
|
thread.unpark();
|
||||||
|
@ -623,10 +612,17 @@ fn start_sync(mut wallet: Wallet) -> Thread {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set an error when required integrated node is not enabled
|
// Check integrated node state.
|
||||||
// and skip cycle when node sync is not finished.
|
|
||||||
if wallet.get_current_ext_conn_id().is_none() {
|
if wallet.get_current_ext_conn_id().is_none() {
|
||||||
wallet.set_sync_error(!Node::is_running() || Node::is_stopping());
|
let not_enabled = !Node::is_running() || Node::is_stopping();
|
||||||
|
if not_enabled {
|
||||||
|
// Reset loading progress.
|
||||||
|
wallet.info_sync_progress.store(0, Ordering::Relaxed);
|
||||||
|
wallet.txs_sync_progress.store(0, Ordering::Relaxed);
|
||||||
|
}
|
||||||
|
// Set an error when required integrated node is not enabled.
|
||||||
|
wallet.set_sync_error(not_enabled);
|
||||||
|
// Skip cycle when node sync is not finished.
|
||||||
if !Node::is_running() || Node::get_sync_status() != Some(SyncStatus::NoSync) {
|
if !Node::is_running() || Node::get_sync_status() != Some(SyncStatus::NoSync) {
|
||||||
println!("integrated node wait");
|
println!("integrated node wait");
|
||||||
thread::park_timeout(Duration::from_millis(1000));
|
thread::park_timeout(Duration::from_millis(1000));
|
||||||
|
|
Loading…
Reference in a new issue