Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unneeded chain spec criteria #3243

Merged
merged 1 commit into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion parachain/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion parachain/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ homepage = 'https://litentry.com/'
license = 'GPL-3.0'
name = 'litentry-collator'
repository = 'https://github.com/litentry/litentry-parachain'
version = '0.9.22'
version = '0.9.23'

[[bin]]
name = 'litentry-collator'
Expand Down
88 changes: 13 additions & 75 deletions parachain/node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,33 +35,16 @@ use std::net::SocketAddr;
const UNSUPPORTED_CHAIN_MESSAGE: &str = "Unsupported chain spec, please use litentry*";

trait IdentifyChain {
fn is_litentry(&self) -> bool;
fn is_paseo(&self) -> bool;
fn is_standalone(&self) -> bool;
}

impl IdentifyChain for dyn sc_service::ChainSpec {
fn is_litentry(&self) -> bool {
// we need the combined condition as the id in our paseo spec starts with `litentry-paseo`
// simply renaming `litentry-paseo` to `paseo` everywhere would have an impact on the
// existing litentry-paseo chain
self.id().starts_with("litentry") && !self.id().starts_with("litentry-paseo")
}
fn is_paseo(&self) -> bool {
self.id().starts_with("litentry-paseo")
}
fn is_standalone(&self) -> bool {
self.id().eq("standalone") || self.id().eq("dev")
}
}

impl<T: sc_service::ChainSpec + 'static> IdentifyChain for T {
fn is_litentry(&self) -> bool {
<dyn sc_service::ChainSpec>::is_litentry(self)
}
fn is_paseo(&self) -> bool {
<dyn sc_service::ChainSpec>::is_paseo(self)
}
fn is_standalone(&self) -> bool {
<dyn sc_service::ChainSpec>::is_standalone(self)
}
Expand Down Expand Up @@ -89,12 +72,7 @@ fn load_spec(id: &str) -> std::result::Result<Box<dyn sc_service::ChainSpec>, St
"generate-paseo" => Box::new(chain_specs::paseo::get_chain_spec_prod()),
path => {
let chain_spec = chain_specs::ChainSpec::from_json_file(path.into())?;
if chain_spec.is_paseo() {
Box::new(chain_specs::ChainSpec::from_json_file(path.into())?)
} else {
// Fallback: use Litentry chain spec
Box::new(chain_spec)
}
Box::new(chain_spec)
},
})
}
Expand Down Expand Up @@ -170,14 +148,11 @@ impl SubstrateCli for RelayChainCli {
/// Creates partial components for the runtimes that are supported by the benchmarks.
macro_rules! construct_benchmark_partials {
($config:expr, |$partials:ident| $code:expr) => {
if $config.chain_spec.is_litentry() {
let $partials = new_partial::<_>(&$config, build_import_queue, false, true)?;
$code
} else if $config.chain_spec.is_paseo() {
if $config.chain_spec.is_standalone() {
panic!("{}", UNSUPPORTED_CHAIN_MESSAGE)
} else {
let $partials = new_partial::<_>(&$config, build_import_queue, false, true)?;
$code
} else {
panic!("{}", UNSUPPORTED_CHAIN_MESSAGE)
}
};
}
Expand All @@ -186,20 +161,9 @@ macro_rules! construct_async_run {
(|$components:ident, $cli:ident, $cmd:ident, $config:ident| $( $code:tt )* ) => {{
let runner = $cli.create_runner($cmd)?;

if runner.config().chain_spec.is_litentry() {
runner.async_run(|$config| {
let $components = new_partial::<
_
>(
&$config,
build_import_queue,
false,
$cli.delayed_best_block,
)?;
let task_manager = $components.task_manager;
{ $( $code )* }.map(|v| (v, task_manager))
})
} else if runner.config().chain_spec.is_paseo() {
if runner.config().chain_spec.is_standalone() {
panic!("{}", UNSUPPORTED_CHAIN_MESSAGE)
} else {
runner.async_run(|$config| {
let $components = new_partial::<
_
Expand All @@ -213,9 +177,6 @@ macro_rules! construct_async_run {
{ $( $code )* }.map(|v| (v, task_manager))
})
}
else {
panic!("{}", UNSUPPORTED_CHAIN_MESSAGE)
}
}}
}

Expand Down Expand Up @@ -272,17 +233,9 @@ pub fn run() -> Result<()> {

Some(Subcommand::ExportGenesisHead(cmd)) => {
let runner = cli.create_runner(cmd)?;
if runner.config().chain_spec.is_litentry() {
runner.sync_run(|config| {
let sc_service::PartialComponents { client, .. } = new_partial::<_>(
&config,
build_import_queue,
false,
cli.delayed_best_block,
)?;
cmd.run(client)
})
} else if runner.config().chain_spec.is_paseo() {
if runner.config().chain_spec.is_standalone() {
panic!("{}", UNSUPPORTED_CHAIN_MESSAGE)
} else {
runner.sync_run(|config| {
let sc_service::PartialComponents { client, .. } = new_partial::<_>(
&config,
Expand All @@ -292,8 +245,6 @@ pub fn run() -> Result<()> {
)?;
cmd.run(client)
})
} else {
panic!("{}", UNSUPPORTED_CHAIN_MESSAGE)
}
},
Some(Subcommand::ExportGenesisWasm(cmd)) => {
Expand Down Expand Up @@ -411,20 +362,9 @@ pub fn run() -> Result<()> {
let additional_config =
AdditionalConfig { evm_tracing_config, enable_evm_rpc: cli.enable_evm_rpc };

if config.chain_spec.is_litentry() {
start_node(
config,
polkadot_config,
collator_options,
para_id,
hwbench,
additional_config,
cli.delayed_best_block,
)
.await
.map(|r| r.0)
.map_err(Into::into)
} else if config.chain_spec.is_paseo() {
if config.chain_spec.is_standalone() {
Err(UNSUPPORTED_CHAIN_MESSAGE.into())
} else {
start_node(
config,
polkadot_config,
Expand All @@ -437,8 +377,6 @@ pub fn run() -> Result<()> {
.await
.map(|r| r.0)
.map_err(Into::into)
} else {
Err(UNSUPPORTED_CHAIN_MESSAGE.into())
}
})
},
Expand Down