Commit 900b2c4c authored by asynchronous rob's avatar asynchronous rob Committed by Gavin Wood
Browse files

Add versioning to `ParachainHost` runtime API (#652)

* add version to ParachainHost API

* better error message
parent 7754bea9
Pipeline #70919 passed with stages
in 21 minutes and 21 seconds
......@@ -22,7 +22,7 @@ use std::thread;
use log::{error, info, trace, warn};
use sp_blockchain::{Result as ClientResult};
use sp_runtime::traits::{Header as HeaderT, ProvideRuntimeApi};
use sp_api::ApiExt;
use sp_api::{ApiExt, ApiErrorFor};
use client::{
BlockchainEvents, BlockBody,
blockchain::ProvideCache,
......@@ -214,9 +214,20 @@ where
{
let extrinsics = client.block_body(block)?;
Ok(match extrinsics {
Some(extrinsics) => client.runtime_api()
.get_heads(&parent, extrinsics).map_err(|_| ConsensusError::ChainLookup("".into()))?
.and_then(|v| Some(v.into_iter())),
Some(extrinsics) => {
let api = client.runtime_api();
if api.has_api_with::<dyn ParachainHost<Block, Error = ApiErrorFor<P, Block>>, _>(
parent,
|version| version >= 2,
).map_err(|_| ConsensusError::ChainLookup("outdated runtime API".into()))? {
api.get_heads(&parent, extrinsics)
.map_err(|_| ConsensusError::ChainLookup("".into()))?
.map(|v| v.into_iter())
} else {
None
}
}
None => None,
})
}
......
......@@ -591,6 +591,7 @@ use runtime_primitives::traits::{Block as BlockT};
sp_api::decl_runtime_apis! {
/// The API for querying the state of parachains on-chain.
#[api_version(2)]
pub trait ParachainHost {
/// Get the current validators.
fn validators() -> Vec<ValidatorId>;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment