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 1 commit
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
Prev Previous commit
Next Next commit
*: Gate authority discovery module behind feature flag
  • Loading branch information
mxinden committed Nov 28, 2019
commit 6e1a56b2714233f97afabd90b5fe819720c93306
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 @@ -54,13 +54,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 @@ -164,6 +168,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 @@ -283,18 +288,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