minor improvement on stratum server log for miner status (#2301)

* add a log to show the stratum worker status

* add miner starting time (height)

* rustfmt
This commit is contained in:
Gary Yu
2019-01-07 07:19:25 +08:00
committed by GitHub
parent b927c10b01
commit 657392b592
2 changed files with 22 additions and 3 deletions
+3
View File
@@ -72,6 +72,8 @@ pub struct WorkerStats {
pub is_connected: bool,
/// Timestamp of most recent communication with this worker
pub last_seen: SystemTime,
/// which block height it starts mining
pub initial_block_height: u64,
/// pow difficulty this worker is using
pub pow_difficulty: u64,
/// number of valid shares submitted
@@ -207,6 +209,7 @@ impl Default for WorkerStats {
id: String::from("unknown"),
is_connected: false,
last_seen: SystemTime::now(),
initial_block_height: 0,
pow_difficulty: 0,
num_accepted: 0,
num_rejected: 0,
+19 -3
View File
@@ -312,7 +312,11 @@ impl StratumServer {
// Call the handler function for requested method
let response = match request.method.as_str() {
"login" => self.handle_login(request.params, &mut workers_l[num]),
"login" => {
stratum_stats.worker_stats[worker_stats_id].initial_block_height =
self.current_block_versions.last().unwrap().header.height;
self.handle_login(request.params, &mut workers_l[num])
}
"submit" => {
let res = self.handle_submit(
request.params,
@@ -338,7 +342,7 @@ impl StratumServer {
}
}
"status" => {
self.handle_status(&stratum_stats.worker_stats[worker_stats_id])
self.handle_status(&mut stratum_stats.worker_stats[worker_stats_id])
}
_ => {
// Called undefined method
@@ -384,7 +388,7 @@ impl StratumServer {
}
// Handle STATUS message
fn handle_status(&self, worker_stats: &WorkerStats) -> Result<Value, Value> {
fn handle_status(&self, worker_stats: &mut WorkerStats) -> Result<Value, Value> {
// Return worker status in json for use by a dashboard or healthcheck.
let status = WorkerStatus {
id: worker_stats.id.clone(),
@@ -394,6 +398,18 @@ impl StratumServer {
rejected: worker_stats.num_rejected,
stale: worker_stats.num_stale,
};
if worker_stats.initial_block_height == 0 {
worker_stats.initial_block_height = status.height;
}
debug!("(Server ID: {}) Status of worker: {} - Share Accepted: {}, Rejected: {}, Stale: {}. Blocks Found: {}/{}",
self.id,
worker_stats.id,
worker_stats.num_accepted,
worker_stats.num_rejected,
worker_stats.num_stale,
worker_stats.num_blocks_found,
status.height - worker_stats.initial_block_height,
);
let response = serde_json::to_value(&status).unwrap();
return Ok(response);
}