summaryrefslogtreecommitdiffstats
path: root/src/remake/api.rs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-10-26 05:38:41 +0100
committertv <tv@krebsco.de>2026-10-26 05:38:41 +0100
commitf12a839d6e6bdd29a86ac52d5de836519a41aaf0 (patch)
treeb34da34a22292793c991b15a95908f6cd78bb70b /src/remake/api.rs
parent504435444c65efc59c0f7c6881991296258538a7 (diff)
wrap unix timestamps in newtype
Diffstat (limited to 'src/remake/api.rs')
-rw-r--r--src/remake/api.rs33
1 files changed, 17 insertions, 16 deletions
diff --git a/src/remake/api.rs b/src/remake/api.rs
index f5063e0..f019696 100644
--- a/src/remake/api.rs
+++ b/src/remake/api.rs
@@ -75,6 +75,7 @@ use super::records::{
};
use super::{Host, kind, vote};
use crate::api::error_response;
+use crate::clock::UnixMillis;
use crate::document::store::StoreError;
use crate::force::Force;
@@ -105,9 +106,9 @@ pub(crate) struct StartQuery {
rules: Option<String>,
/// Comma-separated hex.
base_heads: Option<String>,
- #[serde(default, with = "crate::units::optional_duration")]
+ #[serde(default, deserialize_with = "crate::units::optional_duration")]
settle: Option<Duration>,
- #[serde(default, with = "crate::units::optional_duration")]
+ #[serde(default, deserialize_with = "crate::units::optional_duration")]
switch_delay: Option<Duration>,
}
@@ -168,11 +169,11 @@ struct StartRequest {
replay_window: Option<RetentionRequest>,
archive_retention: Option<RetentionRequest>,
/// How long votes are collected; twice the dormancy threshold if absent.
- #[serde(default, with = "crate::units::optional_duration")]
+ #[serde(default, deserialize_with = "crate::units::optional_duration")]
settle: Option<Duration>,
/// How long nodes wait after seeing the commit before switching; one keepalive
/// interval if absent. Shorter only with `?force=switchDelay`.
- #[serde(default, with = "crate::units::optional_duration")]
+ #[serde(default, deserialize_with = "crate::units::optional_duration")]
switch_delay: Option<Duration>,
}
@@ -181,7 +182,7 @@ struct StartRequest {
#[serde(rename_all = "camelCase", deny_unknown_fields)]
struct RetentionRequest {
epochs: Option<u64>,
- #[serde(default, with = "crate::units::optional_duration")]
+ #[serde(default, deserialize_with = "crate::units::optional_duration")]
age: Option<Duration>,
}
@@ -205,11 +206,11 @@ const ABORT_FORCE: &[&str] = &["coordinatorActive"];
/// period after it expired. Its coordinator stops committing at expiry
/// (`coordinator::decide`), so an abort from elsewhere and a commit can only cross if
/// their clocks are more than a grace period apart.
-fn abortable_at(record: &Record, grace: u64) -> u64 {
+fn abortable_at(record: &Record, grace: u64) -> UnixMillis {
record
.proposal
.settle_until
- .saturating_add(grace.saturating_mul(2))
+ .plus_ms(grace.saturating_mul(2))
}
/// Why this node may not abort expired `record` now, and the `force` name that would
@@ -219,7 +220,7 @@ fn abort_obstacle(
me: &str,
active_peers: &HashSet<String>,
force: &Force,
- now: u64,
+ now: UnixMillis,
grace: u64,
) -> Option<(String, Option<&'static str>)> {
let at = abortable_at(record, grace);
@@ -227,7 +228,7 @@ fn abort_obstacle(
return Some((
format!(
"only its coordinator may abort it until a grace period after it expired ({}s from now)",
- (at - now).div_ceil(1000)
+ at.ms_since(now).div_ceil(1000)
),
None,
));
@@ -261,10 +262,10 @@ struct ExpiredRemake {
id: String,
coordinator: String,
coordinator_active: bool,
- /// When it expired (Unix milliseconds).
- since: u64,
+ /// When it expired.
+ since: UnixMillis,
/// When another node may abort it (`abortable_at`).
- abortable_at: u64,
+ abortable_at: UnixMillis,
tally: vote::Tally,
}
@@ -516,7 +517,7 @@ async fn start_kind<H: Host>(
},
settle_ms,
proposed_at: now,
- settle_until: now + settle_ms,
+ settle_until: now.plus(settle),
switch_delay_ms: switch_delay.map(|delay| delay.as_millis() as u64),
// Filled in when the proposal is written, from the document at that moment.
electorate: Vec::new(),
@@ -640,13 +641,13 @@ async fn propose<H: Host>(
mut proposal: Proposal,
base: Option<Vec<ChangeHash>>,
supersede: Supersede,
- now: u64,
+ now: UnixMillis,
grace: u64,
) -> Result<Record, StartError> {
let record_id = id.clone();
let electorate_host = host.clone();
let me = host.node_id();
- let started = host.remake().started_at() + grace;
+ let started = host.remake().started_at().plus_ms(grace);
let base_at_commit = kind::by_name(&proposal.kind).is_some_and(|kind| kind.base_at_commit());
let record = host
.commit_doc(move |doc| -> Result<Record, StartError> {
@@ -679,7 +680,7 @@ async fn propose<H: Host>(
coordinator_active: supersede
.active_peers
.contains(&record.proposal.coordinator),
- since: record.proposal.settle_until.saturating_add(grace),
+ since: record.proposal.settle_until.plus_ms(grace),
abortable_at: abortable_at(record, grace),
tally: vote::tally(id, record, &all, &register),
})