diff --git a/nomium/shares-logger/src/services/share_processor.rs b/nomium/shares-logger/src/services/share_processor.rs index 1f6a6e41ad..4827ab6e50 100644 --- a/nomium/shares-logger/src/services/share_processor.rs +++ b/nomium/shares-logger/src/services/share_processor.rs @@ -17,9 +17,9 @@ impl ShareProcessor { ntime: u32, version: u32, hash: [u8; 32], - downstream_target: Target, extranonce: Vec, user_identity_json: String, + share_status: ShareStatus, ) -> ShareLog { let worker_identity: Value = serde_json::from_str(&user_identity_json) .unwrap_or_else(|_| json!({ @@ -42,7 +42,7 @@ impl ShareProcessor { hash_bytes.reverse(); let difficulty = DifficultyService::calculate_difficulty_from_hash(&hash_bytes); - let status = ShareStatus::NetworkValid; + //let status = ShareStatus::NetworkValid; ShareLog::new( channel_id, @@ -52,7 +52,7 @@ impl ShareProcessor { ntime, version, hash_bytes.to_vec(), - status, + share_status, extranonce, difficulty, user_identity, diff --git a/protocols/v2/roles-logic-sv2/src/channel_logic/channel_factory.rs b/protocols/v2/roles-logic-sv2/src/channel_logic/channel_factory.rs index d29baef3b9..c7e2284546 100644 --- a/protocols/v2/roles-logic-sv2/src/channel_logic/channel_factory.rs +++ b/protocols/v2/roles-logic-sv2/src/channel_logic/channel_factory.rs @@ -19,7 +19,6 @@ use std::{collections::HashMap, convert::TryInto, sync::Arc}; use template_distribution_sv2::{NewTemplate, SetNewPrevHash as SetNewPrevHashFromTp}; use tracing::{debug, error, info, trace, warn}; -use std::backtrace::Backtrace; use stratum_common::{ bitcoin, @@ -30,6 +29,8 @@ use stratum_common::{ }, }; +use shares_logger::models::ShareStatus; + /// A stripped type of `SetCustomMiningJob` without the (`channel_id, `request_id` and `token`) /// fields #[derive(Debug)] @@ -831,6 +832,8 @@ impl ChannelFactory { let hash_ = header.block_hash(); let hash = hash_.as_hash().into_inner(); + + // NOMIUM share_log injection ---- let user_identity = match &m { Share::Extended(share) => std::str::from_utf8(share.user_identity.as_ref()) @@ -838,6 +841,16 @@ impl ChannelFactory { .to_string(), Share::Standard(_) => panic!("Expected Extended share, got Standard"), }; + let share_hash: Target = hash.into(); //todo (?) - move to shares_logger (?) + let share_status = if share_hash <= bitcoin_target { + ShareStatus::NetworkValid + } else if share_hash <= upstream_target { + ShareStatus::PoolValid + } else if share_hash <= downstream_target { + ShareStatus::MinerValid + } else { + ShareStatus::Invalid + }; match self.kind { ExtendedChannelKind::Pool => { /* let share_log = shares_logger::services::share_processor::ShareProcessor::prepare_share_log( @@ -848,7 +861,6 @@ impl ChannelFactory { m.get_n_time(), m.get_version(), hash, - downstream_target.clone(), extranonce.to_vec(), user_identity, ); */ @@ -864,9 +876,9 @@ impl ChannelFactory { m.get_n_time(), m.get_version(), hash, - downstream_target.clone(), extranonce.to_vec(), user_identity, + share_status, ); info!("Calling share logging for PROXY"); shares_logger::log_share(share_log); diff --git a/roles/translator/config-examples/tproxy-config-local-pool-PoolTest.toml b/roles/translator/config-examples/tproxy-config-local-pool-PoolTest.toml index 657dc993df..25bd6ffe88 100644 --- a/roles/translator/config-examples/tproxy-config-local-pool-PoolTest.toml +++ b/roles/translator/config-examples/tproxy-config-local-pool-PoolTest.toml @@ -29,7 +29,7 @@ min_extranonce2_size = 8 # min_individual_miner_hashrate=100_000.0 min_individual_miner_hashrate=15_000_000.0 # target number of shares per minute the miner should be sending -shares_per_minute = 10.0 +shares_per_minute = 20.0 [upstream_difficulty_config] # interval in seconds to elapse before updating channel hashrate with the pool diff --git a/roles/translator/src/lib/downstream_sv1/downstream.rs b/roles/translator/src/lib/downstream_sv1/downstream.rs index 4cb9bd6aec..17cafe0448 100644 --- a/roles/translator/src/lib/downstream_sv1/downstream.rs +++ b/roles/translator/src/lib/downstream_sv1/downstream.rs @@ -655,6 +655,31 @@ impl IsServer<'static> for Downstream { true } else { + // NOMIUM share_log injection ---- + let worker_identity = shares_logger::worker_name_store::get_worker_identity(&request.user_name) + .map(|id| serde_json::json!({ + "worker_name": id.worker_name, + "worker_id": id.worker_id + }).to_string()) + .expect("Worker should be authorized"); + + let share_log = shares_logger::services::share_processor::ShareProcessor::prepare_share_log( + 1, + 0, + request.job_id.parse().unwrap_or(0), + request.nonce.0, + request.time.0, + match &request.version_bits { + Some(v) => v.0, + None => 0, + }, + [0u8; 32], + vec![], + worker_identity, + shares_logger::models::ShareStatus::Invalid + ); + shares_logger::log_share(share_log); + // NOMIUM share_log injection ---- false } }