Skip to content

Commit 2ea077b

Browse files
author
Samuel Dare
committed
feat: benchmark adjust senate
1 parent 81ed321 commit 2ea077b

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

pallets/subtensor/src/benchmarks.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ benchmarks! {
8080
// This is a whitelisted caller who can make transaction without weights.
8181
let caller: T::AccountId = whitelisted_caller::<AccountIdOf<T>>();
8282
let caller_origin = <T as frame_system::Config>::RuntimeOrigin::from(RawOrigin::Signed(caller.clone()));
83-
let netuid: u16 = 1;
83+
let netuid: u16 = 0;
8484
let version_key: u64 = 1;
8585
let tempo: u16 = 1;
8686
let modality: u16 = 0;
@@ -428,4 +428,29 @@ reveal_weights {
428428
let _ = Subtensor::<T>::commit_weights(<T as frame_system::Config>::RuntimeOrigin::from(RawOrigin::Signed(hotkey.clone())), netuid, commit_hash);
429429

430430
}: reveal_weights(RawOrigin::Signed(hotkey.clone()), netuid, uids, weight_values, salt, version_key)
431+
432+
433+
adjust_senate {
434+
migration::migrate_create_root_network::<T>();
435+
let netuid: u16 = 1;
436+
let tempo: u16 = 13;
437+
let burn_cost = 1000;
438+
let hotkey: T::AccountId = account("hot", 0, 1);
439+
let coldkey: T::AccountId = account("cold", 0, 2);
440+
441+
Subtensor::<T>::init_new_network(netuid, 100);
442+
Subtensor::<T>::set_burn(netuid, 1);
443+
Subtensor::<T>::set_max_allowed_uids( netuid, 4096 );
444+
assert_eq!(Subtensor::<T>::get_max_allowed_uids(netuid), 4096);
445+
Subtensor::<T>::set_burn(netuid, burn_cost);
446+
447+
let amount_to_be_staked = 100_000_000_000;
448+
Subtensor::<T>::add_balance_to_coldkey_account(&coldkey.clone(), amount_to_be_staked);
449+
450+
assert_ok!(Subtensor::<T>::burned_register(RawOrigin::Signed(coldkey.clone()).into(), netuid, hotkey.clone()));
451+
assert_ok!(Subtensor::<T>::become_delegate(RawOrigin::Signed(coldkey.clone()).into(), hotkey.clone()));
452+
assert_ok!(Subtensor::<T>::root_register(RawOrigin::Signed(coldkey.clone()).into(), hotkey.clone()));
453+
T::SenateMembers::remove_member(&hotkey).map_err(|_| "Failed to remove member")?;
454+
455+
}: adjust_senate(RawOrigin::Signed(coldkey.clone()), hotkey.clone())
431456
}

pallets/subtensor/src/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1950,9 +1950,10 @@ pub mod pallet {
19501950

19511951
/// Attempt to adjust the senate membership to include a hotkey
19521952
#[pallet::call_index(63)]
1953-
#[pallet::weight((Weight::from_parts(0, 0)
1954-
.saturating_add(T::DbWeight::get().reads(0))
1955-
.saturating_add(T::DbWeight::get().writes(0)), DispatchClass::Normal, Pays::Yes))]
1953+
#[pallet::weight((Weight::from_parts(50_000_000, 0)
1954+
.saturating_add(Weight::from_parts(0, 4632))
1955+
.saturating_add(T::DbWeight::get().reads(5))
1956+
.saturating_add(T::DbWeight::get().writes(1)), DispatchClass::Normal, Pays::Yes))]
19561957
pub fn adjust_senate(origin: OriginFor<T>, hotkey: T::AccountId) -> DispatchResult {
19571958
Self::do_adjust_senate(origin, hotkey)
19581959
}

scripts/benchmark.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ $BIN_PATH build-spec --disable-default-bootnode --raw --chain local > $TMP_SPEC
4343
$BIN_PATH benchmark pallet \
4444
--chain=$TMP_SPEC \
4545
--execution=native --wasm-execution=compiled \
46-
--pallet pallet-subtensor --extrinsic 'benchmark_dissolve_network' \
46+
--pallet pallet-subtensor --extrinsic 'adjust_senate' \
4747
--output $OUTPUT_FILE
4848

4949
rm $TMP_SPEC

0 commit comments

Comments
 (0)