From 8b0fa07204e5630471aca9d65d481727bfc65b71 Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Sun, 19 Jan 2020 23:32:29 +0100 Subject: [PATCH 1/2] deprecate chain_status field of network handshake --- client/network/src/protocol.rs | 2 +- client/network/src/protocol/message.rs | 58 +++++++++++++++++++++++++- 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/client/network/src/protocol.rs b/client/network/src/protocol.rs index 2aa29ea2793e3..6914ea9efe138 100644 --- a/client/network/src/protocol.rs +++ b/client/network/src/protocol.rs @@ -74,7 +74,7 @@ const MAX_KNOWN_BLOCKS: usize = 1024; // ~32kb per peer + LruHashSet overhead const MAX_KNOWN_EXTRINSICS: usize = 4096; // ~128kb per peer + overhead /// Current protocol version. -pub(crate) const CURRENT_VERSION: u32 = 5; +pub(crate) const CURRENT_VERSION: u32 = 6; /// Lowest version we support pub(crate) const MIN_VERSION: u32 = 3; diff --git a/client/network/src/protocol/message.rs b/client/network/src/protocol/message.rs index 30f0c34175aa5..4749cf38f801b 100644 --- a/client/network/src/protocol/message.rs +++ b/client/network/src/protocol/message.rs @@ -252,7 +252,29 @@ pub mod generic { } /// Status sent on connection. + // TODO https://github.com/paritytech/substrate/issues/4674: replace the `Status` + // struct with this one, after waiting a few releases beyond `NetworkSpecialization`'s + // removal (https://github.com/paritytech/substrate/pull/4665) + // + // and set MIN_VERSION to 6. #[derive(Debug, PartialEq, Eq, Clone, Encode, Decode)] + pub struct CompactStatus { + /// Protocol version. + pub version: u32, + /// Minimum supported version. + pub min_supported_version: u32, + /// Supported roles. + pub roles: Roles, + /// Best block number. + pub best_number: Number, + /// Best block hash. + pub best_hash: Hash, + /// Genesis block hash. + pub genesis_hash: Hash, + } + + /// Status sent on connection. + #[derive(Debug, PartialEq, Eq, Clone, Encode)] pub struct Status { /// Protocol version. pub version: u32, @@ -266,10 +288,44 @@ pub mod generic { pub best_hash: Hash, /// Genesis block hash. pub genesis_hash: Hash, - /// Chain-specific status. + /// DEPRECATED. Chain-specific status. pub chain_status: Vec, } + impl Decode for Status { + fn decode(value: &mut I) -> Result { + const LAST_CHAIN_STATUS_VERSION: u32 = 5; + let compact = CompactStatus::decode(value)?; + let chain_status = match >::decode(value) { + Ok(v) => v, + Err(e) => if compact.version <= LAST_CHAIN_STATUS_VERSION { + return Err(e) + } else { + Vec::new() + } + }; + + let CompactStatus { + version, + min_supported_version, + roles, + best_number, + best_hash, + genesis_hash, + } = compact; + + Ok(Status { + version, + min_supported_version, + roles, + best_number, + best_hash, + genesis_hash, + chain_status, + }) + } + } + /// Request block data from a peer. #[derive(Debug, PartialEq, Eq, Clone, Encode, Decode)] pub struct BlockRequest { From 8e3886542de1e48a1f6b8824148686d3e41aaeb0 Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Mon, 20 Jan 2020 12:41:42 +0100 Subject: [PATCH 2/2] Update client/network/src/protocol/message.rs remove unneeded whitespace. Co-Authored-By: Pierre Krieger --- client/network/src/protocol/message.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/network/src/protocol/message.rs b/client/network/src/protocol/message.rs index 4749cf38f801b..ef7d550de6cbe 100644 --- a/client/network/src/protocol/message.rs +++ b/client/network/src/protocol/message.rs @@ -298,7 +298,7 @@ pub mod generic { let compact = CompactStatus::decode(value)?; let chain_status = match >::decode(value) { Ok(v) => v, - Err(e) => if compact.version <= LAST_CHAIN_STATUS_VERSION { + Err(e) => if compact.version <= LAST_CHAIN_STATUS_VERSION { return Err(e) } else { Vec::new()