aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md8
-rw-r--r--docs/federation-tests.md3
-rw-r--r--docs/federation.md32
-rw-r--r--src/federation/client.rs33
-rw-r--r--src/federation/harness.rs6
-rw-r--r--src/federation/properties.rs17
-rw-r--r--src/federation/revision.rs18
-rw-r--r--src/federation/version.rs57
8 files changed, 152 insertions, 22 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c2e592d..6a666db 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,14 @@ it from the release before ([`docs/operations.md`](docs/operations.md),
## Unreleased
+* Revision 2 of federation 1, `federation-name`: a version may give the federation a
+ name, which a later one changes; the first version's, in the root, parts the federation
+ from a rehearsal of the same parties, keys, nodes and rules named otherwise
+ ([`docs/federation.md`](docs/federation.md),
+ [Changing the federation](docs/federation.md#changing-the-federation);
+ [`src/federation/revision.rs`](src/federation/revision.rs),
+ [`src/federation/version.rs`](src/federation/version.rs)).
+
* `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);
diff --git a/docs/federation-tests.md b/docs/federation-tests.md
index eeb90b6..e6b3ba7 100644
--- a/docs/federation-tests.md
+++ b/docs/federation-tests.md
@@ -61,7 +61,8 @@ to: a stage is done when its tests are.
## Properties, over generated histories
Histories are generated: a few parties (3 to 7), their keys, versions passing, honest
-writes and votes, nodes merging under a revision with merge events or not, and an
+writes and votes, nodes merging and versions naming the federation anew under the newest
+revision or neither under the base revision, and an
adversary that signs anything its own keys or stolen ones can, on any dependencies, and
puts out events no party signs. Each property is checked for
every order of every history small enough (up to some 8 events, every order that puts
diff --git a/docs/federation.md b/docs/federation.md
index df4501e..7b7bd54 100644
--- a/docs/federation.md
+++ b/docs/federation.md
@@ -227,6 +227,12 @@ current at its heads, [Forks](#forks)). Spread out:
those of the parties that start it ([Nodes](#nodes)).
* **The checkpoint** (`checkpoint`), where the version names one: the heads at which the
store moves to a checkpoint once the version is current ([Checkpoints](#checkpoints)).
+* **The federation's name** (`name`), where the version gives one, under a revision that
+ has names ([Changing the federation](#changing-the-federation)): spelled as a party's
+ name. The first version's is in the root, so it parts the federation from one whose
+ first version is alike otherwise ([Starting a federation](#starting-a-federation)); a
+ later version changes it as anything else, which changes what the federation is
+ called, not which it is.
* **The rules**, in order: the first whose path matches a path says who writes there. A
path is segments separated by `/`, none empty. A rule's first segment is literal, and
not `_continuum`; any other is literal, `{party}` (the name of a party of the version,
@@ -247,16 +253,17 @@ party named like a shared name takes it where a `{party}` rule comes before it:
application keeps party names apart from its spelling (no party named `wiki` while
`wiki.r` is lass's).
-A version is none if a field is missing or more (but for `checkpoint`, which it may
-leave out), if it names more than 96 parties (two thirds of them would be more votes than
-a version event may name), if it gives a party more keys than a key set may hold or more
-nodes than a node list, or a rule a path longer than a write's may be, or if it breaks
-any of the above. A version is one event, its parties and rules with it, so it fits in
-256 KiB: a federation giving each name a rule of its own holds a few thousand names. A
-proposal is taken whatever it holds: whether it is a version is asked
-where a version event names it, so that nodes knowing more of what a version may say don't
-part from those knowing less. A node can't tell a version that is none from one a later
-continuum reads: at a version event writing one that passed, it stops
+A version is none if a field is missing (but `checkpoint`, `revision` and `name`, which
+it may leave out) or more (`name` among them, under a revision without names), if it
+names more than 96 parties (two thirds of them would be more votes than a version event
+may name), if it gives a party more keys than a key set may hold or more nodes than a
+node list, or a rule a path longer than a write's may be, or if it breaks any of the
+above. A version is one event, its parties and rules with it, so it fits in 256 KiB: a
+federation giving each name a rule of its own holds a few thousand names. A proposal is
+taken whatever it holds: whether it is a version is asked where a version event names it,
+so that nodes knowing more of what a version may say don't part from those knowing less.
+A node can't tell a version that is none from one a later continuum reads: at a version
+event writing one that passed, it stops
([Changing the federation](#changing-the-federation)). A node shows whether a proposal is
a version by the federation it knows, and a party's client backs none that isn't: two
thirds backing one that is none stop every node at its version event, until their
@@ -702,7 +709,9 @@ parties, zones, blocks and names that are nobody's by their spelling.
A federation starts with a store of its own: its root, a checkpoint without heads that
keeps nothing, its version the first, which no party signs ([Checkpoints](#checkpoints)),
-so one first version makes one federation, named by the root's ID. Among the node lists
+so one first version makes one federation, named by the root's ID. Its founders give it a
+name there ([The policy](#the-policy)), so that a rehearsal, named otherwise, is another
+federation, though its parties, keys, nodes and rules are the same. Among the node lists
the version gives, one names a node of its founders', so the federation starts with
members, and other nodes come in as their parties list them. Its swarm's genesis change
holds the root, built byte for byte from it, its policy naming the fold `federation`
@@ -933,6 +942,7 @@ another build's among them, can't read a version naming it:
| Revision | Its feature | What it adds |
| --- | --- | --- |
| 1 | `merge-events` | Merge events, which a node its party lists signs with its own key, building on events it holds and writing nothing ([Events](#events)) |
+| 2 | `federation-name` | The federation's name, which a version gives and a later one changes; the first version's, in the root, parts it from a federation alike otherwise ([The policy](#the-policy)) |
What no history judges, the document, a change, the snapshot and the Automerge version, no
version names: a change there splits the swarm until every node runs it
diff --git a/src/federation/client.rs b/src/federation/client.rs
index ca2db86..74be7c8 100644
--- a/src/federation/client.rs
+++ b/src/federation/client.rs
@@ -433,8 +433,8 @@ pub(crate) fn backable(current: &Version, proposed: &Json) -> Result<Version, St
/// What the version `proposed` does to `current`, in words, a line each: the parties it
/// lets in or takes out, the keys and node lists it names anew, the rules it adds or drops,
-/// the checkpoint it moves the store to, and the revision it moves to; what a party votes
-/// on, without its JSON. Its number and the hash it changes go without saying. A node goes
+/// the checkpoint it moves the store to, the revision it moves to, and the federation's
+/// name it gives; what a party votes 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,
@@ -492,6 +492,14 @@ pub(crate) fn described(
if proposed.revision != current.revision {
lines.push(format!("moves to {}", proposed.revision));
}
+ match (&current.name, &proposed.name) {
+ (None, Some(name)) => lines.push(format!("names the federation {name}")),
+ (Some(was), Some(name)) if was != name => {
+ lines.push(format!("renames the federation {was} -> {name}"));
+ }
+ (Some(was), None) => lines.push(format!("drops the federation's name, {was}")),
+ _ => {}
+ }
lines
}
@@ -1411,6 +1419,27 @@ mod tests {
"moves to revision 1 (merge-events)".to_owned(),
]
);
+ let mut named = Spec::first(&[&tv, &lass], &rules);
+ named.revision = Revision::newest();
+ named.name = Some("krebs".to_owned());
+ assert_eq!(
+ described(&current, &read(&named)),
+ [
+ format!("moves to {}", Revision::newest()),
+ "names the federation krebs".to_owned(),
+ ]
+ );
+ let mut renamed = named.clone();
+ renamed.name = Some("krebs-test".to_owned());
+ assert_eq!(
+ described(&read(&named), &read(&renamed)),
+ ["renames the federation krebs -> krebs-test"]
+ );
+ renamed.name = None;
+ assert_eq!(
+ described(&read(&named), &read(&renamed)),
+ ["drops the federation's name, krebs"]
+ );
}
/// Each hash is named by its shortest prefix no other has, of four digits at least, and
diff --git a/src/federation/harness.rs b/src/federation/harness.rs
index f14736d..04308da 100644
--- a/src/federation/harness.rs
+++ b/src/federation/harness.rs
@@ -138,6 +138,8 @@ pub(crate) struct Spec {
pub(crate) parties: Vec<SpecParty>,
/// The revision it follows: named where it isn't the base revision.
pub(crate) revision: Revision,
+ /// The federation's name, where it gives one.
+ pub(crate) name: Option<String>,
/// Each rule: its path and its writer.
pub(crate) rules: Vec<(String, Json)>,
pub(crate) checkpoint: Option<Vec<Id>>,
@@ -151,6 +153,7 @@ impl Spec {
number: 0,
changes: None,
revision: Revision::default(),
+ name: None,
parties: parties
.iter()
.enumerate()
@@ -256,6 +259,9 @@ impl Spec {
if self.revision != Revision::default() {
members.push(("revision", str(&self.revision.id().to_string())));
}
+ if let Some(name) = &self.name {
+ members.push(("name", str(name)));
+ }
object(members)
}
diff --git a/src/federation/properties.rs b/src/federation/properties.rs
index 2b824f0..dce0984 100644
--- a/src/federation/properties.rs
+++ b/src/federation/properties.rs
@@ -108,7 +108,7 @@ fn generate(rng: &mut Rng, kind: Kind) -> History {
}
/// A history of `kind`, its first version following `revision`, or, where none is given,
-/// the base revision or one with merge events alike.
+/// the base revision or the newest alike.
pub(super) fn generate_at(rng: &mut Rng, kind: Kind, revision: Option<Revision>) -> History {
let count = rng.between(3, 5);
let parties: Vec<Party> = (0..count)
@@ -117,13 +117,18 @@ pub(super) fn generate_at(rng: &mut Rng, kind: Kind, revision: Option<Revision>)
let adversary = count - 1;
let refs: Vec<&Party> = parties.iter().collect();
let mut first = Spec::first(&refs, &[("names/{party}", harness::str("{party}"))]);
- // Half the federations begin at a revision with merge events, which nodes then sign.
- let merging = rng.chance(0.5);
- first.revision = revision.unwrap_or(if merging {
- Feature::MergeEvents.revision()
+ // Half the federations begin at the newest revision: with merge events, which nodes
+ // then sign, and a name, which versions change.
+ let newest = rng.chance(0.5);
+ first.revision = revision.unwrap_or(if newest {
+ Revision::newest()
} else {
Revision::default()
});
+ let naming = first.revision.has(Feature::FederationName);
+ if naming {
+ first.name = Some("f".to_owned());
+ }
let root = first.root();
let root_id = Id::of(&root);
let mut world: Store<Federation> = Store::new(root.clone(), Vec::new()).expect("a root");
@@ -204,6 +209,8 @@ pub(super) fn generate_at(rng: &mut Rng, kind: Kind, revision: Option<Revision>)
let head = *deps.iter().find(|dep| **dep != root_id).expect("one");
next.checkpoint = Some(vec![head]);
deps = vec![head];
+ } else if naming && rng.chance(0.3) {
+ next.name = Some(format!("f{step}"));
} else {
next.rules
.push((format!("names/x{step}"), harness::str(&party.name)));
diff --git a/src/federation/revision.rs b/src/federation/revision.rs
index 7be6254..2e5464d 100644
--- a/src/federation/revision.rs
+++ b/src/federation/revision.rs
@@ -16,6 +16,9 @@ pub(crate) enum Feature {
/// Merge events: a node its party lists, with its own key, builds on events it holds,
/// writing nothing (`Does::Merge`).
MergeEvents,
+ /// The federation's name, in its versions (`Version::name`): the first version's, in
+ /// the root, parts it from a federation of a first version alike otherwise.
+ FederationName,
}
impl Feature {
@@ -24,6 +27,7 @@ impl Feature {
pub(crate) fn name(self) -> &'static str {
match self {
Feature::MergeEvents => "merge-events",
+ Feature::FederationName => "federation-name",
}
}
@@ -34,6 +38,10 @@ impl Feature {
"merge events, which a node its party lists signs with its own key, building \
on events it holds and writing nothing"
}
+ Feature::FederationName => {
+ "the federation's name, which a version gives it and a later one changes: the \
+ first version's, in the root, parts it from a federation alike otherwise"
+ }
}
}
@@ -49,7 +57,7 @@ impl Feature {
/// The features, in the order revisions add them: revision n has the first n, the base
/// revision none. Only ever appended to.
-pub(crate) const FEATURES: &[Feature] = &[Feature::MergeEvents];
+pub(crate) const FEATURES: &[Feature] = &[Feature::MergeEvents, Feature::FederationName];
/// A revision: how many of `FEATURES` it has.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord)]
@@ -158,6 +166,14 @@ mod tests {
Id::of(br#"["merge-events"]"#),
"a released revision's ID changes never"
);
+ assert_eq!(
+ Revision(2).id(),
+ Id::of(br#"["merge-events","federation-name"]"#)
+ );
+ assert_eq!(
+ Feature::FederationName.revision().to_string(),
+ "revision 2 (merge-events, federation-name)"
+ );
let names: Vec<&str> = FEATURES.iter().map(|feature| feature.name()).collect();
let distinct: std::collections::BTreeSet<&str> = names.iter().copied().collect();
assert_eq!(distinct.len(), names.len(), "a feature named twice");
diff --git a/src/federation/version.rs b/src/federation/version.rs
index fa534b3..cebb83a 100644
--- a/src/federation/version.rs
+++ b/src/federation/version.rs
@@ -5,7 +5,7 @@ use std::collections::{BTreeMap, BTreeSet};
use super::jcs::Json;
use super::keys;
-use super::revision::Revision;
+use super::revision::{Feature, Revision};
use super::store::Id;
/// The federation this is: a version naming another is none here.
@@ -34,6 +34,10 @@ pub(crate) struct Version {
pub(crate) json: Json,
/// The revision of the federation it follows: the base revision where it names none.
pub(crate) revision: Revision,
+ /// The federation's name, where it gives one (`Feature::FederationName`): spelled as a
+ /// party's name. The first version's, in the root, parts the federation from one of a
+ /// first version alike otherwise; a later version's changes only what it is called.
+ pub(crate) name: Option<String>,
pub(crate) number: u64,
/// The version it changes; none for the first.
pub(crate) changes: Option<Id>,
@@ -157,7 +161,7 @@ impl Version {
json,
"a version",
&["federation", "number", "changes", "keys", "nodes", "rules"],
- &["checkpoint", "revision"],
+ &["checkpoint", "revision", "name"],
)?;
match json.get("federation").and_then(Json::as_int) {
Some(FEDERATION) => {}
@@ -192,6 +196,22 @@ impl Version {
}
}
};
+ let name = match json.get("name") {
+ None => None,
+ Some(_) if !revision.has(Feature::FederationName) => {
+ return Err(format!(
+ "a `name`, which {revision} doesn't give a version: {} does",
+ Feature::FederationName.revision()
+ ));
+ }
+ Some(Json::Str(name)) if is_party(name) => Some(name.clone()),
+ Some(_) => {
+ return Err(
+ "a `name` that is no name: 1 to 64 of A-Z a-z 0-9 . _ @ -, as a party's"
+ .to_owned(),
+ );
+ }
+ };
let number = json
.get("number")
.and_then(Json::as_int)
@@ -226,6 +246,7 @@ impl Version {
hash: Id::of(&json.bytes()),
json: json.clone(),
revision,
+ name,
number,
changes,
parties,
@@ -624,6 +645,38 @@ mod tests {
}
}
+ /// A version gives its federation a name only under a revision that has names, spelled
+ /// as a party's name; one without gives none.
+ #[test]
+ fn a_version_names_its_federation_under_a_revision_with_names() {
+ let named = Feature::FederationName.revision();
+ let with = |revision: Revision, name: &str| {
+ let text = String::from_utf8(first().bytes()).expect("UTF-8");
+ let text = text.replacen(r#""nodes":"#, &format!(r#""name":{name},"nodes":"#), 1);
+ let text = text.replacen(
+ r#""rules":"#,
+ &format!(r#""revision":"{}","rules":"#, revision.id()),
+ 1,
+ );
+ Version::read(&jcs::read(text.as_bytes()).expect("JCS"))
+ };
+ assert_eq!(
+ with(named, r#""krebs""#)
+ .expect("a version")
+ .name
+ .as_deref(),
+ Some("krebs")
+ );
+ let why = with(Revision(named.0 - 1), r#""krebs""#).unwrap_err();
+ assert!(why.starts_with("a `name`, which revision 1"), "{why}");
+ let long = format!(r#""{}""#, "x".repeat(65));
+ for none in [r#""""#, r#""a/b""#, "1", long.as_str()] {
+ let why = with(named, none).unwrap_err();
+ assert!(why.contains("no name"), "{none}: {why}");
+ }
+ assert_eq!(Version::read(&first()).expect("a version").name, None);
+ }
+
#[test]
fn a_version_changes_another_by_its_number_hash_and_sinces() {
let first = Version::read(&first()).expect("a version");