diff options
| author | tv <tv@krebsco.de> | 2026-11-24 18:52:02 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-24 18:52:02 +0000 |
| commit | c105463a8f4d080c28f39fa07d170e47e8d1eb8e (patch) | |
| tree | b69ae1fc1ccfd83e05d0ca0727b8d158be3733b2 | |
| parent | c386d753054ed38bc4516c945ff8aa315f0e23b9 (diff) | |
store: what heads leave out is what a move to them refuses
left_out, the voters' rule's and a fork's check, took an event for above
the heads where it had them all in its history. A move asks more: each
of its dependencies among the heads or above them (above, beside). So an
event built on the heads and on something beside them passed the rule,
and the move refused it, with all built on it.
A followed key used that: it signs what will be its heads and a proposal
beside them, clients build on both as on every head they hold, and a
checkpoint proposed there later leaves out nothing by the rule, and
refuses every write, key set and node list since.
Now left_out asks what the move asks.
| -rw-r--r-- | CHANGELOG.md | 5 | ||||
| -rw-r--r-- | src/federation/store/memory.rs | 23 | ||||
| -rw-r--r-- | src/federation/vote.rs | 39 |
3 files changed, 57 insertions, 10 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 581217a..f8fc7d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ it from the release before ([`docs/operations.md`](docs/operations.md), ## Unreleased +* A node backs no checkpoint whose move refuses what it held for a while: an event + building on the heads and on something beside them was taken for above them, and a + followed key could so have every write since a point it prepared refused + ([`src/federation/store/memory.rs`](src/federation/store/memory.rs)). + * A checkpoint that passed is written even where a `true` on it was built beside its heads: the version event goes on votes above them alone; before, with such a vote among the first that pass it, no node wrote the version, and its backers stayed bound diff --git a/src/federation/store/memory.rs b/src/federation/store/memory.rs index b4be6f0..092a606 100644 --- a/src/federation/store/memory.rs +++ b/src/federation/store/memory.rs @@ -339,22 +339,20 @@ impl<F: Fold> Store<F> { } /// Of `ids`, events the store took, those not among `heads`, in their history, nor - /// above them (each with them all in its history): what a checkpoint at `heads` leaves - /// out, by the voters' rule (`docs/federation.md`, Checkpoints). + /// above them (`above`): what a checkpoint at `heads` leaves out, by the voters' rule + /// (`docs/federation.md`, Checkpoints), which is what a move there refuses (`beside`). + /// One with every head in its history that also builds on something beside them is + /// left out. pub(crate) fn left_out<'a>( &self, heads: &[Id], ids: impl IntoIterator<Item = &'a Id>, ) -> Vec<Id> { - let covered = self.history(heads); + let set: BTreeSet<Id> = heads.iter().copied().collect(); + let before = self.history(heads); + let above = self.above(&set, &before); ids.into_iter() - .filter(|id| { - !heads.contains(id) - && !covered.contains(id) - && !heads - .iter() - .all(|head| self.history(std::slice::from_ref(id)).contains(head)) - }) + .filter(|id| !before.contains(id) && !above.contains(id)) .copied() .collect() } @@ -1210,6 +1208,11 @@ mod tests { let both = taken(store.offer(testfold::put(&[above, beside], "d", "1"))); assert_eq!(store.beside(&[head]), vec![beside, both]); assert_eq!(store.beside(&[head, beside]), vec![above, both]); + // And so do those heads leave it out, though it has them all in its history. + assert_eq!( + store.left_out(&[head], &[first, head, beside, above, both]), + vec![beside, both] + ); } /// A store whose root holds puts and a lock, cut at the lock: the cut's ID, the lock's, diff --git a/src/federation/vote.rs b/src/federation/vote.rs index 7000b40..a633b0e 100644 --- a/src/federation/vote.rs +++ b/src/federation/vote.rs @@ -520,6 +520,45 @@ mod tests { } } + /// The voters' rule backs no checkpoint whose move refuses what the node held for a + /// while: a write built on the heads and on something beside them, a proposal say, as + /// clients build on every head they hold, has the heads in its history, and the move + /// refuses it all the same. + #[test] + fn a_node_backs_no_checkpoint_that_refuses_what_it_held() { + let (tv, lass, _, first, mut store) = three(); + let root = store.id(); + let head = taken( + &mut store, + tv.write(&[root], "home/tv/a", harness::str("1")), + ); + let mut junk = first.after(first.hash()); + junk.rules.push(("names/x".to_owned(), harness::str("tv"))); + let beside = taken(&mut store, tv.propose(&[root], &junk.json())); + let write = taken( + &mut store, + lass.write(&[head, beside], "home/lass/b", harness::str("2")), + ); + let mut checkpoint = first.after(first.hash()); + checkpoint.checkpoint = Some(vec![head]); + 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, ¤t, &version, Duration::ZERO) + .expect_err("its move refuses a write held for a while"); + assert!(why.contains(&write.to_string()), "{why}"); + assert_eq!(store.beside(&[head]), vec![beside, write]); + } + #[test] fn a_node_follows_a_party_on_checkpoints() { let (tv, lass, _, first, mut store) = three(); |
