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 9a17c4e commit 68d1aca
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 33 deletions.
57 changes: 27 additions & 30 deletions node/subsystem-types/src/runtime_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

use async_trait::async_trait;
use polkadot_primitives::{
runtime_api::ParachainHost, vstaging::ExecutorParams, Block, BlockId, BlockNumber,
CandidateCommitments, CandidateEvent, CandidateHash, CommittedCandidateReceipt, CoreState,
DisputeState, GroupRotationInfo, Hash, Id, InboundDownwardMessage, InboundHrmpMessage,
runtime_api::ParachainHost, vstaging::ExecutorParams, Block, BlockNumber, CandidateCommitments,
CandidateEvent, CandidateHash, CommittedCandidateReceipt, CoreState, DisputeState,
GroupRotationInfo, Hash, Id, InboundDownwardMessage, InboundHrmpMessage,
OccupiedCoreAssumption, OldV1SessionInfo, PersistedValidationData, PvfCheckStatement,
ScrapedOnChainVotes, SessionIndex, SessionInfo, ValidationCode, ValidationCodeHash,
ValidatorId, ValidatorIndex, ValidatorSignature,
Expand Down Expand Up @@ -219,21 +219,21 @@ where
T::Api: ParachainHost<Block> + BabeApi<Block> + AuthorityDiscoveryApi<Block>,
{
async fn validators(&self, at: Hash) -> Result<Vec<ValidatorId>, ApiError> {
self.runtime_api().validators(&BlockId::Hash(at))
self.runtime_api().validators(at)
}

async fn validator_groups(
&self,
at: Hash,
) -> Result<(Vec<Vec<ValidatorIndex>>, GroupRotationInfo<BlockNumber>), ApiError> {
self.runtime_api().validator_groups(&BlockId::Hash(at))
self.runtime_api().validator_groups(at)
}

async fn availability_cores(
&self,
at: Hash,
) -> Result<Vec<CoreState<Hash, BlockNumber>>, ApiError> {
self.runtime_api().availability_cores(&BlockId::Hash(at))
self.runtime_api().availability_cores(at)
}

async fn persisted_validation_data(
Expand All @@ -242,8 +242,7 @@ where
para_id: Id,
assumption: OccupiedCoreAssumption,
) -> Result<Option<PersistedValidationData<Hash, BlockNumber>>, ApiError> {
self.runtime_api()
.persisted_validation_data(&BlockId::Hash(at), para_id, assumption)
self.runtime_api().persisted_validation_data(at, para_id, assumption)
}

async fn assumed_validation_data(
Expand All @@ -254,7 +253,7 @@ where
) -> Result<Option<(PersistedValidationData<Hash, BlockNumber>, ValidationCodeHash)>, ApiError>
{
self.runtime_api().assumed_validation_data(
&BlockId::Hash(at),
at,
para_id,
expected_persisted_validation_data_hash,
)
Expand All @@ -266,12 +265,11 @@ where
para_id: Id,
outputs: CandidateCommitments,
) -> Result<bool, ApiError> {
self.runtime_api()
.check_validation_outputs(&BlockId::Hash(at), para_id, outputs)
self.runtime_api().check_validation_outputs(at, para_id, outputs)
}

async fn session_index_for_child(&self, at: Hash) -> Result<SessionIndex, ApiError> {
self.runtime_api().session_index_for_child(&BlockId::Hash(at))
self.runtime_api().session_index_for_child(at)
}

async fn validation_code(
Expand All @@ -280,66 +278,66 @@ where
para_id: Id,
assumption: OccupiedCoreAssumption,
) -> Result<Option<ValidationCode>, ApiError> {
self.runtime_api().validation_code(&BlockId::Hash(at), para_id, assumption)
self.runtime_api().validation_code(at, para_id, assumption)
}

async fn candidate_pending_availability(
&self,
at: Hash,
para_id: Id,
) -> Result<Option<CommittedCandidateReceipt<Hash>>, ApiError> {
self.runtime_api().candidate_pending_availability(&BlockId::Hash(at), para_id)
self.runtime_api().candidate_pending_availability(at, para_id)
}

async fn candidate_events(&self, at: Hash) -> Result<Vec<CandidateEvent<Hash>>, ApiError> {
self.runtime_api().candidate_events(&BlockId::Hash(at))
self.runtime_api().candidate_events(at)
}

async fn dmq_contents(
&self,
at: Hash,
recipient: Id,
) -> Result<Vec<InboundDownwardMessage<BlockNumber>>, ApiError> {
self.runtime_api().dmq_contents(&BlockId::Hash(at), recipient)
self.runtime_api().dmq_contents(at, recipient)
}

async fn inbound_hrmp_channels_contents(
&self,
at: Hash,
recipient: Id,
) -> Result<BTreeMap<Id, Vec<InboundHrmpMessage<BlockNumber>>>, ApiError> {
self.runtime_api().inbound_hrmp_channels_contents(&BlockId::Hash(at), recipient)
self.runtime_api().inbound_hrmp_channels_contents(at, recipient)
}

async fn validation_code_by_hash(
&self,
at: Hash,
hash: ValidationCodeHash,
) -> Result<Option<ValidationCode>, ApiError> {
self.runtime_api().validation_code_by_hash(&BlockId::Hash(at), hash)
self.runtime_api().validation_code_by_hash(at, hash)
}

async fn on_chain_votes(
&self,
at: Hash,
) -> Result<Option<ScrapedOnChainVotes<Hash>>, ApiError> {
self.runtime_api().on_chain_votes(&BlockId::Hash(at))
self.runtime_api().on_chain_votes(at)
}

async fn session_executor_params(
&self,
at: Hash,
session_index: SessionIndex,
) -> Result<Option<ExecutorParams>, ApiError> {
self.runtime_api().session_executor_params(&BlockId::Hash(at), session_index)
self.runtime_api().session_executor_params(at, session_index)
}

async fn session_info(
&self,
at: Hash,
index: SessionIndex,
) -> Result<Option<SessionInfo>, ApiError> {
self.runtime_api().session_info(&BlockId::Hash(at), index)
self.runtime_api().session_info(at, index)
}

async fn submit_pvf_check_statement(
Expand All @@ -348,12 +346,11 @@ where
stmt: PvfCheckStatement,
signature: ValidatorSignature,
) -> Result<(), ApiError> {
self.runtime_api()
.submit_pvf_check_statement(&BlockId::Hash(at), stmt, signature)
self.runtime_api().submit_pvf_check_statement(at, stmt, signature)
}

async fn pvfs_require_precheck(&self, at: Hash) -> Result<Vec<ValidationCodeHash>, ApiError> {
self.runtime_api().pvfs_require_precheck(&BlockId::Hash(at))
self.runtime_api().pvfs_require_precheck(at)
}

async fn validation_code_hash(
Expand All @@ -362,22 +359,22 @@ where
para_id: Id,
assumption: OccupiedCoreAssumption,
) -> Result<Option<ValidationCodeHash>, ApiError> {
self.runtime_api().validation_code_hash(&BlockId::Hash(at), para_id, assumption)
self.runtime_api().validation_code_hash(at, para_id, assumption)
}

async fn current_epoch(&self, at: Hash) -> Result<Epoch, ApiError> {
self.runtime_api().current_epoch(&BlockId::Hash(at))
self.runtime_api().current_epoch(at)
}

async fn authorities(
&self,
at: Hash,
) -> std::result::Result<Vec<sp_authority_discovery::AuthorityId>, ApiError> {
self.runtime_api().authorities(&BlockId::Hash(at))
self.runtime_api().authorities(at)
}

async fn api_version_parachain_host(&self, at: Hash) -> Result<Option<u32>, ApiError> {
self.runtime_api().api_version::<dyn ParachainHost<Block>>(&BlockId::Hash(at))
self.runtime_api().api_version::<dyn ParachainHost<Block>>(at)
}

#[warn(deprecated)]
Expand All @@ -387,13 +384,13 @@ where
index: SessionIndex,
) -> Result<Option<OldV1SessionInfo>, ApiError> {
#[allow(deprecated)]
self.runtime_api().session_info_before_version_2(&BlockId::Hash(at), index)
self.runtime_api().session_info_before_version_2(at, index)
}

async fn disputes(
&self,
at: Hash,
) -> Result<Vec<(SessionIndex, CandidateHash, DisputeState<BlockNumber>)>, ApiError> {
self.runtime_api().disputes(&BlockId::Hash(at))
self.runtime_api().disputes(at)
}
}
5 changes: 2 additions & 3 deletions node/test/client/src/block_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,8 @@ impl InitPolkadotBlockBuilder for Client {
&self,
hash: <Block as BlockT>::Hash,
) -> BlockBuilder<Block, Client, FullBackend> {
let at = BlockId::Hash(hash);
let last_timestamp =
self.runtime_api().get_last_timestamp(&at).expect("Get last timestamp");
self.runtime_api().get_last_timestamp(hash).expect("Get last timestamp");

// `MinimumPeriod` is a storage parameter type that requires externalities to access the value.
let minimum_period = BasicExternalities::new_empty()
Expand Down Expand Up @@ -88,7 +87,7 @@ impl InitPolkadotBlockBuilder for Client {
};

let mut block_builder = self
.new_block_at(&at, digest, false)
.new_block_at(&BlockId::Hash(hash), digest, false)
.expect("Creates new block builder for test runtime");

let mut inherent_data = sp_inherents::InherentData::new();
Expand Down

0 comments on commit 68d1aca

Please sign in to comment.