From c9ccb627ebce5427dccfddbd15cd94f9dbdbe0e0 Mon Sep 17 00:00:00 2001 From: herryho Date: Tue, 27 Jul 2021 15:25:35 +0800 Subject: [PATCH 1/4] bancor add_token_to_pool benchmarking functionality --- Cargo.lock | 1 + pallets/bancor/Cargo.toml | 8 +++++ pallets/bancor/src/benchmarking.rs | 47 ++++++++++++++++++++++++++++++ pallets/bancor/src/lib.rs | 3 ++ pallets/bancor/src/mock.rs | 12 ++++++++ runtime/asgard/Cargo.toml | 1 + runtime/asgard/src/lib.rs | 1 + 7 files changed, 73 insertions(+) create mode 100644 pallets/bancor/src/benchmarking.rs diff --git a/Cargo.lock b/Cargo.lock index 600e72915e..105c7c925c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -612,6 +612,7 @@ dependencies = [ name = "bifrost-bancor" version = "0.8.0" dependencies = [ + "frame-benchmarking", "frame-support", "frame-system", "node-primitives", diff --git a/pallets/bancor/Cargo.toml b/pallets/bancor/Cargo.toml index f86fa3683d..c3b23f14f4 100644 --- a/pallets/bancor/Cargo.toml +++ b/pallets/bancor/Cargo.toml @@ -18,6 +18,8 @@ orml-tokens = { version = "0.4.1-dev", default-features = false } node-primitives = { path = "../../node/primitives", default-features = false } num-bigint = { version = "0.4", default-features = false } sp-std = { version = "3.0.0", default-features = false } +frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false, optional = true } + [dev-dependencies] sp-core = "3.0.0" @@ -38,4 +40,10 @@ std = [ "node-primitives/std", "num-bigint/std", "sp-std/std", +] + +runtime-benchmarks = [ + "frame-benchmarking", + "frame-support/runtime-benchmarks", + "frame-system/runtime-benchmarks", ] \ No newline at end of file diff --git a/pallets/bancor/src/benchmarking.rs b/pallets/bancor/src/benchmarking.rs new file mode 100644 index 0000000000..8dbffedc30 --- /dev/null +++ b/pallets/bancor/src/benchmarking.rs @@ -0,0 +1,47 @@ +// This file is part of Bifrost. + +// Copyright (C) 2019-2021 Liebi Technologies (UK) Ltd. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#![cfg(feature = "runtime-benchmarks")] + +use frame_benchmarking::{benchmarks, impl_benchmark_test_suite, whitelisted_caller}; +use frame_system::RawOrigin; +use node_primitives::{CurrencyId, TokenSymbol}; +use sp_runtime::traits::UniqueSaturatedFrom; + +use super::*; +#[allow(unused_imports)] +use crate::Pallet as Bancor; + +benchmarks! { + add_token_to_pool { + let currency_id = CurrencyId::Token(TokenSymbol::DOT); + + let caller: T::AccountId = whitelisted_caller(); + + let token_amount = BalanceOf::::unique_saturated_from(1_000_000_000_000 as u128); + }: _(RawOrigin::Signed(caller), currency_id, token_amount) + +} + +impl_benchmark_test_suite!( + Bancor, + crate::mock::ExtBuilder::default() + .one_precision_for_each_currency_type_for_whitelist_account() + .build(), + crate::mock::Test +); diff --git a/pallets/bancor/src/lib.rs b/pallets/bancor/src/lib.rs index d7b4f070fe..2fdfb096b9 100644 --- a/pallets/bancor/src/lib.rs +++ b/pallets/bancor/src/lib.rs @@ -34,6 +34,9 @@ mod mock; mod tests; pub mod weights; +#[cfg(feature = "runtime-benchmarks")] +mod benchmarking; + pub use pallet::*; type AccountIdOf = ::AccountId; diff --git a/pallets/bancor/src/mock.rs b/pallets/bancor/src/mock.rs index 79bf26159e..073d18470d 100644 --- a/pallets/bancor/src/mock.rs +++ b/pallets/bancor/src/mock.rs @@ -18,6 +18,7 @@ #![cfg(test)] +use frame_benchmarking::whitelisted_caller; use frame_support::{ construct_runtime, parameter_types, traits::{GenesisBuild, OnFinalize, OnInitialize}, @@ -165,6 +166,17 @@ impl ExtBuilder { ]) } + pub fn one_precision_for_each_currency_type_for_whitelist_account(self) -> Self { + let whitelist_caller: AccountId = whitelisted_caller(); + + self.balances(vec![ + (whitelist_caller.clone(), KSM, 2_000_000_000_000), + (whitelist_caller.clone(), DOT, 2_000_000_000_000), + (whitelist_caller.clone(), VSKSM, 2_000_000_000_000), + (whitelist_caller.clone(), VSDOT, 2_000_000_000_000), + ]) + } + pub fn build(self) -> sp_io::TestExternalities { let mut t = frame_system::GenesisConfig::default().build_storage::().unwrap(); diff --git a/runtime/asgard/Cargo.toml b/runtime/asgard/Cargo.toml index 1da5182bf2..f54196ca21 100644 --- a/runtime/asgard/Cargo.toml +++ b/runtime/asgard/Cargo.toml @@ -185,4 +185,5 @@ runtime-benchmarks = [ "xcm-builder/runtime-benchmarks", "pallet-xcm/runtime-benchmarks", "bifrost-salp/runtime-benchmarks", + "bifrost-bancor/runtime-benchmarks", ] diff --git a/runtime/asgard/src/lib.rs b/runtime/asgard/src/lib.rs index 4b7ce49229..31887d1acf 100644 --- a/runtime/asgard/src/lib.rs +++ b/runtime/asgard/src/lib.rs @@ -1482,6 +1482,7 @@ impl_runtime_apis! { let mut batches = Vec::::new(); let params = (&config, &whitelist); add_benchmark!(params, batches, bifrost_salp, Salp); + add_benchmark!(params, batches, bifrost_bancor, Bancor); if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) } Ok(batches) From dcd47d657c40163f70e68d5eaebbf4fa3bb3d461 Mon Sep 17 00:00:00 2001 From: "ron.yang" Date: Wed, 28 Jul 2021 10:36:25 +0800 Subject: [PATCH 2/4] Fix benchmarking&CI integration --- .github/workflows/pr-build.yml | 4 +++- pallets/salp/Cargo.toml | 2 ++ pallets/salp/src/benchmarking.rs | 10 +++++++--- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pr-build.yml b/.github/workflows/pr-build.yml index fb26144068..d3dd3bac79 100644 --- a/.github/workflows/pr-build.yml +++ b/.github/workflows/pr-build.yml @@ -36,7 +36,9 @@ jobs: - name: Check All run: make check-all - name: Test All - run: make test-all + run: | + make test-all + make test-benchmarking - name: Inform buddies online uses: 8398a7/action-slack@v3 if: always() && (github.event_name == 'pull_request' && github.event.pull_request.draft == false) diff --git a/pallets/salp/Cargo.toml b/pallets/salp/Cargo.toml index 0b86930027..1cd5e52bcd 100644 --- a/pallets/salp/Cargo.toml +++ b/pallets/salp/Cargo.toml @@ -17,6 +17,8 @@ sp-arithmetic = { version = "3.0.0", default-features = false } xcm = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.8", default-features = false } xcm-support = { path = "../../xcm-support", default-features = false } orml-traits = { version = "0.4.1-dev", default-features = false } +xcm-builder = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.8" } +pallet-xcm = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.8" } polkadot-parachain = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.8" } [dev-dependencies] diff --git a/pallets/salp/src/benchmarking.rs b/pallets/salp/src/benchmarking.rs index ea2aed6543..eab2c05a6c 100644 --- a/pallets/salp/src/benchmarking.rs +++ b/pallets/salp/src/benchmarking.rs @@ -42,7 +42,11 @@ fn create_fund(id: u32) -> ParaId { let caller = account("fund_creator", id, 0); - assert_ok!(CurrencyOf::::deposit(Salp::::token(), &caller, T::SubmissionDeposit::get())); + assert_ok!(::MultiCurrency::deposit( + ::DepositToken::get(), + &caller, + T::SubmissionDeposit::get() + )); assert_ok!(Salp::::create( RawOrigin::Signed(caller).into(), @@ -71,8 +75,8 @@ benchmarks! { let caller: T::AccountId = whitelisted_caller(); - CurrencyOf::::deposit( - Salp::::token(), + ::MultiCurrency::deposit( + ::DepositToken::get(), &caller, T::SubmissionDeposit::get(), )?; From 4843bf9dfa4f4532850a0ec2035efc142f33a3c2 Mon Sep 17 00:00:00 2001 From: herryho Date: Tue, 3 Aug 2021 15:14:44 +0800 Subject: [PATCH 3/4] add bancor module benchmarking --- node/service/src/chain_spec/asgard.rs | 9 ++- pallets/bancor/src/benchmarking.rs | 47 ++++++++++++- pallets/bancor/src/lib.rs | 5 +- pallets/bancor/src/mock.rs | 11 ++-- pallets/bancor/src/weights.rs | 19 ++---- runtime/asgard/src/lib.rs | 4 +- runtime/asgard/src/weights/bifrost_bancor.rs | 66 +++++++++++++++++++ .../{pallet_salp.rs => bifrost_salp.rs} | 32 ++++----- runtime/asgard/src/weights/mod.rs | 3 +- runtime/asgard/src/weights/pallet_assets.rs | 54 --------------- 10 files changed, 147 insertions(+), 103 deletions(-) create mode 100644 runtime/asgard/src/weights/bifrost_bancor.rs rename runtime/asgard/src/weights/{pallet_salp.rs => bifrost_salp.rs} (78%) delete mode 100644 runtime/asgard/src/weights/pallet_assets.rs diff --git a/node/service/src/chain_spec/asgard.rs b/node/service/src/chain_spec/asgard.rs index de21534eba..c00a5de310 100644 --- a/node/service/src/chain_spec/asgard.rs +++ b/node/service/src/chain_spec/asgard.rs @@ -24,6 +24,7 @@ use asgard_runtime::{ TokensConfig, VestingConfig, VtokenMintConfig, WASM_BINARY, }; use cumulus_primitives_core::ParaId; +use frame_benchmarking::whitelisted_caller; use hex_literal::hex; use node_primitives::{CurrencyId, TokenSymbol}; use sc_service::ChainType; @@ -126,7 +127,10 @@ pub fn asgard_genesis( } fn development_config_genesis(id: ParaId) -> GenesisConfig { - let endowed_accounts = vec![get_account_id_from_seed::("Alice")]; + let endowed_accounts = vec![ + get_account_id_from_seed::("Alice"), + whitelisted_caller(), // Benchmarking whitelist_account + ]; let balances = endowed_accounts .iter() .chain(faucet_accounts().iter()) @@ -144,7 +148,8 @@ fn development_config_genesis(id: ParaId) -> GenesisConfig { .flat_map(|x| { vec![ (x.clone(), CurrencyId::Stable(TokenSymbol::AUSD), ENDOWMENT * 10_000), - (x.clone(), CurrencyId::Token(TokenSymbol::DOT), ENDOWMENT), + (x.clone(), CurrencyId::Token(TokenSymbol::DOT), ENDOWMENT * 4_000_000), + (x.clone(), CurrencyId::VSToken(TokenSymbol::DOT), ENDOWMENT * 4_000_000), (x.clone(), CurrencyId::Token(TokenSymbol::ETH), ENDOWMENT), (x.clone(), CurrencyId::Token(TokenSymbol::KSM), ENDOWMENT), ] diff --git a/pallets/bancor/src/benchmarking.rs b/pallets/bancor/src/benchmarking.rs index 8dbffedc30..0b826d0af5 100644 --- a/pallets/bancor/src/benchmarking.rs +++ b/pallets/bancor/src/benchmarking.rs @@ -24,24 +24,65 @@ use node_primitives::{CurrencyId, TokenSymbol}; use sp_runtime::traits::UniqueSaturatedFrom; use super::*; +use crate::BancorPools; #[allow(unused_imports)] use crate::Pallet as Bancor; benchmarks! { add_token_to_pool { let currency_id = CurrencyId::Token(TokenSymbol::DOT); + let caller: T::AccountId = whitelisted_caller(); + let token_amount = BalanceOf::::unique_saturated_from(10u32 as u128); + }: _(RawOrigin::Signed(caller), currency_id, token_amount) + exchange_for_token { let caller: T::AccountId = whitelisted_caller(); + let currency_id = CurrencyId::Token(TokenSymbol::DOT); + let vstoken_amount = BalanceOf::::unique_saturated_from(1u128); + let token_out_min = BalanceOf::::unique_saturated_from(0u128); - let token_amount = BalanceOf::::unique_saturated_from(1_000_000_000_000 as u128); - }: _(RawOrigin::Signed(caller), currency_id, token_amount) + // add token to the pool + BancorPools::::mutate(currency_id, |pool_info_option|{ + let pool_info = pool_info_option.as_mut().unwrap(); + + pool_info.token_ceiling = + pool_info.token_ceiling.saturating_add(BalanceOf::::unique_saturated_from(10u128)); + }); + + }: _(RawOrigin::Signed(caller), currency_id, vstoken_amount, token_out_min) + + exchange_for_vstoken { + let caller: T::AccountId = whitelisted_caller(); + let currency_id = CurrencyId::Token(TokenSymbol::DOT); + let token_amount = BalanceOf::::unique_saturated_from(100u128); + let vstoken_out_min = BalanceOf::::unique_saturated_from(0u128); + + BancorPools::::mutate(currency_id, |pool| { + let pool_info = pool.as_mut().unwrap(); + pool_info.token_pool = pool_info.token_pool.saturating_add(token_amount); + pool_info.vstoken_pool = pool_info.vstoken_pool.saturating_add(token_amount); + }); + }: _(RawOrigin::Signed(caller), currency_id, token_amount, vstoken_out_min) + + on_initialize { + let currency_id = CurrencyId::Token(TokenSymbol::DOT); + let caller: T::AccountId = whitelisted_caller(); + let token_amount = BalanceOf::::unique_saturated_from(7200 as u128); + + BancorPools::::mutate(currency_id, |pool| { + let pool_info = pool.as_mut().unwrap(); + pool_info.token_pool = pool_info.token_pool.saturating_add(token_amount); + }); + + let block_num = T::BlockNumber::from(100u32); + }:{Bancor::::on_initialize(block_num);} } impl_benchmark_test_suite!( Bancor, crate::mock::ExtBuilder::default() - .one_precision_for_each_currency_type_for_whitelist_account() + .one_hundred_precision_for_each_currency_type_for_whitelist_account() .build(), crate::mock::Test ); diff --git a/pallets/bancor/src/lib.rs b/pallets/bancor/src/lib.rs index 2fdfb096b9..7fe451a6ec 100644 --- a/pallets/bancor/src/lib.rs +++ b/pallets/bancor/src/lib.rs @@ -28,7 +28,7 @@ use sp_runtime::{ traits::{CheckedAdd, CheckedDiv, CheckedMul, CheckedSub, Saturating, Zero}, SaturatedConversion, }; -use weights::WeightInfo; +pub use weights::WeightInfo; mod mock; mod tests; @@ -226,8 +226,7 @@ pub mod pallet { } } - // TODO: Estimate weight for this function - 1_000 + T::WeightInfo::on_initialize() } } diff --git a/pallets/bancor/src/mock.rs b/pallets/bancor/src/mock.rs index 073d18470d..bf88009a3a 100644 --- a/pallets/bancor/src/mock.rs +++ b/pallets/bancor/src/mock.rs @@ -18,6 +18,7 @@ #![cfg(test)] +#[cfg(feature = "runtime-benchmarks")] use frame_benchmarking::whitelisted_caller; use frame_support::{ construct_runtime, parameter_types, @@ -166,14 +167,14 @@ impl ExtBuilder { ]) } - pub fn one_precision_for_each_currency_type_for_whitelist_account(self) -> Self { + pub fn one_hundred_precision_for_each_currency_type_for_whitelist_account(self) -> Self { let whitelist_caller: AccountId = whitelisted_caller(); self.balances(vec![ - (whitelist_caller.clone(), KSM, 2_000_000_000_000), - (whitelist_caller.clone(), DOT, 2_000_000_000_000), - (whitelist_caller.clone(), VSKSM, 2_000_000_000_000), - (whitelist_caller.clone(), VSDOT, 2_000_000_000_000), + (whitelist_caller.clone(), KSM, 100_000_000_000_000), + (whitelist_caller.clone(), DOT, 100_000_000_000_000), + (whitelist_caller.clone(), VSKSM, 100_000_000_000_000), + (whitelist_caller.clone(), VSDOT, 100_000_000_000_000), ]) } diff --git a/pallets/bancor/src/weights.rs b/pallets/bancor/src/weights.rs index 1ecc861260..85d1ebe635 100644 --- a/pallets/bancor/src/weights.rs +++ b/pallets/bancor/src/weights.rs @@ -30,11 +30,11 @@ pub trait WeightInfo { fn add_token_to_pool() -> Weight; fn exchange_for_token() -> Weight; fn exchange_for_vstoken() -> Weight; + fn on_initialize() -> Weight; } -/// Weights for the pallet using the Bifrost node and recommended hardware. -pub struct BifrostWeight(PhantomData); -impl WeightInfo for BifrostWeight { +// For backwards compatibility and tests +impl WeightInfo for () { fn add_token_to_pool() -> Weight { (50_000_000 as Weight) } @@ -46,19 +46,8 @@ impl WeightInfo for BifrostWeight { fn exchange_for_vstoken() -> Weight { (50_000_000 as Weight) } -} - -// For backwards compatibility and tests -impl WeightInfo for () { - fn add_token_to_pool() -> Weight { - (50_000_000 as Weight) - } - fn exchange_for_token() -> Weight { - (50_000_000 as Weight) - } - - fn exchange_for_vstoken() -> Weight { + fn on_initialize() -> Weight { (50_000_000 as Weight) } } diff --git a/runtime/asgard/src/lib.rs b/runtime/asgard/src/lib.rs index abde1c59ef..cffc4bae39 100644 --- a/runtime/asgard/src/lib.rs +++ b/runtime/asgard/src/lib.rs @@ -963,7 +963,7 @@ impl bifrost_salp::Config for Runtime { type SubmissionDeposit = SubmissionDeposit; type VSBondValidPeriod = VSBondValidPeriod; type XcmTransferOrigin = XcmTransferOrigin; - type WeightInfo = weights::pallet_salp::WeightInfo; // bifrost_salp::TestWeightInfo; + type WeightInfo = weights::bifrost_salp::WeightInfo; // bifrost_salp::TestWeightInfo; } parameter_types! { @@ -976,7 +976,7 @@ impl bifrost_bancor::Config for Runtime { type InterventionPercentage = InterventionPercentage; type DailyReleasePercentage = DailyReleasePercentage; type MultiCurrency = Currencies; - type WeightInfo = bifrost_bancor::weights::BifrostWeight; + type WeightInfo = weights::bifrost_bancor::WeightInfo; } parameter_types! { diff --git a/runtime/asgard/src/weights/bifrost_bancor.rs b/runtime/asgard/src/weights/bifrost_bancor.rs new file mode 100644 index 0000000000..cbfc8d80b9 --- /dev/null +++ b/runtime/asgard/src/weights/bifrost_bancor.rs @@ -0,0 +1,66 @@ +// This file is part of Bifrost. + +// Copyright (C) 2019-2021 Liebi Technologies (UK) Ltd. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +//! Autogenerated weights for bifrost_bancor +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 3.0.0 +//! DATE: 2021-08-03, STEPS: `[50, ]`, REPEAT: 1, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("asgard-dev"), DB CACHE: 128 + +// Executed Command: +// target/release/bifrost +// benchmark +// --chain=asgard-dev +// --steps=50 +// --repeat=1 +// --pallet=bifrost-bancor +// --extrinsic=* +// --execution=wasm +// --wasm-execution=compiled +// --heap-pages=4096 +// --header=./HEADER-GPL3 +// --output=./runtime/asgard/src/weights/bifrost_bancor.rs + +#![allow(unused_parens)] +#![allow(unused_imports)] + +use frame_support::{traits::Get, weights::Weight}; +use sp_std::marker::PhantomData; + +/// Weight functions for bifrost_bancor. +pub struct WeightInfo(PhantomData); +impl bifrost_bancor::WeightInfo for WeightInfo { + fn add_token_to_pool() -> Weight { + (64_732_000 as Weight) + .saturating_add(T::DbWeight::get().reads(3 as Weight)) + .saturating_add(T::DbWeight::get().writes(3 as Weight)) + } + fn exchange_for_token() -> Weight { + (94_428_000 as Weight) + .saturating_add(T::DbWeight::get().reads(3 as Weight)) + .saturating_add(T::DbWeight::get().writes(3 as Weight)) + } + fn exchange_for_vstoken() -> Weight { + (82_786_000 as Weight) + .saturating_add(T::DbWeight::get().reads(3 as Weight)) + .saturating_add(T::DbWeight::get().writes(3 as Weight)) + } + fn on_initialize() -> Weight { + (22_914_000 as Weight).saturating_add(T::DbWeight::get().reads(3 as Weight)) + } +} diff --git a/runtime/asgard/src/weights/pallet_salp.rs b/runtime/asgard/src/weights/bifrost_salp.rs similarity index 78% rename from runtime/asgard/src/weights/pallet_salp.rs rename to runtime/asgard/src/weights/bifrost_salp.rs index 5b82ba2d59..4f95249a7f 100644 --- a/runtime/asgard/src/weights/pallet_salp.rs +++ b/runtime/asgard/src/weights/bifrost_salp.rs @@ -19,24 +19,22 @@ //! Autogenerated weights for bifrost_salp //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 3.0.0 -//! DATE: 2021-07-11, STEPS: `[50, ]`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2021-07-30, STEPS: `[50, ]`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("asgard-dev"), DB CACHE: 128 // Executed Command: -// target/debug/bifrost +// target/release/bifrost // benchmark -// --chain -// asgard-dev +// --chain=asgard-dev // --steps=50 // --repeat=20 -// --pallet=bifrost-salp -// --extrinsic -// * +// --pallet=bifrost_salp +// --extrinsic=* // --execution=wasm // --wasm-execution=compiled // --heap-pages=4096 // --header=./HEADER-GPL3 -// --output=./runtime/asgard/src/weights/salp.rs +// --output=./runtime/asgard/src/weights/bifrost_salp.rs #![allow(unused_parens)] #![allow(unused_imports)] @@ -48,22 +46,20 @@ use sp_std::marker::PhantomData; pub struct WeightInfo(PhantomData); impl bifrost_salp::WeightInfo for WeightInfo { fn create() -> Weight { - (2_345_291_000 as Weight) - .saturating_add(T::DbWeight::get().reads(3 as Weight)) - .saturating_add(T::DbWeight::get().writes(3 as Weight)) + (60_294_000 as Weight) + .saturating_add(T::DbWeight::get().reads(2 as Weight)) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) } - fn contribute() -> Weight { - (1_251_633_000 as Weight) + (63_079_000 as Weight) .saturating_add(T::DbWeight::get().reads(4 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } - fn on_finalize(n: u32) -> Weight { - (290_825_000 as Weight) - // Standard Error: 5_000 - .saturating_add((399_000 as Weight).saturating_mul(n as Weight)) - .saturating_add(T::DbWeight::get().reads(2 as Weight)) + (8_753_000 as Weight) + // Standard Error: 0 + .saturating_add((214_000 as Weight).saturating_mul(n as Weight)) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } } diff --git a/runtime/asgard/src/weights/mod.rs b/runtime/asgard/src/weights/mod.rs index 3cdec6fda5..2206502d2c 100644 --- a/runtime/asgard/src/weights/mod.rs +++ b/runtime/asgard/src/weights/mod.rs @@ -20,5 +20,6 @@ //! A list of the different weight modules for our runtime. -pub mod pallet_salp; +pub mod bifrost_bancor; +pub mod bifrost_salp; pub mod pallet_vesting; diff --git a/runtime/asgard/src/weights/pallet_assets.rs b/runtime/asgard/src/weights/pallet_assets.rs deleted file mode 100644 index 559d2ee809..0000000000 --- a/runtime/asgard/src/weights/pallet_assets.rs +++ /dev/null @@ -1,54 +0,0 @@ -// This file is part of Bifrost. - -// Copyright (C) 2019-2021 Liebi Technologies (UK) Ltd. -// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 2.0.0 - -use frame_support::{traits::Get, weights::Weight}; -use sp_std::marker::PhantomData; -pub struct WeightInfo(PhantomData); -impl bifrost_assets::WeightInfo for WeightInfo { - fn create() -> Weight { - (65949000 as Weight) - //.saturating_add(T::DbWeight::get().reads(0 as Weight)) - .saturating_add(T::DbWeight::get().writes(1 as Weight)) - } - fn create_pair() -> Weight { - (65949000 as Weight) - .saturating_add(T::DbWeight::get().writes(1 as Weight)) - } - fn issue() -> Weight { - (46665000 as Weight) - .saturating_add(T::DbWeight::get().reads(1 as Weight)) - .saturating_add(T::DbWeight::get().writes(1 as Weight)) - } - fn transfer() -> Weight { - (27086000 as Weight) - .saturating_add(T::DbWeight::get().reads(1 as Weight)) - .saturating_add(T::DbWeight::get().writes(1 as Weight)) - } - fn destroy() -> Weight { - (39_603_000 as Weight) - .saturating_add(T::DbWeight::get().reads(1 as Weight)) - .saturating_add(T::DbWeight::get().writes(1 as Weight)) - } - fn redeem() -> Weight { - (110_679_000 as Weight) - .saturating_add(T::DbWeight::get().reads(1 as Weight)) - .saturating_add(T::DbWeight::get().writes(1 as Weight)) - } -} \ No newline at end of file From 5f80643aee8dd7d0022070ef0459595df0bf1a95 Mon Sep 17 00:00:00 2001 From: herryho Date: Tue, 3 Aug 2021 16:10:05 +0800 Subject: [PATCH 4/4] fixes --- pallets/bancor/src/mock.rs | 1 + runtime/dev/src/lib.rs | 4 +- runtime/dev/src/weights/bifrost_bancor.rs | 66 +++++++++++++++++++ .../{pallet_salp.rs => bifrost_salp.rs} | 32 ++++----- runtime/dev/src/weights/mod.rs | 3 +- runtime/dev/src/weights/pallet_assets.rs | 53 --------------- 6 files changed, 85 insertions(+), 74 deletions(-) create mode 100644 runtime/dev/src/weights/bifrost_bancor.rs rename runtime/dev/src/weights/{pallet_salp.rs => bifrost_salp.rs} (78%) delete mode 100644 runtime/dev/src/weights/pallet_assets.rs diff --git a/pallets/bancor/src/mock.rs b/pallets/bancor/src/mock.rs index bf88009a3a..6f1c175456 100644 --- a/pallets/bancor/src/mock.rs +++ b/pallets/bancor/src/mock.rs @@ -167,6 +167,7 @@ impl ExtBuilder { ]) } + #[cfg(feature = "runtime-benchmarks")] pub fn one_hundred_precision_for_each_currency_type_for_whitelist_account(self) -> Self { let whitelist_caller: AccountId = whitelisted_caller(); diff --git a/runtime/dev/src/lib.rs b/runtime/dev/src/lib.rs index c274ece108..a248b4c24d 100644 --- a/runtime/dev/src/lib.rs +++ b/runtime/dev/src/lib.rs @@ -945,7 +945,7 @@ impl bifrost_salp::Config for Runtime { type SubmissionDeposit = SubmissionDeposit; type VSBondValidPeriod = VSBondValidPeriod; type XcmTransferOrigin = XcmTransferOrigin; - type WeightInfo = weights::pallet_salp::WeightInfo; // bifrost_salp::TestWeightInfo; + type WeightInfo = weights::bifrost_salp::WeightInfo; // bifrost_salp::TestWeightInfo; } parameter_types! { @@ -958,7 +958,7 @@ impl bifrost_bancor::Config for Runtime { type InterventionPercentage = InterventionPercentage; type DailyReleasePercentage = DailyReleasePercentage; type MultiCurrency = Currencies; - type WeightInfo = bifrost_bancor::weights::BifrostWeight; + type WeightInfo = weights::bifrost_bancor::WeightInfo; } parameter_types! { diff --git a/runtime/dev/src/weights/bifrost_bancor.rs b/runtime/dev/src/weights/bifrost_bancor.rs new file mode 100644 index 0000000000..cbfc8d80b9 --- /dev/null +++ b/runtime/dev/src/weights/bifrost_bancor.rs @@ -0,0 +1,66 @@ +// This file is part of Bifrost. + +// Copyright (C) 2019-2021 Liebi Technologies (UK) Ltd. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +//! Autogenerated weights for bifrost_bancor +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 3.0.0 +//! DATE: 2021-08-03, STEPS: `[50, ]`, REPEAT: 1, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("asgard-dev"), DB CACHE: 128 + +// Executed Command: +// target/release/bifrost +// benchmark +// --chain=asgard-dev +// --steps=50 +// --repeat=1 +// --pallet=bifrost-bancor +// --extrinsic=* +// --execution=wasm +// --wasm-execution=compiled +// --heap-pages=4096 +// --header=./HEADER-GPL3 +// --output=./runtime/asgard/src/weights/bifrost_bancor.rs + +#![allow(unused_parens)] +#![allow(unused_imports)] + +use frame_support::{traits::Get, weights::Weight}; +use sp_std::marker::PhantomData; + +/// Weight functions for bifrost_bancor. +pub struct WeightInfo(PhantomData); +impl bifrost_bancor::WeightInfo for WeightInfo { + fn add_token_to_pool() -> Weight { + (64_732_000 as Weight) + .saturating_add(T::DbWeight::get().reads(3 as Weight)) + .saturating_add(T::DbWeight::get().writes(3 as Weight)) + } + fn exchange_for_token() -> Weight { + (94_428_000 as Weight) + .saturating_add(T::DbWeight::get().reads(3 as Weight)) + .saturating_add(T::DbWeight::get().writes(3 as Weight)) + } + fn exchange_for_vstoken() -> Weight { + (82_786_000 as Weight) + .saturating_add(T::DbWeight::get().reads(3 as Weight)) + .saturating_add(T::DbWeight::get().writes(3 as Weight)) + } + fn on_initialize() -> Weight { + (22_914_000 as Weight).saturating_add(T::DbWeight::get().reads(3 as Weight)) + } +} diff --git a/runtime/dev/src/weights/pallet_salp.rs b/runtime/dev/src/weights/bifrost_salp.rs similarity index 78% rename from runtime/dev/src/weights/pallet_salp.rs rename to runtime/dev/src/weights/bifrost_salp.rs index 5b82ba2d59..4f95249a7f 100644 --- a/runtime/dev/src/weights/pallet_salp.rs +++ b/runtime/dev/src/weights/bifrost_salp.rs @@ -19,24 +19,22 @@ //! Autogenerated weights for bifrost_salp //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 3.0.0 -//! DATE: 2021-07-11, STEPS: `[50, ]`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2021-07-30, STEPS: `[50, ]`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("asgard-dev"), DB CACHE: 128 // Executed Command: -// target/debug/bifrost +// target/release/bifrost // benchmark -// --chain -// asgard-dev +// --chain=asgard-dev // --steps=50 // --repeat=20 -// --pallet=bifrost-salp -// --extrinsic -// * +// --pallet=bifrost_salp +// --extrinsic=* // --execution=wasm // --wasm-execution=compiled // --heap-pages=4096 // --header=./HEADER-GPL3 -// --output=./runtime/asgard/src/weights/salp.rs +// --output=./runtime/asgard/src/weights/bifrost_salp.rs #![allow(unused_parens)] #![allow(unused_imports)] @@ -48,22 +46,20 @@ use sp_std::marker::PhantomData; pub struct WeightInfo(PhantomData); impl bifrost_salp::WeightInfo for WeightInfo { fn create() -> Weight { - (2_345_291_000 as Weight) - .saturating_add(T::DbWeight::get().reads(3 as Weight)) - .saturating_add(T::DbWeight::get().writes(3 as Weight)) + (60_294_000 as Weight) + .saturating_add(T::DbWeight::get().reads(2 as Weight)) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) } - fn contribute() -> Weight { - (1_251_633_000 as Weight) + (63_079_000 as Weight) .saturating_add(T::DbWeight::get().reads(4 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } - fn on_finalize(n: u32) -> Weight { - (290_825_000 as Weight) - // Standard Error: 5_000 - .saturating_add((399_000 as Weight).saturating_mul(n as Weight)) - .saturating_add(T::DbWeight::get().reads(2 as Weight)) + (8_753_000 as Weight) + // Standard Error: 0 + .saturating_add((214_000 as Weight).saturating_mul(n as Weight)) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } } diff --git a/runtime/dev/src/weights/mod.rs b/runtime/dev/src/weights/mod.rs index 3cdec6fda5..2206502d2c 100644 --- a/runtime/dev/src/weights/mod.rs +++ b/runtime/dev/src/weights/mod.rs @@ -20,5 +20,6 @@ //! A list of the different weight modules for our runtime. -pub mod pallet_salp; +pub mod bifrost_bancor; +pub mod bifrost_salp; pub mod pallet_vesting; diff --git a/runtime/dev/src/weights/pallet_assets.rs b/runtime/dev/src/weights/pallet_assets.rs deleted file mode 100644 index 82ec7cfe61..0000000000 --- a/runtime/dev/src/weights/pallet_assets.rs +++ /dev/null @@ -1,53 +0,0 @@ -// This file is part of Bifrost. - -// Copyright (C) 2019-2021 Liebi Technologies (UK) Ltd. -// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 2.0.0 - -use frame_support::{traits::Get, weights::Weight}; -use sp_std::marker::PhantomData; -pub struct WeightInfo(PhantomData); -impl bifrost_assets::WeightInfo for WeightInfo { - fn create() -> Weight { - (65949000 as Weight) - //.saturating_add(T::DbWeight::get().reads(0 as Weight)) - .saturating_add(T::DbWeight::get().writes(1 as Weight)) - } - fn create_pair() -> Weight { - (65949000 as Weight).saturating_add(T::DbWeight::get().writes(1 as Weight)) - } - fn issue() -> Weight { - (46665000 as Weight) - .saturating_add(T::DbWeight::get().reads(1 as Weight)) - .saturating_add(T::DbWeight::get().writes(1 as Weight)) - } - fn transfer() -> Weight { - (27086000 as Weight) - .saturating_add(T::DbWeight::get().reads(1 as Weight)) - .saturating_add(T::DbWeight::get().writes(1 as Weight)) - } - fn destroy() -> Weight { - (39_603_000 as Weight) - .saturating_add(T::DbWeight::get().reads(1 as Weight)) - .saturating_add(T::DbWeight::get().writes(1 as Weight)) - } - fn redeem() -> Weight { - (110_679_000 as Weight) - .saturating_add(T::DbWeight::get().reads(1 as Weight)) - .saturating_add(T::DbWeight::get().writes(1 as Weight)) - } -}