diff options
| author | tv <tv@krebsco.de> | 2026-11-19 03:52:49 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-19 05:11:45 +0100 |
| commit | 6c6f978189eafa15add0df865f713dc946dfc5cb (patch) | |
| tree | 2b4c556ba96820aa6fd13c22d96cd5fe5af9e091 /src/federation/revision.rs | |
| parent | 54bcc0e4ee8e1e6a29e0e01369c2ba95b27abce8 (diff) | |
federation: merge events, the first revision
What builds on many heads merges them, but only an event a party writes: in a quiet
federation, heads beside each other stay so, and past 64 no event is above them all.
Revision 1 (`merge-events`) adds merge events: `{"merge": true}`, signed with a node's
own key, the `key` its Ed25519 key, for the party whose node list names it. One counts for
nothing, and only gathers what it builds on into the history of what builds on it. Under
the base revision, signed by a node its party doesn't list, or by a party's key, it is
refused; the model alike. Generated federations begin at either revision, and their nodes
merge.
A node voting by itself backs no version changing the revision, on any version neither:
its party's operators vote on that one, once their nodes run a continuum that knows it.
`federation.md` lists the revisions, says what a merge event is, and row 71 is tested
(`federation_attack_71`).
Diffstat (limited to 'src/federation/revision.rs')
| -rw-r--r-- | src/federation/revision.rs | 37 |
1 files changed, 33 insertions, 4 deletions
diff --git a/src/federation/revision.rs b/src/federation/revision.rs index 876ec15..3c6261b 100644 --- a/src/federation/revision.rs +++ b/src/federation/revision.rs @@ -12,24 +12,44 @@ use super::store::Id; /// A feature a revision adds. #[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub(crate) enum Feature {} +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, +} impl Feature { /// Its name, in the IDs of the revisions that have it: never changed once released, /// and specific, so that a feature another build names alike is one it adds alike. pub(crate) fn name(self) -> &'static str { - match self {} + match self { + Feature::MergeEvents => "merge-events", + } } /// What it adds, in a line. pub(crate) fn what(self) -> &'static str { - match self {} + match self { + Feature::MergeEvents => { + "merge events, which a node its party lists signs with its own key, building \ + on events it holds and writing nothing" + } + } + } + + /// The revision that adds it. + pub(crate) fn revision(self) -> Revision { + let at = FEATURES + .iter() + .position(|feature| *feature == self) + .expect("every feature is in FEATURES"); + Revision(at + 1) } } /// 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] = &[]; +pub(crate) const FEATURES: &[Feature] = &[Feature::MergeEvents]; /// A revision: how many of `FEATURES` it has. #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord)] @@ -113,6 +133,15 @@ mod tests { assert_eq!(Revision::of(&Id::of(b"[]")), Some(Revision(0))); assert_eq!(Revision::of(&Id::of(b"[\"elsewhere\"]")), None); assert_eq!(Revision::default().to_string(), "the base revision"); + assert_eq!( + Feature::MergeEvents.revision().to_string(), + "revision 1 (merge-events)" + ); + assert_eq!( + Revision(1).id(), + Id::of(br#"["merge-events"]"#), + "a released revision's ID changes never" + ); 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"); |
