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/config/mod.rs | 14 ++++++++++++++ src/federation/fold.rs | 5 +++++ src/federation/vote.rs | 52 +++++++++++++++++++++++++++++++++++++++++--------- src/lib.rs | 1 + 4 files changed, 63 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/config/mod.rs b/src/config/mod.rs index feb16e3..0e6e1b9 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -305,6 +305,14 @@ pub(crate) const OPTIONS: &[OptionSpec] = &[ "With store-vote-key: propose a checkpoint, as store-propose-events, once this long passed by its own clock since its store moved to its checkpoint, or started there.", ), #[cfg(feature = "federation")] + option( + "store-propose-versions", + Kind::Integer, + "COUNT", + None, + "With store-vote-key: propose a checkpoint, as store-propose-events, once this many versions were written since its store's checkpoint: with 1, after every version, so that what keys voting twice could grow beside it at a history from before ends there.", + ), + #[cfg(feature = "federation")] option( "store-held-for", Kind::Duration, @@ -835,6 +843,8 @@ pub(crate) struct Settings { )] pub(crate) store_propose_every: Option, #[cfg(feature = "federation")] + pub(crate) store_propose_versions: Option, + #[cfg(feature = "federation")] #[serde( default = "default_store_held_for", with = "crate::units::duration_option" @@ -1370,6 +1380,10 @@ impl Settings { ("store-nay-beside", self.store_nay_beside), ("store-propose-events", self.store_propose_events.is_some()), ("store-propose-every", self.store_propose_every.is_some()), + ( + "store-propose-versions", + self.store_propose_versions.is_some(), + ), ]; match (&self.store_vote_key, &self.store_vote_record) { (Some(_), None) => { diff --git a/src/federation/fold.rs b/src/federation/fold.rs index 46f56e1..3670051 100644 --- a/src/federation/fold.rs +++ b/src/federation/fold.rs @@ -348,6 +348,11 @@ impl State { ballots } + /// The checkpoint's version: the one current where the store moved there, or started. + pub(crate) fn checkpoint_version(&self) -> &Version { + &self.versions[&self.checkpoint] + } + /// The version the proposal of hash `proposal` proposes, as JSON, where it holds one: /// whether it is a version is asked apart (`Version::read`). pub(crate) fn proposal(&self, proposal: &Id) -> Option<&Json> { 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(); diff --git a/src/lib.rs b/src/lib.rs index 66d54bc..5873a89 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -69,6 +69,7 @@ fn voter(args: &config::Settings) -> Result> { nay_beside: args.store_nay_beside, propose_events: args.store_propose_events, propose_every: args.store_propose_every, + propose_versions: args.store_propose_versions, held_for: args.store_held_for, back_after: args.store_back_after, }, -- cgit v1.3.1