From 0abfb9b3f7743d9170894c43b118730eff1a1025 Mon Sep 17 00:00:00 2001 From: Samuel Dare Date: Fri, 12 Jul 2024 15:55:31 +0400 Subject: [PATCH] chore: remove coldkey swap rpc --- node/src/rpc.rs | 1 - pallets/subtensor/rpc/src/lib.rs | 68 +------ pallets/subtensor/runtime-api/src/lib.rs | 6 - pallets/subtensor/src/lib.rs | 1 - .../src/schedule_coldkey_swap_info.rs | 176 ------------------ runtime/src/lib.rs | 17 -- 6 files changed, 1 insertion(+), 268 deletions(-) delete mode 100644 pallets/subtensor/src/schedule_coldkey_swap_info.rs diff --git a/node/src/rpc.rs b/node/src/rpc.rs index c169b8530..54f82447f 100644 --- a/node/src/rpc.rs +++ b/node/src/rpc.rs @@ -60,7 +60,6 @@ where C::Api: subtensor_custom_rpc_runtime_api::NeuronInfoRuntimeApi, C::Api: subtensor_custom_rpc_runtime_api::SubnetInfoRuntimeApi, C::Api: subtensor_custom_rpc_runtime_api::SubnetRegistrationRuntimeApi, - C::Api: subtensor_custom_rpc_runtime_api::ColdkeySwapRuntimeApi, B: sc_client_api::Backend + Send + Sync + 'static, P: TransactionPool + 'static, { diff --git a/pallets/subtensor/rpc/src/lib.rs b/pallets/subtensor/rpc/src/lib.rs index 15157be2f..2f71e9c21 100644 --- a/pallets/subtensor/rpc/src/lib.rs +++ b/pallets/subtensor/rpc/src/lib.rs @@ -12,7 +12,7 @@ use std::sync::Arc; use sp_api::ProvideRuntimeApi; pub use subtensor_custom_rpc_runtime_api::{ - ColdkeySwapRuntimeApi, DelegateInfoRuntimeApi, NeuronInfoRuntimeApi, SubnetInfoRuntimeApi, + DelegateInfoRuntimeApi, NeuronInfoRuntimeApi, SubnetInfoRuntimeApi, SubnetRegistrationRuntimeApi, }; @@ -51,24 +51,6 @@ pub trait SubtensorCustomApi { #[method(name = "subnetInfo_getLockCost")] fn get_network_lock_cost(&self, at: Option) -> RpcResult; - #[method(name = "coldkeySwap_getScheduledColdkeySwap")] - fn get_scheduled_coldkey_swap( - &self, - coldkey_account_vec: Vec, - at: Option, - ) -> RpcResult>; - #[method(name = "coldkeySwap_getRemainingArbitrationPeriod")] - fn get_remaining_arbitration_period( - &self, - coldkey_account_vec: Vec, - at: Option, - ) -> RpcResult>; - #[method(name = "coldkeySwap_getColdkeySwapDestinations")] - fn get_coldkey_swap_destinations( - &self, - coldkey_account_vec: Vec, - at: Option, - ) -> RpcResult>; } pub struct SubtensorCustom { @@ -117,7 +99,6 @@ where C::Api: NeuronInfoRuntimeApi, C::Api: SubnetInfoRuntimeApi, C::Api: SubnetRegistrationRuntimeApi, - C::Api: ColdkeySwapRuntimeApi, { fn get_delegates(&self, at: Option<::Hash>) -> RpcResult> { let api = self.client.runtime_api(); @@ -242,51 +223,4 @@ where Error::RuntimeError(format!("Unable to get subnet lock cost: {:?}", e)).into() }) } - - fn get_scheduled_coldkey_swap( - &self, - coldkey_account_vec: Vec, - at: Option<::Hash>, - ) -> RpcResult> { - let api = self.client.runtime_api(); - let at = at.unwrap_or_else(|| self.client.info().best_hash); - - api.get_scheduled_coldkey_swap(at, coldkey_account_vec) - .map_err(|e| { - Error::RuntimeError(format!("Unable to get scheduled coldkey swap: {:?}", e)).into() - }) - } - - fn get_remaining_arbitration_period( - &self, - coldkey_account_vec: Vec, - at: Option<::Hash>, - ) -> RpcResult> { - let api = self.client.runtime_api(); - let at = at.unwrap_or_else(|| self.client.info().best_hash); - - api.get_remaining_arbitration_period(at, coldkey_account_vec) - .map_err(|e| { - Error::RuntimeError(format!( - "Unable to get remaining arbitration period: {:?}", - e - )) - .into() - }) - } - - fn get_coldkey_swap_destinations( - &self, - coldkey_account_vec: Vec, - at: Option<::Hash>, - ) -> RpcResult> { - let api = self.client.runtime_api(); - let at = at.unwrap_or_else(|| self.client.info().best_hash); - - api.get_coldkey_swap_destinations(at, coldkey_account_vec) - .map_err(|e| { - Error::RuntimeError(format!("Unable to get coldkey swap destinations: {:?}", e)) - .into() - }) - } } diff --git a/pallets/subtensor/runtime-api/src/lib.rs b/pallets/subtensor/runtime-api/src/lib.rs index a647d3619..9095ad54a 100644 --- a/pallets/subtensor/runtime-api/src/lib.rs +++ b/pallets/subtensor/runtime-api/src/lib.rs @@ -32,10 +32,4 @@ sp_api::decl_runtime_apis! { pub trait SubnetRegistrationRuntimeApi { fn get_network_registration_cost() -> u64; } - - pub trait ColdkeySwapRuntimeApi { - fn get_scheduled_coldkey_swap( coldkey_account_vec: Vec ) -> Vec; - fn get_remaining_arbitration_period( coldkey_account_vec: Vec ) -> Vec; - fn get_coldkey_swap_destinations( coldkey_account_vec: Vec ) -> Vec; - } } diff --git a/pallets/subtensor/src/lib.rs b/pallets/subtensor/src/lib.rs index 4326fba86..d4def0c27 100644 --- a/pallets/subtensor/src/lib.rs +++ b/pallets/subtensor/src/lib.rs @@ -51,7 +51,6 @@ mod weights; pub mod delegate_info; pub mod neuron_info; -pub mod schedule_coldkey_swap_info; pub mod stake_info; pub mod subnet_info; diff --git a/pallets/subtensor/src/schedule_coldkey_swap_info.rs b/pallets/subtensor/src/schedule_coldkey_swap_info.rs deleted file mode 100644 index e23ad23b6..000000000 --- a/pallets/subtensor/src/schedule_coldkey_swap_info.rs +++ /dev/null @@ -1,176 +0,0 @@ -use super::*; -use codec::Compact; -use frame_support::pallet_prelude::{Decode, Encode}; - -use sp_core::hexdisplay::AsBytesRef; - -#[derive(Decode, Encode, PartialEq, Eq, Clone, Debug)] -pub struct ScheduledColdkeySwapInfo { - old_coldkey: T::AccountId, - new_coldkey: T::AccountId, - arbitration_block: Compact, -} - -impl Pallet { - /// Retrieves the scheduled coldkey swap information for an existing account. - /// - /// # Arguments - /// - /// * `coldkey` - The account ID of the coldkey to check. - /// - /// # Returns - /// - /// * `Option>` - The scheduled coldkey swap information if it exists, otherwise `None`. - /// - /// # Notes - /// - /// This function checks if there are any destination coldkeys associated with the given coldkey. - /// If there are, it retrieves the arbitration block and constructs the `ScheduledColdkeySwapInfo` struct. - fn get_scheduled_coldkey_swap_by_existing_account( - coldkey: AccountIdOf, - ) -> Option> { - let destinations: Vec = ColdkeySwapDestinations::::get(&coldkey); - if destinations.is_empty() { - return None; - } - - let arbitration_block: u64 = ColdkeyArbitrationBlock::::get(&coldkey); - - Some(ScheduledColdkeySwapInfo { - old_coldkey: coldkey, - new_coldkey: destinations.first().cloned().unwrap_or_else(|| { - T::AccountId::decode(&mut sp_runtime::traits::TrailingZeroInput::zeroes()) - .expect("Infinite length input; no invalid inputs for type; qed") - }), - arbitration_block: arbitration_block.into(), - }) - } - - /// Retrieves the scheduled coldkey swap information for a given coldkey account vector. - /// - /// # Arguments - /// - /// * `coldkey_account_vec` - The vector of bytes representing the coldkey account. - /// - /// # Returns - /// - /// * `Option>` - The scheduled coldkey swap information if it exists, otherwise `None`. - /// - /// # Notes - /// - /// This function decodes the coldkey account vector into an account ID and then calls - /// `get_scheduled_coldkey_swap_by_existing_account` to retrieve the swap information. - pub fn get_scheduled_coldkey_swap( - coldkey_account_vec: Vec, - ) -> Option> { - if coldkey_account_vec.len() != 32 { - return None; - } - - let coldkey: AccountIdOf = - T::AccountId::decode(&mut coldkey_account_vec.as_bytes_ref()).ok()?; - Self::get_scheduled_coldkey_swap_by_existing_account(coldkey) - } - - /// Retrieves all scheduled coldkey swaps from storage. - /// - /// # Returns - /// - /// * `Vec>` - A vector containing all scheduled coldkey swap information. - /// - /// # Notes - /// - /// This function iterates over all coldkeys in `ColdkeySwapDestinations` and retrieves their swap information - /// using `get_scheduled_coldkey_swap_by_existing_account`. - pub fn get_all_scheduled_coldkey_swaps() -> Vec> { - let mut scheduled_swaps: Vec> = Vec::new(); - for coldkey in ColdkeySwapDestinations::::iter_keys() { - if let Some(swap_info) = Self::get_scheduled_coldkey_swap_by_existing_account(coldkey) { - scheduled_swaps.push(swap_info); - } - } - scheduled_swaps - } - - /// Retrieves the scheduled coldkey swaps for a given block. - /// - /// # Arguments - /// - /// * `block` - The block number to check for scheduled coldkey swaps. - /// - /// # Returns - /// - /// * `Vec>` - A vector containing the scheduled coldkey swap information for the given block. - /// - /// # Notes - /// - /// This function retrieves the coldkeys to swap at the given block and then retrieves their swap information - /// using `get_scheduled_coldkey_swap_by_existing_account`. - pub fn get_scheduled_coldkey_swaps_at_block(block: u64) -> Vec> { - let coldkeys_to_swap: Vec = ColdkeysToSwapAtBlock::::get(block); - let mut scheduled_swaps: Vec> = Vec::new(); - for coldkey in coldkeys_to_swap { - if let Some(swap_info) = Self::get_scheduled_coldkey_swap_by_existing_account(coldkey) { - scheduled_swaps.push(swap_info); - } - } - scheduled_swaps - } - - /// Retrieves the remaining arbitration period for a given coldkey account vector. - /// - /// # Arguments - /// - /// * `coldkey_account_vec` - The vector of bytes representing the coldkey account. - /// - /// # Returns - /// - /// * `Option` - The remaining arbitration period in blocks if it exists, otherwise `None`. - /// - /// # Notes - /// - /// This function decodes the coldkey account vector into an account ID and calculates the remaining arbitration period - /// by subtracting the current block number from the arbitration block number. - pub fn get_remaining_arbitration_period(coldkey_account_vec: Vec) -> Option { - if coldkey_account_vec.len() != 32 { - return None; - } - - let coldkey: AccountIdOf = - T::AccountId::decode(&mut coldkey_account_vec.as_bytes_ref()).ok()?; - let current_block: u64 = Self::get_current_block_as_u64(); - let arbitration_block: u64 = ColdkeyArbitrationBlock::::get(&coldkey); - - if arbitration_block > current_block { - Some(arbitration_block.saturating_sub(current_block)) - } else { - Some(0) - } - } - - /// Retrieves the destination coldkeys for a given coldkey account vector. - /// - /// # Arguments - /// - /// * `coldkey_account_vec` - The vector of bytes representing the coldkey account. - /// - /// # Returns - /// - /// * `Option>` - A vector containing the destination coldkeys if they exist, otherwise `None`. - /// - /// # Notes - /// - /// This function decodes the coldkey account vector into an account ID and retrieves the destination coldkeys - /// from `ColdkeySwapDestinations`. - pub fn get_coldkey_swap_destinations( - coldkey_account_vec: Vec, - ) -> Option> { - if coldkey_account_vec.len() != 32 { - return None; - } - - let coldkey: AccountIdOf = - T::AccountId::decode(&mut coldkey_account_vec.as_bytes_ref()).ok()?; - Some(ColdkeySwapDestinations::::get(&coldkey)) - } -} diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 3e5af1b43..de8be6e61 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -1664,23 +1664,6 @@ impl_runtime_apis! { SubtensorModule::get_network_lock_cost() } } - - impl subtensor_custom_rpc_runtime_api::ColdkeySwapRuntimeApi for Runtime { - fn get_scheduled_coldkey_swap( coldkey_account_vec: Vec ) -> Vec { - let result = SubtensorModule::get_scheduled_coldkey_swap( coldkey_account_vec ); - result.encode() - } - - fn get_remaining_arbitration_period( coldkey_account_vec: Vec ) -> Vec { - let result = SubtensorModule::get_remaining_arbitration_period( coldkey_account_vec ); - result.encode() - } - - fn get_coldkey_swap_destinations( coldkey_account_vec: Vec ) -> Vec { - let result = SubtensorModule::get_coldkey_swap_destinations( coldkey_account_vec ); - result.encode() - } - } } // #[cfg(test)]