Skip to content

Commit

Permalink
Refactor Benchmarks and update calls that use T::Swap (Honzon and C…
Browse files Browse the repository at this point in the history
…dp Treasury) (#2303)

* refactor inject utility

* refactor currency id in benchmarks

* refactor fixes

* update honzon and cdp treasury benches

* Update runtime/mandala/src/benchmarking/utils.rs

Co-authored-by: Xiliang Chen <xlchen1291@gmail.com>

* use STAKING for prices benchmark

* decrease ED a little

* update to use correct ED

* cargo run --quiet --profile=production  --color=never --bin=acala --features=runtime-benchmarks --features=with-acala-runtime --features=on-chain-release-build -- benchmark pallet --chain=acala-dev --steps=50 --repeat=20 --pallet=module_honzon --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --template=./templates/runtime-weight-template.hbs --output=./runtime/acala/src/weights/

* cargo run --quiet --profile=production  --color=never --bin=acala --features=runtime-benchmarks --features=with-acala-runtime --features=on-chain-release-build -- benchmark pallet --chain=acala-dev --steps=50 --repeat=20 --pallet=module_cdp_treasury --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --template=./templates/runtime-weight-template.hbs --output=./runtime/acala/src/weights/

* cargo run --quiet --profile=production  --color=never --bin=acala --features=runtime-benchmarks --features=with-acala-runtime --features=on-chain-release-build -- benchmark pallet --chain=acala-dev --steps=50 --repeat=20 --pallet=module_prices --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --template=./templates/runtime-weight-template.hbs --output=./runtime/acala/src/weights/

Co-authored-by: Xiliang Chen <xlchen1291@gmail.com>
Co-authored-by: Acala Benchmarking Bot <hello@acala.network>
  • Loading branch information
3 people authored Aug 2, 2022
1 parent 63efabc commit aa12c5d
Show file tree
Hide file tree
Showing 25 changed files with 324 additions and 460 deletions.
35 changes: 20 additions & 15 deletions runtime/acala/src/weights/module_cdp_treasury.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
//! Autogenerated weights for module_cdp_treasury
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2022-07-25, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! DATE: 2022-08-01, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("acala-dev"), DB CACHE: 1024
// Executed Command:
Expand All @@ -29,7 +29,7 @@
// --chain=acala-dev
// --steps=50
// --repeat=20
// --pallet=*
// --pallet=module_cdp_treasury
// --extrinsic=*
// --execution=wasm
// --wasm-execution=compiled
Expand Down Expand Up @@ -58,39 +58,44 @@ impl<T: frame_system::Config> module_cdp_treasury::WeightInfo for WeightInfo<T>
// Storage: Auction AuctionEndTime (r:0 w:1)
// Storage: Auction Auctions (r:0 w:1)
fn auction_collateral(b: u32, ) -> Weight {
(39_476_000 as Weight)
// Standard Error: 79_000
.saturating_add((11_045_000 as Weight).saturating_mul(b as Weight))
(35_898_000 as Weight)
// Standard Error: 22_000
.saturating_add((11_084_000 as Weight).saturating_mul(b as Weight))
.saturating_add(T::DbWeight::get().reads(7 as Weight))
.saturating_add(T::DbWeight::get().writes(7 as Weight))
.saturating_add(T::DbWeight::get().writes((3 as Weight).saturating_mul(b as Weight)))
}
// Storage: unknown [0x3a7472616e73616374696f6e5f6c6576656c3a] (r:1 w:1)
// Storage: Tokens Accounts (r:4 w:4)
// Storage: Tokens Accounts (r:8 w:8)
// Storage: AuctionManager TotalCollateralInAuction (r:1 w:0)
// Storage: Dex TradingPairStatuses (r:3 w:0)
// Storage: Dex LiquidityPool (r:1 w:1)
// Storage: StableAsset Pools (r:1 w:0)
// Storage: Dex TradingPairStatuses (r:5 w:0)
// Storage: Dex LiquidityPool (r:5 w:1)
// Storage: StableAsset Pools (r:2 w:1)
// Storage: AggregatedDex AggregatedSwapPaths (r:1 w:0)
// Storage: System Account (r:2 w:1)
// Storage: Homa TotalStakingBonded (r:1 w:0)
// Storage: Homa ToBondPool (r:1 w:0)
// Storage: Tokens TotalIssuance (r:2 w:1)
// Storage: Homa TotalVoidLiquid (r:1 w:0)
// Storage: System Account (r:3 w:1)
// Storage: EvmAccounts EvmAddresses (r:1 w:0)
// Storage: AssetRegistry AssetMetadatas (r:1 w:0)
fn exchange_collateral_to_stable() -> Weight {
(123_137_000 as Weight)
.saturating_add(T::DbWeight::get().reads(15 as Weight))
.saturating_add(T::DbWeight::get().writes(7 as Weight))
(333_621_000 as Weight)
.saturating_add(T::DbWeight::get().reads(33 as Weight))
.saturating_add(T::DbWeight::get().writes(13 as Weight))
}
// Storage: unknown [0x3a7472616e73616374696f6e5f6c6576656c3a] (r:1 w:1)
// Storage: CdpTreasury ExpectedCollateralAuctionSize (r:0 w:1)
fn set_expected_collateral_auction_size() -> Weight {
(13_748_000 as Weight)
(13_320_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().writes(2 as Weight))
}
// Storage: unknown [0x3a7472616e73616374696f6e5f6c6576656c3a] (r:1 w:1)
// Storage: Tokens Accounts (r:2 w:2)
// Storage: System Account (r:2 w:1)
fn extract_surplus_to_treasury() -> Weight {
(40_323_000 as Weight)
(40_013_000 as Weight)
.saturating_add(T::DbWeight::get().reads(5 as Weight))
.saturating_add(T::DbWeight::get().writes(4 as Weight))
}
Expand Down
50 changes: 27 additions & 23 deletions runtime/acala/src/weights/module_honzon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
//! Autogenerated weights for module_honzon
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2022-07-25, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! DATE: 2022-08-01, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("acala-dev"), DB CACHE: 1024
// Executed Command:
Expand All @@ -29,7 +29,7 @@
// --chain=acala-dev
// --steps=50
// --repeat=20
// --pallet=*
// --pallet=module_honzon
// --extrinsic=*
// --execution=wasm
// --wasm-execution=compiled
Expand All @@ -51,25 +51,25 @@ impl<T: frame_system::Config> module_honzon::WeightInfo for WeightInfo<T> {
// Storage: Honzon Authorization (r:1 w:1)
// Storage: Balances Reserves (r:1 w:1)
fn authorize() -> Weight {
(29_314_000 as Weight)
(29_590_000 as Weight)
.saturating_add(T::DbWeight::get().reads(3 as Weight))
.saturating_add(T::DbWeight::get().writes(3 as Weight))
}
// Storage: unknown [0x3a7472616e73616374696f6e5f6c6576656c3a] (r:1 w:1)
// Storage: Honzon Authorization (r:1 w:1)
// Storage: Balances Reserves (r:1 w:1)
fn unauthorize() -> Weight {
(31_004_000 as Weight)
(31_399_000 as Weight)
.saturating_add(T::DbWeight::get().reads(3 as Weight))
.saturating_add(T::DbWeight::get().writes(3 as Weight))
}
// Storage: unknown [0x3a7472616e73616374696f6e5f6c6576656c3a] (r:1 w:1)
// Storage: Balances Reserves (r:1 w:0)
// Storage: Honzon Authorization (r:0 w:1)
fn unauthorize_all(c: u32, ) -> Weight {
(21_015_000 as Weight)
// Standard Error: 364_000
.saturating_add((6_209_000 as Weight).saturating_mul(c as Weight))
(22_300_000 as Weight)
// Standard Error: 398_000
.saturating_add((4_857_000 as Weight).saturating_mul(c as Weight))
.saturating_add(T::DbWeight::get().reads(2 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
.saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(c as Weight)))
Expand All @@ -89,7 +89,7 @@ impl<T: frame_system::Config> module_honzon::WeightInfo for WeightInfo<T> {
// Storage: AcalaOracle Values (r:1 w:0)
// Storage: AssetRegistry AssetMetadatas (r:2 w:0)
fn adjust_loan() -> Weight {
(114_367_000 as Weight)
(104_230_000 as Weight)
.saturating_add(T::DbWeight::get().reads(16 as Weight))
.saturating_add(T::DbWeight::get().writes(8 as Weight))
}
Expand All @@ -107,7 +107,7 @@ impl<T: frame_system::Config> module_honzon::WeightInfo for WeightInfo<T> {
// Storage: System Account (r:1 w:1)
// Storage: Loans TotalPositions (r:1 w:1)
fn transfer_loan_from() -> Weight {
(85_827_000 as Weight)
(86_873_000 as Weight)
.saturating_add(T::DbWeight::get().reads(17 as Weight))
.saturating_add(T::DbWeight::get().writes(8 as Weight))
}
Expand Down Expand Up @@ -136,7 +136,7 @@ impl<T: frame_system::Config> module_honzon::WeightInfo for WeightInfo<T> {
// Storage: StableAsset Pools (r:1 w:0)
// Storage: AggregatedDex AggregatedSwapPaths (r:1 w:0)
fn close_loan_has_debit_by_dex() -> Weight {
(256_405_000 as Weight)
(257_598_000 as Weight)
.saturating_add(T::DbWeight::get().reads(37 as Weight))
.saturating_add(T::DbWeight::get().writes(16 as Weight))
}
Expand All @@ -147,7 +147,7 @@ impl<T: frame_system::Config> module_honzon::WeightInfo for WeightInfo<T> {
// Storage: System Account (r:2 w:1)
// Storage: Dex TradingPairStatuses (r:5 w:0)
// Storage: Dex LiquidityPool (r:5 w:2)
// Storage: StableAsset Pools (r:1 w:0)
// Storage: StableAsset Pools (r:2 w:0)
// Storage: AggregatedDex AggregatedSwapPaths (r:1 w:0)
// Storage: CdpEngine DebitExchangeRate (r:1 w:0)
// Storage: Loans Positions (r:1 w:1)
Expand All @@ -158,28 +158,32 @@ impl<T: frame_system::Config> module_honzon::WeightInfo for WeightInfo<T> {
// Storage: AcalaOracle Values (r:1 w:0)
// Storage: AssetRegistry AssetMetadatas (r:2 w:0)
fn expand_position_collateral() -> Weight {
(213_798_000 as Weight)
.saturating_add(T::DbWeight::get().reads(31 as Weight))
(227_767_000 as Weight)
.saturating_add(T::DbWeight::get().reads(32 as Weight))
.saturating_add(T::DbWeight::get().writes(13 as Weight))
}
// Storage: unknown [0x3a7472616e73616374696f6e5f6c6576656c3a] (r:1 w:1)
// Storage: CdpEngine CollateralParams (r:1 w:0)
// Storage: Loans Positions (r:1 w:1)
// Storage: Dex TradingPairStatuses (r:5 w:0)
// Storage: Dex LiquidityPool (r:5 w:2)
// Storage: StableAsset Pools (r:1 w:0)
// Storage: Dex LiquidityPool (r:5 w:1)
// Storage: StableAsset Pools (r:2 w:1)
// Storage: AggregatedDex AggregatedSwapPaths (r:1 w:0)
// Storage: Tokens Accounts (r:5 w:5)
// Storage: System Account (r:2 w:1)
// Storage: Homa TotalStakingBonded (r:1 w:0)
// Storage: Homa ToBondPool (r:1 w:0)
// Storage: Tokens TotalIssuance (r:3 w:2)
// Storage: Homa TotalVoidLiquid (r:1 w:0)
// Storage: Tokens Accounts (r:9 w:9)
// Storage: System Account (r:3 w:1)
// Storage: AssetRegistry AssetMetadatas (r:1 w:0)
// Storage: CdpEngine DebitExchangeRate (r:1 w:0)
// Storage: Rewards SharesAndWithdrawnRewards (r:1 w:1)
// Storage: Rewards PoolInfos (r:1 w:1)
// Storage: Loans TotalPositions (r:1 w:1)
// Storage: Tokens TotalIssuance (r:1 w:1)
fn shrink_position_debit() -> Weight {
(208_443_000 as Weight)
.saturating_add(T::DbWeight::get().reads(27 as Weight))
.saturating_add(T::DbWeight::get().writes(14 as Weight))
(365_182_000 as Weight)
.saturating_add(T::DbWeight::get().reads(39 as Weight))
.saturating_add(T::DbWeight::get().writes(19 as Weight))
}
// Storage: unknown [0x3a7472616e73616374696f6e5f6c6576656c3a] (r:1 w:1)
// Storage: Tokens Accounts (r:1 w:1)
Expand All @@ -195,7 +199,7 @@ impl<T: frame_system::Config> module_honzon::WeightInfo for WeightInfo<T> {
// Storage: Homa ToBondPool (r:1 w:0)
// Storage: Homa TotalVoidLiquid (r:1 w:0)
fn transfer_debit() -> Weight {
(134_399_000 as Weight)
(217_935_000 as Weight)
.saturating_add(T::DbWeight::get().reads(21 as Weight))
.saturating_add(T::DbWeight::get().writes(7 as Weight))
}
Expand All @@ -209,7 +213,7 @@ impl<T: frame_system::Config> module_honzon::WeightInfo for WeightInfo<T> {
// Storage: Homa TotalVoidLiquid (r:1 w:0)
// Storage: CdpEngine DebitExchangeRate (r:1 w:0)
fn precompile_get_current_collateral_ratio() -> Weight {
(32_267_000 as Weight)
(32_496_000 as Weight)
.saturating_add(T::DbWeight::get().reads(11 as Weight))
}
}
11 changes: 6 additions & 5 deletions runtime/acala/src/weights/module_prices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
//! Autogenerated weights for module_prices
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2022-07-25, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! DATE: 2022-08-01, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("acala-dev"), DB CACHE: 1024
// Executed Command:
Expand All @@ -29,7 +29,7 @@
// --chain=acala-dev
// --steps=50
// --repeat=20
// --pallet=*
// --pallet=module_prices
// --extrinsic=*
// --execution=wasm
// --wasm-execution=compiled
Expand All @@ -48,17 +48,18 @@ use sp_std::marker::PhantomData;
pub struct WeightInfo<T>(PhantomData<T>);
impl<T: frame_system::Config> module_prices::WeightInfo for WeightInfo<T> {
// Storage: unknown [0x3a7472616e73616374696f6e5f6c6576656c3a] (r:1 w:1)
// Storage: AcalaOracle Values (r:1 w:0)
// Storage: AssetRegistry AssetMetadatas (r:1 w:0)
// Storage: Prices LockedPrice (r:0 w:1)
fn lock_price() -> Weight {
(19_442_000 as Weight)
.saturating_add(T::DbWeight::get().reads(2 as Weight))
(21_712_000 as Weight)
.saturating_add(T::DbWeight::get().reads(3 as Weight))
.saturating_add(T::DbWeight::get().writes(2 as Weight))
}
// Storage: unknown [0x3a7472616e73616374696f6e5f6c6576656c3a] (r:1 w:1)
// Storage: Prices LockedPrice (r:1 w:1)
fn unlock_price() -> Weight {
(16_525_000 as Weight)
(17_165_000 as Weight)
.saturating_add(T::DbWeight::get().reads(2 as Weight))
.saturating_add(T::DbWeight::get().writes(2 as Weight))
}
Expand Down
6 changes: 2 additions & 4 deletions runtime/mandala/src/benchmarking/asset_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use crate::{AccountId, AssetRegistry, CurrencyId, GetNativeCurrencyId, Origin, Runtime, EVM};
use crate::{AccountId, AssetRegistry, CurrencyId, Origin, Runtime, EVM};

use super::utils::{dollar, set_balance};
use super::utils::{dollar, set_balance, NATIVE};
use frame_support::assert_ok;
use frame_system::RawOrigin;
use module_evm::EvmAddress;
Expand All @@ -28,8 +28,6 @@ use primitives::{currency::AssetMetadata, TokenSymbol};
use sp_std::{boxed::Box, str::FromStr, vec};
use xcm::{v1::MultiLocation, VersionedMultiLocation};

const NATIVE: CurrencyId = GetNativeCurrencyId::get();

pub fn alice() -> AccountId {
<Runtime as module_evm::Config>::AddressMapping::get_account_id(&alice_evm_addr())
}
Expand Down
10 changes: 2 additions & 8 deletions runtime/mandala/src/benchmarking/auction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,9 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use crate::{
AccountId, Auction, AuctionId, AuctionManager, AuctionTimeToClose, CdpTreasury, CurrencyId, GetStableCurrencyId,
GetStakingCurrencyId, Runtime, System,
};
use crate::{AccountId, Auction, AuctionId, AuctionManager, AuctionTimeToClose, CdpTreasury, Runtime, System};

use super::utils::{dollar, set_balance};
use super::utils::{dollar, set_balance, STABLECOIN, STAKING};
use frame_benchmarking::{account, whitelisted_caller};
use frame_support::traits::OnFinalize;
use frame_system::RawOrigin;
Expand All @@ -33,9 +30,6 @@ const SEED: u32 = 0;
const MAX_DOLLARS: u32 = 1000;
const MAX_AUCTION_ID: u32 = 100;

const STABLECOIN: CurrencyId = GetStableCurrencyId::get();
const STAKING: CurrencyId = GetStakingCurrencyId::get();

runtime_benchmarks! {
{ Runtime, orml_auction }

Expand Down
10 changes: 2 additions & 8 deletions runtime/mandala/src/benchmarking/auction_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,9 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use crate::{
AccountId, AuctionId, AuctionManager, CdpTreasury, Currencies, CurrencyId, EmergencyShutdown, GetStableCurrencyId,
GetStakingCurrencyId, Price, Runtime,
};
use crate::{AccountId, AuctionId, AuctionManager, CdpTreasury, Currencies, EmergencyShutdown, Price, Runtime};

use super::utils::{dollar, feed_price};
use super::utils::{dollar, feed_price, STABLECOIN, STAKING};
use frame_benchmarking::account;
use frame_system::RawOrigin;
use module_support::{AuctionManager as AuctionManagerTrait, CDPTreasury};
Expand All @@ -32,9 +29,6 @@ use sp_std::vec;

const SEED: u32 = 0;

const STABLECOIN: CurrencyId = GetStableCurrencyId::get();
const STAKING: CurrencyId = GetStakingCurrencyId::get();

runtime_benchmarks! {
{ Runtime, module_auction_manager }

Expand Down
Loading

0 comments on commit aa12c5d

Please sign in to comment.