From dd720b2556fa64bd07dc1d087b502ac4ab0f7899 Mon Sep 17 00:00:00 2001 From: tv Date: Thu, 19 Nov 2026 01:48:58 +0000 Subject: vote: propose a checkpoint after so many versions The votes cast before count at a history from before too: a proposal that died, or a rival, needs there only the votes it lacked, and after a close vote one key voting twice is enough, at any time until a checkpoint above the version that followed. Nodes that took that version refuse it; one lagging behind, or joining from the root, may take it. `federation.md` said it took the keys of two thirds of the parties. A node voting by itself proposes a checkpoint once so many versions were written since its store's (`--store-propose-versions`), as the design lists: with 1, after every version, so that what keys voting twice grow beside a version ends at a checkpoint above it. `federation.md` says how little a rival version takes, row 20 too, and the guides the option. --- src/federation/vote.rs | 52 +++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 9 deletions(-) (limited to 'src/federation/vote.rs') diff --git a/src/federation/vote.rs b/src/federation/vote.rs index 4c4cdfa..2e5ce15 100644 --- a/src/federation/vote.rs +++ b/src/federation/vote.rs @@ -6,13 +6,13 @@ //! follows voted `true`, never `false`; by default only on a version that only moves to a //! checkpoint (`Version::only_moves_on`), and then only where no proposal that changes //! more holds it back (`holds_back`), as such a version lapses it. -//! * **Proposing a checkpoint**: once so many events are held beyond its checkpoint, 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 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. +//! * **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 +//! 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. //! * **Voting `false` beside**: where it backs a proposal that can still pass, it votes //! `false` on every other proposal on the current version that only moves to a //! checkpoint, so that, of two checkpoints proposed at once, the one it doesn't back @@ -46,8 +46,10 @@ pub(crate) struct Rules { pub(crate) follow_any: bool, /// Proposing a checkpoint once so many events are held beyond the checkpoint... pub(crate) propose_events: Option, - /// ...or so long after the store moved to it, by its own clock. + /// ...or so long after the store moved to it, by its own clock... 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. pub(crate) held_for: Duration, /// Voting `false` on a checkpoint proposed beside one it backs. @@ -407,12 +409,16 @@ pub(crate) fn by_hand( /// that nobody backs but its proposer. fn checkpoint(seen: &Seen<'_>, rules: &Rules, current: &Version, all: &[Proposed]) -> Option { let store = seen.store; + let since = current.number - store.state().checkpoint_version().number; let due = rules .propose_events .is_some_and(|events| store.taken().len() >= events) || rules .propose_every - .is_some_and(|every| seen.since_move >= every); + .is_some_and(|every| seen.since_move >= every) + || rules + .propose_versions + .is_some_and(|versions| since >= versions); if !due || seen.since_move < rules.back_after { return None; } @@ -779,6 +785,34 @@ mod tests { assert!(by_hand(&seen(&store, &long), &rules, &record, next.hash(), false).is_err()); } + /// A node proposes a checkpoint once so many versions were written since its store's: + /// with one, after every version, at heads above it. + #[test] + fn a_node_proposes_a_checkpoint_after_a_version() { + let (tv, lass, _, first, mut store) = three(); + let root = store.id(); + let on = first.hash(); + let next = first.after(on); + let proposal = taken(&mut store, tv.propose(&[root], &next.json())); + let votes = [&tv, &lass] + .map(|party| taken(&mut store, party.vote(&[proposal], on, next.hash(), true))); + let rules = Rules { + propose_versions: Some(1), + ..Rules::default() + }; + let long = |_: &Id| Some(Duration::from_secs(3600)); + let record = record(&store, "makefu"); + assert!(decide(&seen(&store, &long), &rules, &record).is_empty()); + let written = taken(&mut store, harness::version_event(&votes, next.hash())); + let acts = decide(&seen(&store, &long), &rules, &record); + let [Act::Propose(json)] = acts.as_slice() else { + panic!("not one proposal: {acts:?}"); + }; + let version = Version::read(json).unwrap(); + assert_eq!(version.checkpoint, Some(vec![written])); + assert_eq!(version.changes, Some(next.hash())); + } + #[test] fn a_node_proposes_a_checkpoint_at_what_it_held_for_a_while() { let (tv, _, _, first, mut store) = three(); -- cgit v1.3.1