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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions node/service/src/chain_spec/asgard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -126,7 +127,10 @@ pub fn asgard_genesis(
}

fn development_config_genesis(id: ParaId) -> GenesisConfig {
let endowed_accounts = vec![get_account_id_from_seed::<sr25519::Public>("Alice")];
let endowed_accounts = vec![
get_account_id_from_seed::<sr25519::Public>("Alice"),
whitelisted_caller(), // Benchmarking whitelist_account
];
let balances = endowed_accounts
.iter()
.chain(faucet_accounts().iter())
Expand All @@ -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),
]
Expand Down
8 changes: 8 additions & 0 deletions pallets/bancor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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",
]
88 changes: 88 additions & 0 deletions pallets/bancor/src/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// 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 <https://www.gnu.org/licenses/>.

#![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::*;
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::<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 vstoken_amount = BalanceOf::<T>::unique_saturated_from(1u128);
let token_out_min = BalanceOf::<T>::unique_saturated_from(0u128);

// add token to the pool
BancorPools::<T>::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::<T>::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::<T>::unique_saturated_from(100u128);
let vstoken_out_min = BalanceOf::<T>::unique_saturated_from(0u128);

BancorPools::<T>::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::<T>::unique_saturated_from(7200 as u128);

BancorPools::<T>::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::<T>::on_initialize(block_num);}

}

impl_benchmark_test_suite!(
Bancor,
crate::mock::ExtBuilder::default()
.one_hundred_precision_for_each_currency_type_for_whitelist_account()
.build(),
crate::mock::Test
);
8 changes: 5 additions & 3 deletions pallets/bancor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@ use sp_runtime::{
traits::{CheckedAdd, CheckedDiv, CheckedMul, CheckedSub, Saturating, Zero},
SaturatedConversion,
};
use weights::WeightInfo;
pub use weights::WeightInfo;

mod mock;
mod tests;
pub mod weights;

#[cfg(feature = "runtime-benchmarks")]
mod benchmarking;

pub use pallet::*;

type AccountIdOf<T> = <T as frame_system::Config>::AccountId;
Expand Down Expand Up @@ -223,8 +226,7 @@ pub mod pallet {
}
}

// TODO: Estimate weight for this function
1_000
T::WeightInfo::on_initialize()
}
}

Expand Down
14 changes: 14 additions & 0 deletions pallets/bancor/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

#![cfg(test)]

#[cfg(feature = "runtime-benchmarks")]
use frame_benchmarking::whitelisted_caller;
use frame_support::{
construct_runtime, parameter_types,
traits::{GenesisBuild, OnFinalize, OnInitialize},
Expand Down Expand Up @@ -165,6 +167,18 @@ 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();

self.balances(vec![
(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),
])
}

pub fn build(self) -> sp_io::TestExternalities {
let mut t = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();

Expand Down
19 changes: 4 additions & 15 deletions pallets/bancor/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(PhantomData<T>);
impl<T: frame_system::Config> WeightInfo for BifrostWeight<T> {
// For backwards compatibility and tests
impl WeightInfo for () {
fn add_token_to_pool() -> Weight {
(50_000_000 as Weight)
}
Expand All @@ -46,19 +46,8 @@ impl<T: frame_system::Config> WeightInfo for BifrostWeight<T> {
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)
}
}
1 change: 1 addition & 0 deletions runtime/asgard/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,5 @@ runtime-benchmarks = [
"xcm-builder/runtime-benchmarks",
"pallet-xcm/runtime-benchmarks",
"bifrost-salp/runtime-benchmarks",
"bifrost-bancor/runtime-benchmarks",
]
5 changes: 3 additions & 2 deletions runtime/asgard/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,7 @@ impl bifrost_salp::Config for Runtime {
type SubmissionDeposit = SubmissionDeposit;
type VSBondValidPeriod = VSBondValidPeriod;
type XcmTransferOrigin = XcmTransferOrigin;
type WeightInfo = weights::pallet_salp::WeightInfo<Runtime>; // bifrost_salp::TestWeightInfo;
type WeightInfo = weights::bifrost_salp::WeightInfo<Runtime>; // bifrost_salp::TestWeightInfo;
}

parameter_types! {
Expand All @@ -986,7 +986,7 @@ impl bifrost_bancor::Config for Runtime {
type InterventionPercentage = InterventionPercentage;
type DailyReleasePercentage = DailyReleasePercentage;
type MultiCurrency = Currencies;
type WeightInfo = bifrost_bancor::weights::BifrostWeight<Runtime>;
type WeightInfo = weights::bifrost_bancor::WeightInfo<Runtime>;
}

parameter_types! {
Expand Down Expand Up @@ -1496,6 +1496,7 @@ impl_runtime_apis! {
let mut batches = Vec::<BenchmarkBatch>::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)
Expand Down
66 changes: 66 additions & 0 deletions runtime/asgard/src/weights/bifrost_bancor.rs
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.

//! 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<T>(PhantomData<T>);
impl<T: frame_system::Config> bifrost_bancor::WeightInfo for WeightInfo<T> {
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))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -48,22 +46,20 @@ use sp_std::marker::PhantomData;
pub struct WeightInfo<T>(PhantomData<T>);
impl<T: frame_system::Config> bifrost_salp::WeightInfo for WeightInfo<T> {
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))
}
}
Loading