1234567891011121314151617pub mod config;18pub mod construct_runtime;19pub mod dispatch;20pub mod ethereum;21pub mod identity;22pub mod instance;23pub mod maintenance;24pub mod runtime_apis;2526pub mod sponsoring;27#[allow(missing_docs)]28pub mod weights;2930#[cfg(test)]31pub mod tests;3233use frame_support::{34 traits::{Currency, Imbalance, OnUnbalanced},35 weights::Weight,36};37use sp_runtime::{38 generic, impl_opaque_keys,39 traits::{BlakeTwo256, BlockNumberProvider},40};41use sp_std::vec::Vec;42#[cfg(feature = "std")]43use sp_version::NativeVersion;44use up_common::types::{AccountId, BlockNumber};4546use crate::{AllPalletsWithSystem, Aura, Balances, Runtime, RuntimeCall, Signature, Treasury};4748#[macro_export]49macro_rules! unsupported {50 () => {51 pallet_common::unsupported!($crate::Runtime)52 };53}545556pub type Address = sp_runtime::MultiAddress<AccountId, ()>;5758pub type SignedBlock = generic::SignedBlock<Block>;5960pub type UncheckedExtrinsic =61 fp_self_contained::UncheckedExtrinsic<Address, RuntimeCall, Signature, SignedExtra>;6263pub type Header = generic::Header<BlockNumber, BlakeTwo256>;6465pub type Block = generic::Block<Header, UncheckedExtrinsic>;6667pub type BlockId = generic::BlockId<Block>;6869impl_opaque_keys! {70 pub struct SessionKeys {71 pub aura: Aura,72 }73}747576#[cfg(feature = "std")]77pub fn native_version() -> NativeVersion {78 NativeVersion {79 runtime_version: crate::VERSION,80 can_author_with: Default::default(),81 }82}8384pub type ChargeTransactionPayment = pallet_charge_transaction::ChargeTransactionPayment<Runtime>;8586pub type SignedExtra = (87 frame_system::CheckSpecVersion<Runtime>,88 frame_system::CheckTxVersion<Runtime>,89 frame_system::CheckGenesis<Runtime>,90 frame_system::CheckEra<Runtime>,91 frame_system::CheckNonce<Runtime>,92 frame_system::CheckWeight<Runtime>,93 maintenance::CheckMaintenance,94 identity::DisableIdentityCalls,95 ChargeTransactionPayment,96 97 pallet_ethereum::FakeTransactionFinalizer<Runtime>,98);99100101pub type Executive = frame_executive::Executive<102 Runtime,103 Block,104 frame_system::ChainContext<Runtime>,105 Runtime,106 AllPalletsWithSystem,107 AuraToCollatorSelection,108>;109110type NegativeImbalance = <Balances as Currency<AccountId>>::NegativeImbalance;111112pub struct DealWithFees;113impl OnUnbalanced<NegativeImbalance> for DealWithFees {114 fn on_unbalanceds<B>(mut fees_then_tips: impl Iterator<Item = NegativeImbalance>) {115 if let Some(fees) = fees_then_tips.next() {116 117 let mut split = fees.ration(100, 0);118 if let Some(tips) = fees_then_tips.next() {119 120 tips.ration_merge_into(100, 0, &mut split);121 }122 Treasury::on_unbalanced(split.0);123 124 }125 }126}127128pub struct RelayChainBlockNumberProvider<T>(sp_std::marker::PhantomData<T>);129130impl<T: cumulus_pallet_parachain_system::Config> BlockNumberProvider131 for RelayChainBlockNumberProvider<T>132{133 type BlockNumber = BlockNumber;134135 fn current_block_number() -> Self::BlockNumber {136 cumulus_pallet_parachain_system::Pallet::<T>::validation_data()137 .map(|d| d.relay_parent_number)138 .unwrap_or_default()139 }140 #[cfg(feature = "runtime-benchmarks")]141 fn set_block_number(block: Self::BlockNumber) {142 cumulus_pallet_parachain_system::RelaychainDataProvider::<T>::set_block_number(block)143 }144}145146#[cfg(not(feature = "lookahead"))]147pub(crate) struct CheckInherents;148149#[cfg(not(feature = "lookahead"))]150impl cumulus_pallet_parachain_system::CheckInherents<Block> for CheckInherents {151 fn check_inherents(152 block: &Block,153 relay_state_proof: &cumulus_pallet_parachain_system::RelayChainStateProof,154 ) -> sp_inherents::CheckInherentsResult {155 use crate::InherentDataExt;156157 let relay_chain_slot = relay_state_proof158 .read_slot()159 .expect("Could not read the relay chain slot from the proof");160161 let inherent_data =162 cumulus_primitives_timestamp::InherentDataProvider::from_relay_chain_slot_and_duration(163 relay_chain_slot,164 sp_std::time::Duration::from_secs(6),165 )166 .create_inherent_data()167 .expect("Could not create the timestamp inherent data");168169 inherent_data.check_extrinsics(block)170 }171}172173#[derive(parity_scale_codec::Encode, parity_scale_codec::Decode)]174pub enum XCMPMessage<XAccountId, XBalance> {175 176 TransferToken(XAccountId, XBalance),177}178179pub struct AuraToCollatorSelection;180impl frame_support::traits::OnRuntimeUpgrade for AuraToCollatorSelection {181 fn on_runtime_upgrade() -> Weight {182 #[cfg(feature = "collator-selection")]183 {184 use frame_support::{storage::migration, BoundedVec};185 use pallet_session::SessionManager;186 use sp_runtime::{traits::OpaqueKeys, RuntimeAppPublic};187188 use crate::config::pallets::MaxCollators;189190 let mut weight = <Runtime as frame_system::Config>::DbWeight::get().reads(1);191192 let version = migration::get_storage_value::<()>(193 b"AuraToCollatorSelection",194 b"StorageVersion",195 &[],196 );197198 let should_upgrade = version.is_none();199200 if should_upgrade {201 log::info!(202 target: "runtime::aura_to_collator_selection",203 "Running migration of Aura authorities to Collator Selection invulnerables"204 );205206 let invulnerables = pallet_aura::Pallet::<Runtime>::authorities()207 .iter()208 .cloned()209 .filter_map(|authority_id| {210 weight.saturating_accrue(<Runtime as frame_system::Config>::DbWeight::get().reads_writes(1, 1));211 let vec = authority_id.to_raw_vec();212 let slice = vec.as_slice();213 let array: Option<[u8; 32]> = match slice.try_into() {214 Ok(a) => Some(a),215 Err(_) => {216 log::error!("Failed to convert an Aura authority to a Collator Selection invulnerable: {:?}", authority_id);217 None218 },219 };220 array.map(|a| (AccountId::from(a), authority_id))221 })222 .collect::<Vec<_>>();223224 let bounded_invulnerables = BoundedVec::<_, MaxCollators>::try_from(225 invulnerables226 .iter()227 .cloned()228 .map(|(acc, _)| acc)229 .collect::<Vec<_>>(),230 )231 .expect("Existing collators/invulnerables are more than MaxCollators");232233 <pallet_collator_selection::Invulnerables<Runtime>>::put(bounded_invulnerables);234235 let keys = invulnerables236 .into_iter()237 .map(|(acc, aura)| {238 (239 acc.clone(), 240 acc, 241 SessionKeys { aura }, 242 )243 })244 .collect::<Vec<_>>();245246 for (account, val, keys) in keys.iter() {247 for id in <Runtime as pallet_session::Config>::Keys::key_ids() {248 <pallet_session::KeyOwner<Runtime>>::insert((*id, keys.get_raw(*id)), val)249 }250 <pallet_session::NextKeys<Runtime>>::insert(val, keys);251 252 if frame_system::Pallet::<Runtime>::inc_consumers_without_limit(account)253 .is_err()254 {255 log::warn!(256 "We have entered an error with incrementing consumers without limit during the migration"257 );258 259 260 261 262 frame_system::Pallet::<Runtime>::inc_providers(account);263 }264 }265266 let initial_validators_0 =267 <Runtime as pallet_session::Config>::SessionManager::new_session(0)268 .unwrap_or_else(|| {269 frame_support::print(270 "No initial validator provided by `SessionManager`, use \271 session config keys to generate initial validator set.",272 );273 keys.iter().map(|x| x.1.clone()).collect()274 });275 276277278279280 let initial_validators_1 =281 <Runtime as pallet_session::Config>::SessionManager::new_session(1)282 .unwrap_or_else(|| initial_validators_0.clone());283 284285286287288 let queued_keys: Vec<_> = initial_validators_1289 .iter()290 .cloned()291 .map(|v| {292 (293 v.clone(),294 <pallet_session::NextKeys<Runtime>>::get(&v)295 .expect("Validator in session 1 missing keys!"),296 )297 })298 .collect();299300 301 302303 <pallet_session::Validators<Runtime>>::put(initial_validators_0);304 <pallet_session::QueuedKeys<Runtime>>::put(queued_keys);305306 <Runtime as pallet_session::Config>::SessionManager::start_session(0);307308 log::info!(309 target: "runtime::aura_to_collator_selection",310 "Migration of Aura authorities to Collator Selection invulnerables is complete."311 );312313 migration::put_storage_value::<()>(314 b"AuraToCollatorSelection",315 b"StorageVersion",316 &[],317 (),318 );319320 weight += <Runtime as frame_system::Config>::DbWeight::get().writes(1)321 } else {322 log::info!(323 target: "runtime::aura_to_collator_selection",324 "The storage migration has already been flagged as complete. No migration needs to be done.",325 );326 }327328 weight329 }330331 #[cfg(not(feature = "collator-selection"))]332 {333 Weight::zero()334 }335 }336}