From 08b485fa5bc67ccba3c751480249de874dd33eea Mon Sep 17 00:00:00 2001 From: Gary Krause Date: Wed, 24 Sep 2025 12:28:58 -0400 Subject: [PATCH] feat: add user_identity to ShareAccounting --- protocols/v2/channels-sv2/src/client/extended.rs | 4 ++-- .../v2/channels-sv2/src/client/share_accounting.rs | 12 ++++++++++-- protocols/v2/channels-sv2/src/client/standard.rs | 4 ++-- protocols/v2/channels-sv2/src/server/extended.rs | 4 ++-- .../v2/channels-sv2/src/server/share_accounting.rs | 10 +++++++++- protocols/v2/channels-sv2/src/server/standard.rs | 4 ++-- 6 files changed, 27 insertions(+), 11 deletions(-) diff --git a/protocols/v2/channels-sv2/src/client/extended.rs b/protocols/v2/channels-sv2/src/client/extended.rs index b39978b40d..e5ac4c314d 100644 --- a/protocols/v2/channels-sv2/src/client/extended.rs +++ b/protocols/v2/channels-sv2/src/client/extended.rs @@ -90,7 +90,7 @@ impl<'a> ExtendedChannel<'a> { ) -> Self { Self { channel_id, - user_identity, + user_identity: user_identity.clone(), extranonce_prefix, rollable_extranonce_size, target, @@ -100,7 +100,7 @@ impl<'a> ExtendedChannel<'a> { active_job: None, past_jobs: HashMap::new(), stale_jobs: HashMap::new(), - share_accounting: ShareAccounting::new(), + share_accounting: ShareAccounting::new(user_identity), chain_tip: None, } } diff --git a/protocols/v2/channels-sv2/src/client/share_accounting.rs b/protocols/v2/channels-sv2/src/client/share_accounting.rs index bd9f1de5ca..09b3504889 100644 --- a/protocols/v2/channels-sv2/src/client/share_accounting.rs +++ b/protocols/v2/channels-sv2/src/client/share_accounting.rs @@ -53,23 +53,26 @@ pub struct ShareAccounting { share_work_sum: u64, seen_shares: HashSet, best_diff: f64, + user_identity: String, } impl Default for ShareAccounting { fn default() -> Self { - Self::new() + Self::new(String::new()) } } impl ShareAccounting { /// Creates a new [`ShareAccounting`] instance, initializing all statistics to zero. - pub fn new() -> Self { + /// `user_identity` is the identity string associated with the channel. + pub fn new(user_identity: String) -> Self { Self { last_share_sequence_number: 0, shares_accepted: 0, share_work_sum: 0, seen_shares: HashSet::new(), best_diff: 0.0, + user_identity, } } @@ -129,4 +132,9 @@ impl ShareAccounting { self.best_diff = diff; } } + + /// Returns the user identity string associated with this channel. + pub fn get_user_identity(&self) -> &String { + &self.user_identity + } } diff --git a/protocols/v2/channels-sv2/src/client/standard.rs b/protocols/v2/channels-sv2/src/client/standard.rs index a0d0294601..5dfb812628 100644 --- a/protocols/v2/channels-sv2/src/client/standard.rs +++ b/protocols/v2/channels-sv2/src/client/standard.rs @@ -68,7 +68,7 @@ impl<'a> StandardChannel<'a> { ) -> Self { Self { channel_id, - user_identity, + user_identity: user_identity.clone(), extranonce_prefix, target, nominal_hashrate, @@ -76,7 +76,7 @@ impl<'a> StandardChannel<'a> { active_job: None, past_jobs: HashMap::new(), stale_jobs: HashMap::new(), - share_accounting: ShareAccounting::new(), + share_accounting: ShareAccounting::new(user_identity), chain_tip: None, } } diff --git a/protocols/v2/channels-sv2/src/server/extended.rs b/protocols/v2/channels-sv2/src/server/extended.rs index 71d33e4ca1..8bf4eae6b8 100644 --- a/protocols/v2/channels-sv2/src/server/extended.rs +++ b/protocols/v2/channels-sv2/src/server/extended.rs @@ -225,7 +225,7 @@ where Ok(Self { channel_id, - user_identity, + user_identity: user_identity.clone(), extranonce_prefix, rollable_extranonce_size: available_rollable_extranonce_size, requested_max_target: max_target, @@ -233,7 +233,7 @@ where nominal_hashrate, job_store, job_factory: JobFactory::new(version_rolling_allowed, pool_tag, miner_tag), - share_accounting: ShareAccounting::new(share_batch_size), + share_accounting: ShareAccounting::new(share_batch_size, user_identity), expected_share_per_minute, chain_tip: None, phantom: PhantomData, diff --git a/protocols/v2/channels-sv2/src/server/share_accounting.rs b/protocols/v2/channels-sv2/src/server/share_accounting.rs index 4369b1610a..b72f475241 100644 --- a/protocols/v2/channels-sv2/src/server/share_accounting.rs +++ b/protocols/v2/channels-sv2/src/server/share_accounting.rs @@ -86,13 +86,15 @@ pub struct ShareAccounting { share_batch_size: usize, seen_shares: HashSet, best_diff: f64, + user_identity: String, } impl ShareAccounting { /// Constructs a new `ShareAccounting` instance for a channel. /// /// `share_batch_size` controls how many accepted shares trigger a batch acknowledgment. - pub fn new(share_batch_size: usize) -> Self { + /// `user_identity` is the identity string associated with the channel. + pub fn new(share_batch_size: usize, user_identity: String) -> Self { Self { last_share_sequence_number: 0, shares_accepted: 0, @@ -100,6 +102,7 @@ impl ShareAccounting { share_batch_size, seen_shares: HashSet::new(), best_diff: 0.0, + user_identity, } } @@ -169,4 +172,9 @@ impl ShareAccounting { self.best_diff = diff; } } + + /// Returns the user identity string associated with this channel. + pub fn get_user_identity(&self) -> &String { + &self.user_identity + } } diff --git a/protocols/v2/channels-sv2/src/server/standard.rs b/protocols/v2/channels-sv2/src/server/standard.rs index 986b864f8c..b0e207a59e 100644 --- a/protocols/v2/channels-sv2/src/server/standard.rs +++ b/protocols/v2/channels-sv2/src/server/standard.rs @@ -205,12 +205,12 @@ where Ok(Self { channel_id, - user_identity, + user_identity: user_identity.clone(), extranonce_prefix, requested_max_target, target, nominal_hashrate, - share_accounting: ShareAccounting::new(share_batch_size), + share_accounting: ShareAccounting::new(share_batch_size, user_identity), expected_share_per_minute, job_factory: JobFactory::new(true, pool_tag_string, miner_tag_string), chain_tip: None,