aboutsummaryrefslogtreecommitdiffstats
path: root/src/federation/client.rs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-19 13:34:24 +0000
committertv <tv@krebsco.de>2026-11-19 14:39:54 +0100
commit9164ebfe9a4014cbbaaaff90c5a1d722e39457fd (patch)
tree9a45156bd4919054939d12c97a19672e92e07b98 /src/federation/client.rs
parent7a5aeb02024ddff71ba60f40913555cd21a633ad (diff)
federation: which nodes know a revision, in counts and before a `true`
`GET /events/counts` says, of each node a party lists, what it said it speaks and knows (`knows`, by node ID): the wire versions, the oldest and the newest, and the newest revision of the federation it knows, by number and ID and as people read it, its number null where this continuum doesn't know it; null where it said nothing, a build from before SPEAKS or one the node didn't hear from; the node's own as it is. So the nodes still to upgrade before a revision passes show, every party's, where before a party's operators could check only their own. A party's client, backing a proposal that moves to another revision, warns of every node of any party not known to know it, a line a party naming each and what it said: once it passes, those stop at it till upgraded. `next` warns alike, of the revision it moves to, or of the later one it suggests. A warning, not a refusal: what a node heard is no proof, and a node not heard from may well be upgraded.
Diffstat (limited to 'src/federation/client.rs')
-rw-r--r--src/federation/client.rs66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/federation/client.rs b/src/federation/client.rs
index 7b9d3d7..45f5019 100644
--- a/src/federation/client.rs
+++ b/src/federation/client.rs
@@ -22,6 +22,7 @@ use serde::{Deserialize, Serialize};
use super::event::{Does, Event, Signed};
use super::jcs::{self, Json};
+use super::revision::Revision;
use super::store::Id;
use super::version::Version;
@@ -480,6 +481,41 @@ pub(crate) fn changes(current: &Json, proposed: &Json) -> Vec<String> {
lines
}
+/// Of the parties' nodes, those not known to know `revision`, by what the node a client
+/// talks to heard each say it knows (`knows` in `counts`, from `GET /events/counts`): a
+/// line for each party with any, naming them and what each said. Once a version of
+/// `revision` passes, such a node stops at it till upgraded. None where every node said
+/// it knows it.
+pub(crate) fn unready(counts: &serde_json::Value, revision: Revision) -> Vec<String> {
+ let mut lines = Vec::new();
+ for (party, of) in counts["parties"].as_object().into_iter().flatten() {
+ let behind: Vec<String> = of["knows"]
+ .as_object()
+ .into_iter()
+ .flatten()
+ .filter_map(|(node, knows)| {
+ let newest = &knows["revision"];
+ let named = newest["named"].as_str().unwrap_or("?");
+ match newest["number"].as_u64() {
+ Some(number) if usize::try_from(number).is_ok_and(|n| n >= revision.0) => None,
+ Some(_) => Some(format!("{node} knows {named} at newest")),
+ None if newest.is_object() => Some(format!("{node} knows {named}")),
+ None if knows.is_object() => Some(format!(
+ "{node} knows no revision: built without the federation"
+ )),
+ None => Some(format!(
+ "{node} said nothing: a build from before SPEAKS, or not heard from"
+ )),
+ }
+ })
+ .collect();
+ if !behind.is_empty() {
+ lines.push(format!("{party}: {}", behind.join("; ")));
+ }
+ }
+ lines
+}
+
/// The parties that voted twice, by the votes `records` keep: of each version they name,
/// a party whose `true` and `false` are on one proposal, or whose `true` is on two
/// proposals of which neither is dead by all the votes. Each vote counts as checked from
@@ -908,4 +944,34 @@ mod tests {
)]
);
}
+
+ /// Of the nodes `knows` names, those that didn't say they know a revision are named,
+ /// with what each said; a party whose nodes all did, not.
+ #[test]
+ fn nodes_not_known_to_know_a_revision_are_named() {
+ let one = Revision(1);
+ let id = one.id().to_string();
+ let counts = serde_json::json!({"parties": {
+ "lass": {"knows": {
+ "a": {"wire": [52, 52], "revision": {"number": 1, "id": id, "named": "one"}},
+ }},
+ "tv": {"knows": {
+ "b": {"wire": [52, 52], "revision": {"number": 0, "named": "the base"}},
+ "c": null,
+ "d": {"wire": [52, 52], "revision": {"number": null, "named": "x, unknown"}},
+ "e": {"wire": [52, 52], "revision": null},
+ "f": {"wire": [52, 53], "revision": {"number": 2, "named": "two"}},
+ }},
+ }});
+ assert_eq!(
+ unready(&counts, one),
+ [
+ "tv: b knows the base at newest; c said nothing: a build from before SPEAKS, \
+ or not heard from; d knows x, unknown; e knows no revision: built without \
+ the federation"
+ ]
+ );
+ assert!(unready(&counts, Revision(0)).len() == 1);
+ assert!(unready(&serde_json::json!({}), one).is_empty());
+ }
}