diff options
Diffstat (limited to 'src/federation/fold.rs')
| -rw-r--r-- | src/federation/fold.rs | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/src/federation/fold.rs b/src/federation/fold.rs index c636a13..b96cf1f 100644 --- a/src/federation/fold.rs +++ b/src/federation/fold.rs @@ -610,9 +610,30 @@ impl State { } /// Whether a version event on `deps` may write a version naming `heads` for a - /// checkpoint: after the checkpoint current at its history, at which that one is - /// current too, none in another's history; and the version event above them. + /// checkpoint: heads a version may name (`may_name`), and the version event above + /// them. fn may_move(&self, heads: &[Id], deps: &[Id]) -> Result<(), Refused> { + self.may_name(heads)?; + let named: BTreeSet<Id> = heads.iter().copied().collect(); + let above = self.above(&named); + let is_above = deps + .iter() + .all(|dep| named.contains(dep) || above.contains(dep)) + && (deps.iter().any(|dep| above.contains(dep)) + || named.iter().all(|head| deps.contains(head))); + if !is_above { + return Err(Refused::new( + "not above the heads of the checkpoint it names", + )); + } + Ok(()) + } + + /// Whether a version written here may name `heads` for a checkpoint: after the + /// checkpoint current at its history, at which that one is current too, none in + /// another's history. Where not, no version event naming them is taken, whatever it + /// builds on: a `true` on such a version binds its party to what is never written. + pub(crate) fn may_name(&self, heads: &[Id]) -> Result<(), Refused> { if heads .iter() .any(|a| heads.iter().any(|b| a != b && self.built_on(a, b))) @@ -655,17 +676,6 @@ impl State { "checkpoint heads not after the current checkpoint, or at which it isn't current", )); } - let above = self.above(&named); - let is_above = deps - .iter() - .all(|dep| named.contains(dep) || above.contains(dep)) - && (deps.iter().any(|dep| above.contains(dep)) - || named.iter().all(|head| deps.contains(head))); - if !is_above { - return Err(Refused::new( - "not above the heads of the checkpoint it names", - )); - } Ok(()) } |
