summaryrefslogtreecommitdiffstats
path: root/src/federation
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-19 01:48:57 +0000
committertv <tv@krebsco.de>2026-11-19 03:19:12 +0100
commite0075264e9efdd4c8a32290c0d5643e7f48bfb14 (patch)
tree646f0ab7fb2dd61e93bc1b8cce6f6a13a5ff0b8b /src/federation
parent31d41eb1c902c907a5c6e5608510f96c4b1bc864 (diff)
federation: a checkpoint of 64 heads at most, a version of 96 parties
No event is above more heads than it may name dependencies (64): a version naming more for its checkpoint is never written. A node voting by itself proposed one at whatever heads it held for a while, however many; it now proposes none past 64, as what is written merges them, and a party's client backs none such (`client::backable`). A version event names the votes passing a proposal, two thirds of its version's parties: past 96 parties, more than an event may name. A version names at most 96 now (`version::PARTIES`).
Diffstat (limited to 'src/federation')
-rw-r--r--src/federation/client.rs30
-rw-r--r--src/federation/version.rs25
-rw-r--r--src/federation/vote.rs6
3 files changed, 56 insertions, 5 deletions
diff --git a/src/federation/client.rs b/src/federation/client.rs
index c5d3651..489741a 100644
--- a/src/federation/client.rs
+++ b/src/federation/client.rs
@@ -362,15 +362,24 @@ 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.
+/// version, changing `current` as a version must (`Version::changes_validly`), naming no
+/// more checkpoint heads than an event may be above, and 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 named.len() > super::event::DEPENDENCIES {
+ return Err(format!(
+ "its checkpoint names {} heads: no event is above more than {}, so it is never \
+ written",
+ named.len(),
+ super::event::DEPENDENCIES
+ ));
+ }
if let Some(head) = current
.checkpoint
.iter()
@@ -752,11 +761,24 @@ mod tests {
}
/// 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.
+ /// checkpoint, where it names one, names no more heads than an event may be above, and
+ /// 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 wide = one.clone();
+ let heads: Vec<Id> = (0..=super::super::event::DEPENDENCIES)
+ .map(|n| Id::of(format!("head {n}").as_bytes()))
+ .collect();
+ wide.checkpoint = Some(heads[1..].to_vec());
+ assert!(backable(&current, &wide.json()).is_ok());
+ wide.checkpoint = Some(heads);
+ assert!(
+ backable(&current, &wide.json())
+ .unwrap_err()
+ .contains("65 heads")
+ );
let mut far = one.clone();
far.number += 1;
assert!(backable(&current, &far.json()).is_err());
diff --git a/src/federation/version.rs b/src/federation/version.rs
index d714a47..378e122 100644
--- a/src/federation/version.rs
+++ b/src/federation/version.rs
@@ -16,6 +16,11 @@ pub(crate) const KEYS: usize = 16;
/// Nodes a node list may name.
pub(crate) const NODES: usize = 64;
+/// Parties a version may name: a version event names the votes passing a proposal, two
+/// thirds of its version's parties, and an event names no more than 64 events
+/// (`event::DEPENDENCIES`).
+pub(crate) const PARTIES: usize = 96;
+
/// Segments a path may have, and bytes a segment.
pub(crate) const SEGMENTS: usize = 32;
pub(crate) const SEGMENT_BYTES: usize = 255;
@@ -210,6 +215,12 @@ impl Version {
if keys.names().is_empty() {
return Err("no party".to_owned());
}
+ if keys.names().len() > PARTIES {
+ return Err(format!(
+ "{} parties, more than {PARTIES}",
+ keys.names().len()
+ ));
+ }
let mut parties = BTreeMap::new();
let mut every_key = BTreeSet::new();
for name in keys.names() {
@@ -534,6 +545,20 @@ mod tests {
);
}
+ /// A version names no more parties than a version event may name the votes of two
+ /// thirds of.
+ #[test]
+ fn a_version_names_at_most_96_parties() {
+ use super::super::harness::{Party, Spec};
+ let parties: Vec<Party> = (1..=PARTIES as u8 + 1)
+ .map(|n| Party::new(&format!("p{n}"), n))
+ .collect();
+ let named: Vec<&Party> = parties.iter().collect();
+ assert!(Version::read(&Spec::first(&named[1..], &[]).json()).is_ok());
+ let why = Version::read(&Spec::first(&named, &[]).json()).unwrap_err();
+ assert_eq!(why, "97 parties, more than 96");
+ }
+
#[test]
fn a_version_changes_another_by_its_number_hash_and_sinces() {
let first = Version::read(&first()).expect("a version");
diff --git a/src/federation/vote.rs b/src/federation/vote.rs
index 1b4de16..693339e 100644
--- a/src/federation/vote.rs
+++ b/src/federation/vote.rs
@@ -397,7 +397,11 @@ fn checkpoint(seen: &Seen<'_>, rules: &Rules, current: &Version, all: &[Proposed
.flatten()
.collect();
let heads: Vec<Id> = held.difference(&built_on).copied().collect();
- if heads.is_empty() || store.state_at(&heads).current().hash != current.hash {
+ // No event is above more heads than it may name: what is written merges them.
+ if heads.is_empty()
+ || heads.len() > super::event::DEPENDENCIES
+ || store.state_at(&heads).current().hash != current.hash
+ {
return None;
}
let Json::Object(mut members) = current