diff --git a/protocols/v2/channels-sv2/src/client/extended.rs b/protocols/v2/channels-sv2/src/client/extended.rs index d0b8a076de..4cf5f691b0 100644 --- a/protocols/v2/channels-sv2/src/client/extended.rs +++ b/protocols/v2/channels-sv2/src/client/extended.rs @@ -533,11 +533,11 @@ impl<'a> ExtendedChannel<'a> { // check if a block was found if network_target.is_met_by(hash) { self.share_accounting.update_share_accounting( - self.target.difficulty_float() as u64, + self.target.difficulty_float(), share.sequence_number, hash.to_raw_hash(), ); - return Ok(ShareValidationResult::BlockFound); + return Ok(ShareValidationResult::BlockFound(hash.to_raw_hash())); } // check if the share hash meets the channel target @@ -547,7 +547,7 @@ impl<'a> ExtendedChannel<'a> { } self.share_accounting.update_share_accounting( - self.target.difficulty_float() as u64, + self.target.difficulty_float(), share.sequence_number, hash.to_raw_hash(), ); @@ -555,7 +555,7 @@ impl<'a> ExtendedChannel<'a> { // update the best diff self.share_accounting.update_best_diff(hash_as_diff); - return Ok(ShareValidationResult::Valid); + return Ok(ShareValidationResult::Valid(hash.to_raw_hash())); } Err(ShareValidationError::DoesNotMeetTarget) @@ -815,7 +815,7 @@ mod tests { let res = channel.validate_share(share_valid_block); - assert!(matches!(res, Ok(ShareValidationResult::BlockFound))); + assert!(matches!(res, Ok(ShareValidationResult::BlockFound(_)))); } #[test] @@ -1002,7 +1002,7 @@ mod tests { let res = channel.validate_share(valid_share); - assert!(matches!(res, Ok(ShareValidationResult::Valid))); + assert!(matches!(res, Ok(ShareValidationResult::Valid(_)))); // try to cheat by re-submitting the same share // with a different sequence number diff --git a/protocols/v2/channels-sv2/src/client/share_accounting.rs b/protocols/v2/channels-sv2/src/client/share_accounting.rs index ee51074c30..0c53fbaaea 100644 --- a/protocols/v2/channels-sv2/src/client/share_accounting.rs +++ b/protocols/v2/channels-sv2/src/client/share_accounting.rs @@ -13,8 +13,8 @@ use bitcoin::hashes::sha256d::Hash; /// - `BlockFound`: The submitted share resulted in a new block being found. #[derive(Debug)] pub enum ShareValidationResult { - Valid, - BlockFound, + Valid(Hash), + BlockFound(Hash), } /// Possible errors encountered during share validation. @@ -53,7 +53,7 @@ pub enum ShareValidationError { pub struct ShareAccounting { last_share_sequence_number: u32, shares_accepted: u32, - share_work_sum: u64, + share_work_sum: f64, seen_shares: HashSet, best_diff: f64, } @@ -70,7 +70,7 @@ impl ShareAccounting { Self { last_share_sequence_number: 0, shares_accepted: 0, - share_work_sum: 0, + share_work_sum: 0.0, seen_shares: HashSet::new(), best_diff: 0.0, } @@ -83,7 +83,7 @@ impl ShareAccounting { /// - Records share hash to detect duplicates. pub fn update_share_accounting( &mut self, - share_work: u64, + share_work: f64, share_sequence_number: u32, share_hash: Hash, ) { @@ -112,7 +112,7 @@ impl ShareAccounting { } /// Returns the cumulative work of all accepted shares. - pub fn get_share_work_sum(&self) -> u64 { + pub fn get_share_work_sum(&self) -> f64 { self.share_work_sum } diff --git a/protocols/v2/channels-sv2/src/client/standard.rs b/protocols/v2/channels-sv2/src/client/standard.rs index df56ec2d9d..017883b0b5 100644 --- a/protocols/v2/channels-sv2/src/client/standard.rs +++ b/protocols/v2/channels-sv2/src/client/standard.rs @@ -330,11 +330,11 @@ impl<'a> StandardChannel<'a> { // check if a block was found if network_target.is_met_by(hash) { self.share_accounting.update_share_accounting( - self.target.difficulty_float() as u64, + self.target.difficulty_float(), share.sequence_number, hash.to_raw_hash(), ); - return Ok(ShareValidationResult::BlockFound); + return Ok(ShareValidationResult::BlockFound(hash.to_raw_hash())); } // check if the share hash meets the channel target @@ -344,7 +344,7 @@ impl<'a> StandardChannel<'a> { } self.share_accounting.update_share_accounting( - self.target.difficulty_float() as u64, + self.target.difficulty_float(), share.sequence_number, hash.to_raw_hash(), ); @@ -352,7 +352,7 @@ impl<'a> StandardChannel<'a> { // update the best diff self.share_accounting.update_best_diff(hash_as_diff); - return Ok(ShareValidationResult::Valid); + return Ok(ShareValidationResult::Valid(hash.to_raw_hash())); } Err(ShareValidationError::DoesNotMeetTarget) @@ -542,7 +542,7 @@ mod tests { let res = channel.validate_share(share_valid_block); - assert!(matches!(res, Ok(ShareValidationResult::BlockFound))); + assert!(matches!(res, Ok(ShareValidationResult::BlockFound(_)))); } #[test] @@ -691,6 +691,6 @@ mod tests { let res = channel.validate_share(valid_share); - assert!(matches!(res, Ok(ShareValidationResult::Valid))); + assert!(matches!(res, Ok(ShareValidationResult::Valid(_)))); } } diff --git a/protocols/v2/channels-sv2/src/server/extended.rs b/protocols/v2/channels-sv2/src/server/extended.rs index bd20a0d59f..c9fb26be84 100644 --- a/protocols/v2/channels-sv2/src/server/extended.rs +++ b/protocols/v2/channels-sv2/src/server/extended.rs @@ -673,7 +673,7 @@ where // check if a block was found if network_target.is_met_by(hash) { self.share_accounting.update_share_accounting( - self.target.difficulty_float() as u64, + self.target.difficulty_float(), share.sequence_number, hash.to_raw_hash(), ); @@ -687,12 +687,17 @@ where JobOrigin::NewTemplate(template) => { let template_id = template.template_id; return Ok(ShareValidationResult::BlockFound( + hash.to_raw_hash(), Some(template_id), coinbase, )); } JobOrigin::SetCustomMiningJob(_set_custom_mining_job) => { - return Ok(ShareValidationResult::BlockFound(None, coinbase)); + return Ok(ShareValidationResult::BlockFound( + hash.to_raw_hash(), + None, + coinbase, + )); } } } @@ -704,7 +709,7 @@ where } self.share_accounting.update_share_accounting( - self.target.difficulty_float() as u64, + self.target.difficulty_float(), share.sequence_number, hash.to_raw_hash(), ); @@ -712,21 +717,7 @@ where // update the best diff self.share_accounting.update_best_diff(hash_as_diff); - let last_sequence_number = self.share_accounting.get_last_share_sequence_number(); - let new_submits_accepted_count = self.share_accounting.get_shares_accepted(); - let new_shares_sum = self.share_accounting.get_share_work_sum(); - - // if sequence number is a multiple of share_batch_size - // it's time to send a SubmitShares.Success - if self.share_accounting.should_acknowledge() { - Ok(ShareValidationResult::ValidWithAcknowledgement( - last_sequence_number, - new_submits_accepted_count, - new_shares_sum, - )) - } else { - Ok(ShareValidationResult::Valid) - } + Ok(ShareValidationResult::Valid(hash.to_raw_hash())) } else { Err(ShareValidationError::DoesNotMeetTarget) } @@ -1206,7 +1197,10 @@ mod tests { let res = channel.validate_share(share_valid_block); - assert!(matches!(res, Ok(ShareValidationResult::BlockFound(_, _)))); + assert!(matches!( + res, + Ok(ShareValidationResult::BlockFound(_, _, _)) + )); } #[test] @@ -1429,7 +1423,7 @@ mod tests { }; let res = channel.validate_share(valid_share); - assert!(matches!(res, Ok(ShareValidationResult::Valid))); + assert!(matches!(res, Ok(ShareValidationResult::Valid(_)))); // try to cheat by re-submitting the same share // with a different sequence number diff --git a/protocols/v2/channels-sv2/src/server/share_accounting.rs b/protocols/v2/channels-sv2/src/server/share_accounting.rs index 85db09fde4..0b317065a0 100644 --- a/protocols/v2/channels-sv2/src/server/share_accounting.rs +++ b/protocols/v2/channels-sv2/src/server/share_accounting.rs @@ -38,18 +38,13 @@ use std::collections::HashSet; #[derive(Debug)] pub enum ShareValidationResult { /// The share is valid and accepted. - Valid, - /// The share is valid and triggers a batch acknowledgment. - /// Contains: - /// - `last_sequence_number`: The sequence number of the last accepted share in the batch. - /// - `new_submits_accepted_count`: The number of new shares accepted in this batch. - /// - `new_shares_sum`: The total work contributed by shares in this batch. - ValidWithAcknowledgement(u32, u32, u64), + Valid(Hash), /// The share solves a block. /// Contains: + /// - `share_hash`: The hash of the share that solved the block. /// - `template_id`: The template ID associated with the job, or `None` for custom jobs. /// - `coinbase`: The serialized coinbase transaction for the block. - BlockFound(Option, Vec), + BlockFound(Hash, Option, Vec), } /// The error variants that can occur during share validation. @@ -84,7 +79,7 @@ pub enum ShareValidationError { pub struct ShareAccounting { last_share_sequence_number: u32, shares_accepted: u32, - share_work_sum: u64, + share_work_sum: f64, share_batch_size: usize, seen_shares: HashSet, best_diff: f64, @@ -98,7 +93,7 @@ impl ShareAccounting { Self { last_share_sequence_number: 0, shares_accepted: 0, - share_work_sum: 0, + share_work_sum: 0.0, share_batch_size, seen_shares: HashSet::new(), best_diff: 0.0, @@ -112,7 +107,7 @@ impl ShareAccounting { /// - Records the share hash to detect duplicates. pub fn update_share_accounting( &mut self, - share_work: u64, + share_work: f64, share_sequence_number: u32, share_hash: Hash, ) { @@ -141,7 +136,7 @@ impl ShareAccounting { } /// Returns the sum of work contributed by all accepted shares. - pub fn get_share_work_sum(&self) -> u64 { + pub fn get_share_work_sum(&self) -> f64 { self.share_work_sum } diff --git a/protocols/v2/channels-sv2/src/server/standard.rs b/protocols/v2/channels-sv2/src/server/standard.rs index 1ffd3a1a8d..44d0c3e9f1 100644 --- a/protocols/v2/channels-sv2/src/server/standard.rs +++ b/protocols/v2/channels-sv2/src/server/standard.rs @@ -594,7 +594,7 @@ where // check if a block was found if network_target.is_met_by(hash) { self.share_accounting.update_share_accounting( - self.target.difficulty_float() as u64, + self.target.difficulty_float(), share.sequence_number, hash.to_raw_hash(), ); @@ -628,6 +628,7 @@ where .map_err(|_| ShareValidationError::InvalidCoinbase)?; return Ok(ShareValidationResult::BlockFound( + hash.to_raw_hash(), Some(job.get_template().template_id), serialized_coinbase, )); @@ -640,7 +641,7 @@ where } self.share_accounting.update_share_accounting( - self.target.difficulty_float() as u64, + self.target.difficulty_float(), share.sequence_number, hash.to_raw_hash(), ); @@ -648,21 +649,7 @@ where // update the best diff self.share_accounting.update_best_diff(hash_as_diff); - let last_sequence_number = self.share_accounting.get_last_share_sequence_number(); - let new_submits_accepted_count = self.share_accounting.get_shares_accepted(); - let new_shares_sum = self.share_accounting.get_share_work_sum(); - - // if sequence number is a multiple of share_batch_size - // it's time to send a SubmitShares.Success - if self.share_accounting.should_acknowledge() { - Ok(ShareValidationResult::ValidWithAcknowledgement( - last_sequence_number, - new_submits_accepted_count, - new_shares_sum, - )) - } else { - Ok(ShareValidationResult::Valid) - } + Ok(ShareValidationResult::Valid(hash.to_raw_hash())) } else { Err(ShareValidationError::DoesNotMeetTarget) } @@ -1022,7 +1009,10 @@ mod tests { let res = standard_channel.validate_share(share_valid_block); - assert!(matches!(res, Ok(ShareValidationResult::BlockFound(_, _)))); + assert!(matches!( + res, + Ok(ShareValidationResult::BlockFound(_, _, _)) + )); } #[test] @@ -1238,7 +1228,7 @@ mod tests { }; let res = standard_channel.validate_share(valid_share); - assert!(matches!(res, Ok(ShareValidationResult::Valid))); + assert!(matches!(res, Ok(ShareValidationResult::Valid(_)))); } #[test] diff --git a/roles/jd-client/src/lib/channel_manager/downstream_message_handler.rs b/roles/jd-client/src/lib/channel_manager/downstream_message_handler.rs index 6b88979517..abdf0feeaf 100644 --- a/roles/jd-client/src/lib/channel_manager/downstream_message_handler.rs +++ b/roles/jd-client/src/lib/channel_manager/downstream_message_handler.rs @@ -967,33 +967,27 @@ impl HandleMiningMessagesFromClientAsync for ChannelManager { let res = standard_channel.validate_share(msg.clone()); let mut is_downstream_share_valid = false; match res { - Ok(ShareValidationResult::Valid) => { - info!( - "SubmitSharesStandard on downstream channel: valid share | channel_id: {}, sequence_number: {} ☑️", - channel_id, msg.sequence_number - ); - is_downstream_share_valid = true; - } - Ok(ShareValidationResult::ValidWithAcknowledgement( - last_sequence_number, - new_submits_accepted_count, - new_shares_sum, - )) => { - let success = SubmitSharesSuccess { - channel_id, - last_sequence_number, - new_submits_accepted_count, - new_shares_sum, - }; + Ok(ShareValidationResult::Valid(share_hash)) => { + let share_accounting = standard_channel.get_share_accounting(); + if share_accounting.should_acknowledge() { + let success = SubmitSharesSuccess { + channel_id, + last_sequence_number: share_accounting.get_last_share_sequence_number(), + new_submits_accepted_count: share_accounting.get_shares_accepted(), + new_shares_sum: share_accounting.get_share_work_sum() as u64, + }; + info!("SubmitSharesStandard on downstream channel: {} ✅", success); + messages.push((downstream.downstream_id, Mining::SubmitSharesSuccess(success)).into()); + } else { + info!( + "SubmitSharesStandard on downstream channel: valid share | channel_id: {}, sequence_number: {}, share_hash: {} ☑️", + channel_id, msg.sequence_number, share_hash + ); + } is_downstream_share_valid = true; - info!("SubmitSharesStandard on downstream channel: {} ✅", success); - messages.push( - (downstream.downstream_id, - Mining::SubmitSharesSuccess(success)).into(), - ); } - Ok(ShareValidationResult::BlockFound(template_id, coinbase)) => { - info!("SubmitSharesStandard on downstream channel: 💰 Block Found!!! 💰"); + Ok(ShareValidationResult::BlockFound(share_hash, template_id, coinbase)) => { + info!("SubmitSharesStandard on downstream channel: 💰 Block Found!!! 💰{share_hash}"); is_downstream_share_valid = true; if let Some(template_id) = template_id { info!("SubmitSharesStandard: Propagating solution to the Template Provider."); @@ -1012,7 +1006,7 @@ impl HandleMiningMessagesFromClientAsync for ChannelManager { channel_id, last_sequence_number: share_accounting.get_last_share_sequence_number(), new_submits_accepted_count: share_accounting.get_shares_accepted(), - new_shares_sum: share_accounting.get_share_work_sum(), + new_shares_sum: share_accounting.get_share_work_sum() as u64, }; messages.push(( downstream.downstream_id, @@ -1064,17 +1058,17 @@ impl HandleMiningMessagesFromClientAsync for ChannelManager { if let Some(mut upstream_message) = upstream_message { let res = upstream_channel.validate_share(upstream_message.clone()); match res { - Ok(client::share_accounting::ShareValidationResult::Valid) => { + Ok(client::share_accounting::ShareValidationResult::Valid(share_hash)) => { upstream_message.sequence_number = channel_manager_data.sequence_number_factory.fetch_add(1, Ordering::Relaxed); info!( - "SubmitSharesStandard, forwarding it to upstream: valid share | channel_id: {}, sequence_number: {} ✅", - channel_id, upstream_message.sequence_number + "SubmitSharesStandard, forwarding it to upstream: valid share | channel_id: {}, sequence_number: {}, share_hash: {} ✅", + channel_id, upstream_message.sequence_number, share_hash ); messages.push(Mining::SubmitSharesExtended(upstream_message).into()); } - Ok(client::share_accounting::ShareValidationResult::BlockFound) => { + Ok(client::share_accounting::ShareValidationResult::BlockFound(share_hash)) => { upstream_message.sequence_number = channel_manager_data.sequence_number_factory.fetch_add(1, Ordering::Relaxed); - info!("SubmitSharesStandard forwarding it to upstream: 💰 Block Found!!! 💰"); + info!("SubmitSharesStandard forwarding it to upstream: 💰 Block Found!!! 💰{share_hash}"); let push_solution = PushSolution { extranonce: standard_channel.get_extranonce_prefix().to_vec().try_into()?, ntime: upstream_message.ntime, @@ -1168,33 +1162,27 @@ impl HandleMiningMessagesFromClientAsync for ChannelManager { let res = extended_channel.validate_share(msg.clone()); let mut is_downstream_share_valid = false; match res { - Ok(ShareValidationResult::Valid) => { - info!( - "SubmitSharesExtended on downstream channel: valid share | channel_id: {}, sequence_number: {} ☑️", - channel_id, msg.sequence_number - ); - is_downstream_share_valid = true; - } - Ok(ShareValidationResult::ValidWithAcknowledgement( - last_sequence_number, - new_submits_accepted_count, - new_shares_sum, - )) => { - let success = SubmitSharesSuccess { - channel_id, - last_sequence_number, - new_submits_accepted_count, - new_shares_sum, - }; - info!("SubmitSharesExtended on downstream channel: {} ✅", success); + Ok(ShareValidationResult::Valid(share_hash)) => { + let share_accounting = extended_channel.get_share_accounting(); + if share_accounting.should_acknowledge() { + let success = SubmitSharesSuccess { + channel_id, + last_sequence_number: share_accounting.get_last_share_sequence_number(), + new_submits_accepted_count: share_accounting.get_shares_accepted(), + new_shares_sum: share_accounting.get_share_work_sum() as u64, + }; + info!("SubmitSharesExtended on downstream channel: {} ✅", success); + messages.push((downstream.downstream_id, Mining::SubmitSharesSuccess(success)).into()); + } else { + info!( + "SubmitSharesExtended on downstream channel: valid share | channel_id: {}, sequence_number: {}, share_hash: {} ☑️", + channel_id, msg.sequence_number, share_hash + ); + } is_downstream_share_valid = true; - messages.push(( - downstream.downstream_id, - Mining::SubmitSharesSuccess(success), - ).into()); } - Ok(ShareValidationResult::BlockFound(template_id, coinbase)) => { - info!("SubmitSharesExtended on downstream channel: 💰 Block Found!!! 💰"); + Ok(ShareValidationResult::BlockFound(share_hash, template_id, coinbase)) => { + info!("SubmitSharesExtended on downstream channel: 💰 Block Found!!! 💰{share_hash}"); if let Some(template_id) = template_id { info!("SubmitSharesExtended: Propagating solution to the Template Provider."); let solution = SubmitSolution { @@ -1211,7 +1199,7 @@ impl HandleMiningMessagesFromClientAsync for ChannelManager { channel_id, last_sequence_number: share_accounting.get_last_share_sequence_number(), new_submits_accepted_count: share_accounting.get_shares_accepted(), - new_shares_sum: share_accounting.get_share_work_sum(), + new_shares_sum: share_accounting.get_share_work_sum() as u64, }; is_downstream_share_valid = true; messages.push(( @@ -1263,19 +1251,19 @@ impl HandleMiningMessagesFromClientAsync for ChannelManager { if let Some(mut upstream_message) = upstream_message{ let res = upstream_channel.validate_share(upstream_message.clone()); match res { - Ok(client::share_accounting::ShareValidationResult::Valid) => { + Ok(client::share_accounting::ShareValidationResult::Valid(share_hash)) => { upstream_message.sequence_number = channel_manager_data.sequence_number_factory.fetch_add(1, Ordering::Relaxed); info!( - "SubmitSharesExtended forwarding it to upstream: valid share | channel_id: {}, sequence_number: {} ✅", - channel_id, upstream_message.sequence_number + "SubmitSharesExtended forwarding it to upstream: valid share | channel_id: {}, sequence_number: {}, share_hash: {} ✅", + channel_id, upstream_message.sequence_number, share_hash ); messages.push( Mining::SubmitSharesExtended(upstream_message.into_static()).into(), ); } - Ok(client::share_accounting::ShareValidationResult::BlockFound) => { + Ok(client::share_accounting::ShareValidationResult::BlockFound(share_hash)) => { upstream_message.sequence_number = channel_manager_data.sequence_number_factory.fetch_add(1, Ordering::Relaxed); - info!("SubmitSharesExtended forwarding it to upstream: 💰 Block Found!!! 💰"); + info!("SubmitSharesExtended forwarding it to upstream: 💰 Block Found!!! 💰{share_hash}"); let mut channel_extranonce = upstream_channel.get_extranonce_prefix().to_vec(); channel_extranonce.extend_from_slice(&upstream_message.extranonce.to_vec()); let push_solution = PushSolution { diff --git a/roles/pool/src/lib/channel_manager/mining_message_handler.rs b/roles/pool/src/lib/channel_manager/mining_message_handler.rs index 5f2dff2fc5..3e33307413 100644 --- a/roles/pool/src/lib/channel_manager/mining_message_handler.rs +++ b/roles/pool/src/lib/channel_manager/mining_message_handler.rs @@ -529,28 +529,28 @@ impl HandleMiningMessagesFromClientAsync for ChannelManager { match res { - Ok(ShareValidationResult::Valid) => { - info!( - "SubmitSharesStandard: valid share | downstream_id: {}, channel_id: {}, sequence_number: {} ✅", - downstream_id, channel_id, msg.sequence_number - ); - } - Ok(ShareValidationResult::ValidWithAcknowledgement( - last_sequence_number, - new_submits_accepted_count, - new_shares_sum, - )) => { - let success = SubmitSharesSuccess { - channel_id, - last_sequence_number, - new_submits_accepted_count, - new_shares_sum, - }; - info!("SubmitSharesStandard: {} ✅", success); - messages.push((downstream_id, Mining::SubmitSharesSuccess(success)).into()); + Ok(ShareValidationResult::Valid(share_hash)) => { + let share_accounting = standard_channel.get_share_accounting(); + if share_accounting.should_acknowledge() { + let success = SubmitSharesSuccess { + channel_id, + last_sequence_number: share_accounting.get_last_share_sequence_number(), + new_submits_accepted_count: share_accounting.get_shares_accepted(), + new_shares_sum: share_accounting.get_share_work_sum() as u64, + }; + info!("SubmitSharesStandard: {} ✅", success); + messages.push((downstream_id, Mining::SubmitSharesSuccess(success)).into()); + } else { + let share_work = standard_channel.get_target().difficulty_float(); + info!( + "SubmitSharesStandard: valid share | downstream_id: {}, channel_id: {}, sequence_number: {}, share_hash: {}, share_work: {} ✅", + downstream_id, channel_id, msg.sequence_number, share_hash, share_work + ); + } + } - Ok(ShareValidationResult::BlockFound(template_id, coinbase)) => { - info!("SubmitSharesStandard: 💰 Block Found!!! 💰"); + Ok(ShareValidationResult::BlockFound(share_hash, template_id, coinbase)) => { + info!("SubmitSharesStandard: 💰 Block Found!!! 💰{share_hash}"); // if we have a template id (i.e.: this was not a custom job) // we can propagate the solution to the TP if let Some(template_id) = template_id { @@ -569,7 +569,7 @@ impl HandleMiningMessagesFromClientAsync for ChannelManager { channel_id, last_sequence_number: share_accounting.get_last_share_sequence_number(), new_submits_accepted_count: share_accounting.get_shares_accepted(), - new_shares_sum: share_accounting.get_share_work_sum(), + new_shares_sum: share_accounting.get_share_work_sum() as u64, }; messages.push((downstream_id, Mining::SubmitSharesSuccess(success)).into()); } @@ -687,28 +687,27 @@ impl HandleMiningMessagesFromClientAsync for ChannelManager { vardiff.increment_shares_since_last_update(); match res { - Ok(ShareValidationResult::Valid) => { - info!( - "SubmitSharesExtended: valid share | downstream_id: {}, channel_id: {}, sequence_number: {} ✅", - downstream_id, channel_id, msg.sequence_number - ); - } - Ok(ShareValidationResult::ValidWithAcknowledgement( - last_sequence_number, - new_submits_accepted_count, - new_shares_sum, - )) => { - let success = SubmitSharesSuccess { - channel_id, - last_sequence_number, - new_submits_accepted_count, - new_shares_sum, - }; - info!("SubmitSharesExtended: {} ✅", success); - messages.push((downstream_id, Mining::SubmitSharesSuccess(success)).into()); + Ok(ShareValidationResult::Valid(share_hash)) => { + let share_accounting = extended_channel.get_share_accounting(); + if share_accounting.should_acknowledge() { + let success = SubmitSharesSuccess { + channel_id, + last_sequence_number: share_accounting.get_last_share_sequence_number(), + new_submits_accepted_count: share_accounting.get_shares_accepted(), + new_shares_sum: share_accounting.get_share_work_sum() as u64, + }; + info!("SubmitSharesExtended: {} ✅", success); + messages.push((downstream_id, Mining::SubmitSharesSuccess(success)).into()); + } else { + let share_work = extended_channel.get_target().difficulty_float(); + info!( + "SubmitSharesExtended: valid share | downstream_id: {}, channel_id: {}, sequence_number: {}, share_hash: {}, share_work: {} ✅", + downstream_id, channel_id, msg.sequence_number, share_hash, share_work + ); + } } - Ok(ShareValidationResult::BlockFound(template_id, coinbase)) => { - info!("SubmitSharesExtended: 💰 Block Found!!! 💰"); + Ok(ShareValidationResult::BlockFound(share_hash, template_id, coinbase)) => { + info!("SubmitSharesExtended: 💰 Block Found!!! 💰{share_hash}"); // if we have a template id (i.e.: this was not a custom job) // we can propagate the solution to the TP if let Some(template_id) = template_id { @@ -727,7 +726,7 @@ impl HandleMiningMessagesFromClientAsync for ChannelManager { channel_id, last_sequence_number: share_accounting.get_last_share_sequence_number(), new_submits_accepted_count: share_accounting.get_shares_accepted(), - new_shares_sum: share_accounting.get_share_work_sum(), + new_shares_sum: share_accounting.get_share_work_sum() as u64, }; messages.push((downstream_id, Mining::SubmitSharesSuccess(success)).into()); }