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

BlockId removal: refactor of runtime API #6721

Merged
merged 5 commits into from
Feb 20, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 26 additions & 29 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, PersistedValidationData, PvfCheckStatement, ScrapedOnChainVotes,
SessionIndex, SessionInfo, ValidationCode, ValidationCodeHash, ValidatorId, ValidatorIndex,
ValidatorSignature,
Expand Down Expand Up @@ -210,21 +210,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 @@ -233,8 +233,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 @@ -245,7 +244,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 @@ -257,12 +256,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 @@ -271,66 +269,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 @@ -339,12 +337,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 @@ -353,28 +350,28 @@ 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)
}

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)
michalkucharczyk marked this conversation as resolved.
Show resolved Hide resolved
.expect("Creates new block builder for test runtime");

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