feature: txhashset downloading progress display on tui (#1729)

This commit is contained in:
Gary Yu
2018-10-13 06:53:50 +08:00
committed by Ignotus Peverell
parent 3fb4669d0a
commit 5c0eb11a7d
10 changed files with 157 additions and 22 deletions
+32 -2
View File
@@ -14,6 +14,7 @@
//! Basic status view definition
use chrono::prelude::Utc;
use cursive::direction::Orientation;
use cursive::traits::Identifiable;
use cursive::view::View;
@@ -26,6 +27,8 @@ use tui::types::TUIStatusListener;
use servers::common::types::SyncStatus;
use servers::ServerStats;
const NANO_TO_MILLIS: f64 = 1.0 / 1_000_000.0;
pub struct TUIStatusView;
impl TUIStatusListener for TUIStatusView {
@@ -101,8 +104,35 @@ impl TUIStatusListener for TUIStatusView {
};
format!("Downloading headers: {}%, step 1/4", percent)
}
SyncStatus::TxHashsetDownload => {
"Downloading chain state for fast sync, step 2/4".to_string()
SyncStatus::TxHashsetDownload {
start_time,
downloaded_size,
total_size,
} => {
if total_size > 0 {
let percent = if total_size > 0 {
downloaded_size * 100 / total_size
} else {
0
};
let start = start_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 fast 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 },
)
} else {
let start = start_time.timestamp_millis();
let fin = Utc::now().timestamp_millis();
let dur_secs = (fin - start) / 1000;
format!("Downloading chain state for fast sync. Waiting remote peer to start: {}s, step 2/4",
dur_secs,
)
}
}
SyncStatus::TxHashsetSetup => {
"Preparing chain state for validation, step 3/4".to_string()