Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,10 @@ impl RuntimeApiSubsystemClient for BlockChainRpcClient {
async fn validation_code_bomb_limit(&self, at: Hash) -> Result<u32, sp_api::ApiError> {
Ok(self.rpc_client.parachain_host_validation_code_bomb_limit(at).await?)
}

async fn para_ids(&self, at: Hash) -> Result<Vec<ParaId>, sp_api::ApiError> {
Ok(self.rpc_client.parachain_host_para_ids(at).await?)
}
}

#[async_trait::async_trait]
Expand Down
11 changes: 11 additions & 0 deletions polkadot/node/core/runtime-api/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ pub(crate) struct RequestResultCache {
backing_constraints: LruMap<(Hash, ParaId), Option<Constraints>>,
scheduling_lookahead: LruMap<SessionIndex, u32>,
validation_code_bomb_limits: LruMap<SessionIndex, u32>,
para_ids: LruMap<Hash, Vec<ParaId>>,
}

impl Default for RequestResultCache {
Expand Down Expand Up @@ -118,6 +119,7 @@ impl Default for RequestResultCache {
backing_constraints: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
scheduling_lookahead: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
validation_code_bomb_limits: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
para_ids: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
}
}
}
Expand Down Expand Up @@ -602,6 +604,14 @@ impl RequestResultCache {
pub(crate) fn validation_code_bomb_limit(&mut self, session: SessionIndex) -> Option<u32> {
self.validation_code_bomb_limits.get(&session).copied()
}

pub(crate) fn para_ids(&mut self, relay_parent: &Hash) -> Option<&Vec<ParaId>> {
self.para_ids.get(relay_parent).map(|v| &*v)
}

pub(crate) fn cache_para_ids(&mut self, relay_parent: Hash, value: Vec<ParaId>) {
self.para_ids.insert(relay_parent, value);
}
}

pub(crate) enum RequestResult {
Expand Down Expand Up @@ -655,4 +665,5 @@ pub(crate) enum RequestResult {
BackingConstraints(Hash, ParaId, Option<Constraints>),
SchedulingLookahead(SessionIndex, u32),
ValidationCodeBombLimit(SessionIndex, u32),
ParaIdsAtRelayParent(Hash, Vec<ParaId>),
}
11 changes: 11 additions & 0 deletions polkadot/node/core/runtime-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ where
.cache_scheduling_lookahead(session_index, scheduling_lookahead),
ValidationCodeBombLimit(session_index, limit) =>
self.requests_cache.cache_validation_code_bomb_limit(session_index, limit),
ParaIdsAtRelayParent(relay_parent, para_ids) => {
self.requests_cache.cache_para_ids(relay_parent, para_ids);
},
}
}

Expand Down Expand Up @@ -368,6 +371,8 @@ where
Some(Request::ValidationCodeBombLimit(index, sender))
}
},
Request::ParaidsAtRelayParent(sender) =>
query!(para_ids(), sender).map(|sender| Request::ParaidsAtRelayParent(sender)),
}
}

Expand Down Expand Up @@ -702,5 +707,11 @@ where
sender,
result = (index)
),
Request::ParaidsAtRelayParent(sender) => query!(
ParaIdsAtRelayParent,
para_ids(),
ver = Request::PARAIDS_AT_RELAY_PARENT_RUNTIME_REQUIREMENT,
sender
),
}
}
4 changes: 4 additions & 0 deletions polkadot/node/core/runtime-api/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,10 @@ impl RuntimeApiSubsystemClient for MockSubsystemClient {
async fn validation_code_bomb_limit(&self, _: Hash) -> Result<u32, ApiError> {
todo!("Not required for tests")
}

async fn para_ids(&self, _: Hash) -> Result<Vec<ParaId>, ApiError> {
todo!("Not required for tests")
}
}

#[test]
Expand Down
6 changes: 6 additions & 0 deletions polkadot/node/subsystem-types/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,9 @@ pub enum RuntimeApiRequest {
/// Get the maximum uncompressed code size.
/// `V12`
ValidationCodeBombLimit(SessionIndex, RuntimeApiSender<u32>),
/// Get the paraids at the relay parent.
/// `V14`
ParaidsAtRelayParent(RuntimeApiSender<Vec<ParaId>>),
}

impl RuntimeApiRequest {
Expand Down Expand Up @@ -830,6 +833,9 @@ impl RuntimeApiRequest {

/// `SchedulingLookahead`
pub const SCHEDULING_LOOKAHEAD_RUNTIME_REQUIREMENT: u32 = 13;

/// `ParaidsAtRelayParent`
pub const PARAIDS_AT_RELAY_PARENT_RUNTIME_REQUIREMENT: u32 = 14;
}

/// A message to the Runtime API subsystem.
Expand Down
11 changes: 11 additions & 0 deletions polkadot/node/subsystem-types/src/runtime_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,10 @@ pub trait RuntimeApiSubsystemClient {
// === v12 ===
/// Fetch the maximum uncompressed code size.
async fn validation_code_bomb_limit(&self, at: Hash) -> Result<u32, ApiError>;

// == v14 ==
/// Fetch the list of all parachain IDs registered in the relay chain.
async fn para_ids(&self, relay_parent: Hash) -> Result<Vec<Id>, ApiError>;
}

/// Default implementation of [`RuntimeApiSubsystemClient`] using the client.
Expand Down Expand Up @@ -650,6 +654,13 @@ where
async fn validation_code_bomb_limit(&self, at: Hash) -> Result<u32, ApiError> {
self.client.runtime_api().validation_code_bomb_limit(at)
}

async fn para_ids(&self, relay_parent: Hash) -> Result<Vec<Id>, ApiError> {
self.client
.runtime_api()
.para_ids(relay_parent)
.map(|ids| ids.into_iter().map(Id::from).collect())
}
}

impl<Client, Block> HeaderBackend<Block> for DefaultSubsystemClient<Client>
Expand Down
4 changes: 4 additions & 0 deletions polkadot/primitives/src/runtime_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,10 @@ sp_api::decl_runtime_apis! {
#[api_version(13)]
fn scheduling_lookahead() -> u32;

/***** Added in v14 *****/
/// Retrieve paraids at relay parent
#[api_version(14)]
fn para_ids() -> Vec<u32>;

}
}
8 changes: 7 additions & 1 deletion polkadot/runtime/parachains/src/runtime_api_impl/vstaging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

//! Put implementations of functions from staging APIs here.

use crate::{configuration, initializer};
use crate::{configuration, initializer, paras};
use alloc::vec::Vec;

use frame_system::pallet_prelude::*;
use polkadot_primitives::{vstaging::async_backing::Constraints, Id as ParaId};

Expand Down Expand Up @@ -56,3 +58,7 @@ pub fn validation_code_bomb_limit<T: initializer::Config>() -> u32 {
configuration::ActiveConfig::<T>::get().max_code_size *
configuration::MAX_VALIDATION_CODE_COMPRESSION_RATIO
}

pub fn para_ids<T: initializer::Config>() -> Vec<ParaId> {
paras::Heads::<T>::iter().map(|(para_id, _)| para_id).collect()
}
9 changes: 8 additions & 1 deletion polkadot/runtime/rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2014,7 +2014,7 @@ sp_api::impl_runtime_apis! {
}
}

#[api_version(13)]
#[api_version(14)]
impl polkadot_primitives::runtime_api::ParachainHost<Block> for Runtime {
fn validators() -> Vec<ValidatorId> {
parachains_runtime_api_impl::validators::<Runtime>()
Expand Down Expand Up @@ -2192,6 +2192,13 @@ sp_api::impl_runtime_apis! {
fn validation_code_bomb_limit() -> u32 {
parachains_staging_runtime_api_impl::validation_code_bomb_limit::<Runtime>()
}

fn para_ids() -> Vec<u32> {
parachains_staging_runtime_api_impl::para_ids::<Runtime>()
.into_iter()
.map(|id| id.into())
.collect()
}
}

#[api_version(5)]
Expand Down
6 changes: 5 additions & 1 deletion polkadot/runtime/test-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,7 @@ sp_api::impl_runtime_apis! {
}
}

#[api_version(13)]
#[api_version(14)]
impl polkadot_primitives::runtime_api::ParachainHost<Block> for Runtime {
fn validators() -> Vec<ValidatorId> {
runtime_impl::validators::<Runtime>()
Expand Down Expand Up @@ -1140,6 +1140,10 @@ sp_api::impl_runtime_apis! {
fn validation_code_bomb_limit() -> u32 {
staging_runtime_impl::validation_code_bomb_limit::<Runtime>()
}

fn para_ids() -> Vec<u32> {
staging_runtime_impl::para_ids::<Runtime>().into_iter().map(|p| p.into()).collect()
}
}

impl sp_consensus_beefy::BeefyApi<Block, BeefyId> for Runtime {
Expand Down
8 changes: 7 additions & 1 deletion polkadot/runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2232,7 +2232,7 @@ sp_api::impl_runtime_apis! {
}
}

#[api_version(13)]
#[api_version(14)]
impl polkadot_primitives::runtime_api::ParachainHost<Block> for Runtime {
fn validators() -> Vec<ValidatorId> {
parachains_runtime_api_impl::validators::<Runtime>()
Expand Down Expand Up @@ -2410,6 +2410,12 @@ sp_api::impl_runtime_apis! {
fn validation_code_bomb_limit() -> u32 {
parachains_staging_runtime_api_impl::validation_code_bomb_limit::<Runtime>()
}

fn para_ids() -> Vec<u32> {
parachains_staging_runtime_api_impl::para_ids::<Runtime>().into_iter()
.map(|id| id.into())
.collect()
}
}

#[api_version(5)]
Expand Down
8 changes: 7 additions & 1 deletion substrate/frame/staking-async/runtimes/rc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2063,7 +2063,7 @@ sp_api::impl_runtime_apis! {
}
}

#[api_version(13)]
#[api_version(14)]
impl polkadot_primitives::runtime_api::ParachainHost<Block> for Runtime {
fn validators() -> Vec<ValidatorId> {
parachains_runtime_api_impl::validators::<Runtime>()
Expand Down Expand Up @@ -2241,6 +2241,12 @@ sp_api::impl_runtime_apis! {
fn scheduling_lookahead() -> u32 {
parachains_staging_runtime_api_impl::scheduling_lookahead::<Runtime>()
}

fn para_ids() -> Vec<u32> {
parachains_staging_runtime_api_impl::para_ids::<Runtime>().into_iter()
.map(|id| id.into())
.collect()
}
}

#[api_version(5)]
Expand Down
Loading