From 059e6ad5455bcccf3afa4fe5e9a7d6b1712dcaca Mon Sep 17 00:00:00 2001 From: Blade Doyle Date: Thu, 4 Mar 2021 06:39:14 -0800 Subject: [PATCH] Mining tui updates (#3584) * add column ordering, set mining workers table to sort the connected workers to the top by default * add column ordering, set mining workers table to sort the connected workers to the top by default * Mining TUI fixes and updates --- servers/src/common/stats.rs | 8 ++- servers/src/mining/stratumserver.rs | 3 +- src/bin/tui/mining.rs | 107 ++++++++++++---------------- 3 files changed, 55 insertions(+), 63 deletions(-) diff --git a/servers/src/common/stats.rs b/servers/src/common/stats.rs index 811a084c6f..862c99c503 100644 --- a/servers/src/common/stats.rs +++ b/servers/src/common/stats.rs @@ -130,8 +130,12 @@ pub struct StratumStats { pub network_difficulty: u64, /// cuckoo size of last share submitted pub edge_bits: u16, + /// Number of blocks found by all workers + pub blocks_found: u16, /// current network Hashrate (for edge_bits) pub network_hashrate: f64, + /// The minimum acceptable share difficulty to request from miners + pub minimum_share_difficulty: u64, /// Individual worker status pub worker_stats: Vec, } @@ -271,8 +275,10 @@ impl Default for StratumStats { num_workers: 0, block_height: 0, network_difficulty: 0, - edge_bits: 0, + edge_bits: 32, + blocks_found: 0, network_hashrate: 0.0, + minimum_share_difficulty: 1, worker_stats: Vec::new(), } } diff --git a/servers/src/mining/stratumserver.rs b/servers/src/mining/stratumserver.rs index b90d15101f..c49838c5c5 100644 --- a/servers/src/mining/stratumserver.rs +++ b/servers/src/mining/stratumserver.rs @@ -714,7 +714,7 @@ impl WorkersList { let mut worker_stats = WorkerStats::default(); worker_stats.is_connected = true; worker_stats.id = worker_id.to_string(); - worker_stats.pow_difficulty = 1; // XXX TODO + worker_stats.pow_difficulty = stratum_stats.minimum_share_difficulty; stratum_stats.worker_stats.push(worker_stats); stratum_stats.num_workers = workers_list.len(); worker_id @@ -885,6 +885,7 @@ impl StratumServer { let mut stratum_stats = self.stratum_stats.write(); stratum_stats.is_running = true; stratum_stats.edge_bits = (global::min_edge_bits() + 1) as u16; + stratum_stats.minimum_share_difficulty = self.config.minimum_share_difficulty; } warn!( diff --git a/src/bin/tui/mining.rs b/src/bin/tui/mining.rs index 31afaea827..5cd8145375 100644 --- a/src/bin/tui/mining.rs +++ b/src/bin/tui/mining.rs @@ -50,7 +50,7 @@ enum StratumWorkerColumn { impl StratumWorkerColumn { fn _as_str(&self) -> &str { match *self { - StratumWorkerColumn::Id => "Worker ID", + StratumWorkerColumn::Id => "ID", StratumWorkerColumn::IsConnected => "Connected", StratumWorkerColumn::LastSeen => "Last Seen", StratumWorkerColumn::PowDifficulty => "PowDifficulty", @@ -85,19 +85,21 @@ impl TableViewItem for WorkerStats { } } - fn cmp(&self, _other: &Self, column: StratumWorkerColumn) -> Ordering + fn cmp(&self, other: &Self, column: StratumWorkerColumn) -> Ordering where Self: Sized, { match column { - StratumWorkerColumn::Id => Ordering::Equal, - StratumWorkerColumn::IsConnected => Ordering::Equal, - StratumWorkerColumn::LastSeen => Ordering::Equal, - StratumWorkerColumn::PowDifficulty => Ordering::Equal, - StratumWorkerColumn::NumAccepted => Ordering::Equal, - StratumWorkerColumn::NumRejected => Ordering::Equal, - StratumWorkerColumn::NumStale => Ordering::Equal, - StratumWorkerColumn::NumBlocksFound => Ordering::Equal, + StratumWorkerColumn::Id => self.id.cmp(&other.id), + StratumWorkerColumn::IsConnected => self.is_connected.cmp(&other.is_connected), + StratumWorkerColumn::LastSeen => self.last_seen.cmp(&other.last_seen), + StratumWorkerColumn::PowDifficulty => self.pow_difficulty.cmp(&other.pow_difficulty), + StratumWorkerColumn::NumAccepted => self.num_accepted.cmp(&other.num_accepted), + StratumWorkerColumn::NumRejected => self.num_rejected.cmp(&other.num_rejected), + StratumWorkerColumn::NumStale => self.num_stale.cmp(&other.num_stale), + StratumWorkerColumn::NumBlocksFound => { + self.num_blocks_found.cmp(&other.num_blocks_found) + } } } } @@ -105,9 +107,7 @@ impl TableViewItem for WorkerStats { enum DiffColumn { Height, Hash, - PoWType, Difficulty, - SecondaryScaling, Time, Duration, } @@ -117,9 +117,7 @@ impl DiffColumn { match *self { DiffColumn::Height => "Height", DiffColumn::Hash => "Hash", - DiffColumn::PoWType => "Type", DiffColumn::Difficulty => "Network Difficulty", - DiffColumn::SecondaryScaling => "Sec. Scaling", DiffColumn::Time => "Block Time", DiffColumn::Duration => "Duration", } @@ -130,35 +128,26 @@ impl TableViewItem for DiffBlock { fn to_column(&self, column: DiffColumn) -> String { let naive_datetime = NaiveDateTime::from_timestamp(self.time as i64, 0); let datetime: DateTime = DateTime::from_utc(naive_datetime, Utc); - let pow_type = if self.is_secondary { - String::from("Secondary") - } else { - String::from("Primary") - }; match column { DiffColumn::Height => self.block_height.to_string(), DiffColumn::Hash => self.block_hash.to_string(), - DiffColumn::PoWType => pow_type, DiffColumn::Difficulty => self.difficulty.to_string(), - DiffColumn::SecondaryScaling => self.secondary_scaling.to_string(), DiffColumn::Time => format!("{}", datetime), DiffColumn::Duration => format!("{}s", self.duration), } } - fn cmp(&self, _other: &Self, column: DiffColumn) -> Ordering + fn cmp(&self, other: &Self, column: DiffColumn) -> Ordering where Self: Sized, { match column { - DiffColumn::Height => Ordering::Equal, - DiffColumn::Hash => Ordering::Equal, - DiffColumn::PoWType => Ordering::Equal, - DiffColumn::Difficulty => Ordering::Equal, - DiffColumn::SecondaryScaling => Ordering::Equal, - DiffColumn::Time => Ordering::Equal, - DiffColumn::Duration => Ordering::Equal, + DiffColumn::Height => self.block_height.cmp(&other.block_height), + DiffColumn::Hash => self.block_hash.cmp(&other.block_hash), + DiffColumn::Difficulty => self.difficulty.cmp(&other.difficulty), + DiffColumn::Time => self.time.cmp(&other.time), + DiffColumn::Duration => self.duration.cmp(&other.duration), } } } @@ -185,29 +174,31 @@ impl TUIMiningView { .child(Panel::new(devices_button)) .child(Panel::new(difficulty_button)); - let table_view = TableView::::new() - .column(StratumWorkerColumn::Id, "Worker ID", |c| c.width_percent(8)) + let mut table_view = TableView::::new() + .column(StratumWorkerColumn::Id, "ID", |c| c.width_percent(6)) .column(StratumWorkerColumn::IsConnected, "Connected", |c| { - c.width_percent(8) + c.width_percent(14) }) .column(StratumWorkerColumn::LastSeen, "Last Seen", |c| { - c.width_percent(16) - }) - .column(StratumWorkerColumn::PowDifficulty, "Pow Difficulty", |c| { - c.width_percent(12) + c.width_percent(20) }) - .column(StratumWorkerColumn::NumAccepted, "Num Accepted", |c| { + .column(StratumWorkerColumn::PowDifficulty, "Difficulty", |c| { c.width_percent(10) }) - .column(StratumWorkerColumn::NumRejected, "Num Rejected", |c| { - c.width_percent(10) + .column(StratumWorkerColumn::NumAccepted, "Accepted", |c| { + c.width_percent(5) }) - .column(StratumWorkerColumn::NumStale, "Num Stale", |c| { - c.width_percent(10) + .column(StratumWorkerColumn::NumRejected, "Rejected", |c| { + c.width_percent(5) + }) + .column(StratumWorkerColumn::NumStale, "Stale", |c| { + c.width_percent(5) }) .column(StratumWorkerColumn::NumBlocksFound, "Blocks Found", |c| { - c.width_percent(10) - }); + c.width_percent(35) + }) + .default_column(StratumWorkerColumn::IsConnected); + table_view.sort_by(StratumWorkerColumn::IsConnected, Ordering::Greater); let status_view = LinearLayout::new(Orientation::Vertical) .child( @@ -228,7 +219,7 @@ impl TUIMiningView { ) .child( LinearLayout::new(Orientation::Horizontal) - .child(TextView::new(" ").with_name("stratum_edge_bits_status")), + .child(TextView::new(" ").with_name("stratum_blocks_found_status")), ) .child( LinearLayout::new(Orientation::Horizontal) @@ -270,17 +261,14 @@ impl TUIMiningView { ); let diff_table_view = TableView::::new() - .column(DiffColumn::Height, "Height", |c| c.width_percent(10)) - .column(DiffColumn::Hash, "Hash", |c| c.width_percent(10)) - .column(DiffColumn::PoWType, "Type", |c| c.width_percent(10)) + .column(DiffColumn::Height, "Height", |c| c.width_percent(15)) + .column(DiffColumn::Hash, "Hash", |c| c.width_percent(15)) .column(DiffColumn::Difficulty, "Network Difficulty", |c| { c.width_percent(15) }) - .column(DiffColumn::SecondaryScaling, "Sec. Scaling", |c| { - c.width_percent(10) - }) - .column(DiffColumn::Time, "Block Time", |c| c.width_percent(25)) - .column(DiffColumn::Duration, "Duration", |c| c.width_percent(25)); + .column(DiffColumn::Time, "Block Time", |c| c.width_percent(30)) + .column(DiffColumn::Duration, "Duration", |c| c.width_percent(25)) + .default_column(DiffColumn::Height); let mining_difficulty_view = LinearLayout::new(Orientation::Vertical) .child(diff_status_view) @@ -333,22 +321,19 @@ impl TUIStatusListener for TUIMiningView { let _ = c.call_on_name( TABLE_MINING_DIFF_STATUS, |t: &mut TableView| { - t.set_items_stable(diff_stats); + t.set_items(diff_stats); }, ); let stratum_stats = stats.stratum_stats.clone(); let worker_stats = stratum_stats.worker_stats; let stratum_enabled = format!("Mining server enabled: {}", stratum_stats.is_enabled); let stratum_is_running = format!("Mining server running: {}", stratum_stats.is_running); - let stratum_num_workers = format!("Number of workers: {}", stratum_stats.num_workers); + let stratum_num_workers = format!("Active workers: {}", stratum_stats.num_workers); + let stratum_blocks_found = format!("Blocks Found: {}", stratum_stats.blocks_found); let stratum_block_height = match stratum_stats.num_workers { 0 => "Solving Block Height: n/a".to_string(), _ => format!("Solving Block Height: {}", stratum_stats.block_height), }; - let stratum_edge_bits = match stratum_stats.num_workers { - 0 => "Latest POW submitted: n/a".to_string(), - _ => format!("Latest POW submitted: Cuckoo{}", stratum_stats.edge_bits), - }; let stratum_network_difficulty = match stratum_stats.num_workers { 0 => "Network Difficulty: n/a".to_string(), _ => format!( @@ -373,12 +358,12 @@ impl TUIStatusListener for TUIMiningView { c.call_on_name("stratum_num_workers_status", |t: &mut TextView| { t.set_content(stratum_num_workers); }); + c.call_on_name("stratum_blocks_found_status", |t: &mut TextView| { + t.set_content(stratum_blocks_found); + }); c.call_on_name("stratum_block_height_status", |t: &mut TextView| { t.set_content(stratum_block_height); }); - c.call_on_name("stratum_edge_bits_status", |t: &mut TextView| { - t.set_content(stratum_edge_bits); - }); c.call_on_name("stratum_network_difficulty_status", |t: &mut TextView| { t.set_content(stratum_network_difficulty); });