aboutsummaryrefslogtreecommitdiffstats
path: root/src/federation/vote.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/federation/vote.rs')
-rw-r--r--src/federation/vote.rs62
1 files changed, 60 insertions, 2 deletions
diff --git a/src/federation/vote.rs b/src/federation/vote.rs
index a633b0e..530b339 100644
--- a/src/federation/vote.rs
+++ b/src/federation/vote.rs
@@ -156,8 +156,9 @@ fn proposed(seen: &Seen<'_>, current: &Version) -> Vec<Proposed> {
/// Whether the node backs `version`, proposed `proposed_held` ago, by the voters' rule: one
/// naming a checkpoint only where it changes nothing of `current` but its number, what it
/// changes and its checkpoint, and its heads leave out nothing the node held for a while
-/// before it was proposed, proposals and votes aside, which lapse with the move; and only
-/// once its store held its checkpoint, or ran, for a while (`Rules::back_after`).
+/// before it was proposed, proposals and votes aside, which lapse with the move, and are
+/// heads a version may name (`State::may_name`); and only once its store held its
+/// checkpoint, or ran, for a while (`Rules::back_after`).
pub(crate) fn backs_checkpoint(
seen: &Seen<'_>,
rules: &Rules,
@@ -173,6 +174,13 @@ pub(crate) fn backs_checkpoint(
"a checkpoint that changes more than its number and what it changes".to_owned(),
);
}
+ // Heads no version may name: votes on it are taken, and no version event on them.
+ if let Err(why) = seen.store.state().may_name(heads) {
+ return Err(format!(
+ "no version event may name its heads ({}): a `true` on it is never written on",
+ why.0
+ ));
+ }
if seen.since_move < rules.back_after {
return Err(format!(
"its store held its checkpoint, or ran, {}s: it backs a later one after {}s",
@@ -559,6 +567,56 @@ mod tests {
assert_eq!(store.beside(&[head]), vec![beside, write]);
}
+ /// The voters' rule backs no checkpoint at heads no version may name, one in
+ /// another's history say: votes on it are taken, no version event on them is, and a
+ /// `true` there would bind the party to what is never written.
+ #[test]
+ fn a_node_backs_no_checkpoint_at_heads_no_version_may_name() {
+ let (tv, _, _, first, mut store) = three();
+ let root = store.id();
+ let under = taken(
+ &mut store,
+ tv.write(&[root], "home/tv/a", harness::str("1")),
+ );
+ let over = taken(
+ &mut store,
+ tv.write(&[under], "home/tv/a", harness::str("2")),
+ );
+ let mut checkpoint = first.after(first.hash());
+ checkpoint.checkpoint = Some(vec![under, over]);
+ let version = Version::read(&checkpoint.json()).unwrap();
+ let rules = Rules {
+ held_for: Duration::from_secs(60),
+ ..Rules::default()
+ };
+ let long = |_: &Id| Some(Duration::from_secs(3600));
+ let seen = Seen {
+ store: &store,
+ held: &long,
+ since_move: Duration::from_secs(86400),
+ };
+ let current = store.state().current().clone();
+ let why = backs_checkpoint(&seen, &rules, &current, &version, Duration::ZERO)
+ .expect_err("no version event names those heads");
+ assert!(why.contains("one in another's history"), "{why}");
+ // The votes are taken, and no version event on them is.
+ let proposal = taken(&mut store, tv.propose(&[over], &checkpoint.json()));
+ let (lass, makefu) = (Party::new("lass", 2), Party::new("makefu", 3));
+ let votes: Vec<Id> = [&tv, &lass, &makefu]
+ .iter()
+ .map(|party| {
+ taken(
+ &mut store,
+ party.vote(&[proposal], first.hash(), checkpoint.hash(), true),
+ )
+ })
+ .collect();
+ assert!(matches!(
+ store.offer(harness::version_event(&votes, checkpoint.hash())),
+ Offered::Refused(_)
+ ));
+ }
+
#[test]
fn a_node_follows_a_party_on_checkpoints() {
let (tv, lass, _, first, mut store) = three();