From 1c0ad4202d971a3555157c2babc07999d166959d Mon Sep 17 00:00:00 2001 From: tv Date: Wed, 18 Nov 2026 11:50:43 +0000 Subject: continuum-party next: the version after the current one, to change `next` prints the current version numbered on, naming its hash as the version it changes, and without the checkpoint it names, whose heads are behind: what a party changes and proposes. The guides begin a version with it. --- src/federation/party.rs | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'src/federation') diff --git a/src/federation/party.rs b/src/federation/party.rs index 9d9c268..bc10a10 100644 --- a/src/federation/party.rs +++ b/src/federation/party.rs @@ -12,6 +12,8 @@ //! * `write PATH VALUE`: writes `VALUE` (JSON) at `PATH`; //! * `keys KEY...`, `nodes NODE...`: writes the party's key set (`authorized_keys` lines, //! each one argument, their comments left out) or node list (node IDs); +//! * `next`: the version after the current one, to change and propose: the current one +//! numbered on, naming its hash, without its checkpoint (JSON), to standard output; //! * `propose FILE`: proposes the version `FILE` holds (JSON); //! * `vote PROPOSAL yes|no`: votes on the proposal of hash `PROPOSAL` on the current //! version, by the record; with `--through`, through the node that votes for the @@ -99,6 +101,10 @@ fn command() -> Command { .about("Writes the party's node list") .arg(Arg::new("nodes").num_args(0..)), ) + .subcommand(Command::new("next").about( + "The version after the current one, to change and propose: numbered on, naming the \ + current one's hash, without its checkpoint", + )) .subcommand( Command::new("propose") .about("Proposes the version a file holds (JSON)") @@ -185,6 +191,11 @@ pub(crate) async fn main() -> Result<()> { if name == "proposals" { return proposals(&node).await; } + if name == "next" { + let next = next(&node.current().await?)?; + println!("{}", serde_json::to_string_pretty(&next)?); + return Ok(()); + } if name == "fork" { let version = version_in(sub.get_one::("file").expect("required"))?; let heads = strings(sub, "heads"); @@ -600,6 +611,20 @@ async fn proposals(node: &Node) -> Result<()> { Ok(()) } +/// The version after `current`, to change and propose: `current` numbered on, naming its +/// hash as the version it changes, and without the checkpoint it names, whose heads are +/// behind: a version naming them again is never written. +fn next(current: &Version) -> Result { + let mut next: JsonValue = serde_json::from_slice(¤t.json.bytes())?; + let fields = next + .as_object_mut() + .context("a version that is no object")?; + fields.insert("number".to_owned(), (current.number + 1).into()); + fields.insert("changes".to_owned(), current.hash.to_string().into()); + fields.remove("checkpoint"); + Ok(next) +} + /// 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))?; @@ -790,6 +815,25 @@ mod tests { assert!(why.contains("OpenSSH private key"), "{why}"); } + /// The next version is the current one numbered on, naming its hash, without its + /// checkpoint: a version changing it, as its parties may pass. + #[test] + fn the_next_version_changes_the_current_one() { + use crate::federation::harness::{Party, Spec}; + use crate::federation::store::Id; + use crate::federation::version::Version; + let first = Spec::first(&[&Party::new("tv", 1), &Party::new("lass", 2)], &[]); + let mut second = first.after(first.hash()); + second.checkpoint = Some(vec![Id::of(b"a head")]); + let current = Version::read(&second.json()).unwrap(); + let next = super::next(¤t).unwrap(); + assert_eq!(next["number"], current.number + 1); + assert_eq!(next["changes"], current.hash.to_string()); + assert!(next.get("checkpoint").is_none()); + let next = Version::read(&crate::federation::client::json(&next).unwrap()).unwrap(); + next.changes_validly(Some(¤t)).unwrap(); + } + /// Its options come from configuration files as the node's do, arguments winning. #[test] fn its_options_come_from_configuration_files_and_arguments() { -- cgit v1.3.1