From efaf79e7fd55db2b9704ccefedde33346f874a1d Mon Sep 17 00:00:00 2001 From: tv Date: Thu, 19 Nov 2026 03:56:57 +0000 Subject: vote: a node proposes a checkpoint at the heads it holds A node proposed a checkpoint at the heads of what it held for a while: every event written in that while, and every one built on an event beside those heads, as one party writing now and then on something old makes them, was beside them, and refused once the store moved. A voter whose while was shorter backed none, one whose while was longer backed it and lost those. It proposes at the heads its store holds, sorted: what was written before is in their history, and only what is written while the vote takes its course may be beside them. It proposes none where they are more than an event may name: under a revision with merge events, it merges them first; otherwise, what is written after does. `--store-held-for` keeps the voters' rule and how long a new proposal holds back a checkpoint. `federation.md`, the guides and the options say so. --- src/federation/vote.rs | 53 ++++++++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 25 deletions(-) (limited to 'src/federation/vote.rs') diff --git a/src/federation/vote.rs b/src/federation/vote.rs index c274849..4ba2e8f 100644 --- a/src/federation/vote.rs +++ b/src/federation/vote.rs @@ -9,8 +9,8 @@ //! the revision. //! * **Proposing a checkpoint**: once so many events are held beyond its checkpoint, so //! many versions were written since, or so long after it moved there by its own clock, it -//! proposes a version that only moves to a checkpoint, at the heads of what it held for a -//! while, where no proposal on the current version holds it back: one it would back that +//! proposes a version that only moves to a checkpoint, at the heads its store holds, no +//! more than an event may name, where no proposal on the current version holds it back: one it would back that //! can still pass, one that can still pass that a third of the parties back, someone but //! its proposer among them, or one new, held less than a while, whose proposer has no //! older one on the version (`holds_back`). It backs what it proposes. @@ -51,7 +51,8 @@ pub(crate) struct Rules { pub(crate) propose_every: Option, /// ...or once so many versions were written since the one it holds. pub(crate) propose_versions: Option, - /// How long it holds an event before it holds it for a while. + /// How long it holds an event before it holds it for a while: the voters' rule, and how + /// long a new proposal holds back a checkpoint. pub(crate) held_for: Duration, /// Voting `false` on a checkpoint proposed beside one it backs. pub(crate) nay_beside: bool, @@ -414,9 +415,10 @@ pub(crate) fn by_hand( } /// The version that only moves to a checkpoint the node proposes now, if its rules have it -/// propose one: at the heads of what it held for a while, at which the current version is -/// current, where nothing that can still pass is proposed on it, but one it wouldn't back -/// that nobody backs but its proposer. +/// propose one: at the heads its store holds, at which the current version is current, +/// where no proposal on it holds it back. None where they are more than an event may name: +/// the node merges them first, under a revision with merge events (`Holding::merge`), or +/// what is written after does. fn checkpoint(seen: &Seen<'_>, rules: &Rules, current: &Version, all: &[Proposed]) -> Option { let store = seen.store; let since = current.number - store.state().checkpoint_version().number; @@ -442,23 +444,11 @@ fn checkpoint(seen: &Seen<'_>, rules: &Rules, current: &Version, all: &[Proposed if blocked { return None; } - let held: BTreeSet = store - .taken() - .iter() - .filter(|id| (seen.held)(id).is_some_and(|held| held >= rules.held_for)) - .copied() - .collect(); - let built_on: BTreeSet = held - .iter() - .filter_map(|id| store.get(id)) - .filter_map(|bytes| match Event::read_taken(bytes)? { - Event::Signed(Signed { deps, .. }) | Event::Version { deps, .. } => Some(deps), - }) - .flatten() - .collect(); - let heads: Vec = held.difference(&built_on).copied().collect(); - // No event is above more heads than it may name: what is written merges them. - if heads.is_empty() + // Its heads, which nothing taken builds on: the checkpoint's own, where nothing came + // after it, which a later checkpoint names not. + let mut heads = store.heads(); + heads.sort_unstable(); + if store.taken().is_empty() || heads.len() > super::event::DEPENDENCIES || store.state_at(&heads).current().hash != current.hash { @@ -848,8 +838,10 @@ mod tests { assert_eq!(version.changes, Some(next.hash())); } + /// A node proposes a checkpoint at the heads its store holds, the one it took a moment + /// ago among them; none where they are more than an event may name. #[test] - fn a_node_proposes_a_checkpoint_at_what_it_held_for_a_while() { + fn a_node_proposes_a_checkpoint_at_the_heads_it_holds() { let (tv, _, _, first, mut store) = three(); let root = store.id(); let old = taken( @@ -875,7 +867,7 @@ mod tests { panic!("not one proposal: {acts:?}"); }; let version = Version::read(json).unwrap(); - assert_eq!(version.checkpoint, Some(vec![old])); + assert_eq!(version.checkpoint, Some(vec![new])); assert!(version.only_moves_on(store.state().current())); assert_eq!(version.changes, Some(first.hash())); // Not due: none. @@ -892,6 +884,17 @@ mod tests { let acts = decide(&seen(&store, &held), &rules, &record); assert_eq!(acts.len(), 1); assert!(matches!(&acts[0], Act::Vote { yes: true, .. })); + // Heads apart, more than an event may name. + let (tv, _, _, _, mut apart) = three(); + let root = apart.id(); + for n in 0..=crate::federation::event::DEPENDENCIES { + taken( + &mut apart, + tv.write(&[root], &format!("home/tv/k{n}"), harness::str("1")), + ); + } + let record = super::tests::record(&apart, "tv"); + assert!(decide(&seen(&apart, &held), &rules, &record).is_empty()); } /// Two checkpoints proposed at once: a node backing one votes `false` on the other by -- cgit v1.3.1