aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-21 22:21:56 +0000
committertv <tv@krebsco.de>2026-11-21 22:21:56 +0000
commit37a521169f703f5f412ea6dd52684b03289c350d (patch)
tree14927bbf2f63b21d5ee9490be597c3430d05bc33
parentd8880260d8d5002367e86c3aab9fa504e6cec40b (diff)
roots: a seed joining itself names the root once it has it
A joiner takes no root before each of its seeds named one, and a seed names its root only in a handshake. A seed that shook hands while joining itself named none, and never again: its joiner waited for ever. scripts/wire-check hit that (b joining a, c through b, d through c): b's reply to c came 2 ms before b had its document. Now a node notes the peers its handshakes named no root to, and once ready, shakes hands with them again, naming it. Older joiners take it too: it's a handshake as before.
-rw-r--r--CHANGELOG.md4
-rw-r--r--docs/access.md3
-rw-r--r--src/swarm/bootstrap.rs11
-rw-r--r--src/swarm/peer/handshake.rs4
-rw-r--r--src/swarm/roots.rs27
5 files changed, 45 insertions, 4 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ed31404..abdb16f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,10 @@ it from the release before ([`docs/operations.md`](docs/operations.md),
## Unreleased
+* A node joining through a seed that is joining itself no longer waits for ever: a seed
+ names the swarm's root once it has it, shaking hands again with each peer it named
+ none to ([`docs/access.md`](docs/access.md); [`src/swarm/roots.rs`](src/swarm/roots.rs)).
+
* The feature `most` builds every transport, the dashboard and the federation at once,
as development does throughout ([`docs/development.md`](docs/development.md);
[`Cargo.toml`](Cargo.toml)).
diff --git a/docs/access.md b/docs/access.md
index 019565e..5153b16 100644
--- a/docs/access.md
+++ b/docs/access.md
@@ -395,7 +395,8 @@ a root (one of a member's own identities, say) disputes it, but neither ends the
nor starts it. So without `--genesis-root`, the root is the one the seeds that answer
within that wait agree on, none while any peer names another: one seed hands a joiner
another root only if it is all the joiner hears of its seeds by then; with
-`--genesis-root`, never.
+`--genesis-root`, never. A seed joining itself names no root until it has one: once
+ready, it shakes hands again with every peer it named none to.
What it doesn't do yet:
diff --git a/src/swarm/bootstrap.rs b/src/swarm/bootstrap.rs
index ed0c5cc..53b4af8 100644
--- a/src/swarm/bootstrap.rs
+++ b/src/swarm/bootstrap.rs
@@ -177,6 +177,17 @@ pub(crate) async fn bootstrap(state: &AppState, seeds: &[String], start: Start)
state.mark_ready(swarm_id.clone()).await?;
info!(swarm_id = %swarm_id, "Node is ready");
crate::swarm::peer::announce(state);
+ // Peers it named no root to while it had none, among them those joining
+ // through it, which wait for it to: a handshake again names it.
+ let unnamed = crate::swarm::roots::unnamed(state);
+ if !unnamed.is_empty() {
+ let state = state.clone();
+ tokio::spawn(async move {
+ for peer in unnamed {
+ crate::swarm::peer::rehandshake(&state, &peer).await;
+ }
+ });
+ }
return Ok(());
}
}
diff --git a/src/swarm/peer/handshake.rs b/src/swarm/peer/handshake.rs
index ef7d379..d3f6b99 100644
--- a/src/swarm/peer/handshake.rs
+++ b/src/swarm/peer/handshake.rs
@@ -140,7 +140,7 @@ async fn transmit_hello(state: &AppState, peer: &str) -> Result<()> {
ready: state.is_ready().await,
run_id: state.run_id,
handshake,
- root: crate::swarm::roots::own(state)
+ root: crate::swarm::roots::named_to(state, peer)
.await
.map(|root| root.0.to_vec()),
party: party(state),
@@ -250,7 +250,7 @@ pub(super) async fn send_hello_reply(
run_id,
away_ms: away.map(|away| away.as_millis() as u64),
sender_run_id: state.run_id,
- root: crate::swarm::roots::own(state)
+ root: crate::swarm::roots::named_to(state, peer)
.await
.map(|root| root.0.to_vec()),
party: party(state),
diff --git a/src/swarm/roots.rs b/src/swarm/roots.rs
index 2fb6d6e..c0aa4ea 100644
--- a/src/swarm/roots.rs
+++ b/src/swarm/roots.rs
@@ -14,7 +14,9 @@
//! the seed that answers first doesn't decide alone. Seeds are the nodes proven at
//! the seeds' addresses (`seed_found`): a peer answering under identities of its own
//! neither ends the wait nor starts its clock, only disputes. One seed hands a joiner
-//! another root only if it is all the joiner hears of its seeds within the wait.
+//! another root only if it is all the joiner hears of its seeds within the wait. A
+//! seed naming none, joining itself, names it once ready, in a handshake again with
+//! each peer it named none to (`named_to`, `unnamed`).
use std::collections::{HashMap, HashSet};
use std::time::Duration;
@@ -45,6 +47,8 @@ pub(crate) struct Roots {
awaiting: Option<(usize, Option<tokio::time::Instant>)>,
/// Its own, for the document (`Replica::epoch_seq`), once known.
own: Option<(u32, ChangeHash)>,
+ /// Peers our handshakes named no root to, while we had none (`named_to`).
+ unnamed: HashSet<String>,
/// Peers whose root differs, logged once each.
differing: HashSet<String>,
}
@@ -94,6 +98,27 @@ pub(crate) async fn own(state: &AppState) -> Option<ChangeHash> {
Some(root)
}
+/// This node's epoch's root, for a handshake with `peer` (`HelloRequest::root`,
+/// `HelloReply::root`). Where it has none yet, joining itself, `peer` is noted: a peer
+/// joining through it takes no root before its seeds named one, so once this node is
+/// ready it shakes hands with those again (`unnamed`), and names its root then.
+pub(crate) async fn named_to(state: &AppState, peer: &str) -> Option<ChangeHash> {
+ let root = own(state).await;
+ if root.is_none() {
+ state
+ .roots
+ .lock_or_recover()
+ .unnamed
+ .insert(peer.to_owned());
+ }
+ root
+}
+
+/// The peers this node's handshakes named no root to (`named_to`), forgotten here.
+pub(crate) fn unnamed(state: &AppState) -> Vec<String> {
+ state.roots.lock_or_recover().unnamed.drain().collect()
+}
+
/// `peer`, in a handshake of `epoch`, names `root` as its root. Refused (an error) if
/// this node's document holds another of the same epoch; of the first epoch, what an
/// empty document takes as its root follows (`pin`).