aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--docs/guides/federation/common-changes.md4
-rw-r--r--docs/guides/federation/getting-started.md11
-rw-r--r--docs/guides/federation/proposing-and-voting.md8
-rw-r--r--src/federation/party.rs44
4 files changed, 58 insertions, 9 deletions
diff --git a/docs/guides/federation/common-changes.md b/docs/guides/federation/common-changes.md
index 2e5861e..acbd98a 100644
--- a/docs/guides/federation/common-changes.md
+++ b/docs/guides/federation/common-changes.md
@@ -12,9 +12,7 @@ hash as `changes`, and no `checkpoint` (a version names one only to move the sto
on, and the current version's heads are behind):
```sh
-curl -s -u tv:secret localhost:3000/events/counts |
- jq '.version as $v | $v.version | .number += 1 | .changes = $v.hash | del(.checkpoint)' \
- > next.json
+continuum-party --node http://tv:secret@localhost:3000 next > next.json
```
Each recipe is a `jq` filter on that file; then propose the result, and vote.
diff --git a/docs/guides/federation/getting-started.md b/docs/guides/federation/getting-started.md
index 6f1693c..6eebbd8 100644
--- a/docs/guides/federation/getting-started.md
+++ b/docs/guides/federation/getting-started.md
@@ -150,8 +150,15 @@ continuum-party --record makefu.record init makefu --root root
```
The founders write the version letting makefu in: the next number, the hash of the
-version it changes (`.version.hash` in `GET /events/counts`), makefu's keys and node
-list named anew in it (`since` its number), and the founders' as they were:
+version it changes, makefu's keys and node list named anew in it (`since` its number),
+and the founders' as they were. `continuum-party next` gives the current version with
+the first two changed:
+
+```sh
+continuum-party --node http://tv:secret@localhost:3000 next > second.json
+```
+
+and makefu goes in:
```json
{ "federation": 1, "number": 1, "changes": "1f4c…",
diff --git a/docs/guides/federation/proposing-and-voting.md b/docs/guides/federation/proposing-and-voting.md
index 5330b06..7293fba 100644
--- a/docs/guides/federation/proposing-and-voting.md
+++ b/docs/guides/federation/proposing-and-voting.md
@@ -10,14 +10,14 @@ node list and its key set are its own to write, without a vote
## Writing a version
A version is the whole policy, not a change to it. Begin from the current one, as a node
-shows it ([`common-changes.md`](common-changes.md) does the first steps below in one):
+shows it, with `number` and `changes` set and its `checkpoint` left out, as below:
```sh
-curl -s -u tv:secret localhost:3000/events/counts | jq .version.version > next.json
-curl -s -u tv:secret localhost:3000/events/counts | jq -r .version.hash
+continuum-party --node http://tv:secret@localhost:3000 next > next.json
```
-Then change it:
+What each field holds, to change ([`common-changes.md`](common-changes.md) has recipes
+for the changes made most):
* **`number`**: one more than the current version's.
* **`changes`**: the current version's hash.
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::<String>("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<JsonValue> {
+ let mut next: JsonValue = serde_json::from_slice(&current.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<Version> {
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(&current).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(&current)).unwrap();
+ }
+
/// Its options come from configuration files as the node's do, arguments winning.
#[test]
fn its_options_come_from_configuration_files_and_arguments() {