aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-24 18:58:32 +0000
committertv <tv@krebsco.de>2026-11-24 18:58:32 +0000
commitfb54044c688e0252b4af54a057151b9c4d4ccf98 (patch)
tree10e2566a2302ed11e4ec6d96a52e0afde7ad4582
parentc105463a8f4d080c28f39fa07d170e47e8d1eb8e (diff)
federation: no true on a checkpoint at heads no version may name
A version event is refused where the heads its version names for a checkpoint have one in another's history, or aren't after the current checkpoint (may_move). Neither the voters' rule nor what a node tells clients asked that: votes on such a proposal are taken, no version event on them ever is, so nothing lapses, and every party that voted true stays bound until others' nays end it. A followed key proposing one bound all its followers; with two thirds of the parties so, nothing passed on that version again. may_move's part about the heads is may_name now, which backs_checkpoint asks before a true, and GET /events/counts says as none, so that a party's client backs no such proposal either.
-rw-r--r--CHANGELOG.md6
-rw-r--r--src/api/events.rs14
-rw-r--r--src/federation/fold.rs36
-rw-r--r--src/federation/vote.rs62
4 files changed, 102 insertions, 16 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f8fc7d6..83eb3fa 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,12 @@ it from the release before ([`docs/operations.md`](docs/operations.md),
## Unreleased
+* A node backs no checkpoint at heads no version may name (one in another's history,
+ say), and tells clients so (`none` in `GET /events/counts`): votes on such a proposal
+ are taken, no version event on them is, and its backers stayed bound for good
+ ([`src/federation/vote.rs`](src/federation/vote.rs),
+ [`src/federation/fold.rs`](src/federation/fold.rs)).
+
* 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
diff --git a/src/api/events.rs b/src/api/events.rs
index 5a69769..1d275f9 100644
--- a/src/api/events.rs
+++ b/src/api/events.rs
@@ -199,7 +199,8 @@ async fn heard(state: &AppState) -> std::collections::HashMap<String, u64> {
/// for a checkpoint, those above its heads), the votes on it, the parties
/// voting `true` and `false`, whether it passed and whether it is dead, why a party's
/// client backs it not, where it is no version that can be written on the current one
-/// (`client::backable`), and, for a checkpoint, what its parties signed that moving there
+/// (`client::backable`) or names heads no version may (`State::may_name`), and, for a
+/// checkpoint, what its parties signed that moving there
/// refuses (`beside`, `signed_beside`).
async fn counts(State(state): State<AppState>) -> Response {
let aliases = crate::swarm::members::aliases(&state.doc.read().await.doc);
@@ -256,6 +257,17 @@ async fn counts(State(state): State<AppState>) -> Response {
.proposal(&hash)
.and_then(|proposed| client::backable(current, proposed).err())
.or_else(|| {
+ let heads = read
+ .proposal(&hash)
+ .and_then(|json| crate::federation::version::Version::read(json).ok())
+ .and_then(|version| version.checkpoint)?;
+ let why = read.may_name(&heads).err()?;
+ Some(format!(
+ "no version event may name its heads ({}): it is never written",
+ why.0
+ ))
+ })
+ .or_else(|| {
(proposing.is_empty() && !ballot.proposals.is_empty()).then(|| {
"no event proposing it is above the heads it names: no version \
event is written on a vote on it"
diff --git a/src/federation/fold.rs b/src/federation/fold.rs
index c636a13..b96cf1f 100644
--- a/src/federation/fold.rs
+++ b/src/federation/fold.rs
@@ -610,9 +610,30 @@ impl State {
}
/// Whether a version event on `deps` may write a version naming `heads` for a
- /// checkpoint: after the checkpoint current at its history, at which that one is
- /// current too, none in another's history; and the version event above them.
+ /// checkpoint: heads a version may name (`may_name`), and the version event above
+ /// them.
fn may_move(&self, heads: &[Id], deps: &[Id]) -> Result<(), Refused> {
+ self.may_name(heads)?;
+ let named: BTreeSet<Id> = heads.iter().copied().collect();
+ let above = self.above(&named);
+ let is_above = deps
+ .iter()
+ .all(|dep| named.contains(dep) || above.contains(dep))
+ && (deps.iter().any(|dep| above.contains(dep))
+ || named.iter().all(|head| deps.contains(head)));
+ if !is_above {
+ return Err(Refused::new(
+ "not above the heads of the checkpoint it names",
+ ));
+ }
+ Ok(())
+ }
+
+ /// Whether a version written here may name `heads` for a checkpoint: after the
+ /// checkpoint current at its history, at which that one is current too, none in
+ /// another's history. Where not, no version event naming them is taken, whatever it
+ /// builds on: a `true` on such a version binds its party to what is never written.
+ pub(crate) fn may_name(&self, heads: &[Id]) -> Result<(), Refused> {
if heads
.iter()
.any(|a| heads.iter().any(|b| a != b && self.built_on(a, b)))
@@ -655,17 +676,6 @@ impl State {
"checkpoint heads not after the current checkpoint, or at which it isn't current",
));
}
- let above = self.above(&named);
- let is_above = deps
- .iter()
- .all(|dep| named.contains(dep) || above.contains(dep))
- && (deps.iter().any(|dep| above.contains(dep))
- || named.iter().all(|head| deps.contains(head)));
- if !is_above {
- return Err(Refused::new(
- "not above the heads of the checkpoint it names",
- ));
- }
Ok(())
}
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();