From 08ec65219991c7413c8cdef4ce77434f2a121331 Mon Sep 17 00:00:00 2001 From: tv Date: Mon, 30 Nov 2026 17:57:55 +0000 Subject: A node of both kinds, for a swarm to move to sets by (--store-both) With store-document, store-both has the node hold its store in the Automerge document too, and sync with nodes of either kind: * it says to each peer the kind that peer holds, and passes its set on to those that hold sets (swarm::set::holds_a_set), the Automerge document to the others; * what its set takes of the document goes on to the peers on sets (Holding::unpassed), and what its set takes of them is put into the document, as events it lacks are (Holding::lacking); * its entry in the document is put as its entry in the set (swarm::set::mirror_entry), and it reads the members of both; * without the set's file yet, its set is made of the store as it reads it of its document, with what store-file kept of its own. A simulation: two nodes on the Automerge document, one on a set, one of both between them; an event put on either side reaches all four. --- src/config/mod.rs | 21 +++++++++++- src/federation/held.rs | 78 +++++++++++++++++++++++++++++++++++++-------- src/lib.rs | 22 ++++++------- src/simtest/holding.rs | 74 ++++++++++++++++++++++++++++++++++++++++++ src/swarm/bootstrap.rs | 35 ++++++++++++++------ src/swarm/peer/inbound.rs | 11 ++++--- src/swarm/peer/keepalive.rs | 18 ++++++++--- src/swarm/set.rs | 69 +++++++++++++++++++++++++++++++++++---- src/swarm/sync.rs | 6 ++-- 9 files changed, 280 insertions(+), 54 deletions(-) diff --git a/src/config/mod.rs b/src/config/mod.rs index 5a723c7..7b17f5d 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -223,6 +223,14 @@ pub(crate) const OPTIONS: &[OptionSpec] = &[ "With store-root or store-id: hold the store in a document of its own kind, a set of events (docs/document.md), kept in this file, instead of in the Automerge document a swarm syncs otherwise. The node then syncs with nodes holding such a set, and with no others: a swarm is of one kind. The file holds the store's events, what the node refused of its own and what its operator had it drop, and its members' entries; started again, the node goes on from it. Without the file yet, the node begins it from the root where it is given one (store-root) and pins no checkpoint; else it joins with nothing, and gathers of the members it reaches what its set begins from, by name: the root, or the checkpoint store-checkpoint names. Can't be combined with store-file, which the file stands for.", ), #[cfg(feature = "federation")] + option( + "store-both", + Kind::Flag, + "BOOL", + Some("false"), + "With store-document: hold the store in the Automerge document too, and sync with nodes of either kind, taking into each what the other holds: an event that comes by one goes on by the other, and the node's entry is in both. For moving a running swarm to sets of events node by node (docs/document.md, From an Automerge document to this): a node is started with it, on the document it has, and without it once no node it reaches holds the Automerge document alone. Without the set's file yet, the set begins from the store as the node reads it of its document.", + ), + #[cfg(feature = "federation")] option( "store-keeps-forgotten", Kind::Duration, @@ -827,6 +835,9 @@ pub(crate) struct Settings { #[cfg(feature = "federation")] pub(crate) store_document: Option, #[cfg(feature = "federation")] + #[serde(default)] + pub(crate) store_both: bool, + #[cfg(feature = "federation")] #[serde( default = "default_store_keeps_forgotten", with = "crate::units::duration_option" @@ -1361,6 +1372,7 @@ impl Settings { ("store-file", self.store_file.is_some()), ("store-checkpoint", self.store_checkpoint.is_some()), ("store-document", self.store_document.is_some()), + ("store-both", self.store_both), ("store-party", self.store_party.is_some()), ("store-readers", !self.store_readers.is_empty()), ( @@ -1384,9 +1396,14 @@ impl Settings { return Ok(()); } }; - if self.store_document.is_some() && self.store_file.is_some() { + if self.store_document.is_some() && self.store_file.is_some() && !self.store_both { bail!("store-document holds what store-file would: unset store-file"); } + if self.store_both && self.store_document.is_none() { + bail!( + "store-both: set store-document, the file of the set of events the node holds beside its Automerge document" + ); + } match &self.store_party { None => bail!( "{store}: set store-party, the party this node is of: in a swarm holding a store, nodes sync with the nodes its parties list, each as its party's" @@ -1516,6 +1533,8 @@ impl Settings { #[cfg(feature = "federation")] ("store-document", self.store_document.is_some()), #[cfg(feature = "federation")] + ("store-both", self.store_both), + #[cfg(feature = "federation")] ("store-party", self.store_party.is_some()), #[cfg(feature = "federation")] ("store-readers", !self.store_readers.is_empty()), diff --git a/src/federation/held.rs b/src/federation/held.rs index 154544f..c5527cb 100644 --- a/src/federation/held.rs +++ b/src/federation/held.rs @@ -120,6 +120,9 @@ pub(crate) struct Holding { /// Whether the node holds the store in the document a swarm syncs otherwise too /// (`of_both`): a node of both kinds, by which a running swarm moves to sets. both: bool, + /// For how long a set made of the store read from the document keeps what a + /// checkpoint forgot (`of_both`). + keeps_forgotten: Duration, // A std mutex: never held while waiting for the document. inner: Mutex, } @@ -188,6 +191,9 @@ struct Inner { /// A set of events to be, where the node started with nothing of its store and /// gathers what its set begins from of its peers (`store::passing::Start`). starting: Option>, + /// What the set took of the document, to be passed on to the peers that hold sets + /// (`unpassed`): a node of both kinds takes into each what the other holds. + unpassed: Vec, /// The document read from (`Replica::epoch_seq`), and its events read. epoch_seq: Option, read: HashSet, @@ -282,6 +288,7 @@ impl Holding { voter: None, of_a_set: false, both: false, + keeps_forgotten: Duration::ZERO, document: None, written: Mutex::default(), inner: Mutex::new(Inner { @@ -387,9 +394,13 @@ impl Holding { match started { Ok(store) => { info!(store = %id, refused = own.len(), dropped = dropped.len(), "Reading the store from the document"); - inner.store = Some(Carried::Store(Box::new( - store.refusing(&own, &dropped, &writes), - ))); + let store = store.refusing(&own, &dropped, &writes); + // A node of both kinds: the store in a set too, from here on. + inner.store = Some(if self.of_a_set { + Carried::Set(Box::new(Set::new(store, self.keeps_forgotten))) + } else { + Carried::Store(Box::new(store)) + }); } Err(why) => { if inner.none.replace(id) != Some(id) { @@ -404,7 +415,13 @@ impl Holding { for (id, bytes) in unread.events { inner.read.insert(id); match store.offer(bytes) { - Offered::Taken(ids) => taken += ids.len(), + Offered::Taken(ids) => { + taken += ids.len(); + // To pass on, where a set carries the store too (`unpassed`). + if self.of_a_set { + inner.unpassed.extend(ids); + } + } Offered::Refused(why) => { refused += 1; info!(event = %id, why = ?why, "The store refuses an event the document holds"); @@ -558,8 +575,8 @@ impl Holding { /// what its store's checkpoint keeps, then what it took after it, then what it holds /// back, stopped (`Store::held_back`). pub(crate) fn lacking(&self, doc: &impl ReadDoc) -> Vec<(Id, Vec)> { - // A set of events is the store's own document: it lacks none of it. - if self.of_a_set { + // A set of events alone is the store's own document: it lacks none of it. + if self.of_a_set && !self.both { return Vec::new(); } let mut held: HashSet = events::ids(doc).into_iter().collect(); @@ -1062,6 +1079,11 @@ impl Holding { self } + /// What the set took of the document since last asked, in the order taken. + pub(crate) fn unpassed(&self) -> Vec { + std::mem::take(&mut self.inner.lock_or_recover().unpassed) + } + /// The names a node that started with nothing asks a peer for, to begin its set /// from; none, once it holds one. pub(crate) fn start_wants(&self) -> Vec { @@ -1098,7 +1120,7 @@ impl Holding { } /// Itself, its store carried by the set `begun`, held or to be, and kept in the - /// file at `path`; itself, where the node is given no set. + /// file at `path`; itself, where the node is given no set and holds none. pub(crate) fn carrying_if( self, begun: Option, @@ -1108,11 +1130,13 @@ impl Holding { let holding = match begun { Some(Begun::Set(set)) => self.carrying(*set), Some(Begun::Start(start)) => self.awaiting(start), - None => return self, + None => self, }; match path { - Some(path) => holding.kept_in(path, files), - None => holding, + // A set held, to be gathered, or to be made of the store read from the + // document (`of_both`). + Some(path) if holding.of_a_set => holding.kept_in(path, files), + _ => holding, } } @@ -1162,9 +1186,18 @@ impl Holding { self.of_a_set } - /// Itself, holding its store in the Automerge document too, beside the set. - pub(crate) fn of_both(mut self) -> Self { + /// [`of_both`](Self::of_both), where `both`. + pub(crate) fn of_both_if(self, both: bool, keeps: Duration) -> Self { + if both { self.of_both(keeps) } else { self } + } + + /// Itself, holding its store in the Automerge document and in a set of events: the + /// set it is given (`carrying`), or, given none, one made of the store as it is + /// first read from the document, keeping what a checkpoint forgot for `keeps`. + pub(crate) fn of_both(mut self, keeps: Duration) -> Self { self.both = true; + self.of_a_set = true; + self.keeps_forgotten = keeps; self } @@ -1369,6 +1402,16 @@ pub(crate) async fn run_worker(state: crate::state::AppState) { error!(error = %error, "Reading the store from the document failed"); (false, false, false, Vec::new(), Vec::new()) }); + // What the set took of the document goes on to the peers that hold sets, and + // the node's entry in the document is its entry in the set: a node of both + // kinds takes into each what the other holds. + if state.holding.has_a_set() && !state.of_a_set() { + let unpassed = state.holding.unpassed(); + if !unpassed.is_empty() { + crate::swarm::set::wrote(&state, unpassed).await; + } + crate::swarm::set::mirror_entry(&state).await; + } for bytes in signed { if let Err(error) = write(&state, None, bytes).await { warn!(error = %error, "Couldn't put what it signed for its party: put again later"); @@ -1455,7 +1498,7 @@ pub(crate) async fn run_worker(state: crate::state::AppState) { _ = looks.tick() => { look = true; // A set of events to its file, where it changed (`Holding::save`). - if state.of_a_set() { + if state.holding.has_a_set() { let holding = Arc::clone(&state.holding); if let Ok(Err(error)) = tokio::task::spawn_blocking(move || holding.save()).await @@ -1525,7 +1568,14 @@ pub(crate) async fn write( }, ) .await - .map(|_| ()) + .map(|_| ())?; + // A node of both kinds: on to the peers that hold sets, too (`swarm::set`). + if state.holding.has_a_set() + && state.holding.with(|store| store.get(&id).is_some()) == Some(true) + { + crate::swarm::set::wrote(state, vec![id]).await; + } + Ok(()) } async fn put_again(state: &crate::state::AppState) { diff --git a/src/lib.rs b/src/lib.rs index d4989ab..b57f6a5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -225,21 +225,20 @@ pub async fn run() -> Result<()> { // or from the root. #[cfg(feature = "federation")] let set = match (&store, &args.store_document) { - (Some(store), Some(path)) => Some( - store.set( - path, - &files, - args.store_checkpoint - .as_deref() - .and_then(federation::store::Id::from_hex), - args.store_keeps_forgotten, - )?, - ), + (Some(store), Some(path)) => store.set( + path, + &files, + args.store_checkpoint + .as_deref() + .and_then(federation::store::Id::from_hex), + args.store_keeps_forgotten, + args.store_both, + )?, _ => None, }; #[cfg(feature = "federation")] let starting = match &store { - Some(store) if set.is_none() => { + Some(store) if set.is_none() || args.store_both => { store.starting(starting, remembered.as_ref().map(|r| r.swarm_id.as_str()))? } // A set is the store's document: the one a swarm syncs otherwise stays empty. @@ -400,6 +399,7 @@ pub async fn run() -> Result<()> { )? .near(args.store_neighbour_parties.clone()) .voting(voter(args)?) + .of_both_if(args.store_both, args.store_keeps_forgotten) .carrying_if(set, args.store_document.clone(), Arc::clone(&files)), strict_keys: args .strict_keys diff --git a/src/simtest/holding.rs b/src/simtest/holding.rs index 0841a75..120c6da 100644 --- a/src/simtest/holding.rs +++ b/src/simtest/holding.rs @@ -2123,3 +2123,77 @@ async fn a_node_of_a_set_away_across_a_move_builds_the_checkpoint_itself() { .await; assert_eq!(counts(d), counts(&a)); } + +/// A swarm on its way from Automerge documents to sets of events: a and b hold the +/// store in the Automerge document, e in a set, and m in both. a and e take none of +/// each other's handshakes; m takes both, saying to each the kind it holds. An event +/// put on a reaches e through m, and one put on e reaches a and b: m takes into each +/// what the other holds. +#[tokio::test(flavor = "multi_thread", worker_threads = 4)] +async fn a_node_of_both_kinds_carries_events_between_them() { + let sim = Sim::with_identity(97); + let (tv, lass, makefu) = three(); + let (_, root, id) = federation(&[(&tv, &["a", "b"]), (&lass, &["m"]), (&makefu, &["e"])]); + let start = |name: &'static str, seeds: &'static [&'static str], holding: Holding| { + let root = root.clone(); + sim.start_with( + name, + seeds, + Start::FromDocument(Origin::Root), + move |config| { + of_the_store(config, id, Some(&root), holding); + }, + ) + }; + let a = start("a", &[], holding("tv")); + let b = start("b", &["a"], holding("tv")); + let m = start( + "m", + &["a"], + holding("lass").of_both(Duration::from_secs(600)), + ); + assert_eq!(m.kinds().len(), 2); + let e = { + let seeds = ["m"]; + let root = root.clone(); + sim.start_with( + "e", + &seeds, + Start::FromDocument(Origin::Root), + move |config| { + config.store = Some(id); + config.holding = holding("makefu").carrying_if( + Some(held::Begun::Set(Box::new(a_set(&root)))), + None, + Arc::new(Files::default()), + ); + }, + ) + }; + let all = &[&a, &b, &m, &e]; + sim.wait_ready(all, SOON).await; + sim.wait_until( + "m holds a set, and its entry and e's in it", + LONG, + move || async move { entries(all[2]) == 2 && entries(all[3]) == 2 }, + ) + .await; + + let on_a = tv.write(&[id], "home/tv/x", s("1")); + let on_e = makefu.write(&[id], "home/makefu/y", s("2")); + let ids = [Id::of(&on_a), Id::of(&on_e)]; + put(&a, &[&on_a]).await; + put(&e, &[&on_e]).await; + let ids = &ids; + sim.wait_until("all four hold both events", LONG, move || async move { + all.iter().all(|node| holds(node, ids)) + }) + .await; + for node in all.iter() { + assert_eq!(read(node, |store| store.state().values().len()), Some(2)); + } + // e's event is in the Automerge document, which m put it in; a's isn't in e's, which + // holds nothing. + assert!(events::ids(&a.doc.read().await.doc).contains(&ids[1])); + assert!(e.doc.read().await.heads().is_empty()); +} diff --git a/src/swarm/bootstrap.rs b/src/swarm/bootstrap.rs index b21b579..45c86e6 100644 --- a/src/swarm/bootstrap.rs +++ b/src/swarm/bootstrap.rs @@ -344,14 +344,16 @@ impl StoreStart { /// at `path`: as the file has it, where there is one, which must be this store's; /// else begun from the root, where the node is given it and pins no checkpoint; else /// to be gathered of its peers, from the checkpoint `pin` names, or the root, by its - /// name. What a checkpoint forgot is kept for `keeps`. + /// name; of `both` kinds, none without a file. What a checkpoint forgot is kept for + /// `keeps`. pub(crate) fn set( &self, path: &Path, files: &Files, pin: Option, keeps: std::time::Duration, - ) -> Result { + both: bool, + ) -> Result> { use crate::federation::fold::Federation; use crate::federation::held::Begun; use crate::federation::store::{memory::Store, passing::Start, set::Set}; @@ -376,7 +378,12 @@ impl StoreStart { ); } info!(swarm_id = %self.id, path = %path.display(), "Going on with the store's document"); - return Ok(Begun::Set(Box::new(set))); + return Ok(Some(Begun::Set(Box::new(set)))); + } + // A node of both kinds makes its set of the store as it reads it of its + // document (`Holding::of_both`). + if both { + return Ok(None); } match (&self.root, pin) { (Some((root, kept)), None) => { @@ -385,12 +392,12 @@ impl StoreStart { anyhow::anyhow!("The store's root is none: {}", refused.0) })?; info!(swarm_id = %self.id, "Starting the swarm holding the store from its root, as a set of events (--store-document)"); - Ok(Begun::Set(Box::new(Set::new(store, keeps)))) + Ok(Some(Begun::Set(Box::new(Set::new(store, keeps))))) } (_, pin) => { let at = pin.unwrap_or(self.id); info!(swarm_id = %self.id, from = %at, "Joining the swarm holding the store with nothing of it: its set begins from what members give by that name"); - Ok(Begun::Start(Start::new(self.id, at, keeps))) + Ok(Some(Begun::Start(Start::new(self.id, at, keeps)))) } } } @@ -753,9 +760,9 @@ mod tests { let files = Files::default(); let keeps = Duration::from_secs(60); use crate::federation::held::Begun; - let set_of = |start: &StoreStart, pin| match start.set(&path, &files, pin, keeps) { - Ok(Begun::Set(set)) => Some(*set), - Ok(Begun::Start(_)) => None, + let set_of = |start: &StoreStart, pin| match start.set(&path, &files, pin, keeps, false) { + Ok(Some(Begun::Set(set))) => Some(*set), + Ok(Some(Begun::Start(_)) | None) => None, Err(error) => panic!("{error:#}"), }; // No file: from the root, where given and no checkpoint is pinned; else to be @@ -780,9 +787,17 @@ mod tests { id: Id::of(&other_root), root: Some((other_root, Vec::new())), }; - assert!(other.set(&path, &files, None, keeps).is_err()); + assert!(other.set(&path, &files, None, keeps, false).is_err()); std::fs::write(&path, b"something else").unwrap(); - assert!(store.set(&path, &files, None, keeps).is_err()); + assert!(store.set(&path, &files, None, keeps, false).is_err()); + // A node of both kinds: the file, where there is one; else none here. + std::fs::remove_file(&path).unwrap(); + assert!( + store + .set(&path, &files, None, keeps, true) + .unwrap() + .is_none() + ); } /// A fork's root, and the event it keeps on a line of its own: the swarm starts from diff --git a/src/swarm/peer/inbound.rs b/src/swarm/peer/inbound.rs index 35d67c8..b6c486d 100644 --- a/src/swarm/peer/inbound.rs +++ b/src/swarm/peer/inbound.rs @@ -228,11 +228,14 @@ pub(crate) async fn handle_message( .map_err(|error| anyhow!("Failed to notify sync worker: {error}"))?; } transport::ParsedMessage::Sync(envelope) => { - // Of a set of events, where one carries this node's store: its own to - // take (`swarm::set`), and nothing of an Automerge document's. + // Of a set of events: this node's set's to take, where it holds one + // (`swarm::set`); and of an Automerge document nothing, where it holds a set + // alone. #[cfg(feature = "federation")] - if state.of_a_set() { - if let transport::SyncBody::Kind(body) = envelope.body { + if state.of_a_set() || matches!(envelope.body, transport::SyncBody::Kind(_)) { + if let transport::SyncBody::Kind(body) = envelope.body + && state.holding.has_a_set() + { crate::swarm::set::received(state, &peer, body).await; } return Ok(()); diff --git a/src/swarm/peer/keepalive.rs b/src/swarm/peer/keepalive.rs index 6ab49d8..bbcc6e3 100644 --- a/src/swarm/peer/keepalive.rs +++ b/src/swarm/peer/keepalive.rs @@ -182,13 +182,21 @@ pub(crate) async fn local_status(state: &AppState, peer: &str) -> transport::Sta let stamp = state.stamp.borrow(); (stamp.summary(), stamp.epoch, stamp.epoch_seq) }; - let syncs_with_you = match state.get_peer_state(peer).await { - Some(peer_state) => peer_state.lock().await.syncs_on(epoch), - None => false, + let (syncs_with_you, _of_a_set) = match state.get_peer_state(peer).await { + Some(peer_state) => { + let peer_state = peer_state.lock().await; + ( + peer_state.syncs_on(epoch), + peer_state + .kind + .is_some_and(|kind| kind != crate::document::KIND), + ) + } + None => (false, false), }; - // Where a set of events carries the store, where that stands (`swarm::set`). + // To a peer that holds a set of events, where this node's stands (`swarm::set`). #[cfg(feature = "federation")] - let heads = crate::swarm::set::stamp(state).unwrap_or(heads); + let heads = crate::swarm::set::stamp(state, _of_a_set).unwrap_or(heads); let (reaches, round_trips) = crate::swarm::reach::published_with_round_trips(state); transport::Status { heads, diff --git a/src/swarm/set.rs b/src/swarm/set.rs index 6df78ba..54a48fe 100644 --- a/src/swarm/set.rs +++ b/src/swarm/set.rs @@ -22,10 +22,22 @@ use crate::state::AppState; use crate::swarm::topology; use crate::transport::{self, HeadsSummary, ParsedMessage, SyncBody}; -/// Where this node's set stands, as its STATUSes say it; none, where no set carries its -/// store. -pub(crate) fn stamp(state: &AppState) -> Option { - if !state.holding.of_a_set() { +/// Whether `peer` holds a set of events, as its handshakes said: what a node of both +/// kinds passes its set on to. A node that holds a set alone takes handshakes of no +/// other. +pub(crate) async fn holds_a_set(state: &AppState, peer: &str) -> bool { + match state.get_peer_state(peer).await { + Some(peer_state) => { + peer_state.lock().await.kind == Some(crate::federation::store::set::KIND) + } + None => false, + } +} + +/// Where this node's set stands, as its STATUSes say it to a peer that holds one +/// (`to_a_set`); none, where the node holds no set, or the peer doesn't. +pub(crate) fn stamp(state: &AppState, to_a_set: bool) -> Option { + if !state.holding.has_a_set() || !(to_a_set || state.holding.of_a_set()) { return None; } // A node still gathering what its set begins from stands nowhere yet. @@ -45,9 +57,14 @@ pub(crate) fn heard_status( peer: &str, mut remote: transport::Status, ) -> transport::Status { - let Some(ours) = stamp(state) else { + // A peer that says where a set stands holds one. + let of_a_set = matches!(remote.heads, HeadsSummary::Kind(_)); + let Some(ours) = stamp(state, of_a_set) else { return remote; }; + if !of_a_set && !state.holding.of_a_set() { + return remote; + } if let HeadsSummary::Kind(bytes) = std::mem::replace(&mut remote.heads, ours) && let Ok(stamp) = rmp_serde::from_slice::(&bytes) { @@ -174,7 +191,10 @@ async fn pass_on(state: &AppState, from: Option<&str>, took: Took) { } let message = Message::Units(units); for peer in state.active_peers_on_local_epoch().await { - if Some(peer.as_str()) != from && topology::is_neighbour(state, &peer) { + if Some(peer.as_str()) != from + && topology::is_neighbour(state, &peer) + && holds_a_set(state, &peer).await + { send(state, &peer, &message).await; } } @@ -219,3 +239,40 @@ pub(crate) async fn registered(state: &AppState) { ) .await; } + +/// On a node of both kinds, puts its entry as the document it holds has it as its entry +/// in the set, where the two differ, and passes it on: what the node says of itself, +/// it says to the peers of either kind. +pub(crate) async fn mirror_entry(state: &AppState) { + use crate::federation::store::entry::Entry; + use crate::federation::store::set::Put; + + if !state.holding.has_a_set() || state.holding.of_a_set() { + return; + } + let Some(key) = state.node_key.clone() else { + return; + }; + let node = state.local_id().to_owned(); + let own = crate::swarm::members::member_path(&node); + let written = crate::document::view::read_path(&state.doc.read().await.doc, &own); + let Ok(Some(serde_json::Value::Object(written))) = written else { + return; + }; + let put = state.holding.change_set(|set| { + let held = set.entry(&node); + if held.and_then(|entry| entry.value()).as_ref() == Some(&written) { + return None; + } + let count = held.map_or(1, |entry| entry.count() + 1); + Some(set.put_entry(Entry::new( + &set.store().id(), + &key, + count, + &serde_json::Value::Object(written), + ))) + }); + if put.flatten() == Some(Put::Taken) { + registered(state).await; + } +} diff --git a/src/swarm/sync.rs b/src/swarm/sync.rs index 5e736a1..3939377 100644 --- a/src/swarm/sync.rs +++ b/src/swarm/sync.rs @@ -63,10 +63,10 @@ async fn deliver_sync_to_peer(state: &AppState, peer: &str) -> Result<()> { } } - // A set of events is passed on otherwise (`swarm::set`): of the Automerge document - // a node holds beside one, nothing. + // A set of events is passed on otherwise (`swarm::set`): with a peer that holds + // one, and of the Automerge document a node holds beside one alone, no sync. #[cfg(feature = "federation")] - if state.of_a_set() { + if state.of_a_set() || crate::swarm::set::holds_a_set(state, peer).await { return Ok(()); } -- cgit v1.3.1