From e31d93577ccefdf540fd3df518a7d9837cb20cbb Mon Sep 17 00:00:00 2001 From: tv Date: Fri, 20 Nov 2026 00:55:34 +0000 Subject: continuum-party: nodes by their names wherever it shows them A node goes by the name it gave itself (`--alias`), as `names` in `GET /events/counts` shows it, in what a proposal does (`show`, `proposals`, `status`, before a vote), among the nodes not known to know a revision, and at the head of `status`'s section on the node it asks, which now names that node by its ID too. A node no party lists yet has no name there: only members' entries reach the node. --- CHANGELOG.md | 5 ++ docs/guides/federation/proposing-and-voting.md | 9 ++-- docs/guides/federation/upgrades.md | 2 +- docs/guides/federation/watching.md | 11 +++-- src/federation/client.rs | 68 +++++++++++++++++++------- src/federation/party.rs | 4 +- src/federation/party/status.rs | 37 ++++++++++---- 7 files changed, 98 insertions(+), 38 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e7dda5b..5fda415 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ it from the release before ([`docs/operations.md`](docs/operations.md), ## Unreleased +* `continuum-party` names a node by the name it gave itself wherever it shows one: in + what a proposal does, the nodes not known to know a revision, and the node `status` + asks ([`docs/guides/federation/watching.md`](docs/guides/federation/watching.md); + [`src/federation/client.rs`](src/federation/client.rs)). + * `continuum-party write -r` writes the value as a string, as it is, not JSON ([`docs/guides/federation/writing-and-reading.md`](docs/guides/federation/writing-and-reading.md), [Writing](docs/guides/federation/writing-and-reading.md#writing); diff --git a/docs/guides/federation/proposing-and-voting.md b/docs/guides/federation/proposing-and-voting.md index 48ec03c..1769a1f 100644 --- a/docs/guides/federation/proposing-and-voting.md +++ b/docs/guides/federation/proposing-and-voting.md @@ -246,10 +246,11 @@ it lets in or takes out, with their keys by fingerprint (as `ssh-keygen -l` give and their nodes; the keys and node lists it names anew; the rules it adds or drops, where they are among the rules; the checkpoint it moves the store to, and what moving there refuses of what the node took; the revision it moves to, and the nodes not known to know -it. And the places holding a value whose writer it changes (`who writes`): admitting a -party named as a segment of a place is, or changing the rules or their order, moves who -writes there, rules unchanged in the first case, and what was written there counts no -more once it passes. Where no client backs it, it says why, by the federation it knows: +it, each node by the name it gave itself (`--alias`) where the node knows it. And the +places holding a value whose writer it changes (`who writes`): admitting a party named as +a segment of a place is, or changing the rules or their order, moves who writes there, +rules unchanged in the first case, and what was written there counts no more once it +passes. Where no client backs it, it says why, by the federation it knows: ```sh continuum-party --node http://tv:secret@localhost:3000 show 8d02 diff --git a/docs/guides/federation/upgrades.md b/docs/guides/federation/upgrades.md index cb82382..778f8c5 100644 --- a/docs/guides/federation/upgrades.md +++ b/docs/guides/federation/upgrades.md @@ -108,7 +108,7 @@ adds is refused everywhere until a version names it. # 5e81…: can still pass, 2 more `true` passing it (3 of 4); true: tv; false: nobody # proposed by tv: version 5 on 4 # moves to revision 1 (merge-events) - # not known to know revision 1 (merge-events): lass: continuum:9c07… said nothing: … + # not known to know revision 1 (merge-events): lass: continuum:9c07… (beta) said nothing: … continuum-party --node http://tv:secret@localhost:3000 --key tv.key \ --record tv.record vote 5e81 yes ``` diff --git a/docs/guides/federation/watching.md b/docs/guides/federation/watching.md index 537e42b..056f77c 100644 --- a/docs/guides/federation/watching.md +++ b/docs/guides/federation/watching.md @@ -14,7 +14,7 @@ store, through its API and its log. store 6d1e8a0c4f2b9d77… checkpoint 6d1e8a0c4f2b9d77… 3 heads, 120 events taken after the checkpoint -the node +the node continuum:9c07e2a4b6d8f0a1… (beta) lass's, voting for it by itself knows the base revision, revision 1 (merge-events) version 3 (a7c2e81b9d0453f6…) @@ -49,10 +49,11 @@ you: tv ``` IDs and hashes are cut short here; the client writes them whole, the shortest prefix -naming a proposal in bold, and keys by their fingerprints. It says of every party's nodes -the names they gave themselves (`--alias`), how long ago the node heard from each, and -what each runs (its wire versions and the newest revision it knows: the nodes to upgrade -before a revision passes); of every proposal how it stands, who voted what and who not +naming a proposal in bold, and keys by their fingerprints. Every node goes by the name it +gave itself (`--alias`) where the node knows it, a node no party lists yet by its ID +alone. It says of every party's nodes how long ago the node heard from each, and what each +runs (its wire versions and the newest revision it knows: the nodes to upgrade before a +revision passes); of every proposal how it stands, who voted what and who not yet, and what it does, as `show` says it; and of the party it works as (its record's, `--party`'s, or else the node's), its `--key`, its record held against the votes the node shows, what `again` signs again, and what may keep votes away. What people read may change diff --git a/src/federation/client.rs b/src/federation/client.rs index b95cb3c..ca2db86 100644 --- a/src/federation/client.rs +++ b/src/federation/client.rs @@ -434,15 +434,21 @@ pub(crate) fn backable(current: &Version, proposed: &Json) -> Result Vec { +/// on, without its JSON. Its number and the hash it changes go without saying. A node goes +/// by its name where `names` has one (`node_names`). +pub(crate) fn described( + current: &Version, + proposed: &Version, + names: &BTreeMap, +) -> Vec { + let node_spelled = |node: &String| node_spelled(node, names); let mut lines = Vec::new(); for (party, given) in &proposed.parties { if !current.parties.contains_key(party) { lines.push(format!( "lets {party} in: {}; {}", counted(&given.keys, "key", |key| fingerprint(key)), - counted(&given.nodes, "node", |node| node_spelled(node)), + counted(&given.nodes, "node", node_spelled), )); } } @@ -464,9 +470,7 @@ pub(crate) fn described(current: &Version, proposed: &Version) -> Vec { if is.nodes_since != was.nodes_since || is.nodes != was.nodes { lines.push(format!( "names {party}'s node list anew{}", - differing(&was.nodes, &is.nodes, "as it was", |node| node_spelled( - node - )) + differing(&was.nodes, &is.nodes, "as it was", node_spelled) )); } } @@ -548,15 +552,33 @@ pub(crate) fn fingerprint(line: &str) -> String { } } -/// A node's ID, its first twelve hex digits enough to tell it. -fn node_spelled(node: &str) -> String { +/// A node's ID, its first twelve hex digits enough to tell it, and its name after it +/// where `names` has one. +fn node_spelled(node: &str, names: &BTreeMap) -> String { let at = node.find(':').map_or(0, |colon| colon + 1); - match node.get(..at + 12) { + let id = match node.get(..at + 12) { Some(start) if node.len() > at + 12 => format!("{start}…"), _ => node.to_owned(), + }; + match names.get(node) { + Some(name) => format!("{id} ({name})"), + None => id, } } +/// The names the nodes of every party gave themselves, as `counts` (`GET /events/counts`) +/// shows them (`names`), by node ID. +pub(crate) fn node_names(counts: &serde_json::Value) -> BTreeMap { + counts["parties"] + .as_object() + .into_iter() + .flatten() + .filter_map(|(_, of)| of["names"].as_object()) + .flatten() + .filter_map(|(node, name)| Some((node.clone(), name.as_str()?.to_owned()))) + .collect() +} + /// A rule's path as a version spells it. fn rule_path(path: &[super::version::Segment]) -> String { use super::version::Segment; @@ -849,6 +871,10 @@ pub(crate) fn unready(counts: &serde_json::Value, revision: Revision) -> Vec format!("{node} ({name})"), + None => node.clone(), + }; let newest = &knows["revision"]; let named = newest["named"].as_str().unwrap_or("?"); match newest["number"].as_u64() { @@ -1350,6 +1376,9 @@ mod tests { let read = |spec: &Spec| Version::read(&spec.json()).unwrap(); let first = Spec::first(&[&tv, &lass], &rules); let current = read(&first); + let names = BTreeMap::from([(harness::node_id(1), "alpha".to_owned())]); + let described = + |current: &Version, proposed: &Version| described(current, proposed, &names); assert!(described(¤t, ¤t).is_empty()); let admitted = Spec::first(&[&tv, &lass, &makefu], &rules); assert_eq!( @@ -1361,6 +1390,7 @@ mod tests { ); let mut changed = Spec::first(&[&tv], &[]); changed.parties[0].keys_since = 1; + changed.parties[0].nodes.push(harness::node_id(1)); changed .rules .insert(0, ("names/r/wiki".to_owned(), harness::str("tv"))); @@ -1369,12 +1399,16 @@ mod tests { assert_eq!( described(¤t, &read(&changed)), [ - "takes lass out", - "names tv's keys anew, as they were", - "adds rule 1: names/r/wiki -> tv", - "drops rule 2: names/** -> tv", - "moves the store to a checkpoint at 2 heads", - "moves to revision 1 (merge-events)", + "takes lass out".to_owned(), + "names tv's keys anew, as they were".to_owned(), + format!( + "names tv's node list anew: + {}… (alpha)", + &harness::node_id(1)[..22] + ), + "adds rule 1: names/r/wiki -> tv".to_owned(), + "drops rule 2: names/** -> tv".to_owned(), + "moves the store to a checkpoint at 2 heads".to_owned(), + "moves to revision 1 (merge-events)".to_owned(), ] ); } @@ -1489,7 +1523,7 @@ mod tests { "lass": {"knows": { "a": {"wire": [52, 52], "revision": {"number": 1, "id": id, "named": "one"}}, }}, - "tv": {"knows": { + "tv": {"names": {"b": "beta"}, "knows": { "b": {"wire": [52, 52], "revision": {"number": 0, "named": "the base"}}, "c": null, "d": {"wire": [52, 52], "revision": {"number": null, "named": "x, unknown"}}, @@ -1500,7 +1534,7 @@ mod tests { assert_eq!( unready(&counts, one), [ - "tv: b knows the base at newest; c said nothing: a build from before SPEAKS, \ + "tv: b (beta) 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" ] diff --git a/src/federation/party.rs b/src/federation/party.rs index 8f5143b..8357d22 100644 --- a/src/federation/party.rs +++ b/src/federation/party.rs @@ -973,7 +973,7 @@ pub(crate) async fn main() -> Result<()> { let version = to_propose(&node, ¤t, sub).await?; let proposed = client::backable(¤t, &version) .map_err(|why| anyhow!("not a version a party may back: {why}"))?; - if client::described(¤t, &proposed).is_empty() { + if client::described(¤t, &proposed, &Default::default()).is_empty() { bail!( "it changes nothing of version {} but its number", current.number @@ -2055,7 +2055,7 @@ fn ballot_line(counts: &JsonValue, current: &Version, hash: &str, hashes: &[Stri /// (`client::described`), the places holding a value in `counts` whose writer it moves, /// and the nodes not known to know its revision. fn version_lines(counts: &JsonValue, current: &Version, proposed: &Version) -> Vec { - let mut lines = client::described(current, proposed); + let mut lines = client::described(current, proposed, &client::node_names(counts)); let places: Vec<&str> = counts["values"] .as_object() .into_iter() diff --git a/src/federation/party/status.rs b/src/federation/party/status.rs index 4c637fa..47c32e5 100644 --- a/src/federation/party/status.rs +++ b/src/federation/party/status.rs @@ -114,6 +114,9 @@ async fn model(node: &Node, options: &Options, party: Option<&str>) -> Result Vec { } let node = &model["node"]; - out.push(heading("the node")); + // A node's name after its ID, where it gave itself one. + let named = |node: &JsonValue| match node["name"].as_str() { + Some(name) => format!(" ({})", paint.paint(Style::Name, name)), + None => String::new(), + }; + out.push(match node["id"].as_str() { + Some(id) => format!( + "{} {}{}", + heading("the node"), + paint.paint(Style::Id, id), + named(node) + ), + None => heading("the node"), + }); out.push(match node["party"].as_str() { Some(party) => format!( " {}'s{}", @@ -521,13 +537,10 @@ fn render(model: &JsonValue, paint: &Paint) -> Vec { out.push(" nodes:".to_owned()); } for node in &nodes { - let name = match node["name"].as_str() { - Some(name) => format!(" ({})", paint.paint(Style::Name, name)), - None => String::new(), - }; out.push(format!( - " {}{name}", - paint.paint(Style::Id, &text(&node["id"])) + " {}{}", + paint.paint(Style::Id, &text(&node["id"])), + named(node) )); let heard = match node["heard"].as_u64() { _ if node["here"].as_bool() == Some(true) => paint.paint(Style::Good, "this node"), @@ -759,7 +772,13 @@ mod tests { json!({ "format": FORMAT, "store": {"id": "6d1e", "checkpoint": "6d1e", "heads": 3, "taken": 1, "stopped": null}, - "node": {"party": "lass", "votesByItself": true, "revisions": ["the base revision"]}, + "node": { + "id": "continuum:9c07", + "name": "beta", + "party": "lass", + "votesByItself": true, + "revisions": ["the base revision"], + }, "version": { "number": 3, "hash": "a7c2", @@ -844,7 +863,7 @@ mod tests { ); }; has("store 6d1e"); - has("the node"); + has("the node continuum:9c07 (beta)"); has(" lass's, voting for it by itself"); has("version 3 (a7c2)"); has(" 2 parties, 2 passing a change"); -- cgit v1.3.1