BlockId removal: refactor of runtime API (#6721)

* BlockId removal: refactor of runtime API

It changes the first argument of all generated runtime API calls from: `BlockId<Block>` to: `Block::Hash`

* fmt

* update lockfile for {"substrate"}

---------

Co-authored-by: parity-processbot <>
This commit is contained in:
Michal Kucharczyk
2023-02-21 00:44:20 +01:00
committed by GitHub
parent 35a0d69af8
commit d091a84a07
3 changed files with 210 additions and 214 deletions
+182 -182
View File
File diff suppressed because it is too large Load Diff
@@ -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,
@@ -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(
@@ -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(
@@ -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,
)
@@ -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(
@@ -271,7 +269,7 @@ 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(
@@ -279,11 +277,11 @@ where
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(
@@ -291,7 +289,7 @@ where
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(
@@ -299,7 +297,7 @@ where
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(
@@ -307,14 +305,14 @@ where
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(
@@ -322,7 +320,7 @@ where
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(
@@ -330,7 +328,7 @@ where
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(
@@ -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(
@@ -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)
}
}
@@ -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()
@@ -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();