Skip to content
Merged
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
2 changes: 1 addition & 1 deletion pallets/subtensor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ rand_chacha.workspace = true
pallet-crowdloan.workspace = true
pallet-subtensor-proxy.workspace = true
pallet-shield.workspace = true
pallet-scheduler.workspace = true

[dev-dependencies]
pallet-balances = { workspace = true, features = ["std"] }
pallet-scheduler.workspace = true
pallet-subtensor-proxy.workspace = true
pallet-aura.workspace = true
pallet-timestamp.workspace = true
Expand Down
18 changes: 17 additions & 1 deletion pallets/subtensor/src/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,21 @@ mod pallet_benchmarks {
_(RawOrigin::Signed(coldkey));
}

#[benchmark]
fn clear_coldkey_swap_announcement() {
let coldkey: T::AccountId = account("coldkey", 0, 0);
let new_coldkey: T::AccountId = account("new_coldkey", 0, 0);
let new_coldkey_hash: T::Hash = <T as frame_system::Config>::Hashing::hash_of(&new_coldkey);
let now = frame_system::Pallet::<T>::block_number();
let delay = ColdkeySwapReannouncementDelay::<T>::get();

ColdkeySwapAnnouncements::<T>::insert(&coldkey, (now, new_coldkey_hash));
frame_system::Pallet::<T>::set_block_number(now + delay);

#[extrinsic_call]
_(RawOrigin::Signed(coldkey));
}

#[benchmark]
fn reset_coldkey_swap() {
let coldkey: T::AccountId = account("old_coldkey", 0, 0);
Expand Down Expand Up @@ -582,7 +597,8 @@ mod pallet_benchmarks {
let block_number: u64 = Subtensor::<T>::get_current_block_as_u64();
let (nonce, work) =
Subtensor::<T>::create_work_for_block_number(netuid, block_number, 3, &hotkey);
let origin = T::RuntimeOrigin::from(RawOrigin::Signed(hotkey.clone()));
let origin =
<T as frame_system::Config>::RuntimeOrigin::from(RawOrigin::Signed(hotkey.clone()));
assert_ok!(Subtensor::<T>::register(
origin.clone(),
netuid,
Expand Down
2 changes: 1 addition & 1 deletion pallets/subtensor/src/coinbase/reveal_commits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ impl<T: Config> Pallet<T> {
// Apply weights
// ------------------------------------------------------------------
if let Err(e) = Self::do_set_mechanism_weights(
T::RuntimeOrigin::signed(who.clone()),
OriginFor::<T>::signed(who.clone()),
netuid,
MechId::from(mecid),
uids,
Expand Down
2 changes: 1 addition & 1 deletion pallets/subtensor/src/coinbase/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl<T: Config> Pallet<T> {
/// # Returns:
/// * 'DispatchResult': A result type indicating success or failure of the registration.
///
pub fn do_root_register(origin: T::RuntimeOrigin, hotkey: T::AccountId) -> DispatchResult {
pub fn do_root_register(origin: OriginFor<T>, hotkey: T::AccountId) -> DispatchResult {
// --- 0. Get the unique identifier (UID) for the root network.
let current_block_number: u64 = Self::get_current_block_as_u64();
ensure!(
Expand Down
2 changes: 1 addition & 1 deletion pallets/subtensor/src/epoch/run_epoch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1508,7 +1508,7 @@ impl<T: Config> Pallet<T> {
}

pub fn do_set_alpha_values(
origin: T::RuntimeOrigin,
origin: OriginFor<T>,
netuid: NetUid,
alpha_low: u16,
alpha_high: u16,
Expand Down
1 change: 1 addition & 0 deletions pallets/subtensor/src/guards/check_coldkey_swap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ where
Call::announce_coldkey_swap { .. }
| Call::swap_coldkey_announced { .. }
| Call::dispute_coldkey_swap { .. }
| Call::clear_coldkey_swap_announcement { .. }
)
);

Expand Down
2 changes: 2 additions & 0 deletions pallets/subtensor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ pub(crate) mod tests;
// apparently this is stabilized since rust 1.36
extern crate alloc;

pub type OriginFor<T> = <T as frame_system::Config>::RuntimeOrigin;

pub const MAX_CRV3_COMMIT_SIZE_BYTES: u32 = 5000;

pub const ALPHA_MAP_BATCH_SIZE: usize = 30;
Expand Down
9 changes: 6 additions & 3 deletions pallets/subtensor/src/macros/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,21 @@ mod config {
/// Configure the pallet by specifying the parameters and types on which it depends.
#[pallet::config]
pub trait Config:
frame_system::Config + pallet_drand::Config + pallet_crowdloan::Config
frame_system::Config
+ pallet_drand::Config
+ pallet_crowdloan::Config
+ pallet_scheduler::Config
{
/// call type
type RuntimeCall: Parameter
+ Dispatchable<RuntimeOrigin = Self::RuntimeOrigin>
+ Dispatchable<RuntimeOrigin = OriginFor<Self>>
+ From<Call<Self>>
+ IsType<<Self as frame_system::Config>::RuntimeCall>
+ From<frame_system::Call<Self>>;

/// A sudo-able call.
type SudoRuntimeCall: Parameter
+ UnfilteredDispatchable<RuntimeOrigin = Self::RuntimeOrigin>
+ UnfilteredDispatchable<RuntimeOrigin = OriginFor<Self>>
+ GetDispatchInfo;

/// Currency type that will be used to place deposits on neurons
Expand Down
80 changes: 51 additions & 29 deletions pallets/subtensor/src/macros/dispatches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ mod dispatches {
.saturating_add(T::DbWeight::get().reads(10_u64))
.saturating_add(T::DbWeight::get().writes(2)), DispatchClass::Normal, Pays::No))]
pub fn commit_weights(
origin: T::RuntimeOrigin,
origin: OriginFor<T>,
netuid: NetUid,
commit_hash: H256,
) -> DispatchResult {
Expand Down Expand Up @@ -275,7 +275,7 @@ mod dispatches {
.saturating_add(T::DbWeight::get().reads(7))
.saturating_add(T::DbWeight::get().writes(2)), DispatchClass::Normal, Pays::No))]
pub fn commit_mechanism_weights(
origin: T::RuntimeOrigin,
origin: OriginFor<T>,
netuid: NetUid,
mecid: MechId,
commit_hash: H256,
Expand Down Expand Up @@ -359,7 +359,7 @@ mod dispatches {
.saturating_add(T::DbWeight::get().reads(17_u64))
.saturating_add(T::DbWeight::get().writes(2)), DispatchClass::Normal, Pays::No))]
pub fn reveal_weights(
origin: T::RuntimeOrigin,
origin: OriginFor<T>,
netuid: NetUid,
uids: Vec<u16>,
values: Vec<u16>,
Expand Down Expand Up @@ -414,7 +414,7 @@ mod dispatches {
.saturating_add(T::DbWeight::get().reads(16))
.saturating_add(T::DbWeight::get().writes(2)), DispatchClass::Normal, Pays::No))]
pub fn reveal_mechanism_weights(
origin: T::RuntimeOrigin,
origin: OriginFor<T>,
netuid: NetUid,
mecid: MechId,
uids: Vec<u16>,
Expand Down Expand Up @@ -512,7 +512,7 @@ mod dispatches {
.saturating_add(T::DbWeight::get().reads(7_u64))
.saturating_add(T::DbWeight::get().writes(2)), DispatchClass::Normal, Pays::No))]
pub fn commit_crv3_mechanism_weights(
origin: T::RuntimeOrigin,
origin: OriginFor<T>,
netuid: NetUid,
mecid: MechId,
commit: BoundedVec<u8, ConstU32<MAX_CRV3_COMMIT_SIZE_BYTES>>,
Expand Down Expand Up @@ -572,7 +572,7 @@ mod dispatches {
.saturating_add(T::DbWeight::get().reads(17_u64))
.saturating_add(T::DbWeight::get().writes(2_u64)), DispatchClass::Normal, Pays::No))]
pub fn batch_reveal_weights(
origin: T::RuntimeOrigin,
origin: OriginFor<T>,
netuid: NetUid,
uids_list: Vec<Vec<u16>>,
values_list: Vec<Vec<u16>>,
Expand Down Expand Up @@ -1304,7 +1304,7 @@ mod dispatches {
.saturating_add(T::DbWeight::get().reads(6))
.saturating_add(T::DbWeight::get().writes(31)), DispatchClass::Normal, Pays::Yes))]
pub fn set_children(
origin: T::RuntimeOrigin,
origin: OriginFor<T>,
hotkey: T::AccountId,
netuid: NetUid,
children: Vec<(u64, T::AccountId)>,
Expand Down Expand Up @@ -1523,7 +1523,7 @@ mod dispatches {
.saturating_add(T::DbWeight::get().reads(15_u64))
.saturating_add(T::DbWeight::get().writes(7_u64)), DispatchClass::Normal, Pays::Yes))]
pub fn move_stake(
origin: T::RuntimeOrigin,
origin: OriginFor<T>,
origin_hotkey: T::AccountId,
destination_hotkey: T::AccountId,
origin_netuid: NetUid,
Expand Down Expand Up @@ -1566,7 +1566,7 @@ mod dispatches {
.saturating_add(T::DbWeight::get().reads(13_u64))
.saturating_add(T::DbWeight::get().writes(6_u64)), DispatchClass::Normal, Pays::Yes))]
pub fn transfer_stake(
origin: T::RuntimeOrigin,
origin: OriginFor<T>,
destination_coldkey: T::AccountId,
hotkey: T::AccountId,
origin_netuid: NetUid,
Expand Down Expand Up @@ -1611,7 +1611,7 @@ mod dispatches {
Pays::Yes
))]
pub fn swap_stake(
origin: T::RuntimeOrigin,
origin: OriginFor<T>,
hotkey: T::AccountId,
origin_netuid: NetUid,
destination_netuid: NetUid,
Expand Down Expand Up @@ -1785,7 +1785,7 @@ mod dispatches {
Pays::Yes
))]
pub fn swap_stake_limit(
origin: T::RuntimeOrigin,
origin: OriginFor<T>,
hotkey: T::AccountId,
origin_netuid: NetUid,
destination_netuid: NetUid,
Expand Down Expand Up @@ -1818,10 +1818,7 @@ mod dispatches {
DispatchClass::Normal,
Pays::Yes
))]
pub fn try_associate_hotkey(
origin: T::RuntimeOrigin,
hotkey: T::AccountId,
) -> DispatchResult {
pub fn try_associate_hotkey(origin: OriginFor<T>, hotkey: T::AccountId) -> DispatchResult {
let coldkey = ensure_signed(origin)?;

let _ = Self::do_try_associate_hotkey(&coldkey, &hotkey);
Expand All @@ -1843,7 +1840,7 @@ mod dispatches {
DispatchClass::Normal,
Pays::Yes
))]
pub fn start_call(origin: T::RuntimeOrigin, netuid: NetUid) -> DispatchResult {
pub fn start_call(origin: OriginFor<T>, netuid: NetUid) -> DispatchResult {
Self::do_start_call(origin, netuid)?;
Ok(())
}
Expand Down Expand Up @@ -1880,7 +1877,7 @@ mod dispatches {
Pays::No
))]
pub fn associate_evm_key(
origin: T::RuntimeOrigin,
origin: OriginFor<T>,
netuid: NetUid,
evm_key: H160,
block_number: u64,
Expand All @@ -1906,7 +1903,7 @@ mod dispatches {
Pays::Yes
))]
pub fn recycle_alpha(
origin: T::RuntimeOrigin,
origin: OriginFor<T>,
hotkey: T::AccountId,
amount: AlphaCurrency,
netuid: NetUid,
Expand All @@ -1931,7 +1928,7 @@ mod dispatches {
Pays::Yes
))]
pub fn burn_alpha(
origin: T::RuntimeOrigin,
origin: OriginFor<T>,
hotkey: T::AccountId,
amount: AlphaCurrency,
netuid: NetUid,
Expand Down Expand Up @@ -1960,7 +1957,7 @@ mod dispatches {
.saturating_add(T::DbWeight::get().reads(28_u64))
.saturating_add(T::DbWeight::get().writes(14_u64)), DispatchClass::Normal, Pays::Yes))]
pub fn remove_stake_full_limit(
origin: T::RuntimeOrigin,
origin: OriginFor<T>,
hotkey: T::AccountId,
netuid: NetUid,
limit_price: Option<TaoCurrency>,
Expand All @@ -1987,7 +1984,7 @@ mod dispatches {
#[pallet::call_index(110)]
#[pallet::weight(SubnetLeasingWeightInfo::<T>::do_register_leased_network(T::MaxContributors::get()))]
pub fn register_leased_network(
origin: T::RuntimeOrigin,
origin: OriginFor<T>,
emissions_share: Percent,
end_block: Option<BlockNumberFor<T>>,
) -> DispatchResultWithPostInfo {
Expand All @@ -2013,7 +2010,7 @@ mod dispatches {
#[pallet::call_index(111)]
#[pallet::weight(SubnetLeasingWeightInfo::<T>::do_terminate_lease(T::MaxContributors::get()))]
pub fn terminate_lease(
origin: T::RuntimeOrigin,
origin: OriginFor<T>,
lease_id: LeaseId,
hotkey: T::AccountId,
) -> DispatchResultWithPostInfo {
Expand Down Expand Up @@ -2086,7 +2083,7 @@ mod dispatches {
.saturating_add(T::DbWeight::get().reads(10_u64))
.saturating_add(T::DbWeight::get().writes(2)), DispatchClass::Normal, Pays::No))]
pub fn commit_timelocked_weights(
origin: T::RuntimeOrigin,
origin: OriginFor<T>,
netuid: NetUid,
commit: BoundedVec<u8, ConstU32<MAX_CRV3_COMMIT_SIZE_BYTES>>,
reveal_round: u64,
Expand Down Expand Up @@ -2117,7 +2114,7 @@ mod dispatches {
.saturating_add(T::DbWeight::get().reads(4_u64))
.saturating_add(T::DbWeight::get().writes(2_u64)), DispatchClass::Normal, Pays::Yes))]
pub fn set_coldkey_auto_stake_hotkey(
origin: T::RuntimeOrigin,
origin: OriginFor<T>,
netuid: NetUid,
hotkey: T::AccountId,
) -> DispatchResult {
Expand Down Expand Up @@ -2191,7 +2188,7 @@ mod dispatches {
.saturating_add(T::DbWeight::get().reads(9_u64))
.saturating_add(T::DbWeight::get().writes(2)), DispatchClass::Normal, Pays::No))]
pub fn commit_timelocked_mechanism_weights(
origin: T::RuntimeOrigin,
origin: OriginFor<T>,
netuid: NetUid,
mecid: MechId,
commit: BoundedVec<u8, ConstU32<MAX_CRV3_COMMIT_SIZE_BYTES>>,
Expand Down Expand Up @@ -2291,7 +2288,7 @@ mod dispatches {

/// --- Sets root claim number (sudo extrinsic). Zero disables auto-claim.
#[pallet::call_index(123)]
#[pallet::weight(Weight::from_parts(4_000_000, 0)
#[pallet::weight(Weight::from_parts(2_283_000, 0)
.saturating_add(T::DbWeight::get().reads(0_u64))
.saturating_add(T::DbWeight::get().writes(1_u64)))]
pub fn sudo_set_num_root_claims(origin: OriginFor<T>, new_value: u64) -> DispatchResult {
Expand Down Expand Up @@ -2362,8 +2359,8 @@ mod dispatches {

if let Some((when, _)) = ColdkeySwapAnnouncements::<T>::get(who.clone()) {
let reannouncement_delay = ColdkeySwapReannouncementDelay::<T>::get();
let new_when = when.saturating_add(reannouncement_delay);
ensure!(now >= new_when, Error::<T>::ColdkeySwapReannouncedTooEarly);
let min_when = when.saturating_add(reannouncement_delay);
ensure!(now >= min_when, Error::<T>::ColdkeySwapReannouncedTooEarly);
} else {
// Only charge the swap cost on the first announcement
let swap_cost = Self::get_key_swap_cost();
Expand Down Expand Up @@ -2561,13 +2558,38 @@ mod dispatches {
Pays::Yes
))]
pub fn add_stake_burn(
origin: T::RuntimeOrigin,
origin: OriginFor<T>,
hotkey: T::AccountId,
netuid: NetUid,
amount: TaoCurrency,
limit: Option<TaoCurrency>,
) -> DispatchResult {
Self::do_add_stake_burn(origin, hotkey, netuid, amount, limit)
}

/// Clears a coldkey swap announcement after the reannouncement delay if
/// it has not been disputed.
///
/// The `ColdkeySwapCleared` event is emitted on successful clear.
#[pallet::call_index(133)]
#[pallet::weight(Weight::from_parts(17_890_000, 0)
.saturating_add(T::DbWeight::get().reads(2))
.saturating_add(T::DbWeight::get().writes(1)))]
pub fn clear_coldkey_swap_announcement(origin: OriginFor<T>) -> DispatchResult {
let who = ensure_signed(origin)?;
let now = <frame_system::Pallet<T>>::block_number();

let Some((when, _)) = ColdkeySwapAnnouncements::<T>::get(who.clone()) else {
return Err(Error::<T>::ColdkeySwapAnnouncementNotFound.into());
};
let delay = ColdkeySwapReannouncementDelay::<T>::get();
let min_when = when.saturating_add(delay);
ensure!(now >= min_when, Error::<T>::ColdkeySwapClearTooEarly);

ColdkeySwapAnnouncements::<T>::remove(&who);

Self::deposit_event(Event::ColdkeySwapCleared { who });
Ok(())
}
}
}
2 changes: 2 additions & 0 deletions pallets/subtensor/src/macros/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,5 +286,7 @@ mod errors {
ColdkeySwapAnnounced,
/// A coldkey swap for this account is under dispute.
ColdkeySwapDisputed,
/// Coldkey swap clear too early.
ColdkeySwapClearTooEarly,
}
}
5 changes: 5 additions & 0 deletions pallets/subtensor/src/macros/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,5 +528,10 @@ mod events {
/// Alpha burned
alpha: AlphaCurrency,
},
/// A coldkey swap announcement has been cleared.
ColdkeySwapCleared {
/// The account ID of the coldkey that cleared the announcement.
who: T::AccountId,
},
}
}
Loading
Loading