diff options
| author | tv <tv@krebsco.de> | 2026-11-25 12:57:24 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-25 12:57:24 +0000 |
| commit | 1820e326115f803ffa84280aad4e367f20d91e9f (patch) | |
| tree | 24b3e1ec3eb498b7770dbdd082f4fd8f19fb011d | |
| parent | 8a34ccaf072e9f91ea6103cb96926833ef0f57f9 (diff) | |
federation: a second true on the nays that end the first, no more
A party's true after one that died builds on the nays that freed it, and
an event builds on 64 at most. may_vote kept every vote it was given,
once for each earlier true: a node gives it all on the version, a client
all on the proposals its party backed. A proposal all of 64 parties voted
on was past that already, and below, one party signed its false 64 times
on other dependencies, each of which the fold takes: by hand the vote
failed, a node skipped it and said nothing.
Now it keeps, for each earlier true, one false of each party, of the
lowest ID, of the first parties by name, as many as end the proposal: a
third of the parties and one (ending).
| -rw-r--r-- | CHANGELOG.md | 5 | ||||
| -rw-r--r-- | src/federation/client.rs | 75 |
2 files changed, 76 insertions, 4 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index b5ecc43..b123947 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ it from the release before ([`docs/operations.md`](docs/operations.md), ## Unreleased +* A party's second `true` builds on just the nays that end its first: one of each party, + of as many parties as it takes. It built on every vote held, so one party signing its + `false` again and again, or 64 parties voting, left a freed party unable to vote + ([`src/federation/client.rs`](src/federation/client.rs)). + * A node voting by itself proposes a checkpoint a random wait after one is due, and none beside another node's that it would back: proposing at once, each at the heads it held then, nodes made as many proposals, each party's one `true` on its own diff --git a/src/federation/client.rs b/src/federation/client.rs index 74be7c8..32e3b70 100644 --- a/src/federation/client.rs +++ b/src/federation/client.rs @@ -200,6 +200,35 @@ impl Vote { } } +/// Of `nays`, each checked from itself and `on`, those that make the proposal `proposal` +/// on `on` dead, so many parties voting `false` that the rest can't pass it: of each party +/// one, of the lowest ID, of the first parties by name, as many as it takes and no more. +/// None where they don't. Other parties sign as many votes as they like, and a vote builds +/// on few events (`building`): these are a third of the parties and one. +fn ending(on: &Version, proposal: &Id, nays: &[Vec<u8>]) -> Option<Vec<Vec<u8>>> { + let mut no: BTreeMap<String, (Id, &Vec<u8>)> = BTreeMap::new(); + for bytes in nays { + let Some(vote) = Vote::read(bytes, true) else { + continue; + }; + if !vote.counts_on(on) || vote.proposal != *proposal || vote.yes { + continue; + } + let id = Id::of(bytes); + let lowest = no.entry(vote.party).or_insert((id, bytes)); + if id < lowest.0 { + *lowest = (id, bytes); + } + } + let needed = on.parties.len() / 3 + 1; + (no.len() >= needed).then(|| { + no.into_values() + .take(needed) + .map(|(_, bytes)| bytes.clone()) + .collect() + }) +} + /// Whether `nays`, each checked from itself and `on`, make the proposal `proposal` on `on` /// dead: so many parties voted `false` that the rest can't pass it. fn dead_by(on: &Version, proposal: &Id, nays: &[Vec<u8>]) -> bool { @@ -314,7 +343,7 @@ impl Record { /// `nays` to keep with it, or why not. Never `true` and `false` on one proposal, nor /// the same twice; none on the version it began on; a `true` only for a version, and /// one at a time: its party's earlier `true` on `current` must be on a proposal the - /// `nays` make dead. + /// `nays` make dead, and of them it keeps those that do, no more (`ending`). pub(crate) fn may_vote( &self, current: &Version, @@ -341,15 +370,19 @@ impl Record { return Ok(Vec::new()); } backable(current, proposed)?; - let mut kept = Vec::new(); + let mut kept: Vec<Vec<u8>> = Vec::new(); for earlier in cast.iter().filter(|vote| vote.yes) { - if !dead_by(current, &earlier.proposal, nays) { + let Some(ending) = ending(current, &earlier.proposal, nays) else { return Err(format!( "one `true` at a time: the party's on {} isn't dead by the votes given", earlier.proposal )); + }; + for nay in ending { + if !kept.contains(&nay) { + kept.push(nay); + } } - kept.extend(nays.iter().cloned()); } Ok(kept) } @@ -1509,6 +1542,40 @@ mod tests { assert!(building(y, false, &many).is_err()); } + /// A second `true` keeps just the nays that end the first: of each party one, of the + /// lowest ID, and of no more parties than end it. Given every vote on the version, as + /// a node gives them, one party's `false` signed again and again on other dependencies + /// among them, it kept them all, and a vote builds on 64 events at most. + #[test] + fn a_second_true_keeps_only_the_nays_that_end_the_first() { + let (tv, lass, makefu, first, current, one, two) = three(); + let (root, on) = (Id::of(&first.root()), first.hash()); + let x = Id::of(&tv.propose(&[root], &one.json())); + let backed = tv.vote(&[x], on, one.hash(), true); + let mut record = Record::before(root, "tv"); + record.cast(¤t, &backed, Vec::new()); + let mut votes: Vec<Vec<u8>> = (0..70) + .map(|n| { + let write = lass.write(&[root], "home/lass/a", harness::str(&n.to_string())); + lass.vote(&[x, Id::of(&write)], on, one.hash(), false) + }) + .collect(); + let lowest = votes + .iter() + .min_by_key(|vote| Id::of(vote)) + .unwrap() + .clone(); + let makefus = makefu.vote(&[x], on, one.hash(), false); + votes.push(makefus.clone()); + votes.push(backed); + let kept = record + .may_vote(¤t, two.hash(), &two.json(), true, &votes) + .unwrap(); + assert_eq!(kept.len(), 2); + assert!(kept.contains(&lowest) && kept.contains(&makefus)); + assert_eq!(building(x, false, &kept).unwrap().len(), 3); + } + /// Row 72 (`docs/federation.md`): a party admitted under the name of a place's segment /// moves who writes there, rules unchanged, and so does a change of the rules' order; /// the places it moves are named, the others left out. |
