From fb54044c688e0252b4af54a057151b9c4d4ccf98 Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 24 Nov 2026 18:58:32 +0000 Subject: federation: no true on a checkpoint at heads no version may name A version event is refused where the heads its version names for a checkpoint have one in another's history, or aren't after the current checkpoint (may_move). Neither the voters' rule nor what a node tells clients asked that: votes on such a proposal are taken, no version event on them ever is, so nothing lapses, and every party that voted true stays bound until others' nays end it. A followed key proposing one bound all its followers; with two thirds of the parties so, nothing passed on that version again. may_move's part about the heads is may_name now, which backs_checkpoint asks before a true, and GET /events/counts says as none, so that a party's client backs no such proposal either. --- src/federation/fold.rs | 36 ++++++++++++++++++----------- src/federation/vote.rs | 62 ++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 83 insertions(+), 15 deletions(-) (limited to 'src/federation') diff --git a/src/federation/fold.rs b/src/federation/fold.rs index c636a13..b96cf1f 100644 --- a/src/federation/fold.rs +++ b/src/federation/fold.rs @@ -610,9 +610,30 @@ impl State { } /// Whether a version event on `deps` may write a version naming `heads` for a - /// checkpoint: after the checkpoint current at its history, at which that one is - /// current too, none in another's history; and the version event above them. + /// checkpoint: heads a version may name (`may_name`), and the version event above + /// them. fn may_move(&self, heads: &[Id], deps: &[Id]) -> Result<(), Refused> { + self.may_name(heads)?; + let named: BTreeSet = heads.iter().copied().collect(); + let above = self.above(&named); + let is_above = deps + .iter() + .all(|dep| named.contains(dep) || above.contains(dep)) + && (deps.iter().any(|dep| above.contains(dep)) + || named.iter().all(|head| deps.contains(head))); + if !is_above { + return Err(Refused::new( + "not above the heads of the checkpoint it names", + )); + } + Ok(()) + } + + /// Whether a version written here may name `heads` for a checkpoint: after the + /// checkpoint current at its history, at which that one is current too, none in + /// another's history. Where not, no version event naming them is taken, whatever it + /// builds on: a `true` on such a version binds its party to what is never written. + pub(crate) fn may_name(&self, heads: &[Id]) -> Result<(), Refused> { if heads .iter() .any(|a| heads.iter().any(|b| a != b && self.built_on(a, b))) @@ -655,17 +676,6 @@ impl State { "checkpoint heads not after the current checkpoint, or at which it isn't current", )); } - let above = self.above(&named); - let is_above = deps - .iter() - .all(|dep| named.contains(dep) || above.contains(dep)) - && (deps.iter().any(|dep| above.contains(dep)) - || named.iter().all(|head| deps.contains(head))); - if !is_above { - return Err(Refused::new( - "not above the heads of the checkpoint it names", - )); - } Ok(()) } diff --git a/src/federation/vote.rs b/src/federation/vote.rs index a633b0e..530b339 100644 --- a/src/federation/vote.rs +++ b/src/federation/vote.rs @@ -156,8 +156,9 @@ fn proposed(seen: &Seen<'_>, current: &Version) -> Vec { /// Whether the node backs `version`, proposed `proposed_held` ago, by the voters' rule: one /// naming a checkpoint only where it changes nothing of `current` but its number, what it /// changes and its checkpoint, and its heads leave out nothing the node held for a while -/// before it was proposed, proposals and votes aside, which lapse with the move; and only -/// once its store held its checkpoint, or ran, for a while (`Rules::back_after`). +/// before it was proposed, proposals and votes aside, which lapse with the move, and are +/// heads a version may name (`State::may_name`); and only once its store held its +/// checkpoint, or ran, for a while (`Rules::back_after`). pub(crate) fn backs_checkpoint( seen: &Seen<'_>, rules: &Rules, @@ -173,6 +174,13 @@ pub(crate) fn backs_checkpoint( "a checkpoint that changes more than its number and what it changes".to_owned(), ); } + // Heads no version may name: votes on it are taken, and no version event on them. + if let Err(why) = seen.store.state().may_name(heads) { + return Err(format!( + "no version event may name its heads ({}): a `true` on it is never written on", + why.0 + )); + } if seen.since_move < rules.back_after { return Err(format!( "its store held its checkpoint, or ran, {}s: it backs a later one after {}s", @@ -559,6 +567,56 @@ mod tests { assert_eq!(store.beside(&[head]), vec![beside, write]); } + /// The voters' rule backs no checkpoint at heads no version may name, one in + /// another's history say: votes on it are taken, no version event on them is, and a + /// `true` there would bind the party to what is never written. + #[test] + fn a_node_backs_no_checkpoint_at_heads_no_version_may_name() { + let (tv, _, _, first, mut store) = three(); + let root = store.id(); + let under = taken( + &mut store, + tv.write(&[root], "home/tv/a", harness::str("1")), + ); + let over = taken( + &mut store, + tv.write(&[under], "home/tv/a", harness::str("2")), + ); + let mut checkpoint = first.after(first.hash()); + checkpoint.checkpoint = Some(vec![under, over]); + let version = Version::read(&checkpoint.json()).unwrap(); + let rules = Rules { + held_for: Duration::from_secs(60), + ..Rules::default() + }; + let long = |_: &Id| Some(Duration::from_secs(3600)); + let seen = Seen { + store: &store, + held: &long, + since_move: Duration::from_secs(86400), + }; + let current = store.state().current().clone(); + let why = backs_checkpoint(&seen, &rules, ¤t, &version, Duration::ZERO) + .expect_err("no version event names those heads"); + assert!(why.contains("one in another's history"), "{why}"); + // The votes are taken, and no version event on them is. + let proposal = taken(&mut store, tv.propose(&[over], &checkpoint.json())); + let (lass, makefu) = (Party::new("lass", 2), Party::new("makefu", 3)); + let votes: Vec = [&tv, &lass, &makefu] + .iter() + .map(|party| { + taken( + &mut store, + party.vote(&[proposal], first.hash(), checkpoint.hash(), true), + ) + }) + .collect(); + assert!(matches!( + store.offer(harness::version_event(&votes, checkpoint.hash())), + Offered::Refused(_) + )); + } + #[test] fn a_node_follows_a_party_on_checkpoints() { let (tv, lass, _, first, mut store) = three(); -- cgit v1.3.1