Skip to content

Commit d675892

Browse files
authored
Remove immediate timer reset. (#4323)
Messages are reliably delivered until garbage collection. Additional retries may just fill up the outbound message buffers of peers. Change `Timer` to fire only once to avoid repeated timeouts. Thus after a timer expires it needs to be reset to make it fire again.
1 parent ffd6f4f commit d675892

2 files changed

Lines changed: 12 additions & 7 deletions

File tree

crates/hotshot/new-protocol/src/coordinator.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -306,11 +306,6 @@ where
306306
},
307307
() = &mut self.timer => {
308308
let input = ConsensusInput::Timeout(self.timer.view(), self.timer.epoch());
309-
// Timer is only reset so we can resend the timeout vote
310-
// This isn't strictly necessary for the protocol, but it's a good idea to
311-
// resend the timeout vote to avoid a situation where the network is stuck
312-
// view because we fail to form a timeout certificate.
313-
self.timer.reset();
314309
return Ok(input)
315310
}
316311
Some(output) = self.state_manager.next() => {

crates/hotshot/new-protocol/src/coordinator/timer.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::{
22
pin::Pin,
3-
task::{Context, Poll},
3+
task::{Context, Poll, ready},
44
time::Duration,
55
};
66

@@ -12,6 +12,7 @@ pub struct Timer {
1212
view: ViewNumber,
1313
epoch: EpochNumber,
1414
duration: Duration,
15+
done: bool,
1516
}
1617

1718
impl Timer {
@@ -21,6 +22,7 @@ impl Timer {
2122
view: v,
2223
epoch: e,
2324
duration: d,
25+
done: false,
2426
}
2527
}
2628

@@ -33,16 +35,19 @@ impl Timer {
3335
}
3436

3537
pub fn reset(&mut self) {
38+
self.done = false;
3639
self.sleep.as_mut().reset(Instant::now() + self.duration);
3740
}
3841

3942
pub fn reset_with(&mut self, v: ViewNumber) {
4043
self.view = v;
44+
self.done = false;
4145
self.sleep.as_mut().reset(Instant::now() + self.duration);
4246
}
4347
pub fn reset_with_epoch(&mut self, v: ViewNumber, e: EpochNumber) {
4448
self.view = v;
4549
self.epoch = e;
50+
self.done = false;
4651
self.sleep.as_mut().reset(Instant::now() + self.duration);
4752
}
4853
}
@@ -51,6 +56,11 @@ impl Future for Timer {
5156
type Output = ();
5257

5358
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<()> {
54-
self.sleep.as_mut().poll(cx)
59+
if self.done {
60+
return Poll::Pending;
61+
}
62+
ready!(self.sleep.as_mut().poll(cx));
63+
self.done = true;
64+
Poll::Ready(())
5565
}
5666
}

0 commit comments

Comments
 (0)