aboutsummaryrefslogtreecommitdiffstats
path: root/src/federation/client.rs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-17 16:11:50 +0000
committertv <tv@krebsco.de>2026-11-17 17:14:42 +0100
commite9b1ea18694c88abe1e31f8236f8d8beb6362be9 (patch)
treefcf5e9f2c4f6c95e503a6a418234553780e8dfab /src/federation/client.rs
parent1ed4ccdb0cd3a9407b6101b1bc595df2a451a18d (diff)
continuum-party proposals: where each proposal stands, and what it changes
`continuum-party proposals` lists the proposals on the current version at the node, each with whether it passed or is dead and the parties voting `true` and `false`, as `GET /events/counts` names them, and what its version changes of the current one, read from an event proposing it, its signature checked: each field whose value differs, and of `keys` and `nodes` each party's (`client::changes`).
Diffstat (limited to 'src/federation/client.rs')
-rw-r--r--src/federation/client.rs67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/federation/client.rs b/src/federation/client.rs
index 9834771..0f06ca3 100644
--- a/src/federation/client.rs
+++ b/src/federation/client.rs
@@ -364,6 +364,46 @@ impl Record {
}
}
+/// What the version `proposed` changes of `current`, a line each: each field whose value
+/// differs, and of `keys` and `nodes` each party's, as `field: before -> after`, its JCS
+/// on either side, `-` where a version lacks it.
+pub(crate) fn changes(current: &Json, proposed: &Json) -> Vec<String> {
+ fn text(json: Option<&Json>) -> String {
+ json.map_or_else(
+ || "-".to_owned(),
+ |json| String::from_utf8_lossy(&json.bytes()).into_owned(),
+ )
+ }
+ fn names<'a>(a: Option<&'a Json>, b: Option<&'a Json>) -> BTreeSet<&'a str> {
+ a.into_iter().chain(b).flat_map(Json::names).collect()
+ }
+ let mut lines = Vec::new();
+ for name in names(Some(current), Some(proposed)) {
+ let (before, after) = (current.get(name), proposed.get(name));
+ if before == after {
+ continue;
+ }
+ let by_party = matches!(name, "keys" | "nodes")
+ && [before, after]
+ .iter()
+ .all(|json| matches!(json, Some(Json::Object(_))));
+ if !by_party {
+ lines.push(format!("{name}: {} -> {}", text(before), text(after)));
+ continue;
+ }
+ for party in names(before, after) {
+ let (was, is) = (
+ before.and_then(|json| json.get(party)),
+ after.and_then(|json| json.get(party)),
+ );
+ if was != is {
+ lines.push(format!("{name}.{party}: {} -> {}", text(was), text(is)));
+ }
+ }
+ }
+ 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
@@ -657,4 +697,31 @@ mod tests {
assert_eq!(again.len(), 2);
assert!(again.contains(&Id::of(&later)) && again.contains(&Id::of(&keys)));
}
+
+ /// What a proposed version changes: each field apart, each party's keys and nodes.
+ #[test]
+ fn changes_name_each_field_and_party_a_version_changes() {
+ let read = |text: &str| -> Json {
+ json(&serde_json::from_str::<serde_json::Value>(text).expect("JSON")).expect("JSON")
+ };
+ let current = read(
+ r#"{"number": 0, "changes": null, "keys": {"tv": {"since": 0, "keys": ["a"]}},
+ "rules": []}"#,
+ );
+ let proposed = read(
+ r#"{"number": 1, "changes": "h", "checkpoint": ["x"],
+ "keys": {"tv": {"since": 0, "keys": ["a"]}, "lass": {"since": 1, "keys": ["b"]}},
+ "rules": []}"#,
+ );
+ assert_eq!(
+ changes(&current, &proposed),
+ [
+ r#"changes: null -> "h""#,
+ r#"checkpoint: - -> ["x"]"#,
+ r#"keys.lass: - -> {"keys":["b"],"since":1}"#,
+ "number: 0 -> 1",
+ ]
+ );
+ assert!(changes(&current, &current).is_empty());
+ }
}