diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml new file mode 100644 index 0000000000..a6cd6b07ef --- /dev/null +++ b/.github/workflows/benchmark.yml @@ -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 \ No newline at end of file diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml index ea4042caf0..fcdaecabea 100644 --- a/.github/workflows/ci-build.yml +++ b/.github/workflows/ci-build.yml @@ -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 \ No newline at end of file + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_PULLREQUEST_WEBHOOK_URL }} \ No newline at end of file diff --git a/Makefile b/Makefile index 38b4e9c579..4c45e25e42 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/pallets/liquidity-mining/src/benchmarking.rs b/pallets/liquidity-mining/src/benchmarking.rs index 5894271157..ba030f261e 100644 --- a/pallets/liquidity-mining/src/benchmarking.rs +++ b/pallets/liquidity-mining/src/benchmarking.rs @@ -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; @@ -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(n: BlockNumberFor) { +fn run_to_block, I: 'static>(n: BlockNumberFor) { type System = frame_system::Pallet; while System::::block_number() < n { - LM::::on_finalize(System::::block_number()); + LM::::on_finalize(System::::block_number()); System::::on_finalize(System::::block_number()); System::::set_block_number(System::::block_number() + 1u128.saturated_into()); System::::on_initialize(System::::block_number()); - LM::::on_initialize(System::::block_number()); + LM::::on_initialize(System::::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 = UNIT.saturated_into(); + let amount: BalanceOf = UNIT.saturated_into(); - assert_ok!(::MultiCurrency::deposit(REWARD_1, &caller, amount)); - assert_ok!(::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::::create_pool( + assert_ok!(LM::::create_pool( (FARMING_DEPOSIT_1, FARMING_DEPOSIT_2), (REWARD_1, amount), vec![(REWARD_2, amount)].try_into().unwrap(), @@ -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 = UNIT.saturated_into(); + let amount: BalanceOf = UNIT.saturated_into(); let investor: T::AccountId = account("lm", 0, 0); - assert_ok!(::MultiCurrency::deposit(REWARD_1, &investor, amount)); - assert_ok!(::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!(::MultiCurrency::deposit(FARMING_DEPOSIT_1, &caller, amount)); - assert_ok!(::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::::create_pool( + assert_ok!(LM::::create_pool( (FARMING_DEPOSIT_1, FARMING_DEPOSIT_2), (REWARD_1, amount), vec![(REWARD_2, amount)].try_into().unwrap(), @@ -88,24 +90,24 @@ benchmarks! { 0u128.saturated_into() )); - assert_ok!(LM::::charge(RawOrigin::Signed(investor).into(), 0)); + assert_ok!(LM::::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 = UNIT.saturated_into(); + let amount: BalanceOf = UNIT.saturated_into(); let investor: T::AccountId = account("lm", 0, 0); - assert_ok!(::MultiCurrency::deposit(REWARD_1, &investor, amount)); - assert_ok!(::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!(::MultiCurrency::deposit(FARMING_DEPOSIT_1, &caller, amount)); - assert_ok!(::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::::create_pool( + assert_ok!(LM::::create_pool( (FARMING_DEPOSIT_1, FARMING_DEPOSIT_2), (REWARD_1, amount), vec![(REWARD_2, amount)].try_into().unwrap(), @@ -115,17 +117,17 @@ benchmarks! { 0u128.saturated_into() )); - assert_ok!(LM::::charge(RawOrigin::Signed(investor).into(), 0)); + assert_ok!(LM::::charge(RawOrigin::Signed(investor).into(), 0)); - assert_ok!(LM::::deposit(RawOrigin::Signed(caller.clone()).into(), 0, amount)); + assert_ok!(LM::::deposit(RawOrigin::Signed(caller.clone()).into(), 0, amount)); // Run to block - run_to_block::(duration); + run_to_block::(duration); }: _(RawOrigin::Signed(caller.clone()), 0, amount) verify { - let pool = LM::::pool(0); - let deposit_data = LM::::user_deposit_data(0, caller.clone()); + let pool = LM::::pool(0); + let deposit_data = LM::::user_deposit_data(0, caller.clone()); assert!(pool.is_none()); assert!(deposit_data.is_none()); } @@ -133,17 +135,17 @@ benchmarks! { redeem_all { let duration = T::MinimumDuration::get().saturating_add(1u128.saturated_into()); let min_deposit_to_start = T::MinimumDepositOfUser::get(); - let amount: BalanceOf = UNIT.saturated_into(); + let amount: BalanceOf = UNIT.saturated_into(); let investor: T::AccountId = account("lm", 0, 0); - assert_ok!(::MultiCurrency::deposit(REWARD_1, &investor, amount)); - assert_ok!(::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!(::MultiCurrency::deposit(FARMING_DEPOSIT_1, &caller, amount)); - assert_ok!(::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::::create_pool( + assert_ok!(LM::::create_pool( (FARMING_DEPOSIT_1, FARMING_DEPOSIT_2), (REWARD_1, amount), vec![(REWARD_2, amount)].try_into().unwrap(), @@ -153,17 +155,17 @@ benchmarks! { 0u128.saturated_into() )); - assert_ok!(LM::::charge(RawOrigin::Signed(investor).into(), 0)); + assert_ok!(LM::::charge(RawOrigin::Signed(investor).into(), 0)); - assert_ok!(LM::::deposit(RawOrigin::Signed(caller.clone()).into(), 0, amount)); + assert_ok!(LM::::deposit(RawOrigin::Signed(caller.clone()).into(), 0, amount)); // Run to block - run_to_block::(duration); + run_to_block::(duration); }: _(RawOrigin::Signed(caller.clone()), 0) verify { - let pool = LM::::pool(0); - let deposit_data = LM::::user_deposit_data(0, caller.clone()); + let pool = LM::::pool(0); + let deposit_data = LM::::user_deposit_data(0, caller.clone()); assert!(pool.is_none()); assert!(deposit_data.is_none()); } @@ -171,17 +173,17 @@ benchmarks! { volunteer_to_redeem { let duration = T::MinimumDuration::get().saturating_add(1u128.saturated_into()); let min_deposit_to_start = T::MinimumDepositOfUser::get(); - let amount: BalanceOf = UNIT.saturated_into(); + let amount: BalanceOf = UNIT.saturated_into(); let investor: T::AccountId = account("lm", 0, 0); - assert_ok!(::MultiCurrency::deposit(REWARD_1, &investor, amount)); - assert_ok!(::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!(::MultiCurrency::deposit(FARMING_DEPOSIT_1, &caller, amount)); - assert_ok!(::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::::create_pool( + assert_ok!(LM::::create_pool( (FARMING_DEPOSIT_1, FARMING_DEPOSIT_2), (REWARD_1, amount), vec![(REWARD_2, amount)].try_into().unwrap(), @@ -191,19 +193,19 @@ benchmarks! { 0u128.saturated_into() )); - assert_ok!(LM::::charge(RawOrigin::Signed(investor).into(), 0)); + assert_ok!(LM::::charge(RawOrigin::Signed(investor).into(), 0)); - assert_ok!(LM::::deposit(RawOrigin::Signed(caller.clone()).into(), 0, amount)); + assert_ok!(LM::::deposit(RawOrigin::Signed(caller.clone()).into(), 0, amount)); // Run to block - run_to_block::(duration); + run_to_block::(duration); let volunteer = account("lm", 0, 1); }: _(RawOrigin::Signed(volunteer), 0, None) verify { - let pool = LM::::pool(0); - let deposit_data = LM::::user_deposit_data(0, caller.clone()); + let pool = LM::::pool(0); + let deposit_data = LM::::user_deposit_data(0, caller.clone()); assert!(pool.is_none()); assert!(deposit_data.is_none()); } @@ -211,17 +213,17 @@ benchmarks! { claim { let duration = T::MinimumDuration::get().saturating_add(1u128.saturated_into()); let min_deposit_to_start = T::MinimumDepositOfUser::get(); - let amount: BalanceOf = UNIT.saturated_into(); + let amount: BalanceOf = UNIT.saturated_into(); let investor: T::AccountId = account("lm", 0, 0); - assert_ok!(::MultiCurrency::deposit(REWARD_1, &investor, amount)); - assert_ok!(::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!(::MultiCurrency::deposit(FARMING_DEPOSIT_1, &caller, amount)); - assert_ok!(::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::::create_pool( + assert_ok!(LM::::create_pool( (FARMING_DEPOSIT_1, FARMING_DEPOSIT_2), (REWARD_1, amount), vec![(REWARD_2, amount)].try_into().unwrap(), @@ -231,12 +233,12 @@ benchmarks! { 0u128.saturated_into() )); - assert_ok!(LM::::charge(RawOrigin::Signed(investor).into(), 0)); + assert_ok!(LM::::charge(RawOrigin::Signed(investor).into(), 0)); - assert_ok!(LM::::deposit(RawOrigin::Signed(caller.clone()).into(), 0, amount)); + assert_ok!(LM::::deposit(RawOrigin::Signed(caller.clone()).into(), 0, amount)); // Run to block - run_to_block::(1u128.saturated_into()); + run_to_block::(1u128.saturated_into()); }: _(RawOrigin::Signed(caller.clone()), 0) } diff --git a/pallets/salp-lite/src/benchmarking.rs b/pallets/salp-lite/src/benchmarking.rs index bc2663b1bf..1e7789f0c2 100644 --- a/pallets/salp-lite/src/benchmarking.rs +++ b/pallets/salp-lite/src/benchmarking.rs @@ -79,7 +79,6 @@ benchmarks! { let contribution = T::MinContribution::get(); contribute_fund::(&caller,fund_index); assert_ok!(Salp::::fund_success(RawOrigin::Root.into(), fund_index)); - assert_ok!(Salp::::unlock(RawOrigin::Root.into(), caller.clone(), fund_index)); assert_ok!(Salp::::fund_retire(RawOrigin::Root.into(), fund_index)); assert_ok!(Salp::::withdraw(RawOrigin::Root.into(), fund_index)); assert_eq!(Salp::::redeem_pool(), T::MinContribution::get()); @@ -88,6 +87,24 @@ benchmarks! { assert_eq!(Salp::::redeem_pool(), 0_u32.saturated_into()); assert_last_event::(Event::::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::(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::(&caller,fund_index); + } + assert_ok!(Salp::::fund_fail(RawOrigin::Root.into(), fund_index)); + }: _(RawOrigin::Signed(caller.clone()), fund_index) + verify { + let fund = Salp::::funds(fund_index).unwrap(); + let (_, status) = Salp::::contribution(fund.trie_index, &caller); + assert_eq!(status, ContributionStatus::Unlocked); + assert_last_event::(Event::::AllUnlocked(fund_index).into()); + } } impl_benchmark_test_suite!(Salp, crate::mock::new_test_ext(), crate::mock::Test); diff --git a/runtime/bifrost/Cargo.toml b/runtime/bifrost/Cargo.toml index 2ca603b3b9..f4b1eef0c9 100644 --- a/runtime/bifrost/Cargo.toml +++ b/runtime/bifrost/Cargo.toml @@ -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", diff --git a/runtime/bifrost/src/lib.rs b/runtime/bifrost/src/lib.rs index e665cff2f2..22ea63a4be 100644 --- a/runtime/bifrost/src/lib.rs +++ b/runtime/bifrost/src/lib.rs @@ -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::, 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);