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:
Pierre Krieger
2020-04-03 19:08:14 +02:00
committed by GitHub
parent 9dbcb11f66
commit 8c03a4fcef
44 changed files with 591 additions and 432 deletions
@@ -16,7 +16,7 @@
use structopt::StructOpt;
use log::info;
use sc_network::config::build_multiaddr;
use sc_network::config::{build_multiaddr, MultiaddrWithPeerId};
use sc_service::{Configuration, ChainSpec};
use crate::error;
@@ -60,11 +60,10 @@ impl BuildSpecCmd {
if spec.boot_nodes().is_empty() && !self.disable_default_bootnode {
let keys = config.network.node_key.into_keypair()?;
let peer_id = keys.public().into_peer_id();
let addr = build_multiaddr![
Ip4([127, 0, 0, 1]),
Tcp(30333u16),
P2p(peer_id)
];
let addr = MultiaddrWithPeerId {
multiaddr: build_multiaddr![Ip4([127, 0, 0, 1]), Tcp(30333u16)],
peer_id,
};
spec.add_boot_node(addr)
}
@@ -18,7 +18,7 @@ use std::fmt::Debug;
use std::str::FromStr;
use structopt::StructOpt;
use sc_service::{
Configuration, ServiceBuilderCommand, Roles, ChainSpec,
Configuration, ServiceBuilderCommand, Role, ChainSpec,
};
use sp_runtime::traits::{Block as BlockT, Header as HeaderT};
use sp_runtime::generic::BlockId;
@@ -93,7 +93,7 @@ impl CheckBlockCmd {
F: FnOnce(&str) -> Result<Box<dyn ChainSpec>, String>,
{
self.shared_params.update_config(&mut config, spec_factory, version)?;
self.import_params.update_config(&mut config, Roles::FULL, self.shared_params.dev)?;
self.import_params.update_config(&mut config, &Role::Full, self.shared_params.dev)?;
config.use_in_memory_keystore()?;
Ok(())
@@ -22,7 +22,7 @@ use log::info;
use structopt::StructOpt;
use sc_service::{
Configuration, ServiceBuilderCommand, ChainSpec,
config::DatabaseConfig, Roles,
config::DatabaseConfig, Role,
};
use sp_runtime::traits::{Block as BlockT, Header as HeaderT};
@@ -105,7 +105,7 @@ impl ExportBlocksCmd {
F: FnOnce(&str) -> Result<Box<dyn ChainSpec>, String>,
{
self.shared_params.update_config(&mut config, spec_factory, version)?;
self.pruning_params.update_config(&mut config, Roles::FULL, true)?;
self.pruning_params.update_config(&mut config, &Role::Full, true)?;
config.use_in_memory_keystore()?;
Ok(())
@@ -20,7 +20,7 @@ use std::fs;
use std::path::PathBuf;
use structopt::StructOpt;
use sc_service::{
Configuration, ServiceBuilderCommand, ChainSpec, Roles,
Configuration, ServiceBuilderCommand, ChainSpec, Role,
};
use sp_runtime::traits::{Block as BlockT, Header as HeaderT};
@@ -95,7 +95,7 @@ impl ImportBlocksCmd {
F: FnOnce(&str) -> Result<Box<dyn ChainSpec>, String>,
{
self.shared_params.update_config(&mut config, spec_factory, version)?;
self.import_params.update_config(&mut config, Roles::FULL, self.shared_params.dev)?;
self.import_params.update_config(&mut config, &Role::Full, self.shared_params.dev)?;
config.use_in_memory_keystore()?;
Ok(())
@@ -17,7 +17,7 @@
use std::fmt::Debug;
use structopt::StructOpt;
use sc_service::{
Configuration, ServiceBuilderCommand, ChainSpec, Roles,
Configuration, ServiceBuilderCommand, ChainSpec, Role,
};
use sp_runtime::traits::{Block as BlockT, Header as HeaderT};
@@ -71,7 +71,7 @@ impl RevertCmd {
F: FnOnce(&str) -> Result<Box<dyn ChainSpec>, String>,
{
self.shared_params.update_config(&mut config, spec_factory, version)?;
self.pruning_params.update_config(&mut config, Roles::FULL, true)?;
self.pruning_params.update_config(&mut config, &Role::Full, true)?;
config.use_in_memory_keystore()?;
Ok(())
+19 -19
View File
@@ -23,8 +23,8 @@ use names::{Generator, Name};
use regex::Regex;
use chrono::prelude::*;
use sc_service::{
AbstractService, Configuration, ChainSpec, Roles,
config::{KeystoreConfig, PrometheusConfig},
AbstractService, Configuration, ChainSpec, Role,
config::{MultiaddrWithPeerId, KeystoreConfig, PrometheusConfig},
};
use sc_telemetry::TelemetryEndpoints;
@@ -78,9 +78,10 @@ pub struct RunCmd {
/// available to relay to private nodes.
#[structopt(
long = "sentry",
conflicts_with_all = &[ "validator", "light" ]
conflicts_with_all = &[ "validator", "light" ],
parse(try_from_str)
)]
pub sentry: bool,
pub sentry: Vec<MultiaddrWithPeerId>,
/// Disable GRANDPA voter when running in validator mode, otherwise disable the GRANDPA observer.
#[structopt(long = "no-grandpa")]
@@ -329,18 +330,20 @@ impl RunCmd {
let keyring = self.get_keyring();
let is_dev = self.shared_params.dev;
let is_light = self.light;
let is_authority = (self.validator || self.sentry || is_dev || keyring.is_some())
let is_authority = (self.validator || is_dev || keyring.is_some())
&& !is_light;
let role =
if is_light {
sc_service::Roles::LIGHT
sc_service::Role::Light
} else if is_authority {
sc_service::Roles::AUTHORITY
sc_service::Role::Authority { sentry_nodes: self.network_config.sentry_nodes.clone() }
} else if !self.sentry.is_empty() {
sc_service::Role::Sentry { validators: self.sentry.clone() }
} else {
sc_service::Roles::FULL
sc_service::Role::Full
};
self.import_params.update_config(&mut config, role, is_dev)?;
self.import_params.update_config(&mut config, &role, is_dev)?;
config.name = match (self.name.as_ref(), keyring) {
(Some(name), _) => name.to_string(),
@@ -356,17 +359,14 @@ impl RunCmd {
));
}
// set sentry mode (i.e. act as an authority but **never** actively participate)
config.sentry_mode = self.sentry;
config.offchain_worker = match (&self.offchain_worker, role) {
(OffchainWorkerEnabled::WhenValidating, sc_service::Roles::AUTHORITY) => true,
config.offchain_worker = match (&self.offchain_worker, &role) {
(OffchainWorkerEnabled::WhenValidating, sc_service::Role::Authority { .. }) => true,
(OffchainWorkerEnabled::Always, _) => true,
(OffchainWorkerEnabled::Never, _) => false,
(OffchainWorkerEnabled::WhenValidating, _) => false,
};
config.roles = role;
config.role = role;
config.disable_grandpa = self.no_grandpa;
let client_id = config.client_id();
@@ -463,10 +463,10 @@ impl RunCmd {
info!("❤️ by {}, {}-{}", version.author, version.copyright_start_year, Local::today().year());
info!("📋 Chain specification: {}", config.expect_chain_spec().name());
info!("🏷 Node name: {}", config.name);
info!("👤 Roles: {}", config.display_role());
info!("👤 Role: {}", config.display_role());
match config.roles {
Roles::LIGHT => run_service_until_exit(
match config.role {
Role::Light => run_service_until_exit(
config,
new_light,
),
@@ -688,7 +688,7 @@ mod tests {
"test",
"test-id",
|| (),
vec!["boo".to_string()],
vec!["/ip4/127.0.0.1/tcp/30333/p2p/QmdSHZLmwEL5Axz5JvWNE2mmxU7qyd7xHBFpyUfktgAdg7".parse().unwrap()],
Some(TelemetryEndpoints::new(vec![("wss://foo/bar".to_string(), 42)])
.expect("provided url should be valid")),
None,