Skip to content
Draft
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
2 changes: 1 addition & 1 deletion sv2/channels-sv2/src/client/extended.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ impl<'a> ExtendedChannel<'a> {
pub fn on_share_acknowledgement(
&mut self,
new_submits_accepted_count: u32,
new_shares_sum: f64,
new_shares_sum: u64,
) {
self.share_accounting
.on_share_acknowledgement(new_submits_accepted_count, new_shares_sum);
Expand Down
10 changes: 5 additions & 5 deletions sv2/channels-sv2/src/client/share_accounting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub struct ShareAccounting {
acknowledged_shares: u32,
validated_shares: u32,
rejected_shares: u32,
share_work_sum: f64,
share_work_sum: u64,
seen_shares: HashSet<Hash>,
best_diff: f64,
blocks_found: u32,
Expand All @@ -87,7 +87,7 @@ impl ShareAccounting {
acknowledged_shares: 0,
validated_shares: 0,
rejected_shares: 0,
share_work_sum: 0.0,
share_work_sum: 0,
seen_shares: HashSet::new(),
best_diff: 0.0,
blocks_found: 0,
Expand All @@ -104,10 +104,10 @@ impl ShareAccounting {
pub fn on_share_acknowledgement(
&mut self,
new_submits_accepted_count: u32,
new_shares_sum: f64,
new_shares_sum: u64,
) {
self.acknowledged_shares += new_submits_accepted_count;
self.share_work_sum += new_shares_sum;
self.share_work_sum = self.share_work_sum.saturating_add(new_shares_sum);
}

/// Updates rejection accounting based on a [`SubmitSharesError`] message from the upstream
Expand Down Expand Up @@ -159,7 +159,7 @@ impl ShareAccounting {
}

/// Returns the cumulative work of all accepted shares.
pub fn get_share_work_sum(&self) -> f64 {
pub fn get_share_work_sum(&self) -> u64 {
self.share_work_sum
}

Expand Down
2 changes: 1 addition & 1 deletion sv2/channels-sv2/src/client/standard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ impl<'a> StandardChannel<'a> {
pub fn on_share_acknowledgement(
&mut self,
new_submits_accepted_count: u32,
new_shares_sum: f64,
new_shares_sum: u64,
) {
self.share_accounting
.on_share_acknowledgement(new_submits_accepted_count, new_shares_sum);
Expand Down
7 changes: 5 additions & 2 deletions sv2/channels-sv2/src/server/share_accounting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,11 @@ impl ShareAccounting {
}

/// Returns the sum of work contributed by shares in the last batch.
pub fn get_last_batch_work_sum(&self) -> f64 {
self.last_batch_work_sum
///
/// Note: this is meant to be used for `SubmitShares.Success` messages.
/// Therefore, it truncates `f64` into `u64`.
pub fn get_last_batch_work_sum(&self) -> u64 {
self.last_batch_work_sum as u64
}

/// Returns the total number of shares accepted on this channel.
Expand Down
Loading