git.delta.rocks / unique-network / refs/commits / cec8ffa65f46

difftreelog

fix(preimage) maintenance not working with quantum preimage (due to runtimes)

Fahrrader2023-02-21parent: #c80473f.patch.diff
in: master

9 files changed

modifiedpallets/maintenance/src/benchmarking.rsdiffbeforeafterboth
before · pallets/maintenance/src/benchmarking.rs
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617use super::*;18use crate::{Pallet as Maintenance, Config};1920use frame_benchmarking::benchmarks;21use frame_system::{Call as RuntimeCall, RawOrigin};22use frame_support::{ensure, traits::StorePreimage};23use codec::Encode;24use sp_std::vec;2526benchmarks! {27	enable {28	}: _(RawOrigin::Root)29	verify {30		ensure!(<Enabled<T>>::get(), "didn't enable the MM");31	}3233	disable {34		Maintenance::<T>::enable(RawOrigin::Root.into())?;35	}: _(RawOrigin::Root)36	verify {37		ensure!(!<Enabled<T>>::get(), "didn't disable the MM");38	}3940	execute_preimage {41		let call_hash = RuntimeCall::<T>::set_storage { items: vec![] }.encode();42		let hash = T::Preimages::note(call_hash.into())?;43	}: _(RawOrigin::Root, hash)44	verify {45	}46}
after · pallets/maintenance/src/benchmarking.rs
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617use super::*;18use crate::{Pallet as Maintenance, Config};1920use frame_benchmarking::benchmarks;21use frame_system::{Call as RuntimeCall, RawOrigin};22use frame_support::{ensure, traits::StorePreimage};23use codec::Encode;24use sp_std::vec;2526#[cfg(not(feature = "governance"))]27benchmarks! {28	enable {29	}: _(RawOrigin::Root)30	verify {31		ensure!(<Enabled<T>>::get(), "didn't enable the MM");32	}3334	disable {35		Maintenance::<T>::enable(RawOrigin::Root.into())?;36	}: _(RawOrigin::Root)37	verify {38		ensure!(!<Enabled<T>>::get(), "didn't disable the MM");39	}4041	execute_preimage {42		let call_hash = RuntimeCall::<T>::set_storage { items: vec![] }.encode();43		let hash = T::Preimages::note(call_hash.into())?;44	}: _(RawOrigin::Root, hash)45	verify {46	}47}4849#[cfg(feature = "governance")]50benchmarks! {51	enable {52	}: _(RawOrigin::Root)53	verify {54		ensure!(<Enabled<T>>::get(), "didn't enable the MM");55	}5657	disable {58		Maintenance::<T>::enable(RawOrigin::Root.into())?;59	}: _(RawOrigin::Root)60	verify {61		ensure!(!<Enabled<T>>::get(), "didn't disable the MM");62	}6364	execute_preimage {65		let call_hash = RuntimeCall::<T>::set_storage { items: vec![] }.encode();66		let hash = T::Preimages::note(call_hash.into())?;67	}: _(RawOrigin::Root, hash)68	verify {69	}70}
modifiedpallets/maintenance/src/lib.rsdiffbeforeafterboth
--- 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(<T as Config>::WeightInfo::execute_preimage())]
-		pub fn execute_preimage(origin: OriginFor<T>, hash: H256) -> DispatchResult {
-			ensure_root(origin)?;
+		pub fn execute_preimage(_origin: OriginFor<T>, _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::<<T as Config>::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::<<T as Config>::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)
+			}
 		}
 	}
 }
modifiedruntime/common/config/pallets/mod.rsdiffbeforeafterboth
--- 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<Self>;
 }
modifiedruntime/common/construct_runtime.rsdiffbeforeafterboth
--- 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<T>} = 40,
 
-                // todo:governance switch feature to governance
-                #[cfg(feature = "collator-selection")]
+                #[cfg(feature = "governance")]
                 Preimage: pallet_preimage::{Pallet, Call, Storage, Event<T>} = 41,
 
                 // XCM helpers.
modifiedruntime/common/maintenance.rsdiffbeforeafterboth
--- 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")]
modifiedruntime/common/runtime_apis.rsdiffbeforeafterboth
--- 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")]
modifiedruntime/opal/Cargo.tomldiffbeforeafterboth
--- 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 = []
modifiedruntime/quartz/Cargo.tomldiffbeforeafterboth
--- 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 = []
 
modifiedruntime/unique/Cargo.tomldiffbeforeafterboth
--- a/runtime/unique/Cargo.toml
+++ b/runtime/unique/Cargo.toml
@@ -183,6 +183,7 @@
 app-promotion = []
 collator-selection = []
 foreign-assets = []
+governance = []
 refungible = []
 scheduler = []