From 377d3b2fa3c2e9f67abe14f2ef9d6f167caa2fa1 Mon Sep 17 00:00:00 2001 From: tv Date: Sat, 24 Oct 2026 19:29:00 +0200 Subject: being caught up needs some heads A sync message from a ready peer only completes the initial sync if that peer has at least one head. A peer with an empty document can no longer make a joiner ready on an empty store: a misconfigured second swarm, or a genesis node in its first seconds. Effect on a brand-new swarm: a joiner now waits until the genesis node has registered itself in the member list, which happens within about 5 s of it becoming ready. --- src/swarm/sync.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src/swarm/sync.rs') diff --git a/src/swarm/sync.rs b/src/swarm/sync.rs index 58a08db..17e25c4 100644 --- a/src/swarm/sync.rs +++ b/src/swarm/sync.rs @@ -378,8 +378,11 @@ pub(crate) async fn handle_sync( } Ok(Some(( - // Only from a ready peer: a peer still catching up has empty heads, which - // every document "contains". + // Only from a ready peer, and only if it has heads at all: empty heads are + // "contained" in every document, so they prove nothing. A peer still + // catching up has them, and so does a ready peer whose document is empty + // (a misconfigured second swarm, or a genesis node in its first seconds, + // before it registered itself). check_caught_up && from_ready && peer_state @@ -388,9 +391,10 @@ pub(crate) async fn handle_sync( .their_heads .as_ref() .is_some_and(|heads| { - heads - .iter() - .all(|h| replica.doc.get_change_by_hash(h).is_some()) + !heads.is_empty() + && heads + .iter() + .all(|h| replica.doc.get_change_by_hash(h).is_some()) }), changed, ))) -- cgit v1.3.1