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/node.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/node.rs') diff --git a/src/node.rs b/src/node.rs index 57d961c..5005d30 100644 --- a/src/node.rs +++ b/src/node.rs @@ -12,6 +12,7 @@ use automerge::{ActorId, AutoCommit}; use tokio::sync::{RwLock, broadcast, mpsc, watch}; use tracing::trace; +use crate::clock::Clock; use crate::document::file::DocumentFile; use crate::document::replica::{Epoch, Replica}; use crate::files::Files; @@ -46,6 +47,8 @@ pub(crate) struct NodeConfig { pub(crate) document_file: Option>, /// For `GET /admin/config`. pub(crate) config_report: serde_json::Value, + /// The node's wall clock; `Clock::default()` outside tests. + pub(crate) clock: Arc, } /// A built node whose workers haven't started yet. @@ -91,7 +94,7 @@ impl Node { initial_sync_done: Arc::new(AtomicBool::new(false)), change_events, timing: config.timing, - remake: Arc::new(remake::RemakeState::default()), + remake: Arc::new(remake::RemakeState::new(config.clock.now_millis())), swarm_key: config.swarm_key, run_id: uuid::Uuid::new_v4().into_bytes(), neighbours_k: config.neighbours_k, @@ -114,6 +117,7 @@ impl Node { catch_up_source: Default::default(), catch_up_preference: Default::default(), catch_up_avoided: Default::default(), + clock: config.clock, }; for actor in config.earlier_actors { state.remake.add_own_actor(actor); -- cgit v1.3.1