Skip to content

Commit

Permalink
Add versioning to ParachainHost runtime API (paritytech#652)
Browse files Browse the repository at this point in the history
* add version to ParachainHost API

* better error message
  • Loading branch information
rphmeier authored and gavofyork committed Dec 4, 2019
1 parent 7754bea commit 900b2c4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
19 changes: 15 additions & 4 deletions availability-store/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
})
}
Expand Down
1 change: 1 addition & 0 deletions primitives/src/parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
Expand Down

0 comments on commit 900b2c4

Please sign in to comment.