From 55a62cbeb66a640c8d9eff07b0ac441ef2d9859c Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 17 Nov 2026 02:49:55 +0000 Subject: federation: votes build on the events proposing what they vote on A node voting by itself, and a party's client, signed a vote on the heads the node held: where those held what is beside a checkpoint's heads (a party's writes made while the swarm was parted, say), the vote wasn't above them, and a version event written on it was refused, so the checkpoint never moved, though it passed. Both now vote on the events proposing what they vote on, and a node proposes a checkpoint on the heads it names: so their votes are above those heads wherever the proposal is. --- src/federation/held.rs | 79 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 77 insertions(+), 2 deletions(-) (limited to 'src/federation/held.rs') diff --git a/src/federation/held.rs b/src/federation/held.rs index e1c930d..2121184 100644 --- a/src/federation/held.rs +++ b/src/federation/held.rs @@ -515,6 +515,7 @@ impl Holding { return Ok(Vec::new()); } let current = store.state().current().clone(); + let ballots = store.state().ballots(¤t.hash); let heads = store.heads(); let line = crate::access::sshsig::PublicKey(voter.key.verifying_key().to_bytes()).line(); let mut record = record.clone(); @@ -526,11 +527,21 @@ impl Holding { yes, nays, } => { + // On the events proposing it: above the heads it names for a + // checkpoint wherever they are, so a version event may be written on + // it, which the node's heads, holding what is beside them, may not be. + let proposing = ballots + .get(&proposal) + .map_or_else(Vec::new, |ballot| ballot.proposals.clone()); let cast = event::signed( &voter.key, party, &line, - &heads, + if proposing.is_empty() { + &heads + } else { + &proposing + }, event::vote(current.hash, proposal, yes), ); record.cast(¤t, &cast, nays); @@ -538,8 +549,13 @@ impl Holding { signed.push(cast); } Act::Propose(version) => { + // On the heads it names for a checkpoint: above them. + let at = Version::read(&version) + .ok() + .and_then(|version| version.checkpoint) + .unwrap_or_else(|| heads.clone()); let proposing = - event::signed(&voter.key, party, &line, &heads, event::proposal(&version)); + event::signed(&voter.key, party, &line, &at, event::proposal(&version)); record.signed(&proposing); info!(proposal = %Id::of(&version.bytes()), "Proposing a checkpoint for its party"); signed.push(proposing); @@ -1294,6 +1310,65 @@ mod tests { assert_eq!(holding.passed(), Vec::>::new()); } + /// tv's checkpoint at its write, and a write of lass's beside it: makefu's node, + /// following tv, votes on the event proposing it, not on its heads, which hold lass's + /// write too; so its vote is above the checkpoint's heads, the version event written + /// on it is taken, and the node moves there. + #[test] + fn a_node_votes_above_the_heads_of_the_checkpoint_it_votes_on() { + let (tv, lass, makefu) = ( + Party::new("tv", 1), + Party::new("lass", 2), + Party::new("makefu", 3), + ); + let first = Spec::first(&[&tv, &lass, &makefu], &[]); + let root = first.root(); + let on = first.hash(); + let write = tv.write(&[Id::of(&root)], "home/tv/x", harness::str("1")); + let beside = lass.write(&[Id::of(&root)], "home/lass/x", harness::str("1")); + let mut next = first.after(on); + next.checkpoint = Some(vec![Id::of(&write)]); + let proposal = tv.propose(&[Id::of(&write)], &next.json()); + let yes = tv.vote(&[Id::of(&proposal)], on, next.hash(), true); + let mut doc = events::started(Federation::NAME, &root, &[]).unwrap(); + for event in [&write, &beside, &proposal, &yes] { + put(&mut doc, event); + } + let record = crate::files::scratch_dir("held-votes-above").join("makefu.json"); + let version = Version::read(&first.json()).unwrap(); + let mut begun = Record::begin(Id::of(&root), "makefu", &version); + begun.began = Id::of(b"before the federation").to_string(); + begun.save(&record).unwrap(); + let holding = Holding::open( + None, + Arc::new(Files::default()), + None, + Some("makefu".into()), + ) + .unwrap() + .voting(Some(Voter { + key: makefu.key.clone(), + record, + rules: Rules { + follow: vec!["tv".to_owned()], + ..Rules::default() + }, + })); + read(&holding, &doc, 0); + let cast = holding.act(); + assert_eq!(cast.len(), 1); + assert!(matches!( + Event::read_taken(&cast[0]), + Some(Event::Signed(Signed { deps, does: Does::Vote { yes: true, .. }, .. })) + if deps == vec![Id::of(&proposal)] + )); + assert_eq!(holding.passed().len(), 1); + assert_eq!( + holding.with(|store| store.state().current().hash), + Some(next.hash()) + ); + } + /// Rows whose tests wait: remakes (stage 5), and flooding. const LATER: &[u32] = &[11, 12, 13, 15, 16, 21, 22, 28, 29, 30, 31]; -- cgit v1.3.1