diff options
| -rw-r--r-- | docs/federation.md | 30 | ||||
| -rw-r--r-- | src/federation/held.rs | 79 | ||||
| -rw-r--r-- | src/federation/party.rs | 8 |
3 files changed, 98 insertions, 19 deletions
diff --git a/docs/federation.md b/docs/federation.md index 0ddb4bd..72bcca1 100644 --- a/docs/federation.md +++ b/docs/federation.md @@ -431,20 +431,22 @@ for a fork (Forks). This is the voter's rule, by its own clock: nothing more is It is a version only where its proposal is above those heads, and a version event writing it is taken only where it is above them too, and so is every vote it is written on ([`store.md`](store.md), Events): so moving to the checkpoint refuses nothing that -decided it. A vote beside them binds its party as any yes does, until the move refuses -it. A node that takes the version moves to the checkpoint: it builds it, forgets -everything before those heads that it doesn't keep, and every event not above them, and -refuses such events from then on. Judging an event after them needs nothing it forgot: -the version, every party's keys and node list, and the proposals on the current version -with their votes all count, and are kept. A node starting from a checkpoint reads what -it keeps as written under its version, as it holds none of their histories: each was -written under that one or an earlier, counting there, a kept proposal is on it, and a -later `since` that leaves one out is past it. A node that can't build a checkpoint, as -it was away across a move and a remake after it, or as it joins, takes it only where its -operator pins it ([`store.md`](store.md), Pinned checkpoints). What it can't check of -its heads it takes on its operator's word: that they are after the checkpoint current at -the version naming them, at which that one is current too; so it judges that version as -every node does. +decided it. A party's client, and a node voting by itself, vote on the events proposing +what they vote on, and a node proposes a checkpoint on its heads: so their votes are +above those heads wherever the proposal is. A vote beside them binds its party as any +yes does, until the move refuses it. A node that takes the version moves to the +checkpoint: it builds it, forgets everything before those heads that it doesn't keep, +and every event not above them, and refuses such events from then on. Judging an event +after them needs nothing it forgot: the version, every party's keys and node list, and +the proposals on the current version with their votes all count, and are kept. A node +starting from a checkpoint reads what it keeps as written under its version, as it holds +none of their histories: each was written under that one or an earlier, counting there, +a kept proposal is on it, and a later `since` that leaves one out is past it. A node +that can't build a checkpoint, as it was away across a move and a remake after it, or as +it joins, takes it only where its operator pins it ([`store.md`](store.md), Pinned +checkpoints). What it can't check of its heads it takes on its operator's word: that +they are after the checkpoint current at the version naming them, at which that one is +current too; so it judges that version as every node does. What a checkpoint loses: what counted no more before it, so that a key added back, or a place given back, brings back nothing signed before it, and a party that voted twice on 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 |
