Skip to content

Commit 18379a4

Browse files
authored
Merge pull request #1757 from opentensor/hotfix-cooldown
cooldown
2 parents 0e9f293 + 73094c9 commit 18379a4

File tree

5 files changed

+34
-11
lines changed

5 files changed

+34
-11
lines changed

pallets/subtensor/src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1715,6 +1715,17 @@ pub mod pallet {
17151715
#[pallet::storage] // --- Storage for migration run status
17161716
pub type HasMigrationRun<T: Config> = StorageMap<_, Identity, Vec<u8>, bool, ValueQuery>;
17171717

1718+
#[pallet::type_value]
1719+
/// Default value for pending childkey cooldown (settable by root, default 0)
1720+
pub fn DefaultPendingChildKeyCooldown<T: Config>() -> u64 {
1721+
0
1722+
}
1723+
1724+
#[pallet::storage]
1725+
/// Storage value for pending childkey cooldown, settable by root.
1726+
pub type PendingChildKeyCooldown<T: Config> =
1727+
StorageValue<_, u64, ValueQuery, DefaultPendingChildKeyCooldown<T>>;
1728+
17181729
#[pallet::genesis_config]
17191730
pub struct GenesisConfig<T: Config> {
17201731
/// Stakes record in genesis.

pallets/subtensor/src/macros/dispatches.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1786,7 +1786,7 @@ mod dispatches {
17861786
///
17871787
#[pallet::call_index(88)]
17881788
#[pallet::weight((Weight::from_parts(159_200_000, 0)
1789-
.saturating_add(T::DbWeight::get().reads(13))
1789+
.saturating_add(T::DbWeight::get().reads(14))
17901790
.saturating_add(T::DbWeight::get().writes(10)), DispatchClass::Normal, Pays::No))]
17911791
pub fn add_stake_limit(
17921792
origin: OriginFor<T>,
@@ -2057,6 +2057,18 @@ mod dispatches {
20572057
Self::do_burn_alpha(origin, hotkey, amount, netuid)
20582058
}
20592059

2060+
/// Sets the pending childkey cooldown (in blocks). Root only.
2061+
#[pallet::call_index(109)]
2062+
#[pallet::weight((Weight::from_parts(10_000, 0), DispatchClass::Operational, Pays::No))]
2063+
pub fn set_pending_childkey_cooldown(
2064+
origin: OriginFor<T>,
2065+
cooldown: u64,
2066+
) -> DispatchResult {
2067+
ensure_root(origin)?;
2068+
PendingChildKeyCooldown::<T>::put(cooldown);
2069+
Ok(())
2070+
}
2071+
20602072
// /// --- Adds stake to a hotkey on a subnet with a price limit.
20612073
// /// This extrinsic allows to specify the limit price for alpha token
20622074
// /// at which or better (lower) the staking should execute.

pallets/subtensor/src/staking/set_children.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 do_set_child_singular: Sets a single child.
@@ -123,7 +122,7 @@ impl<T: Config> Pallet<T> {
123122

124123
// Calculate cool-down block
125124
let cooldown_block =
126-
Self::get_current_block_as_u64().saturating_add(DefaultPendingCooldown::<T>::get());
125+
Self::get_current_block_as_u64().saturating_add(PendingChildKeyCooldown::<T>::get());
127126

128127
// Insert or update PendingChildKeys
129128
PendingChildKeys::<T>::insert(netuid, hotkey.clone(), (children.clone(), cooldown_block));

pallets/subtensor/src/tests/children.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3949,14 +3949,14 @@ fn test_dividend_distribution_with_children_same_coldkey_owner() {
39493949
}
39503950

39513951
#[test]
3952-
fn test_pending_cooldown_one_day() {
3952+
fn test_pending_cooldown_as_expected() {
39533953
let curr_block = 1;
3954-
3955-
let expected_cooldown = if cfg!(feature = "fast-blocks") {
3956-
15
3957-
} else {
3958-
7_200
3959-
};
3954+
// TODO: Fix when CHK splitting patched
3955+
// let expected_cooldown = if cfg!(feature = "fast-blocks") {
3956+
// 15
3957+
// } else {
3958+
// 7200
3959+
// };
39603960

39613961
new_test_ext(curr_block).execute_with(|| {
39623962
let coldkey = U256::from(1);
@@ -3966,6 +3966,7 @@ fn test_pending_cooldown_one_day() {
39663966
let netuid: u16 = 1;
39673967
let proportion1: u64 = 1000;
39683968
let proportion2: u64 = 2000;
3969+
let expected_cooldown = PendingChildKeyCooldown::<Test>::get();
39693970

39703971
// Add network and register hotkey
39713972
add_network(netuid, 13, 0);

runtime/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
209209
// `spec_version`, and `authoring_version` are the same between Wasm and native.
210210
// This value is set to 100 to notify Polkadot-JS App (https://polkadot.js.org/apps) to use
211211
// the compatible custom types.
212-
spec_version: 276,
212+
spec_version: 277,
213213
impl_version: 1,
214214
apis: RUNTIME_API_VERSIONS,
215215
transaction_version: 1,

0 commit comments

Comments
 (0)