summaryrefslogtreecommitdiffstats
path: root/src/federation/client.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/federation/client.rs')
-rw-r--r--src/federation/client.rs30
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(&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());