summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-19 01:48:58 +0000
committertv <tv@krebsco.de>2026-11-19 03:19:45 +0100
commit295ba74159e371bb9082fcbdada5eaf78de5d1dc (patch)
tree2639551c6526b879107ee23fd5a47036f518f005
parentdd720b2556fa64bd07dc1d087b502ac4ab0f7899 (diff)
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.
-rw-r--r--docs/guides/federation/proposing-and-voting.md6
-rw-r--r--src/federation/client.rs65
-rw-r--r--src/federation/party.rs14
3 files changed, 85 insertions, 0 deletions
diff --git a/docs/guides/federation/proposing-and-voting.md b/docs/guides/federation/proposing-and-voting.md
index 6793271..0c3e1a8 100644
--- a/docs/guides/federation/proposing-and-voting.md
+++ b/docs/guides/federation/proposing-and-voting.md
@@ -93,6 +93,12 @@ record before it sends the vote. It casts no vote that would make its party vote
party backed is dead. The client fetches the votes that made it so from the node, and
keeps them in the record beside the new `true`.
+A `true` holds the party until its proposal passes or is dead, and only other parties'
+nays make it dead. Where ending it would take every party yet to vote, or more, and those
+are a third of the parties or fewer, the client says so before it casts the `true`
+(``Warning: this `true` binds tv until the proposal passes, …``): one of them staying
+quiet binds the party on this version for good, unless the proposal passes.
+
A party votes from one client, with one record: two clients backing two proposals at once
is voting twice, and shows ([`federation.md`](../../federation.md),
[Changing the policy](../../federation.md#changing-the-policy)). A party whose node votes
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<Version, St
Ok(version)
}
+/// Where a `true` of `party` on a proposal on `current`, on which the parties of `yes` and
+/// `no` voted so far, binds it until the proposal passes unless every party yet to vote, or
+/// more, votes `false`, those being a third of the parties or fewer: a `true` holds its
+/// party until the proposal is dead, and nays alone make it so (`docs/federation.md`,
+/// Changing the policy). Why, said; none otherwise.
+pub(crate) fn binding(
+ current: &Version,
+ party: &str,
+ yes: &BTreeSet<String>,
+ no: &BTreeSet<String>,
+) -> Option<String> {
+ 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<String> {
+ names.iter().map(|name| (*name).to_owned()).collect()
+ };
+ let (_, _, _, _, current, _, _) = three();
+ let why = binding(&current, "tv", &set(&[]), &set(&["lass"])).expect("binding");
+ assert!(why.contains("every one of the 1 parties"), "{why}");
+ assert!(binding(&current, "tv", &set(&[]), &set(&[])).is_none());
+ let parties: Vec<Party> = (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.
diff --git a/src/federation/party.rs b/src/federation/party.rs
index 162f8bd..655d4c2 100644
--- a/src/federation/party.rs
+++ b/src/federation/party.rs
@@ -734,6 +734,20 @@ async fn vote(
let kept = record
.may_vote(&current, proposal, &proposed, yes, &nays)
.map_err(|why| anyhow!(why))?;
+ if yes {
+ let parties = |what: &str| -> BTreeSet<String> {
+ ballots[proposal.to_string()][what]
+ .as_array()
+ .into_iter()
+ .flatten()
+ .filter_map(|party| party.as_str().map(str::to_owned))
+ .collect()
+ };
+ if let Some(why) = client::binding(&current, &signer.party, &parties("yes"), &parties("no"))
+ {
+ eprintln!("Warning: {why}");
+ }
+ }
// On the events proposing it the node shows, those above the heads it names for a
// checkpoint, so a version event may be written on it.
let cast = signer.sign(&proposals, event::vote(current.hash, proposal, yes))?;