Skip to content
Merged
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
22 changes: 17 additions & 5 deletions crates/node/src/network/handshake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub async fn p2p_handshake<T: AsyncRead + AsyncWrite + Unpin>(
}

let other_protocol_version = u32::from_be_bytes(other_handshake[1..].try_into().unwrap());
if other_protocol_version != MPC_PROTOCOL_VERSION {
if other_protocol_version < MPC_PROTOCOL_VERSION {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For future reference, we plan to keep track of the agreed protocol version in a future release so newer nodes will know which version of the protocol they need to "speak". However, in this case the old nodes are simply "trusting" newer nodes to decide if they want to accept the connection and not, and the responsibility is on the newer nodes to communicate in a backwards compatible way.

anyhow::bail!(
"Incompatible protocol version; we have {}, they have {}",
MPC_PROTOCOL_VERSION,
Expand Down Expand Up @@ -61,20 +61,32 @@ mod tests {
}

#[tokio::test]
async fn test_p2p_handshake_different_version() {
async fn test_p2p_handshake_accept_higher_version() {
let (a, mut b) = tokio::io::duplex(1024);
let new_version = MPC_PROTOCOL_VERSION + 1;
let a_result = do_handshake(a);
let mut buf = [0u8; 5];
b.read_exact(&mut buf).await.unwrap();
buf[1..].copy_from_slice(&(MPC_PROTOCOL_VERSION + 1).to_be_bytes());
buf[1..].copy_from_slice(&(new_version).to_be_bytes());
b.write_all(&buf).await.unwrap();
a_result.await.unwrap();
}

#[tokio::test]
async fn test_p2p_handshake_reject_lower_version() {
let (a, mut b) = tokio::io::duplex(1024);
let a_result = do_handshake(a);
let mut buf = [0u8; 5];
let old_version = MPC_PROTOCOL_VERSION - 1;
b.read_exact(&mut buf).await.unwrap();
buf[1..].copy_from_slice(&(old_version).to_be_bytes());
b.write_all(&buf).await.unwrap();
let err = a_result.await.unwrap_err();
assert_eq!(
err.to_string(),
format!(
"Incompatible protocol version; we have {}, they have {}",
MPC_PROTOCOL_VERSION,
MPC_PROTOCOL_VERSION + 1
MPC_PROTOCOL_VERSION, old_version
)
);
}
Expand Down