diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/federation/held.rs | 79 | ||||
| -rw-r--r-- | src/federation/party.rs | 8 |
2 files changed, 82 insertions, 5 deletions
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::<Vec<u8>>::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]; diff --git a/src/federation/party.rs b/src/federation/party.rs index d7880c2..ecd75a9 100644 --- a/src/federation/party.rs +++ b/src/federation/party.rs @@ -364,7 +364,8 @@ async fn vote( .filter_map(|id| id.as_str().and_then(Id::from_hex)) .collect() }; - let Some(proposing) = ids(&proposal, "proposals").first().copied() else { + let proposals = ids(&proposal, "proposals"); + let Some(proposing) = proposals.first().copied() else { bail!("no proposal of hash {proposal} on the current version, as the node reads it"); }; let proposed = match Event::read(&node.event(&proposing).await?) { @@ -400,8 +401,9 @@ async fn vote( let kept = record .may_vote(¤t, proposal, &proposed, yes, &nays) .map_err(|why| anyhow!(why))?; - let (_, heads) = node.summary().await?; - let cast = signer.sign(&heads, event::vote(current.hash, proposal, yes)); + // 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. + let cast = signer.sign(&proposals, event::vote(current.hash, proposal, yes)); record.cast(¤t, &cast, kept); record.save(path).map_err(|why| anyhow!(why))?; node.put(&cast).await |
