Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
node: Protect against non-monotonic clocks
cloudhead committed 2 years ago
commit e5df616ead14ccfa6a75e8ca6b359de42d64d458
parent bb5355fcb1a47e6a6ac3e441e2b807906d7ef135
2 files changed +13 -3
modified Cargo.lock
@@ -1736,9 +1736,9 @@ checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c"

[[package]]
name = "localtime"
-
version = "1.3.0"
+
version = "1.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-
checksum = "71c67b83b03434bb31132aef0b314b8a49a0db55ce195c7e3c29d27bbf003819"
+
checksum = "016a009e0bb8ba6e3229fb74bf11a8fe6ef24542cc6ef35ef38863ac13f96d87"
dependencies = [
 "serde",
]
modified radicle-node/src/service.rs
@@ -676,7 +676,17 @@ where
            "Tick +{}",
            now - self.started_at.expect("Service::tick: service must be initialized")
        );
-
        self.clock = now;
+
        if now >= self.clock {
+
            self.clock = now;
+
        } else {
+
            // Nb. In tests, we often move the clock forwards in time to test different behaviors,
+
            // so this warning isn't applicable there.
+
            #[cfg(not(test))]
+
            warn!(
+
                target: "service",
+
                "System clock is not monotonic: {now} is not greater or equal to {}", self.clock
+
            );
+
        }
    }

    pub fn wake(&mut self) {