Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions protocols/v2/channels-sv2/src/client/extended.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
}
}
Expand Down
12 changes: 10 additions & 2 deletions protocols/v2/channels-sv2/src/client/share_accounting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,26 @@ pub struct ShareAccounting {
share_work_sum: u64,
seen_shares: HashSet<Hash>,
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,
}
}

Expand Down Expand Up @@ -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
}
}
4 changes: 2 additions & 2 deletions protocols/v2/channels-sv2/src/client/standard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ impl<'a> StandardChannel<'a> {
) -> Self {
Self {
channel_id,
user_identity,
user_identity: user_identity.clone(),
extranonce_prefix,
target,
nominal_hashrate,
future_jobs: HashMap::new(),
active_job: None,
past_jobs: HashMap::new(),
stale_jobs: HashMap::new(),
share_accounting: ShareAccounting::new(),
share_accounting: ShareAccounting::new(user_identity),
chain_tip: None,
}
}
Expand Down
4 changes: 2 additions & 2 deletions protocols/v2/channels-sv2/src/server/extended.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,15 +225,15 @@ 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,
target,
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,
Expand Down
10 changes: 9 additions & 1 deletion protocols/v2/channels-sv2/src/server/share_accounting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,20 +86,23 @@ pub struct ShareAccounting {
share_batch_size: usize,
seen_shares: HashSet<Hash>,
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,
share_work_sum: 0,
share_batch_size,
seen_shares: HashSet::new(),
best_diff: 0.0,
user_identity,
}
}

Expand Down Expand Up @@ -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
}
}
4 changes: 2 additions & 2 deletions protocols/v2/channels-sv2/src/server/standard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading