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

difftreelog

fix remove from_ref_time usages

Yaroslav Bolyukin2023-04-17parent: #07a293d.patch.diff
in: master

9 files changed

modifiedpallets/common/src/dispatch.rsdiffbeforeafterboth
--- a/pallets/common/src/dispatch.rs
+++ b/pallets/common/src/dispatch.rs
@@ -19,7 +19,7 @@
 	// Read collection
 	<T as frame_system::Config>::DbWeight::get().reads(1)
 	// Dynamic dispatch?
-	+ Weight::from_ref_time(6_000_000)
+	+ Weight::from_parts(6_000_000, 0)
 	// submit_logs is measured as part of collection pallets
 }
 
modifiedpallets/common/src/lib.rsdiffbeforeafterboth
--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -92,6 +92,7 @@
 pub mod dispatch;
 pub mod erc;
 pub mod eth;
+#[allow(missing_docs)]
 pub mod weights;
 
 /// Weight info.
@@ -157,10 +158,12 @@
 		reads: u64,
 	) -> pallet_evm_coder_substrate::execution::Result<()> {
 		self.recorder
-			.consume_gas(T::GasWeightMapping::weight_to_gas(Weight::from_ref_time(
+			.consume_gas(T::GasWeightMapping::weight_to_gas(Weight::from_parts(
 				<T as frame_system::Config>::DbWeight::get()
 					.read
 					.saturating_mul(reads),
+				// TODO: measure proof
+				0,
 			)))
 	}
 
@@ -170,10 +173,12 @@
 		writes: u64,
 	) -> pallet_evm_coder_substrate::execution::Result<()> {
 		self.recorder
-			.consume_gas(T::GasWeightMapping::weight_to_gas(Weight::from_ref_time(
+			.consume_gas(T::GasWeightMapping::weight_to_gas(Weight::from_parts(
 				<T as frame_system::Config>::DbWeight::get()
 					.write
 					.saturating_mul(writes),
+				// TODO: measure proof
+				0,
 			)))
 	}
 
@@ -187,8 +192,10 @@
 		let reads = weight.read.saturating_mul(reads);
 		let writes = weight.read.saturating_mul(writes);
 		self.recorder
-			.consume_gas(T::GasWeightMapping::weight_to_gas(Weight::from_ref_time(
+			.consume_gas(T::GasWeightMapping::weight_to_gas(Weight::from_parts(
 				reads.saturating_add(writes),
+				// TODO: measure proof
+				0,
 			)))
 	}
 
modifiedpallets/evm-coder-substrate/src/execution.rsdiffbeforeafterboth
--- a/pallets/evm-coder-substrate/src/execution.rs
+++ b/pallets/evm-coder-substrate/src/execution.rs
@@ -61,7 +61,7 @@
 	fn dispatch_info(&self) -> DispatchInfo {
 		DispatchInfo {
 			// ERC165 impl should be cheap
-			weight: Weight::from_ref_time(200),
+			weight: Weight::from_parts(200, 0),
 		}
 	}
 }
@@ -77,10 +77,11 @@
 		Self { weight }
 	}
 }
+// TODO: use 2-dimensional weight after frontier upgrade
 impl From<u64> for DispatchInfo {
 	fn from(weight: u64) -> Self {
 		Self {
-			weight: Weight::from_ref_time(weight),
+			weight: Weight::from_parts(weight, 0),
 		}
 	}
 }
modifiedpallets/evm-migration/src/lib.rsdiffbeforeafterboth
before · pallets/evm-migration/src/lib.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/>.1617#![doc = include_str!("../README.md")]18#![cfg_attr(not(feature = "std"), no_std)]19#![deny(missing_docs)]2021pub use pallet::*;22#[cfg(feature = "runtime-benchmarks")]23pub mod benchmarking;24pub mod weights;2526#[frame_support::pallet]27pub mod pallet {28	use frame_support::{29		pallet_prelude::{*, DispatchResult},30		traits::IsType,31	};32	use frame_system::pallet_prelude::{*, OriginFor};33	use sp_core::{H160, H256};34	use sp_std::vec::Vec;35	use super::weights::WeightInfo;36	use pallet_evm::{PrecompileHandle, Pallet as PalletEvm};3738	#[pallet::config]39	pub trait Config: frame_system::Config + pallet_evm::Config {40		/// Weights41		type WeightInfo: WeightInfo;42		/// The overarching event type.43		type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;44	}4546	type SelfWeightOf<T> = <T as Config>::WeightInfo;4748	#[pallet::pallet]49	pub struct Pallet<T>(_);5051	#[pallet::event]52	pub enum Event<T: Config> {53		/// This event is used in benchmarking and can be used for tests54		TestEvent,55	}5657	#[pallet::error]58	pub enum Error<T> {59		/// Can only migrate to empty address.60		AccountNotEmpty,61		/// Migration of this account is not yet started, or already finished.62		AccountIsNotMigrating,63		/// Failed to decode event bytes64		BadEvent,65	}6667	#[pallet::storage]68	pub(super) type MigrationPending<T: Config> =69		StorageMap<Hasher = Twox64Concat, Key = H160, Value = bool, QueryKind = ValueQuery>;7071	#[pallet::call]72	impl<T: Config> Pallet<T> {73		/// Start contract migration, inserts contract stub at target address,74		/// and marks account as pending, allowing to insert storage75		#[pallet::call_index(0)]76		#[pallet::weight(<SelfWeightOf<T>>::begin())]77		pub fn begin(origin: OriginFor<T>, address: H160) -> DispatchResult {78			ensure_root(origin)?;79			ensure!(80				<PalletEvm<T>>::is_account_empty(&address) && !<MigrationPending<T>>::get(&address),81				<Error<T>>::AccountNotEmpty,82			);8384			<MigrationPending<T>>::insert(address, true);85			Ok(())86		}8788		/// Insert items into contract storage, this method can be called89		/// multiple times90		#[pallet::call_index(1)]91		#[pallet::weight(<SelfWeightOf<T>>::set_data(data.len() as u32))]92		pub fn set_data(93			origin: OriginFor<T>,94			address: H160,95			data: Vec<(H256, H256)>,96		) -> DispatchResult {97			ensure_root(origin)?;98			ensure!(99				<MigrationPending<T>>::get(&address),100				<Error<T>>::AccountIsNotMigrating,101			);102103			for (k, v) in data {104				<pallet_evm::AccountStorages<T>>::insert(&address, k, v);105			}106			Ok(())107		}108109		/// Finish contract migration, allows it to be called.110		/// It is not possible to alter contract storage via [`Self::set_data`]111		/// after this call.112		#[pallet::call_index(2)]113		#[pallet::weight(<SelfWeightOf<T>>::finish(code.len() as u32))]114		pub fn finish(origin: OriginFor<T>, address: H160, code: Vec<u8>) -> DispatchResult {115			ensure_root(origin)?;116			ensure!(117				<MigrationPending<T>>::get(&address),118				<Error<T>>::AccountIsNotMigrating,119			);120121			<pallet_evm::AccountCodes<T>>::insert(&address, code);122			<MigrationPending<T>>::remove(address);123			Ok(())124		}125126		/// Create ethereum events attached to the fake transaction127		#[pallet::call_index(3)]128		#[pallet::weight(<SelfWeightOf<T>>::insert_eth_logs(logs.len() as u32))]129		pub fn insert_eth_logs(origin: OriginFor<T>, logs: Vec<ethereum::Log>) -> DispatchResult {130			ensure_root(origin)?;131			for log in logs {132				<pallet_evm::Pallet<T>>::deposit_log(log);133			}134			// Transactions is created by FakeTransactionFinalizer135			Ok(())136		}137138		/// Create substrate events139		#[pallet::call_index(4)]140		#[pallet::weight(<SelfWeightOf<T>>::insert_events(events.len() as u32))]141		pub fn insert_events(origin: OriginFor<T>, events: Vec<Vec<u8>>) -> DispatchResult {142			ensure_root(origin)?;143			for event in events {144				<frame_system::Pallet<T>>::deposit_event(145					<T as frame_system::Config>::RuntimeEvent::decode(&mut event.as_slice())146						.map_err(|_| <Error<T>>::BadEvent)?,147				);148			}149			Ok(())150		}151152		/// Remove remark compatibility data leftovers153		#[pallet::call_index(5)]154		#[pallet::weight(<T as frame_system::Config>::DbWeight::get().reads_writes(10, 10))]155		pub fn remove_rmrk_data(origin: OriginFor<T>) -> DispatchResult {156			use sp_io::hashing::twox_128;157			ensure_root(origin)?;158			let _ = sp_io::storage::clear_prefix(&twox_128(b"RmrkEquip"), Some(5));159			let _ = sp_io::storage::clear_prefix(&twox_128(b"RmrkCore"), Some(5));160			Ok(())161		}162	}163164	/// Implements [`pallet_evm::OnMethodCall`], which reserves accounts with pending migration165	pub struct OnMethodCall<T>(PhantomData<T>);166	impl<T: Config> pallet_evm::OnMethodCall<T> for OnMethodCall<T> {167		fn is_reserved(contract: &H160) -> bool {168			<MigrationPending<T>>::get(&contract)169		}170171		fn is_used(_contract: &H160) -> bool {172			false173		}174175		fn call(_handle: &mut impl PrecompileHandle) -> Option<pallet_evm::PrecompileResult> {176			None177		}178179		fn get_code(_contract: &H160) -> Option<Vec<u8>> {180			None181		}182	}183}
after · pallets/evm-migration/src/lib.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/>.1617#![doc = include_str!("../README.md")]18#![cfg_attr(not(feature = "std"), no_std)]19#![deny(missing_docs)]2021pub use pallet::*;22#[cfg(feature = "runtime-benchmarks")]23pub mod benchmarking;24#[allow(missing_docs)]25pub mod weights;2627#[frame_support::pallet]28pub mod pallet {29	use frame_support::{30		pallet_prelude::{*, DispatchResult},31		traits::IsType,32	};33	use frame_system::pallet_prelude::{*, OriginFor};34	use sp_core::{H160, H256};35	use sp_std::vec::Vec;36	use super::weights::WeightInfo;37	use pallet_evm::{PrecompileHandle, Pallet as PalletEvm};3839	#[pallet::config]40	pub trait Config: frame_system::Config + pallet_evm::Config {41		/// Weights42		type WeightInfo: WeightInfo;43		/// The overarching event type.44		type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;45	}4647	type SelfWeightOf<T> = <T as Config>::WeightInfo;4849	#[pallet::pallet]50	pub struct Pallet<T>(_);5152	#[pallet::event]53	pub enum Event<T: Config> {54		/// This event is used in benchmarking and can be used for tests55		TestEvent,56	}5758	#[pallet::error]59	pub enum Error<T> {60		/// Can only migrate to empty address.61		AccountNotEmpty,62		/// Migration of this account is not yet started, or already finished.63		AccountIsNotMigrating,64		/// Failed to decode event bytes65		BadEvent,66	}6768	#[pallet::storage]69	pub(super) type MigrationPending<T: Config> =70		StorageMap<Hasher = Twox64Concat, Key = H160, Value = bool, QueryKind = ValueQuery>;7172	#[pallet::call]73	impl<T: Config> Pallet<T> {74		/// Start contract migration, inserts contract stub at target address,75		/// and marks account as pending, allowing to insert storage76		#[pallet::call_index(0)]77		#[pallet::weight(<SelfWeightOf<T>>::begin())]78		pub fn begin(origin: OriginFor<T>, address: H160) -> DispatchResult {79			ensure_root(origin)?;80			ensure!(81				<PalletEvm<T>>::is_account_empty(&address) && !<MigrationPending<T>>::get(&address),82				<Error<T>>::AccountNotEmpty,83			);8485			<MigrationPending<T>>::insert(address, true);86			Ok(())87		}8889		/// Insert items into contract storage, this method can be called90		/// multiple times91		#[pallet::call_index(1)]92		#[pallet::weight(<SelfWeightOf<T>>::set_data(data.len() as u32))]93		pub fn set_data(94			origin: OriginFor<T>,95			address: H160,96			data: Vec<(H256, H256)>,97		) -> DispatchResult {98			ensure_root(origin)?;99			ensure!(100				<MigrationPending<T>>::get(&address),101				<Error<T>>::AccountIsNotMigrating,102			);103104			for (k, v) in data {105				<pallet_evm::AccountStorages<T>>::insert(&address, k, v);106			}107			Ok(())108		}109110		/// Finish contract migration, allows it to be called.111		/// It is not possible to alter contract storage via [`Self::set_data`]112		/// after this call.113		#[pallet::call_index(2)]114		#[pallet::weight(<SelfWeightOf<T>>::finish(code.len() as u32))]115		pub fn finish(origin: OriginFor<T>, address: H160, code: Vec<u8>) -> DispatchResult {116			ensure_root(origin)?;117			ensure!(118				<MigrationPending<T>>::get(&address),119				<Error<T>>::AccountIsNotMigrating,120			);121122			<pallet_evm::AccountCodes<T>>::insert(&address, code);123			<MigrationPending<T>>::remove(address);124			Ok(())125		}126127		/// Create ethereum events attached to the fake transaction128		#[pallet::call_index(3)]129		#[pallet::weight(<SelfWeightOf<T>>::insert_eth_logs(logs.len() as u32))]130		pub fn insert_eth_logs(origin: OriginFor<T>, logs: Vec<ethereum::Log>) -> DispatchResult {131			ensure_root(origin)?;132			for log in logs {133				<pallet_evm::Pallet<T>>::deposit_log(log);134			}135			// Transactions is created by FakeTransactionFinalizer136			Ok(())137		}138139		/// Create substrate events140		#[pallet::call_index(4)]141		#[pallet::weight(<SelfWeightOf<T>>::insert_events(events.len() as u32))]142		pub fn insert_events(origin: OriginFor<T>, events: Vec<Vec<u8>>) -> DispatchResult {143			ensure_root(origin)?;144			for event in events {145				<frame_system::Pallet<T>>::deposit_event(146					<T as frame_system::Config>::RuntimeEvent::decode(&mut event.as_slice())147						.map_err(|_| <Error<T>>::BadEvent)?,148				);149			}150			Ok(())151		}152153		/// Remove remark compatibility data leftovers154		#[pallet::call_index(5)]155		#[pallet::weight(<T as frame_system::Config>::DbWeight::get().reads_writes(10, 10))]156		pub fn remove_rmrk_data(origin: OriginFor<T>) -> DispatchResult {157			use sp_io::hashing::twox_128;158			ensure_root(origin)?;159			let _ = sp_io::storage::clear_prefix(&twox_128(b"RmrkEquip"), Some(5));160			let _ = sp_io::storage::clear_prefix(&twox_128(b"RmrkCore"), Some(5));161			Ok(())162		}163	}164165	/// Implements [`pallet_evm::OnMethodCall`], which reserves accounts with pending migration166	pub struct OnMethodCall<T>(PhantomData<T>);167	impl<T: Config> pallet_evm::OnMethodCall<T> for OnMethodCall<T> {168		fn is_reserved(contract: &H160) -> bool {169			<MigrationPending<T>>::get(&contract)170		}171172		fn is_used(_contract: &H160) -> bool {173			false174		}175176		fn call(_handle: &mut impl PrecompileHandle) -> Option<pallet_evm::PrecompileResult> {177			None178		}179180		fn get_code(_contract: &H160) -> Option<Vec<u8>> {181			None182		}183	}184}
modifiedpallets/unique/src/benchmarking.rsdiffbeforeafterboth
--- a/pallets/unique/src/benchmarking.rs
+++ b/pallets/unique/src/benchmarking.rs
@@ -26,6 +26,11 @@
 	Config as CommonConfig,
 	benchmarking::{create_data, create_u16_data},
 };
+use up_data_structs::{
+	CollectionId, CollectionMode, MAX_COLLECTION_NAME_LENGTH, MAX_TOKEN_PREFIX_LENGTH,
+	MAX_COLLECTION_DESCRIPTION_LENGTH, CollectionLimits,
+};
+use pallet_common::erc::CrossAccountId;
 
 const SEED: u32 = 1;
 
@@ -34,9 +39,9 @@
 	mode: CollectionMode,
 ) -> Result<CollectionId, DispatchError> {
 	<T as CommonConfig>::Currency::deposit_creating(&owner, T::CollectionCreationPrice::get());
-	let col_name = create_u16_data::<MAX_COLLECTION_NAME_LENGTH>();
-	let col_desc = create_u16_data::<MAX_COLLECTION_DESCRIPTION_LENGTH>();
-	let token_prefix = create_data::<MAX_TOKEN_PREFIX_LENGTH>();
+	let col_name = create_u16_data::<{ MAX_COLLECTION_NAME_LENGTH }>();
+	let col_desc = create_u16_data::<{ MAX_COLLECTION_DESCRIPTION_LENGTH }>();
+	let token_prefix = create_data::<{ MAX_TOKEN_PREFIX_LENGTH }>();
 	<Pallet<T>>::create_collection(
 		RawOrigin::Signed(owner).into(),
 		col_name,
@@ -54,9 +59,9 @@
 
 benchmarks! {
 	create_collection {
-		let col_name = create_u16_data::<MAX_COLLECTION_NAME_LENGTH>();
-		let col_desc = create_u16_data::<MAX_COLLECTION_DESCRIPTION_LENGTH>();
-		let token_prefix = create_data::<MAX_TOKEN_PREFIX_LENGTH>();
+		let col_name = create_u16_data::<{MAX_COLLECTION_NAME_LENGTH}>();
+		let col_desc = create_u16_data::<{MAX_COLLECTION_DESCRIPTION_LENGTH}>();
+		let token_prefix = create_data::<{MAX_TOKEN_PREFIX_LENGTH}>();
 		let mode: CollectionMode = CollectionMode::NFT;
 		let caller: T::AccountId = account("caller", 0, SEED);
 		<T as CommonConfig>::Currency::deposit_creating(&caller, T::CollectionCreationPrice::get());
modifiedpallets/unique/src/lib.rsdiffbeforeafterboth
--- a/pallets/unique/src/lib.rs
+++ b/pallets/unique/src/lib.rs
@@ -89,14 +89,11 @@
 	use frame_support::{
 		dispatch::DispatchResult,
 		ensure, fail,
-		weights::{Weight},
-		pallet_prelude::{*},
 		BoundedVec,
 		storage::Key,
 	};
-	use frame_system::pallet_prelude::*;
 	use scale_info::TypeInfo;
-	use frame_system::{self as system, ensure_signed, ensure_root};
+	use frame_system::{ensure_signed, ensure_root};
 	use sp_std::{vec, vec::Vec};
 	use up_data_structs::{
 		MAX_COLLECTION_NAME_LENGTH, MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_TOKEN_PREFIX_LENGTH,
modifiedprimitives/common/src/constants.rsdiffbeforeafterboth
--- a/primitives/common/src/constants.rs
+++ b/primitives/common/src/constants.rs
@@ -64,9 +64,10 @@
 /// by  Operational  extrinsics.
 pub const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
 /// We allow for 2 seconds of compute with a 6 second average block time.
-pub const MAXIMUM_BLOCK_WEIGHT: Weight =
-	Weight::from_ref_time(WEIGHT_REF_TIME_PER_SECOND.saturating_div(2))
-		.set_proof_size(MAX_POV_SIZE as u64);
+pub const MAXIMUM_BLOCK_WEIGHT: Weight = Weight::from_parts(
+	WEIGHT_REF_TIME_PER_SECOND.saturating_div(2),
+	MAX_POV_SIZE as u64,
+);
 
 parameter_types! {
 	pub const TransactionByteFee: Balance = 501 * MICROUNIQUE / 2;
modifiedruntime/common/config/ethereum.rsdiffbeforeafterboth
--- a/runtime/common/config/ethereum.rs
+++ b/runtime/common/config/ethereum.rs
@@ -28,7 +28,7 @@
 	pub const GasPerSecond: u64 = WritesPerSecond::get() * 20000;
 	pub const WeightTimePerGas: u64 = WEIGHT_REF_TIME_PER_SECOND / GasPerSecond::get();
 
-	pub const WeightPerGas: Weight = Weight::from_ref_time(WeightTimePerGas::get());
+	pub const WeightPerGas: Weight = Weight::from_parts(WeightTimePerGas::get(), 0);
 }
 
 /// Limiting EVM execution to 50% of block for substrate users and management tasks
modifiedruntime/common/mod.rsdiffbeforeafterboth
--- a/runtime/common/mod.rs
+++ b/runtime/common/mod.rs
@@ -27,6 +27,7 @@
 pub mod scheduler;
 
 pub mod sponsoring;
+#[allow(missing_docs)]
 pub mod weights;
 
 #[cfg(test)]
@@ -152,7 +153,7 @@
 	}
 	#[cfg(feature = "runtime-benchmarks")]
 	fn set_block_number(block: Self::BlockNumber) {
-		cumulus_pallet_parachain_system::RelaychainBlockNumberProvider::<T>::set_block_number(block)
+		cumulus_pallet_parachain_system::RelaychainDataProvider::<T>::set_block_number(block)
 	}
 }