Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add ApplyAuthorizedUpgradeOrigin #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ pub mod mainnet {
impl frame_system::Config for Test {
type BaseCallFilter = frame_support::traits::Everything;
type OnSetCode = ();
type ApplyAuthorizedUpgradeOrigin = frame_system::EnsureAlways;
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ impl frame_system::Config for Test {
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
type ApplyAuthorizedUpgradeOrigin = frame_system::EnsureAlways;
type MaxConsumers = frame_support::traits::ConstU32<16>;
type Nonce = u64;
type Block = Block;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ impl frame_system::Config for Test {
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
type ApplyAuthorizedUpgradeOrigin = frame_system::EnsureAlways;
type MaxConsumers = frame_support::traits::ConstU32<16>;
type Nonce = u64;
type Block = Block;
Expand Down
1 change: 1 addition & 0 deletions bridges/snowbridge/parachain/pallets/system/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ impl frame_system::Config for Test {
type SystemWeightInfo = ();
type SS58Prefix = ConstU16<42>;
type OnSetCode = ();
type ApplyAuthorizedUpgradeOrigin = frame_system::EnsureAlways;
type MaxConsumers = frame_support::traits::ConstU32<16>;
type Nonce = u64;
type Block = Block;
Expand Down
3 changes: 2 additions & 1 deletion cumulus/pallets/parachain-system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -693,9 +693,10 @@ pub mod pallet {
note = "To be removed after June 2024. Migrate to `frame_system::apply_authorized_upgrade`."
)]
pub fn enact_authorized_upgrade(
_: OriginFor<T>,
origin: OriginFor<T>,
code: Vec<u8>,
) -> DispatchResultWithPostInfo {
<T as frame_system::Config>::ApplyAuthorizedUpgradeOrigin::ensure_origin(origin)?;
let post = frame_system::Pallet::<T>::do_apply_authorize_upgrade(code)?;
Ok(post)
}
Expand Down
24 changes: 22 additions & 2 deletions substrate/frame/system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ pub mod pallet {

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

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

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

/// The set code logic, just the default since we're not a parachain.
type OnSetCode = ();

type ApplyAuthorizedUpgradeOrigin = EnsureAlways;
}

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

type ApplyAuthorizedUpgradeOrigin: EnsureOrigin<Self::RuntimeOrigin>;

/// The maximum number of consumers allowed on a single account.
type MaxConsumers: ConsumerLimits;
}
Expand Down Expand Up @@ -757,9 +762,10 @@ pub mod pallet {
#[pallet::call_index(11)]
#[pallet::weight((T::SystemWeightInfo::apply_authorized_upgrade(), DispatchClass::Operational))]
pub fn apply_authorized_upgrade(
_: OriginFor<T>,
origin: OriginFor<T>,
code: Vec<u8>,
) -> DispatchResultWithPostInfo {
T::ApplyAuthorizedUpgradeOrigin::ensure_origin(origin)?;
let post = Self::do_apply_authorize_upgrade(code)?;
Ok(post)
}
Expand Down Expand Up @@ -1259,6 +1265,20 @@ impl_ensure_origin_with_arg_ignoring_arg! {
{}
}

/// Always pass.
pub struct EnsureAlways;
impl<O> EnsureOrigin<O> for EnsureAlways {
type Success = ();
fn try_origin(_: O) -> Result<(), O> {
Ok(())
}

#[cfg(feature = "runtime-benchmarks")]
fn try_successful_origin() -> Result<O, ()> {
Ok(O::from(RawOrigin::None))
}
}

#[docify::export]
/// Ensure that the origin `o` represents a signed extrinsic (i.e. transaction).
/// Returns `Ok` with the account that signed the extrinsic or an `Err` otherwise.
Expand Down
Loading