From c52d4b5ae43c202569c8801c312c2b56954ff8a0 Mon Sep 17 00:00:00 2001 From: tv Date: Sun, 25 Oct 2026 23:00:56 +0100 Subject: 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. --- src/remake/api.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'src/remake/api.rs') diff --git a/src/remake/api.rs b/src/remake/api.rs index 0428a43..24fb7e8 100644 --- a/src/remake/api.rs +++ b/src/remake/api.rs @@ -69,7 +69,7 @@ use super::coordinator; use super::local::LocalStatus; use super::records::{ self, AbortRequest, ContentRef, Decision, EpochRecord, Phase, Policy, Proposal, Record, - Retention, Vote, unix_millis, + Retention, Vote, }; use super::{Host, kind, vote}; use crate::document::store::StoreError; @@ -299,7 +299,7 @@ fn grace(host: &H) -> u64 { fn report(host: &H, id: String, record: Record) -> Report { Report { - phase: record.phase(unix_millis(), grace(host)), + phase: record.phase(host.now_millis(), grace(host)), local: host.remake().status(&id), id, record, @@ -502,7 +502,7 @@ async fn start_kind( _ => {} } - let now = unix_millis(); + let now = host.now_millis(); let settle_ms = settle.as_millis() as u64; let id = Uuid::new_v4().to_string(); let grace = grace(&host); @@ -887,7 +887,7 @@ async fn abort_by_id(host: H, id: String, query: AbortQuery) -> Respons if current.record.abort_requested.is_none() { let request = AbortRequest { by: host.node_id(), - at: unix_millis(), + at: host.now_millis(), }; let record_id = id.clone(); if let Err(error) = host @@ -926,7 +926,7 @@ async fn abort_expired(host: &H, current: Report, force: &Force) -> Res &host.node_id(), &active_peers(host).await, force, - unix_millis(), + host.now_millis(), grace, ) { return error_response( @@ -946,11 +946,12 @@ async fn abort_expired(host: &H, current: Report, force: &Force) -> Res "aborted by operator via {} after it expired", host.node_id() ), - decided_at: unix_millis(), + decided_at: host.now_millis(), }; + let clock = host.clock(); let written = host .commit_doc(move |doc| -> Result { - let now = unix_millis(); + let now = clock.now_millis(); let expired = records::load(doc, &record_id).is_some_and(|record| { record.phase(now, grace) == Phase::Expired && now >= abortable_at(&record, grace) }); -- cgit v1.3.1