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

Update smoldot, improve chainspec loading error message #1581

Closed
wants to merge 3 commits into from
Closed
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
8 changes: 4 additions & 4 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions cumulus/client/relay-chain-rpc-interface/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ url = "2.4.0"
serde_json = "1.0.107"
serde = "1.0.188"
schnellru = "0.2.1"
smoldot = { version = "0.11.0", default_features = false, features = ["std"]}
smoldot-light = { version = "0.9.0", default_features = false, features = ["std"] }
smoldot = { version = "0.12.0", default_features = false, features = ["std"]}
smoldot-light = { version = "0.10.0", default_features = false, features = ["std"] }
either = "1.8.1"
thiserror = "1.0.48"
rand = "0.8.5"
Expand Down
36 changes: 20 additions & 16 deletions cumulus/polkadot-parachain/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,29 +52,30 @@ enum Runtime {
}

trait RuntimeResolver {
fn runtime(&self) -> Runtime;
fn runtime(&self) -> Result<Runtime>;
}

impl RuntimeResolver for dyn ChainSpec {
fn runtime(&self) -> Runtime {
runtime(self.id())
fn runtime(&self) -> Result<Runtime> {
Ok(runtime(self.id()))
}
}

/// Implementation, that can resolve [`Runtime`] from any json configuration file
impl RuntimeResolver for PathBuf {
fn runtime(&self) -> Runtime {
fn runtime(&self) -> Result<Runtime> {
#[derive(Debug, serde::Deserialize)]
struct EmptyChainSpecWithId {
id: String,
}

let file = std::fs::File::open(self).expect("Failed to open file");
let file = std::fs::File::open(self)?;

let reader = std::io::BufReader::new(file);
let chain_spec: EmptyChainSpecWithId = serde_json::from_reader(reader)
.expect("Failed to read 'json' file with ChainSpec configuration");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this failure also could be returned with '?'


runtime(&chain_spec.id)
Ok(runtime(&chain_spec.id))
}
}

Expand Down Expand Up @@ -243,7 +244,10 @@ fn load_spec(id: &str) -> std::result::Result<Box<dyn ChainSpec>, String> {
// -- Loading a specific spec from disk
path => {
let path: PathBuf = path.into();
match path.runtime() {
match path
.runtime()
.map_err(|e| format!("Failed to open chainspec '{}': {e}", path.display()))?
{
Runtime::AssetHubPolkadot => Box::new(
chain_spec::asset_hubs::AssetHubPolkadotChainSpec::from_json_file(path)?,
),
Expand Down Expand Up @@ -383,7 +387,7 @@ impl SubstrateCli for RelayChainCli {
/// Creates partial components for the runtimes that are supported by the benchmarks.
macro_rules! construct_partials {
($config:expr, |$partials:ident| $code:expr) => {
match $config.chain_spec.runtime() {
match $config.chain_spec.runtime()? {
Runtime::AssetHubKusama => {
let $partials = new_partial::<asset_hub_kusama_runtime::RuntimeApi, _>(
&$config,
Expand Down Expand Up @@ -498,7 +502,7 @@ macro_rules! construct_partials {
macro_rules! construct_async_run {
(|$components:ident, $cli:ident, $cmd:ident, $config:ident| $( $code:tt )* ) => {{
let runner = $cli.create_runner($cmd)?;
match runner.config().chain_spec.runtime() {
match runner.config().chain_spec.runtime()? {
Runtime::AssetHubWestend => {
runner.async_run(|$config| {
let $components = new_partial::<asset_hub_westend_runtime::RuntimeApi, _>(
Expand Down Expand Up @@ -835,7 +839,7 @@ pub fn run() -> Result<()> {
info!("Parachain Account: {}", parachain_account);
info!("Is collating: {}", if config.role.is_authority() { "yes" } else { "no" });

match config.chain_spec.runtime() {
match config.chain_spec.runtime()? {
Runtime::AssetHubPolkadot => crate::service::start_generic_aura_node::<
asset_hub_polkadot_runtime::RuntimeApi,
AssetHubPolkadotAuraId,
Expand Down Expand Up @@ -1171,36 +1175,36 @@ mod tests {
&temp_dir,
Box::new(create_default_with_extensions("shell-1", Extensions1::default())),
);
assert_eq!(Runtime::Shell, path.runtime());
assert_eq!(Runtime::Shell, path.runtime().unwrap());

let path = store_configuration(
&temp_dir,
Box::new(create_default_with_extensions("shell-2", Extensions2::default())),
);
assert_eq!(Runtime::Shell, path.runtime());
assert_eq!(Runtime::Shell, path.runtime().unwrap());

let path = store_configuration(
&temp_dir,
Box::new(create_default_with_extensions("seedling", Extensions2::default())),
);
assert_eq!(Runtime::Seedling, path.runtime());
assert_eq!(Runtime::Seedling, path.runtime().unwrap());

let path = store_configuration(
&temp_dir,
Box::new(crate::chain_spec::rococo_parachain::rococo_parachain_local_config()),
);
assert_eq!(Runtime::Default, path.runtime());
assert_eq!(Runtime::Default, path.runtime().unwrap());

let path = store_configuration(
&temp_dir,
Box::new(crate::chain_spec::asset_hubs::asset_hub_kusama_local_config()),
);
assert_eq!(Runtime::AssetHubKusama, path.runtime());
assert_eq!(Runtime::AssetHubKusama, path.runtime().unwrap());

let path = store_configuration(
&temp_dir,
Box::new(crate::chain_spec::contracts::contracts_rococo_local_config()),
);
assert_eq!(Runtime::ContractsRococo, path.runtime());
assert_eq!(Runtime::ContractsRococo, path.runtime().unwrap());
}
}