Skip to content

Commit

Permalink
rpc: Enable ChainSpec for polkadot-parachain (paritytech#5205)
Browse files Browse the repository at this point in the history
This PR enables the `chainSpec_v1` class for the polkadot-parachian. 
The chainSpec is part of the rpc-v2 which is spec-ed at:
https://github.com/paritytech/json-rpc-interface-spec/blob/main/src/api/chainSpec.md.

This also paves the way for enabling a future `chainSpec_unstable_spec`
on all nodes.

Closes: paritytech#5191

cc @paritytech/subxt-team

---------

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
  • Loading branch information
lexnv committed Aug 2, 2024
1 parent 8ccb6b3 commit ce6938a
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 16 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

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

6 changes: 0 additions & 6 deletions polkadot/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ where
use sc_consensus_babe_rpc::{Babe, BabeApiServer};
use sc_consensus_beefy_rpc::{Beefy, BeefyApiServer};
use sc_consensus_grandpa_rpc::{Grandpa, GrandpaApiServer};
use sc_rpc_spec_v2::chain_spec::{ChainSpec, ChainSpecApiServer};
use sc_sync_state_rpc::{SyncState, SyncStateApiServer};
use substrate_frame_rpc_system::{System, SystemApiServer};
use substrate_state_trie_migration_rpc::{StateMigration, StateMigrationApiServer};
Expand All @@ -139,11 +138,6 @@ where
finality_provider,
} = grandpa;

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();

io.merge(ChainSpec::new(chain_name, genesis_hash, properties).into_rpc())?;
io.merge(StateMigration::new(client.clone(), backend.clone(), deny_unsafe).into_rpc())?;
io.merge(System::new(client.clone(), pool.clone(), deny_unsafe).into_rpc())?;
io.merge(TransactionPayment::new(client.clone()).into_rpc())?;
Expand Down
18 changes: 18 additions & 0 deletions prdoc/pr_5205.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
title: Enable ChainSpec API for polkadot-parachain

doc:
- audience:
- Runtime Dev
- Node Dev
description: |
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.
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: sc-service
bump: patch
- name: polkadot-rpc
bump: patch
1 change: 0 additions & 1 deletion substrate/bin/node/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ sc-consensus-grandpa-rpc = { workspace = true, default-features = true }
sc-mixnet = { workspace = true, default-features = true }
sc-rpc = { workspace = true, default-features = true }
sc-rpc-api = { workspace = true, default-features = true }
sc-rpc-spec-v2 = { workspace = true, default-features = true }
sc-sync-state-rpc = { workspace = true, default-features = true }
sc-transaction-pool-api = { workspace = true, default-features = true }
sp-api = { workspace = true, default-features = true }
Expand Down
6 changes: 0 additions & 6 deletions substrate/bin/node/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ where
mixnet::MixnetApiServer,
statement::StatementApiServer,
};
use sc_rpc_spec_v2::chain_spec::{ChainSpec, ChainSpecApiServer};
use sc_sync_state_rpc::{SyncState, SyncStateApiServer};
use substrate_frame_rpc_system::{System, SystemApiServer};
use substrate_state_trie_migration_rpc::{StateMigration, StateMigrationApiServer};
Expand All @@ -176,11 +175,6 @@ where
finality_provider,
} = grandpa;

let chain_name = chain_spec.name().to_string();
let genesis_hash = client.block_hash(0).ok().flatten().expect("Genesis block exists; qed");
let properties = chain_spec.properties();
io.merge(ChainSpec::new(chain_name, genesis_hash, properties).into_rpc())?;

io.merge(System::new(client.clone(), pool, deny_unsafe).into_rpc())?;
// Making synchronous calls in light client freezes the browser currently,
// more context: https://github.com/paritytech/substrate/pull/3480
Expand Down
13 changes: 11 additions & 2 deletions substrate/client/service/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ use sc_rpc::{
use sc_rpc_spec_v2::{
archive::ArchiveApiServer,
chain_head::ChainHeadApiServer,
chain_spec::ChainSpecApiServer,
transaction::{TransactionApiServer, TransactionBroadcastApiServer},
};
use sc_telemetry::{telemetry, ConnectionMessage, Telemetry, TelemetryHandle, SUBSTRATE_INFO};
Expand Down Expand Up @@ -675,9 +676,8 @@ where
// - block pruning in archive mode: The block's body is kept around
let is_archive_node = config.state_pruning.as_ref().map(|sp| sp.is_archive()).unwrap_or(false) &&
config.blocks_pruning.is_archive();
let genesis_hash = client.hash(Zero::zero()).ok().flatten().expect("Genesis block exists; qed");
if is_archive_node {
let genesis_hash =
client.hash(Zero::zero()).ok().flatten().expect("Genesis block exists; qed");
let archive_v2 = sc_rpc_spec_v2::archive::Archive::new(
client.clone(),
backend.clone(),
Expand All @@ -689,6 +689,14 @@ where
rpc_api.merge(archive_v2).map_err(|e| Error::Application(e.into()))?;
}

// ChainSpec RPC-v2.
let chain_spec_v2 = sc_rpc_spec_v2::chain_spec::ChainSpec::new(
config.chain_spec.name().into(),
genesis_hash,
config.chain_spec.properties(),
)
.into_rpc();

let author = sc_rpc::author::Author::new(
client.clone(),
transaction_pool,
Expand All @@ -712,6 +720,7 @@ where
.merge(transaction_broadcast_rpc_v2)
.map_err(|e| Error::Application(e.into()))?;
rpc_api.merge(chain_head_v2).map_err(|e| Error::Application(e.into()))?;
rpc_api.merge(chain_spec_v2).map_err(|e| Error::Application(e.into()))?;

// Part of the old RPC spec.
rpc_api.merge(chain).map_err(|e| Error::Application(e.into()))?;
Expand Down

0 comments on commit ce6938a

Please sign in to comment.