aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/swarm/roots.rs20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/swarm/roots.rs b/src/swarm/roots.rs
index 9b17218..d12f089 100644
--- a/src/swarm/roots.rs
+++ b/src/swarm/roots.rs
@@ -5,8 +5,9 @@
//! sent it first. So every node names its epoch's root in its handshakes
//! (`HelloRequest::root`, `HelloReply::root`), and:
//!
-//! * a node whose document holds another root of the same epoch refuses the handshake:
-//! another history under this swarm's ID (a forged root, or a genesis started again);
+//! * a node whose document holds another root of the same epoch, or that was given
+//! another (`--genesis-root`), refuses the handshake: another history under this
+//! swarm's ID (a forged root, or a genesis started again);
//! * a joining node takes as its root only the one given (`--genesis-root`), or else the
//! one its peers name, and none while they name different ones (`RootPin`); and none
//! before each of its seeds named one, or `ROOT_WAIT` passed since the first did, so
@@ -119,6 +120,21 @@ pub(crate) async fn heard(
bail!("{peer} starts epoch {epoch} from root {root}, ours from {ours}");
}
if epoch.generation == 0 {
+ // The root given: a peer naming another is another history, whatever this
+ // node's document holds yet.
+ if let Some(given) = state.genesis_root
+ && given != root
+ {
+ if state
+ .roots
+ .lock_or_recover()
+ .differing
+ .insert(peer.to_owned())
+ {
+ error!(peer = %peer, given = %given, theirs = %root, "A peer's document starts from another root than the one given (--genesis-root): another history under this swarm's ID; not synced with");
+ }
+ bail!("{peer} starts the first epoch from root {root}, not the one given ({given})");
+ }
state
.roots
.lock_or_recover()