Skip to content

Commit b4d41d0

Browse files
committed
Add ChildkeysMinStake, fix clippy, fix tests
1 parent d001c99 commit b4d41d0

File tree

5 files changed

+14
-12
lines changed

5 files changed

+14
-12
lines changed

pallets/subtensor/src/lib.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -686,9 +686,9 @@ pub mod pallet {
686686
}
687687

688688
#[pallet::type_value]
689-
/// Default value for minimum stake.
690-
pub fn DefaultMinStake<T: Config>() -> u64 {
691-
1_000_000_000
689+
/// Default minimum stake for setting childkeys.
690+
pub fn DefaultChildkeysMinStake<T: Config>() -> u64 {
691+
1_000_000_000_000
692692
}
693693

694694
#[pallet::storage]
@@ -1298,6 +1298,9 @@ pub mod pallet {
12981298
/// ITEM( weights_min_stake )
12991299
pub type WeightsMinStake<T> = StorageValue<_, u64, ValueQuery, DefaultWeightsMinStake<T>>;
13001300
#[pallet::storage]
1301+
/// ITEM( childkeys_min_stake )
1302+
pub type ChildkeysMinStake<T> = StorageValue<_, u64, ValueQuery, DefaultChildkeysMinStake<T>>;
1303+
#[pallet::storage]
13011304
/// --- MAP (netuid, who) --> VecDeque<(hash, commit_block, first_reveal_block, last_reveal_block)> | Stores a queue of commits for an account on a given netuid.
13021305
pub type WeightCommits<T: Config> = StorageDoubleMap<
13031306
_,

pallets/subtensor/src/staking/remove_stake.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use super::*;
2-
use sp_core::Get;
32

43
impl<T: Config> Pallet<T> {
54
/// ---- The implementation for the extrinsic remove_stake: Removes stake from a hotkey account and adds it onto a coldkey.
@@ -92,7 +91,7 @@ impl<T: Config> Pallet<T> {
9291
Self::clear_small_nomination_if_required(&hotkey, &coldkey, new_stake);
9392

9493
// Check if stake lowered below MinStake and remove Pending children if it did
95-
if Self::get_total_stake_for_hotkey(&hotkey) < DefaultMinStake::<T>::get() {
94+
if Self::get_total_stake_for_hotkey(&hotkey) < ChildkeysMinStake::<T>::get() {
9695
Self::get_all_subnet_netuids().iter().for_each(|netuid| {
9796
PendingChildKeys::<T>::remove(netuid, &hotkey);
9897
})

pallets/subtensor/src/staking/set_children.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ impl<T: Config> Pallet<T> {
113113
// (checking with check_weights_min_stake wouldn't work because it considers
114114
// grandparent stake in this case)
115115
ensure!(
116-
Self::get_total_stake_for_hotkey(&hotkey) >= DefaultMinStake::<T>::get(),
116+
Self::get_total_stake_for_hotkey(&hotkey) >= ChildkeysMinStake::<T>::get(),
117117
Error::<T>::NotEnoughStakeToSetChildkeys
118118
);
119119

pallets/subtensor/src/tests/children.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use super::mock::*;
33
use frame_support::{assert_err, assert_noop, assert_ok};
44

55
use crate::{utils::rate_limiting::TransactionType, *};
6-
use sp_core::{Get, U256};
6+
use sp_core::U256;
77

88
// 1: Successful setting of a single child
99
// SKIP_WASM_BUILD=1 RUST_LOG=info cargo test --test children -- test_do_set_child_singular_success --exact --nocapture
@@ -3674,7 +3674,7 @@ fn test_do_remove_stake_clears_pending_childkeys() {
36743674
SubtensorModule::increase_stake_on_coldkey_hotkey_account(
36753675
&coldkey,
36763676
&hotkey,
3677-
100_000_000_000,
3677+
ChildkeysMinStake::<Test>::get(),
36783678
);
36793679

36803680
// Attempt to set child
@@ -3687,7 +3687,7 @@ fn test_do_remove_stake_clears_pending_childkeys() {
36873687

36883688
// Check that pending child exists
36893689
let pending_before = PendingChildKeys::<Test>::get(netuid, hotkey);
3690-
assert!(pending_before.0.len() > 0);
3690+
assert!(!pending_before.0.is_empty());
36913691
assert!(pending_before.1 > 0);
36923692

36933693
// Remove stake
@@ -3720,7 +3720,7 @@ fn test_do_set_child_cooldown_period() {
37203720

37213721
// Set minimum stake for setting children
37223722
let parent_total_stake_original = TotalHotkeyStake::<Test>::get(parent);
3723-
TotalHotkeyStake::<Test>::insert(parent, DefaultMinStake::<Test>::get());
3723+
TotalHotkeyStake::<Test>::insert(parent, ChildkeysMinStake::<Test>::get());
37243724

37253725
// Schedule parent-child relationship
37263726
assert_ok!(SubtensorModule::do_schedule_children(

pallets/subtensor/src/tests/mock.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ impl CanVote<AccountId> for CanVoteToTriumvirate {
208208
}
209209
}
210210

211-
use crate::{CollectiveInterface, DefaultMinStake, MemberManagement, TotalHotkeyStake};
211+
use crate::{ChildkeysMinStake, CollectiveInterface, MemberManagement, TotalHotkeyStake};
212212
pub struct ManageSenateMembers;
213213
impl MemberManagement<AccountId> for ManageSenateMembers {
214214
fn add_member(account: &AccountId) -> DispatchResultWithPostInfo {
@@ -615,7 +615,7 @@ pub fn wait_and_set_pending_children(netuid: u16) {
615615
pub fn mock_set_children(coldkey: &U256, parent: &U256, netuid: u16, child_vec: &[(u64, U256)]) {
616616
// Set minimum stake for setting children
617617
let parent_total_stake_original = TotalHotkeyStake::<Test>::get(parent);
618-
TotalHotkeyStake::<Test>::insert(parent, DefaultMinStake::<Test>::get());
618+
TotalHotkeyStake::<Test>::insert(parent, ChildkeysMinStake::<Test>::get());
619619

620620
// Set initial parent-child relationship
621621
assert_ok!(SubtensorModule::do_schedule_children(

0 commit comments

Comments
 (0)