node: add sentry mode flag (#3959)

* node: add sentry mode flag

* cli: extend docs on validator and sentry modes

* service: add missing field in test Configuration

* node: Display instead of Debug when printing node role
This commit is contained in:
André Silva
2019-10-29 18:58:34 +00:00
committed by Bastian Köcher
parent dc14809804
commit c92eda9809
8 changed files with 79 additions and 10 deletions
+16 -1
View File
@@ -236,6 +236,17 @@ where
}
}
/// Returns a string displaying the node role, special casing the sentry mode
/// (returning `SENTRY`), since the node technically has an `AUTHORITY` role but
/// doesn't participate.
pub fn display_role<A, B>(config: &Configuration<(), A, B>) -> String {
if config.sentry_mode {
"SENTRY".to_string()
} else {
format!("{:?}", config.roles)
}
}
/// Output of calling `parse_and_prepare`.
#[must_use]
pub enum ParseAndPrepare<'a, CC, RP> {
@@ -658,16 +669,20 @@ where
config.state_cache_size = cli.state_cache_size;
let is_dev = cli.shared_params.dev;
let is_authority = cli.validator || cli.sentry || is_dev || cli.keyring.account.is_some();
let role =
if cli.light {
service::Roles::LIGHT
} else if cli.validator || is_dev || cli.keyring.account.is_some() {
} else if is_authority {
service::Roles::AUTHORITY
} else {
service::Roles::FULL
};
// set sentry mode (i.e. act as an authority but **never** actively participate)
config.sentry_mode = cli.sentry;
// by default we disable pruning if the node is an authority (i.e.
// `ArchiveAll`), otherwise we keep state for the last 256 blocks. if the
// node is an authority and pruning is enabled explicitly, then we error
+23 -1
View File
@@ -301,9 +301,31 @@ pub struct ExecutionStrategies {
#[derive(Debug, StructOpt, Clone)]
pub struct RunCmd {
/// Enable validator mode.
#[structopt(long = "validator")]
///
/// The node will be started with the authority role and actively
/// participate in any consensus task that it can (e.g. depending on
/// availability of local keys).
#[structopt(
long = "validator",
conflicts_with_all = &[ "sentry" ]
)]
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" ]
)]
pub sentry: bool,
/// Disable GRANDPA voter when running in validator mode, otherwise disables the GRANDPA observer.
#[structopt(long = "no-grandpa")]
pub no_grandpa: bool,