From 68d1aca903b684e3349c92ed76eae5daa9939a40 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Tue, 14 Feb 2023 15:49:26 +0100 Subject: [PATCH] BlockId removal: refactor of runtime API It changes the first argument of all generated runtime API calls from: `BlockId` to: `Block::Hash` --- node/subsystem-types/src/runtime_client.rs | 57 ++++++++++------------ node/test/client/src/block_builder.rs | 5 +- 2 files changed, 29 insertions(+), 33 deletions(-) diff --git a/node/subsystem-types/src/runtime_client.rs b/node/subsystem-types/src/runtime_client.rs index 03283942b74d..5ac010178f08 100644 --- a/node/subsystem-types/src/runtime_client.rs +++ b/node/subsystem-types/src/runtime_client.rs @@ -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, @@ -219,21 +219,21 @@ where T::Api: ParachainHost + BabeApi + AuthorityDiscoveryApi, { async fn validators(&self, at: Hash) -> Result, ApiError> { - self.runtime_api().validators(&BlockId::Hash(at)) + self.runtime_api().validators(at) } async fn validator_groups( &self, at: Hash, ) -> Result<(Vec>, GroupRotationInfo), ApiError> { - self.runtime_api().validator_groups(&BlockId::Hash(at)) + self.runtime_api().validator_groups(at) } async fn availability_cores( &self, at: Hash, ) -> Result>, ApiError> { - self.runtime_api().availability_cores(&BlockId::Hash(at)) + self.runtime_api().availability_cores(at) } async fn persisted_validation_data( @@ -242,8 +242,7 @@ where para_id: Id, assumption: OccupiedCoreAssumption, ) -> Result>, 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( @@ -254,7 +253,7 @@ where ) -> Result, ValidationCodeHash)>, ApiError> { self.runtime_api().assumed_validation_data( - &BlockId::Hash(at), + at, para_id, expected_persisted_validation_data_hash, ) @@ -266,12 +265,11 @@ where para_id: Id, outputs: CandidateCommitments, ) -> Result { - 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 { - self.runtime_api().session_index_for_child(&BlockId::Hash(at)) + self.runtime_api().session_index_for_child(at) } async fn validation_code( @@ -280,7 +278,7 @@ where para_id: Id, assumption: OccupiedCoreAssumption, ) -> Result, 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( @@ -288,11 +286,11 @@ where at: Hash, para_id: Id, ) -> Result>, 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>, ApiError> { - self.runtime_api().candidate_events(&BlockId::Hash(at)) + self.runtime_api().candidate_events(at) } async fn dmq_contents( @@ -300,7 +298,7 @@ where at: Hash, recipient: Id, ) -> Result>, ApiError> { - self.runtime_api().dmq_contents(&BlockId::Hash(at), recipient) + self.runtime_api().dmq_contents(at, recipient) } async fn inbound_hrmp_channels_contents( @@ -308,7 +306,7 @@ where at: Hash, recipient: Id, ) -> Result>>, 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( @@ -316,14 +314,14 @@ where at: Hash, hash: ValidationCodeHash, ) -> Result, 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>, ApiError> { - self.runtime_api().on_chain_votes(&BlockId::Hash(at)) + self.runtime_api().on_chain_votes(at) } async fn session_executor_params( @@ -331,7 +329,7 @@ where at: Hash, session_index: SessionIndex, ) -> Result, 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( @@ -339,7 +337,7 @@ where at: Hash, index: SessionIndex, ) -> Result, ApiError> { - self.runtime_api().session_info(&BlockId::Hash(at), index) + self.runtime_api().session_info(at, index) } async fn submit_pvf_check_statement( @@ -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, ApiError> { - self.runtime_api().pvfs_require_precheck(&BlockId::Hash(at)) + self.runtime_api().pvfs_require_precheck(at) } async fn validation_code_hash( @@ -362,22 +359,22 @@ where para_id: Id, assumption: OccupiedCoreAssumption, ) -> Result, 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 { - self.runtime_api().current_epoch(&BlockId::Hash(at)) + self.runtime_api().current_epoch(at) } async fn authorities( &self, at: Hash, ) -> std::result::Result, ApiError> { - self.runtime_api().authorities(&BlockId::Hash(at)) + self.runtime_api().authorities(at) } async fn api_version_parachain_host(&self, at: Hash) -> Result, ApiError> { - self.runtime_api().api_version::>(&BlockId::Hash(at)) + self.runtime_api().api_version::>(at) } #[warn(deprecated)] @@ -387,13 +384,13 @@ where index: SessionIndex, ) -> Result, 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)>, ApiError> { - self.runtime_api().disputes(&BlockId::Hash(at)) + self.runtime_api().disputes(at) } } diff --git a/node/test/client/src/block_builder.rs b/node/test/client/src/block_builder.rs index 74a5157c7de9..d73ee0902e67 100644 --- a/node/test/client/src/block_builder.rs +++ b/node/test/client/src/block_builder.rs @@ -56,9 +56,8 @@ impl InitPolkadotBlockBuilder for Client { &self, hash: ::Hash, ) -> BlockBuilder { - 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();