WIP: Node role RPC call (#3719)

* Add a Node Role RPC call

* Formatting

* Fix tests

* Change tests to use NodeRole::Authority so I don't forget to update the test

* Improve role checking

* return a vec instead

* fix tests
This commit is contained in:
Ashley
2019-10-16 10:59:25 +01:00
committed by Bastian Köcher
parent 8ef20a5534
commit 642c8504c4
5 changed files with 62 additions and 9 deletions
+18 -1
View File
@@ -368,6 +368,7 @@ macro_rules! new_impl {
let _ = to_spawn_tx.unbounded_send(Box::new(build_network_future(
$config.roles,
network_mut,
client.clone(),
network_status_sinks.clone(),
@@ -662,6 +663,7 @@ fn build_network_future<
S: network::specialization::NetworkSpecialization<B>,
H: network::ExHashT
> (
roles: Roles,
mut network: network::NetworkWorker<B, S, H>,
client: Arc<C>,
status_sinks: Arc<Mutex<Vec<mpsc::UnboundedSender<(NetworkStatus<B>, NetworkState)>>>>,
@@ -669,7 +671,7 @@ fn build_network_future<
should_have_peers: bool,
dht_event_tx: Option<mpsc::Sender<DhtEvent>>,
) -> impl Future<Item = (), Error = ()> {
// Compatibility shim while we're transitionning to stable Futures.
// Compatibility shim while we're transitioning to stable Futures.
// See https://github.com/paritytech/substrate/issues/3099
let mut rpc_rx = futures03::compat::Compat::new(rpc_rx.map(|v| Ok::<_, ()>(v)));
@@ -725,6 +727,21 @@ fn build_network_future<
let _ = sender.send(network_state);
}
}
rpc::system::Request::NodeRoles(sender) => {
use rpc::system::NodeRole;
let node_roles = (0 .. 8)
.filter(|&bit_number| (roles.bits() >> bit_number) & 1 == 1)
.map(|bit_number| match Roles::from_bits(1 << bit_number) {
Some(Roles::AUTHORITY) => NodeRole::Authority,
Some(Roles::LIGHT) => NodeRole::LightClient,
Some(Roles::FULL) => NodeRole::Full,
_ => NodeRole::UnknownRole(bit_number),
})
.collect();
let _ = sender.send(node_roles);
}
};
}