Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add divide by zero check #4287

Merged
merged 4 commits into from
Jul 13, 2022
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions dan_layer/core/src/models/view_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,19 @@ impl ViewId {
pub fn current_leader(&self, committee_size: usize) -> usize {
#[allow(clippy::cast_possible_truncation)]
let view_id = self.0 as usize;
view_id % committee_size
if committee_size == 0 {
0
} else {
view_id % committee_size
}
}

pub fn is_genesis(&self) -> bool {
self.0 == 0
}

pub fn next(&self) -> ViewId {
ViewId(self.0 + 1)
ViewId(self.0.wrapping_add(1))
}

pub fn as_u64(&self) -> u64 {
Expand Down