Skip to content

Commit aee5c4a

Browse files
committed
refactor: avoid using Duration
1 parent c6655aa commit aee5c4a

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/tasks/block/sim.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -237,20 +237,19 @@ impl SimulatorTask {
237237
// Get the current number of milliseconds into the slot.
238238
let timepoint_ms =
239239
self.slot_calculator().current_point_within_slot_ms().expect("host chain has started");
240-
let slot_duration = Duration::from_secs(self.slot_calculator().slot_duration()).as_millis();
241-
let elapsed_in_slot = Duration::from_millis(timepoint_ms);
242-
let query_cutoff_buffer = Duration::from_millis(self.config.block_query_cutoff_buffer);
240+
241+
let slot_duration = self.slot_calculator().slot_duration() * 1000; // convert to milliseconds
242+
let query_cutoff_buffer = self.config.block_query_cutoff_buffer;
243243

244244
// To find the remaining slot time, subtract the timepoint from the slot duration.
245245
// Then subtract the block query cutoff buffer from the slot duration to account for
246246
// the sequencer stopping signing.
247-
let remaining = slot_duration
248-
.saturating_sub(elapsed_in_slot.as_millis())
249-
.saturating_sub(query_cutoff_buffer.as_millis());
247+
let remaining =
248+
slot_duration.saturating_sub(timepoint_ms).saturating_sub(query_cutoff_buffer);
250249

251250
// The deadline is then calculated by adding the remaining time from this instant.
252251
// NB: Downcast is okay because u64 will work for 500 million+ years.
253-
let deadline = Instant::now() + Duration::from_millis(remaining as u64);
252+
let deadline = Instant::now() + Duration::from_millis(remaining);
254253
deadline.max(Instant::now())
255254
}
256255
}

0 commit comments

Comments
 (0)