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