From 1b780814ae95f31bd9efc129eef299ec3ca61e22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20Gawrya=C5=82?= Date: Wed, 11 Oct 2023 15:36:29 +0200 Subject: [PATCH 01/24] Collect low level addresses --- bin/node/src/aleph_node_rpc.rs | 4 ++- bin/node/src/service.rs | 4 +++ clique/src/lib.rs | 3 ++ clique/src/mock.rs | 4 +++ finality-aleph/src/lib.rs | 3 +- finality-aleph/src/network/gossip/mod.rs | 4 +-- finality-aleph/src/network/gossip/service.rs | 4 ++- finality-aleph/src/network/mod.rs | 33 +++++++++++++++++++ finality-aleph/src/network/session/manager.rs | 15 +++++++-- finality-aleph/src/network/session/service.rs | 14 +++++--- finality-aleph/src/network/tcp.rs | 4 +++ finality-aleph/src/nodes.rs | 2 ++ 12 files changed, 83 insertions(+), 11 deletions(-) diff --git a/bin/node/src/aleph_node_rpc.rs b/bin/node/src/aleph_node_rpc.rs index 13dd7f5079..3c9b4dbf03 100644 --- a/bin/node/src/aleph_node_rpc.rs +++ b/bin/node/src/aleph_node_rpc.rs @@ -1,6 +1,8 @@ use std::sync::Arc; -use finality_aleph::{AlephJustification, BlockId, Justification, JustificationTranslator}; +use finality_aleph::{ + AlephJustification, BlockId, Justification, JustificationTranslator, ValidatorsAddressingInfo, +}; use futures::channel::mpsc; use jsonrpsee::{ core::{error::Error as JsonRpseeError, RpcResult}, diff --git a/bin/node/src/service.rs b/bin/node/src/service.rs index 15f68f926f..e11eccbf7c 100644 --- a/bin/node/src/service.rs +++ b/bin/node/src/service.rs @@ -10,6 +10,7 @@ use finality_aleph::{ run_validator_node, AlephBlockImport, AlephConfig, BlockImporter, Justification, JustificationTranslator, MillisecsPerBlock, Protocol, ProtocolNaming, RateLimiterConfig, SessionPeriod, SubstrateChainStatus, SyncOracle, TimingBlockMetrics, TracingBlockImport, + ValidatorsAddressingInfo, }; use futures::channel::mpsc; use log::warn; @@ -403,6 +404,8 @@ pub fn new_authority( .unwrap_or(usize::MAX), }; + let validators_addressing_info = ValidatorsAddressingInfo::new(); + let aleph_config = AlephConfig { network, sync_network, @@ -424,6 +427,7 @@ pub fn new_authority( protocol_naming, rate_limiter_config, sync_oracle, + validators_addressing_info, }; task_manager.spawn_essential_handle().spawn_blocking( diff --git a/clique/src/lib.rs b/clique/src/lib.rs index 9e8940044d..a3434de0cd 100644 --- a/clique/src/lib.rs +++ b/clique/src/lib.rs @@ -58,6 +58,9 @@ pub trait AddressingInformation: Debug + Hash + Codec + Clone + Eq + Send + Sync /// Verify the information. fn verify(&self) -> bool; + + // Address used internally by the protocol. + fn internal_protocol_address(&self) -> String; } /// Abstraction for requesting own network addressing information. diff --git a/clique/src/mock.rs b/clique/src/mock.rs index b04a803981..32710f5337 100644 --- a/clique/src/mock.rs +++ b/clique/src/mock.rs @@ -293,6 +293,10 @@ impl AddressingInformation for MockAddressingInformation { fn verify(&self) -> bool { self.valid } + + fn internal_protocol_address(&self) -> String { + self.address.clone() + } } impl NetworkIdentity for MockAddressingInformation { diff --git a/finality-aleph/src/lib.rs b/finality-aleph/src/lib.rs index 48be643b43..3f0ff8e0b5 100644 --- a/finality-aleph/src/lib.rs +++ b/finality-aleph/src/lib.rs @@ -61,7 +61,7 @@ pub use crate::{ import::{AlephBlockImport, TracingBlockImport}, justification::AlephJustification, metrics::TimingBlockMetrics, - network::{Protocol, ProtocolNaming}, + network::{Protocol, ProtocolNaming, ValidatorsAddressingInfo}, nodes::run_validator_node, session::SessionPeriod, sync::{ @@ -287,4 +287,5 @@ pub struct AlephConfig { pub protocol_naming: ProtocolNaming, pub rate_limiter_config: RateLimiterConfig, pub sync_oracle: SyncOracle, + pub validators_addressing_info: ValidatorsAddressingInfo, } diff --git a/finality-aleph/src/network/gossip/mod.rs b/finality-aleph/src/network/gossip/mod.rs index 55afc8fe47..fd5948a5f3 100644 --- a/finality-aleph/src/network/gossip/mod.rs +++ b/finality-aleph/src/network/gossip/mod.rs @@ -22,7 +22,7 @@ pub use service::{Error, Service}; /// connected to them directly. pub trait Network: Send + 'static { type Error: Display + Send; - type PeerId: Clone + Debug + Eq + Hash + Send + 'static; + type PeerId: Clone + Debug + Display + Eq + Hash + Send + 'static; /// Attempt to send data to a peer. Might silently fail if we are not connected to them. fn send_to(&mut self, data: D, peer_id: Self::PeerId) -> Result<(), Self::Error>; @@ -87,7 +87,7 @@ pub trait EventStream

{ pub trait RawNetwork: Clone + Send + Sync + 'static { type SenderError: std::error::Error; type NetworkSender: NetworkSender; - type PeerId: Clone + Debug + Eq + Hash + Send + 'static; + type PeerId: Clone + Debug + Display + Eq + Hash + Send + 'static; type EventStream: EventStream; /// Returns a stream of events representing what happens on the network. diff --git a/finality-aleph/src/network/gossip/service.rs b/finality-aleph/src/network/gossip/service.rs index f73d4c1c93..f49031a2f9 100644 --- a/finality-aleph/src/network/gossip/service.rs +++ b/finality-aleph/src/network/gossip/service.rs @@ -77,7 +77,9 @@ impl Display for Error { } #[async_trait::async_trait] -impl Network for ServiceInterface { +impl Network + for ServiceInterface +{ type Error = Error; type PeerId = P; diff --git a/finality-aleph/src/network/mod.rs b/finality-aleph/src/network/mod.rs index a9513c111c..ecc86a67d8 100644 --- a/finality-aleph/src/network/mod.rs +++ b/finality-aleph/src/network/mod.rs @@ -1,4 +1,9 @@ +use current_aleph_bft::NodeIndex; use parity_scale_codec::Codec; +use std::collections::HashMap; +use std::sync::Arc; + +use parking_lot::Mutex; pub mod data; mod gossip; @@ -28,3 +33,31 @@ pub trait RequestBlocks: Clone + Send + Sync + 'static { pub trait Data: Clone + Codec + Send + Sync + 'static {} impl Data for D {} + +#[derive(Debug, Clone)] +struct SingleValidatorNetworkDetails { + address: String, + network_level_peer_id: String, + authority_index_in_current_session: Option, +} +pub struct ValidatorsAddressingInfo { + data: Arc>>, +} + +impl ValidatorsAddressingInfo { + pub fn new() -> Self { + ValidatorsAddressingInfo { + data: Arc::new(Mutex::new(HashMap::new())), + } + } + fn update(&self, info: A, network_level_peer_id: String) { + self.data.lock().insert( + info.peer_id().to_string(), + SingleValidatorNetworkDetails { + address: info.internal_protocol_address(), + network_level_peer_id, + authority_index_in_current_session: None, + }, + ); + } +} diff --git a/finality-aleph/src/network/session/manager.rs b/finality-aleph/src/network/session/manager.rs index 6aabd0b7da..014a9ffee4 100644 --- a/finality-aleph/src/network/session/manager.rs +++ b/finality-aleph/src/network/session/manager.rs @@ -1,3 +1,4 @@ +use std::fmt::Display; use std::{ collections::{HashMap, HashSet}, fmt::Debug, @@ -7,6 +8,7 @@ use std::{ use futures::channel::mpsc; use log::{debug, info}; +use crate::network::ValidatorsAddressingInfo; use crate::{ abft::Recipient, crypto::{AuthorityPen, AuthorityVerifier}, @@ -82,6 +84,7 @@ pub struct Manager { network_identity: NI, connections: Connections, sessions: HashMap>, + validators_addressing_info: ValidatorsAddressingInfo, discovery_cooldown: Duration, } @@ -94,11 +97,16 @@ pub enum SendError { impl Manager { /// Create a new connection manager. - pub fn new(network_identity: NI, discovery_cooldown: Duration) -> Self { + pub fn new( + network_identity: NI, + validators_addressing_info: ValidatorsAddressingInfo, + discovery_cooldown: Duration, + ) -> Self { Manager { network_identity, connections: Connections::new(), sessions: HashMap::new(), + validators_addressing_info, discovery_cooldown, } } @@ -303,9 +311,10 @@ impl Manager { /// Handle a discovery message. /// Returns actions the manager wants to take. - pub fn on_discovery_message( + pub fn on_discovery_message( &mut self, message: DiscoveryMessage, + low_level_peer_id: LPID, ) -> ManagerActions { let session_id = message.session_id(); match self.sessions.get_mut(&session_id) { @@ -318,6 +327,8 @@ impl Manager { (Some(address), true) => { debug!(target: "aleph-network", "Adding addresses for session {:?} to reserved: {:?}", session_id, address); self.connections.add_peers(session_id, [address.peer_id()]); + self.validators_addressing_info + .update(address.clone(), low_level_peer_id.to_string()); Some(ConnectionCommand::AddReserved([address].into())) } _ => None, diff --git a/finality-aleph/src/network/session/service.rs b/finality-aleph/src/network/session/service.rs index cd5bc1a5ea..2a496a438a 100644 --- a/finality-aleph/src/network/session/service.rs +++ b/finality-aleph/src/network/session/service.rs @@ -26,7 +26,8 @@ use crate::{ }, AddressingInformation, Data, GossipNetwork, NetworkIdentity, }, - MillisecsPerBlock, NodeIndex, SessionId, SessionPeriod, STATUS_REPORT_INTERVAL, + MillisecsPerBlock, NodeIndex, SessionId, SessionPeriod, ValidatorsAddressingInfo, + STATUS_REPORT_INTERVAL, }; /// Commands for manipulating sessions, stopping them and starting both validator and non-validator @@ -222,6 +223,7 @@ where network_identity: NI, validator_network: CN, gossip_network: GN, + validators_addressing_info: ValidatorsAddressingInfo, config: Config, ) -> ( Service, @@ -232,7 +234,11 @@ where maintenance_period, initial_delay, } = config; - let manager = Manager::new(network_identity, discovery_cooldown); + let manager = Manager::new( + network_identity, + validators_addressing_info, + discovery_cooldown, + ); let (commands_for_service, commands_from_user) = mpsc::unbounded(); let (messages_for_service, messages_from_user) = mpsc::unbounded(); ( @@ -381,11 +387,11 @@ where } }, maybe_authentication = self.gossip_network.next() => { - let (authentication, _) = maybe_authentication.map_err(Error::GossipNetwork)?; + let (authentication, low_level_peer_id) = maybe_authentication.map_err(Error::GossipNetwork)?; trace!(target: "aleph-network", "Manager received an authentication from network"); match authentication.try_into() { Ok(message) => { - let manager_actions = self.manager.on_discovery_message(message); + let manager_actions = self.manager.on_discovery_message(message, low_level_peer_id); self.handle_manager_actions(manager_actions)? }, Err(e) => debug!(target: "aleph-network", "Could not cast versioned authentication in discovery message: {:?}", e), diff --git a/finality-aleph/src/network/tcp.rs b/finality-aleph/src/network/tcp.rs index b863cc11c1..44f20bc631 100644 --- a/finality-aleph/src/network/tcp.rs +++ b/finality-aleph/src/network/tcp.rs @@ -106,6 +106,10 @@ impl AddressingInformation for SignedTcpAddressingInformation { self.peer_id() .verify(&self.addressing_information.encode(), &self.signature) } + + fn internal_protocol_address(&self) -> String { + return self.addressing_information.primary_address.clone(); + } } impl NetworkIdentity for SignedTcpAddressingInformation { diff --git a/finality-aleph/src/nodes.rs b/finality-aleph/src/nodes.rs index c610468ba1..f23e62577c 100644 --- a/finality-aleph/src/nodes.rs +++ b/finality-aleph/src/nodes.rs @@ -71,6 +71,7 @@ where protocol_naming, rate_limiter_config, sync_oracle, + validators_addressing_info, } = aleph_config; // We generate the phrase manually to only save the key in RAM, we don't want to have these @@ -170,6 +171,7 @@ where network_identity, validator_network, authentication_network, + validators_addressing_info, ConnectionManagerConfig::with_session_period(&session_period, &millisecs_per_block), ); From 75e0bd487bec06164ad3f1ee8c04aab28ff232fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20Gawrya=C5=82?= Date: Thu, 12 Oct 2023 13:25:17 +0200 Subject: [PATCH 02/24] Get stash validator id from chain --- bin/node/src/aleph_node_rpc.rs | 2 +- bin/node/src/service.rs | 7 +- bin/runtime/src/lib.rs | 4 + finality-aleph/src/lib.rs | 4 +- finality-aleph/src/network/mock.rs | 10 +- finality-aleph/src/network/mod.rs | 147 +++++++++++++++--- finality-aleph/src/network/session/manager.rs | 40 +++-- finality-aleph/src/network/session/service.rs | 16 +- finality-aleph/src/nodes.rs | 31 ++-- finality-aleph/src/testing/network.rs | 2 + primitives/src/lib.rs | 3 + 11 files changed, 208 insertions(+), 58 deletions(-) diff --git a/bin/node/src/aleph_node_rpc.rs b/bin/node/src/aleph_node_rpc.rs index 3c9b4dbf03..79976007fe 100644 --- a/bin/node/src/aleph_node_rpc.rs +++ b/bin/node/src/aleph_node_rpc.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use finality_aleph::{ - AlephJustification, BlockId, Justification, JustificationTranslator, ValidatorsAddressingInfo, + AlephJustification, BlockId, Justification, JustificationTranslator, ValidatorAddressCache, }; use futures::channel::mpsc; use jsonrpsee::{ diff --git a/bin/node/src/service.rs b/bin/node/src/service.rs index e11eccbf7c..b198e2e967 100644 --- a/bin/node/src/service.rs +++ b/bin/node/src/service.rs @@ -10,7 +10,7 @@ use finality_aleph::{ run_validator_node, AlephBlockImport, AlephConfig, BlockImporter, Justification, JustificationTranslator, MillisecsPerBlock, Protocol, ProtocolNaming, RateLimiterConfig, SessionPeriod, SubstrateChainStatus, SyncOracle, TimingBlockMetrics, TracingBlockImport, - ValidatorsAddressingInfo, + ValidatorAddressCache, }; use futures::channel::mpsc; use log::warn; @@ -404,7 +404,8 @@ pub fn new_authority( .unwrap_or(usize::MAX), }; - let validators_addressing_info = ValidatorsAddressingInfo::new(); + // TODO before this PR: get from runtime instead + let validator_address_cache = ValidatorAddressCache::new(); let aleph_config = AlephConfig { network, @@ -427,7 +428,7 @@ pub fn new_authority( protocol_naming, rate_limiter_config, sync_oracle, - validators_addressing_info, + validator_address_cache, }; task_manager.spawn_essential_handle().spawn_blocking( diff --git a/bin/runtime/src/lib.rs b/bin/runtime/src/lib.rs index 5029e1640d..31a205ea40 100644 --- a/bin/runtime/src/lib.rs +++ b/bin/runtime/src/lib.rs @@ -1013,6 +1013,10 @@ impl_runtime_apis! { ) -> Result, SessionValidatorError> { CommitteeManagement::predict_session_committee_for_session(session) } + + fn aleph_key_owner(key: AlephId) -> Option { + Session::key_owner(primitives::KEY_TYPE, key.as_ref()) + } } impl pallet_nomination_pools_runtime_api::NominationPoolsApi for Runtime { diff --git a/finality-aleph/src/lib.rs b/finality-aleph/src/lib.rs index 3f0ff8e0b5..e6f0e74d1b 100644 --- a/finality-aleph/src/lib.rs +++ b/finality-aleph/src/lib.rs @@ -61,7 +61,7 @@ pub use crate::{ import::{AlephBlockImport, TracingBlockImport}, justification::AlephJustification, metrics::TimingBlockMetrics, - network::{Protocol, ProtocolNaming, ValidatorsAddressingInfo}, + network::{Protocol, ProtocolNaming, ValidatorAddressCache, ValidatorAddressingInfo}, nodes::run_validator_node, session::SessionPeriod, sync::{ @@ -287,5 +287,5 @@ pub struct AlephConfig { pub protocol_naming: ProtocolNaming, pub rate_limiter_config: RateLimiterConfig, pub sync_oracle: SyncOracle, - pub validators_addressing_info: ValidatorsAddressingInfo, + pub validator_address_cache: ValidatorAddressCache, } diff --git a/finality-aleph/src/network/mock.rs b/finality-aleph/src/network/mock.rs index c9b839df5c..634b3d62b0 100644 --- a/finality-aleph/src/network/mock.rs +++ b/finality-aleph/src/network/mock.rs @@ -5,10 +5,12 @@ use parity_scale_codec::{Decode, Encode, Output}; use sp_keystore::{testing::MemoryKeystore as Keystore, Keystore as _}; use tokio::time::timeout; +use crate::network::ValidatorAddressCacheUpdater; +use crate::session::SessionId; use crate::{ aleph_primitives::KEY_TYPE, crypto::{AuthorityPen, AuthorityVerifier}, - AuthorityId, NodeIndex, + AuthorityId, NodeIndex, ValidatorAddressingInfo, }; #[derive(Hash, Debug, Clone, PartialEq, Eq)] @@ -100,6 +102,12 @@ impl Channel { } } +pub struct MockValidatorAddressCacheUpdater; + +impl ValidatorAddressCacheUpdater for MockValidatorAddressCacheUpdater { + fn update(&self, _: SessionId, _: NodeIndex, _: ValidatorAddressingInfo) {} +} + impl Default for Channel { fn default() -> Self { Self::new() diff --git a/finality-aleph/src/network/mod.rs b/finality-aleph/src/network/mod.rs index ecc86a67d8..31cc5dfbd5 100644 --- a/finality-aleph/src/network/mod.rs +++ b/finality-aleph/src/network/mod.rs @@ -1,9 +1,12 @@ -use current_aleph_bft::NodeIndex; +use abft::NodeIndex; use parity_scale_codec::Codec; use std::collections::HashMap; +use std::marker::PhantomData; use std::sync::Arc; use parking_lot::Mutex; +use sc_client_api::Backend; +use sp_runtime::traits::{Block, Header}; pub mod data; mod gossip; @@ -19,9 +22,13 @@ pub use gossip::{ Error as GossipError, Network as GossipNetwork, Protocol, Service as GossipService, }; use network_clique::{AddressingInformation, NetworkIdentity, PeerId}; +use primitives::AlephSessionApi; +use primitives::{AccountId, AuthorityId, BlockHash, BlockNumber}; pub use substrate::{ProtocolNaming, SubstrateNetwork}; -use crate::BlockId; +use crate::session::{SessionBoundaryInfo, SessionId}; +use crate::session_map::AuthorityProvider; +use crate::{abft, BlockId, ClientForAleph}; /// Abstraction for requesting stale blocks. pub trait RequestBlocks: Clone + Send + Sync + 'static { @@ -34,30 +41,132 @@ pub trait Data: Clone + Codec + Send + Sync + 'static {} impl Data for D {} +pub trait KeyOwnerInfoProvider { + fn aleph_key_owner(&self, block_number: BlockNumber, key: AuthorityId) -> Option; +} + +pub struct KeyOwnerInfoProviderImpl +where + C: ClientForAleph + Send + Sync + 'static, + C::Api: crate::aleph_primitives::AlephSessionApi, + B: Block, + BE: Backend + 'static, +{ + client: Arc, + _phantom: PhantomData<(B, BE)>, +} + +impl KeyOwnerInfoProviderImpl +where + C: ClientForAleph + Send + Sync + 'static, + C::Api: crate::aleph_primitives::AlephSessionApi, + B: Block, + B::Header: Header, + BE: Backend + 'static, +{ + pub fn new(client: Arc) -> Self { + Self { + client, + _phantom: PhantomData, + } + } +} + +impl KeyOwnerInfoProvider for KeyOwnerInfoProviderImpl +where + C: ClientForAleph + Send + Sync + 'static, + C::Api: crate::aleph_primitives::AlephSessionApi, + B: Block, + B::Header: Header, + BE: Backend + 'static, +{ + fn aleph_key_owner(&self, block_number: BlockNumber, key: AuthorityId) -> Option { + let block_hash = self.client.block_hash(block_number).ok()??; + self.client + .runtime_api() + .aleph_key_owner(block_hash, key) + .ok()? + } +} + #[derive(Debug, Clone)] -struct SingleValidatorNetworkDetails { - address: String, - network_level_peer_id: String, - authority_index_in_current_session: Option, +pub struct ValidatorAddressingInfo { + pub network_level_address: String, + pub network_level_peer_id: String, + pub validator_network_peer_id: String, } -pub struct ValidatorsAddressingInfo { - data: Arc>>, + +#[derive(Debug, Clone)] +pub struct ValidatorAddressCache { + data: Arc>>, } -impl ValidatorsAddressingInfo { +impl ValidatorAddressCache { pub fn new() -> Self { - ValidatorsAddressingInfo { + Self { data: Arc::new(Mutex::new(HashMap::new())), } } - fn update(&self, info: A, network_level_peer_id: String) { - self.data.lock().insert( - info.peer_id().to_string(), - SingleValidatorNetworkDetails { - address: info.internal_protocol_address(), - network_level_peer_id, - authority_index_in_current_session: None, - }, - ); + + pub fn insert(&self, validator_stash: AccountId, info: ValidatorAddressingInfo) { + self.data.lock().insert(validator_stash, info); + } + + pub fn as_hashmap(&self) -> HashMap { + self.data.lock().clone() + } +} + +pub trait ValidatorAddressCacheUpdater { + /// In session `SessionIndex`, validator `NodeIndex` was using addresses specified in `info`. + fn update(&self, session: SessionId, validator_index: NodeIndex, info: ValidatorAddressingInfo); +} + +pub struct ValidatorAddressCacheUpdaterImpl { + validator_address_cache: ValidatorAddressCache, + key_owner_info_provider: K, + authority_provider: A, + session_boundary_info: SessionBoundaryInfo, +} + +impl ValidatorAddressCacheUpdaterImpl { + pub fn new( + validator_address_cache: ValidatorAddressCache, + key_owner_info_provider: K, + authority_provider: A, + session_boundary_info: SessionBoundaryInfo, + ) -> Self { + Self { + validator_address_cache, + key_owner_info_provider, + authority_provider, + session_boundary_info, + } + } +} + +impl ValidatorAddressCacheUpdater + for ValidatorAddressCacheUpdaterImpl +{ + fn update( + &self, + session: SessionId, + validator_index: NodeIndex, + info: ValidatorAddressingInfo, + ) { + let block = self + .session_boundary_info + .boundaries_for_session(session) + .first_block(); + + if let Some(authority_data) = self.authority_provider.authority_data(block) { + let aleph_key = authority_data.authorities()[validator_index.0].clone(); + if let Some(validator_stash) = self + .key_owner_info_provider + .aleph_key_owner(block, aleph_key) + { + self.validator_address_cache.insert(validator_stash, info); + } + } } } diff --git a/finality-aleph/src/network/session/manager.rs b/finality-aleph/src/network/session/manager.rs index 014a9ffee4..0e39acf354 100644 --- a/finality-aleph/src/network/session/manager.rs +++ b/finality-aleph/src/network/session/manager.rs @@ -8,7 +8,7 @@ use std::{ use futures::channel::mpsc; use log::{debug, info}; -use crate::network::ValidatorsAddressingInfo; +use crate::network::ValidatorAddressCacheUpdater; use crate::{ abft::Recipient, crypto::{AuthorityPen, AuthorityVerifier}, @@ -19,7 +19,7 @@ use crate::{ }, AddressingInformation, Data, NetworkIdentity, PeerId, }, - NodeIndex, SessionId, + NodeIndex, SessionId, ValidatorAddressingInfo, }; /// Commands for manipulating the reserved peers set. @@ -80,11 +80,11 @@ impl ManagerActions { /// 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 { +pub struct Manager { network_identity: NI, connections: Connections, sessions: HashMap>, - validators_addressing_info: ValidatorsAddressingInfo, + validator_address_cache_updater: VU, discovery_cooldown: Duration, } @@ -95,18 +95,18 @@ pub enum SendError { NoSession, } -impl Manager { +impl Manager { /// Create a new connection manager. pub fn new( network_identity: NI, - validators_addressing_info: ValidatorsAddressingInfo, + validator_address_cache_updater: VU, discovery_cooldown: Duration, ) -> Self { Manager { network_identity, connections: Connections::new(), sessions: HashMap::new(), - validators_addressing_info, + validator_address_cache_updater, discovery_cooldown, } } @@ -317,6 +317,7 @@ impl Manager { low_level_peer_id: LPID, ) -> ManagerActions { let session_id = message.session_id(); + let creator = message.0.creator(); match self.sessions.get_mut(&session_id) { Some(Session { handler, discovery, .. @@ -327,8 +328,16 @@ impl Manager { (Some(address), true) => { debug!(target: "aleph-network", "Adding addresses for session {:?} to reserved: {:?}", session_id, address); self.connections.add_peers(session_id, [address.peer_id()]); - self.validators_addressing_info - .update(address.clone(), low_level_peer_id.to_string()); + + self.validator_address_cache_updater.update( + session_id, + creator, + ValidatorAddressingInfo { + network_level_address: address.internal_protocol_address(), + network_level_peer_id: low_level_peer_id.to_string(), + validator_network_peer_id: address.peer_id().to_string(), + }, + ); Some(ConnectionCommand::AddReserved([address].into())) } _ => None, @@ -449,6 +458,7 @@ mod tests { ConnectionCommand, Manager, ManagerActions, PreNonvalidatorSession, PreValidatorSession, SendError, }; + use crate::network::mock::MockValidatorAddressCacheUpdater; use crate::{ network::{mock::crypto_basics, session::data::DataInSession}, Recipient, SessionId, @@ -457,8 +467,12 @@ mod tests { const NUM_NODES: usize = 7; const DISCOVERY_PERIOD: Duration = Duration::from_secs(60); - fn build() -> Manager { - Manager::new(random_address(), DISCOVERY_PERIOD) + fn build() -> Manager { + Manager::new( + random_address(), + MockValidatorAddressCacheUpdater, + DISCOVERY_PERIOD, + ) } #[test] @@ -574,7 +588,7 @@ mod tests { let ManagerActions { maybe_command, maybe_message, - } = manager.on_discovery_message(message); + } = manager.on_discovery_message(message, "mock peer id"); assert_eq!( maybe_command, Some(ConnectionCommand::AddReserved( @@ -609,7 +623,7 @@ mod tests { }) .unwrap(); let message = maybe_message.expect("there should be a discovery message"); - manager.on_discovery_message(message); + manager.on_discovery_message(message, "mock peer id"); let messages = manager.on_user_message(2137, session_id, Recipient::Everyone); assert_eq!(messages.len(), 1); let (network_data, _) = &messages[0]; diff --git a/finality-aleph/src/network/session/service.rs b/finality-aleph/src/network/session/service.rs index 2a496a438a..bac564d3b3 100644 --- a/finality-aleph/src/network/session/service.rs +++ b/finality-aleph/src/network/session/service.rs @@ -12,6 +12,7 @@ use log::{debug, trace, warn}; use network_clique::{Network as CliqueNetwork, PublicKey}; use tokio::time::{self, Instant}; +use crate::network::ValidatorAddressCacheUpdater; use crate::{ abft::Recipient, crypto::{AuthorityPen, AuthorityVerifier}, @@ -26,8 +27,7 @@ use crate::{ }, AddressingInformation, Data, GossipNetwork, NetworkIdentity, }, - MillisecsPerBlock, NodeIndex, SessionId, SessionPeriod, ValidatorsAddressingInfo, - STATUS_REPORT_INTERVAL, + MillisecsPerBlock, NodeIndex, SessionId, SessionPeriod, STATUS_REPORT_INTERVAL, }; /// Commands for manipulating sessions, stopping them and starting both validator and non-validator @@ -177,10 +177,11 @@ pub struct Service< NI: NetworkIdentity, CN: CliqueNetwork>, GN: GossipNetwork>, + VU: ValidatorAddressCacheUpdater, > where NI::PeerId: PublicKey, { - manager: Manager, + manager: Manager, commands_from_user: mpsc::UnboundedReceiver>, messages_from_user: mpsc::UnboundedReceiver<(D, SessionId, Recipient)>, validator_network: CN, @@ -215,7 +216,8 @@ impl< NI: NetworkIdentity, CN: CliqueNetwork>, GN: GossipNetwork>, - > Service + VU: ValidatorAddressCacheUpdater, + > Service where NI::PeerId: PublicKey, { @@ -223,10 +225,10 @@ where network_identity: NI, validator_network: CN, gossip_network: GN, - validators_addressing_info: ValidatorsAddressingInfo, + validator_address_cache_updater: VU, config: Config, ) -> ( - Service, + Service, impl SessionManager, ) { let Config { @@ -236,7 +238,7 @@ where } = config; let manager = Manager::new( network_identity, - validators_addressing_info, + validator_address_cache_updater, discovery_cooldown, ); let (commands_for_service, commands_from_user) = mpsc::unbounded(); diff --git a/finality-aleph/src/nodes.rs b/finality-aleph/src/nodes.rs index f23e62577c..297f8f6efb 100644 --- a/finality-aleph/src/nodes.rs +++ b/finality-aleph/src/nodes.rs @@ -1,14 +1,6 @@ use std::{marker::PhantomData, sync::Arc}; -use bip39::{Language, Mnemonic, MnemonicType}; -use futures::channel::oneshot; -use log::{debug, error}; -use network_clique::{RateLimitingDialer, RateLimitingListener, Service, SpawnHandleT}; -use rate_limiter::SleepingRateLimiter; -use sc_client_api::Backend; -use sp_consensus::SelectChain; -use sp_keystore::Keystore; - +use crate::network::KeyOwnerInfoProviderImpl; use crate::{ aleph_primitives::Block, crypto::AuthorityPen, @@ -16,7 +8,7 @@ use crate::{ network::{ session::{ConnectionManager, ConnectionManagerConfig}, tcp::{new_tcp_network, KEY_TYPE}, - GossipService, SubstrateNetwork, + GossipService, SubstrateNetwork, ValidatorAddressCacheUpdaterImpl, }, party::{ impls::ChainStateImpl, manager::NodeSessionManagerImpl, ConsensusParty, @@ -31,6 +23,14 @@ use crate::{ }, AlephConfig, }; +use bip39::{Language, Mnemonic, MnemonicType}; +use futures::channel::oneshot; +use log::{debug, error}; +use network_clique::{RateLimitingDialer, RateLimitingListener, Service, SpawnHandleT}; +use rate_limiter::SleepingRateLimiter; +use sc_client_api::Backend; +use sp_consensus::SelectChain; +use sp_keystore::Keystore; // How many sessions we remember. pub const VERIFIER_CACHE_SIZE: usize = 2; @@ -71,7 +71,7 @@ where protocol_naming, rate_limiter_config, sync_oracle, - validators_addressing_info, + validator_address_cache, } = aleph_config; // We generate the phrase manually to only save the key in RAM, we don't want to have these @@ -167,11 +167,18 @@ where }; let sync_task = async move { sync_service.run().await }; + let validator_address_cache_updater = ValidatorAddressCacheUpdaterImpl::new( + validator_address_cache.clone(), + KeyOwnerInfoProviderImpl::new(client.clone()), + AuthorityProviderImpl::new(client.clone()), + session_info.clone(), + ); + let (connection_manager_service, connection_manager) = ConnectionManager::new( network_identity, validator_network, authentication_network, - validators_addressing_info, + validator_address_cache_updater, ConnectionManagerConfig::with_session_period(&session_period, &millisecs_per_block), ); diff --git a/finality-aleph/src/testing/network.rs b/finality-aleph/src/testing/network.rs index 168986a2a3..53c044fa69 100644 --- a/finality-aleph/src/testing/network.rs +++ b/finality-aleph/src/testing/network.rs @@ -16,6 +16,7 @@ use parity_scale_codec::{Decode, Encode}; use sc_service::TaskManager; use tokio::{runtime::Handle, task::JoinHandle, time::timeout}; +use crate::network::mock::MockValidatorAddressCacheUpdater; use crate::{ crypto::{AuthorityPen, AuthorityVerifier}, network::{ @@ -110,6 +111,7 @@ async fn prepare_one_session_test_data() -> TestData { authorities[0].address(), validator_network.clone(), gossip_network, + MockValidatorAddressCacheUpdater, ConnectionManagerConfig::with_session_period(&SESSION_PERIOD, &MILLISECS_PER_BLOCK), ); let session_manager = Box::new(session_manager); diff --git a/primitives/src/lib.rs b/primitives/src/lib.rs index a48c3c1e7d..64669576fc 100644 --- a/primitives/src/lib.rs +++ b/primitives/src/lib.rs @@ -290,6 +290,9 @@ sp_api::decl_runtime_apis! { fn predict_session_committee( session: SessionIndex ) -> Result, SessionValidatorError>; + + /// Allows to get owner's AccountId for an Aleph key used in the current session. + fn aleph_key_owner(key: AuthorityId) -> Option; } } From dd5dee65a5242a688fa001055e142cf43604dfff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20Gawrya=C5=82?= Date: Thu, 12 Oct 2023 14:50:26 +0200 Subject: [PATCH 03/24] Move address cache to separate file --- finality-aleph/src/lib.rs | 7 +- finality-aleph/src/network/address_cache.rs | 153 ++++++++++++++++++ finality-aleph/src/network/mock.rs | 4 +- finality-aleph/src/network/mod.rs | 146 +---------------- finality-aleph/src/network/session/manager.rs | 13 +- finality-aleph/src/network/session/service.rs | 2 +- finality-aleph/src/nodes.rs | 21 +-- finality-aleph/src/testing/network.rs | 3 +- 8 files changed, 183 insertions(+), 166 deletions(-) create mode 100644 finality-aleph/src/network/address_cache.rs diff --git a/finality-aleph/src/lib.rs b/finality-aleph/src/lib.rs index e6f0e74d1b..8d7f6fd841 100644 --- a/finality-aleph/src/lib.rs +++ b/finality-aleph/src/lib.rs @@ -17,7 +17,7 @@ use sc_client_api::{ Backend, BlockBackend, BlockchainEvents, Finalizer, LockImportRun, TransactionFor, }; use sc_consensus::BlockImport; -use sc_network::NetworkService; +use sc_network::{config::NonReservedPeerMode, NetworkService}; use sc_network_sync::SyncingService; use sp_api::ProvideRuntimeApi; use sp_blockchain::{HeaderBackend, HeaderMetadata}; @@ -61,7 +61,10 @@ pub use crate::{ import::{AlephBlockImport, TracingBlockImport}, justification::AlephJustification, metrics::TimingBlockMetrics, - network::{Protocol, ProtocolNaming, ValidatorAddressCache, ValidatorAddressingInfo}, + network::{ + address_cache::{ValidatorAddressCache, ValidatorAddressingInfo}, + Protocol, ProtocolNaming, + }, nodes::run_validator_node, session::SessionPeriod, sync::{ diff --git a/finality-aleph/src/network/address_cache.rs b/finality-aleph/src/network/address_cache.rs new file mode 100644 index 0000000000..c9b7fbcbf2 --- /dev/null +++ b/finality-aleph/src/network/address_cache.rs @@ -0,0 +1,153 @@ +use std::{collections::HashMap, marker::PhantomData, sync::Arc}; + +use parking_lot::Mutex; +use primitives::{AccountId, AlephSessionApi, AuthorityId, BlockHash, BlockNumber}; +use sc_client_api::Backend; +use sp_runtime::traits::{Block, Header}; + +use crate::{ + abft::NodeIndex, + session::{SessionBoundaryInfo, SessionId}, + session_map::AuthorityProvider, + ClientForAleph, +}; + +pub trait KeyOwnerInfoProvider { + fn aleph_key_owner(&self, block_number: BlockNumber, key: AuthorityId) -> Option; +} + +/// Network details for a given validator. This information is purely informational +/// and can change over time, even within a session. +#[derive(Debug, Clone)] +pub struct ValidatorAddressingInfo { + pub network_level_address: String, + pub network_level_peer_id: String, + pub validator_network_peer_id: String, +} + +/// Stores most recent information about validator addresses. +/// TODO: Consider using LruCache there. +#[derive(Debug, Clone)] +pub struct ValidatorAddressCache { + data: Arc>>, +} + +impl ValidatorAddressCache { + pub fn new() -> Self { + Self { + data: Arc::new(Mutex::new(HashMap::new())), + } + } + + pub fn insert(&self, validator_stash: AccountId, info: ValidatorAddressingInfo) { + self.data.lock().insert(validator_stash, info); + } + + pub fn as_hashmap(&self) -> HashMap { + self.data.lock().clone() + } +} + +pub trait ValidatorAddressCacheUpdater { + /// In session `SessionIndex`, validator `NodeIndex` was using addresses specified in `most_recent_info`. + /// A session and validator_index identify the validator uniquely. + fn update( + &self, + session: SessionId, + validator_index: NodeIndex, + most_recent_info: ValidatorAddressingInfo, + ); +} + +pub struct ValidatorAddressCacheUpdaterImpl { + validator_address_cache: ValidatorAddressCache, + key_owner_info_provider: K, + authority_provider: A, + session_boundary_info: SessionBoundaryInfo, +} + +impl ValidatorAddressCacheUpdaterImpl { + pub fn new( + validator_address_cache: ValidatorAddressCache, + key_owner_info_provider: K, + authority_provider: A, + session_boundary_info: SessionBoundaryInfo, + ) -> Self { + Self { + validator_address_cache, + key_owner_info_provider, + authority_provider, + session_boundary_info, + } + } +} + +impl ValidatorAddressCacheUpdater + for ValidatorAddressCacheUpdaterImpl +{ + fn update( + &self, + session: SessionId, + validator_index: NodeIndex, + info: ValidatorAddressingInfo, + ) { + let block = self + .session_boundary_info + .boundaries_for_session(session) + .first_block(); + + if let Some(authority_data) = self.authority_provider.authority_data(block) { + let aleph_key = authority_data.authorities()[validator_index.0].clone(); + if let Some(validator_stash) = self + .key_owner_info_provider + .aleph_key_owner(block, aleph_key) + { + self.validator_address_cache.insert(validator_stash, info); + } + } + } +} + +pub struct KeyOwnerInfoProviderImpl +where + C: ClientForAleph + Send + Sync + 'static, + C::Api: crate::aleph_primitives::AlephSessionApi, + B: Block, + BE: Backend + 'static, +{ + client: Arc, + _phantom: PhantomData<(B, BE)>, +} + +impl KeyOwnerInfoProviderImpl +where + C: ClientForAleph + Send + Sync + 'static, + C::Api: crate::aleph_primitives::AlephSessionApi, + B: Block, + B::Header: Header, + BE: Backend + 'static, +{ + pub fn new(client: Arc) -> Self { + Self { + client, + _phantom: PhantomData, + } + } +} + +impl KeyOwnerInfoProvider for KeyOwnerInfoProviderImpl +where + C: ClientForAleph + Send + Sync + 'static, + C::Api: crate::aleph_primitives::AlephSessionApi, + B: Block, + B::Header: Header, + BE: Backend + 'static, +{ + fn aleph_key_owner(&self, block_number: BlockNumber, key: AuthorityId) -> Option { + let block_hash = self.client.block_hash(block_number).ok()??; + self.client + .runtime_api() + .aleph_key_owner(block_hash, key) + .ok()? + } +} diff --git a/finality-aleph/src/network/mock.rs b/finality-aleph/src/network/mock.rs index 634b3d62b0..ade78b51f8 100644 --- a/finality-aleph/src/network/mock.rs +++ b/finality-aleph/src/network/mock.rs @@ -5,11 +5,11 @@ use parity_scale_codec::{Decode, Encode, Output}; use sp_keystore::{testing::MemoryKeystore as Keystore, Keystore as _}; use tokio::time::timeout; -use crate::network::ValidatorAddressCacheUpdater; -use crate::session::SessionId; use crate::{ aleph_primitives::KEY_TYPE, crypto::{AuthorityPen, AuthorityVerifier}, + network::address_cache::ValidatorAddressCacheUpdater, + session::SessionId, AuthorityId, NodeIndex, ValidatorAddressingInfo, }; diff --git a/finality-aleph/src/network/mod.rs b/finality-aleph/src/network/mod.rs index 31cc5dfbd5..8e660c2fca 100644 --- a/finality-aleph/src/network/mod.rs +++ b/finality-aleph/src/network/mod.rs @@ -1,13 +1,7 @@ -use abft::NodeIndex; use parity_scale_codec::Codec; -use std::collections::HashMap; -use std::marker::PhantomData; -use std::sync::Arc; - -use parking_lot::Mutex; -use sc_client_api::Backend; -use sp_runtime::traits::{Block, Header}; +use sp_runtime::traits::Block; +pub mod address_cache; pub mod data; mod gossip; #[cfg(test)] @@ -22,13 +16,9 @@ pub use gossip::{ Error as GossipError, Network as GossipNetwork, Protocol, Service as GossipService, }; use network_clique::{AddressingInformation, NetworkIdentity, PeerId}; -use primitives::AlephSessionApi; -use primitives::{AccountId, AuthorityId, BlockHash, BlockNumber}; pub use substrate::{ProtocolNaming, SubstrateNetwork}; -use crate::session::{SessionBoundaryInfo, SessionId}; -use crate::session_map::AuthorityProvider; -use crate::{abft, BlockId, ClientForAleph}; +use crate::BlockId; /// Abstraction for requesting stale blocks. pub trait RequestBlocks: Clone + Send + Sync + 'static { @@ -40,133 +30,3 @@ pub trait RequestBlocks: Clone + Send + Sync + 'static { pub trait Data: Clone + Codec + Send + Sync + 'static {} impl Data for D {} - -pub trait KeyOwnerInfoProvider { - fn aleph_key_owner(&self, block_number: BlockNumber, key: AuthorityId) -> Option; -} - -pub struct KeyOwnerInfoProviderImpl -where - C: ClientForAleph + Send + Sync + 'static, - C::Api: crate::aleph_primitives::AlephSessionApi, - B: Block, - BE: Backend + 'static, -{ - client: Arc, - _phantom: PhantomData<(B, BE)>, -} - -impl KeyOwnerInfoProviderImpl -where - C: ClientForAleph + Send + Sync + 'static, - C::Api: crate::aleph_primitives::AlephSessionApi, - B: Block, - B::Header: Header, - BE: Backend + 'static, -{ - pub fn new(client: Arc) -> Self { - Self { - client, - _phantom: PhantomData, - } - } -} - -impl KeyOwnerInfoProvider for KeyOwnerInfoProviderImpl -where - C: ClientForAleph + Send + Sync + 'static, - C::Api: crate::aleph_primitives::AlephSessionApi, - B: Block, - B::Header: Header, - BE: Backend + 'static, -{ - fn aleph_key_owner(&self, block_number: BlockNumber, key: AuthorityId) -> Option { - let block_hash = self.client.block_hash(block_number).ok()??; - self.client - .runtime_api() - .aleph_key_owner(block_hash, key) - .ok()? - } -} - -#[derive(Debug, Clone)] -pub struct ValidatorAddressingInfo { - pub network_level_address: String, - pub network_level_peer_id: String, - pub validator_network_peer_id: String, -} - -#[derive(Debug, Clone)] -pub struct ValidatorAddressCache { - data: Arc>>, -} - -impl ValidatorAddressCache { - pub fn new() -> Self { - Self { - data: Arc::new(Mutex::new(HashMap::new())), - } - } - - pub fn insert(&self, validator_stash: AccountId, info: ValidatorAddressingInfo) { - self.data.lock().insert(validator_stash, info); - } - - pub fn as_hashmap(&self) -> HashMap { - self.data.lock().clone() - } -} - -pub trait ValidatorAddressCacheUpdater { - /// In session `SessionIndex`, validator `NodeIndex` was using addresses specified in `info`. - fn update(&self, session: SessionId, validator_index: NodeIndex, info: ValidatorAddressingInfo); -} - -pub struct ValidatorAddressCacheUpdaterImpl { - validator_address_cache: ValidatorAddressCache, - key_owner_info_provider: K, - authority_provider: A, - session_boundary_info: SessionBoundaryInfo, -} - -impl ValidatorAddressCacheUpdaterImpl { - pub fn new( - validator_address_cache: ValidatorAddressCache, - key_owner_info_provider: K, - authority_provider: A, - session_boundary_info: SessionBoundaryInfo, - ) -> Self { - Self { - validator_address_cache, - key_owner_info_provider, - authority_provider, - session_boundary_info, - } - } -} - -impl ValidatorAddressCacheUpdater - for ValidatorAddressCacheUpdaterImpl -{ - fn update( - &self, - session: SessionId, - validator_index: NodeIndex, - info: ValidatorAddressingInfo, - ) { - let block = self - .session_boundary_info - .boundaries_for_session(session) - .first_block(); - - if let Some(authority_data) = self.authority_provider.authority_data(block) { - let aleph_key = authority_data.authorities()[validator_index.0].clone(); - if let Some(validator_stash) = self - .key_owner_info_provider - .aleph_key_owner(block, aleph_key) - { - self.validator_address_cache.insert(validator_stash, info); - } - } - } -} diff --git a/finality-aleph/src/network/session/manager.rs b/finality-aleph/src/network/session/manager.rs index 0e39acf354..9ad91c9f0a 100644 --- a/finality-aleph/src/network/session/manager.rs +++ b/finality-aleph/src/network/session/manager.rs @@ -1,25 +1,24 @@ -use std::fmt::Display; use std::{ collections::{HashMap, HashSet}, - fmt::Debug, + fmt::{Debug, Display}, time::Duration, }; use futures::channel::mpsc; use log::{debug, info}; -use crate::network::ValidatorAddressCacheUpdater; use crate::{ abft::Recipient, crypto::{AuthorityPen, AuthorityVerifier}, network::{ + address_cache::{ValidatorAddressCacheUpdater, ValidatorAddressingInfo}, session::{ data::DataInSession, Authentication, Connections, Discovery, DiscoveryMessage, SessionHandler, SessionHandlerError, }, AddressingInformation, Data, NetworkIdentity, PeerId, }, - NodeIndex, SessionId, ValidatorAddressingInfo, + NodeIndex, SessionId, }; /// Commands for manipulating the reserved peers set. @@ -458,9 +457,11 @@ mod tests { ConnectionCommand, Manager, ManagerActions, PreNonvalidatorSession, PreValidatorSession, SendError, }; - use crate::network::mock::MockValidatorAddressCacheUpdater; use crate::{ - network::{mock::crypto_basics, session::data::DataInSession}, + network::{ + mock::{crypto_basics, MockValidatorAddressCacheUpdater}, + session::data::DataInSession, + }, Recipient, SessionId, }; diff --git a/finality-aleph/src/network/session/service.rs b/finality-aleph/src/network/session/service.rs index bac564d3b3..5ce40caa46 100644 --- a/finality-aleph/src/network/session/service.rs +++ b/finality-aleph/src/network/session/service.rs @@ -12,11 +12,11 @@ use log::{debug, trace, warn}; use network_clique::{Network as CliqueNetwork, PublicKey}; use tokio::time::{self, Instant}; -use crate::network::ValidatorAddressCacheUpdater; use crate::{ abft::Recipient, crypto::{AuthorityPen, AuthorityVerifier}, network::{ + address_cache::ValidatorAddressCacheUpdater, session::{ data::DataInSession, manager::{ diff --git a/finality-aleph/src/nodes.rs b/finality-aleph/src/nodes.rs index 297f8f6efb..a3dcb286eb 100644 --- a/finality-aleph/src/nodes.rs +++ b/finality-aleph/src/nodes.rs @@ -1,14 +1,23 @@ use std::{marker::PhantomData, sync::Arc}; -use crate::network::KeyOwnerInfoProviderImpl; +use bip39::{Language, Mnemonic, MnemonicType}; +use futures::channel::oneshot; +use log::{debug, error}; +use network_clique::{RateLimitingDialer, RateLimitingListener, Service, SpawnHandleT}; +use rate_limiter::SleepingRateLimiter; +use sc_client_api::Backend; +use sp_consensus::SelectChain; +use sp_keystore::Keystore; + use crate::{ aleph_primitives::Block, crypto::AuthorityPen, finalization::AlephFinalizer, network::{ + address_cache::{KeyOwnerInfoProviderImpl, ValidatorAddressCacheUpdaterImpl}, session::{ConnectionManager, ConnectionManagerConfig}, tcp::{new_tcp_network, KEY_TYPE}, - GossipService, SubstrateNetwork, ValidatorAddressCacheUpdaterImpl, + GossipService, SubstrateNetwork, }, party::{ impls::ChainStateImpl, manager::NodeSessionManagerImpl, ConsensusParty, @@ -23,14 +32,6 @@ use crate::{ }, AlephConfig, }; -use bip39::{Language, Mnemonic, MnemonicType}; -use futures::channel::oneshot; -use log::{debug, error}; -use network_clique::{RateLimitingDialer, RateLimitingListener, Service, SpawnHandleT}; -use rate_limiter::SleepingRateLimiter; -use sc_client_api::Backend; -use sp_consensus::SelectChain; -use sp_keystore::Keystore; // How many sessions we remember. pub const VERIFIER_CACHE_SIZE: usize = 2; diff --git a/finality-aleph/src/testing/network.rs b/finality-aleph/src/testing/network.rs index 53c044fa69..d617fe1f17 100644 --- a/finality-aleph/src/testing/network.rs +++ b/finality-aleph/src/testing/network.rs @@ -16,12 +16,11 @@ use parity_scale_codec::{Decode, Encode}; use sc_service::TaskManager; use tokio::{runtime::Handle, task::JoinHandle, time::timeout}; -use crate::network::mock::MockValidatorAddressCacheUpdater; use crate::{ crypto::{AuthorityPen, AuthorityVerifier}, network::{ data::Network, - mock::{crypto_basics, MockData}, + mock::{crypto_basics, MockData, MockValidatorAddressCacheUpdater}, session::{ authentication, ConnectionManager, ConnectionManagerConfig, DataInSession, ManagerError, SessionHandler, SessionManager, VersionedAuthentication, From b944a559f88d30b333c360ed91dcff9cc5a8ec57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20Gawrya=C5=82?= Date: Tue, 17 Oct 2023 12:23:01 +0200 Subject: [PATCH 04/24] Add rpc call --- bin/node/src/aleph_node_rpc.rs | 12 ++++++ bin/node/src/rpc.rs | 5 ++- bin/node/src/service.rs | 42 ++++++++++++------- finality-aleph/src/network/address_cache.rs | 9 ++-- finality-aleph/src/network/mod.rs | 1 - finality-aleph/src/network/session/manager.rs | 13 +++++- 6 files changed, 59 insertions(+), 23 deletions(-) diff --git a/bin/node/src/aleph_node_rpc.rs b/bin/node/src/aleph_node_rpc.rs index 79976007fe..d7a5870dd7 100644 --- a/bin/node/src/aleph_node_rpc.rs +++ b/bin/node/src/aleph_node_rpc.rs @@ -1,7 +1,9 @@ +use std::collections::HashMap; use std::sync::Arc; use finality_aleph::{ AlephJustification, BlockId, Justification, JustificationTranslator, ValidatorAddressCache, + ValidatorAddressingInfo, }; use futures::channel::mpsc; use jsonrpsee::{ @@ -158,6 +160,9 @@ pub trait AlephNodeApi { /// #[method(name = "ready")] fn ready(&self) -> RpcResult; + + #[method(name = "validatorNetworkInfo")] + fn validator_network_info(&self) -> RpcResult>; } /// Aleph Node API implementation @@ -166,6 +171,7 @@ pub struct AlephNode { justification_translator: JustificationTranslator, client: Arc, sync_oracle: SO, + validator_address_cache: ValidatorAddressCache, } impl AlephNode @@ -177,12 +183,14 @@ where justification_translator: JustificationTranslator, client: Arc, sync_oracle: SO, + validator_address_cache: ValidatorAddressCache, ) -> Self { AlephNode { import_justification_tx, justification_translator, client, sync_oracle, + validator_address_cache, } } } @@ -250,6 +258,10 @@ where fn ready(&self) -> RpcResult { Ok(!self.sync_oracle.is_offline() && !self.sync_oracle.is_major_syncing()) } + + fn validator_network_info(&self) -> RpcResult> { + self.Ok(self.validator_address_cache.as_hashmap()) + } } fn read_storage< diff --git a/bin/node/src/rpc.rs b/bin/node/src/rpc.rs index e201fac646..c622196802 100644 --- a/bin/node/src/rpc.rs +++ b/bin/node/src/rpc.rs @@ -8,7 +8,7 @@ use std::sync::Arc; use aleph_runtime::{opaque::Block, AccountId, Balance, Nonce}; -use finality_aleph::{Justification, JustificationTranslator}; +use finality_aleph::{Justification, JustificationTranslator, ValidatorAddressCache}; use futures::channel::mpsc; use jsonrpsee::RpcModule; use sc_client_api::StorageProvider; @@ -30,6 +30,7 @@ pub struct FullDeps { pub import_justification_tx: mpsc::UnboundedSender, pub justification_translator: JustificationTranslator, pub sync_oracle: SO, + pub validator_address_cache: ValidatorAddressCache, } /// Instantiate all full RPC extensions. @@ -62,6 +63,7 @@ where import_justification_tx, justification_translator, sync_oracle, + validator_address_cache, } = deps; module.merge(System::new(client.clone(), pool, deny_unsafe).into_rpc())?; @@ -75,6 +77,7 @@ where justification_translator, client, sync_oracle, + validator_address_cache, ) .into_rpc(), )?; diff --git a/bin/node/src/service.rs b/bin/node/src/service.rs index b198e2e967..4681439fe9 100644 --- a/bin/node/src/service.rs +++ b/bin/node/src/service.rs @@ -222,6 +222,7 @@ fn setup( ProtocolNaming, NetworkStarter, SyncOracle, + ValidatorAddressCache, ), ServiceError, > { @@ -258,10 +259,12 @@ fn setup( })?; let sync_oracle = SyncOracle::new(); + let validator_address_cache = ValidatorAddressCache::new(); let rpc_builder = { let client = client.clone(); let pool = transaction_pool.clone(); let sync_oracle = sync_oracle.clone(); + let validator_address_cache = validator_address_cache.clone(); Box::new(move |deny_unsafe, _| { let deps = RpcFullDeps { client: client.clone(), @@ -270,6 +273,7 @@ fn setup( import_justification_tx: import_justification_tx.clone(), justification_translator: JustificationTranslator::new(chain_status.clone()), sync_oracle: sync_oracle.clone(), + validator_address_cache: validator_address_cache.clone(), }; Ok(create_full_rpc(deps)?) @@ -298,6 +302,7 @@ fn setup( protocol_naming, network_starter, sync_oracle, + validator_address_cache, )) } @@ -334,19 +339,27 @@ pub fn new_authority( let chain_status = SubstrateChainStatus::new(backend.clone()) .map_err(|e| ServiceError::Other(format!("failed to set up chain status: {e}")))?; - let (_rpc_handlers, network, sync_network, protocol_naming, network_starter, sync_oracle) = - setup( - config, - backend, - chain_status.clone(), - &keystore_container, - import_queue, - transaction_pool.clone(), - &mut task_manager, - client.clone(), - &mut telemetry, - justification_tx, - )?; + + let ( + _rpc_handlers, + network, + sync_network, + protocol_naming, + network_starter, + sync_oracle, + validator_address_cache, + ) = setup( + config, + backend, + chain_status.clone(), + &keystore_container, + import_queue, + transaction_pool.clone(), + &mut task_manager, + client.clone(), + &mut telemetry, + justification_tx, + )?; let mut proposer_factory = sc_basic_authorship::ProposerFactory::new( task_manager.spawn_handle(), @@ -404,9 +417,6 @@ pub fn new_authority( .unwrap_or(usize::MAX), }; - // TODO before this PR: get from runtime instead - let validator_address_cache = ValidatorAddressCache::new(); - let aleph_config = AlephConfig { network, sync_network, diff --git a/finality-aleph/src/network/address_cache.rs b/finality-aleph/src/network/address_cache.rs index c9b7fbcbf2..73a30543af 100644 --- a/finality-aleph/src/network/address_cache.rs +++ b/finality-aleph/src/network/address_cache.rs @@ -3,6 +3,7 @@ use std::{collections::HashMap, marker::PhantomData, sync::Arc}; use parking_lot::Mutex; use primitives::{AccountId, AlephSessionApi, AuthorityId, BlockHash, BlockNumber}; use sc_client_api::Backend; +use serde::{Deserialize, Serialize}; use sp_runtime::traits::{Block, Header}; use crate::{ @@ -16,12 +17,12 @@ pub trait KeyOwnerInfoProvider { fn aleph_key_owner(&self, block_number: BlockNumber, key: AuthorityId) -> Option; } -/// Network details for a given validator. This information is purely informational -/// and can change over time, even within a session. -#[derive(Debug, Clone)] +/// Network details for a given validator. This data is purely informational +/// and can change over time, even within a single session. +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct ValidatorAddressingInfo { pub network_level_address: String, - pub network_level_peer_id: String, + pub network_level_peer_id: Option, pub validator_network_peer_id: String, } diff --git a/finality-aleph/src/network/mod.rs b/finality-aleph/src/network/mod.rs index 8e660c2fca..3b209ef808 100644 --- a/finality-aleph/src/network/mod.rs +++ b/finality-aleph/src/network/mod.rs @@ -1,5 +1,4 @@ use parity_scale_codec::Codec; -use sp_runtime::traits::Block; pub mod address_cache; pub mod data; diff --git a/finality-aleph/src/network/session/manager.rs b/finality-aleph/src/network/session/manager.rs index 9ad91c9f0a..35374d958f 100644 --- a/finality-aleph/src/network/session/manager.rs +++ b/finality-aleph/src/network/session/manager.rs @@ -212,6 +212,17 @@ impl Manager Manager Date: Tue, 17 Oct 2023 16:41:52 +0200 Subject: [PATCH 05/24] Use p2p peerid information from substrate --- bin/node/src/aleph_node_rpc.rs | 63 ++++++++++++++++--- bin/node/src/rpc.rs | 5 ++ bin/node/src/service.rs | 2 + finality-aleph/src/network/address_cache.rs | 8 ++- finality-aleph/src/network/session/manager.rs | 13 ++-- finality-aleph/src/network/session/service.rs | 4 +- finality-aleph/src/network/tcp.rs | 11 +++- finality-aleph/src/nodes.rs | 4 +- 8 files changed, 91 insertions(+), 19 deletions(-) diff --git a/bin/node/src/aleph_node_rpc.rs b/bin/node/src/aleph_node_rpc.rs index d7a5870dd7..0ed8c33b19 100644 --- a/bin/node/src/aleph_node_rpc.rs +++ b/bin/node/src/aleph_node_rpc.rs @@ -1,5 +1,4 @@ -use std::collections::HashMap; -use std::sync::Arc; +use std::{collections::HashMap, net::IpAddr, sync::Arc}; use finality_aleph::{ AlephJustification, BlockId, Justification, JustificationTranslator, ValidatorAddressCache, @@ -7,13 +6,14 @@ use finality_aleph::{ }; use futures::channel::mpsc; use jsonrpsee::{ - core::{error::Error as JsonRpseeError, RpcResult}, + core::{async_trait, error::Error as JsonRpseeError, RpcResult}, proc_macros::rpc, types::error::{CallError, ErrorObject}, }; use parity_scale_codec::Decode; -use primitives::{AccountId, Block, BlockHash, BlockNumber, Signature}; +use primitives::{AccountId, Block, BlockHash, BlockNumber, Hash, Signature}; use sc_client_api::StorageProvider; +use sc_network::{multiaddr::Protocol, network_state::NetworkState, Multiaddr, NetworkService}; use sp_arithmetic::traits::Zero; use sp_blockchain::HeaderBackend; use sp_consensus::SyncOracle; @@ -162,7 +162,9 @@ pub trait AlephNodeApi { fn ready(&self) -> RpcResult; #[method(name = "validatorNetworkInfo")] - fn validator_network_info(&self) -> RpcResult>; + async fn validator_network_info( + &self, + ) -> RpcResult>; } /// Aleph Node API implementation @@ -172,6 +174,7 @@ pub struct AlephNode { client: Arc, sync_oracle: SO, validator_address_cache: ValidatorAddressCache, + network: Arc>, } impl AlephNode @@ -184,6 +187,7 @@ where client: Arc, sync_oracle: SO, validator_address_cache: ValidatorAddressCache, + network: Arc>, ) -> Self { AlephNode { import_justification_tx, @@ -191,10 +195,12 @@ where client, sync_oracle, validator_address_cache, + network, } } } +#[async_trait] impl AlephNodeApiServer for AlephNode where BE: sc_client_api::Backend + 'static, @@ -259,9 +265,52 @@ where Ok(!self.sync_oracle.is_offline() && !self.sync_oracle.is_major_syncing()) } - fn validator_network_info(&self) -> RpcResult> { - self.Ok(self.validator_address_cache.as_hashmap()) + async fn validator_network_info( + &self, + ) -> RpcResult> { + let mut info = self.validator_address_cache.as_hashmap(); + if let Ok(network_state) = self.network.network_state().await { + add_p2p_peer_id_to_validator_addressing_info(&mut info, network_state); + } + Ok(info) + } +} + +fn add_p2p_peer_id_to_validator_addressing_info( + info: &mut HashMap, + network_state: NetworkState, +) { + let mut ip_to_peer_id = HashMap::new(); + network_state + .connected_peers + .iter() + .flat_map(|(peer_id, peer)| peer.known_addresses.iter().map(move |addr| (addr, peer_id))) + .for_each(|(addr, peer_id)| { + if let Some(ip_address) = try_to_ip_addr(addr) { + ip_to_peer_id + .entry(ip_address) + .or_insert(vec![]) + .push(peer_id.clone()); + } + }); + for (_, info) in info.iter_mut() { + if let Ok(addr) = info.network_level_address.parse::() { + if let Some(peer_ids) = ip_to_peer_id.get(&addr) { + info.potential_p2p_network_peer_ids = peer_ids.clone(); + } + } + } +} + +fn try_to_ip_addr(multiaddr: &Multiaddr) -> Option { + for component in multiaddr.iter() { + if let Protocol::Ip4(addr) = component { + return Some(IpAddr::V4(addr)); + } else if let Protocol::Ip6(addr) = component { + return Some(IpAddr::V6(addr)); + } } + None } fn read_storage< diff --git a/bin/node/src/rpc.rs b/bin/node/src/rpc.rs index c622196802..97cbe6c7b7 100644 --- a/bin/node/src/rpc.rs +++ b/bin/node/src/rpc.rs @@ -11,7 +11,9 @@ use aleph_runtime::{opaque::Block, AccountId, Balance, Nonce}; use finality_aleph::{Justification, JustificationTranslator, ValidatorAddressCache}; use futures::channel::mpsc; use jsonrpsee::RpcModule; +use primitives::Hash; use sc_client_api::StorageProvider; +use sc_network::NetworkService; pub use sc_rpc_api::DenyUnsafe; use sc_transaction_pool_api::TransactionPool; use sp_api::ProvideRuntimeApi; @@ -31,6 +33,7 @@ pub struct FullDeps { pub justification_translator: JustificationTranslator, pub sync_oracle: SO, pub validator_address_cache: ValidatorAddressCache, + pub network: Arc>, } /// Instantiate all full RPC extensions. @@ -64,6 +67,7 @@ where justification_translator, sync_oracle, validator_address_cache, + network, } = deps; module.merge(System::new(client.clone(), pool, deny_unsafe).into_rpc())?; @@ -78,6 +82,7 @@ where client, sync_oracle, validator_address_cache, + network, ) .into_rpc(), )?; diff --git a/bin/node/src/service.rs b/bin/node/src/service.rs index 4681439fe9..72c38983b7 100644 --- a/bin/node/src/service.rs +++ b/bin/node/src/service.rs @@ -265,6 +265,7 @@ fn setup( let pool = transaction_pool.clone(); let sync_oracle = sync_oracle.clone(); let validator_address_cache = validator_address_cache.clone(); + let network = network.clone(); Box::new(move |deny_unsafe, _| { let deps = RpcFullDeps { client: client.clone(), @@ -274,6 +275,7 @@ fn setup( justification_translator: JustificationTranslator::new(chain_status.clone()), sync_oracle: sync_oracle.clone(), validator_address_cache: validator_address_cache.clone(), + network: network.clone(), }; Ok(create_full_rpc(deps)?) diff --git a/finality-aleph/src/network/address_cache.rs b/finality-aleph/src/network/address_cache.rs index 73a30543af..04378594f1 100644 --- a/finality-aleph/src/network/address_cache.rs +++ b/finality-aleph/src/network/address_cache.rs @@ -22,7 +22,7 @@ pub trait KeyOwnerInfoProvider { #[derive(Debug, Clone, Serialize, Deserialize)] pub struct ValidatorAddressingInfo { pub network_level_address: String, - pub network_level_peer_id: Option, + pub potential_p2p_network_peer_ids: Vec, pub validator_network_peer_id: String, } @@ -49,6 +49,12 @@ impl ValidatorAddressCache { } } +impl Default for ValidatorAddressCache { + fn default() -> Self { + Self::new() + } +} + pub trait ValidatorAddressCacheUpdater { /// In session `SessionIndex`, validator `NodeIndex` was using addresses specified in `most_recent_info`. /// A session and validator_index identify the validator uniquely. diff --git a/finality-aleph/src/network/session/manager.rs b/finality-aleph/src/network/session/manager.rs index 35374d958f..cb261b6433 100644 --- a/finality-aleph/src/network/session/manager.rs +++ b/finality-aleph/src/network/session/manager.rs @@ -1,6 +1,6 @@ use std::{ collections::{HashMap, HashSet}, - fmt::{Debug, Display}, + fmt::Debug, time::Duration, }; @@ -218,7 +218,7 @@ impl Manager Manager( + pub fn on_discovery_message( &mut self, message: DiscoveryMessage, - low_level_peer_id: LPID, ) -> ManagerActions { let session_id = message.session_id(); let creator = message.0.creator(); @@ -344,7 +343,7 @@ impl Manager { - let (authentication, low_level_peer_id) = maybe_authentication.map_err(Error::GossipNetwork)?; + let (authentication, _) = maybe_authentication.map_err(Error::GossipNetwork)?; trace!(target: "aleph-network", "Manager received an authentication from network"); match authentication.try_into() { Ok(message) => { - let manager_actions = self.manager.on_discovery_message(message, low_level_peer_id); + let manager_actions = self.manager.on_discovery_message(message); self.handle_manager_actions(manager_actions)? }, Err(e) => debug!(target: "aleph-network", "Could not cast versioned authentication in discovery message: {:?}", e), diff --git a/finality-aleph/src/network/tcp.rs b/finality-aleph/src/network/tcp.rs index 44f20bc631..d01fa4b0ab 100644 --- a/finality-aleph/src/network/tcp.rs +++ b/finality-aleph/src/network/tcp.rs @@ -108,7 +108,16 @@ impl AddressingInformation for SignedTcpAddressingInformation { } fn internal_protocol_address(&self) -> String { - return self.addressing_information.primary_address.clone(); + iter::once(self.addressing_information.primary_address.clone()) + .chain(self.addressing_information.other_addresses.clone()) + .filter_map(|address| { + let mut socket_addr = address.to_socket_addrs().ok()?; + socket_addr + .next() + .map(|socket_addr| socket_addr.ip().to_string()) + }) + .next() + .unwrap_or("unknown".to_string()) } } diff --git a/finality-aleph/src/nodes.rs b/finality-aleph/src/nodes.rs index a3dcb286eb..adf8a6a564 100644 --- a/finality-aleph/src/nodes.rs +++ b/finality-aleph/src/nodes.rs @@ -111,8 +111,10 @@ where validator_network_service.run(exit).await }); + let substrate_network = + SubstrateNetwork::new(network.clone(), sync_network.clone(), protocol_naming); let (gossip_network_service, authentication_network, block_sync_network) = GossipService::new( - SubstrateNetwork::new(network.clone(), sync_network.clone(), protocol_naming), + substrate_network.clone(), spawn_handle.clone(), registry.clone(), ); From 5cf22a8eda2ec9b8dc9e43eb92179a445856617d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20Gawrya=C5=82?= Date: Tue, 17 Oct 2023 17:13:46 +0200 Subject: [PATCH 06/24] Bound cache size --- bin/node/src/aleph_node_rpc.rs | 6 +++++- finality-aleph/src/lib.rs | 2 +- finality-aleph/src/network/address_cache.rs | 23 ++++++++++++++------- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/bin/node/src/aleph_node_rpc.rs b/bin/node/src/aleph_node_rpc.rs index 0ed8c33b19..86a9e7d5f0 100644 --- a/bin/node/src/aleph_node_rpc.rs +++ b/bin/node/src/aleph_node_rpc.rs @@ -268,7 +268,11 @@ where async fn validator_network_info( &self, ) -> RpcResult> { - let mut info = self.validator_address_cache.as_hashmap(); + let mut info = self.validator_address_cache.read(); + + // This uses unstable method from substrate's API, but there's probably no other easy way + // of doing this. On the other hand, the p2p peer_id is only for debuging purposes, + // so in case of future substrate API change this if statement can be temporarily safely removed. if let Ok(network_state) = self.network.network_state().await { add_p2p_peer_id_to_validator_addressing_info(&mut info, network_state); } diff --git a/finality-aleph/src/lib.rs b/finality-aleph/src/lib.rs index 8d7f6fd841..183e578ee1 100644 --- a/finality-aleph/src/lib.rs +++ b/finality-aleph/src/lib.rs @@ -17,7 +17,7 @@ use sc_client_api::{ Backend, BlockBackend, BlockchainEvents, Finalizer, LockImportRun, TransactionFor, }; use sc_consensus::BlockImport; -use sc_network::{config::NonReservedPeerMode, NetworkService}; +use sc_network::NetworkService; use sc_network_sync::SyncingService; use sp_api::ProvideRuntimeApi; use sp_blockchain::{HeaderBackend, HeaderMetadata}; diff --git a/finality-aleph/src/network/address_cache.rs b/finality-aleph/src/network/address_cache.rs index 04378594f1..ca267fc465 100644 --- a/finality-aleph/src/network/address_cache.rs +++ b/finality-aleph/src/network/address_cache.rs @@ -1,5 +1,6 @@ -use std::{collections::HashMap, marker::PhantomData, sync::Arc}; +use std::{collections::HashMap, marker::PhantomData, num::NonZeroUsize, sync::Arc}; +use lru::LruCache; use parking_lot::Mutex; use primitives::{AccountId, AlephSessionApi, AuthorityId, BlockHash, BlockNumber}; use sc_client_api::Backend; @@ -21,31 +22,39 @@ pub trait KeyOwnerInfoProvider { /// and can change over time, even within a single session. #[derive(Debug, Clone, Serialize, Deserialize)] pub struct ValidatorAddressingInfo { + /// Network level address of the validator, i.e. IP address pub network_level_address: String, + /// List of peer_ids that have ever used same network level address as network_level_address. + /// It can be empty in case we don't have any info about the given validator peer_id, or even + /// could contain false positives when one validator changed its IP and other node picked it up. pub potential_p2p_network_peer_ids: Vec, + /// PeerId of the validator used in validator (clique) network pub validator_network_peer_id: String, } /// Stores most recent information about validator addresses. -/// TODO: Consider using LruCache there. #[derive(Debug, Clone)] pub struct ValidatorAddressCache { - data: Arc>>, + data: Arc>>, } +const VALIDATOR_ADDRESS_CACHE_SIZE: usize = 300; + impl ValidatorAddressCache { pub fn new() -> Self { Self { - data: Arc::new(Mutex::new(HashMap::new())), + data: Arc::new(Mutex::new(LruCache::new( + NonZeroUsize::try_from(VALIDATOR_ADDRESS_CACHE_SIZE).unwrap(), + ))), } } pub fn insert(&self, validator_stash: AccountId, info: ValidatorAddressingInfo) { - self.data.lock().insert(validator_stash, info); + self.data.lock().put(validator_stash, info); } - pub fn as_hashmap(&self) -> HashMap { - self.data.lock().clone() + pub fn read(&self) -> HashMap { + HashMap::from_iter(self.data.lock().iter().map(|(k, v)| (k.clone(), v.clone()))) } } From 2793b969244fda7212f731a4e58e42648938c146 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20Gawrya=C5=82?= Date: Tue, 17 Oct 2023 17:22:05 +0200 Subject: [PATCH 07/24] Bump versions --- bin/node/Cargo.toml | 2 +- bin/runtime/src/lib.rs | 2 +- clique/Cargo.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/node/Cargo.toml b/bin/node/Cargo.toml index 4e2c9d5371..d2bdd435d0 100644 --- a/bin/node/Cargo.toml +++ b/bin/node/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "aleph-node" -version = "0.9.0" +version = "0.10.0" description = "Aleph node binary" build = "build.rs" license = "GPL-3.0-or-later" diff --git a/bin/runtime/src/lib.rs b/bin/runtime/src/lib.rs index 31a205ea40..6daedcae23 100644 --- a/bin/runtime/src/lib.rs +++ b/bin/runtime/src/lib.rs @@ -94,7 +94,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("aleph-node"), impl_name: create_runtime_str!("aleph-node"), authoring_version: 1, - spec_version: 56, + spec_version: 57, impl_version: 1, apis: RUNTIME_API_VERSIONS, transaction_version: 16, diff --git a/clique/Cargo.toml b/clique/Cargo.toml index c455afdc7a..95cc4b187b 100644 --- a/clique/Cargo.toml +++ b/clique/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "network-clique" -version = "0.5.0" +version = "0.6.0" license = "Apache 2.0" authors.workspace = true edition.workspace = true From 640714ed4f2b8510ae6de4b273f2f21ad8bfc5bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20Gawrya=C5=82?= Date: Wed, 18 Oct 2023 10:41:26 +0200 Subject: [PATCH 08/24] Add sessionid --- finality-aleph/src/network/address_cache.rs | 6 ++++-- finality-aleph/src/network/session/manager.rs | 6 ++++-- finality-aleph/src/session.rs | 17 ++++++++++++++++- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/finality-aleph/src/network/address_cache.rs b/finality-aleph/src/network/address_cache.rs index ca267fc465..527378cad3 100644 --- a/finality-aleph/src/network/address_cache.rs +++ b/finality-aleph/src/network/address_cache.rs @@ -24,12 +24,14 @@ pub trait KeyOwnerInfoProvider { pub struct ValidatorAddressingInfo { /// Network level address of the validator, i.e. IP address pub network_level_address: String, + /// PeerId of the validator used in validator (clique) network + pub validator_network_peer_id: String, + /// Session to which the given `validator_network_peer_id` corresponds. + pub session: SessionId, /// List of peer_ids that have ever used same network level address as network_level_address. /// It can be empty in case we don't have any info about the given validator peer_id, or even /// could contain false positives when one validator changed its IP and other node picked it up. pub potential_p2p_network_peer_ids: Vec, - /// PeerId of the validator used in validator (clique) network - pub validator_network_peer_id: String, } /// Stores most recent information about validator addresses. diff --git a/finality-aleph/src/network/session/manager.rs b/finality-aleph/src/network/session/manager.rs index cb261b6433..59ff1e1493 100644 --- a/finality-aleph/src/network/session/manager.rs +++ b/finality-aleph/src/network/session/manager.rs @@ -218,8 +218,9 @@ impl Manager Manager Date: Wed, 18 Oct 2023 17:21:00 +0200 Subject: [PATCH 09/24] Fix for non-validators --- finality-aleph/src/network/session/manager.rs | 32 +++++++++---------- finality-aleph/src/network/tcp.rs | 7 +--- 2 files changed, 17 insertions(+), 22 deletions(-) diff --git a/finality-aleph/src/network/session/manager.rs b/finality-aleph/src/network/session/manager.rs index 59ff1e1493..e19776cd25 100644 --- a/finality-aleph/src/network/session/manager.rs +++ b/finality-aleph/src/network/session/manager.rs @@ -334,25 +334,25 @@ impl Manager { let (maybe_address, maybe_message) = discovery.handle_authentication(message, handler); - let maybe_command = match (maybe_address, handler.is_validator()) { - (Some(address), true) => { + let mut maybe_command = None; + if let Some(address) = maybe_address { + self.validator_address_cache_updater.update( + session_id, + creator, + ValidatorAddressingInfo { + network_level_address: address.internal_protocol_address(), + validator_network_peer_id: address.peer_id().to_string(), + session: session_id, + potential_p2p_network_peer_ids: vec![], + }, + ); + if handler.is_validator() { debug!(target: "aleph-network", "Adding addresses for session {:?} to reserved: {:?}", session_id, address); self.connections.add_peers(session_id, [address.peer_id()]); - - self.validator_address_cache_updater.update( - session_id, - creator, - ValidatorAddressingInfo { - network_level_address: address.internal_protocol_address(), - validator_network_peer_id: address.peer_id().to_string(), - session: session_id, - potential_p2p_network_peer_ids: vec![], - }, - ); - Some(ConnectionCommand::AddReserved([address].into())) + maybe_command = Some(ConnectionCommand::AddReserved([address].into())); } - _ => None, - }; + } + ManagerActions { maybe_command, maybe_message, diff --git a/finality-aleph/src/network/tcp.rs b/finality-aleph/src/network/tcp.rs index d01fa4b0ab..2b7d351ad8 100644 --- a/finality-aleph/src/network/tcp.rs +++ b/finality-aleph/src/network/tcp.rs @@ -110,12 +110,7 @@ impl AddressingInformation for SignedTcpAddressingInformation { fn internal_protocol_address(&self) -> String { iter::once(self.addressing_information.primary_address.clone()) .chain(self.addressing_information.other_addresses.clone()) - .filter_map(|address| { - let mut socket_addr = address.to_socket_addrs().ok()?; - socket_addr - .next() - .map(|socket_addr| socket_addr.ip().to_string()) - }) + .filter_map(|address| Some(address.to_socket_addrs().ok()?.next()?.ip().to_string())) .next() .unwrap_or("unknown".to_string()) } From 7108ceed21d5fba0f282313f81294bf3f7416e70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20Gawrya=C5=82?= Date: Wed, 18 Oct 2023 17:57:37 +0200 Subject: [PATCH 10/24] Add version string to p2p net info --- bin/node/src/aleph_node_rpc.rs | 39 +++++++++++++------ finality-aleph/src/lib.rs | 4 +- finality-aleph/src/network/address_cache.rs | 15 +++++-- finality-aleph/src/network/session/manager.rs | 4 +- 4 files changed, 43 insertions(+), 19 deletions(-) diff --git a/bin/node/src/aleph_node_rpc.rs b/bin/node/src/aleph_node_rpc.rs index 86a9e7d5f0..03576644c8 100644 --- a/bin/node/src/aleph_node_rpc.rs +++ b/bin/node/src/aleph_node_rpc.rs @@ -1,8 +1,8 @@ use std::{collections::HashMap, net::IpAddr, sync::Arc}; use finality_aleph::{ - AlephJustification, BlockId, Justification, JustificationTranslator, ValidatorAddressCache, - ValidatorAddressingInfo, + AdditionalP2PAddressingInfo, AlephJustification, BlockId, Justification, + JustificationTranslator, ValidatorAddressCache, ValidatorAddressingInfo, }; use futures::channel::mpsc; use jsonrpsee::{ @@ -13,7 +13,11 @@ use jsonrpsee::{ use parity_scale_codec::Decode; use primitives::{AccountId, Block, BlockHash, BlockNumber, Hash, Signature}; use sc_client_api::StorageProvider; -use sc_network::{multiaddr::Protocol, network_state::NetworkState, Multiaddr, NetworkService}; +use sc_network::{ + multiaddr::Protocol, + network_state::{NetworkState, PeerEndpoint}, + Multiaddr, NetworkService, +}; use sp_arithmetic::traits::Zero; use sp_blockchain::HeaderBackend; use sp_consensus::SyncOracle; @@ -274,13 +278,13 @@ where // of doing this. On the other hand, the p2p peer_id is only for debuging purposes, // so in case of future substrate API change this if statement can be temporarily safely removed. if let Ok(network_state) = self.network.network_state().await { - add_p2p_peer_id_to_validator_addressing_info(&mut info, network_state); + attach_p2p_network_info_to_validator_addressing_info(&mut info, network_state); } Ok(info) } } -fn add_p2p_peer_id_to_validator_addressing_info( +fn attach_p2p_network_info_to_validator_addressing_info( info: &mut HashMap, network_state: NetworkState, ) { @@ -288,19 +292,30 @@ fn add_p2p_peer_id_to_validator_addressing_info( network_state .connected_peers .iter() - .flat_map(|(peer_id, peer)| peer.known_addresses.iter().map(move |addr| (addr, peer_id))) - .for_each(|(addr, peer_id)| { + .flat_map(|(peer_id, peer)| { + let extra_address_to_check = match &peer.endpoint { + PeerEndpoint::Dialing(addr, _) => Some(addr), + _ => None, + }; + peer.known_addresses + .iter() + .chain(extra_address_to_check) + .map(move |addr| (addr, peer_id, peer.version_string.clone())) + }) + .for_each(|(addr, peer_id, version_string)| { if let Some(ip_address) = try_to_ip_addr(addr) { - ip_to_peer_id - .entry(ip_address) - .or_insert(vec![]) - .push(peer_id.clone()); + ip_to_peer_id.entry(ip_address).or_insert(vec![]).push( + AdditionalP2PAddressingInfo { + p2p_network_peer_id: peer_id.clone(), + version_string, + }, + ); } }); for (_, info) in info.iter_mut() { if let Ok(addr) = info.network_level_address.parse::() { if let Some(peer_ids) = ip_to_peer_id.get(&addr) { - info.potential_p2p_network_peer_ids = peer_ids.clone(); + info.potential_p2p_network_additional_info = peer_ids.clone(); } } } diff --git a/finality-aleph/src/lib.rs b/finality-aleph/src/lib.rs index 153350fb80..c1fbaf9397 100644 --- a/finality-aleph/src/lib.rs +++ b/finality-aleph/src/lib.rs @@ -62,7 +62,9 @@ pub use crate::{ justification::AlephJustification, metrics::TimingBlockMetrics, network::{ - address_cache::{ValidatorAddressCache, ValidatorAddressingInfo}, + address_cache::{ + AdditionalP2PAddressingInfo, ValidatorAddressCache, ValidatorAddressingInfo, + }, Protocol, ProtocolNaming, }, nodes::run_validator_node, diff --git a/finality-aleph/src/network/address_cache.rs b/finality-aleph/src/network/address_cache.rs index 527378cad3..688b5500ca 100644 --- a/finality-aleph/src/network/address_cache.rs +++ b/finality-aleph/src/network/address_cache.rs @@ -28,10 +28,17 @@ pub struct ValidatorAddressingInfo { pub validator_network_peer_id: String, /// Session to which the given `validator_network_peer_id` corresponds. pub session: SessionId, - /// List of peer_ids that have ever used same network level address as network_level_address. - /// It can be empty in case we don't have any info about the given validator peer_id, or even - /// could contain false positives when one validator changed its IP and other node picked it up. - pub potential_p2p_network_peer_ids: Vec, + /// Vec of substrate's P2P network extra data (e.g. peer_id) that *could* match a given addressing info, + /// that is, which was sent from the same address as network_level_address. + /// It can be empty in case we haven't been ever connected directly to a given peer in p2p network, + /// or even could contain false positives when one validator changed its IP and other node picked it up. + pub potential_p2p_network_additional_info: Vec, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct AdditionalP2PAddressingInfo { + pub p2p_network_peer_id: String, + pub version_string: Option, } /// Stores most recent information about validator addresses. diff --git a/finality-aleph/src/network/session/manager.rs b/finality-aleph/src/network/session/manager.rs index e19776cd25..a5c638d81a 100644 --- a/finality-aleph/src/network/session/manager.rs +++ b/finality-aleph/src/network/session/manager.rs @@ -220,7 +220,7 @@ impl Manager Manager Date: Wed, 18 Oct 2023 17:59:56 +0200 Subject: [PATCH 11/24] Comment --- finality-aleph/src/network/address_cache.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/finality-aleph/src/network/address_cache.rs b/finality-aleph/src/network/address_cache.rs index 688b5500ca..bf3f4022e3 100644 --- a/finality-aleph/src/network/address_cache.rs +++ b/finality-aleph/src/network/address_cache.rs @@ -35,6 +35,8 @@ pub struct ValidatorAddressingInfo { pub potential_p2p_network_additional_info: Vec, } +/// Additional information about a node in substrate's P2P network. Use only for debugging purposes, +/// as content of this struct rely on unstable substrate's API and can change in future. #[derive(Debug, Clone, Serialize, Deserialize)] pub struct AdditionalP2PAddressingInfo { pub p2p_network_peer_id: String, From 4150278fe90f0f07d28a5efc16441f80fe02f2e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20Gawrya=C5=82?= Date: Thu, 19 Oct 2023 10:47:11 +0200 Subject: [PATCH 12/24] Dont resolve dns --- bin/node/src/aleph_node_rpc.rs | 8 ++-- clique/src/lib.rs | 4 +- clique/src/mock.rs | 2 +- finality-aleph/src/network/session/manager.rs | 4 +- finality-aleph/src/network/tcp.rs | 39 +++++++++++++++++-- 5 files changed, 44 insertions(+), 13 deletions(-) diff --git a/bin/node/src/aleph_node_rpc.rs b/bin/node/src/aleph_node_rpc.rs index 03576644c8..b668018b91 100644 --- a/bin/node/src/aleph_node_rpc.rs +++ b/bin/node/src/aleph_node_rpc.rs @@ -323,10 +323,10 @@ fn attach_p2p_network_info_to_validator_addressing_info( fn try_to_ip_addr(multiaddr: &Multiaddr) -> Option { for component in multiaddr.iter() { - if let Protocol::Ip4(addr) = component { - return Some(IpAddr::V4(addr)); - } else if let Protocol::Ip6(addr) = component { - return Some(IpAddr::V6(addr)); + match component { + Protocol::Ip4(addr) => return Some(IpAddr::V4(addr)), + Protocol::Ip6(addr) => return Some(IpAddr::V6(addr)), + _ => {} } } None diff --git a/clique/src/lib.rs b/clique/src/lib.rs index a3434de0cd..b9663257ae 100644 --- a/clique/src/lib.rs +++ b/clique/src/lib.rs @@ -59,8 +59,8 @@ pub trait AddressingInformation: Debug + Hash + Codec + Clone + Eq + Send + Sync /// Verify the information. fn verify(&self) -> bool; - // Address used internally by the protocol. - fn internal_protocol_address(&self) -> String; + // Address used by the underlying protocol, for debugging purposes. + fn lower_level_address(&self) -> String; } /// Abstraction for requesting own network addressing information. diff --git a/clique/src/mock.rs b/clique/src/mock.rs index 32710f5337..cf5d358c35 100644 --- a/clique/src/mock.rs +++ b/clique/src/mock.rs @@ -294,7 +294,7 @@ impl AddressingInformation for MockAddressingInformation { self.valid } - fn internal_protocol_address(&self) -> String { + fn lower_level_address(&self) -> String { self.address.clone() } } diff --git a/finality-aleph/src/network/session/manager.rs b/finality-aleph/src/network/session/manager.rs index a5c638d81a..631320f6d8 100644 --- a/finality-aleph/src/network/session/manager.rs +++ b/finality-aleph/src/network/session/manager.rs @@ -217,7 +217,7 @@ impl Manager Manager String { + fn lower_level_address(&self) -> String { iter::once(self.addressing_information.primary_address.clone()) .chain(self.addressing_information.other_addresses.clone()) - .filter_map(|address| Some(address.to_socket_addrs().ok()?.next()?.ip().to_string())) + .filter_map(|address| Some(address.parse::().ok()?.to_string())) .next() .unwrap_or("unknown".to_string()) } @@ -217,9 +221,13 @@ pub async fn new_tcp_network( #[cfg(test)] pub mod testing { + use network_clique::AddressingInformation; use super::{AuthorityIdWrapper, SignedTcpAddressingInformation}; - use crate::{crypto::AuthorityPen, network::NetworkIdentity}; + use crate::{ + crypto::AuthorityPen, + network::{mock::crypto_basics, NetworkIdentity}, + }; /// Creates a realistic identity. pub fn new_identity( @@ -232,4 +240,27 @@ pub mod testing { SignedTcpAddressingInformation::new(external_addresses, authority_pen) .expect("the provided addresses are fine") } + + #[test] + pub fn lower_level_address_parses_ip() { + let (_, authority_pen) = &crypto_basics(1).0[0]; + for ip in ["127.0.0.1", "[::1]", "[2607:f8b0:4003:c00::6a]"] { + let ip_and_port = format!("{}:1234", ip); + let addr = + SignedTcpAddressingInformation::new(vec![ip_and_port.clone()], authority_pen) + .unwrap(); + + assert_eq!(addr.lower_level_address(), ip_and_port.to_string()) + } + } + #[test] + pub fn lower_level_address_doesnt_try_to_resolve_dns() { + let (_, authority_pen) = &crypto_basics(1).0[0]; + let addr = SignedTcpAddressingInformation::new( + vec!["bootnode-eu-west-1-0.test.azero.dev:30333".to_string()], + authority_pen, + ) + .unwrap(); + assert_eq!(addr.lower_level_address(), "unknown".to_string()) + } } From 2c3165627990ba326a78d65bdae0f583ee937dcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20Gawrya=C5=82?= Date: Thu, 19 Oct 2023 10:57:22 +0200 Subject: [PATCH 13/24] Remove display --- finality-aleph/src/network/gossip/mod.rs | 4 ++-- finality-aleph/src/network/gossip/service.rs | 4 +--- finality-aleph/src/network/session/manager.rs | 8 ++++---- finality-aleph/src/network/session/service.rs | 12 ++++++------ finality-aleph/src/nodes.rs | 4 +--- 5 files changed, 14 insertions(+), 18 deletions(-) diff --git a/finality-aleph/src/network/gossip/mod.rs b/finality-aleph/src/network/gossip/mod.rs index fd5948a5f3..55afc8fe47 100644 --- a/finality-aleph/src/network/gossip/mod.rs +++ b/finality-aleph/src/network/gossip/mod.rs @@ -22,7 +22,7 @@ pub use service::{Error, Service}; /// connected to them directly. pub trait Network: Send + 'static { type Error: Display + Send; - type PeerId: Clone + Debug + Display + Eq + Hash + Send + 'static; + type PeerId: Clone + Debug + Eq + Hash + Send + 'static; /// Attempt to send data to a peer. Might silently fail if we are not connected to them. fn send_to(&mut self, data: D, peer_id: Self::PeerId) -> Result<(), Self::Error>; @@ -87,7 +87,7 @@ pub trait EventStream

{ pub trait RawNetwork: Clone + Send + Sync + 'static { type SenderError: std::error::Error; type NetworkSender: NetworkSender; - type PeerId: Clone + Debug + Display + Eq + Hash + Send + 'static; + type PeerId: Clone + Debug + Eq + Hash + Send + 'static; type EventStream: EventStream; /// Returns a stream of events representing what happens on the network. diff --git a/finality-aleph/src/network/gossip/service.rs b/finality-aleph/src/network/gossip/service.rs index f49031a2f9..f73d4c1c93 100644 --- a/finality-aleph/src/network/gossip/service.rs +++ b/finality-aleph/src/network/gossip/service.rs @@ -77,9 +77,7 @@ impl Display for Error { } #[async_trait::async_trait] -impl Network - for ServiceInterface -{ +impl Network for ServiceInterface { type Error = Error; type PeerId = P; diff --git a/finality-aleph/src/network/session/manager.rs b/finality-aleph/src/network/session/manager.rs index 631320f6d8..57d0e91536 100644 --- a/finality-aleph/src/network/session/manager.rs +++ b/finality-aleph/src/network/session/manager.rs @@ -79,11 +79,11 @@ impl ManagerActions { /// 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 { +pub struct Manager { network_identity: NI, connections: Connections, sessions: HashMap>, - validator_address_cache_updater: VU, + validator_address_cache_updater: VCU, discovery_cooldown: Duration, } @@ -94,11 +94,11 @@ pub enum SendError { NoSession, } -impl Manager { +impl Manager { /// Create a new connection manager. pub fn new( network_identity: NI, - validator_address_cache_updater: VU, + validator_address_cache_updater: VCU, discovery_cooldown: Duration, ) -> Self { Manager { diff --git a/finality-aleph/src/network/session/service.rs b/finality-aleph/src/network/session/service.rs index a0e0b6d9c2..f44598955d 100644 --- a/finality-aleph/src/network/session/service.rs +++ b/finality-aleph/src/network/session/service.rs @@ -177,11 +177,11 @@ pub struct Service< NI: NetworkIdentity, CN: CliqueNetwork>, GN: GossipNetwork>, - VU: ValidatorAddressCacheUpdater, + VCU: ValidatorAddressCacheUpdater, > where NI::PeerId: PublicKey, { - manager: Manager, + manager: Manager, commands_from_user: mpsc::UnboundedReceiver>, messages_from_user: mpsc::UnboundedReceiver<(D, SessionId, Recipient)>, validator_network: CN, @@ -216,8 +216,8 @@ impl< NI: NetworkIdentity, CN: CliqueNetwork>, GN: GossipNetwork>, - VU: ValidatorAddressCacheUpdater, - > Service + VCU: ValidatorAddressCacheUpdater, + > Service where NI::PeerId: PublicKey, { @@ -225,10 +225,10 @@ where network_identity: NI, validator_network: CN, gossip_network: GN, - validator_address_cache_updater: VU, + validator_address_cache_updater: VCU, config: Config, ) -> ( - Service, + Service, impl SessionManager, ) { let Config { diff --git a/finality-aleph/src/nodes.rs b/finality-aleph/src/nodes.rs index 3603479da0..fb21fdeea9 100644 --- a/finality-aleph/src/nodes.rs +++ b/finality-aleph/src/nodes.rs @@ -112,10 +112,8 @@ where validator_network_service.run(exit).await }); - let substrate_network = - SubstrateNetwork::new(network.clone(), sync_network.clone(), protocol_naming); let (gossip_network_service, authentication_network, block_sync_network) = GossipService::new( - substrate_network.clone(), + SubstrateNetwork::new(network.clone(), sync_network.clone(), protocol_naming), spawn_handle.clone(), registry.clone(), ); From 174fbf02136111e81e356298d3cde396310d1cac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20Gawrya=C5=82?= Date: Thu, 19 Oct 2023 11:16:40 +0200 Subject: [PATCH 14/24] Remove port --- finality-aleph/src/network/tcp.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/finality-aleph/src/network/tcp.rs b/finality-aleph/src/network/tcp.rs index bdbe23da87..2bf76abbb0 100644 --- a/finality-aleph/src/network/tcp.rs +++ b/finality-aleph/src/network/tcp.rs @@ -114,7 +114,7 @@ impl AddressingInformation for SignedTcpAddressingInformation { fn lower_level_address(&self) -> String { iter::once(self.addressing_information.primary_address.clone()) .chain(self.addressing_information.other_addresses.clone()) - .filter_map(|address| Some(address.parse::().ok()?.to_string())) + .filter_map(|address| Some(address.parse::().ok()?.ip().to_string())) .next() .unwrap_or("unknown".to_string()) } @@ -247,10 +247,12 @@ pub mod testing { for ip in ["127.0.0.1", "[::1]", "[2607:f8b0:4003:c00::6a]"] { let ip_and_port = format!("{}:1234", ip); let addr = - SignedTcpAddressingInformation::new(vec![ip_and_port.clone()], authority_pen) - .unwrap(); + SignedTcpAddressingInformation::new(vec![ip_and_port], authority_pen).unwrap(); - assert_eq!(addr.lower_level_address(), ip_and_port.to_string()) + assert_eq!( + addr.lower_level_address(), + ip.trim_matches(&['[', ']'] as &[_]).to_string() + ) } } #[test] From 81f8b2b58073be2f687f2250696ee86fccd377e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20Gawrya=C5=82?= Date: Thu, 19 Oct 2023 12:32:48 +0200 Subject: [PATCH 15/24] Deduplicate entries in potential p2p network additional info --- bin/node/src/aleph_node_rpc.rs | 17 +++++++++++------ finality-aleph/src/network/address_cache.rs | 2 +- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/bin/node/src/aleph_node_rpc.rs b/bin/node/src/aleph_node_rpc.rs index b668018b91..b575f5d3c3 100644 --- a/bin/node/src/aleph_node_rpc.rs +++ b/bin/node/src/aleph_node_rpc.rs @@ -1,4 +1,8 @@ -use std::{collections::HashMap, net::IpAddr, sync::Arc}; +use std::{ + collections::{HashMap, HashSet}, + net::IpAddr, + sync::Arc, +}; use finality_aleph::{ AdditionalP2PAddressingInfo, AlephJustification, BlockId, Justification, @@ -304,18 +308,19 @@ fn attach_p2p_network_info_to_validator_addressing_info( }) .for_each(|(addr, peer_id, version_string)| { if let Some(ip_address) = try_to_ip_addr(addr) { - ip_to_peer_id.entry(ip_address).or_insert(vec![]).push( - AdditionalP2PAddressingInfo { + ip_to_peer_id + .entry(ip_address) + .or_insert(HashSet::new()) + .insert(AdditionalP2PAddressingInfo { p2p_network_peer_id: peer_id.clone(), version_string, - }, - ); + }); } }); for (_, info) in info.iter_mut() { if let Ok(addr) = info.network_level_address.parse::() { if let Some(peer_ids) = ip_to_peer_id.get(&addr) { - info.potential_p2p_network_additional_info = peer_ids.clone(); + info.potential_p2p_network_additional_info = peer_ids.iter().cloned().collect(); } } } diff --git a/finality-aleph/src/network/address_cache.rs b/finality-aleph/src/network/address_cache.rs index bf3f4022e3..c79b807e6a 100644 --- a/finality-aleph/src/network/address_cache.rs +++ b/finality-aleph/src/network/address_cache.rs @@ -37,7 +37,7 @@ pub struct ValidatorAddressingInfo { /// Additional information about a node in substrate's P2P network. Use only for debugging purposes, /// as content of this struct rely on unstable substrate's API and can change in future. -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Hash, PartialEq, Eq, Serialize, Deserialize)] pub struct AdditionalP2PAddressingInfo { pub p2p_network_peer_id: String, pub version_string: Option, From 027256925611af5027baa291630b5ceabf0c4a79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20Gawrya=C5=82?= Date: Wed, 25 Oct 2023 11:28:49 +0200 Subject: [PATCH 16/24] Rename read to snapshot --- bin/node/src/aleph_node_rpc.rs | 9 ++------- bin/node/src/rpc.rs | 5 ----- bin/node/src/service.rs | 8 ++------ finality-aleph/src/network/address_cache.rs | 7 ++++++- 4 files changed, 10 insertions(+), 19 deletions(-) diff --git a/bin/node/src/aleph_node_rpc.rs b/bin/node/src/aleph_node_rpc.rs index 38d8275011..60ecec12f5 100644 --- a/bin/node/src/aleph_node_rpc.rs +++ b/bin/node/src/aleph_node_rpc.rs @@ -11,9 +11,8 @@ use jsonrpsee::{ types::error::{CallError, ErrorObject}, }; use parity_scale_codec::Decode; -use primitives::{AccountId, Block, BlockHash, BlockNumber, Hash, Signature}; +use primitives::{AccountId, Block, BlockHash, BlockNumber, Signature}; use sc_client_api::StorageProvider; -use sc_network::NetworkService; use sp_arithmetic::traits::Zero; use sp_blockchain::HeaderBackend; use sp_consensus::SyncOracle; @@ -174,7 +173,6 @@ pub struct AlephNode { client: Arc, sync_oracle: SO, validator_address_cache: ValidatorAddressCache, - network: Arc>, } impl AlephNode @@ -187,7 +185,6 @@ where client: Arc, sync_oracle: SO, validator_address_cache: ValidatorAddressCache, - network: Arc>, ) -> Self { AlephNode { import_justification_tx, @@ -195,7 +192,6 @@ where client, sync_oracle, validator_address_cache, - network, } } } @@ -268,8 +264,7 @@ where async fn validator_network_info( &self, ) -> RpcResult> { - todo!() - // self.validator_address_cache.read() + Ok(self.validator_address_cache.snapshot()) } } diff --git a/bin/node/src/rpc.rs b/bin/node/src/rpc.rs index 97cbe6c7b7..c622196802 100644 --- a/bin/node/src/rpc.rs +++ b/bin/node/src/rpc.rs @@ -11,9 +11,7 @@ use aleph_runtime::{opaque::Block, AccountId, Balance, Nonce}; use finality_aleph::{Justification, JustificationTranslator, ValidatorAddressCache}; use futures::channel::mpsc; use jsonrpsee::RpcModule; -use primitives::Hash; use sc_client_api::StorageProvider; -use sc_network::NetworkService; pub use sc_rpc_api::DenyUnsafe; use sc_transaction_pool_api::TransactionPool; use sp_api::ProvideRuntimeApi; @@ -33,7 +31,6 @@ pub struct FullDeps { pub justification_translator: JustificationTranslator, pub sync_oracle: SO, pub validator_address_cache: ValidatorAddressCache, - pub network: Arc>, } /// Instantiate all full RPC extensions. @@ -67,7 +64,6 @@ where justification_translator, sync_oracle, validator_address_cache, - network, } = deps; module.merge(System::new(client.clone(), pool, deny_unsafe).into_rpc())?; @@ -82,7 +78,6 @@ where client, sync_oracle, validator_address_cache, - network, ) .into_rpc(), )?; diff --git a/bin/node/src/service.rs b/bin/node/src/service.rs index 28aee7a0a2..39542d4f86 100644 --- a/bin/node/src/service.rs +++ b/bin/node/src/service.rs @@ -218,7 +218,7 @@ fn setup( ProtocolNaming, NetworkStarter, SyncOracle, - ValidatorAddressCache, + Option, ), ServiceError, > { @@ -261,7 +261,6 @@ fn setup( let pool = transaction_pool.clone(); let sync_oracle = sync_oracle.clone(); let validator_address_cache = validator_address_cache.clone(); - let network = network.clone(); Box::new(move |deny_unsafe, _| { let deps = RpcFullDeps { client: client.clone(), @@ -271,7 +270,6 @@ fn setup( justification_translator: JustificationTranslator::new(chain_status.clone()), sync_oracle: sync_oracle.clone(), validator_address_cache: validator_address_cache.clone(), - network: network.clone(), }; Ok(create_full_rpc(deps)?) @@ -300,7 +298,7 @@ fn setup( protocol_naming, network_starter, sync_oracle, - validator_address_cache, + Some(validator_address_cache), )) } @@ -417,8 +415,6 @@ pub fn new_authority( .unwrap_or(usize::MAX), }; - let validator_address_cache = None; - let aleph_config = AlephConfig { network, sync_network, diff --git a/finality-aleph/src/network/address_cache.rs b/finality-aleph/src/network/address_cache.rs index 0d3506481c..d460f41317 100644 --- a/finality-aleph/src/network/address_cache.rs +++ b/finality-aleph/src/network/address_cache.rs @@ -1,3 +1,4 @@ +use std::collections::HashMap; use std::{fmt::Debug, num::NonZeroUsize, sync::Arc}; use lru::LruCache; @@ -21,7 +22,7 @@ pub struct ValidatorAddressingInfo { } /// Stores most recent information about validator addresses. -#[derive(Debug, Clone)] +#[derive(Clone)] pub struct ValidatorAddressCache { data: Arc>>, } @@ -41,6 +42,10 @@ impl ValidatorAddressCache { pub fn insert(&self, validator_stash: AccountId, info: ValidatorAddressingInfo) { self.data.lock().put(validator_stash, info); } + + pub fn snapshot(&self) -> HashMap { + HashMap::from_iter(self.data.lock().iter().map(|(k, v)| (k.clone(), v.clone()))) + } } impl Default for ValidatorAddressCache { From 88ae6bb90703beac0cfb469f6ffb07201eb48c58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20Gawrya=C5=82?= Date: Wed, 25 Oct 2023 12:25:12 +0200 Subject: [PATCH 17/24] Enable caching only for non-authority, rpc node --- bin/node/src/aleph_node_rpc.rs | 21 +++++++++++++++++---- bin/node/src/rpc.rs | 2 +- bin/node/src/service.rs | 9 +++++++-- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/bin/node/src/aleph_node_rpc.rs b/bin/node/src/aleph_node_rpc.rs index 60ecec12f5..1997b38c5e 100644 --- a/bin/node/src/aleph_node_rpc.rs +++ b/bin/node/src/aleph_node_rpc.rs @@ -58,6 +58,9 @@ pub enum Error { /// Failed to find a block with provided hash. #[error("Failed to find a block with hash {0}.")] UnknownHash(String), + /// Network info caching is not enabled. + #[error("Unable to get any data, because network info caching is not enabled.")] + NetworkInfoCachingNotEnabled, } // Base code for all system errors. @@ -80,6 +83,8 @@ const FAILED_STORAGE_DECODING_ERROR: i32 = BASE_ERROR + 7; const FAILED_HEADER_DECODING_ERROR: i32 = BASE_ERROR + 8; /// Failed to find a block with provided hash. const UNKNOWN_HASH_ERROR: i32 = BASE_ERROR + 9; +/// Network info caching is not enabled. +const NETWORK_INFO_CACHING_NOT_ENABLED_ERROR: i32 = BASE_ERROR + 10; impl From for JsonRpseeError { fn from(e: Error) -> Self { @@ -135,6 +140,11 @@ impl From for JsonRpseeError { format!("Failed to find a block with hash {hash}.",), None::<()>, )), + Error::NetworkInfoCachingNotEnabled => CallError::Custom(ErrorObject::owned( + NETWORK_INFO_CACHING_NOT_ENABLED_ERROR, + "Unable to get any data, because network info caching is not enabled.", + None::<()>, + )), } .into() } @@ -160,7 +170,7 @@ pub trait AlephNodeApi { #[method(name = "ready")] fn ready(&self) -> RpcResult; - #[method(name = "validatorNetworkInfo")] + #[method(name = "unstable_validatorNetworkInfo")] async fn validator_network_info( &self, ) -> RpcResult>; @@ -172,7 +182,7 @@ pub struct AlephNode { justification_translator: JustificationTranslator, client: Arc, sync_oracle: SO, - validator_address_cache: ValidatorAddressCache, + validator_address_cache: Option, } impl AlephNode @@ -184,7 +194,7 @@ where justification_translator: JustificationTranslator, client: Arc, sync_oracle: SO, - validator_address_cache: ValidatorAddressCache, + validator_address_cache: Option, ) -> Self { AlephNode { import_justification_tx, @@ -264,7 +274,10 @@ where async fn validator_network_info( &self, ) -> RpcResult> { - Ok(self.validator_address_cache.snapshot()) + self.validator_address_cache + .as_ref() + .map(|c| c.snapshot()) + .ok_or(Error::NetworkInfoCachingNotEnabled.into()) } } diff --git a/bin/node/src/rpc.rs b/bin/node/src/rpc.rs index c622196802..235f8df85e 100644 --- a/bin/node/src/rpc.rs +++ b/bin/node/src/rpc.rs @@ -30,7 +30,7 @@ pub struct FullDeps { pub import_justification_tx: mpsc::UnboundedSender, pub justification_translator: JustificationTranslator, pub sync_oracle: SO, - pub validator_address_cache: ValidatorAddressCache, + pub validator_address_cache: Option, } /// Instantiate all full RPC extensions. diff --git a/bin/node/src/service.rs b/bin/node/src/service.rs index 39542d4f86..082e4fb716 100644 --- a/bin/node/src/service.rs +++ b/bin/node/src/service.rs @@ -255,7 +255,12 @@ fn setup( })?; let sync_oracle = SyncOracle::new(); - let validator_address_cache = ValidatorAddressCache::new(); + + // Validator network info caching is enabled only for non-validator nodes with RPC enabled. + let validator_address_cache = match (&config.role, config.rpc_addr) { + (sc_network::config::Role::Full, Some(_)) => Some(ValidatorAddressCache::new()), + (_, _) => None, + }; let rpc_builder = { let client = client.clone(); let pool = transaction_pool.clone(); @@ -298,7 +303,7 @@ fn setup( protocol_naming, network_starter, sync_oracle, - Some(validator_address_cache), + validator_address_cache, )) } From 4576f998a905bdf33cf6f81317616a9f96e8fbac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20Gawrya=C5=82?= Date: Wed, 25 Oct 2023 12:28:01 +0200 Subject: [PATCH 18/24] Remove unnecessary async trait --- bin/node/src/aleph_node_rpc.rs | 11 +++-------- finality-aleph/src/network/address_cache.rs | 3 +-- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/bin/node/src/aleph_node_rpc.rs b/bin/node/src/aleph_node_rpc.rs index 1997b38c5e..9697d90c44 100644 --- a/bin/node/src/aleph_node_rpc.rs +++ b/bin/node/src/aleph_node_rpc.rs @@ -6,7 +6,7 @@ use finality_aleph::{ }; use futures::channel::mpsc; use jsonrpsee::{ - core::{async_trait, error::Error as JsonRpseeError, RpcResult}, + core::{error::Error as JsonRpseeError, RpcResult}, proc_macros::rpc, types::error::{CallError, ErrorObject}, }; @@ -171,9 +171,7 @@ pub trait AlephNodeApi { fn ready(&self) -> RpcResult; #[method(name = "unstable_validatorNetworkInfo")] - async fn validator_network_info( - &self, - ) -> RpcResult>; + fn validator_network_info(&self) -> RpcResult>; } /// Aleph Node API implementation @@ -206,7 +204,6 @@ where } } -#[async_trait] impl AlephNodeApiServer for AlephNode where BE: sc_client_api::Backend + 'static, @@ -271,9 +268,7 @@ where Ok(!self.sync_oracle.is_offline() && !self.sync_oracle.is_major_syncing()) } - async fn validator_network_info( - &self, - ) -> RpcResult> { + fn validator_network_info(&self) -> RpcResult> { self.validator_address_cache .as_ref() .map(|c| c.snapshot()) diff --git a/finality-aleph/src/network/address_cache.rs b/finality-aleph/src/network/address_cache.rs index d460f41317..a74434e8ce 100644 --- a/finality-aleph/src/network/address_cache.rs +++ b/finality-aleph/src/network/address_cache.rs @@ -1,5 +1,4 @@ -use std::collections::HashMap; -use std::{fmt::Debug, num::NonZeroUsize, sync::Arc}; +use std::{collections::HashMap, fmt::Debug, num::NonZeroUsize, sync::Arc}; use lru::LruCache; use parking_lot::Mutex; From 5d18b03b13b712e058185f5625581137b2880b04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20Gawrya=C5=82?= Date: Wed, 25 Oct 2023 12:46:07 +0200 Subject: [PATCH 19/24] Rollback node and spec version --- Cargo.lock | 2 +- bin/node/Cargo.toml | 2 +- bin/runtime/src/lib.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9785d6c992..71e45290cb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -343,7 +343,7 @@ dependencies = [ [[package]] name = "aleph-node" -version = "0.10.0" +version = "0.9.0" dependencies = [ "aleph-runtime", "finality-aleph", diff --git a/bin/node/Cargo.toml b/bin/node/Cargo.toml index d2bdd435d0..4e2c9d5371 100644 --- a/bin/node/Cargo.toml +++ b/bin/node/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "aleph-node" -version = "0.10.0" +version = "0.9.0" description = "Aleph node binary" build = "build.rs" license = "GPL-3.0-or-later" diff --git a/bin/runtime/src/lib.rs b/bin/runtime/src/lib.rs index fc85de9477..a3b5d7bd01 100644 --- a/bin/runtime/src/lib.rs +++ b/bin/runtime/src/lib.rs @@ -96,7 +96,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("aleph-node"), impl_name: create_runtime_str!("aleph-node"), authoring_version: 1, - spec_version: 57, + spec_version: 56, impl_version: 1, apis: RUNTIME_API_VERSIONS, transaction_version: 16, From 61fa1b347907c72c35657b1ab0919376c3af2aab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20Gawrya=C5=82?= Date: Wed, 25 Oct 2023 12:49:48 +0200 Subject: [PATCH 20/24] Fmt --- bin/runtime/src/lib.rs | 1 + finality-aleph/src/network/tcp.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/bin/runtime/src/lib.rs b/bin/runtime/src/lib.rs index a3b5d7bd01..1ec50e7c31 100644 --- a/bin/runtime/src/lib.rs +++ b/bin/runtime/src/lib.rs @@ -1018,6 +1018,7 @@ impl_runtime_apis! { fn next_session_aura_authorities() -> Vec { let queued_keys = QueuedKeys::::get(); + queued_keys.into_iter().filter_map(|(_, keys)| keys.get(AURA)).collect() } diff --git a/finality-aleph/src/network/tcp.rs b/finality-aleph/src/network/tcp.rs index 6b071ea80f..8d480bb133 100644 --- a/finality-aleph/src/network/tcp.rs +++ b/finality-aleph/src/network/tcp.rs @@ -213,6 +213,7 @@ pub async fn new_tcp_network( #[cfg(test)] pub mod testing { + use super::{AuthorityIdWrapper, SignedTcpAddressingInformation}; use crate::{crypto::AuthorityPen, network::NetworkIdentity}; From c3188e79be0ed9e378de7a02b1dfedfe6e1ed26e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20Gawrya=C5=82?= Date: Tue, 31 Oct 2023 09:39:17 +0100 Subject: [PATCH 21/24] Enable for telemetry nodes --- bin/node/src/service.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/node/src/service.rs b/bin/node/src/service.rs index 082e4fb716..3cc41faac9 100644 --- a/bin/node/src/service.rs +++ b/bin/node/src/service.rs @@ -256,9 +256,9 @@ fn setup( let sync_oracle = SyncOracle::new(); - // Validator network info caching is enabled only for non-validator nodes with RPC enabled. - let validator_address_cache = match (&config.role, config.rpc_addr) { - (sc_network::config::Role::Full, Some(_)) => Some(ValidatorAddressCache::new()), + // Validator network info caching is enabled only for nodes with telemetry and RPC enabled. + let validator_address_cache = match (&config.role, config.telemetry_endpoints.is_some()) { + (sc_network::config::Role::Full, true) => Some(ValidatorAddressCache::new()), (_, _) => None, }; let rpc_builder = { From 26a9190f54eeb969329b825b10c367f82a97b5e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20Gawrya=C5=82?= Date: Tue, 31 Oct 2023 12:57:53 +0100 Subject: [PATCH 22/24] Add cli flag instead --- bin/node/src/aleph_cli.rs | 8 ++++++++ bin/node/src/service.rs | 12 ++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/bin/node/src/aleph_cli.rs b/bin/node/src/aleph_cli.rs index 30319d2bac..503e50adb0 100644 --- a/bin/node/src/aleph_cli.rs +++ b/bin/node/src/aleph_cli.rs @@ -51,6 +51,10 @@ pub struct AlephCli { /// Maximum bit-rate per node in bytes per second of the alephbft validator network. #[clap(long, default_value_t = 64 * 1024)] alephbft_bit_rate_per_connection: u64, + + /// Spend some extra time to collect more debugging data (e.g. validator network details). + #[clap(long, default_value_t = false)] + collect_extra_debugging_data: bool, } impl AlephCli { @@ -92,4 +96,8 @@ impl AlephCli { pub fn alephbft_bit_rate_per_connection(&self) -> u64 { self.alephbft_bit_rate_per_connection } + + pub fn collect_extra_debugging_data(&self) -> bool { + self.collect_extra_debugging_data + } } diff --git a/bin/node/src/service.rs b/bin/node/src/service.rs index 3cc41faac9..9422e79533 100644 --- a/bin/node/src/service.rs +++ b/bin/node/src/service.rs @@ -210,6 +210,7 @@ fn setup( client: Arc, telemetry: &mut Option, import_justification_tx: mpsc::UnboundedSender, + collect_extra_debugging_data: bool, ) -> Result< ( RpcHandlers, @@ -256,11 +257,11 @@ fn setup( let sync_oracle = SyncOracle::new(); - // Validator network info caching is enabled only for nodes with telemetry and RPC enabled. - let validator_address_cache = match (&config.role, config.telemetry_endpoints.is_some()) { - (sc_network::config::Role::Full, true) => Some(ValidatorAddressCache::new()), - (_, _) => None, + let validator_address_cache = match collect_extra_debugging_data { + true => Some(ValidatorAddressCache::new()), + false => None, }; + let rpc_builder = { let client = client.clone(); let pool = transaction_pool.clone(); @@ -343,6 +344,8 @@ pub fn new_authority( let chain_status = SubstrateChainStatus::new(backend.clone()) .map_err(|e| ServiceError::Other(format!("failed to set up chain status: {e}")))?; + let collect_extra_debugging_data = aleph_config.collect_extra_debugging_data(); + let ( _rpc_handlers, network, @@ -362,6 +365,7 @@ pub fn new_authority( client.clone(), &mut telemetry, justification_tx, + collect_extra_debugging_data, )?; let mut proposer_factory = sc_basic_authorship::ProposerFactory::new( From 90e2b7287fc7a8e63d527a333f6b36b7509e404f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20Gawrya=C5=82?= Date: Wed, 8 Nov 2023 16:35:38 +0100 Subject: [PATCH 23/24] Enable extra debugging data by default --- bin/node/src/aleph_cli.rs | 6 +++--- bin/node/src/service.rs | 2 +- bin/runtime/src/lib.rs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/bin/node/src/aleph_cli.rs b/bin/node/src/aleph_cli.rs index 503e50adb0..dc7d8b1355 100644 --- a/bin/node/src/aleph_cli.rs +++ b/bin/node/src/aleph_cli.rs @@ -54,7 +54,7 @@ pub struct AlephCli { /// Spend some extra time to collect more debugging data (e.g. validator network details). #[clap(long, default_value_t = false)] - collect_extra_debugging_data: bool, + no_collection_of_extra_debugging_data: bool, } impl AlephCli { @@ -97,7 +97,7 @@ impl AlephCli { self.alephbft_bit_rate_per_connection } - pub fn collect_extra_debugging_data(&self) -> bool { - self.collect_extra_debugging_data + pub fn no_collection_of_extra_debugging_data(&self) -> bool { + self.no_collection_of_extra_debugging_data } } diff --git a/bin/node/src/service.rs b/bin/node/src/service.rs index 9422e79533..c9bb990628 100644 --- a/bin/node/src/service.rs +++ b/bin/node/src/service.rs @@ -344,7 +344,7 @@ pub fn new_authority( let chain_status = SubstrateChainStatus::new(backend.clone()) .map_err(|e| ServiceError::Other(format!("failed to set up chain status: {e}")))?; - let collect_extra_debugging_data = aleph_config.collect_extra_debugging_data(); + let collect_extra_debugging_data = !aleph_config.no_collection_of_extra_debugging_data(); let ( _rpc_handlers, diff --git a/bin/runtime/src/lib.rs b/bin/runtime/src/lib.rs index f1afea9970..c1edc8b5d7 100644 --- a/bin/runtime/src/lib.rs +++ b/bin/runtime/src/lib.rs @@ -1023,7 +1023,7 @@ impl_runtime_apis! { queued_keys.into_iter().filter_map(|(_, keys)| keys.get(AURA)).collect() } - fn key_owner(key: AlephId) -> Option { + fn key_owner(key: AlephId) -> Option { Session::key_owner(primitives::KEY_TYPE, key.as_ref()) } } From 18207772a9c545197987caa8c9ded209f1fef4ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20Gawrya=C5=82?= Date: Wed, 8 Nov 2023 16:40:07 +0100 Subject: [PATCH 24/24] Better flag desc --- bin/node/src/aleph_cli.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bin/node/src/aleph_cli.rs b/bin/node/src/aleph_cli.rs index dc7d8b1355..f8569296f0 100644 --- a/bin/node/src/aleph_cli.rs +++ b/bin/node/src/aleph_cli.rs @@ -52,7 +52,8 @@ pub struct AlephCli { #[clap(long, default_value_t = 64 * 1024)] alephbft_bit_rate_per_connection: u64, - /// Spend some extra time to collect more debugging data (e.g. validator network details). + /// Don't spend some extra time to collect more debugging data (e.g. validator network details). + /// By default collecting is enabled, as the impact on performance is negligible, if any. #[clap(long, default_value_t = false)] no_collection_of_extra_debugging_data: bool, }