diff options
| author | tv <tv@krebsco.de> | 2026-11-19 01:48:57 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-19 03:19:12 +0100 |
| commit | e0075264e9efdd4c8a32290c0d5643e7f48bfb14 (patch) | |
| tree | 646f0ab7fb2dd61e93bc1b8cce6f6a13a5ff0b8b /src/federation/client.rs | |
| parent | 31d41eb1c902c907a5c6e5608510f96c4b1bc864 (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/client.rs')
| -rw-r--r-- | src/federation/client.rs | 30 |
1 files changed, 26 insertions, 4 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(¤t, &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(¤t, &wide.json()).is_ok()); + wide.checkpoint = Some(heads); + assert!( + backable(¤t, &wide.json()) + .unwrap_err() + .contains("65 heads") + ); let mut far = one.clone(); far.number += 1; assert!(backable(¤t, &far.json()).is_err()); |
