diff --git a/finality-aleph/src/crypto.rs b/finality-aleph/src/crypto.rs index dd6a5d3b06..17070a6e82 100644 --- a/finality-aleph/src/crypto.rs +++ b/finality-aleph/src/crypto.rs @@ -2,7 +2,7 @@ use std::{convert::TryInto, sync::Arc}; use aleph_primitives::{AuthorityId, AuthoritySignature, KEY_TYPE}; use codec::{Decode, Encode}; -use sp_core::{crypto::KeyTypeId, ed25519::Signature as RawSignature}; +use sp_core::crypto::KeyTypeId; use sp_keystore::{CryptoStore, Error as KeystoreError}; use sp_runtime::RuntimeAppPublic; @@ -24,13 +24,6 @@ impl From for Signature { } } -// This is here just for a compatibility hack, remove when removing legacy/v1 authentications. -impl From<[u8; 64]> for Signature { - fn from(bytes: [u8; 64]) -> Signature { - Signature(RawSignature::from_raw(bytes).into()) - } -} - /// Ties an authority identification and a cryptography keystore together for use in /// signing that requires an authority. #[derive(Clone)] diff --git a/finality-aleph/src/network/session/compatibility.rs b/finality-aleph/src/network/session/compatibility.rs index 146341bb51..ec301a191a 100644 --- a/finality-aleph/src/network/session/compatibility.rs +++ b/finality-aleph/src/network/session/compatibility.rs @@ -7,10 +7,7 @@ use codec::{Decode, Encode, Error as CodecError, Input as CodecInput}; use log::warn; use crate::{ - network::{ - session::{AuthData, Authentication, LegacyAuthentication}, - AddressingInformation, Data, - }, + network::{session::Authentication, AddressingInformation}, SessionId, Version, }; @@ -19,129 +16,35 @@ type ByteCount = u16; // We allow sending authentications of size up to 16KiB, that should be enough. const MAX_AUTHENTICATION_SIZE: u16 = 16 * 1024; -/// The possible forms of peer authentications we can have, either only new, only legacy or both. -#[derive(Clone, Debug, PartialEq, Eq, Hash)] -pub enum PeerAuthentications> + Into>> { - NewOnly(Authentication), - LegacyOnly(LegacyAuthentication), - Both(Authentication, LegacyAuthentication), -} - -impl> + Into>> PeerAuthentications { - /// The session with which these authentications are associated. - pub fn session_id(&self) -> SessionId { - use PeerAuthentications::*; - match self { - NewOnly((auth_data, _)) | Both((auth_data, _), _) => auth_data.session(), - LegacyOnly((auth_data, _)) => auth_data.session(), - } - } - - /// Add an authentication, overriding one that might have been here previously. - pub fn add_authentication(&mut self, authentication: Authentication) { - use PeerAuthentications::*; - match self { - NewOnly(_) => *self = NewOnly(authentication), - LegacyOnly(legacy_authentication) | Both(_, legacy_authentication) => { - *self = Both(authentication, legacy_authentication.clone()) - } - } - } - - /// Add a legacy authentication, overriding one that might have been here previously. - pub fn add_legacy_authentication(&mut self, legacy_authentication: LegacyAuthentication) { - use PeerAuthentications::*; - match self { - LegacyOnly(_) => *self = LegacyOnly(legacy_authentication), - NewOnly(authentication) | Both(authentication, _) => { - *self = Both(authentication.clone(), legacy_authentication) - } - } - } - - /// The associated address, if any. Can be `None` only for legacy authentications. - pub fn maybe_address(&self) -> Option { - use PeerAuthentications::*; - match self { - NewOnly((auth_data, _)) | Both((auth_data, _), _) => Some(auth_data.address()), - LegacyOnly((legacy_auth_data, _)) => legacy_auth_data - .clone() - .try_into() - .map(|auth_data: AuthData| auth_data.address()) - .ok(), - } - } -} - -/// Legacy messages used for discovery and authentication. -#[derive(Clone, Debug, PartialEq, Eq, Hash, Encode, Decode)] -pub enum LegacyDiscoveryMessage { - AuthenticationBroadcast(LegacyAuthentication), - Authentication(LegacyAuthentication), -} - #[derive(Clone, Debug, PartialEq, Eq)] -pub enum VersionedAuthentication { +pub enum VersionedAuthentication { // Most likely from the future. Other(Version, Vec), - V1(LegacyDiscoveryMessage), V2(Authentication), } -impl> + Into>> - From> for Vec> -{ - fn from(authentications: PeerAuthentications) -> Self { - use LegacyDiscoveryMessage::*; - use PeerAuthentications::*; - use VersionedAuthentication::*; - match authentications { - NewOnly(authentication) => vec![V2(authentication)], - LegacyOnly(legacy_authentication) => { - vec![V1(AuthenticationBroadcast(legacy_authentication))] - } - Both(authentication, legacy_authentication) => vec![ - V2(authentication), - V1(AuthenticationBroadcast(legacy_authentication)), - ], - } +impl From> for Vec> { + fn from(authentication: Authentication) -> Self { + vec![VersionedAuthentication::V2(authentication)] } } -/// One of the possible messages we could have gotten as part of discovery. -/// Ignores whether the old authentication was a broadcast or not, we don't send the -/// non-broadcasts anymore anyway, and treating them as broadcasts doesn't break anything. -#[derive(Clone, Debug, PartialEq, Eq, Hash)] -pub enum DiscoveryMessage> + Into>> { - Authentication(Authentication), - LegacyAuthentication(LegacyAuthentication), -} +pub type DiscoveryMessage = Authentication; -impl> + Into>> DiscoveryMessage { +impl DiscoveryMessage { /// Session ID associated with this message. pub fn session_id(&self) -> SessionId { - use DiscoveryMessage::*; - match self { - Authentication((auth_data, _)) => auth_data.session(), - LegacyAuthentication((auth_data, _)) => auth_data.session(), - } + self.0.session() } } -impl> + Into>> - TryInto> for VersionedAuthentication -{ +impl TryInto> for VersionedAuthentication { type Error = Error; - fn try_into(self) -> Result, Self::Error> { - use LegacyDiscoveryMessage::*; + fn try_into(self) -> Result, Self::Error> { use VersionedAuthentication::*; match self { - V1(AuthenticationBroadcast(legacy_authentication)) - | V1(Authentication(legacy_authentication)) => Ok( - DiscoveryMessage::LegacyAuthentication(legacy_authentication), - ), - V2(authentication) => Ok(DiscoveryMessage::Authentication(authentication)), + V2(authentication) => Ok(authentication), Other(v, _) => Err(Error::UnknownVersion(v)), } } @@ -177,9 +80,7 @@ fn encode_with_version(version: Version, payload: &[u8]) -> Vec { result } -impl> + Into>> Encode - for VersionedAuthentication -{ +impl Encode for VersionedAuthentication { fn size_hint(&self) -> usize { use VersionedAuthentication::*; let version_size = size_of::(); @@ -188,7 +89,6 @@ impl> + Into>> Encode + byte_count_size + match self { Other(_, payload) => payload.len(), - V1(data) => data.size_hint(), V2(data) => data.size_hint(), } } @@ -197,21 +97,17 @@ impl> + Into>> Encode use VersionedAuthentication::*; match self { Other(version, payload) => encode_with_version(*version, payload), - V1(data) => encode_with_version(Version(1), &data.encode()), V2(data) => encode_with_version(Version(2), &data.encode()), } } } -impl> + Into>> Decode - for VersionedAuthentication -{ +impl Decode for VersionedAuthentication { fn decode(input: &mut I) -> Result { use VersionedAuthentication::*; let version = Version::decode(input)?; let num_bytes = ByteCount::decode(input)?; match version { - Version(1) => Ok(V1(LegacyDiscoveryMessage::decode(input)?)), Version(2) => Ok(V2(Authentication::decode(input)?)), _ => { if num_bytes > MAX_AUTHENTICATION_SIZE { @@ -253,11 +149,8 @@ mod test { crypto::AuthorityVerifier, network::{ clique::mock::MockAddressingInformation, - session::{ - compatibility::{PeerAuthentications, MAX_AUTHENTICATION_SIZE}, - LegacyDiscoveryMessage, SessionHandler, - }, - tcp::{testing::new_identity, LegacyTcpMultiaddress, SignedTcpAddressingInformation}, + session::{compatibility::MAX_AUTHENTICATION_SIZE, SessionHandler}, + tcp::{testing::new_identity, SignedTcpAddressingInformation}, NetworkIdentity, }, nodes::testing::new_pen, @@ -265,7 +158,7 @@ mod test { }; /// Session Handler used for generating versioned authentication in `raw_authentication_v1` - async fn handler() -> SessionHandler { + async fn handler() -> SessionHandler { let mnemonic = "ring cool spatial rookie need wing opinion pond fork garbage more april"; let external_addresses = vec![ String::from("addr1"), @@ -286,52 +179,14 @@ mod test { .await } - fn authentication_v1( - handler: SessionHandler, - ) -> VersionedAuthentication { - match handler - .authentication() - .expect("should have authentication") - { - PeerAuthentications::Both(_, authentication) => { - VersionedAuthentication::V1(LegacyDiscoveryMessage::Authentication(authentication)) - } - _ => panic!("handler doesn't have both authentications"), - } - } - fn authentication_v2( - handler: SessionHandler, - ) -> VersionedAuthentication { - match handler - .authentication() - .expect("should have authentication") - { - PeerAuthentications::Both(authentication, _) => { - VersionedAuthentication::V2(authentication) - } - _ => panic!("handler doesn't have both authentications"), - } - } - - /// Versioned authentication for authority with: - /// external_addresses: [String::from("addr1"), String::from("addr2"), String::from("addr3")] - /// derived from mnemonic "ring cool spatial rookie need wing opinion pond fork garbage more april" - /// for node index 21 and session id 37 - /// encoded at version of Aleph Node from r-8.0 - fn raw_authentication_v1() -> Vec { - vec![ - 1, 0, 192, 0, 1, 12, 50, 40, 192, 239, 72, 72, 119, 156, 76, 37, 212, 220, 76, 165, 39, - 73, 20, 89, 77, 66, 171, 174, 61, 31, 254, 137, 186, 1, 7, 141, 187, 219, 20, 97, 100, - 100, 114, 49, 50, 40, 192, 239, 72, 72, 119, 156, 76, 37, 212, 220, 76, 165, 39, 73, - 20, 89, 77, 66, 171, 174, 61, 31, 254, 137, 186, 1, 7, 141, 187, 219, 20, 97, 100, 100, - 114, 50, 50, 40, 192, 239, 72, 72, 119, 156, 76, 37, 212, 220, 76, 165, 39, 73, 20, 89, - 77, 66, 171, 174, 61, 31, 254, 137, 186, 1, 7, 141, 187, 219, 20, 97, 100, 100, 114, - 51, 21, 0, 0, 0, 0, 0, 0, 0, 37, 0, 0, 0, 166, 39, 166, 74, 57, 190, 80, 240, 169, 85, - 240, 126, 250, 119, 54, 24, 244, 91, 199, 127, 32, 78, 52, 98, 159, 182, 227, 170, 251, - 49, 47, 89, 13, 171, 79, 190, 220, 22, 65, 254, 25, 115, 232, 103, 177, 252, 161, 222, - 74, 18, 216, 213, 105, 220, 223, 247, 221, 85, 31, 146, 177, 96, 254, 9, - ] + handler: SessionHandler, + ) -> VersionedAuthentication { + VersionedAuthentication::V2( + handler + .authentication() + .expect("should have authentication"), + ) } /// Versioned authentication for authority with: @@ -355,37 +210,6 @@ mod test { ] } - #[tokio::test] - async fn correcly_encodes_v1_to_bytes() { - let handler = handler().await; - let raw = raw_authentication_v1(); - let authentication_v1 = authentication_v1(handler); - - assert_eq!(authentication_v1.encode(), raw); - } - - #[tokio::test] - async fn correcly_decodes_v1_from_bytes() { - let handler = handler().await; - let raw = raw_authentication_v1(); - let authentication_v1 = authentication_v1(handler); - - let decoded = VersionedAuthentication::decode(&mut raw.as_slice()); - - assert_eq!(decoded, Ok(authentication_v1)); - } - - #[tokio::test] - async fn correctly_decodes_v1_roundtrip() { - let handler = handler().await; - let authentication_v1 = authentication_v1(handler); - - let encoded = authentication_v1.encode(); - let decoded = VersionedAuthentication::decode(&mut encoded.as_slice()); - - assert_eq!(decoded, Ok(authentication_v1)) - } - #[tokio::test] async fn correcly_encodes_v2_to_bytes() { let handler = handler().await; @@ -420,10 +244,7 @@ mod test { #[tokio::test] async fn correctly_decodes_other() { let other = - VersionedAuthentication::::Other( - Version(42), - vec![21, 37], - ); + VersionedAuthentication::::Other(Version(42), vec![21, 37]); let encoded = other.encode(); let decoded = VersionedAuthentication::decode(&mut encoded.as_slice()); assert_eq!(decoded, Ok(other)); @@ -432,15 +253,13 @@ mod test { other_big.append(&mut (MAX_AUTHENTICATION_SIZE).encode()); other_big.append(&mut vec![0u8; (MAX_AUTHENTICATION_SIZE).into()]); let decoded = - VersionedAuthentication::::decode( - &mut other_big.as_slice(), - ); + VersionedAuthentication::::decode(&mut other_big.as_slice()); assert_eq!( decoded, - Ok(VersionedAuthentication::< - MockAddressingInformation, - MockAddressingInformation, - >::Other(Version(42), other_big[4..].to_vec())) + Ok(VersionedAuthentication::::Other( + Version(42), + other_big[4..].to_vec() + )) ); } @@ -451,21 +270,16 @@ mod test { other.append(&mut size.encode()); other.append(&mut vec![0u8; size.into()]); let decoded = - VersionedAuthentication::::decode( - &mut other.as_slice(), - ); + VersionedAuthentication::::decode(&mut other.as_slice()); assert!(decoded.is_err()); - let other = - VersionedAuthentication::::Other( - Version(42), - vec![0u8; size.into()], - ); + let other = VersionedAuthentication::::Other( + Version(42), + vec![0u8; size.into()], + ); let encoded = other.encode(); let decoded = - VersionedAuthentication::::decode( - &mut encoded.as_slice(), - ); + VersionedAuthentication::::decode(&mut encoded.as_slice()); assert!(decoded.is_err()); } @@ -475,9 +289,7 @@ mod test { other.append(&mut MAX_AUTHENTICATION_SIZE.encode()); other.append(&mut vec![21, 37]); let decoded = - VersionedAuthentication::::decode( - &mut other.as_slice(), - ); + VersionedAuthentication::::decode(&mut other.as_slice()); assert!(decoded.is_err()); } } diff --git a/finality-aleph/src/network/session/discovery.rs b/finality-aleph/src/network/session/discovery.rs index e64e1a030c..752279e88b 100644 --- a/finality-aleph/src/network/session/discovery.rs +++ b/finality-aleph/src/network/session/discovery.rs @@ -1,6 +1,5 @@ use std::{ collections::HashMap, - fmt::Debug, marker::PhantomData, time::{Duration, Instant}, }; @@ -9,30 +8,25 @@ use log::{debug, info, trace}; use crate::{ network::{ - session::{ - compatibility::PeerAuthentications, Authentication, LegacyAuthentication, - SessionHandler, - }, - AddressingInformation, Data, + session::{Authentication, SessionHandler}, + AddressingInformation, }, NodeIndex, }; /// Handles creating and rebroadcasting discovery messages. -pub struct Discovery> + Into>> { +pub struct Discovery { cooldown: Duration, last_broadcast: HashMap, - last_legacy_broadcast: HashMap, - _phantom: PhantomData<(M, A)>, + _phantom: PhantomData, } -impl> + Into>> Discovery { +impl Discovery { /// Create a new discovery handler with the given response/broadcast cooldown. pub fn new(cooldown: Duration) -> Self { Discovery { cooldown, last_broadcast: HashMap::new(), - last_legacy_broadcast: HashMap::new(), _phantom: PhantomData, } } @@ -40,8 +34,8 @@ impl> + Into>> /// Returns a message that should be sent as part of authority discovery at this moment. pub fn discover_authorities( &mut self, - handler: &SessionHandler, - ) -> Option> { + handler: &SessionHandler, + ) -> Option> { let authentication = match handler.authentication() { Some(authentication) => authentication, None => return None, @@ -60,21 +54,14 @@ impl> + Into>> } } - fn should_legacy_rebroadcast(&self, node_id: &NodeIndex) -> bool { - match self.last_legacy_broadcast.get(node_id) { - Some(instant) => Instant::now() > *instant + self.cooldown, - None => true, - } - } - /// Processes the provided authentication and returns any new address we should /// be connected to if we want to stay connected to the committee and an optional /// message that we should send as a result of it. pub fn handle_authentication( &mut self, authentication: Authentication, - handler: &mut SessionHandler, - ) -> (Option, Option>) { + handler: &mut SessionHandler, + ) -> (Option, Option>) { debug!(target: "aleph-network", "Handling broadcast with authentication {:?}.", authentication); let address = match handler.handle_authentication(authentication.clone()) { Some(address) => Some(address), @@ -86,32 +73,7 @@ impl> + Into>> } trace!(target: "aleph-network", "Rebroadcasting {:?}.", authentication); self.last_broadcast.insert(node_id, Instant::now()); - (address, Some(PeerAuthentications::NewOnly(authentication))) - } - - /// Processes the legacy authentication and returns any new address we should - /// be connected to if we want to stay connected to the committee and an optional - /// message that we should send as a result of it. - pub fn handle_legacy_authentication( - &mut self, - legacy_authentication: LegacyAuthentication, - handler: &mut SessionHandler, - ) -> (Option, Option>) { - debug!(target: "aleph-network", "Handling broadcast with legacy authentication {:?}.", legacy_authentication); - let address = match handler.handle_legacy_authentication(legacy_authentication.clone()) { - Some(address) => Some(address), - None => return (None, None), - }; - let node_id = legacy_authentication.0.creator(); - if !self.should_legacy_rebroadcast(&node_id) { - return (address, None); - } - trace!(target: "aleph-network", "Rebroadcasting {:?}.", legacy_authentication); - self.last_legacy_broadcast.insert(node_id, Instant::now()); - ( - address, - Some(PeerAuthentications::LegacyOnly(legacy_authentication)), - ) + (address, Some(authentication)) } } @@ -124,10 +86,7 @@ mod tests { network::{ clique::mock::{random_address, MockAddressingInformation}, mock::crypto_basics, - session::{ - authentication, compatibility::PeerAuthentications, legacy_authentication, - SessionHandler, - }, + session::{authentication, Authentication, SessionHandler}, }, SessionId, }; @@ -142,9 +101,9 @@ mod tests { async fn build_number( num_nodes: u8, ) -> ( - Discovery, - Vec>, - SessionHandler, + Discovery, + Vec>, + SessionHandler, ) { let crypto_basics = crypto_basics(num_nodes.into()).await; let mut handlers = Vec::new(); @@ -174,9 +133,9 @@ mod tests { } async fn build() -> ( - Discovery, - Vec>, - SessionHandler, + Discovery, + Vec>, + SessionHandler, ) { build_number(NUM_NODES).await } @@ -211,18 +170,7 @@ mod tests { let (address, command) = discovery.handle_authentication(authentication.clone(), handler); assert_eq!(address, Some(authentication.0.address())); assert!(matches!(command, Some( - PeerAuthentications::NewOnly(rebroadcast_authentication), - ) if rebroadcast_authentication == authentication)); - } - - #[tokio::test] - async fn legacy_rebroadcasts_and_accepts_addresses() { - let (mut discovery, mut handlers, _) = build().await; - let authentication = legacy_authentication(&handlers[1]); - let handler = &mut handlers[0]; - let (_, command) = discovery.handle_legacy_authentication(authentication.clone(), handler); - assert!(matches!(command, Some( - PeerAuthentications::LegacyOnly(rebroadcast_authentication), + rebroadcast_authentication, ) if rebroadcast_authentication == authentication)); } @@ -234,45 +182,22 @@ mod tests { discovery.handle_authentication(authentication.clone(), &mut non_validator); assert_eq!(address, Some(authentication.0.address())); assert!(matches!(command, Some( - PeerAuthentications::NewOnly(rebroadcast_authentication), - ) if rebroadcast_authentication == authentication)); - } - - #[tokio::test] - async fn legacy_non_validator_rebroadcasts() { - let (mut discovery, handlers, mut non_validator) = build().await; - let authentication = legacy_authentication(&handlers[1]); - let (_, command) = - discovery.handle_legacy_authentication(authentication.clone(), &mut non_validator); - assert!(matches!(command, Some( - PeerAuthentications::LegacyOnly(rebroadcast_authentication), + rebroadcast_authentication, ) if rebroadcast_authentication == authentication)); } #[tokio::test] async fn does_not_rebroadcast_wrong_authentications() { let (mut discovery, mut handlers, _) = build().await; - let (auth_data, _) = authentication(&handlers[1]); - let (_, signature) = authentication(&handlers[2]); - let authentication = (auth_data, signature); + let Authentication(auth_data, _) = authentication(&handlers[1]); + let Authentication(_, signature) = authentication(&handlers[2]); + let authentication = Authentication(auth_data, signature); let handler = &mut handlers[0]; let (address, command) = discovery.handle_authentication(authentication, handler); assert!(address.is_none()); assert!(command.is_none()); } - #[tokio::test] - async fn legacy_does_not_rebroadcast_wrong_authentications() { - let (mut discovery, mut handlers, _) = build().await; - let (auth_data, _) = legacy_authentication(&handlers[1]); - let (_, signature) = legacy_authentication(&handlers[2]); - let authentication = (auth_data, signature); - let handler = &mut handlers[0]; - let (address, command) = discovery.handle_legacy_authentication(authentication, handler); - assert!(address.is_none()); - assert!(command.is_none()); - } - #[tokio::test] async fn rebroadcasts_after_cooldown() { let (mut discovery, mut handlers, _) = build().await; @@ -283,34 +208,7 @@ mod tests { let (address, command) = discovery.handle_authentication(authentication.clone(), handler); assert_eq!(address, Some(authentication.0.address())); assert!(matches!(command, Some( - PeerAuthentications::NewOnly(rebroadcast_authentication), - ) if rebroadcast_authentication == authentication)); - } - - #[tokio::test] - async fn legacy_rebroadcasts_after_cooldown() { - let (mut discovery, mut handlers, _) = build().await; - let authentication = legacy_authentication(&handlers[1]); - let handler = &mut handlers[0]; - discovery.handle_legacy_authentication(authentication.clone(), handler); - sleep(Duration::from_millis(MS_COOLDOWN + 5)); - let (_, command) = discovery.handle_legacy_authentication(authentication.clone(), handler); - assert!(matches!(command, Some( - PeerAuthentications::LegacyOnly(rebroadcast_authentication), + rebroadcast_authentication, ) if rebroadcast_authentication == authentication)); } - - #[tokio::test] - async fn rebroadcasts_legacy_immediately() { - let (mut discovery, mut handlers, _) = build().await; - let authentication = authentication(&handlers[1]); - let legacy_authentication = legacy_authentication(&handlers[1]); - let handler = &mut handlers[0]; - discovery.handle_authentication(authentication, handler); - let (_, command) = - discovery.handle_legacy_authentication(legacy_authentication.clone(), handler); - assert!(matches!(command, Some( - PeerAuthentications::LegacyOnly(rebroadcast_authentication), - ) if rebroadcast_authentication == legacy_authentication)); - } } diff --git a/finality-aleph/src/network/session/handler.rs b/finality-aleph/src/network/session/handler.rs index 797fe073d6..0ce4d8828e 100644 --- a/finality-aleph/src/network/session/handler.rs +++ b/finality-aleph/src/network/session/handler.rs @@ -6,22 +6,19 @@ use crate::{ abft::NodeCount, crypto::{AuthorityPen, AuthorityVerifier}, network::{ - session::{ - compatibility::PeerAuthentications, AuthData, Authentication, LegacyAuthData, - LegacyAuthentication, - }, - AddressingInformation, Data, + session::{AuthData, Authentication}, + AddressingInformation, }, NodeIndex, SessionId, }; #[derive(Debug)] -pub enum SessionInfo> + Into>> { +pub enum SessionInfo { SessionId(SessionId), - OwnAuthentication(PeerAuthentications), + OwnAuthentication(Authentication), } -impl> + Into>> SessionInfo { +impl SessionInfo { fn session_id(&self) -> SessionId { match self { SessionInfo::SessionId(session_id) => *session_id, @@ -34,10 +31,10 @@ impl> + Into>> Session /// A struct for handling authentications for a given session and maintaining /// mappings between PeerIds and NodeIndexes within that session. -pub struct Handler> + Into>> { +pub struct Handler { peers_by_node: HashMap, - authentications: HashMap>, - session_info: SessionInfo, + authentications: HashMap>, + session_info: SessionInfo, own_peer_id: A::PeerId, authority_index_and_pen: Option<(NodeIndex, AuthorityPen)>, authority_verifier: AuthorityVerifier, @@ -50,14 +47,11 @@ pub enum HandlerError { TypeChange, } -async fn construct_session_info< - M: Data, - A: AddressingInformation + TryFrom> + Into>, ->( +async fn construct_session_info( authority_index_and_pen: &Option<(NodeIndex, AuthorityPen)>, session_id: SessionId, address: A, -) -> (SessionInfo, A::PeerId) { +) -> (SessionInfo, A::PeerId) { let peer_id = address.peer_id(); match authority_index_and_pen { Some((node_index, authority_pen)) => { @@ -66,20 +60,15 @@ async fn construct_session_info< node_id: *node_index, session_id, }; - let legacy_auth_data: LegacyAuthData = auth_data.clone().into(); let signature = authority_pen.sign(&auth_data.encode()).await; - let legacy_signature = authority_pen.sign(&legacy_auth_data.encode()).await; - let authentications = PeerAuthentications::Both( - (auth_data, signature), - (legacy_auth_data, legacy_signature), - ); + let authentications = Authentication(auth_data, signature); (SessionInfo::OwnAuthentication(authentications), peer_id) } None => (SessionInfo::SessionId(session_id), peer_id), } } -impl> + Into>> Handler { +impl Handler { /// Creates a new session handler. It will be a validator session handler if the authority /// index and pen are provided. pub async fn new( @@ -87,7 +76,7 @@ impl> + Into>> Handler authority_verifier: AuthorityVerifier, session_id: SessionId, address: A, - ) -> Handler { + ) -> Handler { let (session_info, own_peer_id) = construct_session_info(&authority_index_and_pen, session_id, address).await; Handler { @@ -120,7 +109,7 @@ impl> + Into>> Handler } /// Returns the authentication for the node and session this handler is responsible for. - pub fn authentication(&self) -> Option> { + pub fn authentication(&self) -> Option> { match &self.session_info { SessionInfo::SessionId(_) => None, SessionInfo::OwnAuthentication(own_authentications) => { @@ -149,7 +138,7 @@ impl> + Into>> Handler if authentication.0.session() != self.session_id() { return None; } - let (auth_data, signature) = &authentication; + let Authentication(auth_data, signature) = &authentication; let address = auth_data.address(); if !address.verify() { @@ -167,50 +156,7 @@ impl> + Into>> Handler } self.peers_by_node .insert(auth_data.creator(), peer_id.clone()); - self.authentications - .entry(peer_id) - .and_modify(|authentications| { - authentications.add_authentication(authentication.clone()) - }) - .or_insert(PeerAuthentications::NewOnly(authentication)); - Some(address) - } - - /// Verifies the legacy authentication, uses it to update mappings, and returns the address we should stay connected to if any. - pub fn handle_legacy_authentication( - &mut self, - legacy_authentication: LegacyAuthentication, - ) -> Option { - if legacy_authentication.0.session() != self.session_id() { - return None; - } - let (legacy_auth_data, signature) = &legacy_authentication; - - if !self.authority_verifier.verify( - &legacy_auth_data.encode(), - signature, - legacy_auth_data.creator(), - ) { - return None; - } - - let maybe_auth_data: Option> = legacy_auth_data.clone().try_into().ok(); - let address = match maybe_auth_data { - Some(auth_data) => auth_data.address(), - None => return None, - }; - let peer_id = address.peer_id(); - if peer_id == self.own_peer_id { - return None; - } - self.peers_by_node - .insert(legacy_auth_data.creator(), peer_id.clone()); - self.authentications - .entry(peer_id) - .and_modify(|authentications| { - authentications.add_legacy_authentication(legacy_authentication.clone()) - }) - .or_insert(PeerAuthentications::LegacyOnly(legacy_authentication)); + self.authentications.insert(peer_id, authentication); Some(address) } @@ -249,21 +195,13 @@ impl> + Into>> Handler ) .await; - use PeerAuthentications::*; for (_, authentication) in authentications { - match authentication { - NewOnly(auth) => self.handle_authentication(auth), - LegacyOnly(legacy_auth) => self.handle_legacy_authentication(legacy_auth), - Both(auth, legacy_auth) => { - self.handle_legacy_authentication(legacy_auth); - self.handle_authentication(auth) - } - }; + self.handle_authentication(authentication); } Ok(self .authentications .values() - .flat_map(|authentication| authentication.maybe_address()) + .map(|authentication| authentication.0.address()) .collect()) } } @@ -275,34 +213,18 @@ pub mod tests { network::{ clique::mock::{random_address, random_invalid_address, MockAddressingInformation}, mock::crypto_basics, - session::{compatibility::PeerAuthentications, Authentication, LegacyAuthentication}, + session::Authentication, AddressingInformation, }, NodeIndex, SessionId, }; - pub fn legacy_authentication( - handler: &Handler, - ) -> LegacyAuthentication { - match handler - .authentication() - .expect("this is a validator handler") - { - PeerAuthentications::Both(_, authentication) => authentication, - _ => panic!("handler doesn't have both authentications"), - } - } - pub fn authentication( - handler: &Handler, + handler: &Handler, ) -> Authentication { - match handler + handler .authentication() .expect("this is a validator handler") - { - PeerAuthentications::Both(authentication, _) => authentication, - _ => panic!("handler doesn't have both authentications"), - } } const NUM_NODES: usize = 7; @@ -431,9 +353,6 @@ pub mod tests { assert!(handler0 .handle_authentication(authentication(&handler1)) .is_some()); - assert!(handler0 - .handle_legacy_authentication(legacy_authentication(&handler1)) - .is_some()); let missing_nodes = handler0.missing_nodes(); let expected_missing: Vec<_> = (2..NUM_NODES).map(NodeIndex).collect(); assert_eq!(missing_nodes, expected_missing); @@ -462,9 +381,6 @@ pub mod tests { assert!(handler0 .handle_authentication(authentication(&handler1)) .is_some()); - assert!(handler0 - .handle_legacy_authentication(legacy_authentication(&handler1)) - .is_some()); let missing_nodes = handler0.missing_nodes(); let mut expected_missing: Vec<_> = (0..NUM_NODES).map(NodeIndex).collect(); expected_missing.remove(1); @@ -543,9 +459,6 @@ pub mod tests { assert!(handler0 .handle_authentication(authentication(&handler1)) .is_none()); - assert!(handler0 - .handle_legacy_authentication(legacy_authentication(&handler1)) - .is_none()); let missing_nodes = handler0.missing_nodes(); let expected_missing: Vec<_> = (1..NUM_NODES).map(NodeIndex).collect(); assert_eq!(missing_nodes, expected_missing); @@ -564,9 +477,6 @@ pub mod tests { assert!(handler0 .handle_authentication(authentication(&handler0)) .is_none()); - assert!(handler0 - .handle_legacy_authentication(legacy_authentication(&handler0)) - .is_none()); let missing_nodes = handler0.missing_nodes(); let expected_missing: Vec<_> = (1..NUM_NODES).map(NodeIndex).collect(); assert_eq!(missing_nodes, expected_missing); @@ -592,9 +502,6 @@ pub mod tests { assert!(handler0 .handle_authentication(authentication(&handler1)) .is_some()); - assert!(handler0 - .handle_legacy_authentication(legacy_authentication(&handler1)) - .is_some()); let new_crypto_basics = crypto_basics(NUM_NODES).await; handler0 .update( diff --git a/finality-aleph/src/network/session/manager.rs b/finality-aleph/src/network/session/manager.rs index 6feff15c67..e9483c7f69 100644 --- a/finality-aleph/src/network/session/manager.rs +++ b/finality-aleph/src/network/session/manager.rs @@ -12,8 +12,8 @@ use crate::{ crypto::{AuthorityPen, AuthorityVerifier}, network::{ session::{ - compatibility::PeerAuthentications, data::DataInSession, Connections, Discovery, - DiscoveryMessage, SessionHandler, SessionHandlerError, + data::DataInSession, Authentication, Connections, Discovery, DiscoveryMessage, + SessionHandler, SessionHandlerError, }, AddressingInformation, Data, NetworkIdentity, PeerId, }, @@ -30,9 +30,9 @@ pub enum ConnectionCommand { // In practice D: Data and P: PeerId, but we cannot require that in type aliases. pub type AddressedData = (D, P); -struct Session> + Into>> { - handler: SessionHandler, - discovery: Discovery, +struct Session { + handler: SessionHandler, + discovery: Discovery, data_for_user: Option>, } @@ -55,12 +55,12 @@ pub struct PreNonvalidatorSession { /// Actions that the manager wants to take as the result of some information. Might contain a /// command for connecting to or disconnecting from some peers or a message to broadcast for /// discovery purposes. -pub struct ManagerActions> + Into>> { +pub struct ManagerActions { pub maybe_command: Option>, - pub maybe_message: Option>, + pub maybe_message: Option>, } -impl> + Into>> ManagerActions { +impl ManagerActions { fn noop() -> Self { ManagerActions { maybe_command: None, @@ -78,13 +78,10 @@ impl> + Into>> Manager /// 1. In-session messages are forwarded to the user. /// 2. Authentication messages forwarded to session handlers. /// 4. Running periodic maintenance, mostly related to node discovery. -pub struct Manager -where - NI::AddressingInformation: TryFrom> + Into>, -{ +pub struct Manager { network_identity: NI, connections: Connections, - sessions: HashMap>, + sessions: HashMap>, discovery_cooldown: Duration, } @@ -95,10 +92,7 @@ pub enum SendError { NoSession, } -impl Manager -where - NI::AddressingInformation: TryFrom> + Into>, -{ +impl Manager { /// Create a new connection manager. pub fn new(network_identity: NI, discovery_cooldown: Duration) -> Self { Manager { @@ -122,7 +116,7 @@ where pub fn finish_session( &mut self, session_id: SessionId, - ) -> ManagerActions { + ) -> ManagerActions { self.sessions.remove(&session_id); ManagerActions { maybe_command: Self::delete_reserved(self.connections.remove_session(session_id)), @@ -133,7 +127,7 @@ where fn discover_authorities( &mut self, session_id: &SessionId, - ) -> Option> { + ) -> Option> { self.sessions.get_mut(session_id).and_then( |Session { handler, discovery, .. @@ -142,7 +136,7 @@ where } /// Returns all the network messages that should be sent as part of discovery at this moment. - pub fn discovery(&mut self) -> Vec> { + pub fn discovery(&mut self) -> Vec> { let sessions: Vec<_> = self.sessions.keys().cloned().collect(); sessions .iter() @@ -155,7 +149,7 @@ where pre_session: PreValidatorSession, address: NI::AddressingInformation, ) -> ( - Option>, + Option>, mpsc::UnboundedReceiver, ) { let PreValidatorSession { @@ -186,7 +180,7 @@ where pre_session: PreValidatorSession, ) -> Result< ( - ManagerActions, + ManagerActions, mpsc::UnboundedReceiver, ), SessionHandlerError, @@ -263,7 +257,7 @@ where pub async fn update_nonvalidator_session( &mut self, pre_session: PreNonvalidatorSession, - ) -> Result, SessionHandlerError> { + ) -> Result, SessionHandlerError> { let address = self.network_identity.identity(); match self.sessions.get_mut(&pre_session.session_id) { Some(session) => { @@ -314,22 +308,15 @@ where /// Returns actions the manager wants to take. pub fn on_discovery_message( &mut self, - message: DiscoveryMessage, - ) -> ManagerActions { - use DiscoveryMessage::*; + message: DiscoveryMessage, + ) -> ManagerActions { let session_id = message.session_id(); match self.sessions.get_mut(&session_id) { Some(Session { handler, discovery, .. }) => { - let (maybe_address, maybe_message) = match message { - Authentication(authentication) => { - discovery.handle_authentication(authentication, handler) - } - LegacyAuthentication(legacy_authentication) => { - discovery.handle_legacy_authentication(legacy_authentication, handler) - } - }; + let (maybe_address, maybe_message) = + discovery.handle_authentication(message, handler); let maybe_command = match (maybe_address, handler.is_validator()) { (Some(address), true) => { debug!(target: "aleph-network", "Adding addresses for session {:?} to reserved: {:?}", session_id, address); @@ -458,7 +445,7 @@ mod tests { network::{ clique::mock::{random_address, MockAddressingInformation}, mock::crypto_basics, - session::{compatibility::PeerAuthentications, data::DataInSession, DiscoveryMessage}, + session::data::DataInSession, }, Recipient, SessionId, }; @@ -466,7 +453,7 @@ mod tests { const NUM_NODES: usize = 7; const DISCOVERY_PERIOD: Duration = Duration::from_secs(60); - fn build() -> Manager { + fn build() -> Manager { Manager::new(random_address(), DISCOVERY_PERIOD) } @@ -584,13 +571,7 @@ mod tests { .await .unwrap(); let message = maybe_message.expect("there should be a discovery message"); - let (address, message) = match message { - PeerAuthentications::Both(authentication, _) => ( - authentication.0.address(), - DiscoveryMessage::Authentication(authentication), - ), - message => panic!("Expected both authentications, got {:?}", message), - }; + let (address, message) = (message.0.address(), message); let ManagerActions { maybe_command, maybe_message, @@ -630,12 +611,7 @@ mod tests { }) .await .unwrap(); - let message = match maybe_message.expect("there should be a discovery message") { - PeerAuthentications::Both(authentication, _) => { - DiscoveryMessage::Authentication(authentication) - } - message => panic!("Expected both authentications, got {:?}", message), - }; + let message = maybe_message.expect("there should be a discovery message"); manager.on_discovery_message(message); let messages = manager.on_user_message(2137, session_id, Recipient::Everyone); assert_eq!(messages.len(), 1); diff --git a/finality-aleph/src/network/session/mod.rs b/finality-aleph/src/network/session/mod.rs index a3b7ed75ad..1101690f51 100644 --- a/finality-aleph/src/network/session/mod.rs +++ b/finality-aleph/src/network/session/mod.rs @@ -24,37 +24,16 @@ mod handler; mod manager; mod service; -pub use compatibility::{ - DiscoveryMessage, LegacyDiscoveryMessage, PeerAuthentications, VersionedAuthentication, -}; +pub use compatibility::{DiscoveryMessage, VersionedAuthentication}; use connections::Connections; #[cfg(test)] pub use data::DataInSession; pub use discovery::Discovery; #[cfg(test)] -pub use handler::tests::{authentication, legacy_authentication}; +pub use handler::tests::authentication; pub use handler::{Handler as SessionHandler, HandlerError as SessionHandlerError}; pub use service::{Config as ConnectionManagerConfig, ManagerError, Service as ConnectionManager}; -/// Data validators used to use to authenticate themselves for a single session -/// and disseminate their addresses. -#[derive(Clone, Debug, PartialEq, Eq, Hash, Encode, Decode)] -pub struct LegacyAuthData { - addresses: Vec, - node_id: NodeIndex, - session_id: SessionId, -} - -impl LegacyAuthData { - pub fn session(&self) -> SessionId { - self.session_id - } - - pub fn creator(&self) -> NodeIndex { - self.node_id - } -} - /// Data validators use to authenticate themselves for a single session /// and disseminate their addresses. #[derive(Clone, Debug, PartialEq, Eq, Hash, Encode, Decode)] @@ -78,47 +57,9 @@ impl AuthData { } } -impl>> From> for LegacyAuthData { - fn from(auth_data: AuthData) -> Self { - let AuthData { - address, - node_id, - session_id, - } = auth_data; - let addresses = address.into(); - LegacyAuthData { - addresses, - node_id, - session_id, - } - } -} - -impl>> TryFrom> - for AuthData -{ - type Error = (); - - fn try_from(legacy_auth_data: LegacyAuthData) -> Result { - let LegacyAuthData { - addresses, - node_id, - session_id, - } = legacy_auth_data; - let address = addresses.try_into().map_err(|_| ())?; - Ok(AuthData { - address, - node_id, - session_id, - }) - } -} - -/// A full legacy authentication, consisting of a signed LegacyAuthData. -pub type LegacyAuthentication = (LegacyAuthData, Signature); - /// A full authentication, consisting of a signed AuthData. -pub type Authentication = (AuthData, Signature); +#[derive(Clone, Decode, Encode, Debug, Eq, PartialEq, Hash)] +pub struct Authentication(AuthData, Signature); /// Sends data within a single session. #[derive(Clone)] diff --git a/finality-aleph/src/network/session/service.rs b/finality-aleph/src/network/session/service.rs index 8225260e2f..16efd3b017 100644 --- a/finality-aleph/src/network/session/service.rs +++ b/finality-aleph/src/network/session/service.rs @@ -173,15 +173,13 @@ impl Config { /// The connection manager service. pub struct Service< D: Data, - M: Data + Debug, NI: NetworkIdentity, CN: CliqueNetwork>, - GN: GossipNetwork>, + GN: GossipNetwork>, > where NI::PeerId: PublicKey, - NI::AddressingInformation: TryFrom> + Into>, { - manager: Manager, + manager: Manager, commands_from_user: mpsc::UnboundedReceiver>, messages_from_user: mpsc::UnboundedReceiver<(D, SessionId, Recipient)>, validator_network: CN, @@ -213,14 +211,12 @@ impl Display for Error { impl< D: Data, - M: Data + Debug, NI: NetworkIdentity, CN: CliqueNetwork>, - GN: GossipNetwork>, - > Service + GN: GossipNetwork>, + > Service where NI::PeerId: PublicKey, - NI::AddressingInformation: TryFrom> + Into>, { pub fn new( network_identity: NI, @@ -228,7 +224,7 @@ where gossip_network: GN, config: Config, ) -> ( - Service, + Service, impl SessionManager, ) { let Config { @@ -262,7 +258,7 @@ where fn send_authentications( &mut self, - to_send: Vec>, + to_send: Vec>, ) -> Result<(), Error> { for auth in to_send { self.gossip_network @@ -296,7 +292,7 @@ where ManagerActions { maybe_command, maybe_message, - }: ManagerActions, + }: ManagerActions, ) -> Result<(), Error> { if let Some(command) = maybe_command { self.handle_connection_command(command); @@ -312,7 +308,7 @@ where async fn handle_command( &mut self, command: SessionCommand, - ) -> Result, SessionHandlerError> { + ) -> Result, SessionHandlerError> { use SessionCommand::*; match command { StartValidator(session_id, verifier, node_id, pen, result_for_user) => { diff --git a/finality-aleph/src/network/tcp.rs b/finality-aleph/src/network/tcp.rs index 98346ff3ed..526400e2ff 100644 --- a/finality-aleph/src/network/tcp.rs +++ b/finality-aleph/src/network/tcp.rs @@ -96,13 +96,6 @@ impl SecretKey for AuthorityPen { } } -/// A representation of a single TCP address with an associated peer ID. -#[derive(Debug, Hash, Encode, Decode, Clone, PartialEq, Eq)] -pub struct LegacyTcpMultiaddress { - peer_id: AuthorityId, - address: String, -} - /// What can go wrong when handling addressing information. #[derive(Debug, Hash, Clone, PartialEq, Eq)] pub enum AddressingInformationError { @@ -118,44 +111,6 @@ struct TcpAddressingInformation { other_addresses: Vec, } -impl TryFrom> for TcpAddressingInformation { - type Error = AddressingInformationError; - - fn try_from(legacy: Vec) -> Result { - let mut legacy = legacy.into_iter(); - let (peer_id, primary_address) = match legacy.next() { - Some(LegacyTcpMultiaddress { peer_id, address }) => (peer_id, address), - None => return Err(AddressingInformationError::NoAddress), - }; - let other_addresses = legacy - .filter(|la| la.peer_id == peer_id) - .map(|la| la.address) - .collect(); - Ok(TcpAddressingInformation { - peer_id, - primary_address, - other_addresses, - }) - } -} - -impl From for Vec { - fn from(address: TcpAddressingInformation) -> Self { - let TcpAddressingInformation { - peer_id, - primary_address, - other_addresses, - } = address; - iter::once(primary_address) - .chain(other_addresses) - .map(|address| LegacyTcpMultiaddress { - peer_id: peer_id.clone(), - address, - }) - .collect() - } -} - impl TcpAddressingInformation { fn new( addresses: Vec, @@ -185,29 +140,6 @@ pub struct SignedTcpAddressingInformation { signature: Signature, } -impl TryFrom> for SignedTcpAddressingInformation { - type Error = AddressingInformationError; - - fn try_from(legacy: Vec) -> Result { - let addressing_information = legacy.try_into()?; - // This will never get validated, but that is alright and working as intended. - // We temporarily accept legacy messages and there is no way to verify them completely, - // since they were unsigned previously. In the next update we will remove this, and the - // problem will be completely gone. - let signature = [0; 64].into(); - Ok(SignedTcpAddressingInformation { - addressing_information, - signature, - }) - } -} - -impl From for Vec { - fn from(address: SignedTcpAddressingInformation) -> Self { - address.addressing_information.into() - } -} - impl AddressingInformation for SignedTcpAddressingInformation { type PeerId = AuthorityId; diff --git a/finality-aleph/src/testing/network.rs b/finality-aleph/src/testing/network.rs index 78cbbb009e..1e5fe7e774 100644 --- a/finality-aleph/src/testing/network.rs +++ b/finality-aleph/src/testing/network.rs @@ -19,9 +19,8 @@ use crate::{ data::Network, mock::{crypto_basics, MockData}, session::{ - authentication, legacy_authentication, ConnectionManager, ConnectionManagerConfig, - DataInSession, LegacyDiscoveryMessage, ManagerError, SessionHandler, SessionManager, - VersionedAuthentication, + authentication, ConnectionManager, ConnectionManagerConfig, DataInSession, + ManagerError, SessionHandler, SessionManager, VersionedAuthentication, }, AddressingInformation, GossipService, MockEvent, MockRawNetwork, Protocol, }, @@ -179,7 +178,7 @@ impl TestData { &self, node_id: usize, session_id: u32, - ) -> SessionHandler { + ) -> SessionHandler { SessionHandler::new( Some((NodeIndex(node_id), self.authorities[node_id].pen())), self.authority_verifier.clone(), @@ -199,15 +198,6 @@ impl TestData { .await .expect("Should add reserved nodes"); reserved_addresses.insert(address); - // Gotta repeat this, because we are adding every address twice, due to legacy - // authentications. - let (_, address) = self - .validator_network - .add_connection - .next() - .await - .expect("Should add reserved nodes"); - reserved_addresses.insert(address); } let mut expected_addresses = HashSet::new(); @@ -225,7 +215,7 @@ impl TestData { self.connect_identity_to_network(authority.auth_peer_id(), Protocol::Authentication); for versioned_authentication in - Vec::>::from(handler.authentication().unwrap()) + Vec::>::from(handler.authentication().unwrap()) { self.network.emit_event(MockEvent::Messages( authority.auth_peer_id(), @@ -249,7 +239,7 @@ impl TestData { async fn next_sent_auth( &mut self, ) -> Option<( - VersionedAuthentication, + VersionedAuthentication, MockPublicKey, Protocol, )> { @@ -258,10 +248,9 @@ impl TestData { Some((data, peer_id, protocol)) => { if protocol == Protocol::Authentication { return Some(( - VersionedAuthentication::< - MockAddressingInformation, - MockAddressingInformation, - >::decode(&mut data.as_slice()) + VersionedAuthentication::::decode( + &mut data.as_slice(), + ) .expect("should decode"), peer_id, protocol, @@ -295,16 +284,6 @@ async fn test_sends_discovery_message() { for _ in 0..4 { match test_data.next_sent_auth().await { - Some(( - VersionedAuthentication::V1(LegacyDiscoveryMessage::AuthenticationBroadcast( - authentication, - )), - peer_id, - _, - )) => { - assert_eq!(peer_id, connected_peer_id); - assert_eq!(authentication, legacy_authentication(&handler)); - } Some((VersionedAuthentication::V2(new_authentication), peer_id, _)) => { assert_eq!(peer_id, connected_peer_id); assert_eq!(new_authentication, authentication(&handler)); @@ -335,7 +314,7 @@ async fn test_forwards_authentication_broadcast() { } for versioned_authentication in - Vec::>::from(sending_peer_handler.authentication().unwrap()) + Vec::>::from(sending_peer_handler.authentication().unwrap()) { test_data.network.emit_event(MockEvent::Messages( sending_peer.auth_peer_id(), @@ -346,46 +325,27 @@ async fn test_forwards_authentication_broadcast() { )); } - for _ in 0..2 { - // Since we send the legacy auth and both are correct this should happen twice. - assert_eq!( - test_data - .validator_network - .add_connection - .next() - .await - .expect("Should add reserved nodes"), - (sending_peer.peer_id(), sending_peer.address()), - ); - } + assert_eq!( + test_data + .validator_network + .add_connection + .next() + .await + .expect("Should add reserved nodes"), + (sending_peer.peer_id(), sending_peer.address()), + ); let mut expected_authentication = HashMap::new(); - let mut expected_legacy_authentication = HashMap::new(); for authority in test_data.authorities.iter().skip(1) { expected_authentication.insert( authority.auth_peer_id(), authentication(&sending_peer_handler), ); - expected_legacy_authentication.insert( - authority.auth_peer_id(), - legacy_authentication(&sending_peer_handler), - ); } let mut sent_authentication = HashMap::new(); - let mut sent_legacy_authentication = HashMap::new(); - while sent_authentication.len() < NODES_N - 1 || sent_legacy_authentication.len() < NODES_N - 1 - { + while sent_authentication.len() < NODES_N - 1 { match test_data.next_sent_auth().await { - Some(( - VersionedAuthentication::V1(LegacyDiscoveryMessage::AuthenticationBroadcast(auth)), - peer_id, - _, - )) => { - if auth != legacy_authentication(&handler) { - sent_legacy_authentication.insert(peer_id, auth); - } - } Some((VersionedAuthentication::V2(auth), peer_id, _)) => { if auth != authentication(&handler) { sent_authentication.insert(peer_id, auth); @@ -397,7 +357,6 @@ async fn test_forwards_authentication_broadcast() { } assert_eq!(sent_authentication, expected_authentication); - assert_eq!(sent_legacy_authentication, expected_legacy_authentication); test_data.cleanup().await; assert_eq!( @@ -477,7 +436,7 @@ async fn test_stops_session() { // This assert should be before cleanup. We want to check whether `session_manager.stop_session(...)` // drops the sender. After cleanup all network tasks end and senders will be dropped. - // If assert was after cleanup we wouldn't know whether data_network receiver is droopped + // If assert was after cleanup we wouldn't know whether data_network receiver is dropped // because of `session_manager.stop_session(...)` or because of cleanup. assert_eq!( timeout(DEFAULT_TIMEOUT, data_network.next()).await,