diff options
| -rw-r--r-- | CHANGELOG.md | 5 | ||||
| -rw-r--r-- | docs/guides/federation/watching.md | 29 | ||||
| -rw-r--r-- | docs/openapi.yaml | 9 | ||||
| -rw-r--r-- | share/bash-completion/completions/continuum-party | 2 | ||||
| -rw-r--r-- | src/api/events.rs | 9 | ||||
| -rw-r--r-- | src/federation/party.rs | 176 |
6 files changed, 169 insertions, 61 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index ae116bc..d52027a 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 status` says the party's keys and nodes a line each, its nodes by the + names they gave themselves, which `GET /events/counts` shows (`names`) + ([`docs/guides/federation/watching.md`](docs/guides/federation/watching.md); + [`src/federation/party.rs`](src/federation/party.rs), [`src/api/events.rs`](src/api/events.rs)). + * `continuum-party --party NAME` names the party it reads as where no record does: one who only reads needs no record ([`docs/configuration.md`](docs/configuration.md), [The party's client](docs/configuration.md#the-partys-client)). diff --git a/docs/guides/federation/watching.md b/docs/guides/federation/watching.md index d99d36c..7b71bf4 100644 --- a/docs/guides/federation/watching.md +++ b/docs/guides/federation/watching.md @@ -9,7 +9,34 @@ store, through its API and its log. `continuum-party status` says most of what follows at a glance: the store and its version, the party's keys and nodes, the node's stop, the proposals on the current version, -the versions the node refused of its own, and what the party signs again after a move. +the versions the node refused of its own, and what the party signs again after a move: + +``` +store 6d1e8a0c4f2b… + checkpoint 6d1e8a0c4f2b… + 3 heads, 120 events taken after the checkpoint +version 3 (a7c2e81b9d04…) + federation 1, the base revision + 3 parties, 2 passing a change: + lass + makefu + tv +tv + keys the version names (votes, proposals, key set, node list): + ssh-ed25519 SHA256:J1nQ… + keys of its key set (writes): + ssh-ed25519 SHA256:pX4c… (--key) + ssh-ed25519 SHA256:r82M… + nodes: + continuum:5be1… (alpha) + continuum:77d0… +the node: lass's +1 proposal on version 3 (show says more): + 8d02…: can still pass, 1 more `true` passing it (2 of 3); true: tv; false: nobody +``` + +Each node goes by the name it gave itself (`--alias`), where it did: `names` of each +party in `GET /events/counts`. * **A version the node refused** (`own` in `GET /events/refused` not empty): keys voted twice, and nodes may be apart. Act on it at once diff --git a/docs/openapi.yaml b/docs/openapi.yaml index 797c46f..af17d69 100644 --- a/docs/openapi.yaml +++ b/docs/openapi.yaml @@ -1586,7 +1586,8 @@ paths: description: | What counts, as the store reads now (docs/federation.md): the current version (its number, its hash, its revision, by number and ID and as people read it, and - the version itself), each party's keys and nodes, what each of those nodes said + the version itself), each party's keys and nodes, the names those nodes gave + themselves (`names`, by node ID, `--alias`, of those that did), what each said it speaks and knows (`knows`, by node ID: the wire versions it speaks, 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 node doesn't know it; @@ -1622,7 +1623,7 @@ paths: type: object additionalProperties: type: object - required: [keys, nodes, knows] + required: [keys, nodes, names, knows] properties: keys: type: array @@ -1632,6 +1633,10 @@ paths: type: array items: type: string + names: + type: object + additionalProperties: + type: string knows: type: object additionalProperties: diff --git a/share/bash-completion/completions/continuum-party b/share/bash-completion/completions/continuum-party index 057e8a5..de44be7 100644 --- a/share/bash-completion/completions/continuum-party +++ b/share/bash-completion/completions/continuum-party @@ -21,7 +21,7 @@ _continuum_party_proposals() _continuum_party_parties() { _continuum_party_asking status | - sed -n 's/^version .* passing a change (\(.*\))$/\1/p' | tr -d ',' + awk '/passing a change:$/ { on = 1; next } on && /^ [^ ]/ { print $1; next } { on = 0 }' } # The places holding a value. diff --git a/src/api/events.rs b/src/api/events.rs index 06a6e31..81f1481 100644 --- a/src/api/events.rs +++ b/src/api/events.rs @@ -155,7 +155,8 @@ async fn event(State(state): State<AppState>, Path(id): Path<String>) -> Respons } /// `GET /events/counts`: what counts, as the store reads now: the current version, each -/// party's keys and nodes, what each of those nodes says it speaks and knows (`knows`), +/// party's keys and nodes, the names those nodes gave themselves (`names`, `--alias`), what +/// each of them says it speaks and knows (`knows`), /// the values at places, the members, and the proposals on the /// current version, each with the events proposing it a vote may build on (`proposals`: /// for a checkpoint, those above its heads), the votes on it, the parties @@ -164,6 +165,7 @@ async fn event(State(state): State<AppState>, Path(id): Path<String>) -> Respons /// (`client::backable`), 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); with_store(&state, |store| { let read = store.state(); let current = read.current(); @@ -176,11 +178,16 @@ async fn counts(State(state): State<AppState>) -> Response { .iter() .map(|node| (node.clone(), knows(&state, node))) .collect(); + let names: serde_json::Map<String, JsonValue> = nodes + .iter() + .filter_map(|node| Some((node.clone(), aliases.get(node)?.clone().into()))) + .collect(); ( party.clone(), json!({ "keys": read.keys_of(party, current), "nodes": nodes, + "names": names, "knows": knows, }), ) diff --git a/src/federation/party.rs b/src/federation/party.rs index 17769f3..19aadbd 100644 --- a/src/federation/party.rs +++ b/src/federation/party.rs @@ -1566,30 +1566,37 @@ async fn status(node: &Node, options: &Options, party: Option<&str>) -> Result<( _ => id.to_owned(), }; let text = |value: &JsonValue| value.as_str().unwrap_or_default().to_owned(); + let plural = + |n: usize, one: &str, many: &str| format!("{n} {}", if n == 1 { one } else { many }); let heads = summary["heads"].as_array().map_or(0, Vec::len); + println!("store {}", short(&text(&summary["store"]))); + println!(" checkpoint {}", short(&text(&summary["checkpoint"]))); println!( - "store {}: checkpoint {}, {heads} head{}, {} events taken after it", - short(&text(&summary["store"])), - short(&text(&summary["checkpoint"])), - if heads == 1 { "" } else { "s" }, - summary["taken"] + " {}, {} taken after the checkpoint", + plural(heads, "head", "heads"), + plural( + summary["taken"].as_u64().unwrap_or_default() as usize, + "event", + "events" + ) ); - let parties: Vec<&String> = current.parties.keys().collect(); - let needed = (2 * parties.len()).div_ceil(3); + let needed = (2 * current.parties.len()).div_ceil(3); println!( - "version {} ({}) of federation {}, {}: {} part{}, {needed} passing a change ({})", + "version {} ({})", current.number, - short(¤t.hash.to_string()), - counts["version"]["version"]["federation"], - current.revision, - parties.len(), - if parties.len() == 1 { "y" } else { "ies" }, - parties - .iter() - .map(|party| party.as_str()) - .collect::<Vec<_>>() - .join(", ") + short(¤t.hash.to_string()) ); + println!( + " federation {}, {}", + counts["version"]["version"]["federation"], current.revision + ); + println!( + " {}, {needed} passing a change:", + plural(current.parties.len(), "party", "parties") + ); + for party in current.parties.keys() { + println!(" {party}"); + } let record = options .record .as_ref() @@ -1601,46 +1608,14 @@ async fn status(node: &Node, options: &Options, party: Option<&str>) -> Result<( .map(str::to_owned) .or_else(|| summary["party"].as_str().map(str::to_owned)); if let Some(party) = &party { - let keys = listed(&counts, party, "keys"); - let nodes = listed(&counts, party, "nodes"); - let named = match options.key.as_deref().map(given_key) { - Some(Ok(given)) => { - let line = match given { - Given::Private(key) => PublicKey(key.verifying_key().to_bytes()).line(), - Given::Public(key, _) => key.line(), - }; - let names = current - .parties - .get(party) - .is_some_and(|given| given.keys.contains(&line)); - if names { - "; the version names --key's" - } else { - "; the version doesn't name --key's: it signs none of its votes, proposals, \ - key set or node list" + println!("{party}"); + match current.parties.get(party) { + None => println!(" no party of version {}", current.number), + Some(given) => { + for line in party_lines(&counts, party, &given.keys, options.key.as_deref()) { + println!(" {line}"); } } - _ => "", - }; - let spelled = |items: &[String], spell: fn(&str) -> String| { - items - .iter() - .map(|item| spell(item)) - .collect::<Vec<_>>() - .join(", ") - }; - if current.parties.contains_key(party) { - println!( - "{party}: {} key{} ({}){named}; {} node{} ({})", - keys.len(), - if keys.len() == 1 { "" } else { "s" }, - spelled(&keys, client::fingerprint), - nodes.len(), - if nodes.len() == 1 { "" } else { "s" }, - spelled(&nodes, |node| node.to_owned()), - ); - } else { - println!("{party}: no party of version {}", current.number); } } let by_itself = if summary["votesByItself"].as_bool() == Some(true) { @@ -1707,6 +1682,63 @@ async fn status(node: &Node, options: &Options, party: Option<&str>) -> Result<( Ok(()) } +/// A party's keys and nodes, as `status` says them under its name, a line each, indented +/// beneath their heading: the keys the version names (`named`), which sign its votes, +/// proposals, key set and node list; those of its key set as it counts (`counts`), which +/// sign its writes; each by its fingerprint, `--key`'s (`given`) marked, and said where +/// it is neither; and its nodes as they count, by ID, each with the name it gave itself +/// where it did. +fn party_lines( + counts: &JsonValue, + party: &str, + named: &[String], + given: Option<&str>, +) -> Vec<String> { + let given = given.and_then(|given| match given_key(given).ok()? { + Given::Private(key) => Some(PublicKey(key.verifying_key().to_bytes()).line()), + Given::Public(key, _) => Some(key.line()), + }); + let key_line = |key: &String| { + let mark = if given.as_ref() == Some(key) { + " (--key)" + } else { + "" + }; + format!(" {}{mark}", client::fingerprint(key)) + }; + let set = listed(counts, party, "keys"); + let mut lines = + vec!["keys the version names (votes, proposals, key set, node list):".to_owned()]; + lines.extend(named.iter().map(key_line)); + if set == named { + lines.push("keys of its key set (writes): the same".to_owned()); + } else { + lines.push("keys of its key set (writes):".to_owned()); + lines.extend(set.iter().map(key_line)); + } + if let Some(given) = &given + && !named.contains(given) + && !set.contains(given) + { + lines.push(format!( + "--key, {}, is none of these: it signs nothing for {party}", + client::fingerprint(given) + )); + } + let nodes = listed(counts, party, "nodes"); + if nodes.is_empty() { + lines.push("nodes: none".to_owned()); + } else { + lines.push("nodes:".to_owned()); + } + let names = &counts["parties"][party]["names"]; + lines.extend(nodes.iter().map(|node| match names[node].as_str() { + Some(name) => format!(" {node} ({name})"), + None => format!(" {node}"), + })); + lines +} + /// The values that count, all or under the place `path` names (and it), each with who /// writes there, a line each: `PATH VALUE (WRITER)`, the value as JSON; or with `--json`, /// one JSON object of them, by place. @@ -2866,6 +2898,38 @@ mod tests { assert_eq!(working_as(&["status"], None, None).unwrap(), None); } + /// `status` says a party's keys and nodes a line each: the version's, its key set's + /// where they differ, `--key`'s marked, and each node with the name it gave itself. + #[test] + fn a_partys_keys_and_nodes_a_line_each() { + use crate::federation::client::fingerprint; + use crate::federation::harness::{key_line, node_id}; + let (named, laptop) = (key_line(1), key_line(2)); + let counts = serde_json::json!({"parties": {"tv": { + "keys": [laptop], + "nodes": [node_id(1), node_id(2)], + "names": {node_id(1): "alpha"}, + }}}); + let dir = crate::files::scratch_dir("party-lines"); + let given = dir.join("laptop.pub"); + std::fs::write(&given, format!("{laptop} tv@laptop\n")).unwrap(); + let lines = super::party_lines(&counts, "tv", std::slice::from_ref(&named), given.to_str()); + assert_eq!( + lines, + [ + "keys the version names (votes, proposals, key set, node list):".to_owned(), + format!(" {}", fingerprint(&named)), + "keys of its key set (writes):".to_owned(), + format!(" {} (--key)", fingerprint(&laptop)), + "nodes:".to_owned(), + format!(" {} (alpha)", node_id(1)), + format!(" {}", node_id(2)), + ] + ); + let lines = super::party_lines(&counts, "tv", std::slice::from_ref(&laptop), None); + assert_eq!(lines[2], "keys of its key set (writes): the same"); + } + /// `values` shows a place and those under it, not those beside it. #[test] fn places_under_a_path() { |
