@@ -45,23 +45,28 @@ pub enum ShareValidationError {
4545/// Used only on Mining Clients. Share accounting is split into two phases:
4646///
4747/// **Validation phase** (updated by [`validate_share`] via [`track_validated_share`]):
48+ /// - total validated shares (shares that passed local validation)
4849/// - hashes of seen shares (for duplicate detection)
4950/// - last received share's sequence number
5051/// - highest difficulty seen in validated shares
5152///
5253/// **Acceptance phase** (updated by the application layer via [`on_share_acknowledgement`]):
53- /// - total accepted shares (confirmed by upstream [`SubmitSharesSuccess`])
54+ /// - total acknowledged shares (confirmed by upstream [`SubmitSharesSuccess`])
55+ /// - total rejected shares (reported by upstream [`SubmitSharesError`])
5456/// - cumulative work from accepted shares
5557/// - number of blocks found
5658///
5759/// [`validate_share`]: super::extended::ExtendedChannel::validate_share
5860/// [`track_validated_share`]: ShareAccounting::track_validated_share
5961/// [`on_share_acknowledgement`]: ShareAccounting::on_share_acknowledgement
6062/// [`SubmitSharesSuccess`]: mining_sv2::SubmitSharesSuccess
63+ /// [`SubmitSharesError`]: mining_sv2::SubmitSharesError
6164#[ derive( Clone , Debug ) ]
6265pub struct ShareAccounting {
6366 last_share_sequence_number : u32 ,
64- shares_accepted : u32 ,
67+ acknowledged_shares : u32 ,
68+ validated_shares : u32 ,
69+ rejected_shares : u32 ,
6570 share_work_sum : f64 ,
6671 seen_shares : HashSet < Hash > ,
6772 best_diff : f64 ,
@@ -79,7 +84,9 @@ impl ShareAccounting {
7984 pub fn new ( ) -> Self {
8085 Self {
8186 last_share_sequence_number : 0 ,
82- shares_accepted : 0 ,
87+ acknowledged_shares : 0 ,
88+ validated_shares : 0 ,
89+ rejected_shares : 0 ,
8390 share_work_sum : 0.0 ,
8491 seen_shares : HashSet :: new ( ) ,
8592 best_diff : 0.0 ,
@@ -99,10 +106,18 @@ impl ShareAccounting {
99106 new_submits_accepted_count : u32 ,
100107 new_shares_sum : f64 ,
101108 ) {
102- self . shares_accepted += new_submits_accepted_count;
109+ self . acknowledged_shares += new_submits_accepted_count;
103110 self . share_work_sum += new_shares_sum;
104111 }
105112
113+ /// Updates rejection accounting based on a [`SubmitSharesError`] message from the upstream
114+ /// server.
115+ ///
116+ /// One call corresponds to one rejected share.
117+ pub fn on_share_rejection ( & mut self ) {
118+ self . rejected_shares += 1 ;
119+ }
120+
106121 /// Records a share that passed local validation.
107122 ///
108123 /// Adds the hash to the seen set for duplicate detection and updates the last sequence
@@ -111,6 +126,7 @@ impl ShareAccounting {
111126 /// called when the upstream server confirms via [`SubmitSharesSuccess`].
112127 pub fn track_validated_share ( & mut self , share_sequence_number : u32 , share_hash : Hash ) {
113128 self . last_share_sequence_number = share_sequence_number;
129+ self . validated_shares += 1 ;
114130 self . seen_shares . insert ( share_hash) ;
115131 }
116132
@@ -127,9 +143,19 @@ impl ShareAccounting {
127143 self . last_share_sequence_number
128144 }
129145
130- /// Returns the total number of shares accepted.
131- pub fn get_shares_accepted ( & self ) -> u32 {
132- self . shares_accepted
146+ /// Returns the total number of shares acknowledged by upstream.
147+ pub fn get_acknowledged_shares ( & self ) -> u32 {
148+ self . acknowledged_shares
149+ }
150+
151+ /// Returns the total number of locally validated shares.
152+ pub fn get_validated_shares ( & self ) -> u32 {
153+ self . validated_shares
154+ }
155+
156+ /// Returns the total number of shares rejected by upstream.
157+ pub fn get_rejected_shares ( & self ) -> u32 {
158+ self . rejected_shares
133159 }
134160
135161 /// Returns the cumulative work of all accepted shares.
0 commit comments