From fd730333d8a1eeca95c508820966431ae2a87c11 Mon Sep 17 00:00:00 2001 From: romandukhanin Date: Fri, 10 Jan 2025 23:15:20 +0300 Subject: [PATCH 1/3] RRP-482 Do share_status Just Working But Need Opt --- .../src/services/share_processor.rs | 5 +++-- .../src/channel_logic/channel_factory.rs | 16 +++++++++++++++- .../tproxy-config-local-pool-PoolTest.toml | 2 +- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/nomium/shares-logger/src/services/share_processor.rs b/nomium/shares-logger/src/services/share_processor.rs index 1f6a6e41ad..72b5fdcc5b 100644 --- a/nomium/shares-logger/src/services/share_processor.rs +++ b/nomium/shares-logger/src/services/share_processor.rs @@ -20,6 +20,7 @@ impl ShareProcessor { 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 +43,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 +53,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..720b4436a4 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( @@ -867,6 +880,7 @@ impl ChannelFactory { 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 From 4d3f9ba0a21d8d0b46dfdc6fc80aae42d39855e4 Mon Sep 17 00:00:00 2001 From: romandukhanin Date: Sat, 11 Jan 2025 11:31:18 +0300 Subject: [PATCH 2/3] RRP-482 todo? --- .../v2/roles-logic-sv2/src/channel_logic/channel_factory.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 720b4436a4..10e4de5394 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 @@ -841,7 +841,7 @@ 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_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 { From 1465536089488a383349bc1d7f68c5157f80aba4 Mon Sep 17 00:00:00 2001 From: romandukhanin Date: Sat, 11 Jan 2025 14:07:02 +0300 Subject: [PATCH 3/3] RRP-482 prepare_share_log in handle_submit --- .../src/services/share_processor.rs | 1 - .../src/channel_logic/channel_factory.rs | 2 -- .../src/lib/downstream_sv1/downstream.rs | 25 +++++++++++++++++++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/nomium/shares-logger/src/services/share_processor.rs b/nomium/shares-logger/src/services/share_processor.rs index 72b5fdcc5b..4827ab6e50 100644 --- a/nomium/shares-logger/src/services/share_processor.rs +++ b/nomium/shares-logger/src/services/share_processor.rs @@ -17,7 +17,6 @@ impl ShareProcessor { ntime: u32, version: u32, hash: [u8; 32], - downstream_target: Target, extranonce: Vec, user_identity_json: String, share_status: ShareStatus, 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 10e4de5394..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 @@ -861,7 +861,6 @@ impl ChannelFactory { m.get_n_time(), m.get_version(), hash, - downstream_target.clone(), extranonce.to_vec(), user_identity, ); */ @@ -877,7 +876,6 @@ impl ChannelFactory { m.get_n_time(), m.get_version(), hash, - downstream_target.clone(), extranonce.to_vec(), user_identity, share_status, 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 } }