Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -224,7 +224,7 @@ pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError>
name: Some(name),
observer_enabled: false,
keystore,
is_authority: role.is_network_authority(),
is_authority: role.is_authority(),
};

if enable_grandpa {
Expand Down
2 changes: 1 addition & 1 deletion bin/node/cli/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ pub fn new_full_base(
name: Some(name),
observer_enabled: false,
keystore,
is_authority: role.is_network_authority(),
is_authority: role.is_authority(),
};

if enable_grandpa {
Expand Down
42 changes: 4 additions & 38 deletions client/cli/src/commands/run_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use crate::params::TransactionPoolParams;
use crate::CliConfiguration;
use regex::Regex;
use sc_service::{
config::{BasePath, MultiaddrWithPeerId, PrometheusConfig, TransactionPoolOptions},
config::{BasePath, PrometheusConfig, TransactionPoolOptions},
ChainSpec, Role,
};
use sc_telemetry::TelemetryEndpoints;
Expand All @@ -43,33 +43,16 @@ pub struct RunCmd {
/// participate in any consensus task that it can (e.g. depending on
/// availability of local keys).
#[structopt(
long = "validator",
conflicts_with_all = &[ "sentry" ]
long = "validator"
)]
pub validator: bool,

/// Enable sentry mode.
///
/// The node will be started with the authority role and participate in
/// consensus tasks as an "observer", it will never actively participate
/// regardless of whether it could (e.g. keys are available locally). This
/// mode is useful as a secure proxy for validators (which would run
/// detached from the network), since we want this node to participate in
/// the full consensus protocols in order to have all needed consensus data
/// available to relay to private nodes.
#[structopt(
long = "sentry",
conflicts_with_all = &[ "validator", "light" ],
parse(try_from_str)
)]
pub sentry: Vec<MultiaddrWithPeerId>,

/// Disable GRANDPA voter when running in validator mode, otherwise disable the GRANDPA observer.
#[structopt(long)]
pub no_grandpa: bool,

/// Experimental: Run in light client mode.
#[structopt(long = "light", conflicts_with = "sentry")]
#[structopt(long = "light")]
pub light: bool,

/// Listen to all RPC interfaces.
Expand Down Expand Up @@ -245,17 +228,6 @@ pub struct RunCmd {
#[structopt(long)]
pub max_runtime_instances: Option<usize>,

/// Specify a list of sentry node public addresses.
///
/// Can't be used with --public-addr as the sentry node would take precedence over the public address
/// specified there.
#[structopt(
long = "sentry-nodes",
value_name = "ADDR",
conflicts_with_all = &[ "sentry", "public-addr" ]
)]
pub sentry_nodes: Vec<MultiaddrWithPeerId>,

/// Run a temporary node.
///
/// A temporary directory will be created to store the configuration and will be deleted
Expand Down Expand Up @@ -366,13 +338,7 @@ impl CliConfiguration for RunCmd {
Ok(if is_light {
sc_service::Role::Light
} else if is_authority {
sc_service::Role::Authority {
sentry_nodes: self.sentry_nodes.clone(),
}
} else if !self.sentry.is_empty() {
sc_service::Role::Sentry {
validators: self.sentry.clone(),
}
sc_service::Role::Authority
} else {
sc_service::Role::Full
})
Expand Down
2 changes: 1 addition & 1 deletion client/cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ pub trait CliConfiguration<DCV: DefaultConfigurationValues = ()>: Sized {
let node_key = self.node_key(&net_config_dir)?;
let role = self.role(is_dev)?;
let max_runtime_instances = self.max_runtime_instances()?.unwrap_or(8);
let is_validator = role.is_network_authority();
let is_validator = role.is_authority();
let (keystore_remote, keystore) = self.keystore_config(&config_dir)?;
let telemetry_endpoints = telemetry_handle
.as_ref()
Expand Down
4 changes: 2 additions & 2 deletions client/cli/src/params/pruning_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ impl PruningParams {
// unless `unsafe_pruning` is set.
Ok(match &self.pruning {
Some(ref s) if s == "archive" => PruningMode::ArchiveAll,
None if role.is_network_authority() => PruningMode::ArchiveAll,
None if role.is_authority() => PruningMode::ArchiveAll,
None => PruningMode::default(),
Some(s) => {
if role.is_network_authority() && !unsafe_pruning {
if role.is_authority() && !unsafe_pruning {
return Err(error::Error::Input(
"Validators should run with state pruning disabled (i.e. archive). \
You can ignore this check with `--unsafe-pruning`."
Expand Down
7 changes: 1 addition & 6 deletions client/finality-grandpa/src/communication/gossip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -563,12 +563,10 @@ impl<N: Ord> Peers<N> {
}

fn authorities(&self) -> usize {
// Note that our sentry and our validator are neither authorities nor non-authorities.
self.inner.iter().filter(|(_, info)| matches!(info.roles, ObservedRole::Authority)).count()
}

fn non_authorities(&self) -> usize {
// Note that our sentry and our validator are neither authorities nor non-authorities.
self.inner
.iter()
.filter(|(_, info)| matches!(info.roles, ObservedRole::Full | ObservedRole::Light))
Expand Down Expand Up @@ -665,8 +663,7 @@ impl CatchUpConfig {
match self {
CatchUpConfig::Disabled => false,
CatchUpConfig::Enabled { only_from_authorities, .. } => match peer.roles {
ObservedRole::Authority | ObservedRole::OurSentry |
ObservedRole::OurGuardedAuthority => true,
ObservedRole::Authority => true,
_ => !only_from_authorities
}
}
Expand Down Expand Up @@ -1158,7 +1155,6 @@ impl<Block: BlockT> Inner<Block> {
}

match peer.roles {
ObservedRole::OurGuardedAuthority | ObservedRole::OurSentry => true,
ObservedRole::Authority => {
let authorities = self.peers.authorities();

Expand Down Expand Up @@ -1214,7 +1210,6 @@ impl<Block: BlockT> Inner<Block> {
};

match peer.roles {
ObservedRole::OurSentry | ObservedRole::OurGuardedAuthority => true,
ObservedRole::Authority => {
let authorities = self.peers.authorities();

Expand Down
21 changes: 4 additions & 17 deletions client/network/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use crate::{
config::{ProtocolId, Role},
config::ProtocolId,
bitswap::Bitswap,
discovery::{DiscoveryBehaviour, DiscoveryConfig, DiscoveryOut},
protocol::{message::Roles, CustomMessageOutcome, NotificationsSink, Protocol},
Expand Down Expand Up @@ -71,10 +71,6 @@ pub struct Behaviour<B: BlockT, H: ExHashT> {
#[behaviour(ignore)]
events: VecDeque<BehaviourOut<B>>,

/// Role of our local node, as originally passed from the configuration.
#[behaviour(ignore)]
role: Role,

/// Light client request handling.
#[behaviour(ignore)]
light_client_request_sender: light_client_requests::sender::LightClientRequestSender<B>,
Expand Down Expand Up @@ -180,7 +176,6 @@ impl<B: BlockT, H: ExHashT> Behaviour<B, H> {
/// Builds a new `Behaviour`.
pub fn new(
substrate: Protocol<B, H>,
role: Role,
user_agent: String,
local_public_key: PublicKey,
light_client_request_sender: light_client_requests::sender::LightClientRequestSender<B>,
Expand All @@ -206,7 +201,6 @@ impl<B: BlockT, H: ExHashT> Behaviour<B, H> {
request_responses::RequestResponsesBehaviour::new(request_response_protocols.into_iter())?,
light_client_request_sender,
events: VecDeque::new(),
role,

block_request_protocol_name,
})
Expand Down Expand Up @@ -290,15 +284,9 @@ impl<B: BlockT, H: ExHashT> Behaviour<B, H> {
}
}

fn reported_roles_to_observed_role(local_role: &Role, remote: &PeerId, roles: Roles) -> ObservedRole {
fn reported_roles_to_observed_role(roles: Roles) -> ObservedRole {
if roles.is_authority() {
match local_role {
Role::Authority { sentry_nodes }
if sentry_nodes.iter().any(|s| s.peer_id == *remote) => ObservedRole::OurSentry,
Role::Sentry { validators }
if validators.iter().any(|s| s.peer_id == *remote) => ObservedRole::OurGuardedAuthority,
_ => ObservedRole::Authority
}
ObservedRole::Authority
} else if roles.is_full() {
ObservedRole::Full
} else {
Expand Down Expand Up @@ -337,11 +325,10 @@ Behaviour<B, H> {
);
},
CustomMessageOutcome::NotificationStreamOpened { remote, protocol, roles, notifications_sink } => {
let role = reported_roles_to_observed_role(&self.role, &remote, roles);
self.events.push_back(BehaviourOut::NotificationStreamOpened {
remote,
protocol,
role: role.clone(),
role: reported_roles_to_observed_role(roles),
notifications_sink: notifications_sink.clone(),
});
},
Expand Down
2 changes: 1 addition & 1 deletion client/network/src/block_request_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl <B: BlockT> BlockRequestHandler<B> {
pub fn new(protocol_id: &ProtocolId, client: Arc<dyn Client<B>>) -> (Self, ProtocolConfig) {
// Rate of arrival multiplied with the waiting time in the queue equals the queue length.
//
// An average Polkadot sentry node serves less than 5 requests per second. The 95th percentile
// An average Polkadot node serves less than 5 requests per second. The 95th percentile
// serving a request is less than 2 second. Thus one would estimate the queue length to be
// below 10.
//
Expand Down
19 changes: 1 addition & 18 deletions client/network/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,39 +128,22 @@ pub enum Role {
Full,
/// Regular light node.
Light,
/// Sentry node that guards an authority. Will be reported as "authority" on the wire protocol.
Sentry {
/// Address and identity of the validator nodes that we're guarding.
///
/// The nodes will be granted some priviledged status.
validators: Vec<MultiaddrWithPeerId>,
},
/// Actual authority.
Authority {
/// List of public addresses and identities of our sentry nodes.
sentry_nodes: Vec<MultiaddrWithPeerId>,
}
Authority,
}

impl Role {
/// True for `Role::Authority`
pub fn is_authority(&self) -> bool {
matches!(self, Role::Authority { .. })
}

/// True for `Role::Authority` and `Role::Sentry` since they're both
/// announced as having the authority role to the network.
pub fn is_network_authority(&self) -> bool {
matches!(self, Role::Authority { .. } | Role::Sentry { .. })
}
}

impl fmt::Display for Role {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Role::Full => write!(f, "FULL"),
Role::Light => write!(f, "LIGHT"),
Role::Sentry { .. } => write!(f, "SENTRY"),
Role::Authority { .. } => write!(f, "AUTHORITY"),
}
}
Expand Down
15 changes: 0 additions & 15 deletions client/network/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,21 +384,6 @@ impl<B: BlockT, H: ExHashT> Protocol<B, H> {
let mut sets = Vec::with_capacity(NUM_HARDCODED_PEERSETS + network_config.extra_sets.len());

let mut default_sets_reserved = HashSet::new();
match config_role {
config::Role::Sentry { validators } => {
for validator in validators {
default_sets_reserved.insert(validator.peer_id.clone());
known_addresses.push((validator.peer_id.clone(), validator.multiaddr.clone()));
}
}
config::Role::Authority { sentry_nodes } => {
for sentry_node in sentry_nodes {
default_sets_reserved.insert(sentry_node.peer_id.clone());
known_addresses.push((sentry_node.peer_id.clone(), sentry_node.multiaddr.clone()));
}
}
_ => {}
};
for reserved in network_config.default_peers_set.reserved_nodes.iter() {
default_sets_reserved.insert(reserved.peer_id.clone());
known_addresses.push((reserved.peer_id.clone(), reserved.multiaddr.clone()));
Expand Down
8 changes: 4 additions & 4 deletions client/network/src/protocol/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,16 @@ pub enum Event {

/// Role that the peer sent to us during the handshake, with the addition of what our local node
/// knows about that peer.
///
/// > **Note**: This enum is different from the `Role` enum. The `Role` enum indicates what a
/// > node says about itself, while `ObservedRole` is a `Role` merged with the
/// > information known locally about that node.
#[derive(Debug, Clone)]
pub enum ObservedRole {
/// Full node.
Full,
/// Light node.
Light,
/// When we are a validator node, this is a sentry that protects us.
OurSentry,
/// When we are a sentry node, this is the authority we are protecting.
OurGuardedAuthority,
/// Third-party authority.
Authority,
}
Expand Down
1 change: 0 additions & 1 deletion client/network/src/protocol/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ pub mod generic {
match roles {
crate::config::Role::Full => Roles::FULL,
crate::config::Role::Light => Roles::LIGHT,
crate::config::Role::Sentry { .. } => Roles::AUTHORITY,
crate::config::Role::Authority { .. } => Roles::AUTHORITY,
}
}
Expand Down
19 changes: 1 addition & 18 deletions client/network/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
use crate::{
ExHashT, NetworkStateInfo, NetworkStatus,
behaviour::{self, Behaviour, BehaviourOut},
config::{parse_str_addr, Params, Role, TransportConfig},
config::{parse_str_addr, Params, TransportConfig},
DhtEvent,
discovery::DiscoveryConfig,
error::Error,
Expand Down Expand Up @@ -225,22 +225,6 @@ impl<B: BlockT + 'static, H: ExHashT> NetworkWorker<B, H> {
}
)?;

// Print a message about the deprecation of sentry nodes.
let print_deprecated_message = match &params.role {
Role::Sentry { .. } => true,
Role::Authority { sentry_nodes } if !sentry_nodes.is_empty() => true,
_ => false,
};
if print_deprecated_message {
log::warn!(
"🙇 Sentry nodes are deprecated, and the `--sentry` and `--sentry-nodes` \
CLI options will eventually be removed in a future version. The Substrate \
and Polkadot networking protocol require validators to be \
publicly-accessible. Please do not block access to your validator nodes. \
For details, see https://github.com/paritytech/substrate/issues/6845."
);
}

let checker = params.on_demand.as_ref()
.map(|od| od.checker().clone())
.unwrap_or_else(|| Arc::new(AlwaysBadChecker));
Expand Down Expand Up @@ -339,7 +323,6 @@ impl<B: BlockT + 'static, H: ExHashT> NetworkWorker<B, H> {
let bitswap = if params.network_config.ipfs_server { Some(Bitswap::new(client)) } else { None };
let result = Behaviour::new(
protocol,
params.role,
user_agent,
local_public,
light_client_request_sender,
Expand Down
2 changes: 0 additions & 2 deletions client/rpc-api/src/system/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ pub enum NodeRole {
LightClient,
/// The node is an authority
Authority,
/// The node is a sentry
Sentry,
}

/// The state of the syncing of the node.
Expand Down
1 change: 0 additions & 1 deletion client/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,6 @@ async fn build_network_future<
Role::Authority { .. } => NodeRole::Authority,
Role::Light => NodeRole::LightClient,
Role::Full => NodeRole::Full,
Role::Sentry { .. } => NodeRole::Sentry,
};

let _ = sender.send(vec![node_role]);
Expand Down
1 change: 0 additions & 1 deletion client/service/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ impl MetricsService {
let role_bits = match config.role {
Role::Full => 1u64,
Role::Light => 2u64,
Role::Sentry { .. } => 3u64,
Role::Authority { .. } => 4u64,
};

Expand Down
2 changes: 1 addition & 1 deletion client/service/test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ impl<G, E, F, L, U> TestNet<G, E, F, L, U> where
let node_config = node_config(
self.nodes,
&self.chain_spec,
Role::Authority { sentry_nodes: Vec::new() },
Role::Authority,
task_executor.clone(),
Some(key),
self.base_port,
Expand Down