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 = "unique-scheduler")]27pub mod scheduler;2829pub mod sponsoring;30#[allow(missing_docs)]31pub mod weights;3233#[cfg(test)]34pub mod tests;3536use frame_support::{37 traits::{Currency, Imbalance, OnUnbalanced},38 weights::Weight,39};40use sp_runtime::{41 generic, impl_opaque_keys,42 traits::{BlakeTwo256, BlockNumberProvider},43};44use sp_std::vec::Vec;45#[cfg(feature = "std")]46use sp_version::NativeVersion;47use up_common::types::{AccountId, BlockNumber};4849use crate::{50 AllPalletsWithSystem, Aura, Balances, InherentDataExt, Runtime, RuntimeCall, Signature,51 Treasury,52};5354#[macro_export]55macro_rules! unsupported {56 () => {57 pallet_common::unsupported!($crate::Runtime)58 };59}606162pub type Address = sp_runtime::MultiAddress<AccountId, ()>;6364pub type SignedBlock = generic::SignedBlock<Block>;6566pub type UncheckedExtrinsic =67 fp_self_contained::UncheckedExtrinsic<Address, RuntimeCall, Signature, SignedExtra>;6869pub type Header = generic::Header<BlockNumber, BlakeTwo256>;7071pub type Block = generic::Block<Header, UncheckedExtrinsic>;7273pub type BlockId = generic::BlockId<Block>;7475impl_opaque_keys! {76 pub struct SessionKeys {77 pub aura: Aura,78 }79}808182#[cfg(feature = "std")]83pub fn native_version() -> NativeVersion {84 NativeVersion {85 runtime_version: crate::VERSION,86 can_author_with: Default::default(),87 }88}8990pub type ChargeTransactionPayment = pallet_charge_transaction::ChargeTransactionPayment<Runtime>;9192pub type SignedExtra = (93 frame_system::CheckSpecVersion<Runtime>,94 frame_system::CheckTxVersion<Runtime>,95 frame_system::CheckGenesis<Runtime>,96 frame_system::CheckEra<Runtime>,97 frame_system::CheckNonce<Runtime>,98 frame_system::CheckWeight<Runtime>,99 maintenance::CheckMaintenance,100 identity::DisableIdentityCalls,101 ChargeTransactionPayment,102 103 pallet_ethereum::FakeTransactionFinalizer<Runtime>,104);105106107pub type Executive = frame_executive::Executive<108 Runtime,109 Block,110 frame_system::ChainContext<Runtime>,111 Runtime,112 AllPalletsWithSystem,113 AuraToCollatorSelection,114>;115116type NegativeImbalance = <Balances as Currency<AccountId>>::NegativeImbalance;117118pub struct DealWithFees;119impl OnUnbalanced<NegativeImbalance> for DealWithFees {120 fn on_unbalanceds<B>(mut fees_then_tips: impl Iterator<Item = NegativeImbalance>) {121 if let Some(fees) = fees_then_tips.next() {122 123 let mut split = fees.ration(100, 0);124 if let Some(tips) = fees_then_tips.next() {125 126 tips.ration_merge_into(100, 0, &mut split);127 }128 Treasury::on_unbalanced(split.0);129 130 }131 }132}133134pub struct RelayChainBlockNumberProvider<T>(sp_std::marker::PhantomData<T>);135136impl<T: cumulus_pallet_parachain_system::Config> BlockNumberProvider137 for RelayChainBlockNumberProvider<T>138{139 type BlockNumber = BlockNumber;140141 fn current_block_number() -> Self::BlockNumber {142 cumulus_pallet_parachain_system::Pallet::<T>::validation_data()143 .map(|d| d.relay_parent_number)144 .unwrap_or_default()145 }146 #[cfg(feature = "runtime-benchmarks")]147 fn set_block_number(block: Self::BlockNumber) {148 cumulus_pallet_parachain_system::RelaychainDataProvider::<T>::set_block_number(block)149 }150}151152pub(crate) struct CheckInherents;153154impl cumulus_pallet_parachain_system::CheckInherents<Block> for CheckInherents {155 fn check_inherents(156 block: &Block,157 relay_state_proof: &cumulus_pallet_parachain_system::RelayChainStateProof,158 ) -> sp_inherents::CheckInherentsResult {159 let relay_chain_slot = relay_state_proof160 .read_slot()161 .expect("Could not read the relay chain slot from the proof");162163 let inherent_data =164 cumulus_primitives_timestamp::InherentDataProvider::from_relay_chain_slot_and_duration(165 relay_chain_slot,166 sp_std::time::Duration::from_secs(6),167 )168 .create_inherent_data()169 .expect("Could not create the timestamp inherent data");170171 inherent_data.check_extrinsics(block)172 }173}174175#[derive(parity_scale_codec::Encode, parity_scale_codec::Decode)]176pub enum XCMPMessage<XAccountId, XBalance> {177 178 TransferToken(XAccountId, XBalance),179}180181pub struct AuraToCollatorSelection;182impl frame_support::traits::OnRuntimeUpgrade for AuraToCollatorSelection {183 fn on_runtime_upgrade() -> Weight {184 #[cfg(feature = "collator-selection")]185 {186 use frame_support::{storage::migration, BoundedVec};187 use pallet_session::SessionManager;188 use sp_runtime::{traits::OpaqueKeys, RuntimeAppPublic};189190 use crate::config::pallets::MaxCollators;191192 let mut weight = <Runtime as frame_system::Config>::DbWeight::get().reads(1);193194 let version = migration::get_storage_value::<()>(195 b"AuraToCollatorSelection",196 b"StorageVersion",197 &[],198 );199200 let should_upgrade = version.is_none();201202 if should_upgrade {203 log::info!(204 target: "runtime::aura_to_collator_selection",205 "Running migration of Aura authorities to Collator Selection invulnerables"206 );207208 let invulnerables = pallet_aura::Pallet::<Runtime>::authorities()209 .iter()210 .cloned()211 .filter_map(|authority_id| {212 weight.saturating_accrue(<Runtime as frame_system::Config>::DbWeight::get().reads_writes(1, 1));213 let vec = authority_id.to_raw_vec();214 let slice = vec.as_slice();215 let array: Option<[u8; 32]> = match slice.try_into() {216 Ok(a) => Some(a),217 Err(_) => {218 log::error!("Failed to convert an Aura authority to a Collator Selection invulnerable: {:?}", authority_id);219 None220 },221 };222 array.map(|a| (AccountId::from(a), authority_id))223 })224 .collect::<Vec<_>>();225226 let bounded_invulnerables = BoundedVec::<_, MaxCollators>::try_from(227 invulnerables228 .iter()229 .cloned()230 .map(|(acc, _)| acc)231 .collect::<Vec<_>>(),232 )233 .expect("Existing collators/invulnerables are more than MaxCollators");234235 <pallet_collator_selection::Invulnerables<Runtime>>::put(bounded_invulnerables);236237 let keys = invulnerables238 .into_iter()239 .map(|(acc, aura)| {240 (241 acc.clone(), 242 acc, 243 SessionKeys { aura }, 244 )245 })246 .collect::<Vec<_>>();247248 for (account, val, keys) in keys.iter() {249 for id in <Runtime as pallet_session::Config>::Keys::key_ids() {250 <pallet_session::KeyOwner<Runtime>>::insert((*id, keys.get_raw(*id)), val)251 }252 <pallet_session::NextKeys<Runtime>>::insert(val, keys);253 254 if frame_system::Pallet::<Runtime>::inc_consumers_without_limit(account)255 .is_err()256 {257 log::warn!(258 "We have entered an error with incrementing consumers without limit during the migration"259 );260 261 262 263 264 frame_system::Pallet::<Runtime>::inc_providers(account);265 }266 }267268 let initial_validators_0 =269 <Runtime as pallet_session::Config>::SessionManager::new_session(0)270 .unwrap_or_else(|| {271 frame_support::print(272 "No initial validator provided by `SessionManager`, use \273 session config keys to generate initial validator set.",274 );275 keys.iter().map(|x| x.1.clone()).collect()276 });277 278279280281282 let initial_validators_1 =283 <Runtime as pallet_session::Config>::SessionManager::new_session(1)284 .unwrap_or_else(|| initial_validators_0.clone());285 286287288289290 let queued_keys: Vec<_> = initial_validators_1291 .iter()292 .cloned()293 .map(|v| {294 (295 v.clone(),296 <pallet_session::NextKeys<Runtime>>::get(&v)297 .expect("Validator in session 1 missing keys!"),298 )299 })300 .collect();301302 303 304305 <pallet_session::Validators<Runtime>>::put(initial_validators_0);306 <pallet_session::QueuedKeys<Runtime>>::put(queued_keys);307308 <Runtime as pallet_session::Config>::SessionManager::start_session(0);309310 log::info!(311 target: "runtime::aura_to_collator_selection",312 "Migration of Aura authorities to Collator Selection invulnerables is complete."313 );314315 migration::put_storage_value::<()>(316 b"AuraToCollatorSelection",317 b"StorageVersion",318 &[],319 (),320 );321322 weight += <Runtime as frame_system::Config>::DbWeight::get().writes(1)323 } else {324 log::info!(325 target: "runtime::aura_to_collator_selection",326 "The storage migration has already been flagged as complete. No migration needs to be done.",327 );328 }329330 weight331 }332333 #[cfg(not(feature = "collator-selection"))]334 {335 Weight::zero()336 }337 }338}