Skip to content

Commit

Permalink
feat: added benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
Supremesource committed Dec 2, 2024
1 parent fc04b42 commit 755f787
Show file tree
Hide file tree
Showing 6 changed files with 198 additions and 109 deletions.
104 changes: 52 additions & 52 deletions pallets/governance/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Proof Size summary in bytes:
// Measured: `1316`
// Estimated: `3569`
// Minimum execution time: 99_137_000 picoseconds.
Weight::from_parts(102_083_000, 3569)
// Minimum execution time: 99_207_000 picoseconds.
Weight::from_parts(100_810_000, 3569)
.saturating_add(T::DbWeight::get().reads(17_u64))
.saturating_add(T::DbWeight::get().writes(2_u64))
}
Expand Down Expand Up @@ -176,8 +176,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Proof Size summary in bytes:
// Measured: `2633`
// Estimated: `18473`
// Minimum execution time: 234_062_000 picoseconds.
Weight::from_parts(246_625_000, 18473)
// Minimum execution time: 240_284_000 picoseconds.
Weight::from_parts(247_908_000, 18473)
.saturating_add(T::DbWeight::get().reads(43_u64))
.saturating_add(T::DbWeight::get().writes(2_u64))
}
Expand All @@ -191,8 +191,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Proof Size summary in bytes:
// Measured: `120`
// Estimated: `3569`
// Minimum execution time: 43_492_000 picoseconds.
Weight::from_parts(44_705_000, 3569)
// Minimum execution time: 44_263_000 picoseconds.
Weight::from_parts(45_276_000, 3569)
.saturating_add(T::DbWeight::get().reads(3_u64))
.saturating_add(T::DbWeight::get().writes(2_u64))
}
Expand All @@ -206,8 +206,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Proof Size summary in bytes:
// Measured: `120`
// Estimated: `3569`
// Minimum execution time: 49_043_000 picoseconds.
Weight::from_parts(52_258_000, 3569)
// Minimum execution time: 49_733_000 picoseconds.
Weight::from_parts(50_996_000, 3569)
.saturating_add(T::DbWeight::get().reads(3_u64))
.saturating_add(T::DbWeight::get().writes(2_u64))
}
Expand All @@ -223,8 +223,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Proof Size summary in bytes:
// Measured: `318`
// Estimated: `6148`
// Minimum execution time: 54_624_000 picoseconds.
Weight::from_parts(57_578_000, 6148)
// Minimum execution time: 54_382_000 picoseconds.
Weight::from_parts(55_495_000, 6148)
.saturating_add(T::DbWeight::get().reads(5_u64))
.saturating_add(T::DbWeight::get().writes(2_u64))
}
Expand All @@ -240,8 +240,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Proof Size summary in bytes:
// Measured: `1186`
// Estimated: `7126`
// Minimum execution time: 58_180_000 picoseconds.
Weight::from_parts(62_097_000, 7126)
// Minimum execution time: 56_987_000 picoseconds.
Weight::from_parts(58_510_000, 7126)
.saturating_add(T::DbWeight::get().reads(6_u64))
.saturating_add(T::DbWeight::get().writes(1_u64))
}
Expand All @@ -251,8 +251,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Proof Size summary in bytes:
// Measured: `195`
// Estimated: `3464`
// Minimum execution time: 22_513_000 picoseconds.
Weight::from_parts(25_056_000, 3464)
// Minimum execution time: 21_802_000 picoseconds.
Weight::from_parts(22_642_000, 3464)
.saturating_add(T::DbWeight::get().reads(1_u64))
.saturating_add(T::DbWeight::get().writes(1_u64))
}
Expand All @@ -262,8 +262,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Proof Size summary in bytes:
// Measured: `43`
// Estimated: `1484`
// Minimum execution time: 8_005_000 picoseconds.
Weight::from_parts(9_187_000, 1484)
// Minimum execution time: 7_615_000 picoseconds.
Weight::from_parts(7_975_000, 1484)
.saturating_add(T::DbWeight::get().reads(1_u64))
.saturating_add(T::DbWeight::get().writes(1_u64))
}
Expand All @@ -273,8 +273,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Proof Size summary in bytes:
// Measured: `43`
// Estimated: `1484`
// Minimum execution time: 8_326_000 picoseconds.
Weight::from_parts(8_766_000, 1484)
// Minimum execution time: 8_096_000 picoseconds.
Weight::from_parts(8_486_000, 1484)
.saturating_add(T::DbWeight::get().reads(1_u64))
.saturating_add(T::DbWeight::get().writes(1_u64))
}
Expand All @@ -290,8 +290,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Proof Size summary in bytes:
// Measured: `120`
// Estimated: `3820`
// Minimum execution time: 48_932_000 picoseconds.
Weight::from_parts(50_404_000, 3820)
// Minimum execution time: 49_253_000 picoseconds.
Weight::from_parts(50_515_000, 3820)
.saturating_add(T::DbWeight::get().reads(4_u64))
.saturating_add(T::DbWeight::get().writes(2_u64))
}
Expand All @@ -303,8 +303,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Proof Size summary in bytes:
// Measured: `222`
// Estimated: `3820`
// Minimum execution time: 15_409_000 picoseconds.
Weight::from_parts(15_870_000, 3820)
// Minimum execution time: 15_109_000 picoseconds.
Weight::from_parts(15_529_000, 3820)
.saturating_add(T::DbWeight::get().reads(2_u64))
.saturating_add(T::DbWeight::get().writes(1_u64))
}
Expand All @@ -320,8 +320,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Proof Size summary in bytes:
// Measured: `299`
// Estimated: `6650`
// Minimum execution time: 58_402_000 picoseconds.
Weight::from_parts(59_694_000, 6650)
// Minimum execution time: 58_280_000 picoseconds.
Weight::from_parts(60_474_000, 6650)
.saturating_add(T::DbWeight::get().reads(5_u64))
.saturating_add(T::DbWeight::get().writes(3_u64))
}
Expand All @@ -335,8 +335,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Proof Size summary in bytes:
// Measured: `275`
// Estimated: `6650`
// Minimum execution time: 34_966_000 picoseconds.
Weight::from_parts(36_459_000, 6650)
// Minimum execution time: 33_903_000 picoseconds.
Weight::from_parts(34_826_000, 6650)
.saturating_add(T::DbWeight::get().reads(4_u64))
.saturating_add(T::DbWeight::get().writes(2_u64))
}
Expand Down Expand Up @@ -382,8 +382,8 @@ impl WeightInfo for () {
// Proof Size summary in bytes:
// Measured: `1316`
// Estimated: `3569`
// Minimum execution time: 99_137_000 picoseconds.
Weight::from_parts(102_083_000, 3569)
// Minimum execution time: 99_207_000 picoseconds.
Weight::from_parts(100_810_000, 3569)
.saturating_add(RocksDbWeight::get().reads(17_u64))
.saturating_add(RocksDbWeight::get().writes(2_u64))
}
Expand Down Expand Up @@ -467,8 +467,8 @@ impl WeightInfo for () {
// Proof Size summary in bytes:
// Measured: `2633`
// Estimated: `18473`
// Minimum execution time: 234_062_000 picoseconds.
Weight::from_parts(246_625_000, 18473)
// Minimum execution time: 240_284_000 picoseconds.
Weight::from_parts(247_908_000, 18473)
.saturating_add(RocksDbWeight::get().reads(43_u64))
.saturating_add(RocksDbWeight::get().writes(2_u64))
}
Expand All @@ -482,8 +482,8 @@ impl WeightInfo for () {
// Proof Size summary in bytes:
// Measured: `120`
// Estimated: `3569`
// Minimum execution time: 43_492_000 picoseconds.
Weight::from_parts(44_705_000, 3569)
// Minimum execution time: 44_263_000 picoseconds.
Weight::from_parts(45_276_000, 3569)
.saturating_add(RocksDbWeight::get().reads(3_u64))
.saturating_add(RocksDbWeight::get().writes(2_u64))
}
Expand All @@ -497,8 +497,8 @@ impl WeightInfo for () {
// Proof Size summary in bytes:
// Measured: `120`
// Estimated: `3569`
// Minimum execution time: 49_043_000 picoseconds.
Weight::from_parts(52_258_000, 3569)
// Minimum execution time: 49_733_000 picoseconds.
Weight::from_parts(50_996_000, 3569)
.saturating_add(RocksDbWeight::get().reads(3_u64))
.saturating_add(RocksDbWeight::get().writes(2_u64))
}
Expand All @@ -514,8 +514,8 @@ impl WeightInfo for () {
// Proof Size summary in bytes:
// Measured: `318`
// Estimated: `6148`
// Minimum execution time: 54_624_000 picoseconds.
Weight::from_parts(57_578_000, 6148)
// Minimum execution time: 54_382_000 picoseconds.
Weight::from_parts(55_495_000, 6148)
.saturating_add(RocksDbWeight::get().reads(5_u64))
.saturating_add(RocksDbWeight::get().writes(2_u64))
}
Expand All @@ -531,8 +531,8 @@ impl WeightInfo for () {
// Proof Size summary in bytes:
// Measured: `1186`
// Estimated: `7126`
// Minimum execution time: 58_180_000 picoseconds.
Weight::from_parts(62_097_000, 7126)
// Minimum execution time: 56_987_000 picoseconds.
Weight::from_parts(58_510_000, 7126)
.saturating_add(RocksDbWeight::get().reads(6_u64))
.saturating_add(RocksDbWeight::get().writes(1_u64))
}
Expand All @@ -542,8 +542,8 @@ impl WeightInfo for () {
// Proof Size summary in bytes:
// Measured: `195`
// Estimated: `3464`
// Minimum execution time: 22_513_000 picoseconds.
Weight::from_parts(25_056_000, 3464)
// Minimum execution time: 21_802_000 picoseconds.
Weight::from_parts(22_642_000, 3464)
.saturating_add(RocksDbWeight::get().reads(1_u64))
.saturating_add(RocksDbWeight::get().writes(1_u64))
}
Expand All @@ -553,8 +553,8 @@ impl WeightInfo for () {
// Proof Size summary in bytes:
// Measured: `43`
// Estimated: `1484`
// Minimum execution time: 8_005_000 picoseconds.
Weight::from_parts(9_187_000, 1484)
// Minimum execution time: 7_615_000 picoseconds.
Weight::from_parts(7_975_000, 1484)
.saturating_add(RocksDbWeight::get().reads(1_u64))
.saturating_add(RocksDbWeight::get().writes(1_u64))
}
Expand All @@ -564,8 +564,8 @@ impl WeightInfo for () {
// Proof Size summary in bytes:
// Measured: `43`
// Estimated: `1484`
// Minimum execution time: 8_326_000 picoseconds.
Weight::from_parts(8_766_000, 1484)
// Minimum execution time: 8_096_000 picoseconds.
Weight::from_parts(8_486_000, 1484)
.saturating_add(RocksDbWeight::get().reads(1_u64))
.saturating_add(RocksDbWeight::get().writes(1_u64))
}
Expand All @@ -581,8 +581,8 @@ impl WeightInfo for () {
// Proof Size summary in bytes:
// Measured: `120`
// Estimated: `3820`
// Minimum execution time: 48_932_000 picoseconds.
Weight::from_parts(50_404_000, 3820)
// Minimum execution time: 49_253_000 picoseconds.
Weight::from_parts(50_515_000, 3820)
.saturating_add(RocksDbWeight::get().reads(4_u64))
.saturating_add(RocksDbWeight::get().writes(2_u64))
}
Expand All @@ -594,8 +594,8 @@ impl WeightInfo for () {
// Proof Size summary in bytes:
// Measured: `222`
// Estimated: `3820`
// Minimum execution time: 15_409_000 picoseconds.
Weight::from_parts(15_870_000, 3820)
// Minimum execution time: 15_109_000 picoseconds.
Weight::from_parts(15_529_000, 3820)
.saturating_add(RocksDbWeight::get().reads(2_u64))
.saturating_add(RocksDbWeight::get().writes(1_u64))
}
Expand All @@ -611,8 +611,8 @@ impl WeightInfo for () {
// Proof Size summary in bytes:
// Measured: `299`
// Estimated: `6650`
// Minimum execution time: 58_402_000 picoseconds.
Weight::from_parts(59_694_000, 6650)
// Minimum execution time: 58_280_000 picoseconds.
Weight::from_parts(60_474_000, 6650)
.saturating_add(RocksDbWeight::get().reads(5_u64))
.saturating_add(RocksDbWeight::get().writes(3_u64))
}
Expand All @@ -626,8 +626,8 @@ impl WeightInfo for () {
// Proof Size summary in bytes:
// Measured: `275`
// Estimated: `6650`
// Minimum execution time: 34_966_000 picoseconds.
Weight::from_parts(36_459_000, 6650)
// Minimum execution time: 33_903_000 picoseconds.
Weight::from_parts(34_826_000, 6650)
.saturating_add(RocksDbWeight::get().reads(4_u64))
.saturating_add(RocksDbWeight::get().writes(2_u64))
}
Expand Down
24 changes: 24 additions & 0 deletions pallets/subnet_emission/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,28 @@ benchmarks! {
let hash = vec![10u8];
MinValidatorStake::<T>::set(netuid, 0);
}: set_weights_encrypted(RawOrigin::Signed(module_key2), netuid, weights, hash)

delegate_weight_control {
let module_key: T::AccountId = account("ModuleKey", 0, 2);
let module_key2: T::AccountId = account("ModuleKey2", 0, 3);

register_mock::<T>(module_key.clone(), module_key.clone(), "test".as_bytes().to_vec())?;
register_mock::<T>(module_key2.clone(), module_key2.clone(), "test1".as_bytes().to_vec())?;
let netuid = SubspaceMod::<T>::get_netuid_for_name("testnet".as_bytes()).unwrap();

}: delegate_weight_control(RawOrigin::Signed(module_key), netuid, module_key2.clone())

remove_weight_control {
// we first delegate
let module_key: T::AccountId = account("ModuleKey", 0, 2);
let module_key2: T::AccountId = account("ModuleKey2", 0, 3);

register_mock::<T>(module_key.clone(), module_key.clone(), "test".as_bytes().to_vec())?;
register_mock::<T>(module_key2.clone(), module_key2.clone(), "test1".as_bytes().to_vec())?;

let netuid = SubspaceMod::<T>::get_netuid_for_name("testnet".as_bytes()).unwrap();

let _ = Pallet::<T>::delegate_weight_control(RawOrigin::Signed(module_key.clone()).into(), netuid, module_key2.clone());

}: remove_weight_control(RawOrigin::Signed(module_key), netuid)
}
12 changes: 7 additions & 5 deletions pallets/subnet_emission/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ pub mod pallet {
use pallet_subnet_emission_api::SubnetConsensus;
use pallet_subspace::{define_module_includes, define_subnet_includes, TotalStake};
use subnet_pricing::root::RootPricing;
pub use crate::weights::WeightInfo;

#[cfg(feature = "testnet")]
const STORAGE_VERSION: StorageVersion = StorageVersion::new(16);
Expand Down Expand Up @@ -104,6 +105,8 @@ pub mod pallet {
/// node. So the final count is `MaxEncryptionPeriod + EncryptionPeriodBuffer`
#[pallet::constant]
type EncryptionPeriodBuffer: Get<u64>;

type WeightInfo: WeightInfo;
}

type BalanceOf<T> =
Expand Down Expand Up @@ -389,12 +392,11 @@ pub mod pallet {
}
}

// TODO:
// add benchmarks
#[pallet::call]
impl<T: Config> Pallet<T> {
#[pallet::call_index(0)]
#[pallet::weight((0, DispatchClass::Normal, Pays::No))]
#[pallet::weight((<T as pallet::Config>::WeightInfo::set_weights(), DispatchClass::Normal, Pays::No))]
pub fn set_weights(
origin: OriginFor<T>,
netuid: u16,
Expand All @@ -405,7 +407,7 @@ pub mod pallet {
}

#[pallet::call_index(1)]
#[pallet::weight((0, DispatchClass::Normal, Pays::No))]
#[pallet::weight((<T as pallet::Config>::WeightInfo::set_weights_encrypted(), DispatchClass::Normal, Pays::No))]
pub fn set_weights_encrypted(
origin: OriginFor<T>,
netuid: u16,
Expand All @@ -422,7 +424,7 @@ pub mod pallet {
}

#[pallet::call_index(2)]
#[pallet::weight((0, DispatchClass::Normal, Pays::No))]
#[pallet::weight((<T as pallet::Config>::WeightInfo::set_weights_encrypted(), DispatchClass::Normal, Pays::No))]
pub fn delegate_weight_control(
origin: OriginFor<T>,
netuid: u16,
Expand All @@ -432,7 +434,7 @@ pub mod pallet {
}

#[pallet::call_index(3)]
#[pallet::weight((0, DispatchClass::Normal, Pays::No))]
#[pallet::weight((<T as pallet::Config>::WeightInfo::set_weights_encrypted(), DispatchClass::Normal, Pays::No))]
pub fn remove_weight_control(origin: OriginFor<T>, netuid: u16) -> DispatchResult {
Self::do_remove_weight_control(origin, netuid)
}
Expand Down
Loading

0 comments on commit 755f787

Please sign in to comment.