Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
32 changes: 32 additions & 0 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: ci-build

on:
workflow_dispatch:

env:
CARGO_TERM_COLOR: always

jobs:
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-11-07
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
25 changes: 1 addition & 24 deletions .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,27 +42,4 @@ jobs:
status: ${{ job.status }}
fields: repo,author,eventName,workflow,ref,commit
env:
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
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_PULLREQUEST_WEBHOOK_URL }}
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ generate-asgard-weights:

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

.PHONY: build-asgard-release-with-bench
build-asgard-release-with-bench: copy-genesis-config-release
Expand Down
118 changes: 60 additions & 58 deletions pallets/liquidity-mining/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@

// Ensure we're `no_std` when compiling for Wasm.
#![cfg(feature = "runtime-benchmarks")]
use frame_benchmarking::{account, benchmarks, impl_benchmark_test_suite, whitelisted_caller};
use frame_benchmarking::{
account, benchmarks_instance_pallet, impl_benchmark_test_suite, whitelisted_caller,
};
use frame_support::{assert_ok, sp_runtime::sp_std::convert::TryInto, sp_std::prelude::*};
use frame_system::RawOrigin;
use node_primitives::Balance;
Expand All @@ -31,30 +33,30 @@ const REWARD_1: CurrencyId = CurrencyId::Native(TokenSymbol::BNC);
const REWARD_2: CurrencyId = CurrencyId::Token(TokenSymbol::KSM);
const UNIT: Balance = 1_000_000_000_000;

fn run_to_block<T: Config>(n: BlockNumberFor<T>) {
fn run_to_block<T: Config<I>, I: 'static>(n: BlockNumberFor<T>) {
type System<T> = frame_system::Pallet<T>;

while System::<T>::block_number() < n {
LM::<T>::on_finalize(System::<T>::block_number());
LM::<T, I>::on_finalize(System::<T>::block_number());
System::<T>::on_finalize(System::<T>::block_number());
System::<T>::set_block_number(System::<T>::block_number() + 1u128.saturated_into());
System::<T>::on_initialize(System::<T>::block_number());
LM::<T>::on_initialize(System::<T>::block_number());
LM::<T, I>::on_initialize(System::<T>::block_number());
}
}

benchmarks! {
benchmarks_instance_pallet! {
charge {
let caller: T::AccountId = whitelisted_caller();

let duration = T::MinimumDuration::get().saturating_add(1u128.saturated_into());
let min_deposit_to_start = T::MinimumDepositOfUser::get();
let amount: BalanceOf<T> = UNIT.saturated_into();
let amount: BalanceOf<T,I> = UNIT.saturated_into();

assert_ok!(<T as Config>::MultiCurrency::deposit(REWARD_1, &caller, amount));
assert_ok!(<T as Config>::MultiCurrency::deposit(REWARD_2, &caller, amount));
assert_ok!(T::MultiCurrency::deposit(REWARD_1, &caller, amount));
assert_ok!(T::MultiCurrency::deposit(REWARD_2, &caller, amount));

assert_ok!(LM::<T>::create_pool(
assert_ok!(LM::<T,I>::create_pool(
(FARMING_DEPOSIT_1, FARMING_DEPOSIT_2),
(REWARD_1, amount),
vec![(REWARD_2, amount)].try_into().unwrap(),
Expand All @@ -68,17 +70,17 @@ benchmarks! {
deposit {
let duration = T::MinimumDuration::get().saturating_add(1u128.saturated_into());
let min_deposit_to_start = T::MinimumDepositOfUser::get();
let amount: BalanceOf<T> = UNIT.saturated_into();
let amount: BalanceOf<T,I> = UNIT.saturated_into();

let investor: T::AccountId = account("lm", 0, 0);
assert_ok!(<T as Config>::MultiCurrency::deposit(REWARD_1, &investor, amount));
assert_ok!(<T as Config>::MultiCurrency::deposit(REWARD_2, &investor, amount));
assert_ok!(T::MultiCurrency::deposit(REWARD_1, &investor, amount));
assert_ok!(T::MultiCurrency::deposit(REWARD_2, &investor, amount));

let caller: T::AccountId = whitelisted_caller();
assert_ok!(<T as Config>::MultiCurrency::deposit(FARMING_DEPOSIT_1, &caller, amount));
assert_ok!(<T as Config>::MultiCurrency::deposit(FARMING_DEPOSIT_2, &caller, amount));
assert_ok!(T::MultiCurrency::deposit(FARMING_DEPOSIT_1, &caller, amount));
assert_ok!(T::MultiCurrency::deposit(FARMING_DEPOSIT_2, &caller, amount));

assert_ok!(LM::<T>::create_pool(
assert_ok!(LM::<T,I>::create_pool(
(FARMING_DEPOSIT_1, FARMING_DEPOSIT_2),
(REWARD_1, amount),
vec![(REWARD_2, amount)].try_into().unwrap(),
Expand All @@ -88,24 +90,24 @@ benchmarks! {
0u128.saturated_into()
));

assert_ok!(LM::<T>::charge(RawOrigin::Signed(investor).into(), 0));
assert_ok!(LM::<T,I>::charge(RawOrigin::Signed(investor).into(), 0));

}: _(RawOrigin::Signed(caller.clone()), 0, T::MinimumDepositOfUser::get())

redeem {
let duration = T::MinimumDuration::get().saturating_add(1u128.saturated_into());
let min_deposit_to_start = T::MinimumDepositOfUser::get();
let amount: BalanceOf<T> = UNIT.saturated_into();
let amount: BalanceOf<T,I> = UNIT.saturated_into();

let investor: T::AccountId = account("lm", 0, 0);
assert_ok!(<T as Config>::MultiCurrency::deposit(REWARD_1, &investor, amount));
assert_ok!(<T as Config>::MultiCurrency::deposit(REWARD_2, &investor, amount));
assert_ok!(T::MultiCurrency::deposit(REWARD_1, &investor, amount));
assert_ok!(T::MultiCurrency::deposit(REWARD_2, &investor, amount));

let caller: T::AccountId = whitelisted_caller();
assert_ok!(<T as Config>::MultiCurrency::deposit(FARMING_DEPOSIT_1, &caller, amount));
assert_ok!(<T as Config>::MultiCurrency::deposit(FARMING_DEPOSIT_2, &caller, amount));
assert_ok!(T::MultiCurrency::deposit(FARMING_DEPOSIT_1, &caller, amount));
assert_ok!(T::MultiCurrency::deposit(FARMING_DEPOSIT_2, &caller, amount));

assert_ok!(LM::<T>::create_pool(
assert_ok!(LM::<T,I>::create_pool(
(FARMING_DEPOSIT_1, FARMING_DEPOSIT_2),
(REWARD_1, amount),
vec![(REWARD_2, amount)].try_into().unwrap(),
Expand All @@ -115,35 +117,35 @@ benchmarks! {
0u128.saturated_into()
));

assert_ok!(LM::<T>::charge(RawOrigin::Signed(investor).into(), 0));
assert_ok!(LM::<T,I>::charge(RawOrigin::Signed(investor).into(), 0));

assert_ok!(LM::<T>::deposit(RawOrigin::Signed(caller.clone()).into(), 0, amount));
assert_ok!(LM::<T,I>::deposit(RawOrigin::Signed(caller.clone()).into(), 0, amount));

// Run to block
run_to_block::<T>(duration);
run_to_block::<T,I>(duration);

}: _(RawOrigin::Signed(caller.clone()), 0, amount)
verify {
let pool = LM::<T>::pool(0);
let deposit_data = LM::<T>::user_deposit_data(0, caller.clone());
let pool = LM::<T,I>::pool(0);
let deposit_data = LM::<T,I>::user_deposit_data(0, caller.clone());
assert!(pool.is_none());
assert!(deposit_data.is_none());
}

redeem_all {
let duration = T::MinimumDuration::get().saturating_add(1u128.saturated_into());
let min_deposit_to_start = T::MinimumDepositOfUser::get();
let amount: BalanceOf<T> = UNIT.saturated_into();
let amount: BalanceOf<T,I> = UNIT.saturated_into();

let investor: T::AccountId = account("lm", 0, 0);
assert_ok!(<T as Config>::MultiCurrency::deposit(REWARD_1, &investor, amount));
assert_ok!(<T as Config>::MultiCurrency::deposit(REWARD_2, &investor, amount));
assert_ok!(T::MultiCurrency::deposit(REWARD_1, &investor, amount));
assert_ok!(T::MultiCurrency::deposit(REWARD_2, &investor, amount));

let caller: T::AccountId = whitelisted_caller();
assert_ok!(<T as Config>::MultiCurrency::deposit(FARMING_DEPOSIT_1, &caller, amount));
assert_ok!(<T as Config>::MultiCurrency::deposit(FARMING_DEPOSIT_2, &caller, amount));
assert_ok!(T::MultiCurrency::deposit(FARMING_DEPOSIT_1, &caller, amount));
assert_ok!(T::MultiCurrency::deposit(FARMING_DEPOSIT_2, &caller, amount));

assert_ok!(LM::<T>::create_pool(
assert_ok!(LM::<T,I>::create_pool(
(FARMING_DEPOSIT_1, FARMING_DEPOSIT_2),
(REWARD_1, amount),
vec![(REWARD_2, amount)].try_into().unwrap(),
Expand All @@ -153,35 +155,35 @@ benchmarks! {
0u128.saturated_into()
));

assert_ok!(LM::<T>::charge(RawOrigin::Signed(investor).into(), 0));
assert_ok!(LM::<T,I>::charge(RawOrigin::Signed(investor).into(), 0));

assert_ok!(LM::<T>::deposit(RawOrigin::Signed(caller.clone()).into(), 0, amount));
assert_ok!(LM::<T,I>::deposit(RawOrigin::Signed(caller.clone()).into(), 0, amount));

// Run to block
run_to_block::<T>(duration);
run_to_block::<T,I>(duration);

}: _(RawOrigin::Signed(caller.clone()), 0)
verify {
let pool = LM::<T>::pool(0);
let deposit_data = LM::<T>::user_deposit_data(0, caller.clone());
let pool = LM::<T,I>::pool(0);
let deposit_data = LM::<T,I>::user_deposit_data(0, caller.clone());
assert!(pool.is_none());
assert!(deposit_data.is_none());
}

volunteer_to_redeem {
let duration = T::MinimumDuration::get().saturating_add(1u128.saturated_into());
let min_deposit_to_start = T::MinimumDepositOfUser::get();
let amount: BalanceOf<T> = UNIT.saturated_into();
let amount: BalanceOf<T,I> = UNIT.saturated_into();

let investor: T::AccountId = account("lm", 0, 0);
assert_ok!(<T as Config>::MultiCurrency::deposit(REWARD_1, &investor, amount));
assert_ok!(<T as Config>::MultiCurrency::deposit(REWARD_2, &investor, amount));
assert_ok!(T::MultiCurrency::deposit(REWARD_1, &investor, amount));
assert_ok!(T::MultiCurrency::deposit(REWARD_2, &investor, amount));

let caller: T::AccountId = whitelisted_caller();
assert_ok!(<T as Config>::MultiCurrency::deposit(FARMING_DEPOSIT_1, &caller, amount));
assert_ok!(<T as Config>::MultiCurrency::deposit(FARMING_DEPOSIT_2, &caller, amount));
assert_ok!(T::MultiCurrency::deposit(FARMING_DEPOSIT_1, &caller, amount));
assert_ok!(T::MultiCurrency::deposit(FARMING_DEPOSIT_2, &caller, amount));

assert_ok!(LM::<T>::create_pool(
assert_ok!(LM::<T,I>::create_pool(
(FARMING_DEPOSIT_1, FARMING_DEPOSIT_2),
(REWARD_1, amount),
vec![(REWARD_2, amount)].try_into().unwrap(),
Expand All @@ -191,37 +193,37 @@ benchmarks! {
0u128.saturated_into()
));

assert_ok!(LM::<T>::charge(RawOrigin::Signed(investor).into(), 0));
assert_ok!(LM::<T,I>::charge(RawOrigin::Signed(investor).into(), 0));

assert_ok!(LM::<T>::deposit(RawOrigin::Signed(caller.clone()).into(), 0, amount));
assert_ok!(LM::<T,I>::deposit(RawOrigin::Signed(caller.clone()).into(), 0, amount));

// Run to block
run_to_block::<T>(duration);
run_to_block::<T,I>(duration);

let volunteer = account("lm", 0, 1);

}: _(RawOrigin::Signed(volunteer), 0, None)
verify {
let pool = LM::<T>::pool(0);
let deposit_data = LM::<T>::user_deposit_data(0, caller.clone());
let pool = LM::<T,I>::pool(0);
let deposit_data = LM::<T,I>::user_deposit_data(0, caller.clone());
assert!(pool.is_none());
assert!(deposit_data.is_none());
}

claim {
let duration = T::MinimumDuration::get().saturating_add(1u128.saturated_into());
let min_deposit_to_start = T::MinimumDepositOfUser::get();
let amount: BalanceOf<T> = UNIT.saturated_into();
let amount: BalanceOf<T,I> = UNIT.saturated_into();

let investor: T::AccountId = account("lm", 0, 0);
assert_ok!(<T as Config>::MultiCurrency::deposit(REWARD_1, &investor, amount));
assert_ok!(<T as Config>::MultiCurrency::deposit(REWARD_2, &investor, amount));
assert_ok!(T::MultiCurrency::deposit(REWARD_1, &investor, amount));
assert_ok!(T::MultiCurrency::deposit(REWARD_2, &investor, amount));

let caller: T::AccountId = whitelisted_caller();
assert_ok!(<T as Config>::MultiCurrency::deposit(FARMING_DEPOSIT_1, &caller, amount));
assert_ok!(<T as Config>::MultiCurrency::deposit(FARMING_DEPOSIT_2, &caller, amount));
assert_ok!(T::MultiCurrency::deposit(FARMING_DEPOSIT_1, &caller, amount));
assert_ok!(T::MultiCurrency::deposit(FARMING_DEPOSIT_2, &caller, amount));

assert_ok!(LM::<T>::create_pool(
assert_ok!(LM::<T,I>::create_pool(
(FARMING_DEPOSIT_1, FARMING_DEPOSIT_2),
(REWARD_1, amount),
vec![(REWARD_2, amount)].try_into().unwrap(),
Expand All @@ -231,12 +233,12 @@ benchmarks! {
0u128.saturated_into()
));

assert_ok!(LM::<T>::charge(RawOrigin::Signed(investor).into(), 0));
assert_ok!(LM::<T,I>::charge(RawOrigin::Signed(investor).into(), 0));

assert_ok!(LM::<T>::deposit(RawOrigin::Signed(caller.clone()).into(), 0, amount));
assert_ok!(LM::<T,I>::deposit(RawOrigin::Signed(caller.clone()).into(), 0, amount));

// Run to block
run_to_block::<T>(1u128.saturated_into());
run_to_block::<T,I>(1u128.saturated_into());

}: _(RawOrigin::Signed(caller.clone()), 0)
}
Expand Down
19 changes: 18 additions & 1 deletion pallets/salp-lite/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ benchmarks! {
let contribution = T::MinContribution::get();
contribute_fund::<T>(&caller,fund_index);
assert_ok!(Salp::<T>::fund_success(RawOrigin::Root.into(), fund_index));
assert_ok!(Salp::<T>::unlock(RawOrigin::Root.into(), caller.clone(), fund_index));
assert_ok!(Salp::<T>::fund_retire(RawOrigin::Root.into(), fund_index));
assert_ok!(Salp::<T>::withdraw(RawOrigin::Root.into(), fund_index));
assert_eq!(Salp::<T>::redeem_pool(), T::MinContribution::get());
Expand All @@ -88,6 +87,24 @@ benchmarks! {
assert_eq!(Salp::<T>::redeem_pool(), 0_u32.saturated_into());
assert_last_event::<T>(Event::<T>::Redeemed(caller.clone(), fund_index, (0 as u32).into(),(7 as u32).into(),contribution).into())
}

batch_migrate {
let k in 1 .. T::BatchKeysLimit::get();
let fund_index = create_fund::<T>(1);
let contribution = T::MinContribution::get();
let mut caller: T::AccountId = whitelisted_caller();
for i in 0 .. k {
caller = account("contributor", i, 0);
contribute_fund::<T>(&caller,fund_index);
}
assert_ok!(Salp::<T>::fund_fail(RawOrigin::Root.into(), fund_index));
}: _(RawOrigin::Signed(caller.clone()), fund_index)
verify {
let fund = Salp::<T>::funds(fund_index).unwrap();
let (_, status) = Salp::<T>::contribution(fund.trie_index, &caller);
assert_eq!(status, ContributionStatus::Unlocked);
assert_last_event::<T>(Event::<T>::AllUnlocked(fund_index).into());
}
}

impl_benchmark_test_suite!(Salp, crate::mock::new_test_ext(), crate::mock::Test);
2 changes: 1 addition & 1 deletion runtime/bifrost/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ runtime-benchmarks = [
"xcm-builder/runtime-benchmarks",
"bifrost-flexible-fee/runtime-benchmarks",
"bifrost-salp/runtime-benchmarks",
# "bifrost-salp-lite/runtime-benchmarks",
"bifrost-salp-lite/runtime-benchmarks",
"bifrost-liquidity-mining/runtime-benchmarks",
"bifrost-token-issuer/runtime-benchmarks",
"bifrost-lightening-redeem/runtime-benchmarks",
Expand Down
2 changes: 1 addition & 1 deletion runtime/bifrost/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1873,7 +1873,7 @@ impl_runtime_apis! {
list_benchmark!(list, extra, bifrost_flexible_fee, FlexibleFee);
list_benchmark!(list, extra, bifrost_salp, Salp);
list_benchmark!(list, extra, bifrost_salp_lite, SalpLite);
list_benchmark!(list, extra, bifrost_liquidity_mining, LiquidityMining);
list_benchmark!(list, extra, bifrost_liquidity_mining::<Instance1>, LiquidityMining);
list_benchmark!(list, extra, bifrost_token_issuer, TokenIssuer);
list_benchmark!(list, extra, bifrost_lightening_redeem, LighteningRedeem);
list_benchmark!(list, extra, bifrost_call_switchgear, CallSwitchgear);
Expand Down