diff --git a/.github/e2e.yml b/.github/e2e.yml new file mode 100644 index 0000000000..65fb5fed57 --- /dev/null +++ b/.github/e2e.yml @@ -0,0 +1,4 @@ +name: E2E Tests + +on: + workflow_dispatch: \ No newline at end of file diff --git a/pallets/subtensor/Cargo.toml b/pallets/subtensor/Cargo.toml index 7ed0d8e28a..01407e9020 100644 --- a/pallets/subtensor/Cargo.toml +++ b/pallets/subtensor/Cargo.toml @@ -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 subtensor-runtime-common.workspace = true diff --git a/pallets/subtensor/src/benchmarks.rs b/pallets/subtensor/src/benchmarks.rs index 98bb64c263..8a768c95a3 100644 --- a/pallets/subtensor/src/benchmarks.rs +++ b/pallets/subtensor/src/benchmarks.rs @@ -554,6 +554,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 = ::Hashing::hash_of(&new_coldkey); + let now = frame_system::Pallet::::block_number(); + let delay = ColdkeySwapReannouncementDelay::::get(); + + ColdkeySwapAnnouncements::::insert(&coldkey, (now, new_coldkey_hash)); + frame_system::Pallet::::set_block_number(now + delay); + + #[extrinsic_call] + _(RawOrigin::Signed(coldkey)); + } + #[benchmark] fn reset_coldkey_swap() { let coldkey: T::AccountId = account("old_coldkey", 0, 0); @@ -586,7 +601,8 @@ mod pallet_benchmarks { let block_number: u64 = Subtensor::::get_current_block_as_u64(); let (nonce, work) = Subtensor::::create_work_for_block_number(netuid, block_number, 3, &hotkey); - let origin = T::RuntimeOrigin::from(RawOrigin::Signed(hotkey.clone())); + let origin = + ::RuntimeOrigin::from(RawOrigin::Signed(hotkey.clone())); assert_ok!(Subtensor::::register( origin.clone(), netuid, diff --git a/pallets/subtensor/src/coinbase/reveal_commits.rs b/pallets/subtensor/src/coinbase/reveal_commits.rs index 6fdafa76da..3d43cfba29 100644 --- a/pallets/subtensor/src/coinbase/reveal_commits.rs +++ b/pallets/subtensor/src/coinbase/reveal_commits.rs @@ -178,7 +178,7 @@ impl Pallet { // Apply weights // ------------------------------------------------------------------ if let Err(e) = Self::do_set_mechanism_weights( - T::RuntimeOrigin::signed(who.clone()), + OriginFor::::signed(who.clone()), netuid, MechId::from(mecid), uids, diff --git a/pallets/subtensor/src/coinbase/root.rs b/pallets/subtensor/src/coinbase/root.rs index e2714fba1b..db5b4fe2cc 100644 --- a/pallets/subtensor/src/coinbase/root.rs +++ b/pallets/subtensor/src/coinbase/root.rs @@ -77,7 +77,7 @@ impl Pallet { /// # 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, 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!( diff --git a/pallets/subtensor/src/epoch/run_epoch.rs b/pallets/subtensor/src/epoch/run_epoch.rs index 9f8fbc905b..793f6fbe4a 100644 --- a/pallets/subtensor/src/epoch/run_epoch.rs +++ b/pallets/subtensor/src/epoch/run_epoch.rs @@ -1508,7 +1508,7 @@ impl Pallet { } pub fn do_set_alpha_values( - origin: T::RuntimeOrigin, + origin: OriginFor, netuid: NetUid, alpha_low: u16, alpha_high: u16, diff --git a/pallets/subtensor/src/guards/check_coldkey_swap.rs b/pallets/subtensor/src/guards/check_coldkey_swap.rs index ab0a5e862a..67a0d2b2af 100644 --- a/pallets/subtensor/src/guards/check_coldkey_swap.rs +++ b/pallets/subtensor/src/guards/check_coldkey_swap.rs @@ -51,6 +51,7 @@ where Call::announce_coldkey_swap { .. } | Call::swap_coldkey_announced { .. } | Call::dispute_coldkey_swap { .. } + | Call::clear_coldkey_swap_announcement { .. } ) ); diff --git a/pallets/subtensor/src/lib.rs b/pallets/subtensor/src/lib.rs index 8dc031fbc4..54ccadc1a1 100644 --- a/pallets/subtensor/src/lib.rs +++ b/pallets/subtensor/src/lib.rs @@ -56,6 +56,8 @@ pub(crate) mod tests; // apparently this is stabilized since rust 1.36 extern crate alloc; +pub type OriginFor = ::RuntimeOrigin; + pub const MAX_CRV3_COMMIT_SIZE_BYTES: u32 = 5000; pub const ALPHA_MAP_BATCH_SIZE: usize = 30; diff --git a/pallets/subtensor/src/macros/config.rs b/pallets/subtensor/src/macros/config.rs index 1537de65b3..40439da27b 100644 --- a/pallets/subtensor/src/macros/config.rs +++ b/pallets/subtensor/src/macros/config.rs @@ -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 + + Dispatchable> + From> + IsType<::RuntimeCall> + From>; /// A sudo-able call. type SudoRuntimeCall: Parameter - + UnfilteredDispatchable + + UnfilteredDispatchable> + GetDispatchInfo; /// Currency type that will be used to place deposits on neurons diff --git a/pallets/subtensor/src/macros/dispatches.rs b/pallets/subtensor/src/macros/dispatches.rs index 2ba2c87e16..f70b83f52d 100644 --- a/pallets/subtensor/src/macros/dispatches.rs +++ b/pallets/subtensor/src/macros/dispatches.rs @@ -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, netuid: NetUid, commit_hash: H256, ) -> DispatchResult { @@ -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, netuid: NetUid, mecid: MechId, commit_hash: H256, @@ -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, netuid: NetUid, uids: Vec, values: Vec, @@ -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, netuid: NetUid, mecid: MechId, uids: Vec, @@ -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, netuid: NetUid, mecid: MechId, commit: BoundedVec>, @@ -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, netuid: NetUid, uids_list: Vec>, values_list: Vec>, @@ -1339,7 +1339,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, hotkey: T::AccountId, netuid: NetUid, children: Vec<(u64, T::AccountId)>, @@ -1558,7 +1558,7 @@ mod dispatches { .saturating_add(T::DbWeight::get().reads(19_u64)) .saturating_add(T::DbWeight::get().writes(7_u64)), DispatchClass::Normal, Pays::Yes))] pub fn move_stake( - origin: T::RuntimeOrigin, + origin: OriginFor, origin_hotkey: T::AccountId, destination_hotkey: T::AccountId, origin_netuid: NetUid, @@ -1601,7 +1601,7 @@ mod dispatches { .saturating_add(T::DbWeight::get().reads(16_u64)) .saturating_add(T::DbWeight::get().writes(6_u64)), DispatchClass::Normal, Pays::Yes))] pub fn transfer_stake( - origin: T::RuntimeOrigin, + origin: OriginFor, destination_coldkey: T::AccountId, hotkey: T::AccountId, origin_netuid: NetUid, @@ -1646,7 +1646,7 @@ mod dispatches { Pays::Yes ))] pub fn swap_stake( - origin: T::RuntimeOrigin, + origin: OriginFor, hotkey: T::AccountId, origin_netuid: NetUid, destination_netuid: NetUid, @@ -1820,7 +1820,7 @@ mod dispatches { Pays::Yes ))] pub fn swap_stake_limit( - origin: T::RuntimeOrigin, + origin: OriginFor, hotkey: T::AccountId, origin_netuid: NetUid, destination_netuid: NetUid, @@ -1853,10 +1853,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, hotkey: T::AccountId) -> DispatchResult { let coldkey = ensure_signed(origin)?; let _ = Self::do_try_associate_hotkey(&coldkey, &hotkey); @@ -1878,7 +1875,7 @@ mod dispatches { DispatchClass::Normal, Pays::Yes ))] - pub fn start_call(origin: T::RuntimeOrigin, netuid: NetUid) -> DispatchResult { + pub fn start_call(origin: OriginFor, netuid: NetUid) -> DispatchResult { Self::do_start_call(origin, netuid)?; Ok(()) } @@ -1915,7 +1912,7 @@ mod dispatches { Pays::No ))] pub fn associate_evm_key( - origin: T::RuntimeOrigin, + origin: OriginFor, netuid: NetUid, evm_key: H160, block_number: u64, @@ -1941,7 +1938,7 @@ mod dispatches { Pays::Yes ))] pub fn recycle_alpha( - origin: T::RuntimeOrigin, + origin: OriginFor, hotkey: T::AccountId, amount: AlphaBalance, netuid: NetUid, @@ -1966,7 +1963,7 @@ mod dispatches { Pays::Yes ))] pub fn burn_alpha( - origin: T::RuntimeOrigin, + origin: OriginFor, hotkey: T::AccountId, amount: AlphaBalance, netuid: NetUid, @@ -1995,7 +1992,7 @@ mod dispatches { .saturating_add(T::DbWeight::get().reads(30_u64)) .saturating_add(T::DbWeight::get().writes(13_u64)), DispatchClass::Normal, Pays::Yes))] pub fn remove_stake_full_limit( - origin: T::RuntimeOrigin, + origin: OriginFor, hotkey: T::AccountId, netuid: NetUid, limit_price: Option, @@ -2022,7 +2019,7 @@ mod dispatches { #[pallet::call_index(110)] #[pallet::weight(SubnetLeasingWeightInfo::::do_register_leased_network(T::MaxContributors::get()))] pub fn register_leased_network( - origin: T::RuntimeOrigin, + origin: OriginFor, emissions_share: Percent, end_block: Option>, ) -> DispatchResultWithPostInfo { @@ -2048,7 +2045,7 @@ mod dispatches { #[pallet::call_index(111)] #[pallet::weight(SubnetLeasingWeightInfo::::do_terminate_lease(T::MaxContributors::get()))] pub fn terminate_lease( - origin: T::RuntimeOrigin, + origin: OriginFor, lease_id: LeaseId, hotkey: T::AccountId, ) -> DispatchResultWithPostInfo { @@ -2121,7 +2118,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, netuid: NetUid, commit: BoundedVec>, reveal_round: u64, @@ -2152,7 +2149,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, netuid: NetUid, hotkey: T::AccountId, ) -> DispatchResult { @@ -2226,7 +2223,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, netuid: NetUid, mecid: MechId, commit: BoundedVec>, @@ -2326,7 +2323,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, new_value: u64) -> DispatchResult { @@ -2397,8 +2394,8 @@ mod dispatches { if let Some((when, _)) = ColdkeySwapAnnouncements::::get(who.clone()) { let reannouncement_delay = ColdkeySwapReannouncementDelay::::get(); - let new_when = when.saturating_add(reannouncement_delay); - ensure!(now >= new_when, Error::::ColdkeySwapReannouncedTooEarly); + let min_when = when.saturating_add(reannouncement_delay); + ensure!(now >= min_when, Error::::ColdkeySwapReannouncedTooEarly); } else { // Only charge the swap cost on the first announcement let swap_cost = Self::get_key_swap_cost(); @@ -2596,7 +2593,7 @@ mod dispatches { Pays::Yes ))] pub fn add_stake_burn( - origin: T::RuntimeOrigin, + origin: OriginFor, hotkey: T::AccountId, netuid: NetUid, amount: TaoBalance, @@ -2604,5 +2601,30 @@ mod dispatches { ) -> 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) -> DispatchResult { + let who = ensure_signed(origin)?; + let now = >::block_number(); + + let Some((when, _)) = ColdkeySwapAnnouncements::::get(who.clone()) else { + return Err(Error::::ColdkeySwapAnnouncementNotFound.into()); + }; + let delay = ColdkeySwapReannouncementDelay::::get(); + let min_when = when.saturating_add(delay); + ensure!(now >= min_when, Error::::ColdkeySwapClearTooEarly); + + ColdkeySwapAnnouncements::::remove(&who); + + Self::deposit_event(Event::ColdkeySwapCleared { who }); + Ok(()) + } } } diff --git a/pallets/subtensor/src/macros/errors.rs b/pallets/subtensor/src/macros/errors.rs index 78e8becb12..637704f970 100644 --- a/pallets/subtensor/src/macros/errors.rs +++ b/pallets/subtensor/src/macros/errors.rs @@ -284,5 +284,7 @@ mod errors { ColdkeySwapAnnounced, /// A coldkey swap for this account is under dispute. ColdkeySwapDisputed, + /// Coldkey swap clear too early. + ColdkeySwapClearTooEarly, } } diff --git a/pallets/subtensor/src/macros/events.rs b/pallets/subtensor/src/macros/events.rs index ad62ec7c46..0370ad2e06 100644 --- a/pallets/subtensor/src/macros/events.rs +++ b/pallets/subtensor/src/macros/events.rs @@ -529,6 +529,12 @@ mod events { alpha: AlphaBalance, }, + /// A coldkey swap announcement has been cleared. + ColdkeySwapCleared { + /// The account ID of the coldkey that cleared the announcement. + who: T::AccountId, + }, + /// Transaction fee was paid in Alpha. /// /// Emitted in addition to `TransactionFeePaid` when the fee payment path is Alpha. diff --git a/pallets/subtensor/src/migrations/migrate_coldkey_swap_scheduled_to_announcements.rs b/pallets/subtensor/src/migrations/migrate_coldkey_swap_scheduled_to_announcements.rs index 12fa3f5768..52b2a66e8f 100644 --- a/pallets/subtensor/src/migrations/migrate_coldkey_swap_scheduled_to_announcements.rs +++ b/pallets/subtensor/src/migrations/migrate_coldkey_swap_scheduled_to_announcements.rs @@ -1,13 +1,19 @@ use super::*; use crate::AccountIdOf; -use frame_support::{pallet_prelude::Blake2_128Concat, traits::Get, weights::Weight}; +use frame_support::{ + pallet_prelude::Blake2_128Concat, + traits::{Bounded, Get}, + weights::Weight, +}; use frame_system::pallet_prelude::BlockNumberFor; +use pallet_scheduler::ScheduledOf; use scale_info::prelude::string::String; use sp_io::storage::clear; use sp_runtime::{Saturating, traits::Hash}; pub mod deprecated { use super::*; + use codec::{Decode, Encode}; use frame_support::storage_alias; #[storage_alias] @@ -26,9 +32,26 @@ pub mod deprecated { (BlockNumberFor, AccountIdOf), OptionQuery, >; + + #[derive(Encode, Decode)] + pub enum RuntimeCall { + #[codec(index = 7)] + SubtensorCall(SubtensorCall), + } + + #[derive(Encode, Decode)] + pub enum SubtensorCall { + #[codec(index = 71)] + SwapColdkey { + old_coldkey: AccountIdOf, + new_coldkey: AccountIdOf, + swap_cost: TaoBalance, + }, + } } -pub fn migrate_coldkey_swap_scheduled_to_announcements() -> Weight { +pub fn migrate_coldkey_swap_scheduled_to_announcements() +-> Weight { let migration_name = b"migrate_coldkey_swap_scheduled_to_announcements".to_vec(); let mut weight = T::DbWeight::get().reads(1); @@ -64,7 +87,10 @@ pub fn migrate_coldkey_swap_scheduled_to_announcements() -> Weight { let coldkey_hash = ::Hashing::hash_of(&new_coldkey); // The announcement should be at the scheduled time - delay to be able to call // the swap_coldkey_announced call at the old scheduled time - ColdkeySwapAnnouncements::::insert(who, (when.saturating_sub(delay), coldkey_hash)); + ColdkeySwapAnnouncements::::insert( + who.clone(), + (when.saturating_sub(delay), coldkey_hash), + ); weight.saturating_accrue(T::DbWeight::get().writes(1)); } weight.saturating_accrue(T::DbWeight::get().reads(1)); @@ -75,6 +101,22 @@ pub fn migrate_coldkey_swap_scheduled_to_announcements() -> Weight { T::DbWeight::get().reads_writes(results.loops as u64, results.backend as u64), ); + pallet_scheduler::Agenda::::translate_values::>>, _>( + |mut agenda| { + weight.saturating_accrue(T::DbWeight::get().reads_writes(1, 1)); + for schedule in agenda.iter_mut() { + // SwapColdkey call is guaranteed to be inlined and below 128 bytes. + if let Some(Bounded::Inline(data)) = schedule.as_ref().map(|s| s.call.clone()) + && deprecated::RuntimeCall::::decode(&mut &data[..]).is_ok() + { + // Remove calls that decode as a SwapColdkey call + schedule.take(); + } + } + Some(BoundedVec::truncate_from(agenda)) + }, + ); + // ------------------------------ // Step 2: Mark Migration as Completed // ------------------------------ diff --git a/pallets/subtensor/src/staking/add_stake.rs b/pallets/subtensor/src/staking/add_stake.rs index 17dd9e2eb9..a4ad9b92cf 100644 --- a/pallets/subtensor/src/staking/add_stake.rs +++ b/pallets/subtensor/src/staking/add_stake.rs @@ -38,7 +38,7 @@ impl Pallet { /// - Thrown if key has hit transaction rate limit /// pub fn do_add_stake( - origin: T::RuntimeOrigin, + origin: OriginFor, hotkey: T::AccountId, netuid: NetUid, stake_to_be_added: TaoBalance, @@ -121,7 +121,7 @@ impl Pallet { /// - Thrown if key has hit transaction rate limit /// pub fn do_add_stake_limit( - origin: T::RuntimeOrigin, + origin: OriginFor, hotkey: T::AccountId, netuid: NetUid, stake_to_be_added: TaoBalance, diff --git a/pallets/subtensor/src/staking/decrease_take.rs b/pallets/subtensor/src/staking/decrease_take.rs index 43bc633431..b099d0a7e7 100644 --- a/pallets/subtensor/src/staking/decrease_take.rs +++ b/pallets/subtensor/src/staking/decrease_take.rs @@ -28,7 +28,7 @@ impl Pallet { /// - The delegate is setting a take which is not lower than the previous. /// pub fn do_decrease_take( - origin: T::RuntimeOrigin, + origin: OriginFor, hotkey: T::AccountId, take: u16, ) -> dispatch::DispatchResult { diff --git a/pallets/subtensor/src/staking/increase_take.rs b/pallets/subtensor/src/staking/increase_take.rs index 3a101c7e0f..65ea70a025 100644 --- a/pallets/subtensor/src/staking/increase_take.rs +++ b/pallets/subtensor/src/staking/increase_take.rs @@ -31,7 +31,7 @@ impl Pallet { /// - The delegate is setting a take which is not greater than the previous. /// pub fn do_increase_take( - origin: T::RuntimeOrigin, + origin: OriginFor, hotkey: T::AccountId, take: u16, ) -> dispatch::DispatchResult { diff --git a/pallets/subtensor/src/staking/move_stake.rs b/pallets/subtensor/src/staking/move_stake.rs index 2cc08b4f02..8e94339339 100644 --- a/pallets/subtensor/src/staking/move_stake.rs +++ b/pallets/subtensor/src/staking/move_stake.rs @@ -28,7 +28,7 @@ impl Pallet { /// # Events /// Emits a `StakeMoved` event upon successful completion of the stake movement. pub fn do_move_stake( - origin: T::RuntimeOrigin, + origin: OriginFor, origin_hotkey: T::AccountId, destination_hotkey: T::AccountId, origin_netuid: NetUid, @@ -119,7 +119,7 @@ impl Pallet { /// # Events /// Emits a `StakeTransferred` event upon successful completion of the transfer. pub fn do_transfer_stake( - origin: T::RuntimeOrigin, + origin: OriginFor, destination_coldkey: T::AccountId, hotkey: T::AccountId, origin_netuid: NetUid, @@ -185,7 +185,7 @@ impl Pallet { /// # Events /// Emits a `StakeSwapped` event upon successful completion. pub fn do_swap_stake( - origin: T::RuntimeOrigin, + origin: OriginFor, hotkey: T::AccountId, origin_netuid: NetUid, destination_netuid: NetUid, @@ -251,7 +251,7 @@ impl Pallet { /// # Events /// Emits a `StakeSwapped` event upon successful completion. pub fn do_swap_stake_limit( - origin: T::RuntimeOrigin, + origin: OriginFor, hotkey: T::AccountId, origin_netuid: NetUid, destination_netuid: NetUid, diff --git a/pallets/subtensor/src/staking/recycle_alpha.rs b/pallets/subtensor/src/staking/recycle_alpha.rs index cd7d92e67e..bb93c12818 100644 --- a/pallets/subtensor/src/staking/recycle_alpha.rs +++ b/pallets/subtensor/src/staking/recycle_alpha.rs @@ -16,7 +16,7 @@ impl Pallet { /// /// * `DispatchResult` - Success or error pub(crate) fn do_recycle_alpha( - origin: T::RuntimeOrigin, + origin: OriginFor, hotkey: T::AccountId, amount: AlphaBalance, netuid: NetUid, @@ -74,7 +74,7 @@ impl Pallet { /// /// * `DispatchResult` - Success or error pub(crate) fn do_burn_alpha( - origin: T::RuntimeOrigin, + origin: OriginFor, hotkey: T::AccountId, amount: AlphaBalance, netuid: NetUid, @@ -119,7 +119,7 @@ impl Pallet { Ok(()) } pub(crate) fn do_add_stake_burn( - origin: T::RuntimeOrigin, + origin: OriginFor, hotkey: T::AccountId, netuid: NetUid, amount: TaoBalance, diff --git a/pallets/subtensor/src/staking/remove_stake.rs b/pallets/subtensor/src/staking/remove_stake.rs index 75733aeb18..0750456106 100644 --- a/pallets/subtensor/src/staking/remove_stake.rs +++ b/pallets/subtensor/src/staking/remove_stake.rs @@ -37,7 +37,7 @@ impl Pallet { /// - Thrown if key has hit transaction rate limit /// pub fn do_remove_stake( - origin: T::RuntimeOrigin, + origin: OriginFor, hotkey: T::AccountId, netuid: NetUid, alpha_unstaked: AlphaBalance, @@ -119,10 +119,7 @@ impl Pallet { /// * 'TxRateLimitExceeded': /// - Thrown if key has hit transaction rate limit /// - pub fn do_unstake_all( - origin: T::RuntimeOrigin, - hotkey: T::AccountId, - ) -> dispatch::DispatchResult { + pub fn do_unstake_all(origin: OriginFor, hotkey: T::AccountId) -> dispatch::DispatchResult { // 1. We check the transaction is signed by the caller and retrieve the T::AccountId coldkey information. let coldkey = ensure_signed(origin)?; log::debug!("do_unstake_all( origin:{coldkey:?} hotkey:{hotkey:?} )"); @@ -210,7 +207,7 @@ impl Pallet { /// - Thrown if key has hit transaction rate limit /// pub fn do_unstake_all_alpha( - origin: T::RuntimeOrigin, + origin: OriginFor, hotkey: T::AccountId, ) -> dispatch::DispatchResult { // 1. We check the transaction is signed by the caller and retrieve the T::AccountId coldkey information. @@ -330,7 +327,7 @@ impl Pallet { /// - Thrown if there is not enough stake on the hotkey to withdwraw this amount. /// pub fn do_remove_stake_limit( - origin: T::RuntimeOrigin, + origin: OriginFor, hotkey: T::AccountId, netuid: NetUid, alpha_unstaked: AlphaBalance, @@ -416,7 +413,7 @@ impl Pallet { } pub fn do_remove_stake_full_limit( - origin: T::RuntimeOrigin, + origin: OriginFor, hotkey: T::AccountId, netuid: NetUid, limit_price: Option, diff --git a/pallets/subtensor/src/staking/set_children.rs b/pallets/subtensor/src/staking/set_children.rs index c7ebd62c04..8082f22c32 100644 --- a/pallets/subtensor/src/staking/set_children.rs +++ b/pallets/subtensor/src/staking/set_children.rs @@ -478,7 +478,7 @@ impl Pallet { /// - Too many children in request /// pub fn do_schedule_children( - origin: T::RuntimeOrigin, + origin: OriginFor, hotkey: T::AccountId, netuid: NetUid, children: Vec<(u64, T::AccountId)>, diff --git a/pallets/subtensor/src/subnets/leasing.rs b/pallets/subtensor/src/subnets/leasing.rs index e7c10bf8ff..cc1094d227 100644 --- a/pallets/subtensor/src/subnets/leasing.rs +++ b/pallets/subtensor/src/subnets/leasing.rs @@ -20,6 +20,7 @@ use frame_support::{ dispatch::RawOrigin, traits::{Defensive, fungible::*, tokens::Preservation}, }; +use frame_system::pallet_prelude::OriginFor; use frame_system::pallet_prelude::*; use sp_core::blake2_256; use sp_runtime::{Percent, traits::TrailingZeroInput}; @@ -66,7 +67,7 @@ impl Pallet { /// /// The leftover cap is refunded to the contributors and the beneficiary. pub fn do_register_leased_network( - origin: T::RuntimeOrigin, + origin: OriginFor, emissions_share: Percent, end_block: Option>, ) -> DispatchResultWithPostInfo { @@ -194,7 +195,7 @@ impl Pallet { /// The beneficiary can terminate the lease after the end block has passed and get the subnet ownership. /// The subnet is transferred to the beneficiary and the lease is removed from storage. pub fn do_terminate_lease( - origin: T::RuntimeOrigin, + origin: OriginFor, lease_id: LeaseId, hotkey: T::AccountId, ) -> DispatchResultWithPostInfo { diff --git a/pallets/subtensor/src/subnets/registration.rs b/pallets/subtensor/src/subnets/registration.rs index ccf32f6ac7..842f1ad628 100644 --- a/pallets/subtensor/src/subnets/registration.rs +++ b/pallets/subtensor/src/subnets/registration.rs @@ -62,7 +62,7 @@ impl Pallet { /// - The hotkey is already registered on this network. /// pub fn do_burned_registration( - origin: T::RuntimeOrigin, + origin: OriginFor, netuid: NetUid, hotkey: T::AccountId, ) -> DispatchResult { @@ -216,7 +216,7 @@ impl Pallet { /// - The seal is incorrect. /// pub fn do_registration( - origin: T::RuntimeOrigin, + origin: OriginFor, netuid: NetUid, block_number: u64, nonce: u64, @@ -335,7 +335,7 @@ impl Pallet { } pub fn do_faucet( - origin: T::RuntimeOrigin, + origin: OriginFor, block_number: u64, nonce: u64, work: Vec, diff --git a/pallets/subtensor/src/subnets/serving.rs b/pallets/subtensor/src/subnets/serving.rs index d11eb479d3..29923f5ade 100644 --- a/pallets/subtensor/src/subnets/serving.rs +++ b/pallets/subtensor/src/subnets/serving.rs @@ -56,7 +56,7 @@ impl Pallet { /// - Attempting to set prometheus information withing the rate limit min. /// pub fn do_serve_axon( - origin: T::RuntimeOrigin, + origin: OriginFor, netuid: NetUid, version: u32, ip: u128, @@ -160,7 +160,7 @@ impl Pallet { /// - Attempting to set prometheus information withing the rate limit min. /// pub fn do_serve_prometheus( - origin: T::RuntimeOrigin, + origin: OriginFor, netuid: NetUid, version: u32, ip: u128, diff --git a/pallets/subtensor/src/subnets/subnet.rs b/pallets/subtensor/src/subnets/subnet.rs index 769db17ebe..c6a87af63a 100644 --- a/pallets/subtensor/src/subnets/subnet.rs +++ b/pallets/subtensor/src/subnets/subnet.rs @@ -109,7 +109,7 @@ impl Pallet { /// * `InvalidIdentity` – supplied `identity` failed validation. /// pub fn do_register_network( - origin: T::RuntimeOrigin, + origin: OriginFor, hotkey: &T::AccountId, mechid: u16, identity: Option, @@ -343,7 +343,7 @@ impl Pallet { /// # Returns /// /// * `DispatchResult`: A result indicating the success or failure of the operation. - pub fn do_start_call(origin: T::RuntimeOrigin, netuid: NetUid) -> DispatchResult { + pub fn do_start_call(origin: OriginFor, netuid: NetUid) -> DispatchResult { ensure!(Self::if_subnet_exist(netuid), Error::::SubnetNotExists); Self::ensure_subnet_owner(origin, netuid)?; ensure!( @@ -401,7 +401,7 @@ impl Pallet { /// # Rate Limiting /// This function is rate-limited to one call per subnet per interval (e.g., one week). pub fn do_set_sn_owner_hotkey( - origin: T::RuntimeOrigin, + origin: OriginFor, netuid: NetUid, hotkey: &T::AccountId, ) -> DispatchResult { diff --git a/pallets/subtensor/src/subnets/weights.rs b/pallets/subtensor/src/subnets/weights.rs index 56acbef9c7..652815dfa4 100644 --- a/pallets/subtensor/src/subnets/weights.rs +++ b/pallets/subtensor/src/subnets/weights.rs @@ -42,7 +42,7 @@ impl Pallet { /// * `WeightsCommitted`: /// - Emitted upon successfully storing the weight hash. pub fn do_commit_weights( - origin: T::RuntimeOrigin, + origin: OriginFor, netuid: NetUid, commit_hash: H256, ) -> DispatchResult { @@ -50,7 +50,7 @@ impl Pallet { } pub fn do_commit_mechanism_weights( - origin: T::RuntimeOrigin, + origin: OriginFor, netuid: NetUid, mecid: MechId, commit_hash: H256, @@ -59,7 +59,7 @@ impl Pallet { } fn internal_commit_weights( - origin: T::RuntimeOrigin, + origin: OriginFor, netuid: NetUid, mecid: MechId, commit_hash: H256, @@ -169,7 +169,7 @@ impl Pallet { /// - Emitted when the lengths of the input vectors are not equal. /// pub fn do_batch_commit_weights( - origin: T::RuntimeOrigin, + origin: OriginFor, netuids: Vec>, commit_hashes: Vec, ) -> dispatch::DispatchResult { @@ -258,7 +258,7 @@ impl Pallet { /// # Events /// * `TimelockedWeightsCommitted(hotkey, netuid, commit_hash, reveal_round)` – Fired after the commit is successfully stored. pub fn do_commit_timelocked_weights( - origin: T::RuntimeOrigin, + origin: OriginFor, netuid: NetUid, commit: BoundedVec>, reveal_round: u64, @@ -275,7 +275,7 @@ impl Pallet { } pub fn do_commit_timelocked_mechanism_weights( - origin: T::RuntimeOrigin, + origin: OriginFor, netuid: NetUid, mecid: MechId, commit: BoundedVec>, @@ -293,7 +293,7 @@ impl Pallet { } pub fn internal_commit_timelocked_weights( - origin: T::RuntimeOrigin, + origin: OriginFor, netuid: NetUid, mecid: MechId, commit: BoundedVec>, @@ -418,7 +418,7 @@ impl Pallet { /// * `InvalidRevealCommitHashNotMatch`: /// - The revealed hash does not match any committed hash. pub fn do_reveal_weights( - origin: T::RuntimeOrigin, + origin: OriginFor, netuid: NetUid, uids: Vec, values: Vec, @@ -437,7 +437,7 @@ impl Pallet { } pub fn do_reveal_mechanism_weights( - origin: T::RuntimeOrigin, + origin: OriginFor, netuid: NetUid, mecid: MechId, uids: Vec, @@ -449,7 +449,7 @@ impl Pallet { } fn internal_reveal_weights( - origin: T::RuntimeOrigin, + origin: OriginFor, netuid: NetUid, mecid: MechId, uids: Vec, @@ -603,7 +603,7 @@ impl Pallet { /// * `InputLengthsUnequal`: /// - The input vectors are of mismatched lengths. pub fn do_batch_reveal_weights( - origin: T::RuntimeOrigin, + origin: OriginFor, netuid: NetUid, uids_list: Vec>, values_list: Vec>, @@ -746,7 +746,7 @@ impl Pallet { } fn internal_set_weights( - origin: T::RuntimeOrigin, + origin: OriginFor, netuid: NetUid, mecid: MechId, uids: Vec, @@ -917,7 +917,7 @@ impl Pallet { /// - Attempting to set weights with max value exceeding limit. /// pub fn do_set_weights( - origin: T::RuntimeOrigin, + origin: OriginFor, netuid: NetUid, uids: Vec, values: Vec, @@ -986,7 +986,7 @@ impl Pallet { /// - Attempting to set weights with max value exceeding limit. /// pub fn do_set_mechanism_weights( - origin: T::RuntimeOrigin, + origin: OriginFor, netuid: NetUid, mecid: MechId, uids: Vec, @@ -1027,7 +1027,7 @@ impl Pallet { /// - Emitted when the lengths of the input vectors are not equal. /// pub fn do_batch_set_weights( - origin: T::RuntimeOrigin, + origin: OriginFor, netuids: Vec>, weights: Vec, Compact)>>, version_keys: Vec>, diff --git a/pallets/subtensor/src/swap/swap_hotkey.rs b/pallets/subtensor/src/swap/swap_hotkey.rs index 8cb12a974a..1138ed1cde 100644 --- a/pallets/subtensor/src/swap/swap_hotkey.rs +++ b/pallets/subtensor/src/swap/swap_hotkey.rs @@ -28,7 +28,7 @@ impl Pallet { /// * `HotKeyAlreadyRegisteredInSubNet` - If the new hotkey is already registered in the subnet. /// * `NotEnoughBalanceToPaySwapHotKey` - If there is not enough balance to pay for the swap. pub fn do_swap_hotkey( - origin: T::RuntimeOrigin, + origin: OriginFor, old_hotkey: &T::AccountId, new_hotkey: &T::AccountId, netuid: Option, diff --git a/pallets/subtensor/src/tests/migration.rs b/pallets/subtensor/src/tests/migration.rs index f4d0347686..7f19c96b3d 100644 --- a/pallets/subtensor/src/tests/migration.rs +++ b/pallets/subtensor/src/tests/migration.rs @@ -19,13 +19,17 @@ use frame_support::{ weights::Weight, }; +use crate::migrations::migrate_coldkey_swap_scheduled_to_announcements::deprecated as coldkey_swap_deprecated; use crate::migrations::migrate_storage; +use frame_support::traits::Bounded; use frame_system::Config; use pallet_drand::types::RoundNumber; +use pallet_scheduler::ScheduledOf; use scale_info::prelude::collections::VecDeque; use sp_core::{H256, U256, crypto::Ss58Codec}; use sp_io::hashing::twox_128; use sp_runtime::{traits::Hash, traits::Zero}; +use sp_std::marker::PhantomData; use substrate_fixed::types::extra::U2; use substrate_fixed::types::{I96F32, U64F64}; use subtensor_runtime_common::{NetUidStorageIndex, TaoBalance}; @@ -2971,35 +2975,93 @@ fn test_migrate_remove_unknown_neuron_axon_cert_prom() { #[test] fn test_migrate_coldkey_swap_scheduled_to_announcements() { new_test_ext(1000).execute_with(|| { - const MIGRATION_NAME: &[u8] = b"migrate_coldkey_swap_scheduled_to_announcements"; use crate::migrations::migrate_coldkey_swap_scheduled_to_announcements::*; + use coldkey_swap_deprecated as deprecated; + + const MIGRATION_NAME: &[u8] = b"migrate_coldkey_swap_scheduled_to_announcements"; let now = frame_system::Pallet::::block_number(); // Set the schedule duration and reschedule duration deprecated::ColdkeySwapScheduleDuration::::set(Some(now + 100)); deprecated::ColdkeySwapRescheduleDuration::::set(Some(now + 200)); - // Set some scheduled coldkey swaps + let make_swap_task = |who: U256, new_coldkey: U256| -> ScheduledOf { + let call_bytes = deprecated::RuntimeCall::::SubtensorCall( + deprecated::SubtensorCall::SwapColdkey { + old_coldkey: who, + new_coldkey, + swap_cost: 1000.into(), + }, + ) + .encode(); + pallet_scheduler::Scheduled { + maybe_id: None, + priority: 63, + call: Bounded::Inline(BoundedVec::truncate_from(call_bytes)), + maybe_periodic: None, + origin: OriginCaller::system(frame_system::RawOrigin::Root), + _phantom: PhantomData, + } + }; + + let make_other_task = || -> ScheduledOf { + let call_bytes = RuntimeCall::SubtensorModule(crate::Call::burned_register { + netuid: 1u16.into(), + hotkey: U256::from(999), + }) + .encode(); + pallet_scheduler::Scheduled { + maybe_id: None, + priority: 63, + call: Bounded::Inline(BoundedVec::truncate_from(call_bytes)), + maybe_periodic: None, + origin: OriginCaller::system(frame_system::RawOrigin::Root), + _phantom: PhantomData, + } + }; + deprecated::ColdkeySwapScheduled::::insert( U256::from(1), (now + 100, U256::from(10)), ); + pallet_scheduler::Agenda::::insert( + now + 100, + BoundedVec::truncate_from(vec![ + Some(make_swap_task(U256::from(1), U256::from(10))), + Some(make_other_task()), + ]), + ); + deprecated::ColdkeySwapScheduled::::insert( U256::from(2), (now - 200, U256::from(20)), ); + deprecated::ColdkeySwapScheduled::::insert( U256::from(3), (now + 200, U256::from(30)), ); + pallet_scheduler::Agenda::::insert( + now + 200, + BoundedVec::truncate_from(vec![Some(make_swap_task(U256::from(3), U256::from(30)))]), + ); + deprecated::ColdkeySwapScheduled::::insert( U256::from(4), (now - 400, U256::from(40)), ); + deprecated::ColdkeySwapScheduled::::insert( U256::from(5), (now + 300, U256::from(50)), ); + pallet_scheduler::Agenda::::insert( + now + 300, + BoundedVec::truncate_from(vec![ + Some(make_other_task()), + Some(make_swap_task(U256::from(5), U256::from(50))), + ]), + ); let w = migrate_coldkey_swap_scheduled_to_announcements::(); @@ -3011,11 +3073,32 @@ fn test_migrate_coldkey_swap_scheduled_to_announcements() { assert!(!deprecated::ColdkeySwapRescheduleDuration::::exists()); assert_eq!(deprecated::ColdkeySwapScheduled::::iter().count(), 0); - // Ensure scheduled have been migrated to announcements if not executed yet - // The announcement should be at the scheduled time - delay to be able to call - // the swap_coldkey_announced call at the old scheduled time + assert_eq!( + pallet_scheduler::Agenda::::get(now + 100), + vec![None, Some(make_other_task())], + "swap task for who=1 should be cancelled" + ); + + assert_eq!( + pallet_scheduler::Agenda::::get(now + 200), + vec![None], + "swap task for who=3 should be cancelled" + ); + + assert_eq!( + pallet_scheduler::Agenda::::get(now + 300), + vec![Some(make_other_task()), None], + "swap task for who=5 should be cancelled" + ); + let delay = ColdkeySwapAnnouncementDelay::::get(); assert_eq!(ColdkeySwapAnnouncements::::iter().count(), 3); + assert!(!ColdkeySwapAnnouncements::::contains_key(U256::from( + 2 + ))); + assert!(!ColdkeySwapAnnouncements::::contains_key(U256::from( + 4 + ))); assert_eq!( ColdkeySwapAnnouncements::::get(U256::from(1)), Some(( diff --git a/pallets/subtensor/src/tests/swap_coldkey.rs b/pallets/subtensor/src/tests/swap_coldkey.rs index 67362ab614..512f83dd1d 100644 --- a/pallets/subtensor/src/tests/swap_coldkey.rs +++ b/pallets/subtensor/src/tests/swap_coldkey.rs @@ -1372,11 +1372,9 @@ fn test_do_swap_coldkey_effect_on_delegations() { fn test_dispute_coldkey_swap_works() { new_test_ext(1).execute_with(|| { let who = U256::from(1); - let new_coldkey = U256::from(2); - let new_coldkey_hash = ::Hashing::hash_of(&new_coldkey); let now = System::block_number(); - - ColdkeySwapAnnouncements::::insert(who, (now, new_coldkey_hash)); + let new_coldkey = U256::from(2); + announce_coldkey_swap(who, new_coldkey); assert_ok!(SubtensorModule::dispute_coldkey_swap( RuntimeOrigin::signed(who) @@ -1395,10 +1393,7 @@ fn test_dispute_coldkey_swap_with_bad_origin_fails() { new_test_ext(1).execute_with(|| { let who = U256::from(1); let new_coldkey = U256::from(2); - let new_coldkey_hash = ::Hashing::hash_of(&new_coldkey); - let now = System::block_number(); - - ColdkeySwapAnnouncements::::insert(who, (now, new_coldkey_hash)); + announce_coldkey_swap(who, new_coldkey); assert_noop!( SubtensorModule::dispute_coldkey_swap(RuntimeOrigin::root()), @@ -1416,9 +1411,6 @@ fn test_dispute_coldkey_swap_with_bad_origin_fails() { fn test_dispute_coldkey_swap_without_announcement_fails() { new_test_ext(1).execute_with(|| { let who = U256::from(1); - let new_coldkey = U256::from(2); - let new_coldkey_hash = ::Hashing::hash_of(&new_coldkey); - let now = System::block_number(); assert_noop!( SubtensorModule::dispute_coldkey_swap(RuntimeOrigin::signed(who)), @@ -1432,11 +1424,8 @@ fn test_dispute_coldkey_swap_already_disputed_fails() { new_test_ext(1).execute_with(|| { let who = U256::from(1); let new_coldkey = U256::from(2); - let new_coldkey_hash = ::Hashing::hash_of(&new_coldkey); - let now = System::block_number(); - - ColdkeySwapAnnouncements::::insert(who, (now, new_coldkey_hash)); - ColdkeySwapDisputes::::insert(who, now); + announce_coldkey_swap(who, new_coldkey); + dispute_coldkey_swap(who); assert_noop!( SubtensorModule::dispute_coldkey_swap(RuntimeOrigin::signed(who)), @@ -1450,11 +1439,7 @@ fn test_reset_coldkey_swap_works() { new_test_ext(1).execute_with(|| { let who = U256::from(1); let new_coldkey = U256::from(2); - let new_coldkey_hash = ::Hashing::hash_of(&new_coldkey); - let now = System::block_number(); - - ColdkeySwapAnnouncements::::insert(who, (now, new_coldkey_hash)); - ColdkeySwapDisputes::::insert(who, now); + announce_coldkey_swap(who, new_coldkey); assert_ok!(SubtensorModule::reset_coldkey_swap( RuntimeOrigin::root(), @@ -1488,6 +1473,74 @@ fn test_reset_coldkey_swap_with_bad_origin_fails() { }); } +#[test] +fn test_clear_coldkey_swap_announcement_works() { + new_test_ext(1).execute_with(|| { + let who = U256::from(1); + let new_coldkey = U256::from(2); + announce_coldkey_swap(who, new_coldkey); + + let (when, _) = ColdkeySwapAnnouncements::::get(who).unwrap(); + let delay = ColdkeySwapReannouncementDelay::::get(); + run_to_block(when + delay); + + assert_ok!(SubtensorModule::clear_coldkey_swap_announcement( + RuntimeOrigin::signed(who) + )); + + assert!(!ColdkeySwapAnnouncements::::contains_key(who)); + System::assert_last_event(Event::ColdkeySwapCleared { who }.into()); + }); +} + +#[test] +fn test_clear_coldkey_swap_announcement_not_found() { + new_test_ext(1).execute_with(|| { + let who = U256::from(1); + + assert_noop!( + SubtensorModule::clear_coldkey_swap_announcement(RuntimeOrigin::signed(who)), + Error::::ColdkeySwapAnnouncementNotFound + ); + }); +} + +#[test] +fn test_clear_coldkey_swap_announcement_too_early() { + new_test_ext(1).execute_with(|| { + let who = U256::from(1); + let new_coldkey = U256::from(2); + announce_coldkey_swap(who, new_coldkey); + + // Advance by less than the full delay — one block short + let (when, _) = ColdkeySwapAnnouncements::::get(who).unwrap(); + let delay = ColdkeySwapReannouncementDelay::::get(); + run_to_block(when + delay - 1); + + assert_noop!( + SubtensorModule::clear_coldkey_swap_announcement(RuntimeOrigin::signed(who)), + Error::::ColdkeySwapClearTooEarly + ); + + // Announcement is still present + assert!(ColdkeySwapAnnouncements::::contains_key(who)); + }); +} + +#[test] +fn test_clear_coldkey_swap_announcement_bad_origin() { + new_test_ext(1).execute_with(|| { + assert_noop!( + SubtensorModule::clear_coldkey_swap_announcement(RuntimeOrigin::root()), + BadOrigin + ); + assert_noop!( + SubtensorModule::clear_coldkey_swap_announcement(RuntimeOrigin::none()), + BadOrigin + ); + }); +} + #[test] #[allow(deprecated)] fn test_schedule_swap_coldkey_deprecated() { @@ -1745,3 +1798,24 @@ macro_rules! comprehensive_checks { ); }; } + +fn coldkey_hash_of(coldkey: U256) -> H256 { + ::Hashing::hash_of(&coldkey) +} + +fn announce_coldkey_swap(who: U256, new_coldkey: U256) { + let ed = ExistentialDeposit::get(); + let swap_cost = SubtensorModule::get_key_swap_cost(); + SubtensorModule::add_balance_to_coldkey_account(&who, ed + swap_cost); + + assert_ok!(SubtensorModule::announce_coldkey_swap( + RuntimeOrigin::signed(who), + coldkey_hash_of(new_coldkey), + )); +} + +fn dispute_coldkey_swap(who: U256) { + assert_ok!(SubtensorModule::dispute_coldkey_swap( + RuntimeOrigin::signed(who), + )); +} diff --git a/pallets/subtensor/src/utils/evm.rs b/pallets/subtensor/src/utils/evm.rs index 3363a9ade5..1ac5c65b24 100644 --- a/pallets/subtensor/src/utils/evm.rs +++ b/pallets/subtensor/src/utils/evm.rs @@ -43,7 +43,7 @@ impl Pallet { /// * `signature` - A signed message by the `evm_key` containing the `hotkey` and the hashed /// `block_number`. pub fn do_associate_evm_key( - origin: T::RuntimeOrigin, + origin: OriginFor, netuid: NetUid, evm_key: H160, block_number: u64, diff --git a/pallets/subtensor/src/utils/identity.rs b/pallets/subtensor/src/utils/identity.rs index 1904d0e682..c2406321ed 100644 --- a/pallets/subtensor/src/utils/identity.rs +++ b/pallets/subtensor/src/utils/identity.rs @@ -25,7 +25,7 @@ impl Pallet { /// /// Returns `Ok(())` if the identity is successfully set, otherwise returns an error. pub fn do_set_identity( - origin: T::RuntimeOrigin, + origin: OriginFor, name: Vec, url: Vec, github_repo: Vec, @@ -96,7 +96,7 @@ impl Pallet { /// /// Returns `Ok(())` if the subnet identity is successfully set, otherwise returns an error. pub fn do_set_subnet_identity( - origin: T::RuntimeOrigin, + origin: OriginFor, netuid: NetUid, subnet_name: Vec, github_repo: Vec, diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 75f2d6695d..45462ec600 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -10,7 +10,7 @@ use subtensor_runtime_common::{AlphaBalance, NetUid, NetUidStorageIndex, TaoBala impl Pallet { pub fn ensure_subnet_owner_or_root( - o: T::RuntimeOrigin, + o: OriginFor, netuid: NetUid, ) -> Result, DispatchError> { let coldkey = ensure_signed_or_root(o); @@ -23,7 +23,7 @@ impl Pallet { } pub fn ensure_subnet_owner( - o: T::RuntimeOrigin, + o: OriginFor, netuid: NetUid, ) -> Result { let coldkey = ensure_signed(o); @@ -36,7 +36,7 @@ impl Pallet { /// Ensure owner-or-root with a set of TransactionType rate checks (owner only). pub fn ensure_sn_owner_or_root_with_limits( - o: T::RuntimeOrigin, + o: OriginFor, netuid: NetUid, limits: &[crate::utils::rate_limiting::TransactionType], ) -> Result, DispatchError> { diff --git a/pallets/transaction-fee/src/lib.rs b/pallets/transaction-fee/src/lib.rs index ec9eadf773..068867ddd4 100644 --- a/pallets/transaction-fee/src/lib.rs +++ b/pallets/transaction-fee/src/lib.rs @@ -47,7 +47,7 @@ impl WeightToFeePolynomial for LinearWeightToFee { fn polynomial() -> WeightToFeeCoefficients { let coefficient: WeightToFeeCoefficient = WeightToFeeCoefficient { coeff_integer: TaoBalance::new(0), - coeff_frac: Perbill::from_parts(50_000), + coeff_frac: Perbill::from_parts(500_000), negative: false, degree: 1, };