Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions cumulus/polkadot-parachain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ sp-block-builder = { workspace = true, default-features = true }
sp-keystore = { workspace = true, default-features = true }
sc-chain-spec = { workspace = true, default-features = true }
sc-rpc = { workspace = true, default-features = true }
sc-rpc-spec-v2 = { workspace = true, default-features = true }
sp-version = { workspace = true, default-features = true }
sc-tracing = { workspace = true, default-features = true }
sp-offchain = { workspace = true, default-features = true }
Expand Down
10 changes: 10 additions & 0 deletions cumulus/polkadot-parachain/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use sc_rpc::{
dev::{Dev, DevApiServer},
DenyUnsafe,
};
use sc_rpc_spec_v2::chain_spec::{ChainSpec, ChainSpecApiServer};
use std::{marker::PhantomData, sync::Arc};
use substrate_frame_rpc_system::{System, SystemApiServer};
use substrate_state_trie_migration_rpc::{StateMigration, StateMigrationApiServer};
Expand All @@ -41,6 +42,7 @@ pub(crate) trait BuildRpcExtensions<Client, Backend, Pool> {
client: Arc<Client>,
backend: Arc<Backend>,
pool: Arc<Pool>,
chain_spec: Box<dyn sc_chain_spec::ChainSpec>,
) -> sc_service::error::Result<RpcExtension>;
}

Expand All @@ -60,6 +62,7 @@ where
_client: Arc<ParachainClient<RuntimeApi>>,
_backend: Arc<ParachainBackend>,
_pool: Arc<sc_transaction_pool::FullPool<Block, ParachainClient<RuntimeApi>>>,
_chain_spec: Box<dyn sc_chain_spec::ChainSpec>,
) -> sc_service::error::Result<RpcExtension> {
Ok(RpcExtension::new(()))
}
Expand All @@ -83,6 +86,7 @@ where
client: Arc<ParachainClient<RuntimeApi>>,
backend: Arc<ParachainBackend>,
pool: Arc<sc_transaction_pool::FullPool<Block, ParachainClient<RuntimeApi>>>,
chain_spec: Box<dyn sc_chain_spec::ChainSpec>,
) -> sc_service::error::Result<RpcExtension> {
let build = || -> Result<RpcExtension, Box<dyn std::error::Error + Send + Sync>> {
let mut module = RpcExtension::new(());
Expand All @@ -92,6 +96,12 @@ where
module.merge(StateMigration::new(client.clone(), backend, deny_unsafe).into_rpc())?;
module.merge(Dev::new(client, deny_unsafe).into_rpc())?;

// RPC spec v2 method.
let chain_name = chain_spec.name().to_string();
let genesis_hash = client.hash(0).ok().flatten().expect("Genesis block exists; qed");
let properties = chain_spec.properties();
module.merge(ChainSpec::new(chain_name, genesis_hash, properties).into_rpc())?;

Ok(module)
};
build().map_err(Into::into)
Expand Down
4 changes: 3 additions & 1 deletion cumulus/polkadot-parachain/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ pub(crate) trait NodeSpec {

let validator = parachain_config.role.is_authority();
let prometheus_registry = parachain_config.prometheus_registry().cloned();
let chain_spec = parachain_config.chain_spec.cloned();
let transaction_pool = params.transaction_pool.clone();
let import_queue_service = params.import_queue.service();
let net_config = FullNetworkConfiguration::<_, _, Net>::new(
Expand All @@ -281,12 +282,13 @@ pub(crate) trait NodeSpec {
let transaction_pool = transaction_pool.clone();
let backend_for_rpc = backend.clone();

Box::new(move |deny_unsafe, _| {
Box::new(move |deny_unsafe: sc_rpc::DenyUnsafe, _| {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why is the type needed now in contrast to before?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think I've hit the autocomplete by mistake :D No longer needed since I was able to obtain the same by moving the initialization to the substrate builder

Self::BuildRpcExtensions::build_rpc_extensions(
deny_unsafe,
client.clone(),
backend_for_rpc.clone(),
transaction_pool.clone(),
chain_spec,
)
})
};
Expand Down
16 changes: 16 additions & 0 deletions prdoc/pr_5205.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
title: Enable ChainSpec API for polkadot-parachain

doc:
- audience:
- Runtime Dev
- Node Dev
description: |
Enables the `chainSpec_v1` rpc-v2 API for polkadot-parachains.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would like to re-phrase this as:

The substrate-service-builder now includes the entire rpc v2 API. The chainspec API was previously defined as rpc extension where for instance chains would need to enable it explicitly for it to be enabled which isn't the case anymore

This RPC is needed to provide extra information about the specification of the chain.
At the same time, this paves the way for implementing in the future a `chainSpec_v1_getSpec`
method that can extract the chainSpec of any chain (including parachains) for the use with lightclients.
For more info about the `chainSpec`, please see the specification: https://github.com/paritytech/json-rpc-interface-spec/blob/main/src/api/chainSpec.md.

crates:
- name: polkadot-parachain-bin
bump: minor