Skip to content

Commit

Permalink
Remove checks incompatible with legacy runtimes
Browse files Browse the repository at this point in the history
  • Loading branch information
serban300 committed Jun 3, 2024
1 parent 8905ab5 commit 8c16afb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 31 deletions.
13 changes: 4 additions & 9 deletions cumulus/polkadot-parachain/common/src/aura.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use codec::Codec;
use cumulus_primitives_aura::AuraUnincludedSegmentApi;
use cumulus_primitives_core::BlockT;
use sp_api::ApiError;
use sp_consensus_aura::AuraApi;
use sp_runtime::app_crypto::{AppCrypto, AppPair, AppSignature, Pair};

Expand Down Expand Up @@ -54,14 +53,10 @@ pub trait AuraRuntimeApi<Block: BlockT, AuraId: AuraIdT>:
+ AuraUnincludedSegmentApi<Block>
+ Sized
{
/// Check if the runtime has the Aura APIs.
fn has_aura_apis(&self, at: Block::Hash) -> bool {
let check = || -> Result<bool, ApiError> {
Ok(self.has_api::<dyn AuraApi<Block, <AuraId::BoundedPair as Pair>::Public>>(at)? &&
self.has_api::<dyn AuraUnincludedSegmentApi<Block>>(at)?)
};

check().unwrap_or(false)
/// Check if the runtime has the Aura API.
fn has_aura_api(&self, at: Block::Hash) -> bool {
self.has_api::<dyn AuraApi<Block, <AuraId::BoundedPair as Pair>::Public>>(at)
.unwrap_or(false)
}
}

Expand Down
14 changes: 1 addition & 13 deletions cumulus/polkadot-parachain/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
pub mod aura;

use cumulus_primitives_core::CollectCollationInfo;
use sp_api::{ApiError, ApiExt, CallApiAt, ConstructRuntimeApi, Metadata};
use sp_api::{ApiExt, CallApiAt, ConstructRuntimeApi, Metadata};
use sp_block_builder::BlockBuilder;
use sp_runtime::traits::Block as BlockT;
use sp_session::SessionKeys;
Expand All @@ -37,18 +37,6 @@ pub trait NodeRuntimeApi<Block: BlockT>:
+ CollectCollationInfo<Block>
+ Sized
{
/// Check if the runtime has the required APIs.
fn has_basic_apis(&self, at: Block::Hash) -> bool {
let check = || -> Result<bool, ApiError> {
Ok(self.has_api::<dyn Metadata<Block>>(at)? &&
self.has_api::<dyn SessionKeys<Block>>(at)? &&
self.has_api::<dyn BlockBuilder<Block>>(at)? &&
self.has_api::<dyn TaggedTransactionQueue<Block>>(at)? &&
self.has_api::<dyn CollectCollationInfo<Block>>(at)?)
};

check().unwrap_or(false)
}
}

impl<T, Block: BlockT> NodeRuntimeApi<Block> for T where
Expand Down
13 changes: 4 additions & 9 deletions cumulus/polkadot-parachain/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ use substrate_prometheus_endpoint::Registry;

use polkadot_parachain_common::{
aura::{AuraIdT, AuraRuntimeApi},
ConstructNodeRuntimeApi, NodeRuntimeApi,
ConstructNodeRuntimeApi,
};
use polkadot_primitives::CollatorPair;

Expand Down Expand Up @@ -235,11 +235,6 @@ where
let client = params.client.clone();
let backend = params.backend.clone();

let info = backend.blockchain().info();
if !client.runtime_api().has_basic_apis(info.genesis_hash) {
return Err(sc_service::error::Error::Other("Missing basic runtime APIs".to_string()));
}

let mut task_manager = params.task_manager;
let (relay_chain_interface, collator_key) = build_relay_chain_interface(
polkadot_config,
Expand Down Expand Up @@ -535,7 +530,7 @@ where
&mut self,
block_import: BlockImportParams<Block>,
) -> Result<BlockImportParams<Block>, String> {
if self.client.runtime_api().has_aura_apis(*block_import.header.parent_hash()) {
if self.client.runtime_api().has_aura_api(*block_import.header.parent_hash()) {
self.aura_verifier.get_mut().verify(block_import).await
} else {
self.relay_chain_verifier.verify(block_import).await
Expand Down Expand Up @@ -713,7 +708,7 @@ where

// Check if we have upgraded to an Aura compatible runtime and transition if
// necessary.
if client.runtime_api().has_aura_apis(last_head_hash) {
if client.runtime_api().has_aura_api(last_head_hash) {
// Respond to this request before transitioning to Aura.
request.complete(None);
break
Expand Down Expand Up @@ -854,7 +849,7 @@ where
RuntimeApi::RuntimeApi: AuraRuntimeApi<Block, AuraId>,
{
let info = backend.blockchain().info();
if !client.runtime_api().has_aura_apis(info.finalized_hash) {
if !client.runtime_api().has_aura_api(info.finalized_hash) {
return Err(sc_service::error::Error::Other("Missing aura runtime APIs".to_string()));
}

Expand Down

0 comments on commit 8c16afb

Please sign in to comment.