Skip to content
Snippets Groups Projects
Commit 1a9dba41 authored by cmd[bot]'s avatar cmd[bot]
Browse files

Update from bkontur running command 'fmt'

parent 693c2773
Branches
No related merge requests found
Pipeline #515631 waiting for manual action with stages
in 11 minutes and 37 seconds
...@@ -119,7 +119,7 @@ use codec::{Decode, Encode}; ...@@ -119,7 +119,7 @@ use codec::{Decode, Encode};
use core::{cmp, mem}; use core::{cmp, mem};
use frame_support::{ use frame_support::{
dispatch::PostDispatchInfo, pallet_prelude::*, traits::EstimateNextSessionRotation, dispatch::PostDispatchInfo, pallet_prelude::*, traits::EstimateNextSessionRotation,
DefaultNoBound DefaultNoBound,
}; };
use frame_system::pallet_prelude::*; use frame_system::pallet_prelude::*;
use polkadot_primitives::{ use polkadot_primitives::{
...@@ -661,10 +661,7 @@ pub mod pallet { ...@@ -661,10 +661,7 @@ pub mod pallet {
/// Current code has been updated for a Para. `para_id` /// Current code has been updated for a Para. `para_id`
CurrentCodeUpdated(ParaId), CurrentCodeUpdated(ParaId),
/// New code hash has been authorized for a Para. /// New code hash has been authorized for a Para.
CodeAuthorized { CodeAuthorized { code_hash: ValidationCodeHash, para_id: ParaId },
code_hash: ValidationCodeHash,
para_id: ParaId,
},
/// Current head has been updated for a Para. `para_id` /// Current head has been updated for a Para. `para_id`
CurrentHeadUpdated(ParaId), CurrentHeadUpdated(ParaId),
/// A code upgrade has been scheduled for a Para. `para_id` /// A code upgrade has been scheduled for a Para. `para_id`
...@@ -809,7 +806,8 @@ pub mod pallet { ...@@ -809,7 +806,8 @@ pub mod pallet {
/// The code hash of a para which is authorized. /// The code hash of a para which is authorized.
#[pallet::storage] #[pallet::storage]
pub(super) type AuthorizedCodeHash<T: Config> = StorageMap<_, Twox64Concat, ParaId, ValidationCodeHash>; pub(super) type AuthorizedCodeHash<T: Config> =
StorageMap<_, Twox64Concat, ParaId, ValidationCodeHash>;
/// This is used by the relay-chain to communicate to a parachain a go-ahead with in the upgrade /// This is used by the relay-chain to communicate to a parachain a go-ahead with in the upgrade
/// procedure. /// procedure.
...@@ -1184,7 +1182,8 @@ pub mod pallet { ...@@ -1184,7 +1182,8 @@ pub mod pallet {
) -> DispatchResult { ) -> DispatchResult {
ensure_root(origin)?; ensure_root(origin)?;
// if one is already authorized, means it has not been applied yet, so we just replace it. // if one is already authorized, means it has not been applied yet, so we just replace
// it.
if let Some(already_authorized) = AuthorizedCodeHash::<T>::take(para) { if let Some(already_authorized) = AuthorizedCodeHash::<T>::take(para) {
log::warn!( log::warn!(
target: LOG_TARGET, target: LOG_TARGET,
...@@ -1199,10 +1198,7 @@ pub mod pallet { ...@@ -1199,10 +1198,7 @@ pub mod pallet {
// insert authorized code hash. // insert authorized code hash.
AuthorizedCodeHash::<T>::insert(&para, new_code_hash); AuthorizedCodeHash::<T>::insert(&para, new_code_hash);
Self::deposit_event(Event::CodeAuthorized { Self::deposit_event(Event::CodeAuthorized { para_id: para, code_hash: new_code_hash });
para_id: para,
code_hash: new_code_hash,
});
Ok(()) Ok(())
} }
...@@ -2251,10 +2247,7 @@ impl<T: Config> Pallet<T> { ...@@ -2251,10 +2247,7 @@ impl<T: Config> Pallet<T> {
} }
/// Force set the current code for the given parachain. /// Force set the current code for the given parachain.
fn do_force_set_current_code_update( fn do_force_set_current_code_update(para: ParaId, new_code: ValidationCode) {
para: ParaId,
new_code: ValidationCode,
) {
let new_code_hash = new_code.hash(); let new_code_hash = new_code.hash();
Self::increase_code_ref(&new_code_hash, &new_code); Self::increase_code_ref(&new_code_hash, &new_code);
Self::set_current_code(para, new_code_hash, frame_system::Pallet::<T>::block_number()); Self::set_current_code(para, new_code_hash, frame_system::Pallet::<T>::block_number());
......
...@@ -2036,7 +2036,11 @@ fn authorize_and_apply_set_current_code_works() { ...@@ -2036,7 +2036,11 @@ fn authorize_and_apply_set_current_code_works() {
// cannot apply non-authorized code // cannot apply non-authorized code
assert_err!( assert_err!(
Paras::apply_authorized_force_set_current_code(non_root.clone(), para_a, code_1.clone()), Paras::apply_authorized_force_set_current_code(
non_root.clone(),
para_a,
code_1.clone()
),
Error::<Test>::CannotUpgradeCode, Error::<Test>::CannotUpgradeCode,
); );
...@@ -2057,7 +2061,11 @@ fn authorize_and_apply_set_current_code_works() { ...@@ -2057,7 +2061,11 @@ fn authorize_and_apply_set_current_code_works() {
// non-root cannot apply unauthorized code // non-root cannot apply unauthorized code
assert_err!( assert_err!(
Paras::apply_authorized_force_set_current_code(non_root.clone(), para_a, code_2.clone()), Paras::apply_authorized_force_set_current_code(
non_root.clone(),
para_a,
code_2.clone()
),
Error::<Test>::CannotUpgradeCode, Error::<Test>::CannotUpgradeCode,
); );
assert_eq!(AuthorizedCodeHash::<Test>::get(para_a), Some(code_1_hash)); assert_eq!(AuthorizedCodeHash::<Test>::get(para_a), Some(code_1_hash));
...@@ -2067,7 +2075,11 @@ fn authorize_and_apply_set_current_code_works() { ...@@ -2067,7 +2075,11 @@ fn authorize_and_apply_set_current_code_works() {
check_code_is_not_stored(&code_3); check_code_is_not_stored(&code_3);
// non-root can apply authorized code // non-root can apply authorized code
assert_ok!(Paras::apply_authorized_force_set_current_code(non_root.clone(), para_a, code_1.clone())); assert_ok!(Paras::apply_authorized_force_set_current_code(
non_root.clone(),
para_a,
code_1.clone()
));
// check authorized code was applied // check authorized code was applied
assert!(AuthorizedCodeHash::<Test>::get(para_a).is_none()); assert!(AuthorizedCodeHash::<Test>::get(para_a).is_none());
...@@ -2094,16 +2106,28 @@ fn authorize_and_apply_set_current_code_works() { ...@@ -2094,16 +2106,28 @@ fn authorize_and_apply_set_current_code_works() {
// cannot apply older ones // cannot apply older ones
assert_err!( assert_err!(
Paras::apply_authorized_force_set_current_code(non_root.clone(), para_a, code_1.clone()), Paras::apply_authorized_force_set_current_code(
non_root.clone(),
para_a,
code_1.clone()
),
Error::<Test>::CannotUpgradeCode, Error::<Test>::CannotUpgradeCode,
); );
assert_err!( assert_err!(
Paras::apply_authorized_force_set_current_code(non_root.clone(), para_a, code_2.clone()), Paras::apply_authorized_force_set_current_code(
non_root.clone(),
para_a,
code_2.clone()
),
Error::<Test>::CannotUpgradeCode, Error::<Test>::CannotUpgradeCode,
); );
// apply just authorized // apply just authorized
assert_ok!(Paras::apply_authorized_force_set_current_code(non_root.clone(), para_a, code_3.clone())); assert_ok!(Paras::apply_authorized_force_set_current_code(
non_root.clone(),
para_a,
code_3.clone()
));
assert!(AuthorizedCodeHash::<Test>::get(para_a).is_none()); assert!(AuthorizedCodeHash::<Test>::get(para_a).is_none());
assert_eq!(CurrentCodeHash::<Test>::get(para_a), Some(code_3_hash)); assert_eq!(CurrentCodeHash::<Test>::get(para_a), Some(code_3_hash));
check_code_is_stored(&code_1); check_code_is_stored(&code_1);
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment