refactor: improve the deadline module#423
Conversation
15a9863 to
02b53d2
Compare
|
|
||
| /// Wall-clock start of the given slot: `genesis_time + slot * | ||
| /// slot_duration`. | ||
| fn slot_start(&self, slot: SlotNumber) -> Result<DateTime<Utc>> { |
There was a problem hiding this comment.
would be good to have a unit test for it
|
|
||
| /// Network-delay margin added to every deadline: `slot_duration / | ||
| /// MARGIN_FACTOR`. | ||
| fn margin(&self) -> Result<Millis> { |
8b1312b to
82815f3
Compare
| label = %self.label, | ||
| duty = %curr_duty, | ||
| "Deadliner output channel full" | ||
| ); |
There was a problem hiding this comment.
Maybe return some small sleep time here to retry in a while?
|
@claude review the changes |
|
Claude finished @therustmonk's task in 3m 32s —— View job Code Review: PR #423 — refactor: improve the deadline module
SummaryNice refactor overall. Splitting the 743-line A few correctness and design points below. Correctness1. Sentinel duty can leak to the output channel after ~10 years of idle — When fn handle_expired(&mut self) -> Option<Duration> {
if self.duties.is_empty() {
// Sentinel timer fired with no real duty; just reschedule.
return Some(self.remaining_duration());
}
// ...rest unchanged
}2.
3. mskrzypkows's comment on The reviewer suggests returning a small sleep time to retry instead of dropping the duty. The current behavior — log + drop + advance — matches 4. Not a bug, just wasteful: we already know the new duty has the smallest deadline, so an O(n) scan re-confirms what we already know. Could be: self.duties.insert(duty.clone());
self.curr_duty = duty;
self.curr_deadline = deadline;
Some(self.remaining_duration())Skip if you want to keep the code path uniform — the HashSet is small in practice. Design / API5. The thing that
The doc comment on 6.
7. Module-level doc and struct-level doc say the same thing nearly verbatim. Drop one. Tests8. Real-time tests with sub-second deadlines are notorious on loaded CI. The 5s timeout for ~1s expirations is generous, but consider 9. The test does 10. Voluntary-exits test path is misleading — The Other
VerdictSolid refactor, well-tested, faithful to Charon. The points above are mostly polish; the only real correctness item is #1 (sentinel-duty leak after 10y idle) and the #2 buffer-size deviation from Charon, which the golden rule on functional equivalence asks us to justify or revert. |
| use super::{Result, millis::Millis, to_chrono_duration}; | ||
|
|
||
| /// Fraction of slot duration to use as a margin for network delays. | ||
| const MARGIN_FACTOR: i32 = 12; |
There was a problem hiding this comment.
This can be i64 from the begin, no casting later
|
|
||
| /// Duty-type-specific offset from slot start. | ||
| fn duty_duration(&self, duty_type: &DutyType) -> Result<Millis> { | ||
| let secs = Millis::from(self.slot_duration); |
There was a problem hiding this comment.
msecs is better name i think, it's Millis
No description provided.