mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-28 14:27:57 +00:00
Split the Roles in three types (#5520)
* Split the Roles bitfield in three * Forgot to include some changes * Fix cli test * More test fixes * Oh God, merging master broke other tests * Didn't run the doctests * Address review * I'm trying to fix the build blindly because it's taking a good hour to compile on my machine * Address some review * Also update the peerset's API to make sense * Fix peerset tests * Fix browser node * client: distinguish between local and network authority Co-authored-by: André Silva <andre.beat@gmail.com>
This commit is contained in:
@@ -27,7 +27,7 @@
|
||||
|
||||
use crate::{
|
||||
behaviour::{Behaviour, BehaviourOut},
|
||||
config::{parse_addr, parse_str_addr, NonReservedPeerMode, Params, TransportConfig},
|
||||
config::{parse_addr, parse_str_addr, NonReservedPeerMode, Params, Role, TransportConfig},
|
||||
error::Error,
|
||||
network_state::{
|
||||
NetworkState, NotConnectedPeer as NetworkStateNotConnectedPeer, Peer as NetworkStatePeer,
|
||||
@@ -181,19 +181,13 @@ impl<B: BlockT + 'static, H: ExHashT> NetworkWorker<B, H> {
|
||||
// List of multiaddresses that we know in the network.
|
||||
let mut known_addresses = Vec::new();
|
||||
let mut bootnodes = Vec::new();
|
||||
let mut reserved_nodes = Vec::new();
|
||||
let mut boot_node_ids = HashSet::new();
|
||||
|
||||
// Process the bootnodes.
|
||||
for bootnode in params.network_config.boot_nodes.iter() {
|
||||
match parse_str_addr(bootnode) {
|
||||
Ok((peer_id, addr)) => {
|
||||
bootnodes.push(peer_id.clone());
|
||||
boot_node_ids.insert(peer_id.clone());
|
||||
known_addresses.push((peer_id, addr));
|
||||
},
|
||||
Err(_) => warn!(target: "sub-libp2p", "Not a valid bootnode address: {}", bootnode),
|
||||
}
|
||||
bootnodes.push(bootnode.peer_id.clone());
|
||||
boot_node_ids.insert(bootnode.peer_id.clone());
|
||||
known_addresses.push((bootnode.peer_id.clone(), bootnode.multiaddr.clone()));
|
||||
}
|
||||
|
||||
let boot_node_ids = Arc::new(boot_node_ids);
|
||||
@@ -215,22 +209,43 @@ impl<B: BlockT + 'static, H: ExHashT> NetworkWorker<B, H> {
|
||||
}
|
||||
)?;
|
||||
|
||||
// Initialize the reserved peers.
|
||||
for reserved in params.network_config.reserved_nodes.iter() {
|
||||
if let Ok((peer_id, addr)) = parse_str_addr(reserved) {
|
||||
reserved_nodes.push(peer_id.clone());
|
||||
known_addresses.push((peer_id, addr));
|
||||
} else {
|
||||
warn!(target: "sub-libp2p", "Not a valid reserved node address: {}", reserved);
|
||||
// Initialize the peers we should always be connected to.
|
||||
let priority_groups = {
|
||||
let mut reserved_nodes = HashSet::new();
|
||||
for reserved in params.network_config.reserved_nodes.iter() {
|
||||
reserved_nodes.insert(reserved.peer_id.clone());
|
||||
known_addresses.push((reserved.peer_id.clone(), reserved.multiaddr.clone()));
|
||||
}
|
||||
}
|
||||
|
||||
let mut sentries_and_validators = HashSet::new();
|
||||
match ¶ms.role {
|
||||
Role::Sentry { validators } => {
|
||||
for validator in validators {
|
||||
sentries_and_validators.insert(validator.peer_id.clone());
|
||||
known_addresses.push((validator.peer_id.clone(), validator.multiaddr.clone()));
|
||||
}
|
||||
}
|
||||
Role::Authority { sentry_nodes } => {
|
||||
for sentry_node in sentry_nodes {
|
||||
sentries_and_validators.insert(sentry_node.peer_id.clone());
|
||||
known_addresses.push((sentry_node.peer_id.clone(), sentry_node.multiaddr.clone()));
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
vec![
|
||||
("reserved".to_owned(), reserved_nodes),
|
||||
("sentries_and_validators".to_owned(), sentries_and_validators),
|
||||
]
|
||||
};
|
||||
|
||||
let peerset_config = sc_peerset::PeersetConfig {
|
||||
in_peers: params.network_config.in_peers,
|
||||
out_peers: params.network_config.out_peers,
|
||||
bootnodes,
|
||||
reserved_only: params.network_config.non_reserved_mode == NonReservedPeerMode::Deny,
|
||||
reserved_nodes,
|
||||
priority_groups,
|
||||
};
|
||||
|
||||
// Private and public keys configuration.
|
||||
@@ -253,7 +268,7 @@ impl<B: BlockT + 'static, H: ExHashT> NetworkWorker<B, H> {
|
||||
let is_major_syncing = Arc::new(AtomicBool::new(false));
|
||||
let (protocol, peerset_handle) = Protocol::new(
|
||||
protocol::ProtocolConfig {
|
||||
roles: params.roles,
|
||||
roles: From::from(¶ms.role),
|
||||
max_parallel_downloads: params.network_config.max_parallel_downloads,
|
||||
},
|
||||
params.chain.clone(),
|
||||
@@ -285,6 +300,7 @@ impl<B: BlockT + 'static, H: ExHashT> NetworkWorker<B, H> {
|
||||
};
|
||||
let behaviour = futures::executor::block_on(Behaviour::new(
|
||||
protocol,
|
||||
params.role,
|
||||
user_agent,
|
||||
local_public,
|
||||
known_addresses,
|
||||
@@ -971,11 +987,8 @@ impl<B: BlockT + 'static, H: ExHashT> Future for NetworkWorker<B, H> {
|
||||
this.network_service.user_protocol_mut().write_notification(target, engine_id, message)
|
||||
},
|
||||
ServiceToWorkerMsg::RegisterNotifProtocol { engine_id, protocol_name } => {
|
||||
let events = this.network_service.user_protocol_mut()
|
||||
this.network_service
|
||||
.register_notifications_protocol(engine_id, protocol_name);
|
||||
for event in events {
|
||||
this.event_streams.retain(|sender| sender.unbounded_send(event.clone()).is_ok());
|
||||
}
|
||||
},
|
||||
ServiceToWorkerMsg::DisconnectPeer(who) =>
|
||||
this.network_service.user_protocol_mut().disconnect_peer(&who),
|
||||
|
||||
Reference in New Issue
Block a user