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
--- 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
before · runtime/unique/Cargo.toml
1################################################################################2# Package34[package]5authors = ['Unique Network <support@uniquenetwork.io>']6build = 'build.rs'7description = 'Unique Runtime'8edition = '2021'9homepage = 'https://unique.network'10license = 'GPLv3'11name = 'unique-runtime'12repository = 'https://github.com/UniqueNetwork/unique-chain'13version.workspace = true1415[package.metadata.docs.rs]16targets = ['x86_64-unknown-linux-gnu']1718[features]19default = ['std', 'unique-runtime']20limit-testing = ['pallet-unique/limit-testing', 'up-data-structs/limit-testing']21pov-estimate = []22runtime-benchmarks = [23	'frame-benchmarking',24	'frame-support/runtime-benchmarks',25	'frame-system-benchmarking',26	'frame-system/runtime-benchmarks',27	'hex-literal',28	'pallet-app-promotion/runtime-benchmarks',29	'pallet-balances/runtime-benchmarks',30	'pallet-collator-selection/runtime-benchmarks',31	'pallet-common/runtime-benchmarks',32	'pallet-configuration/runtime-benchmarks',33	'pallet-ethereum/runtime-benchmarks',34	'pallet-evm-coder-substrate/runtime-benchmarks',35	'pallet-evm-migration/runtime-benchmarks',36	'pallet-foreign-assets/runtime-benchmarks',37	'pallet-fungible/runtime-benchmarks',38	'pallet-identity/runtime-benchmarks',39	'pallet-inflation/runtime-benchmarks',40	'pallet-maintenance/runtime-benchmarks',41	'pallet-nonfungible/runtime-benchmarks',42	"pallet-preimage/runtime-benchmarks",43	'pallet-refungible/runtime-benchmarks',44	'pallet-structure/runtime-benchmarks',45	'pallet-timestamp/runtime-benchmarks',46	'pallet-unique/runtime-benchmarks',47	'pallet-xcm/runtime-benchmarks',48	'sp-runtime/runtime-benchmarks',49	'up-data-structs/runtime-benchmarks',50	'xcm-builder/runtime-benchmarks',51]52std = [53	'codec/std',54	'cumulus-pallet-aura-ext/std',55	'cumulus-pallet-parachain-system/std',56	'cumulus-pallet-xcm/std',57	'cumulus-pallet-xcmp-queue/std',58	'cumulus-primitives-core/std',59	'cumulus-primitives-utility/std',60	'frame-executive/std',61	'frame-support/std',62	'frame-system-rpc-runtime-api/std',63	'frame-system/std',64	'frame-try-runtime/std',65	'pallet-aura/std',66	'pallet-balances/std',67	# 'pallet-contracts/std',68	# 'pallet-contracts-primitives/std',69	# 'pallet-contracts-rpc-runtime-api/std',70	# 'pallet-contract-helpers/std',71	"pallet-preimage/std",72	"pallet-authorship/std",73	"pallet-identity/std",74	"pallet-session/std",75	"sp-consensus-aura/std",76	'app-promotion-rpc/std',77	'evm-coder/std',78	'fp-evm-mapping/std',79	'fp-rpc/std',80	'fp-self-contained/std',81	'pallet-app-promotion/std',82	'pallet-base-fee/std',83	'pallet-charge-transaction/std',84	'pallet-collator-selection/std',85	'pallet-common/std',86	'pallet-configuration/std',87	'pallet-ethereum/std',88	'pallet-evm-coder-substrate/std',89	'pallet-evm-contract-helpers/std',90	'pallet-evm-migration/std',91	'pallet-evm-transaction-payment/std',92	'pallet-evm/std',93	'pallet-fungible/std',94	'pallet-inflation/std',95	'pallet-nonfungible/std',96	'pallet-randomness-collective-flip/std',97	'pallet-refungible/std',98	'pallet-structure/std',99	'pallet-sudo/std',100	'pallet-timestamp/std',101	'pallet-transaction-payment-rpc-runtime-api/std',102	'pallet-transaction-payment/std',103	'pallet-treasury/std',104	'pallet-unique/std',105	'parachain-info/std',106	'sp-api/std',107	'sp-block-builder/std',108	'sp-core/std',109	'sp-inherents/std',110	'sp-io/std',111	'sp-offchain/std',112	'sp-runtime/std',113	'sp-session/std',114	'sp-std/std',115	'sp-transaction-pool/std',116	'sp-version/std',117	'up-common/std',118	'up-data-structs/std',119	'up-pov-estimate-rpc/std',120	'up-rpc/std',121	'up-sponsorship/std',122	'xcm-builder/std',123	'xcm-executor/std',124	'xcm/std',125126	"orml-tokens/std",127	"orml-traits/std",128	"orml-vesting/std",129	"orml-xtokens/std",130	"pallet-foreign-assets/std",131	"pallet-maintenance/std",132]133stubgen = ["evm-coder/stubgen"]134try-runtime = [135	"pallet-authorship/try-runtime",136	"pallet-collator-selection/try-runtime",137	"pallet-identity/try-runtime",138	"pallet-session/try-runtime",139	"pallet-preimage/try-runtime",140	'cumulus-pallet-aura-ext/try-runtime',141	'cumulus-pallet-dmp-queue/try-runtime',142	'cumulus-pallet-parachain-system/try-runtime',143	'cumulus-pallet-xcm/try-runtime',144	'cumulus-pallet-xcmp-queue/try-runtime',145	'fp-self-contained/try-runtime',146	'frame-executive/try-runtime',147	'frame-support/try-runtime',148	'frame-system/try-runtime',149	'frame-try-runtime',150	'orml-tokens/try-runtime',151	'orml-vesting/try-runtime',152	'orml-xtokens/try-runtime',153	'pallet-app-promotion/try-runtime',154	'pallet-aura/try-runtime',155	'pallet-balances/try-runtime',156	'pallet-charge-transaction/try-runtime',157	'pallet-common/try-runtime',158	'pallet-configuration/try-runtime',159	'pallet-ethereum/try-runtime',160	'pallet-evm-coder-substrate/try-runtime',161	'pallet-evm-contract-helpers/try-runtime',162	'pallet-evm-migration/try-runtime',163	'pallet-evm-transaction-payment/try-runtime',164	'pallet-evm/try-runtime',165	'pallet-foreign-assets/try-runtime',166	'pallet-fungible/try-runtime',167	'pallet-inflation/try-runtime',168	'pallet-maintenance/try-runtime',169	'pallet-nonfungible/try-runtime',170	'pallet-randomness-collective-flip/try-runtime',171	'pallet-refungible/try-runtime',172	'pallet-structure/try-runtime',173	'pallet-sudo/try-runtime',174	'pallet-timestamp/try-runtime',175	'pallet-transaction-payment/try-runtime',176	'pallet-treasury/try-runtime',177	'pallet-unique/try-runtime',178	'pallet-xcm/try-runtime',179	'parachain-info/try-runtime',180]181unique-runtime = ['app-promotion', 'foreign-assets', 'refungible']182183app-promotion = []184collator-selection = []185foreign-assets = []186refungible = []187scheduler = []188189################################################################################190# local dependencies191192[dependencies]193# Note: `package = "parity-scale-codec"` must be supplied since the `Encode` macro searches for it.194codec = { workspace = true, package = "parity-scale-codec" }195196cumulus-pallet-aura-ext = { workspace = true }197cumulus-pallet-dmp-queue = { workspace = true }198cumulus-pallet-parachain-system = { workspace = true }199cumulus-pallet-xcm = { workspace = true }200cumulus-pallet-xcmp-queue = { workspace = true }201cumulus-primitives-core = { workspace = true }202cumulus-primitives-timestamp = { workspace = true }203cumulus-primitives-utility = { workspace = true }204frame-executive = { workspace = true }205frame-support = { workspace = true }206frame-system = { workspace = true }207frame-system-rpc-runtime-api = { workspace = true }208orml-tokens = { workspace = true }209orml-traits = { workspace = true }210orml-vesting = { workspace = true }211orml-xtokens = { workspace = true }212pallet-aura = { workspace = true }213pallet-authorship = { workspace = true }214pallet-balances = { workspace = true }215pallet-preimage = { workspace = true }216pallet-randomness-collective-flip = { workspace = true }217pallet-session = { workspace = true }218pallet-sudo = { workspace = true }219pallet-timestamp = { workspace = true }220pallet-transaction-payment = { workspace = true }221pallet-transaction-payment-rpc-runtime-api = { workspace = true }222pallet-treasury = { workspace = true }223pallet-xcm = { workspace = true }224parachain-info = { workspace = true }225polkadot-parachain = { workspace = true }226smallvec = { workspace = true }227sp-api = { workspace = true }228sp-arithmetic = { workspace = true }229sp-block-builder = { workspace = true }230sp-consensus-aura = { workspace = true }231sp-core = { workspace = true }232sp-inherents = { workspace = true }233sp-io = { workspace = true }234sp-offchain = { workspace = true }235sp-runtime = { workspace = true }236sp-session = { workspace = true }237sp-std = { workspace = true }238sp-transaction-pool = { workspace = true }239sp-version = { workspace = true }240xcm = { workspace = true }241xcm-builder = { workspace = true }242xcm-executor = { workspace = true }243244app-promotion-rpc = { workspace = true }245derivative = { workspace = true }246log = { workspace = true }247pallet-app-promotion = { workspace = true }248pallet-collator-selection = { workspace = true }249pallet-common = { workspace = true }250pallet-configuration = { workspace = true }251pallet-fungible = { workspace = true }252pallet-identity = { workspace = true }253pallet-inflation = { workspace = true }254pallet-nonfungible = { workspace = true }255pallet-refungible = { workspace = true }256pallet-structure = { workspace = true }257pallet-unique = { workspace = true }258scale-info = { workspace = true }259up-common = { workspace = true }260up-data-structs = { workspace = true }261up-pov-estimate-rpc = { workspace = true }262up-rpc = { workspace = true }263# pallet-contract-helpers = { path = '../pallets/contract-helpers', default-features = false, version = '0.1.0' }264evm-coder = { workspace = true }265fp-evm = { workspace = true }266fp-evm-mapping = { workspace = true }267fp-rpc = { workspace = true }268fp-self-contained = { workspace = true }269num_enum = { workspace = true }270pallet-base-fee = { workspace = true }271pallet-charge-transaction = { workspace = true }272pallet-ethereum = { workspace = true }273pallet-evm = { workspace = true }274pallet-evm-coder-substrate = { workspace = true }275pallet-evm-contract-helpers = { workspace = true }276pallet-evm-migration = { workspace = true }277pallet-evm-precompile-simple = { workspace = true }278pallet-evm-transaction-payment = { workspace = true }279pallet-foreign-assets = { workspace = true }280pallet-maintenance = { workspace = true }281precompile-utils-macro = { workspace = true }282up-sponsorship = { workspace = true }283284################################################################################285# Optional dependencies286287frame-system-benchmarking = { workspace = true, optional = true }288frame-benchmarking = { workspace = true, optional = true }289frame-try-runtime = { workspace = true, optional = true }290serde = { workspace = true, optional = true }291hex-literal = { workspace = true, optional = true }292293################################################################################294# Test dependencies295296pallet-test-utils = { workspace = true }297298################################################################################299# Other Dependencies300301impl-trait-for-tuples = { workspace = true }302303[dev-dependencies]304logtest = { workspace = true }305306[build-dependencies]307substrate-wasm-builder = { workspace = true }