Fix the way shares are validated (#1153)

* Fix the way shares are validated

* fix includes

* Add unique error codes for share rejection reasons
This commit is contained in:
Blade Doyle 2018-06-11 08:39:04 -07:00 committed by Yeastplume
parent edc01bb05a
commit 973d46e6aa
2 changed files with 9 additions and 6 deletions

View file

@ -107,7 +107,7 @@ pub fn get_block(
self::Error::Wallet(_) => { self::Error::Wallet(_) => {
error!( error!(
LOGGER, LOGGER,
"Stratum server: Can't connect to wallet listener at {:?}; will retry", "Error building new block: Can't connect to wallet listener at {:?}; will retry",
wallet_listener_url.as_ref().unwrap() wallet_listener_url.as_ref().unwrap()
); );
thread::sleep(Duration::from_secs(wallet_retry_interval)); thread::sleep(Duration::from_secs(wallet_retry_interval));

View file

@ -31,7 +31,9 @@ use chain;
use common::adapters::PoolToChainAdapter; use common::adapters::PoolToChainAdapter;
use common::stats::{StratumStats, WorkerStats}; use common::stats::{StratumStats, WorkerStats};
use common::types::StratumServerConfig; use common::types::StratumServerConfig;
use core::consensus;
use core::core::{Block, BlockHeader}; use core::core::{Block, BlockHeader};
use core::pow;
use keychain; use keychain;
use mining::mine_block; use mining::mine_block;
use pool; use pool;
@ -466,7 +468,7 @@ impl StratumServer {
self.minimum_share_difficulty, self.minimum_share_difficulty,
); );
worker_stats.num_rejected += 1; worker_stats.num_rejected += 1;
let e = r#"{"code": -1, "message": "Share rejected due to low difficulty"}"#; let e = r#"{"code": -32501, "message": "Share rejected due to low difficulty"}"#;
let err = e.to_string(); let err = e.to_string();
return (err, true); return (err, true);
} }
@ -483,14 +485,15 @@ impl StratumServer {
e e
); );
worker_stats.num_rejected += 1; worker_stats.num_rejected += 1;
let e = r#"{"code": -1, "message": "Failed to validate solution"}"#; let e = r#"{"code": -32502, "message": "Failed to validate solution"}"#;
let err = e.to_string(); let err = e.to_string();
return (err, true); return (err, true);
} }
// Success case falls through to be logged // Success case falls through to be logged
} else { } else {
// This is a low-difficulty share, not a full solution
// Do some validation but dont submit // Do some validation but dont submit
if self.current_block.header.pre_pow_hash() != b.header.pre_pow_hash() { if !pow::verify_size(&b.header, consensus::DEFAULT_SIZESHIFT) {
// Return error status // Return error status
error!( error!(
LOGGER, LOGGER,
@ -500,7 +503,7 @@ impl StratumServer {
b.header.nonce b.header.nonce
); );
worker_stats.num_rejected += 1; worker_stats.num_rejected += 1;
let e = r#"{"code": -1, "message": "Failed to validate share"}"#; let e = r#"{"code": -32502, "message": "Failed to validate share"}"#;
let err = e.to_string(); let err = e.to_string();
return (err, true); return (err, true);
} }
@ -514,7 +517,7 @@ impl StratumServer {
submit_params.height submit_params.height
); );
worker_stats.num_stale += 1; worker_stats.num_stale += 1;
let e = r#"{"code": -1, "message": "Solution submitted too late"}"#; let e = r#"{"code": -32503, "message": "Solution submitted too late"}"#;
let err = e.to_string(); let err = e.to_string();
return (err, true); return (err, true);
} }