From 866c6a402e65f9102e63cebdf5a50c0a3f526260 Mon Sep 17 00:00:00 2001 From: tv Date: Thu, 19 Nov 2026 16:13:53 +0000 Subject: wire: a peer on another version is named older or newer, with what to upgrade A node meeting messages of a wire version it doesn't speak logged `Peer speaks another wire version (another build)`, with the versions as fields only. It says now, in the message, which build is the newer and which node to upgrade: this one, where the peer's is newer (`upgrade this node to talk with it`), else the peer's (`upgrade that node`), with the peer's version and the ones this build speaks. Its fields are the peer's version and the oldest and newest this build speaks. --- src/transport/wire.rs | 47 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 5 deletions(-) (limited to 'src/transport') diff --git a/src/transport/wire.rs b/src/transport/wire.rs index abaa408..0b661dd 100644 --- a/src/transport/wire.rs +++ b/src/transport/wire.rs @@ -135,9 +135,9 @@ pub(crate) fn encode(message: &ParsedMessage) -> Result, WireError> { const MAX_OTHER_VERSIONS: usize = 1024; /// Senders whose messages are of another wire version (`WireError::Version`): each -/// logged once, at warn level, so two builds that don't speak to each other say so, -/// instead of silently retrying their HELLOs for good. Bounded: anyone can send us -/// anything. +/// logged once, at warn level, so two builds that don't speak to each other say so, and +/// which of them to upgrade, instead of silently retrying their HELLOs for good. Bounded: +/// anyone can send us anything. #[derive(Default)] pub(crate) struct OtherVersions(std::sync::Mutex>); @@ -155,13 +155,36 @@ impl OtherVersions { tracing::warn!( from = %super::Addressed(scheme, &sender), version, - ours = VERSION, - "Peer speaks another wire version (another build); ignoring its messages" + oldest = OLDEST, + newest = VERSION, + "Peer speaks another wire version: {}; ignoring its messages", + other_build(version) ); } } } +/// Of a peer whose messages are of wire `version`, which this build doesn't speak, what +/// an operator does: upgrade this node where the peer's build is newer, the peer's where +/// it is older. +fn other_build(version: u8) -> String { + let ours = if OLDEST == VERSION { + VERSION.to_string() + } else { + format!("{OLDEST} to {VERSION}") + }; + if version > VERSION { + format!( + "a newer build (wire version {version}; this one speaks {ours}): upgrade this node \ + to talk with it" + ) + } else { + format!( + "an older build (wire version {version}; this one speaks {ours}): upgrade that node" + ) + } +} + pub(crate) fn decode(payload: &[u8]) -> Result { let (&version, payload) = payload.split_first().ok_or(WireError::Empty)?; if version == SPEAKS { @@ -616,6 +639,20 @@ mod tests { assert!(other.0.lock().unwrap().len() <= MAX_OTHER_VERSIONS); } + /// The warning says which build is the older, the one to upgrade, and both versions. + #[test] + fn the_older_build_is_named() { + let newer = other_build(VERSION + 1); + assert!(newer.contains("upgrade this node"), "{newer}"); + assert!( + newer.contains(&format!("wire version {}", VERSION + 1)), + "{newer}" + ); + assert!(newer.contains(&format!("speaks {VERSION}")), "{newer}"); + let older = other_build(OLDEST - 1); + assert!(older.contains("upgrade that node"), "{older}"); + } + /// Every kind decodes to what was encoded: re-encoded, the same bytes. #[test] fn every_kind_round_trips() { -- cgit v1.3.1