diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/api/events.rs | 33 | ||||
| -rw-r--r-- | src/federation/store/memory.rs | 54 |
2 files changed, 70 insertions, 17 deletions
diff --git a/src/api/events.rs b/src/api/events.rs index 5182c23..06a6e31 100644 --- a/src/api/events.rs +++ b/src/api/events.rs @@ -157,11 +157,12 @@ async fn event(State(state): State<AppState>, Path(id): Path<String>) -> Respons /// `GET /events/counts`: what counts, as the store reads now: the current version, each /// party's keys and nodes, what each of those nodes says it speaks and knows (`knows`), /// the values at places, the members, and the proposals on the -/// current version, each with the events proposing it a vote may build on (`proposing`: +/// current version, each with the events proposing it a vote may build on (`proposals`: /// for a checkpoint, those above its heads), the votes on it, the parties -/// voting `true` and `false`, whether it passed and whether it is dead, and why a party's +/// voting `true` and `false`, whether it passed and whether it is dead, why a party's /// client backs it not, where it is no version that can be written on the current one -/// (`client::backable`). +/// (`client::backable`), and, for a checkpoint, what its parties signed that moving there +/// refuses (`beside`, `signed_beside`). async fn counts(State(state): State<AppState>) -> Response { with_store(&state, |store| { let read = store.state(); @@ -196,6 +197,11 @@ async fn counts(State(state): State<AppState>) -> Response { .map(|(hash, ballot)| { let tally = read.tally(current, &hash); let proposing = read.proposing(¤t.hash, &hash); + let beside = read + .proposal(&hash) + .and_then(|json| crate::federation::version::Version::read(json).ok()) + .and_then(|version| version.checkpoint) + .map(|heads| ids(signed_beside(store, &heads))); let none = read .proposal(&hash) .and_then(|proposed| client::backable(current, proposed).err()) @@ -216,6 +222,7 @@ async fn counts(State(state): State<AppState>) -> Response { "passed": tally.passed, "dead": tally.dead, "none": none, + "beside": beside, }), ) }) @@ -239,6 +246,26 @@ async fn counts(State(state): State<AppState>) -> Response { }) } +/// Of what `store` took, what its parties signed that a move to a checkpoint at `heads` +/// refuses (`Store::beside`), and they sign again: their writes, key sets and node lists. +/// Proposals and votes lapse with the move, and merge events count for nothing. +fn signed_beside(store: &Store<Federation>, heads: &[Id]) -> Vec<Id> { + use crate::federation::event::{Does, Event, Signed}; + store + .beside(heads) + .into_iter() + .filter(|id| { + matches!( + store.get(id).and_then(Event::read_taken), + Some(Event::Signed(Signed { + does: Does::Write { .. } | Does::Keys(_) | Does::Nodes(_), + .. + })) + ) + }) + .collect() +} + /// What kind of refusal it is, as a client tells them apart, and the event it builds on, /// for one built on a refused one. fn kind(refusal: &Refusal) -> (&'static str, Option<&Id>) { diff --git a/src/federation/store/memory.rs b/src/federation/store/memory.rs index 05479e3..b4be6f0 100644 --- a/src/federation/store/memory.rs +++ b/src/federation/store/memory.rs @@ -359,6 +359,41 @@ impl<F: Fold> Store<F> { .collect() } + /// Of the events taken after the checkpoint, those a move to a checkpoint at `heads` + /// refuses: neither among them, nor in their history, nor above them (`moved`), where + /// they are heads a version may name. + pub(crate) fn beside(&self, heads: &[Id]) -> Vec<Id> { + let set: BTreeSet<Id> = heads.iter().copied().collect(); + let before = self.history(heads); + let above = self.above(&set, &before); + self.order + .iter() + .filter(|id| !before.contains(id) && !above.contains(id)) + .copied() + .collect() + } + + /// Of the events taken after the checkpoint, those above `heads`, `before` being their + /// history: each building on the heads, or on what is above them, alone, and on all + /// the heads or on one above them. + fn above(&self, heads: &BTreeSet<Id>, before: &HashSet<Id>) -> HashSet<Id> { + let mut above: HashSet<Id> = HashSet::new(); + for id in self.order.iter().filter(|id| !before.contains(id)) { + let dependencies = &self.events[id].dependencies; + let on = dependencies + .iter() + .all(|dependency| heads.contains(dependency) || above.contains(dependency)); + let holds = dependencies + .iter() + .any(|dependency| above.contains(dependency)) + || heads.iter().all(|head| dependencies.contains(head)); + if on && holds { + above.insert(*id); + } + } + above + } + /// The events taken after the checkpoint among `ids` and all they build on. fn history(&self, ids: &[Id]) -> HashSet<Id> { let mut history = HashSet::new(); @@ -422,20 +457,7 @@ impl<F: Fold> Store<F> { return false; }; let before = self.history(&ids); - let mut above: HashSet<Id> = HashSet::new(); - for id in self.order.iter().filter(|id| !before.contains(id)) { - let dependencies = &self.events[id].dependencies; - let on = dependencies - .iter() - .all(|dependency| heads.contains(dependency) || above.contains(dependency)); - let holds = dependencies - .iter() - .any(|dependency| above.contains(dependency)) - || heads.iter().all(|head| dependencies.contains(head)); - if on && holds { - above.insert(*id); - } - } + let above = self.above(&heads, &before); for id in &self.order { if before.contains(id) { if !kept.contains_key(id) && !heads.contains(id) { @@ -1184,6 +1206,10 @@ mod tests { store.left_out(&[head, beside], &[first, beside, above]), vec![above] ); + // What a move there refuses: what is beside them, and what builds on it too. + let both = taken(store.offer(testfold::put(&[above, beside], "d", "1"))); + assert_eq!(store.beside(&[head]), vec![beside, both]); + assert_eq!(store.beside(&[head, beside]), vec![above, both]); } /// A store whose root holds puts and a lock, cut at the lock: the cut's ID, the lock's, |
