From 610987a19da816a76c296c99f311ce8f6e9ab3d8 Mon Sep 17 00:00:00 2001 From: Matteo Muraca <56828990+muraca@users.noreply.github.com> Date: Mon, 18 Mar 2024 20:19:20 +0100 Subject: [PATCH 1/4] removed `pallet::getter` usage from cumulus pallets (#3471) Part of #3326 @ggwpez @kianenigma @shawntabrizi polkadot address: 12poSUQPtcF1HUPQGY3zZu2P8emuW9YnsPduA4XG3oCEfJVp --------- Signed-off-by: Matteo Muraca --- .../pallets/aura-ext/src/consensus_hook.rs | 6 +- cumulus/pallets/aura-ext/src/lib.rs | 1 - .../collator-selection/src/benchmarking.rs | 76 ++--- cumulus/pallets/collator-selection/src/lib.rs | 83 +++-- .../collator-selection/src/migration.rs | 2 +- .../pallets/collator-selection/src/tests.rs | 316 +++++++++--------- cumulus/pallets/parachain-system/src/lib.rs | 30 +- .../pallets/parachain-info/src/lib.rs | 11 +- prdoc/pr_3471.prdoc | 33 ++ 9 files changed, 292 insertions(+), 266 deletions(-) create mode 100644 prdoc/pr_3471.prdoc diff --git a/cumulus/pallets/aura-ext/src/consensus_hook.rs b/cumulus/pallets/aura-ext/src/consensus_hook.rs index 089ab5c3198b..592029803391 100644 --- a/cumulus/pallets/aura-ext/src/consensus_hook.rs +++ b/cumulus/pallets/aura-ext/src/consensus_hook.rs @@ -54,8 +54,8 @@ where let velocity = V.max(1); let relay_chain_slot = state_proof.read_slot().expect("failed to read relay chain slot"); - let (slot, authored) = pallet::Pallet::::slot_info() - .expect("slot info is inserted on block initialization"); + let (slot, authored) = + pallet::SlotInfo::::get().expect("slot info is inserted on block initialization"); // Convert relay chain timestamp. let relay_chain_timestamp = @@ -100,7 +100,7 @@ impl< /// is more recent than the included block itself. pub fn can_build_upon(included_hash: T::Hash, new_slot: Slot) -> bool { let velocity = V.max(1); - let (last_slot, authored_so_far) = match pallet::Pallet::::slot_info() { + let (last_slot, authored_so_far) = match pallet::SlotInfo::::get() { None => return true, Some(x) => x, }; diff --git a/cumulus/pallets/aura-ext/src/lib.rs b/cumulus/pallets/aura-ext/src/lib.rs index b71ae628954c..7ca84dff7c51 100644 --- a/cumulus/pallets/aura-ext/src/lib.rs +++ b/cumulus/pallets/aura-ext/src/lib.rs @@ -103,7 +103,6 @@ pub mod pallet { /// /// Updated on each block initialization. #[pallet::storage] - #[pallet::getter(fn slot_info)] pub(crate) type SlotInfo = StorageValue<_, (Slot, u32), OptionQuery>; #[pallet::genesis_config] diff --git a/cumulus/pallets/collator-selection/src/benchmarking.rs b/cumulus/pallets/collator-selection/src/benchmarking.rs index e2af74a6e60e..c6b600445282 100644 --- a/cumulus/pallets/collator-selection/src/benchmarking.rs +++ b/cumulus/pallets/collator-selection/src/benchmarking.rs @@ -86,23 +86,23 @@ fn register_validators(count: u32) -> Vec(count: u32) { let candidates = (0..count).map(|c| account("candidate", c, SEED)).collect::>(); - assert!(>::get() > 0u32.into(), "Bond cannot be zero!"); + assert!(CandidacyBond::::get() > 0u32.into(), "Bond cannot be zero!"); for who in candidates { - T::Currency::make_free_balance_be(&who, >::get() * 3u32.into()); + T::Currency::make_free_balance_be(&who, CandidacyBond::::get() * 3u32.into()); >::register_as_candidate(RawOrigin::Signed(who).into()).unwrap(); } } fn min_candidates() -> u32 { let min_collators = T::MinEligibleCollators::get(); - let invulnerable_length = >::get().len(); + let invulnerable_length = Invulnerables::::get().len(); min_collators.saturating_sub(invulnerable_length.try_into().unwrap()) } fn min_invulnerables() -> u32 { let min_collators = T::MinEligibleCollators::get(); - let candidates_length = >::decode_len() + let candidates_length = CandidateList::::decode_len() .unwrap_or_default() .try_into() .unwrap_or_default(); @@ -143,8 +143,8 @@ mod benchmarks { T::UpdateOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?; // need to fill up candidates - >::put(T::Currency::minimum_balance()); - >::put(c); + CandidacyBond::::put(T::Currency::minimum_balance()); + DesiredCandidates::::put(c); // get accounts and keys for the `c` candidates let mut candidates = (0..c).map(|cc| validator::(cc)).collect::>(); // add one more to the list. should not be in `b` (invulnerables) because it's the account @@ -159,15 +159,15 @@ mod benchmarks { } // ... and register them. for (who, _) in candidates.iter() { - let deposit = >::get(); + let deposit = CandidacyBond::::get(); T::Currency::make_free_balance_be(who, deposit * 1000_u32.into()); - >::try_mutate(|list| { + CandidateList::::try_mutate(|list| { list.try_push(CandidateInfo { who: who.clone(), deposit }).unwrap(); Ok::<(), BenchmarkError>(()) }) .unwrap(); T::Currency::reserve(who, deposit)?; - >::insert( + LastAuthoredBlock::::insert( who.clone(), frame_system::Pallet::::block_number() + T::KickThreshold::get(), ); @@ -178,7 +178,7 @@ mod benchmarks { invulnerables.sort(); let invulnerables: frame_support::BoundedVec<_, T::MaxInvulnerables> = frame_support::BoundedVec::try_from(invulnerables).unwrap(); - >::put(invulnerables); + Invulnerables::::put(invulnerables); #[extrinsic_call] _(origin as T::RuntimeOrigin, new_invulnerable.clone()); @@ -197,8 +197,8 @@ mod benchmarks { invulnerables.sort(); let invulnerables: frame_support::BoundedVec<_, T::MaxInvulnerables> = frame_support::BoundedVec::try_from(invulnerables).unwrap(); - >::put(invulnerables); - let to_remove = >::get().first().unwrap().clone(); + Invulnerables::::put(invulnerables); + let to_remove = Invulnerables::::get().first().unwrap().clone(); #[extrinsic_call] _(origin as T::RuntimeOrigin, to_remove.clone()); @@ -226,14 +226,14 @@ mod benchmarks { k: Linear<0, { T::MaxCandidates::get() }>, ) -> Result<(), BenchmarkError> { let initial_bond_amount: BalanceOf = T::Currency::minimum_balance() * 2u32.into(); - >::put(initial_bond_amount); + CandidacyBond::::put(initial_bond_amount); register_validators::(c); register_candidates::(c); let kicked = cmp::min(k, c); let origin = T::UpdateOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?; let bond_amount = if k > 0 { - >::mutate(|candidates| { + CandidateList::::mutate(|candidates| { for info in candidates.iter_mut().skip(kicked as usize) { info.deposit = T::Currency::minimum_balance() * 3u32.into(); } @@ -254,13 +254,13 @@ mod benchmarks { fn update_bond( c: Linear<{ min_candidates::() + 1 }, { T::MaxCandidates::get() }>, ) -> Result<(), BenchmarkError> { - >::put(T::Currency::minimum_balance()); - >::put(c); + CandidacyBond::::put(T::Currency::minimum_balance()); + DesiredCandidates::::put(c); register_validators::(c); register_candidates::(c); - let caller = >::get()[0].who.clone(); + let caller = CandidateList::::get()[0].who.clone(); v2::whitelist!(caller); let bond_amount: BalanceOf = @@ -273,7 +273,7 @@ mod benchmarks { Event::CandidateBondUpdated { account_id: caller, deposit: bond_amount }.into(), ); assert!( - >::get().iter().last().unwrap().deposit == + CandidateList::::get().iter().last().unwrap().deposit == T::Currency::minimum_balance() * 2u32.into() ); Ok(()) @@ -283,8 +283,8 @@ mod benchmarks { // one. #[benchmark] fn register_as_candidate(c: Linear<1, { T::MaxCandidates::get() - 1 }>) { - >::put(T::Currency::minimum_balance()); - >::put(c + 1); + CandidacyBond::::put(T::Currency::minimum_balance()); + DesiredCandidates::::put(c + 1); register_validators::(c); register_candidates::(c); @@ -310,8 +310,8 @@ mod benchmarks { #[benchmark] fn take_candidate_slot(c: Linear<{ min_candidates::() + 1 }, { T::MaxCandidates::get() }>) { - >::put(T::Currency::minimum_balance()); - >::put(1); + CandidacyBond::::put(T::Currency::minimum_balance()); + DesiredCandidates::::put(1); register_validators::(c); register_candidates::(c); @@ -327,7 +327,7 @@ mod benchmarks { ) .unwrap(); - let target = >::get().iter().last().unwrap().who.clone(); + let target = CandidateList::::get().iter().last().unwrap().who.clone(); #[extrinsic_call] _(RawOrigin::Signed(caller.clone()), bond / 2u32.into(), target.clone()); @@ -341,13 +341,13 @@ mod benchmarks { // worse case is the last candidate leaving. #[benchmark] fn leave_intent(c: Linear<{ min_candidates::() + 1 }, { T::MaxCandidates::get() }>) { - >::put(T::Currency::minimum_balance()); - >::put(c); + CandidacyBond::::put(T::Currency::minimum_balance()); + DesiredCandidates::::put(c); register_validators::(c); register_candidates::(c); - let leaving = >::get().iter().last().unwrap().who.clone(); + let leaving = CandidateList::::get().iter().last().unwrap().who.clone(); v2::whitelist!(leaving); #[extrinsic_call] @@ -359,7 +359,7 @@ mod benchmarks { // worse case is paying a non-existing candidate account. #[benchmark] fn note_author() { - >::put(T::Currency::minimum_balance()); + CandidacyBond::::put(T::Currency::minimum_balance()); T::Currency::make_free_balance_be( &>::account_id(), T::Currency::minimum_balance() * 4u32.into(), @@ -385,8 +385,8 @@ mod benchmarks { r: Linear<1, { T::MaxCandidates::get() }>, c: Linear<1, { T::MaxCandidates::get() }>, ) { - >::put(T::Currency::minimum_balance()); - >::put(c); + CandidacyBond::::put(T::Currency::minimum_balance()); + DesiredCandidates::::put(c); frame_system::Pallet::::set_block_number(0u32.into()); register_validators::(c); @@ -394,7 +394,7 @@ mod benchmarks { let new_block: BlockNumberFor = T::KickThreshold::get(); let zero_block: BlockNumberFor = 0u32.into(); - let candidates: Vec = >::get() + let candidates: Vec = CandidateList::::get() .iter() .map(|candidate_info| candidate_info.who.clone()) .collect(); @@ -402,25 +402,25 @@ mod benchmarks { let non_removals = c.saturating_sub(r); for i in 0..c { - >::insert(candidates[i as usize].clone(), zero_block); + LastAuthoredBlock::::insert(candidates[i as usize].clone(), zero_block); } if non_removals > 0 { for i in 0..non_removals { - >::insert(candidates[i as usize].clone(), new_block); + LastAuthoredBlock::::insert(candidates[i as usize].clone(), new_block); } } else { for i in 0..c { - >::insert(candidates[i as usize].clone(), new_block); + LastAuthoredBlock::::insert(candidates[i as usize].clone(), new_block); } } let min_candidates = min_candidates::(); - let pre_length = >::decode_len().unwrap_or_default(); + let pre_length = CandidateList::::decode_len().unwrap_or_default(); frame_system::Pallet::::set_block_number(new_block); - let current_length: u32 = >::decode_len() + let current_length: u32 = CandidateList::::decode_len() .unwrap_or_default() .try_into() .unwrap_or_default(); @@ -434,12 +434,12 @@ mod benchmarks { // candidates > removals and remaining candidates > min candidates // => remaining candidates should be shorter than before removal, i.e. some were // actually removed. - assert!(>::decode_len().unwrap_or_default() < pre_length); + assert!(CandidateList::::decode_len().unwrap_or_default() < pre_length); } else if c > r && non_removals < min_candidates { // candidates > removals and remaining candidates would be less than min candidates // => remaining candidates should equal min candidates, i.e. some were removed up to // the minimum, but then any more were "forced" to stay in candidates. - let current_length: u32 = >::decode_len() + let current_length: u32 = CandidateList::::decode_len() .unwrap_or_default() .try_into() .unwrap_or_default(); @@ -447,7 +447,7 @@ mod benchmarks { } else { // removals >= candidates, non removals must == 0 // can't remove more than exist - assert!(>::decode_len().unwrap_or_default() == pre_length); + assert!(CandidateList::::decode_len().unwrap_or_default() == pre_length); } } diff --git a/cumulus/pallets/collator-selection/src/lib.rs b/cumulus/pallets/collator-selection/src/lib.rs index 62c00737f91a..84bde5c9fac9 100644 --- a/cumulus/pallets/collator-selection/src/lib.rs +++ b/cumulus/pallets/collator-selection/src/lib.rs @@ -196,7 +196,6 @@ pub mod pallet { /// The invulnerable, permissioned collators. This list must be sorted. #[pallet::storage] - #[pallet::getter(fn invulnerables)] pub type Invulnerables = StorageValue<_, BoundedVec, ValueQuery>; @@ -206,7 +205,6 @@ pub mod pallet { /// This list is sorted in ascending order by deposit and when the deposits are equal, the least /// recently updated is considered greater. #[pallet::storage] - #[pallet::getter(fn candidate_list)] pub type CandidateList = StorageValue< _, BoundedVec>, T::MaxCandidates>, @@ -215,7 +213,6 @@ pub mod pallet { /// Last block authored by collator. #[pallet::storage] - #[pallet::getter(fn last_authored_block)] pub type LastAuthoredBlock = StorageMap<_, Twox64Concat, T::AccountId, BlockNumberFor, ValueQuery>; @@ -223,14 +220,12 @@ pub mod pallet { /// /// This should ideally always be less than [`Config::MaxCandidates`] for weights to be correct. #[pallet::storage] - #[pallet::getter(fn desired_candidates)] pub type DesiredCandidates = StorageValue<_, u32, ValueQuery>; /// Fixed amount to deposit to become a collator. /// /// When a collator calls `leave_intent` they immediately receive the deposit back. #[pallet::storage] - #[pallet::getter(fn candidacy_bond)] pub type CandidacyBond = StorageValue<_, BalanceOf, ValueQuery>; #[pallet::genesis_config] @@ -263,9 +258,9 @@ pub mod pallet { bounded_invulnerables.sort(); - >::put(self.desired_candidates); - >::put(self.candidacy_bond); - >::put(bounded_invulnerables); + DesiredCandidates::::put(self.desired_candidates); + CandidacyBond::::put(self.candidacy_bond); + Invulnerables::::put(bounded_invulnerables); } } @@ -424,7 +419,7 @@ pub mod pallet { // Invulnerables must be sorted for removal. bounded_invulnerables.sort(); - >::put(&bounded_invulnerables); + Invulnerables::::put(&bounded_invulnerables); Self::deposit_event(Event::NewInvulnerables { invulnerables: bounded_invulnerables.to_vec(), }); @@ -448,7 +443,7 @@ pub mod pallet { if max > T::MaxCandidates::get() { log::warn!("max > T::MaxCandidates; you might need to run benchmarks again"); } - >::put(max); + DesiredCandidates::::put(max); Self::deposit_event(Event::NewDesiredCandidates { desired_candidates: max }); Ok(().into()) } @@ -470,17 +465,17 @@ pub mod pallet { bond: BalanceOf, ) -> DispatchResultWithPostInfo { T::UpdateOrigin::ensure_origin(origin)?; - let bond_increased = >::mutate(|old_bond| -> bool { + let bond_increased = CandidacyBond::::mutate(|old_bond| -> bool { let bond_increased = *old_bond < bond; *old_bond = bond; bond_increased }); - let initial_len = >::decode_len().unwrap_or_default(); + let initial_len = CandidateList::::decode_len().unwrap_or_default(); let kicked = (bond_increased && initial_len > 0) .then(|| { // Closure below returns the number of candidates which were kicked because // their deposits were lower than the new candidacy bond. - >::mutate(|candidates| -> usize { + CandidateList::::mutate(|candidates| -> usize { let first_safe_candidate = candidates .iter() .position(|candidate| candidate.deposit >= bond) @@ -488,7 +483,7 @@ pub mod pallet { let kicked_candidates = candidates.drain(..first_safe_candidate); for candidate in kicked_candidates { T::Currency::unreserve(&candidate.who, candidate.deposit); - >::remove(candidate.who); + LastAuthoredBlock::::remove(candidate.who); } first_safe_candidate }) @@ -512,12 +507,12 @@ pub mod pallet { let who = ensure_signed(origin)?; // ensure we are below limit. - let length: u32 = >::decode_len() + let length: u32 = CandidateList::::decode_len() .unwrap_or_default() .try_into() .unwrap_or_default(); ensure!(length < T::MaxCandidates::get(), Error::::TooManyCandidates); - ensure!(!Self::invulnerables().contains(&who), Error::::AlreadyInvulnerable); + ensure!(!Invulnerables::::get().contains(&who), Error::::AlreadyInvulnerable); let validator_key = T::ValidatorIdOf::convert(who.clone()) .ok_or(Error::::NoAssociatedValidatorId)?; @@ -526,15 +521,15 @@ pub mod pallet { Error::::ValidatorNotRegistered ); - let deposit = Self::candidacy_bond(); + let deposit = CandidacyBond::::get(); // First authored block is current block plus kick threshold to handle session delay - >::try_mutate(|candidates| -> Result<(), DispatchError> { + CandidateList::::try_mutate(|candidates| -> Result<(), DispatchError> { ensure!( !candidates.iter().any(|candidate_info| candidate_info.who == who), Error::::AlreadyCandidate ); T::Currency::reserve(&who, deposit)?; - >::insert( + LastAuthoredBlock::::insert( who.clone(), frame_system::Pallet::::block_number() + T::KickThreshold::get(), ); @@ -564,7 +559,7 @@ pub mod pallet { Self::eligible_collators() > T::MinEligibleCollators::get(), Error::::TooFewEligibleCollators ); - let length = >::decode_len().unwrap_or_default(); + let length = CandidateList::::decode_len().unwrap_or_default(); // Do remove their last authored block. Self::try_remove_candidate(&who, true)?; @@ -594,7 +589,7 @@ pub mod pallet { Error::::ValidatorNotRegistered ); - >::try_mutate(|invulnerables| -> DispatchResult { + Invulnerables::::try_mutate(|invulnerables| -> DispatchResult { match invulnerables.binary_search(&who) { Ok(_) => return Err(Error::::AlreadyInvulnerable)?, Err(pos) => invulnerables @@ -615,7 +610,7 @@ pub mod pallet { .unwrap_or_default() .try_into() .unwrap_or(T::MaxInvulnerables::get().saturating_sub(1)), - >::decode_len() + CandidateList::::decode_len() .unwrap_or_default() .try_into() .unwrap_or(T::MaxCandidates::get()), @@ -638,7 +633,7 @@ pub mod pallet { Error::::TooFewEligibleCollators ); - >::try_mutate(|invulnerables| -> DispatchResult { + Invulnerables::::try_mutate(|invulnerables| -> DispatchResult { let pos = invulnerables.binary_search(&who).map_err(|_| Error::::NotInvulnerable)?; invulnerables.remove(pos); @@ -663,12 +658,12 @@ pub mod pallet { new_deposit: BalanceOf, ) -> DispatchResultWithPostInfo { let who = ensure_signed(origin)?; - ensure!(new_deposit >= >::get(), Error::::DepositTooLow); + ensure!(new_deposit >= CandidacyBond::::get(), Error::::DepositTooLow); // The function below will try to mutate the `CandidateList` entry for the caller to // update their deposit to the new value of `new_deposit`. The return value is the // position of the entry in the list, used for weight calculation. let length = - >::try_mutate(|candidates| -> Result { + CandidateList::::try_mutate(|candidates| -> Result { let idx = candidates .iter() .position(|candidate_info| candidate_info.who == who) @@ -682,7 +677,7 @@ pub mod pallet { } else if new_deposit < old_deposit { // Casting `u32` to `usize` should be safe on all machines running this. ensure!( - idx.saturating_add(>::get() as usize) < + idx.saturating_add(DesiredCandidates::::get() as usize) < candidate_count, Error::::InvalidUnreserve ); @@ -727,8 +722,8 @@ pub mod pallet { ) -> DispatchResultWithPostInfo { let who = ensure_signed(origin)?; - ensure!(!Self::invulnerables().contains(&who), Error::::AlreadyInvulnerable); - ensure!(deposit >= Self::candidacy_bond(), Error::::InsufficientBond); + ensure!(!Invulnerables::::get().contains(&who), Error::::AlreadyInvulnerable); + ensure!(deposit >= CandidacyBond::::get(), Error::::InsufficientBond); let validator_key = T::ValidatorIdOf::convert(who.clone()) .ok_or(Error::::NoAssociatedValidatorId)?; @@ -737,12 +732,12 @@ pub mod pallet { Error::::ValidatorNotRegistered ); - let length = >::decode_len().unwrap_or_default(); + let length = CandidateList::::decode_len().unwrap_or_default(); // The closure below iterates through all elements of the candidate list to ensure that // the caller isn't already a candidate and to find the target it's trying to replace in // the list. The return value is a tuple of the position of the candidate to be replaced // in the list along with its candidate information. - let target_info = >::try_mutate( + let target_info = CandidateList::::try_mutate( |candidates| -> Result>, DispatchError> { // Find the position in the list of the candidate that is being replaced. let mut target_info_idx = None; @@ -787,8 +782,8 @@ pub mod pallet { )?; T::Currency::reserve(&who, deposit)?; T::Currency::unreserve(&target_info.who, target_info.deposit); - >::remove(target_info.who.clone()); - >::insert( + LastAuthoredBlock::::remove(target_info.who.clone()); + LastAuthoredBlock::::insert( who.clone(), frame_system::Pallet::::block_number() + T::KickThreshold::get(), ); @@ -807,7 +802,7 @@ pub mod pallet { /// Return the total number of accounts that are eligible collators (candidates and /// invulnerables). fn eligible_collators() -> u32 { - >::decode_len() + CandidateList::::decode_len() .unwrap_or_default() .saturating_add(Invulnerables::::decode_len().unwrap_or_default()) .try_into() @@ -819,7 +814,7 @@ pub mod pallet { who: &T::AccountId, remove_last_authored: bool, ) -> Result<(), DispatchError> { - >::try_mutate(|candidates| -> Result<(), DispatchError> { + CandidateList::::try_mutate(|candidates| -> Result<(), DispatchError> { let idx = candidates .iter() .position(|candidate_info| candidate_info.who == *who) @@ -828,7 +823,7 @@ pub mod pallet { T::Currency::unreserve(who, deposit); candidates.remove(idx); if remove_last_authored { - >::remove(who.clone()) + LastAuthoredBlock::::remove(who.clone()) }; Ok(()) })?; @@ -841,10 +836,10 @@ pub mod pallet { /// This is done on the fly, as frequent as we are told to do so, as the session manager. pub fn assemble_collators() -> Vec { // Casting `u32` to `usize` should be safe on all machines running this. - let desired_candidates = >::get() as usize; - let mut collators = Self::invulnerables().to_vec(); + let desired_candidates = DesiredCandidates::::get() as usize; + let mut collators = Invulnerables::::get().to_vec(); collators.extend( - >::get() + CandidateList::::get() .iter() .rev() .cloned() @@ -865,10 +860,10 @@ pub mod pallet { candidates .into_iter() .filter_map(|c| { - let last_block = >::get(c.clone()); + let last_block = LastAuthoredBlock::::get(c.clone()); let since_last = now.saturating_sub(last_block); - let is_invulnerable = Self::invulnerables().contains(&c); + let is_invulnerable = Invulnerables::::get().contains(&c); let is_lazy = since_last >= kick_threshold; if is_invulnerable { @@ -907,7 +902,7 @@ pub mod pallet { /// or equal to the minimum number of eligible collators. #[cfg(any(test, feature = "try-runtime"))] pub fn do_try_state() -> Result<(), sp_runtime::TryRuntimeError> { - let desired_candidates = >::get(); + let desired_candidates = DesiredCandidates::::get(); frame_support::ensure!( desired_candidates <= T::MaxCandidates::get(), @@ -939,7 +934,7 @@ pub mod pallet { // `reward` is half of pot account minus ED, this should never fail. let _success = T::Currency::transfer(&pot, &author, reward, KeepAlive); debug_assert!(_success.is_ok()); - >::insert(author, frame_system::Pallet::::block_number()); + LastAuthoredBlock::::insert(author, frame_system::Pallet::::block_number()); frame_system::Pallet::::register_extra_weight_unchecked( T::WeightInfo::note_author(), @@ -960,12 +955,12 @@ pub mod pallet { // The `expect` below is safe because the list is a `BoundedVec` with a max size of // `T::MaxCandidates`, which is a `u32`. When `decode_len` returns `Some(len)`, `len` // must be valid and at most `u32::MAX`, which must always be able to convert to `u32`. - let candidates_len_before: u32 = >::decode_len() + let candidates_len_before: u32 = CandidateList::::decode_len() .unwrap_or_default() .try_into() .expect("length is at most `T::MaxCandidates`, so it must fit in `u32`; qed"); let active_candidates_count = Self::kick_stale_candidates( - >::get() + CandidateList::::get() .iter() .map(|candidate_info| candidate_info.who.clone()), ); diff --git a/cumulus/pallets/collator-selection/src/migration.rs b/cumulus/pallets/collator-selection/src/migration.rs index f384981dbae8..5dc2fba4279a 100644 --- a/cumulus/pallets/collator-selection/src/migration.rs +++ b/cumulus/pallets/collator-selection/src/migration.rs @@ -34,7 +34,7 @@ pub mod v1 { let on_chain_version = Pallet::::on_chain_storage_version(); if on_chain_version == 0 { let invulnerables_len = Invulnerables::::get().to_vec().len(); - >::mutate(|invulnerables| { + Invulnerables::::mutate(|invulnerables| { invulnerables.sort(); }); diff --git a/cumulus/pallets/collator-selection/src/tests.rs b/cumulus/pallets/collator-selection/src/tests.rs index ed2044ccdfad..e8b2a4e146a2 100644 --- a/cumulus/pallets/collator-selection/src/tests.rs +++ b/cumulus/pallets/collator-selection/src/tests.rs @@ -14,7 +14,10 @@ // limitations under the License. use crate as collator_selection; -use crate::{mock::*, CandidateInfo, Error}; +use crate::{ + mock::*, CandidacyBond, CandidateInfo, CandidateList, DesiredCandidates, Error, Invulnerables, + LastAuthoredBlock, +}; use frame_support::{ assert_noop, assert_ok, traits::{Currency, OnInitialize}, @@ -25,12 +28,12 @@ use sp_runtime::{testing::UintAuthorityId, traits::BadOrigin, BuildStorage}; #[test] fn basic_setup_works() { new_test_ext().execute_with(|| { - assert_eq!(CollatorSelection::desired_candidates(), 2); - assert_eq!(CollatorSelection::candidacy_bond(), 10); + assert_eq!(DesiredCandidates::::get(), 2); + assert_eq!(CandidacyBond::::get(), 10); - assert_eq!(>::get().iter().count(), 0); + assert_eq!(CandidateList::::get().iter().count(), 0); // genesis should sort input - assert_eq!(CollatorSelection::invulnerables(), vec![1, 2]); + assert_eq!(Invulnerables::::get(), vec![1, 2]); }); } @@ -43,7 +46,7 @@ fn it_should_set_invulnerables() { new_set.clone() )); new_set.sort(); - assert_eq!(CollatorSelection::invulnerables(), new_set); + assert_eq!(Invulnerables::::get(), new_set); // cannot set with non-root. assert_noop!( @@ -56,7 +59,7 @@ fn it_should_set_invulnerables() { #[test] fn it_should_set_invulnerables_even_with_some_invalid() { new_test_ext().execute_with(|| { - assert_eq!(CollatorSelection::invulnerables(), vec![1, 2]); + assert_eq!(Invulnerables::::get(), vec![1, 2]); let new_with_invalid = vec![1, 4, 3, 42, 2]; assert_ok!(CollatorSelection::set_invulnerables( @@ -65,7 +68,7 @@ fn it_should_set_invulnerables_even_with_some_invalid() { )); // should succeed and order them, but not include 42 - assert_eq!(CollatorSelection::invulnerables(), vec![1, 2, 3, 4]); + assert_eq!(Invulnerables::::get(), vec![1, 2, 3, 4]); }); } @@ -73,7 +76,7 @@ fn it_should_set_invulnerables_even_with_some_invalid() { fn add_invulnerable_works() { new_test_ext().execute_with(|| { initialize_to_block(1); - assert_eq!(CollatorSelection::invulnerables(), vec![1, 2]); + assert_eq!(Invulnerables::::get(), vec![1, 2]); let new = 3; // function runs @@ -93,7 +96,7 @@ fn add_invulnerable_works() { ); // new element is now part of the invulnerables list - assert!(CollatorSelection::invulnerables().to_vec().contains(&new)); + assert!(Invulnerables::::get().to_vec().contains(&new)); // cannot add with non-root assert_noop!(CollatorSelection::add_invulnerable(RuntimeOrigin::signed(1), new), BadOrigin); @@ -113,7 +116,7 @@ fn add_invulnerable_works() { #[test] fn invulnerable_limit_works() { new_test_ext().execute_with(|| { - assert_eq!(CollatorSelection::invulnerables(), vec![1, 2]); + assert_eq!(Invulnerables::::get(), vec![1, 2]); // MaxInvulnerables: u32 = 20 for ii in 3..=21 { @@ -140,7 +143,7 @@ fn invulnerable_limit_works() { } } let expected: Vec = (1..=20).collect(); - assert_eq!(CollatorSelection::invulnerables(), expected); + assert_eq!(Invulnerables::::get(), expected); // Cannot set too many Invulnerables let too_many_invulnerables: Vec = (1..=21).collect(); @@ -151,7 +154,7 @@ fn invulnerable_limit_works() { ), Error::::TooManyInvulnerables ); - assert_eq!(CollatorSelection::invulnerables(), expected); + assert_eq!(Invulnerables::::get(), expected); }); } @@ -159,7 +162,7 @@ fn invulnerable_limit_works() { fn remove_invulnerable_works() { new_test_ext().execute_with(|| { initialize_to_block(1); - assert_eq!(CollatorSelection::invulnerables(), vec![1, 2]); + assert_eq!(Invulnerables::::get(), vec![1, 2]); assert_ok!(CollatorSelection::add_invulnerable( RuntimeOrigin::signed(RootAccount::get()), @@ -170,7 +173,7 @@ fn remove_invulnerable_works() { 3 )); - assert_eq!(CollatorSelection::invulnerables(), vec![1, 2, 3, 4]); + assert_eq!(Invulnerables::::get(), vec![1, 2, 3, 4]); assert_ok!(CollatorSelection::remove_invulnerable( RuntimeOrigin::signed(RootAccount::get()), @@ -180,7 +183,7 @@ fn remove_invulnerable_works() { System::assert_last_event(RuntimeEvent::CollatorSelection( crate::Event::InvulnerableRemoved { account_id: 2 }, )); - assert_eq!(CollatorSelection::invulnerables(), vec![1, 3, 4]); + assert_eq!(Invulnerables::::get(), vec![1, 3, 4]); // cannot remove invulnerable not in the list assert_noop!( @@ -200,11 +203,11 @@ fn remove_invulnerable_works() { fn candidate_to_invulnerable_works() { new_test_ext().execute_with(|| { initialize_to_block(1); - assert_eq!(CollatorSelection::desired_candidates(), 2); - assert_eq!(CollatorSelection::candidacy_bond(), 10); + assert_eq!(DesiredCandidates::::get(), 2); + assert_eq!(CandidacyBond::::get(), 10); - assert_eq!(>::get().iter().count(), 0); - assert_eq!(CollatorSelection::invulnerables(), vec![1, 2]); + assert_eq!(CandidateList::::get().iter().count(), 0); + assert_eq!(Invulnerables::::get(), vec![1, 2]); assert_eq!(Balances::free_balance(3), 100); assert_eq!(Balances::free_balance(4), 100); @@ -225,9 +228,9 @@ fn candidate_to_invulnerable_works() { System::assert_has_event(RuntimeEvent::CollatorSelection( crate::Event::InvulnerableAdded { account_id: 3 }, )); - assert!(CollatorSelection::invulnerables().to_vec().contains(&3)); + assert!(Invulnerables::::get().to_vec().contains(&3)); assert_eq!(Balances::free_balance(3), 100); - assert_eq!(>::get().iter().count(), 1); + assert_eq!(CandidateList::::get().iter().count(), 1); assert_ok!(CollatorSelection::add_invulnerable( RuntimeOrigin::signed(RootAccount::get()), @@ -239,10 +242,10 @@ fn candidate_to_invulnerable_works() { System::assert_has_event(RuntimeEvent::CollatorSelection( crate::Event::InvulnerableAdded { account_id: 4 }, )); - assert!(CollatorSelection::invulnerables().to_vec().contains(&4)); + assert!(Invulnerables::::get().to_vec().contains(&4)); assert_eq!(Balances::free_balance(4), 100); - assert_eq!(>::get().iter().count(), 0); + assert_eq!(CandidateList::::get().iter().count(), 0); }); } @@ -250,14 +253,14 @@ fn candidate_to_invulnerable_works() { fn set_desired_candidates_works() { new_test_ext().execute_with(|| { // given - assert_eq!(CollatorSelection::desired_candidates(), 2); + assert_eq!(DesiredCandidates::::get(), 2); // can set assert_ok!(CollatorSelection::set_desired_candidates( RuntimeOrigin::signed(RootAccount::get()), 7 )); - assert_eq!(CollatorSelection::desired_candidates(), 7); + assert_eq!(DesiredCandidates::::get(), 7); // rejects bad origin assert_noop!( @@ -271,16 +274,16 @@ fn set_desired_candidates_works() { fn set_candidacy_bond_empty_candidate_list() { new_test_ext().execute_with(|| { // given - assert_eq!(CollatorSelection::candidacy_bond(), 10); - assert!(>::get().is_empty()); + assert_eq!(CandidacyBond::::get(), 10); + assert!(CandidateList::::get().is_empty()); // can decrease without candidates assert_ok!(CollatorSelection::set_candidacy_bond( RuntimeOrigin::signed(RootAccount::get()), 7 )); - assert_eq!(CollatorSelection::candidacy_bond(), 7); - assert!(>::get().is_empty()); + assert_eq!(CandidacyBond::::get(), 7); + assert!(CandidateList::::get().is_empty()); // rejects bad origin. assert_noop!(CollatorSelection::set_candidacy_bond(RuntimeOrigin::signed(1), 8), BadOrigin); @@ -290,8 +293,8 @@ fn set_candidacy_bond_empty_candidate_list() { RuntimeOrigin::signed(RootAccount::get()), 20 )); - assert!(>::get().is_empty()); - assert_eq!(CollatorSelection::candidacy_bond(), 20); + assert!(CandidateList::::get().is_empty()); + assert_eq!(CandidacyBond::::get(), 20); }); } @@ -299,36 +302,36 @@ fn set_candidacy_bond_empty_candidate_list() { fn set_candidacy_bond_with_one_candidate() { new_test_ext().execute_with(|| { // given - assert_eq!(CollatorSelection::candidacy_bond(), 10); - assert!(>::get().is_empty()); + assert_eq!(CandidacyBond::::get(), 10); + assert!(CandidateList::::get().is_empty()); let candidate_3 = CandidateInfo { who: 3, deposit: 10 }; assert_ok!(CollatorSelection::register_as_candidate(RuntimeOrigin::signed(3))); - assert_eq!(>::get(), vec![candidate_3.clone()]); + assert_eq!(CandidateList::::get(), vec![candidate_3.clone()]); // can decrease with one candidate assert_ok!(CollatorSelection::set_candidacy_bond( RuntimeOrigin::signed(RootAccount::get()), 7 )); - assert_eq!(CollatorSelection::candidacy_bond(), 7); - assert_eq!(>::get(), vec![candidate_3.clone()]); + assert_eq!(CandidacyBond::::get(), 7); + assert_eq!(CandidateList::::get(), vec![candidate_3.clone()]); // can increase up to initial deposit assert_ok!(CollatorSelection::set_candidacy_bond( RuntimeOrigin::signed(RootAccount::get()), 10 )); - assert_eq!(CollatorSelection::candidacy_bond(), 10); - assert_eq!(>::get(), vec![candidate_3.clone()]); + assert_eq!(CandidacyBond::::get(), 10); + assert_eq!(CandidateList::::get(), vec![candidate_3.clone()]); // can increase past initial deposit, should kick existing candidate assert_ok!(CollatorSelection::set_candidacy_bond( RuntimeOrigin::signed(RootAccount::get()), 20 )); - assert!(>::get().is_empty()); + assert!(CandidateList::::get().is_empty()); }); } @@ -336,8 +339,8 @@ fn set_candidacy_bond_with_one_candidate() { fn set_candidacy_bond_with_many_candidates_same_deposit() { new_test_ext().execute_with(|| { // given - assert_eq!(CollatorSelection::candidacy_bond(), 10); - assert!(>::get().is_empty()); + assert_eq!(CandidacyBond::::get(), 10); + assert!(CandidateList::::get().is_empty()); let candidate_3 = CandidateInfo { who: 3, deposit: 10 }; let candidate_4 = CandidateInfo { who: 4, deposit: 10 }; @@ -347,7 +350,7 @@ fn set_candidacy_bond_with_many_candidates_same_deposit() { assert_ok!(CollatorSelection::register_as_candidate(RuntimeOrigin::signed(4))); assert_ok!(CollatorSelection::register_as_candidate(RuntimeOrigin::signed(5))); assert_eq!( - >::get(), + CandidateList::::get(), vec![candidate_5.clone(), candidate_4.clone(), candidate_3.clone()] ); @@ -356,9 +359,9 @@ fn set_candidacy_bond_with_many_candidates_same_deposit() { RuntimeOrigin::signed(RootAccount::get()), 7 )); - assert_eq!(CollatorSelection::candidacy_bond(), 7); + assert_eq!(CandidacyBond::::get(), 7); assert_eq!( - >::get(), + CandidateList::::get(), vec![candidate_5.clone(), candidate_4.clone(), candidate_3.clone()] ); @@ -367,9 +370,9 @@ fn set_candidacy_bond_with_many_candidates_same_deposit() { RuntimeOrigin::signed(RootAccount::get()), 10 )); - assert_eq!(CollatorSelection::candidacy_bond(), 10); + assert_eq!(CandidacyBond::::get(), 10); assert_eq!( - >::get(), + CandidateList::::get(), vec![candidate_5.clone(), candidate_4.clone(), candidate_3.clone()] ); @@ -378,7 +381,7 @@ fn set_candidacy_bond_with_many_candidates_same_deposit() { RuntimeOrigin::signed(RootAccount::get()), 20 )); - assert!(>::get().is_empty()); + assert!(CandidateList::::get().is_empty()); }); } @@ -386,8 +389,8 @@ fn set_candidacy_bond_with_many_candidates_same_deposit() { fn set_candidacy_bond_with_many_candidates_different_deposits() { new_test_ext().execute_with(|| { // given - assert_eq!(CollatorSelection::candidacy_bond(), 10); - assert!(>::get().is_empty()); + assert_eq!(CandidacyBond::::get(), 10); + assert!(CandidateList::::get().is_empty()); let candidate_3 = CandidateInfo { who: 3, deposit: 10 }; let candidate_4 = CandidateInfo { who: 4, deposit: 20 }; @@ -399,7 +402,7 @@ fn set_candidacy_bond_with_many_candidates_different_deposits() { assert_ok!(CollatorSelection::update_bond(RuntimeOrigin::signed(5), 30)); assert_ok!(CollatorSelection::update_bond(RuntimeOrigin::signed(4), 20)); assert_eq!( - >::get(), + CandidateList::::get(), vec![candidate_3.clone(), candidate_4.clone(), candidate_5.clone()] ); @@ -408,9 +411,9 @@ fn set_candidacy_bond_with_many_candidates_different_deposits() { RuntimeOrigin::signed(RootAccount::get()), 7 )); - assert_eq!(CollatorSelection::candidacy_bond(), 7); + assert_eq!(CandidacyBond::::get(), 7); assert_eq!( - >::get(), + CandidateList::::get(), vec![candidate_3.clone(), candidate_4.clone(), candidate_5.clone()] ); // can increase up to initial deposit @@ -418,9 +421,9 @@ fn set_candidacy_bond_with_many_candidates_different_deposits() { RuntimeOrigin::signed(RootAccount::get()), 10 )); - assert_eq!(CollatorSelection::candidacy_bond(), 10); + assert_eq!(CandidacyBond::::get(), 10); assert_eq!( - >::get(), + CandidateList::::get(), vec![candidate_3.clone(), candidate_4.clone(), candidate_5.clone()] ); @@ -429,27 +432,24 @@ fn set_candidacy_bond_with_many_candidates_different_deposits() { RuntimeOrigin::signed(RootAccount::get()), 20 )); - assert_eq!(CollatorSelection::candidacy_bond(), 20); - assert_eq!( - >::get(), - vec![candidate_4.clone(), candidate_5.clone()] - ); + assert_eq!(CandidacyBond::::get(), 20); + assert_eq!(CandidateList::::get(), vec![candidate_4.clone(), candidate_5.clone()]); // can increase past 4's deposit, should kick 4 assert_ok!(CollatorSelection::set_candidacy_bond( RuntimeOrigin::signed(RootAccount::get()), 25 )); - assert_eq!(CollatorSelection::candidacy_bond(), 25); - assert_eq!(>::get(), vec![candidate_5.clone()]); + assert_eq!(CandidacyBond::::get(), 25); + assert_eq!(CandidateList::::get(), vec![candidate_5.clone()]); // lowering the minimum deposit should have no effect assert_ok!(CollatorSelection::set_candidacy_bond( RuntimeOrigin::signed(RootAccount::get()), 5 )); - assert_eq!(CollatorSelection::candidacy_bond(), 5); - assert_eq!(>::get(), vec![candidate_5.clone()]); + assert_eq!(CandidacyBond::::get(), 5); + assert_eq!(CandidateList::::get(), vec![candidate_5.clone()]); // add 3 and 4 back but with higher deposits than minimum assert_ok!(CollatorSelection::register_as_candidate(RuntimeOrigin::signed(3))); @@ -457,7 +457,7 @@ fn set_candidacy_bond_with_many_candidates_different_deposits() { assert_ok!(CollatorSelection::update_bond(RuntimeOrigin::signed(3), 10)); assert_ok!(CollatorSelection::update_bond(RuntimeOrigin::signed(4), 20)); assert_eq!( - >::get(), + CandidateList::::get(), vec![candidate_3.clone(), candidate_4.clone(), candidate_5.clone()] ); @@ -467,8 +467,8 @@ fn set_candidacy_bond_with_many_candidates_different_deposits() { RuntimeOrigin::signed(RootAccount::get()), 40 )); - assert_eq!(CollatorSelection::candidacy_bond(), 40); - assert!(>::get().is_empty()); + assert_eq!(CandidacyBond::::get(), 40); + assert!(CandidateList::::get().is_empty()); }); } @@ -500,8 +500,8 @@ fn cannot_register_candidate_if_too_many() { #[test] fn cannot_unregister_candidate_if_too_few() { new_test_ext().execute_with(|| { - assert_eq!(>::get().iter().count(), 0); - assert_eq!(CollatorSelection::invulnerables(), vec![1, 2]); + assert_eq!(CandidateList::::get().iter().count(), 0); + assert_eq!(Invulnerables::::get(), vec![1, 2]); assert_ok!(CollatorSelection::remove_invulnerable( RuntimeOrigin::signed(RootAccount::get()), 1 @@ -532,7 +532,7 @@ fn cannot_unregister_candidate_if_too_few() { #[test] fn cannot_register_as_candidate_if_invulnerable() { new_test_ext().execute_with(|| { - assert_eq!(CollatorSelection::invulnerables(), vec![1, 2]); + assert_eq!(Invulnerables::::get(), vec![1, 2]); // can't 1 because it is invulnerable. assert_noop!( @@ -561,10 +561,10 @@ fn cannot_register_dupe_candidate() { // tuple of (id, deposit). let addition = CandidateInfo { who: 3, deposit: 10 }; assert_eq!( - >::get().iter().cloned().collect::>(), + CandidateList::::get().iter().cloned().collect::>(), vec![addition] ); - assert_eq!(CollatorSelection::last_authored_block(3), 10); + assert_eq!(LastAuthoredBlock::::get(3), 10); assert_eq!(Balances::free_balance(3), 90); // but no more @@ -596,11 +596,11 @@ fn cannot_register_as_candidate_if_poor() { fn register_as_candidate_works() { new_test_ext().execute_with(|| { // given - assert_eq!(CollatorSelection::desired_candidates(), 2); - assert_eq!(CollatorSelection::candidacy_bond(), 10); + assert_eq!(DesiredCandidates::::get(), 2); + assert_eq!(CandidacyBond::::get(), 10); - assert_eq!(>::get().iter().count(), 0); - assert_eq!(CollatorSelection::invulnerables(), vec![1, 2]); + assert_eq!(CandidateList::::get().iter().count(), 0); + assert_eq!(Invulnerables::::get(), vec![1, 2]); // take two endowed, non-invulnerables accounts. assert_eq!(Balances::free_balance(3), 100); @@ -612,14 +612,14 @@ fn register_as_candidate_works() { assert_eq!(Balances::free_balance(3), 90); assert_eq!(Balances::free_balance(4), 90); - assert_eq!(>::get().iter().count(), 2); + assert_eq!(CandidateList::::get().iter().count(), 2); }); } #[test] fn cannot_take_candidate_slot_if_invulnerable() { new_test_ext().execute_with(|| { - assert_eq!(CollatorSelection::invulnerables(), vec![1, 2]); + assert_eq!(Invulnerables::::get(), vec![1, 2]); // can't 1 because it is invulnerable. assert_noop!( @@ -649,11 +649,10 @@ fn cannot_take_candidate_slot_if_duplicate() { // tuple of (id, deposit). let candidate_3 = CandidateInfo { who: 3, deposit: 10 }; let candidate_4 = CandidateInfo { who: 4, deposit: 10 }; - let actual_candidates = - >::get().iter().cloned().collect::>(); + let actual_candidates = CandidateList::::get().iter().cloned().collect::>(); assert_eq!(actual_candidates, vec![candidate_4, candidate_3]); - assert_eq!(CollatorSelection::last_authored_block(3), 10); - assert_eq!(CollatorSelection::last_authored_block(4), 10); + assert_eq!(LastAuthoredBlock::::get(3), 10); + assert_eq!(LastAuthoredBlock::::get(4), 10); assert_eq!(Balances::free_balance(3), 90); // but no more @@ -672,10 +671,10 @@ fn cannot_take_candidate_slot_if_target_invalid() { // tuple of (id, deposit). let candidate_3 = CandidateInfo { who: 3, deposit: 10 }; assert_eq!( - >::get().iter().cloned().collect::>(), + CandidateList::::get().iter().cloned().collect::>(), vec![candidate_3] ); - assert_eq!(CollatorSelection::last_authored_block(3), 10); + assert_eq!(LastAuthoredBlock::::get(3), 10); assert_eq!(Balances::free_balance(3), 90); assert_eq!(Balances::free_balance(4), 100); @@ -744,11 +743,11 @@ fn cannot_take_candidate_slot_if_deposit_less_than_target() { fn take_candidate_slot_works() { new_test_ext().execute_with(|| { // given - assert_eq!(CollatorSelection::desired_candidates(), 2); - assert_eq!(CollatorSelection::candidacy_bond(), 10); + assert_eq!(DesiredCandidates::::get(), 2); + assert_eq!(CandidacyBond::::get(), 10); - assert_eq!(>::get().iter().count(), 0); - assert_eq!(CollatorSelection::invulnerables(), vec![1, 2]); + assert_eq!(CandidateList::::get().iter().count(), 0); + assert_eq!(Invulnerables::::get(), vec![1, 2]); // take two endowed, non-invulnerables accounts. assert_eq!(Balances::free_balance(3), 100); @@ -763,7 +762,7 @@ fn take_candidate_slot_works() { assert_eq!(Balances::free_balance(4), 90); assert_eq!(Balances::free_balance(5), 90); - assert_eq!(>::get().iter().count(), 3); + assert_eq!(CandidateList::::get().iter().count(), 3); Balances::make_free_balance_be(&6, 100); let key = MockSessionKeys { aura: UintAuthorityId(6) }; @@ -785,10 +784,10 @@ fn take_candidate_slot_works() { let candidate_6 = CandidateInfo { who: 6, deposit: 50 }; let candidate_5 = CandidateInfo { who: 5, deposit: 10 }; let mut actual_candidates = - >::get().iter().cloned().collect::>(); + CandidateList::::get().iter().cloned().collect::>(); actual_candidates.sort_by(|info_1, info_2| info_1.deposit.cmp(&info_2.deposit)); assert_eq!( - >::get().iter().cloned().collect::>(), + CandidateList::::get().iter().cloned().collect::>(), vec![candidate_5, candidate_3, candidate_6] ); }); @@ -798,11 +797,11 @@ fn take_candidate_slot_works() { fn increase_candidacy_bond_non_candidate_account() { new_test_ext().execute_with(|| { // given - assert_eq!(CollatorSelection::desired_candidates(), 2); - assert_eq!(CollatorSelection::candidacy_bond(), 10); + assert_eq!(DesiredCandidates::::get(), 2); + assert_eq!(CandidacyBond::::get(), 10); - assert_eq!(>::get().iter().count(), 0); - assert_eq!(CollatorSelection::invulnerables(), vec![1, 2]); + assert_eq!(CandidateList::::get().iter().count(), 0); + assert_eq!(Invulnerables::::get(), vec![1, 2]); assert_ok!(CollatorSelection::register_as_candidate(RuntimeOrigin::signed(3))); assert_ok!(CollatorSelection::register_as_candidate(RuntimeOrigin::signed(4))); @@ -818,11 +817,11 @@ fn increase_candidacy_bond_non_candidate_account() { fn increase_candidacy_bond_insufficient_balance() { new_test_ext().execute_with(|| { // given - assert_eq!(CollatorSelection::desired_candidates(), 2); - assert_eq!(CollatorSelection::candidacy_bond(), 10); + assert_eq!(DesiredCandidates::::get(), 2); + assert_eq!(CandidacyBond::::get(), 10); - assert_eq!(>::get().iter().count(), 0); - assert_eq!(CollatorSelection::invulnerables(), vec![1, 2]); + assert_eq!(CandidateList::::get().iter().count(), 0); + assert_eq!(Invulnerables::::get(), vec![1, 2]); // take two endowed, non-invulnerables accounts. assert_eq!(Balances::free_balance(3), 100); @@ -850,11 +849,11 @@ fn increase_candidacy_bond_insufficient_balance() { fn increase_candidacy_bond_works() { new_test_ext().execute_with(|| { // given - assert_eq!(CollatorSelection::desired_candidates(), 2); - assert_eq!(CollatorSelection::candidacy_bond(), 10); + assert_eq!(DesiredCandidates::::get(), 2); + assert_eq!(CandidacyBond::::get(), 10); - assert_eq!(>::get().iter().count(), 0); - assert_eq!(CollatorSelection::invulnerables(), vec![1, 2]); + assert_eq!(CandidateList::::get().iter().count(), 0); + assert_eq!(Invulnerables::::get(), vec![1, 2]); // take three endowed, non-invulnerables accounts. assert_eq!(Balances::free_balance(3), 100); @@ -873,7 +872,7 @@ fn increase_candidacy_bond_works() { assert_ok!(CollatorSelection::update_bond(RuntimeOrigin::signed(4), 30)); assert_ok!(CollatorSelection::update_bond(RuntimeOrigin::signed(5), 40)); - assert_eq!(>::get().iter().count(), 3); + assert_eq!(CandidateList::::get().iter().count(), 3); assert_eq!(Balances::free_balance(3), 80); assert_eq!(Balances::free_balance(4), 70); assert_eq!(Balances::free_balance(5), 60); @@ -881,7 +880,7 @@ fn increase_candidacy_bond_works() { assert_ok!(CollatorSelection::update_bond(RuntimeOrigin::signed(3), 40)); assert_ok!(CollatorSelection::update_bond(RuntimeOrigin::signed(4), 60)); - assert_eq!(>::get().iter().count(), 3); + assert_eq!(CandidateList::::get().iter().count(), 3); assert_eq!(Balances::free_balance(3), 60); assert_eq!(Balances::free_balance(4), 40); assert_eq!(Balances::free_balance(5), 60); @@ -892,11 +891,11 @@ fn increase_candidacy_bond_works() { fn decrease_candidacy_bond_non_candidate_account() { new_test_ext().execute_with(|| { // given - assert_eq!(CollatorSelection::desired_candidates(), 2); - assert_eq!(CollatorSelection::candidacy_bond(), 10); + assert_eq!(DesiredCandidates::::get(), 2); + assert_eq!(CandidacyBond::::get(), 10); - assert_eq!(>::get().iter().count(), 0); - assert_eq!(CollatorSelection::invulnerables(), vec![1, 2]); + assert_eq!(CandidateList::::get().iter().count(), 0); + assert_eq!(Invulnerables::::get(), vec![1, 2]); assert_ok!(CollatorSelection::register_as_candidate(RuntimeOrigin::signed(3))); assert_ok!(CollatorSelection::register_as_candidate(RuntimeOrigin::signed(4))); @@ -914,11 +913,11 @@ fn decrease_candidacy_bond_non_candidate_account() { fn decrease_candidacy_bond_insufficient_funds() { new_test_ext().execute_with(|| { // given - assert_eq!(CollatorSelection::desired_candidates(), 2); - assert_eq!(CollatorSelection::candidacy_bond(), 10); + assert_eq!(DesiredCandidates::::get(), 2); + assert_eq!(CandidacyBond::::get(), 10); - assert_eq!(>::get().iter().count(), 0); - assert_eq!(CollatorSelection::invulnerables(), vec![1, 2]); + assert_eq!(CandidateList::::get().iter().count(), 0); + assert_eq!(Invulnerables::::get(), vec![1, 2]); // take two endowed, non-invulnerables accounts. assert_eq!(Balances::free_balance(3), 100); @@ -961,7 +960,7 @@ fn decrease_candidacy_bond_insufficient_funds() { #[test] fn decrease_candidacy_bond_occupying_top_slot() { new_test_ext().execute_with(|| { - assert_eq!(CollatorSelection::desired_candidates(), 2); + assert_eq!(DesiredCandidates::::get(), 2); // Register 3 candidates. assert_ok!(CollatorSelection::register_as_candidate(RuntimeOrigin::signed(3))); assert_ok!(CollatorSelection::register_as_candidate(RuntimeOrigin::signed(4))); @@ -976,7 +975,7 @@ fn decrease_candidacy_bond_occupying_top_slot() { let candidate_4 = CandidateInfo { who: 4, deposit: 30 }; let candidate_5 = CandidateInfo { who: 5, deposit: 60 }; assert_eq!( - >::get().iter().cloned().collect::>(), + CandidateList::::get().iter().cloned().collect::>(), vec![candidate_4, candidate_3, candidate_5] ); @@ -1000,7 +999,7 @@ fn decrease_candidacy_bond_occupying_top_slot() { let candidate_4 = CandidateInfo { who: 4, deposit: 35 }; let candidate_5 = CandidateInfo { who: 5, deposit: 60 }; assert_eq!( - >::get().iter().cloned().collect::>(), + CandidateList::::get().iter().cloned().collect::>(), vec![candidate_3, candidate_4, candidate_5] ); @@ -1023,11 +1022,11 @@ fn decrease_candidacy_bond_occupying_top_slot() { fn decrease_candidacy_bond_works() { new_test_ext().execute_with(|| { // given - assert_eq!(CollatorSelection::desired_candidates(), 2); - assert_eq!(CollatorSelection::candidacy_bond(), 10); + assert_eq!(DesiredCandidates::::get(), 2); + assert_eq!(CandidacyBond::::get(), 10); - assert_eq!(>::get().iter().count(), 0); - assert_eq!(CollatorSelection::invulnerables(), vec![1, 2]); + assert_eq!(CandidateList::::get().iter().count(), 0); + assert_eq!(Invulnerables::::get(), vec![1, 2]); // take three endowed, non-invulnerables accounts. assert_eq!(Balances::free_balance(3), 100); @@ -1046,14 +1045,14 @@ fn decrease_candidacy_bond_works() { assert_ok!(CollatorSelection::update_bond(RuntimeOrigin::signed(4), 30)); assert_ok!(CollatorSelection::update_bond(RuntimeOrigin::signed(5), 40)); - assert_eq!(>::get().iter().count(), 3); + assert_eq!(CandidateList::::get().iter().count(), 3); assert_eq!(Balances::free_balance(3), 80); assert_eq!(Balances::free_balance(4), 70); assert_eq!(Balances::free_balance(5), 60); assert_ok!(CollatorSelection::update_bond(RuntimeOrigin::signed(3), 10)); - assert_eq!(>::get().iter().count(), 3); + assert_eq!(CandidateList::::get().iter().count(), 3); assert_eq!(Balances::free_balance(3), 90); assert_eq!(Balances::free_balance(4), 70); assert_eq!(Balances::free_balance(5), 60); @@ -1064,11 +1063,11 @@ fn decrease_candidacy_bond_works() { fn update_candidacy_bond_with_identical_amount() { new_test_ext().execute_with(|| { // given - assert_eq!(CollatorSelection::desired_candidates(), 2); - assert_eq!(CollatorSelection::candidacy_bond(), 10); + assert_eq!(DesiredCandidates::::get(), 2); + assert_eq!(CandidacyBond::::get(), 10); - assert_eq!(>::get().iter().count(), 0); - assert_eq!(CollatorSelection::invulnerables(), vec![1, 2]); + assert_eq!(CandidateList::::get().iter().count(), 0); + assert_eq!(Invulnerables::::get(), vec![1, 2]); // take three endowed, non-invulnerables accounts. assert_eq!(Balances::free_balance(3), 100); @@ -1087,7 +1086,7 @@ fn update_candidacy_bond_with_identical_amount() { assert_ok!(CollatorSelection::update_bond(RuntimeOrigin::signed(4), 30)); assert_ok!(CollatorSelection::update_bond(RuntimeOrigin::signed(5), 40)); - assert_eq!(>::get().iter().count(), 3); + assert_eq!(CandidateList::::get().iter().count(), 3); assert_eq!(Balances::free_balance(3), 80); assert_eq!(Balances::free_balance(4), 70); assert_eq!(Balances::free_balance(5), 60); @@ -1104,11 +1103,11 @@ fn update_candidacy_bond_with_identical_amount() { fn candidate_list_works() { new_test_ext().execute_with(|| { // given - assert_eq!(CollatorSelection::desired_candidates(), 2); - assert_eq!(CollatorSelection::candidacy_bond(), 10); + assert_eq!(DesiredCandidates::::get(), 2); + assert_eq!(CandidacyBond::::get(), 10); - assert_eq!(>::get().iter().count(), 0); - assert_eq!(CollatorSelection::invulnerables(), vec![1, 2]); + assert_eq!(CandidateList::::get().iter().count(), 0); + assert_eq!(Invulnerables::::get(), vec![1, 2]); // take three endowed, non-invulnerables accounts. assert_eq!(Balances::free_balance(3), 100); @@ -1131,7 +1130,7 @@ fn candidate_list_works() { let candidate_4 = CandidateInfo { who: 4, deposit: 25 }; let candidate_5 = CandidateInfo { who: 5, deposit: 10 }; assert_eq!( - >::get().iter().cloned().collect::>(), + CandidateList::::get().iter().cloned().collect::>(), vec![candidate_5, candidate_4, candidate_3] ); }); @@ -1157,7 +1156,7 @@ fn leave_intent() { // bond is returned assert_ok!(CollatorSelection::leave_intent(RuntimeOrigin::signed(3))); assert_eq!(Balances::free_balance(3), 100); - assert_eq!(CollatorSelection::last_authored_block(3), 0); + assert_eq!(LastAuthoredBlock::::get(3), 0); }); } @@ -1177,10 +1176,10 @@ fn authorship_event_handler() { let collator = CandidateInfo { who: 4, deposit: 10 }; assert_eq!( - >::get().iter().cloned().collect::>(), + CandidateList::::get().iter().cloned().collect::>(), vec![collator] ); - assert_eq!(CollatorSelection::last_authored_block(4), 0); + assert_eq!(LastAuthoredBlock::::get(4), 0); // half of the pot goes to the collator who's the author (4 in tests). assert_eq!(Balances::free_balance(4), 140); @@ -1206,10 +1205,10 @@ fn fees_edgecases() { let collator = CandidateInfo { who: 4, deposit: 10 }; assert_eq!( - >::get().iter().cloned().collect::>(), + CandidateList::::get().iter().cloned().collect::>(), vec![collator] ); - assert_eq!(CollatorSelection::last_authored_block(4), 0); + assert_eq!(LastAuthoredBlock::::get(4), 0); // Nothing received assert_eq!(Balances::free_balance(4), 90); // all fee stays @@ -1236,7 +1235,7 @@ fn session_management_single_candidate() { // session won't see this. assert_eq!(SessionHandlerCollators::get(), vec![1, 2]); // but we have a new candidate. - assert_eq!(>::get().iter().count(), 1); + assert_eq!(CandidateList::::get().iter().count(), 1); initialize_to_block(10); assert_eq!(SessionChangeBlock::get(), 10); @@ -1274,7 +1273,7 @@ fn session_management_max_candidates() { // session won't see this. assert_eq!(SessionHandlerCollators::get(), vec![1, 2]); // but we have a new candidate. - assert_eq!(>::get().iter().count(), 3); + assert_eq!(CandidateList::::get().iter().count(), 3); initialize_to_block(10); assert_eq!(SessionChangeBlock::get(), 10); @@ -1313,7 +1312,7 @@ fn session_management_increase_bid_with_list_update() { // session won't see this. assert_eq!(SessionHandlerCollators::get(), vec![1, 2]); // but we have a new candidate. - assert_eq!(>::get().iter().count(), 3); + assert_eq!(CandidateList::::get().iter().count(), 3); initialize_to_block(10); assert_eq!(SessionChangeBlock::get(), 10); @@ -1352,7 +1351,7 @@ fn session_management_candidate_list_eager_sort() { // session won't see this. assert_eq!(SessionHandlerCollators::get(), vec![1, 2]); // but we have a new candidate. - assert_eq!(>::get().iter().count(), 3); + assert_eq!(CandidateList::::get().iter().count(), 3); initialize_to_block(10); assert_eq!(SessionChangeBlock::get(), 10); @@ -1399,7 +1398,7 @@ fn session_management_reciprocal_outbidding() { // session won't see this. assert_eq!(SessionHandlerCollators::get(), vec![1, 2]); // but we have a new candidate. - assert_eq!(>::get().iter().count(), 3); + assert_eq!(CandidateList::::get().iter().count(), 3); initialize_to_block(10); assert_eq!(SessionChangeBlock::get(), 10); @@ -1451,7 +1450,7 @@ fn session_management_decrease_bid_after_auction() { // session won't see this. assert_eq!(SessionHandlerCollators::get(), vec![1, 2]); // but we have a new candidate. - assert_eq!(>::get().iter().count(), 3); + assert_eq!(CandidateList::::get().iter().count(), 3); initialize_to_block(10); assert_eq!(SessionChangeBlock::get(), 10); @@ -1476,20 +1475,20 @@ fn kick_mechanism() { assert_ok!(CollatorSelection::register_as_candidate(RuntimeOrigin::signed(3))); assert_ok!(CollatorSelection::register_as_candidate(RuntimeOrigin::signed(4))); initialize_to_block(10); - assert_eq!(>::get().iter().count(), 2); + assert_eq!(CandidateList::::get().iter().count(), 2); initialize_to_block(20); assert_eq!(SessionChangeBlock::get(), 20); // 4 authored this block, gets to stay 3 was kicked - assert_eq!(>::get().iter().count(), 1); + assert_eq!(CandidateList::::get().iter().count(), 1); // 3 will be kicked after 1 session delay assert_eq!(SessionHandlerCollators::get(), vec![1, 2, 3, 4]); // tuple of (id, deposit). let collator = CandidateInfo { who: 4, deposit: 10 }; assert_eq!( - >::get().iter().cloned().collect::>(), + CandidateList::::get().iter().cloned().collect::>(), vec![collator] ); - assert_eq!(CollatorSelection::last_authored_block(4), 20); + assert_eq!(LastAuthoredBlock::::get(4), 20); initialize_to_block(30); // 3 gets kicked after 1 session delay assert_eq!(SessionHandlerCollators::get(), vec![1, 2, 4]); @@ -1503,8 +1502,8 @@ fn should_not_kick_mechanism_too_few() { new_test_ext().execute_with(|| { // remove the invulnerables and add new collators 3 and 5 - assert_eq!(>::get().iter().count(), 0); - assert_eq!(CollatorSelection::invulnerables(), vec![1, 2]); + assert_eq!(CandidateList::::get().iter().count(), 0); + assert_eq!(Invulnerables::::get(), vec![1, 2]); assert_ok!(CollatorSelection::remove_invulnerable( RuntimeOrigin::signed(RootAccount::get()), 1 @@ -1517,21 +1516,21 @@ fn should_not_kick_mechanism_too_few() { )); initialize_to_block(10); - assert_eq!(>::get().iter().count(), 2); + assert_eq!(CandidateList::::get().iter().count(), 2); initialize_to_block(20); assert_eq!(SessionChangeBlock::get(), 20); // 4 authored this block, 3 is kicked, 5 stays because of too few collators - assert_eq!(>::get().iter().count(), 1); + assert_eq!(CandidateList::::get().iter().count(), 1); // 3 will be kicked after 1 session delay assert_eq!(SessionHandlerCollators::get(), vec![3, 5]); // tuple of (id, deposit). let collator = CandidateInfo { who: 3, deposit: 10 }; assert_eq!( - >::get().iter().cloned().collect::>(), + CandidateList::::get().iter().cloned().collect::>(), vec![collator] ); - assert_eq!(CollatorSelection::last_authored_block(4), 20); + assert_eq!(LastAuthoredBlock::::get(4), 20); initialize_to_block(30); // 3 gets kicked after 1 session delay @@ -1544,7 +1543,7 @@ fn should_not_kick_mechanism_too_few() { #[test] fn should_kick_invulnerables_from_candidates_on_session_change() { new_test_ext().execute_with(|| { - assert_eq!(>::get().iter().count(), 0); + assert_eq!(CandidateList::::get().iter().count(), 0); assert_ok!(CollatorSelection::register_as_candidate(RuntimeOrigin::signed(3))); assert_ok!(CollatorSelection::register_as_candidate(RuntimeOrigin::signed(4))); assert_eq!(Balances::free_balance(3), 90); @@ -1558,20 +1557,19 @@ fn should_kick_invulnerables_from_candidates_on_session_change() { let collator_3 = CandidateInfo { who: 3, deposit: 10 }; let collator_4 = CandidateInfo { who: 4, deposit: 10 }; - let actual_candidates = - >::get().iter().cloned().collect::>(); + let actual_candidates = CandidateList::::get().iter().cloned().collect::>(); assert_eq!(actual_candidates, vec![collator_4.clone(), collator_3]); - assert_eq!(CollatorSelection::invulnerables(), vec![1, 2, 3]); + assert_eq!(Invulnerables::::get(), vec![1, 2, 3]); // session change initialize_to_block(10); // 3 is removed from candidates assert_eq!( - >::get().iter().cloned().collect::>(), + CandidateList::::get().iter().cloned().collect::>(), vec![collator_4] ); // but not from invulnerables - assert_eq!(CollatorSelection::invulnerables(), vec![1, 2, 3]); + assert_eq!(Invulnerables::::get(), vec![1, 2, 3]); // and it got its deposit back assert_eq!(Balances::free_balance(3), 100); }); diff --git a/cumulus/pallets/parachain-system/src/lib.rs b/cumulus/pallets/parachain-system/src/lib.rs index 81965a2a3138..1c01ef33c7e7 100644 --- a/cumulus/pallets/parachain-system/src/lib.rs +++ b/cumulus/pallets/parachain-system/src/lib.rs @@ -267,7 +267,7 @@ pub mod pallet { LastRelayChainBlockNumber::::put(vfp.relay_parent_number); - let host_config = match Self::host_configuration() { + let host_config = match HostConfiguration::::get() { Some(ok) => ok, None => { debug_assert!( @@ -281,7 +281,7 @@ pub mod pallet { // Before updating the relevant messaging state, we need to extract // the total bandwidth limits for the purpose of updating the unincluded // segment. - let total_bandwidth_out = match Self::relevant_messaging_state() { + let total_bandwidth_out = match RelevantMessagingState::::get() { Some(s) => OutboundBandwidthLimits::from_relay_chain_state(&s), None => { debug_assert!( @@ -298,7 +298,8 @@ pub mod pallet { Self::adjust_egress_bandwidth_limits(); let (ump_msg_count, ump_total_bytes) = >::mutate(|up| { - let (available_capacity, available_size) = match Self::relevant_messaging_state() { + let (available_capacity, available_size) = match RelevantMessagingState::::get() + { Some(limits) => ( limits.relay_dispatch_queue_remaining_capacity.remaining_count, limits.relay_dispatch_queue_remaining_capacity.remaining_size, @@ -476,7 +477,7 @@ pub mod pallet { // than the announced, we would waste some of weight. In the case the actual value is // greater than the announced, we will miss opportunity to send a couple of messages. weight += T::DbWeight::get().reads_writes(1, 1); - let hrmp_max_message_num_per_candidate = Self::host_configuration() + let hrmp_max_message_num_per_candidate = HostConfiguration::::get() .map(|cfg| cfg.hrmp_max_message_num_per_candidate) .unwrap_or(0); >::put(hrmp_max_message_num_per_candidate); @@ -764,7 +765,6 @@ pub mod pallet { /// [`:code`][sp_core::storage::well_known_keys::CODE] which will result the next block process /// with the new validation code. This concludes the upgrade process. #[pallet::storage] - #[pallet::getter(fn new_validation_function)] pub(super) type PendingValidationCode = StorageValue<_, Vec, ValueQuery>; /// Validation code that is set by the parachain and is to be communicated to collator and @@ -779,7 +779,6 @@ pub mod pallet { /// This value is expected to be set only once per block and it's never stored /// in the trie. #[pallet::storage] - #[pallet::getter(fn validation_data)] pub(super) type ValidationData = StorageValue<_, PersistedValidationData>; /// Were the validation data set to notify the relay chain? @@ -820,7 +819,6 @@ pub mod pallet { /// /// This data is also absent from the genesis. #[pallet::storage] - #[pallet::getter(fn relay_state_proof)] pub(super) type RelayStateProof = StorageValue<_, sp_trie::StorageProof>; /// The snapshot of some state related to messaging relevant to the current parachain as per @@ -831,7 +829,6 @@ pub mod pallet { /// /// This data is also absent from the genesis. #[pallet::storage] - #[pallet::getter(fn relevant_messaging_state)] pub(super) type RelevantMessagingState = StorageValue<_, MessagingStateSnapshot>; /// The parachain host configuration that was obtained from the relay parent. @@ -842,7 +839,6 @@ pub mod pallet { /// This data is also absent from the genesis. #[pallet::storage] #[pallet::disable_try_decode_storage] - #[pallet::getter(fn host_configuration)] pub(super) type HostConfiguration = StorageValue<_, AbridgedHostConfiguration>; /// The last downward message queue chain head we have observed. @@ -1041,7 +1037,7 @@ impl GetChannelInfo for Pallet { // // Here it a similar case, with the difference that the realization that the channel is // closed came the same block. - let channels = match Self::relevant_messaging_state() { + let channels = match RelevantMessagingState::::get() { None => { log::warn!("calling `get_channel_status` with no RelevantMessagingState?!"); return ChannelStatus::Closed @@ -1069,7 +1065,7 @@ impl GetChannelInfo for Pallet { } fn get_channel_info(id: ParaId) -> Option { - let channels = Self::relevant_messaging_state()?.egress_channels; + let channels = RelevantMessagingState::::get()?.egress_channels; let index = channels.binary_search_by_key(&id, |item| item.0).ok()?; let info = ChannelInfo { max_capacity: channels[index].1.max_capacity, @@ -1406,7 +1402,7 @@ impl Pallet { ensure!(>::get().is_none(), Error::::ProhibitedByPolkadot); ensure!(!>::exists(), Error::::OverlappingUpgrades); - let cfg = Self::host_configuration().ok_or(Error::::HostConfigurationNotAvailable)?; + let cfg = HostConfiguration::::get().ok_or(Error::::HostConfigurationNotAvailable)?; ensure!(validation_function.len() <= cfg.max_code_size as usize, Error::::TooBig); // When a code upgrade is scheduled, it has to be applied in two @@ -1562,7 +1558,7 @@ impl Pallet { // may change so that the message is no longer valid. // // However, changing this setting is expected to be rare. - if let Some(cfg) = Self::host_configuration() { + if let Some(cfg) = HostConfiguration::::get() { if message_len > cfg.max_upward_message_size as usize { return Err(MessageSendError::TooBig) } @@ -1718,14 +1714,14 @@ impl BlockNumberProvider for RelaychainDataProvider { type BlockNumber = relay_chain::BlockNumber; fn current_block_number() -> relay_chain::BlockNumber { - Pallet::::validation_data() + ValidationData::::get() .map(|d| d.relay_parent_number) .unwrap_or_else(|| Pallet::::last_relay_block_number()) } #[cfg(feature = "runtime-benchmarks")] fn set_block_number(block: Self::BlockNumber) { - let mut validation_data = Pallet::::validation_data().unwrap_or_else(|| + let mut validation_data = ValidationData::::get().unwrap_or_else(|| // PersistedValidationData does not impl default in non-std PersistedValidationData { parent_head: vec![].into(), @@ -1740,7 +1736,7 @@ impl BlockNumberProvider for RelaychainDataProvider { impl RelaychainStateProvider for RelaychainDataProvider { fn current_relay_chain_state() -> RelayChainState { - Pallet::::validation_data() + ValidationData::::get() .map(|d| RelayChainState { number: d.relay_parent_number, state_root: d.relay_parent_storage_root, @@ -1750,7 +1746,7 @@ impl RelaychainStateProvider for RelaychainDataProvider { #[cfg(feature = "runtime-benchmarks")] fn set_current_relay_chain_state(state: RelayChainState) { - let mut validation_data = Pallet::::validation_data().unwrap_or_else(|| + let mut validation_data = ValidationData::::get().unwrap_or_else(|| // PersistedValidationData does not impl default in non-std PersistedValidationData { parent_head: vec![].into(), diff --git a/cumulus/parachains/pallets/parachain-info/src/lib.rs b/cumulus/parachains/pallets/parachain-info/src/lib.rs index c17a6d5e1460..a4ef448a6b6b 100644 --- a/cumulus/parachains/pallets/parachain-info/src/lib.rs +++ b/cumulus/parachains/pallets/parachain-info/src/lib.rs @@ -54,7 +54,7 @@ pub mod pallet { #[pallet::genesis_build] impl BuildGenesisConfig for GenesisConfig { fn build(&self) { - >::put(self.parachain_id); + ParachainId::::put(self.parachain_id); } } @@ -64,13 +64,18 @@ pub mod pallet { } #[pallet::storage] - #[pallet::getter(fn parachain_id)] pub(super) type ParachainId = StorageValue<_, ParaId, ValueQuery, DefaultForParachainId>; impl Get for Pallet { fn get() -> ParaId { - Self::parachain_id() + ParachainId::::get() + } + } + + impl Pallet { + pub fn parachain_id() -> ParaId { + ParachainId::::get() } } } diff --git a/prdoc/pr_3471.prdoc b/prdoc/pr_3471.prdoc new file mode 100644 index 000000000000..0c16587fc908 --- /dev/null +++ b/prdoc/pr_3471.prdoc @@ -0,0 +1,33 @@ +# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0 +# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json + +title: removed `pallet::getter` from cumulus pallets + +doc: + - audience: Runtime Dev + description: | + This PR removes all the `pallet::getter` usages from cumulus pallets, and updates depdendant runtimes accordingly. + The ParaId can be retrieved using `>::get()`. + For other storage items, the syntax `StorageItem::::get()` should be used instead. + +crates: + - name: cumulus-pallet-aura-ext + - name: pallet-collator-selection + - name: cumulus-pallet-parachain-system + - name: staging-parachain-info + - name: parachain-template-runtime + - name: asset-hub-rococo-runtime + - name: asset-hub-westend-runtime + - name: bridge-hub-rococo-runtime + - name: bridge-hub-westend-runtime + - name: collectives-westend-runtime + - name: contracts-rococo-runtime + - name: coretime-rococo-runtime + - name: coretime-westend-runtime + - name: glutton-westend-runtime + - name: people-rococo-runtime + - name: people-westend-runtime + - name: shell-runtime + - name: penpal-runtime + - name: rococo-parachain-runtime + From e2ead8887681d2236cae4a0f05b05e4cb5bf63a7 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 19 Mar 2024 04:34:17 +0100 Subject: [PATCH 2/4] Bump the known_good_semver group with 2 updates (#3726) Bumps the known_good_semver group with 2 updates: [serde_yaml](https://github.com/dtolnay/serde-yaml) and [syn](https://github.com/dtolnay/syn). Updates `serde_yaml` from 0.9.32 to 0.9.33
Release notes

Sourced from serde_yaml's releases.

0.9.33

Commits
  • f4c9ed9 Release 0.9.33
  • b4edaee Pull in yaml_parser_fetch_more_tokens fix from libyaml
  • 8a5542c Resolve non_local_definitions warning in test
  • See full diff in compare view

Updates `syn` from 2.0.52 to 2.0.53
Release notes

Sourced from syn's releases.

2.0.53

  • Implement Copy, Clone, and ToTokens for syn::parse::Nothing (#1597)
Commits
  • 32dcf8d Release 2.0.53
  • fd1f2aa Merge pull request #1597 from dtolnay/copyprintnothing
  • 4f6c052 Implement ToTokens for syn::parse::Nothing
  • 3f37543 Implement Copy for syn::parse::Nothing
  • 36a4122 Update test suite to nightly-2024-03-16
  • bd93106 Revert "Temporarily disable nightly testing due to libLLVM link issue"
  • 06166a7 Update test suite to nightly-2024-03-09
  • ed545e7 Work around doc_markdown lint in test_precedence
  • 7aef1ed Temporarily disable nightly testing due to libLLVM link issue
  • 556b10b Update test suite to nightly-2024-03-06
  • Additional commits viewable in compare view

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) ---
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore major version` will close this group update PR and stop Dependabot creating any more for the specific dependency's major version (unless you unignore this specific dependency's major version or upgrade to it yourself) - `@dependabot ignore minor version` will close this group update PR and stop Dependabot creating any more for the specific dependency's minor version (unless you unignore this specific dependency's minor version or upgrade to it yourself) - `@dependabot ignore ` will close this group update PR and stop Dependabot creating any more for the specific dependency (unless you unignore this specific dependency or upgrade to it yourself) - `@dependabot unignore ` will remove all of the ignore conditions of the specified dependency - `@dependabot unignore ` will remove the ignore condition of the specified dependency and ignore conditions
Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- Cargo.lock | 132 ++++++++++++++++++++++++++--------------------------- Cargo.toml | 2 +- 2 files changed, 67 insertions(+), 67 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d641f5544318..5c0066e97283 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -191,7 +191,7 @@ checksum = "c0391754c09fab4eae3404d19d0d297aa1c670c1775ab51d8a5312afeca23157" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -206,7 +206,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", "syn-solidity", "tiny-keccak", ] @@ -347,7 +347,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -1228,7 +1228,7 @@ checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -1245,7 +1245,7 @@ checksum = "a66537f1bb974b254c98ed142ff995236e81b9d0fe4db0575f46612cb15eb0f9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -1427,7 +1427,7 @@ dependencies = [ "regex", "rustc-hash", "shlex", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -2674,7 +2674,7 @@ dependencies = [ "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -3895,7 +3895,7 @@ dependencies = [ "proc-macro-crate 3.0.0", "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -4410,7 +4410,7 @@ checksum = "83fdaf97f4804dcebfa5862639bc9ce4121e82140bec2a987ac5140294865b5b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -4450,7 +4450,7 @@ dependencies = [ "proc-macro2", "quote", "scratch", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -4467,7 +4467,7 @@ checksum = "50c49547d73ba8dcfd4ad7325d64c6d5391ff4224d498fc39a6f3f49825a530d" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -4675,7 +4675,7 @@ checksum = "487585f4d0c6655fe74905e2504d8ad6908e4db67f744eb140876906c2f3175d" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -4745,7 +4745,7 @@ dependencies = [ "proc-macro2", "quote", "regex", - "syn 2.0.52", + "syn 2.0.53", "termcolor", "walkdir", ] @@ -4762,7 +4762,7 @@ dependencies = [ "proc-macro2", "quote", "regex", - "syn 2.0.52", + "syn 2.0.53", "termcolor", "toml 0.8.8", "walkdir", @@ -4990,7 +4990,7 @@ checksum = "5e9a1f9f7d83e59740248a6e14ecf93929ade55027844dfcea78beafccc15745" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -5001,7 +5001,7 @@ checksum = "c2ad8cef1d801a4686bfd8919f0b30eac4c8e48968c437a6405ded4fb5272d2b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -5191,7 +5191,7 @@ dependencies = [ "fs-err", "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -5578,7 +5578,7 @@ dependencies = [ "quote", "scale-info", "sp-arithmetic", - "syn 2.0.52", + "syn 2.0.53", "trybuild", ] @@ -5735,7 +5735,7 @@ dependencies = [ "quote", "regex", "sp-crypto-hashing", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -5746,7 +5746,7 @@ dependencies = [ "proc-macro-crate 3.0.0", "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -5755,7 +5755,7 @@ version = "11.0.0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -5988,7 +5988,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -7933,7 +7933,7 @@ dependencies = [ "macro_magic_core", "macro_magic_macros", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -7947,7 +7947,7 @@ dependencies = [ "macro_magic_core_macros", "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -7958,7 +7958,7 @@ checksum = "9ea73aa640dc01d62a590d48c0c3521ed739d53b27f919b25c3551e233481654" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -7969,7 +7969,7 @@ checksum = "ef9d79ae96aaba821963320eb2b6e34d17df1e5a83d8a1985c29cc5be59577b3" dependencies = [ "macro_magic_core", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -9630,7 +9630,7 @@ version = "18.0.0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -10858,7 +10858,7 @@ dependencies = [ "proc-macro2", "quote", "sp-runtime", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -11953,7 +11953,7 @@ dependencies = [ "pest_meta", "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -11994,7 +11994,7 @@ checksum = "4359fd9c9171ec6e8c62926d6faaf553a8dc3f64e1507e76da7911b4f6a04405" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -13891,7 +13891,7 @@ dependencies = [ "polkavm-common", "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -13901,7 +13901,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ba81f7b5faac81e528eb6158a6f3c9e0bb1008e0ffa19653bc8dea925ecb429" dependencies = [ "polkavm-derive-impl", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -14097,7 +14097,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c64d9ba0963cdcea2e1b2230fbae2bab30eb25a174be395c41e764bfb65dd62" dependencies = [ "proc-macro2", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -14188,7 +14188,7 @@ checksum = "9b698b0b09d40e9b7c1a47b132d66a8b54bcd20583d9b6d06e4535e383b4405c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -14260,7 +14260,7 @@ checksum = "440f724eba9f6996b75d63681b0a92b06947f1457076d503a4d2e2c8f56442b8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -14360,7 +14360,7 @@ dependencies = [ "itertools 0.11.0", "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -14703,7 +14703,7 @@ checksum = "7f7473c2cfcf90008193dd0e3e16599455cb601a9fce322b5bb55de799664925" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -15194,7 +15194,7 @@ dependencies = [ "regex", "relative-path", "rustc_version 0.4.0", - "syn 2.0.52", + "syn 2.0.53", "unicode-ident", ] @@ -15648,7 +15648,7 @@ dependencies = [ "proc-macro-crate 3.0.0", "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -16930,7 +16930,7 @@ dependencies = [ "proc-macro-crate 3.0.0", "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -17332,7 +17332,7 @@ checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -17389,9 +17389,9 @@ dependencies = [ [[package]] name = "serde_yaml" -version = "0.9.32" +version = "0.9.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fd075d994154d4a774f95b51fb96bdc2832b0ea48425c92546073816cda1f2f" +checksum = "a0623d197252096520c6f2a5e1171ee436e5af99a5d7caa2891e55e61950e6d9" dependencies = [ "indexmap 2.2.3", "itoa", @@ -17432,7 +17432,7 @@ checksum = "91d129178576168c589c9ec973feedf7d3126c01ac2bf08795109aa35b69fb8f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -18340,7 +18340,7 @@ dependencies = [ "proc-macro-crate 3.0.0", "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -18723,7 +18723,7 @@ version = "0.0.0" dependencies = [ "quote", "sp-crypto-hashing", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -18741,7 +18741,7 @@ source = "git+https://github.com/paritytech/polkadot-sdk#82912acb33a9030c0ef3bf5 dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -18750,7 +18750,7 @@ version = "14.0.0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -19018,7 +19018,7 @@ dependencies = [ "proc-macro-crate 1.3.1", "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -19030,7 +19030,7 @@ dependencies = [ "proc-macro-crate 3.0.0", "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -19292,7 +19292,7 @@ dependencies = [ "proc-macro2", "quote", "sp-version", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -19735,7 +19735,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -20132,9 +20132,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.52" +version = "2.0.53" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b699d15b36d1f02c3e7c69f8ffef53de37aefae075d8488d4ba1a7788d574a07" +checksum = "7383cd0e49fff4b6b90ca5670bfd3e9d6a733b3f90c686605aa7eec8c4996032" dependencies = [ "proc-macro2", "quote", @@ -20150,7 +20150,7 @@ dependencies = [ "paste", "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -20415,7 +20415,7 @@ checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -20576,7 +20576,7 @@ checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -20783,7 +20783,7 @@ checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -20825,7 +20825,7 @@ dependencies = [ "proc-macro-crate 3.0.0", "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -21180,9 +21180,9 @@ dependencies = [ [[package]] name = "unsafe-libyaml" -version = "0.2.10" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab4c90930b95a82d00dc9e9ac071b4991924390d46cbd0dfe566148667605e4b" +checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861" [[package]] name = "unsigned-varint" @@ -21390,7 +21390,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", "wasm-bindgen-shared", ] @@ -21424,7 +21424,7 @@ checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -22441,7 +22441,7 @@ dependencies = [ "proc-macro2", "quote", "staging-xcm", - "syn 2.0.52", + "syn 2.0.53", "trybuild", ] @@ -22563,7 +22563,7 @@ checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -22583,7 +22583,7 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 3acb6c1d0555..01d6ef8e87bd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -554,7 +554,7 @@ serde-big-array = { version = "0.3.2" } serde_derive = { version = "1.0.117" } serde_json = { version = "1.0.114", default-features = false } serde_yaml = { version = "0.9" } -syn = { version = "2.0.52" } +syn = { version = "2.0.53" } thiserror = { version = "1.0.48" } [profile.release] From 8b3bf39ab85ff7146e06e7c8236475bfa4e3bf39 Mon Sep 17 00:00:00 2001 From: Juan Ignacio Rios <54085674+JuaniRios@users.noreply.github.com> Date: Tue, 19 Mar 2024 09:12:39 +0100 Subject: [PATCH 3/4] Add HRMP notification handlers to the xcm-executor (#3696) Currently the xcm-executor returns an `Unimplemented` error if it receives any HRMP-related instruction. What I propose here, which is what we are currently doing in our forked executor at polimec, is to introduce a trait implemented by the executor which will handle those instructions. This way, if parachains want to keep the default behavior, they just use `()` and it will return unimplemented, but they can also implement their own logic to establish HRMP channels with other chains in an automated fashion, without requiring to go through governance. Our implementation is mentioned in the [polkadot HRMP docs](https://arc.net/l/quote/hduiivbu), and it was suggested to us to submit a PR to add these changes to polkadot-sdk. --------- Co-authored-by: Branislav Kontur Co-authored-by: command-bot <> --- cumulus/pallets/xcmp-queue/src/mock.rs | 3 + .../assets/asset-hub-rococo/src/xcm_config.rs | 3 + .../asset-hub-westend/src/xcm_config.rs | 3 + .../bridge-hub-rococo/src/xcm_config.rs | 3 + .../bridge-hub-westend/src/xcm_config.rs | 3 + .../collectives-westend/src/xcm_config.rs | 3 + .../contracts-rococo/src/xcm_config.rs | 3 + .../coretime-rococo/src/xcm_config.rs | 3 + .../coretime-westend/src/xcm_config.rs | 3 + .../glutton/glutton-westend/src/xcm_config.rs | 3 + .../people/people-rococo/src/xcm_config.rs | 3 + .../people/people-westend/src/xcm_config.rs | 3 + .../runtimes/starters/shell/src/xcm_config.rs | 3 + .../runtimes/testing/penpal/src/xcm_config.rs | 3 + .../testing/rococo-parachain/src/lib.rs | 3 + polkadot/runtime/rococo/src/xcm_config.rs | 3 + .../runtime/test-runtime/src/xcm_config.rs | 3 + polkadot/runtime/westend/src/xcm_config.rs | 3 + .../src/fungible/mock.rs | 3 + .../pallet-xcm-benchmarks/src/generic/mock.rs | 3 + polkadot/xcm/pallet-xcm/src/mock.rs | 3 + polkadot/xcm/xcm-builder/src/tests/mock.rs | 3 + .../xcm/xcm-builder/src/tests/pay/mock.rs | 3 + polkadot/xcm/xcm-builder/tests/mock/mod.rs | 3 + polkadot/xcm/xcm-executor/src/config.rs | 10 +++- polkadot/xcm/xcm-executor/src/lib.rs | 21 +++++-- polkadot/xcm/xcm-executor/src/traits/hrmp.rs | 56 +++++++++++++++++++ polkadot/xcm/xcm-executor/src/traits/mod.rs | 4 ++ .../xcm-simulator/example/src/parachain.rs | 3 + .../xcm-simulator/example/src/relay_chain.rs | 3 + .../xcm/xcm-simulator/fuzzer/src/parachain.rs | 3 + .../xcm-simulator/fuzzer/src/relay_chain.rs | 3 + prdoc/pr_3696.prdoc | 17 ++++++ .../contracts/mock-network/src/parachain.rs | 3 + .../contracts/mock-network/src/relay_chain.rs | 3 + templates/parachain/runtime/src/xcm_config.rs | 3 + 36 files changed, 196 insertions(+), 5 deletions(-) create mode 100644 polkadot/xcm/xcm-executor/src/traits/hrmp.rs create mode 100644 prdoc/pr_3696.prdoc diff --git a/cumulus/pallets/xcmp-queue/src/mock.rs b/cumulus/pallets/xcmp-queue/src/mock.rs index 294f978f6ad5..9d9a723cf8b5 100644 --- a/cumulus/pallets/xcmp-queue/src/mock.rs +++ b/cumulus/pallets/xcmp-queue/src/mock.rs @@ -175,6 +175,9 @@ impl xcm_executor::Config for XcmConfig { type SafeCallFilter = Everything; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); } pub type XcmRouter = ( diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs index 2584dbdf3106..c438361cc177 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs @@ -628,6 +628,9 @@ impl xcm_executor::Config for XcmConfig { type SafeCallFilter = SafeCallFilter; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); } /// Converts a local signed origin into an XCM location. diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs index 50865c000611..c993d61545a6 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs @@ -649,6 +649,9 @@ impl xcm_executor::Config for XcmConfig { type SafeCallFilter = SafeCallFilter; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); } /// Local origins on this chain are allowed to dispatch XCM sends/executions. diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs index 55c78477b568..8934ff9b2272 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs @@ -336,6 +336,9 @@ impl xcm_executor::Config for XcmConfig { type SafeCallFilter = SafeCallFilter; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); } pub type PriceForParentDelivery = diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/xcm_config.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/xcm_config.rs index e18df6feda82..840d0c9af0e5 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/xcm_config.rs @@ -264,6 +264,9 @@ impl xcm_executor::Config for XcmConfig { type SafeCallFilter = SafeCallFilter; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); } pub type PriceForParentDelivery = diff --git a/cumulus/parachains/runtimes/collectives/collectives-westend/src/xcm_config.rs b/cumulus/parachains/runtimes/collectives/collectives-westend/src/xcm_config.rs index 87f637d5b59a..b83106a58284 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-westend/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-westend/src/xcm_config.rs @@ -288,6 +288,9 @@ impl xcm_executor::Config for XcmConfig { type SafeCallFilter = SafeCallFilter; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); } /// Converts a local signed origin into an XCM location. diff --git a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/xcm_config.rs b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/xcm_config.rs index e8f3209eb67f..ac6fe634662f 100644 --- a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/xcm_config.rs @@ -197,6 +197,9 @@ impl xcm_executor::Config for XcmConfig { type SafeCallFilter = Everything; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); } /// Converts a local signed origin into an XCM location. diff --git a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/xcm_config.rs b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/xcm_config.rs index 1722e1fcb319..955f2eeba339 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/xcm_config.rs @@ -257,6 +257,9 @@ impl xcm_executor::Config for XcmConfig { type SafeCallFilter = SafeCallFilter; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); } /// Converts a local signed origin into an XCM location. Forms the basis for local origins diff --git a/cumulus/parachains/runtimes/coretime/coretime-westend/src/xcm_config.rs b/cumulus/parachains/runtimes/coretime/coretime-westend/src/xcm_config.rs index b03c7748fe09..fc7d36a8ba18 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-westend/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-westend/src/xcm_config.rs @@ -269,6 +269,9 @@ impl xcm_executor::Config for XcmConfig { type SafeCallFilter = SafeCallFilter; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); } /// Converts a local signed origin into an XCM location. Forms the basis for local origins diff --git a/cumulus/parachains/runtimes/glutton/glutton-westend/src/xcm_config.rs b/cumulus/parachains/runtimes/glutton/glutton-westend/src/xcm_config.rs index ad61987c0e70..15bb519e115c 100644 --- a/cumulus/parachains/runtimes/glutton/glutton-westend/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/glutton/glutton-westend/src/xcm_config.rs @@ -88,6 +88,9 @@ impl xcm_executor::Config for XcmConfig { type SafeCallFilter = Everything; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); } impl cumulus_pallet_xcm::Config for Runtime { diff --git a/cumulus/parachains/runtimes/people/people-rococo/src/xcm_config.rs b/cumulus/parachains/runtimes/people/people-rococo/src/xcm_config.rs index 534d65190862..a10333fdb626 100644 --- a/cumulus/parachains/runtimes/people/people-rococo/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/people/people-rococo/src/xcm_config.rs @@ -269,6 +269,9 @@ impl xcm_executor::Config for XcmConfig { type SafeCallFilter = SafeCallFilter; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); } /// Converts a local signed origin into an XCM location. Forms the basis for local origins diff --git a/cumulus/parachains/runtimes/people/people-westend/src/xcm_config.rs b/cumulus/parachains/runtimes/people/people-westend/src/xcm_config.rs index 6353a5813525..fee2f5684ac3 100644 --- a/cumulus/parachains/runtimes/people/people-westend/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/people/people-westend/src/xcm_config.rs @@ -277,6 +277,9 @@ impl xcm_executor::Config for XcmConfig { type SafeCallFilter = SafeCallFilter; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); } /// Converts a local signed origin into an XCM location. Forms the basis for local origins diff --git a/cumulus/parachains/runtimes/starters/shell/src/xcm_config.rs b/cumulus/parachains/runtimes/starters/shell/src/xcm_config.rs index f6af50f76d85..df89158729cd 100644 --- a/cumulus/parachains/runtimes/starters/shell/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/starters/shell/src/xcm_config.rs @@ -88,6 +88,9 @@ impl xcm_executor::Config for XcmConfig { type SafeCallFilter = Everything; type Aliasers = Nothing; type TransactionalProcessor = (); + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); } impl cumulus_pallet_xcm::Config for Runtime { diff --git a/cumulus/parachains/runtimes/testing/penpal/src/xcm_config.rs b/cumulus/parachains/runtimes/testing/penpal/src/xcm_config.rs index bc1aa05a6177..d83a877c2f89 100644 --- a/cumulus/parachains/runtimes/testing/penpal/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/testing/penpal/src/xcm_config.rs @@ -338,6 +338,9 @@ impl xcm_executor::Config for XcmConfig { type SafeCallFilter = Everything; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); } /// Multiplier used for dedicated `TakeFirstAssetTrader` with `ForeignAssets` instance. diff --git a/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs b/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs index a066cab1b6dc..1b7efa6f400a 100644 --- a/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs +++ b/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs @@ -484,6 +484,9 @@ impl xcm_executor::Config for XcmConfig { type SafeCallFilter = Everything; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); } /// Local origins on this chain are allowed to dispatch XCM sends/executions. diff --git a/polkadot/runtime/rococo/src/xcm_config.rs b/polkadot/runtime/rococo/src/xcm_config.rs index 67f34916fe78..328879715de3 100644 --- a/polkadot/runtime/rococo/src/xcm_config.rs +++ b/polkadot/runtime/rococo/src/xcm_config.rs @@ -221,6 +221,9 @@ impl xcm_executor::Config for XcmConfig { type SafeCallFilter = Everything; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); } parameter_types! { diff --git a/polkadot/runtime/test-runtime/src/xcm_config.rs b/polkadot/runtime/test-runtime/src/xcm_config.rs index a48bca17e9ff..8411b79f2529 100644 --- a/polkadot/runtime/test-runtime/src/xcm_config.rs +++ b/polkadot/runtime/test-runtime/src/xcm_config.rs @@ -153,6 +153,9 @@ impl xcm_executor::Config for XcmConfig { type SafeCallFilter = Everything; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); } impl pallet_xcm::Config for crate::Runtime { diff --git a/polkadot/runtime/westend/src/xcm_config.rs b/polkadot/runtime/westend/src/xcm_config.rs index 7281007f0060..73127cb1efd6 100644 --- a/polkadot/runtime/westend/src/xcm_config.rs +++ b/polkadot/runtime/westend/src/xcm_config.rs @@ -219,6 +219,9 @@ impl xcm_executor::Config for XcmConfig { type SafeCallFilter = Everything; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); } parameter_types! { diff --git a/polkadot/xcm/pallet-xcm-benchmarks/src/fungible/mock.rs b/polkadot/xcm/pallet-xcm-benchmarks/src/fungible/mock.rs index c75ecbceb083..c831cd024659 100644 --- a/polkadot/xcm/pallet-xcm-benchmarks/src/fungible/mock.rs +++ b/polkadot/xcm/pallet-xcm-benchmarks/src/fungible/mock.rs @@ -145,6 +145,9 @@ impl xcm_executor::Config for XcmConfig { type SafeCallFilter = Everything; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); } impl crate::Config for Test { diff --git a/polkadot/xcm/pallet-xcm-benchmarks/src/generic/mock.rs b/polkadot/xcm/pallet-xcm-benchmarks/src/generic/mock.rs index b037d3dd8b23..534f7d85ea2e 100644 --- a/polkadot/xcm/pallet-xcm-benchmarks/src/generic/mock.rs +++ b/polkadot/xcm/pallet-xcm-benchmarks/src/generic/mock.rs @@ -135,6 +135,9 @@ impl xcm_executor::Config for XcmConfig { type SafeCallFilter = Everything; type Aliasers = Aliasers; type TransactionalProcessor = FrameTransactionalProcessor; + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); } parameter_types! { diff --git a/polkadot/xcm/pallet-xcm/src/mock.rs b/polkadot/xcm/pallet-xcm/src/mock.rs index 77b30b1eaa1d..b29562fc833b 100644 --- a/polkadot/xcm/pallet-xcm/src/mock.rs +++ b/polkadot/xcm/pallet-xcm/src/mock.rs @@ -513,6 +513,9 @@ impl xcm_executor::Config for XcmConfig { type SafeCallFilter = Everything; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); } pub type LocalOriginToLocation = SignedToAccountId32; diff --git a/polkadot/xcm/xcm-builder/src/tests/mock.rs b/polkadot/xcm/xcm-builder/src/tests/mock.rs index 4521d5e92a42..4bf347ea7713 100644 --- a/polkadot/xcm/xcm-builder/src/tests/mock.rs +++ b/polkadot/xcm/xcm-builder/src/tests/mock.rs @@ -743,6 +743,9 @@ impl Config for TestConfig { type SafeCallFilter = Everything; type Aliasers = AliasForeignAccountId32; type TransactionalProcessor = (); + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); } pub fn fungible_multi_asset(location: Location, amount: u128) -> Asset { diff --git a/polkadot/xcm/xcm-builder/src/tests/pay/mock.rs b/polkadot/xcm/xcm-builder/src/tests/pay/mock.rs index 9feda8fb90b2..019113a12b2f 100644 --- a/polkadot/xcm/xcm-builder/src/tests/pay/mock.rs +++ b/polkadot/xcm/xcm-builder/src/tests/pay/mock.rs @@ -218,6 +218,9 @@ impl xcm_executor::Config for XcmConfig { type SafeCallFilter = Everything; type Aliasers = Nothing; type TransactionalProcessor = (); + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); } parameter_types! { diff --git a/polkadot/xcm/xcm-builder/tests/mock/mod.rs b/polkadot/xcm/xcm-builder/tests/mock/mod.rs index 536f8851bb4f..f3cf5ab26490 100644 --- a/polkadot/xcm/xcm-builder/tests/mock/mod.rs +++ b/polkadot/xcm/xcm-builder/tests/mock/mod.rs @@ -204,6 +204,9 @@ impl xcm_executor::Config for XcmConfig { type SafeCallFilter = Everything; type Aliasers = Nothing; type TransactionalProcessor = (); + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); } pub type LocalOriginToLocation = SignedToAccountId32; diff --git a/polkadot/xcm/xcm-executor/src/config.rs b/polkadot/xcm/xcm-executor/src/config.rs index ebe532a42fd3..b296d32ca2ad 100644 --- a/polkadot/xcm/xcm-executor/src/config.rs +++ b/polkadot/xcm/xcm-executor/src/config.rs @@ -16,7 +16,8 @@ use crate::traits::{ AssetExchange, AssetLock, CallDispatcher, ClaimAssets, ConvertOrigin, DropAssets, ExportXcm, - FeeManager, OnResponse, ProcessTransaction, ShouldExecute, TransactAsset, + FeeManager, HandleHrmpChannelAccepted, HandleHrmpChannelClosing, + HandleHrmpNewChannelOpenRequest, OnResponse, ProcessTransaction, ShouldExecute, TransactAsset, VersionChangeNotifier, WeightBounds, WeightTrader, }; use frame_support::{ @@ -114,4 +115,11 @@ pub trait Config { /// Transactional processor for XCM instructions. type TransactionalProcessor: ProcessTransaction; + + /// Allows optional logic execution for the `HrmpNewChannelOpenRequest` XCM notification. + type HrmpNewChannelOpenRequestHandler: HandleHrmpNewChannelOpenRequest; + /// Allows optional logic execution for the `HrmpChannelAccepted` XCM notification. + type HrmpChannelAcceptedHandler: HandleHrmpChannelAccepted; + /// Allows optional logic execution for the `HrmpChannelClosing` XCM notification. + type HrmpChannelClosingHandler: HandleHrmpChannelClosing; } diff --git a/polkadot/xcm/xcm-executor/src/lib.rs b/polkadot/xcm/xcm-executor/src/lib.rs index c61e1e1d15bc..81b81fe6a171 100644 --- a/polkadot/xcm/xcm-executor/src/lib.rs +++ b/polkadot/xcm/xcm-executor/src/lib.rs @@ -31,7 +31,8 @@ use xcm::latest::prelude::*; pub mod traits; use traits::{ validate_export, AssetExchange, AssetLock, CallDispatcher, ClaimAssets, ConvertOrigin, - DropAssets, Enact, ExportXcm, FeeManager, FeeReason, OnResponse, ProcessTransaction, + DropAssets, Enact, ExportXcm, FeeManager, FeeReason, HandleHrmpChannelAccepted, + HandleHrmpChannelClosing, HandleHrmpNewChannelOpenRequest, OnResponse, ProcessTransaction, Properties, ShouldExecute, TransactAsset, VersionChangeNotifier, WeightBounds, WeightTrader, XcmAssetTransfers, }; @@ -1212,9 +1213,21 @@ impl XcmExecutor { ); Ok(()) }, - HrmpNewChannelOpenRequest { .. } => Err(XcmError::Unimplemented), - HrmpChannelAccepted { .. } => Err(XcmError::Unimplemented), - HrmpChannelClosing { .. } => Err(XcmError::Unimplemented), + HrmpNewChannelOpenRequest { sender, max_message_size, max_capacity } => + Config::TransactionalProcessor::process(|| { + Config::HrmpNewChannelOpenRequestHandler::handle( + sender, + max_message_size, + max_capacity, + ) + }), + HrmpChannelAccepted { recipient } => Config::TransactionalProcessor::process(|| { + Config::HrmpChannelAcceptedHandler::handle(recipient) + }), + HrmpChannelClosing { initiator, sender, recipient } => + Config::TransactionalProcessor::process(|| { + Config::HrmpChannelClosingHandler::handle(initiator, sender, recipient) + }), } } } diff --git a/polkadot/xcm/xcm-executor/src/traits/hrmp.rs b/polkadot/xcm/xcm-executor/src/traits/hrmp.rs new file mode 100644 index 000000000000..b6bbb9316d75 --- /dev/null +++ b/polkadot/xcm/xcm-executor/src/traits/hrmp.rs @@ -0,0 +1,56 @@ +// Copyright (C) Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Polkadot is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Polkadot. If not, see . + +use xcm::latest::Result as XcmResult; + +/// Executes logic when a `HrmpNewChannelOpenRequest` XCM notification is received. +pub trait HandleHrmpNewChannelOpenRequest { + fn handle(sender: u32, max_message_size: u32, max_capacity: u32) -> XcmResult; +} + +/// Executes optional logic when a `HrmpChannelAccepted` XCM notification is received. +pub trait HandleHrmpChannelAccepted { + fn handle(recipient: u32) -> XcmResult; +} + +/// Executes optional logic when a `HrmpChannelClosing` XCM notification is received. +pub trait HandleHrmpChannelClosing { + fn handle(initiator: u32, sender: u32, recipient: u32) -> XcmResult; +} + +#[impl_trait_for_tuples::impl_for_tuples(30)] +impl HandleHrmpNewChannelOpenRequest for Tuple { + fn handle(sender: u32, max_message_size: u32, max_capacity: u32) -> XcmResult { + for_tuples!( #( Tuple::handle(sender, max_message_size, max_capacity)?; )* ); + Ok(()) + } +} + +#[impl_trait_for_tuples::impl_for_tuples(30)] +impl HandleHrmpChannelAccepted for Tuple { + fn handle(recipient: u32) -> XcmResult { + for_tuples!( #( Tuple::handle(recipient)?; )* ); + Ok(()) + } +} + +#[impl_trait_for_tuples::impl_for_tuples(30)] +impl HandleHrmpChannelClosing for Tuple { + fn handle(initiator: u32, sender: u32, recipient: u32) -> XcmResult { + for_tuples!( #( Tuple::handle(initiator, sender, recipient)?; )* ); + Ok(()) + } +} diff --git a/polkadot/xcm/xcm-executor/src/traits/mod.rs b/polkadot/xcm/xcm-executor/src/traits/mod.rs index b445e84d3912..aa3f0d26e302 100644 --- a/polkadot/xcm/xcm-executor/src/traits/mod.rs +++ b/polkadot/xcm/xcm-executor/src/traits/mod.rs @@ -45,6 +45,10 @@ mod should_execute; pub use should_execute::{CheckSuspension, Properties, ShouldExecute}; mod transact_asset; pub use transact_asset::TransactAsset; +mod hrmp; +pub use hrmp::{ + HandleHrmpChannelAccepted, HandleHrmpChannelClosing, HandleHrmpNewChannelOpenRequest, +}; mod weight; #[deprecated = "Use `sp_runtime::traits::` instead"] pub use sp_runtime::traits::{Identity, TryConvertInto as JustTry}; diff --git a/polkadot/xcm/xcm-simulator/example/src/parachain.rs b/polkadot/xcm/xcm-simulator/example/src/parachain.rs index 50a12a3a698d..86401d756af3 100644 --- a/polkadot/xcm/xcm-simulator/example/src/parachain.rs +++ b/polkadot/xcm/xcm-simulator/example/src/parachain.rs @@ -251,6 +251,9 @@ impl Config for XcmConfig { type SafeCallFilter = Everything; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); } #[frame_support::pallet] diff --git a/polkadot/xcm/xcm-simulator/example/src/relay_chain.rs b/polkadot/xcm/xcm-simulator/example/src/relay_chain.rs index f41e273839b4..377c77f30a47 100644 --- a/polkadot/xcm/xcm-simulator/example/src/relay_chain.rs +++ b/polkadot/xcm/xcm-simulator/example/src/relay_chain.rs @@ -198,6 +198,9 @@ impl Config for XcmConfig { type SafeCallFilter = Everything; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); } pub type LocalOriginToLocation = SignedToAccountId32; diff --git a/polkadot/xcm/xcm-simulator/fuzzer/src/parachain.rs b/polkadot/xcm/xcm-simulator/fuzzer/src/parachain.rs index 1130701a3446..cadfc1e7200c 100644 --- a/polkadot/xcm/xcm-simulator/fuzzer/src/parachain.rs +++ b/polkadot/xcm/xcm-simulator/fuzzer/src/parachain.rs @@ -156,6 +156,9 @@ impl Config for XcmConfig { type SafeCallFilter = Everything; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); } #[frame_support::pallet] diff --git a/polkadot/xcm/xcm-simulator/fuzzer/src/relay_chain.rs b/polkadot/xcm/xcm-simulator/fuzzer/src/relay_chain.rs index 42dd8237cbff..3224df66cbe5 100644 --- a/polkadot/xcm/xcm-simulator/fuzzer/src/relay_chain.rs +++ b/polkadot/xcm/xcm-simulator/fuzzer/src/relay_chain.rs @@ -157,6 +157,9 @@ impl Config for XcmConfig { type SafeCallFilter = Everything; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); } pub type LocalOriginToLocation = SignedToAccountId32; diff --git a/prdoc/pr_3696.prdoc b/prdoc/pr_3696.prdoc new file mode 100644 index 000000000000..f3371d1734ad --- /dev/null +++ b/prdoc/pr_3696.prdoc @@ -0,0 +1,17 @@ +# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0 +# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json + +title: Add HRMP notification handlers to the xcm-executor + +doc: + - audience: Runtime Dev + description: | + Adds optional HRMP notification handlers to the xcm-executor. These handlers are 3 new config types on the xcm-executor `Config` trait: + - `HrmpNewChannelOpenRequestHandler` + - `HrmpChannelAcceptedHandler` + - `HrmpChannelClosingHandler` + + The traits of these config types are implemented on tuples, and on `()` for the default case. + +crates: + - name: staging-xcm-executor diff --git a/substrate/frame/contracts/mock-network/src/parachain.rs b/substrate/frame/contracts/mock-network/src/parachain.rs index 0848f97b09c6..d4ad47581d16 100644 --- a/substrate/frame/contracts/mock-network/src/parachain.rs +++ b/substrate/frame/contracts/mock-network/src/parachain.rs @@ -282,6 +282,9 @@ impl Config for XcmConfig { type SafeCallFilter = Everything; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); } impl mock_msg_queue::Config for Runtime { diff --git a/substrate/frame/contracts/mock-network/src/relay_chain.rs b/substrate/frame/contracts/mock-network/src/relay_chain.rs index 8c79255728eb..e2a8d3d1337b 100644 --- a/substrate/frame/contracts/mock-network/src/relay_chain.rs +++ b/substrate/frame/contracts/mock-network/src/relay_chain.rs @@ -182,6 +182,9 @@ impl Config for XcmConfig { type SafeCallFilter = Everything; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); } pub type LocalOriginToLocation = SignedToAccountId32; diff --git a/templates/parachain/runtime/src/xcm_config.rs b/templates/parachain/runtime/src/xcm_config.rs index b1230ba1e5d4..7dce71648886 100644 --- a/templates/parachain/runtime/src/xcm_config.rs +++ b/templates/parachain/runtime/src/xcm_config.rs @@ -137,6 +137,9 @@ impl xcm_executor::Config for XcmConfig { type SafeCallFilter = Everything; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); } /// No local origins on this chain are allowed to dispatch XCM sends/executions. From 430ad2f5610dc3d53b4708c651617e34affa97f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Tue, 19 Mar 2024 09:27:51 +0100 Subject: [PATCH 4/4] Make `availability-recovery-regression-bench` a benchmark (#3741) Closes: https://github.com/paritytech/polkadot-sdk/issues/3704 --- .gitlab/pipeline/test.yml | 2 +- polkadot/node/network/availability-recovery/Cargo.toml | 4 ++-- .../availability-recovery-regression-bench.rs | 0 3 files changed, 3 insertions(+), 3 deletions(-) rename polkadot/node/network/availability-recovery/{tests => benches}/availability-recovery-regression-bench.rs (100%) diff --git a/.gitlab/pipeline/test.yml b/.gitlab/pipeline/test.yml index 26e55e9385f3..d244316000aa 100644 --- a/.gitlab/pipeline/test.yml +++ b/.gitlab/pipeline/test.yml @@ -502,7 +502,7 @@ subsystem-regression-tests: - .common-refs - .run-immediately script: - - cargo test --profile=testnet -p polkadot-availability-recovery --test availability-recovery-regression-bench --features subsystem-benchmarks + - cargo bench --profile=testnet -p polkadot-availability-recovery --bench availability-recovery-regression-bench --features subsystem-benchmarks tags: - benchmark allow_failure: true diff --git a/polkadot/node/network/availability-recovery/Cargo.toml b/polkadot/node/network/availability-recovery/Cargo.toml index 12b6ce7a0571..23c4148fa858 100644 --- a/polkadot/node/network/availability-recovery/Cargo.toml +++ b/polkadot/node/network/availability-recovery/Cargo.toml @@ -43,9 +43,9 @@ polkadot-node-subsystem-test-helpers = { path = "../../subsystem-test-helpers" } polkadot-primitives-test-helpers = { path = "../../../primitives/test-helpers" } polkadot-subsystem-bench = { path = "../../subsystem-bench" } -[[test]] +[[bench]] name = "availability-recovery-regression-bench" -path = "tests/availability-recovery-regression-bench.rs" +path = "benches/availability-recovery-regression-bench.rs" harness = false required-features = ["subsystem-benchmarks"] diff --git a/polkadot/node/network/availability-recovery/tests/availability-recovery-regression-bench.rs b/polkadot/node/network/availability-recovery/benches/availability-recovery-regression-bench.rs similarity index 100% rename from polkadot/node/network/availability-recovery/tests/availability-recovery-regression-bench.rs rename to polkadot/node/network/availability-recovery/benches/availability-recovery-regression-bench.rs