git.delta.rocks / unique-network / refs/commits / 4efe3bf847ba

difftreelog

Merge pull request #920 from UniqueNetwork/fix/on-runtime-upgrade

Yaroslav Bolyukin2023-04-20parents: #2eecdab #81e4404.patch.diff
in: master

9 files changed

modifiedCargo.lockdiffbeforeafterboth
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -5996,7 +5996,7 @@
 
 [[package]]
 name = "pallet-app-promotion"
-version = "0.1.5"
+version = "0.1.6"
 dependencies = [
  "frame-benchmarking",
  "frame-support",
modifiednode/cli/src/chain_spec.rsdiffbeforeafterboth
before · node/cli/src/chain_spec.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 sc_chain_spec::{ChainSpecExtension, ChainSpecGroup};18use sc_service::ChainType;19use sp_core::{sr25519, Pair, Public};20use sp_runtime::traits::{IdentifyAccount, Verify};21use std::collections::BTreeMap;2223use serde::{Deserialize, Serialize};24use serde_json::map::Map;2526use up_common::types::opaque::*;2728#[cfg(feature = "unique-runtime")]29pub use unique_runtime as default_runtime;3031#[cfg(all(not(feature = "unique-runtime"), feature = "quartz-runtime"))]32pub use quartz_runtime as default_runtime;3334#[cfg(all(not(feature = "unique-runtime"), not(feature = "quartz-runtime")))]35pub use opal_runtime as default_runtime;3637/// The `ChainSpec` parameterized for the unique runtime.38#[cfg(feature = "unique-runtime")]39pub type UniqueChainSpec = sc_service::GenericChainSpec<unique_runtime::GenesisConfig, Extensions>;4041/// The `ChainSpec` parameterized for the quartz runtime.42#[cfg(feature = "quartz-runtime")]43pub type QuartzChainSpec = sc_service::GenericChainSpec<quartz_runtime::GenesisConfig, Extensions>;4445/// The `ChainSpec` parameterized for the opal runtime.46pub type OpalChainSpec = sc_service::GenericChainSpec<opal_runtime::GenesisConfig, Extensions>;4748#[cfg(feature = "unique-runtime")]49pub type DefaultChainSpec = UniqueChainSpec;5051#[cfg(all(not(feature = "unique-runtime"), feature = "quartz-runtime"))]52pub type DefaultChainSpec = QuartzChainSpec;5354#[cfg(all(not(feature = "unique-runtime"), not(feature = "quartz-runtime")))]55pub type DefaultChainSpec = OpalChainSpec;5657#[cfg(not(feature = "unique-runtime"))]58/// PARA_ID for Opal/Sapphire/Quartz59const PARA_ID: u32 = 2095;6061#[cfg(feature = "unique-runtime")]62/// PARA_ID for Unique63const PARA_ID: u32 = 2037;6465pub trait RuntimeIdentification {66	fn runtime_id(&self) -> RuntimeId;67}6869impl RuntimeIdentification for Box<dyn sc_service::ChainSpec> {70	fn runtime_id(&self) -> RuntimeId {71		#[cfg(feature = "unique-runtime")]72		if self.id().starts_with("unique") || self.id().starts_with("unq") {73			return RuntimeId::Unique;74		}7576		#[cfg(feature = "quartz-runtime")]77		if self.id().starts_with("quartz")78			|| self.id().starts_with("qtz")79			|| self.id().starts_with("sapphire")80		{81			return RuntimeId::Quartz;82		}8384		if self.id().starts_with("opal") || self.id() == "dev" || self.id() == "local_testnet" {85			return RuntimeId::Opal;86		}8788		RuntimeId::Unknown(self.id().into())89	}90}9192pub enum ServiceId {93	Prod,94	Dev,95}9697pub trait ServiceIdentification {98	fn service_id(&self) -> ServiceId;99}100101impl ServiceIdentification for Box<dyn sc_service::ChainSpec> {102	fn service_id(&self) -> ServiceId {103		if self.id().ends_with("dev") {104			ServiceId::Dev105		} else {106			ServiceId::Prod107		}108	}109}110111/// Helper function to generate a crypto pair from seed112pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {113	TPublic::Pair::from_string(&format!("//{}", seed), None)114		.expect("static values are valid; qed")115		.public()116}117118/// The extensions for the [`DefaultChainSpec`].119#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, ChainSpecGroup, ChainSpecExtension)]120#[serde(deny_unknown_fields)]121pub struct Extensions {122	/// The relay chain of the Parachain.123	pub relay_chain: String,124	/// The id of the Parachain.125	pub para_id: u32,126}127128impl Extensions {129	/// Try to get the extension from the given `ChainSpec`.130	pub fn try_get(chain_spec: &dyn sc_service::ChainSpec) -> Option<&Self> {131		sc_chain_spec::get_extension(chain_spec.extensions())132	}133}134135type AccountPublic = <Signature as Verify>::Signer;136137/// Helper function to generate an account ID from seed138pub fn get_account_id_from_seed<TPublic: Public>(seed: &str) -> AccountId139where140	AccountPublic: From<<TPublic::Pair as Pair>::Public>,141{142	AccountPublic::from(get_from_seed::<TPublic>(seed)).into_account()143}144145#[cfg(not(feature = "unique-runtime"))]146macro_rules! testnet_genesis {147	(148		$runtime:path,149		$root_key:expr,150		$initial_invulnerables:expr,151		$endowed_accounts:expr,152		$id:expr153	) => {{154		use $runtime::*;155156		GenesisConfig {157			system: SystemConfig {158				code: WASM_BINARY159					.expect("WASM binary was not build, please build it!")160					.to_vec(),161			},162			balances: BalancesConfig {163				balances: $endowed_accounts164					.iter()165					.cloned()166					// 1e13 UNQ167					.map(|k| (k, 1 << 100))168					.collect(),169			},170			treasury: Default::default(),171			tokens: TokensConfig { balances: vec![] },172			sudo: SudoConfig {173				key: Some($root_key),174			},175			vesting: VestingConfig { vesting: vec![] },176			parachain_info: ParachainInfoConfig {177				parachain_id: $id.into(),178			},179			parachain_system: Default::default(),180			collator_selection: CollatorSelectionConfig {181				invulnerables: $initial_invulnerables182					.iter()183					.cloned()184					.map(|(acc, _)| acc)185					.collect(),186			},187			session: SessionConfig {188				keys: $initial_invulnerables189					.into_iter()190					.map(|(acc, aura)| {191						(192							acc.clone(),          // account id193							acc,                  // validator id194							SessionKeys { aura }, // session keys195						)196					})197					.collect(),198			},199			aura: Default::default(),200			aura_ext: Default::default(),201			evm: EVMConfig {202				accounts: BTreeMap::new(),203			},204			ethereum: EthereumConfig {},205			polkadot_xcm: Default::default(),206			transaction_payment: Default::default(),207		}208	}};209}210211#[cfg(feature = "unique-runtime")]212macro_rules! testnet_genesis {213	(214		$runtime:path,215		$root_key:expr,216		$initial_invulnerables:expr,217		$endowed_accounts:expr,218		$id:expr219	) => {{220		use $runtime::*;221222		GenesisConfig {223			system: SystemConfig {224				code: WASM_BINARY225					.expect("WASM binary was not build, please build it!")226					.to_vec(),227			},228			balances: BalancesConfig {229				balances: $endowed_accounts230					.iter()231					.cloned()232					// 1e13 UNQ233					.map(|k| (k, 1 << 100))234					.collect(),235			},236			treasury: Default::default(),237			tokens: TokensConfig { balances: vec![] },238			sudo: SudoConfig {239				key: Some($root_key),240			},241			vesting: VestingConfig { vesting: vec![] },242			parachain_info: ParachainInfoConfig {243				parachain_id: $id.into(),244			},245			parachain_system: Default::default(),246			aura: AuraConfig {247				authorities: $initial_invulnerables248					.into_iter()249					.map(|(_, aura)| aura)250					.collect(),251			},252			aura_ext: Default::default(),253			evm: EVMConfig {254				accounts: BTreeMap::new(),255			},256			ethereum: EthereumConfig {},257			polkadot_xcm: Default::default(),258			transaction_payment: Default::default(),259		}260	}};261}262263pub fn development_config() -> DefaultChainSpec {264	let mut properties = Map::new();265	properties.insert("tokenSymbol".into(), default_runtime::TOKEN_SYMBOL.into());266	properties.insert("tokenDecimals".into(), 18.into());267	properties.insert(268		"ss58Format".into(),269		default_runtime::SS58Prefix::get().into(),270	);271272	DefaultChainSpec::from_genesis(273		// Name274		format!(275			"{}{}",276			default_runtime::RUNTIME_NAME.to_uppercase(),277			if cfg!(feature = "unique-runtime") {278				""279			} else {280				" by UNIQUE"281			}282		)283		.as_str(),284		// ID285		format!("{}_dev", default_runtime::RUNTIME_NAME).as_str(),286		ChainType::Local,287		move || {288			testnet_genesis!(289				default_runtime,290				// Sudo account291				get_account_id_from_seed::<sr25519::Public>("Alice"),292				vec![293					(294						get_account_id_from_seed::<sr25519::Public>("Alice"),295						get_from_seed::<AuraId>("Alice"),296					),297					(298						get_account_id_from_seed::<sr25519::Public>("Bob"),299						get_from_seed::<AuraId>("Bob"),300					),301				],302				// Pre-funded accounts303				vec![304					get_account_id_from_seed::<sr25519::Public>("Alice"),305					get_account_id_from_seed::<sr25519::Public>("Bob"),306					get_account_id_from_seed::<sr25519::Public>("Charlie"),307					get_account_id_from_seed::<sr25519::Public>("Dave"),308					get_account_id_from_seed::<sr25519::Public>("Eve"),309					get_account_id_from_seed::<sr25519::Public>("Ferdie"),310					get_account_id_from_seed::<sr25519::Public>("Alice//stash"),311					get_account_id_from_seed::<sr25519::Public>("Bob//stash"),312					get_account_id_from_seed::<sr25519::Public>("Charlie//stash"),313					get_account_id_from_seed::<sr25519::Public>("Dave//stash"),314					get_account_id_from_seed::<sr25519::Public>("Eve//stash"),315					get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),316				],317				PARA_ID318			)319		},320		// Bootnodes321		vec![],322		// Telemetry323		None,324		// Protocol ID325		None,326		None,327		// Properties328		Some(properties),329		// Extensions330		Extensions {331			relay_chain: "rococo-dev".into(),332			para_id: PARA_ID,333		},334	)335}336337pub fn local_testnet_config() -> DefaultChainSpec {338	let mut properties = Map::new();339	properties.insert("tokenSymbol".into(), default_runtime::TOKEN_SYMBOL.into());340	properties.insert("tokenDecimals".into(), 18.into());341	properties.insert(342		"ss58Format".into(),343		default_runtime::SS58Prefix::get().into(),344	);345346	DefaultChainSpec::from_genesis(347		// Name348		format!(349			"{}{}",350			default_runtime::RUNTIME_NAME.to_uppercase(),351			if cfg!(feature = "unique-runtime") {352				""353			} else {354				" by UNIQUE"355			}356		)357		.as_str(),358		// ID359		format!("{}_local", default_runtime::RUNTIME_NAME).as_str(),360		ChainType::Local,361		move || {362			testnet_genesis!(363				default_runtime,364				// Sudo account365				get_account_id_from_seed::<sr25519::Public>("Alice"),366				vec![367					(368						get_account_id_from_seed::<sr25519::Public>("Alice"),369						get_from_seed::<AuraId>("Alice"),370					),371					(372						get_account_id_from_seed::<sr25519::Public>("Bob"),373						get_from_seed::<AuraId>("Bob"),374					),375				],376				// Pre-funded accounts377				vec![378					get_account_id_from_seed::<sr25519::Public>("Alice"),379					get_account_id_from_seed::<sr25519::Public>("Bob"),380					get_account_id_from_seed::<sr25519::Public>("Charlie"),381					get_account_id_from_seed::<sr25519::Public>("Dave"),382					get_account_id_from_seed::<sr25519::Public>("Eve"),383					get_account_id_from_seed::<sr25519::Public>("Ferdie"),384					get_account_id_from_seed::<sr25519::Public>("Alice//stash"),385					get_account_id_from_seed::<sr25519::Public>("Bob//stash"),386					get_account_id_from_seed::<sr25519::Public>("Charlie//stash"),387					get_account_id_from_seed::<sr25519::Public>("Dave//stash"),388					get_account_id_from_seed::<sr25519::Public>("Eve//stash"),389					get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),390				],391				PARA_ID392			)393		},394		// Bootnodes395		vec![],396		// Telemetry397		None,398		// Protocol ID399		None,400		None,401		// Properties402		Some(properties),403		// Extensions404		Extensions {405			relay_chain: "westend-local".into(),406			para_id: PARA_ID,407		},408	)409}
modifiedpallets/app-promotion/CHANGELOG.mddiffbeforeafterboth
--- a/pallets/app-promotion/CHANGELOG.md
+++ b/pallets/app-promotion/CHANGELOG.md
@@ -3,6 +3,11 @@
 All notable changes to this project will be documented in this file.
 
 <!-- bureaucrate goes here -->
+## [0.1.6] - 2023-04-19
+
+- ### Fixed
+
+- Useless `on_runtime_upgrade()` has been removed
 
 ## [0.1.5] - 2023-02-14
 
modifiedpallets/app-promotion/Cargo.tomldiffbeforeafterboth
--- a/pallets/app-promotion/Cargo.toml
+++ b/pallets/app-promotion/Cargo.toml
@@ -9,7 +9,7 @@
 license = 'GPLv3'
 name = 'pallet-app-promotion'
 repository = 'https://github.com/UniqueNetwork/unique-chain'
-version = '0.1.5'
+version = '0.1.6'
 
 [package.metadata.docs.rs]
 targets = ['x86_64-unknown-linux-gnu']
modifiedpallets/app-promotion/src/lib.rsdiffbeforeafterboth
--- a/pallets/app-promotion/src/lib.rs
+++ b/pallets/app-promotion/src/lib.rs
@@ -263,10 +263,6 @@
 	pub type PreviousCalculatedRecord<T: Config> =
 		StorageValue<Value = (T::AccountId, T::BlockNumber), QueryKind = OptionQuery>;
 
-	#[pallet::storage]
-	pub(crate) type UpgradedToReserves<T: Config> =
-		StorageValue<Value = bool, QueryKind = ValueQuery>;
-
 	#[pallet::hooks]
 	impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
 		/// Block overflow is impossible due to the fact that the unstake algorithm in on_initialize
@@ -289,12 +285,6 @@
 			}
 
 			<T as Config>::WeightInfo::on_initialize(counter)
-		}
-
-		fn on_runtime_upgrade() -> Weight {
-			<UpgradedToReserves<T>>::kill();
-
-			T::DbWeight::get().reads_writes(0, 1)
 		}
 	}
 
modifiedpallets/common/CHANGELOG.mddiffbeforeafterboth
--- a/pallets/common/CHANGELOG.md
+++ b/pallets/common/CHANGELOG.md
@@ -3,7 +3,12 @@
 All notable changes to this project will be documented in this file.
 
 <!-- bureaucrate goes here -->
+## [0.1.14] - 2023-04-19
+
+- ### Fixed
 
+- Useless `on_runtime_upgrade()` has been removed
+
 ## [0.1.14] - 2023-03-28
 
 ### Added
@@ -82,7 +87,7 @@
 However, we don't use prefix removal limits, so upgrade is
 straightforward
 
-Upstream-Change: https://github.com/paritytech/substrate/pull/11490
+Upstream-Change: <https://github.com/paritytech/substrate/pull/11490>
 
 - build: Upgrade polkadot to v0.9.25 cdfb9bdc7b205ff1b5134f034ef9973d769e5e6b
 
modifiedpallets/common/src/lib.rsdiffbeforeafterboth
--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -420,10 +420,11 @@
 
 #[frame_support::pallet]
 pub mod pallet {
+	use core::marker::PhantomData;
+
 	use super::*;
 	use dispatch::CollectionDispatch;
 	use frame_support::{Blake2_128Concat, pallet_prelude::*, storage::Key, traits::StorageVersion};
-	use frame_system::pallet_prelude::*;
 	use frame_support::traits::Currency;
 	use up_data_structs::{TokenId, mapping::TokenAddressMapping};
 	use scale_info::TypeInfo;
@@ -479,6 +480,23 @@
 		}
 	}
 
+	#[pallet::genesis_config]
+	pub struct GenesisConfig<T>(PhantomData<T>);
+
+	#[cfg(feature = "std")]
+	impl<T: Config> Default for GenesisConfig<T> {
+		fn default() -> Self {
+			Self(Default::default())
+		}
+	}
+
+	#[pallet::genesis_build]
+	impl<T: Config> GenesisBuild<T> for GenesisConfig<T> {
+		fn build(&self) {
+			StorageVersion::new(1).put::<Pallet<T>>();
+		}
+	}
+
 	impl<T: Config> Pallet<T> {
 		/// Helper function that handles deposit events
 		pub fn deposit_event(event: Event<T>) {
@@ -869,15 +887,6 @@
 		),
 		QueryKind = OptionQuery,
 	>;
-
-	#[pallet::hooks]
-	impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
-		fn on_runtime_upgrade() -> Weight {
-			StorageVersion::new(1).put::<Pallet<T>>();
-
-			Weight::zero()
-		}
-	}
 }
 
 impl<T: Config> Pallet<T> {
modifiedpallets/nonfungible/CHANGELOG.mddiffbeforeafterboth
--- a/pallets/nonfungible/CHANGELOG.md
+++ b/pallets/nonfungible/CHANGELOG.md
@@ -3,7 +3,12 @@
 All notable changes to this project will be documented in this file.
 
 <!-- bureaucrate goes here -->
+## [0.1.14] - 2023-04-19
+
+- ### Fixed
 
+- Useless `on_runtime_upgrade()` has been removed
+
 ## [0.1.14] - 2023-03-28
 
 ### Fixed
@@ -83,7 +88,7 @@
 However, we don't use prefix removal limits, so upgrade is
 straightforward
 
-Upstream-Change: https://github.com/paritytech/substrate/pull/11490
+Upstream-Change: <https://github.com/paritytech/substrate/pull/11490>
 
 - build: Upgrade polkadot to v0.9.25 cdfb9bdc7b205ff1b5134f034ef9973d769e5e6b
 
modifiedpallets/nonfungible/src/lib.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/lib.rs
+++ b/pallets/nonfungible/src/lib.rs
@@ -283,13 +283,20 @@
 		QueryKind = ValueQuery,
 	>;
 
-	/// Upgrade from the old schema to properties.
-	#[pallet::hooks]
-	impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
-		fn on_runtime_upgrade() -> Weight {
-			StorageVersion::new(1).put::<Pallet<T>>();
+	#[pallet::genesis_config]
+	pub struct GenesisConfig<T>(PhantomData<T>);
 
-			Weight::zero()
+	#[cfg(feature = "std")]
+	impl<T: Config> Default for GenesisConfig<T> {
+		fn default() -> Self {
+			Self(Default::default())
+		}
+	}
+
+	#[pallet::genesis_build]
+	impl<T: Config> GenesisBuild<T> for GenesisConfig<T> {
+		fn build(&self) {
+			StorageVersion::new(1).put::<Pallet<T>>();
 		}
 	}
 }