From 4c9984cf1158c21fed70b1bcca3b722e15038295 Mon Sep 17 00:00:00 2001 From: Agreene Date: Sun, 3 Mar 2019 13:44:31 -0800 Subject: [PATCH] Display the current download rate rather than the average when syncing the chain (#2633) * When syncing the chain, calculate the displayed download speed using the current rate from the most recent iteration, rather than the average download speed from the entire syncing process. * Replace the explicitly ignored variables in the pattern with an implicit ignore --- servers/src/common/adapters.rs | 9 ++++++++- servers/src/common/types.rs | 3 +++ servers/src/grin/sync/state_sync.rs | 3 +++ src/bin/tui/status.rs | 7 +++++-- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/servers/src/common/adapters.rs b/servers/src/common/adapters.rs index ae160267b..e6e58b730 100644 --- a/servers/src/common/adapters.rs +++ b/servers/src/common/adapters.rs @@ -326,10 +326,17 @@ impl p2p::ChainAdapter for NetToChainAdapter { total_size: u64, ) -> bool { match self.sync_state.status() { - SyncStatus::TxHashsetDownload { .. } => { + SyncStatus::TxHashsetDownload { + update_time: old_update_time, + downloaded_size: old_downloaded_size, + .. + } => { self.sync_state .update_txhashset_download(SyncStatus::TxHashsetDownload { start_time, + prev_update_time: old_update_time, + update_time: Utc::now(), + prev_downloaded_size: old_downloaded_size, downloaded_size, total_size, }) diff --git a/servers/src/common/types.rs b/servers/src/common/types.rs index 5b2c9e267..54658dfc3 100644 --- a/servers/src/common/types.rs +++ b/servers/src/common/types.rs @@ -262,6 +262,9 @@ pub enum SyncStatus { /// Downloading the various txhashsets TxHashsetDownload { start_time: DateTime, + prev_update_time: DateTime, + update_time: DateTime, + prev_downloaded_size: u64, downloaded_size: u64, total_size: u64, }, diff --git a/servers/src/grin/sync/state_sync.rs b/servers/src/grin/sync/state_sync.rs index c4d012eca..887c29d44 100644 --- a/servers/src/grin/sync/state_sync.rs +++ b/servers/src/grin/sync/state_sync.rs @@ -147,6 +147,9 @@ impl StateSync { self.sync_state.update(SyncStatus::TxHashsetDownload { start_time: Utc::now(), + prev_update_time: Utc::now(), + update_time: Utc::now(), + prev_downloaded_size: 0, downloaded_size: 0, total_size: 0, }); diff --git a/src/bin/tui/status.rs b/src/bin/tui/status.rs index afc92cd17..6651c66b3 100644 --- a/src/bin/tui/status.rs +++ b/src/bin/tui/status.rs @@ -128,6 +128,9 @@ impl TUIStatusListener for TUIStatusView { } SyncStatus::TxHashsetDownload { start_time, + prev_update_time, + update_time: _, + prev_downloaded_size, downloaded_size, total_size, } => { @@ -137,14 +140,14 @@ impl TUIStatusListener for TUIStatusView { } else { 0 }; - let start = start_time.timestamp_nanos(); + let start = prev_update_time.timestamp_nanos(); let fin = Utc::now().timestamp_nanos(); let dur_ms = (fin - start) as f64 * NANO_TO_MILLIS; format!("Downloading {}(MB) chain state for state sync: {}% at {:.1?}(kB/s), step 2/4", total_size / 1_000_000, percent, - if dur_ms > 1.0f64 { downloaded_size as f64 / dur_ms as f64 } else { 0f64 }, + if dur_ms > 1.0f64 { (downloaded_size - prev_downloaded_size) as f64 / dur_ms as f64 } else { 0f64 }, ) } else { let start = start_time.timestamp_millis();