Skip to content

Commit

Permalink
Reduce &Configuration usage
Browse files Browse the repository at this point in the history
  • Loading branch information
nazar-pc committed Aug 14, 2024
1 parent c8718f5 commit 7d0fef5
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 36 deletions.
10 changes: 2 additions & 8 deletions cumulus/polkadot-parachain/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -664,15 +664,9 @@ impl CliConfiguration<Self> for RelayChainCli {
self.base.base.prometheus_config(default_listen_port, chain_spec)
}

fn init<F>(
&self,
_support_url: &String,
_impl_version: &String,
_logger_hook: F,
_config: &sc_service::Configuration,
) -> Result<()>
fn init<F>(&self, _support_url: &String, _impl_version: &String, _logger_hook: F) -> Result<()>
where
F: FnOnce(&mut sc_cli::LoggerBuilder, &sc_service::Configuration),
F: FnOnce(&mut sc_cli::LoggerBuilder),
{
unreachable!("PolkadotCli is never initialized; qed");
}
Expand Down
3 changes: 1 addition & 2 deletions cumulus/test/service/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,9 @@ impl CliConfiguration<Self> for RelayChainCli {
_support_url: &String,
_impl_version: &String,
_logger_hook: F,
_config: &sc_service::Configuration,
) -> CliResult<()>
where
F: FnOnce(&mut sc_cli::LoggerBuilder, &sc_service::Configuration),
F: FnOnce(&mut sc_cli::LoggerBuilder),
{
unreachable!("PolkadotCli is never initialized; qed");
}
Expand Down
20 changes: 3 additions & 17 deletions substrate/client/cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -615,15 +615,9 @@ pub trait CliConfiguration<DCV: DefaultConfigurationValues = ()>: Sized {
/// }
/// }
/// ```
fn init<F>(
&self,
support_url: &String,
impl_version: &String,
logger_hook: F,
config: &Configuration,
) -> Result<()>
fn init<F>(&self, support_url: &String, impl_version: &String, logger_hook: F) -> Result<()>
where
F: FnOnce(&mut LoggerBuilder, &Configuration),
F: FnOnce(&mut LoggerBuilder),
{
sp_panic_handler::set(support_url, impl_version);

Expand All @@ -642,18 +636,10 @@ pub trait CliConfiguration<DCV: DefaultConfigurationValues = ()>: Sized {
}

// Call hook for custom profiling setup.
logger_hook(&mut logger, config);
logger_hook(&mut logger);

logger.init()?;

if config.role.is_authority() && config.network.public_addresses.is_empty() {
warn!(
"WARNING: No public address specified, validator node may not be reachable.
Consider setting `--public-addr` to the public IP address of this node.
This will become a hard requirement in future versions."
);
}

match fdlimit::raise_fd_limit() {
Ok(fdlimit::Outcome::LimitRaised { to, .. }) =>
if to < RECOMMENDED_OPEN_FILE_DESCRIPTOR_LIMIT {
Expand Down
14 changes: 13 additions & 1 deletion substrate/client/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#![warn(unused_imports)]

use clap::{CommandFactory, FromArgMatches, Parser};
use log::warn;
use sc_service::Configuration;

pub mod arg_enums;
Expand Down Expand Up @@ -242,7 +243,18 @@ pub trait SubstrateCli: Sized {

let config = command.create_configuration(self, tokio_runtime.handle().clone())?;

command.init(&Self::support_url(), &Self::impl_version(), logger_hook, &config)?;
command.init(&Self::support_url(), &Self::impl_version(), |logger_builder| {
logger_hook(logger_builder, &config)
})?;

if config.role.is_authority() && config.network.public_addresses.is_empty() {
warn!(
"WARNING: No public address specified, validator node may not be reachable.
Consider setting `--public-addr` to the public IP address of this node.
This will become a hard requirement in future versions."
);
}

Runner::new(config, tokio_runtime, signals)
}
}
10 changes: 2 additions & 8 deletions templates/parachain/node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,15 +309,9 @@ impl CliConfiguration<Self> for RelayChainCli {
self.base.base.prometheus_config(default_listen_port, chain_spec)
}

fn init<F>(
&self,
_support_url: &String,
_impl_version: &String,
_logger_hook: F,
_config: &sc_service::Configuration,
) -> Result<()>
fn init<F>(&self, _support_url: &String, _impl_version: &String, _logger_hook: F) -> Result<()>
where
F: FnOnce(&mut sc_cli::LoggerBuilder, &sc_service::Configuration),
F: FnOnce(&mut sc_cli::LoggerBuilder),
{
unreachable!("PolkadotCli is never initialized; qed");
}
Expand Down

0 comments on commit 7d0fef5

Please sign in to comment.