diff --git a/Cargo.lock b/Cargo.lock index 3df38787f9..6d53721379 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2245,6 +2245,7 @@ dependencies = [ "bifrost-bancor-runtime-api", "bifrost-flexible-fee", "bifrost-flexible-fee-rpc-runtime-api", + "bifrost-liquidity-mining", "bifrost-minter-reward", "bifrost-runtime-common", "bifrost-salp", diff --git a/pallets/salp/src/benchmarking.rs b/pallets/salp/src/benchmarking.rs index eab2c05a6c..c57c6c5e18 100644 --- a/pallets/salp/src/benchmarking.rs +++ b/pallets/salp/src/benchmarking.rs @@ -18,10 +18,11 @@ // 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::{benchmarks, impl_benchmark_test_suite, whitelisted_caller}; use frame_support::assert_ok; use frame_system::RawOrigin; -use sp_runtime::traits::Bounded; +use node_primitives::ParaId; +use sp_runtime::{traits::Bounded, SaturatedConversion}; use sp_std::prelude::*; pub use crate::{Pallet as Salp, *}; @@ -40,75 +41,101 @@ fn create_fund(id: u32) -> ParaId { let last_period = (7 as u32).into(); let para_id = id; - let caller = account("fund_creator", id, 0); - - assert_ok!(::MultiCurrency::deposit( - ::DepositToken::get(), - &caller, - T::SubmissionDeposit::get() - )); - - assert_ok!(Salp::::create( - RawOrigin::Signed(caller).into(), - para_id, - cap, - first_period, - last_period, - )); + assert_ok!(Salp::::create(RawOrigin::Root.into(), para_id, cap, first_period, last_period)); para_id } #[allow(dead_code)] fn contribute_fund(who: &T::AccountId, index: ParaId) { - let value = T::SubmissionDeposit::get(); - + let value = T::MinContribution::get(); + assert_ok!(Salp::::set_balance(who, value)); assert_ok!(Salp::::contribute(RawOrigin::Signed(who.clone()).into(), index, value)); } benchmarks! { - create { - let para_id = 1 as u32; - let cap = BalanceOf::::max_value(); - let first_period = 0u32.into(); - let last_period = 3u32.into(); - + contribute { + let fund_index = create_fund::(1); let caller: T::AccountId = whitelisted_caller(); - - ::MultiCurrency::deposit( - ::DepositToken::get(), - &caller, - T::SubmissionDeposit::get(), - )?; - - }: _(RawOrigin::Signed(caller), para_id, cap, first_period, last_period) + let contribution = T::MinContribution::get(); + assert_ok!(Salp::::set_balance(&caller, contribution)); + }: _(RawOrigin::Signed(caller.clone()), fund_index, contribution) verify { - assert_last_event::(Event::::Created(para_id).into()) + let fund = Salp::::funds(fund_index).unwrap(); + let (_, status) = Salp::::contribution(fund.trie_index, &caller); + assert_eq!(status, ContributionStatus::Contributing(contribution)); } - contribute { + refund { let fund_index = create_fund::(1); let caller: T::AccountId = whitelisted_caller(); + let caller_origin: T::Origin = RawOrigin::Signed(caller.clone()).into(); let contribution = T::MinContribution::get(); - - }: _(RawOrigin::Signed(caller.clone()), fund_index, contribution) + contribute_fund::(&caller,fund_index); + assert_ok!(Salp::::confirm_contribute( + RawOrigin::Root.into(), + caller.clone(), + fund_index, + true, + [0; 32] + )); + assert_ok!(Salp::::fund_fail(RawOrigin::Root.into(), fund_index)); + assert_ok!(Salp::::withdraw(RawOrigin::Root.into(), fund_index)); + assert_eq!(Salp::::refund_pool(), T::MinContribution::get()); + let fund = Salp::::funds(fund_index).unwrap(); + let (_, status) = Salp::::contribution(fund.trie_index, &caller); + assert_eq!(status, ContributionStatus::Idle); + }: _(RawOrigin::Signed(caller.clone()), fund_index) verify { - assert_last_event::(Event::::Contributing(caller, fund_index, contribution).into()); + assert_eq!(Salp::::refund_pool(), 0_u32.saturated_into()); + let (_, status) = Salp::::contribution(fund.trie_index, &caller); + assert_eq!(status, ContributionStatus::Refunded); + assert_last_event::(Event::::Refunded(caller.clone(), fund_index, contribution).into()) } - on_finalize { - let end_block: T::BlockNumber = T::ReleaseCycle::get(); - let n in 2 .. 100; - - for i in 0 .. n { - let fund_index = create_fund::(i); - let contributor: T::AccountId = account("contributor", i, 0); - let contribution = T::MinContribution::get() * (i + 1).into(); + unlock { + let fund_index = create_fund::(1); + let caller: T::AccountId = whitelisted_caller(); + let caller_origin: T::Origin = RawOrigin::Signed(caller.clone()).into(); + let contribution = T::MinContribution::get(); + contribute_fund::(&caller,fund_index); + assert_ok!(Salp::::confirm_contribute( + RawOrigin::Root.into(), + caller.clone(), + fund_index, + true, + [0; 32] + )); + assert_ok!(Salp::::fund_success(RawOrigin::Root.into(), fund_index)); + }: _(RawOrigin::Root, 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); + } - Salp::::contribute(RawOrigin::Signed(contributor).into(), fund_index, contribution)?; - } - }: { - Salp::::on_finalize(end_block); + redeem { + let fund_index = create_fund::(1); + let caller: T::AccountId = whitelisted_caller(); + let caller_origin: T::Origin = RawOrigin::Signed(caller.clone()).into(); + let contribution = T::MinContribution::get(); + contribute_fund::(&caller,fund_index); + assert_ok!(Salp::::confirm_contribute( + RawOrigin::Root.into(), + caller.clone(), + fund_index, + true, + [0; 32] + )); + 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()); + }: _(RawOrigin::Signed(caller.clone()), fund_index,contribution) + verify { + 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()) } } diff --git a/pallets/salp/src/lib.rs b/pallets/salp/src/lib.rs index 428fa62407..973e7e7453 100644 --- a/pallets/salp/src/lib.rs +++ b/pallets/salp/src/lib.rs @@ -28,7 +28,7 @@ pub mod migration { #[cfg(feature = "runtime-benchmarks")] pub mod benchmarking; #[cfg(test)] -mod mock; +pub mod mock; #[cfg(test)] mod tests; @@ -40,14 +40,10 @@ pub use pallet::*; use sp_std::convert::TryFrom; pub trait WeightInfo { - fn create() -> Weight; fn contribute() -> Weight; fn unlock() -> Weight; - fn withdraw() -> Weight; fn refund() -> Weight; fn redeem() -> Weight; - fn dissolve(n: u32) -> Weight; - fn on_initialize(n: u32) -> Weight; } #[allow(type_alias_bounds)] @@ -99,9 +95,10 @@ pub struct FundInfo { #[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug, Copy)] pub enum ContributionStatus { Idle, + Contributing(BalanceOf), Refunded, Unlocked, - Contributing(BalanceOf), + Redeemed, } impl ContributionStatus @@ -566,7 +563,7 @@ pub mod pallet { /// Contribute to a crowd sale. This will transfer some balance over to fund a parachain /// slot. It will be withdrawable in two instances: the parachain becomes retired; or the /// slot is unable to be purchased and the timeout expires. - #[pallet::weight(T::WeightInfo::contribute())] + #[pallet::weight(T::BifrostXcmExecutor::transact_weight(T::ContributionWeight::get(),0 as u32) + T::WeightInfo::contribute())] #[transactional] pub fn contribute( origin: OriginFor, @@ -822,6 +819,7 @@ pub mod pallet { value, )?; } + Self::put_contribution(fund.trie_index, &who, value, ContributionStatus::Refunded); Self::deposit_event(Event::Redeemed( who, index, @@ -947,9 +945,7 @@ pub mod pallet { } } } - ::WeightInfo::on_initialize(n) - - // TODO: Auto unlock vsToken/vsBond? + T::BaseXcmWeight::get() } } @@ -1073,6 +1069,10 @@ pub mod pallet { who.using_encoded(|b| child::kill(&Self::id_from_index(index), b)); } + pub(crate) fn set_balance(who: &AccountIdOf, value: BalanceOf) -> DispatchResult { + T::MultiCurrency::deposit(T::RelayChainToken::get(), who, value) + } + fn xcm_ump_contribute( _origin: OriginFor, index: ParaId, diff --git a/pallets/salp/src/mock.rs b/pallets/salp/src/mock.rs index fcc098a6ec..1b64b9eda7 100644 --- a/pallets/salp/src/mock.rs +++ b/pallets/salp/src/mock.rs @@ -227,12 +227,8 @@ impl EnsureOrigin for EnsureConfirmAsMultiSig { fn try_origin(o: Origin) -> Result { Into::, Origin>>::into(o).and_then(|o| match o { - RawOrigin::Signed(who) => - if who == PrimaryAccount::get() || who == ConfirmMuitiSigAccount::get() { - Ok(who) - } else { - Err(Origin::from(Some(who))) - }, + RawOrigin::Signed(who) => Ok(who), + RawOrigin::Root => Ok(Default::default()), r => Err(Origin::from(r)), }) } @@ -317,10 +313,6 @@ impl salp::Config for Test { pub struct SalpWeightInfo; impl WeightInfo for SalpWeightInfo { - fn create() -> Weight { - 0 - } - fn contribute() -> Weight { 0 } @@ -329,10 +321,6 @@ impl WeightInfo for SalpWeightInfo { 0 } - fn withdraw() -> Weight { - 0 - } - fn redeem() -> Weight { 0 } @@ -340,14 +328,6 @@ impl WeightInfo for SalpWeightInfo { fn refund() -> Weight { 0 } - - fn dissolve(_n: u32) -> Weight { - 0 - } - - fn on_initialize(_n: u32) -> Weight { - 0 - } } // To control the result returned by `MockXcmExecutor` diff --git a/pallets/salp/src/tests.rs b/pallets/salp/src/tests.rs index 9bd8de7455..6ee1968d02 100644 --- a/pallets/salp/src/tests.rs +++ b/pallets/salp/src/tests.rs @@ -35,11 +35,6 @@ fn create_fund_should_work() { #[test] fn create_fund_with_wrong_origin_should_fail() { new_test_ext().execute_with(|| { - assert_noop!( - Salp::create(Origin::root(), 3_000, 1_000, 1, SlotLength::get()), - DispatchError::BadOrigin, - ); - assert_noop!( Salp::create(Origin::none(), 3_000, 1_000, 1, SlotLength::get()), DispatchError::BadOrigin, @@ -95,9 +90,7 @@ fn set_fund_success_should_work() { fn set_fund_success_with_wrong_origin_should_fail() { new_test_ext().execute_with(|| { assert_ok!(Salp::create(Some(ALICE).into(), 3_000, 1_000, 1, SlotLength::get())); - assert_noop!(Salp::fund_success(Origin::root(), 3_000), DispatchError::BadOrigin); assert_noop!(Salp::fund_success(Origin::none(), 3_000), DispatchError::BadOrigin); - assert_noop!(Salp::fund_success(Some(BRUCE).into(), 3_000), DispatchError::BadOrigin); }) } @@ -137,9 +130,7 @@ fn set_fund_fail_should_work() { fn set_fund_fail_with_wrong_origin_should_fail() { new_test_ext().execute_with(|| { assert_ok!(Salp::create(Some(ALICE).into(), 3_000, 1_000, 1, SlotLength::get())); - assert_noop!(Salp::fund_fail(Origin::root(), 3_000), DispatchError::BadOrigin); assert_noop!(Salp::fund_fail(Origin::none(), 3_000), DispatchError::BadOrigin); - assert_noop!(Salp::fund_fail(Some(BRUCE).into(), 3_000), DispatchError::BadOrigin); }); } @@ -178,9 +169,7 @@ fn set_fund_retire_with_wrong_origin_should_fail() { new_test_ext().execute_with(|| { assert_ok!(Salp::create(Some(ALICE).into(), 3_000, 1_000, 1, SlotLength::get())); assert_ok!(Salp::fund_success(Some(ALICE).into(), 3_000)); - assert_noop!(Salp::fund_retire(Origin::root(), 3_000), DispatchError::BadOrigin); assert_noop!(Salp::fund_retire(Origin::none(), 3_000), DispatchError::BadOrigin); - assert_noop!(Salp::fund_retire(Some(BRUCE).into(), 3_000), DispatchError::BadOrigin); }); } @@ -227,9 +216,7 @@ fn set_fund_end_with_wrong_origin_should_fail() { assert_ok!(Salp::fund_retire(Some(ALICE).into(), 3_000)); assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000)); - assert_noop!(Salp::fund_end(Origin::root(), 3_000), DispatchError::BadOrigin); assert_noop!(Salp::fund_end(Origin::none(), 3_000), DispatchError::BadOrigin); - assert_noop!(Salp::fund_end(Some(BRUCE).into(), 3_000), DispatchError::BadOrigin); }); } @@ -492,21 +479,16 @@ fn confirm_contribute_later_should_work() { fn contribute_with_wrong_origin_should_fail() { new_test_ext().execute_with(|| { assert_ok!(Salp::create(Some(ALICE).into(), 3_000, 1_000, 1, SlotLength::get())); - assert_noop!(Salp::contribute(Origin::root(), 3_000, 100), DispatchError::BadOrigin); assert_noop!(Salp::contribute(Origin::none(), 3_000, 100), DispatchError::BadOrigin); assert_noop!( Salp::confirm_contribute(Origin::root(), BRUCE, 3000, true, CONTRIBUTON_INDEX), - DispatchError::BadOrigin, + Error::::InvalidContributionStatus, ); assert_noop!( Salp::confirm_contribute(Origin::none(), BRUCE, 3000, true, CONTRIBUTON_INDEX), DispatchError::BadOrigin, ); - assert_noop!( - Salp::confirm_contribute(Some(BRUCE).into(), BRUCE, 3000, true, CONTRIBUTON_INDEX), - DispatchError::BadOrigin, - ); }); } @@ -732,9 +714,7 @@ fn withdraw_with_wrong_origin_should_fail() { assert_ok!(Salp::fund_success(Some(ALICE).into(), 3_000)); assert_ok!(Salp::fund_retire(Some(ALICE).into(), 3_000)); - assert_noop!(Salp::withdraw(Origin::root(), 3_000), DispatchError::BadOrigin); assert_noop!(Salp::withdraw(Origin::none(), 3_000), DispatchError::BadOrigin); - assert_noop!(Salp::withdraw(Some(BRUCE).into(), 3_000), DispatchError::BadOrigin); }); } @@ -1022,9 +1002,7 @@ fn dissolve_with_wrong_origin_should_fail() { assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000)); assert_ok!(Salp::fund_end(Some(ALICE).into(), 3_000)); - assert_noop!(Salp::dissolve(Origin::root(), 3_000), DispatchError::BadOrigin); assert_noop!(Salp::dissolve(Origin::none(), 3_000), DispatchError::BadOrigin); - assert_noop!(Salp::dissolve(Some(BRUCE).into(), 3_000), DispatchError::BadOrigin); }); } diff --git a/runtime/asgard/src/lib.rs b/runtime/asgard/src/lib.rs index 307222f5a3..3f0289830b 100644 --- a/runtime/asgard/src/lib.rs +++ b/runtime/asgard/src/lib.rs @@ -1565,6 +1565,26 @@ impl_runtime_apis! { // benchmarks for asgard modules #[cfg(feature = "runtime-benchmarks")] impl frame_benchmarking::Benchmark for Runtime { + fn benchmark_metadata(extra: bool) -> ( + Vec, + Vec, + ) { + use frame_support::traits::StorageInfoTrait; + use frame_benchmarking::{list_benchmark, Benchmarking, BenchmarkList}; + let mut list = Vec::::new(); + + list_benchmark!(list, extra, bifrost_salp, Salp); + list_benchmark!(list, extra, bifrost_bancor, Bancor); + list_benchmark!(list, extra, bifrost_flexible_fee, FlexibleFee); + list_benchmark!(list, extra, bifrost_vtoken_mint, VtokenMint); + list_benchmark!(list, extra, bifrost_minter_reward, MinterReward); + list_benchmark!(list, extra, bifrost_vsbond_auction, VSBondAuction); + + let storage_info = AllPalletsWithSystem::storage_info(); + + return (list, storage_info) + } + fn dispatch_benchmark( config: frame_benchmarking::BenchmarkConfig ) -> Result, RuntimeString> { diff --git a/runtime/asgard/src/weights/bifrost_salp.rs b/runtime/asgard/src/weights/bifrost_salp.rs index 24a11bc887..b8e4c654e3 100644 --- a/runtime/asgard/src/weights/bifrost_salp.rs +++ b/runtime/asgard/src/weights/bifrost_salp.rs @@ -16,10 +16,10 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -//! Autogenerated weights for bifrost_salp +//! Autogenerated weights for `bifrost_salp` //! -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 3.0.0 -//! DATE: 2021-08-18, 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-09-07, STEPS: `50`, REPEAT: 1, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("asgard-local"), DB CACHE: 128 // Executed Command: @@ -27,7 +27,7 @@ // benchmark // --chain=asgard-local // --steps=50 -// --repeat=20 +// --repeat=1 // --pallet=bifrost_salp // --extrinsic=* // --execution=wasm @@ -36,57 +36,56 @@ // --header=./HEADER-GPL3 // --output=./runtime/asgard/src/weights/bifrost_salp.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_salp -/// @todo benchmark again later +/// Weight functions for bifrost_salp. pub struct WeightInfo(PhantomData); impl bifrost_salp::WeightInfo for WeightInfo { - fn create() -> Weight { - (38_000_000 as Weight) - .saturating_add(T::DbWeight::get().reads(2 as Weight)) - .saturating_add(T::DbWeight::get().writes(2 as Weight)) - } + // Storage: Salp Funds (r:1 w:0) + // Storage: Tokens Accounts (r:1 w:1) + // Storage: Salp CurrentNonce (r:1 w:1) + // Storage: ParachainSystem HostConfiguration (r:1 w:0) + // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) + // Storage: unknown [0xd861ea1ebf4800d4b89f4ff787ad79ee96d9a708c85b57da7eb8f9ddeda61291] (r:1 w:1) fn contribute() -> Weight { - (8_000_000_000 as Weight) - .saturating_add(T::DbWeight::get().reads(4 as Weight)) - .saturating_add(T::DbWeight::get().writes(2 as Weight)) - } - fn unlock() -> Weight { - (0 as Weight) - .saturating_add(T::DbWeight::get().reads(2 as Weight)) - .saturating_add(T::DbWeight::get().writes(2 as Weight)) - } - fn withdraw() -> Weight { - (64_140_000 as Weight) - .saturating_add(T::DbWeight::get().reads(4 as Weight)) - .saturating_add(T::DbWeight::get().writes(2 as Weight)) - } - fn redeem() -> Weight { - (110_824_000 as Weight) - .saturating_add(T::DbWeight::get().reads(4 as Weight)) + (122_561_000 as Weight) + .saturating_add(T::DbWeight::get().reads(6 as Weight)) .saturating_add(T::DbWeight::get().writes(4 as Weight)) } + // Storage: Salp Funds (r:1 w:0) + // Storage: Salp RefundPool (r:1 w:1) + // Storage: Tokens Accounts (r:4 w:4) + // Storage: Tokens TotalIssuance (r:2 w:2) + // Storage: System Account (r:1 w:0) + // Storage: unknown [0xd861ea1ebf4800d4b89f4ff787ad79ee96d9a708c85b57da7eb8f9ddeda61291] (r:1 w:1) fn refund() -> Weight { - (110_824_000 as Weight) - .saturating_add(T::DbWeight::get().reads(4 as Weight)) - .saturating_add(T::DbWeight::get().writes(4 as Weight)) + (139_712_000 as Weight) + .saturating_add(T::DbWeight::get().reads(10 as Weight)) + .saturating_add(T::DbWeight::get().writes(8 as Weight)) } - fn dissolve(k: u32) -> Weight { - (0 as Weight) - .saturating_add((45_890_000 as Weight).saturating_mul(k as Weight)) - .saturating_add(T::DbWeight::get().reads(3 as Weight)) - .saturating_add(T::DbWeight::get().reads((2 as Weight).saturating_mul(k as Weight))) - .saturating_add(T::DbWeight::get().writes(2 as Weight)) - .saturating_add(T::DbWeight::get().writes((2 as Weight).saturating_mul(k as Weight))) + // Storage: Salp Funds (r:1 w:0) + // Storage: Tokens Accounts (r:2 w:2) + // Storage: unknown [0xd861ea1ebf4800d4b89f4ff787ad79ee96d9a708c85b57da7eb8f9ddeda61291] (r:1 w:1) + fn unlock() -> Weight { + (99_237_000 as Weight) + .saturating_add(T::DbWeight::get().reads(4 as Weight)) + .saturating_add(T::DbWeight::get().writes(3 as Weight)) } - fn on_initialize(_n: u32) -> Weight { - (9_002_000 as Weight) - .saturating_add(T::DbWeight::get().reads(2 as Weight)) - .saturating_add(T::DbWeight::get().writes(1 as Weight)) + // Storage: Salp Funds (r:1 w:0) + // Storage: Salp RedeemPool (r:1 w:1) + // Storage: Tokens Accounts (r:4 w:4) + // Storage: Tokens TotalIssuance (r:2 w:2) + // Storage: System Account (r:1 w:0) + // Storage: unknown [0xd861ea1ebf4800d4b89f4ff787ad79ee96d9a708c85b57da7eb8f9ddeda61291] (r:0 w:1) + fn redeem() -> Weight { + (169_980_000 as Weight) + .saturating_add(T::DbWeight::get().reads(9 as Weight)) + .saturating_add(T::DbWeight::get().writes(8 as Weight)) } } diff --git a/runtime/bifrost/src/lib.rs b/runtime/bifrost/src/lib.rs index a592646087..b7fed9540d 100644 --- a/runtime/bifrost/src/lib.rs +++ b/runtime/bifrost/src/lib.rs @@ -1281,6 +1281,23 @@ impl_runtime_apis! { #[cfg(feature = "runtime-benchmarks")] impl frame_benchmarking::Benchmark for Runtime { + fn benchmark_metadata(extra: bool) -> ( + Vec, + Vec, + ) { + use frame_support::traits::StorageInfoTrait; + use frame_benchmarking::{list_benchmark, Benchmarking, BenchmarkList}; + + let mut list = Vec::::new(); + + list_benchmark!(list, extra, bifrost_bancor, Bancor); + list_benchmark!(list, extra, bifrost_flexible_fee, FlexibleFee); + list_benchmark!(list, extra, bifrost_salp, Salp); + + let storage_info = AllPalletsWithSystem::storage_info(); + + return (list, storage_info) + } fn dispatch_benchmark( config: frame_benchmarking::BenchmarkConfig ) -> Result, sp_runtime::RuntimeString> { @@ -1307,6 +1324,7 @@ impl_runtime_apis! { add_benchmark!(params, batches, pallet_utility, Utility); add_benchmark!(params, batches, pallet_vesting, Vesting); add_benchmark!(params, batches, bifrost_flexible_fee, FlexibleFee); + add_benchmark!(params, batches, bifrost_salp, Salp); if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) } Ok(batches) diff --git a/runtime/bifrost/src/weights/bifrost_salp.rs b/runtime/bifrost/src/weights/bifrost_salp.rs index 24a11bc887..cf59d68c86 100644 --- a/runtime/bifrost/src/weights/bifrost_salp.rs +++ b/runtime/bifrost/src/weights/bifrost_salp.rs @@ -16,77 +16,92 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -//! Autogenerated weights for bifrost_salp +//! Autogenerated weights for `bifrost_salp` //! -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 3.0.0 -//! DATE: 2021-08-18, STEPS: `[50, ]`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("asgard-local"), DB CACHE: 128 +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2021-09-07, STEPS: `50`, REPEAT: 1, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("bifrost-local"), DB CACHE: 128 // Executed Command: // target/release/bifrost // benchmark -// --chain=asgard-local +// --chain=bifrost-local // --steps=50 -// --repeat=20 +// --repeat=1 // --pallet=bifrost_salp // --extrinsic=* // --execution=wasm // --wasm-execution=compiled // --heap-pages=4096 // --header=./HEADER-GPL3 -// --output=./runtime/asgard/src/weights/bifrost_salp.rs +// --output=./runtime/bifrost/src/weights/bifrost_salp.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_salp -/// @todo benchmark again later +/// Weight functions for bifrost_salp. pub struct WeightInfo(PhantomData); impl bifrost_salp::WeightInfo for WeightInfo { - fn create() -> Weight { - (38_000_000 as Weight) - .saturating_add(T::DbWeight::get().reads(2 as Weight)) - .saturating_add(T::DbWeight::get().writes(2 as Weight)) - } + // Storage: Salp Funds (r:1 w:0) + // Storage: Tokens Accounts (r:1 w:1) + // Storage: System Number (r:1 w:0) + // Storage: System ExecutionPhase (r:1 w:0) + // Storage: System EventCount (r:1 w:1) + // Storage: System Events (r:1 w:1) + // Storage: Salp CurrentNonce (r:1 w:1) + // Storage: ParachainSystem HostConfiguration (r:1 w:0) + // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) + // Storage: unknown [0xd861ea1ebf4800d4b89f4ff787ad79ee96d9a708c85b57da7eb8f9ddeda61291] (r:1 w:1) fn contribute() -> Weight { - (8_000_000_000 as Weight) - .saturating_add(T::DbWeight::get().reads(4 as Weight)) - .saturating_add(T::DbWeight::get().writes(2 as Weight)) - } - fn unlock() -> Weight { - (0 as Weight) - .saturating_add(T::DbWeight::get().reads(2 as Weight)) - .saturating_add(T::DbWeight::get().writes(2 as Weight)) - } - fn withdraw() -> Weight { - (64_140_000 as Weight) - .saturating_add(T::DbWeight::get().reads(4 as Weight)) - .saturating_add(T::DbWeight::get().writes(2 as Weight)) - } - fn redeem() -> Weight { - (110_824_000 as Weight) - .saturating_add(T::DbWeight::get().reads(4 as Weight)) - .saturating_add(T::DbWeight::get().writes(4 as Weight)) + (156_695_000 as Weight) + .saturating_add(T::DbWeight::get().reads(10 as Weight)) + .saturating_add(T::DbWeight::get().writes(6 as Weight)) } + // Storage: Salp Funds (r:1 w:0) + // Storage: Salp RefundPool (r:1 w:1) + // Storage: Tokens Accounts (r:4 w:4) + // Storage: Tokens TotalIssuance (r:2 w:2) + // Storage: System Number (r:1 w:0) + // Storage: System ExecutionPhase (r:1 w:0) + // Storage: System EventCount (r:1 w:1) + // Storage: System Events (r:1 w:1) + // Storage: System Account (r:1 w:1) + // Storage: unknown [0xd861ea1ebf4800d4b89f4ff787ad79ee96d9a708c85b57da7eb8f9ddeda61291] (r:1 w:1) fn refund() -> Weight { - (110_824_000 as Weight) - .saturating_add(T::DbWeight::get().reads(4 as Weight)) - .saturating_add(T::DbWeight::get().writes(4 as Weight)) + (191_941_000 as Weight) + .saturating_add(T::DbWeight::get().reads(14 as Weight)) + .saturating_add(T::DbWeight::get().writes(11 as Weight)) } - fn dissolve(k: u32) -> Weight { - (0 as Weight) - .saturating_add((45_890_000 as Weight).saturating_mul(k as Weight)) - .saturating_add(T::DbWeight::get().reads(3 as Weight)) - .saturating_add(T::DbWeight::get().reads((2 as Weight).saturating_mul(k as Weight))) - .saturating_add(T::DbWeight::get().writes(2 as Weight)) - .saturating_add(T::DbWeight::get().writes((2 as Weight).saturating_mul(k as Weight))) + // Storage: Salp Funds (r:1 w:0) + // Storage: Tokens Accounts (r:2 w:2) + // Storage: System Number (r:1 w:0) + // Storage: System ExecutionPhase (r:1 w:0) + // Storage: System EventCount (r:1 w:1) + // Storage: System Events (r:1 w:1) + // Storage: unknown [0xd861ea1ebf4800d4b89f4ff787ad79ee96d9a708c85b57da7eb8f9ddeda61291] (r:1 w:1) + fn unlock() -> Weight { + (132_639_000 as Weight) + .saturating_add(T::DbWeight::get().reads(8 as Weight)) + .saturating_add(T::DbWeight::get().writes(5 as Weight)) } - fn on_initialize(_n: u32) -> Weight { - (9_002_000 as Weight) - .saturating_add(T::DbWeight::get().reads(2 as Weight)) - .saturating_add(T::DbWeight::get().writes(1 as Weight)) + // Storage: Salp Funds (r:1 w:0) + // Storage: Salp RedeemPool (r:1 w:1) + // Storage: System Number (r:1 w:0) + // Storage: Tokens Accounts (r:4 w:4) + // Storage: Tokens TotalIssuance (r:2 w:2) + // Storage: System ExecutionPhase (r:1 w:0) + // Storage: System EventCount (r:1 w:1) + // Storage: System Events (r:1 w:1) + // Storage: System Account (r:1 w:1) + // Storage: unknown [0xd861ea1ebf4800d4b89f4ff787ad79ee96d9a708c85b57da7eb8f9ddeda61291] (r:0 w:1) + fn redeem() -> Weight { + (222_549_000 as Weight) + .saturating_add(T::DbWeight::get().reads(13 as Weight)) + .saturating_add(T::DbWeight::get().writes(11 as Weight)) } } diff --git a/runtime/dev/Cargo.toml b/runtime/dev/Cargo.toml index 0b4ef325fc..e1046d3bd3 100644 --- a/runtime/dev/Cargo.toml +++ b/runtime/dev/Cargo.toml @@ -92,7 +92,7 @@ bifrost-vsbond-auction = { path = "../../pallets/vsbond-auction", default-featur bifrost-vtoken-mint = { path = "../../pallets/vtoken-mint", default-features = false } pallet-vesting = { package = "bifrost-vesting", path = "../../pallets/vesting", default-features = false } xcm-support = { path = "../../xcm-support", default-features = false } - +bifrost-liquidity-mining = { path = "../../pallets/liquidity-mining", default-features = false } # orml orml-currencies = { version = "0.4.1-dev", default-features = false } orml-tokens = { version = "0.4.1-dev", default-features = false } @@ -183,6 +183,7 @@ std = [ "orml-xcm-support/std", "zenlink-protocol/std", "zenlink-protocol-runtime-api/std", + "bifrost-liquidity-mining/std", ] runtime-benchmarks = [ @@ -198,6 +199,7 @@ runtime-benchmarks = [ "bifrost-flexible-fee/runtime-benchmarks", "bifrost-vtoken-mint/runtime-benchmarks", "bifrost-minter-reward/runtime-benchmarks", + "bifrost-vsbond-auction/runtime-benchmarks", ] try-runtime = [ diff --git a/runtime/dev/src/lib.rs b/runtime/dev/src/lib.rs index 08621c626e..9cb178c59a 100644 --- a/runtime/dev/src/lib.rs +++ b/runtime/dev/src/lib.rs @@ -1045,6 +1045,28 @@ impl bifrost_vsbond_auction::Config for Runtime { type WeightInfo = weights::bifrost_vsbond_auction::WeightInfo; } +parameter_types! { + pub const RelayChainTokenSymbol: TokenSymbol = TokenSymbol::KSM; + pub const MaximumDepositInPool: Balance = 1_000_000_000 * DOLLARS; + pub const MinimumDepositOfUser: Balance = 1_000_000; + pub const MinimumRewardPerBlock: Balance = 1_000; + pub const MinimumDuration: BlockNumber = DAYS; + pub const MaximumApproved: u32 = 8; +} + +impl bifrost_liquidity_mining::Config for Runtime { + type Event = Event; + type ControlOrigin = + pallet_collective::EnsureProportionAtLeast<_2, _3, AccountId, TechnicalCollective>; + type MultiCurrency = Currencies; + type RelayChainTokenSymbol = RelayChainTokenSymbol; + type MaximumDepositInPool = MaximumDepositInPool; + type MinimumDepositOfUser = MinimumDepositOfUser; + type MinimumRewardPerBlock = MinimumRewardPerBlock; + type MinimumDuration = MinimumDuration; + type MaximumApproved = MaximumApproved; +} + // bifrost runtime end // zenlink runtime start @@ -1260,6 +1282,7 @@ construct_runtime! { Salp: bifrost_salp::{Pallet, Call, Storage, Event} = 105, Bancor: bifrost_bancor::{Pallet, Call, Storage, Event, Config} = 106, VSBondAuction: bifrost_vsbond_auction::{Pallet, Call, Storage, Event} = 107, + LiquidityMining: bifrost_liquidity_mining::{Pallet, Call, Storage, Event} = 108, } } @@ -1514,6 +1537,25 @@ impl_runtime_apis! { // benchmarks for asgard modules #[cfg(feature = "runtime-benchmarks")] impl frame_benchmarking::Benchmark for Runtime { + fn benchmark_metadata(extra: bool) -> ( + Vec, + Vec, + ) { + use frame_support::traits::StorageInfoTrait; + use frame_benchmarking::{list_benchmark, Benchmarking, BenchmarkList}; + let mut list = Vec::::new(); + + list_benchmark!(list, extra, bifrost_salp, Salp); + list_benchmark!(list, extra, bifrost_bancor, Bancor); + list_benchmark!(list, extra, bifrost_flexible_fee, FlexibleFee); + list_benchmark!(list, extra, bifrost_vtoken_mint, VtokenMint); + list_benchmark!(list, extra, bifrost_minter_reward, MinterReward); + list_benchmark!(list, extra, bifrost_vsbond_auction, VSBondAuction); + + let storage_info = AllPalletsWithSystem::storage_info(); + + return (list, storage_info) + } fn dispatch_benchmark( config: frame_benchmarking::BenchmarkConfig ) -> Result, RuntimeString> { @@ -1543,6 +1585,7 @@ impl_runtime_apis! { add_benchmark!(params, batches, bifrost_flexible_fee, FlexibleFee); add_benchmark!(params, batches, bifrost_vtoken_mint, VtokenMint); add_benchmark!(params, batches, bifrost_minter_reward, MinterReward); + add_benchmark!(params, batches, bifrost_vsbond_auction, VSBondAuction); if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) } Ok(batches) diff --git a/runtime/dev/src/weights/bifrost_salp.rs b/runtime/dev/src/weights/bifrost_salp.rs index 1ef5490cc6..e157dedde6 100644 --- a/runtime/dev/src/weights/bifrost_salp.rs +++ b/runtime/dev/src/weights/bifrost_salp.rs @@ -46,47 +46,49 @@ use sp_std::marker::PhantomData; /// @todo benchmark again later pub struct WeightInfo(PhantomData); impl bifrost_salp::WeightInfo for WeightInfo { - fn create() -> Weight { - (60_954_000 as Weight) - .saturating_add(T::DbWeight::get().reads(2 as Weight)) - .saturating_add(T::DbWeight::get().writes(2 as Weight)) - } + // Storage: Salp Funds (r:1 w:0) + // Storage: Tokens Accounts (r:1 w:1) + // Storage: Salp CurrentNonce (r:1 w:1) + // Storage: ParachainSystem HostConfiguration (r:1 w:0) + // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) + // Storage: unknown [0xd861ea1ebf4800d4b89f4ff787ad79ee96d9a708c85b57da7eb8f9ddeda61291] (r:1 + // w:1) fn contribute() -> Weight { - (64_140_000 as Weight) - .saturating_add(T::DbWeight::get().reads(4 as Weight)) - .saturating_add(T::DbWeight::get().writes(2 as Weight)) - } - fn unlock() -> Weight { - (0 as Weight) - .saturating_add(T::DbWeight::get().reads(2 as Weight)) - .saturating_add(T::DbWeight::get().writes(2 as Weight)) - } - fn withdraw() -> Weight { - (64_140_000 as Weight) - .saturating_add(T::DbWeight::get().reads(4 as Weight)) - .saturating_add(T::DbWeight::get().writes(2 as Weight)) - } - fn redeem() -> Weight { - (110_824_000 as Weight) - .saturating_add(T::DbWeight::get().reads(4 as Weight)) + (122_561_000 as Weight) + .saturating_add(T::DbWeight::get().reads(6 as Weight)) .saturating_add(T::DbWeight::get().writes(4 as Weight)) } + // Storage: Salp Funds (r:1 w:0) + // Storage: Salp RefundPool (r:1 w:1) + // Storage: Tokens Accounts (r:4 w:4) + // Storage: Tokens TotalIssuance (r:2 w:2) + // Storage: System Account (r:1 w:0) + // Storage: unknown [0xd861ea1ebf4800d4b89f4ff787ad79ee96d9a708c85b57da7eb8f9ddeda61291] (r:1 + // w:1) fn refund() -> Weight { - (110_824_000 as Weight) - .saturating_add(T::DbWeight::get().reads(4 as Weight)) - .saturating_add(T::DbWeight::get().writes(4 as Weight)) + (139_712_000 as Weight) + .saturating_add(T::DbWeight::get().reads(10 as Weight)) + .saturating_add(T::DbWeight::get().writes(8 as Weight)) } - fn dissolve(k: u32) -> Weight { - (0 as Weight) - .saturating_add((45_890_000 as Weight).saturating_mul(k as Weight)) - .saturating_add(T::DbWeight::get().reads(3 as Weight)) - .saturating_add(T::DbWeight::get().reads((2 as Weight).saturating_mul(k as Weight))) - .saturating_add(T::DbWeight::get().writes(2 as Weight)) - .saturating_add(T::DbWeight::get().writes((2 as Weight).saturating_mul(k as Weight))) + // Storage: Salp Funds (r:1 w:0) + // Storage: Tokens Accounts (r:2 w:2) + // Storage: unknown [0xd861ea1ebf4800d4b89f4ff787ad79ee96d9a708c85b57da7eb8f9ddeda61291] (r:1 + // w:1) + fn unlock() -> Weight { + (99_237_000 as Weight) + .saturating_add(T::DbWeight::get().reads(4 as Weight)) + .saturating_add(T::DbWeight::get().writes(3 as Weight)) } - fn on_initialize(_n: u32) -> Weight { - (9_002_000 as Weight) - .saturating_add(T::DbWeight::get().reads(2 as Weight)) - .saturating_add(T::DbWeight::get().writes(1 as Weight)) + // Storage: Salp Funds (r:1 w:0) + // Storage: Salp RedeemPool (r:1 w:1) + // Storage: Tokens Accounts (r:4 w:4) + // Storage: Tokens TotalIssuance (r:2 w:2) + // Storage: System Account (r:1 w:0) + // Storage: unknown [0xd861ea1ebf4800d4b89f4ff787ad79ee96d9a708c85b57da7eb8f9ddeda61291] (r:0 + // w:1) + fn redeem() -> Weight { + (169_980_000 as Weight) + .saturating_add(T::DbWeight::get().reads(9 as Weight)) + .saturating_add(T::DbWeight::get().writes(8 as Weight)) } } diff --git a/scripts/run_all_benches.sh b/scripts/run_all_benches.sh index 526dc1d828..53cd899669 100755 --- a/scripts/run_all_benches.sh +++ b/scripts/run_all_benches.sh @@ -3,9 +3,7 @@ # Runs all benchmarks for all pallets, for each of the runtimes specified below # Should be run on a reference machine to gain accurate benchmarks(currently run on bifrost builder) -runtimes=( - asgard -) +runtimes=(asgard bifrost) # cargo build --locked --release for runtime in "${runtimes[@]}"; do