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
--- 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!(<Enabled<T>>::get(), "didn't enable the MM");
+	}
+
+	disable {
+		Maintenance::<T>::enable(RawOrigin::Root.into())?;
+	}: _(RawOrigin::Root)
+	verify {
+		ensure!(!<Enabled<T>>::get(), "didn't disable the MM");
+	}
+
+	execute_preimage {
+		let call_hash = RuntimeCall::<T>::set_storage { items: vec![] }.encode();
+		let hash = T::Preimages::note(call_hash.into())?;
+	}: _(RawOrigin::Root, hash)
+	verify {
+	}
+}
+
+#[cfg(feature = "governance")]
 benchmarks! {
 	enable {
 	}: _(RawOrigin::Root)
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
before · runtime/common/maintenance.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 scale_info::TypeInfo;18use codec::{Encode, Decode};19use up_common::types::AccountId;20use crate::{RuntimeCall, Maintenance};2122use sp_runtime::{23	traits::{DispatchInfoOf, SignedExtension},24	transaction_validity::{25		TransactionValidity, ValidTransaction, InvalidTransaction, TransactionValidityError,26	},27};2829#[derive(Debug, Encode, Decode, PartialEq, Eq, Clone, TypeInfo)]30pub struct CheckMaintenance;3132impl SignedExtension for CheckMaintenance {33	type AccountId = AccountId;34	type Call = RuntimeCall;35	type AdditionalSigned = ();36	type Pre = ();3738	const IDENTIFIER: &'static str = "CheckMaintenance";3940	fn additional_signed(&self) -> Result<Self::AdditionalSigned, TransactionValidityError> {41		Ok(())42	}4344	fn pre_dispatch(45		self,46		who: &Self::AccountId,47		call: &Self::Call,48		info: &DispatchInfoOf<Self::Call>,49		len: usize,50	) -> Result<Self::Pre, TransactionValidityError> {51		self.validate(who, call, info, len).map(|_| ())52	}5354	fn validate(55		&self,56		_who: &Self::AccountId,57		call: &Self::Call,58		_info: &DispatchInfoOf<Self::Call>,59		_len: usize,60	) -> TransactionValidity {61		if Maintenance::is_enabled() {62			match call {63				RuntimeCall::EvmMigration(_)64				| RuntimeCall::EVM(_)65				| RuntimeCall::Ethereum(_)66				| RuntimeCall::Inflation(_)67				| RuntimeCall::Structure(_)68				| RuntimeCall::Unique(_) => Err(TransactionValidityError::Invalid(InvalidTransaction::Call)),6970				#[cfg(feature = "scheduler")]71				RuntimeCall::Scheduler(_) => Err(TransactionValidityError::Invalid(InvalidTransaction::Call)),7273				#[cfg(feature = "app-promotion")]74				RuntimeCall::AppPromotion(_) => {75					Err(TransactionValidityError::Invalid(InvalidTransaction::Call))76				}7778				#[cfg(feature = "foreign-assets")]79				RuntimeCall::ForeignAssets(_) => {80					Err(TransactionValidityError::Invalid(InvalidTransaction::Call))81				}8283				#[cfg(feature = "collator-selection")]84				RuntimeCall::CollatorSelection(_)85				| RuntimeCall::Authorship(_)86				| RuntimeCall::Session(_)87				| RuntimeCall::Identity(_) => Err(TransactionValidityError::Invalid(InvalidTransaction::Call)),8889				// todo:governance switch the feature to governance90				#[cfg(feature = "collator-selection")]91				RuntimeCall::Preimage(_) => Err(TransactionValidityError::Invalid(InvalidTransaction::Call)),9293				#[cfg(feature = "pallet-test-utils")]94				RuntimeCall::TestUtils(_) => Err(TransactionValidityError::Invalid(InvalidTransaction::Call)),9596				_ => Ok(ValidTransaction::default()),97			}98		} else {99			Ok(ValidTransaction::default())100		}101	}102103	fn pre_dispatch_unsigned(104		call: &Self::Call,105		info: &DispatchInfoOf<Self::Call>,106		len: usize,107	) -> Result<(), TransactionValidityError> {108		Self::validate_unsigned(call, info, len).map(|_| ())109	}110111	fn validate_unsigned(112		call: &Self::Call,113		_info: &DispatchInfoOf<Self::Call>,114		_len: usize,115	) -> TransactionValidity {116		if Maintenance::is_enabled() {117			match call {118				RuntimeCall::EVM(_) | RuntimeCall::Ethereum(_) | RuntimeCall::EvmMigration(_) => {119					Err(TransactionValidityError::Invalid(InvalidTransaction::Call))120				}121				_ => Ok(ValidTransaction::default()),122			}123		} else {124			Ok(ValidTransaction::default())125		}126	}127}
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 = []