reject share for small cuckoo size (#2197)

This commit is contained in:
Gary Yu 2018-12-21 18:14:19 +08:00 committed by GitHub
parent ecf736d78a
commit bc7780354c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -13,9 +13,9 @@
// limitations under the License.
//! Mining Stratum Server
use crate::util::{Mutex, RwLock};
use bufstream::BufStream;
use chrono::prelude::Utc;
use crate::util::{Mutex, RwLock};
use serde;
use serde_json;
use serde_json::Value;
@ -447,8 +447,8 @@ impl StratumServer {
if b.is_none() {
// Return error status
error!(
"(Server ID: {}) Failed to validate solution at height {}, nonce {}, with {} edge_bits: invalid job_id {}",
self.id, params.height, params.nonce, params.edge_bits, params.job_id,
"(Server ID: {}) Failed to validate solution at height {}, edge_bits {}, nonce {}, job_id {}: block data not found",
self.id, params.height, params.edge_bits, params.nonce, params.job_id,
);
worker_stats.num_rejected += 1;
let e = RpcError {
@ -463,11 +463,25 @@ impl StratumServer {
b.header.pow.nonce = params.nonce;
b.header.pow.proof.nonces = params.pow;
if !b.header.pow.is_primary() && !b.header.pow.is_secondary() {
// Return error status
error!(
"(Server ID: {}) Failed to validate solution at height {}, hash {}, edge_bits {}, nonce {}, job_id {}: cuckoo size too small",
self.id, params.height, b.hash(), params.edge_bits, params.nonce, params.job_id,
);
worker_stats.num_rejected += 1;
let e = RpcError {
code: -32502,
message: "Failed to validate solution".to_string(),
};
return Err(serde_json::to_value(e).unwrap());
}
if params.height != self.current_block_versions.last().unwrap().header.height {
// Return error status
error!(
"(Server ID: {}) Share at height {}, nonce {}, hash {}, with {} edge_bits submitted too late",
self.id, params.height, params.nonce, b.hash(), params.edge_bits,
"(Server ID: {}) Share at height {}, hash {}, edge_bits {}, nonce {}, job_id {} submitted too late",
self.id, params.height, b.hash(), params.edge_bits, params.nonce, params.job_id,
);
worker_stats.num_stale += 1;
let e = RpcError {
@ -482,8 +496,8 @@ impl StratumServer {
if share_difficulty < self.minimum_share_difficulty {
// Return error status
error!(
"(Server ID: {}) Share at height {}, nonce {}, hash {}, with {} edge_bits rejected due to low difficulty: {}/{}",
self.id, params.height, params.nonce, b.hash(), params.edge_bits, share_difficulty, self.minimum_share_difficulty,
"(Server ID: {}) Share at height {}, hash {}, edge_bits {}, nonce {}, job_id {} rejected due to low difficulty: {}/{}",
self.id, params.height, b.hash(), params.edge_bits, params.nonce, params.job_id, share_difficulty, self.minimum_share_difficulty,
);
worker_stats.num_rejected += 1;
let e = RpcError {
@ -499,12 +513,13 @@ impl StratumServer {
if let Err(e) = res {
// Return error status
error!(
"(Server ID: {}) Failed to validate solution at height {}, nonce {}, hash {}, with {} edge_bits: {}: {}",
"(Server ID: {}) Failed to validate solution at height {}, hash {}, edge_bits {}, nonce {}, job_id {}, {}: {}",
self.id,
params.height,
params.nonce,
b.hash(),
b.hash(),
params.edge_bits,
params.nonce,
params.job_id,
e,
e.backtrace().unwrap(),
);
@ -527,16 +542,18 @@ impl StratumServer {
);
} else {
// Do some validation but dont submit
if !pow::verify_size(&b.header).is_ok() {
let res = pow::verify_size(&b.header);
if !res.is_ok() {
// Return error status
error!(
"(Server ID: {}) Failed to validate share at height {}, hash {}, with {} edge_bits with nonce {} using job_id {}",
"(Server ID: {}) Failed to validate share at height {}, hash {}, edge_bits {}, nonce {}, job_id {}. {:?}",
self.id,
params.height,
b.hash(),
b.hash(),
params.edge_bits,
b.header.pow.nonce,
params.job_id,
res,
);
worker_stats.num_rejected += 1;
let e = RpcError {
@ -552,12 +569,13 @@ impl StratumServer {
Some(login) => login.clone(),
};
info!(
"(Server ID: {}) Got share for block: hash {}, height {}, edge_bits {}, nonce {}, difficulty {}/{}, submitted by {}",
"(Server ID: {}) Got share at height {}, hash {}, edge_bits {}, nonce {}, job_id {}, difficulty {}/{}, submitted by {}",
self.id,
b.hash(),
b.header.height,
b.hash(),
b.header.pow.proof.edge_bits,
b.header.pow.nonce,
params.job_id,
share_difficulty,
self.current_difficulty,
submitted_by,