Add versioning to ParachainHost runtime API (#652)

* add version to ParachainHost API

* better error message
This commit is contained in:
Robert Habermeier
2019-12-04 02:04:03 +01:00
committed by Gavin Wood
parent d80adceea8
commit ab2333da89
2 changed files with 16 additions and 4 deletions
+15 -4
View File
@@ -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,
})
}
+1
View File
@@ -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>;