diff --git a/p2p/src/handshake.rs b/p2p/src/handshake.rs index 6c5ac4694a..7f018cd457 100644 --- a/p2p/src/handshake.rs +++ b/p2p/src/handshake.rs @@ -86,12 +86,7 @@ impl Handshake { // write and read the handshake response write_message(conn, hand, Type::Hand)?; let shake: Shake = read_message(conn, Type::Shake)?; - if shake.version != PROTOCOL_VERSION { - return Err(Error::ProtocolMismatch { - us: PROTOCOL_VERSION, - peer: shake.version, - }); - } else if shake.genesis != self.genesis { + if shake.genesis != self.genesis { return Err(Error::GenesisMismatch { us: self.genesis, peer: shake.genesis, @@ -132,12 +127,7 @@ impl Handshake { let hand: Hand = read_message(conn, Type::Hand)?; // all the reasons we could refuse this connection for - if hand.version != PROTOCOL_VERSION { - return Err(Error::ProtocolMismatch { - us: PROTOCOL_VERSION, - peer: hand.version, - }); - } else if hand.genesis != self.genesis { + if hand.genesis != self.genesis { return Err(Error::GenesisMismatch { us: self.genesis, peer: hand.genesis, diff --git a/p2p/src/msg.rs b/p2p/src/msg.rs index 16fb81c28d..30a7892af1 100644 --- a/p2p/src/msg.rs +++ b/p2p/src/msg.rs @@ -28,7 +28,14 @@ use crate::types::{ }; use crate::util::read_write::read_exact; -/// Current latest version of the protocol +/// Our local node protocol version. +/// We will increment the protocol version with every change to p2p msg serialization +/// so we will likely connect with peers with both higher and lower protocol versions. +/// We need to be aware that some msg formats will be potentially incompatible and handle +/// this for each individual peer connection. +/// Note: A peer may disconnect and reconnect with an updated protocol version. Normally +/// the protocol version will increase but we need to handle decreasing values also +/// as a peer may rollback to previous version of the code. pub const PROTOCOL_VERSION: u32 = 1; /// Grin's user agent with current version diff --git a/p2p/src/types.rs b/p2p/src/types.rs index 732039d0b6..952e4a027d 100644 --- a/p2p/src/types.rs +++ b/p2p/src/types.rs @@ -68,10 +68,6 @@ pub enum Error { Chain(chain::Error), PeerWithSelf, NoDandelionRelay, - ProtocolMismatch { - us: u32, - peer: u32, - }, GenesisMismatch { us: Hash, peer: Hash, diff --git a/servers/src/grin/server.rs b/servers/src/grin/server.rs index 7ed10aa2fd..598def0212 100644 --- a/servers/src/grin/server.rs +++ b/servers/src/grin/server.rs @@ -402,6 +402,11 @@ impl Server { self.chain.header_head().map_err(|e| e.into()) } + /// Current p2p layer protocol version. + pub fn protocol_version() -> u32 { + p2p::msg::PROTOCOL_VERSION + } + /// Returns a set of stats about this server. This and the ServerStats /// structure /// can be updated over time to include any information needed by tests or diff --git a/src/bin/tui/ui.rs b/src/bin/tui/ui.rs index c9984f3e6b..a33d069e66 100644 --- a/src/bin/tui/ui.rs +++ b/src/bin/tui/ui.rs @@ -88,7 +88,11 @@ impl UI { let mut title_string = StyledString::new(); title_string.append(StyledString::styled( - format!("Grin Version {}", built_info::PKG_VERSION), + format!( + "Grin Version {} (protocol version: {})", + built_info::PKG_VERSION, + Server::protocol_version() + ), Color::Dark(BaseColor::Green), ));