Fix coinbase key reuse in stratum, only reset on new block (#1233)

This commit is contained in:
Ignotus Peverell 2018-07-09 09:14:34 +01:00 committed by Yeastplume
parent 74f1335bfd
commit 6450b603ea

View file

@ -314,8 +314,10 @@ impl StratumServer {
&mut stratum_stats.worker_stats[worker_stats_id], &mut stratum_stats.worker_stats[worker_stats_id],
); );
// this key_id has been used now, reset // this key_id has been used now, reset
if let Ok((_, true)) = res {
self.current_key_id = None; self.current_key_id = None;
res }
res.map(|(v, _)| v)
} }
"keepalive" => self.handle_keepalive(), "keepalive" => self.handle_keepalive(),
"getjobtemplate" => { "getjobtemplate" => {
@ -433,7 +435,7 @@ impl StratumServer {
params: Option<Value>, params: Option<Value>,
worker: &mut Worker, worker: &mut Worker,
worker_stats: &mut WorkerStats, worker_stats: &mut WorkerStats,
) -> Result<Value, Value> { ) -> Result<(Value, bool), Value> {
// Validate parameters // Validate parameters
let params: SubmitParams = match params { let params: SubmitParams = match params {
Some(val) => serde_json::from_value(val).unwrap(), Some(val) => serde_json::from_value(val).unwrap(),
@ -448,6 +450,7 @@ impl StratumServer {
let mut b: Block; let mut b: Block;
let share_difficulty: u64; let share_difficulty: u64;
let mut share_is_block = false;
if params.height == self.current_block.header.height { if params.height == self.current_block.header.height {
// Reconstruct the block header with this nonce and pow added // Reconstruct the block header with this nonce and pow added
b = self.current_block.clone(); b = self.current_block.clone();
@ -490,6 +493,8 @@ impl StratumServer {
message: "Failed to validate solution".to_string(), message: "Failed to validate solution".to_string(),
}; };
return Err(serde_json::to_value(e).unwrap()); return Err(serde_json::to_value(e).unwrap());
} else {
share_is_block = true;
} }
// Success case falls through to be logged // Success case falls through to be logged
} else { } else {
@ -542,7 +547,7 @@ impl StratumServer {
submitted_by, submitted_by,
); );
worker_stats.num_accepted += 1; worker_stats.num_accepted += 1;
return Ok(serde_json::to_value("ok".to_string()).unwrap()); return Ok((serde_json::to_value("ok".to_string()).unwrap(), share_is_block));
} // handle submit a solution } // handle submit a solution
// Purge dead/sick workers - remove all workers marked in error state // Purge dead/sick workers - remove all workers marked in error state