Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate WeightInfo Automatically #380

Merged
merged 20 commits into from
Nov 2, 2021
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
54f5996
:bug: ($PALLET) Fix bancor bench error
AllenPocketGamer Oct 17, 2021
c80f020
:bug: ($PALLET) Fix vtoken-mint bench error
AllenPocketGamer Oct 17, 2021
05c8399
:wrench: ($PROJ) Add more phony
AllenPocketGamer Oct 18, 2021
5a3270f
:bug: ($PALLETS) Fix benchmark errors that occur by compile
AllenPocketGamer Oct 26, 2021
263b5b6
:sparkles: ($RUNTIME) Supple the benchmark settings that missing on B…
AllenPocketGamer Oct 26, 2021
db87289
:fire: ($RUNTIME) Unlist pallet_* benchmarks
AllenPocketGamer Oct 26, 2021
0378d4c
:recycle: ($SCRIPT) Refactor script that generates weightInfos
AllenPocketGamer Oct 27, 2021
c5c1c34
:fire: ($RUNTIME) Remove useless code
AllenPocketGamer Oct 27, 2021
7dc2fbc
:recycle: ($SCRIPT) Refactor ..
AllenPocketGamer Oct 27, 2021
bd74b6a
:construction_worker: ($CI) Try to generate all-runtime weight files
AllenPocketGamer Oct 27, 2021
de9782b
:art: ($RUNTIME) Format ..
AllenPocketGamer Oct 27, 2021
8f21138
:construction: ($CI) Close check & test temporarily
AllenPocketGamer Oct 27, 2021
de85f38
:construction: ($CI) Working around..
AllenPocketGamer Oct 27, 2021
8f668e5
:bug: ($SCRIPT) Fix Syntax error 2
AllenPocketGamer Oct 27, 2021
6aee672
:construction_worker: ($CI) Modify ci flow
AllenPocketGamer Oct 28, 2021
2a79887
:bug: ($CI) Fix ci syntax error
AllenPocketGamer Oct 28, 2021
0d0f84e
:bug: ($PALLET) Fix bench errors of lightening-redeem
AllenPocketGamer Oct 28, 2021
7cad829
:bug: ($CI) Remove file_pattern option
AllenPocketGamer Oct 28, 2021
c03f372
🤖 ($WEIGHT) Generate weightInfo files automatically
AllenPocketGamer Oct 28, 2021
1d4649b
Merge branch 'develop' into fix-bench-errs
ark930 Nov 2, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ env:
jobs:
build:
if: "!contains(github.event.commits[0].message, '[skip ci]')"
runs-on: self-hosted
runs-on: [self-hosted, normal]
steps:
- name: Check to latest commit
uses: actions/checkout@v2
Expand All @@ -42,4 +42,27 @@ jobs:
status: ${{ job.status }}
fields: repo,author,eventName,workflow,ref,commit
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_PULLREQUEST_WEBHOOK_URL }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_PULLREQUEST_WEBHOOK_URL }}
bench:
if: "!contains(github.event.commits[0].message, '[skip ci]')"
runs-on: [self-hosted, bench]
steps:
- name: Check to latest commit
uses: actions/checkout@v2
with:
submodules: recursive
- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly-2021-09-12
components: rustfmt
target: wasm32-unknown-unknown
default: true
- name: Generate WeightInfo Files
run: make generate-all-weights
- name: Commit Automatically
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: 🤖 ($WEIGHT) Generate weightInfo files automatically
# file_pattern: runtime/**/*.rs
26 changes: 23 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,29 @@ format:
test-benchmarking:
cargo test --features runtime-benchmarks --features with-all-runtime --features --all benchmarking

.PHONY: run-benchmarking
run-benchmarking:
./scripts/run_all_benches.sh
.PHONY: generate-bifrost-weights
generate-bifrost-weights:
bash ./scripts/generate-weights.sh bifrost

.PHONY: generate-asgard-weights
generate-asgard-weights:
bash ./scripts/generate-weights.sh asgard

.PHONY: generate-all-weights
generate-all-weights:
bash ./scripts/generate-weights.sh asgard bifrost

.PHONY: build-asgard-release-with-bench
build-asgard-release-with-bench: copy-genesis-config-release
cargo build -p node-cli --locked --features "with-asgard-runtime,runtime-benchmarks" --release

.PHONY: build-bifrost-release-with-bench
build-bifrost-release-with-bench: copy-genesis-config-release
cargo build -p node-cli --locked --features "with-bifrost-runtime,runtime-benchmarks" --release

.PHONY: build-all-release-with-bench
build-all-release-with-bench: copy-genesis-config-release
cargo build -p node-cli --locked --features "with-all-runtime,runtime-benchmarks" --release

# Deploy
.PHONY: deploy-asgard-local
Expand Down
5 changes: 5 additions & 0 deletions node/service/src/chain_spec/bifrost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ fn local_config_genesis(id: ParaId) -> GenesisConfig {
CurrencyId::VSBond(TokenSymbol::KSM, 3000, 13, 20),
ENDOWMENT * 4_000_000,
),
(
x.clone(),
CurrencyId::VSBond(TokenSymbol::BNC, 2001, 13, 20),
ENDOWMENT * 4_000_000,
),
]
})
.collect();
Expand Down
8 changes: 4 additions & 4 deletions pallets/bancor/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ use crate::Pallet as Bancor;

benchmarks! {
add_token_to_pool {
let currency_id = CurrencyId::Token(TokenSymbol::DOT);
let currency_id = CurrencyId::Token(TokenSymbol::KSM);
let caller: T::AccountId = whitelisted_caller();
let token_amount = BalanceOf::<T>::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 currency_id = CurrencyId::Token(TokenSymbol::KSM);
let vstoken_amount = BalanceOf::<T>::unique_saturated_from(1u128);
let token_out_min = BalanceOf::<T>::unique_saturated_from(0u128);

Expand All @@ -53,7 +53,7 @@ benchmarks! {

exchange_for_vstoken {
let caller: T::AccountId = whitelisted_caller();
let currency_id = CurrencyId::Token(TokenSymbol::DOT);
let currency_id = CurrencyId::Token(TokenSymbol::KSM);
let token_amount = BalanceOf::<T>::unique_saturated_from(100u128);
let vstoken_out_min = BalanceOf::<T>::unique_saturated_from(0u128);

Expand All @@ -65,7 +65,7 @@ benchmarks! {
}: _(RawOrigin::Signed(caller), currency_id, token_amount, vstoken_out_min)

on_initialize {
let currency_id = CurrencyId::Token(TokenSymbol::DOT);
let currency_id = CurrencyId::Token(TokenSymbol::KSM);
let caller: T::AccountId = whitelisted_caller();
let token_amount = BalanceOf::<T>::unique_saturated_from(7200 as u128);

Expand Down
6 changes: 3 additions & 3 deletions pallets/lightening-redeem/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,20 @@ benchmarks! {
edit_exchange_price {
let origin = T::ControlOrigin::successful_origin();
let price = BalanceOf::<T>::unique_saturated_from(50u128);
let call = Call::<T>::edit_exchange_price(price);
let call = Call::<T>::edit_exchange_price { price };
}: {call.dispatch_bypass_filter(origin)?}

edit_release_per_day {
let origin = T::ControlOrigin::successful_origin();
let amount_per_day = BalanceOf::<T>::unique_saturated_from(50u128);
let call = Call::<T>::edit_release_per_day(amount_per_day);
let call = Call::<T>::edit_release_per_day { amount_per_day };
}: {call.dispatch_bypass_filter(origin)?}

edit_release_start_and_end_block {
let origin = T::ControlOrigin::successful_origin();
let start = BlockNumberFor::<T>::from(50u32);
let end = BlockNumberFor::<T>::from(100u32);
let call = Call::<T>::edit_release_start_and_end_block(start, end);
let call = Call::<T>::edit_release_start_and_end_block { start, end };
}: {call.dispatch_bypass_filter(origin)?}

on_initialize {
Expand Down
2 changes: 1 addition & 1 deletion pallets/salp/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ benchmarks! {
for i in 0 .. k {
caller = account("contributor", i, 0);
contribute_fund::<T>(&caller,fund_index);
Salp::<T>::confirm_contribute(
let _ = Salp::<T>::confirm_contribute(
RawOrigin::Root.into(),
caller.clone(),
fund_index,
Expand Down
16 changes: 8 additions & 8 deletions pallets/token-issuer/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,41 +32,41 @@ benchmarks! {
let origin = T::ControlOrigin::successful_origin();
let account: T::AccountId = whitelisted_caller();
let currency_id = CurrencyId::Token(TokenSymbol::KSM);
let call = Call::<T>::add_to_issue_whitelist(currency_id, account);
let call = Call::<T>::add_to_issue_whitelist { currency_id, account };
}: {call.dispatch_bypass_filter(origin)?}

remove_from_issue_whitelist {
let origin = T::ControlOrigin::successful_origin();
let account: T::AccountId = whitelisted_caller();
let currency_id = CurrencyId::Token(TokenSymbol::KSM);
let add_call = Call::<T>::add_to_issue_whitelist(currency_id, account.clone());
let add_call = Call::<T>::add_to_issue_whitelist { currency_id, account: account.clone() };
add_call.dispatch_bypass_filter(origin.clone())?;

let remove_call = Call::<T>::remove_from_issue_whitelist(currency_id, account);
let remove_call = Call::<T>::remove_from_issue_whitelist { currency_id, account };
}: {remove_call.dispatch_bypass_filter(origin)?}

add_to_transfer_whitelist {
let origin = T::ControlOrigin::successful_origin();
let account: T::AccountId = whitelisted_caller();
let currency_id = CurrencyId::Token(TokenSymbol::KSM);
let call = Call::<T>::add_to_transfer_whitelist(currency_id, account);
let call = Call::<T>::add_to_transfer_whitelist { currency_id, account };
}: {call.dispatch_bypass_filter(origin)?}

remove_from_transfer_whitelist {
let origin = T::ControlOrigin::successful_origin();
let account: T::AccountId = whitelisted_caller();
let currency_id = CurrencyId::Token(TokenSymbol::KSM);
let add_call = Call::<T>::add_to_transfer_whitelist(currency_id, account.clone());
let add_call = Call::<T>::add_to_transfer_whitelist { currency_id, account: account.clone() };
add_call.dispatch_bypass_filter(origin.clone())?;

let remove_call = Call::<T>::remove_from_transfer_whitelist(currency_id, account);
let remove_call = Call::<T>::remove_from_transfer_whitelist { currency_id, account };
}: {remove_call.dispatch_bypass_filter(origin)?}

issue {
let origin = T::ControlOrigin::successful_origin();
let caller: T::AccountId = whitelisted_caller();
let currency_id = CurrencyId::Token(TokenSymbol::KSM);
let add_call = Call::<T>::add_to_issue_whitelist(currency_id.clone(), caller.clone());
let add_call = Call::<T>::add_to_issue_whitelist { currency_id: currency_id.clone(), account: caller.clone() };
add_call.dispatch_bypass_filter(origin.clone())?;

let original_balance = T::MultiCurrency::free_balance(currency_id.clone(), &caller);
Expand All @@ -82,7 +82,7 @@ benchmarks! {
let currency_id = CurrencyId::Token(TokenSymbol::KSM);

// add caller to the transfer whitelist
let add_transfer_call = Call::<T>::add_to_transfer_whitelist(currency_id.clone(), caller.clone());
let add_transfer_call = Call::<T>::add_to_transfer_whitelist { currency_id: currency_id.clone(), account: caller.clone() };
add_transfer_call.dispatch_bypass_filter(origin.clone())?;

// transfer some ksm from caller account to receiver account
Expand Down
16 changes: 8 additions & 8 deletions pallets/vtoken-mint/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,31 @@ use crate::Pallet as VtokenMint;

benchmarks! {
set_token_staking_lock_period {
let token_id = CurrencyId::Token(TokenSymbol::DOT);
let token_id = CurrencyId::Token(TokenSymbol::KSM);
let locking_blocks = T::BlockNumber::from(100u32);
}: _(RawOrigin::Root, token_id, locking_blocks)

set_vtoken_pool {
let currency_id = CurrencyId::Token(TokenSymbol::DOT);
let currency_id = CurrencyId::Token(TokenSymbol::KSM);
let new_token_pool = BalanceOf::<T>::unique_saturated_from(10u32 as u128);
let new_vtoken_pool = BalanceOf::<T>::unique_saturated_from(20u32 as u128);
}: _(RawOrigin::Root, currency_id, new_token_pool, new_vtoken_pool)

mint {
VtokenMint::<T>::expand_mint_pool(CurrencyId::Token(TokenSymbol::DOT), BalanceOf::<T>::unique_saturated_from(100u32 as u128))?;
VtokenMint::<T>::expand_mint_pool(CurrencyId::VToken(TokenSymbol::DOT), BalanceOf::<T>::unique_saturated_from(200u32 as u128))?;
VtokenMint::<T>::expand_mint_pool(CurrencyId::Token(TokenSymbol::KSM), BalanceOf::<T>::unique_saturated_from(100u32 as u128))?;
VtokenMint::<T>::expand_mint_pool(CurrencyId::VToken(TokenSymbol::KSM), BalanceOf::<T>::unique_saturated_from(200u32 as u128))?;

let caller: T::AccountId = whitelisted_caller();
let vtoken_id = CurrencyId::VToken(TokenSymbol::DOT);
let vtoken_id = CurrencyId::VToken(TokenSymbol::KSM);
let token_amount = BalanceOf::<T>::unique_saturated_from(10u32 as u128);
}: _(RawOrigin::Signed(caller), vtoken_id, token_amount)

redeem {
VtokenMint::<T>::expand_mint_pool(CurrencyId::Token(TokenSymbol::DOT), BalanceOf::<T>::unique_saturated_from(100u32 as u128))?;
VtokenMint::<T>::expand_mint_pool(CurrencyId::VToken(TokenSymbol::DOT), BalanceOf::<T>::unique_saturated_from(200u32 as u128))?;
VtokenMint::<T>::expand_mint_pool(CurrencyId::Token(TokenSymbol::KSM), BalanceOf::<T>::unique_saturated_from(100u32 as u128))?;
VtokenMint::<T>::expand_mint_pool(CurrencyId::VToken(TokenSymbol::KSM), BalanceOf::<T>::unique_saturated_from(200u32 as u128))?;

let caller: T::AccountId = whitelisted_caller();
let token_id = CurrencyId::Token(TokenSymbol::DOT);
let token_id = CurrencyId::Token(TokenSymbol::KSM);
let vtoken_amount = BalanceOf::<T>::unique_saturated_from(10u32 as u128);
}: _(RawOrigin::Signed(caller), token_id, vtoken_amount)

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

//! Autogenerated weights for bifrost_bancor
//! Autogenerated weights for `bifrost_bancor`
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 3.0.0
//! DATE: 2021-08-11, STEPS: `[50, ]`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2021-10-28, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("asgard-local"), DB CACHE: 128

// Executed Command:
Expand All @@ -36,31 +36,44 @@
// --header=./HEADER-GPL3
// --output=./runtime/asgard/src/weights/bifrost_bancor.rs


#![cfg_attr(rustfmt, rustfmt_skip)]
#![allow(unused_parens)]
#![allow(unused_imports)]

use frame_support::{traits::Get, weights::Weight};
use sp_std::marker::PhantomData;

/// Weight functions for bifrost_bancor.
/// Weight functions for `bifrost_bancor`.
pub struct WeightInfo<T>(PhantomData<T>);
impl<T: frame_system::Config> bifrost_bancor::WeightInfo for WeightInfo<T> {
// Storage: Tokens Accounts (r:1 w:1)
// Storage: Tokens TotalIssuance (r:1 w:1)
// Storage: Bancor BancorReserve (r:1 w:1)
fn add_token_to_pool() -> Weight {
(64_271_000 as Weight)
(109_574_000 as Weight)
.saturating_add(T::DbWeight::get().reads(3 as Weight))
.saturating_add(T::DbWeight::get().writes(3 as Weight))
}
// Storage: Tokens Accounts (r:1 w:1)
// Storage: Bancor BancorPools (r:1 w:1)
// Storage: Tokens TotalIssuance (r:1 w:1)
fn exchange_for_token() -> Weight {
(91_953_000 as Weight)
(136_423_000 as Weight)
.saturating_add(T::DbWeight::get().reads(3 as Weight))
.saturating_add(T::DbWeight::get().writes(3 as Weight))
}
// Storage: Tokens Accounts (r:1 w:1)
// Storage: Bancor BancorPools (r:1 w:1)
// Storage: Tokens TotalIssuance (r:1 w:1)
fn exchange_for_vstoken() -> Weight {
(79_409_000 as Weight)
(126_910_000 as Weight)
.saturating_add(T::DbWeight::get().reads(3 as Weight))
.saturating_add(T::DbWeight::get().writes(3 as Weight))
}
// Storage: Bancor BancorReserve (r:3 w:0)
fn on_initialize() -> Weight {
(21_690_000 as Weight).saturating_add(T::DbWeight::get().reads(3 as Weight))
(78_733_000 as Weight)
.saturating_add(T::DbWeight::get().reads(3 as Weight))
}
}
14 changes: 8 additions & 6 deletions runtime/asgard/src/weights/bifrost_flexible_fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

//! Autogenerated weights for bifrost_flexible_fee
//! Autogenerated weights for `bifrost_flexible_fee`
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 3.0.0
//! DATE: 2021-08-11, STEPS: `[50, ]`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2021-10-28, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("asgard-local"), DB CACHE: 128

// Executed Command:
Expand All @@ -36,18 +36,20 @@
// --header=./HEADER-GPL3
// --output=./runtime/asgard/src/weights/bifrost_flexible_fee.rs


#![cfg_attr(rustfmt, rustfmt_skip)]
#![allow(unused_parens)]
#![allow(unused_imports)]

use frame_support::{traits::Get, weights::Weight};
use sp_std::marker::PhantomData;

/// Weight functions for bifrost_flexible_fee.
/// Weight functions for `bifrost_flexible_fee`.
pub struct WeightInfo<T>(PhantomData<T>);
impl<T: frame_system::Config> bifrost_flexible_fee::WeightInfo for WeightInfo<T> {
// Storage: FlexibleFee UserFeeChargeOrderList (r:0 w:1)
fn set_user_fee_charge_order() -> Weight {
(6_081_000 as Weight)
.saturating_add(T::DbWeight::get().writes(1 as Weight))
(6_345_000 as Weight)
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
}
Loading