mirror of
https://github.com/mimblewimble/grin.git
synced 2025-01-20 19:11:08 +03:00
cleanup mining stats (#3439)
* cleanup mining stats; make edge_bits dynamic (last size submitted), dont show bogus stats when no miners are connected Co-authored-by: Quentin Le Sceller <q.lesceller@gmail.com>
This commit is contained in:
parent
a22d98e9d5
commit
dc47beda78
4 changed files with 73 additions and 46 deletions
|
@ -19,7 +19,6 @@ use crate::util::RwLock;
|
|||
use std::sync::Arc;
|
||||
use std::time::SystemTime;
|
||||
|
||||
use crate::core::consensus::graph_weight;
|
||||
use crate::core::core::hash::Hash;
|
||||
use crate::core::ser::ProtocolVersion;
|
||||
|
||||
|
@ -128,8 +127,10 @@ pub struct StratumStats {
|
|||
pub block_height: u64,
|
||||
/// current network difficulty we're working on
|
||||
pub network_difficulty: u64,
|
||||
/// cuckoo size used for mining
|
||||
/// cuckoo size of last share submitted
|
||||
pub edge_bits: u16,
|
||||
/// current network Hashrate (for edge_bits)
|
||||
pub network_hashrate: f64,
|
||||
/// Individual worker status
|
||||
pub worker_stats: Vec<WorkerStats>,
|
||||
}
|
||||
|
@ -211,14 +212,6 @@ impl PartialEq for DiffBlock {
|
|||
}
|
||||
}
|
||||
|
||||
impl StratumStats {
|
||||
/// Calculate network hashrate
|
||||
pub fn network_hashrate(&self, height: u64) -> f64 {
|
||||
42.0 * (self.network_difficulty as f64 / graph_weight(height, self.edge_bits as u8) as f64)
|
||||
/ 60.0
|
||||
}
|
||||
}
|
||||
|
||||
impl PeerStats {
|
||||
/// Convert from a peer directly
|
||||
pub fn from_peer(peer: &p2p::Peer) -> PeerStats {
|
||||
|
@ -273,8 +266,9 @@ impl Default for StratumStats {
|
|||
is_running: false,
|
||||
num_workers: 0,
|
||||
block_height: 0,
|
||||
network_difficulty: 1000,
|
||||
edge_bits: 29,
|
||||
network_difficulty: 0,
|
||||
edge_bits: 0,
|
||||
network_hashrate: 0.0,
|
||||
worker_stats: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -361,7 +361,6 @@ impl Server {
|
|||
|
||||
/// Start a minimal "stratum" mining service on a separate thread
|
||||
pub fn start_stratum_server(&self, config: StratumServerConfig) {
|
||||
let edge_bits = global::min_edge_bits();
|
||||
let proof_size = global::proofsize();
|
||||
let sync_state = self.sync_state.clone();
|
||||
|
||||
|
@ -375,7 +374,7 @@ impl Server {
|
|||
let _ = thread::Builder::new()
|
||||
.name("stratum_server".to_string())
|
||||
.spawn(move || {
|
||||
stratum_server.run_loop(edge_bits as u32, proof_size, sync_state);
|
||||
stratum_server.run_loop(proof_size, sync_state);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -35,8 +35,10 @@ use std::time::{Duration, SystemTime};
|
|||
use crate::chain::{self, SyncState};
|
||||
use crate::common::stats::{StratumStats, WorkerStats};
|
||||
use crate::common::types::StratumServerConfig;
|
||||
use crate::core::consensus::graph_weight;
|
||||
use crate::core::core::hash::Hashed;
|
||||
use crate::core::core::Block;
|
||||
use crate::core::global;
|
||||
use crate::core::{pow, ser};
|
||||
use crate::keychain;
|
||||
use crate::mining::mine_block;
|
||||
|
@ -468,6 +470,7 @@ impl Handler {
|
|||
}
|
||||
}
|
||||
// Log this as a valid share
|
||||
self.workers.update_edge_bits(params.edge_bits as u16);
|
||||
let worker = self.workers.get_worker(worker_id)?;
|
||||
let submitted_by = match worker.login {
|
||||
None => worker.id.to_string(),
|
||||
|
@ -535,10 +538,9 @@ impl Handler {
|
|||
head = self.chain.head().unwrap();
|
||||
let latest_hash = head.last_block_h;
|
||||
|
||||
// Build a new block if:
|
||||
// There is a new block on the chain
|
||||
// or We are rebuilding the current one to include new transactions
|
||||
// and there is at least one worker connected
|
||||
// Build a new block if there is at least one worker and
|
||||
// There is a new block on the chain or its time to rebuild
|
||||
// the current one to include new transactions
|
||||
if (current_hash != latest_hash || Utc::now().timestamp() >= deadline)
|
||||
&& self.workers.count() > 0
|
||||
{
|
||||
|
@ -550,7 +552,7 @@ impl Handler {
|
|||
} else {
|
||||
None
|
||||
};
|
||||
// If this is a new block, clear the current_block version history
|
||||
// If this is a new block we will clear the current_block version history
|
||||
let clear_blocks = current_hash != latest_hash;
|
||||
|
||||
// Build the new block (version)
|
||||
|
@ -574,16 +576,21 @@ impl Handler {
|
|||
// set a new deadline for rebuilding with fresh transactions
|
||||
deadline = Utc::now().timestamp() + config.attempt_time_per_block as i64;
|
||||
|
||||
self.workers.update_block_height(new_block.header.height);
|
||||
self.workers
|
||||
.update_network_difficulty(state.current_difficulty);
|
||||
|
||||
// If this is a new block we will clear the current_block version history
|
||||
if clear_blocks {
|
||||
state.current_block_versions.clear();
|
||||
}
|
||||
|
||||
// Update the mining stats
|
||||
self.workers.update_block_height(new_block.header.height);
|
||||
let difficulty = new_block.header.total_difficulty() - head.total_difficulty;
|
||||
self.workers.update_network_difficulty(difficulty.to_num());
|
||||
self.workers.update_network_hashrate();
|
||||
|
||||
// Add this new block candidate onto our list of block versions for this height
|
||||
state.current_block_versions.push(new_block);
|
||||
// Send this job to all connected workers
|
||||
}
|
||||
// Send this job to all connected workers
|
||||
self.broadcast_job();
|
||||
}
|
||||
|
||||
|
@ -785,6 +792,14 @@ impl WorkersList {
|
|||
self.workers_list.read().len()
|
||||
}
|
||||
|
||||
pub fn update_edge_bits(&self, edge_bits: u16) {
|
||||
{
|
||||
let mut stratum_stats = self.stratum_stats.write();
|
||||
stratum_stats.edge_bits = edge_bits;
|
||||
}
|
||||
self.update_network_hashrate();
|
||||
}
|
||||
|
||||
pub fn update_block_height(&self, height: u64) {
|
||||
let mut stratum_stats = self.stratum_stats.write();
|
||||
stratum_stats.block_height = height;
|
||||
|
@ -794,6 +809,14 @@ impl WorkersList {
|
|||
let mut stratum_stats = self.stratum_stats.write();
|
||||
stratum_stats.network_difficulty = difficulty;
|
||||
}
|
||||
|
||||
pub fn update_network_hashrate(&self) {
|
||||
let mut stratum_stats = self.stratum_stats.write();
|
||||
stratum_stats.network_hashrate = 42.0
|
||||
* (stratum_stats.network_difficulty as f64
|
||||
/ graph_weight(stratum_stats.block_height, stratum_stats.edge_bits as u8) as f64)
|
||||
/ 60.0;
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------
|
||||
|
@ -834,10 +857,10 @@ impl StratumServer {
|
|||
/// existing chain anytime required and sending that to the connected
|
||||
/// stratum miner, proxy, or pool, and accepts full solutions to
|
||||
/// be submitted.
|
||||
pub fn run_loop(&mut self, edge_bits: u32, proof_size: usize, sync_state: Arc<SyncState>) {
|
||||
pub fn run_loop(&mut self, proof_size: usize, sync_state: Arc<SyncState>) {
|
||||
info!(
|
||||
"(Server ID: {}) Starting stratum server with edge_bits = {}, proof_size = {}",
|
||||
self.id, edge_bits, proof_size
|
||||
"(Server ID: {}) Starting stratum server with proof_size = {}",
|
||||
self.id, proof_size
|
||||
);
|
||||
|
||||
self.sync_state = sync_state;
|
||||
|
@ -861,7 +884,7 @@ impl StratumServer {
|
|||
{
|
||||
let mut stratum_stats = self.stratum_stats.write();
|
||||
stratum_stats.is_running = true;
|
||||
stratum_stats.edge_bits = edge_bits as u16;
|
||||
stratum_stats.edge_bits = (global::min_edge_bits() + 1) as u16;
|
||||
}
|
||||
|
||||
warn!(
|
||||
|
|
|
@ -226,6 +226,10 @@ impl TUIMiningView {
|
|||
LinearLayout::new(Orientation::Horizontal)
|
||||
.child(TextView::new(" ").with_name("stratum_block_height_status")),
|
||||
)
|
||||
.child(
|
||||
LinearLayout::new(Orientation::Horizontal)
|
||||
.child(TextView::new(" ").with_name("stratum_edge_bits_status")),
|
||||
)
|
||||
.child(
|
||||
LinearLayout::new(Orientation::Horizontal)
|
||||
.child(TextView::new(" ").with_name("stratum_network_difficulty_status")),
|
||||
|
@ -233,10 +237,6 @@ impl TUIMiningView {
|
|||
.child(
|
||||
LinearLayout::new(Orientation::Horizontal)
|
||||
.child(TextView::new(" ").with_name("stratum_network_hashrate")),
|
||||
)
|
||||
.child(
|
||||
LinearLayout::new(Orientation::Horizontal)
|
||||
.child(TextView::new(" ").with_name("stratum_edge_bits_status")),
|
||||
);
|
||||
|
||||
let mining_device_view = LinearLayout::new(Orientation::Vertical)
|
||||
|
@ -337,21 +337,32 @@ impl TUIStatusListener for TUIMiningView {
|
|||
},
|
||||
);
|
||||
let stratum_stats = stats.stratum_stats.clone();
|
||||
let stratum_network_hashrate = format!(
|
||||
"Network Hashrate: {:.*}",
|
||||
2,
|
||||
stratum_stats.network_hashrate(stratum_stats.block_height)
|
||||
);
|
||||
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_block_height = format!("Solving Block Height: {}", stratum_stats.block_height);
|
||||
let stratum_network_difficulty = format!(
|
||||
"Network Difficulty: {}",
|
||||
stratum_stats.network_difficulty
|
||||
);
|
||||
let stratum_edge_bits = format!("Cuckoo Size: {}", stratum_stats.edge_bits);
|
||||
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!(
|
||||
"Network Difficulty: {}",
|
||||
stratum_stats.network_difficulty
|
||||
),
|
||||
};
|
||||
let stratum_network_hashrate = match stratum_stats.num_workers {
|
||||
0 => "Network Hashrate: n/a".to_string(),
|
||||
_ => format!(
|
||||
"Network Hashrate C{}: {:.*}",
|
||||
stratum_stats.edge_bits, 2, stratum_stats.network_hashrate
|
||||
),
|
||||
};
|
||||
|
||||
c.call_on_name("stratum_config_status", |t: &mut TextView| {
|
||||
t.set_content(stratum_enabled);
|
||||
|
@ -365,15 +376,15 @@ impl TUIStatusListener for TUIMiningView {
|
|||
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);
|
||||
});
|
||||
c.call_on_name("stratum_network_hashrate", |t: &mut TextView| {
|
||||
t.set_content(stratum_network_hashrate);
|
||||
});
|
||||
c.call_on_name("stratum_edge_bits_status", |t: &mut TextView| {
|
||||
t.set_content(stratum_edge_bits);
|
||||
});
|
||||
let _ = c.call_on_name(
|
||||
TABLE_MINING_STATUS,
|
||||
|t: &mut TableView<WorkerStats, StratumWorkerColumn>| {
|
||||
|
|
Loading…
Reference in a new issue