diff --git a/pallets/token-issuer/src/benchmarking.rs b/pallets/token-issuer/src/benchmarking.rs index 0dc47d130..efa74ab1a 100644 --- a/pallets/token-issuer/src/benchmarking.rs +++ b/pallets/token-issuer/src/benchmarking.rs @@ -18,90 +18,192 @@ #![cfg(feature = "runtime-benchmarks")] use bifrost_primitives::{CurrencyId, TokenSymbol}; -use frame_benchmarking::{ - account, benchmarks, impl_benchmark_test_suite, v1::BenchmarkError, whitelisted_caller, +use frame_benchmarking::v2::*; +use frame_support::{ + assert_ok, sp_runtime::traits::UniqueSaturatedFrom, traits::UnfilteredDispatchable, }; -use frame_support::{sp_runtime::traits::UniqueSaturatedFrom, traits::UnfilteredDispatchable}; use frame_system::RawOrigin; use super::*; -#[allow(unused_imports)] -use crate::Pallet as TokenIssuer; -benchmarks! { - add_to_issue_whitelist { - let origin = T::ControlOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?; +#[benchmarks(where T: Config)] +mod benchmarks { + use super::*; + + #[benchmark] + fn add_to_issue_whitelist() -> Result<(), BenchmarkError> { + let origin = + T::ControlOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?; let account: T::AccountId = whitelisted_caller(); let currency_id = CurrencyId::Token(TokenSymbol::KSM); - let call = Call::::add_to_issue_whitelist { currency_id, account }; - }: {call.dispatch_bypass_filter(origin)?} + let call = Call::::add_to_issue_whitelist { + currency_id, + account, + }; + + #[block] + { + call.dispatch_bypass_filter(origin)?; + } - remove_from_issue_whitelist { - let origin = T::ControlOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?; + Ok(()) + } + + #[benchmark] + fn remove_from_issue_whitelist() -> Result<(), BenchmarkError> { + let origin = + T::ControlOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?; let account: T::AccountId = whitelisted_caller(); let currency_id = CurrencyId::Token(TokenSymbol::KSM); - let add_call = Call::::add_to_issue_whitelist { currency_id, account: account.clone() }; + + let add_call = Call::::add_to_issue_whitelist { + currency_id, + account: account.clone(), + }; add_call.dispatch_bypass_filter(origin.clone())?; - let remove_call = Call::::remove_from_issue_whitelist { currency_id, account }; - }: {remove_call.dispatch_bypass_filter(origin)?} + let remove_call = Call::::remove_from_issue_whitelist { + currency_id, + account, + }; - add_to_transfer_whitelist { - let origin = T::ControlOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?; + #[block] + { + remove_call.dispatch_bypass_filter(origin)?; + } + + Ok(()) + } + + #[benchmark] + fn add_to_transfer_whitelist() -> Result<(), BenchmarkError> { + let origin = + T::ControlOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?; let account: T::AccountId = whitelisted_caller(); let currency_id = CurrencyId::Token(TokenSymbol::KSM); - let call = Call::::add_to_transfer_whitelist { currency_id, account }; - }: {call.dispatch_bypass_filter(origin)?} + let call = Call::::add_to_transfer_whitelist { + currency_id, + account, + }; - remove_from_transfer_whitelist { - let origin = T::ControlOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?; + #[block] + { + call.dispatch_bypass_filter(origin)?; + } + + Ok(()) + } + + #[benchmark] + fn remove_from_transfer_whitelist() -> Result<(), BenchmarkError> { + let origin = + T::ControlOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?; let account: T::AccountId = whitelisted_caller(); let currency_id = CurrencyId::Token(TokenSymbol::KSM); - let add_call = Call::::add_to_transfer_whitelist { currency_id, account: account.clone() }; + + let add_call = Call::::add_to_transfer_whitelist { + currency_id, + account: account.clone(), + }; add_call.dispatch_bypass_filter(origin.clone())?; - let remove_call = Call::::remove_from_transfer_whitelist { currency_id, account }; - }: {remove_call.dispatch_bypass_filter(origin)?} + let remove_call = Call::::remove_from_transfer_whitelist { + currency_id, + account, + }; + + #[block] + { + remove_call.dispatch_bypass_filter(origin)?; + } + + Ok(()) + } - issue { - let origin = T::ControlOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?; + #[benchmark] + fn issue() -> Result<(), BenchmarkError> { + let origin = + T::ControlOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?; let caller: T::AccountId = whitelisted_caller(); let currency_id = CurrencyId::Token(TokenSymbol::KSM); - let add_call = Call::::add_to_issue_whitelist { currency_id: currency_id, account: caller.clone() }; + + let add_call = Call::::add_to_issue_whitelist { + currency_id, + account: caller.clone(), + }; add_call.dispatch_bypass_filter(origin.clone())?; let original_balance = T::MultiCurrency::free_balance(currency_id, &caller); - let token_amount = BalanceOf::::unique_saturated_from(1000u32 as u128); - }: _(RawOrigin::Signed(caller.clone()), caller.clone(), currency_id, token_amount) - verify { - assert_eq!(T::MultiCurrency::free_balance(currency_id, &caller), token_amount + original_balance); + let token_amount = BalanceOf::::unique_saturated_from(1000000000000000u128); + + #[block] + { + Pallet::::issue( + RawOrigin::Signed(caller.clone()).into(), + caller.clone(), + currency_id, + token_amount, + )?; + } + + assert_eq!( + T::MultiCurrency::free_balance(currency_id, &caller), + token_amount + original_balance + ); + + Ok(()) } - transfer { - let origin = T::ControlOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?; + #[benchmark] + fn transfer() -> Result<(), BenchmarkError> { + let origin = + T::ControlOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?; let caller: T::AccountId = whitelisted_caller(); let currency_id = CurrencyId::Token(TokenSymbol::KSM); - // add caller to the transfer whitelist - let add_transfer_call = Call::::add_to_transfer_whitelist { currency_id: currency_id, account: caller.clone() }; + let initial_amount = BalanceOf::::unique_saturated_from(1_000_000_000_000_000u128); + assert_ok!(T::MultiCurrency::deposit( + currency_id, + &caller, + initial_amount + )); + + let add_transfer_call = Call::::add_to_transfer_whitelist { + currency_id, + account: caller.clone(), + }; add_transfer_call.dispatch_bypass_filter(origin.clone())?; - // transfer some ksm from caller account to receiver account let receiver: T::AccountId = account("bechmarking_account_1", 0, 0); - let transfer_token_amount = BalanceOf::::unique_saturated_from(800u32 as u128); + let transfer_token_amount = BalanceOf::::unique_saturated_from(800_000_000_000_000u128); let caller_original_balance = T::MultiCurrency::free_balance(currency_id, &caller); let receiver_original_balance = T::MultiCurrency::free_balance(currency_id, &receiver); - }: _(RawOrigin::Signed(caller.clone()), receiver.clone(), currency_id, transfer_token_amount) - verify { - assert_eq!(T::MultiCurrency::free_balance(currency_id, &caller), caller_original_balance - transfer_token_amount); - assert_eq!(T::MultiCurrency::free_balance(currency_id, &receiver), transfer_token_amount+ receiver_original_balance); + + #[block] + { + Pallet::::transfer( + RawOrigin::Signed(caller.clone()).into(), + receiver.clone(), + currency_id, + transfer_token_amount, + )?; + } + + assert_eq!( + T::MultiCurrency::free_balance(currency_id, &caller), + caller_original_balance - transfer_token_amount + ); + assert_eq!( + T::MultiCurrency::free_balance(currency_id, &receiver), + transfer_token_amount + receiver_original_balance + ); + + Ok(()) } -} -impl_benchmark_test_suite!( - TokenIssuer, - crate::mock::ExtBuilder::default() - .one_hundred_precision_for_each_currency_type_for_whitelist_account() - .build(), - crate::mock::Runtime -); + impl_benchmark_test_suite!( + Pallet, + crate::mock::new_test_ext_benchmark(), + crate::mock::Runtime + ); +} diff --git a/pallets/token-issuer/src/mock.rs b/pallets/token-issuer/src/mock.rs index 2873e4497..f284f74f8 100644 --- a/pallets/token-issuer/src/mock.rs +++ b/pallets/token-issuer/src/mock.rs @@ -227,3 +227,8 @@ impl ExtBuilder { t.into() } } + +#[cfg(feature = "runtime-benchmarks")] +pub fn new_test_ext_benchmark() -> sp_io::TestExternalities { + ExtBuilder::default().build() +} diff --git a/pallets/token-issuer/src/weights.rs b/pallets/token-issuer/src/weights.rs index 4b18dc31d..46ac0020f 100644 --- a/pallets/token-issuer/src/weights.rs +++ b/pallets/token-issuer/src/weights.rs @@ -24,9 +24,9 @@ //! Autogenerated weights for bifrost_token_issuer //! -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-09-14, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! HOSTNAME: `bifrost-jenkins`, CPU: `Intel(R) Xeon(R) CPU E5-26xx v4` +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 42.0.1 +//! DATE: 2024-12-30, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! HOSTNAME: `mjl-legion`, CPU: `12th Gen Intel(R) Core(TM) i9-12900H` //! WASM-EXECUTION: Compiled, CHAIN: Some("bifrost-kusama-local"), DB CACHE: 1024 // Executed Command: @@ -63,80 +63,82 @@ pub trait WeightInfo { // For backwards compatibility and tests impl WeightInfo for () { - /// Storage: TokenIssuer IssueWhiteList (r:1 w:1) - /// Proof Skipped: TokenIssuer IssueWhiteList (max_values: None, max_size: None, mode: Measured) + /// Storage: `TokenIssuer::IssueWhiteList` (r:1 w:1) + /// Proof: `TokenIssuer::IssueWhiteList` (`max_values`: None, `max_size`: None, mode: `Measured`) fn add_to_issue_whitelist() -> Weight { // Proof Size summary in bytes: // Measured: `142` // Estimated: `3607` - // Minimum execution time: 32_693_000 picoseconds. - Weight::from_parts(33_651_000, 3607) + // Minimum execution time: 6_203_000 picoseconds. + Weight::from_parts(6_858_000, 3607) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } - /// Storage: TokenIssuer IssueWhiteList (r:1 w:1) - /// Proof Skipped: TokenIssuer IssueWhiteList (max_values: None, max_size: None, mode: Measured) + /// Storage: `TokenIssuer::IssueWhiteList` (r:1 w:1) + /// Proof: `TokenIssuer::IssueWhiteList` (`max_values`: None, `max_size`: None, mode: `Measured`) fn remove_from_issue_whitelist() -> Weight { // Proof Size summary in bytes: // Measured: `220` // Estimated: `3685` - // Minimum execution time: 34_136_000 picoseconds. - Weight::from_parts(35_196_000, 3685) + // Minimum execution time: 6_672_000 picoseconds. + Weight::from_parts(7_119_000, 3685) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } - /// Storage: TokenIssuer TransferWhiteList (r:1 w:1) - /// Proof Skipped: TokenIssuer TransferWhiteList (max_values: None, max_size: None, mode: Measured) + /// Storage: `TokenIssuer::TransferWhiteList` (r:1 w:1) + /// Proof: `TokenIssuer::TransferWhiteList` (`max_values`: None, `max_size`: None, mode: `Measured`) fn add_to_transfer_whitelist() -> Weight { // Proof Size summary in bytes: // Measured: `142` // Estimated: `3607` - // Minimum execution time: 32_485_000 picoseconds. - Weight::from_parts(33_735_000, 3607) + // Minimum execution time: 6_326_000 picoseconds. + Weight::from_parts(6_852_000, 3607) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } - /// Storage: TokenIssuer TransferWhiteList (r:1 w:1) - /// Proof Skipped: TokenIssuer TransferWhiteList (max_values: None, max_size: None, mode: Measured) + /// Storage: `TokenIssuer::TransferWhiteList` (r:1 w:1) + /// Proof: `TokenIssuer::TransferWhiteList` (`max_values`: None, `max_size`: None, mode: `Measured`) fn remove_from_transfer_whitelist() -> Weight { // Proof Size summary in bytes: // Measured: `220` // Estimated: `3685` - // Minimum execution time: 33_573_000 picoseconds. - Weight::from_parts(34_609_000, 3685) + // Minimum execution time: 7_016_000 picoseconds. + Weight::from_parts(7_358_000, 3685) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } - /// Storage: TokenIssuer IssueWhiteList (r:1 w:0) - /// Proof Skipped: TokenIssuer IssueWhiteList (max_values: None, max_size: None, mode: Measured) - /// Storage: Tokens Accounts (r:1 w:1) - /// Proof: Tokens Accounts (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) - /// Storage: AssetRegistry CurrencyMetadatas (r:1 w:0) - /// Proof Skipped: AssetRegistry CurrencyMetadatas (max_values: None, max_size: None, mode: Measured) - /// Storage: Tokens TotalIssuance (r:1 w:1) - /// Proof: Tokens TotalIssuance (max_values: None, max_size: Some(38), added: 2513, mode: MaxEncodedLen) + /// Storage: `TokenIssuer::IssueWhiteList` (r:1 w:0) + /// Proof: `TokenIssuer::IssueWhiteList` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `Tokens::Accounts` (r:1 w:1) + /// Proof: `Tokens::Accounts` (`max_values`: None, `max_size`: Some(118), added: 2593, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::CurrencyMetadatas` (r:1 w:0) + /// Proof: `AssetRegistry::CurrencyMetadatas` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `Tokens::TotalIssuance` (r:1 w:1) + /// Proof: `Tokens::TotalIssuance` (`max_values`: None, `max_size`: Some(38), added: 2513, mode: `MaxEncodedLen`) fn issue() -> Weight { // Proof Size summary in bytes: - // Measured: `1870` - // Estimated: `5335` - // Minimum execution time: 99_796_000 picoseconds. - Weight::from_parts(100_707_000, 5335) + // Measured: `679` + // Estimated: `4144` + // Minimum execution time: 21_440_000 picoseconds. + Weight::from_parts(23_100_000, 4144) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } - /// Storage: TokenIssuer TransferWhiteList (r:1 w:0) - /// Proof Skipped: TokenIssuer TransferWhiteList (max_values: None, max_size: None, mode: Measured) - /// Storage: Tokens Accounts (r:2 w:2) - /// Proof: Tokens Accounts (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) - /// Storage: AssetRegistry CurrencyMetadatas (r:1 w:0) - /// Proof Skipped: AssetRegistry CurrencyMetadatas (max_values: None, max_size: None, mode: Measured) + /// Storage: `TokenIssuer::TransferWhiteList` (r:1 w:0) + /// Proof: `TokenIssuer::TransferWhiteList` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `Tokens::Accounts` (r:2 w:2) + /// Proof: `Tokens::Accounts` (`max_values`: None, `max_size`: Some(118), added: 2593, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::CurrencyMetadatas` (r:1 w:0) + /// Proof: `AssetRegistry::CurrencyMetadatas` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) fn transfer() -> Weight { // Proof Size summary in bytes: - // Measured: `1989` + // Measured: `950` // Estimated: `6176` - // Minimum execution time: 114_723_000 picoseconds. - Weight::from_parts(115_788_000, 6176) - .saturating_add(RocksDbWeight::get().reads(4_u64)) - .saturating_add(RocksDbWeight::get().writes(2_u64)) + // Minimum execution time: 32_395_000 picoseconds. + Weight::from_parts(33_244_000, 6176) + .saturating_add(RocksDbWeight::get().reads(5_u64)) + .saturating_add(RocksDbWeight::get().writes(3_u64)) } -} +} \ No newline at end of file