Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions chain-extensions/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,7 @@ parameter_types! {
pub const InitialAlphaLow: u16 = 45875; // Represents 0.7 as per the production default
pub const InitialLiquidAlphaOn: bool = false; // Default value for LiquidAlphaOn
pub const InitialYuma3On: bool = false; // Default value for Yuma3On
// pub const InitialNetworkMaxStake: u64 = u64::MAX; // (DEPRECATED)
pub const InitialColdkeySwapScheduleDuration: u64 = 5 * 24 * 60 * 60 / 12; // Default as 5 days
pub const InitialColdkeySwapRescheduleDuration: u64 = 24 * 60 * 60 / 12; // Default as 1 day
pub const InitialColdKeySwapAnnouncementDelay: u64 = 5 * 24 * 60 * 60 / 12; // Default as 5 days
pub const InitialDissolveNetworkScheduleDuration: u64 = 5 * 24 * 60 * 60 / 12; // Default as 5 days
pub const InitialTaoWeight: u64 = 0; // 100% global weight.
pub const InitialEmaPriceHalvingPeriod: u64 = 201_600_u64; // 4 weeks
Expand Down Expand Up @@ -397,8 +395,7 @@ impl pallet_subtensor::Config for Test {
type LiquidAlphaOn = InitialLiquidAlphaOn;
type Yuma3On = InitialYuma3On;
type Preimages = Preimage;
type InitialColdkeySwapScheduleDuration = InitialColdkeySwapScheduleDuration;
type InitialColdkeySwapRescheduleDuration = InitialColdkeySwapRescheduleDuration;
type InitialColdkeySwapAnnouncementDelay = InitialColdkeySwapAnnouncementDelay;
type InitialDissolveNetworkScheduleDuration = InitialDissolveNetworkScheduleDuration;
type InitialTaoWeight = InitialTaoWeight;
type InitialEmaPriceHalvingPeriod = InitialEmaPriceHalvingPeriod;
Expand Down
2 changes: 1 addition & 1 deletion pallets/admin-utils/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ mod benchmarks {
}

#[benchmark]
fn sudo_set_coldkey_swap_schedule_duration() {
fn sudo_set_coldkey_swap_announcement_delay() {
#[extrinsic_call]
_(RawOrigin::Root, 100u32.into());
}
Expand Down
57 changes: 19 additions & 38 deletions pallets/admin-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1348,44 +1348,6 @@ pub mod pallet {
res
}

/// Sets the duration of the coldkey swap schedule.
///
/// This extrinsic allows the root account to set the duration for the coldkey swap schedule.
/// The coldkey swap schedule determines how long it takes for a coldkey swap operation to complete.
///
/// # Arguments
/// * `origin` - The origin of the call, which must be the root account.
/// * `duration` - The new duration for the coldkey swap schedule, in number of blocks.
///
/// # Errors
/// * `BadOrigin` - If the caller is not the root account.
///
/// # Weight
/// Weight is handled by the `#[pallet::weight]` attribute.
#[pallet::call_index(54)]
#[pallet::weight((
Weight::from_parts(5_000_000, 0)
.saturating_add(T::DbWeight::get().reads(0_u64))
.saturating_add(T::DbWeight::get().writes(1_u64)),
DispatchClass::Operational,
Pays::Yes
))]
pub fn sudo_set_coldkey_swap_schedule_duration(
origin: OriginFor<T>,
duration: BlockNumberFor<T>,
) -> DispatchResult {
// Ensure the call is made by the root account
ensure_root(origin)?;

// Set the new duration of schedule coldkey swap
pallet_subtensor::Pallet::<T>::set_coldkey_swap_schedule_duration(duration);

// Log the change
log::trace!("ColdkeySwapScheduleDurationSet( duration: {duration:?} )");

Ok(())
}

/// Sets the duration of the dissolve network schedule.
///
/// This extrinsic allows the root account to set the duration for the dissolve network schedule.
Expand Down Expand Up @@ -2213,6 +2175,25 @@ pub mod pallet {
log::debug!("set_tao_flow_smoothing_factor( {smoothing_factor:?} ) ");
Ok(())
}

/// Sets the announcement delay for coldkey swap.
#[pallet::call_index(84)]
#[pallet::weight((
Weight::from_parts(5_000_000, 0)
.saturating_add(T::DbWeight::get().reads(0_u64))
.saturating_add(T::DbWeight::get().writes(1_u64)),
DispatchClass::Operational,
Pays::Yes
))]
pub fn sudo_set_coldkey_swap_announcement_delay(
origin: OriginFor<T>,
duration: BlockNumberFor<T>,
) -> DispatchResult {
ensure_root(origin)?;
pallet_subtensor::Pallet::<T>::set_coldkey_swap_announcement_delay(duration);
log::trace!("ColdkeySwapScheduleDurationSet( duration: {duration:?} )");
Ok(())
}
}
}

Expand Down
9 changes: 2 additions & 7 deletions pallets/admin-utils/src/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,13 @@ parameter_types! {
pub const InitialNetworkMinLockCost: u64 = 100_000_000_000;
pub const InitialSubnetOwnerCut: u16 = 0; // 0%. 100% of rewards go to validators + miners.
pub const InitialNetworkLockReductionInterval: u64 = 2; // 2 blocks.
// pub const InitialSubnetLimit: u16 = 10; // (DEPRECATED)
pub const InitialNetworkRateLimit: u64 = 0;
pub const InitialKeySwapCost: u64 = 1_000_000_000;
pub const InitialAlphaHigh: u16 = 58982; // Represents 0.9 as per the production default
pub const InitialAlphaLow: u16 = 45875; // Represents 0.7 as per the production default
pub const InitialLiquidAlphaOn: bool = false; // Default value for LiquidAlphaOn
pub const InitialYuma3On: bool = false; // Default value for Yuma3On
// pub const InitialHotkeyEmissionTempo: u64 = 1; // (DEPRECATED)
// pub const InitialNetworkMaxStake: u64 = u64::MAX; // (DEPRECATED)
pub const InitialColdkeySwapScheduleDuration: u64 = 5 * 24 * 60 * 60 / 12; // 5 days
pub const InitialColdkeySwapRescheduleDuration: u64 = 24 * 60 * 60 / 12; // 1 day
pub const InitialColdkeySwapAnnouncementDelay: u64 = 5 * 24 * 60 * 60 / 12; // 5 days
pub const InitialDissolveNetworkScheduleDuration: u64 = 5 * 24 * 60 * 60 / 12; // 5 days
pub const InitialTaoWeight: u64 = u64::MAX/10; // 10% global weight.
pub const InitialEmaPriceHalvingPeriod: u64 = 201_600_u64; // 4 weeks
Expand Down Expand Up @@ -210,8 +206,7 @@ impl pallet_subtensor::Config for Test {
type LiquidAlphaOn = InitialLiquidAlphaOn;
type Yuma3On = InitialYuma3On;
type Preimages = ();
type InitialColdkeySwapScheduleDuration = InitialColdkeySwapScheduleDuration;
type InitialColdkeySwapRescheduleDuration = InitialColdkeySwapRescheduleDuration;
type InitialColdkeySwapAnnouncementDelay = InitialColdkeySwapAnnouncementDelay;
type InitialDissolveNetworkScheduleDuration = InitialDissolveNetworkScheduleDuration;
type InitialTaoWeight = InitialTaoWeight;
type InitialEmaPriceHalvingPeriod = InitialEmaPriceHalvingPeriod;
Expand Down
8 changes: 4 additions & 4 deletions pallets/admin-utils/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1382,7 +1382,7 @@ fn test_sudo_get_set_alpha() {
}

#[test]
fn test_sudo_set_coldkey_swap_schedule_duration() {
fn test_sudo_set_coldkey_swap_announcement_delay() {
new_test_ext().execute_with(|| {
// Arrange
let root = RuntimeOrigin::root();
Expand All @@ -1391,12 +1391,12 @@ fn test_sudo_set_coldkey_swap_schedule_duration() {

// Act & Assert: Non-root account should fail
assert_noop!(
AdminUtils::sudo_set_coldkey_swap_schedule_duration(non_root, new_duration),
AdminUtils::sudo_set_coldkey_swap_announcement_delay(non_root, new_duration),
DispatchError::BadOrigin
);

// Act: Root account should succeed
assert_ok!(AdminUtils::sudo_set_coldkey_swap_schedule_duration(
assert_ok!(AdminUtils::sudo_set_coldkey_swap_announcement_delay(
root.clone(),
new_duration
));
Expand All @@ -1408,7 +1408,7 @@ fn test_sudo_set_coldkey_swap_schedule_duration() {
);

// Act & Assert: Setting the same value again should succeed (idempotent operation)
assert_ok!(AdminUtils::sudo_set_coldkey_swap_schedule_duration(
assert_ok!(AdminUtils::sudo_set_coldkey_swap_announcement_delay(
root,
new_duration
));
Expand Down
55 changes: 15 additions & 40 deletions pallets/subtensor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -943,17 +943,11 @@ pub mod pallet {
pub fn DefaultAlphaValues<T: Config>() -> (u16, u16) {
(45875, 58982)
}

/// Default value for coldkey swap schedule duration
/// Default value for coldkey swap announcement delay.
#[pallet::type_value]
pub fn DefaultColdkeySwapScheduleDuration<T: Config>() -> BlockNumberFor<T> {
T::InitialColdkeySwapScheduleDuration::get()
}

/// Default value for coldkey swap reschedule duration
#[pallet::type_value]
pub fn DefaultColdkeySwapRescheduleDuration<T: Config>() -> BlockNumberFor<T> {
T::InitialColdkeySwapRescheduleDuration::get()
pub fn DefaultColdkeySwapAnnouncementDelay<T: Config>() -> BlockNumberFor<T> {
T::InitialColdkeySwapAnnouncementDelay::get()
}

/// Default value for applying pending items (e.g. childkeys).
Expand Down Expand Up @@ -1012,15 +1006,6 @@ pub mod pallet {
360
}

/// Default value for coldkey swap scheduled
#[pallet::type_value]
pub fn DefaultColdkeySwapScheduled<T: Config>() -> (BlockNumberFor<T>, T::AccountId) {
#[allow(clippy::expect_used)]
let default_account = T::AccountId::decode(&mut TrailingZeroInput::zeroes())
.expect("trailing zeroes always produce a valid account ID; qed");
(BlockNumberFor::<T>::from(0_u32), default_account)
}

/// Default value for setting subnet owner hotkey rate limit
#[pallet::type_value]
pub fn DefaultSetSNOwnerHotkeyRateLimit<T: Config>() -> u64 {
Expand Down Expand Up @@ -1072,16 +1057,6 @@ pub mod pallet {
pub type OwnerHyperparamRateLimit<T: Config> =
StorageValue<_, u16, ValueQuery, DefaultOwnerHyperparamRateLimit<T>>;

/// Duration of coldkey swap schedule before execution
#[pallet::storage]
pub type ColdkeySwapScheduleDuration<T: Config> =
StorageValue<_, BlockNumberFor<T>, ValueQuery, DefaultColdkeySwapScheduleDuration<T>>;

/// Duration of coldkey swap reschedule before execution
#[pallet::storage]
pub type ColdkeySwapRescheduleDuration<T: Config> =
StorageValue<_, BlockNumberFor<T>, ValueQuery, DefaultColdkeySwapRescheduleDuration<T>>;

/// Duration of dissolve network schedule before execution
#[pallet::storage]
pub type DissolveNetworkScheduleDuration<T: Config> =
Expand Down Expand Up @@ -1358,16 +1333,16 @@ pub mod pallet {
ValueQuery,
>;

/// --- DMAP ( cold ) --> (block_expected, new_coldkey), Maps coldkey to the block to swap at and new coldkey.
/// The delay after an announcement before a coldkey swap can be performed.
#[pallet::storage]
pub type ColdkeySwapScheduled<T: Config> = StorageMap<
_,
Blake2_128Concat,
T::AccountId,
(BlockNumberFor<T>, T::AccountId),
ValueQuery,
DefaultColdkeySwapScheduled<T>,
>;
pub type ColdkeySwapAnnouncementDelay<T: Config> =
StorageValue<_, BlockNumberFor<T>, ValueQuery, DefaultColdkeySwapAnnouncementDelay<T>>;

/// A map of the coldkey swap announcements from a coldkey
/// to the block number the announcement was made and the new coldkey.
#[pallet::storage]
pub type ColdkeySwapAnnouncements<T: Config> =
StorageMap<_, Twox64Concat, T::AccountId, (BlockNumberFor<T>, T::Hash), OptionQuery>;

/// --- DMAP ( hot, netuid ) --> alpha | Returns the total amount of alpha a hotkey owns.
#[pallet::storage]
Expand Down Expand Up @@ -2427,7 +2402,7 @@ pub mod pallet {

#[derive(Debug, PartialEq)]
pub enum CustomTransactionError {
ColdkeyInSwapSchedule,
ColdkeySwapAnnounced,
StakeAmountTooLow,
BalanceTooLow,
SubnetNotExists,
Expand All @@ -2454,7 +2429,7 @@ pub enum CustomTransactionError {
impl From<CustomTransactionError> for u8 {
fn from(variant: CustomTransactionError) -> u8 {
match variant {
CustomTransactionError::ColdkeyInSwapSchedule => 0,
CustomTransactionError::ColdkeySwapAnnounced => 0,
CustomTransactionError::StakeAmountTooLow => 1,
CustomTransactionError::BalanceTooLow => 2,
CustomTransactionError::SubnetNotExists => 3,
Expand Down
5 changes: 1 addition & 4 deletions pallets/subtensor/src/macros/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,7 @@ mod config {
// type InitialHotkeyEmissionTempo: Get<u64>;
/// Coldkey swap schedule duartion.
#[pallet::constant]
type InitialColdkeySwapScheduleDuration: Get<BlockNumberFor<Self>>;
/// Coldkey swap reschedule duration.
#[pallet::constant]
type InitialColdkeySwapRescheduleDuration: Get<BlockNumberFor<Self>>;
type InitialColdkeySwapAnnouncementDelay: Get<BlockNumberFor<Self>>;
/// Dissolve network schedule duration
#[pallet::constant]
type InitialDissolveNetworkScheduleDuration: Get<BlockNumberFor<Self>>;
Expand Down
Loading