@@ -342,8 +342,13 @@ impl<TYPES: NodeType> ValidatorParticipation<TYPES> {
342
342
num_proposed as f64 / num_leader as f64
343
343
} ;
344
344
let last_epoch_participation = self . last_epoch_participation . get ( & key) ;
345
- let last_epoch_participation_ratio =
346
- last_epoch_participation. map ( |( leader, proposed) | * leader as f64 / * proposed as f64 ) ;
345
+ let last_epoch_participation_ratio = last_epoch_participation. map ( |( leader, proposed) | {
346
+ if * leader == 0 {
347
+ 0.0
348
+ } else {
349
+ * proposed as f64 / * leader as f64
350
+ }
351
+ } ) ;
347
352
(
348
353
current_epoch_participation_ratio,
349
354
last_epoch_participation_ratio,
@@ -353,13 +358,31 @@ impl<TYPES: NodeType> ValidatorParticipation<TYPES> {
353
358
fn current_proposal_participation ( & self ) -> HashMap < TYPES :: SignatureKey , f64 > {
354
359
self . current_epoch_participation
355
360
. iter ( )
356
- . map ( |( key, ( leader, proposed) ) | ( key. clone ( ) , * leader as f64 / * proposed as f64 ) )
361
+ . map ( |( key, ( leader, proposed) ) | {
362
+ (
363
+ key. clone ( ) ,
364
+ if * leader == 0 {
365
+ 0.0
366
+ } else {
367
+ * proposed as f64 / * leader as f64
368
+ } ,
369
+ )
370
+ } )
357
371
. collect ( )
358
372
}
359
373
fn previous_proposal_participation ( & self ) -> HashMap < TYPES :: SignatureKey , f64 > {
360
374
self . last_epoch_participation
361
375
. iter ( )
362
- . map ( |( key, ( leader, proposed) ) | ( key. clone ( ) , * leader as f64 / * proposed as f64 ) )
376
+ . map ( |( key, ( leader, proposed) ) | {
377
+ (
378
+ key. clone ( ) ,
379
+ if * leader == 0 {
380
+ 0.0
381
+ } else {
382
+ * proposed as f64 / * leader as f64
383
+ } ,
384
+ )
385
+ } )
363
386
. collect ( )
364
387
}
365
388
}
0 commit comments