Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/node-template/node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ macro_rules! new_full_start {
pub fn new_full(config: Configuration)
-> Result<impl AbstractService, ServiceError>
{
let is_authority = config.roles.is_authority();
let is_authority = config.role.is_authority();
Comment thread
cecton marked this conversation as resolved.
Outdated
let force_authoring = config.force_authoring;
let name = config.name.clone();
let disable_grandpa = config.disable_grandpa;
Expand Down
4 changes: 2 additions & 2 deletions bin/node/cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.

use sc_cli::VersionInfo;
use sc_service::{Roles as ServiceRoles};
use sc_service::{Role as ServiceRole};
use node_transaction_factory::RuntimeAdapter;
use crate::{Cli, service, ChainSpec, load_spec, Subcommand, factory_impl::FactoryState};

Expand Down Expand Up @@ -65,7 +65,7 @@ where
cli_args.shared_params.update_config(&mut config, load_spec, &version)?;
cli_args.import_params.update_config(
&mut config,
ServiceRoles::FULL,
&ServiceRole::Full,
cli_args.shared_params.dev,
)?;

Expand Down
23 changes: 10 additions & 13 deletions bin/node/cli/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,24 +120,17 @@ macro_rules! new_full {
use sc_client_api::ExecutorProvider;

let (
is_authority,
role,
force_authoring,
name,
disable_grandpa,
sentry_nodes,
) = (
$config.roles.is_authority(),
$config.role.clone(),
$config.force_authoring,
$config.name.clone(),
$config.disable_grandpa,
$config.network.sentry_nodes.clone(),
);

// sentry nodes announce themselves as authorities to the network
// and should run the same protocols authorities do, but it should
// never actively participate in any consensus process.
let participates_in_consensus = is_authority && !$config.sentry_mode;

let (builder, mut import_setup, inherent_data_providers) = new_full_start!($config);

let service = builder
Expand All @@ -153,7 +146,7 @@ macro_rules! new_full {

($with_startup_data)(&block_import, &babe_link);

if participates_in_consensus {
if let sc_service::config::Role::Authority { sentry_nodes } = &role {
let proposer = sc_basic_authorship::ProposerFactory::new(
service.client(),
service.transaction_pool()
Expand Down Expand Up @@ -190,7 +183,7 @@ macro_rules! new_full {
let authority_discovery = sc_authority_discovery::AuthorityDiscovery::new(
service.client(),
network,
sentry_nodes,
sentry_nodes.clone(),
service.keystore(),
dht_event_stream,
service.prometheus_registry(),
Expand All @@ -201,7 +194,7 @@ macro_rules! new_full {

// if the node isn't actively participating in consensus then it doesn't
// need a keystore, regardless of which protocol we use below.
let keystore = if participates_in_consensus {
let keystore = if role.is_authority() {
Some(service.keystore())
} else {
None
Expand All @@ -214,7 +207,11 @@ macro_rules! new_full {
name: Some(name),
observer_enabled: false,
keystore,
is_authority,
is_authority: match role {
sc_service::config::Role::Authority { .. } |
sc_service::config::Role::Sentry { .. } => true,
_ => false,
}
};

let enable_grandpa = !disable_grandpa;
Expand Down
2 changes: 1 addition & 1 deletion bin/node/inspect/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl InspectCmd {
// and all import params (especially pruning that has to match db meta)
self.import_params.update_config(
&mut config,
sc_service::Roles::FULL,
&sc_service::Role::Full,
self.shared_params.dev,
)?;

Expand Down
18 changes: 3 additions & 15 deletions client/authority-discovery/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,11 @@ use futures_timer::Delay;

use codec::{Decode, Encode};
use error::{Error, Result};
use libp2p::Multiaddr;
use log::{debug, error, log_enabled, warn};
use prometheus_endpoint::{Counter, CounterVec, Gauge, Opts, U64, register};
use prost::Message;
use sc_client_api::blockchain::HeaderBackend;
use sc_network::{DhtEvent, ExHashT, NetworkStateInfo};
use sc_network::{Multiaddr, config::MultiaddrWithPeerId, DhtEvent, ExHashT, NetworkStateInfo};
use sp_authority_discovery::{AuthorityDiscoveryApi, AuthorityId, AuthoritySignature, AuthorityPair};
use sp_core::crypto::{key_types, CryptoTypePublicPair, Pair};
use sp_core::traits::BareCryptoStorePtr;
Expand Down Expand Up @@ -187,7 +186,7 @@ where
pub fn new(
client: Arc<Client>,
network: Arc<Network>,
sentry_nodes: Vec<String>,
sentry_nodes: Vec<MultiaddrWithPeerId>,
key_store: BareCryptoStorePtr,
dht_event_rx: Pin<Box<dyn Stream<Item = DhtEvent> + Send>>,
prometheus_registry: Option<prometheus_endpoint::Registry>,
Expand All @@ -210,18 +209,7 @@ where
);

let sentry_nodes = if !sentry_nodes.is_empty() {
let addrs = sentry_nodes.into_iter().filter_map(|a| match a.parse() {
Ok(addr) => Some(addr),
Err(e) => {
error!(
target: "sub-authority-discovery",
"Failed to parse sentry node public address '{:?}', continuing anyways.", e,
);
None
}
}).collect::<Vec<Multiaddr>>();

Some(addrs)
Some(sentry_nodes.into_iter().map(|ma| ma.concat()).collect::<Vec<_>>())
} else {
None
};
Expand Down
16 changes: 8 additions & 8 deletions client/chain-spec/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use sp_runtime::BuildStorage;
use serde_json as json;
use crate::RuntimeGenesis;
use crate::extension::GetExtension;
use sc_network::Multiaddr;
use sc_network::config::MultiaddrWithPeerId;
use sc_telemetry::TelemetryEndpoints;

enum GenesisSource<G> {
Expand Down Expand Up @@ -137,7 +137,7 @@ enum Genesis<G> {
struct ClientSpec<E> {
name: String,
id: String,
boot_nodes: Vec<String>,
boot_nodes: Vec<MultiaddrWithPeerId>,
telemetry_endpoints: Option<TelemetryEndpoints>,
protocol_id: Option<String>,
properties: Option<Properties>,
Expand Down Expand Up @@ -174,7 +174,7 @@ impl<G, E: Clone> Clone for ChainSpec<G, E> {

impl<G, E> ChainSpec<G, E> {
/// A list of bootnode addresses.
pub fn boot_nodes(&self) -> &[String] {
pub fn boot_nodes(&self) -> &[MultiaddrWithPeerId] {
&self.client_spec.boot_nodes
}

Expand Down Expand Up @@ -206,8 +206,8 @@ impl<G, E> ChainSpec<G, E> {
}

/// Add a bootnode to the list.
pub fn add_boot_node(&mut self, addr: Multiaddr) {
self.client_spec.boot_nodes.push(addr.to_string())
pub fn add_boot_node(&mut self, addr: MultiaddrWithPeerId) {
self.client_spec.boot_nodes.push(addr)
}

/// Returns a reference to defined chain spec extensions.
Expand All @@ -220,7 +220,7 @@ impl<G, E> ChainSpec<G, E> {
name: &str,
id: &str,
constructor: F,
boot_nodes: Vec<String>,
boot_nodes: Vec<MultiaddrWithPeerId>,
telemetry_endpoints: Option<TelemetryEndpoints>,
protocol_id: Option<&str>,
properties: Option<Properties>,
Expand Down Expand Up @@ -320,7 +320,7 @@ where
G: RuntimeGenesis,
E: GetExtension + serde::Serialize + Clone + Send,
{
fn boot_nodes(&self) -> &[String] {
fn boot_nodes(&self) -> &[MultiaddrWithPeerId] {
ChainSpec::boot_nodes(self)
}

Expand All @@ -344,7 +344,7 @@ where
ChainSpec::properties(self)
}

fn add_boot_node(&mut self, addr: Multiaddr) {
fn add_boot_node(&mut self, addr: MultiaddrWithPeerId) {
ChainSpec::add_boot_node(self, addr)
}

Expand Down
6 changes: 3 additions & 3 deletions client/chain-spec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ pub use sc_chain_spec_derive::{ChainSpecExtension, ChainSpecGroup};

use serde::{Serialize, de::DeserializeOwned};
use sp_runtime::BuildStorage;
use sc_network::Multiaddr;
use sc_network::config::MultiaddrWithPeerId;
use sc_telemetry::TelemetryEndpoints;

/// A set of traits for the runtime genesis config.
Expand All @@ -131,7 +131,7 @@ pub trait ChainSpec: BuildStorage + Send {
/// Spec id.
fn id(&self) -> &str;
/// A list of bootnode addresses.
fn boot_nodes(&self) -> &[String];
fn boot_nodes(&self) -> &[MultiaddrWithPeerId];
/// Telemetry endpoints (if any)
fn telemetry_endpoints(&self) -> &Option<TelemetryEndpoints>;
/// Network protocol id.
Expand All @@ -143,7 +143,7 @@ pub trait ChainSpec: BuildStorage + Send {
/// Returns a reference to defined chain spec extensions.
fn extensions(&self) -> &dyn GetExtension;
/// Add a bootnode to the list.
fn add_boot_node(&mut self, addr: Multiaddr);
fn add_boot_node(&mut self, addr: MultiaddrWithPeerId);
/// Return spec as JSON.
fn as_json(&self, raw: bool) -> Result<String, String>;
/// Return StorageBuilder for this spec.
Expand Down
11 changes: 5 additions & 6 deletions client/cli/src/commands/build_spec_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
}

Expand Down
4 changes: 2 additions & 2 deletions client/cli/src/commands/check_block_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(())
Expand Down
4 changes: 2 additions & 2 deletions client/cli/src/commands/export_blocks_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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(())
Expand Down
4 changes: 2 additions & 2 deletions client/cli/src/commands/import_blocks_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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(())
Expand Down
4 changes: 2 additions & 2 deletions client/cli/src/commands/revert_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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(())
Expand Down
Loading