From 111c07f83ac626074ef6efc361e706a87556e248 Mon Sep 17 00:00:00 2001 From: tv Date: Sun, 29 Nov 2026 14:24:28 +0000 Subject: federation: what carries a node's store, a document or a set of events Holding's store is read from a document, as it was, or is a set of events' (held::Carried): what offers to it, drops from it and allows again goes through whichever carries it. Nothing makes one carried by a set yet. --- src/federation/held.rs | 50 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 47 insertions(+), 3 deletions(-) (limited to 'src/federation') diff --git a/src/federation/held.rs b/src/federation/held.rs index ec3738f..508b2eb 100644 --- a/src/federation/held.rs +++ b/src/federation/held.rs @@ -34,6 +34,7 @@ use super::event::{self, Does, Event, Signed}; use super::fold::Federation; use super::revision::Feature; use super::store::memory::{Built, Offered, Store}; +use super::store::set::Set; use super::store::{Fold, Id, Refused}; use super::version::Version; use super::vote::{self, Act, Rules, Seen}; @@ -123,10 +124,51 @@ pub(crate) struct Voter { pub(crate) rules: Rules, } +/// What carries the store: a document it is read from, or a set of events, which is +/// the store's own document (`store::set`). +enum Carried { + Store(Box>), + Set(Box>), +} + +impl std::ops::Deref for Carried { + type Target = Store; + + fn deref(&self) -> &Store { + match self { + Carried::Store(store) => store, + Carried::Set(set) => set.store(), + } + } +} + +impl Carried { + fn offer(&mut self, bytes: Vec) -> Offered { + match self { + Carried::Store(store) => store.offer(bytes), + Carried::Set(set) => set.offer(bytes, Instant::now()), + } + } + + fn drop_taken(&mut self, ids: &[Id]) -> Result, Refused> { + match self { + Carried::Store(store) => store.drop_taken(ids), + Carried::Set(set) => set.drop_taken(ids, Instant::now()), + } + } + + fn allow(&mut self, ids: &[Id]) { + match self { + Carried::Store(store) => store.allow(ids), + Carried::Set(set) => set.allow(ids, Instant::now()), + } + } +} + #[derive(Default)] struct Inner { /// None until a document holding a store holds its root. - store: Option>, + store: Option, /// The document read from (`Replica::epoch_seq`), and its events read. epoch_seq: Option, read: HashSet, @@ -322,7 +364,9 @@ impl Holding { match started { Ok(store) => { info!(store = %id, refused = own.len(), dropped = dropped.len(), "Reading the store from the document"); - inner.store = Some(store.refusing(&own, &dropped, &writes)); + inner.store = Some(Carried::Store(Box::new( + store.refusing(&own, &dropped, &writes), + ))); } Err(why) => { if inner.none.replace(id) != Some(id) { @@ -968,7 +1012,7 @@ impl Holding { /// `f` of the store, where the node holds one. pub(crate) fn with(&self, f: impl FnOnce(&Store) -> T) -> Option { - self.inner.lock_or_recover().store.as_ref().map(f) + self.inner.lock_or_recover().store.as_deref().map(f) } /// What a remake's snapshot holds of the store: as this node reads it anew from -- cgit v1.3.1