diff --git a/pallets/vstoken-conversion/src/benchmarking.rs b/pallets/vstoken-conversion/src/benchmarking.rs index ec947163ca..1cb3a283fa 100644 --- a/pallets/vstoken-conversion/src/benchmarking.rs +++ b/pallets/vstoken-conversion/src/benchmarking.rs @@ -20,7 +20,7 @@ #![cfg(feature = "runtime-benchmarks")] use bifrost_primitives::{CurrencyId, TokenSymbol}; -use frame_benchmarking::v1::{account, benchmarks, BenchmarkError}; +use frame_benchmarking::v2::*; use frame_support::{ assert_ok, traits::{EnsureOrigin, Get}, @@ -36,106 +36,166 @@ use crate::{ pub const VS_BOND: CurrencyId = CurrencyId::VSBond(TokenSymbol::BNC, 2001, 0, 8); pub const VS_KSM: CurrencyId = CurrencyId::VSToken(TokenSymbol::KSM); -benchmarks! { - set_exchange_fee { - let origin = T::ControlOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?; - let fee: VstokenConversionExchangeFee> = - VstokenConversionExchangeFee { - vstoken_exchange_fee: 10u32.into(), - vsbond_exchange_fee_of_vstoken: 10u32.into(), - }; - }: _(origin,fee) - - set_exchange_rate { - let origin = T::ControlOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?; - let fee: VstokenConversionExchangeFee> = - VstokenConversionExchangeFee { - vstoken_exchange_fee: 10u32.into(), - vsbond_exchange_fee_of_vstoken: 10u32.into(), - }; +#[benchmarks] +mod benchmarks { + use super::*; + + #[benchmark] + fn set_exchange_fee() -> Result<(), BenchmarkError> { + let origin = + T::ControlOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?; + let fee: VstokenConversionExchangeFee> = VstokenConversionExchangeFee { + vstoken_exchange_fee: 10u32.into(), + vsbond_exchange_fee_of_vstoken: 10u32.into(), + }; + + #[extrinsic_call] + _(origin as ::RuntimeOrigin, fee); + + Ok(()) + } + + #[benchmark] + fn set_exchange_rate() -> Result<(), BenchmarkError> { + let origin = + T::ControlOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?; let rate: VstokenConversionExchangeRate = VstokenConversionExchangeRate { vsbond_convert_to_vstoken: Percent::from_percent(5), vstoken_convert_to_vsbond: Percent::from_percent(5), }; - }: _(origin,1,rate) - - set_relaychain_lease { - let origin = T::ControlOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?; - }: _(origin,1) - - vsbond_convert_to_vstoken { - let test_account: T::AccountId = account("seed",1,1); - let fee: VstokenConversionExchangeFee> = - VstokenConversionExchangeFee { - vstoken_exchange_fee: 10u32.into(), - vsbond_exchange_fee_of_vstoken: 10u32.into(), - }; + + #[extrinsic_call] + _(origin as ::RuntimeOrigin, 1, rate); + + Ok(()) + } + + #[benchmark] + fn set_relaychain_lease() -> Result<(), BenchmarkError> { + let origin = + T::ControlOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?; + + #[extrinsic_call] + _(origin as ::RuntimeOrigin, 1); + + Ok(()) + } + + #[benchmark] + fn vsbond_convert_to_vstoken() -> Result<(), BenchmarkError> { + let test_account: T::AccountId = account("seed", 1, 1); + let fee: VstokenConversionExchangeFee> = VstokenConversionExchangeFee { + vstoken_exchange_fee: 10u32.into(), + vsbond_exchange_fee_of_vstoken: 10u32.into(), + }; let rate: VstokenConversionExchangeRate = VstokenConversionExchangeRate { vsbond_convert_to_vstoken: Percent::from_percent(95), vstoken_convert_to_vsbond: Percent::from_percent(95), }; - assert_ok!( - VstokenConversion::::set_exchange_fee( - T::ControlOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?, - fee - )); - - assert_ok!( - VstokenConversion::::set_exchange_rate( - T::ControlOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?, - 8, - rate - )); - - assert_ok!( - VstokenConversion::::set_relaychain_lease( - T::ControlOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?, - 1 - )); + + let origin = + T::ControlOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?; + + // Setup initial conditions + assert_ok!(VstokenConversion::::set_exchange_fee( + origin.clone() as ::RuntimeOrigin, + fee + )); + assert_ok!(VstokenConversion::::set_exchange_rate( + origin.clone() as ::RuntimeOrigin, + 8, + rate + )); + assert_ok!(VstokenConversion::::set_relaychain_lease( + origin as ::RuntimeOrigin, + 1 + )); let vsbond_account: T::AccountId = ::VsbondAccount::get().into_account_truncating(); - T::MultiCurrency::deposit(VS_KSM, &vsbond_account, BalanceOf::::unique_saturated_from(1000000000000u128))?; - T::MultiCurrency::deposit(VS_BOND, &test_account, BalanceOf::::unique_saturated_from(1000000000000u128))?; - }: _(RawOrigin::Signed(test_account),VS_BOND,BalanceOf::::unique_saturated_from(100000000000u128),BalanceOf::::unique_saturated_from(10000000000u128)) - - vstoken_convert_to_vsbond { - let test_account: T::AccountId = account("seed",1,1); - let fee: VstokenConversionExchangeFee> = - VstokenConversionExchangeFee { - vstoken_exchange_fee: 10u32.into(), - vsbond_exchange_fee_of_vstoken: 10u32.into(), - }; + T::MultiCurrency::deposit( + VS_KSM, + &vsbond_account, + BalanceOf::::unique_saturated_from(1000000000000u128), + )?; + T::MultiCurrency::deposit( + VS_BOND, + &test_account, + BalanceOf::::unique_saturated_from(1000000000000u128), + )?; + + #[extrinsic_call] + _( + RawOrigin::Signed(test_account), + VS_BOND, + BalanceOf::::unique_saturated_from(100000000000u128), + BalanceOf::::unique_saturated_from(10000000000u128), + ); + + Ok(()) + } + + #[benchmark] + fn vstoken_convert_to_vsbond() -> Result<(), BenchmarkError> { + let test_account: T::AccountId = account("seed", 1, 1); + let fee: VstokenConversionExchangeFee> = VstokenConversionExchangeFee { + vstoken_exchange_fee: 10u32.into(), + vsbond_exchange_fee_of_vstoken: 10u32.into(), + }; let rate: VstokenConversionExchangeRate = VstokenConversionExchangeRate { vsbond_convert_to_vstoken: Percent::from_percent(5), vstoken_convert_to_vsbond: Percent::from_percent(5), }; - assert_ok!( - VstokenConversion::::set_exchange_fee( - T::ControlOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?, - fee - )); - - assert_ok!( - VstokenConversion::::set_exchange_rate( - T::ControlOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?, - 8, - rate - )); - - assert_ok!( - VstokenConversion::::set_relaychain_lease( - T::ControlOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?, - 1 - )); + + let origin = + T::ControlOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?; + + // Setup initial conditions + assert_ok!(VstokenConversion::::set_exchange_fee( + origin.clone() as ::RuntimeOrigin, + fee + )); + assert_ok!(VstokenConversion::::set_exchange_rate( + origin.clone() as ::RuntimeOrigin, + 8, + rate + )); + assert_ok!(VstokenConversion::::set_relaychain_lease( + origin as ::RuntimeOrigin, + 1 + )); let vsbond_account: T::AccountId = ::VsbondAccount::get().into_account_truncating(); - T::MultiCurrency::deposit(VS_BOND, &vsbond_account, BalanceOf::::unique_saturated_from(100000000000000u128))?; - T::MultiCurrency::deposit(VS_KSM, &test_account, BalanceOf::::unique_saturated_from(100000000000000u128))?; - - }: _(RawOrigin::Signed(test_account),VS_BOND,BalanceOf::::unique_saturated_from(1000000000000u128),BalanceOf::::unique_saturated_from(100000000000u128)) - - - impl_benchmark_test_suite!(VstokenConversion,crate::mock::ExtBuilder::default().build(),crate::mock::Runtime); + T::MultiCurrency::deposit( + VS_BOND, + &vsbond_account, + BalanceOf::::unique_saturated_from(100000000000000u128), + )?; + T::MultiCurrency::deposit( + VS_KSM, + &test_account, + BalanceOf::::unique_saturated_from(100000000000000u128), + )?; + + #[extrinsic_call] + _( + RawOrigin::Signed(test_account), + VS_BOND, + BalanceOf::::unique_saturated_from(1000000000000u128), + BalanceOf::::unique_saturated_from(100000000000u128), + ); + + Ok(()) + } + + // This line generates test cases for benchmarking, and could be run by: + // `cargo test -p pallet-example-basic --all-features`, you will see one line per case: + // `test benchmarking::bench_sort_vector ... ok` + // `test benchmarking::bench_accumulate_dummy ... ok` + // `test benchmarking::bench_set_dummy_benchmark ... ok` in the result. + // + // The line generates three steps per benchmark, with repeat=1 and the three steps are + // [low, mid, high] of the range. + impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext_benchmark(), crate::mock::Runtime); } diff --git a/pallets/vstoken-conversion/src/mock.rs b/pallets/vstoken-conversion/src/mock.rs index 46e56b292d..2ae3d81d83 100644 --- a/pallets/vstoken-conversion/src/mock.rs +++ b/pallets/vstoken-conversion/src/mock.rs @@ -209,3 +209,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/vstoken-conversion/src/weights.rs b/pallets/vstoken-conversion/src/weights.rs index e1e22dee8d..a06986fcb4 100644 --- a/pallets/vstoken-conversion/src/weights.rs +++ b/pallets/vstoken-conversion/src/weights.rs @@ -24,9 +24,9 @@ //! Autogenerated weights for bifrost_vstoken_conversion //! -//! 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 32.0.0 +//! DATE: 2024-12-03, 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: @@ -36,7 +36,7 @@ // --chain=bifrost-kusama-local // --steps=50 // --repeat=20 -// --pallet=bifrost_vstoken_conversion +// --pallet=bifrost_vstoken-conversion // --extrinsic=* // --execution=wasm // --wasm-execution=compiled @@ -62,82 +62,82 @@ pub trait WeightInfo { // For backwards compatibility and tests impl WeightInfo for () { - /// Storage: VstokenConversion ExchangeFee (r:1 w:1) - /// Proof: VstokenConversion ExchangeFee (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen) + /// Storage: `VstokenConversion::ExchangeFee` (r:1 w:1) + /// Proof: `VstokenConversion::ExchangeFee` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`) fn set_exchange_fee() -> Weight { // Proof Size summary in bytes: - // Measured: `180` + // Measured: `213` // Estimated: `1517` - // Minimum execution time: 30_744_000 picoseconds. - Weight::from_parts(31_166_000, 1517) + // Minimum execution time: 19_049_000 picoseconds. + Weight::from_parts(21_188_000, 1517) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } - /// Storage: VstokenConversion ExchangeRate (r:1 w:1) - /// Proof: VstokenConversion ExchangeRate (max_values: None, max_size: Some(14), added: 2489, mode: MaxEncodedLen) + /// Storage: `VstokenConversion::ExchangeRate` (r:1 w:1) + /// Proof: `VstokenConversion::ExchangeRate` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`) fn set_exchange_rate() -> Weight { // Proof Size summary in bytes: - // Measured: `180` + // Measured: `213` // Estimated: `3479` - // Minimum execution time: 30_215_000 picoseconds. - Weight::from_parts(31_148_000, 3479) + // Minimum execution time: 21_707_000 picoseconds. + Weight::from_parts(23_228_000, 3479) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } - /// Storage: VstokenConversion RelaychainLease (r:1 w:1) - /// Proof: VstokenConversion RelaychainLease (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: `VstokenConversion::RelaychainLease` (r:1 w:1) + /// Proof: `VstokenConversion::RelaychainLease` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) fn set_relaychain_lease() -> Weight { // Proof Size summary in bytes: - // Measured: `180` + // Measured: `213` // Estimated: `1489` - // Minimum execution time: 28_293_000 picoseconds. - Weight::from_parts(29_337_000, 1489) + // Minimum execution time: 19_567_000 picoseconds. + Weight::from_parts(20_639_000, 1489) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } - /// Storage: Tokens Accounts (r:4 w:4) - /// Proof: Tokens Accounts (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) - /// Storage: AssetRegistry CurrencyMetadatas (r:2 w:0) - /// Proof Skipped: AssetRegistry CurrencyMetadatas (max_values: None, max_size: None, mode: Measured) - /// Storage: VstokenConversion RelaychainLease (r:1 w:0) - /// Proof: VstokenConversion RelaychainLease (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: VstokenConversion ExchangeRate (r:1 w:0) - /// Proof: VstokenConversion ExchangeRate (max_values: None, max_size: Some(14), added: 2489, mode: MaxEncodedLen) - /// Storage: VstokenConversion ExchangeFee (r:1 w:0) - /// Proof: VstokenConversion ExchangeFee (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen) - /// Storage: System Account (r:3 w:3) - /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) - /// Storage: Tokens TotalIssuance (r:2 w:2) - /// Proof: Tokens TotalIssuance (max_values: None, max_size: Some(38), added: 2513, mode: MaxEncodedLen) + /// Storage: `Tokens::Accounts` (r:4 w:4) + /// Proof: `Tokens::Accounts` (`max_values`: None, `max_size`: Some(118), added: 2593, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::CurrencyMetadatas` (r:2 w:0) + /// Proof: `AssetRegistry::CurrencyMetadatas` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `VstokenConversion::RelaychainLease` (r:1 w:0) + /// Proof: `VstokenConversion::RelaychainLease` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `VstokenConversion::ExchangeRate` (r:1 w:0) + /// Proof: `VstokenConversion::ExchangeRate` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`) + /// Storage: `VstokenConversion::ExchangeFee` (r:1 w:0) + /// Proof: `VstokenConversion::ExchangeFee` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:3 w:3) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Tokens::TotalIssuance` (r:2 w:2) + /// Proof: `Tokens::TotalIssuance` (`max_values`: None, `max_size`: Some(38), added: 2513, mode: `MaxEncodedLen`) fn vsbond_convert_to_vstoken() -> Weight { // Proof Size summary in bytes: - // Measured: `2336` + // Measured: `1461` // Estimated: `11362` - // Minimum execution time: 258_393_000 picoseconds. - Weight::from_parts(262_031_000, 11362) + // Minimum execution time: 186_527_000 picoseconds. + Weight::from_parts(201_205_000, 11362) .saturating_add(RocksDbWeight::get().reads(14_u64)) .saturating_add(RocksDbWeight::get().writes(9_u64)) } - /// Storage: Tokens Accounts (r:4 w:4) - /// Proof: Tokens Accounts (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) - /// Storage: AssetRegistry CurrencyMetadatas (r:2 w:0) - /// Proof Skipped: AssetRegistry CurrencyMetadatas (max_values: None, max_size: None, mode: Measured) - /// Storage: VstokenConversion RelaychainLease (r:1 w:0) - /// Proof: VstokenConversion RelaychainLease (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: VstokenConversion ExchangeRate (r:1 w:0) - /// Proof: VstokenConversion ExchangeRate (max_values: None, max_size: Some(14), added: 2489, mode: MaxEncodedLen) - /// Storage: VstokenConversion ExchangeFee (r:1 w:0) - /// Proof: VstokenConversion ExchangeFee (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen) - /// Storage: System Account (r:3 w:2) - /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) - /// Storage: Tokens TotalIssuance (r:1 w:1) - /// Proof: Tokens TotalIssuance (max_values: None, max_size: Some(38), added: 2513, mode: MaxEncodedLen) + /// Storage: `Tokens::Accounts` (r:4 w:4) + /// Proof: `Tokens::Accounts` (`max_values`: None, `max_size`: Some(118), added: 2593, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::CurrencyMetadatas` (r:2 w:0) + /// Proof: `AssetRegistry::CurrencyMetadatas` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `VstokenConversion::RelaychainLease` (r:1 w:0) + /// Proof: `VstokenConversion::RelaychainLease` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `VstokenConversion::ExchangeRate` (r:1 w:0) + /// Proof: `VstokenConversion::ExchangeRate` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`) + /// Storage: `VstokenConversion::ExchangeFee` (r:1 w:0) + /// Proof: `VstokenConversion::ExchangeFee` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:3 w:2) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Tokens::TotalIssuance` (r:1 w:1) + /// Proof: `Tokens::TotalIssuance` (`max_values`: None, `max_size`: Some(38), added: 2513, mode: `MaxEncodedLen`) fn vstoken_convert_to_vsbond() -> Weight { // Proof Size summary in bytes: - // Measured: `2327` + // Measured: `1453` // Estimated: `11362` - // Minimum execution time: 244_708_000 picoseconds. - Weight::from_parts(247_427_000, 11362) + // Minimum execution time: 181_662_000 picoseconds. + Weight::from_parts(188_009_000, 11362) .saturating_add(RocksDbWeight::get().reads(13_u64)) .saturating_add(RocksDbWeight::get().writes(7_u64)) }