Skip to content

Commit

Permalink
Mining tui updates (#3584)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
bladedoyle authored Mar 4, 2021
1 parent 64b2fdd commit 059e6ad
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 63 deletions.
8 changes: 7 additions & 1 deletion servers/src/common/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<WorkerStats>,
}
Expand Down Expand Up @@ -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(),
}
}
Expand Down
3 changes: 2 additions & 1 deletion servers/src/mining/stratumserver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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!(
Expand Down
107 changes: 46 additions & 61 deletions src/bin/tui/mining.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -85,29 +85,29 @@ impl TableViewItem<StratumWorkerColumn> 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)
}
}
}
}
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
enum DiffColumn {
Height,
Hash,
PoWType,
Difficulty,
SecondaryScaling,
Time,
Duration,
}
Expand All @@ -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",
}
Expand All @@ -130,35 +128,26 @@ impl TableViewItem<DiffColumn> for DiffBlock {
fn to_column(&self, column: DiffColumn) -> String {
let naive_datetime = NaiveDateTime::from_timestamp(self.time as i64, 0);
let datetime: DateTime<Utc> = 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),
}
}
}
Expand All @@ -185,29 +174,31 @@ impl TUIMiningView {
.child(Panel::new(devices_button))
.child(Panel::new(difficulty_button));

let table_view = TableView::<WorkerStats, StratumWorkerColumn>::new()
.column(StratumWorkerColumn::Id, "Worker ID", |c| c.width_percent(8))
let mut table_view = TableView::<WorkerStats, StratumWorkerColumn>::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(
Expand All @@ -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)
Expand Down Expand Up @@ -270,17 +261,14 @@ impl TUIMiningView {
);

let diff_table_view = TableView::<DiffBlock, DiffColumn>::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)
Expand Down Expand Up @@ -333,22 +321,19 @@ impl TUIStatusListener for TUIMiningView {
let _ = c.call_on_name(
TABLE_MINING_DIFF_STATUS,
|t: &mut TableView<DiffBlock, DiffColumn>| {
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!(
Expand All @@ -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);
});
Expand Down

0 comments on commit 059e6ad

Please sign in to comment.