From f367e8e748e3b7592cd433f4bfc01e6837b2523f Mon Sep 17 00:00:00 2001 From: Kevin Deforth <32777623+kevindeforth@users.noreply.github.com.> Date: Fri, 16 Jan 2026 09:50:54 +0100 Subject: [PATCH 1/3] nodes accept peer with same or higher protocol version --- crates/node/src/network/handshake.rs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/crates/node/src/network/handshake.rs b/crates/node/src/network/handshake.rs index f72e7c7700..1ace12b1f3 100644 --- a/crates/node/src/network/handshake.rs +++ b/crates/node/src/network/handshake.rs @@ -24,7 +24,7 @@ pub async fn p2p_handshake( } 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 { anyhow::bail!( "Incompatible protocol version; we have {}, they have {}", MPC_PROTOCOL_VERSION, @@ -61,20 +61,31 @@ 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 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()); b.write_all(&buf).await.unwrap(); + let err = 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]; + b.read_exact(&mut buf).await.unwrap(); + buf[1..].copy_from_slice(&(MPC_PROTOCOL_VERSION - 1).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 - 1 ) ); } From 1aaac2501b6a1a7ff005ed383fd57cdae6672a23 Mon Sep 17 00:00:00 2001 From: Kevin Deforth <32777623+kevindeforth@users.noreply.github.com.> Date: Fri, 16 Jan 2026 10:09:40 +0100 Subject: [PATCH 2/3] clippy --- crates/node/src/network/handshake.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/node/src/network/handshake.rs b/crates/node/src/network/handshake.rs index 1ace12b1f3..dd647fcedf 100644 --- a/crates/node/src/network/handshake.rs +++ b/crates/node/src/network/handshake.rs @@ -68,7 +68,7 @@ mod tests { b.read_exact(&mut buf).await.unwrap(); buf[1..].copy_from_slice(&(MPC_PROTOCOL_VERSION + 1).to_be_bytes()); b.write_all(&buf).await.unwrap(); - let err = a_result.await.unwrap(); + a_result.await.unwrap(); } #[tokio::test] From 33fac66e197d5e52ff84bbfea1b914d47ada7abe Mon Sep 17 00:00:00 2001 From: Kevin Deforth <32777623+kevindeforth@users.noreply.github.com.> Date: Fri, 16 Jan 2026 10:12:56 +0100 Subject: [PATCH 3/3] improve test code --- crates/node/src/network/handshake.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/crates/node/src/network/handshake.rs b/crates/node/src/network/handshake.rs index dd647fcedf..af1f9258f4 100644 --- a/crates/node/src/network/handshake.rs +++ b/crates/node/src/network/handshake.rs @@ -63,10 +63,11 @@ mod tests { #[tokio::test] 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(); } @@ -76,16 +77,16 @@ mod tests { 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(&(MPC_PROTOCOL_VERSION - 1).to_be_bytes()); + 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 ) ); }