ParachainHost: No need to be generic over the block or hash type (#2537)

The `BlockNumber` and `Hash` are fixed types any way.
This commit is contained in:
Bastian Köcher
2023-11-29 15:31:51 +01:00
committed by GitHub
parent 8f03570a46
commit d3d301fa42
5 changed files with 23 additions and 20 deletions
@@ -116,7 +116,7 @@ sp_api::impl_runtime_apis! {
} }
} }
impl runtime_api::ParachainHost<Block, Hash, BlockNumber> for Runtime { impl runtime_api::ParachainHost<Block> for Runtime {
fn validators() -> Vec<ValidatorId> { fn validators() -> Vec<ValidatorId> {
unimplemented!() unimplemented!()
} }
+19 -16
View File
@@ -116,11 +116,10 @@
use crate::{ use crate::{
async_backing, slashing, vstaging, AsyncBackingParams, BlockNumber, CandidateCommitments, async_backing, slashing, vstaging, AsyncBackingParams, BlockNumber, CandidateCommitments,
CandidateEvent, CandidateHash, CommittedCandidateReceipt, CoreState, DisputeState, CandidateEvent, CandidateHash, CommittedCandidateReceipt, CoreState, DisputeState,
ExecutorParams, GroupRotationInfo, OccupiedCoreAssumption, PersistedValidationData, ExecutorParams, GroupRotationInfo, Hash, OccupiedCoreAssumption, PersistedValidationData,
PvfCheckStatement, ScrapedOnChainVotes, SessionIndex, SessionInfo, ValidatorId, ValidatorIndex, PvfCheckStatement, ScrapedOnChainVotes, SessionIndex, SessionInfo, ValidatorId, ValidatorIndex,
ValidatorSignature, ValidatorSignature,
}; };
use parity_scale_codec::{Decode, Encode};
use polkadot_core_primitives as pcp; use polkadot_core_primitives as pcp;
use polkadot_parachain_primitives::primitives as ppp; use polkadot_parachain_primitives::primitives as ppp;
use sp_std::{collections::btree_map::BTreeMap, prelude::*}; use sp_std::{collections::btree_map::BTreeMap, prelude::*};
@@ -128,18 +127,18 @@ use sp_std::{collections::btree_map::BTreeMap, prelude::*};
sp_api::decl_runtime_apis! { sp_api::decl_runtime_apis! {
/// The API for querying the state of parachains on-chain. /// The API for querying the state of parachains on-chain.
#[api_version(5)] #[api_version(5)]
pub trait ParachainHost<H: Encode + Decode = pcp::v2::Hash, N: Encode + Decode = pcp::v2::BlockNumber> { pub trait ParachainHost {
/// Get the current validators. /// Get the current validators.
fn validators() -> Vec<ValidatorId>; fn validators() -> Vec<ValidatorId>;
/// Returns the validator groups and rotation info localized based on the hypothetical child /// Returns the validator groups and rotation info localized based on the hypothetical child
/// of a block whose state this is invoked on. Note that `now` in the `GroupRotationInfo` /// of a block whose state this is invoked on. Note that `now` in the `GroupRotationInfo`
/// should be the successor of the number of the block. /// should be the successor of the number of the block.
fn validator_groups() -> (Vec<Vec<ValidatorIndex>>, GroupRotationInfo<N>); fn validator_groups() -> (Vec<Vec<ValidatorIndex>>, GroupRotationInfo<BlockNumber>);
/// Yields information on all availability cores as relevant to the child block. /// Yields information on all availability cores as relevant to the child block.
/// Cores are either free or occupied. Free cores can have paras assigned to them. /// Cores are either free or occupied. Free cores can have paras assigned to them.
fn availability_cores() -> Vec<CoreState<H, N>>; fn availability_cores() -> Vec<CoreState<Hash, BlockNumber>>;
/// Yields the persisted validation data for the given `ParaId` along with an assumption that /// Yields the persisted validation data for the given `ParaId` along with an assumption that
/// should be used if the para currently occupies a core. /// should be used if the para currently occupies a core.
@@ -147,15 +146,15 @@ sp_api::decl_runtime_apis! {
/// Returns `None` if either the para is not registered or the assumption is `Freed` /// Returns `None` if either the para is not registered or the assumption is `Freed`
/// and the para already occupies a core. /// and the para already occupies a core.
fn persisted_validation_data(para_id: ppp::Id, assumption: OccupiedCoreAssumption) fn persisted_validation_data(para_id: ppp::Id, assumption: OccupiedCoreAssumption)
-> Option<PersistedValidationData<H, N>>; -> Option<PersistedValidationData<Hash, BlockNumber>>;
/// Returns the persisted validation data for the given `ParaId` along with the corresponding /// Returns the persisted validation data for the given `ParaId` along with the corresponding
/// validation code hash. Instead of accepting assumption about the para, matches the validation /// validation code hash. Instead of accepting assumption about the para, matches the validation
/// data hash against an expected one and yields `None` if they're not equal. /// data hash against an expected one and yields `None` if they're not equal.
fn assumed_validation_data( fn assumed_validation_data(
para_id: ppp::Id, para_id: ppp::Id,
expected_persisted_validation_data_hash: pcp::v2::Hash, expected_persisted_validation_data_hash: Hash,
) -> Option<(PersistedValidationData<H, N>, ppp::ValidationCodeHash)>; ) -> Option<(PersistedValidationData<Hash, BlockNumber>, ppp::ValidationCodeHash)>;
/// Checks if the given validation outputs pass the acceptance criteria. /// Checks if the given validation outputs pass the acceptance criteria.
fn check_validation_outputs(para_id: ppp::Id, outputs: CandidateCommitments) -> bool; fn check_validation_outputs(para_id: ppp::Id, outputs: CandidateCommitments) -> bool;
@@ -169,30 +168,34 @@ sp_api::decl_runtime_apis! {
/// ///
/// Returns `None` if either the para is not registered or the assumption is `Freed` /// Returns `None` if either the para is not registered or the assumption is `Freed`
/// and the para already occupies a core. /// and the para already occupies a core.
fn validation_code(para_id: ppp::Id, assumption: OccupiedCoreAssumption) fn validation_code(
-> Option<ppp::ValidationCode>; para_id: ppp::Id,
assumption: OccupiedCoreAssumption,
) -> Option<ppp::ValidationCode>;
/// Get the receipt of a candidate pending availability. This returns `Some` for any paras /// Get the receipt of a candidate pending availability. This returns `Some` for any paras
/// assigned to occupied cores in `availability_cores` and `None` otherwise. /// assigned to occupied cores in `availability_cores` and `None` otherwise.
fn candidate_pending_availability(para_id: ppp::Id) -> Option<CommittedCandidateReceipt<H>>; fn candidate_pending_availability(para_id: ppp::Id) -> Option<CommittedCandidateReceipt<Hash>>;
/// Get a vector of events concerning candidates that occurred within a block. /// Get a vector of events concerning candidates that occurred within a block.
fn candidate_events() -> Vec<CandidateEvent<H>>; fn candidate_events() -> Vec<CandidateEvent<Hash>>;
/// Get all the pending inbound messages in the downward message queue for a para. /// Get all the pending inbound messages in the downward message queue for a para.
fn dmq_contents( fn dmq_contents(
recipient: ppp::Id, recipient: ppp::Id,
) -> Vec<pcp::v2::InboundDownwardMessage<N>>; ) -> Vec<pcp::v2::InboundDownwardMessage<BlockNumber>>;
/// Get the contents of all channels addressed to the given recipient. Channels that have no /// Get the contents of all channels addressed to the given recipient. Channels that have no
/// messages in them are also included. /// messages in them are also included.
fn inbound_hrmp_channels_contents(recipient: ppp::Id) -> BTreeMap<ppp::Id, Vec<pcp::v2::InboundHrmpMessage<N>>>; fn inbound_hrmp_channels_contents(
recipient: ppp::Id,
) -> BTreeMap<ppp::Id, Vec<pcp::v2::InboundHrmpMessage<BlockNumber>>>;
/// Get the validation code from its hash. /// Get the validation code from its hash.
fn validation_code_by_hash(hash: ppp::ValidationCodeHash) -> Option<ppp::ValidationCode>; fn validation_code_by_hash(hash: ppp::ValidationCodeHash) -> Option<ppp::ValidationCode>;
/// Scrape dispute relevant from on-chain, backing votes and resolved disputes. /// Scrape dispute relevant from on-chain, backing votes and resolved disputes.
fn on_chain_votes() -> Option<ScrapedOnChainVotes<H>>; fn on_chain_votes() -> Option<ScrapedOnChainVotes<Hash>>;
/***** Added in v2 *****/ /***** Added in v2 *****/
@@ -253,7 +256,7 @@ sp_api::decl_runtime_apis! {
/// Returns the state of parachain backing for a given para. /// Returns the state of parachain backing for a given para.
#[api_version(7)] #[api_version(7)]
fn para_backing_state(_: ppp::Id) -> Option<async_backing::BackingState<H, N>>; fn para_backing_state(_: ppp::Id) -> Option<async_backing::BackingState<Hash, BlockNumber>>;
/// Returns candidate's acceptance limitations for asynchronous backing for a relay parent. /// Returns candidate's acceptance limitations for asynchronous backing for a relay parent.
#[api_version(7)] #[api_version(7)]
+1 -1
View File
@@ -1802,7 +1802,7 @@ sp_api::impl_runtime_apis! {
} }
#[api_version(9)] #[api_version(9)]
impl primitives::runtime_api::ParachainHost<Block, Hash, BlockNumber> for Runtime { impl primitives::runtime_api::ParachainHost<Block> for Runtime {
fn validators() -> Vec<ValidatorId> { fn validators() -> Vec<ValidatorId> {
parachains_runtime_api_impl::validators::<Runtime>() parachains_runtime_api_impl::validators::<Runtime>()
} }
+1 -1
View File
@@ -826,7 +826,7 @@ sp_api::impl_runtime_apis! {
} }
} }
impl primitives::runtime_api::ParachainHost<Block, Hash, BlockNumber> for Runtime { impl primitives::runtime_api::ParachainHost<Block> for Runtime {
fn validators() -> Vec<ValidatorId> { fn validators() -> Vec<ValidatorId> {
runtime_impl::validators::<Runtime>() runtime_impl::validators::<Runtime>()
} }
+1 -1
View File
@@ -1796,7 +1796,7 @@ sp_api::impl_runtime_apis! {
} }
#[api_version(9)] #[api_version(9)]
impl primitives::runtime_api::ParachainHost<Block, Hash, BlockNumber> for Runtime { impl primitives::runtime_api::ParachainHost<Block> for Runtime {
fn validators() -> Vec<ValidatorId> { fn validators() -> Vec<ValidatorId> {
parachains_runtime_api_impl::validators::<Runtime>() parachains_runtime_api_impl::validators::<Runtime>()
} }