From f60f68fd196fcf6a286d550fd8543cc7df9721b8 Mon Sep 17 00:00:00 2001 From: Samuel Dare Date: Fri, 16 Aug 2024 14:01:59 +0400 Subject: [PATCH 1/3] chore: give funds to alice , bob and charlie --- node/src/chain_spec/raonet.rs | 34 ++++++++++++++++++++++++++++++++++ scripts/specs/raonet.json | 5 ++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/node/src/chain_spec/raonet.rs b/node/src/chain_spec/raonet.rs index 99c4eb327..1266bd8c8 100644 --- a/node/src/chain_spec/raonet.rs +++ b/node/src/chain_spec/raonet.rs @@ -3,6 +3,17 @@ use super::*; +/// Generates the configuration for the Raonet chain. +/// +/// # Returns +/// +/// * `Result` - The chain specification or an error message. +/// +/// # Example +/// +/// ```rust +/// let chain_spec = raonet_config().expect("Failed to generate Raonet config"); +/// ``` pub fn raonet_config() -> Result { let wasm_binary = WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?; @@ -44,11 +55,34 @@ pub fn raonet_config() -> Result { .build()) } +/// Generates the genesis configuration for the Raonet chain. +/// +/// # Arguments +/// +/// * `initial_authorities` - A vector of initial authorities (AuraId, GrandpaId). +/// * `_enable_println` - A boolean flag to enable println (currently unused). +/// +/// # Returns +/// +/// * `serde_json::Value` - The genesis configuration as a JSON value. fn raonet_genesis( initial_authorities: Vec<(AuraId, GrandpaId)>, _enable_println: bool, ) -> serde_json::Value { let mut balances = vec![ + // Add Alice, Bob, and Charlie with 10 trillion tokens each + ( + get_account_id_from_seed::("Alice"), + 10_000_000_000_000u128, + ), + ( + get_account_id_from_seed::("Bob"), + 10_000_000_000_000u128, + ), + ( + get_account_id_from_seed::("Charlie"), + 10_000_000_000_000u128, + ), ( ::from_ss58check("5FRo4vab84LM3aiK4DijnVawGDKagLGLzfn95j9tjDaHja8Z").unwrap(), 100_000_000_000u128, diff --git a/scripts/specs/raonet.json b/scripts/specs/raonet.json index c233f949d..9616108bb 100644 --- a/scripts/specs/raonet.json +++ b/scripts/specs/raonet.json @@ -29,6 +29,7 @@ "0x26aa394eea5630e07c48ae0c9558cef7b99d880ec681799c0cf30e8886371da91b167e23cbebb7878d58f0cfbe24fade1e7baeac6e4320c5c6b73a5eb854500b7ff2b8687ed317db704b4abad0a45f65": "0x0000000000000000010000000000000000e87648170000000000000000000000000000000000000000000000000000000000000000000080", "0x26aa394eea5630e07c48ae0c9558cef7b99d880ec681799c0cf30e8886371da938dd096bcb24cc8c4e13c4599ef5c3b81493fb01f6bc22dc61058060bda668bd9176f1d65b6d66d2049e89977e5bd668": "0x0000000000000000010000000000000000e87648170000000000000000000000000000000000000000000000000000000000000000000080", "0x26aa394eea5630e07c48ae0c9558cef7b99d880ec681799c0cf30e8886371da9429fc86d7333582b998a35c8896a77ce3ede627d972b461687bb5b61e787755834a8766c2a97cdad7c3d0057b21e931e": "0x0000000000000000010000000000000000e87648170000000000000000000000000000000000000000000000000000000000000000000080", + "0x26aa394eea5630e07c48ae0c9558cef7b99d880ec681799c0cf30e8886371da94f9aea1afa791265fae359272badc1cf8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48": "0x0000000000000000010000000000000000a0724e180900000000000000000000000000000000000000000000000000000000000000000080", "0x26aa394eea5630e07c48ae0c9558cef7b99d880ec681799c0cf30e8886371da964e5f34e3743dc8069c20d13b30c5fbddc84503cd7f06da23828bf915f198ea549d0d4f4398c32c4d84154e819a8c23b": "0x0000000000000000010000000000000000e87648170000000000000000000000000000000000000000000000000000000000000000000080", "0x26aa394eea5630e07c48ae0c9558cef7b99d880ec681799c0cf30e8886371da96a55c6839a54c8ca50de2626b6f039dce0730733a54b0595ceddaf2b0d4089a777c1dd8bdeba334656beda1567e7bc0c": "0x0000000000000000010000000000000000e87648170000000000000000000000000000000000000000000000000000000000000000000080", "0x26aa394eea5630e07c48ae0c9558cef7b99d880ec681799c0cf30e8886371da9716d4f62e450a2bd8928b2962b8c0501e41ff5d2aa23e35a4830fdd5a4191abb9c9c804f0aa315d257bcd132e91a332d": "0x0000000000000000010000000000000000e87648170000000000000000000000000000000000000000000000000000000000000000000080", @@ -39,8 +40,10 @@ "0x26aa394eea5630e07c48ae0c9558cef7b99d880ec681799c0cf30e8886371da98f65b4d1e52ab839c9d2ac69e6a0e41f3e31d977c148833c83e2ee95e74034a1b3b32946e5c5ae4ae9ce4d1ac2f0b444": "0x0000000000000000010000000000000000e87648170000000000000000000000000000000000000000000000000000000000000000000080", "0x26aa394eea5630e07c48ae0c9558cef7b99d880ec681799c0cf30e8886371da9a027f81e14ea99ce4073009c0d87ae906a7952ece498544ab3bd8978d5350f0f475846289d80dceafca38070c9f27832": "0x0000000000000000010000000000000000e87648170000000000000000000000000000000000000000000000000000000000000000000080", "0x26aa394eea5630e07c48ae0c9558cef7b99d880ec681799c0cf30e8886371da9a7a93cd301b14fb55b5551dbf15d9f361ccfe35ab623e7eaec1590656d36a74bc8582dc3f1f769a1838d075ff9e1cd6a": "0x0000000000000000010000000000000000e87648170000000000000000000000000000000000000000000000000000000000000000000080", + "0x26aa394eea5630e07c48ae0c9558cef7b99d880ec681799c0cf30e8886371da9b0edae20838083f2cde1c4080db8cf8090b5ab205c6974c9ea841be688864633dc9ca8a357843eeacf2314649965fe22": "0x0000000000000000010000000000000000a0724e180900000000000000000000000000000000000000000000000000000000000000000080", "0x26aa394eea5630e07c48ae0c9558cef7b99d880ec681799c0cf30e8886371da9b65645a40eeb88fbfc80422e63f5bb88ba5aad47261de88951fda9fd78998be184cd208349267ad95320470daaf0694b": "0x0000000000000000010000000000000000e87648170000000000000000000000000000000000000000000000000000000000000000000080", "0x26aa394eea5630e07c48ae0c9558cef7b99d880ec681799c0cf30e8886371da9cfa073cf1f3eb4ae5db2029ea6f52ebc9095a72dd4aa58af5f43914ae500754b4bc20d89ba9c44e84eb386f222b77b6a": "0x0000000000000000010000000000000000e87648170000000000000000000000000000000000000000000000000000000000000000000080", + "0x26aa394eea5630e07c48ae0c9558cef7b99d880ec681799c0cf30e8886371da9de1e86a9a8c739864cf3cc5ec2bea59fd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d": "0x0000000000000000010000000000000000a0724e180900000000000000000000000000000000000000000000000000000000000000000080", "0x26aa394eea5630e07c48ae0c9558cef7b99d880ec681799c0cf30e8886371da9df3cf604c2c25efbc864feb8f6d4feed48ea0f98e9c83ff536e748efa8cc4a708009d9896c9adf2910395a22742dcb38": "0x0000000000000000010000000000000000e87648170000000000000000000000000000000000000000000000000000000000000000000080", "0x26aa394eea5630e07c48ae0c9558cef7b99d880ec681799c0cf30e8886371da9e99a494997e77bbb23d2c85322a5f7e5d4974d8d2d4c8f7005f81c70f222738c6d37010ae219037481fe75c5cceb886f": "0x0000000000000000010000000000000000e87648170000000000000000000000000000000000000000000000000000000000000000000080", "0x26aa394eea5630e07c48ae0c9558cef7b99d880ec681799c0cf30e8886371da9f128d73105ad2727b45028c061fe9141b099776c4958437cd72bfefe9f73788f3a06734dc9c4350d2acc886eecabb10b": "0x0000000000000000010000000000000000e87648170000000000000000000000000000000000000000000000000000000000000000000080", @@ -83,7 +86,7 @@ "0xb8c7f96c134ebb49eb7e77df71f098ad4e7b9012096b41c4eb3aaf947f6ea429": "0x0000", "0xbd2a529379475088d3e29a918cd478724e7b9012096b41c4eb3aaf947f6ea429": "0x0000", "0xc2261276cc9d1f8598ea4b6a74b15c2f4e7b9012096b41c4eb3aaf947f6ea429": "0x0100", - "0xc2261276cc9d1f8598ea4b6a74b15c2f57c875e4cff74148e4628f264b974c80": "0x0008c1f1e8010000", + "0xc2261276cc9d1f8598ea4b6a74b15c2f57c875e4cff74148e4628f264b974c80": "0x00e818dd311d0000", "0xca407206ec1ab726b2636c4b145ac2874e7b9012096b41c4eb3aaf947f6ea429": "0x0000", "0xd5e1a2fa16732ce6906189438c0a82c64e7b9012096b41c4eb3aaf947f6ea429": "0x0000", "0xd8f314b7f4e6b095f0f8ee4656a448254e7b9012096b41c4eb3aaf947f6ea429": "0x0100", From 391a427327598daa2cbb45e433ffac23f6b59b7b Mon Sep 17 00:00:00 2001 From: Samuel Dare Date: Fri, 16 Aug 2024 17:08:29 +0400 Subject: [PATCH 2/3] fix: update_subnet_owner --- pallets/subtensor/src/staking/lock.rs | 17 ++- pallets/subtensor/tests/lock.rs | 186 -------------------------- 2 files changed, 11 insertions(+), 192 deletions(-) diff --git a/pallets/subtensor/src/staking/lock.rs b/pallets/subtensor/src/staking/lock.rs index eabfcd038..e21bdacb5 100644 --- a/pallets/subtensor/src/staking/lock.rs +++ b/pallets/subtensor/src/staking/lock.rs @@ -77,7 +77,7 @@ impl Pallet { netuid: u16, ) -> u64 { let (locked, _, end) = Locks::::get((netuid, hotkey.clone(), coldkey.clone())); - + Self::calculate_conviction(locked, end, Self::get_current_block_as_u64()) } @@ -318,8 +318,8 @@ impl Pallet { // Set the total subnet Conviction. let largest_conviction = convictions.iter().max().cloned().unwrap_or(1); - SubnetLocked::::insert( netuid, total_conviction ) ; - LargestLocked::::insert( netuid, largest_conviction ); + SubnetLocked::::insert(netuid, total_conviction); + LargestLocked::::insert(netuid, largest_conviction); // Calculate shares using the lion's share distribution let shares: Vec = Self::calculate_lions_share(convictions, 20); @@ -463,12 +463,16 @@ impl Pallet { // Handle the case where no locks exist for the subnet if hotkey_convictions.is_empty() { log::warn!("No locks found for subnet {}", netuid); + SubnetOwner::::remove(netuid); + SubnetLocked::::remove(netuid); return; } // Implement a minimum conviction threshold for becoming a subnet owner let min_conviction_threshold = I96F32::from_num(1000); // Example threshold, adjust as needed if max_total_conviction < min_conviction_threshold { + SubnetOwner::::remove(netuid); + SubnetLocked::::remove(netuid); return; } @@ -476,6 +480,8 @@ impl Pallet { if let Some(hotkey) = max_conviction_hotkey { let owning_coldkey = Self::get_owning_coldkey_for_hotkey(&hotkey); SubnetOwner::::insert(netuid, owning_coldkey.clone()); + // Set the SubnetLocked value to the maximum conviction + SubnetLocked::::insert(netuid, max_total_conviction.to_num::()); } // Implement a tie-breaking mechanism for equal conviction scores @@ -486,8 +492,7 @@ impl Pallet { if tied_hotkeys.len() > 1 { // Use a deterministic method to break ties, e.g., lowest hotkey value - if let Some((winning_hotkey, _)) = - tied_hotkeys.iter().min_by_key(|(hotkey, _)| hotkey) + if let Some((winning_hotkey, _)) = tied_hotkeys.iter().min_by_key(|(hotkey, _)| hotkey) { let owning_coldkey = Self::get_owning_coldkey_for_hotkey(winning_hotkey); SubnetOwner::::insert(netuid, owning_coldkey.clone()); @@ -536,7 +541,7 @@ impl Pallet { -I96F32::from_num(lock_duration).saturating_div(I96F32::from_num(lock_interval_blocks)); let exp_term = I96F32::from_num(1) - exp_safe_f96(I96F32::from_num(time_factor)); let conviction_score = I96F32::from_num(lock_amount).saturating_mul(exp_term); - + conviction_score.to_num::() } diff --git a/pallets/subtensor/tests/lock.rs b/pallets/subtensor/tests/lock.rs index 18ab66daf..849c434db 100644 --- a/pallets/subtensor/tests/lock.rs +++ b/pallets/subtensor/tests/lock.rs @@ -1432,192 +1432,6 @@ fn test_calculate_conviction_consistency() { }); } -// pub fn calculate_lions_share(convictions: Vec, sharpness: u32) -> Vec { -// // Handle empty convictions vector -// if convictions.is_empty() { -// return Vec::new(); -// } - -// // For a single conviction, return a vector with a single element of value 1 -// if convictions.len() == 1 { -// return vec![I96F32::from_num(1)]; -// } - -// // Find the maximum conviction -// let max_conviction = convictions.iter().max().cloned().unwrap_or(1); -// // If the maximum conviction is zero, return a vector of zeros -// if max_conviction == 0 { -// return vec![I96F32::from_num(0); convictions.len()]; -// } - -// // Normalize convictions and apply exponential function -// let mut powered_convictions: Vec = Vec::with_capacity(convictions.len()); -// for c in convictions.iter() { -// let normalized = I96F32::from_num(*c) / I96F32::from_num(max_conviction); -// // Use checked_mul to prevent overflow in exponentiation -// let powered = exp_safe_f96(I96F32::from_num(sharpness).saturating_mul(normalized - I96F32::from_num(1))); -// powered_convictions.push(powered); -// } - -// // Calculate total powered conviction -// let total_powered: I96F32 = powered_convictions.iter().sum(); - -// // Handle case where total_powered is zero to avoid division by zero -// if total_powered == I96F32::from_num(0) { -// return vec![I96F32::from_num(0); convictions.len()]; -// } - -// // Calculate shares -// let shares: Vec = powered_convictions.into_iter().map(|pc| { -// pc / total_powered -// }).collect(); - -// shares -// } -// pub fn calculate_conviction(lock_amount: u64, end_block: u64, current_block: u64) -> u64 { -// let lock_duration = end_block.saturating_sub(current_block); -// let time_factor = -I96F32::from_num(lock_duration).saturating_div(I96F32::from_num(Self::get_lock_interval_blocks())); // Convert days to blocks -// let exp_term = I96F32::from_num(1) - exp_safe_f96(I96F32::from_num(time_factor)); -// let conviction_score = I96F32::from_num(lock_amount).saturating_mul(exp_term); -// let final_score = conviction_score.to_num::(); -// final_score -// } - -// pub fn get_owning_coldkey_for_hotkey(hotkey: &T::AccountId) -> T::AccountId { -// Owner::::get(hotkey) -// } -// pub fn distribute_owner_cut(netuid: u16, amount: u64) -> u64 { -// // Get the current block number -// let current_block = Self::get_current_block_as_u64(); - -// // Initialize variables to track total conviction and individual hotkey convictions -// let mut total_conviction: u64 = 0; -// let mut hotkey_convictions: BTreeMap = BTreeMap::new(); - -// // Calculate total conviction and individual hotkey convictions -// for ((iter_netuid, hotkey, _), (lock_amount, _, end_block)) in Locks::::iter() { -// if iter_netuid != netuid { continue; } -// // Calculate conviction for each lock -// let conviction = Self::calculate_conviction(lock_amount, end_block, current_block); -// // Add conviction to the hotkey's total -// *hotkey_convictions.entry(hotkey).or_default() += conviction; -// // Add to the total conviction -// total_conviction = total_conviction.saturating_add(conviction); -// } - -// // If there's no conviction, return the full amount -// if total_conviction == 0 { -// return amount; -// } - -// // Convert convictions to a vector for the lion's share calculation -// let convictions: Vec = hotkey_convictions.values().cloned().collect(); - -// // Calculate shares using the lion's share distribution -// let shares: Vec = Self::calculate_lions_share(convictions, 20); - -// // Initialize variable to track remaining amount to distribute -// let mut remaining_amount = amount; - -// // Distribute the owner cut based on calculated shares -// for ((hotkey, _), share) in hotkey_convictions.iter().zip(shares.iter()) { -// // Calculate the share for this hotkey -// let share_amount = I96F32::from_num(amount) -// .checked_mul(*share) -// .unwrap_or(I96F32::from_num(0)) -// .to_num::(); - -// // Get the coldkey associated with this hotkey -// let owner_coldkey = Self::get_owning_coldkey_for_hotkey(&hotkey); - -// // Emit the calculated share into the subnet for this hotkey -// Self::emit_into_subnet(&hotkey, &owner_coldkey, netuid, share_amount); - -// // Add the share to the lock. -// if Locks::::contains_key((netuid, hotkey.clone(), owner_coldkey.clone())) { -// let (current_lock, start_block, end_block) = Locks::::get((netuid, hotkey.clone(), owner_coldkey.clone())); -// let new_lock = current_lock.saturating_add(share_amount); -// Locks::::insert( -// (netuid, hotkey.clone(), owner_coldkey.clone()), -// (new_lock, start_block, end_block) -// ); -// } - -// // Subtract the distributed share from the remaining amount -// remaining_amount = remaining_amount.saturating_sub(share_amount); -// } - -// // Return any undistributed amount -// remaining_amount -// } - -// pub fn update_subnet_owner(netuid: u16) { -// let mut max_total_conviction: I96F32 = I96F32::from_num(0.0); -// let mut max_conviction_hotkey = None; -// let mut hotkey_convictions = BTreeMap::new(); -// let current_block = Self::get_current_block_as_u64(); - -// // Iterate through all locks in the subnet -// for ((iter_netuid, iter_hotkey, _), (lock_amount, _, end_block)) in Locks::::iter() { -// // Skip if the subnet does not match. -// if iter_netuid != netuid { continue; } - -// // Calculate conviction score based on lock amount and duration -// let conviction_score = I96F32::from_num(Self::calculate_conviction(lock_amount, end_block, current_block)); - -// // Accumulate conviction scores for each hotkey -// let total_conviction = hotkey_convictions.entry(iter_hotkey.clone()).or_insert(I96F32::from_num(0)); -// *total_conviction = total_conviction.saturating_add(conviction_score); - -// // Update max conviction if current hotkey has higher total conviction -// if *total_conviction > max_total_conviction { -// max_total_conviction = *total_conviction; -// max_conviction_hotkey = Some(iter_hotkey.clone()); -// } -// } - -// // Set the total subnet Conviction. -// SubnetLocked::::insert(netuid, max_total_conviction.to_num::()); - -// // Handle the case where no locks exist for the subnet -// if hotkey_convictions.is_empty() { -// log::warn!("No locks found for subnet {}", netuid); -// return; -// } - -// // Implement a minimum conviction threshold for becoming a subnet owner -// let min_conviction_threshold = I96F32::from_num(1000); // Example threshold, adjust as needed -// if max_total_conviction < min_conviction_threshold { -// log::info!("No hotkey meets the minimum conviction threshold for subnet {}", netuid); -// return; -// } - -// // Set the subnet owner to the coldkey of the hotkey with highest conviction -// if let Some(hotkey) = max_conviction_hotkey { -// let owning_coldkey = Self::get_owning_coldkey_for_hotkey(&hotkey); -// SubnetOwner::::insert(netuid, owning_coldkey); -// } - -// // Implement a tie-breaking mechanism for equal conviction scores -// let tied_hotkeys: Vec<_> = hotkey_convictions -// .iter() -// .filter(|(_, &conviction)| conviction == max_total_conviction) -// .collect(); - -// if tied_hotkeys.len() > 1 { -// // Use a deterministic method to break ties, e.g., lowest hotkey value -// if let Some((winning_hotkey, _)) = tied_hotkeys.iter().min_by_key(|(&ref hotkey, _)| hotkey) { -// let owning_coldkey = Self::get_owning_coldkey_for_hotkey(winning_hotkey); -// SubnetOwner::::insert(netuid, owning_coldkey); -// } -// } - -// // Log performance metrics for large subnets -// if hotkey_convictions.len() > 1000 { -// log::warn!("Large subnet {} processed with {} hotkeys", netuid, hotkey_convictions.len()); -// } -// } - // SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --test lock -- test_distribute_owner_cut_basic --exact --nocapture #[test] fn test_distribute_owner_cut_basic() { From 8d36c425b89dbdd929f596229e48f432b61a09fe Mon Sep 17 00:00:00 2001 From: Samuel Dare Date: Fri, 16 Aug 2024 18:37:01 +0400 Subject: [PATCH 3/3] chore: comment out "deprecated tests" --- node/src/chain_spec/raonet.rs | 112 ++++++++++++++++----- pallets/subtensor/src/staking/add_stake.rs | 1 - pallets/subtensor/tests/staking.rs | 104 +++++++++---------- 3 files changed, 137 insertions(+), 80 deletions(-) diff --git a/node/src/chain_spec/raonet.rs b/node/src/chain_spec/raonet.rs index 1266bd8c8..0acf17c6e 100644 --- a/node/src/chain_spec/raonet.rs +++ b/node/src/chain_spec/raonet.rs @@ -9,11 +9,6 @@ use super::*; /// /// * `Result` - The chain specification or an error message. /// -/// # Example -/// -/// ```rust -/// let chain_spec = raonet_config().expect("Failed to generate Raonet config"); -/// ``` pub fn raonet_config() -> Result { let wasm_binary = WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?; @@ -84,89 +79,152 @@ fn raonet_genesis( 10_000_000_000_000u128, ), ( - ::from_ss58check("5FRo4vab84LM3aiK4DijnVawGDKagLGLzfn95j9tjDaHja8Z").unwrap(), + ::from_ss58check( + "5FRo4vab84LM3aiK4DijnVawGDKagLGLzfn95j9tjDaHja8Z", + ) + .unwrap(), 100_000_000_000u128, ), ( - ::from_ss58check("5H3qhPGzKMNV9fTPuizxzp8azyFRMd4BnheSuwN9Qxb5Cz3u").unwrap(), // Greg + ::from_ss58check( + "5H3qhPGzKMNV9fTPuizxzp8azyFRMd4BnheSuwN9Qxb5Cz3u", + ) + .unwrap(), // Greg 100_000_000_000u128, ), ( - ::from_ss58check("5H8zkg8K9hkM5PSeumivNXGuK8J8cUjtwEL9PfyqmgWELPka").unwrap(), // William + ::from_ss58check( + "5H8zkg8K9hkM5PSeumivNXGuK8J8cUjtwEL9PfyqmgWELPka", + ) + .unwrap(), // William 100_000_000_000u128, ), ( - ::from_ss58check("5Ckg2z5NdrfbXpsPtZuVYXxRWh283QWw1gbXfN8CJC3tmxnY").unwrap(), // Dick + ::from_ss58check( + "5Ckg2z5NdrfbXpsPtZuVYXxRWh283QWw1gbXfN8CJC3tmxnY", + ) + .unwrap(), // Dick 100_000_000_000u128, ), ( - ::from_ss58check("5CiUxGA5dTh1cPdgH67Kt62x4w5aKubnmWZMYSrZzoB4hpQi").unwrap(), // Michal + ::from_ss58check( + "5CiUxGA5dTh1cPdgH67Kt62x4w5aKubnmWZMYSrZzoB4hpQi", + ) + .unwrap(), // Michal 100_000_000_000u128, ), ( - ::from_ss58check("5FLHD4eZkPStKUG7p9B1VPjD4w93Fxncf6JG5EK2uRcELmJy").unwrap(), // Carlos + ::from_ss58check( + "5FLHD4eZkPStKUG7p9B1VPjD4w93Fxncf6JG5EK2uRcELmJy", + ) + .unwrap(), // Carlos 100_000_000_000u128, ), ( - ::from_ss58check("5G4FseBtaQd8sqeC98ZEL7xgtF2GSdueMXwUs8vsBENs4Ysn").unwrap(), // Sai + ::from_ss58check( + "5G4FseBtaQd8sqeC98ZEL7xgtF2GSdueMXwUs8vsBENs4Ysn", + ) + .unwrap(), // Sai 100_000_000_000u128, ), ( - ::from_ss58check("5DiJqQoQdpgKaLz97Fk8ZkChAxMqf2mF2pVa6xDKYH8Cf9Sx").unwrap(), // Xavier + ::from_ss58check( + "5DiJqQoQdpgKaLz97Fk8ZkChAxMqf2mF2pVa6xDKYH8Cf9Sx", + ) + .unwrap(), // Xavier 100_000_000_000u128, ), ( - ::from_ss58check("5EUJyRh3x9QftnUw7taFk3Xen6fCQgdc9ko8ort51RnR6LCn").unwrap(), // Elo + ::from_ss58check( + "5EUJyRh3x9QftnUw7taFk3Xen6fCQgdc9ko8ort51RnR6LCn", + ) + .unwrap(), // Elo 100_000_000_000u128, ), ( - ::from_ss58check("5FREUpwG4wJYr1Usyp1i5XmxM3ycGTfvtjJtrSZETPgvh4Hx").unwrap(), // Roman + ::from_ss58check( + "5FREUpwG4wJYr1Usyp1i5XmxM3ycGTfvtjJtrSZETPgvh4Hx", + ) + .unwrap(), // Roman 100_000_000_000u128, ), ( - ::from_ss58check("5GxREgL1Kvuv1kixbY2oJe36Q2HnWqTcfakBZqTPKWiPpVxf").unwrap(), // Abe + ::from_ss58check( + "5GxREgL1Kvuv1kixbY2oJe36Q2HnWqTcfakBZqTPKWiPpVxf", + ) + .unwrap(), // Abe 100_000_000_000u128, ), ( - ::from_ss58check("5GsSxM8p1TYrpXfCx7Un5cTp1fr1RwHJczYDUUn8Xjnqj9Sk").unwrap(), // Nico + ::from_ss58check( + "5GsSxM8p1TYrpXfCx7Un5cTp1fr1RwHJczYDUUn8Xjnqj9Sk", + ) + .unwrap(), // Nico 100_000_000_000u128, ), ( - ::from_ss58check("5HjEUemUaXSkxPcxGYiLykHmi5VfXBh5NCeNXYMbj9akYHbn").unwrap(), // Jip + ::from_ss58check( + "5HjEUemUaXSkxPcxGYiLykHmi5VfXBh5NCeNXYMbj9akYHbn", + ) + .unwrap(), // Jip 100_000_000_000u128, ), ( - ::from_ss58check("5DUFdkP4rJrkXq9pfrWMHQS8zgiwXBZRgw2MMEAnBot59Taz").unwrap(), // Bob + ::from_ss58check( + "5DUFdkP4rJrkXq9pfrWMHQS8zgiwXBZRgw2MMEAnBot59Taz", + ) + .unwrap(), // Bob 100_000_000_000u128, ), ( - ::from_ss58check("5CoSC9nRDT4CbnEGLCHcC8PxgpJsWpSdF3RLnTx2aBvX3qPu").unwrap(), // Faybian + ::from_ss58check( + "5CoSC9nRDT4CbnEGLCHcC8PxgpJsWpSdF3RLnTx2aBvX3qPu", + ) + .unwrap(), // Faybian 100_000_000_000u128, ), ( - ::from_ss58check("5CXgmrp6Ts5igz9uxSdQQy9ERUVaJFtswzaSBUXhb3Ci7drK").unwrap(), // Special K + ::from_ss58check( + "5CXgmrp6Ts5igz9uxSdQQy9ERUVaJFtswzaSBUXhb3Ci7drK", + ) + .unwrap(), // Special K 100_000_000_000u128, ), ( - ::from_ss58check("5HDpGZLNYSxHGWVhsPgKRDKVM6oob7MMnwxdpU8dBP7N51dX").unwrap(), // Michal + ::from_ss58check( + "5HDpGZLNYSxHGWVhsPgKRDKVM6oob7MMnwxdpU8dBP7N51dX", + ) + .unwrap(), // Michal 100_000_000_000u128, ), ( - ::from_ss58check("5GH3haJWuJjcZWuC7iFGtaVajJNEpNg2Guaqyf71y9uDfFrt").unwrap(), // Isa + ::from_ss58check( + "5GH3haJWuJjcZWuC7iFGtaVajJNEpNg2Guaqyf71y9uDfFrt", + ) + .unwrap(), // Isa 100_000_000_000u128, ), ( - ::from_ss58check("5HTukLb2y59rrL5tM9RMw3baziCFZUeSZATWMWHgSrNknc9A").unwrap(), // Gus + ::from_ss58check( + "5HTukLb2y59rrL5tM9RMw3baziCFZUeSZATWMWHgSrNknc9A", + ) + .unwrap(), // Gus 100_000_000_000u128, ), ( - ::from_ss58check("5CkV7PPFWh8EihTK5uLm7VNF4C9hiKJ9UeJJwQuByn3bx82L").unwrap(), // Carrot + ::from_ss58check( + "5CkV7PPFWh8EihTK5uLm7VNF4C9hiKJ9UeJJwQuByn3bx82L", + ) + .unwrap(), // Carrot 100_000_000_000u128, ), ( - ::from_ss58check("5DV8tTjq8EXE6KmoCbJ3xaN54HTXsfev5ZyKJEQPyTcm4MmE").unwrap(), // Paul + ::from_ss58check( + "5DV8tTjq8EXE6KmoCbJ3xaN54HTXsfev5ZyKJEQPyTcm4MmE", + ) + .unwrap(), // Paul 100_000_000_000u128, - ) + ), ]; // Check if the environment variable is set diff --git a/pallets/subtensor/src/staking/add_stake.rs b/pallets/subtensor/src/staking/add_stake.rs index 996569528..552d153ea 100644 --- a/pallets/subtensor/src/staking/add_stake.rs +++ b/pallets/subtensor/src/staking/add_stake.rs @@ -1,5 +1,4 @@ use super::*; -// use substrate_fixed::types::I96F32; impl Pallet { /// ---- The implementation for the extrinsic add_stake: Adds stake to a hotkey account. diff --git a/pallets/subtensor/tests/staking.rs b/pallets/subtensor/tests/staking.rs index 170eff3a2..bd65ab344 100644 --- a/pallets/subtensor/tests/staking.rs +++ b/pallets/subtensor/tests/staking.rs @@ -184,36 +184,36 @@ fn test_add_stake_err_signature() { // } // SKIP_WASM_BUILD=1 RUST_LOG=info cargo test --test staking -- test_add_stake_err_neuron_does_not_belong_to_coldkey --exact --nocapture -#[test] -fn test_add_stake_err_neuron_does_not_belong_to_coldkey() { - new_test_ext(1).execute_with(|| { - let coldkey_id = U256::from(544); - let hotkey_id = U256::from(54544); - let other_cold_key = U256::from(99498); - let netuid: u16 = 1; - let tempo: u16 = 13; - let start_nonce: u64 = 0; +// #[test] +// fn test_add_stake_err_neuron_does_not_belong_to_coldkey() { +// new_test_ext(1).execute_with(|| { +// let coldkey_id = U256::from(544); +// let hotkey_id = U256::from(54544); +// let other_cold_key = U256::from(99498); +// let netuid: u16 = 1; +// let tempo: u16 = 13; +// let start_nonce: u64 = 0; - //add network - add_network(netuid, tempo, 0); +// //add network +// add_network(netuid, tempo, 0); - register_ok_neuron(netuid, hotkey_id, coldkey_id, start_nonce); - // Give it some $$$ in his coldkey balance - SubtensorModule::add_balance_to_coldkey_account(&other_cold_key, 100000); +// register_ok_neuron(netuid, hotkey_id, coldkey_id, start_nonce); +// // Give it some $$$ in his coldkey balance +// SubtensorModule::add_balance_to_coldkey_account(&other_cold_key, 100000); - // Perform the request which is signed by a different cold key - let result = SubtensorModule::add_stake( - <::RuntimeOrigin>::signed(other_cold_key), - hotkey_id, - netuid, - 1000, - ); - assert_eq!( - result, - Err(Error::::HotKeyNotDelegateAndSignerNotOwnHotKey.into()) - ); - }); -} +// // Perform the request which is signed by a different cold key +// let result = SubtensorModule::add_stake( +// <::RuntimeOrigin>::signed(other_cold_key), +// hotkey_id, +// netuid, +// 1000, +// ); +// assert_eq!( +// result, +// Err(Error::::HotKeyNotDelegateAndSignerNotOwnHotKey.into()) +// ); +// }); +// } // SKIP_WASM_BUILD=1 RUST_LOG=info cargo test --test staking -- test_add_stake_err_not_enough_belance --exact --nocapture #[test] @@ -691,34 +691,34 @@ fn test_remove_stake_err_signature() { } // SKIP_WASM_BUILD=1 RUST_LOG=info cargo test --test staking -- test_remove_stake_err_hotkey_does_not_belong_to_coldkey --exact --nocapture -#[test] -fn test_remove_stake_err_hotkey_does_not_belong_to_coldkey() { - new_test_ext(1).execute_with(|| { - let coldkey_id = U256::from(544); - let hotkey_id = U256::from(54544); - let other_cold_key = U256::from(99498); - let netuid: u16 = 1; - let tempo: u16 = 13; - let start_nonce: u64 = 0; +// #[test] +// fn test_remove_stake_err_hotkey_does_not_belong_to_coldkey() { +// new_test_ext(1).execute_with(|| { +// let coldkey_id = U256::from(544); +// let hotkey_id = U256::from(54544); +// let other_cold_key = U256::from(99498); +// let netuid: u16 = 1; +// let tempo: u16 = 13; +// let start_nonce: u64 = 0; - //add network - add_network(netuid, tempo, 0); +// //add network +// add_network(netuid, tempo, 0); - register_ok_neuron(netuid, hotkey_id, coldkey_id, start_nonce); +// register_ok_neuron(netuid, hotkey_id, coldkey_id, start_nonce); - // Perform the request which is signed by a different cold key - let result = SubtensorModule::remove_stake( - <::RuntimeOrigin>::signed(other_cold_key), - hotkey_id, - netuid, - 1000, - ); - assert_eq!( - result, - Err(Error::::HotKeyNotDelegateAndSignerNotOwnHotKey.into()) - ); - }); -} +// // Perform the request which is signed by a different cold key +// let result = SubtensorModule::remove_stake( +// <::RuntimeOrigin>::signed(other_cold_key), +// hotkey_id, +// netuid, +// 1000, +// ); +// assert_eq!( +// result, +// Err(Error::::HotKeyNotDelegateAndSignerNotOwnHotKey.into()) +// ); +// }); +// } // SKIP_WASM_BUILD=1 RUST_LOG=info cargo test --test staking -- test_remove_stake_no_enough_stake --exact --nocapture #[test]