@@ -59,7 +59,8 @@ pub struct Reporter<E: CryptoRngCore, S: Scheme, L: ElectorConfig<S>, D: Digest>
5959 pub finalizes : Arc < Mutex < Participation < S :: PublicKey , D > > > ,
6060 pub finalizations : Arc < Mutex < HashMap < View , Finalization < S , D > > > > ,
6161 pub faults : Arc < Mutex < Faults < S , D > > > ,
62- pub invalid : Arc < Mutex < usize > > ,
62+ pub invalid_votes : Arc < Mutex < usize > > ,
63+ pub invalid_certificates : Arc < Mutex < usize > > ,
6364
6465 latest : Arc < Mutex < View > > ,
6566 subscribers : Arc < Mutex < Vec < Sender < View > > > > ,
9091 finalizes : Arc :: new ( Mutex :: new ( HashMap :: new ( ) ) ) ,
9192 finalizations : Arc :: new ( Mutex :: new ( HashMap :: new ( ) ) ) ,
9293 faults : Arc :: new ( Mutex :: new ( HashMap :: new ( ) ) ) ,
93- invalid : Arc :: new ( Mutex :: new ( 0 ) ) ,
94+ invalid_votes : Arc :: new ( Mutex :: new ( 0 ) ) ,
95+ invalid_certificates : Arc :: new ( Mutex :: new ( 0 ) ) ,
9496 latest : Arc :: new ( Mutex :: new ( View :: zero ( ) ) ) ,
9597 subscribers : Arc :: new ( Mutex :: new ( Vec :: new ( ) ) ) ,
9698 }
@@ -108,6 +110,18 @@ where
108110 self . participants . key ( leader) . cloned ( ) . unwrap ( )
109111 } ) ;
110112 }
113+
114+ pub fn assert_no_faults ( & self ) {
115+ let faults = self . faults . lock ( ) ;
116+ assert ! ( faults. is_empty( ) , "faults detected" ) ;
117+ }
118+
119+ pub fn assert_no_invalid ( & self ) {
120+ let invalid_votes = self . invalid_votes . lock ( ) ;
121+ let invalid_certificates = self . invalid_certificates . lock ( ) ;
122+ assert_eq ! ( * invalid_votes, 0 , "invalid votes detected" ) ;
123+ assert_eq ! ( * invalid_certificates, 0 , "invalid certificates detected" ) ;
124+ }
111125}
112126
113127impl < E , S , L , D > crate :: Reporter for Reporter < E , S , L , D >
@@ -123,12 +137,10 @@ where
123137 // We check signatures for all messages to ensure that the prover is working correctly
124138 // but in production this isn't necessary (as signatures are already verified in
125139 // consensus).
126- let verified = activity. verified ( ) ;
127140 match & activity {
128141 Activity :: Notarize ( notarize) => {
129142 if !notarize. verify ( & mut self . context , & self . scheme , & Sequential ) {
130- assert ! ( !verified) ;
131- * self . invalid . lock ( ) += 1 ;
143+ * self . invalid_votes . lock ( ) += 1 ;
132144 return ;
133145 }
134146 let encoded = notarize. encode ( ) ;
@@ -153,8 +165,7 @@ where
153165 & notarization. certificate ,
154166 & Sequential ,
155167 ) {
156- assert ! ( !verified) ;
157- * self . invalid . lock ( ) += 1 ;
168+ * self . invalid_certificates . lock ( ) += 1 ;
158169 return ;
159170 }
160171 let encoded = notarization. encode ( ) ;
@@ -165,8 +176,7 @@ where
165176 }
166177 Activity :: Nullify ( nullify) => {
167178 if !nullify. verify ( & mut self . context , & self . scheme , & Sequential ) {
168- assert ! ( !verified) ;
169- * self . invalid . lock ( ) += 1 ;
179+ * self . invalid_votes . lock ( ) += 1 ;
170180 return ;
171181 }
172182 let encoded = nullify. encode ( ) ;
@@ -189,8 +199,7 @@ where
189199 & nullification. certificate ,
190200 & Sequential ,
191201 ) {
192- assert ! ( !verified) ;
193- * self . invalid . lock ( ) += 1 ;
202+ * self . invalid_certificates . lock ( ) += 1 ;
194203 return ;
195204 }
196205 let encoded = nullification. encode ( ) ;
@@ -203,8 +212,7 @@ where
203212 }
204213 Activity :: Finalize ( finalize) => {
205214 if !finalize. verify ( & mut self . context , & self . scheme , & Sequential ) {
206- assert ! ( !verified) ;
207- * self . invalid . lock ( ) += 1 ;
215+ * self . invalid_votes . lock ( ) += 1 ;
208216 return ;
209217 }
210218 let encoded = finalize. encode ( ) ;
@@ -229,8 +237,7 @@ where
229237 & finalization. certificate ,
230238 & Sequential ,
231239 ) {
232- assert ! ( !verified) ;
233- * self . invalid . lock ( ) += 1 ;
240+ * self . invalid_certificates . lock ( ) += 1 ;
234241 return ;
235242 }
236243 let encoded = finalization. encode ( ) ;
@@ -249,8 +256,7 @@ where
249256 Activity :: ConflictingNotarize ( conflicting) => {
250257 let view = conflicting. view ( ) ;
251258 if !conflicting. verify ( & mut self . context , & self . scheme , & Sequential ) {
252- assert ! ( !verified) ;
253- * self . invalid . lock ( ) += 1 ;
259+ * self . invalid_votes . lock ( ) += 1 ;
254260 return ;
255261 }
256262 let encoded = conflicting. encode ( ) ;
@@ -267,8 +273,7 @@ where
267273 Activity :: ConflictingFinalize ( conflicting) => {
268274 let view = conflicting. view ( ) ;
269275 if !conflicting. verify ( & mut self . context , & self . scheme , & Sequential ) {
270- assert ! ( !verified) ;
271- * self . invalid . lock ( ) += 1 ;
276+ * self . invalid_votes . lock ( ) += 1 ;
272277 return ;
273278 }
274279 let encoded = conflicting. encode ( ) ;
@@ -285,8 +290,7 @@ where
285290 Activity :: NullifyFinalize ( conflicting) => {
286291 let view = conflicting. view ( ) ;
287292 if !conflicting. verify ( & mut self . context , & self . scheme , & Sequential ) {
288- assert ! ( !verified) ;
289- * self . invalid . lock ( ) += 1 ;
293+ * self . invalid_votes . lock ( ) += 1 ;
290294 return ;
291295 }
292296 let encoded = conflicting. encode ( ) ;
0 commit comments