mirror of
https://github.com/mimblewimble/grin.git
synced 2025-04-21 18:01:14 +03:00
Tui update 1 (#911)
* minor low-hanging TUI updates * rustfmt * make diff/height output clearer
This commit is contained in:
parent
0fe27cc4e8
commit
ea9a978c87
8 changed files with 58 additions and 21 deletions
|
@ -306,12 +306,10 @@ impl Server {
|
|||
let (time, diff) = n.clone().unwrap();
|
||||
let dur = time - last_time;
|
||||
let height = earliest_block_height + i + 1;
|
||||
let index = tip_height - height;
|
||||
i += 1;
|
||||
last_time = time;
|
||||
DiffBlock {
|
||||
block_number: height,
|
||||
block_index: index,
|
||||
difficulty: diff.into_num(),
|
||||
time: time,
|
||||
duration: dur,
|
||||
|
|
|
@ -102,8 +102,6 @@ pub struct DiffStats {
|
|||
pub struct DiffBlock {
|
||||
/// Block number (can be negative for a new chain)
|
||||
pub block_number: i64,
|
||||
/// Ordinal index from current block
|
||||
pub block_index: i64,
|
||||
/// Block network difficulty
|
||||
pub difficulty: u64,
|
||||
/// Time block was found (epoch seconds)
|
||||
|
@ -121,8 +119,10 @@ pub struct PeerStats {
|
|||
pub addr: String,
|
||||
/// version running
|
||||
pub version: u32,
|
||||
/// version running
|
||||
/// difficulty repored by peer
|
||||
pub total_difficulty: u64,
|
||||
/// height reported by peer on ping
|
||||
pub height: u64,
|
||||
/// direction
|
||||
pub direction: String,
|
||||
}
|
||||
|
@ -148,6 +148,7 @@ impl PeerStats {
|
|||
addr: addr,
|
||||
version: peer.info.version,
|
||||
total_difficulty: peer.info.total_difficulty.into_num(),
|
||||
height: peer.info.height,
|
||||
direction: direction.to_string(),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -98,6 +98,7 @@ impl Handshake {
|
|||
addr: peer_addr,
|
||||
version: shake.version,
|
||||
total_difficulty: shake.total_difficulty,
|
||||
height: 0,
|
||||
direction: Direction::Outbound,
|
||||
};
|
||||
|
||||
|
@ -153,6 +154,7 @@ impl Handshake {
|
|||
addr: extract_ip(&hand.sender_addr.0, &conn),
|
||||
version: hand.version,
|
||||
total_difficulty: hand.total_difficulty,
|
||||
height: 0,
|
||||
direction: Direction::Inbound,
|
||||
};
|
||||
|
||||
|
|
|
@ -637,6 +637,7 @@ impl NetAdapter for Peers {
|
|||
if let Some(peer) = self.get_connected_peer(&addr) {
|
||||
let mut peer = peer.write().unwrap();
|
||||
peer.info.total_difficulty = diff;
|
||||
peer.info.height = height;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -202,6 +202,7 @@ pub struct PeerInfo {
|
|||
pub version: u32,
|
||||
pub addr: SocketAddr,
|
||||
pub total_difficulty: Difficulty,
|
||||
pub height: u64,
|
||||
pub direction: Direction,
|
||||
}
|
||||
|
||||
|
|
|
@ -107,7 +107,6 @@ impl TableViewItem<MiningDeviceColumn> for CuckooMinerDeviceStats {
|
|||
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
|
||||
enum DiffColumn {
|
||||
BlockNumber,
|
||||
Index,
|
||||
Difficulty,
|
||||
Time,
|
||||
Duration,
|
||||
|
@ -117,7 +116,6 @@ impl DiffColumn {
|
|||
fn _as_str(&self) -> &str {
|
||||
match *self {
|
||||
DiffColumn::BlockNumber => "Block Number",
|
||||
DiffColumn::Index => "Block Index",
|
||||
DiffColumn::Difficulty => "Network Difficulty",
|
||||
DiffColumn::Time => "Block Time",
|
||||
DiffColumn::Duration => "Duration",
|
||||
|
@ -132,7 +130,6 @@ impl TableViewItem<DiffColumn> for DiffBlock {
|
|||
|
||||
match column {
|
||||
DiffColumn::BlockNumber => self.block_number.to_string(),
|
||||
DiffColumn::Index => self.block_index.to_string(),
|
||||
DiffColumn::Difficulty => self.difficulty.to_string(),
|
||||
DiffColumn::Time => format!("{}", datetime).to_string(),
|
||||
DiffColumn::Duration => format!("{}s", self.duration).to_string(),
|
||||
|
@ -145,7 +142,6 @@ impl TableViewItem<DiffColumn> for DiffBlock {
|
|||
{
|
||||
match column {
|
||||
DiffColumn::BlockNumber => Ordering::Equal,
|
||||
DiffColumn::Index => Ordering::Equal,
|
||||
DiffColumn::Difficulty => Ordering::Equal,
|
||||
DiffColumn::Time => Ordering::Equal,
|
||||
DiffColumn::Duration => Ordering::Equal,
|
||||
|
@ -246,16 +242,13 @@ impl TUIStatusListener for TUIMiningView {
|
|||
|
||||
let diff_table_view = TableView::<DiffBlock, DiffColumn>::new()
|
||||
.column(DiffColumn::BlockNumber, "Block Number", |c| {
|
||||
c.width_percent(20)
|
||||
})
|
||||
.column(DiffColumn::Index, "Distance from Head", |c| {
|
||||
c.width_percent(20)
|
||||
c.width_percent(25)
|
||||
})
|
||||
.column(DiffColumn::Difficulty, "Network Difficulty", |c| {
|
||||
c.width_percent(20)
|
||||
c.width_percent(25)
|
||||
})
|
||||
.column(DiffColumn::Time, "Block Time", |c| c.width_percent(20))
|
||||
.column(DiffColumn::Duration, "Duration", |c| c.width_percent(20));
|
||||
.column(DiffColumn::Time, "Block Time", |c| c.width_percent(25))
|
||||
.column(DiffColumn::Duration, "Duration", |c| c.width_percent(25));
|
||||
|
||||
let mining_difficulty_view = LinearLayout::new(Orientation::Vertical)
|
||||
.child(diff_status_view)
|
||||
|
|
|
@ -20,7 +20,8 @@ use grin::stats::{PeerStats, ServerStats};
|
|||
|
||||
use cursive::Cursive;
|
||||
use cursive::view::View;
|
||||
use cursive::views::{BoxView, Dialog};
|
||||
use cursive::views::{BoxView, Dialog, LinearLayout, TextView};
|
||||
use cursive::direction::Orientation;
|
||||
use cursive::traits::*;
|
||||
|
||||
use tui::table::{TableView, TableViewItem};
|
||||
|
@ -53,7 +54,9 @@ impl TableViewItem<PeerColumn> for PeerStats {
|
|||
match column {
|
||||
PeerColumn::Address => self.addr.clone(),
|
||||
PeerColumn::State => self.state.clone(),
|
||||
PeerColumn::TotalDifficulty => self.total_difficulty.to_string(),
|
||||
PeerColumn::TotalDifficulty => {
|
||||
format!("{} D @ {} H", self.total_difficulty, self.height).to_string()
|
||||
}
|
||||
PeerColumn::Direction => self.direction.clone(),
|
||||
PeerColumn::Version => self.version.to_string(),
|
||||
}
|
||||
|
@ -86,20 +89,50 @@ impl TUIStatusListener for TUIPeerView {
|
|||
c.width_percent(20)
|
||||
})
|
||||
.column(PeerColumn::Version, "Version", |c| c.width_percent(20));
|
||||
|
||||
let peer_status_view = BoxView::with_full_screen(
|
||||
Dialog::around(table_view.with_id(TABLE_PEER_STATUS).min_size((50, 20)))
|
||||
.title("Connected Peers"),
|
||||
LinearLayout::new(Orientation::Vertical)
|
||||
.child(
|
||||
LinearLayout::new(Orientation::Horizontal)
|
||||
.child(TextView::new("Total Peers: "))
|
||||
.child(TextView::new(" ").with_id("peers_total")),
|
||||
)
|
||||
.child(
|
||||
LinearLayout::new(Orientation::Horizontal)
|
||||
.child(TextView::new("Longest Chain: "))
|
||||
.child(TextView::new(" ").with_id("longest_work_peer")),
|
||||
)
|
||||
.child(TextView::new(" "))
|
||||
.child(
|
||||
Dialog::around(table_view.with_id(TABLE_PEER_STATUS).min_size((50, 20)))
|
||||
.title("Connected Peers"),
|
||||
),
|
||||
).with_id(VIEW_PEER_SYNC);
|
||||
Box::new(peer_status_view)
|
||||
}
|
||||
|
||||
fn update(c: &mut Cursive, stats: &ServerStats) {
|
||||
let lp = stats
|
||||
.peer_stats
|
||||
.iter()
|
||||
.max_by(|x, y| x.total_difficulty.cmp(&y.total_difficulty));
|
||||
let lp_str = match lp {
|
||||
Some(l) => format!(
|
||||
"{} D @ {} H vs Us: {} D @ {} H",
|
||||
l.total_difficulty, l.height, stats.head.total_difficulty, stats.head.height
|
||||
).to_string(),
|
||||
None => "".to_string(),
|
||||
};
|
||||
let _ = c.call_on_id(
|
||||
TABLE_PEER_STATUS,
|
||||
|t: &mut TableView<PeerStats, PeerColumn>| {
|
||||
t.set_items(stats.peer_stats.clone());
|
||||
},
|
||||
);
|
||||
let _ = c.call_on_id("peers_total", |t: &mut TextView| {
|
||||
t.set_content(stats.peer_stats.len().to_string());
|
||||
});
|
||||
let _ = c.call_on_id("longest_work_peer", |t: &mut TextView| {
|
||||
t.set_content(lp_str);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,6 +47,11 @@ impl TUIStatusListener for TUIStatusView {
|
|||
.child(TextView::new("Chain Height: "))
|
||||
.child(TextView::new(" ").with_id("chain_height")),
|
||||
)
|
||||
.child(
|
||||
LinearLayout::new(Orientation::Horizontal)
|
||||
.child(TextView::new("Total Difficulty: "))
|
||||
.child(TextView::new(" ").with_id("basic_total_difficulty")),
|
||||
)
|
||||
.child(
|
||||
LinearLayout::new(Orientation::Horizontal)
|
||||
.child(TextView::new("------------------------")),
|
||||
|
@ -126,6 +131,9 @@ impl TUIStatusListener for TUIStatusView {
|
|||
c.call_on_id("chain_height", |t: &mut TextView| {
|
||||
t.set_content(stats.head.height.to_string());
|
||||
});
|
||||
c.call_on_id("basic_total_difficulty", |t: &mut TextView| {
|
||||
t.set_content(stats.head.total_difficulty.to_string());
|
||||
});
|
||||
c.call_on_id("basic_mining_config_status", |t: &mut TextView| {
|
||||
t.set_content(basic_mining_config_status);
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue