diff options
| author | tv <tv@krebsco.de> | 2026-11-24 18:42:34 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-24 18:42:34 +0000 |
| commit | c386d753054ed38bc4516c945ff8aa315f0e23b9 (patch) | |
| tree | 26cb176784b6b2ee155b55b5989aa34fc1b80d64 /src | |
| parent | 8ece1c99736209c693adf7886024e7d166d55ac0 (diff) | |
federation: a checkpoint's version event on the votes above its heads
version_event took each party's true of the lowest ID, of the first
parties by name that pass a proposal. Of a version naming a checkpoint,
a true built beside its heads counts, but a version event built on it is
refused (may_move): with such a vote among those taken, every node wrote
the same event, every node refused it, and the version was never
written; its backers stayed bound. One party did that by casting its
true on an event beside the heads, where its name came early enough.
Now it takes only votes above the heads, so the event it names is one a
store takes wherever two thirds voted above them.
Diffstat (limited to 'src')
| -rw-r--r-- | src/federation/fold.rs | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/src/federation/fold.rs b/src/federation/fold.rs index dbe8d4f..c636a13 100644 --- a/src/federation/fold.rs +++ b/src/federation/fold.rs @@ -418,9 +418,18 @@ impl State { /// The version event writing the proposal of hash `proposal` on the current version, /// where it passed here: on the `true` votes of the first parties by name that pass it, - /// each party's of the lowest ID, so that nodes holding those votes write the same. + /// each party's of the lowest ID, so that nodes holding those votes write the same. Of + /// a version naming a checkpoint, only votes above its heads: a version event built on + /// one beside them is refused (`may_move`), so with such a vote among them the version + /// would never be written. pub(crate) fn version_event(&self, proposal: &Id) -> Option<Vec<u8>> { let current = self.current(); + let above = self + .proposed + .get(proposal) + .and_then(|json| Version::read(json).ok()) + .and_then(|version| version.checkpoint) + .map(|heads| self.above(&heads.into_iter().collect())); let mut yes: BTreeMap<&str, Id> = BTreeMap::new(); for (id, signed, _) in self.signed() { if let Does::Vote { @@ -430,6 +439,7 @@ impl State { } = &signed.does && *on == current.hash && voted == proposal + && above.as_ref().is_none_or(|above| above.contains(id)) { let lowest = yes.entry(signed.party.as_str()).or_insert(*id); *lowest = (*lowest).min(*id); @@ -1051,6 +1061,32 @@ mod tests { (store, first, next, proposal) } + /// A checkpoint that passed is written on votes above its heads: a `true` built beside + /// them counts, and no version event built on it is taken, so it isn't among those + /// `version_event` names, though its party is among the first that pass it. + #[test] + fn a_checkpoint_is_written_on_the_votes_above_its_heads() { + let (tv, lass, makefu) = (tv(), lass(), makefu()); + let first = Spec::first(&[&tv, &lass, &makefu], &[]); + let on = first.hash(); + let mut store = federation(&first); + let root = store.id(); + let head = taken(store.offer(tv.write(&[root], "home/tv/a", harness::str("1")))); + let stray = taken(store.offer(lass.write(&[root], "home/lass/b", harness::str("2")))); + let mut next = first.after(on); + next.checkpoint = Some(vec![head]); + let proposal = taken(store.offer(tv.propose(&[head], &next.json()))); + taken(store.offer(lass.vote(&[proposal, stray], on, next.hash(), true))); + let makefus = taken(store.offer(makefu.vote(&[proposal], on, next.hash(), true))); + let tvs = taken(store.offer(tv.vote(&[proposal], on, next.hash(), true))); + let written = store.state().version_event(&next.hash()).expect("passed"); + let mut deps = [makefus, tvs]; + deps.sort_unstable(); + assert_eq!(written, harness::version_event(&deps, next.hash())); + taken(store.offer(written)); + assert_eq!(store.state().current().number, 1); + } + #[test] fn a_proposal_passes_by_two_thirds_and_its_version_changes_the_policy() { let (tv, lass, makefu) = (tv(), lass(), makefu()); |
