Skip to content

Commit bc4f992

Browse files
authored
fix leader participation (#3617)
1 parent 925bb33 commit bc4f992

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

crates/hotshot/types/src/consensus.rs

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,13 @@ impl<TYPES: NodeType> ValidatorParticipation<TYPES> {
342342
num_proposed as f64 / num_leader as f64
343343
};
344344
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+
});
347352
(
348353
current_epoch_participation_ratio,
349354
last_epoch_participation_ratio,
@@ -353,13 +358,31 @@ impl<TYPES: NodeType> ValidatorParticipation<TYPES> {
353358
fn current_proposal_participation(&self) -> HashMap<TYPES::SignatureKey, f64> {
354359
self.current_epoch_participation
355360
.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+
})
357371
.collect()
358372
}
359373
fn previous_proposal_participation(&self) -> HashMap<TYPES::SignatureKey, f64> {
360374
self.last_epoch_participation
361375
.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+
})
363386
.collect()
364387
}
365388
}

0 commit comments

Comments
 (0)