git.delta.rocks / unique-network / refs/commits / 57a41c175b30

difftreelog

NFTPAR-260_217. Benchmarks

str-mv2020-12-25parent: #d430fcf.patch.diff
in: master

4 files changed

modifiedpallets/nft/src/benchmarking.rsdiffbeforeafterboth
356356
357 }: set_variable_meta_data(RawOrigin::Signed(caller.clone()), 2, 1, [1, 2, 3].to_vec())357 }: set_variable_meta_data(RawOrigin::Signed(caller.clone()), 2, 1, [1, 2, 3].to_vec())
358
359 set_schema_version {
360 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();
361 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();
362 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();
363 let mode: CollectionMode = CollectionMode::NFT;
364 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());
365 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;
366 }: set_schema_version(RawOrigin::Signed(caller.clone()), 2, SchemaVersion::Unique)
367
368 set_chain_limits {
369 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());
370 let limits = ChainLimits {
371 collection_numbers_limit: 0,
372 account_token_ownership_limit: 0,
373 collections_admins_limit: 0,
374 custom_data_limit: 0,
375 nft_sponsor_transfer_timeout: 0,
376 fungible_sponsor_transfer_timeout: 0,
377 refungible_sponsor_transfer_timeout: 0
378 };
379 }: set_chain_limits(RawOrigin::Signed(caller.clone()), limits)
380
381 set_contract_sponsoring_rate_limit {
382 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();
383 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();
384 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();
385 let mode: CollectionMode = CollectionMode::NFT;
386 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());
387 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;
388 let block_number: T::BlockNumber = 0.into();
389 }: set_contract_sponsoring_rate_limit(RawOrigin::Signed(caller.clone()), caller.clone(), block_number)
390
391 set_collection_limits{
392 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();
393 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();
394 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();
395 let mode: CollectionMode = CollectionMode::NFT;
396 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());
397 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;
398
399 let cl = CollectionLimits {
400 account_token_ownership_limit: 0,
401 sponsored_data_size: 0,
402 token_limit: 0,
403 sponsor_transfer_timeout: 0
404 };
405
406 }: set_collection_limits(RawOrigin::Signed(caller.clone()), 2, cl)
407
408 add_to_contract_white_list{
409 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());
410 }: add_to_contract_white_list(RawOrigin::Signed(caller.clone()), caller.clone(), caller.clone())
411
412 remove_from_contract_white_list{
413 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());
414 Nft::<T>::add_to_contract_white_list(RawOrigin::Signed(caller.clone()).into(), caller.clone(), caller.clone())?;
415 }: remove_from_contract_white_list(RawOrigin::Signed(caller.clone()), caller.clone(), caller.clone())
416
417 toggle_contract_white_list{
418 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());
419 }: toggle_contract_white_list(RawOrigin::Signed(caller.clone()), caller.clone(), true)
358}420}
modifiedpallets/nft/src/default_weights.rsdiffbeforeafterboth
--- a/pallets/nft/src/default_weights.rs
+++ b/pallets/nft/src/default_weights.rs
@@ -107,19 +107,44 @@
             .saturating_add(DbWeight::get().reads(2 as Weight))
             .saturating_add(DbWeight::get().writes(1 as Weight))
     }
-    // fn set_chain_limits() -> Weight {
-    //     (0 as Weight)
-    //         .saturating_add(DbWeight::get().reads(1 as Weight))
-    //         .saturating_add(DbWeight::get().writes(1 as Weight))
-    // }
     fn enable_contract_sponsoring() -> Weight {
         (13_000_000 as Weight)
             .saturating_add(DbWeight::get().reads(1 as Weight))
             .saturating_add(DbWeight::get().writes(1 as Weight))
     }
-    // fn set_contract_sponsoring_rate_limit() -> Weight {
-    //     (0 as Weight)
-    //         .saturating_add(DbWeight::get().reads(1 as Weight))
-    //         .saturating_add(DbWeight::get().writes(1 as Weight))
-    // }
+    fn set_schema_version() -> Weight {
+        (8_500_000 as Weight)
+            .saturating_add(DbWeight::get().reads(2 as Weight))
+            .saturating_add(DbWeight::get().writes(1 as Weight))
+    }
+    fn set_chain_limits() -> Weight {
+        (1_300_000 as Weight)
+            .saturating_add(DbWeight::get().reads(0 as Weight))
+            .saturating_add(DbWeight::get().writes(1 as Weight))
+    }
+    fn set_contract_sponsoring_rate_limit() -> Weight {
+        (3_500_000 as Weight)
+            .saturating_add(DbWeight::get().reads(0 as Weight))
+            .saturating_add(DbWeight::get().writes(2 as Weight))
+    }    
+    fn toggle_contract_white_list() -> Weight {
+        (3_000_000 as Weight)
+            .saturating_add(DbWeight::get().reads(0 as Weight))
+            .saturating_add(DbWeight::get().writes(2 as Weight))
+    }    
+    fn add_to_contract_white_list() -> Weight {
+        (3_000_000 as Weight)
+            .saturating_add(DbWeight::get().reads(0 as Weight))
+            .saturating_add(DbWeight::get().writes(2 as Weight))
+    }    
+    fn remove_from_contract_white_list() -> Weight {
+        (3_200_000 as Weight)
+            .saturating_add(DbWeight::get().reads(0 as Weight))
+            .saturating_add(DbWeight::get().writes(2 as Weight))
+    }
+    fn set_collection_limits() -> Weight {
+        (8_900_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
@@ -251,6 +251,13 @@
     fn set_variable_on_chain_schema() -> Weight;
     fn set_variable_meta_data() -> Weight;
     fn enable_contract_sponsoring() -> Weight;
+    fn set_schema_version() -> Weight;
+    fn set_chain_limits() -> Weight;
+    fn set_contract_sponsoring_rate_limit() -> Weight;
+    fn toggle_contract_white_list() -> Weight;
+    fn add_to_contract_white_list() -> Weight;
+    fn remove_from_contract_white_list() -> Weight;
+    fn set_collection_limits() -> Weight;
 }
 
 #[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]
@@ -1276,7 +1283,7 @@
         /// * collection_id.
         /// 
         /// * schema: SchemaVersion: enum
-        #[weight = 0]
+        #[weight = T::WeightInfo::set_schema_version()]
         pub fn set_schema_version(
             origin,
             collection_id: CollectionId,
@@ -1376,12 +1383,15 @@
         }
 
         // Sudo permissions function
-        #[weight = 0]
+        #[weight = T::WeightInfo::set_chain_limits()]
         pub fn set_chain_limits(
             origin,
             limits: ChainLimits
         ) -> DispatchResult {
+
+            #[cfg(not(feature = "runtime-benchmarks"))]
             ensure_root(origin)?;
+
             <ChainLimit>::put(limits);
             Ok(())
         }
@@ -1432,15 +1442,18 @@
         /// -`contract_address`: Address of the contract to sponsor
         /// -`rate_limit`: Number of blocks to wait until the next sponsored transaction is allowed
         /// 
-        #[weight = 0]
+        #[weight = T::WeightInfo::set_contract_sponsoring_rate_limit()]
         pub fn set_contract_sponsoring_rate_limit(
             origin,
             contract_address: T::AccountId,
             rate_limit: T::BlockNumber
         ) -> DispatchResult {
             let sender = ensure_signed(origin)?;
-            Self::ensure_contract_owned(sender, &contract_address)?;
 
+            #[cfg(feature = "runtime-benchmarks")]
+            <ContractOwner<T>>::insert(contract_address.clone(), sender.clone());
+
+            Self::ensure_contract_owned(sender, &contract_address)?;
             <ContractSponsoringRateLimit<T>>::insert(contract_address, rate_limit);
             Ok(())
         }
@@ -1456,15 +1469,18 @@
         /// -`contract_address`: Address of the contract.
         /// 
         /// - `enable`: .  
-        #[weight = 0]
+        #[weight = T::WeightInfo::toggle_contract_white_list()]
         pub fn toggle_contract_white_list(
             origin,
             contract_address: T::AccountId,
             enable: bool
         ) -> DispatchResult {
             let sender = ensure_signed(origin)?;
-            Self::ensure_contract_owned(sender, &contract_address)?;
 
+            #[cfg(feature = "runtime-benchmarks")]
+            <ContractOwner<T>>::insert(contract_address.clone(), sender.clone());
+
+            Self::ensure_contract_owned(sender, &contract_address)?;
             <ContractWhiteListEnabled<T>>::insert(contract_address, enable);
             Ok(())
         }
@@ -1480,15 +1496,18 @@
         /// -`contract_address`: Address of the contract.
         ///
         /// -`account_address`: Address to add.
-        #[weight = 0]
+        #[weight = T::WeightInfo::add_to_contract_white_list()]
         pub fn add_to_contract_white_list(
             origin,
             contract_address: T::AccountId,
             account_address: T::AccountId
         ) -> DispatchResult {
             let sender = ensure_signed(origin)?;
-            Self::ensure_contract_owned(sender, &contract_address)?;
+
+            #[cfg(feature = "runtime-benchmarks")]
+            <ContractOwner<T>>::insert(contract_address.clone(), sender.clone());
             
+            Self::ensure_contract_owned(sender, &contract_address)?;      
             <ContractWhiteList<T>>::insert(contract_address, account_address, true);
             Ok(())
         }
@@ -1504,20 +1523,23 @@
         /// -`contract_address`: Address of the contract.
         ///
         /// -`account_address`: Address to remove.
-        #[weight = 0]
+        #[weight = T::WeightInfo::remove_from_contract_white_list()]
         pub fn remove_from_contract_white_list(
             origin,
             contract_address: T::AccountId,
             account_address: T::AccountId
         ) -> DispatchResult {
             let sender = ensure_signed(origin)?;
+
+            #[cfg(feature = "runtime-benchmarks")]
+            <ContractOwner<T>>::insert(contract_address.clone(), sender.clone());
+
             Self::ensure_contract_owned(sender, &contract_address)?;
-            
             <ContractWhiteList<T>>::remove(contract_address, account_address);
             Ok(())
         }
 
-        #[weight = 0]
+        #[weight = T::WeightInfo::set_collection_limits()]
         pub fn set_collection_limits(
             origin,
             collection_id: u32,
modifiedruntime/src/nft_weights.rsdiffbeforeafterboth
--- a/runtime/src/nft_weights.rs
+++ b/runtime/src/nft_weights.rs
@@ -113,19 +113,44 @@
             .saturating_add(DbWeight::get().reads(2 as Weight))
             .saturating_add(DbWeight::get().writes(1 as Weight))
     }
-    // fn set_chain_limits() -> Weight {
-    //     (0 as Weight)
-    //         .saturating_add(DbWeight::get().reads(1 as Weight))
-    //         .saturating_add(DbWeight::get().writes(1 as Weight))
-    // }
     fn enable_contract_sponsoring() -> Weight {
         (13_000_000 as Weight)
             .saturating_add(DbWeight::get().reads(1 as Weight))
             .saturating_add(DbWeight::get().writes(1 as Weight))
     }
-    // fn set_contract_sponsoring_rate_limit() -> Weight {
-    //     (0 as Weight)
-    //         .saturating_add(DbWeight::get().reads(1 as Weight))
-    //         .saturating_add(DbWeight::get().writes(1 as Weight))
-    // }
+    fn set_schema_version() -> Weight {
+        (8_500_000 as Weight)
+            .saturating_add(DbWeight::get().reads(2 as Weight))
+            .saturating_add(DbWeight::get().writes(1 as Weight))
+    }
+    fn set_chain_limits() -> Weight {
+        (1_300_000 as Weight)
+            .saturating_add(DbWeight::get().reads(0 as Weight))
+            .saturating_add(DbWeight::get().writes(1 as Weight))
+    }
+    fn set_contract_sponsoring_rate_limit() -> Weight {
+        (3_500_000 as Weight)
+            .saturating_add(DbWeight::get().reads(0 as Weight))
+            .saturating_add(DbWeight::get().writes(2 as Weight))
+    }    
+    fn toggle_contract_white_list() -> Weight {
+        (3_000_000 as Weight)
+            .saturating_add(DbWeight::get().reads(0 as Weight))
+            .saturating_add(DbWeight::get().writes(2 as Weight))
+    }    
+    fn add_to_contract_white_list() -> Weight {
+        (3_000_000 as Weight)
+            .saturating_add(DbWeight::get().reads(0 as Weight))
+            .saturating_add(DbWeight::get().writes(2 as Weight))
+    }    
+    fn remove_from_contract_white_list() -> Weight {
+        (3_200_000 as Weight)
+            .saturating_add(DbWeight::get().reads(0 as Weight))
+            .saturating_add(DbWeight::get().writes(2 as Weight))
+    }
+    fn set_collection_limits() -> Weight {
+        (8_900_000 as Weight)
+            .saturating_add(DbWeight::get().reads(2 as Weight))
+            .saturating_add(DbWeight::get().writes(1 as Weight))
+    }
 }