Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
*: Gate authority discovery module behind feature flag
Browse files Browse the repository at this point in the history
  • Loading branch information
mxinden committed Nov 27, 2019
1 parent 2e1bfa8 commit 6355956
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
13 changes: 11 additions & 2 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,21 @@ struct ValidationWorkerCommand {
pub mem_id: String,
}

#[derive(Debug, StructOpt, Clone)]
pub struct PolkadotSubParams {
#[structopt(long = "enable-authority-discovery")]
pub authority_discovery_enabled: bool,
}

cli::impl_augment_clap!(PolkadotSubParams);

/// Parses polkadot specific CLI arguments and run the service.
pub fn run<W>(worker: W, version: cli::VersionInfo) -> error::Result<()> where
W: Worker,
{
match cli::parse_and_prepare::<PolkadotSubCommands, NoCustom, _>(&version, "parity-polkadot", std::env::args()) {
match cli::parse_and_prepare::<PolkadotSubCommands, PolkadotSubParams, _>(&version, "parity-polkadot", std::env::args()) {
cli::ParseAndPrepare::Run(cmd) => cmd.run(load_spec, worker,
|worker, _cli_args, _custom_args, mut config| {
|worker, cli_args, custom_args, mut config| {
info!("{}", version.name);
info!(" version {}", config.full_version());
info!(" by {}, 2017-2019", version.author);
Expand All @@ -108,6 +116,7 @@ pub fn run<W>(worker: W, version: cli::VersionInfo) -> error::Result<()> where
info!("Node name: {}", config.name);
info!("Roles: {}", display_role(&config));
config.custom = worker.configuration();
config.custom.authority_discovery_enabled = custom_args.authority_discovery_enabled;
let runtime = Runtime::new().map_err(|e| format!("{:?}", e))?;
match config.roles {
service::Roles::LIGHT =>
Expand Down
29 changes: 18 additions & 11 deletions service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,17 @@ pub struct CustomConfiguration {

/// Maximal `block_data` size.
pub max_block_data_size: Option<u64>,

/// Whether to enable or disable the authority discovery module.
pub authority_discovery_enabled: bool,
}

impl Default for CustomConfiguration {
fn default() -> Self {
Self {
collating_for: None,
max_block_data_size: None,
authority_discovery_enabled: false,
}
}
}
Expand Down Expand Up @@ -160,6 +164,7 @@ pub fn new_full(config: Configuration<CustomConfiguration, GenesisConfig>)
};
let disable_grandpa = config.disable_grandpa;
let name = config.name.clone();
let authority_discovery_enabled = config.custom.authority_discovery_enabled;

// sentry nodes announce themselves as authorities to the network
// and should run the same protocols authorities do, but it should
Expand Down Expand Up @@ -279,18 +284,20 @@ pub fn new_full(config: Configuration<CustomConfiguration, GenesisConfig>)
let babe = babe::start_babe(babe_config)?;
service.spawn_essential_task(babe);

let future03_dht_event_rx = dht_event_rx.compat()
.map(|x| x.expect("<mpsc::channel::Receiver as Stream> never returns an error; qed"))
.boxed();
let authority_discovery = authority_discovery::AuthorityDiscovery::new(
service.client(),
service.network(),
service.keystore(),
future03_dht_event_rx,
);
let future01_authority_discovery = authority_discovery.map(|x| Ok(x)).compat();
if authority_discovery_enabled {
let future03_dht_event_rx = dht_event_rx.compat()
.map(|x| x.expect("<mpsc::channel::Receiver as Stream> never returns an error; qed"))
.boxed();
let authority_discovery = authority_discovery::AuthorityDiscovery::new(
service.client(),
service.network(),
service.keystore(),
future03_dht_event_rx,
);
let future01_authority_discovery = authority_discovery.map(|x| Ok(x)).compat();

service.spawn_task(future01_authority_discovery);
service.spawn_task(future01_authority_discovery);
}
}

// if the node isn't actively participating in consensus then it doesn't
Expand Down

0 comments on commit 6355956

Please sign in to comment.