Skip to content

Commit

Permalink
working on benchmarking
Browse files Browse the repository at this point in the history
  • Loading branch information
amiyatulu committed Sep 22, 2024
1 parent 3af6747 commit 99bd40a
Show file tree
Hide file tree
Showing 22 changed files with 53 additions and 181 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@
.vscode/settings.json

mychain-data

ev
13 changes: 5 additions & 8 deletions custom-pallets/department-funding/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ mod mock;
#[cfg(test)]
mod tests;

#[cfg(feature = "runtime-benchmarks")]
mod benchmarking;
// #[cfg(feature = "runtime-benchmarks")]
// mod benchmarking;
pub mod weights;
pub use weights::*;

Expand All @@ -30,16 +30,13 @@ use frame_system::pallet_prelude::*;
use sp_std::prelude::*;

use frame_support::traits::{
Currency, ExistenceRequirement, OnUnbalanced, ReservableCurrency, WithdrawReasons,
};
Currency, ExistenceRequirement, OnUnbalanced, ReservableCurrency, WithdrawReasons,
};
use pallet_schelling_game_shared::types::{
JurorGameResult, Period, PhaseData, RangePoint, SchellingGameType,
};
use pallet_sortition_sum_game::types::SumTreeName;
use pallet_support::{
new_when_details, new_who_and_when, Content,
WhenDetailsOf, WhoAndWhenOf,
};
use pallet_support::{new_when_details, new_who_and_when, Content, WhenDetailsOf, WhoAndWhenOf};
use trait_departments::DepartmentsLink;
use trait_schelling_game_shared::SchellingGameSharedLink;
use trait_shared_storage::SharedStorageLink;
Expand Down
3 changes: 0 additions & 3 deletions custom-pallets/department-funding/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ impl pallet_timestamp::Config for Test {

impl pallet_shared_storage::Config for Test {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = ();
}
impl pallet_template::Config for Test {
type RuntimeEvent = RuntimeEvent;
Expand Down Expand Up @@ -96,7 +95,6 @@ impl pallet_balances::Config for Test {

impl pallet_schelling_game_shared::Config for Test {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = ();
type Currency = Balances; // New code
type RandomnessSource = TestRandomness<Self>;
type Slash = ();
Expand All @@ -106,7 +104,6 @@ impl pallet_schelling_game_shared::Config for Test {

impl pallet_sortition_sum_game::Config for Test {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = ();
}

impl pallet_departments::Config for Test {
Expand Down
8 changes: 3 additions & 5 deletions custom-pallets/departments/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ mod tests;
// Every callable function or "dispatchable" a pallet exposes must have weight values that correctly
// estimate a dispatchable's execution time. The benchmarking module is used to calculate weights
// for each dispatchable and generates this pallet's weight.rs file. Learn more about benchmarking here: https://docs.substrate.io/test/benchmark/
#[cfg(feature = "runtime-benchmarks")]
mod benchmarking;
// #[cfg(feature = "runtime-benchmarks")]
// mod benchmarking;
pub mod weights;
pub use weights::*;
pub mod extras;
Expand All @@ -66,9 +66,7 @@ use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
pub use types::{DepartmentDetails, FIRST_DEPARTMENT_ID};
type DepartmentId = u64;
use pallet_support::{
new_who_and_when, Content, WhoAndWhenOf,
};
use pallet_support::{new_who_and_when, Content, WhoAndWhenOf};

use sp_std::vec;
use sp_std::vec::Vec;
Expand Down
24 changes: 2 additions & 22 deletions custom-pallets/positive-externality/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,7 @@ use frame_system::RawOrigin;

#[benchmarks]
mod benchmarks {
use super::*;
// use super::*;

#[benchmark]
fn do_something() {
let value = 100u32.into();
let caller: T::AccountId = whitelisted_caller();
#[extrinsic_call]
do_something(RawOrigin::Signed(caller), value);

assert_eq!(Something::<T>::get(), Some(value));
}

#[benchmark]
fn cause_error() {
Something::<T>::put(100u32);
let caller: T::AccountId = whitelisted_caller();
#[extrinsic_call]
cause_error(RawOrigin::Signed(caller));

assert_eq!(Something::<T>::get(), Some(101u32));
}

impl_benchmark_test_suite!(Template, crate::mock::new_test_ext(), crate::mock::Test);
// impl_benchmark_test_suite!(Template, crate::mock::new_test_ext(), crate::mock::Test);
}
13 changes: 7 additions & 6 deletions custom-pallets/positive-externality/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ mod mock;
#[cfg(test)]
mod tests;

#[cfg(feature = "runtime-benchmarks")]
mod benchmarking;
// #[cfg(feature = "runtime-benchmarks")]
// mod benchmarking;
pub mod weights;
pub use weights::*;

Expand All @@ -22,17 +22,18 @@ pub use types::{Post, FIRST_POST_ID};

use frame_support::pallet_prelude::*;
use frame_support::sp_runtime::SaturatedConversion;
use frame_support::{dispatch::DispatchResult, ensure};
use frame_support::traits::{
Currency, ExistenceRequirement, Get, OnUnbalanced, ReservableCurrency, WithdrawReasons,
};
Currency, ExistenceRequirement, Get, OnUnbalanced, ReservableCurrency, WithdrawReasons,
};
use frame_support::{dispatch::DispatchResult, ensure};
use frame_system::pallet_prelude::*;
use pallet_schelling_game_shared::types::{
JurorGameResult, Period, PhaseData, RangePoint, SchellingGameType, WinningDecision,
};
use pallet_sortition_sum_game::types::SumTreeName;
use pallet_support::{
ensure_content_is_valid, new_when_details, new_who_and_when, Content, PostId, WhenDetailsOf, WhoAndWhenOf,
ensure_content_is_valid, new_when_details, new_who_and_when, Content, PostId, WhenDetailsOf,
WhoAndWhenOf,
};
use types::{Incentives, IncentivesMetaData};

Expand Down
3 changes: 0 additions & 3 deletions custom-pallets/positive-externality/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ impl frame_system::Config for Test {

impl pallet_shared_storage::Config for Test {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = ();
}
parameter_types! {
pub const MinimumPeriod: u64 = 5;
Expand Down Expand Up @@ -86,7 +85,6 @@ impl pallet_balances::Config for Test {

impl pallet_schelling_game_shared::Config for Test {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = ();
type Currency = Balances; // New code
type RandomnessSource = TestRandomness<Self>;
type Slash = ();
Expand All @@ -96,7 +94,6 @@ impl pallet_schelling_game_shared::Config for Test {

impl pallet_sortition_sum_game::Config for Test {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = ();
}

impl pallet_template::Config for Test {
Expand Down
12 changes: 4 additions & 8 deletions custom-pallets/profile-validation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ mod mock;
#[cfg(test)]
mod tests;

#[cfg(feature = "runtime-benchmarks")]
mod benchmarking;
// #[cfg(feature = "runtime-benchmarks")]
// mod benchmarking;
pub mod weights;
pub use weights::*;

Expand All @@ -33,9 +33,7 @@ use frame_support::sp_runtime::traits::{CheckedAdd, CheckedSub};
use frame_support::sp_runtime::SaturatedConversion;
use frame_support::{dispatch::DispatchResult, pallet_prelude::*};
use frame_support::{
traits::{
Currency, ExistenceRequirement, OnUnbalanced, ReservableCurrency, WithdrawReasons,
},
traits::{Currency, ExistenceRequirement, OnUnbalanced, ReservableCurrency, WithdrawReasons},
PalletId,
};
use frame_system::pallet_prelude::*;
Expand All @@ -45,9 +43,7 @@ use pallet_schelling_game_shared::types::{
Period, PhaseData, RangePoint, SchellingGameType, WinningDecision,
};
use pallet_sortition_sum_game::types::SumTreeName;
use pallet_support::{
new_who_and_when, Content, WhoAndWhenOf,
};
use pallet_support::{new_who_and_when, Content, WhoAndWhenOf};
use trait_schelling_game_shared::SchellingGameSharedLink;
pub use types::{CitizenDetailsPost, FIRST_CHALLENGE_POST_ID, FIRST_CITIZEN_ID};
type AccountIdOf<T> = <T as frame_system::Config>::AccountId;
Expand Down
2 changes: 0 additions & 2 deletions custom-pallets/profile-validation/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ impl pallet_template::Config for Test {

impl pallet_schelling_game_shared::Config for Test {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = ();
type Currency = Balances; // New code
type RandomnessSource = TestRandomness<Self>;
type Slash = ();
Expand All @@ -100,7 +99,6 @@ impl pallet_schelling_game_shared::Config for Test {

impl pallet_sortition_sum_game::Config for Test {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = ();
}

// Build genesis storage according to the mock runtime.
Expand Down
32 changes: 17 additions & 15 deletions custom-pallets/project-tips/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,36 @@
#![cfg(feature = "runtime-benchmarks")]
use super::*;

use crate::types::{Incentives, TippingName};
#[allow(unused)]
use crate::Pallet as Template;
use crate::Pallet as ProjectTips;
use frame_benchmarking::v2::*;
use frame_system::RawOrigin;
use pallet_support::Content;

#[benchmarks]
mod benchmarks {
use super::*;

#[benchmark]
fn do_something() {
let value = 100u32.into();
let caller: T::AccountId = whitelisted_caller();
#[extrinsic_call]
do_something(RawOrigin::Signed(caller), value);
fn create_project() {
let content: Content = Content::IPFS(
"bafkreiaiq24be2iioasr6ftyaum3icmj7amtjkom2jeokov5k5ojwzhvqy"
.as_bytes()
.to_vec(),
);

assert_eq!(Something::<T>::get(), Some(value));
}
let tipping_name = TippingName::SmallTipper;
let tipping_value = ProjectTips::<T>::value_of_tipping_name(tipping_name);
let max_tipping_value = tipping_value.max_tipping_value;
let stake_required = tipping_value.stake_required;
let funding_needed = max_tipping_value;

#[benchmark]
fn cause_error() {
Something::<T>::put(100u32);
let caller: T::AccountId = whitelisted_caller();
#[extrinsic_call]
cause_error(RawOrigin::Signed(caller));

assert_eq!(Something::<T>::get(), Some(101u32));
#[extrinsic_call]
create_project(RawOrigin::Signed(caller), 5, content.clone(), tipping_name, funding_needed);
}

impl_benchmark_test_suite!(Template, crate::mock::new_test_ext(), crate::mock::Test);
impl_benchmark_test_suite!(ProjectTips, crate::mock::new_test_ext(), crate::mock::Test);
}
14 changes: 5 additions & 9 deletions custom-pallets/project-tips/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,20 @@ mod types;

use frame_support::pallet_prelude::DispatchError;
use frame_support::pallet_prelude::*;
use frame_support::sp_runtime::traits::{CheckedAdd};
use frame_support::sp_runtime::traits::CheckedAdd;
use frame_support::sp_runtime::SaturatedConversion;
use frame_support::{dispatch::DispatchResult, ensure};
use frame_system::pallet_prelude::*;
use sp_std::prelude::*;

use frame_support::
traits::{
Currency, ExistenceRequirement, OnUnbalanced, ReservableCurrency, WithdrawReasons,
};
use frame_support::traits::{
Currency, ExistenceRequirement, OnUnbalanced, ReservableCurrency, WithdrawReasons,
};
use pallet_schelling_game_shared::types::{
JurorGameResult, Period, PhaseData, RangePoint, SchellingGameType, WinningDecision,
};
use pallet_sortition_sum_game::types::SumTreeName;
use pallet_support::{
new_when_details, new_who_and_when, Content,
WhenDetailsOf, WhoAndWhenOf,
};
use pallet_support::{new_when_details, new_who_and_when, Content, WhenDetailsOf, WhoAndWhenOf};
use trait_schelling_game_shared::SchellingGameSharedLink;
use trait_shared_storage::SharedStorageLink;
pub use types::PROJECT_ID;
Expand Down
3 changes: 0 additions & 3 deletions custom-pallets/project-tips/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ impl pallet_timestamp::Config for Test {

impl pallet_shared_storage::Config for Test {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = ();
}
impl pallet_template::Config for Test {
type RuntimeEvent = RuntimeEvent;
Expand Down Expand Up @@ -95,7 +94,6 @@ impl pallet_balances::Config for Test {

impl pallet_schelling_game_shared::Config for Test {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = ();
type Currency = Balances; // New code
type RandomnessSource = TestRandomness<Self>;
type Slash = ();
Expand All @@ -105,7 +103,6 @@ impl pallet_schelling_game_shared::Config for Test {

impl pallet_sortition_sum_game::Config for Test {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = ();
}

// Build genesis storage according to the mock runtime.
Expand Down
7 changes: 0 additions & 7 deletions custom-pallets/schelling-game-shared/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ mod mock;
#[cfg(test)]
mod tests;

#[cfg(feature = "runtime-benchmarks")]
mod benchmarking;
pub mod weights;
pub use weights::*;

mod extras;
mod functions;
mod score_game;
Expand Down Expand Up @@ -63,8 +58,6 @@ pub mod pallet {
pub trait Config: frame_system::Config {
/// Because this pallet emits events, it depends on the runtime's definition of an event.
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
/// Type representing the weight of this pallet
type WeightInfo: WeightInfo;

type SortitionSumGameSource: SortitionSumGameLink<
SumTreeName = SumTreeName<Self::AccountId, BlockNumberOf<Self>>,
Expand Down
2 changes: 0 additions & 2 deletions custom-pallets/schelling-game-shared/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ impl frame_system::Config for Test {

impl pallet_template::Config for Test {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = ();
type Currency = Balances; // New code
type RandomnessSource = TestRandomness<Self>;
type Slash = ();
Expand All @@ -63,7 +62,6 @@ impl pallet_template::Config for Test {

impl pallet_sortition_sum_game::Config for Test {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = ();
}

impl pallet_balances::Config for Test {
Expand Down
35 changes: 0 additions & 35 deletions custom-pallets/shared-storage/src/benchmarking.rs

This file was deleted.

Loading

0 comments on commit 99bd40a

Please sign in to comment.