git.delta.rocks / unique-network / refs/commits / 1b80f30d6749

difftreelog

Transaction payment and weights fix

str-mv2020-10-29parent: #e85b652.patch.diff
in: master

4 files changed

addedpallets/nft/src/default_weights.rsdiffbeforeafterboth
--- /dev/null
+++ b/pallets/nft/src/default_weights.rs
@@ -0,0 +1,95 @@
+use frame_support::weights::{Weight, constants::RocksDbWeight as DbWeight};
+
+impl crate::WeightInfo for () {
+	fn create_collection() -> Weight {
+		(70_000_000 as Weight)
+			.saturating_add(DbWeight::get().reads(7 as Weight))
+			.saturating_add(DbWeight::get().writes(5 as Weight))
+	}
+	fn destroy_collection() -> Weight {
+		(90_000_000 as Weight)
+			.saturating_add(DbWeight::get().reads(2 as Weight))
+			.saturating_add(DbWeight::get().writes(5 as Weight))
+	}
+	fn add_to_white_list() -> Weight {
+		(30_000_000 as Weight)
+			.saturating_add(DbWeight::get().reads(3 as Weight))
+			.saturating_add(DbWeight::get().writes(1 as Weight))
+    }
+    fn remove_from_white_list() -> Weight {
+		(35_000_000 as Weight)
+			.saturating_add(DbWeight::get().reads(3 as Weight))
+			.saturating_add(DbWeight::get().writes(1 as Weight))
+	}
+	fn set_public_access_mode() -> Weight {
+		(27_000_000 as Weight)
+			.saturating_add(DbWeight::get().reads(1 as Weight))
+			.saturating_add(DbWeight::get().writes(1 as Weight))
+	}
+	fn set_mint_permission() -> Weight {
+		(27_000_000 as Weight)
+			.saturating_add(DbWeight::get().reads(1 as Weight))
+			.saturating_add(DbWeight::get().writes(1 as Weight))
+	}
+	fn change_collection_owner() -> Weight {
+		(27_000_000 as Weight)
+			.saturating_add(DbWeight::get().reads(1 as Weight))
+			.saturating_add(DbWeight::get().writes(1 as Weight))
+	}
+	fn add_collection_admin() -> Weight {
+        (32_000_000 as Weight)
+            .saturating_add(DbWeight::get().reads(3 as Weight))
+            .saturating_add(DbWeight::get().writes(1 as Weight))
+	}
+	fn remove_collection_admin() -> Weight {
+		(50_000_000 as Weight)
+            .saturating_add(DbWeight::get().reads(2 as Weight))
+            .saturating_add(DbWeight::get().writes(1 as Weight))
+    }
+    fn set_collection_sponsor() -> Weight {
+		(32_000_000 as Weight)
+            .saturating_add(DbWeight::get().reads(2 as Weight))
+            .saturating_add(DbWeight::get().writes(1 as Weight))
+    }  
+    fn confirm_sponsorship() -> Weight {
+		(22_000_000 as Weight)
+            .saturating_add(DbWeight::get().reads(1 as Weight))
+            .saturating_add(DbWeight::get().writes(1 as Weight))
+    }  
+    fn remove_collection_sponsor() -> Weight {
+		(24_000_000 as Weight)
+            .saturating_add(DbWeight::get().reads(1 as Weight))
+            .saturating_add(DbWeight::get().writes(1 as Weight))
+    }  
+    fn create_item(s: usize, ) -> Weight {
+        (130_000_000 as Weight)
+            .saturating_add((2135 as Weight).saturating_mul(s as Weight))
+            .saturating_add(DbWeight::get().reads(10 as Weight))
+            .saturating_add(DbWeight::get().writes(8 as Weight))
+    }  
+    fn burn_item() -> Weight {
+		(170_000_000 as Weight)
+            .saturating_add(DbWeight::get().reads(9 as Weight))
+            .saturating_add(DbWeight::get().writes(7 as Weight))
+    }  
+    fn transfer() -> Weight {
+        (125_000_000 as Weight)
+            .saturating_add(DbWeight::get().reads(7 as Weight))
+            .saturating_add(DbWeight::get().writes(7 as Weight))
+    }  
+    fn approve() -> Weight {
+        (45_000_000 as Weight)
+            .saturating_add(DbWeight::get().reads(3 as Weight))
+            .saturating_add(DbWeight::get().writes(1 as Weight))
+    }
+    fn transfer_from() -> Weight {
+        (150_000_000 as Weight)
+            .saturating_add(DbWeight::get().reads(9 as Weight))
+            .saturating_add(DbWeight::get().writes(8 as Weight))
+    }
+    fn set_offchain_schema() -> Weight {
+        (33_000_000 as Weight)
+            .saturating_add(DbWeight::get().reads(2 as Weight))
+            .saturating_add(DbWeight::get().writes(1 as Weight))
+    }
+}
modifiedpallets/nft/src/lib.rsdiffbeforeafterboth
--- a/pallets/nft/src/lib.rs
+++ b/pallets/nft/src/lib.rs
@@ -44,6 +44,8 @@
 #[cfg(test)]
 mod tests;
 
+mod default_weights;
+
 // Structs
 // #region
 
@@ -182,8 +184,32 @@
     pub refungible_sponsor_transfer_timeout: u32,
 }
 
-pub trait Trait: system::Trait {
+pub trait WeightInfo {
+	fn create_collection() -> Weight;
+	fn destroy_collection() -> Weight;
+	fn add_to_white_list() -> Weight;
+	fn remove_from_white_list() -> Weight;
+    fn set_public_access_mode() -> Weight;
+    fn set_mint_permission() -> Weight;
+    fn change_collection_owner() -> Weight;
+    fn add_collection_admin() -> Weight;
+    fn remove_collection_admin() -> Weight;
+    fn set_collection_sponsor() -> Weight;
+    fn confirm_sponsorship() -> Weight;
+    fn remove_collection_sponsor() -> Weight;
+    fn create_item(s: usize, ) -> Weight;
+    fn burn_item() -> Weight;
+    fn transfer() -> Weight;
+    fn approve() -> Weight;
+    fn transfer_from() -> Weight;
+    fn set_offchain_schema() -> Weight;
+}
+
+pub trait Trait: system::Trait + Sized  {
     type Event: From<Event<Self>> + Into<<Self as system::Trait>::Event>;
+
+    /// Weight information for extrinsics in this pallet.
+	type WeightInfo: WeightInfo;
 }
 
 #[cfg(feature = "runtime-benchmarks")]
@@ -326,10 +352,7 @@
         /// 
         /// * mode: [CollectionMode] collection type and type dependent data.
         // returns collection ID
-        #[weight =
-        (70_000_000 as Weight)
-        .saturating_add(RocksDbWeight::get().reads(7 as Weight))
-        .saturating_add(RocksDbWeight::get().writes(5 as Weight))]
+        #[weight = T::WeightInfo::create_collection()]
         pub fn create_collection(origin,
                                  collection_name: Vec<u16>,
                                  collection_description: Vec<u16>,
@@ -425,10 +448,7 @@
         /// # Arguments
         /// 
         /// * collection_id: collection to destroy.
-        #[weight =
-        (90_000_000 as Weight)
-        .saturating_add(RocksDbWeight::get().reads(2 as Weight))
-        .saturating_add(RocksDbWeight::get().writes(5 as Weight))]
+        #[weight = T::WeightInfo::destroy_collection()]
         pub fn destroy_collection(origin, collection_id: u64) -> DispatchResult {
 
             let sender = ensure_signed(origin)?;
@@ -475,10 +495,7 @@
         /// * collection_id.
         /// 
         /// * address.
-        #[weight =
-        (30_000_000 as Weight)
-        .saturating_add(RocksDbWeight::get().reads(3 as Weight))
-        .saturating_add(RocksDbWeight::get().writes(1 as Weight))]
+        #[weight = T::WeightInfo::add_to_white_list()]
         pub fn add_to_white_list(origin, collection_id: u64, address: T::AccountId) -> DispatchResult{
 
             let sender = ensure_signed(origin)?;
@@ -513,10 +530,7 @@
         /// * collection_id.
         /// 
         /// * address.
-        #[weight =
-        (35_000_000 as Weight)
-        .saturating_add(RocksDbWeight::get().reads(3 as Weight))
-        .saturating_add(RocksDbWeight::get().writes(1 as Weight))]
+        #[weight = T::WeightInfo::remove_from_white_list()]
         pub fn remove_from_white_list(origin, collection_id: u64, address: T::AccountId) -> DispatchResult{
 
             let sender = ensure_signed(origin)?;
@@ -545,10 +559,7 @@
         /// * collection_id.
         /// 
         /// * mode: [AccessMode]
-        #[weight =
-        (27_000_000 as Weight)
-        .saturating_add(RocksDbWeight::get().reads(1 as Weight))
-        .saturating_add(RocksDbWeight::get().writes(1 as Weight))]
+        #[weight = T::WeightInfo::set_public_access_mode()]
         pub fn set_public_access_mode(origin, collection_id: u64, mode: AccessMode) -> DispatchResult
         {
             let sender = ensure_signed(origin)?;
@@ -574,10 +585,7 @@
         /// * collection_id.
         /// 
         /// * mint_permission: Boolean parameter. If True, allows minting to Anyone with conditions above.
-        #[weight =
-        (27_000_000 as Weight)
-        .saturating_add(RocksDbWeight::get().reads(1 as Weight))
-        .saturating_add(RocksDbWeight::get().writes(1 as Weight))]
+        #[weight = T::WeightInfo::set_mint_permission()]
         pub fn set_mint_permission(origin, collection_id: u64, mint_permission: bool) -> DispatchResult
         {
             let sender = ensure_signed(origin)?;
@@ -601,10 +609,7 @@
         /// * collection_id.
         /// 
         /// * new_owner.
-        #[weight =
-        (27_000_000 as Weight)
-        .saturating_add(RocksDbWeight::get().reads(1 as Weight))
-        .saturating_add(RocksDbWeight::get().writes(1 as Weight))]
+        #[weight = T::WeightInfo::change_collection_owner()]
         pub fn change_collection_owner(origin, collection_id: u64, new_owner: T::AccountId) -> DispatchResult {
 
             let sender = ensure_signed(origin)?;
@@ -629,10 +634,7 @@
         /// * collection_id: ID of the Collection to add admin for.
         /// 
         /// * new_admin_id: Address of new admin to add.
-        #[weight =
-        (32_000_000 as Weight)
-        .saturating_add(RocksDbWeight::get().reads(3 as Weight))
-        .saturating_add(RocksDbWeight::get().writes(1 as Weight))]
+        #[weight = T::WeightInfo::add_collection_admin()]
         pub fn add_collection_admin(origin, collection_id: u64, new_admin_id: T::AccountId) -> DispatchResult {
 
             let sender = ensure_signed(origin)?;
@@ -666,10 +668,7 @@
         /// * collection_id: ID of the Collection to remove admin for.
         /// 
         /// * account_id: Address of admin to remove.
-        #[weight =
-        (50_000_000 as Weight)
-        .saturating_add(RocksDbWeight::get().reads(2 as Weight))
-        .saturating_add(RocksDbWeight::get().writes(1 as Weight))]
+        #[weight = T::WeightInfo::remove_collection_admin()]
         pub fn remove_collection_admin(origin, collection_id: u64, account_id: T::AccountId) -> DispatchResult {
 
             let sender = ensure_signed(origin)?;
@@ -694,10 +693,7 @@
         /// * collection_id.
         /// 
         /// * new_sponsor.
-        #[weight =
-        (32_000_000 as Weight)
-        .saturating_add(RocksDbWeight::get().reads(2 as Weight))
-        .saturating_add(RocksDbWeight::get().writes(1 as Weight))]
+        #[weight = T::WeightInfo::set_collection_sponsor()]
         pub fn set_collection_sponsor(origin, collection_id: u64, new_sponsor: T::AccountId) -> DispatchResult {
 
             let sender = ensure_signed(origin)?;
@@ -719,10 +715,7 @@
         /// # Arguments
         /// 
         /// * collection_id.
-        #[weight =
-        (22_000_000 as Weight)
-        .saturating_add(RocksDbWeight::get().reads(1 as Weight))
-        .saturating_add(RocksDbWeight::get().writes(1 as Weight))]
+        #[weight = T::WeightInfo::confirm_sponsorship()]
         pub fn confirm_sponsorship(origin, collection_id: u64) -> DispatchResult {
 
             let sender = ensure_signed(origin)?;
@@ -747,10 +740,7 @@
         /// # Arguments
         /// 
         /// * collection_id.
-        #[weight =
-        (24_000_000 as Weight)
-        .saturating_add(RocksDbWeight::get().reads(1 as Weight))
-        .saturating_add(RocksDbWeight::get().writes(1 as Weight))]
+        #[weight = T::WeightInfo::remove_collection_sponsor()]
         pub fn remove_collection_sponsor(origin, collection_id: u64) -> DispatchResult {
 
             let sender = ensure_signed(origin)?;
@@ -783,11 +773,13 @@
         /// * properties: Array of bytes that contains NFT properties. Since NFT Module is agnostic of properties meaning, it is treated purely as an array of bytes.
         /// 
         /// * owner: Address, initial owner of the NFT.
-        #[weight =
-        (130_000_000 as Weight)
-        .saturating_add((2135 as Weight).saturating_mul((properties.len() as u64) as Weight))
-        .saturating_add(RocksDbWeight::get().reads(10 as Weight))
-        .saturating_add(RocksDbWeight::get().writes(8 as Weight))]
+        // #[weight =
+        // (130_000_000 as Weight)
+        // .saturating_add((2135 as Weight).saturating_mul((properties.len() as u64) as Weight))
+        // .saturating_add(RocksDbWeight::get().reads(10 as Weight))
+        // .saturating_add(RocksDbWeight::get().writes(8 as Weight))]
+
+        #[weight = T::WeightInfo::create_item(properties.len())]
         pub fn create_item(origin, collection_id: u64, properties: Vec<u8>, owner: T::AccountId) -> DispatchResult {
 
             let sender = ensure_signed(origin)?;
@@ -870,10 +862,7 @@
         /// * collection_id: ID of the collection.
         /// 
         /// * item_id: ID of NFT to burn.
-        #[weight =
-        (170_000_000 as Weight)
-        .saturating_add(RocksDbWeight::get().reads(9 as Weight))
-        .saturating_add(RocksDbWeight::get().writes(7 as Weight))]
+        #[weight = T::WeightInfo::burn_item()]
         pub fn burn_item(origin, collection_id: u64, item_id: u64) -> DispatchResult {
 
             let sender = ensure_signed(origin)?;
@@ -926,10 +915,7 @@
         ///     * Non-Fungible Mode: Ignored
         ///     * Fungible Mode: Must specify transferred amount
         ///     * Re-Fungible Mode: Must specify transferred portion (between 0 and 1)
-        #[weight =
-        (125_000_000 as Weight)
-        .saturating_add(RocksDbWeight::get().reads(7 as Weight))
-        .saturating_add(RocksDbWeight::get().writes(7 as Weight))]
+        #[weight = T::WeightInfo::transfer()]
         pub fn transfer(origin, recipient: T::AccountId, collection_id: u64, item_id: u64, value: u64) -> DispatchResult {
 
             let sender = ensure_signed(origin)?;
@@ -971,10 +957,7 @@
         /// * collection_id.
         /// 
         /// * item_id: ID of the item.
-        #[weight =
-        (45_000_000 as Weight)
-        .saturating_add(RocksDbWeight::get().reads(3 as Weight))
-        .saturating_add(RocksDbWeight::get().writes(1 as Weight))]
+        #[weight = T::WeightInfo::approve()]
         pub fn approve(origin, approved: T::AccountId, collection_id: u64, item_id: u64) -> DispatchResult {
 
             let sender = ensure_signed(origin)?;
@@ -1032,10 +1015,7 @@
         /// * item_id: ID of the item.
         /// 
         /// * value: Amount to transfer.
-        #[weight =
-        (150_000_000 as Weight)
-        .saturating_add(RocksDbWeight::get().reads(9 as Weight))
-        .saturating_add(RocksDbWeight::get().writes(8 as Weight))]
+        #[weight = T::WeightInfo::transfer_from()]
         pub fn transfer_from(origin, from: T::AccountId, recipient: T::AccountId, collection_id: u64, item_id: u64, value: u64 ) -> DispatchResult {
 
             let sender = ensure_signed(origin)?;
@@ -1107,10 +1087,7 @@
         /// * collection_id.
         /// 
         /// * schema: String representing the offchain data schema.
-        #[weight =
-        (33_000_000 as Weight)
-        .saturating_add(RocksDbWeight::get().reads(2 as Weight))
-        .saturating_add(RocksDbWeight::get().writes(1 as Weight))]
+        #[weight = T::WeightInfo::set_offchain_schema()]
         pub fn set_offchain_schema(
             origin,
             collection_id: u64,
modifiedruntime/src/lib.rsdiffbeforeafterboth
--- a/runtime/src/lib.rs
+++ b/runtime/src/lib.rs
@@ -84,6 +84,7 @@
 /// Digest item type.
 pub type DigestItem = generic::DigestItem<Hash>;
 
+mod nft_weights;
 
 /// Opaque types. These are used by the CLI to instantiate machinery that don't need to know
 /// the specifics of the runtime. They can then be made to be agnostic over specific formats
@@ -144,9 +145,12 @@
     pub const MaximumBlockWeight: Weight = 2 * WEIGHT_PER_SECOND;
     pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);
     /// Assume 10% of weight for average on_initialize calls.
-    pub MaximumExtrinsicWeight: Weight = AvailableBlockRatio::get()
-        .saturating_sub(Perbill::from_percent(10)) * MaximumBlockWeight::get();
-    pub const MaximumBlockLength: u32 = 5 * 1024 * 1024;
+    // pub MaximumExtrinsicWeight: Weight = AvailableBlockRatio::get()
+    //     .saturating_sub(Perbill::from_percent(10)) * MaximumBlockWeight::get();
+
+    pub MaximumExtrinsicWeight: Weight = 4_294_967_295; 
+    //pub const MaximumBlockLength: u32 = 5 * 1024 * 1024;
+    pub const MaximumBlockLength: u32 = 4_294_967_295;
     pub const Version: RuntimeVersion = VERSION;
 }
 
@@ -291,7 +295,7 @@
 }
 
 parameter_types! {
-    pub const TransactionByteFee: Balance = 1;
+	pub const TransactionByteFee: Balance = 10 * MILLICENTS;
 }
 
 impl pallet_transaction_payment::Trait for Runtime {
@@ -299,7 +303,7 @@
     type OnTransactionPayment = ();
     type TransactionByteFee = TransactionByteFee;
     type WeightToFee = IdentityFee<Balance>;
-    type FeeMultiplierUpdate = ();
+    type FeeMultiplierUpdate =  ();
 }
 
 impl pallet_sudo::Trait for Runtime {
@@ -310,6 +314,7 @@
 /// Used for the module nft in `./nft.rs`
 impl pallet_nft::Trait for Runtime {
     type Event = Event;
+    type WeightInfo = nft_weights::WeightInfo;
 }
 
 construct_runtime!(
addedruntime/src/nft_weights.rsdiffbeforeafterboth

no changes