summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--docs/guides/federation/proposing-and-voting.md9
-rw-r--r--src/federation/client.rs53
-rw-r--r--src/federation/party.rs13
3 files changed, 60 insertions, 15 deletions
diff --git a/docs/guides/federation/proposing-and-voting.md b/docs/guides/federation/proposing-and-voting.md
index 9ec014b..e342b5b 100644
--- a/docs/guides/federation/proposing-and-voting.md
+++ b/docs/guides/federation/proposing-and-voting.md
@@ -54,8 +54,10 @@ continuum-party --node http://tv:secret@localhost:3000 --key tv.key --record tv.
With `--yes`, the client votes `true` on it too, as `vote 8d02… yes` does (Voting,
below): a party whose node votes for it by itself votes through that node instead.
-The client proposes only a version changing the current one, as a version must (its
-`number`, `changes`, and each `since`), and says why it doesn't otherwise. The proposal
+The client proposes only a version it would back: one changing the current one as a
+version must (its `number`, `changes`, and each `since`), whose checkpoint, where it names
+one, names none of the heads of the current version's checkpoint, as such a version is
+never written. It says why it doesn't propose one otherwise. The proposal
is on the current version, and its hash is the version's: the node shows it under that
hash (`proposals` in `GET /events/counts`), with the events proposing it.
Several parties proposing the same version make one proposal. The key a party proposes
@@ -78,7 +80,8 @@ record before it sends the vote. It casts no vote that would make its party vote
* never `true` and `false` on one proposal, nor the same vote twice;
* nothing on the version current when the record began, as a vote sent before may be
held back somewhere;
-* `true` only for a version changing the current one;
+* `true` only for a version changing the current one, whose checkpoint names none of the
+ current checkpoint's heads;
* one `true` at a time: another `true` on the same version only once the proposal the
party backed is dead. The client fetches the votes that made it so from the node, and
keeps them in the record beside the new `true`.
diff --git a/src/federation/client.rs b/src/federation/client.rs
index 0f06ca3..88e370f 100644
--- a/src/federation/client.rs
+++ b/src/federation/client.rs
@@ -303,10 +303,7 @@ impl Record {
if !yes {
return Ok(Vec::new());
}
- let version = Version::read(proposed).map_err(|why| format!("no version: {why}"))?;
- version
- .changes_validly(Some(current))
- .map_err(|why| format!("no version changing the current one: {why}"))?;
+ backable(current, proposed)?;
let mut kept = Vec::new();
for earlier in cast.iter().filter(|vote| vote.yes) {
if !dead_by(current, &earlier.proposal, nays) {
@@ -364,6 +361,30 @@ impl Record {
}
}
+/// The version `proposed` is, where a party may back it on `current`, and so propose it: a
+/// version, changing `current` as a version must (`Version::changes_validly`), and naming
+/// none of the heads of the checkpoint `current` names: a version's checkpoint is after the
+/// current one's, and one naming those heads again is never written.
+pub(crate) fn backable(current: &Version, proposed: &Json) -> Result<Version, String> {
+ let version = Version::read(proposed).map_err(|why| format!("no version: {why}"))?;
+ version
+ .changes_validly(Some(current))
+ .map_err(|why| format!("no version changing the current one: {why}"))?;
+ let named = version.checkpoint.as_deref().unwrap_or_default();
+ if let Some(head) = current
+ .checkpoint
+ .iter()
+ .flatten()
+ .find(|head| named.contains(*head))
+ {
+ return Err(format!(
+ "its checkpoint names {head}, a head of the current version's checkpoint: a \
+ version naming those again is never written"
+ ));
+ }
+ Ok(version)
+}
+
/// 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.
@@ -698,6 +719,30 @@ mod tests {
assert!(again.contains(&Id::of(&later)) && again.contains(&Id::of(&keys)));
}
+ /// A party backs, and proposes, only a version changing the current one whose
+ /// checkpoint, where it names one, names none of the current checkpoint's heads.
+ #[test]
+ fn a_version_backed_changes_the_current_one_and_moves_on() {
+ let (_, _, _, first, current, one, _) = three();
+ assert!(backable(&current, &one.json()).is_ok());
+ let mut far = one.clone();
+ far.number += 1;
+ assert!(backable(&current, &far.json()).is_err());
+ assert!(backable(&current, &first.after(Id::of(b"another")).json()).is_err());
+ assert!(backable(&current, &harness::str("no version")).is_err());
+ let (head, later) = (Id::of(b"a head"), Id::of(b"a later head"));
+ let mut moved = one.clone();
+ moved.checkpoint = Some(vec![head]);
+ let moved_to = Version::read(&moved.json()).unwrap();
+ let mut again = moved.after(moved_to.hash);
+ again.checkpoint = Some(vec![head]);
+ assert!(backable(&moved_to, &again.json()).is_err());
+ again.checkpoint = Some(vec![later]);
+ assert!(backable(&moved_to, &again.json()).is_ok());
+ again.checkpoint = None;
+ assert!(backable(&moved_to, &again.json()).is_ok());
+ }
+
/// 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() {
diff --git a/src/federation/party.rs b/src/federation/party.rs
index 788bde9..60b7e18 100644
--- a/src/federation/party.rs
+++ b/src/federation/party.rs
@@ -16,9 +16,9 @@
//! changed; with `--set`, set whole. One left empty is written with `--force` only;
//! * `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), where it changes the
-//! current one as a version must (`Version::changes_validly`), and says the proposal's
-//! hash; with `--yes`, votes `true` on it too, as `vote` does;
+//! * `propose FILE`: proposes the version `FILE` holds (JSON), where a party may back it
+//! (`client::backable`), and says the proposal's hash; with `--yes`, votes `true` on it
+//! too, as `vote` does;
//! * `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
//! party by itself and keeps its record, as such a party votes by hand;
@@ -425,11 +425,8 @@ pub(crate) async fn main() -> Result<()> {
let version = version_in(sub.get_one::<String>("file").expect("required"))?;
let current = node.current().await?;
signer.named_by(&current)?;
- let proposed = Version::read(&version)
- .and_then(|proposed| proposed.changes_validly(Some(&current)).map(|()| proposed))
- .map_err(|why| {
- anyhow!("not a version changing version {}: {why}", current.number)
- })?;
+ let proposed = client::backable(&current, &version)
+ .map_err(|why| anyhow!("not a version a party may back: {why}"))?;
sign(
&node,
&signer,