Skip to content

Commit

Permalink
Relax our p2p rules around matching protocol versions (#2764)
Browse files Browse the repository at this point in the history
  • Loading branch information
antiochp authored and ignopeverell committed Apr 24, 2019
1 parent 3c400f7 commit 19106b3
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 18 deletions.
14 changes: 2 additions & 12 deletions p2p/src/handshake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
9 changes: 8 additions & 1 deletion p2p/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions p2p/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,6 @@ pub enum Error {
Chain(chain::Error),
PeerWithSelf,
NoDandelionRelay,
ProtocolMismatch {
us: u32,
peer: u32,
},
GenesisMismatch {
us: Hash,
peer: Hash,
Expand Down
5 changes: 5 additions & 0 deletions servers/src/grin/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion src/bin/tui/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
));

Expand Down

0 comments on commit 19106b3

Please sign in to comment.