Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relax p2p rules around matching protocol versions #2764

Merged
merged 1 commit into from
Apr 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -67,10 +67,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