Skip to content

Commit

Permalink
Use saturating_sub consistently
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszrzasik committed Dec 12, 2024
1 parent f82a563 commit 718b0df
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
11 changes: 4 additions & 7 deletions crates/task-impls/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,11 +353,7 @@ impl<

/// Cancel all tasks for previous views
pub fn cancel_tasks(&mut self, view: TYPES::View) {
if *view == 0 {
return;
}
let keep_view = view - 1;
let keep = self.transmit_tasks.split_off(&keep_view);
let keep = self.transmit_tasks.split_off(&view);

while let Some((_, tasks)) = self.transmit_tasks.pop_first() {
for task in tasks {
Expand Down Expand Up @@ -676,12 +672,13 @@ impl<
if epoch > self.epoch {
self.epoch = epoch;
}
self.cancel_tasks(view);
let keep_view = TYPES::View::new(view.saturating_sub(1));
self.cancel_tasks(keep_view);
let net = Arc::clone(&self.network);
let epoch = self.epoch.u64();
let mem = self.membership.clone();
spawn(async move {
net.update_view::<TYPES>(view.saturating_sub(1), epoch, &mem)
net.update_view::<TYPES>(keep_view, epoch, &mem)
.await;
});
None
Expand Down
6 changes: 4 additions & 2 deletions crates/task-impls/src/quorum_proposal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -529,10 +529,12 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Versions>
if epoch > &self.cur_epoch {
self.cur_epoch = *epoch;
}
self.cancel_tasks(*view);
let keep_view = TYPES::View::new(view.saturating_sub(1));
self.cancel_tasks(keep_view);
}
HotShotEvent::Timeout(view, ..) => {
self.cancel_tasks(*view);
let keep_view = TYPES::View::new(view.saturating_sub(1));
self.cancel_tasks(keep_view);
}
HotShotEvent::HighQcSend(qc, ..) => {
ensure!(qc.view_number() > self.highest_qc.view_number());
Expand Down

0 comments on commit 718b0df

Please sign in to comment.