@@ -50,18 +50,22 @@ pub enum ShareValidationError {
5050/// - highest difficulty seen in validated shares
5151///
5252/// **Acceptance phase** (updated by the application layer via [`on_share_acknowledgement`]):
53- /// - total accepted shares (confirmed by upstream [`SubmitSharesSuccess`])
53+ /// - total acknowledged shares (confirmed by upstream [`SubmitSharesSuccess`])
54+ /// - total rejected shares (reported by upstream [`SubmitSharesError`])
5455/// - cumulative work from accepted shares
5556/// - number of blocks found
5657///
5758/// [`validate_share`]: super::extended::ExtendedChannel::validate_share
5859/// [`track_validated_share`]: ShareAccounting::track_validated_share
5960/// [`on_share_acknowledgement`]: ShareAccounting::on_share_acknowledgement
6061/// [`SubmitSharesSuccess`]: mining_sv2::SubmitSharesSuccess
62+ /// [`SubmitSharesError`]: mining_sv2::SubmitSharesError
6163#[ derive( Clone , Debug ) ]
6264pub struct ShareAccounting {
6365 last_share_sequence_number : u32 ,
64- shares_accepted : u32 ,
66+ acknowledged_shares : u32 ,
67+ validated_shares : u32 ,
68+ rejected_shares : u32 ,
6569 share_work_sum : f64 ,
6670 seen_shares : HashSet < Hash > ,
6771 best_diff : f64 ,
@@ -79,7 +83,9 @@ impl ShareAccounting {
7983 pub fn new ( ) -> Self {
8084 Self {
8185 last_share_sequence_number : 0 ,
82- shares_accepted : 0 ,
86+ acknowledged_shares : 0 ,
87+ validated_shares : 0 ,
88+ rejected_shares : 0 ,
8389 share_work_sum : 0.0 ,
8490 seen_shares : HashSet :: new ( ) ,
8591 best_diff : 0.0 ,
@@ -99,10 +105,18 @@ impl ShareAccounting {
99105 new_submits_accepted_count : u32 ,
100106 new_shares_sum : f64 ,
101107 ) {
102- self . shares_accepted += new_submits_accepted_count;
108+ self . acknowledged_shares += new_submits_accepted_count;
103109 self . share_work_sum += new_shares_sum;
104110 }
105111
112+ /// Updates rejection accounting based on a [`SubmitSharesError`] message from the upstream
113+ /// server.
114+ ///
115+ /// One call corresponds to one rejected share.
116+ pub fn on_share_rejection ( & mut self ) {
117+ self . rejected_shares += 1 ;
118+ }
119+
106120 /// Records a share that passed local validation.
107121 ///
108122 /// Adds the hash to the seen set for duplicate detection and updates the last sequence
@@ -111,6 +125,7 @@ impl ShareAccounting {
111125 /// called when the upstream server confirms via [`SubmitSharesSuccess`].
112126 pub fn track_validated_share ( & mut self , share_sequence_number : u32 , share_hash : Hash ) {
113127 self . last_share_sequence_number = share_sequence_number;
128+ self . validated_shares += 1 ;
114129 self . seen_shares . insert ( share_hash) ;
115130 }
116131
@@ -127,9 +142,19 @@ impl ShareAccounting {
127142 self . last_share_sequence_number
128143 }
129144
130- /// Returns the total number of shares accepted.
131- pub fn get_shares_accepted ( & self ) -> u32 {
132- self . shares_accepted
145+ /// Returns the total number of shares acknowledged by upstream.
146+ pub fn get_acknowledged_shares ( & self ) -> u32 {
147+ self . acknowledged_shares
148+ }
149+
150+ /// Returns the total number of locally validated shares.
151+ pub fn get_validated_shares ( & self ) -> u32 {
152+ self . validated_shares
153+ }
154+
155+ /// Returns the total number of shares rejected by upstream.
156+ pub fn get_rejected_shares ( & self ) -> u32 {
157+ self . rejected_shares
133158 }
134159
135160 /// Returns the cumulative work of all accepted shares.
0 commit comments