Unverified Commit 6da658be authored by Kian Paimani's avatar Kian Paimani Committed by GitHub
Browse files

proper executor/block type for benchmarks and try-runtime (#2771)

* proper executor/block type for benchmarks and try-runtime

* Fix

* update benches as well to latest work

* Remvoe dbg
parent 9cdfd0c0
Pipeline #132131 failed with stages
in 24 minutes and 23 seconds
......@@ -138,6 +138,13 @@ fn set_default_ss58_version(spec: &Box<dyn service::ChainSpec>) {
sp_core::crypto::set_default_ss58_version(ss58_version);
}
const DEV_ONLY_ERROR_PATTERN: &'static str =
"can only use subcommand with --chain [polkadot-dev, kusama-dev, westend-dev], got ";
fn ensure_dev(spec: &Box<dyn service::ChainSpec>) -> std::result::Result<(), String> {
if spec.is_dev() { Ok(()) } else { Err(format!("{}{}", DEV_ONLY_ERROR_PATTERN, spec.id())) }
}
/// Parses polkadot specific CLI arguments and run the service.
pub fn run() -> Result<()> {
let cli = Cli::from_args();
......@@ -268,13 +275,27 @@ pub fn run() -> Result<()> {
Some(Subcommand::Benchmark(cmd)) => {
let runner = cli.create_runner(cmd)?;
let chain_spec = &runner.config().chain_spec;
set_default_ss58_version(chain_spec);
Ok(runner.sync_run(|config| {
cmd.run::<service::kusama_runtime::Block, service::KusamaExecutor>(config)
.map_err(|e| Error::SubstrateCli(e))
})?)
ensure_dev(chain_spec).map_err(Error::Other)?;
if chain_spec.is_polkadot() {
Ok(runner.sync_run(|config| {
cmd.run::<service::polkadot_runtime::Block, service::PolkadotExecutor>(config)
.map_err(|e| Error::SubstrateCli(e))
})?)
} else if chain_spec.is_kusama() {
Ok(runner.sync_run(|config| {
cmd.run::<service::kusama_runtime::Block, service::KusamaExecutor>(config)
.map_err(|e| Error::SubstrateCli(e))
})?)
} else if chain_spec.is_westend() {
Ok(runner.sync_run(|config| {
cmd.run::<service::westend_runtime::Block, service::WestendExecutor>(config)
.map_err(|e| Error::SubstrateCli(e))
})?)
} else {
Err(format!("{}{}", DEV_ONLY_ERROR_PATTERN, chain_spec.id()).into())
}
},
Some(Subcommand::Key(cmd)) => Ok(cmd.run(&cli)?),
#[cfg(feature = "try-runtime")]
......@@ -283,24 +304,38 @@ pub fn run() -> Result<()> {
let chain_spec = &runner.config().chain_spec;
set_default_ss58_version(chain_spec);
runner.async_run(|config| {
use sc_service::TaskManager;
let registry = config.prometheus_config.as_ref().map(|cfg| &cfg.registry);
let task_manager = TaskManager::new(
config.task_executor.clone(),
registry,
).map_err(|e| Error::SubstrateService(sc_service::Error::Prometheus(e)))?;
Ok((
cmd.run::<
use sc_service::TaskManager;
let registry = &runner.config().prometheus_config.as_ref().map(|cfg| &cfg.registry);
let task_manager = TaskManager::new(
runner.config().task_executor.clone(),
*registry,
).map_err(|e| Error::SubstrateService(sc_service::Error::Prometheus(e)))?;
ensure_dev(chain_spec).map_err(Error::Other)?;
if chain_spec.is_polkadot() {
runner.async_run(|config| {
Ok((cmd.run::<
service::polkadot_runtime::Block,
service::PolkadotExecutor,
>(config).map_err(Error::SubstrateCli), task_manager))
})
} else if chain_spec.is_kusama() {
runner.async_run(|config| {
Ok((cmd.run::<
service::kusama_runtime::Block,
service::KusamaExecutor,
>(config).map_err(Error::SubstrateCli),
task_manager
))
// NOTE: we fetch only the block number from the block type, the chance of disparity
// between kusama's and polkadot's block number is small enough to overlook this.
})
>(config).map_err(Error::SubstrateCli), task_manager))
})
} else if chain_spec.is_westend() {
runner.async_run(|config| {
Ok((cmd.run::<
service::westend_runtime::Block,
service::WestendExecutor,
>(config).map_err(Error::SubstrateCli), task_manager))
})
} else {
Err(format!("{}{}", DEV_ONLY_ERROR_PATTERN, chain_spec.id()).into())
}
}
}?;
Ok(())
......
......@@ -160,6 +160,12 @@ pub trait IdentifyVariant {
/// Returns if this is a configuration for the `Rococo` network.
fn is_rococo(&self) -> bool;
/// Returns if this is a configuration for the `Polkadot` network.
fn is_polkadot(&self) -> bool;
/// Returns true if this configuration is for a development network.
fn is_dev(&self) -> bool;
}
impl IdentifyVariant for Box<dyn ChainSpec> {
......@@ -172,6 +178,12 @@ impl IdentifyVariant for Box<dyn ChainSpec> {
fn is_rococo(&self) -> bool {
self.id().starts_with("rococo") || self.id().starts_with("rco")
}
fn is_polkadot(&self) -> bool {
self.id().starts_with("polkadot") || self.id().starts_with("dot")
}
fn is_dev(&self) -> bool {
self.id().ends_with("dev")
}
}
// If we're using prometheus, use a registry with a prefix of `polkadot`.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment