--- a/pallets/maintenance/src/benchmarking.rs +++ b/pallets/maintenance/src/benchmarking.rs @@ -23,6 +23,30 @@ use codec::Encode; use sp_std::vec; +#[cfg(not(feature = "governance"))] +benchmarks! { + enable { + }: _(RawOrigin::Root) + verify { + ensure!(>::get(), "didn't enable the MM"); + } + + disable { + Maintenance::::enable(RawOrigin::Root.into())?; + }: _(RawOrigin::Root) + verify { + ensure!(!>::get(), "didn't disable the MM"); + } + + execute_preimage { + let call_hash = RuntimeCall::::set_storage { items: vec![] }.encode(); + let hash = T::Preimages::note(call_hash.into())?; + }: _(RawOrigin::Root, hash) + verify { + } +} + +#[cfg(feature = "governance")] benchmarks! { enable { }: _(RawOrigin::Root) --- a/pallets/maintenance/src/lib.rs +++ b/pallets/maintenance/src/lib.rs @@ -28,6 +28,8 @@ use frame_support::{ dispatch::*, pallet_prelude::*, + }; + use frame_support::{ traits::{QueryPreimage, StorePreimage}, }; use frame_system::pallet_prelude::*; @@ -105,20 +107,31 @@ #[pallet::call_index(2)] #[pallet::weight(::WeightInfo::execute_preimage())] - pub fn execute_preimage(origin: OriginFor, hash: H256) -> DispatchResult { - ensure_root(origin)?; + pub fn execute_preimage(_origin: OriginFor, _hash: H256) -> DispatchResult { + #[cfg(feature = "governance")] + { + let origin = _origin; + let hash = _hash; + + ensure_root(origin)?; - let len = T::Preimages::len(&hash).ok_or(DispatchError::Unavailable)?; - let bounded = T::Preimages::pick::<::RuntimeCall>(hash, len); - let (call, _) = - T::Preimages::realize(&bounded).map_err(|_| DispatchError::Unavailable)?; + let len = T::Preimages::len(&hash).ok_or(DispatchError::Unavailable)?; + let bounded = T::Preimages::pick::<::RuntimeCall>(hash, len); + let (call, _) = + T::Preimages::realize(&bounded).map_err(|_| DispatchError::Unavailable)?; - let result = match call.dispatch(frame_system::RawOrigin::Root.into()) { - Ok(_) => Ok(()), - Err(error_and_info) => Err(error_and_info.error), - }; + let result = match call.dispatch(frame_system::RawOrigin::Root.into()) { + Ok(_) => Ok(()), + Err(error_and_info) => Err(error_and_info.error), + }; - result + result + } + + #[cfg(not(feature = "governance"))] + { + Err(DispatchError::Unavailable) + } } } } --- a/runtime/common/config/pallets/mod.rs +++ b/runtime/common/config/pallets/mod.rs @@ -23,7 +23,7 @@ weights::CommonWeights, RelayChainBlockNumberProvider, }, - Runtime, RuntimeEvent, RuntimeCall, RuntimeOrigin, Balances, Preimage, + Runtime, RuntimeEvent, RuntimeCall, RuntimeOrigin, Balances, }; use frame_support::traits::{ConstU32, ConstU64}; use up_common::{ @@ -47,8 +47,7 @@ #[cfg(feature = "collator-selection")] pub mod collator_selection; -// todo:governance replace the feature with governance -#[cfg(feature = "collator-selection")] +#[cfg(feature = "governance")] pub mod governance; parameter_types! { @@ -129,6 +128,9 @@ type RuntimeEvent = RuntimeEvent; type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; - type Preimages = Preimage; + #[cfg(feature = "governance")] + type Preimages = crate::Preimage; + #[cfg(not(feature = "governance"))] + type Preimages = (); type WeightInfo = pallet_maintenance::weights::SubstrateWeight; } --- a/runtime/common/construct_runtime.rs +++ b/runtime/common/construct_runtime.rs @@ -56,8 +56,7 @@ #[cfg(feature = "collator-selection")] Identity: pallet_identity::{Pallet, Call, Storage, Event} = 40, - // todo:governance switch feature to governance - #[cfg(feature = "collator-selection")] + #[cfg(feature = "governance")] Preimage: pallet_preimage::{Pallet, Call, Storage, Event} = 41, // XCM helpers. --- a/runtime/common/maintenance.rs +++ b/runtime/common/maintenance.rs @@ -86,8 +86,7 @@ | RuntimeCall::Session(_) | RuntimeCall::Identity(_) => Err(TransactionValidityError::Invalid(InvalidTransaction::Call)), - // todo:governance switch the feature to governance - #[cfg(feature = "collator-selection")] + #[cfg(feature = "governance")] RuntimeCall::Preimage(_) => Err(TransactionValidityError::Invalid(InvalidTransaction::Call)), #[cfg(feature = "pallet-test-utils")] --- a/runtime/common/runtime_apis.rs +++ b/runtime/common/runtime_apis.rs @@ -565,8 +565,7 @@ #[cfg(feature = "collator-selection")] list_benchmark!(list, extra, pallet_identity, Identity); - // todo:governance switch feature to governance - #[cfg(feature = "collator-selection")] + #[cfg(feature = "governance")] list_benchmark!(list, extra, pallet_preimage, Preimage); #[cfg(feature = "foreign-assets")] @@ -633,8 +632,7 @@ #[cfg(feature = "collator-selection")] add_benchmark!(params, batches, pallet_identity, Identity); - // todo:governance switch feature to governance - #[cfg(feature = "collator-selection")] + #[cfg(feature = "governance")] add_benchmark!(params, batches, pallet_preimage, Preimage); #[cfg(feature = "foreign-assets")] --- a/runtime/opal/Cargo.toml +++ b/runtime/opal/Cargo.toml @@ -18,7 +18,7 @@ [features] default = ['opal-runtime', 'std'] limit-testing = ['pallet-unique/limit-testing', 'up-data-structs/limit-testing'] -opal-runtime = ['app-promotion', 'collator-selection', 'foreign-assets', 'pallet-test-utils', 'refungible'] +opal-runtime = ['app-promotion', 'collator-selection', 'foreign-assets', 'governance', 'pallet-test-utils', 'refungible'] pov-estimate = [] runtime-benchmarks = [ 'cumulus-pallet-parachain-system/runtime-benchmarks', @@ -191,6 +191,7 @@ app-promotion = [] collator-selection = [] foreign-assets = [] +governance = [] pallet-test-utils = [] refungible = [] scheduler = [] --- a/runtime/quartz/Cargo.toml +++ b/runtime/quartz/Cargo.toml @@ -20,7 +20,7 @@ default = ['quartz-runtime', 'std'] limit-testing = ['pallet-unique/limit-testing', 'up-data-structs/limit-testing'] pov-estimate = [] -quartz-runtime = ['app-promotion', 'collator-selection', 'foreign-assets', 'refungible'] +quartz-runtime = ['app-promotion', 'collator-selection', 'foreign-assets', 'governance', 'refungible'] runtime-benchmarks = [ 'cumulus-pallet-parachain-system/runtime-benchmarks', 'frame-benchmarking', @@ -184,6 +184,7 @@ app-promotion = [] collator-selection = [] foreign-assets = [] +governance = [] refungible = [] scheduler = [] --- a/runtime/unique/Cargo.toml +++ b/runtime/unique/Cargo.toml @@ -183,6 +183,7 @@ app-promotion = [] collator-selection = [] foreign-assets = [] +governance = [] refungible = [] scheduler = []