From e9b1ea18694c88abe1e31f8236f8d8beb6362be9 Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 17 Nov 2026 16:11:50 +0000 Subject: 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`). --- docs/guides/federation/proposing-and-voting.md | 11 +++++ src/federation/client.rs | 67 ++++++++++++++++++++++++++ src/federation/party.rs | 58 ++++++++++++++++++++++ 3 files changed, 136 insertions(+) diff --git a/docs/guides/federation/proposing-and-voting.md b/docs/guides/federation/proposing-and-voting.md index 3f4aa0f..b25e9d9 100644 --- a/docs/guides/federation/proposing-and-voting.md +++ b/docs/guides/federation/proposing-and-voting.md @@ -123,6 +123,17 @@ curl -s -u tv:secret localhost:3000/events/counts | jq .proposals # "votes":["5a77…","e019…"],"yes":["tv"]}} ``` +The client shows the same, and what each proposal's version changes of the current one, +field by field and party by party: + +```sh +continuum-party --node http://tv:secret@localhost:3000 proposals +# 8d02…: dead; true: tv; false: lass +# changes: null -> "1f4c…" +# checkpoint: - -> ["4a1d…","9e30…"] +# number: 0 -> 1 +``` + `GET /events/{id}` shows a proposing event, the version it proposes in `proposal`, and a vote, signed by its party. A node lacking some votes reads a proposal as neither passed nor dead where another reads it dead; no vote takes either back. A dead proposal stays 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 { + 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::(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(¤t, &proposed), + [ + r#"changes: null -> "h""#, + r#"checkpoint: - -> ["x"]"#, + r#"keys.lass: - -> {"keys":["b"],"since":1}"#, + "number: 0 -> 1", + ] + ); + assert!(changes(¤t, ¤t).is_empty()); + } } diff --git a/src/federation/party.rs b/src/federation/party.rs index e3923a6..aaa983f 100644 --- a/src/federation/party.rs +++ b/src/federation/party.rs @@ -17,6 +17,8 @@ //! * `again`: signs again what a move refused; //! * `twice RECORD...`: names, from the records of parties' clients, a party that voted //! twice; +//! * `proposals`: the proposals on the current version at the node, each with whether it +//! passed or is dead, who voted what, and what its version changes (`client::changes`); //! * `root FILE`: the root of the federation whose first version `FILE` holds (JSON), //! the file its founders start its swarm from (`--store-root`), to standard output; //! * `fork FILE HEAD...`: the root of the fork at the heads named by the version `FILE` @@ -136,6 +138,10 @@ fn command() -> Command { .about("What the node finds of the fork whose root a file holds") .arg(id("file")), ) + .subcommand(Command::new("proposals").about( + "The proposals on the current version: whether each passed or is dead, who voted \ + what, and what it changes", + )) .subcommand( Command::new("twice") .about("Names, from records, a party that voted twice") @@ -179,6 +185,9 @@ pub(crate) async fn main() -> Result<()> { return out(&super::fork::root_file(&root, &[])); } let node = Node::new(&matches)?; + if name == "proposals" { + return proposals(&node).await; + } if name == "fork" { let version = version_in(sub.get_one::("file").expect("required"))?; let heads = strings(sub, "heads"); @@ -466,6 +475,55 @@ async fn again(node: &Node, signer: &Signer, record: &mut Record, path: &Path) - Ok(()) } +/// The proposals on the current version at `node`, each with whether it passed or is dead, +/// who voted what, and what its version changes, as one of the events proposing it holds +/// it. +async fn proposals(node: &Node) -> Result<()> { + let counts = node.counts().await?; + let current = current(&counts)?; + let parties = |names: &JsonValue| -> String { + let names: Vec<&str> = names + .as_array() + .into_iter() + .flatten() + .filter_map(JsonValue::as_str) + .collect(); + if names.is_empty() { + "nobody".to_owned() + } else { + names.join(", ") + } + }; + for (hash, proposal) in counts["proposals"].as_object().into_iter().flatten() { + let standing = match (proposal["passed"].as_bool(), proposal["dead"].as_bool()) { + (Some(true), _) => "passed", + (_, Some(true)) => "dead", + _ => "can still pass", + }; + println!( + "{hash}: {standing}; true: {}; false: {}", + parties(&proposal["yes"]), + parties(&proposal["no"]) + ); + let Some(id) = proposal["proposals"][0].as_str() else { + continue; + }; + let id = Id::from_hex(id).ok_or_else(|| anyhow!("the node names no event ID: {id}"))?; + match Event::read(&node.event(&id).await?) { + Some(Event::Signed(Signed { + does: Does::Proposal { hash: of, version }, + .. + })) if of.to_string() == *hash => { + for line in client::changes(¤t.json, &version) { + println!(" {line}"); + } + } + _ => println!(" the event {id} proposes no version of that hash"), + } + } + Ok(()) +} + /// The current version, as `counts` names it, checked: its hash its own. fn current(counts: &JsonValue) -> Result { let json = client::json(&counts["version"]["version"]).map_err(|why| anyhow!(why))?; -- cgit v1.3.1