aboutsummaryrefslogtreecommitdiffstats
path: root/src/federation/store
diff options
context:
space:
mode:
Diffstat (limited to 'src/federation/store')
-rw-r--r--src/federation/store/memory.rs19
-rw-r--r--src/federation/store/mod.rs7
2 files changed, 25 insertions, 1 deletions
diff --git a/src/federation/store/memory.rs b/src/federation/store/memory.rs
index 092a606..73ee1c3 100644
--- a/src/federation/store/memory.rs
+++ b/src/federation/store/memory.rs
@@ -286,10 +286,27 @@ impl<F: Fold> Store<F> {
/// What a new event builds on: its heads, as many as an event may name
/// (`Fold::DEPENDENCIES`), the earliest taken first, so that what is written merges
- /// what stayed apart the longest.
+ /// what stayed apart the longest; among them always one holding what the fold judges
+ /// a new event by (`Fold::judged_by`), where a head does: the earliest such, in place
+ /// of the last of the others. Without it, an event on old heads alone is judged as at
+ /// their histories: under the federation's version before, say.
pub(crate) fn building_on(&self) -> Vec<Id> {
let mut heads = self.heads();
+ if heads.len() <= F::DEPENDENCIES {
+ return heads;
+ }
+ let judged_by = F::judged_by(&self.state);
+ let holding = heads.iter().copied().find(|head| {
+ let history = self.history(std::slice::from_ref(head));
+ judged_by.iter().any(|id| history.contains(id))
+ });
heads.truncate(F::DEPENDENCIES);
+ if let Some(holding) = holding
+ && !heads.contains(&holding)
+ {
+ heads.pop();
+ heads.push(holding);
+ }
heads
}
diff --git a/src/federation/store/mod.rs b/src/federation/store/mod.rs
index d2028da..06f7a58 100644
--- a/src/federation/store/mod.rs
+++ b/src/federation/store/mod.rs
@@ -128,6 +128,13 @@ pub(crate) trait Fold {
/// The heads of a later checkpoint, where a store reading as `now` moves to one.
fn moves_to(now: &Self::State) -> Option<Vec<Id>>;
+ /// The events one of which a new event is to have in its history, where what an event
+ /// is judged by depends on its history beyond what the checkpoint says: of a store
+ /// reading as `now`, none unless the fold names some (`Store::building_on`).
+ fn judged_by(_now: &Self::State) -> Vec<Id> {
+ Vec::new()
+ }
+
/// The nodes that carry the store, each with its group.
fn members(state: &Self::State) -> Vec<(String, String)>;
}