From c8649cd5add0590c21b57a2379ebeeaa2c7ac939 Mon Sep 17 00:00:00 2001 From: Daniel Shiposha Date: Tue, 9 Jan 2024 11:27:35 +0100 Subject: [PATCH 1/2] feat: add ApplyAuthorizedUpgradeOrigin --- cumulus/pallets/parachain-system/src/lib.rs | 3 ++- substrate/frame/system/src/lib.rs | 24 +++++++++++++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/cumulus/pallets/parachain-system/src/lib.rs b/cumulus/pallets/parachain-system/src/lib.rs index 5a0fa57fb171..5993dca80b71 100644 --- a/cumulus/pallets/parachain-system/src/lib.rs +++ b/cumulus/pallets/parachain-system/src/lib.rs @@ -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, + origin: OriginFor, code: Vec, ) -> DispatchResultWithPostInfo { + ::ApplyAuthorizedUpgradeOrigin::ensure_origin(origin)?; let post = frame_system::Pallet::::do_apply_authorize_upgrade(code)?; Ok(post) } diff --git a/substrate/frame/system/src/lib.rs b/substrate/frame/system/src/lib.rs index 069217bcee46..028c4b5d14ae 100644 --- a/substrate/frame/system/src/lib.rs +++ b/substrate/frame/system/src/lib.rs @@ -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 @@ -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. @@ -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. @@ -568,6 +571,8 @@ pub mod pallet { #[pallet::no_default_bounds] type OnSetCode: SetCode; + type ApplyAuthorizedUpgradeOrigin: EnsureOrigin; + /// The maximum number of consumers allowed on a single account. type MaxConsumers: ConsumerLimits; } @@ -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, + origin: OriginFor, code: Vec, ) -> DispatchResultWithPostInfo { + T::ApplyAuthorizedUpgradeOrigin::ensure_origin(origin)?; let post = Self::do_apply_authorize_upgrade(code)?; Ok(post) } @@ -1259,6 +1265,20 @@ impl_ensure_origin_with_arg_ignoring_arg! { {} } +/// Always pass. +pub struct EnsureAlways; +impl EnsureOrigin for EnsureAlways { + type Success = (); + fn try_origin(_: O) -> Result<(), O> { + Ok(()) + } + + #[cfg(feature = "runtime-benchmarks")] + fn try_successful_origin() -> Result { + 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. From 91f2941570fed20f9618084856910ddaa12e9655 Mon Sep 17 00:00:00 2001 From: Daniel Shiposha Date: Mon, 15 Jan 2024 13:46:58 +0100 Subject: [PATCH 2/2] fix: ApplyAuthorizedUpgradeOrigin in snowbridge mocks --- .../parachain/pallets/ethereum-beacon-client/src/mock.rs | 1 + bridges/snowbridge/parachain/pallets/inbound-queue/src/mock.rs | 1 + bridges/snowbridge/parachain/pallets/outbound-queue/src/mock.rs | 1 + bridges/snowbridge/parachain/pallets/system/src/mock.rs | 1 + 4 files changed, 4 insertions(+) diff --git a/bridges/snowbridge/parachain/pallets/ethereum-beacon-client/src/mock.rs b/bridges/snowbridge/parachain/pallets/ethereum-beacon-client/src/mock.rs index 4d1d14a10158..ba797f6b743c 100644 --- a/bridges/snowbridge/parachain/pallets/ethereum-beacon-client/src/mock.rs +++ b/bridges/snowbridge/parachain/pallets/ethereum-beacon-client/src/mock.rs @@ -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 = (); diff --git a/bridges/snowbridge/parachain/pallets/inbound-queue/src/mock.rs b/bridges/snowbridge/parachain/pallets/inbound-queue/src/mock.rs index 6b79a55e3c93..8442d804889e 100644 --- a/bridges/snowbridge/parachain/pallets/inbound-queue/src/mock.rs +++ b/bridges/snowbridge/parachain/pallets/inbound-queue/src/mock.rs @@ -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; diff --git a/bridges/snowbridge/parachain/pallets/outbound-queue/src/mock.rs b/bridges/snowbridge/parachain/pallets/outbound-queue/src/mock.rs index dd8fee4e2ed0..c76271a9d21c 100644 --- a/bridges/snowbridge/parachain/pallets/outbound-queue/src/mock.rs +++ b/bridges/snowbridge/parachain/pallets/outbound-queue/src/mock.rs @@ -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; diff --git a/bridges/snowbridge/parachain/pallets/system/src/mock.rs b/bridges/snowbridge/parachain/pallets/system/src/mock.rs index 7a4f61189305..4de6dbd897a4 100644 --- a/bridges/snowbridge/parachain/pallets/system/src/mock.rs +++ b/bridges/snowbridge/parachain/pallets/system/src/mock.rs @@ -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;