aboutsummaryrefslogtreecommitdiffstats
path: root/src/remake/vote.rs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-10-25 23:00:56 +0100
committertv <tv@krebsco.de>2026-10-25 23:00:56 +0100
commit05d1694622a7ef181dbbb4b9c0aeb2f8c07a5b48 (patch)
treec71b14e64257a700771c7af5ed0a86c0fb0f7cbd /src/remake/vote.rs
parenta76e50a0a97de28fd22a0c6c366b31f1b40859f8 (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.rs16
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,
- &register,
- started,
- unix_millis(),
- grace,
- )?;
+ let id = choice(&voter, &wanted, &all, &register, 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, &register, started, now, grace)