diff options
| author | tv <tv@krebsco.de> | 2026-10-25 23:00:56 +0100 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-10-25 23:00:56 +0100 |
| commit | c52d4b5ae43c202569c8801c312c2b56954ff8a0 (patch) | |
| tree | dac7221b966d9f4fdb8e1b91b1e20bce607de6fc /src/remake/vote.rs | |
| parent | 2f7265795b7f6ddf460bf93c5f880fb24bde9d3a (diff) | |
add clock module
The Clock module is the system clock that every unix timestamp new goes
through. It comes with an offset that only tests can set.
Diffstat (limited to 'src/remake/vote.rs')
| -rw-r--r-- | src/remake/vote.rs | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/src/remake/vote.rs b/src/remake/vote.rs index b4936dc..9e28cde 100644 --- a/src/remake/vote.rs +++ b/src/remake/vote.rs @@ -28,7 +28,7 @@ use tracing::{info, warn}; use super::Host; use super::content; -use super::records::{self, Decision, EpochRecord, Phase, Record, Register, Vote, unix_millis}; +use super::records::{self, Decision, EpochRecord, Phase, Record, Register, Vote}; use crate::document::store::StoreError; /// A majority of `electorate` members. @@ -235,19 +235,12 @@ pub(super) async fn cast<H: Host>(host: &H) { // Usually there is nothing to vote on: look first, without writing. let (voter, wanted) = (me.clone(), epoch.clone()); + let now = host.now_millis(); let due = host .read_doc(move |doc| { let all = records::load_all(doc); let register = records::load_register(doc); - let id = choice( - &voter, - &wanted, - &all, - ®ister, - started, - unix_millis(), - grace, - )?; + let id = choice(&voter, &wanted, &all, ®ister, started, now, grace)?; let content = all .into_iter() .find(|(other, _)| *other == id) @@ -267,9 +260,10 @@ pub(super) async fn cast<H: Host>(host: &H) { // Decided again under the write lock, so two passes can't both vote. let voter = me.clone(); + let clock = host.clock(); let result = host .commit_doc(move |doc| -> Result<Option<String>, StoreError> { - let now = unix_millis(); + let now = clock.now_millis(); let all = records::load_all(doc); let register = records::load_register(doc); let Some(id) = choice(&voter, &epoch, &all, ®ister, started, now, grace) |
