From dc112d98244bf011d51fdc038cabc9d07c6d3b79 Mon Sep 17 00:00:00 2001 From: PraetorP Date: Tue, 5 Mar 2024 17:22:34 +0700 Subject: [PATCH] refactor --- polkadot/runtime/rococo/src/lib.rs | 56 ++++++++++++----------- polkadot/runtime/westend/src/lib.rs | 69 +++++++++++++++-------------- 2 files changed, 65 insertions(+), 60 deletions(-) diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 7c856b17bcb9..93216dfc3695 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -125,7 +125,7 @@ use governance::{ TreasurySpender, }; use xcm_executor::traits::WeightBounds; -use xcm_payment_runtime_api::Error as XcmPaymentError; +use xcm_payment_runtime_api::Error as XcmPaymentApiError; #[cfg(test)] mod tests; @@ -219,7 +219,7 @@ pub struct OriginPrivilegeCmp; impl PrivilegeCmp for OriginPrivilegeCmp { fn cmp_privilege(left: &OriginCaller, right: &OriginCaller) -> Option { if left == right { - return Some(Ordering::Equal) + return Some(Ordering::Equal); } match (left, right) { @@ -379,10 +379,12 @@ impl OpaqueKeys for OldSessionKeys { <::Public>::ID => self.babe.as_ref(), sp_core::crypto::key_types::IM_ONLINE => self.im_online.as_ref(), <::Public>::ID => self.para_validator.as_ref(), - <::Public>::ID => - self.para_assignment.as_ref(), - <::Public>::ID => - self.authority_discovery.as_ref(), + <::Public>::ID => { + self.para_assignment.as_ref() + }, + <::Public>::ID => { + self.authority_discovery.as_ref() + }, <::Public>::ID => self.beefy.as_ref(), _ => &[], } @@ -860,19 +862,19 @@ impl InstanceFilter for ProxyType { ), ProxyType::IdentityJudgement => matches!( c, - RuntimeCall::Identity(pallet_identity::Call::provide_judgement { .. }) | - RuntimeCall::Utility(..) + RuntimeCall::Identity(pallet_identity::Call::provide_judgement { .. }) + | RuntimeCall::Utility(..) ), ProxyType::CancelProxy => { matches!(c, RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. })) }, ProxyType::Auction => matches!( c, - RuntimeCall::Auctions { .. } | - RuntimeCall::Crowdloan { .. } | - RuntimeCall::Registrar { .. } | - RuntimeCall::Multisig(..) | - RuntimeCall::Slots { .. } + RuntimeCall::Auctions { .. } + | RuntimeCall::Crowdloan { .. } + | RuntimeCall::Registrar { .. } + | RuntimeCall::Multisig(..) + | RuntimeCall::Slots { .. } ), ProxyType::Society => matches!(c, RuntimeCall::Society(..)), ProxyType::OnDemandOrdering => matches!(c, RuntimeCall::OnDemandAssignmentProvider(..)), @@ -1491,11 +1493,11 @@ pub mod migrations { let now = frame_system::Pallet::::block_number(); let lease = slots::Pallet::::lease(para); if lease.is_empty() { - return None + return None; } // Lease not yet started, ignore: if lease.iter().any(Option::is_none) { - return None + return None; } let (index, _) = as Leaser>::lease_period_index(now)?; @@ -1557,7 +1559,7 @@ pub mod migrations { fn pre_upgrade() -> Result, sp_runtime::TryRuntimeError> { if System::last_runtime_upgrade_spec_version() > UPGRADE_SESSION_KEYS_FROM_SPEC { log::warn!(target: "runtime::session_keys", "Skipping session keys migration pre-upgrade check due to spec version (already applied?)"); - return Ok(Vec::new()) + return Ok(Vec::new()); } log::info!(target: "runtime::session_keys", "Collecting pre-upgrade session keys state"); @@ -1586,7 +1588,7 @@ pub mod migrations { fn on_runtime_upgrade() -> Weight { if System::last_runtime_upgrade_spec_version() > UPGRADE_SESSION_KEYS_FROM_SPEC { log::info!("Skipping session keys upgrade: already applied"); - return ::DbWeight::get().reads(1) + return ::DbWeight::get().reads(1); } log::trace!("Upgrading session keys"); Session::upgrade_keys::(transform_session_keys); @@ -1599,7 +1601,7 @@ pub mod migrations { ) -> Result<(), sp_runtime::TryRuntimeError> { if System::last_runtime_upgrade_spec_version() > UPGRADE_SESSION_KEYS_FROM_SPEC { log::warn!(target: "runtime::session_keys", "Skipping session keys migration post-upgrade check due to spec version (already applied?)"); - return Ok(()) + return Ok(()); } let key_ids = SessionKeys::key_ids(); @@ -1780,9 +1782,9 @@ sp_api::impl_runtime_apis! { } impl xcm_payment_runtime_api::XcmPaymentApi for Runtime { - fn query_acceptable_payment_assets(xcm_version: xcm::Version) -> Result, XcmPaymentError> { + fn query_acceptable_payment_assets(xcm_version: xcm::Version) -> Result, XcmPaymentApiError> { if !matches!(xcm_version, 3 | 4) { - return Err(XcmPaymentError::UnhandledXcmVersion); + return Err(XcmPaymentApiError::UnhandledXcmVersion); } Ok([VersionedAssetId::V4(xcm_config::TokenLocation::get().into())] .into_iter() @@ -1790,23 +1792,23 @@ sp_api::impl_runtime_apis! { .collect()) } - fn query_weight_to_asset_fee(weight: Weight, asset: VersionedAssetId) -> Result { + fn query_weight_to_asset_fee(weight: Weight, asset: VersionedAssetId) -> Result { let local_asset = VersionedAssetId::V4(xcm_config::TokenLocation::get().into()); let asset = asset .into_version(4) - .map_err(|_| XcmPaymentError::VersionedConversionFailed)?; + .map_err(|_| XcmPaymentApiError::VersionedConversionFailed)?; - if asset != local_asset { return Err(XcmPaymentError::AssetNotFound); } + if asset != local_asset { return Err(XcmPaymentApiError::AssetNotFound); } Ok(WeightToFee::weight_to_fee(&weight)) } - fn query_xcm_weight(message: VersionedXcm) -> Result { + fn query_xcm_weight(message: VersionedXcm) -> Result { let mut message = message .try_into() - .map_err(|_| XcmPaymentError::VersionedConversionFailed)?; + .map_err(|_| XcmPaymentApiError::VersionedConversionFailed)?; ::Weigher::weight(&mut message) - .map_err(|_| XcmPaymentError::WeightNotComputable) + .map_err(|_| XcmPaymentApiError::WeightNotComputable) } } @@ -2493,7 +2495,7 @@ mod remote_tests { #[tokio::test] async fn run_migrations() { if var("RUN_MIGRATION_TESTS").is_err() { - return + return; } sp_tracing::try_init_simple(); diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index 5f896fbaca6e..e93443f055ef 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -108,7 +108,7 @@ use xcm::{ use xcm_builder::PayOverXcm; use xcm_executor::traits::WeightBounds; -use xcm_payment_runtime_api::Error as XcmPaymentError; +use xcm_payment_runtime_api::Error as XcmPaymentApiError; pub use frame_system::Call as SystemCall; pub use pallet_balances::Call as BalancesCall; @@ -441,10 +441,12 @@ impl OpaqueKeys for OldSessionKeys { <::Public>::ID => self.babe.as_ref(), sp_core::crypto::key_types::IM_ONLINE => self.im_online.as_ref(), <::Public>::ID => self.para_validator.as_ref(), - <::Public>::ID => - self.para_assignment.as_ref(), - <::Public>::ID => - self.authority_discovery.as_ref(), + <::Public>::ID => { + self.para_assignment.as_ref() + }, + <::Public>::ID => { + self.authority_discovery.as_ref() + }, <::Public>::ID => self.beefy.as_ref(), _ => &[], } @@ -1050,11 +1052,12 @@ impl InstanceFilter for ProxyType { ProxyType::Staking => { matches!( c, - RuntimeCall::Staking(..) | - RuntimeCall::Session(..) | RuntimeCall::Utility(..) | - RuntimeCall::FastUnstake(..) | - RuntimeCall::VoterList(..) | - RuntimeCall::NominationPools(..) + RuntimeCall::Staking(..) + | RuntimeCall::Session(..) + | RuntimeCall::Utility(..) + | RuntimeCall::FastUnstake(..) + | RuntimeCall::VoterList(..) + | RuntimeCall::NominationPools(..) ) }, ProxyType::NominationPools => { @@ -1070,24 +1073,24 @@ impl InstanceFilter for ProxyType { ProxyType::Governance => matches!( c, // OpenGov calls - RuntimeCall::ConvictionVoting(..) | - RuntimeCall::Referenda(..) | - RuntimeCall::Whitelist(..) + RuntimeCall::ConvictionVoting(..) + | RuntimeCall::Referenda(..) + | RuntimeCall::Whitelist(..) ), ProxyType::IdentityJudgement => matches!( c, - RuntimeCall::Identity(pallet_identity::Call::provide_judgement { .. }) | - RuntimeCall::Utility(..) + RuntimeCall::Identity(pallet_identity::Call::provide_judgement { .. }) + | RuntimeCall::Utility(..) ), ProxyType::CancelProxy => { matches!(c, RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. })) }, ProxyType::Auction => matches!( c, - RuntimeCall::Auctions(..) | - RuntimeCall::Crowdloan(..) | - RuntimeCall::Registrar(..) | - RuntimeCall::Slots(..) + RuntimeCall::Auctions(..) + | RuntimeCall::Crowdloan(..) + | RuntimeCall::Registrar(..) + | RuntimeCall::Slots(..) ), } } @@ -1593,11 +1596,11 @@ pub mod migrations { let now = frame_system::Pallet::::block_number(); let lease = slots::Pallet::::lease(para); if lease.is_empty() { - return None + return None; } // Lease not yet started, ignore: if lease.iter().any(Option::is_none) { - return None + return None; } let (index, _) = as Leaser>::lease_period_index(now)?; @@ -1619,7 +1622,7 @@ pub mod migrations { fn pre_upgrade() -> Result, sp_runtime::TryRuntimeError> { if System::last_runtime_upgrade_spec_version() > UPGRADE_SESSION_KEYS_FROM_SPEC { log::warn!(target: "runtime::session_keys", "Skipping session keys migration pre-upgrade check due to spec version (already applied?)"); - return Ok(Vec::new()) + return Ok(Vec::new()); } log::info!(target: "runtime::session_keys", "Collecting pre-upgrade session keys state"); @@ -1648,7 +1651,7 @@ pub mod migrations { fn on_runtime_upgrade() -> Weight { if System::last_runtime_upgrade_spec_version() > UPGRADE_SESSION_KEYS_FROM_SPEC { log::warn!("Skipping session keys upgrade: already applied"); - return ::DbWeight::get().reads(1) + return ::DbWeight::get().reads(1); } log::info!("Upgrading session keys"); Session::upgrade_keys::(transform_session_keys); @@ -1661,7 +1664,7 @@ pub mod migrations { ) -> Result<(), sp_runtime::TryRuntimeError> { if System::last_runtime_upgrade_spec_version() > UPGRADE_SESSION_KEYS_FROM_SPEC { log::warn!(target: "runtime::session_keys", "Skipping session keys migration post-upgrade check due to spec version (already applied?)"); - return Ok(()) + return Ok(()); } let key_ids = SessionKeys::key_ids(); @@ -2257,9 +2260,9 @@ sp_api::impl_runtime_apis! { } impl xcm_payment_runtime_api::XcmPaymentApi for Runtime { - fn query_acceptable_payment_assets(xcm_version: xcm::Version) -> Result, XcmPaymentError> { + fn query_acceptable_payment_assets(xcm_version: xcm::Version) -> Result, XcmPaymentApiError> { if !matches!(xcm_version, 3 | 4) { - return Err(XcmPaymentError::UnhandledXcmVersion); + return Err(XcmPaymentApiError::UnhandledXcmVersion); } Ok([VersionedAssetId::V4(xcm_config::TokenLocation::get().into())] .into_iter() @@ -2267,23 +2270,23 @@ sp_api::impl_runtime_apis! { .collect()) } - fn query_weight_to_asset_fee(weight: Weight, asset: VersionedAssetId) -> Result { + fn query_weight_to_asset_fee(weight: Weight, asset: VersionedAssetId) -> Result { let local_asset = VersionedAssetId::V4(xcm_config::TokenLocation::get().into()); let asset = asset .into_version(4) - .map_err(|_| XcmPaymentError::VersionedConversionFailed)?; + .map_err(|_| XcmPaymentApiError::VersionedConversionFailed)?; - if asset != local_asset { return Err(XcmPaymentError::AssetNotFound); } + if asset != local_asset { return Err(XcmPaymentApiError::AssetNotFound); } Ok(WeightToFee::weight_to_fee(&weight)) } - fn query_xcm_weight(message: VersionedXcm) -> Result { + fn query_xcm_weight(message: VersionedXcm) -> Result { let mut message = message .try_into() - .map_err(|_| XcmPaymentError::VersionedConversionFailed)?; + .map_err(|_| XcmPaymentApiError::VersionedConversionFailed)?; ::Weigher::weight(&mut message) - .map_err(|_| XcmPaymentError::WeightNotComputable) + .map_err(|_| XcmPaymentApiError::WeightNotComputable) } } @@ -2578,7 +2581,7 @@ mod remote_tests { #[tokio::test] async fn run_migrations() { if var("RUN_MIGRATION_TESTS").is_err() { - return + return; } sp_tracing::try_init_simple();