Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit a90c72e

Browse files
rphmeiertomaka
andauthored
deprecate chain_status field of network handshake (#4675)
* deprecate chain_status field of network handshake * Update client/network/src/protocol/message.rs remove unneeded whitespace. Co-Authored-By: Pierre Krieger <[email protected]> Co-authored-by: Pierre Krieger <[email protected]>
1 parent 561bd72 commit a90c72e

File tree

2 files changed

+58
-2
lines changed

2 files changed

+58
-2
lines changed

client/network/src/protocol.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ const MAX_KNOWN_BLOCKS: usize = 1024; // ~32kb per peer + LruHashSet overhead
7474
const MAX_KNOWN_EXTRINSICS: usize = 4096; // ~128kb per peer + overhead
7575

7676
/// Current protocol version.
77-
pub(crate) const CURRENT_VERSION: u32 = 5;
77+
pub(crate) const CURRENT_VERSION: u32 = 6;
7878
/// Lowest version we support
7979
pub(crate) const MIN_VERSION: u32 = 3;
8080

client/network/src/protocol/message.rs

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,29 @@ pub mod generic {
252252
}
253253

254254
/// Status sent on connection.
255+
// TODO https://github.com/paritytech/substrate/issues/4674: replace the `Status`
256+
// struct with this one, after waiting a few releases beyond `NetworkSpecialization`'s
257+
// removal (https://github.com/paritytech/substrate/pull/4665)
258+
//
259+
// and set MIN_VERSION to 6.
255260
#[derive(Debug, PartialEq, Eq, Clone, Encode, Decode)]
261+
pub struct CompactStatus<Hash, Number> {
262+
/// Protocol version.
263+
pub version: u32,
264+
/// Minimum supported version.
265+
pub min_supported_version: u32,
266+
/// Supported roles.
267+
pub roles: Roles,
268+
/// Best block number.
269+
pub best_number: Number,
270+
/// Best block hash.
271+
pub best_hash: Hash,
272+
/// Genesis block hash.
273+
pub genesis_hash: Hash,
274+
}
275+
276+
/// Status sent on connection.
277+
#[derive(Debug, PartialEq, Eq, Clone, Encode)]
256278
pub struct Status<Hash, Number> {
257279
/// Protocol version.
258280
pub version: u32,
@@ -266,10 +288,44 @@ pub mod generic {
266288
pub best_hash: Hash,
267289
/// Genesis block hash.
268290
pub genesis_hash: Hash,
269-
/// Chain-specific status.
291+
/// DEPRECATED. Chain-specific status.
270292
pub chain_status: Vec<u8>,
271293
}
272294

295+
impl<Hash: Decode, Number: Decode> Decode for Status<Hash, Number> {
296+
fn decode<I: Input>(value: &mut I) -> Result<Self, codec::Error> {
297+
const LAST_CHAIN_STATUS_VERSION: u32 = 5;
298+
let compact = CompactStatus::decode(value)?;
299+
let chain_status = match <Vec<u8>>::decode(value) {
300+
Ok(v) => v,
301+
Err(e) => if compact.version <= LAST_CHAIN_STATUS_VERSION {
302+
return Err(e)
303+
} else {
304+
Vec::new()
305+
}
306+
};
307+
308+
let CompactStatus {
309+
version,
310+
min_supported_version,
311+
roles,
312+
best_number,
313+
best_hash,
314+
genesis_hash,
315+
} = compact;
316+
317+
Ok(Status {
318+
version,
319+
min_supported_version,
320+
roles,
321+
best_number,
322+
best_hash,
323+
genesis_hash,
324+
chain_status,
325+
})
326+
}
327+
}
328+
273329
/// Request block data from a peer.
274330
#[derive(Debug, PartialEq, Eq, Clone, Encode, Decode)]
275331
pub struct BlockRequest<Hash, Number> {

0 commit comments

Comments
 (0)