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
This commit is contained in:
Agreene 2019-03-03 13:44:31 -08:00 committed by Ignotus Peverell
parent d0ade29fc2
commit 4c9984cf11
4 changed files with 19 additions and 3 deletions

View file

@ -326,10 +326,17 @@ impl p2p::ChainAdapter for NetToChainAdapter {
total_size: u64, total_size: u64,
) -> bool { ) -> bool {
match self.sync_state.status() { match self.sync_state.status() {
SyncStatus::TxHashsetDownload { .. } => { SyncStatus::TxHashsetDownload {
update_time: old_update_time,
downloaded_size: old_downloaded_size,
..
} => {
self.sync_state self.sync_state
.update_txhashset_download(SyncStatus::TxHashsetDownload { .update_txhashset_download(SyncStatus::TxHashsetDownload {
start_time, start_time,
prev_update_time: old_update_time,
update_time: Utc::now(),
prev_downloaded_size: old_downloaded_size,
downloaded_size, downloaded_size,
total_size, total_size,
}) })

View file

@ -262,6 +262,9 @@ pub enum SyncStatus {
/// Downloading the various txhashsets /// Downloading the various txhashsets
TxHashsetDownload { TxHashsetDownload {
start_time: DateTime<Utc>, start_time: DateTime<Utc>,
prev_update_time: DateTime<Utc>,
update_time: DateTime<Utc>,
prev_downloaded_size: u64,
downloaded_size: u64, downloaded_size: u64,
total_size: u64, total_size: u64,
}, },

View file

@ -147,6 +147,9 @@ impl StateSync {
self.sync_state.update(SyncStatus::TxHashsetDownload { self.sync_state.update(SyncStatus::TxHashsetDownload {
start_time: Utc::now(), start_time: Utc::now(),
prev_update_time: Utc::now(),
update_time: Utc::now(),
prev_downloaded_size: 0,
downloaded_size: 0, downloaded_size: 0,
total_size: 0, total_size: 0,
}); });

View file

@ -128,6 +128,9 @@ impl TUIStatusListener for TUIStatusView {
} }
SyncStatus::TxHashsetDownload { SyncStatus::TxHashsetDownload {
start_time, start_time,
prev_update_time,
update_time: _,
prev_downloaded_size,
downloaded_size, downloaded_size,
total_size, total_size,
} => { } => {
@ -137,14 +140,14 @@ impl TUIStatusListener for TUIStatusView {
} else { } else {
0 0
}; };
let start = start_time.timestamp_nanos(); let start = prev_update_time.timestamp_nanos();
let fin = Utc::now().timestamp_nanos(); let fin = Utc::now().timestamp_nanos();
let dur_ms = (fin - start) as f64 * NANO_TO_MILLIS; 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", format!("Downloading {}(MB) chain state for state sync: {}% at {:.1?}(kB/s), step 2/4",
total_size / 1_000_000, total_size / 1_000_000,
percent, 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 { } else {
let start = start_time.timestamp_millis(); let start = start_time.timestamp_millis();