From 295ba74159e371bb9082fcbdada5eaf78de5d1dc Mon Sep 17 00:00:00 2001 From: tv Date: Thu, 19 Nov 2026 01:48:58 +0000 Subject: continuum-party: warns before a true that only every nay left ends A `true` holds its party until its proposal passes or is dead, and only other parties' nays make it dead: where the parties yet to vote are too few, one of them staying quiet binds the party on that version for good. The client says so before it casts such a `true` (`client::binding`): where ending the proposal would take every party yet to vote, or more, and those are a third of the parties or fewer. --- src/federation/client.rs | 65 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) (limited to 'src/federation/client.rs') diff --git a/src/federation/client.rs b/src/federation/client.rs index 489741a..da64923 100644 --- a/src/federation/client.rs +++ b/src/federation/client.rs @@ -394,6 +394,43 @@ pub(crate) fn backable(current: &Version, proposed: &Json) -> Result, + no: &BTreeSet, +) -> Option { + let parties = current.parties.len(); + let voted: BTreeSet<&str> = yes + .iter() + .chain(no) + .map(String::as_str) + .chain([party]) + .collect(); + let left = parties.saturating_sub(voted.len()); + // Dead once 3·(parties − no) < 2·parties. + let ending = (parties / 3 + 1).saturating_sub(no.len()); + if left > ending || 3 * left > parties { + return None; + } + Some(if left == ending { + format!( + "this `true` binds {party} until the proposal passes, unless every one of the \ + {left} parties yet to vote votes `false`" + ) + } else { + format!( + "this `true` binds {party} until the proposal passes: {left} parties are yet to \ + vote, and ending it takes {ending} `false`" + ) + }) +} + /// What the version `proposed` changes of `current`, a line each: each field whose value /// differs, and of `keys` and `nodes` each party's, as `field: before -> after`, its JCS /// on either side, `-` where a version lacks it. @@ -760,6 +797,34 @@ mod tests { assert_eq!(voted_twice(&[record]).len(), 1); } + /// A `true` that binds its party until its proposal passes, unless every party yet to + /// vote votes `false`, or more, those a third of the parties or fewer, is said so: of + /// three, one `false` and one to vote; of nine, four `true`, one `false` and three to + /// vote. Others aren't. + #[test] + fn a_true_that_only_every_nay_left_ends_is_said() { + let set = |names: &[&str]| -> BTreeSet { + names.iter().map(|name| (*name).to_owned()).collect() + }; + let (_, _, _, _, current, _, _) = three(); + let why = binding(¤t, "tv", &set(&[]), &set(&["lass"])).expect("binding"); + assert!(why.contains("every one of the 1 parties"), "{why}"); + assert!(binding(¤t, "tv", &set(&[]), &set(&[])).is_none()); + let parties: Vec = (1..=9).map(|n| Party::new(&format!("p{n}"), n)).collect(); + let named: Vec<&Party> = parties.iter().collect(); + let nine = Version::read(&Spec::first(&named, &[]).json()).unwrap(); + let backing = set(&["p1", "p2", "p3", "p4"]); + assert!(binding(&nine, "p6", &backing, &set(&["p5"])).is_some()); + assert!(binding(&nine, "p6", &backing, &set(&[])).is_none()); + assert!(binding(&nine, "p2", &set(&["p1"]), &set(&[])).is_none()); + let more = set(&["p1", "p2", "p3", "p4", "p5"]); + let why = binding(&nine, "p7", &more, &set(&["p6"])).expect("binding"); + assert!( + why.contains("2 parties are yet to vote, and ending it takes 3"), + "{why}" + ); + } + /// A party backs, and proposes, only a version changing the current one whose /// checkpoint, where it names one, names no more heads than an event may be above, and /// none of the current checkpoint's heads. -- cgit v1.3.1