Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
BlockId removal: refactor of runtime API
Browse files Browse the repository at this point in the history
It changes the first argument of all generated runtime API calls from: `BlockId<Block>` to: `Block::Hash`
  • Loading branch information
michalkucharczyk committed Feb 15, 2023
1 parent f2deedf commit be98b57
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 20 deletions.
12 changes: 4 additions & 8 deletions client/collator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ use sc_client_api::BlockBackend;
use sp_api::{ApiExt, ProvideRuntimeApi};
use sp_consensus::BlockStatus;
use sp_core::traits::SpawnNamed;
use sp_runtime::{
generic::BlockId,
traits::{Block as BlockT, HashFor, Header as HeaderT, Zero},
};
use sp_runtime::traits::{Block as BlockT, HashFor, Header as HeaderT, Zero};

use cumulus_client_consensus_common::ParachainConsensus;
use polkadot_node_primitives::{
Expand Down Expand Up @@ -154,10 +151,9 @@ where
header: &Block::Header,
) -> Result<Option<CollationInfo>, sp_api::ApiError> {
let runtime_api = self.runtime_api.runtime_api();
let block_id = BlockId::Hash(block_hash);

let api_version =
match runtime_api.api_version::<dyn CollectCollationInfo<Block>>(&block_id)? {
match runtime_api.api_version::<dyn CollectCollationInfo<Block>>(block_hash)? {
Some(version) => version,
None => {
tracing::error!(
Expand All @@ -171,10 +167,10 @@ where
let collation_info = if api_version < 2 {
#[allow(deprecated)]
runtime_api
.collect_collation_info_before_version_2(&block_id)?
.collect_collation_info_before_version_2(block_hash)?
.into_latest(header.encode().into())
} else {
runtime_api.collect_collation_info(&block_id, header)?
runtime_api.collect_collation_info(block_hash, header)?
};

Ok(Some(collation_info))
Expand Down
7 changes: 2 additions & 5 deletions client/consensus/relay-chain/src/import_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ use sp_block_builder::BlockBuilder as BlockBuilderApi;
use sp_blockchain::Result as ClientResult;
use sp_consensus::{error::Error as ConsensusError, CacheKeyId};
use sp_inherents::{CreateInherentDataProviders, InherentDataProvider};
use sp_runtime::{
generic::BlockId,
traits::{Block as BlockT, Header as HeaderT},
};
use sp_runtime::traits::{Block as BlockT, Header as HeaderT};

/// A verifier that just checks the inherents.
pub struct Verifier<Client, Block, CIDP> {
Expand Down Expand Up @@ -84,7 +81,7 @@ where
.client
.runtime_api()
.check_inherents(
&BlockId::Hash(*block.header().parent_hash()),
*block.header().parent_hash(),
block.clone(),
inherent_data,
)
Expand Down
14 changes: 7 additions & 7 deletions client/relay-chain-inprocess-interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use std::{pin::Pin, sync::Arc, time::Duration};
use async_trait::async_trait;
use cumulus_primitives_core::{
relay_chain::{
runtime_api::ParachainHost, Block as PBlock, BlockId, CommittedCandidateReceipt,
runtime_api::ParachainHost, Block as PBlock, CommittedCandidateReceipt,
Hash as PHash, Header as PHeader, InboundHrmpMessage, OccupiedCoreAssumption, SessionIndex,
ValidatorId,
},
Expand Down Expand Up @@ -93,7 +93,7 @@ where
relay_parent: PHash,
) -> RelayChainResult<Vec<InboundDownwardMessage>> {
Ok(self.full_client.runtime_api().dmq_contents_with_context(
&BlockId::hash(relay_parent),
relay_parent,
sp_core::ExecutionContext::Importing,
para_id,
)?)
Expand All @@ -105,7 +105,7 @@ where
relay_parent: PHash,
) -> RelayChainResult<BTreeMap<ParaId, Vec<InboundHrmpMessage>>> {
Ok(self.full_client.runtime_api().inbound_hrmp_channels_contents_with_context(
&BlockId::hash(relay_parent),
relay_parent,
sp_core::ExecutionContext::Importing,
para_id,
)?)
Expand All @@ -118,7 +118,7 @@ where
occupied_core_assumption: OccupiedCoreAssumption,
) -> RelayChainResult<Option<PersistedValidationData>> {
Ok(self.full_client.runtime_api().persisted_validation_data(
&BlockId::Hash(hash),
hash,
para_id,
occupied_core_assumption,
)?)
Expand All @@ -132,15 +132,15 @@ where
Ok(self
.full_client
.runtime_api()
.candidate_pending_availability(&BlockId::Hash(hash), para_id)?)
.candidate_pending_availability(hash, para_id)?)
}

async fn session_index_for_child(&self, hash: PHash) -> RelayChainResult<SessionIndex> {
Ok(self.full_client.runtime_api().session_index_for_child(&BlockId::Hash(hash))?)
Ok(self.full_client.runtime_api().session_index_for_child(hash)?)
}

async fn validators(&self, hash: PHash) -> RelayChainResult<Vec<ValidatorId>> {
Ok(self.full_client.runtime_api().validators(&BlockId::Hash(hash))?)
Ok(self.full_client.runtime_api().validators(hash)?)
}

async fn import_notification_stream(
Expand Down

0 comments on commit be98b57

Please sign in to comment.