Skip to content

Commit

Permalink
[orml-vesting-benchmarks] change upstream benchmark so that they fit …
Browse files Browse the repository at this point in the history
…our runtime
  • Loading branch information
clangenb committed Mar 17, 2024
1 parent a786ae4 commit f5dfd9b
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 91 deletions.
36 changes: 0 additions & 36 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ staging-parachain-info = { version = "0.8.0", default-features
# ORML
orml-vesting = { git = "https://github.com/ajuna-network/open-runtime-module-library.git", branch = "remove-nested-workspace", default-features = false }
orml-benchmarking = { git = "https://github.com/ajuna-network/open-runtime-module-library.git", branch = "remove-nested-workspace", default-features = false }
orml-traits = { git = "https://github.com/ajuna-network/open-runtime-module-library.git", branch = "remove-nested-workspace", default-features = false }

# Runtime
bajun-runtime = { path = "runtime/bajun" }
Expand Down
3 changes: 0 additions & 3 deletions runtime/bajun/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ staging-parachain-info = { workspace = true }
# ORML
orml-vesting = { workspace = true }
orml-benchmarking = { workspace = true, optional = true }
orml-traits = { workspace = true, optional = true }

# Ajuna Pallets
pallet-ajuna-affiliates = { workspace = true }
Expand Down Expand Up @@ -119,7 +118,6 @@ std = [
"orml-vesting/std",
"pallet-ajuna-affiliates/std",
"orml-benchmarking?/std",
"orml-traits?/std",
"pallet-ajuna-awesome-avatars/std",
"pallet-ajuna-awesome-avatars-benchmarking?/std",
"pallet-ajuna-nft-transfer/std",
Expand Down Expand Up @@ -176,7 +174,6 @@ runtime-benchmarks = [
"frame-system/runtime-benchmarks",
"orml-vesting/runtime-benchmarks",
"orml-benchmarking",
"orml-traits",
"pallet-balances/runtime-benchmarks",
"pallet-collator-selection/runtime-benchmarks",
"pallet-collective/runtime-benchmarks",
Expand Down
4 changes: 4 additions & 0 deletions runtime/bajun/src/benchmarking/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
mod utils;

// module benchmarking
mod orml_vesting;
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,14 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use super::{
get_vesting_account,
utils::{lookup_of_account, set_balance, NATIVE},
};
use crate::{dollar, AccountId, Balance, BlockNumber, Currencies, Runtime, System, Vesting};

use sp_std::prelude::*;

use super::utils::{get_vesting_account, lookup_of_account, set_balance};
use crate::{AccountId, Balance, Balances, BlockNumber, Runtime, System, Vesting, BAJUN};
use frame_benchmarking::{account, whitelisted_caller};
use frame_support::traits::Get;
use frame_support::traits::{fungible::Inspect, Get};
use frame_system::RawOrigin;
use sp_std::prelude::*;

use orml_benchmarking::runtime_benchmarks;
use orml_traits::MultiCurrency;
use orml_vesting::VestingSchedule;

pub type Schedule = VestingSchedule<BlockNumber, Balance>;
Expand All @@ -47,16 +41,14 @@ runtime_benchmarks! {
per_period: <Runtime as orml_vesting::Config>::MinVestedTransfer::get(),
};

// extra 1 dollar to pay fees
let from: AccountId = get_vesting_account();
set_balance(NATIVE, &from, schedule.total_amount().unwrap() + dollar(NATIVE));
set_balance(from.clone(), schedule.total_amount().unwrap() + BAJUN);

let to: AccountId = account("to", 0, SEED);
let to_lookup = lookup_of_account(to.clone());
}: _(RawOrigin::Signed(from), to_lookup, schedule.clone())
verify {
assert_eq!(
<Currencies as MultiCurrency<_>>::total_balance(NATIVE, &to),
assert_eq!(Balances::total_balance(&to),
schedule.total_amount().unwrap()
);
}
Expand All @@ -72,9 +64,7 @@ runtime_benchmarks! {
};

let from: AccountId = get_vesting_account();
// extra 1 dollar to pay fees
set_balance(NATIVE, &from, schedule.total_amount().unwrap() * i as u128 + dollar(NATIVE));

set_balance(from.clone(), schedule.total_amount().unwrap() + BAJUN);
let to: AccountId = whitelisted_caller();
let to_lookup = lookup_of_account(to.clone());

Expand All @@ -86,7 +76,7 @@ runtime_benchmarks! {
}: _(RawOrigin::Signed(to.clone()))
verify {
assert_eq!(
<Currencies as MultiCurrency<_>>::free_balance(NATIVE, &to),
Balances::free_balance(&to),
schedule.total_amount().unwrap() * i as u128,
);
}
Expand All @@ -102,7 +92,7 @@ runtime_benchmarks! {
};

let to: AccountId = account("to", 0, SEED);
set_balance(NATIVE, &to, schedule.total_amount().unwrap() * i as u128);
set_balance(to.clone(),schedule.total_amount().unwrap() * i as u128);
let to_lookup = lookup_of_account(to.clone());

let mut schedules = vec![];
Expand All @@ -113,7 +103,7 @@ runtime_benchmarks! {
}: _(RawOrigin::Root, to_lookup, schedules)
verify {
assert_eq!(
<Currencies as MultiCurrency<_>>::free_balance(NATIVE, &to),
Balances::free_balance(&to),
schedule.total_amount().unwrap() * i as u128
);
}
Expand Down
30 changes: 30 additions & 0 deletions runtime/bajun/src/benchmarking/utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
pub use crate::{AccountId, Balances, Runtime, BAJUN};
use frame_support::dispatch::RawOrigin;
pub use parity_scale_codec::Encode;
use sp_runtime::traits::{AccountIdConversion, StaticLookup};

pub fn get_vesting_account() -> AccountId {
crate::TreasuryPalletId::get().into_account_truncating()
}

pub fn lookup_of_account(
who: AccountId,
) -> <<Runtime as frame_system::Config>::Lookup as StaticLookup>::Source {
<Runtime as frame_system::Config>::Lookup::unlookup(who)
}

pub fn set_balance(account: AccountId, schedule_amount: u128) {
Balances::force_set_balance(RawOrigin::Root.into(), account.into(), schedule_amount).unwrap();
}

#[cfg(test)]
pub mod tests {
use sp_runtime::BuildStorage;

pub fn new_test_ext() -> sp_io::TestExternalities {
frame_system::GenesisConfig::<crate::Runtime>::default()
.build_storage()
.unwrap()
.into()
}
}
1 change: 0 additions & 1 deletion runtime/bajun/src/benchmarks/mod.rs

This file was deleted.

58 changes: 28 additions & 30 deletions runtime/bajun/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));

#[cfg(feature = "runtime-benchmarks")]
mod benchmarks;
mod benchmarking;
mod gov;
mod proxy_type;
mod weights;
Expand Down Expand Up @@ -928,35 +928,33 @@ extern crate frame_benchmarking;

#[cfg(feature = "runtime-benchmarks")]
mod benches {
define_benchmarks!(
[cumulus_pallet_parachain_system, ParachainSystem]
[cumulus_pallet_xcmp_queue, XcmpQueue]
[frame_system, SystemBench::<Runtime>]
[pallet_balances, Balances]
[pallet_collator_selection, CollatorSelection]
[pallet_collective, Council]
// [pallet_collective, TechnicalCommittee] // writes to the same file
[pallet_democracy, Democracy]
[pallet_identity, Identity]
[pallet_membership, CouncilMembership]
// [pallet_membership, TechnicalCommitteeMembership] // writes to the same file
[pallet_message_queue, MessageQueue]
[pallet_multisig, Multisig]
[pallet_preimage, Preimage]
[pallet_proxy, Proxy]
[pallet_scheduler, Scheduler]
[pallet_session, SessionBench::<Runtime>]
[pallet_sudo, Sudo]
[pallet_timestamp, Timestamp]
// [pallet_treasury, Treasury] // treasury config is broken, needs fixes
[pallet_utility, Utility]
[pallet_ajuna_awesome_avatars, AwesomeAvatarsBench::<Runtime>]
[pallet_nfts, Nft]
);
// Use this section if you want to benchmark individual pallets
// define_benchmarks!(
// [orml_vesting, Vesting]
// )
// [cumulus_pallet_parachain_system, ParachainSystem]
// [cumulus_pallet_xcmp_queue, XcmpQueue]
// [frame_system, SystemBench::<Runtime>]
// [pallet_balances, Balances]
// [pallet_collator_selection, CollatorSelection]
// [pallet_collective, Council]
// // [pallet_collective, TechnicalCommittee] // writes to the same file
// [pallet_democracy, Democracy]
// [pallet_identity, Identity]
// [pallet_membership, CouncilMembership]
// // [pallet_membership, TechnicalCommitteeMembership] // writes to the same file
// [pallet_message_queue, MessageQueue]
// [pallet_multisig, Multisig]
// [pallet_preimage, Preimage]
// [pallet_proxy, Proxy]
// [pallet_scheduler, Scheduler]
// [pallet_session, SessionBench::<Runtime>]
// [pallet_sudo, Sudo]
// [pallet_timestamp, Timestamp]
// // [pallet_treasury, Treasury] // treasury config is broken, needs fixes
// [pallet_utility, Utility]
// [pallet_ajuna_awesome_avatars, AwesomeAvatarsBench::<Runtime>]
// [pallet_nfts, Nft]
// );
// Use this section if you want to benchmark individual pallets
define_benchmarks!([orml_vesting, benchmarking::vesting]);
}

#[cfg(feature = "runtime-benchmarks")]
Expand Down Expand Up @@ -1126,7 +1124,7 @@ impl_runtime_apis! {
}
}

#[cfg(feature = "runtime-benchmarks")]
#[cfg(feature = "runtime-benchmarking")]
impl frame_benchmarking::Benchmark<Block> for Runtime {
fn benchmark_metadata(extra: bool) -> (
Vec<frame_benchmarking::BenchmarkList>,
Expand Down

0 comments on commit f5dfd9b

Please sign in to comment.