Skip to content

Commit fa2a50c

Browse files
committed
feat: add ApplyAuthorizedUpgradeOrigin
1 parent 0ff3f4d commit fa2a50c

2 files changed

Lines changed: 23 additions & 3 deletions

File tree

  • cumulus/pallets/parachain-system/src
  • substrate/frame/system/src

cumulus/pallets/parachain-system/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,9 +693,10 @@ pub mod pallet {
693693
note = "To be removed after June 2024. Migrate to `frame_system::apply_authorized_upgrade`."
694694
)]
695695
pub fn enact_authorized_upgrade(
696-
_: OriginFor<T>,
696+
origin: OriginFor<T>,
697697
code: Vec<u8>,
698698
) -> DispatchResultWithPostInfo {
699+
<T as frame_system::Config>::ApplyAuthorizedUpgradeOrigin::ensure_origin(origin)?;
699700
let post = frame_system::Pallet::<T>::do_apply_authorize_upgrade(code)?;
700701
Ok(post)
701702
}

substrate/frame/system/src/lib.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ pub mod pallet {
257257

258258
/// Default implementations of [`DefaultConfig`], which can be used to implement [`Config`].
259259
pub mod config_preludes {
260-
use super::{inject_runtime_type, DefaultConfig};
260+
use super::{inject_runtime_type, DefaultConfig, EnsureAlways};
261261
use frame_support::derive_impl;
262262

263263
/// Provides a viable default config that can be used with
@@ -298,6 +298,7 @@ pub mod pallet {
298298
type BaseCallFilter = frame_support::traits::Everything;
299299
type BlockHashCount = frame_support::traits::ConstU64<10>;
300300
type OnSetCode = ();
301+
type ApplyAuthorizedUpgradeOrigin = EnsureAlways;
301302
}
302303

303304
/// Default configurations of this pallet in a solo-chain environment.
@@ -392,6 +393,8 @@ pub mod pallet {
392393

393394
/// The set code logic, just the default since we're not a parachain.
394395
type OnSetCode = ();
396+
397+
type ApplyAuthorizedUpgradeOrigin = EnsureAlways;
395398
}
396399

397400
/// Default configurations of this pallet in a relay-chain environment.
@@ -568,6 +571,8 @@ pub mod pallet {
568571
#[pallet::no_default_bounds]
569572
type OnSetCode: SetCode<Self>;
570573

574+
type ApplyAuthorizedUpgradeOrigin: EnsureOrigin<Self::RuntimeOrigin>;
575+
571576
/// The maximum number of consumers allowed on a single account.
572577
type MaxConsumers: ConsumerLimits;
573578
}
@@ -757,9 +762,10 @@ pub mod pallet {
757762
#[pallet::call_index(11)]
758763
#[pallet::weight((T::SystemWeightInfo::apply_authorized_upgrade(), DispatchClass::Operational))]
759764
pub fn apply_authorized_upgrade(
760-
_: OriginFor<T>,
765+
origin: OriginFor<T>,
761766
code: Vec<u8>,
762767
) -> DispatchResultWithPostInfo {
768+
T::ApplyAuthorizedUpgradeOrigin::ensure_origin(origin)?;
763769
let post = Self::do_apply_authorize_upgrade(code)?;
764770
Ok(post)
765771
}
@@ -1259,6 +1265,19 @@ impl_ensure_origin_with_arg_ignoring_arg! {
12591265
{}
12601266
}
12611267

1268+
pub struct EnsureAlways;
1269+
impl<O> EnsureOrigin<O> for EnsureAlways {
1270+
type Success = ();
1271+
fn try_origin(_: O) -> Result<(), O> {
1272+
Ok(())
1273+
}
1274+
1275+
#[cfg(feature = "runtime-benchmarks")]
1276+
fn try_successful_origin() -> Result<O, ()> {
1277+
Ok(O::from(RawOrigin::None))
1278+
}
1279+
}
1280+
12621281
#[docify::export]
12631282
/// Ensure that the origin `o` represents a signed extrinsic (i.e. transaction).
12641283
/// Returns `Ok` with the account that signed the extrinsic or an `Err` otherwise.

0 commit comments

Comments
 (0)