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;2526#[cfg(feature = "scheduler")]27pub mod scheduler;2829pub mod sponsoring;30pub mod weights;3132#[cfg(test)]33pub mod tests;3435use sp_core::H160;36use frame_support::{37 traits::{Currency, OnUnbalanced, Imbalance},38 weights::Weight,39};40use sp_runtime::{41 generic,42 traits::{BlakeTwo256, BlockNumberProvider},43 impl_opaque_keys,44};45use sp_std::vec::Vec;4647#[cfg(feature = "std")]48use sp_version::NativeVersion;4950use crate::{51 Runtime, RuntimeCall, Balances, Treasury, Aura, Signature, AllPalletsWithSystem,52 InherentDataExt,53};54use up_common::types::{AccountId, BlockNumber};5556#[macro_export]57macro_rules! unsupported {58 () => {59 pallet_common::unsupported!($crate::Runtime)60 };61}626364pub type Address = sp_runtime::MultiAddress<AccountId, ()>;6566pub type Header = generic::Header<BlockNumber, BlakeTwo256>;6768pub type Block = generic::Block<Header, UncheckedExtrinsic>;6970pub type SignedBlock = generic::SignedBlock<Block>;7172pub type BlockId = generic::BlockId<Block>;7374impl_opaque_keys! {75 pub struct SessionKeys {76 pub aura: Aura,77 }78}798081#[cfg(feature = "std")]82pub fn native_version() -> NativeVersion {83 NativeVersion {84 runtime_version: crate::VERSION,85 can_author_with: Default::default(),86 }87}8889pub type ChargeTransactionPayment = pallet_charge_transaction::ChargeTransactionPayment<Runtime>;9091pub type SignedExtra = (92 frame_system::CheckSpecVersion<Runtime>,93 frame_system::CheckTxVersion<Runtime>,94 frame_system::CheckGenesis<Runtime>,95 frame_system::CheckEra<Runtime>,96 frame_system::CheckNonce<Runtime>,97 frame_system::CheckWeight<Runtime>,98 maintenance::CheckMaintenance,99 identity::DisableIdentityCalls,100 ChargeTransactionPayment,101 102 pallet_ethereum::FakeTransactionFinalizer<Runtime>,103);104105106pub type UncheckedExtrinsic =107 fp_self_contained::UncheckedExtrinsic<Address, RuntimeCall, Signature, SignedExtra>;108109110pub type CheckedExtrinsic =111 fp_self_contained::CheckedExtrinsic<AccountId, RuntimeCall, SignedExtra, H160>;112113114pub type Executive = frame_executive::Executive<115 Runtime,116 Block,117 frame_system::ChainContext<Runtime>,118 Runtime,119 AllPalletsWithSystem,120 AuraToCollatorSelection,121>;122123type NegativeImbalance = <Balances as Currency<AccountId>>::NegativeImbalance;124125pub struct DealWithFees;126impl OnUnbalanced<NegativeImbalance> for DealWithFees {127 fn on_unbalanceds<B>(mut fees_then_tips: impl Iterator<Item = NegativeImbalance>) {128 if let Some(fees) = fees_then_tips.next() {129 130 let mut split = fees.ration(100, 0);131 if let Some(tips) = fees_then_tips.next() {132 133 tips.ration_merge_into(100, 0, &mut split);134 }135 Treasury::on_unbalanced(split.0);136 137 }138 }139}140141pub struct RelayChainBlockNumberProvider<T>(sp_std::marker::PhantomData<T>);142143impl<T: cumulus_pallet_parachain_system::Config> BlockNumberProvider144 for RelayChainBlockNumberProvider<T>145{146 type BlockNumber = BlockNumber;147148 fn current_block_number() -> Self::BlockNumber {149 cumulus_pallet_parachain_system::Pallet::<T>::validation_data()150 .map(|d| d.relay_parent_number)151 .unwrap_or_default()152 }153 #[cfg(feature = "runtime-benchmarks")]154 fn set_block_number(block: Self::BlockNumber) {155 cumulus_pallet_parachain_system::RelaychainBlockNumberProvider::<T>::set_block_number(block)156 }157}158159pub(crate) struct CheckInherents;160161impl cumulus_pallet_parachain_system::CheckInherents<Block> for CheckInherents {162 fn check_inherents(163 block: &Block,164 relay_state_proof: &cumulus_pallet_parachain_system::RelayChainStateProof,165 ) -> sp_inherents::CheckInherentsResult {166 let relay_chain_slot = relay_state_proof167 .read_slot()168 .expect("Could not read the relay chain slot from the proof");169170 let inherent_data =171 cumulus_primitives_timestamp::InherentDataProvider::from_relay_chain_slot_and_duration(172 relay_chain_slot,173 sp_std::time::Duration::from_secs(6),174 )175 .create_inherent_data()176 .expect("Could not create the timestamp inherent data");177178 inherent_data.check_extrinsics(block)179 }180}181182#[derive(codec::Encode, codec::Decode)]183pub enum XCMPMessage<XAccountId, XBalance> {184 185 TransferToken(XAccountId, XBalance),186}187188pub struct AuraToCollatorSelection;189impl frame_support::traits::OnRuntimeUpgrade for AuraToCollatorSelection {190 fn on_runtime_upgrade() -> Weight {191 #[cfg(feature = "collator-selection")]192 {193 use frame_support::{BoundedVec, storage::migration};194 use sp_runtime::{traits::OpaqueKeys, RuntimeAppPublic};195 use pallet_session::SessionManager;196 use crate::config::pallets::MaxCollators;197198 let mut weight = <Runtime as frame_system::Config>::DbWeight::get().reads(1);199200 let version = migration::get_storage_value::<()>(201 b"AuraToCollatorSelection",202 b"StorageVersion",203 &[],204 );205206 let should_upgrade = match version {207 None => true,208 Some(_) => false,209 };210211 if should_upgrade {212 log::info!(213 target: "runtime::aura_to_collator_selection",214 "Running migration of Aura authorities to Collator Selection invulnerables"215 );216217 let invulnerables = pallet_aura::Pallet::<Runtime>::authorities()218 .iter()219 .cloned()220 .filter_map(|authority_id| {221 weight.saturating_accrue(<Runtime as frame_system::Config>::DbWeight::get().reads_writes(1, 1));222 let vec = authority_id.clone().to_raw_vec();223 let slice = vec.as_slice();224 let array: Option<[u8; 32]> = match slice.try_into() {225 Ok(a) => Some(a),226 Err(_) => {227 log::error!("Failed to convert an Aura authority to a Collator Selection invulnerable: {:?}", authority_id);228 None229 },230 };231 array.map(|a| (AccountId::from(a), authority_id))232 })233 .collect::<Vec<_>>();234235 let bounded_invulnerables = BoundedVec::<_, MaxCollators>::try_from(236 invulnerables237 .iter()238 .cloned()239 .map(|(acc, _)| acc)240 .collect::<Vec<_>>(),241 )242 .expect("Existing collators/invulnerables are more than MaxCollators");243244 <pallet_collator_selection::Invulnerables<Runtime>>::put(bounded_invulnerables);245246 let keys = invulnerables247 .into_iter()248 .map(|(acc, aura)| {249 (250 acc.clone(), 251 acc, 252 SessionKeys { aura: aura.clone() }, 253 )254 })255 .collect::<Vec<_>>();256257 for (account, val, keys) in keys.iter().cloned() {258 for id in <Runtime as pallet_session::Config>::Keys::key_ids() {259 <pallet_session::KeyOwner<Runtime>>::insert((*id, keys.get_raw(*id)), &val)260 }261 <pallet_session::NextKeys<Runtime>>::insert(&val, &keys);262 263 if frame_system::Pallet::<Runtime>::inc_consumers_without_limit(&account)264 .is_err()265 {266 log::warn!(267 "We have entered an error with incrementing consumers without limit during the migration"268 );269 270 271 272 273 frame_system::Pallet::<Runtime>::inc_providers(&account);274 }275 }276277 let initial_validators_0 =278 <Runtime as pallet_session::Config>::SessionManager::new_session(0)279 .unwrap_or_else(|| {280 frame_support::print(281 "No initial validator provided by `SessionManager`, use \282 session config keys to generate initial validator set.",283 );284 keys.iter().map(|x| x.1.clone()).collect()285 });286 287288289290291 let initial_validators_1 =292 <Runtime as pallet_session::Config>::SessionManager::new_session(1)293 .unwrap_or_else(|| initial_validators_0.clone());294 295296297298299 let queued_keys: Vec<_> = initial_validators_1300 .iter()301 .cloned()302 .map(|v| {303 (304 v.clone(),305 <pallet_session::NextKeys<Runtime>>::get(&v)306 .expect("Validator in session 1 missing keys!"),307 )308 })309 .collect();310311 312 313314 <pallet_session::Validators<Runtime>>::put(initial_validators_0);315 <pallet_session::QueuedKeys<Runtime>>::put(queued_keys);316317 <Runtime as pallet_session::Config>::SessionManager::start_session(0);318319 log::info!(320 target: "runtime::aura_to_collator_selection",321 "Migration of Aura authorities to Collator Selection invulnerables is complete."322 );323324 migration::put_storage_value::<()>(325 b"AuraToCollatorSelection",326 b"StorageVersion",327 &[],328 (),329 );330331 weight += <Runtime as frame_system::Config>::DbWeight::get().writes(1)332 } else {333 log::info!(334 target: "runtime::aura_to_collator_selection",335 "The storage migration has already been flagged as complete. No migration needs to be done.",336 );337 }338339 weight340 }341342 #[cfg(not(feature = "collator-selection"))]343 {344 Weight::zero()345 }346 }347}