aboutsummaryrefslogtreecommitdiffstats
path: root/src/federation/store/memory.rs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-25 13:03:52 +0000
committertv <tv@krebsco.de>2026-11-25 13:03:52 +0000
commit1656f73b41a3528048c33774457b0d68ed430934 (patch)
tree56fa9550232e9831f1f2d6ed324d9b16b9d713cf /src/federation/store/memory.rs
parent1820e326115f803ffa84280aad4e367f20d91e9f (diff)
store: a new event builds on a head holding what it is judged by
A new event builds on the heads taken earliest, 64 at most. Where a store holds more, and those all come from before the current version was written, an event on them is written under the version before: a merge event, under one without merge events, was refused, so the backlog of heads a revision was passed to merge stayed, and with more heads than a checkpoint may name, no node proposed one. The fold now says which events a new one is to have in its history (Fold::judged_by; the federation: those writing the current version), and building_on names the earliest head holding one, in place of the last of the others.
Diffstat (limited to 'src/federation/store/memory.rs')
-rw-r--r--src/federation/store/memory.rs19
1 files changed, 18 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
}