From c2d5b1527676080f8aad4f9785e0cc737de26396 Mon Sep 17 00:00:00 2001 From: Andreea Popescu Date: Wed, 22 Jan 2025 12:52:27 +0000 Subject: [PATCH 01/45] yuma bonds scale individually --- pallets/subtensor/src/epoch/math.rs | 27 +++++++++++-- pallets/subtensor/src/epoch/run_epoch.rs | 49 ++++++++++-------------- 2 files changed, 44 insertions(+), 32 deletions(-) diff --git a/pallets/subtensor/src/epoch/math.rs b/pallets/subtensor/src/epoch/math.rs index b4f23ced83..c660b7f02b 100644 --- a/pallets/subtensor/src/epoch/math.rs +++ b/pallets/subtensor/src/epoch/math.rs @@ -1207,6 +1207,15 @@ pub fn interpolate_sparse( result } +// Element-wise product of two vectors. +#[allow(dead_code)] +pub fn vec_mul(a: &[I32F32], b: &[I32F32]) -> Vec { + a.iter() + .zip(b.iter()) + .map(|(x, y)| x.checked_mul(*y).unwrap_or_default()) + .collect() +} + // Element-wise product of two matrices. #[allow(dead_code)] pub fn hadamard(mat1: &[Vec], mat2: &[Vec]) -> Vec> { @@ -1446,9 +1455,21 @@ pub fn mat_ema_alpha_vec( old_row.get(j), result.get_mut(i).and_then(|row| row.get_mut(j)), ) { - *result_val = alpha_val - .saturating_mul(*new_val) - .saturating_add(one_minus_alpha.saturating_mul(*old_val)); + let decayed_val = one_minus_alpha.saturating_mul(*old_val); + let remaining_capacity = I32F32::from_num(1.0) + .saturating_sub(decayed_val) + .max(I32F32::from_num(0.0)); + + // Each validator can increase bonds by at most clamped_alpha per epoch towards the cap + // Validators allocate their purchase across miners based on weights + let purchase_increment = alpha_val.saturating_mul(*new_val); + + // Ensure that purchase does not exceed remaining capacity + let purchase = purchase_increment.min(remaining_capacity); + + *result_val = decayed_val + .saturating_add(purchase) + .min(I32F32::from_num(1.0)); } } } diff --git a/pallets/subtensor/src/epoch/run_epoch.rs b/pallets/subtensor/src/epoch/run_epoch.rs index 62027f9636..51283d9b81 100644 --- a/pallets/subtensor/src/epoch/run_epoch.rs +++ b/pallets/subtensor/src/epoch/run_epoch.rs @@ -204,17 +204,25 @@ impl Pallet { inplace_col_normalize(&mut bonds); // sum_i b_ij = 1 log::trace!("B:\n{:?}\n", &bonds); - // Compute bonds delta column normalized. - let mut bonds_delta: Vec> = row_hadamard(&weights_for_bonds, &active_stake); // ΔB = W◦S - inplace_col_normalize(&mut bonds_delta); // sum_i b_ij = 1 - log::trace!("ΔB:\n{:?}\n", &bonds_delta); // Compute the Exponential Moving Average (EMA) of bonds. - let mut ema_bonds = Self::compute_ema_bonds(netuid, consensus.clone(), bonds_delta, bonds); + // Check if Liquid Alpha is enabled, consensus is not empty, and contains non-zero values. + let mut ema_bonds = if let Some(clamped_bonds_alpha) = + Self::compute_liquid_alpha(netuid, consensus.clone()) + { + // Compute the Exponential Moving Average (EMA) of bonds using the clamped alpha values. + Self::compute_ema_bonds_with_liquid_alpha(&weights.clone(), &bonds, clamped_bonds_alpha) + } else { + log::trace!("Using Bonds Moving Average"); + // Compute the EMA of bonds using a normal alpha value. + Self::compute_ema_bonds_normal(&weights.clone(), &bonds, netuid) + }; + inplace_col_normalize(&mut ema_bonds); // sum_i b_ij = 1 log::trace!("emaB:\n{:?}\n", &ema_bonds); - // Compute dividends: d_i = SUM(j) b_ij * inc_j - let mut dividends: Vec = matmul_transpose(&ema_bonds, &incentive); + // # === Dividend Calculation=== + let total_bonds_per_validator: Vec = matmul_transpose(&ema_bonds, &incentive); + let mut dividends: Vec = vec_mul(&total_bonds_per_validator, &active_stake); inplace_normalize(&mut dividends); log::trace!("D:\n{:?}\n", ÷nds); @@ -1189,22 +1197,15 @@ impl Pallet { } } - /// Compute the Exponential Moving Average (EMA) of bonds based on the Liquid Alpha setting. + /// Compute liquid alphas based on the Liquid Alpha setting. /// /// # Args: /// * `netuid` - The network ID. /// * `consensus` - A vector of consensus values. - /// * `bonds_delta` - A vector of bond deltas. - /// * `bonds` - A vector of bonds. /// /// # Returns: - /// A vector of EMA bonds. - pub fn compute_ema_bonds( - netuid: u16, - consensus: Vec, - bonds_delta: Vec>, - bonds: Vec>, - ) -> Vec> { + /// A vector of alphas + pub fn compute_liquid_alpha(netuid: u16, consensus: Vec) -> Option> { // Check if Liquid Alpha is enabled, consensus is not empty, and contains non-zero values. if LiquidAlphaOn::::get(netuid) && !consensus.is_empty() @@ -1238,20 +1239,10 @@ impl Pallet { // Clamp the alpha values between alpha_high and alpha_low. let clamped_alpha = Self::clamp_alpha_values(alpha, alpha_high, alpha_low); - // Compute the Exponential Moving Average (EMA) of bonds using the clamped alpha values. - Self::compute_ema_bonds_with_liquid_alpha(&bonds_delta, &bonds, clamped_alpha) - } else { - log::trace!("Using Bonds Moving Average"); - - // Compute the EMA of bonds using a normal alpha value. - Self::compute_ema_bonds_normal(&bonds_delta, &bonds, netuid) + return Some(clamped_alpha); } - } else { - log::trace!("Using Bonds Moving Average"); - - // Compute the EMA of bonds using a normal alpha value. - Self::compute_ema_bonds_normal(&bonds_delta, &bonds, netuid) } + None } pub fn do_set_alpha_values( From 447a936a8f3e4fe85fb7d7ca66d0d00be840255d Mon Sep 17 00:00:00 2001 From: Andreea Popescu Date: Wed, 22 Jan 2025 13:16:00 +0000 Subject: [PATCH 02/45] yuma bonds scale individually for sparse --- pallets/subtensor/src/epoch/math.rs | 15 +++- pallets/subtensor/src/epoch/run_epoch.rs | 106 +++++------------------ 2 files changed, 34 insertions(+), 87 deletions(-) diff --git a/pallets/subtensor/src/epoch/math.rs b/pallets/subtensor/src/epoch/math.rs index c660b7f02b..7c00da2587 100644 --- a/pallets/subtensor/src/epoch/math.rs +++ b/pallets/subtensor/src/epoch/math.rs @@ -1387,7 +1387,20 @@ pub fn mat_ema_alpha_vec_sparse( I32F32::saturating_from_num(1.0).saturating_sub(alpha_val); // Compute the EMA component for the old value and add it to the row using saturating operations. if let Some(row_val) = row.get_mut(*j as usize) { - *row_val = row_val.saturating_add(one_minus_alpha.saturating_mul(*value)); + let decayed_val = one_minus_alpha.saturating_mul(*value); + let remaining_capacity = I32F32::from_num(1.0) + .saturating_sub(decayed_val) + .max(I32F32::from_num(0.0)); + // Each validator can increase bonds by at most clamped_alpha per epoch towards the cap + // Validators allocate their purchase across miners based on weights + let purchase_increment = alpha_val.saturating_mul(*row_val); + + // Ensure that purchase does not exceed remaining capacity + let purchase = purchase_increment.min(remaining_capacity); + + *row_val = decayed_val + .saturating_add(purchase) + .min(I32F32::from_num(1.0)); } log::trace!( "old[{}][{}] * (1 - alpha[{}]) = {} * {} = {}", diff --git a/pallets/subtensor/src/epoch/run_epoch.rs b/pallets/subtensor/src/epoch/run_epoch.rs index 51283d9b81..4d30832a37 100644 --- a/pallets/subtensor/src/epoch/run_epoch.rs +++ b/pallets/subtensor/src/epoch/run_epoch.rs @@ -216,7 +216,7 @@ impl Pallet { // Compute the EMA of bonds using a normal alpha value. Self::compute_ema_bonds_normal(&weights.clone(), &bonds, netuid) }; - + // Normalize EMA bonds. inplace_col_normalize(&mut ema_bonds); // sum_i b_ij = 1 log::trace!("emaB:\n{:?}\n", &ema_bonds); @@ -591,25 +591,30 @@ impl Pallet { inplace_col_normalize_sparse(&mut bonds, n); log::trace!("B (mask+norm): {:?}", &bonds); - // Compute bonds delta column normalized. - let mut bonds_delta: Vec> = - row_hadamard_sparse(&weights_for_bonds, &active_stake); // ΔB = W◦S (outdated W masked) - log::trace!("ΔB: {:?}", &bonds_delta); - - // Normalize bonds delta. - inplace_col_normalize_sparse(&mut bonds_delta, n); // sum_i b_ij = 1 - log::trace!("ΔB (norm): {:?}", &bonds_delta); - // Compute the Exponential Moving Average (EMA) of bonds. - let mut ema_bonds = - Self::compute_ema_bonds_sparse(netuid, consensus.clone(), bonds_delta, bonds); + let mut ema_bonds = if let Some(clamped_bonds_alpha) = + Self::compute_liquid_alpha(netuid, consensus.clone()) + { + // Compute the Exponential Moving Average (EMA) of bonds using the clamped alpha values. + Self::compute_ema_bonds_with_liquid_alpha_sparse( + &weights.clone(), + &bonds, + clamped_bonds_alpha, + ) + } else { + log::trace!("Using Bonds Moving Average"); + // Compute the EMA of bonds using a normal alpha value. + Self::compute_ema_bonds_normal_sparse(&weights.clone(), &bonds, netuid) + }; + // Normalize EMA bonds. inplace_col_normalize_sparse(&mut ema_bonds, n); // sum_i b_ij = 1 log::trace!("Exponential Moving Average Bonds: {:?}", &ema_bonds); - // Compute dividends: d_i = SUM(j) b_ij * inc_j. - // range: I32F32(0, 1) - let mut dividends: Vec = matmul_transpose_sparse(&ema_bonds, &incentive); + // # === Dividend Calculation=== + let total_bonds_per_validator: Vec = + matmul_transpose_sparse(&ema_bonds, &incentive); + let mut dividends: Vec = vec_mul(&total_bonds_per_validator, &active_stake); inplace_normalize(&mut dividends); log::trace!("Dividends: {:?}", ÷nds); @@ -1126,77 +1131,6 @@ impl Pallet { ema_bonds } - /// Compute the Exponential Moving Average (EMA) of bonds based on the Liquid Alpha setting for a sparse matrix. - /// - /// # Args: - /// * `netuid` - The network ID. - /// * `consensus` - A vector of consensus values. - /// * `bonds_delta` - A vector of bond deltas. - /// * `bonds` - A vector of bonds. - /// - /// # Returns: - /// A vector of EMA bonds. - pub fn compute_ema_bonds_sparse( - netuid: u16, - consensus: Vec, - bonds_delta: Vec>, - bonds: Vec>, - ) -> Vec> { - // Check if Liquid Alpha is enabled, consensus is not empty, and contains non-zero values. - // This way we avoid the quantil function panic. - if LiquidAlphaOn::::get(netuid) - && !consensus.is_empty() - && consensus - .iter() - .any(|&c| c != I32F32::saturating_from_num(0)) - { - // Calculate the 75th percentile (high) and 25th percentile (low) of the consensus values. - let consensus_high = quantile(&consensus, 0.75); - let consensus_low = quantile(&consensus, 0.25); - // Further check if the high and low consensus values meet the required conditions. - if (consensus_high > consensus_low) || consensus_high != 0 || consensus_low < 0 { - // if (consensus_high > consensus_low) || consensus_high != 0) || consensus_low != 0 { - // if (consensus_high > consensus_low) || consensus_low != 0 { - log::trace!("Using Liquid Alpha"); - - // Get the high and low alpha values for the network. - let (alpha_low, alpha_high): (I32F32, I32F32) = Self::get_alpha_values_32(netuid); - log::trace!("alpha_low: {:?} alpha_high: {:?}", alpha_low, alpha_high); - - // Calculate the logistic function parameters 'a' and 'b' based on alpha and consensus values. - let (a, b) = Self::calculate_logistic_params( - alpha_high, - alpha_low, - consensus_high, - consensus_low, - ); - - // Compute the alpha values using the logistic function parameters. - let alpha = Self::compute_alpha_values(&consensus, a, b); - - // Clamp the alpha values between alpha_high and alpha_low. - let clamped_alpha = Self::clamp_alpha_values(alpha, alpha_high, alpha_low); - - // Compute the Exponential Moving Average (EMA) of bonds using the clamped alpha values. - Self::compute_ema_bonds_with_liquid_alpha_sparse( - &bonds_delta, - &bonds, - clamped_alpha, - ) - } else { - log::trace!("Using Bonds Moving Average"); - - // Compute the EMA of bonds using a normal alpha value. - Self::compute_ema_bonds_normal_sparse(&bonds_delta, &bonds, netuid) - } - } else { - log::trace!("Using Bonds Moving Average"); - - // Compute the EMA of bonds using a normal alpha value. - Self::compute_ema_bonds_normal_sparse(&bonds_delta, &bonds, netuid) - } - } - /// Compute liquid alphas based on the Liquid Alpha setting. /// /// # Args: From ec9a1ed242fadb717db5affd6efb651b963dfd6c Mon Sep 17 00:00:00 2001 From: Andreea Popescu Date: Wed, 22 Jan 2025 14:45:35 +0000 Subject: [PATCH 03/45] refactor alpha values --- pallets/subtensor/src/epoch/math.rs | 66 +---------- pallets/subtensor/src/epoch/run_epoch.rs | 145 ++++++----------------- pallets/subtensor/src/tests/epoch.rs | 10 +- pallets/subtensor/src/tests/math.rs | 16 +-- 4 files changed, 51 insertions(+), 186 deletions(-) diff --git a/pallets/subtensor/src/epoch/math.rs b/pallets/subtensor/src/epoch/math.rs index 7c00da2587..5d17ff9e0b 100644 --- a/pallets/subtensor/src/epoch/math.rs +++ b/pallets/subtensor/src/epoch/math.rs @@ -1268,66 +1268,6 @@ pub fn hadamard_sparse( result } -// Return matrix exponential moving average: `alpha * a_ij + one_minus_alpha * b_ij`. -// `alpha` is the EMA coefficient, how much to add of the new observation, typically small, -// higher alpha discounts older observations faster. -#[allow(dead_code)] -pub fn mat_ema(new: &[Vec], old: &[Vec], alpha: I32F32) -> Vec> { - let Some(first_row) = new.first() else { - return vec![vec![]]; - }; - if first_row.is_empty() { - return vec![vec![]; 1]; - } - let one_minus_alpha: I32F32 = I32F32::saturating_from_num(1.0).saturating_sub(alpha); - new.iter() - .zip(old) - .map(|(new_row, old_row)| { - new_row - .iter() - .zip(old_row) - .map(|(new_elem, old_elem)| { - alpha - .saturating_mul(*new_elem) - .saturating_add(one_minus_alpha.saturating_mul(*old_elem)) - }) - .collect() - }) - .collect() -} - -// Return sparse matrix exponential moving average: `alpha * a_ij + one_minus_alpha * b_ij`. -// `alpha` is the EMA coefficient, how much to add of the new observation, typically small, -// higher alpha discounts older observations faster. -#[allow(dead_code, clippy::indexing_slicing)] -pub fn mat_ema_sparse( - new: &[Vec<(u16, I32F32)>], - old: &[Vec<(u16, I32F32)>], - alpha: I32F32, -) -> Vec> { - assert!(new.len() == old.len()); - let n = new.len(); // assume square matrix, rows=cols - let zero: I32F32 = I32F32::saturating_from_num(0.0); - let one_minus_alpha: I32F32 = I32F32::saturating_from_num(1.0).saturating_sub(alpha); - let mut result: Vec> = vec![vec![]; n]; - for i in 0..new.len() { - let mut row: Vec = vec![zero; n]; - for (j, value) in new[i].iter() { - row[*j as usize] = row[*j as usize].saturating_add(alpha.saturating_mul(*value)); - } - for (j, value) in old[i].iter() { - row[*j as usize] = - row[*j as usize].saturating_add(one_minus_alpha.saturating_mul(*value)); - } - for (j, value) in row.iter().enumerate() { - if *value > zero { - result[i].push((j as u16, *value)) - } - } - } - result -} - // Return sparse matrix only with elements >= threshold of an input sparse matrix. #[allow(dead_code)] pub fn sparse_threshold(w: &[Vec<(u16, I32F32)>], threshold: I32F32) -> Vec> { @@ -1342,6 +1282,10 @@ pub fn sparse_threshold(w: &[Vec<(u16, I32F32)>], threshold: I32F32) -> Vec], @@ -1430,6 +1374,7 @@ pub fn mat_ema_alpha_vec_sparse( /// Return matrix exponential moving average: `alpha_j * a_ij + one_minus_alpha_j * b_ij`. /// `alpha_` is the EMA coefficient passed as a vector per column. +// if liquid alpha off then the alpha vector will be constant #[allow(dead_code)] pub fn mat_ema_alpha_vec( new: &[Vec], @@ -1454,7 +1399,6 @@ pub fn mat_ema_alpha_vec( // Iterate over each row of the matrices. for (i, (new_row, old_row)) in new.iter().zip(old).enumerate() { - // Ensure the current row of the new and old matrices have the same length. assert!(new_row.len() == old_row.len()); // Iterate over each column of the current row. diff --git a/pallets/subtensor/src/epoch/run_epoch.rs b/pallets/subtensor/src/epoch/run_epoch.rs index 4d30832a37..ef0f171c34 100644 --- a/pallets/subtensor/src/epoch/run_epoch.rs +++ b/pallets/subtensor/src/epoch/run_epoch.rs @@ -204,18 +204,11 @@ impl Pallet { inplace_col_normalize(&mut bonds); // sum_i b_ij = 1 log::trace!("B:\n{:?}\n", &bonds); + // Get alpha values + let alpha = Self::compute_liquid_alpha(netuid, consensus.clone()); + // Compute the Exponential Moving Average (EMA) of bonds. - // Check if Liquid Alpha is enabled, consensus is not empty, and contains non-zero values. - let mut ema_bonds = if let Some(clamped_bonds_alpha) = - Self::compute_liquid_alpha(netuid, consensus.clone()) - { - // Compute the Exponential Moving Average (EMA) of bonds using the clamped alpha values. - Self::compute_ema_bonds_with_liquid_alpha(&weights.clone(), &bonds, clamped_bonds_alpha) - } else { - log::trace!("Using Bonds Moving Average"); - // Compute the EMA of bonds using a normal alpha value. - Self::compute_ema_bonds_normal(&weights.clone(), &bonds, netuid) - }; + let mut ema_bonds = Self::compute_ema_bonds(&weights.clone(), &bonds, alpha); // Normalize EMA bonds. inplace_col_normalize(&mut ema_bonds); // sum_i b_ij = 1 log::trace!("emaB:\n{:?}\n", &ema_bonds); @@ -591,22 +584,11 @@ impl Pallet { inplace_col_normalize_sparse(&mut bonds, n); log::trace!("B (mask+norm): {:?}", &bonds); - // Compute the Exponential Moving Average (EMA) of bonds. - let mut ema_bonds = if let Some(clamped_bonds_alpha) = - Self::compute_liquid_alpha(netuid, consensus.clone()) - { - // Compute the Exponential Moving Average (EMA) of bonds using the clamped alpha values. - Self::compute_ema_bonds_with_liquid_alpha_sparse( - &weights.clone(), - &bonds, - clamped_bonds_alpha, - ) - } else { - log::trace!("Using Bonds Moving Average"); - // Compute the EMA of bonds using a normal alpha value. - Self::compute_ema_bonds_normal_sparse(&weights.clone(), &bonds, netuid) - }; + // Get alpha values + let alpha = Self::compute_liquid_alpha(netuid, consensus.clone()); + // Compute the Exponential Moving Average (EMA) of bonds. + let mut ema_bonds = Self::compute_ema_bonds_sparse(&weights.clone(), &bonds, alpha); // Normalize EMA bonds. inplace_col_normalize_sparse(&mut ema_bonds, n); // sum_i b_ij = 1 log::trace!("Exponential Moving Average Bonds: {:?}", &ema_bonds); @@ -1009,16 +991,16 @@ impl Pallet { clamped_alpha } - /// Compute the Exponential Moving Average (EMA) of bonds using the clamped alpha values for a sparse matrix. + /// Compute the Exponential Moving Average (EMA) of bonds using the alpha values for a sparse matrix. /// /// # Args: /// * `bonds_delta` - A vector of bond deltas. /// * `bonds` - A vector of bonds. - /// * `alpha` - A vector of clamped alpha values. + /// * `alpha` - A vector of clamped alpha values (for liquid alpha) or constant alpha values. /// /// # Returns: /// A vector of EMA bonds. - pub fn compute_ema_bonds_with_liquid_alpha_sparse( + pub fn compute_ema_bonds_sparse( bonds_delta: &[Vec<(u16, I32F32)>], bonds: &[Vec<(u16, I32F32)>], alpha: Vec, @@ -1027,25 +1009,22 @@ impl Pallet { let ema_bonds = mat_ema_alpha_vec_sparse(bonds_delta, bonds, &alpha); // Log the computed EMA bonds for debugging purposes. - log::trace!( - "Exponential Moving Average Bonds Liquid Alpha: {:?}", - ema_bonds - ); + log::trace!("Exponential Moving Average Bonds: {:?}", ema_bonds); // Return the computed EMA bonds. ema_bonds } - /// Compute the Exponential Moving Average (EMA) of bonds using the clamped alpha values. + /// Compute the Exponential Moving Average (EMA) of bonds using the alpha values. /// /// # Args: /// * `bonds_delta` - A vector of bond deltas. /// * `bonds` - A vector of bonds. - /// * `alpha` - A vector of clamped alpha values. + /// * `alpha` - A vector of clamped alpha values (for liquid alpha) or constant alpha values. /// /// # Returns: /// A vector of EMA bonds. - pub fn compute_ema_bonds_with_liquid_alpha( + pub fn compute_ema_bonds( bonds_delta: &[Vec], bonds: &[Vec], alpha: Vec, @@ -1054,78 +1033,7 @@ impl Pallet { let ema_bonds = mat_ema_alpha_vec(bonds_delta, bonds, &alpha); // Log the computed EMA bonds for debugging purposes. - log::trace!( - "Exponential Moving Average Bonds Liquid Alpha: {:?}", - ema_bonds - ); - - // Return the computed EMA bonds. - ema_bonds - } - - /// Compute the Exponential Moving Average (EMA) of bonds using a normal alpha value for a sparse matrix. - /// - /// # Args: - /// * `bonds_delta` - A vector of bond deltas. - /// * `bonds` - A vector of bonds. - /// * `netuid` - The network ID. - /// - /// # Returns: - /// A vector of EMA bonds. - pub fn compute_ema_bonds_normal_sparse( - bonds_delta: &[Vec<(u16, I32F32)>], - bonds: &[Vec<(u16, I32F32)>], - netuid: u16, - ) -> Vec> { - // Retrieve the bonds moving average for the given network ID and scale it down. - let bonds_moving_average: I64F64 = - I64F64::saturating_from_num(Self::get_bonds_moving_average(netuid)) - .safe_div(I64F64::saturating_from_num(1_000_000)); - - // Calculate the alpha value for the EMA calculation. - // Alpha is derived by subtracting the scaled bonds moving average from 1. - let alpha: I32F32 = I32F32::saturating_from_num(1) - .saturating_sub(I32F32::saturating_from_num(bonds_moving_average)); - - // Compute the Exponential Moving Average (EMA) of bonds using the calculated alpha value. - let ema_bonds = mat_ema_sparse(bonds_delta, bonds, alpha); - - // Log the computed EMA bonds for debugging purposes. - log::trace!("Exponential Moving Average Bonds Normal: {:?}", ema_bonds); - - // Return the computed EMA bonds. - ema_bonds - } - - /// Compute the Exponential Moving Average (EMA) of bonds using a normal alpha value. - /// - /// # Args: - /// * `bonds_delta` - A vector of bond deltas. - /// * `bonds` - A vector of bonds. - /// * `netuid` - The network ID. - /// - /// # Returns: - /// A vector of EMA bonds. - pub fn compute_ema_bonds_normal( - bonds_delta: &[Vec], - bonds: &[Vec], - netuid: u16, - ) -> Vec> { - // Retrieve the bonds moving average for the given network ID and scale it down. - let bonds_moving_average: I64F64 = - I64F64::saturating_from_num(Self::get_bonds_moving_average(netuid)) - .safe_div(I64F64::saturating_from_num(1_000_000)); - - // Calculate the alpha value for the EMA calculation. - // Alpha is derived by subtracting the scaled bonds moving average from 1. - let alpha: I32F32 = I32F32::saturating_from_num(1) - .saturating_sub(I32F32::saturating_from_num(bonds_moving_average)); - - // Compute the Exponential Moving Average (EMA) of bonds using the calculated alpha value. - let ema_bonds = mat_ema(bonds_delta, bonds, alpha); - - // Log the computed EMA bonds for debugging purposes. - log::trace!("Exponential Moving Average Bonds Normal: {:?}", ema_bonds); + log::trace!("Exponential Moving Average Bonds: {:?}", ema_bonds); // Return the computed EMA bonds. ema_bonds @@ -1139,7 +1047,7 @@ impl Pallet { /// /// # Returns: /// A vector of alphas - pub fn compute_liquid_alpha(netuid: u16, consensus: Vec) -> Option> { + pub fn compute_liquid_alpha(netuid: u16, consensus: Vec) -> Vec { // Check if Liquid Alpha is enabled, consensus is not empty, and contains non-zero values. if LiquidAlphaOn::::get(netuid) && !consensus.is_empty() @@ -1168,15 +1076,30 @@ impl Pallet { ); // Compute the alpha values using the logistic function parameters. + // alpha = 1 / (1 + math.e ** (-a * C + b)) # alpha to the old weight let alpha = Self::compute_alpha_values(&consensus, a, b); // Clamp the alpha values between alpha_high and alpha_low. let clamped_alpha = Self::clamp_alpha_values(alpha, alpha_high, alpha_low); - return Some(clamped_alpha); + return clamped_alpha; } } - None + + // Liquid Alpha is disabled + // or high and low consensus values do not meet the required conditions. + // return vector of constant alpha + + // Retrieve the bonds moving average for the given network ID and scale it down. + let bonds_moving_average: I64F64 = I64F64::from_num(Self::get_bonds_moving_average(netuid)) + .saturating_div(I64F64::from_num(1_000_000)); + + // Calculate the alpha value for the EMA calculation. + // Alpha is derived by subtracting the scaled bonds moving average from 1. + let alpha: I32F32 = + I32F32::from_num(1).saturating_sub(I32F32::from_num(bonds_moving_average)); + + vec![alpha; consensus.len()] } pub fn do_set_alpha_values( diff --git a/pallets/subtensor/src/tests/epoch.rs b/pallets/subtensor/src/tests/epoch.rs index aaaf93e086..6c01ec4aa4 100644 --- a/pallets/subtensor/src/tests/epoch.rs +++ b/pallets/subtensor/src/tests/epoch.rs @@ -2706,7 +2706,7 @@ fn test_calculate_logistic_params_edge_cases() { } #[test] -fn test_compute_ema_bonds_with_liquid_alpha_sparse() { +fn test_compute_ema_bonds_sparse() { // Define test inputs let bonds_delta = vec![ vec![(0, I32F32::from_num(0.1)), (1, I32F32::from_num(0.2))], @@ -2735,8 +2735,7 @@ fn test_compute_ema_bonds_with_liquid_alpha_sparse() { ]; // Call the function - let ema_bonds = - SubtensorModule::compute_ema_bonds_with_liquid_alpha_sparse(&bonds_delta, &bonds, alpha); + let ema_bonds = SubtensorModule::compute_ema_bonds_sparse(&bonds_delta, &bonds, alpha); // Assert the results with an epsilon for approximate equality let epsilon = I32F32::from_num(1e-6); @@ -2744,7 +2743,7 @@ fn test_compute_ema_bonds_with_liquid_alpha_sparse() { } #[test] -fn test_compute_ema_bonds_with_liquid_alpha_sparse_empty() { +fn test_compute_ema_bonds_sparse_empty() { // Test with empty inputs let bonds_delta: Vec> = vec![]; let bonds: Vec> = vec![]; @@ -2754,8 +2753,7 @@ fn test_compute_ema_bonds_with_liquid_alpha_sparse_empty() { let expected_ema_bonds: Vec> = vec![]; // Call the function - let ema_bonds = - SubtensorModule::compute_ema_bonds_with_liquid_alpha_sparse(&bonds_delta, &bonds, alpha); + let ema_bonds = SubtensorModule::compute_ema_bonds_sparse(&bonds_delta, &bonds, alpha); // Assert the results assert_eq!( diff --git a/pallets/subtensor/src/tests/math.rs b/pallets/subtensor/src/tests/math.rs index c70da2c9d2..3500acf589 100644 --- a/pallets/subtensor/src/tests/math.rs +++ b/pallets/subtensor/src/tests/math.rs @@ -2144,7 +2144,7 @@ fn test_math_mat_ema() { let old = vec_to_mat_fixed(&old, 4, false); let new = vec_to_mat_fixed(&new, 4, false); let target = vec_to_mat_fixed(&target, 4, false); - let result = mat_ema(&new, &old, I32F32::from_num(0.1)); + let result = mat_ema_alpha_vec(&new, &old, &vec![I32F32::from_num(0.1); old.len()]); assert_mat_compare(&result, &target, I32F32::from_num(0.000001)); let old: Vec = vec![1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12.]; let new: Vec = vec![ @@ -2154,7 +2154,7 @@ fn test_math_mat_ema() { let old = vec_to_mat_fixed(&old, 4, false); let new = vec_to_mat_fixed(&new, 4, false); let target = vec_to_mat_fixed(&target, 4, false); - let result = mat_ema(&new, &old, I32F32::from_num(0)); + let result = mat_ema_alpha_vec(&new, &old, &vec![I32F32::from_num(0); old.len()]); assert_mat_compare(&result, &target, I32F32::from_num(0.000001)); let old: Vec = vec![1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12.]; let new: Vec = vec![ @@ -2166,7 +2166,7 @@ fn test_math_mat_ema() { let old = vec_to_mat_fixed(&old, 4, false); let new = vec_to_mat_fixed(&new, 4, false); let target = vec_to_mat_fixed(&target, 4, false); - let result = mat_ema(&new, &old, I32F32::from_num(1)); + let result = mat_ema_alpha_vec(&new, &old, &vec![I32F32::from_num(1); old.len()]); assert_mat_compare(&result, &target, I32F32::from_num(0.000001)); } @@ -2182,7 +2182,7 @@ fn test_math_sparse_mat_ema() { let old = vec_to_sparse_mat_fixed(&old, 4, false); let new = vec_to_sparse_mat_fixed(&new, 4, false); let target = vec_to_sparse_mat_fixed(&target, 4, false); - let result = mat_ema_sparse(&new, &old, I32F32::from_num(0.1)); + let result = mat_ema_alpha_vec_sparse(&new, &old, &vec![I32F32::from_num(0.1); old.len()]); assert_sparse_mat_compare(&result, &target, I32F32::from_num(0.000001)); let old: Vec = vec![0., 2., 3., 4., 0., 6., 7., 8., 0., 10., 11., 12.]; let new: Vec = vec![10., 20., 0., 40., 0., 60., 0., 80., 90., 100., 110., 120.]; @@ -2190,7 +2190,7 @@ fn test_math_sparse_mat_ema() { let old = vec_to_sparse_mat_fixed(&old, 4, false); let new = vec_to_sparse_mat_fixed(&new, 4, false); let target = vec_to_sparse_mat_fixed(&target, 4, false); - let result = mat_ema_sparse(&new, &old, I32F32::from_num(0.1)); + let result = mat_ema_alpha_vec_sparse(&new, &old, &vec![I32F32::from_num(0.1); old.len()]); assert_sparse_mat_compare(&result, &target, I32F32::from_num(0.000001)); let old: Vec = vec![0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]; let new: Vec = vec![10., 20., 0., 40., 0., 60., 0., 80., 90., 100., 110., 120.]; @@ -2198,7 +2198,7 @@ fn test_math_sparse_mat_ema() { let old = vec_to_sparse_mat_fixed(&old, 4, false); let new = vec_to_sparse_mat_fixed(&new, 4, false); let target = vec_to_sparse_mat_fixed(&target, 4, false); - let result = mat_ema_sparse(&new, &old, I32F32::from_num(0.1)); + let result = mat_ema_alpha_vec_sparse(&new, &old, &vec![I32F32::from_num(0.1); old.len()]); assert_sparse_mat_compare(&result, &target, I32F32::from_num(0.000001)); let old: Vec = vec![0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]; let new: Vec = vec![0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]; @@ -2206,7 +2206,7 @@ fn test_math_sparse_mat_ema() { let old = vec_to_sparse_mat_fixed(&old, 4, false); let new = vec_to_sparse_mat_fixed(&new, 4, false); let target = vec_to_sparse_mat_fixed(&target, 4, false); - let result = mat_ema_sparse(&new, &old, I32F32::from_num(0.1)); + let result = mat_ema_alpha_vec_sparse(&new, &old, &vec![I32F32::from_num(0.1); old.len()]); assert_sparse_mat_compare(&result, &target, I32F32::from_num(0.000001)); let old: Vec = vec![1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]; let new: Vec = vec![0., 0., 0., 0., 2., 0., 0., 0., 0., 0., 0., 0.]; @@ -2214,7 +2214,7 @@ fn test_math_sparse_mat_ema() { let old = vec_to_sparse_mat_fixed(&old, 4, false); let new = vec_to_sparse_mat_fixed(&new, 4, false); let target = vec_to_sparse_mat_fixed(&target, 4, false); - let result = mat_ema_sparse(&new, &old, I32F32::from_num(0.1)); + let result = mat_ema_alpha_vec_sparse(&new, &old, &vec![I32F32::from_num(0.1); old.len()]); assert_sparse_mat_compare(&result, &target, I32F32::from_num(0.000001)); } From 8f95924fd5a8a94f0cd5822d7aabb127f4d60ea8 Mon Sep 17 00:00:00 2001 From: Andreea Popescu Date: Mon, 27 Jan 2025 03:21:02 +0000 Subject: [PATCH 04/45] rebase fix --- pallets/subtensor/src/epoch/run_epoch.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pallets/subtensor/src/epoch/run_epoch.rs b/pallets/subtensor/src/epoch/run_epoch.rs index ef0f171c34..36510532ce 100644 --- a/pallets/subtensor/src/epoch/run_epoch.rs +++ b/pallets/subtensor/src/epoch/run_epoch.rs @@ -208,7 +208,7 @@ impl Pallet { let alpha = Self::compute_liquid_alpha(netuid, consensus.clone()); // Compute the Exponential Moving Average (EMA) of bonds. - let mut ema_bonds = Self::compute_ema_bonds(&weights.clone(), &bonds, alpha); + let mut ema_bonds = Self::compute_ema_bonds(&weights_for_bonds.clone(), &bonds, alpha); // Normalize EMA bonds. inplace_col_normalize(&mut ema_bonds); // sum_i b_ij = 1 log::trace!("emaB:\n{:?}\n", &ema_bonds); @@ -588,7 +588,8 @@ impl Pallet { let alpha = Self::compute_liquid_alpha(netuid, consensus.clone()); // Compute the Exponential Moving Average (EMA) of bonds. - let mut ema_bonds = Self::compute_ema_bonds_sparse(&weights.clone(), &bonds, alpha); + let mut ema_bonds = + Self::compute_ema_bonds_sparse(&weights_for_bonds.clone(), &bonds, alpha); // Normalize EMA bonds. inplace_col_normalize_sparse(&mut ema_bonds, n); // sum_i b_ij = 1 log::trace!("Exponential Moving Average Bonds: {:?}", &ema_bonds); From c5af5dbba4b80aa6d9c716415bfdcd95ac8e5bae Mon Sep 17 00:00:00 2001 From: Andreea Popescu Date: Tue, 28 Jan 2025 09:54:30 +0000 Subject: [PATCH 05/45] update tests --- pallets/subtensor/src/tests/epoch.rs | 94 +++++++++++++------------- pallets/subtensor/src/tests/math.rs | 98 +++++++++++++++++----------- 2 files changed, 104 insertions(+), 88 deletions(-) diff --git a/pallets/subtensor/src/tests/epoch.rs b/pallets/subtensor/src/tests/epoch.rs index 6c01ec4aa4..9315eef06f 100644 --- a/pallets/subtensor/src/tests/epoch.rs +++ b/pallets/subtensor/src/tests/epoch.rs @@ -1061,9 +1061,9 @@ fn test_bonds() { P: [0.0499999989, 0.0999999992, 0.1500000006, 0.2000000011, 0.049998779, 0.1000006103, 0.1499963375, 0.2000042726] emaB: [[(4, 0.2499999937), (5, 0.2499999953), (6, 0.2499999937), (7, 0.2499999937)], [(4, 0.4999999942), (5, 0.499999997), (6, 0.4999999942), (7, 0.4999999942)], [(4, 0.7499999937), (5, 0.7499999981), (6, 0.7499999995), (7, 0.7499999995)], [(4, 1), (5, 1), (6, 1), (7, 1)], [], [], [], []] */ let bonds = SubtensorModule::get_bonds( netuid ); - assert_eq!(bonds[0][4], 16383); - assert_eq!(bonds[1][4], 32767); - assert_eq!(bonds[2][4], 49151); + assert_eq!(bonds[0][4], 65535); + assert_eq!(bonds[1][4], 65535); + assert_eq!(bonds[2][4], 65535); assert_eq!(bonds[3][4], 65535); // === Set self-weight only on val1 @@ -1109,9 +1109,9 @@ fn test_bonds() { P: [0.0449983515, 0.1011105615, 0.1516672159, 0.2022238704, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] emaB: [[(4, 0.2225175085), (5, 0.2225175085), (6, 0.2225175085), (7, 0.2225175085)], [(4, 0.499993208), (5, 0.4999932083), (6, 0.4999932083), (7, 0.4999932083)], [(4, 0.7499966028), (5, 0.7499966032), (6, 0.7499966032), (7, 0.7499966032)], [(4, 1), (5, 1), (6, 1), (7, 1)], [], [], [], []] */ let bonds = SubtensorModule::get_bonds( netuid ); - assert_eq!(bonds[0][4], 14582); - assert_eq!(bonds[1][4], 32767); - assert_eq!(bonds[2][4], 49151); + assert_eq!(bonds[0][4], 65245); + assert_eq!(bonds[1][4], 65535); + assert_eq!(bonds[2][4], 65535); assert_eq!(bonds[3][4], 65535); // === Set self-weight only on val2 @@ -1146,9 +1146,9 @@ fn test_bonds() { P: [0.040496806, 0.0909997837, 0.157929636, 0.2105737738, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] emaB: [[(4, 0.192316476), (5, 0.192316476), (6, 0.192316476), (7, 0.192316476)], [(4, 0.4321515555), (5, 0.4321515558), (6, 0.4321515558), (7, 0.4321515558)], [(4, 0.7499967015), (5, 0.7499967027), (6, 0.7499967027), (7, 0.7499967027)], [(4, 1), (5, 1), (6, 1), (7, 1)], [], [], [], []] */ let bonds = SubtensorModule::get_bonds( netuid ); - assert_eq!(bonds[0][4], 12603); - assert_eq!(bonds[1][4], 28321); - assert_eq!(bonds[2][4], 49151); + assert_eq!(bonds[0][4], 64956); + assert_eq!(bonds[1][4], 65245); + assert_eq!(bonds[2][4], 65535); assert_eq!(bonds[3][4], 65535); // === Set self-weight only on val3 @@ -1183,11 +1183,12 @@ fn test_bonds() { P: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] emaB: [[(4, 0.1923094518), (5, 0.1923094518), (6, 0.1923094518), (7, 0.1923094518)], [(4, 0.4321507583), (5, 0.4321507583), (6, 0.4321507583), (7, 0.4321507583)], [(4, 0.7499961846), (5, 0.7499961846), (6, 0.7499961846), (7, 0.7499961846)], [(4, 1), (5, 1), (6, 1), (7, 1)], [], [], [], []] */ let bonds = SubtensorModule::get_bonds( netuid ); - assert_eq!(bonds[0][7], 12602); - assert_eq!(bonds[1][7], 28320); - assert_eq!(bonds[2][7], 49150); + assert_eq!(bonds[0][7], 63269); + assert_eq!(bonds[1][7], 64394); + assert_eq!(bonds[2][7], 65535); assert_eq!(bonds[3][7], 65535); + // === Set val3->srv4: 1 assert_ok!(SubtensorModule::set_weights(RuntimeOrigin::signed(U256::from(2)), netuid, vec![7], vec![u16::MAX], 0)); next_block_no_epoch(netuid); @@ -1219,9 +1220,9 @@ fn test_bonds() { P: [0.0364437331, 0.081898629, 0.1635654932, 0.2180921442, 0, 0, 0, 0.5] emaB: [[(4, 0.1922941932), (5, 0.1922941932), (6, 0.1922941932), (7, 0.1671024568)], [(4, 0.4321354993), (5, 0.4321354993), (6, 0.4321354993), (7, 0.3755230587)], [(4, 0.7499809256), (5, 0.7499809256), (6, 0.7499809256), (7, 0.749983425)], [(4, 1), (5, 1), (6, 1), (7, 1)], [], [], [], []] */ let bonds = SubtensorModule::get_bonds( netuid ); - assert_eq!(bonds[0][7], 10951); - assert_eq!(bonds[1][7], 24609); - assert_eq!(bonds[2][7], 49150); + assert_eq!(bonds[0][7], 62177); + assert_eq!(bonds[1][7], 63283); + assert_eq!(bonds[2][7], 65535); assert_eq!(bonds[3][7], 65535); next_block_no_epoch(netuid); @@ -1241,9 +1242,9 @@ fn test_bonds() { P: [0.0327994274, 0.0737066122, 0.1686381293, 0.2248558307, 0, 0, 0, 0.5] emaB: [[(4, 0.1922789337), (5, 0.1922789337), (6, 0.1922789337), (7, 0.1458686984)], [(4, 0.4321202405), (5, 0.4321202405), (6, 0.4321202405), (7, 0.3277949789)], [(4, 0.749965667), (5, 0.749965667), (6, 0.749965667), (7, 0.74998335)], [(4, 1), (5, 1), (6, 1), (7, 1)], [], [], [], []] */ let bonds = SubtensorModule::get_bonds( netuid ); - assert_eq!(bonds[0][7], 9559); - assert_eq!(bonds[1][7], 21482); - assert_eq!(bonds[2][7], 49150); + assert_eq!(bonds[0][7], 61113); + assert_eq!(bonds[1][7], 62200); + assert_eq!(bonds[2][7], 65535); assert_eq!(bonds[3][7], 65535); next_block_no_epoch(netuid); @@ -1263,9 +1264,9 @@ fn test_bonds() { P: [0.029518068, 0.0663361375, 0.1732031347, 0.2309426593, 0, 0, 0, 0.5] emaB: [[(4, 0.192263675), (5, 0.192263675), (6, 0.192263675), (7, 0.1278155716)], [(4, 0.4321049813), (5, 0.4321049813), (6, 0.4321049813), (7, 0.2872407278)], [(4, 0.7499504078), (5, 0.7499504078), (6, 0.7499504078), (7, 0.7499832863)], [(4, 1), (5, 1), (6, 1), (7, 1)], [], [], [], []] */ let bonds = SubtensorModule::get_bonds( netuid ); - assert_eq!(bonds[0][7], 8376); - assert_eq!(bonds[1][7], 18824); - assert_eq!(bonds[2][7], 49150); + assert_eq!(bonds[0][7], 60076); + assert_eq!(bonds[1][7], 61145); + assert_eq!(bonds[2][7], 65535); assert_eq!(bonds[3][7], 65535); next_block_no_epoch(netuid); @@ -1411,9 +1412,9 @@ fn test_bonds_with_liquid_alpha() { // Normalize ΔB: [0.25/7.5, 1.0/7.5, 2.25/7.5, 4.0/7.5] = [0.0333, 0.1333, 0.3, 0.5333] // Final bonds for netuid: [16383, 32767, 49151, 65535] - assert_eq!(bonds[0][4], 16383); // Note: Calculated as explained above - assert_eq!(bonds[1][4], 32767); // Note: Calculated as explained above - assert_eq!(bonds[2][4], 49151); // Note: Calculated as explained above + assert_eq!(bonds[0][4], 65535); // Note: Calculated as explained above + assert_eq!(bonds[1][4], 65535); // Note: Calculated as explained above + assert_eq!(bonds[2][4], 65535); // Note: Calculated as explained above assert_eq!(bonds[3][4], 65535); // Note: Calculated as explained above // === Set self-weight only on val1 @@ -1433,9 +1434,9 @@ fn test_bonds_with_liquid_alpha() { } let bonds = SubtensorModule::get_bonds(netuid); - assert_eq!(bonds[0][4], 2862); - assert_eq!(bonds[1][4], 32767); - assert_eq!(bonds[2][4], 49151); + assert_eq!(bonds[0][4], 27572); + assert_eq!(bonds[1][4], 65535); + assert_eq!(bonds[2][4], 65535); assert_eq!(bonds[3][4], 65535); // === Set self-weight only on val2 @@ -1496,9 +1497,9 @@ fn test_bonds_with_liquid_alpha() { Pruning Scores: [0.0016997808, 0.0151777493, 0.2070524206, 0.2760700488, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] */ - assert_eq!(bonds[0][4], 435); - assert_eq!(bonds[1][4], 4985); - assert_eq!(bonds[2][4], 49151); + assert_eq!(bonds[0][4], 12662); + assert_eq!(bonds[1][4], 30097); + assert_eq!(bonds[2][4], 65535); assert_eq!(bonds[3][4], 65535); }); } @@ -1677,22 +1678,16 @@ fn test_active_stake() { P: [0.275, 0.2249999999, 0.25, 0.25] P (u16): [65535, 53619, 59577, 59577] */ let bonds = SubtensorModule::get_bonds(netuid); - assert_eq!(SubtensorModule::get_dividends_for_uid(netuid, 0), 36044); // Note D = floor((0.5 * 0.9 + 0.1) * 65_535) - assert_eq!(SubtensorModule::get_emission_for_uid(netuid, 0), 274999999); // Note E = 0.5 * 0.55 * 1_000_000_000 = 275_000_000 (discrepancy) + assert_eq!(SubtensorModule::get_dividends_for_uid(netuid, 0), 65535); // Note D = floor((0.5 * 0.9 + 0.1) * 65_535) + assert_eq!(SubtensorModule::get_emission_for_uid(netuid, 0), 500000000); // Note E = 0.5 * 0.55 * 1_000_000_000 = 275_000_000 (discrepancy) for server in ((n / 2) as usize)..n as usize { assert_eq!(bonds[0][server], I32F32::from_num(65_535)); // floor(0.55*(2^16-1))/(2^16-1), then max-upscale } for validator in 1..(n / 2) { - assert_eq!( - SubtensorModule::get_dividends_for_uid(netuid, validator), - 29490 - ); // Note D = floor((0.5 * 0.9) * 65_535) - assert_eq!( - SubtensorModule::get_emission_for_uid(netuid, validator), - 224999999 - ); // Note E = 0.5 * 0.45 * 1_000_000_000 = 225_000_000 (discrepancy) + assert_eq!(SubtensorModule::get_dividends_for_uid(netuid, validator), 0); // Note D = floor((0.5 * 0.9) * 65_535) + assert_eq!(SubtensorModule::get_emission_for_uid(netuid, validator), 0); // Note E = 0.5 * 0.45 * 1_000_000_000 = 225_000_000 (discrepancy) for server in ((n / 2) as usize)..n as usize { - assert_eq!(bonds[validator as usize][server], I32F32::from_num(53619)); + assert_eq!(bonds[validator as usize][server], I32F32::from_num(65535)); // floor(0.45*(2^16-1))/(2^16-1), then max-upscale } } @@ -1738,15 +1733,15 @@ fn test_active_stake() { P: [0.272501133, 0.2274988669, 0.25, 0.25] P (u16): [65535, 54711, 60123, 60123] */ let bonds = SubtensorModule::get_bonds(netuid); - assert_eq!(SubtensorModule::get_dividends_for_uid(netuid, 0), 35716); // Note D = floor((0.55 * 0.9 + 0.5 * 0.1) * 65_535) - assert_eq!(SubtensorModule::get_emission_for_uid(netuid, 0), 272501132); // Note E = 0.5 * (0.55 * 0.9 + 0.5 * 0.1) * 1_000_000_000 = 272_500_000 (discrepancy) + assert_eq!(SubtensorModule::get_dividends_for_uid(netuid, 0), 32767); // Note D = floor((0.55 * 0.9 + 0.5 * 0.1) * 65_535) + assert_eq!(SubtensorModule::get_emission_for_uid(netuid, 0), 250000000); // Note E = 0.5 * (0.55 * 0.9 + 0.5 * 0.1) * 1_000_000_000 = 272_500_000 (discrepancy) for server in ((n / 2) as usize)..n as usize { assert_eq!(bonds[0][server], I32F32::from_num(65_535)); // floor((0.55 * 0.9 + 0.5 * 0.1)*(2^16-1))/(2^16-1), then max-upscale } - assert_eq!(SubtensorModule::get_dividends_for_uid(netuid, 1), 29818); // Note D = floor((0.45 * 0.9 + 0.5 * 0.1) * 65_535) - assert_eq!(SubtensorModule::get_emission_for_uid(netuid, 1), 227498866); // Note E = 0.5 * (0.45 * 0.9 + 0.5 * 0.1) * 1_000_000_000 = 227_500_000 (discrepancy) + assert_eq!(SubtensorModule::get_dividends_for_uid(netuid, 1), 32767); // Note D = floor((0.45 * 0.9 + 0.5 * 0.1) * 65_535) + assert_eq!(SubtensorModule::get_emission_for_uid(netuid, 1), 250000000); // Note E = 0.5 * (0.45 * 0.9 + 0.5 * 0.1) * 1_000_000_000 = 227_500_000 (discrepancy) for server in ((n / 2) as usize)..n as usize { - assert_eq!(bonds[1][server], I32F32::from_num(54712)); // floor((0.45 * 0.9 + 0.5 * 0.1)/(0.55 * 0.9 + 0.5 * 0.1)*(2^16-1)) + assert_eq!(bonds[1][server], I32F32::from_num(65_535)); // floor((0.45 * 0.9 + 0.5 * 0.1)/(0.55 * 0.9 + 0.5 * 0.1)*(2^16-1)) } }); } @@ -2730,15 +2725,16 @@ fn test_compute_ema_bonds_sparse() { // For bond (1, 1): // EMA = 0.8 * 0.4 + (1 - 0.8) * 0.8 = 0.32 + 0.16 = 0.48 let expected_ema_bonds = vec![ - vec![(0, I32F32::from_num(0.14)), (1, I32F32::from_num(0.28))], - vec![(0, I32F32::from_num(0.34)), (1, I32F32::from_num(0.48))], + vec![(0, I32F32::from_num(0.1309)), (1, I32F32::from_num(0.2479))], + vec![(0, I32F32::from_num(0.3129)), (1, I32F32::from_num(0.4159))], ]; // Call the function let ema_bonds = SubtensorModule::compute_ema_bonds_sparse(&bonds_delta, &bonds, alpha); // Assert the results with an epsilon for approximate equality - let epsilon = I32F32::from_num(1e-6); + let epsilon = I32F32::from_num(1e-4); + assert_approx_eq_vec_of_vec(&ema_bonds, &expected_ema_bonds, epsilon); } diff --git a/pallets/subtensor/src/tests/math.rs b/pallets/subtensor/src/tests/math.rs index 3500acf589..51ca7a8fbb 100644 --- a/pallets/subtensor/src/tests/math.rs +++ b/pallets/subtensor/src/tests/math.rs @@ -2134,72 +2134,92 @@ fn test_math_hadamard_sparse() { #[test] fn test_math_mat_ema() { - let old: Vec = vec![1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12.]; - let new: Vec = vec![ - 10., 20., 30., 40., 50., 60., 70., 80., 90., 100., 110., 120., + let old: Vec = vec![ + 0.1, 0.2, 3., 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.10, 0.11, 0.12, ]; + let new: Vec = vec![1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12.]; let target: Vec = vec![ - 1.9, 3.8, 5.7, 7.6, 9.5, 11.4, 13.3, 15.2, 17.1, 19., 20.9, 22.8, + 0.19, 0.38, 1., 0.4359, 0.545, 0.6539, 0.763, 0.8719, 0.981, 1., 1., 1., ]; + let old = vec_to_mat_fixed(&old, 4, false); let new = vec_to_mat_fixed(&new, 4, false); let target = vec_to_mat_fixed(&target, 4, false); - let result = mat_ema_alpha_vec(&new, &old, &vec![I32F32::from_num(0.1); old.len()]); - assert_mat_compare(&result, &target, I32F32::from_num(0.000001)); - let old: Vec = vec![1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12.]; + let result = mat_ema_alpha_vec(&new, &old, &vec![I32F32::from_num(0.1); 3]); + assert_mat_compare(&result, &target, I32F32::from_num(1e-4)); + let old: Vec = vec![ + 0.1, 0.2, 3., 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.10, 0.11, 0.12, + ]; let new: Vec = vec![ 10., 20., 30., 40., 50., 60., 70., 80., 90., 100., 110., 120., ]; - let target: Vec = vec![1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12.]; + let target: Vec = vec![ + 0.10, 0.2, 1., 0.0399, 0.05, 0.0599, 0.07, 0.07999, 0.09, 0.1, 0.10999, 0.11999, + ]; let old = vec_to_mat_fixed(&old, 4, false); let new = vec_to_mat_fixed(&new, 4, false); let target = vec_to_mat_fixed(&target, 4, false); - let result = mat_ema_alpha_vec(&new, &old, &vec![I32F32::from_num(0); old.len()]); - assert_mat_compare(&result, &target, I32F32::from_num(0.000001)); - let old: Vec = vec![1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12.]; + let result = mat_ema_alpha_vec(&new, &old, &vec![I32F32::from_num(0); 3]); + assert_mat_compare(&result, &target, I32F32::from_num(1e-4)); + let old: Vec = vec![ + 0.001, 0.002, 0.003, 0.004, 0.05, 0.006, 0.007, 0.008, 0.009, 0.010, 0.011, 0.012, + ]; let new: Vec = vec![ - 10., 20., 30., 40., 50., 60., 70., 80., 90., 100., 110., 120., + 0.1, 0.2, 3., 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.10, 0.11, 0.12, ]; let target: Vec = vec![ - 10., 20., 30., 40., 50., 60., 70., 80., 90., 100., 110., 120., + 0.10, 0.2, 1., 0.0399, 0.05, 0.0599, 0.07, 0.07999, 0.09, 0.1, 0.10999, 0.11999, ]; + let old = vec_to_mat_fixed(&old, 4, false); let new = vec_to_mat_fixed(&new, 4, false); let target = vec_to_mat_fixed(&target, 4, false); - let result = mat_ema_alpha_vec(&new, &old, &vec![I32F32::from_num(1); old.len()]); - assert_mat_compare(&result, &target, I32F32::from_num(0.000001)); + let result = mat_ema_alpha_vec(&new, &old, &vec![I32F32::from_num(1); 3]); + assert_mat_compare(&result, &target, I32F32::from_num(1e-4)); } #[test] fn test_math_sparse_mat_ema() { - let old: Vec = vec![1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12.]; - let new: Vec = vec![ - 10., 20., 30., 40., 50., 60., 70., 80., 90., 100., 110., 120., + let old: Vec = vec![ + 0.1, 0.2, 3., 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.10, 0.11, 0.12, ]; + let new: Vec = vec![1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12.]; let target: Vec = vec![ - 1.9, 3.8, 5.7, 7.6, 9.5, 11.4, 13.3, 15.2, 17.1, 19., 20.9, 22.8, + 0.1, 0.2, 1., 0.0759, 0.095, 0.11399, 0.133, 0.15199, 0.171, 0.19, 0.20899, 0.22799, ]; let old = vec_to_sparse_mat_fixed(&old, 4, false); let new = vec_to_sparse_mat_fixed(&new, 4, false); let target = vec_to_sparse_mat_fixed(&target, 4, false); let result = mat_ema_alpha_vec_sparse(&new, &old, &vec![I32F32::from_num(0.1); old.len()]); - assert_sparse_mat_compare(&result, &target, I32F32::from_num(0.000001)); - let old: Vec = vec![0., 2., 3., 4., 0., 6., 7., 8., 0., 10., 11., 12.]; - let new: Vec = vec![10., 20., 0., 40., 0., 60., 0., 80., 90., 100., 110., 120.]; - let target: Vec = vec![1., 3.8, 2.7, 7.6, 0., 11.4, 6.3, 15.2, 9., 19., 20.9, 22.8]; + assert_sparse_mat_compare(&result, &target, I32F32::from_num(1e-4)); + let old: Vec = vec![ + 0.001, 0.002, 0.003, 0.004, 0.05, 0.006, 0.007, 0.008, 0.009, 0.010, 0.011, 0.012, + ]; + let new: Vec = vec![ + 0.1, 0.2, 3., 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.10, 0.11, 0.12, + ]; + let target: Vec = vec![ + 0.0019, 0.003799, 0.032699, 0.00399, 0.0455, 0.00599, 0.007, 0.008, 0.00899, 0.0099, + 0.01099, 0.01199, + ]; let old = vec_to_sparse_mat_fixed(&old, 4, false); let new = vec_to_sparse_mat_fixed(&new, 4, false); let target = vec_to_sparse_mat_fixed(&target, 4, false); let result = mat_ema_alpha_vec_sparse(&new, &old, &vec![I32F32::from_num(0.1); old.len()]); - assert_sparse_mat_compare(&result, &target, I32F32::from_num(0.000001)); + assert_sparse_mat_compare(&result, &target, I32F32::from_num(1e-4)); let old: Vec = vec![0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]; - let new: Vec = vec![10., 20., 0., 40., 0., 60., 0., 80., 90., 100., 110., 120.]; - let target: Vec = vec![1., 2., 0., 4., 0., 6., 0., 8., 9., 10., 11., 12.]; + let new: Vec = vec![ + 0.1, 0.2, 3., 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.10, 0.11, 0.12, + ]; + let target: Vec = vec![ + 0.01, 0.02, 0.3, 0.00399, 0.005, 0.00599, 0.007, 0.00799, 0.009, 0.01, 0.011, 0.01199, + ]; + let old = vec_to_sparse_mat_fixed(&old, 4, false); let new = vec_to_sparse_mat_fixed(&new, 4, false); let target = vec_to_sparse_mat_fixed(&target, 4, false); let result = mat_ema_alpha_vec_sparse(&new, &old, &vec![I32F32::from_num(0.1); old.len()]); - assert_sparse_mat_compare(&result, &target, I32F32::from_num(0.000001)); + assert_sparse_mat_compare(&result, &target, I32F32::from_num(1e-4)); let old: Vec = vec![0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]; let new: Vec = vec![0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]; let target: Vec = vec![0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]; @@ -2207,7 +2227,7 @@ fn test_math_sparse_mat_ema() { let new = vec_to_sparse_mat_fixed(&new, 4, false); let target = vec_to_sparse_mat_fixed(&target, 4, false); let result = mat_ema_alpha_vec_sparse(&new, &old, &vec![I32F32::from_num(0.1); old.len()]); - assert_sparse_mat_compare(&result, &target, I32F32::from_num(0.000001)); + assert_sparse_mat_compare(&result, &target, I32F32::from_num(1e-4)); let old: Vec = vec![1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]; let new: Vec = vec![0., 0., 0., 0., 2., 0., 0., 0., 0., 0., 0., 0.]; let target: Vec = vec![0.9, 0., 0., 0., 0.2, 0., 0., 0., 0., 0., 0., 0.]; @@ -2215,7 +2235,7 @@ fn test_math_sparse_mat_ema() { let new = vec_to_sparse_mat_fixed(&new, 4, false); let target = vec_to_sparse_mat_fixed(&target, 4, false); let result = mat_ema_alpha_vec_sparse(&new, &old, &vec![I32F32::from_num(0.1); old.len()]); - assert_sparse_mat_compare(&result, &target, I32F32::from_num(0.000001)); + assert_sparse_mat_compare(&result, &target, I32F32::from_num(1e-4)); } #[test] @@ -2519,7 +2539,7 @@ fn test_mat_ema_alpha_vec_sparse_single_element() { let old: Vec> = vec![vec![(0, I32F32::from_num(2.0))]]; let alpha: Vec = vec![I32F32::from_num(0.5)]; let result = mat_ema_alpha_vec_sparse(&new, &old, &alpha); - assert_eq!(result, vec![vec![(0, I32F32::from_num(1.5))]]); + assert_eq!(result, vec![vec![(0, I32F32::from_num(1.0))]]); } #[test] @@ -2535,8 +2555,8 @@ fn test_mat_ema_alpha_vec_sparse_multiple_elements() { let alpha: Vec = vec![I32F32::from_num(0.1), I32F32::from_num(0.2)]; let result = mat_ema_alpha_vec_sparse(&new, &old, &alpha); let expected = vec![ - vec![(0, I32F32::from_num(4.6)), (1, I32F32::from_num(5.2))], - vec![(0, I32F32::from_num(6.6)), (1, I32F32::from_num(7.2))], + vec![(0, I32F32::from_num(1.0)), (1, I32F32::from_num(1.0))], + vec![(0, I32F32::from_num(1.0)), (1, I32F32::from_num(1.0))], ]; assert_sparse_mat_compare(&result, &expected, I32F32::from_num(0.000001)); } @@ -2547,7 +2567,7 @@ fn test_mat_ema_alpha_vec_sparse_zero_alpha() { let old: Vec> = vec![vec![(0, I32F32::from_num(2.0))]]; let alpha: Vec = vec![I32F32::from_num(0.0)]; let result = mat_ema_alpha_vec_sparse(&new, &old, &alpha); - assert_eq!(result, vec![vec![(0, I32F32::from_num(2.0))]]); + assert_eq!(result, vec![vec![(0, I32F32::from_num(1.0))]]); } #[test] @@ -2574,8 +2594,8 @@ fn test_mat_ema_alpha_vec_sparse_mixed_alpha() { assert_sparse_mat_compare( &result, &[ - vec![(0, I32F32::from_num(3.8)), (1, I32F32::from_num(3.2))], - vec![(0, I32F32::from_num(5.8)), (1, I32F32::from_num(5.2))], + vec![(0, I32F32::from_num(1.0)), (1, I32F32::from_num(1.0))], + vec![(0, I32F32::from_num(1.0)), (1, I32F32::from_num(1.0))], ], I32F32::from_num(0.000001), ); @@ -2596,8 +2616,8 @@ fn test_mat_ema_alpha_vec_sparse_sparse_matrix() { assert_eq!( result, vec![ - vec![(0, I32F32::from_num(3.0))], - vec![(1, I32F32::from_num(6.0))] + vec![(0, I32F32::from_num(1.0))], + vec![(1, I32F32::from_num(1.0))] ] ); } @@ -2611,7 +2631,7 @@ fn test_mat_ema_alpha_vec_basic() { I32F32::from_num(0.5), I32F32::from_num(0.5), ]; - let expected = mat_to_fixed(&[vec![0.75, 1.75, 2.75], vec![3.75, 4.75, 5.75]]); + let expected = mat_to_fixed(&[vec![0.75, 1.0, 1.0], vec![1.0, 1.0, 1.0]]); let result = mat_ema_alpha_vec(&new, &old, &alpha); assert_eq!(result, expected); } @@ -2625,7 +2645,7 @@ fn test_mat_ema_alpha_vec_varying_alpha() { I32F32::from_num(0.5), I32F32::from_num(0.8), ]; - let expected = mat_to_fixed(&[vec![0.6, 1.75, 2.9], vec![3.6, 4.75, 5.9]]); + let expected = mat_to_fixed(&[vec![0.6, 1.0, 1.0], vec![1.0, 1.0, 1.0]]); let result = mat_ema_alpha_vec(&new, &old, &alpha); assert_mat_approx_eq(&result, &expected, I32F32::from_num(1e-6)); } From f6c062a362943329ed41b50f53be92d1170639ef Mon Sep 17 00:00:00 2001 From: Andreea Popescu Date: Tue, 28 Jan 2025 09:56:13 +0000 Subject: [PATCH 06/45] compute_ema_bonds param rename --- pallets/subtensor/src/epoch/run_epoch.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pallets/subtensor/src/epoch/run_epoch.rs b/pallets/subtensor/src/epoch/run_epoch.rs index 36510532ce..26607422ec 100644 --- a/pallets/subtensor/src/epoch/run_epoch.rs +++ b/pallets/subtensor/src/epoch/run_epoch.rs @@ -995,19 +995,19 @@ impl Pallet { /// Compute the Exponential Moving Average (EMA) of bonds using the alpha values for a sparse matrix. /// /// # Args: - /// * `bonds_delta` - A vector of bond deltas. + /// * `weights` - A vector of weights. /// * `bonds` - A vector of bonds. /// * `alpha` - A vector of clamped alpha values (for liquid alpha) or constant alpha values. /// /// # Returns: /// A vector of EMA bonds. pub fn compute_ema_bonds_sparse( - bonds_delta: &[Vec<(u16, I32F32)>], + weights: &[Vec<(u16, I32F32)>], bonds: &[Vec<(u16, I32F32)>], alpha: Vec, ) -> Vec> { // Compute the Exponential Moving Average (EMA) of bonds using the provided clamped alpha values. - let ema_bonds = mat_ema_alpha_vec_sparse(bonds_delta, bonds, &alpha); + let ema_bonds = mat_ema_alpha_vec_sparse(weights, bonds, &alpha); // Log the computed EMA bonds for debugging purposes. log::trace!("Exponential Moving Average Bonds: {:?}", ema_bonds); @@ -1019,19 +1019,19 @@ impl Pallet { /// Compute the Exponential Moving Average (EMA) of bonds using the alpha values. /// /// # Args: - /// * `bonds_delta` - A vector of bond deltas. + /// * `weights` - A vector of weights. /// * `bonds` - A vector of bonds. /// * `alpha` - A vector of clamped alpha values (for liquid alpha) or constant alpha values. /// /// # Returns: /// A vector of EMA bonds. pub fn compute_ema_bonds( - bonds_delta: &[Vec], + weights: &[Vec], bonds: &[Vec], alpha: Vec, ) -> Vec> { // Compute the Exponential Moving Average (EMA) of bonds using the provided clamped alpha values. - let ema_bonds = mat_ema_alpha_vec(bonds_delta, bonds, &alpha); + let ema_bonds = mat_ema_alpha_vec(weights, bonds, &alpha); // Log the computed EMA bonds for debugging purposes. log::trace!("Exponential Moving Average Bonds: {:?}", ema_bonds); From b5963a906e64d20db16a7558c1fead7a4cd75326 Mon Sep 17 00:00:00 2001 From: Andreea Popescu Date: Tue, 28 Jan 2025 14:05:37 +0000 Subject: [PATCH 07/45] update tests logs --- pallets/subtensor/src/tests/epoch.rs | 900 +++++++++++++++------------ pallets/subtensor/src/tests/math.rs | 6 +- 2 files changed, 501 insertions(+), 405 deletions(-) diff --git a/pallets/subtensor/src/tests/epoch.rs b/pallets/subtensor/src/tests/epoch.rs index 9315eef06f..6760a552b3 100644 --- a/pallets/subtensor/src/tests/epoch.rs +++ b/pallets/subtensor/src/tests/epoch.rs @@ -987,305 +987,396 @@ fn test_512_graph_random_weights() { #[test] fn test_bonds() { new_test_ext(1).execute_with(|| { - let sparse: bool = true; - let n: u16 = 8; - let netuid: u16 = 1; - let tempo: u16 = 1; - let max_stake: u64 = 4; - let stakes: Vec = vec![1, 2, 3, 4, 0, 0, 0, 0]; + let sparse: bool = true; + let n: u16 = 8; + let netuid: u16 = 1; + let tempo: u16 = u16::MAX - 1; // high tempo to skip automatic epochs in on_initialize, use manual epochs instead + let max_stake: u64 = 4; + let stakes: Vec = vec![1, 2, 3, 4, 0, 0, 0, 0]; let block_number = System::block_number(); - add_network(netuid, tempo, 0); - SubtensorModule::set_max_allowed_uids( netuid, n ); - assert_eq!(SubtensorModule::get_max_allowed_uids(netuid), n); - SubtensorModule::set_max_registrations_per_block( netuid, n ); - SubtensorModule::set_target_registrations_per_interval(netuid, n); - SubtensorModule::set_weights_set_rate_limit( netuid, 0 ); - SubtensorModule::set_min_allowed_weights( netuid, 1 ); - SubtensorModule::set_max_weight_limit( netuid, u16::MAX ); - SubtensorModule::set_bonds_penalty(netuid, u16::MAX); - - - // === Register [validator1, validator2, validator3, validator4, server1, server2, server3, server4] - for key in 0..n as u64 { - SubtensorModule::add_balance_to_coldkey_account( &U256::from(key), max_stake ); - let (nonce, work): (u64, Vec) = SubtensorModule::create_work_for_block_number( netuid, block_number, key * 1_000_000, &U256::from(key)); - assert_ok!(SubtensorModule::register(<::RuntimeOrigin>::signed(U256::from(key)), netuid, block_number, nonce, work, U256::from(key), U256::from(key))); - SubtensorModule::increase_stake_for_hotkey_and_coldkey_on_subnet( &U256::from(key), &U256::from(key), netuid, stakes[key as usize] ); - } - assert_eq!(SubtensorModule::get_max_allowed_uids(netuid), n); - assert_eq!(SubtensorModule::get_subnetwork_n(netuid), n); - - // === Issue validator permits - SubtensorModule::set_max_allowed_validators(netuid, n); - assert_eq!( SubtensorModule::get_max_allowed_validators(netuid), n); - SubtensorModule::epoch( netuid, 1_000_000_000 ); // run first epoch to set allowed validators - next_block_no_epoch(netuid); // run to next block to ensure weights are set on nodes after their registration block + add_network(netuid, tempo, 0); + SubtensorModule::set_max_allowed_uids(netuid, n); + assert_eq!(SubtensorModule::get_max_allowed_uids(netuid), n); + SubtensorModule::set_max_registrations_per_block(netuid, n); + SubtensorModule::set_target_registrations_per_interval(netuid, n); + SubtensorModule::set_weights_set_rate_limit(netuid, 0); + SubtensorModule::set_min_allowed_weights(netuid, 1); + SubtensorModule::set_max_weight_limit(netuid, u16::MAX); + SubtensorModule::set_bonds_penalty(netuid, u16::MAX); - // === Set weights [val->srv1: 0.1, val->srv2: 0.2, val->srv3: 0.3, val->srv4: 0.4] - for uid in 0..(n/2) as u64 { - assert_ok!(SubtensorModule::set_weights(RuntimeOrigin::signed(U256::from(uid)), netuid, ((n/2)..n).collect(), vec![ u16::MAX/4, u16::MAX/2, (u16::MAX/4)*3, u16::MAX], 0)); - } - if sparse { SubtensorModule::epoch( netuid, 1_000_000_000 ); } - else { SubtensorModule::epoch_dense( netuid, 1_000_000_000 ); } - /* n: 8 - current_block: 1; activity_cutoff: 5000; Last update: [1, 1, 1, 1, 0, 0, 0, 0] - Inactive: [false, false, false, false, false, false, false, false] - Block at registration: [0, 0, 0, 0, 0, 0, 0, 0] - hotkeys: [(0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7)] - S: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] - validator_permits: [true, true, true, true, true, true, true, true] - max_allowed_validators: 8 - new_validator_permits: [true, true, true, true, true, true, true, true] - S: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] - W: [[(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - W (permit): [[(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - W (permit+diag): [[(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - W (permit+diag+outdate): [[(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - W (mask+norm): [[(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] - R (before): [0, 0, 0, 0, 0.099997558, 0.2000012202, 0.2999926745, 0.4000085443] - C: [0, 0, 0, 0, 0.0999975584, 0.2000012207, 0.2999926754, 0.400008545] - W: [[(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] - Tv: [0.9999999995, 0.9999999995, 0.9999999995, 0.9999999995, 0, 0, 0, 0] - R (after): [0, 0, 0, 0, 0.099997558, 0.2000012202, 0.2999926745, 0.4000085443] - T: [0, 0, 0, 0, 1, 1, 1, 1] - I (=R): [0, 0, 0, 0, 0.0999975582, 0.2000012207, 0.2999926752, 0.4000085455] - B: [[], [], [], [], [], [], [], []] - B (outdatedmask): [[], [], [], [], [], [], [], []] - B (mask+norm): [[], [], [], [], [], [], [], []] - ΔB: [[(4, 0.0099997558), (5, 0.020000122), (6, 0.0299992673), (7, 0.0400008543)], [(4, 0.0199995115), (5, 0.040000244), (6, 0.0599985349), (7, 0.0800017088)], [(4, 0.0299992673), (5, 0.060000366), (6, 0.0899978024), (7, 0.1200025633)], [(4, 0.0399990233), (5, 0.080000488), (6, 0.11999707), (7, 0.1600034179)], [], [], [], []] - ΔB (norm): [[(4, 0.0999999996), (5, 0.0999999999), (6, 0.0999999994), (7, 0.0999999996)], [(4, 0.1999999995), (5, 0.2), (6, 0.1999999997), (7, 0.1999999997)], [(4, 0.299999999), (5, 0.2999999998), (6, 0.3), (7, 0.3)], [(4, 0.4000000013), (5, 0.4), (6, 0.4000000004), (7, 0.4000000001)], [], [], [], []] - emaB: [[(4, 0.0999999982), (5, 0.0999999985), (6, 0.099999998), (7, 0.099999998)], [(4, 0.199999999), (5, 0.1999999995), (6, 0.1999999986), (7, 0.1999999986)], [(4, 0.2999999996), (5, 0.3000000003), (6, 0.3000000012), (7, 0.3000000012)], [(4, 0.4000000027), (5, 0.4000000013), (6, 0.4000000018), (7, 0.4000000018)], [], [], [], []] - D: [0.0999999978, 0.1999999983, 0.3000000012, 0.4000000022, 0, 0, 0, 0] - nE: [0.0499999989, 0.0999999992, 0.1500000006, 0.2000000011, 0.049998779, 0.1000006103, 0.1499963375, 0.2000042726] - E: [49999998, 99999999, 150000000, 200000001, 49998779, 100000610, 149996337, 200004272] - P: [0.0499999989, 0.0999999992, 0.1500000006, 0.2000000011, 0.049998779, 0.1000006103, 0.1499963375, 0.2000042726] - emaB: [[(4, 0.2499999937), (5, 0.2499999953), (6, 0.2499999937), (7, 0.2499999937)], [(4, 0.4999999942), (5, 0.499999997), (6, 0.4999999942), (7, 0.4999999942)], [(4, 0.7499999937), (5, 0.7499999981), (6, 0.7499999995), (7, 0.7499999995)], [(4, 1), (5, 1), (6, 1), (7, 1)], [], [], [], []] */ - let bonds = SubtensorModule::get_bonds( netuid ); - assert_eq!(bonds[0][4], 65535); - assert_eq!(bonds[1][4], 65535); - assert_eq!(bonds[2][4], 65535); - assert_eq!(bonds[3][4], 65535); - - // === Set self-weight only on val1 - let uid = 0; - assert_ok!(SubtensorModule::set_weights(RuntimeOrigin::signed(U256::from(uid)), netuid, vec![uid], vec![u16::MAX], 0)); - next_block_no_epoch(netuid); + // === Register [validator1, validator2, validator3, validator4, server1, server2, server3, server4] + for key in 0..n as u64 { + SubtensorModule::add_balance_to_coldkey_account(&U256::from(key), max_stake); + let (nonce, work): (u64, Vec) = SubtensorModule::create_work_for_block_number( + netuid, + block_number, + key * 1_000_000, + &U256::from(key), + ); + assert_ok!(SubtensorModule::register( + <::RuntimeOrigin>::signed(U256::from(key)), + netuid, + block_number, + nonce, + work, + U256::from(key), + U256::from(key) + )); + SubtensorModule::increase_stake_for_hotkey_and_coldkey_on_subnet( + &U256::from(key), + &U256::from(key), + netuid, + stakes[key as usize], + ); + } + assert_eq!(SubtensorModule::get_max_allowed_uids(netuid), n); + assert_eq!(SubtensorModule::get_subnetwork_n(netuid), n); - if sparse { SubtensorModule::epoch( netuid, 1_000_000_000 ); } - else { SubtensorModule::epoch_dense( netuid, 1_000_000_000 ); } - /* n: 8 - current_block: 2 - activity_cutoff: 5000 - Last update: [1, 1, 1, 1, 0, 0, 0, 0] - Inactive: [false, false, false, false, false, false, false, false] - Block at registration: [0, 0, 0, 0, 0, 0, 0, 0] - hotkeys: [(0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7)] - S: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] - validator_permits: [true, true, true, true, true, true, true, true] - max_allowed_validators: 8 - new_validator_permits: [true, true, true, true, true, true, true, true] - S: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] - W: [[(0, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - W (permit): [[(0, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - W (permit+diag): [[], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - W (permit+diag+outdate): [[], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - W (mask+norm): [[], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] - R (before): [0, 0, 0, 0, 0.0899978022, 0.1800010982, 0.2699934072, 0.36000769] - C: [0, 0, 0, 0, 0.0999975584, 0.2000012207, 0.2999926754, 0.400008545] - W: [[], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] - Tv: [0, 0.9999999995, 0.9999999995, 0.9999999995, 0, 0, 0, 0] - R (after): [0, 0, 0, 0, 0.0899978022, 0.1800010982, 0.2699934072, 0.36000769] - T: [0, 0, 0, 0, 1, 1, 1, 1] - I (=R): [0, 0, 0, 0, 0.0999975582, 0.2000012207, 0.2999926754, 0.4000085455] - B: [[(4, 16383), (5, 16383), (6, 16383), (7, 16383)], [(4, 32767), (5, 32767), (6, 32767), (7, 32767)], [(4, 49151), (5, 49151), (6, 49151), (7, 49151)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [], [], [], []] - B (outdatedmask): [[(4, 16383), (5, 16383), (6, 16383), (7, 16383)], [(4, 32767), (5, 32767), (6, 32767), (7, 32767)], [(4, 49151), (5, 49151), (6, 49151), (7, 49151)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [], [], [], []] - B (mask+norm): [[(4, 0.0999963377), (5, 0.0999963377), (6, 0.0999963377), (7, 0.0999963377)], [(4, 0.1999987792), (5, 0.1999987792), (6, 0.1999987792), (7, 0.1999987792)], [(4, 0.3000012205), (5, 0.3000012205), (6, 0.3000012205), (7, 0.3000012205)], [(4, 0.400003662), (5, 0.400003662), (6, 0.400003662), (7, 0.400003662)], [], [], [], []] - ΔB: [[], [(4, 0.0199995115), (5, 0.040000244), (6, 0.0599985349), (7, 0.0800017088)], [(4, 0.0299992673), (5, 0.060000366), (6, 0.0899978024), (7, 0.1200025633)], [(4, 0.0399990233), (5, 0.080000488), (6, 0.11999707), (7, 0.1600034179)], [], [], [], []] - ΔB (norm): [[], [(4, 0.2222222215), (5, 0.222222222), (6, 0.2222222218), (7, 0.2222222218)], [(4, 0.3333333323), (5, 0.3333333333), (6, 0.3333333333), (7, 0.3333333333)], [(4, 0.4444444457), (5, 0.4444444443), (6, 0.4444444447), (7, 0.4444444445)], [], [], [], []] - emaB: [[(4, 0.0899967037), (5, 0.0899967037), (6, 0.0899967037), (7, 0.0899967037)], [(4, 0.2022211235), (5, 0.2022211235), (6, 0.2022211235), (7, 0.2022211235)], [(4, 0.3033344317), (5, 0.3033344317), (6, 0.3033344317), (7, 0.3033344317)], [(4, 0.4044477409), (5, 0.4044477406), (6, 0.4044477406), (7, 0.4044477406)], [], [], [], []] - D: [0.0899967032, 0.2022211233, 0.303334432, 0.404447741, 0, 0, 0, 0] - nE: [0.0449983515, 0.1011105615, 0.1516672159, 0.2022238704, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] - E: [44998351, 101110561, 151667215, 202223870, 49998779, 100000610, 149996337, 200004272] - P: [0.0449983515, 0.1011105615, 0.1516672159, 0.2022238704, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] - emaB: [[(4, 0.2225175085), (5, 0.2225175085), (6, 0.2225175085), (7, 0.2225175085)], [(4, 0.499993208), (5, 0.4999932083), (6, 0.4999932083), (7, 0.4999932083)], [(4, 0.7499966028), (5, 0.7499966032), (6, 0.7499966032), (7, 0.7499966032)], [(4, 1), (5, 1), (6, 1), (7, 1)], [], [], [], []] */ - let bonds = SubtensorModule::get_bonds( netuid ); - assert_eq!(bonds[0][4], 65245); - assert_eq!(bonds[1][4], 65535); - assert_eq!(bonds[2][4], 65535); - assert_eq!(bonds[3][4], 65535); - - // === Set self-weight only on val2 - let uid = 1; - assert_ok!(SubtensorModule::set_weights(RuntimeOrigin::signed(U256::from(uid)), netuid, vec![uid], vec![u16::MAX], 0)); - next_block_no_epoch(netuid); + // === Issue validator permits + SubtensorModule::set_max_allowed_validators(netuid, n); + assert_eq!(SubtensorModule::get_max_allowed_validators(netuid), n); + SubtensorModule::epoch(netuid, 1_000_000_000); // run first epoch to set allowed validators + next_block(); // run to next block to ensure weights are set on nodes after their registration block - if sparse { SubtensorModule::epoch( netuid, 1_000_000_000 ); } - else { SubtensorModule::epoch_dense( netuid, 1_000_000_000 ); } - /* current_block: 3 - W: [[(0, 65535)], [(1, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - W (permit): [[(0, 65535)], [(1, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - W (permit+diag): [[], [], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - W (permit+diag+outdate): [[], [], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - W (mask+norm): [[], [], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] - R (before): [0, 0, 0, 0, 0.0699982906, 0.1400008542, 0.2099948723, 0.2800059812] - C: [0, 0, 0, 0, 0.0999975584, 0.2000012207, 0.2999926754, 0.400008545] - W: [[], [], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] - Tv: [0, 0, 0.9999999995, 0.9999999995, 0, 0, 0, 0] - R (after): [0, 0, 0, 0, 0.0699982906, 0.1400008542, 0.2099948723, 0.2800059812] - T: [0, 0, 0, 0, 1, 1, 1, 1] - I (=R): [0, 0, 0, 0, 0.0999975582, 0.2000012207, 0.2999926754, 0.4000085455] - B: [[(4, 14582), (5, 14582), (6, 14582), (7, 14582)], [(4, 32767), (5, 32767), (6, 32767), (7, 32767)], [(4, 49151), (5, 49151), (6, 49151), (7, 49151)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [], [], [], []] - B (outdatedmask): [[(4, 14582), (5, 14582), (6, 14582), (7, 14582)], [(4, 32767), (5, 32767), (6, 32767), (7, 32767)], [(4, 49151), (5, 49151), (6, 49151), (7, 49151)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [], [], [], []] - B (mask+norm): [[(4, 0.0899929027), (5, 0.0899929027), (6, 0.0899929027), (7, 0.0899929027)], [(4, 0.2022217421), (5, 0.2022217421), (6, 0.2022217421), (7, 0.2022217421)], [(4, 0.303335699), (5, 0.303335699), (6, 0.303335699), (7, 0.303335699)], [(4, 0.404449656), (5, 0.404449656), (6, 0.404449656), (7, 0.404449656)], [], [], [], []] - ΔB: [[], [], [(4, 0.0299992673), (5, 0.060000366), (6, 0.0899978024), (7, 0.1200025633)], [(4, 0.0399990233), (5, 0.080000488), (6, 0.11999707), (7, 0.1600034179)], [], [], [], []] - ΔB (norm): [[], [], [(4, 0.428571427), (5, 0.4285714284), (6, 0.4285714284), (7, 0.4285714284)], [(4, 0.5714285728), (5, 0.5714285714), (6, 0.5714285714), (7, 0.5714285714)], [], [], [], []] - emaB: [[(4, 0.0809936123), (5, 0.0809936123), (6, 0.0809936123), (7, 0.0809936123)], [(4, 0.181999568), (5, 0.181999568), (6, 0.181999568), (7, 0.181999568)], [(4, 0.3158592717), (5, 0.315859272), (6, 0.315859272), (7, 0.315859272)], [(4, 0.4211475477), (5, 0.4211475474), (6, 0.4211475474), (7, 0.4211475474)], [], [], [], []] - D: [0.0809936118, 0.1819995677, 0.3158592721, 0.421147548, 0, 0, 0, 0] - nE: [0.040496806, 0.0909997837, 0.157929636, 0.2105737738, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] - E: [40496805, 90999783, 157929636, 210573773, 49998779, 100000610, 149996337, 200004272] - P: [0.040496806, 0.0909997837, 0.157929636, 0.2105737738, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] - emaB: [[(4, 0.192316476), (5, 0.192316476), (6, 0.192316476), (7, 0.192316476)], [(4, 0.4321515555), (5, 0.4321515558), (6, 0.4321515558), (7, 0.4321515558)], [(4, 0.7499967015), (5, 0.7499967027), (6, 0.7499967027), (7, 0.7499967027)], [(4, 1), (5, 1), (6, 1), (7, 1)], [], [], [], []] */ - let bonds = SubtensorModule::get_bonds( netuid ); - assert_eq!(bonds[0][4], 64956); - assert_eq!(bonds[1][4], 65245); - assert_eq!(bonds[2][4], 65535); - assert_eq!(bonds[3][4], 65535); - - // === Set self-weight only on val3 - let uid = 2; - assert_ok!(SubtensorModule::set_weights(RuntimeOrigin::signed(U256::from(uid)), netuid, vec![uid], vec![u16::MAX], 0)); - next_block_no_epoch(netuid); + // === Set weights [val->srv1: 0.1, val->srv2: 0.2, val->srv3: 0.3, val->srv4: 0.4] + for uid in 0..(n / 2) as u64 { + assert_ok!(SubtensorModule::set_weights( + RuntimeOrigin::signed(U256::from(uid)), + netuid, + ((n / 2)..n).collect(), + vec![u16::MAX / 4, u16::MAX / 2, (u16::MAX / 4) * 3, u16::MAX], + 0 + )); + } + if sparse { + SubtensorModule::epoch(netuid, 1_000_000_000); + } else { + SubtensorModule::epoch_dense(netuid, 1_000_000_000); + } + /* n: 8 + current_block: 2 + activity_cutoff: 5000 + Last update: [2, 2, 2, 2, 1, 1, 1, 1] + Inactive: [false, false, false, false, false, false, false, false] + Block at registration: [1, 1, 1, 1, 1, 1, 1, 1] + hotkeys: [(0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7)] + Normalised Stake: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] + validator_permits: [true, true, true, true, true, true, true, true] + max_allowed_validators: 8 + new_validator_permits: [true, true, true, true, true, true, true, true] + Active Stake: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] + W: [[(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + W (permit): [[(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + W (permit+diag): [[(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + W (permit+diag+outdate): [[(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + Weights (mask+norm): [[(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] + R (before): [0, 0, 0, 0, 0.099997558, 0.2000012202, 0.2999926745, 0.4000085443] + C: [0, 0, 0, 0, 0.0999975584, 0.2000012207, 0.2999926754, 0.400008545] + Clipped Weights: [[(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] + Validator Trust: [0.9999999995, 0.9999999995, 0.9999999995, 0.9999999995, 0, 0, 0, 0] + R (after): [0, 0, 0, 0, 0.099997558, 0.2000012202, 0.2999926745, 0.4000085443] + T: [0, 0, 0, 0, 1, 1, 1, 1] + I (=R): [0, 0, 0, 0, 0.0999975582, 0.2000012207, 0.2999926752, 0.4000085455] + B: [[], [], [], [], [], [], [], []] + B (outdatedmask): [[], [], [], [], [], [], [], []] + B (mask+norm): [[], [], [], [], [], [], [], []] + alpha values: [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1] + Exponential Moving Average Bonds: [[(4, 0.25), (5, 0.25), (6, 0.25), (7, 0.25)], [(4, 0.25), (5, 0.25), (6, 0.25), (7, 0.25)], [(4, 0.25), (5, 0.25), (6, 0.25), (7, 0.25)], [(4, 0.25), (5, 0.25), (6, 0.25), (7, 0.25)], [], [], [], []] + Dividends: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] + Normalized Server Emission: [0, 0, 0, 0, 0.049998779, 0.1000006103, 0.1499963375, 0.2000042726] + Server Emission: [0, 0, 0, 0, 49998779, 100000610, 149996337, 200004272] + Normalized Validator Emission: [0.0499999998, 0.0999999999, 0.15, 0.2, 0, 0, 0, 0] + Validator Emission: [49999999, 99999999, 149999999, 199999999, 0, 0, 0, 0] + Normalized Combined Emission: [0.0499999998, 0.0999999999, 0.15, 0.2, 0.049998779, 0.1000006103, 0.1499963375, 0.2000042726] + Combined Emission: [49999999, 99999999, 149999999, 199999999, 49998779, 100000610, 149996337, 200004272] + Pruning Scores: [0.0499999998, 0.0999999999, 0.15, 0.2, 0.049998779, 0.1000006103, 0.1499963375, 0.2000042726] + */ + let bonds = SubtensorModule::get_bonds(netuid); + assert_eq!(bonds[0][4], 65535); + assert_eq!(bonds[1][4], 65535); + assert_eq!(bonds[2][4], 65535); + assert_eq!(bonds[3][4], 65535); - if sparse { SubtensorModule::epoch( netuid, 1_000_000_000 ); } - else { SubtensorModule::epoch_dense( netuid, 1_000_000_000 ); } - /* current_block: 4 - W: [[(0, 65535)], [(1, 65535)], [(2, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - W (permit): [[(0, 65535)], [(1, 65535)], [(2, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - W (permit+diag): [[], [], [], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - W (permit+diag+outdate): [[], [], [], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - W (mask+norm): [[], [], [], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] - R (before): [0, 0, 0, 0, 0.0399990233, 0.080000488, 0.11999707, 0.1600034179] - C: [0, 0, 0, 0, 0, 0, 0, 0] - W: [[], [], [], [], [], [], [], []] - Tv: [0, 0, 0, 0, 0, 0, 0, 0] - R (after): [0, 0, 0, 0, 0, 0, 0, 0] - T: [0, 0, 0, 0, 0, 0, 0, 0] - I (=R): [0, 0, 0, 0, 0, 0, 0, 0] - B: [[(4, 12603), (5, 12603), (6, 12603), (7, 12603)], [(4, 28321), (5, 28321), (6, 28321), (7, 28321)], [(4, 49151), (5, 49151), (6, 49151), (7, 49151)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [], [], [], []] - B (outdatedmask): [[(4, 12603), (5, 12603), (6, 12603), (7, 12603)], [(4, 28321), (5, 28321), (6, 28321), (7, 28321)], [(4, 49151), (5, 49151), (6, 49151), (7, 49151)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [], [], [], []] - B (mask+norm): [[(4, 0.0809909387), (5, 0.0809909387), (6, 0.0809909387), (7, 0.0809909387)], [(4, 0.1819998713), (5, 0.1819998713), (6, 0.1819998713), (7, 0.1819998713)], [(4, 0.3158601632), (5, 0.3158601632), (6, 0.3158601632), (7, 0.3158601632)], [(4, 0.4211490264), (5, 0.4211490264), (6, 0.4211490264), (7, 0.4211490264)], [], [], [], []] - ΔB: [[], [], [], [], [], [], [], []] - ΔB (norm): [[], [], [], [], [], [], [], []] - emaB: [[(4, 0.0809909385), (5, 0.0809909385), (6, 0.0809909385), (7, 0.0809909385)], [(4, 0.1819998713), (5, 0.1819998713), (6, 0.1819998713), (7, 0.1819998713)], [(4, 0.3158601632), (5, 0.3158601632), (6, 0.3158601632), (7, 0.3158601632)], [(4, 0.4211490266), (5, 0.4211490266), (6, 0.4211490266), (7, 0.4211490266)], [], [], [], []] - D: [0, 0, 0, 0, 0, 0, 0, 0] - nE: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] - E: [99999999, 199999999, 299999999, 399999999, 0, 0, 0, 0] - P: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] - emaB: [[(4, 0.1923094518), (5, 0.1923094518), (6, 0.1923094518), (7, 0.1923094518)], [(4, 0.4321507583), (5, 0.4321507583), (6, 0.4321507583), (7, 0.4321507583)], [(4, 0.7499961846), (5, 0.7499961846), (6, 0.7499961846), (7, 0.7499961846)], [(4, 1), (5, 1), (6, 1), (7, 1)], [], [], [], []] */ - let bonds = SubtensorModule::get_bonds( netuid ); - assert_eq!(bonds[0][7], 63269); - assert_eq!(bonds[1][7], 64394); - assert_eq!(bonds[2][7], 65535); - assert_eq!(bonds[3][7], 65535); - - - // === Set val3->srv4: 1 - assert_ok!(SubtensorModule::set_weights(RuntimeOrigin::signed(U256::from(2)), netuid, vec![7], vec![u16::MAX], 0)); - next_block_no_epoch(netuid); + // === Set self-weight only on val1 + let uid = 0; + assert_ok!(SubtensorModule::set_weights( + RuntimeOrigin::signed(U256::from(uid)), + netuid, + vec![uid], + vec![u16::MAX], + 0 + )); + next_block(); + if sparse { + SubtensorModule::epoch(netuid, 1_000_000_000); + } else { + SubtensorModule::epoch_dense(netuid, 1_000_000_000); + } + /* n: 8 + current_block: 2 + activity_cutoff: 5000 + Last update: [2, 2, 2, 2, 1, 1, 1, 1] + Inactive: [false, false, false, false, false, false, false, false] + Block at registration: [1, 1, 1, 1, 1, 1, 1, 1] + hotkeys: [(0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7)] + Normalised Stake: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] + validator_permits: [true, true, true, true, true, true, true, true] + max_allowed_validators: 8 + new_validator_permits: [true, true, true, true, true, true, true, true] + Active Stake: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] + W: [[(0, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + W (permit): [[(0, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + W (permit+diag): [[], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + W (permit+diag+outdate): [[], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + W (mask+norm): [[], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] + R (before): [0, 0, 0, 0, 0.0899978022, 0.1800010982, 0.2699934072, 0.36000769] + C: [0, 0, 0, 0, 0.0999975584, 0.2000012207, 0.2999926754, 0.400008545] + Clipped Weights: [[], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] + Validator Trust: [0, 0.9999999995, 0.9999999995, 0.9999999995, 0, 0, 0, 0] + R (after): [0, 0, 0, 0, 0.0899978022, 0.1800010982, 0.2699934072, 0.36000769] + T: [0, 0, 0, 0, 1, 1, 1, 1] + I (=R): [0, 0, 0, 0, 0.0999975582, 0.2000012207, 0.2999926754, 0.4000085455] + B: [[(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [], [], [], []] + B (outdatedmask): [[(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [], [], [], []] + B (mask+norm): [[(4, 0.25), (5, 0.25), (6, 0.25), (7, 0.25)], [(4, 0.25), (5, 0.25), (6, 0.25), (7, 0.25)], [(4, 0.25), (5, 0.25), (6, 0.25), (7, 0.25)], [(4, 0.25), (5, 0.25), (6, 0.25), (7, 0.25)], [], [], [], []] + alpha values: [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1] + Exponential Moving Average Bonds: [[(4, 0.2491694554), (5, 0.2483443606), (6, 0.2475248124), (7, 0.246710457)], [(4, 0.250276848), (5, 0.2505518796), (6, 0.2508250624), (7, 0.2510965143)], [(4, 0.250276848), (5, 0.2505518796), (6, 0.2508250624), (7, 0.2510965143)], [(4, 0.250276848), (5, 0.2505518796), (6, 0.2508250624), (7, 0.2510965143)], [], [], [], []] + Dividends: [0.0988155114, 0.2002632194, 0.3003948291, 0.4005264398, 0, 0, 0, 0] + Normalized Server Emission: [0, 0, 0, 0, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] + Server Emission: [0, 0, 0, 0, 49998779, 100000610, 149996337, 200004272] + Normalized Validator Emission: [0.0494077557, 0.1001316097, 0.1501974144, 0.20026322, 0, 0, 0, 0] + Validator Emission: [49407755, 100131609, 150197414, 200263219, 0, 0, 0, 0] + Normalized Combined Emission: [0.0494077557, 0.1001316097, 0.1501974144, 0.20026322, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] + Combined Emission: [49407755, 100131609, 150197414, 200263219, 49998779, 100000610, 149996337, 200004272] + Pruning Scores: [0.0494077557, 0.1001316097, 0.1501974144, 0.20026322, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] + */ - if sparse { SubtensorModule::epoch( netuid, 1_000_000_000 ); } - else { SubtensorModule::epoch_dense( netuid, 1_000_000_000 ); } - /* current_block: 5 - W: [[(0, 65535)], [(1, 65535)], [(7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - W (permit): [[(0, 65535)], [(1, 65535)], [(7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - W (permit+diag): [[], [], [(7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - W (permit+diag+outdate): [[], [], [(7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - W (mask+norm): [[], [], [(7, 1)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] - R (before): [0, 0, 0, 0, 0.0399990233, 0.080000488, 0.11999707, 0.4600034177] - C: [0, 0, 0, 0, 0, 0, 0, 0.400008545] - W: [[], [], [(7, 0.400008545)], [(7, 0.400008545)], [], [], [], []] - Tv: [0, 0, 0.400008545, 0.400008545, 0, 0, 0, 0] - R (after): [0, 0, 0, 0, 0, 0, 0, 0.2800059812] - T: [0, 0, 0, 0, 0, 0, 0, 0.6087041323] - I (=R): [0, 0, 0, 0, 0, 0, 0, 1] - B: [[(4, 12602), (5, 12602), (6, 12602), (7, 12602)], [(4, 28320), (5, 28320), (6, 28320), (7, 28320)], [(4, 49150), (5, 49150), (6, 49150), (7, 49150)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [], [], [], []] - B (outdatedmask): [[(4, 12602), (5, 12602), (6, 12602), (7, 12602)], [(4, 28320), (5, 28320), (6, 28320), (7, 28320)], [(4, 49150), (5, 49150), (6, 49150), (7, 49150)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [], [], [], []] - B (mask+norm): [[(4, 0.0809860737), (5, 0.0809860737), (6, 0.0809860737), (7, 0.0809860737)], [(4, 0.1819969537), (5, 0.1819969537), (6, 0.1819969537), (7, 0.1819969537)], [(4, 0.3158598263), (5, 0.3158598263), (6, 0.3158598263), (7, 0.3158598263)], [(4, 0.4211571459), (5, 0.4211571459), (6, 0.4211571459), (7, 0.4211571459)], [], [], [], []] - ΔB: [[], [], [(7, 0.1200025633)], [(7, 0.1600034179)], [], [], [], []] - ΔB (norm): [[], [], [(7, 0.4285714284)], [(7, 0.5714285714)], [], [], [], []] - emaB: [[(4, 0.0809860737), (5, 0.0809860737), (6, 0.0809860737), (7, 0.0728874663)], [(4, 0.1819969537), (5, 0.1819969537), (6, 0.1819969537), (7, 0.1637972582)], [(4, 0.3158598263), (5, 0.3158598263), (6, 0.3158598263), (7, 0.3271309866)], [(4, 0.421157146), (5, 0.421157146), (6, 0.421157146), (7, 0.4361842885)], [], [], [], []] - D: [0.0728874663, 0.1637972582, 0.3271309866, 0.4361842885, 0, 0, 0, 0] - nE: [0.0364437331, 0.081898629, 0.1635654932, 0.2180921442, 0, 0, 0, 0.5] - E: [36443733, 81898628, 163565493, 218092144, 0, 0, 0, 500000000] - P: [0.0364437331, 0.081898629, 0.1635654932, 0.2180921442, 0, 0, 0, 0.5] - emaB: [[(4, 0.1922941932), (5, 0.1922941932), (6, 0.1922941932), (7, 0.1671024568)], [(4, 0.4321354993), (5, 0.4321354993), (6, 0.4321354993), (7, 0.3755230587)], [(4, 0.7499809256), (5, 0.7499809256), (6, 0.7499809256), (7, 0.749983425)], [(4, 1), (5, 1), (6, 1), (7, 1)], [], [], [], []] */ - let bonds = SubtensorModule::get_bonds( netuid ); - assert_eq!(bonds[0][7], 62177); - assert_eq!(bonds[1][7], 63283); - assert_eq!(bonds[2][7], 65535); - assert_eq!(bonds[3][7], 65535); + let bonds = SubtensorModule::get_bonds(netuid); + assert_eq!(bonds[0][4], 65245); + assert_eq!(bonds[1][4], 65535); + assert_eq!(bonds[2][4], 65535); + assert_eq!(bonds[3][4], 65535); - next_block_no_epoch(netuid); + // === Set self-weight only on val2 + let uid = 1; + assert_ok!(SubtensorModule::set_weights( + RuntimeOrigin::signed(U256::from(uid)), + netuid, + vec![uid], + vec![u16::MAX], + 0 + )); + next_block(); + if sparse { + SubtensorModule::epoch(netuid, 1_000_000_000); + } else { + SubtensorModule::epoch_dense(netuid, 1_000_000_000); + } + /* current_block: 3 + W: [[(0, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + W (permit): [[(0, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + W (permit+diag): [[], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + W (permit+diag+outdate): [[], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + W (mask+norm): [[], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] + R (before): [0, 0, 0, 0, 0.0899978022, 0.1800010982, 0.2699934072, 0.36000769] + C: [0, 0, 0, 0, 0.0999975584, 0.2000012207, 0.2999926754, 0.400008545] + Clipped Weights: [[], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] + Validator Trust: [0, 0.9999999995, 0.9999999995, 0.9999999995, 0, 0, 0, 0] + R (after): [0, 0, 0, 0, 0.0899978022, 0.1800010982, 0.2699934072, 0.36000769] + T: [0, 0, 0, 0, 1, 1, 1, 1] + I (=R): [0, 0, 0, 0, 0.0999975582, 0.2000012207, 0.2999926754, 0.4000085455] + B: [[(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [], [], [], []] + B (outdatedmask): [[(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [], [], [], []] + B (mask+norm): [[(4, 0.25), (5, 0.25), (6, 0.25), (7, 0.25)], [(4, 0.25), (5, 0.25), (6, 0.25), (7, 0.25)], [(4, 0.25), (5, 0.25), (6, 0.25), (7, 0.25)], [(4, 0.25), (5, 0.25), (6, 0.25), (7, 0.25)], [], [], [], []] + alpha values: [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1] + Exponential Moving Average Bonds: [[(4, 0.2491694554), (5, 0.2483443606), (6, 0.2475248124), (7, 0.246710457)], [(4, 0.250276848), (5, 0.2505518796), (6, 0.2508250624), (7, 0.2510965143)], [(4, 0.250276848), (5, 0.2505518796), (6, 0.2508250624), (7, 0.2510965143)], [(4, 0.250276848), (5, 0.2505518796), (6, 0.2508250624), (7, 0.2510965143)], [], [], [], []] + Dividends: [0.0988155114, 0.2002632194, 0.3003948291, 0.4005264398, 0, 0, 0, 0] + Normalized Server Emission: [0, 0, 0, 0, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] + Server Emission: [0, 0, 0, 0, 49998779, 100000610, 149996337, 200004272] + Normalized Validator Emission: [0.0494077557, 0.1001316097, 0.1501974144, 0.20026322, 0, 0, 0, 0] + Validator Emission: [49407755, 100131609, 150197414, 200263219, 0, 0, 0, 0] + Normalized Combined Emission: [0.0494077557, 0.1001316097, 0.1501974144, 0.20026322, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] + Combined Emission: [49407755, 100131609, 150197414, 200263219, 49998779, 100000610, 149996337, 200004272] + Pruning Scores: [0.0494077557, 0.1001316097, 0.1501974144, 0.20026322, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] + */ - if sparse { SubtensorModule::epoch( netuid, 1_000_000_000 ); } - else { SubtensorModule::epoch_dense( netuid, 1_000_000_000 ); } - /* current_block: 6 - B: [[(4, 12601), (5, 12601), (6, 12601), (7, 10951)], [(4, 28319), (5, 28319), (6, 28319), (7, 24609)], [(4, 49149), (5, 49149), (6, 49149), (7, 49150)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [], [], [], []] - B (outdatedmask): [[(4, 12601), (5, 12601), (6, 12601), (7, 10951)], [(4, 28319), (5, 28319), (6, 28319), (7, 24609)], [(4, 49149), (5, 49149), (6, 49149), (7, 49150)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [], [], [], []] - B (mask+norm): [[(4, 0.0809812085), (5, 0.0809812085), (6, 0.0809812085), (7, 0.0728876167)], [(4, 0.181994036), (5, 0.181994036), (6, 0.181994036), (7, 0.163792472)], [(4, 0.3158594894), (5, 0.3158594894), (6, 0.3158594894), (7, 0.3271323503)], [(4, 0.4211652656), (5, 0.4211652656), (6, 0.4211652656), (7, 0.4361875602)], [], [], [], []] - ΔB: [[], [], [(7, 0.1200025633)], [(7, 0.1600034179)], [], [], [], []] - ΔB (norm): [[], [], [(7, 0.4285714284)], [(7, 0.5714285714)], [], [], [], []] - emaB: [[(4, 0.0809812082), (5, 0.0809812082), (6, 0.0809812082), (7, 0.0655988548)], [(4, 0.181994036), (5, 0.181994036), (6, 0.181994036), (7, 0.1474132247)], [(4, 0.3158594896), (5, 0.3158594896), (6, 0.3158594896), (7, 0.3372762585)], [(4, 0.4211652658), (5, 0.4211652658), (6, 0.4211652658), (7, 0.4497116616)], [], [], [], []] - D: [0.0655988548, 0.1474132247, 0.3372762585, 0.4497116616, 0, 0, 0, 0] - nE: [0.0327994274, 0.0737066122, 0.1686381293, 0.2248558307, 0, 0, 0, 0.5] - E: [32799427, 73706612, 168638129, 224855830, 0, 0, 0, 500000000] - P: [0.0327994274, 0.0737066122, 0.1686381293, 0.2248558307, 0, 0, 0, 0.5] - emaB: [[(4, 0.1922789337), (5, 0.1922789337), (6, 0.1922789337), (7, 0.1458686984)], [(4, 0.4321202405), (5, 0.4321202405), (6, 0.4321202405), (7, 0.3277949789)], [(4, 0.749965667), (5, 0.749965667), (6, 0.749965667), (7, 0.74998335)], [(4, 1), (5, 1), (6, 1), (7, 1)], [], [], [], []] */ - let bonds = SubtensorModule::get_bonds( netuid ); - assert_eq!(bonds[0][7], 61113); - assert_eq!(bonds[1][7], 62200); - assert_eq!(bonds[2][7], 65535); - assert_eq!(bonds[3][7], 65535); + let bonds = SubtensorModule::get_bonds(netuid); + assert_eq!(bonds[0][4], 64956); + assert_eq!(bonds[1][4], 65245); + assert_eq!(bonds[2][4], 65535); + assert_eq!(bonds[3][4], 65535); - next_block_no_epoch(netuid); + // === Set self-weight only on val3 + let uid = 2; + assert_ok!(SubtensorModule::set_weights( + RuntimeOrigin::signed(U256::from(uid)), + netuid, + vec![uid], + vec![u16::MAX], + 0 + )); + next_block(); + if sparse { + SubtensorModule::epoch(netuid, 1_000_000_000); + } else { + SubtensorModule::epoch_dense(netuid, 1_000_000_000); + } + /* current_block: 4 + W: [[(0, 65535)], [(1, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + W (permit): [[(0, 65535)], [(1, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + W (permit+diag): [[], [], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + W (permit+diag+outdate): [[], [], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + W (mask+norm): [[], [], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] + R (before): [0, 0, 0, 0, 0.0699982906, 0.1400008542, 0.2099948723, 0.2800059812] + C: [0, 0, 0, 0, 0.0999975584, 0.2000012207, 0.2999926754, 0.400008545] + Clipped Weights: [[], [], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] + Validator Trust: [0, 0, 0.9999999995, 0.9999999995, 0, 0, 0, 0] + R (after): [0, 0, 0, 0, 0.0699982906, 0.1400008542, 0.2099948723, 0.2800059812] + T: [0, 0, 0, 0, 1, 1, 1, 1] + I (=R): [0, 0, 0, 0, 0.0999975582, 0.2000012207, 0.2999926754, 0.4000085455] + B: [[(4, 65245), (5, 64957), (6, 64672), (7, 64390)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [], [], [], []] + B (outdatedmask): [[(4, 65245), (5, 64957), (6, 64672), (7, 64390)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [], [], [], []] + B (mask+norm): [[(4, 0.2491693716), (5, 0.248342649), (6, 0.247522744), (7, 0.246709707)], [(4, 0.250276876), (5, 0.25055245), (6, 0.2508257518), (7, 0.251096764)], [(4, 0.250276876), (5, 0.25055245), (6, 0.2508257518), (7, 0.251096764)], [(4, 0.250276876), (5, 0.25055245), (6, 0.2508257518), (7, 0.251096764)], [], [], [], []] + alpha values: [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1] + Exponential Moving Average Bonds: [[(4, 0.248616903), (5, 0.2472437813), (6, 0.2458835603), (7, 0.2445360073)], [(4, 0.249721952), (5, 0.2494438041), (6, 0.2491646945), (7, 0.248884411)], [(4, 0.2508305723), (5, 0.251656207), (6, 0.2524758724), (7, 0.2532897906)], [(4, 0.2508305723), (5, 0.251656207), (6, 0.2524758724), (7, 0.2532897906)], [], [], [], []] + Dividends: [0.097904461, 0.198416279, 0.3015768253, 0.402102434, 0, 0, 0, 0] + Normalized Server Emission: [0, 0, 0, 0, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] + Server Emission: [0, 0, 0, 0, 49998779, 100000610, 149996337, 200004272] + Normalized Validator Emission: [0.0489522305, 0.0992081393, 0.1507884127, 0.201051217, 0, 0, 0, 0] + Validator Emission: [48952230, 99208139, 150788412, 201051217, 0, 0, 0, 0] + Normalized Combined Emission: [0.0489522305, 0.0992081393, 0.1507884127, 0.201051217, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] + Combined Emission: [48952230, 99208139, 150788412, 201051217, 49998779, 100000610, 149996337, 200004272] + Pruning Scores: [0.0489522305, 0.0992081393, 0.1507884127, 0.201051217, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] + */ + let bonds = SubtensorModule::get_bonds(netuid); + assert_eq!(bonds[0][7], 63269); + assert_eq!(bonds[1][7], 64394); + assert_eq!(bonds[2][7], 65535); + assert_eq!(bonds[3][7], 65535); + + // === Set val3->srv4: 1 + assert_ok!(SubtensorModule::set_weights( + RuntimeOrigin::signed(U256::from(2)), + netuid, + vec![7], + vec![u16::MAX], + 0 + )); + next_block(); + if sparse { + SubtensorModule::epoch(netuid, 1_000_000_000); + } else { + SubtensorModule::epoch_dense(netuid, 1_000_000_000); + } + /* current_block: 5 + W: [[(0, 65535)], [(1, 65535)], [(2, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + W (permit): [[(0, 65535)], [(1, 65535)], [(2, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + W (permit+diag): [[], [], [], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + W (permit+diag+outdate): [[], [], [], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + W (mask+norm): [[], [], [], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] + R (before): [0, 0, 0, 0, 0.0399990233, 0.080000488, 0.11999707, 0.1600034179] + C: [0, 0, 0, 0, 0, 0, 0, 0] + Clipped Weights: [[], [], [], [], [], [], [], []] + Validator Trust: [0, 0, 0, 0, 0, 0, 0, 0] + R (after): [0, 0, 0, 0, 0, 0, 0, 0] + T: [0, 0, 0, 0, 0, 0, 0, 0] + I (=R): [0, 0, 0, 0, 0, 0, 0, 0] + B: [[(4, 64956), (5, 64385), (6, 63823), (7, 63270)], [(4, 65245), (5, 64958), (6, 64675), (7, 64395)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [], [], [], []] + B (outdatedmask): [[(4, 64956), (5, 64385), (6, 63823), (7, 63270)], [(4, 65245), (5, 64958), (6, 64675), (7, 64395)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [], [], [], []] + B (mask+norm): [[(4, 0.2486154223), (5, 0.247241881), (6, 0.2458816185), (7, 0.244535915)], [(4, 0.2497215534), (5, 0.249442232), (6, 0.2491639955), (7, 0.2488839931)], [(4, 0.250831512), (5, 0.2516579432), (6, 0.2524771928), (7, 0.2532900458)], [(4, 0.250831512), (5, 0.2516579432), (6, 0.2524771928), (7, 0.2532900458)], [], [], [], []] + alpha values: [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1] + Exponential Moving Average Bonds: [[(4, 0.2486154223), (5, 0.247241881), (6, 0.2458816185), (7, 0.244535915)], [(4, 0.2497215534), (5, 0.249442232), (6, 0.2491639955), (7, 0.248883993)], [(4, 0.2508315118), (5, 0.2516579432), (6, 0.2524771928), (7, 0.2532900458)], [(4, 0.2508315118), (5, 0.2516579432), (6, 0.2524771928), (7, 0.2532900458)], [], [], [], []] + Dividends: [0, 0, 0, 0, 0, 0, 0, 0] + Normalized Server Emission: [0, 0, 0, 0, 0, 0, 0, 0] + Server Emission: [0, 0, 0, 0, 0, 0, 0, 0] + Normalized Validator Emission: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] + Validator Emission: [99999999, 199999999, 299999999, 399999999, 0, 0, 0, 0] + Normalized Combined Emission: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] + Combined Emission: [99999999, 199999999, 299999999, 399999999, 0, 0, 0, 0] + Pruning Scores: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] + */ + let bonds = SubtensorModule::get_bonds(netuid); + assert_eq!(bonds[0][7], 62177); + assert_eq!(bonds[1][7], 63283); + assert_eq!(bonds[2][7], 65535); + assert_eq!(bonds[3][7], 65535); - if sparse { SubtensorModule::epoch( netuid, 1_000_000_000 ); } - else { SubtensorModule::epoch_dense( netuid, 1_000_000_000 ); } - /* current_block: 7 - B: [[(4, 12600), (5, 12600), (6, 12600), (7, 9559)], [(4, 28318), (5, 28318), (6, 28318), (7, 21482)], [(4, 49148), (5, 49148), (6, 49148), (7, 49150)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [], [], [], []] - B (outdatedmask): [[(4, 12600), (5, 12600), (6, 12600), (7, 9559)], [(4, 28318), (5, 28318), (6, 28318), (7, 21482)], [(4, 49148), (5, 49148), (6, 49148), (7, 49150)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [], [], [], []] - B (mask+norm): [[(4, 0.0809763432), (5, 0.0809763432), (6, 0.0809763432), (7, 0.065595707)], [(4, 0.1819911182), (5, 0.1819911182), (6, 0.1819911182), (7, 0.1474136391)], [(4, 0.3158591525), (5, 0.3158591525), (6, 0.3158591525), (7, 0.337276807)], [(4, 0.4211733856), (5, 0.4211733856), (6, 0.4211733856), (7, 0.4497138464)], [], [], [], []] - ΔB: [[], [], [(7, 0.1200025633)], [(7, 0.1600034179)], [], [], [], []] - ΔB (norm): [[], [], [(7, 0.4285714284)], [(7, 0.5714285714)], [], [], [], []] - emaB: [[(4, 0.080976343), (5, 0.080976343), (6, 0.080976343), (7, 0.0590361361)], [(4, 0.181991118), (5, 0.181991118), (6, 0.181991118), (7, 0.1326722752)], [(4, 0.3158591525), (5, 0.3158591525), (6, 0.3158591525), (7, 0.3464062694)], [(4, 0.4211733858), (5, 0.4211733858), (6, 0.4211733858), (7, 0.4618853189)], [], [], [], []] - D: [0.0590361361, 0.1326722752, 0.3464062694, 0.4618853189, 0, 0, 0, 0] - nE: [0.029518068, 0.0663361375, 0.1732031347, 0.2309426593, 0, 0, 0, 0.5] - E: [29518068, 66336137, 173203134, 230942659, 0, 0, 0, 500000000] - P: [0.029518068, 0.0663361375, 0.1732031347, 0.2309426593, 0, 0, 0, 0.5] - emaB: [[(4, 0.192263675), (5, 0.192263675), (6, 0.192263675), (7, 0.1278155716)], [(4, 0.4321049813), (5, 0.4321049813), (6, 0.4321049813), (7, 0.2872407278)], [(4, 0.7499504078), (5, 0.7499504078), (6, 0.7499504078), (7, 0.7499832863)], [(4, 1), (5, 1), (6, 1), (7, 1)], [], [], [], []] */ - let bonds = SubtensorModule::get_bonds( netuid ); - assert_eq!(bonds[0][7], 60076); - assert_eq!(bonds[1][7], 61145); - assert_eq!(bonds[2][7], 65535); - assert_eq!(bonds[3][7], 65535); - - next_block_no_epoch(netuid); - - if sparse { SubtensorModule::epoch( netuid, 1_000_000_000 ); } - else { SubtensorModule::epoch_dense( netuid, 1_000_000_000 ); } - /* current_block: 8 - B: [[(4, 12599), (5, 12599), (6, 12599), (7, 8376)], [(4, 28317), (5, 28317), (6, 28317), (7, 18824)], [(4, 49147), (5, 49147), (6, 49147), (7, 49150)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [], [], [], []] - B (outdatedmask): [[(4, 12599), (5, 12599), (6, 12599), (7, 8376)], [(4, 28317), (5, 28317), (6, 28317), (7, 18824)], [(4, 49147), (5, 49147), (6, 49147), (7, 49150)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [], [], [], []] - B (mask+norm): [[(4, 0.0809714776), (5, 0.0809714776), (6, 0.0809714776), (7, 0.0590337245)], [(4, 0.1819882002), (5, 0.1819882002), (6, 0.1819882002), (7, 0.1326708249)], [(4, 0.3158588156), (5, 0.3158588156), (6, 0.3158588156), (7, 0.3464073015)], [(4, 0.421181506), (5, 0.421181506), (6, 0.421181506), (7, 0.4618881487)], [], [], [], []] - ΔB: [[], [], [(7, 0.1200025633)], [(7, 0.1600034179)], [], [], [], []] - ΔB (norm): [[], [], [(7, 0.4285714284)], [(7, 0.5714285714)], [], [], [], []] - emaB: [[(4, 0.0809714776), (5, 0.0809714776), (6, 0.0809714776), (7, 0.053130352)], [(4, 0.1819882002), (5, 0.1819882002), (6, 0.1819882002), (7, 0.1194037423)], [(4, 0.3158588156), (5, 0.3158588156), (6, 0.3158588156), (7, 0.3546237142)], [(4, 0.4211815062), (5, 0.4211815062), (6, 0.4211815062), (7, 0.472842191)], [], [], [], []] - D: [0.053130352, 0.1194037423, 0.3546237142, 0.472842191, 0, 0, 0, 0] - nE: [0.026565176, 0.0597018711, 0.177311857, 0.2364210954, 0, 0, 0, 0.5] - E: [26565175, 59701871, 177311856, 236421095, 0, 0, 0, 500000000] - P: [0.026565176, 0.0597018711, 0.177311857, 0.2364210954, 0, 0, 0, 0.5] - emaB: [[(4, 0.1922484161), (5, 0.1922484161), (6, 0.1922484161), (7, 0.1123638137)], [(4, 0.4320897225), (5, 0.4320897225), (6, 0.4320897225), (7, 0.2525234516)], [(4, 0.7499351487), (5, 0.7499351487), (6, 0.7499351487), (7, 0.7499832308)], [(4, 1), (5, 1), (6, 1), (7, 1)], [], [], [], []] */ - }); + next_block(); + if sparse { + SubtensorModule::epoch(netuid, 1_000_000_000); + } else { + SubtensorModule::epoch_dense(netuid, 1_000_000_000); + } + /* current_block: 6 + B: [[(4, 64956), (5, 64384), (6, 63822), (7, 63269)], [(4, 65245), (5, 64958), (6, 64675), (7, 64394)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [], [], [], []] + B (outdatedmask): [[(4, 64956), (5, 64384), (6, 63822), (7, 63269)], [(4, 65245), (5, 64958), (6, 64675), (7, 64394)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [], [], [], []] + B (mask+norm): [[(4, 0.2486154223), (5, 0.2472389904), (6, 0.2458787132), (7, 0.2445339402)], [(4, 0.2497215534), (5, 0.24944319), (6, 0.2491649555), (7, 0.248882052)], [(4, 0.250831512), (5, 0.2516589097), (6, 0.2524781656), (7, 0.2532920036)], [(4, 0.250831512), (5, 0.2516589097), (6, 0.2524781656), (7, 0.2532920036)], [], [], [], []] + alpha values: [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1] + Exponential Moving Average Bonds: [[(4, 0.2486154223), (5, 0.2472389904), (6, 0.2458787132), (7, 0.2423794107)], [(4, 0.2497215534), (5, 0.2494431897), (6, 0.2491649555), (7, 0.2466892123)], [(4, 0.2508315118), (5, 0.2516589097), (6, 0.2524781656), (7, 0.2554656884)], [(4, 0.2508315118), (5, 0.2516589097), (6, 0.2524781656), (7, 0.2554656884)], [], [], [], []] + Dividends: [0.0960292057, 0.195473444, 0.3036417211, 0.4048556287, 0, 0, 0, 0] + Normalized Server Emission: [0, 0, 0, 0, 0, 0, 0, 0.5] + Server Emission: [0, 0, 0, 0, 0, 0, 0, 500000000] + Normalized Validator Emission: [0.0480146029, 0.0977367219, 0.1518208606, 0.2024278142, 0, 0, 0, 0] + Validator Emission: [48014602, 97736721, 151820860, 202427814, 0, 0, 0, 0] + Normalized Combined Emission: [0.0480146029, 0.0977367219, 0.1518208606, 0.2024278142, 0, 0, 0, 0.5] + Combined Emission: [48014602, 97736721, 151820860, 202427814, 0, 0, 0, 500000000] + Pruning Scores: [0.0480146029, 0.0977367219, 0.1518208606, 0.2024278142, 0, 0, 0, 0.5] + */ + let bonds = SubtensorModule::get_bonds(netuid); + assert_eq!(bonds[0][7], 61113); + assert_eq!(bonds[1][7], 62200); + assert_eq!(bonds[2][7], 65535); + assert_eq!(bonds[3][7], 65535); + + next_block(); + if sparse { + SubtensorModule::epoch(netuid, 1_000_000_000); + } else { + SubtensorModule::epoch_dense(netuid, 1_000_000_000); + } + /* current_block: 7 + B: [[(4, 64956), (5, 64383), (6, 63821), (7, 62177)], [(4, 65245), (5, 64957), (6, 64674), (7, 63283)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [], [], [], []] + B (outdatedmask): [[(4, 64956), (5, 64383), (6, 63821), (7, 62177)], [(4, 65245), (5, 64957), (6, 64674), (7, 63283)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [], [], [], []] + B (mask+norm): [[(4, 0.2486154223), (5, 0.247237049), (6, 0.2458767553), (7, 0.2423771098)], [(4, 0.2497215534), (5, 0.2494412656), (6, 0.2491630227), (7, 0.2466884963)], [(4, 0.250831512), (5, 0.2516608424), (6, 0.2524801109), (7, 0.2554671967)], [(4, 0.250831512), (5, 0.2516608424), (6, 0.2524801109), (7, 0.2554671967)], [], [], [], []] + alpha values: [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1] + Exponential Moving Average Bonds: [[(4, 0.2486154223), (5, 0.2472370488), (6, 0.2458767553), (7, 0.2402415834)], [(4, 0.2497215534), (5, 0.2494412656), (6, 0.2491630227), (7, 0.2445149834)], [(4, 0.2508315118), (5, 0.2516608424), (6, 0.2524801109), (7, 0.2576217165)], [(4, 0.2508315118), (5, 0.2516608424), (6, 0.2524801109), (7, 0.2576217165)], [], [], [], []] + Dividends: [0.0948587805, 0.1930922437, 0.3051638464, 0.4068851292, 0, 0, 0, 0] + Normalized Server Emission: [0, 0, 0, 0, 0, 0, 0, 0.5] + Server Emission: [0, 0, 0, 0, 0, 0, 0, 500000000] + Normalized Validator Emission: [0.0474293903, 0.0965461219, 0.1525819232, 0.2034425645, 0, 0, 0, 0] + Validator Emission: [47429390, 96546121, 152581923, 203442564, 0, 0, 0, 0] + Normalized Combined Emission: [0.0474293903, 0.0965461219, 0.1525819232, 0.2034425645, 0, 0, 0, 0.5] + Combined Emission: [47429390, 96546121, 152581923, 203442564, 0, 0, 0, 500000000] + Pruning Scores: [0.0474293903, 0.0965461219, 0.1525819232, 0.2034425645, 0, 0, 0, 0.5] + */ + let bonds = SubtensorModule::get_bonds(netuid); + assert_eq!(bonds[0][7], 60076); + assert_eq!(bonds[1][7], 61145); + assert_eq!(bonds[2][7], 65535); + assert_eq!(bonds[3][7], 65535); + + next_block(); + if sparse { + SubtensorModule::epoch(netuid, 1_000_000_000); + } else { + SubtensorModule::epoch_dense(netuid, 1_000_000_000); + } + /* current_block: 8 + B: [[(4, 64956), (5, 64382), (6, 63821), (7, 61113)], [(4, 65245), (5, 64956), (6, 64674), (7, 62200)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [], [], [], []] + B (outdatedmask): [[(4, 64956), (5, 64382), (6, 63821), (7, 61113)], [(4, 65245), (5, 64956), (6, 64674), (7, 62200)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [], [], [], []] + B (mask+norm): [[(4, 0.2486154223), (5, 0.247235108), (6, 0.2458767553), (7, 0.2402401103)], [(4, 0.2497215534), (5, 0.2494393412), (6, 0.2491630227), (7, 0.2445131945)], [(4, 0.250831512), (5, 0.2516627752), (6, 0.2524801109), (7, 0.2576233475)], [(4, 0.250831512), (5, 0.2516627752), (6, 0.2524801109), (7, 0.2576233475)], [], [], [], []] + alpha values: [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1] + Exponential Moving Average Bonds: [[(4, 0.2486154223), (5, 0.247235108), (6, 0.2458767553), (7, 0.2381234125)], [(4, 0.2497215534), (5, 0.2494393412), (6, 0.2491630227), (7, 0.2423588475)], [(4, 0.2508315118), (5, 0.2516627752), (6, 0.2524801109), (7, 0.2597588697)], [(4, 0.2508315118), (5, 0.2516627752), (6, 0.2524801109), (7, 0.2597588697)], [], [], [], []] + Dividends: [0.0937068302, 0.1907471363, 0.3066625856, 0.4088834478, 0, 0, 0, 0] + Normalized Server Emission: [0, 0, 0, 0, 0, 0, 0, 0.5] + Server Emission: [0, 0, 0, 0, 0, 0, 0, 500000000] + Normalized Validator Emission: [0.046853415, 0.0953735681, 0.1533312928, 0.2044417239, 0, 0, 0, 0] + Validator Emission: [46853414, 95373568, 153331292, 204441723, 0, 0, 0, 0] + Normalized Combined Emission: [0.046853415, 0.0953735681, 0.1533312928, 0.2044417239, 0, 0, 0, 0.5] + Combined Emission: [46853414, 95373568, 153331292, 204441723, 0, 0, 0, 500000000] + Pruning Scores: [0.046853415, 0.0953735681, 0.1533312928, 0.2044417239, 0, 0, 0, 0.5] + */ + }); } // SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --package pallet-subtensor --lib -- tests::epoch::test_512_graph_random_weights --exact --show-output --nocapture @@ -1362,46 +1453,42 @@ fn test_bonds_with_liquid_alpha() { let bonds = SubtensorModule::get_bonds(netuid); /* n: 8 - current_block: 2; activity_cutoff: 5000; - Last update: [1, 1, 1, 1, 0, 0, 0, 0] + current_block: 3 activity_cutoff: 5000 Last update: [2, 2, 2, 2, 1, 1, 1, 1] Inactive: [false, false, false, false, false, false, false, false] Block at registration: [1, 1, 1, 1, 1, 1, 1, 1] hotkeys: [(0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7)] - Stake: [1, 2, 3, 4, 0, 0, 0, 0] Normalised Stake: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] validator_permits: [true, true, true, true, true, true, true, true] - max_allowed_validators: 8 + max_allowed_validators: 64 new_validator_permits: [true, true, true, true, true, true, true, true] Active Stake: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] - Weights: [[(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - Weights (permit): [[(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - Weights (permit+diag): [[(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - Weights (permit+diag+outdate): [[(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - Weights (mask+norm): [[(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] - Ranks (before): [0, 0, 0, 0, 0.099997558, 0.2000012202, 0.2999926745, 0.4000085443] - Consensus: [0, 0, 0, 0, 0.0999975584, 0.2000012207, 0.2999926754, 0.400008545] - Weights: [[(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] - Validator Trust: [0.9999999995, 0.9999999995, 0.9999999995, 0.9999999995, 0, 0, 0, 0] - Ranks (after): [0, 0, 0, 0, 0.099997558, 0.2000012202, 0.2999926745, 0.4000085443] + Weights: [[(0, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, + Weights (permit): [[(0, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 327 + Weights (permit+diag): [[], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), + Weights (permit+diag+outdate): [[], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + Weights (mask+norm): [[], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] + R (before): [0, 0, 0, 0, 0.0899978022, 0.1800010982, 0.2699934072, 0.36000769] + C: [0, 0, 0, 0, 0.0999975584, 0.2000012207, 0.2999926754, 0.400008545] + Clipped Weights: [[], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] + Validator Trust: [0, 0.9999999995, 0.9999999995, 0.9999999995, 0, 0, 0, 0] + R (after): [0, 0, 0, 0, 0.0899978022, 0.1800010982, 0.2699934072, 0.36000769] T: [0, 0, 0, 0, 1, 1, 1, 1] - Incentive (=Rank): [0, 0, 0, 0, 0.0999975582, 0.2000012207, 0, 0.0999975582, 0.2000012207, 0.2999926752, 0.4000085455] - B: [[], [], [], [], [], [], [], []] - B (outdatedmask): [[], [], [], [], [], [], [], []] - B (mask+norm): [[], [], [], [], [], [], [], []] - ΔB: [[(4, 0.0099997558), (5, 0.020000122), (6, 0.0299992673), (7, 0.0400008543)], [(4, 0.0199995115), (5, 0.040000244), (6, 0.0599985349), (7, 0.0800017088)], [(4, 0.0299992673), (5, 0.060000366), (6, 0.0899978024), (7, 0.1200025633)], [(4, 0.0399990233), (5, 0.080000488), (6, 0.11999707), (7, 0.1600034179)], [], [], [], []] - ΔB (norm): [[(4, 0.0999999996), (5, 0.0999999999), (6, 0.0999999994), (7, 0.0999999996)], [(4, 0.1999999995), (5, 0.2), (6, 0.1999999997), (7, 0.1999999997)], [(4, 0.299999999), (5, 0.2999999998), (6, 0.3), (7, 0.3)], [(4, 0.4000000013), (5, 0.4), (6, 0.4000000004), (7, 0.4000000001)], [], [], [], []] - Exponential Moving Average Bonds Liquid Alpha: [[(4, 0.0499983232), (5, 0.0899999999), (6, 0.0899999994), (7, 0.0899999996)], [(4, 0.0999966469), (5, 0.18), (6, 0.1799999997), (7, 0.1799999997)], [(4, 0.1499949703), (5, 0.2699999998), (6, 0.2699999998), (7, 0.2699999998)], [(4, 0.199993295), (5, 0.3599999999), (6, 0.36), (7, 0.3599999999)], [], [], [], []] - Exponential Moving Average Bonds: [[(4, 0.0999999992), (5, 0.0999999999), (6, 0.0999999994), (7, 0.0999999996)], [(4, 0.1999999995), (5, 0.2), (6, 0.1999999997), (7, 0.1999999997)], [(4, 0.2999999993), (5, 0.2999999998), (6, 0.3), (7, 0.3)], [(4, 0.4000000015), (5, 0.4), (6, 0.4000000004), (7, 0.4000000001)], [], [], [], []] - Dividends: [0.0999999994, 0.1999999997, 0.3, 0.4000000006, 0, 0, 0, 0] - Normalized Server Emission: [0, 0, 0, 0, 0.049998779, 0.1000006103, 0.1499963375, 0.2000042726] + Incentive (=Rank): [0, 0, 0, 0, 0.0999975582, 0.2000012207, 0.2999926754, 0.4000085455] + B: [[(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [], [], [], []] + B (outdatedmask): [[(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [], [], [], []] + B (mask+norm): [[(4, 0.25), (5, 0.25), (6, 0.25), (7, 0.25)], [(4, 0.25), (5, 0.25), (6, 0.25), (7, 0.25)], [(4, 0.25), (5, 0.25), (6, 0.25), (7, 0.25)], [(4, 0.25), (5, 0.25), (6, 0.25), (7, 0.25)], [], [], [], []] + alpha values: [0.7000076314, 0.7000076314, 0.7000076314, 0.7000076314, 0.8095842435, 0.8856769793, 0.9000076293, 0.9000076293] + Exponential Moving Average Bonds: [[(4, 0.1229952155), (5, 0.0488576517), (6, 0.0301549898), (7, 0.0233184719)], [(4, 0.292334928), (5, 0.3170474493), (6, 0.32328167), (7, 0.3255605092)], [(4, 0.292334928), (5, 0.3170474493), (6, 0.32328167), (7, 0.3255605092)], [(4, 0.292334928), (5, 0.3170474493), (6, 0.32328167), (7, 0.3255605092)], [], [], [], []] + Dividends: [0.0138551355, 0.2191433029, 0.3287149547, 0.4382866067, 0, 0, 0, 0] + Normalized Server Emission: [0, 0, 0, 0, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] Server Emission: [0, 0, 0, 0, 49998779, 100000610, 149996337, 200004272] - Normalized Validator Emission: [0.0499999996, 0.0999999999, 0.15, 0.2000000002, 0, 0, 0, 0] - Validator Emission: [49999999, 99999999, 149999999, 200000000, 0, 0, 0, 0] - Normalized Combined Emission: [0.0499999996, 0.0999999999, 0.15, 0.2000000002, 0.049998779, 0.1000006103, 0.1499963375, 0.2000042726] - Combined Emission: [49999999, 99999999, 149999999, 200000000, 49998779, 100000610, 149996337, 200004272] - Pruning Scores: [0.0499999996, 0.0999999999, 0.15, 0.2000000002, 0.049998779, 0.1000006103, 0.1499963375, 0.2000042726] + Normalized Validator Emission: [0.0069275678, 0.1095716513, 0.1643574773, 0.2191433033, 0, 0, 0, 0] + Validator Emission: [6927567, 109571651, 164357477, 219143303, 0, 0, 0, 0] + Normalized Combined Emission: [0.0069275678, 0.1095716513, 0.1643574773, 0.2191433033, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] + Combined Emission: [6927567, 109571651, 164357477, 219143303, 49998779, 100000610, 149996337, 200004272] + Pruning Scores: [0.0069275678, 0.1095716513, 0.1643574773, 0.2191433033, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] */ // Expected bonds calculations @@ -1457,12 +1544,12 @@ fn test_bonds_with_liquid_alpha() { let bonds = SubtensorModule::get_bonds(netuid); /* n: 8 - current_block: 4; activity_cutoff: 5000; + current_block: 4 + activity_cutoff: 5000 Last update: [2, 3, 2, 2, 1, 1, 1, 1] Inactive: [false, false, false, false, false, false, false, false] Block at registration: [1, 1, 1, 1, 1, 1, 1, 1] hotkeys: [(0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7)] - Stake: [1, 2, 3, 4, 0, 0, 0, 0] Normalised Stake: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] validator_permits: [true, true, true, true, true, true, true, true] max_allowed_validators: 64 @@ -1473,28 +1560,26 @@ fn test_bonds_with_liquid_alpha() { Weights (permit+diag): [[], [], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] Weights (permit+diag+outdate): [[], [], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] Weights (mask+norm): [[], [], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] - Ranks (before): [0, 0, 0, 0, 0.0699982906, 0.1400008542, 0.2099948723, 0.2800059812] - Consensus: [0, 0, 0, 0, 0.0999975584, 0.2000012207, 0.2999926754, 0.400008545] - Weights: [[], [], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] + R (before): [0, 0, 0, 0, 0.0699982906, 0.1400008542, 0.2099948723, 0.2800059812] + C: [0, 0, 0, 0, 0.0999975584, 0.2000012207, 0.2999926754, 0.400008545] + Clipped Weights: [[], [], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] Validator Trust: [0, 0, 0.9999999995, 0.9999999995, 0, 0, 0, 0] - Ranks (after): [0, 0, 0, 0, 0.0699982906, 0.1400008542, 0.2099948723, 0.2800059812] + R (after): [0, 0, 0, 0, 0.0699982906, 0.1400008542, 0.2099948723, 0.2800059812] T: [0, 0, 0, 0, 1, 1, 1, 1] Incentive (=Rank): [0, 0, 0, 0, 0.0999975582, 0.2000012207, 0.2999926754, 0.4000085455] - B: [[(4, 7760), (5, 1489), (6, 1489), (7, 1489)], [(4, 32767), (5, 32767), (6, 32767), (7, 32767)], [(4, 49151), (5, 49151), (6, 49151), (7, 49151)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [], [], [], []] - B (outdatedmask): [[(4, 7760), (5, 1489), (6, 1489), (7, 1489)], [(4, 32767), (5, 32767), (6, 32767), (7, 32767)], [(4, 49151), (5, 49151), (6, 49151), (7, 49151)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [], [], [], []] - B (mask+norm): [[(4, 0.0499958121), (5, 0.00999718), (6, 0.00999718), (7, 0.00999718)], [(4, 0.211109894), (5, 0.2199983886), (6, 0.2199983886), (7, 0.2199983886)], [(4, 0.3166680625), (5, 0.3300009398), (6, 0.3300009398), (7, 0.3300009398)], [(4, 0.4222262308), (5, 0.4400034912), (6, 0.4400034912), (7, 0.4400034912)], [], [], [], []] - ΔB: [[], [], [(4, 0.0299992673), (5, 0.060000366), (6, 0.0899978024), (7, 0.1200025633)], [(4, 0.0399990233), (5, 0.080000488), (6, 0.11999707), (7, 0.1600034179)], [], [], [], []] - ΔB (norm): [[], [], [(4, 0.428571427), (5, 0.4285714284), (6, 0.4285714284), (7, 0.4285714284)], [(4, 0.5714285728), (5, 0.5714285714), (6, 0.5714285714), (7, 0.5714285714)], [], [], [], []] - Exponential Moving Average Bonds Liquid Alpha: [[(4, 0.024998744), (5, 0.000999718), (6, 0.000999718), (7, 0.000999718)], [(4, 0.105558486), (5, 0.0219998388), (6, 0.0219998388), (7, 0.0219998388)], [(4, 0.3726178685), (5, 0.4187143792), (6, 0.4187143792), (7, 0.4187143792)], [(4, 0.4968249004), (5, 0.5582860631), (6, 0.5582860631), (7, 0.5582860631)], [], [], [], []] - Exponential Moving Average Bonds: [[(4, 0.024998744), (5, 0.000999718), (6, 0.000999718), (7, 0.000999718)], [(4, 0.105558486), (5, 0.0219998388), (6, 0.0219998388), (7, 0.0219998388)], [(4, 0.3726178687), (5, 0.4187143794), (6, 0.4187143794), (7, 0.4187143794)], [(4, 0.4968249009), (5, 0.5582860636), (6, 0.5582860636), (7, 0.5582860636)], [], [], [], []] - Dividends: [0.0033995616, 0.030355499, 0.4141048414, 0.5521400978, 0, 0, 0, 0] + B: [[(4, 27572), (5, 10099), (6, 6112), (7, 4693)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [], [], [], []] + B (outdatedmask): [[(4, 27572), (5, 10099), (6, 6112), (7, 4693)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [], [], [], []] + B (mask+norm): [[(4, 0.1229921), (5, 0.048857303), (6, 0.0301504065), (7, 0.023313694)], [(4, 0.2923359666), (5, 0.3170475655), (6, 0.3232831976), (7, 0.3255621018)], [(4, 0.2923359666), (5, 0.3170475655), (6, 0.3232831976), (7, 0.3255621018)], [(4, 0.2923359666), (5, 0.3170475655), (6, 0.3232831976), (7, 0.3255621018)], [], [], [], []] + alpha values: [0.7000076314, 0.7000076314, 0.7000076314, 0.7000076314, 0.8095842435, 0.8856769793, 0.9000076293, 0.9000076293] + Exponential Moving Average Bonds: [[(4, 0.0728453742), (5, 0.0130473885), (6, 0.0051448268), (7, 0.0031164943)], [(4, 0.1731438267), (5, 0.0846678526), (6, 0.0551646315), (7, 0.0435200238)], [(4, 0.3770053994), (5, 0.4511423793), (6, 0.4698452707), (7, 0.4766817407)], [(4, 0.3770053994), (5, 0.4511423793), (6, 0.4698452707), (7, 0.4766817407)], [], [], [], []] + Dividends: [0.0037682566, 0.0405260534, 0.4095881525, 0.546117537, 0, 0, 0, 0] Normalized Server Emission: [0, 0, 0, 0, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] Server Emission: [0, 0, 0, 0, 49998779, 100000610, 149996337, 200004272] - Normalized Validator Emission: [0.0016997808, 0.0151777493, 0.2070524206, 0.2760700488, 0, 0, 0, 0] - Validator Emission: [1699780, 15177749, 207052420, 276070048, 0, 0, 0, 0] - Normalized Combined Emission: [0.0016997808, 0.0151777493, 0.2070524206, 0.2760700488, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] - Combined Emission: [1699780, 15177749, 207052420, 276070048, 49998779, 100000610, 149996337, 200004272] - Pruning Scores: [0.0016997808, 0.0151777493, 0.2070524206, 0.2760700488, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] + Normalized Validator Emission: [0.0018841282, 0.0202630267, 0.2047940763, 0.2730587684, 0, 0, 0, 0] + Validator Emission: [1884128, 20263026, 204794076, 273058768, 0, 0, 0, 0] + Normalized Combined Emission: [0.0018841282, 0.0202630267, 0.2047940763, 0.2730587684, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] + Combined Emission: [1884128, 20263026, 204794076, 273058768, 49998779, 100000610, 149996337, 200004272] + Pruning Scores: [0.0018841282, 0.0202630267, 0.2047940763, 0.2730587684, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] */ assert_eq!(bonds[0][4], 12662); @@ -1652,31 +1737,36 @@ fn test_active_stake() { SubtensorModule::epoch_dense(netuid, 1_000_000_000); } /* current_block: 5002; activity_cutoff: 5000 - Last update: [5002, 1, 0, 0]; Inactive: [false, true, true, true]; Block at registration: [0, 0, 0, 0] - S: [0.25, 0.25, 0.25, 0.25]; S (mask): [0.25, 0, 0, 0]; S (mask+norm): [1, 0, 0, 0] - validator_permits: [true, true, true, true]; max_allowed_validators: 4; new_validator_permits: [true, true, true, true] - W: [[(2, 0.4999923704), (3, 0.4999923704)], [(2, 0.4999923704), (3, 0.4999923704)], [], []] - W (permit): [[(2, 0.4999923704), (3, 0.4999923704)], [(2, 0.4999923704), (3, 0.4999923704)], [], []] - W (permit+diag): [[(2, 0.4999923704), (3, 0.4999923704)], [(2, 0.4999923704), (3, 0.4999923704)], [], []] - W (permit+diag+outdate): [[(2, 0.4999923704), (3, 0.4999923704)], [(2, 0.4999923704), (3, 0.4999923704)], [], []] - W (mask+norm): [[(2, 0.5), (3, 0.5)], [(2, 0.5), (3, 0.5)], [], []] - R: [0, 0, 0.5, 0.5] - W (threshold): [[(2, 1), (3, 1)], [(2, 1), (3, 1)], [], []] - T: [0, 0, 1, 1] - C: [0.006693358, 0.006693358, 0.9933076561, 0.9933076561] - I: [0, 0, 0.5, 0.5] - B: [[(2, 0.4999923704), (3, 0.4999923704)], [(2, 0.4999923704), (3, 0.4999923704)], [], []] - B (outdatedmask): [[(2, 0.4999923704), (3, 0.4999923704)], [(2, 0.4999923704), (3, 0.4999923704)], [], []] - B (mask+norm): [[(2, 0.5), (3, 0.5)], [(2, 0.5), (3, 0.5)], [], []] - ΔB: [[(2, 0.5), (3, 0.5)], [(2, 0), (3, 0)], [], []] - ΔB (norm): [[(2, 1), (3, 1)], [(2, 0), (3, 0)], [], []] - emaB: [[(2, 0.55), (3, 0.55)], [(2, 0.45), (3, 0.45)], [], []] - emaB (max-upscale): [[(2, 1), (3, 1)], [(2, 1), (3, 1)], [], []] - D: [0.55, 0.4499999997, 0, 0] - nE: [0.275, 0.2249999999, 0.25, 0.25] - E: [274999999, 224999999, 250000000, 250000000] - P: [0.275, 0.2249999999, 0.25, 0.25] - P (u16): [65535, 53619, 59577, 59577] */ + Last update: [5002, 1, 0, 0]; Inactive: [false, true, true, true]; Block at registration: [0, 0, 0, 0] + Normalised Stake: [0.25, 0.25, 0.25, 0.25] + validator_permits: [true, true, true, true]; max_allowed_validators: 4; new_validator_permits: [true, true, true, true] + Active Stake: [1, 0, 0, 0] + W: [[(2, 65535), (3, 65535)], [(2, 65535), (3, 65535)], [], []] + W (permit): [[(2, 65535), (3, 65535)], [(2, 65535), (3, 65535)], [], []] + W (permit+diag): [[(2, 65535), (3, 65535)], [(2, 65535), (3, 65535)], [], []] + W (permit+diag+outdate): [[(2, 65535), (3, 65535)], [(2, 65535), (3, 65535)], [], []] + W (mask+norm): [[(2, 0.5), (3, 0.5)], [(2, 0.5), (3, 0.5)], [], []] + R (before): [0, 0, 0.5, 0.5] + C: [0, 0, 0.5, 0.5] + Clipped W: [[(2, 0.5), (3, 0.5)], [(2, 0.5), (3, 0.5)], [], []] + Validator Trust: [1, 1, 0, 0] + R (after): [0, 0, 0.5, 0.5] + T: [0, 0, 1, 1] + I (=Rank): [0, 0, 0.5, 0.5] + B: [[(2, 65535), (3, 65535)], [(2, 65535), (3, 65535)], [], []] + B (outdatedmask): [[(2, 65535), (3, 65535)], [(2, 65535), (3, 65535)], [], []] + B (mask+norm): [[(2, 0.5), (3, 0.5)], [(2, 0.5), (3, 0.5)], [], []] + alpha values: [0.1, 0.1, 0.1, 0.1] + emaB: [[(2, 0.5), (3, 0.5)], [(2, 0.5), (3, 0.5)], [], []] + D: [1, 0, 0, 0] + Normalized Server Emission: [0, 0, 0.25, 0.25] + Server Emission: [0, 0, 250000000, 250000000] + Normalized Validator Emission: [0.5, 0, 0, 0] + Validator Emission: [500000000, 0, 0, 0] + Normalized Combined Emission: [0.5, 0, 0.25, 0.25] + Combined Emission: [500000000, 0, 250000000, 250000000] + Pruning Scores: [0.5, 0, 0.25, 0.25] + */ let bonds = SubtensorModule::get_bonds(netuid); assert_eq!(SubtensorModule::get_dividends_for_uid(netuid, 0), 65535); // Note D = floor((0.5 * 0.9 + 0.1) * 65_535) assert_eq!(SubtensorModule::get_emission_for_uid(netuid, 0), 500000000); // Note E = 0.5 * 0.55 * 1_000_000_000 = 275_000_000 (discrepancy) @@ -1708,30 +1798,41 @@ fn test_active_stake() { } /* current_block: 5003; activity_cutoff: 5000 Last update: [5002, 5002, 0, 0]; Inactive: [false, false, true, true]; Block at registration: [0, 0, 0, 0] - S: [0.25, 0.25, 0.25, 0.25]; S (mask): [0.25, 0.25, 0, 0]; S (mask+norm): [0.5, 0.5, 0, 0] - validator_permits: [true, true, true, true]; max_allowed_validators: 4; new_validator_permits: [true, true, true, true] - W: [[(2, 0.4999923704), (3, 0.4999923704)], [(2, 0.4999923704), (3, 0.4999923704)], [], []] - W (permit): [[(2, 0.4999923704), (3, 0.4999923704)], [(2, 0.4999923704), (3, 0.4999923704)], [], []] - W (permit+diag): [[(2, 0.4999923704), (3, 0.4999923704)], [(2, 0.4999923704), (3, 0.4999923704)], [], []] - W (permit+diag+outdate): [[(2, 0.4999923704), (3, 0.4999923704)], [(2, 0.4999923704), (3, 0.4999923704)], [], []] + Inactive: [false, false, true, true] + Block at registration: [0, 0, 0, 0] + hotkeys: [(0, 0), (1, 1), (2, 2), (3, 3)] + ls: tao_weight: 0 + Normalised Stake: [0.25, 0.25, 0.25, 0.25] + validator_permits: [true, true, true, true] + max_allowed_validators: 4 + new_validator_permits: [true, true, true, true] + Active Stake: [0.5, 0.5, 0, 0] + W: [[(2, 65535), (3, 65535)], [(2, 65535), (3, 65535)], [], []] + W (permit): [[(2, 65535), (3, 65535)], [(2, 65535), (3, 65535)], [], []] + W (permit+diag): [[(2, 65535), (3, 65535)], [(2, 65535), (3, 65535)], [], []] + W (permit+diag+outdate): [[(2, 65535), (3, 65535)], [(2, 65535), (3, 65535)], [], []] W (mask+norm): [[(2, 0.5), (3, 0.5)], [(2, 0.5), (3, 0.5)], [], []] - R: [0, 0, 0.5, 0.5] - W (threshold): [[(2, 1), (3, 1)], [(2, 1), (3, 1)], [], []] + R (before): [0, 0, 0.5, 0.5] + C: [0, 0, 0.5, 0.5] + Clipped W: [[(2, 0.5), (3, 0.5)], [(2, 0.5), (3, 0.5)], [], []] + Validator Trust: [1, 1, 0, 0] + R (after): [0, 0, 0.5, 0.5] T: [0, 0, 1, 1] - C: [0.006693358, 0.006693358, 0.9933076561, 0.9933076561] - I: [0, 0, 0.5, 0.5] - B: [[(2, 65535), (3, 65535)], [(2, 53619), (3, 53619)], [], []] - B (outdatedmask): [[(2, 65535), (3, 65535)], [(2, 53619), (3, 53619)], [], []] - B (mask+norm): [[(2, 0.5500025176), (3, 0.5500025176)], [(2, 0.4499974821), (3, 0.4499974821)], [], []] - ΔB: [[(2, 0.25), (3, 0.25)], [(2, 0.25), (3, 0.25)], [], []] - ΔB (norm): [[(2, 0.5), (3, 0.5)], [(2, 0.5), (3, 0.5)], [], []] - emaB: [[(2, 0.545002266), (3, 0.545002266)], [(2, 0.4549977337), (3, 0.4549977337)], [], []] - emaB (max-upscale): [[(2, 1), (3, 1)], [(2, 0.8348547556), (3, 0.8348547556)], [], []] - D: [0.545002266, 0.4549977337, 0, 0] - nE: [0.272501133, 0.2274988669, 0.25, 0.25] - E: [272501132, 227498866, 250000000, 250000000] - P: [0.272501133, 0.2274988669, 0.25, 0.25] - P (u16): [65535, 54711, 60123, 60123] */ + I (=Rank): [0, 0, 0.5, 0.5] + B: [[(2, 65535), (3, 65535)], [(2, 65535), (3, 65535)], [], []] + B (outdatedmask): [[(2, 65535), (3, 65535)], [(2, 65535), (3, 65535)], [], []] + B (mask+norm): [[(2, 0.5), (3, 0.5)], [(2, 0.5), (3, 0.5)], [], []] + alpha values: [0.1, 0.1, 0.1, 0.1] + EmaB: [[(2, 0.5), (3, 0.5)], [(2, 0.5), (3, 0.5)], [], []] + D: [0.5, 0.5, 0, 0] + Normalized Server Emission: [0, 0, 0.25, 0.25] + Server Emission: [0, 0, 250000000, 250000000] + Normalized Validator Emission: [0.25, 0.25, 0, 0] + Validator Emission: [250000000, 250000000, 0, 0] + Normalized Combined Emission: [0.25, 0.25, 0.25, 0.25] + Combined Emission: [250000000, 250000000, 250000000, 250000000] + Pruning Scores: [0.25, 0.25, 0.25, 0.25] + */ let bonds = SubtensorModule::get_bonds(netuid); assert_eq!(SubtensorModule::get_dividends_for_uid(netuid, 0), 32767); // Note D = floor((0.55 * 0.9 + 0.5 * 0.1) * 65_535) assert_eq!(SubtensorModule::get_emission_for_uid(netuid, 0), 250000000); // Note E = 0.5 * (0.55 * 0.9 + 0.5 * 0.1) * 1_000_000_000 = 272_500_000 (discrepancy) @@ -2703,7 +2804,7 @@ fn test_calculate_logistic_params_edge_cases() { #[test] fn test_compute_ema_bonds_sparse() { // Define test inputs - let bonds_delta = vec![ + let weights = vec![ vec![(0, I32F32::from_num(0.1)), (1, I32F32::from_num(0.2))], vec![(0, I32F32::from_num(0.3)), (1, I32F32::from_num(0.4))], ]; @@ -2713,27 +2814,22 @@ fn test_compute_ema_bonds_sparse() { ]; let alpha = vec![I32F32::from_num(0.9), I32F32::from_num(0.8)]; - // Expected values - // EMA calculation for each bond: - // EMA = alpha * bond_delta + (1 - alpha) * bond - // For bond (0, 0): - // EMA = 0.9 * 0.1 + (1 - 0.9) * 0.5 = 0.09 + 0.05 = 0.14 - // For bond (0, 1): - // EMA = 0.8 * 0.2 + (1 - 0.8) * 0.6 = 0.16 + 0.12 = 0.28 - // For bond (1, 0): - // EMA = 0.9 * 0.3 + (1 - 0.9) * 0.7 = 0.27 + 0.07 = 0.34 - // For bond (1, 1): - // EMA = 0.8 * 0.4 + (1 - 0.8) * 0.8 = 0.32 + 0.16 = 0.48 let expected_ema_bonds = vec![ - vec![(0, I32F32::from_num(0.1309)), (1, I32F32::from_num(0.2479))], - vec![(0, I32F32::from_num(0.3129)), (1, I32F32::from_num(0.4159))], + vec![ + (0, I32F32::from_num(0.130999)), + (1, I32F32::from_num(0.247999)), + ], + vec![ + (0, I32F32::from_num(0.312999)), + (1, I32F32::from_num(0.415999)), + ], ]; // Call the function - let ema_bonds = SubtensorModule::compute_ema_bonds_sparse(&bonds_delta, &bonds, alpha); + let ema_bonds = SubtensorModule::compute_ema_bonds_sparse(&weights, &bonds, alpha); // Assert the results with an epsilon for approximate equality - let epsilon = I32F32::from_num(1e-4); + let epsilon = I32F32::from_num(1e-6); assert_approx_eq_vec_of_vec(&ema_bonds, &expected_ema_bonds, epsilon); } @@ -2741,7 +2837,7 @@ fn test_compute_ema_bonds_sparse() { #[test] fn test_compute_ema_bonds_sparse_empty() { // Test with empty inputs - let bonds_delta: Vec> = vec![]; + let weights: Vec> = vec![]; let bonds: Vec> = vec![]; let alpha: Vec = vec![]; @@ -2749,7 +2845,7 @@ fn test_compute_ema_bonds_sparse_empty() { let expected_ema_bonds: Vec> = vec![]; // Call the function - let ema_bonds = SubtensorModule::compute_ema_bonds_sparse(&bonds_delta, &bonds, alpha); + let ema_bonds = SubtensorModule::compute_ema_bonds_sparse(&weights, &bonds, alpha); // Assert the results assert_eq!( diff --git a/pallets/subtensor/src/tests/math.rs b/pallets/subtensor/src/tests/math.rs index 51ca7a8fbb..9cf59e96dd 100644 --- a/pallets/subtensor/src/tests/math.rs +++ b/pallets/subtensor/src/tests/math.rs @@ -2145,7 +2145,7 @@ fn test_math_mat_ema() { let old = vec_to_mat_fixed(&old, 4, false); let new = vec_to_mat_fixed(&new, 4, false); let target = vec_to_mat_fixed(&target, 4, false); - let result = mat_ema_alpha_vec(&new, &old, &vec![I32F32::from_num(0.1); 3]); + let result = mat_ema_alpha_vec(&new, &old, &[I32F32::from_num(0.1); 3]); assert_mat_compare(&result, &target, I32F32::from_num(1e-4)); let old: Vec = vec![ 0.1, 0.2, 3., 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.10, 0.11, 0.12, @@ -2159,7 +2159,7 @@ fn test_math_mat_ema() { let old = vec_to_mat_fixed(&old, 4, false); let new = vec_to_mat_fixed(&new, 4, false); let target = vec_to_mat_fixed(&target, 4, false); - let result = mat_ema_alpha_vec(&new, &old, &vec![I32F32::from_num(0); 3]); + let result = mat_ema_alpha_vec(&new, &old, &[I32F32::from_num(0); 3]); assert_mat_compare(&result, &target, I32F32::from_num(1e-4)); let old: Vec = vec![ 0.001, 0.002, 0.003, 0.004, 0.05, 0.006, 0.007, 0.008, 0.009, 0.010, 0.011, 0.012, @@ -2174,7 +2174,7 @@ fn test_math_mat_ema() { let old = vec_to_mat_fixed(&old, 4, false); let new = vec_to_mat_fixed(&new, 4, false); let target = vec_to_mat_fixed(&target, 4, false); - let result = mat_ema_alpha_vec(&new, &old, &vec![I32F32::from_num(1); 3]); + let result = mat_ema_alpha_vec(&new, &old, &[I32F32::from_num(1); 3]); assert_mat_compare(&result, &target, I32F32::from_num(1e-4)); } From d9902e8fae6b6000be43dc7601d4b2bfc351f8fa Mon Sep 17 00:00:00 2001 From: Andreea Popescu Date: Tue, 4 Feb 2025 08:06:49 +0000 Subject: [PATCH 08/45] add yuma4 scenario test --- pallets/subtensor/src/tests/epoch.rs | 155 +++++++++++++++++++++++++++ pallets/subtensor/src/tests/math.rs | 49 +++------ pallets/subtensor/src/utils/misc.rs | 6 ++ 3 files changed, 174 insertions(+), 36 deletions(-) diff --git a/pallets/subtensor/src/tests/epoch.rs b/pallets/subtensor/src/tests/epoch.rs index 6760a552b3..3316f220a1 100644 --- a/pallets/subtensor/src/tests/epoch.rs +++ b/pallets/subtensor/src/tests/epoch.rs @@ -3286,3 +3286,158 @@ fn assert_approx_eq_vec_of_vec( } } } + +// test Yuma 4 scenarios over a sequence of epochs. +fn setup_yuma_4_scenario(netuid: u16, n: u16, max_stake: u64, stakes: Vec) { + let block_number = System::block_number(); + let tempo: u16 = u16::MAX - 1; // high tempo to skip automatic epochs in on_initialize, use manual epochs instead + add_network(netuid, tempo, 0); + + SubtensorModule::set_max_allowed_uids(netuid, n); + assert_eq!(SubtensorModule::get_max_allowed_uids(netuid), n); + SubtensorModule::set_max_registrations_per_block(netuid, n); + SubtensorModule::set_target_registrations_per_interval(netuid, n); + SubtensorModule::set_weights_set_rate_limit(netuid, 0); + SubtensorModule::set_min_allowed_weights(netuid, 1); + SubtensorModule::set_max_weight_limit(netuid, u16::MAX); + SubtensorModule::set_bonds_penalty(netuid, 0); + + // === Register + for key in 0..n as u64 { + SubtensorModule::add_balance_to_coldkey_account(&U256::from(key), max_stake); + let (nonce, work): (u64, Vec) = SubtensorModule::create_work_for_block_number( + netuid, + block_number, + key * 1_000_000, + &U256::from(key), + ); + assert_ok!(SubtensorModule::register( + <::RuntimeOrigin>::signed(U256::from(key)), + netuid, + block_number, + nonce, + work, + U256::from(key), + U256::from(key) + )); + SubtensorModule::increase_stake_for_hotkey_and_coldkey_on_subnet( + &U256::from(key), + &U256::from(key), + netuid, + stakes[key as usize], + ); + } + assert_eq!(SubtensorModule::get_max_allowed_uids(netuid), n); + assert_eq!(SubtensorModule::get_subnetwork_n(netuid), n); + + // Enable Liquid Alpha + SubtensorModule::set_kappa(netuid, 0); + SubtensorModule::set_liquid_alpha_enabled(netuid, true); + + SubtensorModule::set_alpha_values_32(netuid, I32F32::from_num(0.9), I32F32::from_num(0.99)); + + // === Issue validator permits + SubtensorModule::set_max_allowed_validators(netuid, 3); + assert_eq!(SubtensorModule::get_max_allowed_validators(netuid), 3); + SubtensorModule::epoch(netuid, 1_000_000_000); // run first epoch to set allowed validators + next_block(); // run to next block to ensure weights are set on nodes after their registration block +} + +fn run_epoch_check_bonds(netuid: u16, sparse: bool, target_bonds: Vec>) { + next_block(); + if sparse { + SubtensorModule::epoch(netuid, 1_000_000_000); + } else { + SubtensorModule::epoch_dense(netuid, 1_000_000_000); + } + let bonds = SubtensorModule::get_bonds(netuid); + + // server 1 + assert_eq!(bonds[0][3], target_bonds[0][0]); + assert_eq!(bonds[1][3], target_bonds[1][0]); + assert_eq!(bonds[2][3], target_bonds[2][0]); + + // server 2 + assert_eq!(bonds[0][4], target_bonds[0][1]); + assert_eq!(bonds[1][4], target_bonds[1][1]); + assert_eq!(bonds[2][4], target_bonds[2][1]); +} + +#[test] +fn test_yuma_4_kappa_moves_last() { + new_test_ext(1).execute_with(|| { + let sparse: bool = false; + let n: u16 = 5; // 3 validators, 2 servers + let netuid: u16 = 1; + let max_stake: u64 = 8; + + // Validator A: kappa / Big validator (0.8) - moves last + // Validator B: Small eager validator (0.1) - moves first + // Validator C: Small lazy validator (0.1) - moves second + let stakes: Vec = vec![8, 1, 1, 0, 0]; + + setup_yuma_4_scenario(netuid, n, max_stake, stakes); + + // Initially, consensus is achieved by all Validators + for uid in [0, 1, 2] { + assert_ok!(SubtensorModule::set_weights( + RuntimeOrigin::signed(U256::from(uid)), + netuid, + vec![3, 4], + vec![u16::MAX, 0], + 0 + )); + } + let target = vec![vec![65535, 0], vec![65535, 0], vec![65535, 0]]; + run_epoch_check_bonds(netuid, sparse, target); + + // Validator A -> Server 1 + // Validator B -> Server 2 + // Validator C -> Server 1 + for (uid, weights) in [vec![u16::MAX, 0], vec![0, u16::MAX], vec![u16::MAX, 0]] + .iter() + .enumerate() + { + assert_ok!(SubtensorModule::set_weights( + RuntimeOrigin::signed(U256::from(uid)), + netuid, + vec![3, 4], + weights.to_vec(), + 0 + )); + } + let target = vec![vec![65535, 0], vec![220, 65535], vec![65535, 0]]; + run_epoch_check_bonds(netuid, sparse, target); + + // Validator A -> Server 1 + // Validator B -> Server 2 + // Validator C -> Server 2 + for (uid, weights) in [vec![u16::MAX, 0], vec![0, u16::MAX], vec![0, u16::MAX]] + .iter() + .enumerate() + { + assert_ok!(SubtensorModule::set_weights( + RuntimeOrigin::signed(U256::from(uid)), + netuid, + vec![3, 4], + weights.to_vec(), + 0 + )); + } + let target = vec![vec![65535, 0], vec![1, 65535], vec![329, 64878]]; + run_epoch_check_bonds(netuid, sparse, target); + + // Subsequent epochs All validators -> Server 2 + for uid in [0, 1, 2] { + assert_ok!(SubtensorModule::set_weights( + RuntimeOrigin::signed(U256::from(uid)), + netuid, + vec![3, 4], + vec![0, u16::MAX], + 0 + )); + } + let target = vec![vec![65535, 11866], vec![0, 65535], vec![328, 64996]]; + run_epoch_check_bonds(netuid, sparse, target); + }) +} diff --git a/pallets/subtensor/src/tests/math.rs b/pallets/subtensor/src/tests/math.rs index 9cf59e96dd..cea3ca6685 100644 --- a/pallets/subtensor/src/tests/math.rs +++ b/pallets/subtensor/src/tests/math.rs @@ -1221,42 +1221,19 @@ fn test_math_vec_mask_sparse_matrix() { } #[test] -fn test_math_scalar_vec_mask_sparse_matrix() { - let vector: Vec = vec![1., 2., 3., 4., 5., 6., 7., 8., 9.]; - let target: Vec = vec![0., 2., 3., 0., 5., 6., 0., 8., 9.]; - let mat = vec_to_sparse_mat_fixed(&vector, 3, false); - let scalar: u64 = 1; - let masking_vector: Vec = vec![1, 4, 7]; - let result = scalar_vec_mask_sparse_matrix(&mat, scalar, &masking_vector, &|a, b| a == b); - assert_sparse_mat_compare( - &result, - &vec_to_sparse_mat_fixed(&target, 3, false), - I32F32::from_num(0), - ); - - let vector: Vec = vec![1., 2., 3., 4., 5., 6., 7., 8., 9.]; - let target: Vec = vec![1., 2., 0., 4., 5., 0., 7., 8., 0.]; - let mat = vec_to_sparse_mat_fixed(&vector, 3, false); - let scalar: u64 = 5; - let masking_vector: Vec = vec![1, 4, 7]; - let result = scalar_vec_mask_sparse_matrix(&mat, scalar, &masking_vector, &|a, b| a <= b); - assert_sparse_mat_compare( - &result, - &vec_to_sparse_mat_fixed(&target, 3, false), - I32F32::from_num(0), - ); - - let vector: Vec = vec![1., 2., 3., 4., 5., 6., 7., 8., 9.]; - let target: Vec = vec![0., 0., 3., 0., 0., 6., 0., 0., 9.]; - let mat = vec_to_sparse_mat_fixed(&vector, 3, false); - let scalar: u64 = 5; - let masking_vector: Vec = vec![1, 4, 7]; - let result = scalar_vec_mask_sparse_matrix(&mat, scalar, &masking_vector, &|a, b| a >= b); - assert_sparse_mat_compare( - &result, - &vec_to_sparse_mat_fixed(&target, 3, false), - I32F32::from_num(0), - ); +fn test_math_vec_mul() { + let vector: Vec = vec_to_fixed(&[1., 2., 3., 4.]); + let target: Vec = vec_to_fixed(&[1., 4., 9., 16.]); + let result = vec_mul(&vector, &vector); + assert_vec_compare(&result, &target, I32F32::from_num(0)); + let vector_empty: Vec = vec_to_fixed(&[]); + let result = vec_mul(&vector_empty, &vector); + let target: Vec = vec![]; + assert_vec_compare(&result, &target, I32F32::from_num(0)); + let vector_zero: Vec = vec_to_fixed(&[0., 0., 0., 0., 0., 0., 0., 0.]); + let result = vec_mul(&vector_zero, &vector); + let target: Vec = vec![I32F32::from_num(0); 4]; + assert_vec_compare(&result, &target, I32F32::from_num(0)); } #[test] diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index b375cc66e4..6f2ea1ffa3 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -671,6 +671,12 @@ impl Pallet { AlphaValues::::get(netuid) } + pub fn set_alpha_values_32(netuid: u16, low: I32F32, high: I32F32) { + let low = (low.saturating_mul(I32F32::saturating_from_num(u16::MAX))).to_num::(); + let high = (high.saturating_mul(I32F32::saturating_from_num(u16::MAX))).to_num::(); + AlphaValues::::insert(netuid, (low, high)); + } + pub fn get_alpha_values_32(netuid: u16) -> (I32F32, I32F32) { let (alpha_low, alpha_high): (u16, u16) = AlphaValues::::get(netuid); let converted_low = From a177304f2fa20603529c2fc3a28190dc57ba5fe2 Mon Sep 17 00:00:00 2001 From: Andreea Popescu Date: Wed, 22 Jan 2025 12:52:27 +0000 Subject: [PATCH 09/45] yuma bonds scale individually --- pallets/subtensor/src/epoch/run_epoch.rs | 61 ++++++------------------ 1 file changed, 15 insertions(+), 46 deletions(-) diff --git a/pallets/subtensor/src/epoch/run_epoch.rs b/pallets/subtensor/src/epoch/run_epoch.rs index 26607422ec..1a408b85ef 100644 --- a/pallets/subtensor/src/epoch/run_epoch.rs +++ b/pallets/subtensor/src/epoch/run_epoch.rs @@ -204,12 +204,19 @@ impl Pallet { inplace_col_normalize(&mut bonds); // sum_i b_ij = 1 log::trace!("B:\n{:?}\n", &bonds); - // Get alpha values - let alpha = Self::compute_liquid_alpha(netuid, consensus.clone()); - // Compute the Exponential Moving Average (EMA) of bonds. - let mut ema_bonds = Self::compute_ema_bonds(&weights_for_bonds.clone(), &bonds, alpha); - // Normalize EMA bonds. + // Check if Liquid Alpha is enabled, consensus is not empty, and contains non-zero values. + let mut ema_bonds = if let Some(clamped_bonds_alpha) = + Self::compute_liquid_alpha(netuid, consensus.clone()) + { + // Compute the Exponential Moving Average (EMA) of bonds using the clamped alpha values. + Self::compute_ema_bonds_with_liquid_alpha(&weights.clone(), &bonds, clamped_bonds_alpha) + } else { + log::trace!("Using Bonds Moving Average"); + // Compute the EMA of bonds using a normal alpha value. + Self::compute_ema_bonds_normal(&weights.clone(), &bonds, netuid) + }; + inplace_col_normalize(&mut ema_bonds); // sum_i b_ij = 1 log::trace!("emaB:\n{:?}\n", &ema_bonds); @@ -1016,30 +1023,6 @@ impl Pallet { ema_bonds } - /// Compute the Exponential Moving Average (EMA) of bonds using the alpha values. - /// - /// # Args: - /// * `weights` - A vector of weights. - /// * `bonds` - A vector of bonds. - /// * `alpha` - A vector of clamped alpha values (for liquid alpha) or constant alpha values. - /// - /// # Returns: - /// A vector of EMA bonds. - pub fn compute_ema_bonds( - weights: &[Vec], - bonds: &[Vec], - alpha: Vec, - ) -> Vec> { - // Compute the Exponential Moving Average (EMA) of bonds using the provided clamped alpha values. - let ema_bonds = mat_ema_alpha_vec(weights, bonds, &alpha); - - // Log the computed EMA bonds for debugging purposes. - log::trace!("Exponential Moving Average Bonds: {:?}", ema_bonds); - - // Return the computed EMA bonds. - ema_bonds - } - /// Compute liquid alphas based on the Liquid Alpha setting. /// /// # Args: @@ -1048,7 +1031,7 @@ impl Pallet { /// /// # Returns: /// A vector of alphas - pub fn compute_liquid_alpha(netuid: u16, consensus: Vec) -> Vec { + pub fn compute_liquid_alpha(netuid: u16, consensus: Vec) -> Option> { // Check if Liquid Alpha is enabled, consensus is not empty, and contains non-zero values. if LiquidAlphaOn::::get(netuid) && !consensus.is_empty() @@ -1083,24 +1066,10 @@ impl Pallet { // Clamp the alpha values between alpha_high and alpha_low. let clamped_alpha = Self::clamp_alpha_values(alpha, alpha_high, alpha_low); - return clamped_alpha; + return Some(clamped_alpha); } } - - // Liquid Alpha is disabled - // or high and low consensus values do not meet the required conditions. - // return vector of constant alpha - - // Retrieve the bonds moving average for the given network ID and scale it down. - let bonds_moving_average: I64F64 = I64F64::from_num(Self::get_bonds_moving_average(netuid)) - .saturating_div(I64F64::from_num(1_000_000)); - - // Calculate the alpha value for the EMA calculation. - // Alpha is derived by subtracting the scaled bonds moving average from 1. - let alpha: I32F32 = - I32F32::from_num(1).saturating_sub(I32F32::from_num(bonds_moving_average)); - - vec![alpha; consensus.len()] + None } pub fn do_set_alpha_values( From 2baaa98730058a777ba1e1a339ecc8536f7d3086 Mon Sep 17 00:00:00 2001 From: Andreea Popescu Date: Wed, 22 Jan 2025 13:16:00 +0000 Subject: [PATCH 10/45] yuma bonds scale individually for sparse --- pallets/subtensor/src/epoch/run_epoch.rs | 132 ++++++++++++++++++++--- 1 file changed, 120 insertions(+), 12 deletions(-) diff --git a/pallets/subtensor/src/epoch/run_epoch.rs b/pallets/subtensor/src/epoch/run_epoch.rs index 1a408b85ef..5a42024561 100644 --- a/pallets/subtensor/src/epoch/run_epoch.rs +++ b/pallets/subtensor/src/epoch/run_epoch.rs @@ -216,7 +216,7 @@ impl Pallet { // Compute the EMA of bonds using a normal alpha value. Self::compute_ema_bonds_normal(&weights.clone(), &bonds, netuid) }; - + // Normalize EMA bonds. inplace_col_normalize(&mut ema_bonds); // sum_i b_ij = 1 log::trace!("emaB:\n{:?}\n", &ema_bonds); @@ -591,12 +591,22 @@ impl Pallet { inplace_col_normalize_sparse(&mut bonds, n); log::trace!("B (mask+norm): {:?}", &bonds); - // Get alpha values - let alpha = Self::compute_liquid_alpha(netuid, consensus.clone()); - // Compute the Exponential Moving Average (EMA) of bonds. - let mut ema_bonds = - Self::compute_ema_bonds_sparse(&weights_for_bonds.clone(), &bonds, alpha); + let mut ema_bonds = if let Some(clamped_bonds_alpha) = + Self::compute_liquid_alpha(netuid, consensus.clone()) + { + // Compute the Exponential Moving Average (EMA) of bonds using the clamped alpha values. + Self::compute_ema_bonds_with_liquid_alpha_sparse( + &weights.clone(), + &bonds, + clamped_bonds_alpha, + ) + } else { + log::trace!("Using Bonds Moving Average"); + // Compute the EMA of bonds using a normal alpha value. + Self::compute_ema_bonds_normal_sparse(&weights.clone(), &bonds, netuid) + }; + // Normalize EMA bonds. inplace_col_normalize_sparse(&mut ema_bonds, n); // sum_i b_ij = 1 log::trace!("Exponential Moving Average Bonds: {:?}", &ema_bonds); @@ -1002,22 +1012,120 @@ impl Pallet { /// Compute the Exponential Moving Average (EMA) of bonds using the alpha values for a sparse matrix. /// /// # Args: - /// * `weights` - A vector of weights. + /// * `bonds_delta` - A vector of bond deltas. /// * `bonds` - A vector of bonds. - /// * `alpha` - A vector of clamped alpha values (for liquid alpha) or constant alpha values. + /// * `alpha` - A vector of clamped alpha values. /// /// # Returns: /// A vector of EMA bonds. - pub fn compute_ema_bonds_sparse( - weights: &[Vec<(u16, I32F32)>], + pub fn compute_ema_bonds_with_liquid_alpha_sparse( + bonds_delta: &[Vec<(u16, I32F32)>], bonds: &[Vec<(u16, I32F32)>], alpha: Vec, ) -> Vec> { // Compute the Exponential Moving Average (EMA) of bonds using the provided clamped alpha values. - let ema_bonds = mat_ema_alpha_vec_sparse(weights, bonds, &alpha); + let ema_bonds = mat_ema_alpha_vec_sparse(bonds_delta, bonds, &alpha); + + // Log the computed EMA bonds for debugging purposes. + log::trace!( + "Exponential Moving Average Bonds Liquid Alpha: {:?}", + ema_bonds + ); + + // Return the computed EMA bonds. + ema_bonds + } + + /// Compute the Exponential Moving Average (EMA) of bonds using the clamped alpha values. + /// + /// # Args: + /// * `bonds_delta` - A vector of bond deltas. + /// * `bonds` - A vector of bonds. + /// * `alpha` - A vector of clamped alpha values. + /// + /// # Returns: + /// A vector of EMA bonds. + pub fn compute_ema_bonds_with_liquid_alpha( + bonds_delta: &[Vec], + bonds: &[Vec], + alpha: Vec, + ) -> Vec> { + // Compute the Exponential Moving Average (EMA) of bonds using the provided clamped alpha values. + let ema_bonds = mat_ema_alpha_vec(bonds_delta, bonds, &alpha); + + // Log the computed EMA bonds for debugging purposes. + log::trace!( + "Exponential Moving Average Bonds Liquid Alpha: {:?}", + ema_bonds + ); + + // Return the computed EMA bonds. + ema_bonds + } + + /// Compute the Exponential Moving Average (EMA) of bonds using a normal alpha value for a sparse matrix. + /// + /// # Args: + /// * `bonds_delta` - A vector of bond deltas. + /// * `bonds` - A vector of bonds. + /// * `netuid` - The network ID. + /// + /// # Returns: + /// A vector of EMA bonds. + pub fn compute_ema_bonds_normal_sparse( + bonds_delta: &[Vec<(u16, I32F32)>], + bonds: &[Vec<(u16, I32F32)>], + netuid: u16, + ) -> Vec> { + // Retrieve the bonds moving average for the given network ID and scale it down. + let bonds_moving_average: I64F64 = + I64F64::saturating_from_num(Self::get_bonds_moving_average(netuid)) + .safe_div(I64F64::saturating_from_num(1_000_000)); + + // Calculate the alpha value for the EMA calculation. + // Alpha is derived by subtracting the scaled bonds moving average from 1. + let alpha: I32F32 = I32F32::saturating_from_num(1) + .saturating_sub(I32F32::saturating_from_num(bonds_moving_average)); + + // Compute the Exponential Moving Average (EMA) of bonds using the calculated alpha value. + let ema_bonds = mat_ema_sparse(bonds_delta, bonds, alpha); + + // Log the computed EMA bonds for debugging purposes. + log::trace!("Exponential Moving Average Bonds Normal: {:?}", ema_bonds); + + // Return the computed EMA bonds. + ema_bonds + } + + /// Compute the Exponential Moving Average (EMA) of bonds using a normal alpha value. + /// + /// # Args: + /// * `bonds_delta` - A vector of bond deltas. + /// * `bonds` - A vector of bonds. + /// * `netuid` - The network ID. + /// + /// # Returns: + /// A vector of EMA bonds. + pub fn compute_ema_bonds_normal( + bonds_delta: &[Vec], + bonds: &[Vec], + netuid: u16, + ) -> Vec> { + // Retrieve the bonds moving average for the given network ID and scale it down. + let bonds_moving_average: I64F64 = + I64F64::saturating_from_num(Self::get_bonds_moving_average(netuid)) + .safe_div(I64F64::saturating_from_num(1_000_000)); + + // Calculate the alpha value for the EMA calculation. + // Alpha is derived by subtracting the scaled bonds moving average from 1. + let alpha: I32F32 = I32F32::saturating_from_num(1) + .saturating_sub(I32F32::saturating_from_num(bonds_moving_average)); + + // Compute the Exponential Moving Average (EMA) of bonds using the calculated alpha value. + let ema_bonds = mat_ema(bonds_delta, bonds, alpha); // Log the computed EMA bonds for debugging purposes. - log::trace!("Exponential Moving Average Bonds: {:?}", ema_bonds); + log::trace!("Exponential Moving Average Bonds Normal: {:?}", ema_bonds); // Return the computed EMA bonds. ema_bonds From 90bafb82bc11ab2df0f3da65b73ecb5cd259c838 Mon Sep 17 00:00:00 2001 From: Andreea Popescu Date: Wed, 22 Jan 2025 14:45:35 +0000 Subject: [PATCH 11/45] refactor alpha values --- pallets/subtensor/src/epoch/run_epoch.rs | 142 +++++------------------ pallets/subtensor/src/tests/epoch.rs | 4 +- pallets/subtensor/src/tests/math.rs | 36 ++++-- 3 files changed, 60 insertions(+), 122 deletions(-) diff --git a/pallets/subtensor/src/epoch/run_epoch.rs b/pallets/subtensor/src/epoch/run_epoch.rs index 5a42024561..ef0f171c34 100644 --- a/pallets/subtensor/src/epoch/run_epoch.rs +++ b/pallets/subtensor/src/epoch/run_epoch.rs @@ -204,18 +204,11 @@ impl Pallet { inplace_col_normalize(&mut bonds); // sum_i b_ij = 1 log::trace!("B:\n{:?}\n", &bonds); + // Get alpha values + let alpha = Self::compute_liquid_alpha(netuid, consensus.clone()); + // Compute the Exponential Moving Average (EMA) of bonds. - // Check if Liquid Alpha is enabled, consensus is not empty, and contains non-zero values. - let mut ema_bonds = if let Some(clamped_bonds_alpha) = - Self::compute_liquid_alpha(netuid, consensus.clone()) - { - // Compute the Exponential Moving Average (EMA) of bonds using the clamped alpha values. - Self::compute_ema_bonds_with_liquid_alpha(&weights.clone(), &bonds, clamped_bonds_alpha) - } else { - log::trace!("Using Bonds Moving Average"); - // Compute the EMA of bonds using a normal alpha value. - Self::compute_ema_bonds_normal(&weights.clone(), &bonds, netuid) - }; + let mut ema_bonds = Self::compute_ema_bonds(&weights.clone(), &bonds, alpha); // Normalize EMA bonds. inplace_col_normalize(&mut ema_bonds); // sum_i b_ij = 1 log::trace!("emaB:\n{:?}\n", &ema_bonds); @@ -591,22 +584,11 @@ impl Pallet { inplace_col_normalize_sparse(&mut bonds, n); log::trace!("B (mask+norm): {:?}", &bonds); - // Compute the Exponential Moving Average (EMA) of bonds. - let mut ema_bonds = if let Some(clamped_bonds_alpha) = - Self::compute_liquid_alpha(netuid, consensus.clone()) - { - // Compute the Exponential Moving Average (EMA) of bonds using the clamped alpha values. - Self::compute_ema_bonds_with_liquid_alpha_sparse( - &weights.clone(), - &bonds, - clamped_bonds_alpha, - ) - } else { - log::trace!("Using Bonds Moving Average"); - // Compute the EMA of bonds using a normal alpha value. - Self::compute_ema_bonds_normal_sparse(&weights.clone(), &bonds, netuid) - }; + // Get alpha values + let alpha = Self::compute_liquid_alpha(netuid, consensus.clone()); + // Compute the Exponential Moving Average (EMA) of bonds. + let mut ema_bonds = Self::compute_ema_bonds_sparse(&weights.clone(), &bonds, alpha); // Normalize EMA bonds. inplace_col_normalize_sparse(&mut ema_bonds, n); // sum_i b_ij = 1 log::trace!("Exponential Moving Average Bonds: {:?}", &ema_bonds); @@ -1014,11 +996,11 @@ impl Pallet { /// # Args: /// * `bonds_delta` - A vector of bond deltas. /// * `bonds` - A vector of bonds. - /// * `alpha` - A vector of clamped alpha values. + /// * `alpha` - A vector of clamped alpha values (for liquid alpha) or constant alpha values. /// /// # Returns: /// A vector of EMA bonds. - pub fn compute_ema_bonds_with_liquid_alpha_sparse( + pub fn compute_ema_bonds_sparse( bonds_delta: &[Vec<(u16, I32F32)>], bonds: &[Vec<(u16, I32F32)>], alpha: Vec, @@ -1027,25 +1009,22 @@ impl Pallet { let ema_bonds = mat_ema_alpha_vec_sparse(bonds_delta, bonds, &alpha); // Log the computed EMA bonds for debugging purposes. - log::trace!( - "Exponential Moving Average Bonds Liquid Alpha: {:?}", - ema_bonds - ); + log::trace!("Exponential Moving Average Bonds: {:?}", ema_bonds); // Return the computed EMA bonds. ema_bonds } - /// Compute the Exponential Moving Average (EMA) of bonds using the clamped alpha values. + /// Compute the Exponential Moving Average (EMA) of bonds using the alpha values. /// /// # Args: /// * `bonds_delta` - A vector of bond deltas. /// * `bonds` - A vector of bonds. - /// * `alpha` - A vector of clamped alpha values. + /// * `alpha` - A vector of clamped alpha values (for liquid alpha) or constant alpha values. /// /// # Returns: /// A vector of EMA bonds. - pub fn compute_ema_bonds_with_liquid_alpha( + pub fn compute_ema_bonds( bonds_delta: &[Vec], bonds: &[Vec], alpha: Vec, @@ -1054,78 +1033,7 @@ impl Pallet { let ema_bonds = mat_ema_alpha_vec(bonds_delta, bonds, &alpha); // Log the computed EMA bonds for debugging purposes. - log::trace!( - "Exponential Moving Average Bonds Liquid Alpha: {:?}", - ema_bonds - ); - - // Return the computed EMA bonds. - ema_bonds - } - - /// Compute the Exponential Moving Average (EMA) of bonds using a normal alpha value for a sparse matrix. - /// - /// # Args: - /// * `bonds_delta` - A vector of bond deltas. - /// * `bonds` - A vector of bonds. - /// * `netuid` - The network ID. - /// - /// # Returns: - /// A vector of EMA bonds. - pub fn compute_ema_bonds_normal_sparse( - bonds_delta: &[Vec<(u16, I32F32)>], - bonds: &[Vec<(u16, I32F32)>], - netuid: u16, - ) -> Vec> { - // Retrieve the bonds moving average for the given network ID and scale it down. - let bonds_moving_average: I64F64 = - I64F64::saturating_from_num(Self::get_bonds_moving_average(netuid)) - .safe_div(I64F64::saturating_from_num(1_000_000)); - - // Calculate the alpha value for the EMA calculation. - // Alpha is derived by subtracting the scaled bonds moving average from 1. - let alpha: I32F32 = I32F32::saturating_from_num(1) - .saturating_sub(I32F32::saturating_from_num(bonds_moving_average)); - - // Compute the Exponential Moving Average (EMA) of bonds using the calculated alpha value. - let ema_bonds = mat_ema_sparse(bonds_delta, bonds, alpha); - - // Log the computed EMA bonds for debugging purposes. - log::trace!("Exponential Moving Average Bonds Normal: {:?}", ema_bonds); - - // Return the computed EMA bonds. - ema_bonds - } - - /// Compute the Exponential Moving Average (EMA) of bonds using a normal alpha value. - /// - /// # Args: - /// * `bonds_delta` - A vector of bond deltas. - /// * `bonds` - A vector of bonds. - /// * `netuid` - The network ID. - /// - /// # Returns: - /// A vector of EMA bonds. - pub fn compute_ema_bonds_normal( - bonds_delta: &[Vec], - bonds: &[Vec], - netuid: u16, - ) -> Vec> { - // Retrieve the bonds moving average for the given network ID and scale it down. - let bonds_moving_average: I64F64 = - I64F64::saturating_from_num(Self::get_bonds_moving_average(netuid)) - .safe_div(I64F64::saturating_from_num(1_000_000)); - - // Calculate the alpha value for the EMA calculation. - // Alpha is derived by subtracting the scaled bonds moving average from 1. - let alpha: I32F32 = I32F32::saturating_from_num(1) - .saturating_sub(I32F32::saturating_from_num(bonds_moving_average)); - - // Compute the Exponential Moving Average (EMA) of bonds using the calculated alpha value. - let ema_bonds = mat_ema(bonds_delta, bonds, alpha); - - // Log the computed EMA bonds for debugging purposes. - log::trace!("Exponential Moving Average Bonds Normal: {:?}", ema_bonds); + log::trace!("Exponential Moving Average Bonds: {:?}", ema_bonds); // Return the computed EMA bonds. ema_bonds @@ -1139,7 +1047,7 @@ impl Pallet { /// /// # Returns: /// A vector of alphas - pub fn compute_liquid_alpha(netuid: u16, consensus: Vec) -> Option> { + pub fn compute_liquid_alpha(netuid: u16, consensus: Vec) -> Vec { // Check if Liquid Alpha is enabled, consensus is not empty, and contains non-zero values. if LiquidAlphaOn::::get(netuid) && !consensus.is_empty() @@ -1174,10 +1082,24 @@ impl Pallet { // Clamp the alpha values between alpha_high and alpha_low. let clamped_alpha = Self::clamp_alpha_values(alpha, alpha_high, alpha_low); - return Some(clamped_alpha); + return clamped_alpha; } } - None + + // Liquid Alpha is disabled + // or high and low consensus values do not meet the required conditions. + // return vector of constant alpha + + // Retrieve the bonds moving average for the given network ID and scale it down. + let bonds_moving_average: I64F64 = I64F64::from_num(Self::get_bonds_moving_average(netuid)) + .saturating_div(I64F64::from_num(1_000_000)); + + // Calculate the alpha value for the EMA calculation. + // Alpha is derived by subtracting the scaled bonds moving average from 1. + let alpha: I32F32 = + I32F32::from_num(1).saturating_sub(I32F32::from_num(bonds_moving_average)); + + vec![alpha; consensus.len()] } pub fn do_set_alpha_values( diff --git a/pallets/subtensor/src/tests/epoch.rs b/pallets/subtensor/src/tests/epoch.rs index 3316f220a1..175b00ab7f 100644 --- a/pallets/subtensor/src/tests/epoch.rs +++ b/pallets/subtensor/src/tests/epoch.rs @@ -2826,7 +2826,7 @@ fn test_compute_ema_bonds_sparse() { ]; // Call the function - let ema_bonds = SubtensorModule::compute_ema_bonds_sparse(&weights, &bonds, alpha); + let ema_bonds = SubtensorModule::compute_ema_bonds_sparse(&bonds_delta, &bonds, alpha); // Assert the results with an epsilon for approximate equality let epsilon = I32F32::from_num(1e-6); @@ -2845,7 +2845,7 @@ fn test_compute_ema_bonds_sparse_empty() { let expected_ema_bonds: Vec> = vec![]; // Call the function - let ema_bonds = SubtensorModule::compute_ema_bonds_sparse(&weights, &bonds, alpha); + let ema_bonds = SubtensorModule::compute_ema_bonds_sparse(&bonds_delta, &bonds, alpha); // Assert the results assert_eq!( diff --git a/pallets/subtensor/src/tests/math.rs b/pallets/subtensor/src/tests/math.rs index cea3ca6685..16a73c5e37 100644 --- a/pallets/subtensor/src/tests/math.rs +++ b/pallets/subtensor/src/tests/math.rs @@ -2136,11 +2136,19 @@ fn test_math_mat_ema() { let old = vec_to_mat_fixed(&old, 4, false); let new = vec_to_mat_fixed(&new, 4, false); let target = vec_to_mat_fixed(&target, 4, false); - let result = mat_ema_alpha_vec(&new, &old, &[I32F32::from_num(0); 3]); - assert_mat_compare(&result, &target, I32F32::from_num(1e-4)); - let old: Vec = vec![ - 0.001, 0.002, 0.003, 0.004, 0.05, 0.006, 0.007, 0.008, 0.009, 0.010, 0.011, 0.012, + let result = mat_ema_alpha_vec(&new, &old, &vec![I32F32::from_num(0.1); old.len()]); + assert_mat_compare(&result, &target, I32F32::from_num(0.000001)); + let old: Vec = vec![1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12.]; + let new: Vec = vec![ + 10., 20., 30., 40., 50., 60., 70., 80., 90., 100., 110., 120., ]; + let target: Vec = vec![1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12.]; + let old = vec_to_mat_fixed(&old, 4, false); + let new = vec_to_mat_fixed(&new, 4, false); + let target = vec_to_mat_fixed(&target, 4, false); + let result = mat_ema_alpha_vec(&new, &old, &vec![I32F32::from_num(0); old.len()]); + assert_mat_compare(&result, &target, I32F32::from_num(0.000001)); + let old: Vec = vec![1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12.]; let new: Vec = vec![ 0.1, 0.2, 3., 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.10, 0.11, 0.12, ]; @@ -2151,8 +2159,8 @@ fn test_math_mat_ema() { let old = vec_to_mat_fixed(&old, 4, false); let new = vec_to_mat_fixed(&new, 4, false); let target = vec_to_mat_fixed(&target, 4, false); - let result = mat_ema_alpha_vec(&new, &old, &[I32F32::from_num(1); 3]); - assert_mat_compare(&result, &target, I32F32::from_num(1e-4)); + let result = mat_ema_alpha_vec(&new, &old, &vec![I32F32::from_num(1); old.len()]); + assert_mat_compare(&result, &target, I32F32::from_num(0.000001)); } #[test] @@ -2183,7 +2191,15 @@ fn test_math_sparse_mat_ema() { let new = vec_to_sparse_mat_fixed(&new, 4, false); let target = vec_to_sparse_mat_fixed(&target, 4, false); let result = mat_ema_alpha_vec_sparse(&new, &old, &vec![I32F32::from_num(0.1); old.len()]); - assert_sparse_mat_compare(&result, &target, I32F32::from_num(1e-4)); + assert_sparse_mat_compare(&result, &target, I32F32::from_num(0.000001)); + let old: Vec = vec![0., 2., 3., 4., 0., 6., 7., 8., 0., 10., 11., 12.]; + let new: Vec = vec![10., 20., 0., 40., 0., 60., 0., 80., 90., 100., 110., 120.]; + let target: Vec = vec![1., 3.8, 2.7, 7.6, 0., 11.4, 6.3, 15.2, 9., 19., 20.9, 22.8]; + let old = vec_to_sparse_mat_fixed(&old, 4, false); + let new = vec_to_sparse_mat_fixed(&new, 4, false); + let target = vec_to_sparse_mat_fixed(&target, 4, false); + let result = mat_ema_alpha_vec_sparse(&new, &old, &vec![I32F32::from_num(0.1); old.len()]); + assert_sparse_mat_compare(&result, &target, I32F32::from_num(0.000001)); let old: Vec = vec![0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]; let new: Vec = vec![ 0.1, 0.2, 3., 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.10, 0.11, 0.12, @@ -2196,7 +2212,7 @@ fn test_math_sparse_mat_ema() { let new = vec_to_sparse_mat_fixed(&new, 4, false); let target = vec_to_sparse_mat_fixed(&target, 4, false); let result = mat_ema_alpha_vec_sparse(&new, &old, &vec![I32F32::from_num(0.1); old.len()]); - assert_sparse_mat_compare(&result, &target, I32F32::from_num(1e-4)); + assert_sparse_mat_compare(&result, &target, I32F32::from_num(0.000001)); let old: Vec = vec![0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]; let new: Vec = vec![0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]; let target: Vec = vec![0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]; @@ -2204,7 +2220,7 @@ fn test_math_sparse_mat_ema() { let new = vec_to_sparse_mat_fixed(&new, 4, false); let target = vec_to_sparse_mat_fixed(&target, 4, false); let result = mat_ema_alpha_vec_sparse(&new, &old, &vec![I32F32::from_num(0.1); old.len()]); - assert_sparse_mat_compare(&result, &target, I32F32::from_num(1e-4)); + assert_sparse_mat_compare(&result, &target, I32F32::from_num(0.000001)); let old: Vec = vec![1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]; let new: Vec = vec![0., 0., 0., 0., 2., 0., 0., 0., 0., 0., 0., 0.]; let target: Vec = vec![0.9, 0., 0., 0., 0.2, 0., 0., 0., 0., 0., 0., 0.]; @@ -2212,7 +2228,7 @@ fn test_math_sparse_mat_ema() { let new = vec_to_sparse_mat_fixed(&new, 4, false); let target = vec_to_sparse_mat_fixed(&target, 4, false); let result = mat_ema_alpha_vec_sparse(&new, &old, &vec![I32F32::from_num(0.1); old.len()]); - assert_sparse_mat_compare(&result, &target, I32F32::from_num(1e-4)); + assert_sparse_mat_compare(&result, &target, I32F32::from_num(0.000001)); } #[test] From 475299190c3ddc59955ea35663b2f0e4ecc25406 Mon Sep 17 00:00:00 2001 From: Andreea Popescu Date: Mon, 27 Jan 2025 03:21:02 +0000 Subject: [PATCH 12/45] rebase fix --- pallets/subtensor/src/epoch/run_epoch.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pallets/subtensor/src/epoch/run_epoch.rs b/pallets/subtensor/src/epoch/run_epoch.rs index ef0f171c34..36510532ce 100644 --- a/pallets/subtensor/src/epoch/run_epoch.rs +++ b/pallets/subtensor/src/epoch/run_epoch.rs @@ -208,7 +208,7 @@ impl Pallet { let alpha = Self::compute_liquid_alpha(netuid, consensus.clone()); // Compute the Exponential Moving Average (EMA) of bonds. - let mut ema_bonds = Self::compute_ema_bonds(&weights.clone(), &bonds, alpha); + let mut ema_bonds = Self::compute_ema_bonds(&weights_for_bonds.clone(), &bonds, alpha); // Normalize EMA bonds. inplace_col_normalize(&mut ema_bonds); // sum_i b_ij = 1 log::trace!("emaB:\n{:?}\n", &ema_bonds); @@ -588,7 +588,8 @@ impl Pallet { let alpha = Self::compute_liquid_alpha(netuid, consensus.clone()); // Compute the Exponential Moving Average (EMA) of bonds. - let mut ema_bonds = Self::compute_ema_bonds_sparse(&weights.clone(), &bonds, alpha); + let mut ema_bonds = + Self::compute_ema_bonds_sparse(&weights_for_bonds.clone(), &bonds, alpha); // Normalize EMA bonds. inplace_col_normalize_sparse(&mut ema_bonds, n); // sum_i b_ij = 1 log::trace!("Exponential Moving Average Bonds: {:?}", &ema_bonds); From 1abe9c3c1be2a8f6104f6e4b748de0624983e622 Mon Sep 17 00:00:00 2001 From: Andreea Popescu Date: Tue, 28 Jan 2025 09:56:13 +0000 Subject: [PATCH 13/45] compute_ema_bonds param rename --- pallets/subtensor/src/epoch/run_epoch.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pallets/subtensor/src/epoch/run_epoch.rs b/pallets/subtensor/src/epoch/run_epoch.rs index 36510532ce..26607422ec 100644 --- a/pallets/subtensor/src/epoch/run_epoch.rs +++ b/pallets/subtensor/src/epoch/run_epoch.rs @@ -995,19 +995,19 @@ impl Pallet { /// Compute the Exponential Moving Average (EMA) of bonds using the alpha values for a sparse matrix. /// /// # Args: - /// * `bonds_delta` - A vector of bond deltas. + /// * `weights` - A vector of weights. /// * `bonds` - A vector of bonds. /// * `alpha` - A vector of clamped alpha values (for liquid alpha) or constant alpha values. /// /// # Returns: /// A vector of EMA bonds. pub fn compute_ema_bonds_sparse( - bonds_delta: &[Vec<(u16, I32F32)>], + weights: &[Vec<(u16, I32F32)>], bonds: &[Vec<(u16, I32F32)>], alpha: Vec, ) -> Vec> { // Compute the Exponential Moving Average (EMA) of bonds using the provided clamped alpha values. - let ema_bonds = mat_ema_alpha_vec_sparse(bonds_delta, bonds, &alpha); + let ema_bonds = mat_ema_alpha_vec_sparse(weights, bonds, &alpha); // Log the computed EMA bonds for debugging purposes. log::trace!("Exponential Moving Average Bonds: {:?}", ema_bonds); @@ -1019,19 +1019,19 @@ impl Pallet { /// Compute the Exponential Moving Average (EMA) of bonds using the alpha values. /// /// # Args: - /// * `bonds_delta` - A vector of bond deltas. + /// * `weights` - A vector of weights. /// * `bonds` - A vector of bonds. /// * `alpha` - A vector of clamped alpha values (for liquid alpha) or constant alpha values. /// /// # Returns: /// A vector of EMA bonds. pub fn compute_ema_bonds( - bonds_delta: &[Vec], + weights: &[Vec], bonds: &[Vec], alpha: Vec, ) -> Vec> { // Compute the Exponential Moving Average (EMA) of bonds using the provided clamped alpha values. - let ema_bonds = mat_ema_alpha_vec(bonds_delta, bonds, &alpha); + let ema_bonds = mat_ema_alpha_vec(weights, bonds, &alpha); // Log the computed EMA bonds for debugging purposes. log::trace!("Exponential Moving Average Bonds: {:?}", ema_bonds); From 449242f9a7e131f75be57bb0de0ad7a827030098 Mon Sep 17 00:00:00 2001 From: opentaco Date: Mon, 3 Feb 2025 13:15:37 +0200 Subject: [PATCH 14/45] Add consensus test file --- pallets/subtensor/src/tests/consensus.rs | 553 +++++++++++++++++++++++ pallets/subtensor/src/tests/mod.rs | 1 + 2 files changed, 554 insertions(+) create mode 100644 pallets/subtensor/src/tests/consensus.rs diff --git a/pallets/subtensor/src/tests/consensus.rs b/pallets/subtensor/src/tests/consensus.rs new file mode 100644 index 0000000000..e5a7b59b1d --- /dev/null +++ b/pallets/subtensor/src/tests/consensus.rs @@ -0,0 +1,553 @@ +#![allow( + clippy::arithmetic_side_effects, + clippy::indexing_slicing, + clippy::unwrap_used +)] + +use super::mock::*; +use crate::*; + +use frame_support::assert_ok; +use rand::{distributions::Uniform, rngs::StdRng, seq::SliceRandom, thread_rng, Rng, SeedableRng}; +use sp_core::U256; +use std::time::Instant; +use substrate_fixed::types::{I32F32, I64F64}; +use substrate_fixed::transcendental::{cos, ln, sqrt, PI}; + +pub fn fixed(val: f32) -> I32F32 { + I32F32::from_num(val) +} + +pub fn fixed_to_u16(x: I32F32) -> u16 { + x.to_num::() +} + +pub fn fixed_proportion_to_u16(x: I32F32) -> u16 { + fixed_to_u16(x * I32F32::from_num(u16::MAX)) +} + +// Normalizes (sum to 1 except 0) the input vector directly in-place. +#[allow(dead_code)] +pub fn inplace_normalize(x: &mut [I32F32]) { + let x_sum: I32F32 = x.iter().sum(); + if x_sum == I32F32::from_num(0.0_f32) { + return; + } + for i in x.iter_mut() { + *i /= x_sum; + } +} + +// Inplace normalize the passed positive integer weights so that they sum to u16 max value. +fn normalize_weights(mut weights: Vec) -> Vec { + let sum: u64 = weights.iter().map(|x| *x as u64).sum(); + if sum == 0 { + return weights; + } + weights.iter_mut().for_each(|x| { + *x = (*x as u64 * u16::MAX as u64 / sum) as u16; + }); + weights +} + +// Return as usize an I32F32 ratio of a usize input, avoiding the 0% and 100% extremes. +fn non_extreme_fixed_ratio(ratio: I32F32, total: usize) -> usize { + if total == 0 { + return total; + } + let mut subset: usize = (ratio * I32F32::from_num(total)).to_num::(); + if subset == 0 { + subset = 1; + } else if subset == total { + subset = total - 1; + } + return subset; +} + +// Box-Muller Transform converting two uniform random samples to a normal random sample. +fn normal(size: usize, rng: &mut StdRng, dist: &Uniform) -> Vec { + let max: I32F32 = I32F32::from_num(u16::MAX); + let two: I32F32 = I32F32::from_num(2); + let eps: I32F32 = I32F32::from_num(0.000001); + let pi: I32F32 = I32F32::from_num(PI); + + let uniform_u16: Vec = (0..(2 * size)).map(|_| rng.sample(&dist)).collect(); + let uniform: Vec = uniform_u16 + .iter() + .map(|&x| I32F32::from_num(x) / max) + .collect(); + let mut normal: Vec = vec![I32F32::from_num(0); size as usize]; + + for i in 0..size { + let u1: I32F32 = uniform[i] + eps; + let u2: I32F32 = uniform[i + size] + eps; + normal[i] = sqrt::(-two * ln::(u1).expect("")).expect("") + * cos(two * pi * u2); + } + normal +} + +// Returns validators and servers uids with either blockwise, regular, or random interleaving. +fn distribute_nodes( + validators_n: usize, + network_n: usize, + interleave: usize, +) -> (Vec, Vec) { + let mut validators: Vec = vec![]; + let mut servers: Vec = vec![]; + + if interleave == 0 { + // blockwise [validator_block, server_block] + validators = (0..validators_n as u16).collect(); + servers = (validators_n as u16..network_n as u16).collect(); + } else if interleave == 1 { + // regular interleaving [val, srv, srv, ..., srv, val, srv, srv, ..., srv, val, srv, ..., srv] + (validators, servers) = (0..network_n as u16) + .collect::>() + .iter() + .partition(|&i| *i as usize % (network_n / validators_n) == 0); + } else if interleave == 2 { + // random interleaving + let mut permuted_uids: Vec = (0..network_n as u16).collect(); + permuted_uids.shuffle(&mut thread_rng()); + validators = permuted_uids[0..validators_n].into(); + servers = permuted_uids[validators_n..network_n].into(); + } + + (validators, servers) +} + +#[allow(dead_code)] +fn uid_stats(netuid: u16, uid: u16) { + log::info!( + "stake: {:?}", + SubtensorModule::get_total_stake_for_hotkey(&(U256::from(uid))) + ); + log::info!("rank: {:?}", SubtensorModule::get_rank_for_uid(netuid, uid)); + log::info!( + "trust: {:?}", + SubtensorModule::get_trust_for_uid(netuid, uid) + ); + log::info!( + "consensus: {:?}", + SubtensorModule::get_consensus_for_uid(netuid, uid) + ); + log::info!( + "incentive: {:?}", + SubtensorModule::get_incentive_for_uid(netuid, uid) + ); + log::info!( + "dividend: {:?}", + SubtensorModule::get_dividends_for_uid(netuid, uid) + ); + log::info!( + "emission: {:?}", + SubtensorModule::get_emission_for_uid(netuid, uid) + ); +} + +#[allow(clippy::too_many_arguments)] +fn init_run_epochs( + netuid: u16, + n: u16, + validators: &[u16], + servers: &[u16], + epochs: u16, + stake_per_validator: u64, + server_self: bool, + input_stake: &[u64], + use_input_stake: bool, + input_weights: &[Vec<(u16, u16)>], + use_input_weights: bool, + random_weights: bool, + random_seed: u64, + sparse: bool, + bonds_penalty: u16, +) { + // === Create the network + add_network(netuid, u16::MAX - 1, 0); // set higher tempo to avoid built-in epoch, then manual epoch instead + + // === Set bonds penalty + SubtensorModule::set_bonds_penalty(netuid, bonds_penalty); + + // === Register uids + SubtensorModule::set_max_allowed_uids(netuid, n); + for key in 0..n { + let stake = if use_input_stake { + input_stake[key as usize] + } else if validators.contains(&key) { + stake_per_validator + } else { + // only validators receive stake + 0 + }; + + // let stake: u64 = 1; // alternative test: all nodes receive stake, should be same outcome, except stake + SubtensorModule::add_balance_to_coldkey_account(&(U256::from(key)), stake); + SubtensorModule::append_neuron(netuid, &(U256::from(key)), 0); + SubtensorModule::increase_stake_for_hotkey_and_coldkey_on_subnet( + &U256::from(key), + &U256::from(key), + netuid, + stake, + ); + } + assert_eq!(SubtensorModule::get_subnetwork_n(netuid), n); + + // === Issue validator permits + SubtensorModule::set_max_allowed_validators(netuid, validators.len() as u16); + assert_eq!( + SubtensorModule::get_max_allowed_validators(netuid), + validators.len() as u16 + ); + SubtensorModule::epoch(netuid, 1_000_000_000); // run first epoch to set allowed validators + run_to_block(1); // run to next block to ensure weights are set on nodes after their registration block + + // === Set weights + let mut rng = StdRng::seed_from_u64(random_seed); // constant seed so weights over multiple runs are equal + let range = Uniform::new(0, u16::MAX); + let mut weights: Vec = vec![u16::MAX / n; servers.len()]; + for uid in validators { + if random_weights { + weights = (0..servers.len()).map(|_| rng.sample(range)).collect(); + weights = normalize_weights(weights); + // assert_eq!(weights.iter().map(|x| *x as u64).sum::(), u16::MAX as u64); // normalized weight sum not always u16::MAX + } + if use_input_weights { + let sparse_weights = input_weights[*uid as usize].clone(); + weights = sparse_weights.iter().map(|(_, w)| *w).collect(); + let srvs: Vec = sparse_weights.iter().map(|(s, _)| *s).collect(); + assert_ok!(SubtensorModule::set_weights( + RuntimeOrigin::signed(U256::from(*uid as u64)), + netuid, + srvs, + weights.clone(), + 0 + )); + } else { + assert_ok!(SubtensorModule::set_weights( + RuntimeOrigin::signed(U256::from(*uid as u64)), + netuid, + servers.to_vec(), + weights.clone(), + 0 + )); + } + } + if server_self { + for uid in servers { + assert_ok!(SubtensorModule::set_weights( + RuntimeOrigin::signed(U256::from(*uid as u64)), + netuid, + vec![*uid], + vec![u16::MAX], + 0 + )); // server self-weight + } + } + + // === Run the epochs. + log::info!("Start {epochs} epoch(s)"); + let start = Instant::now(); + for _ in 0..epochs { + if sparse { + SubtensorModule::epoch(netuid, 1_000_000_000); + } else { + SubtensorModule::epoch_dense(netuid, 1_000_000_000); + } + } + let duration = start.elapsed(); + log::info!( + "Time elapsed in (sparse={sparse}) epoch() is: {:?}", + duration + ); + + // let bonds = SubtensorModule::get_bonds( netuid ); + // for (uid, node) in vec![ (validators[0], "validator"), (servers[0], "server") ] { + // log::info!("\n{node}" ); + // uid_stats(netuid, uid); + // log::info!("bonds: {:?} (on validator), {:?} (on server)", bonds[uid as usize][0], bonds[uid as usize][servers[0] as usize]); + // } +} + +// Generate a random graph that is split into a major and minor set, each setting specific weight on itself and the complement on the other. +fn split_graph( + major_stake: I32F32, + major_weight: I32F32, + minor_weight: I32F32, + weight_stddev: I32F32, + validators_n: usize, + network_n: usize, + interleave: usize, +) -> ( + Vec, + Vec, + Vec, + Vec, + Vec, + Vec, + Vec, + Vec>, + I32F32, +) { + let servers_n: usize = network_n - validators_n; + let major_servers_n: usize = non_extreme_fixed_ratio(major_stake, servers_n); + let major_validators_n: usize = non_extreme_fixed_ratio(major_stake, validators_n); + + let (validators, servers) = distribute_nodes(validators_n, network_n, interleave as usize); + let major_validators: Vec = (0..major_validators_n).map(|i| validators[i]).collect(); + let minor_validators: Vec = (major_validators_n..validators_n) + .map(|i| validators[i]) + .collect(); + let major_servers: Vec = (0..major_servers_n).map(|i| servers[i]).collect(); + let minor_servers: Vec = (major_servers_n..servers_n).map(|i| servers[i]).collect(); + + let zero: I32F32 = I32F32::from_num(0); + let one: I32F32 = I32F32::from_num(1); + let stddev: I32F32 = I32F32::from_num(0.3); + let total_stake: I64F64 = I64F64::from_num(21_000_000_000_000_000 as u64); + let mut rng = StdRng::seed_from_u64(0); // constant seed so weights over multiple runs are equal + let dist = Uniform::new(0, u16::MAX); + + let mut stake: Vec = vec![0; network_n]; + let mut stake_fixed: Vec = vec![zero; network_n]; + for (ratio, vals) in vec![ + (major_stake, &major_validators), + (one - major_stake, &minor_validators), + ] { + let mut sample: Vec = normal(vals.len(), &mut rng, &dist) + .iter() + .map(|x: &I32F32| { + let v: I32F32 = (stddev * x) + one; + if v < zero { + zero + } else { + v + } + }) + .collect(); + inplace_normalize(&mut sample); + for (i, &val) in vals.iter().enumerate() { + stake[val as usize] = + (I64F64::from_num(ratio) * I64F64::from_num(sample[i]) * total_stake) + .to_num::(); + stake_fixed[val as usize] = + I32F32::from_num(I64F64::from_num(ratio) * I64F64::from_num(sample[i])); + } + } + + let mut weights: Vec> = vec![vec![]; network_n as usize]; + let mut weights_fixed: Vec> = vec![vec![zero; network_n]; network_n]; + for (first, second, vals) in vec![ + (major_weight, one - major_weight, &major_validators), + (one - minor_weight, minor_weight, &minor_validators), + ] { + for &val in vals { + for (weight, srvs) in vec![(first, &major_servers), (second, &minor_servers)] { + let mut sample: Vec = normal(srvs.len(), &mut rng, &dist) + .iter() + .map(|x: &I32F32| { + let v: I32F32 = (weight_stddev * x) + one; + if v < zero { + zero + } else { + v + } + }) + .collect(); + inplace_normalize(&mut sample); + + for (i, &srv) in srvs.iter().enumerate() { + weights[val as usize].push((srv, fixed_proportion_to_u16(weight * sample[i]))); + weights_fixed[val as usize][srv as usize] = weight * sample[i]; + } + } + inplace_normalize(&mut weights_fixed[val as usize]); + } + } + + inplace_normalize(&mut stake_fixed); + + // Calculate stake-weighted mean per server + let mut weight_mean: Vec = vec![zero; network_n]; + for val in 0..network_n { + if stake_fixed[val] > zero { + for srv in 0..network_n { + weight_mean[srv] += stake_fixed[val] * weights_fixed[val][srv]; + } + } + } + + // Calculate stake-weighted absolute standard deviation + let mut weight_dev: Vec = vec![zero; network_n]; + for val in 0..network_n { + if stake_fixed[val] > zero { + for srv in 0..network_n { + weight_dev[srv] += + stake_fixed[val] * (weight_mean[srv] - weights_fixed[val][srv]).abs(); + } + } + } + + // Calculate rank-weighted mean of weight_dev + let avg_weight_dev: I32F32 = + weight_dev.iter().sum::() / weight_mean.iter().sum::(); + + ( + validators, + servers, + major_validators, + minor_validators, + major_servers, + minor_servers, + stake, + weights, + avg_weight_dev, + ) +} + +// Test consensus guarantees with an epoch on a graph with 4096 nodes, of which the first 128 are validators, the graph is split into a major and minor set, each setting specific weight on itself and the complement on the other. Asserts that the major emission ratio >= major stake ratio. +// #[test] +// fn test_consensus_guarantees() { +// let netuid: u16 = 0; +// let network_n: u16 = 512; +// let validators_n: u16 = 64; +// let epochs: u16 = 1; +// let interleave = 2; +// log::info!("test_consensus_guarantees ({network_n:?}, {validators_n:?} validators)"); +// for (major_stake, major_weight, minor_weight, weight_stddev) in vec![ +// (0.51, 1., 1., 0.001), +// (0.51, 0.03, 0., 0.001), +// (0.51, 0.51, 0.49, 0.001), +// (0.51, 0.51, 1., 0.001), +// (0.51, 0.61, 0.8, 0.1), +// (0.6, 0.67, 0.65, 0.2), +// (0.6, 0.74, 0.77, 0.4), +// (0.6, 0.76, 0.8, 0.4), +// (0.6, 0.76, 1., 0.4), +// (0.6, 0.92, 1., 0.4), +// (0.6, 0.94, 1., 0.4), +// (0.65, 0.78, 0.85, 0.6), +// (0.7, 0.81, 0.85, 0.8), +// (0.7, 0.83, 0.85, 1.), +// ] { +// let ( +// validators, +// servers, +// major_validators, +// minor_validators, +// major_servers, +// minor_servers, +// stake, +// weights, +// _avg_weight_dev, +// ) = split_graph( +// fixed(major_stake), +// fixed(major_weight), +// fixed(minor_weight), +// fixed(weight_stddev), +// validators_n as usize, +// network_n as usize, +// interleave as usize, +// ); + +// new_test_ext(1).execute_with(|| { +// init_run_epochs( +// netuid, +// network_n, +// &validators, +// &servers, +// epochs, +// 1, +// true, +// &stake, +// true, +// &weights, +// true, +// false, +// 0, +// false, +// ); + +// let mut major_emission: I64F64 = I64F64::from_num(0); +// let mut minor_emission: I64F64 = I64F64::from_num(0); +// for set in vec![major_validators, major_servers] { +// for uid in set { +// major_emission += +// I64F64::from_num(SubtensorModule::get_emission_for_uid(netuid, uid)); +// } +// } +// for set in vec![minor_validators, minor_servers] { +// for uid in set { +// minor_emission += +// I64F64::from_num(SubtensorModule::get_emission_for_uid(netuid, uid)); +// } +// } +// let major_ratio: I32F32 = +// I32F32::from_num(major_emission / (major_emission + minor_emission)); +// assert!(major_stake <= major_ratio); +// }); +// } +// } + +// Map the retention graph for consensus guarantees with an single epoch on a graph with 512 nodes, of which the first 64 are validators, the graph is split into a major and minor set, each setting specific weight on itself and the complement on the other. +#[test] +fn map_consensus_guarantees() { + let netuid: u16 = 1; + let network_n: u16 = 512; + let validators_n: u16 = 64; + let epochs: u16 = 1; + let interleave = 0; + let weight_stddev: I32F32 = fixed(0.4); + let bonds_penalty: u16 = (std::env::args().nth(2).unwrap().parse::().unwrap() * f32::from(u16::MAX - 1)) as u16; + println!("["); + for _major_stake in vec![0.51, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95, 0.99] { + let major_stake: I32F32 = I32F32::from_num(_major_stake); + for _major_weight in 0..51 { + let major_weight: I32F32 = I32F32::from_num(50 - _major_weight) / I32F32::from_num(50); + for _minor_weight in 0..51 { + let minor_weight: I32F32 = + I32F32::from_num(50 - _minor_weight) / I32F32::from_num(50); + let ( + validators, + servers, + major_validators, + minor_validators, + major_servers, + minor_servers, + stake, + weights, + avg_weight_dev, + ) = split_graph( + major_stake, + major_weight, + minor_weight, + weight_stddev, + validators_n as usize, + network_n as usize, + interleave as usize, + ); + + new_test_ext(1).execute_with(|| { + init_run_epochs(netuid, network_n, &validators, &servers, epochs, 1, true, &stake, true, &weights, true, false, 0, true, bonds_penalty); + + let mut major_emission: I64F64 = I64F64::from_num(0); + let mut minor_emission: I64F64 = I64F64::from_num(0); + for set in vec![major_validators, major_servers] { + for uid in set { + major_emission += I64F64::from_num(SubtensorModule::get_emission_for_uid( netuid, uid )); + } + } + for set in vec![minor_validators, minor_servers] { + for uid in set { + minor_emission += I64F64::from_num(SubtensorModule::get_emission_for_uid( netuid, uid )); + } + } + let major_ratio: I32F32 = I32F32::from_num(major_emission / (major_emission + minor_emission)); + println!("[{major_stake}, {major_weight:.2}, {minor_weight:.2}, {avg_weight_dev:.3}, {major_ratio:.3}], "); + }); + } + } + } + println!("]"); +} diff --git a/pallets/subtensor/src/tests/mod.rs b/pallets/subtensor/src/tests/mod.rs index ce891e5615..161749a923 100644 --- a/pallets/subtensor/src/tests/mod.rs +++ b/pallets/subtensor/src/tests/mod.rs @@ -1,6 +1,7 @@ mod batch_tx; mod children; mod coinbase; +mod consensus; mod delegate_info; mod difficulty; mod emission; From 7e9258d52643f02223ac99358e141ced1ece3e5e Mon Sep 17 00:00:00 2001 From: opentaco Date: Mon, 3 Feb 2025 13:16:30 +0200 Subject: [PATCH 15/45] Add map_consensus.py script --- scripts/map_consensus.py | 130 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 scripts/map_consensus.py diff --git a/scripts/map_consensus.py b/scripts/map_consensus.py new file mode 100644 index 0000000000..8d022f8e11 --- /dev/null +++ b/scripts/map_consensus.py @@ -0,0 +1,130 @@ +import re +import sys +import numpy as np +import matplotlib.pyplot as plt +from matplotlib.pyplot import cm + + +def extract_data(filepath): + """ + Extracts the emission data from a text file. + + Args: + filepath: Path to the data file. + + Returns: + A list of lists containing the numerical data, or None if an error occurs. + """ + try: + with open(filepath, 'r') as f: + content = f.read() + except FileNotFoundError: + print(f"Error: File not found at {filepath}") + return None + + # Regular expression to extract data rows. Matches strings like "[0.51, 1.00, 1.00, ...]" + # Explanation: + # \[ Matches the opening square bracket. + # (?: ... ) Non-capturing group. + # [0-9.]+ Matches one or more digits or decimal points. + # ,\s* Matches a comma followed by zero or more whitespace characters. + # + Matches the previous group (number and comma) one or more times. + # [0-9.]+ Matches the last number in the list. + # \] Matches the closing square bracket. + + list_pattern = r'\[(?:[0-9.]+,\s*)+[0-9.]+\]' # Regular expression to match data rows + matches = re.findall(list_pattern, content) + + if not matches: + print("Error: No matching data found in the file.") + return None + + data = [] + for match in matches: + try: + # Extract numerical values from the matched string. + # 1. match[1:-1]: Removes the square brackets from the beginning and end. + # 2. .split(','): Splits the string into a list of strings at each comma. + # 3. [float(x.strip()) for x in ...]: Converts each string to a float + # after removing leading/trailing whitespace. + + row = [float(x.strip()) for x in match[1:-1].split(',')] + data.append(row) + except ValueError: + print(f"Warning: Skipping invalid data row: {match}") + + return data + + +def visualize_data(emission_data, output_filename="consensus_plot.svg"): + """ + Generates and saves a contour plot of the retention map. + + Args: + emission_data: The extracted emission data. + output_filename: The name of the output SVG file. + """ + major_ratios = {} + avg_weight_devs = {} + + # Process the data to organize it by major stake + for major_stake, major_weight, minor_weight, avg_weight_dev, major_ratio in emission_data: + major_stake_str = f'{major_stake:.2f}' + maj_idx, min_idx = int(round(50 * major_weight)), int(round(50 * minor_weight)) + + avg_weight_devs.setdefault(major_stake_str, np.zeros((51, 51))) + avg_weight_devs[major_stake_str][maj_idx][min_idx] = avg_weight_dev + + major_ratios.setdefault(major_stake_str, np.zeros((51, 51))) + major_ratios[major_stake_str][maj_idx][min_idx] = major_ratio + + + # Create the meshgrid for the contour plot + x = np.linspace(0, 1, 51) + y = np.linspace(0, 1, 51) + x, y = np.meshgrid(x, y, indexing='ij') + + # Set up the plot + fig = plt.figure(figsize=(6, 6), dpi=70) + ax = fig.gca() + ax.set_xticks(np.arange(0, 1, 0.05)) + ax.set_yticks(np.arange(0, 1., 0.05)) + ax.set_xticklabels([f'{_:.2f}'[1:] for _ in np.arange(0, 1., 0.05)]) + plt.grid(linestyle="dotted", color=[0.85, 0.85, 0.85]) + + + # Define stakes and colors for contour lines + isolate = ['0.60'] # Stakes to highlight + stakes = [0.51, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95, 0.99] + colors = cm.viridis(np.linspace(0, 1, len(stakes) + 1)) + + # Create contour lines for each stake + for i, stake in enumerate(stakes): + contours = plt.contour(x, y, major_ratios[f'{stake:.2f}'], levels=[0., stake], colors=[colors[i + 1]]) + if f'{stake:.2f}' in isolate: + contours.collections[1].set_linewidth(3) # Highlight isolated stake + plt.clabel(contours, inline=True, fontsize=10) + + # Add title and labels + plt.title(f'Major emission [$stake_{{maj}}=emission_{{maj}}$ retention lines]') + plt.ylabel('Minor self-weight') + plt.xlabel('Major self-weight') + + # Save the plot + plt.savefig(output_filename, format='svg') + print(f"Plot saved to {output_filename}") + + +if __name__ == "__main__": + if len(sys.argv) < 2: + print("Usage: python scripts/map_consensus.py [optional_output_filename]") + sys.exit(1) + + filepath = sys.argv[1] + output_filename = "consensus_plot.svg" # Default output filename + if len(sys.argv) >= 3: + output_filename = sys.argv[2] # Optional output filename + + extracted_data = extract_data(filepath) + if extracted_data: + visualize_data(extracted_data, output_filename) From b96368dee70293d08802fefe7904ac8d617c9e26 Mon Sep 17 00:00:00 2001 From: opentaco Date: Mon, 3 Feb 2025 13:18:49 +0200 Subject: [PATCH 16/45] Update consensus.md doc --- docs/consensus.md | 200 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 182 insertions(+), 18 deletions(-) diff --git a/docs/consensus.md b/docs/consensus.md index 881b465b48..c3a04c380f 100644 --- a/docs/consensus.md +++ b/docs/consensus.md @@ -17,6 +17,8 @@ Community oversight (as in Steemit) must identify wrongful downvoting, but only High-volume, on-demand generative content (as in Bittensor) demands automated evaluation and divide-and-conquer validation, but introduces subjectivity both in the automated value measures and mutually exclusive task subsets across subnet validators. A coalition of validators can collude to skew scoring of subnet servers in their favour, which is harder to detect because of the inherent subjectivity. Existing consensus mechanisms will fail to deter reward manipulation for such high-volume subjective utility networks, so the need for a more sophisticated consensus arises. +--- + ### Consensus Mechanism Yuma Consensus guarantees long-term network honesty despite persistent adversarial presence in high-volume subjective utility networks. It directly penalizes selfish scoring by down-correction to the majority consensus and slashing of cabal voting stake, and also penalizes low-scoring of honest servers via forfeited validator rewards when cabals don’t score at consensus. @@ -31,6 +33,8 @@ Yuma Consensus is adversarially-resilient when majority stake is honest, via sta **Cabal sets high self-weight**: Cabal servers with poor utility will receive low weights from majority stake, and high self-weight from minority cabals will then get reduced to the low consensus. This means that minority cabals lose voting power as penalty for unfair voting while still receiving low consensus weight despite high self-weight. This consensus mechanism thus protects against selfish weighting if the majority stake is honest. +--- + ### Game-theoretic framework #### Preliminaries @@ -112,6 +116,64 @@ let mut ema_bonds: Vec> = mat_ema( &bonds_delta, &bonds, alpha ); / let mut dividends: Vec = inplace_normalize(matmul_transpose( &ema_bonds, &incentive )); // Validator reward ``` +--- + +### Monte Carlo simulations + +We consider a two-team game between (protagonist) honest stake ($0.5< S_H\le 1$) and (adversarial) cabal stake ($1 - S_H$), with $|H|$ honest and $|C|$ cabal players, that have $S_H = \sum_{i\in H}S_i$ honest stake and $1-S_H = \sum_{i\in C}S_i$ cabal stake. + +#### Network sizing + +A network size of $N=|H|+|C|=(|H_V|+|H_S|)+(|C_V|+|C_S|)=512$ and validator count of $|H_V|+|C_V|=64$ is considered for consensus guarantee experiments, and the honest/cabal ratio $|H|/N=S_H$ reflects the honest stake ratio $S_H$, but modifying extremes to ensure that each subset has at least one validator and at least one server. + +#### Stake sampling + +For the Monte Carlo simulations we use Gaussian distributions for stake and weight assignments, and ensure that the honest/cabal ratios are met. Note that stake is only assigned to validator nodes $H_V$ and $C_V$ and not servers. + +Firstly, we sample initial validator ($i\in H_V\cup C_V$) stake values $S'_i \sim \mathcal{N}(1,\sigma_S^{2})$ with a typical $\sigma_S=0.3$ standard deviation, followed by clamping to avoid negative stake: + +$$S'_i = \begin{cases} +x & \text{if } x \sim \mathcal{N}(1, \sigma_S^2), x \ge 0 \\ +0 & \text{if } x \sim \mathcal{N}(1, \sigma_S^2), x < 0 +\end{cases}$$ + +Then we normalize each honest/cabal subset and multiply by its stake proportion, which thus gives an overall normalized stake and the correct stake ratio for each subset: + +$$S_{i\in H_V} = S_H \cdot S'\_i \left/ \sum_{k\in H_V} S'\_k\right.\qquad\qquad S_{i\in C_V} = (1-S_H)\cdot S'\_i \left/ \sum_{k\in C_V}S'\_k\right.$$ + +#### Weight sampling + +Similarly, we randomize the weights that validators $H_V,C_V$ set on servers $H_S,C_S$. +Specifically, honest players $i\in H$ set $W_H = \sum_{j\in H}W_{ij}$ self-weight and $1-W_H = \sum_{j\in C}W_{ij}$ weight on cabal players, while cabal players $i\in C$ set $W_C = \sum_{j\in C}W_{ij}$ self-weight and $1-W_C = \sum_{j\in H}W_{ij}$ weight on honest players. + +We firstly sample initial weights $W'_{ij} \sim \mathcal{N}(1,\sigma_W^{2})$ with various standard deviations ranging in $0\ge\sigma_W\ge0.4$, but then clamping to avoid negative weights: + +$$W'_{ij} = \begin{cases} +x & \text{if } x \sim \mathcal{N}(1, \sigma_S^2), x \geq 0 \\ +0 & \text{if } x \sim \mathcal{N}(1, \sigma_S^2), x < 0 +\end{cases}$$ + +Weight setting between the two subsets forms quadrants $H_V\rightarrow H_S$, $H_V\rightarrow C_S$, $C_V\rightarrow H_S$, and $C_V\rightarrow C_S$, so we ensure those weight ratios are met by normalizing each weight subset and multiplying by the corresponding quadrant ratio: + +$$W_{i\in H_V, j\in H_S} = W_H\cdot W'\_{ij} \left/ \sum_{k\in H_S}W'\_{ik}\right.\qquad\qquad W_{i\in H_V, j\in C_S} = (1-W_H)\cdot W'\_{ij} \left/ \sum_{k\in C_S}W'\_{ik}\right.$$ + +$$W_{i\in C_V, j\in H_S} = (1-W_C)\cdot W'\_{ij} \left/ \sum_{k\in H_S}W'\_{ik}\right.\qquad\qquad W_{i\in C_V, j\in C_S} = W_C\cdot W'\_{ij} \left/ \sum_{k\in C_S}W'\_{ik}\right.$$ + +#### Emission calculation + +Given the simulation parameters of the network size, validator count, a defined major/honest stake $S_H$, a defined major/honest utility $W_H$, and a defined minor/cabal self-weight $W_C$, we have now instantiated the network with randomly sampled stake and weights and can proceed with an emission calculation. + +We calculate the consensus $\overline{W_j} = \arg \max_w \left( \sum_i S_i \cdot \left\lbrace W_{ij} \ge w \right\rbrace \ge \kappa \right)$ for each server $j$, and calculate consensus-clipped weights $\overline{W_{ij}} = \min( W_{ij}, \overline{W_j} )$. This then gives us the adjusted weights that offers a measure of protection against reward manipulation. + +To calculate emissions for this epoch, we firstly calculate server rank $R_j = \sum_i S_i \cdot \overline{W_{ij}}$ then incentive $I_j = R_j / \sum_k R_k$, as well as validator bonds $\Delta B_{ij} = S_i \cdot \widetilde{W_{ij}} \left/ \left( \sum_k S_k \cdot \widetilde{W_{kj}} \right) \right.$ and rewards $D_i = \sum_j B_{ij} \cdot I_j$. + +Then we add up server incentive and validator bonds over honest nodes to obtain honest emission $E_H = \xi \cdot D_{i\in H} + (1-\xi) \cdot I_{i\in H}$ with a typical validator reward ratio of $\xi=0.5$. +The objective is to prove major stake retention $S_H\ge E_H$ for a single epoch, which by extension proves retention over many epochs due to additive nature of EMA bonds, so we do not bother with validator EMA bonds in these experiments. + +The honest objective $S_H\le E_H$ at least retains scoring power $S_H$ over all action transitions in the game, otherwise when $E_H\le S_H$ honest emission will erode to 0 over time, despite a starting condition of $0.5\lt S_H$. + +--- + ### Consensus guarantees Yuma Consensus guarantees honest majority stake retention $S_H\le E_H$ even under worst-case adversarial attacks, given sufficiently large honest utility $W_H$. The specific honest stake and utility pairs that delineate the guarantees are complicated by natural variances inside large realistic networks. Therefore, we use extensive random sampling simulations (Monte Carlo studies) of large realistic networks and subject them to varying degrees of adversarial attacks, and calculate comprehensive consensus guarantees under representative conditions. @@ -124,9 +186,9 @@ The x-axis is major self-weight and the y-axis is minor self-weight, and each co Major/honest self-weight $W_H$ is the true honest utility, while minor/cabal self-weight $W_C$ is an arbitrary value a self-serving coalition may self-report.

- - - + + +

To understand how we construct these plots, let us first consider contour plot for a single major/honest stake setting $S_H=0.6$. Here each contour value is the honest emission $E_H$, and we highlight at (1) the specific contour $E_H=0.6$ that matches the honest stake. This means that any weight setting on contour $E_H=S_H=0.6$ will retain honest stake, while any setting to the right of it will grow honest stake. @@ -138,18 +200,20 @@ A compound plot then combines all the highlighted $S_H=E_H$ contours from indivi Retention graphs like these comprehensively capture consensus guarantees across all primary conditions, and we utilize these to analyze the effect of consensus hyperparameters. Subtensor integration tests run Monte Carlo simulations of large realistic networks under adversarial conditions, and constructs retention profiles to confirm consensus guarantees of the actual blockchain implementation. -Retention profiles are reproducible by running [`_map_consensus_guarantees`](../pallets/subtensor/tests/epoch.rs) (decorate with `#[test]`). +Retention profiles are reproducible by running test [`map_consensus_guarantees()`](../pallets/subtensor/src/tests/consensus.rs) and plotting with [`map_consensus.py`](../scripts/map_consensus.py). ```bash -RUST_BACKTRACE=1 SKIP_WASM_BUILD=1 cargo test -- _map_consensus_guarantees --exact --nocapture > consensus.txt +RUST_BACKTRACE=1 SKIP_WASM_BUILD=1 RUSTFLAGS="-C opt-level=3" cargo test --manifest-path=pallets/subtensor/Cargo.toml -- tests::consensus::map_consensus_guarantees --exact --nocapture > consensus.txt + +python scripts/map_consensus.py consensus.txt ``` #### Subjectivity variance Yuma Consensus corrects reward manipulation in subjective utility networks, but the extent of subjectivity influences the exact consensus guarantees. In particular, we expect lower subjectivity to offer improved guarantees since there is stronger consensus. However, for higher variance in assigned weights it is easier to hide reward manipulation, we then expect poorer guarantees.

- - - + + +

We assume normally distributed weights originating from a particular side, either honest or cabal, then we modify the weight deviation magnitude $\sigma(W)$ in terms of the mean weight $\mu(W)$. @@ -167,9 +231,9 @@ Increasing $\kappa$ demands greater honest stake, e.g. when $\kappa=0.6$ there i Hence $\kappa=0.5$ is typically the most sensible setting.

- - - + + +

#### Bonds penalty (β) @@ -179,9 +243,9 @@ Lower-stake validators may experience lower service priority, which can result i Full bonds penalty $\beta=1$ may not be desired, due to the presence of non-adversarial cases like these.

- - - + + +

We expect that greater bonds penalty will penalize out-of-consensus validators more, which means less emission going to cabals. Comprehensive simulation with $\beta = 0$, $0.5$, and $1$ respectively show 78%, 76%, and 73% honest utility requirement. This confirms the expectation, that greater bonds penalty means greater inflation going to the honest majority. @@ -191,10 +255,110 @@ Subnet servers need incentive to deliver high utility, and subnet validators nee We expect that more emission going to validators will improve security guarantees, since self-serving validation can then be economically disincentivized.

- - - + + +

We set validation reward ratio at $\xi=0$, $0.25$, and $0.5$ and respectively observe 82%, 78%, 73% honest utility requirement for 60% honest stake preservation. -This means that network security improves as the validation reward ratio is increased, although a significant server incentive ratio still needs to be maintained to ensure overall high utility. \ No newline at end of file +This means that network security improves as the validation reward ratio is increased, although a significant server incentive ratio still needs to be maintained to ensure overall high utility. + +--- + +### Reproduce Consensus Plots (Runpod) + +This guide demonstrates how to reproduce consensus retention profile plots on a minimal Runpod CPU instance. + +#### 1. Deploy Runpod Instance + +Navigate to https://www.runpod.io/console/deploy and select the following: + +* **Pod Type:** CPU Pod, CPU5 (5.7 GHz • DDR5 RAM • NVMe) or equivalent. +* **Instance Configuration:** Compute-Optimized ($0.07/hr, 2 vCPUs, 4GB RAM). + +**Important:** Edit the template and set "Container Disk (Temporary)" to 20GB. This ensures sufficient disk space for the process. + +Retrieve the connection details, including the SSH command and port, under "Connect" -> "SSH over exposed TCP". You can optionally enable Jupyter access (`8888:localhost:8888`) if desired. Connect to your instance via SSH: + +```bash +ssh -L 8888:localhost:8888 root@ -p -i ~/.ssh/id_ed25519 # Replace placeholders +``` + +#### 2. Set up the Environment + +1. **Start a `tmux` session for persistence:** + + ```bash + tmux + ``` + +2. **Update system packages and install prerequisites (Python, Rust, and dependencies):** + + ```bash + sudo apt-get update && sudo apt install -y build-essential clang curl git make libssl-dev llvm libudev-dev protobuf-compiler python3 python3-pip \ + && curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y \ + && source ~/.cargo/env && rustup default stable && rustup update \ + && rustup target add wasm32-unknown-unknown \ + && rustup toolchain install nightly \ + && rustup target add --toolchain nightly wasm32-unknown-unknown + + ``` + +3. **Clone the Subtensor repository and checkout the relevant branch:** + + ```bash + git clone https://github.com/opentensor/subtensor.git + cd subtensor + git checkout main + + ``` + + +#### 3. Simulate Networks and Generate Data + +The Subtensor integration tests simulate large, realistic networks under adversarial conditions to generate retention profiles that validate the blockchain's consensus guarantees. Building takes about 10 minutes, and the actual test itself another 15 minutes approximately. + + +```bash +RUST_BACKTRACE=1 SKIP_WASM_BUILD=1 RUSTFLAGS="-C opt-level=3" cargo test --manifest-path=pallets/subtensor/Cargo.toml -- tests::consensus::map_consensus_guarantees --exact --nocapture > consensus.txt +``` +This command runs the `map_consensus_guarantees` test and saves the output to `consensus.txt`. Replace `` with a float e.g. 1.0 (100% bonds penalty). + +#### 4. Generate Contour Plots + +1. **Create a Python virtual environment and install necessary libraries:** + + ```bash + python3 -m venv .venv + source .venv/bin/activate + pip install numpy matplotlib jupyterlab + + ``` + +2. **Run the plotting script:** + + ```bash + python3 scripts/map_consensus.py consensus.txt + ``` + This generates an SVG file named `consensus_plot.svg` in the current directory. + + +#### 5. Explore and Modify (Optional) + +You can use Jupyter-lab to interactively explore and modify the generated plots: + +1. **Start Jupyter-lab (on VPS):** + ```bash + jupyter-lab --allow-root --port=8888 + ``` + +2. **Connect to Jupyter:** Open the provided URL (e.g., `http://localhost:8888/tree?token=...`) in your local workstation web browser. + +3. **Modify the plotting script:** Edit `scripts/map_consensus.py` to customize the plots, otherwise download the SVG file. + + +#### Disclaimer + +> This reproduction procedure is provided as a guide and may require adjustments depending on your specific VPS environment and configuration. While every effort has been made to ensure accuracy and completeness, variations in system setup, software versions, or network conditions could affect the results. +> +> Please exercise caution when executing commands with root privileges and ensure you understand the potential implications before proceeding. The author assumes no responsibility for any issues arising from the use of this procedure. If you encounter problems or have suggestions for improvement, please open an issue on this repository. From c5a43688ca0dd61dfe132ddd071e894075f0f7e6 Mon Sep 17 00:00:00 2001 From: Andreea Popescu Date: Wed, 5 Feb 2025 14:09:34 +0000 Subject: [PATCH 17/45] fix alpha values --- pallets/subtensor/src/epoch/math.rs | 10 ++ pallets/subtensor/src/epoch/run_epoch.rs | 113 +++++++++++++---------- pallets/subtensor/src/tests/consensus.rs | 41 ++++---- pallets/subtensor/src/tests/epoch.rs | 10 +- 4 files changed, 99 insertions(+), 75 deletions(-) diff --git a/pallets/subtensor/src/epoch/math.rs b/pallets/subtensor/src/epoch/math.rs index 5d17ff9e0b..f1a4b33c57 100644 --- a/pallets/subtensor/src/epoch/math.rs +++ b/pallets/subtensor/src/epoch/math.rs @@ -55,6 +55,11 @@ pub fn u16_proportion_to_fixed(x: u16) -> I32F32 { I32F32::saturating_from_num(x).safe_div(I32F32::saturating_from_num(u16::MAX)) } +#[allow(dead_code)] +pub fn fixed_proportion_to_fixed(x: I32F32) -> I32F32 { + x.safe_div(I32F32::saturating_from_num(u16::MAX)) +} + #[allow(dead_code)] pub fn fixed_proportion_to_u16(x: I32F32) -> u16 { fixed_to_u16(x.saturating_mul(I32F32::saturating_from_num(u16::MAX))) @@ -80,6 +85,11 @@ pub fn vec_fixed64_to_u64(vec: Vec) -> Vec { vec.into_iter().map(fixed64_to_u64).collect() } +#[allow(dead_code)] +pub fn vec_fixed_proportions_to_fixed(vec: Vec) -> Vec { + vec.into_iter().map(fixed_proportion_to_fixed).collect() +} + #[allow(dead_code)] pub fn vec_u16_proportions_to_fixed(vec: Vec) -> Vec { vec.into_iter().map(u16_proportion_to_fixed).collect() diff --git a/pallets/subtensor/src/epoch/run_epoch.rs b/pallets/subtensor/src/epoch/run_epoch.rs index 26607422ec..dabec2351a 100644 --- a/pallets/subtensor/src/epoch/run_epoch.rs +++ b/pallets/subtensor/src/epoch/run_epoch.rs @@ -12,7 +12,7 @@ impl Pallet { pub fn epoch_dense(netuid: u16, rao_emission: u64) -> Vec<(T::AccountId, u64, u64)> { // Get subnetwork size. let n: u16 = Self::get_subnetwork_n(netuid); - log::trace!("n:\n{:?}\n", n); + log::trace!("n: {:?}", n); // ====================== // == Active & updated == @@ -20,7 +20,7 @@ impl Pallet { // Get current block. let current_block: u64 = Self::get_current_block_as_u64(); - log::trace!("current_block:\n{:?}\n", current_block); + log::trace!("current_block: {:?}", current_block); // Get tempo. let tempo: u64 = Self::get_tempo(netuid).into(); @@ -28,25 +28,25 @@ impl Pallet { // Get activity cutoff. let activity_cutoff: u64 = Self::get_activity_cutoff(netuid) as u64; - log::trace!("activity_cutoff:\n{:?}\n", activity_cutoff); + log::trace!("activity_cutoff: {:?}", activity_cutoff); // Last update vector. let last_update: Vec = Self::get_last_update(netuid); - log::trace!("Last update:\n{:?}\n", &last_update); + log::trace!("Last update: {:?}", &last_update); // Inactive mask. let inactive: Vec = last_update .iter() .map(|updated| updated.saturating_add(activity_cutoff) < current_block) .collect(); - log::trace!("Inactive:\n{:?}\n", inactive.clone()); + log::trace!("Inactive: {:?}", inactive.clone()); // Logical negation of inactive. let active: Vec = inactive.iter().map(|&b| !b).collect(); // Block at registration vector (block when each neuron was most recently registered). let block_at_registration: Vec = Self::get_block_at_registration(netuid); - log::trace!("Block at registration:\n{:?}\n", &block_at_registration); + log::trace!("Block at registration: {:?}", &block_at_registration); // Outdated matrix, outdated_ij=True if i has last updated (weights) after j has last registered. let outdated: Vec> = last_update @@ -58,7 +58,7 @@ impl Pallet { .collect() }) .collect(); - log::trace!("Outdated:\n{:?}\n", &outdated); + log::trace!("Outdated: {:?}", &outdated); // Recently registered matrix, recently_ij=True if last_tempo was *before* j was last registered. // Mask if: the last tempo block happened *before* the registration block @@ -84,7 +84,7 @@ impl Pallet { Self::get_stake_weights_for_network(netuid); inplace_normalize_64(&mut total_stake); let stake: Vec = vec_fixed64_to_fixed32(total_stake); - log::trace!("S:\n{:?}\n", &stake); + log::trace!("S: {:?}", &stake); // ======================= // == Validator permits == @@ -119,7 +119,7 @@ impl Pallet { // Normalize active stake. inplace_normalize(&mut active_stake); - log::trace!("S:\n{:?}\n", &active_stake); + log::trace!("S: {:?}", &active_stake); // ============= // == Weights == @@ -130,7 +130,7 @@ impl Pallet { // Access network weights row unnormalized. let mut weights: Vec> = Self::get_weights(netuid); - log::trace!("W:\n{:?}\n", &weights); + log::trace!("W: {:?}", &weights); // Mask weights that are not from permitted validators. inplace_mask_rows(&validator_forbids, &mut weights); @@ -144,15 +144,15 @@ impl Pallet { } inplace_mask_diag(&mut weights); - log::trace!("W (permit+diag):\n{:?}\n", &weights); + log::trace!("W (permit+diag): {:?}", &weights); // Mask outdated weights: remove weights referring to deregistered neurons. inplace_mask_matrix(&outdated, &mut weights); - log::trace!("W (permit+diag+outdate):\n{:?}\n", &weights); + log::trace!("W (permit+diag+outdate): {:?}", &weights); // Normalize remaining weights. inplace_row_normalize(&mut weights); - log::trace!("W (mask+norm):\n{:?}\n", &weights); + log::trace!("W (mask+norm): {:?}", &weights); // ================================ // == Consensus, Validator Trust == @@ -183,7 +183,7 @@ impl Pallet { inplace_normalize(&mut ranks); let incentive: Vec = ranks.clone(); - log::trace!("I:\n{:?}\n", &incentive); + log::trace!("I: {:?}", &incentive); // ========================= // == Bonds and Dividends == @@ -199,25 +199,31 @@ impl Pallet { // Access network bonds. let mut bonds: Vec> = Self::get_bonds(netuid); - // Remove bonds referring to neurons that have registered since last tempo. - inplace_mask_cols(&recently_registered, &mut bonds); // mask recently registered bonds - inplace_col_normalize(&mut bonds); // sum_i b_ij = 1 - log::trace!("B:\n{:?}\n", &bonds); + inplace_mask_matrix(&outdated, &mut bonds); // mask outdated bonds + for bonds_row in &mut bonds { + *bonds_row = vec_fixed_proportions_to_fixed(bonds_row.clone()); + } + // inplace_col_normalize(&mut bonds); // sum_i b_ij = 1 + log::trace!("B: {:?}", &bonds); // Get alpha values - let alpha = Self::compute_liquid_alpha(netuid, consensus.clone()); + let alphas = Self::compute_liquid_alpha(netuid, consensus.clone()); + log::trace!("alphas: {:?}", &alphas); // Compute the Exponential Moving Average (EMA) of bonds. - let mut ema_bonds = Self::compute_ema_bonds(&weights_for_bonds.clone(), &bonds, alpha); + let ema_bonds = Self::compute_ema_bonds(&weights_for_bonds.clone(), &bonds, alphas); + log::trace!("emaB: {:?}", &ema_bonds); + // Normalize EMA bonds. - inplace_col_normalize(&mut ema_bonds); // sum_i b_ij = 1 - log::trace!("emaB:\n{:?}\n", &ema_bonds); + let mut ema_bonds_norm = ema_bonds.clone(); + inplace_col_normalize(&mut ema_bonds_norm); + log::trace!("emaB norm: {:?}", &ema_bonds_norm); // # === Dividend Calculation=== let total_bonds_per_validator: Vec = matmul_transpose(&ema_bonds, &incentive); let mut dividends: Vec = vec_mul(&total_bonds_per_validator, &active_stake); inplace_normalize(&mut dividends); - log::trace!("D:\n{:?}\n", ÷nds); + log::trace!("D: {:?}", ÷nds); // ================================= // == Emission and Pruning scores == @@ -342,8 +348,6 @@ impl Pallet { ValidatorTrust::::insert(netuid, cloned_validator_trust); ValidatorPermit::::insert(netuid, new_validator_permits.clone()); - // Column max-upscale EMA bonds for storage: max_i w_ij = 1. - inplace_col_max_upscale(&mut ema_bonds); new_validator_permits .iter() .zip(validator_permits) @@ -477,7 +481,7 @@ impl Pallet { // Normalize active stake. inplace_normalize(&mut active_stake); - log::debug!("Active Stake:\n{:?}\n", &active_stake); + log::trace!("Active Stake: {:?}", &active_stake); // ============= // == Weights == @@ -585,14 +589,14 @@ impl Pallet { log::trace!("B (mask+norm): {:?}", &bonds); // Get alpha values - let alpha = Self::compute_liquid_alpha(netuid, consensus.clone()); + let alphas = Self::compute_liquid_alpha(netuid, consensus.clone()); // Compute the Exponential Moving Average (EMA) of bonds. let mut ema_bonds = Self::compute_ema_bonds_sparse(&weights_for_bonds.clone(), &bonds, alpha); // Normalize EMA bonds. inplace_col_normalize_sparse(&mut ema_bonds, n); // sum_i b_ij = 1 - log::trace!("Exponential Moving Average Bonds: {:?}", &ema_bonds); + log::trace!("emaB norm: {:?}", &ema_bonds); // # === Dividend Calculation=== let total_bonds_per_validator: Vec = @@ -1057,34 +1061,43 @@ impl Pallet { .any(|&c| c != I32F32::saturating_from_num(0)) { // Calculate the 75th percentile (high) and 25th percentile (low) of the consensus values. - let consensus_high = quantile(&consensus, 0.75); + let mut consensus_high = quantile(&consensus, 0.75); let consensus_low = quantile(&consensus, 0.25); - // Further check if the high and low consensus values meet the required conditions. - if (consensus_high > consensus_low) || consensus_high != 0 || consensus_low < 0 { - log::trace!("Using Liquid Alpha"); - - // Get the high and low alpha values for the network. - let (alpha_low, alpha_high): (I32F32, I32F32) = Self::get_alpha_values_32(netuid); - log::trace!("alpha_low: {:?} alpha_high: {:?}", alpha_low, alpha_high); + if consensus_high == consensus_low { + consensus_high = quantile(&consensus, 0.99); + } + if consensus_high == consensus_low { + consensus_high = I32F32::saturating_from_num(1.0); + } + log::trace!( + "consensus_high: {:?}, consensus_low: {:?}", + consensus_high, + consensus_low + ); - // Calculate the logistic function parameters 'a' and 'b' based on alpha and consensus values. - let (a, b) = Self::calculate_logistic_params( - alpha_high, - alpha_low, - consensus_high, - consensus_low, - ); + // Get the high and low alpha values for the network. + let (alpha_low, alpha_high): (I32F32, I32F32) = Self::get_alpha_values_32(netuid); + // log::warn!("alpha_high: {:?}, alpha_low: {:?} ", alpha_high, alpha_low); - // Compute the alpha values using the logistic function parameters. - // alpha = 1 / (1 + math.e ** (-a * C + b)) # alpha to the old weight - let alpha = Self::compute_alpha_values(&consensus, a, b); + // Calculate the logistic function parameters 'a' and 'b' based on alpha and consensus values. + let (a, b) = Self::calculate_logistic_params( + alpha_high, + alpha_low, + consensus_high, + consensus_low, + ); - // Clamp the alpha values between alpha_high and alpha_low. - let clamped_alpha = Self::clamp_alpha_values(alpha, alpha_high, alpha_low); + // Compute the alpha values using the logistic function parameters. + // alpha = 1 / (1 + math.e ** (-a * C + b)) # alpha to the old weight + let alpha = Self::compute_alpha_values(&consensus, a, b); - return clamped_alpha; - } + // return 1 - alpha values clamped between alpha_high and alpha_low. + let clamped_alpha: Vec = Self::clamp_alpha_values(alpha, alpha_high, alpha_low); + return clamped_alpha + .iter() + .map(|a| I32F32::saturating_from_num(1.0).saturating_sub(*a)) + .collect(); } // Liquid Alpha is disabled diff --git a/pallets/subtensor/src/tests/consensus.rs b/pallets/subtensor/src/tests/consensus.rs index e5a7b59b1d..bb8175120b 100644 --- a/pallets/subtensor/src/tests/consensus.rs +++ b/pallets/subtensor/src/tests/consensus.rs @@ -11,8 +11,8 @@ use frame_support::assert_ok; use rand::{distributions::Uniform, rngs::StdRng, seq::SliceRandom, thread_rng, Rng, SeedableRng}; use sp_core::U256; use std::time::Instant; -use substrate_fixed::types::{I32F32, I64F64}; use substrate_fixed::transcendental::{cos, ln, sqrt, PI}; +use substrate_fixed::types::{I32F32, I64F64}; pub fn fixed(val: f32) -> I32F32 { I32F32::from_num(val) @@ -61,7 +61,7 @@ fn non_extreme_fixed_ratio(ratio: I32F32, total: usize) -> usize { } else if subset == total { subset = total - 1; } - return subset; + subset } // Box-Muller Transform converting two uniform random samples to a normal random sample. @@ -71,12 +71,12 @@ fn normal(size: usize, rng: &mut StdRng, dist: &Uniform) -> Vec { let eps: I32F32 = I32F32::from_num(0.000001); let pi: I32F32 = I32F32::from_num(PI); - let uniform_u16: Vec = (0..(2 * size)).map(|_| rng.sample(&dist)).collect(); + let uniform_u16: Vec = (0..(2 * size)).map(|_| rng.sample(dist)).collect(); let uniform: Vec = uniform_u16 .iter() .map(|&x| I32F32::from_num(x) / max) .collect(); - let mut normal: Vec = vec![I32F32::from_num(0); size as usize]; + let mut normal: Vec = vec![I32F32::from_num(0); size]; for i in 0..size { let u1: I32F32 = uniform[i] + eps; @@ -263,7 +263,7 @@ fn init_run_epochs( ); // let bonds = SubtensorModule::get_bonds( netuid ); - // for (uid, node) in vec![ (validators[0], "validator"), (servers[0], "server") ] { + // for (uid, node) in [ (validators[0], "validator"), (servers[0], "server") ] { // log::info!("\n{node}" ); // uid_stats(netuid, uid); // log::info!("bonds: {:?} (on validator), {:?} (on server)", bonds[uid as usize][0], bonds[uid as usize][servers[0] as usize]); @@ -294,7 +294,7 @@ fn split_graph( let major_servers_n: usize = non_extreme_fixed_ratio(major_stake, servers_n); let major_validators_n: usize = non_extreme_fixed_ratio(major_stake, validators_n); - let (validators, servers) = distribute_nodes(validators_n, network_n, interleave as usize); + let (validators, servers) = distribute_nodes(validators_n, network_n, interleave); let major_validators: Vec = (0..major_validators_n).map(|i| validators[i]).collect(); let minor_validators: Vec = (major_validators_n..validators_n) .map(|i| validators[i]) @@ -305,13 +305,13 @@ fn split_graph( let zero: I32F32 = I32F32::from_num(0); let one: I32F32 = I32F32::from_num(1); let stddev: I32F32 = I32F32::from_num(0.3); - let total_stake: I64F64 = I64F64::from_num(21_000_000_000_000_000 as u64); + let total_stake: I64F64 = I64F64::from_num(21_000_000_000_000_000_u64); let mut rng = StdRng::seed_from_u64(0); // constant seed so weights over multiple runs are equal let dist = Uniform::new(0, u16::MAX); let mut stake: Vec = vec![0; network_n]; let mut stake_fixed: Vec = vec![zero; network_n]; - for (ratio, vals) in vec![ + for (ratio, vals) in [ (major_stake, &major_validators), (one - major_stake, &minor_validators), ] { @@ -336,14 +336,14 @@ fn split_graph( } } - let mut weights: Vec> = vec![vec![]; network_n as usize]; + let mut weights: Vec> = vec![vec![]; network_n]; let mut weights_fixed: Vec> = vec![vec![zero; network_n]; network_n]; - for (first, second, vals) in vec![ + for (first, second, vals) in [ (major_weight, one - major_weight, &major_validators), (one - minor_weight, minor_weight, &minor_validators), ] { for &val in vals { - for (weight, srvs) in vec![(first, &major_servers), (second, &minor_servers)] { + for (weight, srvs) in [(first, &major_servers), (second, &minor_servers)] { let mut sample: Vec = normal(srvs.len(), &mut rng, &dist) .iter() .map(|x: &I32F32| { @@ -372,8 +372,8 @@ fn split_graph( let mut weight_mean: Vec = vec![zero; network_n]; for val in 0..network_n { if stake_fixed[val] > zero { - for srv in 0..network_n { - weight_mean[srv] += stake_fixed[val] * weights_fixed[val][srv]; + for (srv, weight_mean_row) in weight_mean.iter_mut().enumerate().take(network_n) { + *weight_mean_row += stake_fixed[val] * weights_fixed[val][srv]; } } } @@ -415,7 +415,7 @@ fn split_graph( // let epochs: u16 = 1; // let interleave = 2; // log::info!("test_consensus_guarantees ({network_n:?}, {validators_n:?} validators)"); -// for (major_stake, major_weight, minor_weight, weight_stddev) in vec![ +// for (major_stake, major_weight, minor_weight, weight_stddev) in [ // (0.51, 1., 1., 0.001), // (0.51, 0.03, 0., 0.001), // (0.51, 0.51, 0.49, 0.001), @@ -471,13 +471,13 @@ fn split_graph( // let mut major_emission: I64F64 = I64F64::from_num(0); // let mut minor_emission: I64F64 = I64F64::from_num(0); -// for set in vec![major_validators, major_servers] { +// for set in [major_validators, major_servers] { // for uid in set { // major_emission += // I64F64::from_num(SubtensorModule::get_emission_for_uid(netuid, uid)); // } // } -// for set in vec![minor_validators, minor_servers] { +// for set in [minor_validators, minor_servers] { // for uid in set { // minor_emission += // I64F64::from_num(SubtensorModule::get_emission_for_uid(netuid, uid)); @@ -499,9 +499,10 @@ fn map_consensus_guarantees() { let epochs: u16 = 1; let interleave = 0; let weight_stddev: I32F32 = fixed(0.4); - let bonds_penalty: u16 = (std::env::args().nth(2).unwrap().parse::().unwrap() * f32::from(u16::MAX - 1)) as u16; + let bonds_penalty: u16 = + (std::env::args().nth(2).unwrap().parse::().unwrap() * f32::from(u16::MAX - 1)) as u16; println!("["); - for _major_stake in vec![0.51, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95, 0.99] { + for _major_stake in [0.51, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95, 0.99] { let major_stake: I32F32 = I32F32::from_num(_major_stake); for _major_weight in 0..51 { let major_weight: I32F32 = I32F32::from_num(50 - _major_weight) / I32F32::from_num(50); @@ -533,12 +534,12 @@ fn map_consensus_guarantees() { let mut major_emission: I64F64 = I64F64::from_num(0); let mut minor_emission: I64F64 = I64F64::from_num(0); - for set in vec![major_validators, major_servers] { + for set in [major_validators, major_servers] { for uid in set { major_emission += I64F64::from_num(SubtensorModule::get_emission_for_uid( netuid, uid )); } } - for set in vec![minor_validators, minor_servers] { + for set in [minor_validators, minor_servers] { for uid in set { minor_emission += I64F64::from_num(SubtensorModule::get_emission_for_uid( netuid, uid )); } diff --git a/pallets/subtensor/src/tests/epoch.rs b/pallets/subtensor/src/tests/epoch.rs index 175b00ab7f..8b547fb2a1 100644 --- a/pallets/subtensor/src/tests/epoch.rs +++ b/pallets/subtensor/src/tests/epoch.rs @@ -3331,7 +3331,7 @@ fn setup_yuma_4_scenario(netuid: u16, n: u16, max_stake: u64, stakes: Vec) assert_eq!(SubtensorModule::get_subnetwork_n(netuid), n); // Enable Liquid Alpha - SubtensorModule::set_kappa(netuid, 0); + SubtensorModule::set_kappa(netuid, u16::MAX / 2); SubtensorModule::set_liquid_alpha_enabled(netuid, true); SubtensorModule::set_alpha_values_32(netuid, I32F32::from_num(0.9), I32F32::from_num(0.99)); @@ -3388,7 +3388,7 @@ fn test_yuma_4_kappa_moves_last() { 0 )); } - let target = vec![vec![65535, 0], vec![65535, 0], vec![65535, 0]]; + let target = vec![vec![656, 0], vec![656, 0], vec![656, 0]]; run_epoch_check_bonds(netuid, sparse, target); // Validator A -> Server 1 @@ -3406,7 +3406,7 @@ fn test_yuma_4_kappa_moves_last() { 0 )); } - let target = vec![vec![65535, 0], vec![220, 65535], vec![65535, 0]]; + let target = vec![vec![1305, 0], vec![649, 6553], vec![1305, 0]]; run_epoch_check_bonds(netuid, sparse, target); // Validator A -> Server 1 @@ -3424,7 +3424,7 @@ fn test_yuma_4_kappa_moves_last() { 0 )); } - let target = vec![vec![65535, 0], vec![1, 65535], vec![329, 64878]]; + let target = vec![vec![1947, 0], vec![642, 12451], vec![1291, 6553]]; run_epoch_check_bonds(netuid, sparse, target); // Subsequent epochs All validators -> Server 2 @@ -3437,7 +3437,7 @@ fn test_yuma_4_kappa_moves_last() { 0 )); } - let target = vec![vec![65535, 11866], vec![0, 65535], vec![328, 64996]]; + let target = vec![vec![1752, 656], vec![577, 12982], vec![1161, 7143]]; run_epoch_check_bonds(netuid, sparse, target); }) } From e95b412afd8fdab1c8386d0ad35694efc9184b5b Mon Sep 17 00:00:00 2001 From: Andreea Popescu Date: Thu, 6 Feb 2025 06:37:40 +0000 Subject: [PATCH 18/45] dividents fix --- pallets/subtensor/src/epoch/math.rs | 11 +++++++++++ pallets/subtensor/src/epoch/run_epoch.rs | 8 ++++---- pallets/subtensor/src/tests/epoch.rs | 16 +++++++++++----- pallets/subtensor/src/tests/math.rs | 20 ++++++++++++++++++++ 4 files changed, 46 insertions(+), 9 deletions(-) diff --git a/pallets/subtensor/src/epoch/math.rs b/pallets/subtensor/src/epoch/math.rs index f1a4b33c57..7bda9c5fd2 100644 --- a/pallets/subtensor/src/epoch/math.rs +++ b/pallets/subtensor/src/epoch/math.rs @@ -1226,6 +1226,17 @@ pub fn vec_mul(a: &[I32F32], b: &[I32F32]) -> Vec { .collect() } +// Element-wise product of matrix and vector +pub fn mat_vec_mul(matrix: &[Vec], vector: &[I32F32]) -> Vec> { + let Some(first_row) = matrix.first() else { + return vec![vec![]]; + }; + if first_row.is_empty() { + return vec![vec![]]; + } + matrix.iter().map(|row| vec_mul(row, vector)).collect() +} + // Element-wise product of two matrices. #[allow(dead_code)] pub fn hadamard(mat1: &[Vec], mat2: &[Vec]) -> Vec> { diff --git a/pallets/subtensor/src/epoch/run_epoch.rs b/pallets/subtensor/src/epoch/run_epoch.rs index dabec2351a..5fd18bea26 100644 --- a/pallets/subtensor/src/epoch/run_epoch.rs +++ b/pallets/subtensor/src/epoch/run_epoch.rs @@ -220,9 +220,9 @@ impl Pallet { log::trace!("emaB norm: {:?}", &ema_bonds_norm); // # === Dividend Calculation=== - let total_bonds_per_validator: Vec = matmul_transpose(&ema_bonds, &incentive); - let mut dividends: Vec = vec_mul(&total_bonds_per_validator, &active_stake); - inplace_normalize(&mut dividends); + let total_bonds_per_validator: Vec = + row_sum(&mat_vec_mul(&ema_bonds_norm, &incentive)); + let dividends: Vec = vec_mul(&total_bonds_per_validator, &active_stake); log::trace!("D: {:?}", ÷nds); // ================================= @@ -593,7 +593,7 @@ impl Pallet { // Compute the Exponential Moving Average (EMA) of bonds. let mut ema_bonds = - Self::compute_ema_bonds_sparse(&weights_for_bonds.clone(), &bonds, alpha); + Self::compute_ema_bonds_sparse(&weights_for_bonds.clone(), &bonds, alphas); // Normalize EMA bonds. inplace_col_normalize_sparse(&mut ema_bonds, n); // sum_i b_ij = 1 log::trace!("emaB norm: {:?}", &ema_bonds); diff --git a/pallets/subtensor/src/tests/epoch.rs b/pallets/subtensor/src/tests/epoch.rs index 8b547fb2a1..e3e9b1404d 100644 --- a/pallets/subtensor/src/tests/epoch.rs +++ b/pallets/subtensor/src/tests/epoch.rs @@ -3288,7 +3288,7 @@ fn assert_approx_eq_vec_of_vec( } // test Yuma 4 scenarios over a sequence of epochs. -fn setup_yuma_4_scenario(netuid: u16, n: u16, max_stake: u64, stakes: Vec) { +fn setup_yuma_4_scenario(netuid: u16, n: u16, sparse: bool, max_stake: u64, stakes: Vec) { let block_number = System::block_number(); let tempo: u16 = u16::MAX - 1; // high tempo to skip automatic epochs in on_initialize, use manual epochs instead add_network(netuid, tempo, 0); @@ -3339,17 +3339,23 @@ fn setup_yuma_4_scenario(netuid: u16, n: u16, max_stake: u64, stakes: Vec) // === Issue validator permits SubtensorModule::set_max_allowed_validators(netuid, 3); assert_eq!(SubtensorModule::get_max_allowed_validators(netuid), 3); - SubtensorModule::epoch(netuid, 1_000_000_000); // run first epoch to set allowed validators - next_block(); // run to next block to ensure weights are set on nodes after their registration block + + // run first epoch to set allowed validators + // run to next block to ensure weights are set on nodes after their registration block + run_epoch(netuid, sparse); } -fn run_epoch_check_bonds(netuid: u16, sparse: bool, target_bonds: Vec>) { +fn run_epoch(netuid: u16, sparse: bool) { next_block(); if sparse { SubtensorModule::epoch(netuid, 1_000_000_000); } else { SubtensorModule::epoch_dense(netuid, 1_000_000_000); } +} + +fn run_epoch_check_bonds(netuid: u16, sparse: bool, target_bonds: Vec>) { + run_epoch(netuid, sparse); let bonds = SubtensorModule::get_bonds(netuid); // server 1 @@ -3376,7 +3382,7 @@ fn test_yuma_4_kappa_moves_last() { // Validator C: Small lazy validator (0.1) - moves second let stakes: Vec = vec![8, 1, 1, 0, 0]; - setup_yuma_4_scenario(netuid, n, max_stake, stakes); + setup_yuma_4_scenario(netuid, n, sparse, max_stake, stakes); // Initially, consensus is achieved by all Validators for uid in [0, 1, 2] { diff --git a/pallets/subtensor/src/tests/math.rs b/pallets/subtensor/src/tests/math.rs index 16a73c5e37..1ab40869fe 100644 --- a/pallets/subtensor/src/tests/math.rs +++ b/pallets/subtensor/src/tests/math.rs @@ -1236,6 +1236,26 @@ fn test_math_vec_mul() { assert_vec_compare(&result, &target, I32F32::from_num(0)); } +#[test] +fn test_math_mat_vec_mul() { + let matrix: Vec = vec![1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12.]; + let matrix = vec_to_mat_fixed(&matrix, 4, false); + let vector: Vec = vec_to_fixed(&[1., 2., 3.]); + let target: Vec = vec![1., 4., 9., 4., 10., 18., 7., 16., 27., 10., 22., 36.]; + let target = vec_to_mat_fixed(&target, 4, false); + let result = mat_vec_mul(&matrix, &vector); + assert_mat_compare(&result, &target, I32F32::from_num(0)); + let vector_one: Vec = vec_to_fixed(&[1., 0., 0.]); + let target: Vec = vec![1., 0., 0., 4., 0., 0., 7., 0., 0., 10., 0., 0.]; + let target = vec_to_mat_fixed(&target, 4, false); + let result = mat_vec_mul(&matrix, &vector_one); + assert_mat_compare(&result, &target, I32F32::from_num(0)); + let vector_empty: Vec = vec_to_fixed(&[]); + let result = mat_vec_mul(&matrix, &vector_empty); + let target: Vec> = vec![vec![]; 4]; + assert_mat_compare(&result, &target, I32F32::from_num(0)); +} + #[test] fn test_math_row_hadamard() { let vector: Vec = vec_to_fixed(&[1., 2., 3., 4.]); From 388afa9236605788473d96406641eec4917dd17b Mon Sep 17 00:00:00 2001 From: Andreea Popescu Date: Fri, 7 Feb 2025 07:44:47 +0000 Subject: [PATCH 19/45] update sparse computations --- pallets/subtensor/src/epoch/math.rs | 53 +++++++++++------------- pallets/subtensor/src/epoch/run_epoch.rs | 32 +++++++++----- pallets/subtensor/src/tests/epoch.rs | 4 +- 3 files changed, 49 insertions(+), 40 deletions(-) diff --git a/pallets/subtensor/src/epoch/math.rs b/pallets/subtensor/src/epoch/math.rs index 7bda9c5fd2..e825f5af53 100644 --- a/pallets/subtensor/src/epoch/math.rs +++ b/pallets/subtensor/src/epoch/math.rs @@ -1237,6 +1237,21 @@ pub fn mat_vec_mul(matrix: &[Vec], vector: &[I32F32]) -> Vec matrix.iter().map(|row| vec_mul(row, vector)).collect() } +// Element-wise product of matrix and vector +pub fn mat_vec_mul_sparse( + matrix: &[Vec<(u16, I32F32)>], + vector: &[I32F32], +) -> Vec> { + let rows = matrix.len(); + let mut result: Vec> = vec![vec![]; rows]; + for i in 0..rows { + for (j, value) in matrix[i].iter() { + result[i].push((*j, value.saturating_mul(vector[*j as usize]))); + } + } + result +} + // Element-wise product of two matrices. #[allow(dead_code)] pub fn hadamard(mat1: &[Vec], mat2: &[Vec]) -> Vec> { @@ -1325,57 +1340,39 @@ pub fn mat_ema_alpha_vec_sparse( let mut row: Vec = vec![zero; n]; // Process the new matrix values. - for (j, value) in new_row.iter() { + for (j, new_val) in new_row.iter() { // Retrieve the alpha value for the current column. let alpha_val: I32F32 = alpha.get(*j as usize).copied().unwrap_or(zero); // Compute the EMA component for the new value using saturating multiplication. if let Some(row_val) = row.get_mut(*j as usize) { - *row_val = alpha_val.saturating_mul(*value); + // Each validator can increase bonds by at most clamped_alpha per epoch towards the cap + // Validators allocate their purchase across miners based on weights + *row_val = alpha_val.saturating_mul(*new_val); } - log::trace!( - "new[{}][{}] * alpha[{}] = {} * {} = {}", - i, - j, - j, - value, - alpha_val, - row.get(*j as usize).unwrap_or(&zero) - ); } // Process the old matrix values. - for (j, value) in old_row.iter() { + for (j, old_val) in old_row.iter() { // Retrieve the alpha value for the current column. let alpha_val: I32F32 = alpha.get(*j as usize).copied().unwrap_or(zero); // Calculate the complement of the alpha value using saturating subtraction. let one_minus_alpha: I32F32 = I32F32::saturating_from_num(1.0).saturating_sub(alpha_val); // Compute the EMA component for the old value and add it to the row using saturating operations. - if let Some(row_val) = row.get_mut(*j as usize) { - let decayed_val = one_minus_alpha.saturating_mul(*value); + if let Some(purchase_increment) = row.get_mut(*j as usize) { + // *row_val = row_val.saturating_add(one_minus_alpha.saturating_mul(*value)); + let decayed_val = one_minus_alpha.saturating_mul(*old_val); let remaining_capacity = I32F32::from_num(1.0) .saturating_sub(decayed_val) .max(I32F32::from_num(0.0)); - // Each validator can increase bonds by at most clamped_alpha per epoch towards the cap - // Validators allocate their purchase across miners based on weights - let purchase_increment = alpha_val.saturating_mul(*row_val); // Ensure that purchase does not exceed remaining capacity - let purchase = purchase_increment.min(remaining_capacity); + let purchase = purchase_increment.clone().min(remaining_capacity); - *row_val = decayed_val + *purchase_increment = decayed_val .saturating_add(purchase) .min(I32F32::from_num(1.0)); } - log::trace!( - "old[{}][{}] * (1 - alpha[{}]) = {} * {} = {}", - i, - j, - j, - value, - one_minus_alpha, - one_minus_alpha.saturating_mul(*value) - ); } // Collect the non-zero values into the result matrix. diff --git a/pallets/subtensor/src/epoch/run_epoch.rs b/pallets/subtensor/src/epoch/run_epoch.rs index 5fd18bea26..dceec0c06d 100644 --- a/pallets/subtensor/src/epoch/run_epoch.rs +++ b/pallets/subtensor/src/epoch/run_epoch.rs @@ -584,23 +584,37 @@ impl Pallet { ); log::trace!("B (outdatedmask): {:?}", &bonds); - // Normalize remaining bonds: sum_i b_ij = 1. - inplace_col_normalize_sparse(&mut bonds, n); - log::trace!("B (mask+norm): {:?}", &bonds); + let mut result: Vec> = vec![vec![]; bonds.len()]; + for (i, sparse_row) in bonds.iter().enumerate() { + for (j, value) in sparse_row { + result[i].push((*j, fixed_proportion_to_fixed(*value))); + } + } + let bonds = result; + log::trace!("B: (mask+norm) {:?}", &bonds); // Get alpha values let alphas = Self::compute_liquid_alpha(netuid, consensus.clone()); + log::trace!("alphas: {:?}", &alphas); // Compute the Exponential Moving Average (EMA) of bonds. - let mut ema_bonds = - Self::compute_ema_bonds_sparse(&weights_for_bonds.clone(), &bonds, alphas); + log::trace!("weights_for_bonds: {:?}", &weights_for_bonds); + let ema_bonds = Self::compute_ema_bonds_sparse(&weights_for_bonds.clone(), &bonds, alphas); + log::trace!("emaB: {:?}", &ema_bonds); + // Normalize EMA bonds. - inplace_col_normalize_sparse(&mut ema_bonds, n); // sum_i b_ij = 1 - log::trace!("emaB norm: {:?}", &ema_bonds); + let mut ema_bonds_norm = ema_bonds.clone(); + inplace_col_normalize_sparse(&mut ema_bonds_norm, n); // sum_i b_ij = 1 + log::trace!("emaB norm: {:?}", &ema_bonds_norm); // # === Dividend Calculation=== let total_bonds_per_validator: Vec = - matmul_transpose_sparse(&ema_bonds, &incentive); + row_sum_sparse(&mat_vec_mul_sparse(&ema_bonds_norm, &incentive)); + log::trace!( + "total_bonds_per_validator: {:?}", + &total_bonds_per_validator + ); + let mut dividends: Vec = vec_mul(&total_bonds_per_validator, &active_stake); inplace_normalize(&mut dividends); log::trace!("Dividends: {:?}", ÷nds); @@ -734,8 +748,6 @@ impl Pallet { ValidatorTrust::::insert(netuid, cloned_validator_trust); ValidatorPermit::::insert(netuid, new_validator_permits.clone()); - // Column max-upscale EMA bonds for storage: max_i w_ij = 1. - inplace_col_max_upscale_sparse(&mut ema_bonds, n); new_validator_permits .iter() .zip(validator_permits) diff --git a/pallets/subtensor/src/tests/epoch.rs b/pallets/subtensor/src/tests/epoch.rs index e3e9b1404d..e4fb8f7aa0 100644 --- a/pallets/subtensor/src/tests/epoch.rs +++ b/pallets/subtensor/src/tests/epoch.rs @@ -2826,7 +2826,7 @@ fn test_compute_ema_bonds_sparse() { ]; // Call the function - let ema_bonds = SubtensorModule::compute_ema_bonds_sparse(&bonds_delta, &bonds, alpha); + let ema_bonds = SubtensorModule::compute_ema_bonds_sparse(&weights, &bonds, alpha); // Assert the results with an epsilon for approximate equality let epsilon = I32F32::from_num(1e-6); @@ -2845,7 +2845,7 @@ fn test_compute_ema_bonds_sparse_empty() { let expected_ema_bonds: Vec> = vec![]; // Call the function - let ema_bonds = SubtensorModule::compute_ema_bonds_sparse(&bonds_delta, &bonds, alpha); + let ema_bonds = SubtensorModule::compute_ema_bonds_sparse(&weights, &bonds, alpha); // Assert the results assert_eq!( From 8cf307bdcdb956ea38160418e9adc22fbf2a45d6 Mon Sep 17 00:00:00 2001 From: Andreea Popescu Date: Fri, 7 Feb 2025 10:01:20 +0000 Subject: [PATCH 20/45] add yuma4 kappa moves tests --- pallets/subtensor/src/tests/epoch.rs | 372 ++++++++++++++++++++++----- 1 file changed, 310 insertions(+), 62 deletions(-) diff --git a/pallets/subtensor/src/tests/epoch.rs b/pallets/subtensor/src/tests/epoch.rs index e4fb8f7aa0..7f6e57f941 100644 --- a/pallets/subtensor/src/tests/epoch.rs +++ b/pallets/subtensor/src/tests/epoch.rs @@ -3354,7 +3354,7 @@ fn run_epoch(netuid: u16, sparse: bool) { } } -fn run_epoch_check_bonds(netuid: u16, sparse: bool, target_bonds: Vec>) { +fn run_epoch_check_bonds(netuid: u16, sparse: bool, target_bonds: &Vec>) { run_epoch(netuid, sparse); let bonds = SubtensorModule::get_bonds(netuid); @@ -3370,80 +3370,328 @@ fn run_epoch_check_bonds(netuid: u16, sparse: bool, target_bonds: Vec>) } #[test] -fn test_yuma_4_kappa_moves_last() { +fn test_yuma_4_kappa_moves_first() { new_test_ext(1).execute_with(|| { - let sparse: bool = false; + let sparse: bool = true; let n: u16 = 5; // 3 validators, 2 servers let netuid: u16 = 1; let max_stake: u64 = 8; - // Validator A: kappa / Big validator (0.8) - moves last - // Validator B: Small eager validator (0.1) - moves first - // Validator C: Small lazy validator (0.1) - moves second + // Validator A: kappa / Big validator (0.8) - moves first + // Validator B: Small eager validator (0.1) - moves second + // Validator C: Small lazy validator (0.1) - moves last let stakes: Vec = vec![8, 1, 1, 0, 0]; setup_yuma_4_scenario(netuid, n, sparse, max_stake, stakes); - - // Initially, consensus is achieved by all Validators - for uid in [0, 1, 2] { - assert_ok!(SubtensorModule::set_weights( - RuntimeOrigin::signed(U256::from(uid)), - netuid, - vec![3, 4], - vec![u16::MAX, 0], - 0 - )); + let targets_bonds = vec![ + vec![ + vec![656, 0], + vec![656, 0], + vec![656, 0], + vec![0, 0], + vec![0, 0], + ], + vec![ + vec![590, 656], + vec![7144, 0], + vec![7144, 0], + vec![0, 0], + vec![0, 0], + ], + vec![ + vec![530, 1305], + vec![6429, 656], + vec![12983, 0], + vec![0, 0], + vec![0, 0], + ], + vec![ + vec![476, 1947], + vec![5786, 1305], + vec![11684, 656], + vec![0, 0], + vec![0, 0], + ], + vec![ + vec![428, 2583], + vec![5207, 1947], + vec![10515, 1305], + vec![0, 0], + vec![0, 0], + ], + ]; + + for epoch in 0..5 { + match epoch { + 0 => { + // Initially, consensus is achieved by all Validators + for uid in [0, 1, 2] { + assert_ok!(SubtensorModule::set_weights( + RuntimeOrigin::signed(U256::from(uid)), + netuid, + vec![3, 4], + vec![u16::MAX, 0], + 0 + )); + } + } + 1 => { + // Validator A -> Server 2 + // Validator B -> Server 1 + // Validator C -> Server 1 + for (uid, weights) in [vec![0, u16::MAX], vec![u16::MAX, 0], vec![u16::MAX, 0]] + .iter() + .enumerate() + { + assert_ok!(SubtensorModule::set_weights( + RuntimeOrigin::signed(U256::from(uid)), + netuid, + vec![3, 4], + weights.to_vec(), + 0 + )); + } + } + 2 => { + // Validator A -> Server 2 + // Validator B -> Server 2 + // Validator C -> Server 1 + for (uid, weights) in [vec![0, u16::MAX], vec![0, u16::MAX], vec![u16::MAX, 0]] + .iter() + .enumerate() + { + assert_ok!(SubtensorModule::set_weights( + RuntimeOrigin::signed(U256::from(uid)), + netuid, + vec![3, 4], + weights.to_vec(), + 0 + )); + } + } + 3 => { + // Subsequent epochs All validators -> Server 2 + for uid in [0, 1, 2] { + assert_ok!(SubtensorModule::set_weights( + RuntimeOrigin::signed(U256::from(uid)), + netuid, + vec![3, 4], + vec![0, u16::MAX], + 0 + )); + } + } + _ => {} + }; + run_epoch_check_bonds(netuid, sparse, &targets_bonds[epoch]); } - let target = vec![vec![656, 0], vec![656, 0], vec![656, 0]]; - run_epoch_check_bonds(netuid, sparse, target); + }) +} - // Validator A -> Server 1 - // Validator B -> Server 2 - // Validator C -> Server 1 - for (uid, weights) in [vec![u16::MAX, 0], vec![0, u16::MAX], vec![u16::MAX, 0]] - .iter() - .enumerate() - { - assert_ok!(SubtensorModule::set_weights( - RuntimeOrigin::signed(U256::from(uid)), - netuid, - vec![3, 4], - weights.to_vec(), - 0 - )); - } - let target = vec![vec![1305, 0], vec![649, 6553], vec![1305, 0]]; - run_epoch_check_bonds(netuid, sparse, target); +#[test] +fn test_yuma_4_kappa_moves_second() { + new_test_ext(1).execute_with(|| { + let sparse: bool = true; + let n: u16 = 5; // 3 validators, 2 servers + let netuid: u16 = 1; + let max_stake: u64 = 8; - // Validator A -> Server 1 - // Validator B -> Server 2 - // Validator C -> Server 2 - for (uid, weights) in [vec![u16::MAX, 0], vec![0, u16::MAX], vec![0, u16::MAX]] - .iter() - .enumerate() - { - assert_ok!(SubtensorModule::set_weights( - RuntimeOrigin::signed(U256::from(uid)), - netuid, - vec![3, 4], - weights.to_vec(), - 0 - )); + // Validator A: kappa / Big validator (0.8) - moves second + // Validator B: Small eager validator (0.1) - moves first + // Validator C: Small lazy validator (0.1) - moves last + let stakes: Vec = vec![8, 1, 1, 0, 0]; + + setup_yuma_4_scenario(netuid, n, sparse, max_stake, stakes); + let targets_bonds = vec![ + vec![ + vec![656, 0], + vec![656, 0], + vec![656, 0], + vec![0, 0], + vec![0, 0], + ], + vec![ + vec![1305, 0], + vec![649, 6553], + vec![1305, 0], + vec![0, 0], + vec![0, 0], + ], + vec![ + vec![1174, 656], + vec![584, 7143], + vec![7728, 0], + vec![0, 0], + vec![0, 0], + ], + vec![ + vec![1056, 1305], + vec![525, 7727], + vec![6955, 656], + vec![0, 0], + vec![0, 0], + ], + vec![ + vec![950, 1947], + vec![472, 8305], + vec![6259, 1305], + vec![0, 0], + vec![0, 0], + ], + ]; + + for epoch in 0..5 { + match epoch { + 0 => { + // Initially, consensus is achieved by all Validators + for uid in [0, 1, 2] { + assert_ok!(SubtensorModule::set_weights( + RuntimeOrigin::signed(U256::from(uid)), + netuid, + vec![3, 4], + vec![u16::MAX, 0], + 0 + )); + } + } + 1 => { + // Validator A -> Server 1 + // Validator B -> Server 2 + // Validator C -> Server 1 + for (uid, weights) in [vec![u16::MAX, 0], vec![0, u16::MAX], vec![u16::MAX, 0]] + .iter() + .enumerate() + { + assert_ok!(SubtensorModule::set_weights( + RuntimeOrigin::signed(U256::from(uid)), + netuid, + vec![3, 4], + weights.to_vec(), + 0 + )); + } + } + 2 => { + // Validator A -> Server 2 + // Validator B -> Server 2 + // Validator C -> Server 1 + for (uid, weights) in [vec![0, u16::MAX], vec![0, u16::MAX], vec![u16::MAX, 0]] + .iter() + .enumerate() + { + assert_ok!(SubtensorModule::set_weights( + RuntimeOrigin::signed(U256::from(uid)), + netuid, + vec![3, 4], + weights.to_vec(), + 0 + )); + } + } + 3 => { + // Subsequent epochs All validators -> Server 2 + for uid in [0, 1, 2] { + assert_ok!(SubtensorModule::set_weights( + RuntimeOrigin::signed(U256::from(uid)), + netuid, + vec![3, 4], + vec![0, u16::MAX], + 0 + )); + } + } + _ => {} + }; + run_epoch_check_bonds(netuid, sparse, &targets_bonds[epoch]); } - let target = vec![vec![1947, 0], vec![642, 12451], vec![1291, 6553]]; - run_epoch_check_bonds(netuid, sparse, target); + }) +} - // Subsequent epochs All validators -> Server 2 - for uid in [0, 1, 2] { - assert_ok!(SubtensorModule::set_weights( - RuntimeOrigin::signed(U256::from(uid)), - netuid, - vec![3, 4], - vec![0, u16::MAX], - 0 - )); +#[test] +fn test_yuma_4_kappa_moves_last() { + new_test_ext(1).execute_with(|| { + let sparse: bool = true; + let n: u16 = 5; // 3 validators, 2 servers + let netuid: u16 = 1; + let max_stake: u64 = 8; + + // Validator A: kappa / Big validator (0.8) - moves last + // Validator B: Small eager validator (0.1) - moves first + // Validator C: Small lazy validator (0.1) - moves second + let stakes: Vec = vec![8, 1, 1, 0, 0]; + + setup_yuma_4_scenario(netuid, n, sparse, max_stake, stakes); + let targets_bonds = vec![ + vec![vec![656, 0], vec![656, 0], vec![656, 0]], + vec![vec![1305, 0], vec![649, 6553], vec![1305, 0]], + vec![vec![1947, 0], vec![642, 12451], vec![1291, 6553]], + vec![vec![1752, 656], vec![577, 12982], vec![1161, 7143]], + vec![vec![1576, 1305], vec![519, 13508], vec![1044, 7727]], + ]; + + for epoch in 0..5 { + match epoch { + 0 => { + // Initially, consensus is achieved by all Validators + for uid in [0, 1, 2] { + assert_ok!(SubtensorModule::set_weights( + RuntimeOrigin::signed(U256::from(uid)), + netuid, + vec![3, 4], + vec![u16::MAX, 0], + 0 + )); + } + } + 1 => { + // Validator A -> Server 1 + // Validator B -> Server 2 + // Validator C -> Server 1 + for (uid, weights) in [vec![u16::MAX, 0], vec![0, u16::MAX], vec![u16::MAX, 0]] + .iter() + .enumerate() + { + assert_ok!(SubtensorModule::set_weights( + RuntimeOrigin::signed(U256::from(uid)), + netuid, + vec![3, 4], + weights.to_vec(), + 0 + )); + } + } + 2 => { + // Validator A -> Server 1 + // Validator B -> Server 2 + // Validator C -> Server 2 + for (uid, weights) in [vec![u16::MAX, 0], vec![0, u16::MAX], vec![0, u16::MAX]] + .iter() + .enumerate() + { + assert_ok!(SubtensorModule::set_weights( + RuntimeOrigin::signed(U256::from(uid)), + netuid, + vec![3, 4], + weights.to_vec(), + 0 + )); + } + } + 3 => { + // Subsequent epochs All validators -> Server 2 + for uid in [0, 1, 2] { + assert_ok!(SubtensorModule::set_weights( + RuntimeOrigin::signed(U256::from(uid)), + netuid, + vec![3, 4], + vec![0, u16::MAX], + 0 + )); + } + } + _ => {} + }; + run_epoch_check_bonds(netuid, sparse, &targets_bonds[epoch]); } - let target = vec![vec![1752, 656], vec![577, 12982], vec![1161, 7143]]; - run_epoch_check_bonds(netuid, sparse, target); }) } From d1a9d3335d58a0b67ecb8e34f69d8b91ec12a447 Mon Sep 17 00:00:00 2001 From: Andreea Popescu Date: Tue, 11 Feb 2025 12:03:40 +0000 Subject: [PATCH 21/45] tests cleanup --- pallets/subtensor/src/epoch/math.rs | 17 +- pallets/subtensor/src/epoch/run_epoch.rs | 18 +- pallets/subtensor/src/tests/epoch.rs | 956 ++++++++++++----------- pallets/subtensor/src/tests/math.rs | 63 +- 4 files changed, 569 insertions(+), 485 deletions(-) diff --git a/pallets/subtensor/src/epoch/math.rs b/pallets/subtensor/src/epoch/math.rs index e825f5af53..0b5c509512 100644 --- a/pallets/subtensor/src/epoch/math.rs +++ b/pallets/subtensor/src/epoch/math.rs @@ -1238,15 +1238,20 @@ pub fn mat_vec_mul(matrix: &[Vec], vector: &[I32F32]) -> Vec } // Element-wise product of matrix and vector +#[allow(dead_code, clippy::indexing_slicing)] pub fn mat_vec_mul_sparse( matrix: &[Vec<(u16, I32F32)>], vector: &[I32F32], ) -> Vec> { - let rows = matrix.len(); - let mut result: Vec> = vec![vec![]; rows]; - for i in 0..rows { - for (j, value) in matrix[i].iter() { - result[i].push((*j, value.saturating_mul(vector[*j as usize]))); + let mut result: Vec> = vec![vec![]; matrix.len()]; + for (i, matrix_row) in matrix.iter().enumerate() { + for (j, value) in matrix_row.iter() { + if let Some(vector_value) = vector.get(*j as usize) { + let new_value = value.saturating_mul(*vector_value); + if new_value != I32F32::saturating_from_num(0.0) { + result[i].push((*j, new_value)); + } + } } } result @@ -1367,7 +1372,7 @@ pub fn mat_ema_alpha_vec_sparse( .max(I32F32::from_num(0.0)); // Ensure that purchase does not exceed remaining capacity - let purchase = purchase_increment.clone().min(remaining_capacity); + let purchase = (*purchase_increment).min(remaining_capacity); *purchase_increment = decayed_val .saturating_add(purchase) diff --git a/pallets/subtensor/src/epoch/run_epoch.rs b/pallets/subtensor/src/epoch/run_epoch.rs index dceec0c06d..5cb399039f 100644 --- a/pallets/subtensor/src/epoch/run_epoch.rs +++ b/pallets/subtensor/src/epoch/run_epoch.rs @@ -222,7 +222,13 @@ impl Pallet { // # === Dividend Calculation=== let total_bonds_per_validator: Vec = row_sum(&mat_vec_mul(&ema_bonds_norm, &incentive)); - let dividends: Vec = vec_mul(&total_bonds_per_validator, &active_stake); + log::trace!( + "total_bonds_per_validator: {:?}", + &total_bonds_per_validator + ); + + let mut dividends: Vec = vec_mul(&total_bonds_per_validator, &active_stake); + inplace_normalize(&mut dividends); log::trace!("D: {:?}", ÷nds); // ================================= @@ -550,7 +556,7 @@ impl Pallet { // Compute server trust: ratio of rank after vs. rank before. let trust: Vec = vecdiv(&ranks, &preranks); // range: I32F32(0, 1) - log::trace!("T: {:?}", &trust); + log::trace!("Trust: {:?}", &trust); inplace_normalize(&mut ranks); // range: I32F32(0, 1) let incentive: Vec = ranks.clone(); @@ -570,7 +576,7 @@ impl Pallet { // Access network bonds. let mut bonds: Vec> = Self::get_bonds_sparse(netuid); - log::trace!("B: {:?}", &bonds); + log::trace!("Bonds: {:?}", &bonds); // Remove bonds referring to neurons that have registered since last tempo. // Mask if: the last tempo block happened *before* the registration block @@ -582,7 +588,7 @@ impl Pallet { &block_at_registration, &|last_tempo, registered| last_tempo <= registered, ); - log::trace!("B (outdatedmask): {:?}", &bonds); + log::trace!("Bonds (outdatedmask): {:?}", &bonds); let mut result: Vec> = vec![vec![]; bonds.len()]; for (i, sparse_row) in bonds.iter().enumerate() { @@ -591,11 +597,11 @@ impl Pallet { } } let bonds = result; - log::trace!("B: (mask+norm) {:?}", &bonds); + log::trace!("Bonds: (mask+norm) {:?}", &bonds); // Get alpha values let alphas = Self::compute_liquid_alpha(netuid, consensus.clone()); - log::trace!("alphas: {:?}", &alphas); + log::trace!("Alphas: {:?}", &alphas); // Compute the Exponential Moving Average (EMA) of bonds. log::trace!("weights_for_bonds: {:?}", &weights_for_bonds); diff --git a/pallets/subtensor/src/tests/epoch.rs b/pallets/subtensor/src/tests/epoch.rs index 7f6e57f941..d2a7645b86 100644 --- a/pallets/subtensor/src/tests/epoch.rs +++ b/pallets/subtensor/src/tests/epoch.rs @@ -5,7 +5,7 @@ )] use super::mock::*; -use crate::epoch::math::safe_exp; +use crate::epoch::math::{fixed, safe_exp, u16_proportion_to_fixed}; use crate::*; use approx::assert_abs_diff_eq; @@ -714,8 +714,7 @@ fn test_512_graph() { assert_eq!(SubtensorModule::get_dividends_for_uid(netuid, uid), 1023); // Note D = floor(1 / 64 * 65_535) = 1023 assert_eq!(SubtensorModule::get_emission_for_uid(netuid, uid), 7812500); // Note E = 0.5 / 200 * 1_000_000_000 = 7_812_500 assert_eq!(bonds[uid as usize][validator], 0.0); - assert_eq!(bonds[uid as usize][server], I32F32::from_num(65_535)); - // Note B_ij = floor(1 / 64 * 65_535) / 65_535 = 1023 / 65_535, then max-upscaled to 65_535 + assert_eq!(bonds[uid as usize][server], I32F32::from_num(38)); } for uid in servers { assert_eq!( @@ -1054,48 +1053,42 @@ fn test_bonds() { SubtensorModule::epoch_dense(netuid, 1_000_000_000); } /* n: 8 - current_block: 2 - activity_cutoff: 5000 - Last update: [2, 2, 2, 2, 1, 1, 1, 1] + current_block: 2, activity_cutoff: 5000, Last update: [2, 2, 2, 2, 1, 1, 1, 1] Inactive: [false, false, false, false, false, false, false, false] Block at registration: [1, 1, 1, 1, 1, 1, 1, 1] hotkeys: [(0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7)] - Normalised Stake: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] + S: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] validator_permits: [true, true, true, true, true, true, true, true] max_allowed_validators: 8 new_validator_permits: [true, true, true, true, true, true, true, true] - Active Stake: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] + S: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] W: [[(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] W (permit): [[(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] W (permit+diag): [[(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] W (permit+diag+outdate): [[(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - Weights (mask+norm): [[(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] - R (before): [0, 0, 0, 0, 0.099997558, 0.2000012202, 0.2999926745, 0.4000085443] C: [0, 0, 0, 0, 0.0999975584, 0.2000012207, 0.2999926754, 0.400008545] - Clipped Weights: [[(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] - Validator Trust: [0.9999999995, 0.9999999995, 0.9999999995, 0.9999999995, 0, 0, 0, 0] + W: [[(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] + Tv: [0.9999999995, 0.9999999995, 0.9999999995, 0.9999999995, 0, 0, 0, 0] R (after): [0, 0, 0, 0, 0.099997558, 0.2000012202, 0.2999926745, 0.4000085443] T: [0, 0, 0, 0, 1, 1, 1, 1] I (=R): [0, 0, 0, 0, 0.0999975582, 0.2000012207, 0.2999926752, 0.4000085455] B: [[], [], [], [], [], [], [], []] B (outdatedmask): [[], [], [], [], [], [], [], []] - B (mask+norm): [[], [], [], [], [], [], [], []] - alpha values: [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1] - Exponential Moving Average Bonds: [[(4, 0.25), (5, 0.25), (6, 0.25), (7, 0.25)], [(4, 0.25), (5, 0.25), (6, 0.25), (7, 0.25)], [(4, 0.25), (5, 0.25), (6, 0.25), (7, 0.25)], [(4, 0.25), (5, 0.25), (6, 0.25), (7, 0.25)], [], [], [], []] - Dividends: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] - Normalized Server Emission: [0, 0, 0, 0, 0.049998779, 0.1000006103, 0.1499963375, 0.2000042726] - Server Emission: [0, 0, 0, 0, 49998779, 100000610, 149996337, 200004272] - Normalized Validator Emission: [0.0499999998, 0.0999999999, 0.15, 0.2, 0, 0, 0, 0] - Validator Emission: [49999999, 99999999, 149999999, 199999999, 0, 0, 0, 0] - Normalized Combined Emission: [0.0499999998, 0.0999999999, 0.15, 0.2, 0.049998779, 0.1000006103, 0.1499963375, 0.2000042726] - Combined Emission: [49999999, 99999999, 149999999, 199999999, 49998779, 100000610, 149996337, 200004272] - Pruning Scores: [0.0499999998, 0.0999999999, 0.15, 0.2, 0.049998779, 0.1000006103, 0.1499963375, 0.2000042726] + B: [[], [], [], [], [], [], [], []] + alphas: [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1] + emaB: [[(4, 0.0099997558), (5, 0.020000122), (6, 0.0299992675), (7, 0.0400008545)], [(4, 0.0099997558), (5, 0.020000122), (6, 0.0299992675), (7, 0.0400008545)], [(4, 0.0099997558), (5, 0.020000122), (6, 0.0299992675), (7, 0.0400008545)], [(4, 0.0099997558), (5, 0.020000122), (6, 0.0299992675), (7, 0.0400008545)], [], [], [], []] + emaB norm: [[(4, 0.25), (5, 0.25), (6, 0.25), (7, 0.25)], [(4, 0.25), (5, 0.25), (6, 0.25), (7, 0.25)], [(4, 0.25), (5, 0.25), (6, 0.25), (7, 0.25)], [(4, 0.25), (5, 0.25), (6, 0.25), (7, 0.25)], [], [], [], []] + total_bonds_per_validator: [0.2499999995, 0.2499999995, 0.2499999995, 0.2499999995, 0, 0, 0, 0] + D: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] + nE: [0.0499999998, 0.0999999999, 0.15, 0.2, 0.049998779, 0.1000006103, 0.1499963375, 0.2000042726] + E: [49999999, 99999999, 149999999, 199999999, 49998779, 100000610, 149996337, 200004272] + P: [0.0499999998, 0.0999999999, 0.15, 0.2, 0.049998779, 0.1000006103, 0.1499963375, 0.2000042726] */ let bonds = SubtensorModule::get_bonds(netuid); - assert_eq!(bonds[0][4], 65535); - assert_eq!(bonds[1][4], 65535); - assert_eq!(bonds[2][4], 65535); - assert_eq!(bonds[3][4], 65535); + assert_eq!(bonds[0][4], 655); + assert_eq!(bonds[1][4], 655); + assert_eq!(bonds[2][4], 655); + assert_eq!(bonds[3][4], 655); // === Set self-weight only on val1 let uid = 0; @@ -1113,49 +1106,41 @@ fn test_bonds() { SubtensorModule::epoch_dense(netuid, 1_000_000_000); } /* n: 8 - current_block: 2 - activity_cutoff: 5000 - Last update: [2, 2, 2, 2, 1, 1, 1, 1] + current_block: 3, activity_cutoff: 5000, Last update: [2, 2, 2, 2, 1, 1, 1, 1] Inactive: [false, false, false, false, false, false, false, false] Block at registration: [1, 1, 1, 1, 1, 1, 1, 1] hotkeys: [(0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7)] - Normalised Stake: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] + S: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] validator_permits: [true, true, true, true, true, true, true, true] max_allowed_validators: 8 new_validator_permits: [true, true, true, true, true, true, true, true] - Active Stake: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] + S: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] W: [[(0, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] W (permit): [[(0, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] W (permit+diag): [[], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] W (permit+diag+outdate): [[], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - W (mask+norm): [[], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] - R (before): [0, 0, 0, 0, 0.0899978022, 0.1800010982, 0.2699934072, 0.36000769] C: [0, 0, 0, 0, 0.0999975584, 0.2000012207, 0.2999926754, 0.400008545] - Clipped Weights: [[], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] - Validator Trust: [0, 0.9999999995, 0.9999999995, 0.9999999995, 0, 0, 0, 0] + W: [[], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] + Tv: [0, 0.9999999995, 0.9999999995, 0.9999999995, 0, 0, 0, 0] R (after): [0, 0, 0, 0, 0.0899978022, 0.1800010982, 0.2699934072, 0.36000769] T: [0, 0, 0, 0, 1, 1, 1, 1] I (=R): [0, 0, 0, 0, 0.0999975582, 0.2000012207, 0.2999926754, 0.4000085455] - B: [[(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [], [], [], []] - B (outdatedmask): [[(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [], [], [], []] - B (mask+norm): [[(4, 0.25), (5, 0.25), (6, 0.25), (7, 0.25)], [(4, 0.25), (5, 0.25), (6, 0.25), (7, 0.25)], [(4, 0.25), (5, 0.25), (6, 0.25), (7, 0.25)], [(4, 0.25), (5, 0.25), (6, 0.25), (7, 0.25)], [], [], [], []] - alpha values: [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1] - Exponential Moving Average Bonds: [[(4, 0.2491694554), (5, 0.2483443606), (6, 0.2475248124), (7, 0.246710457)], [(4, 0.250276848), (5, 0.2505518796), (6, 0.2508250624), (7, 0.2510965143)], [(4, 0.250276848), (5, 0.2505518796), (6, 0.2508250624), (7, 0.2510965143)], [(4, 0.250276848), (5, 0.2505518796), (6, 0.2508250624), (7, 0.2510965143)], [], [], [], []] - Dividends: [0.0988155114, 0.2002632194, 0.3003948291, 0.4005264398, 0, 0, 0, 0] - Normalized Server Emission: [0, 0, 0, 0, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] - Server Emission: [0, 0, 0, 0, 49998779, 100000610, 149996337, 200004272] - Normalized Validator Emission: [0.0494077557, 0.1001316097, 0.1501974144, 0.20026322, 0, 0, 0, 0] - Validator Emission: [49407755, 100131609, 150197414, 200263219, 0, 0, 0, 0] - Normalized Combined Emission: [0.0494077557, 0.1001316097, 0.1501974144, 0.20026322, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] - Combined Emission: [49407755, 100131609, 150197414, 200263219, 49998779, 100000610, 149996337, 200004272] - Pruning Scores: [0.0494077557, 0.1001316097, 0.1501974144, 0.20026322, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] + B: [[(4, 655), (5, 1310), (6, 1966), (7, 2621)], [(4, 655), (5, 1310), (6, 1966), (7, 2621)], [(4, 655), (5, 1310), (6, 1966), (7, 2621)], [(4, 655), (5, 1310), (6, 1966), (7, 2621)], [], [], [], []] + B (outdatedmask): [[(4, 655), (5, 1310), (6, 1966), (7, 2621)], [(4, 655), (5, 1310), (6, 1966), (7, 2621)], [(4, 655), (5, 1310), (6, 1966), (7, 2621)], [(4, 655), (5, 1310), (6, 1966), (7, 2621)], [], [], [], []] + B: [[(4, 0.0099946593), (5, 0.0199893187), (6, 0.029999237), (7, 0.0399938964)], [(4, 0.0099946593), (5, 0.0199893187), (6, 0.029999237), (7, 0.0399938964)], [(4, 0.0099946593), (5, 0.0199893187), (6, 0.029999237), (7, 0.0399938964)], [(4, 0.0099946593), (5, 0.0199893187), (6, 0.029999237), (7, 0.0399938964)], [], [], [], []] + alphas: [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1] + emaB: [[(4, 0.0089951933), (5, 0.0179903866), (6, 0.0269993132), (7, 0.0359945067)], [(4, 0.018994949), (5, 0.0379905086), (6, 0.0569985807), (7, 0.0759953612)], [(4, 0.018994949), (5, 0.0379905086), (6, 0.0569985807), (7, 0.0759953612)], [(4, 0.018994949), (5, 0.0379905086), (6, 0.0569985807), (7, 0.0759953612)], [], [], [], []] + emaB norm: [[(4, 0.1363320365), (5, 0.1363301442), (6, 0.136363573), (7, 0.1363528532)], [(4, 0.287889321), (5, 0.2878899518), (6, 0.2878788088), (7, 0.287882382)], [(4, 0.287889321), (5, 0.2878899518), (6, 0.2878788088), (7, 0.287882382)], [(4, 0.287889321), (5, 0.2878899518), (6, 0.2878788088), (7, 0.287882382)], [], [], [], []] + total_bonds_per_validator: [0.136349445, 0.2878835173, 0.2878835173, 0.2878835173, 0, 0, 0, 0] + D: [0.0499942757, 0.211112383, 0.3166685747, 0.422224766, 0, 0, 0, 0] + nE: [0.0249971377, 0.1055561914, 0.1583342873, 0.211112383, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] + E: [24997137, 105556191, 158334287, 211112383, 49998779, 100000610, 149996337, 200004272] + P: [0.0249971377, 0.1055561914, 0.1583342873, 0.211112383, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] */ - - let bonds = SubtensorModule::get_bonds(netuid); - assert_eq!(bonds[0][4], 65245); - assert_eq!(bonds[1][4], 65535); - assert_eq!(bonds[2][4], 65535); - assert_eq!(bonds[3][4], 65535); + assert_eq!(bonds[0][4], 655); + assert_eq!(bonds[1][4], 655); + assert_eq!(bonds[2][4], 655); + assert_eq!(bonds[3][4], 655); // === Set self-weight only on val2 let uid = 1; @@ -1173,41 +1158,45 @@ fn test_bonds() { SubtensorModule::epoch_dense(netuid, 1_000_000_000); } /* current_block: 3 - W: [[(0, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - W (permit): [[(0, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - W (permit+diag): [[], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - W (permit+diag+outdate): [[], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - W (mask+norm): [[], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] - R (before): [0, 0, 0, 0, 0.0899978022, 0.1800010982, 0.2699934072, 0.36000769] + current_block: 4, activity_cutoff: 5000, Last update: [2, 3, 2, 2, 1, 1, 1, 1] + Inactive: [false, false, false, false, false, false, false, false] + Block at registration: [1, 1, 1, 1, 1, 1, 1, 1] + hotkeys: [(0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7)] + S: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] + validator_permits: [true, true, true, true, true, true, true, true] + max_allowed_validators: 8 + new_validator_permits: [true, true, true, true, true, true, true, true] + S: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] + W: [[(0, 65535)], [(1, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + W (permit): [[(0, 65535)], [(1, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + W (permit+diag): [[], [], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + W (permit+diag+outdate): [[], [], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] C: [0, 0, 0, 0, 0.0999975584, 0.2000012207, 0.2999926754, 0.400008545] - Clipped Weights: [[], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] - Validator Trust: [0, 0.9999999995, 0.9999999995, 0.9999999995, 0, 0, 0, 0] - R (after): [0, 0, 0, 0, 0.0899978022, 0.1800010982, 0.2699934072, 0.36000769] + W: [[], [], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] + Tv: [0, 0, 0.9999999995, 0.9999999995, 0, 0, 0, 0] + R (after): [0, 0, 0, 0, 0.0699982906, 0.1400008542, 0.2099948723, 0.2800059812] T: [0, 0, 0, 0, 1, 1, 1, 1] I (=R): [0, 0, 0, 0, 0.0999975582, 0.2000012207, 0.2999926754, 0.4000085455] - B: [[(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [], [], [], []] - B (outdatedmask): [[(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [], [], [], []] - B (mask+norm): [[(4, 0.25), (5, 0.25), (6, 0.25), (7, 0.25)], [(4, 0.25), (5, 0.25), (6, 0.25), (7, 0.25)], [(4, 0.25), (5, 0.25), (6, 0.25), (7, 0.25)], [(4, 0.25), (5, 0.25), (6, 0.25), (7, 0.25)], [], [], [], []] - alpha values: [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1] - Exponential Moving Average Bonds: [[(4, 0.2491694554), (5, 0.2483443606), (6, 0.2475248124), (7, 0.246710457)], [(4, 0.250276848), (5, 0.2505518796), (6, 0.2508250624), (7, 0.2510965143)], [(4, 0.250276848), (5, 0.2505518796), (6, 0.2508250624), (7, 0.2510965143)], [(4, 0.250276848), (5, 0.2505518796), (6, 0.2508250624), (7, 0.2510965143)], [], [], [], []] - Dividends: [0.0988155114, 0.2002632194, 0.3003948291, 0.4005264398, 0, 0, 0, 0] - Normalized Server Emission: [0, 0, 0, 0, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] - Server Emission: [0, 0, 0, 0, 49998779, 100000610, 149996337, 200004272] - Normalized Validator Emission: [0.0494077557, 0.1001316097, 0.1501974144, 0.20026322, 0, 0, 0, 0] - Validator Emission: [49407755, 100131609, 150197414, 200263219, 0, 0, 0, 0] - Normalized Combined Emission: [0.0494077557, 0.1001316097, 0.1501974144, 0.20026322, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] - Combined Emission: [49407755, 100131609, 150197414, 200263219, 49998779, 100000610, 149996337, 200004272] - Pruning Scores: [0.0494077557, 0.1001316097, 0.1501974144, 0.20026322, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] + B: [[(4, 589), (5, 1178), (6, 1769), (7, 2358)], [(4, 1244), (5, 2489), (6, 3735), (7, 4980)], [(4, 1244), (5, 2489), (6, 3735), (7, 4980)], [(4, 1244), (5, 2489), (6, 3735), (7, 4980)], [], [], [], []] + B (outdatedmask): [[(4, 589), (5, 1178), (6, 1769), (7, 2358)], [(4, 1244), (5, 2489), (6, 3735), (7, 4980)], [(4, 1244), (5, 2489), (6, 3735), (7, 4980)], [(4, 1244), (5, 2489), (6, 3735), (7, 4980)], [], [], [], []] + B: [[(4, 0.008987564), (5, 0.0179751278), (6, 0.0269932097), (7, 0.0359807736)], [(4, 0.0189822232), (5, 0.0379797055), (6, 0.0569924468), (7, 0.075989929)], [(4, 0.0189822232), (5, 0.0379797055), (6, 0.0569924468), (7, 0.075989929)], [(4, 0.0189822232), (5, 0.0379797055), (6, 0.0569924468), (7, 0.075989929)], [], [], [], []] + alphas: [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1] + emaB: [[(4, 0.0080888073), (5, 0.016177615), (6, 0.0242938886), (7, 0.0323826962)], [(4, 0.0170840009), (5, 0.0341817348), (6, 0.051293202), (7, 0.068390936)], [(4, 0.0270837566), (5, 0.0541818568), (6, 0.0812924695), (7, 0.1083917904)], [(4, 0.0270837566), (5, 0.0541818568), (6, 0.0812924695), (7, 0.1083917904)], [], [], [], []] + emaB norm: [[(4, 0.1019507758), (5, 0.10192353), (6, 0.102001434), (7, 0.101974368)], [(4, 0.2153255814), (5, 0.2153545555), (6, 0.2153619886), (7, 0.215365714)], [(4, 0.3413618212), (5, 0.341360957), (6, 0.3413182884), (7, 0.3413299588)], [(4, 0.3413618212), (5, 0.341360957), (6, 0.3413182884), (7, 0.3413299588)], [], [], [], []] + total_bonds_per_validator: [0.1019699604, 0.215358351, 0.3413358429, 0.3413358429, 0, 0, 0, 0] + D: [0.034896868, 0.1474028623, 0.3504429725, 0.4672572967, 0, 0, 0, 0] + nE: [0.017448434, 0.073701431, 0.1752214862, 0.2336286483, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] + E: [17448433, 73701431, 175221486, 233628648, 49998779, 100000610, 149996337, 200004272] + P: [0.017448434, 0.073701431, 0.1752214862, 0.2336286483, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] */ - let bonds = SubtensorModule::get_bonds(netuid); - assert_eq!(bonds[0][4], 64956); - assert_eq!(bonds[1][4], 65245); - assert_eq!(bonds[2][4], 65535); - assert_eq!(bonds[3][4], 65535); + assert_eq!(bonds[0][4], 530); + assert_eq!(bonds[1][4], 1119); + assert_eq!(bonds[2][4], 1774); + assert_eq!(bonds[3][4], 1774); - // === Set self-weight only on val3 - let uid = 2; + // === Set self-weight only on val2 + let uid = 1; assert_ok!(SubtensorModule::set_weights( RuntimeOrigin::signed(U256::from(uid)), netuid, @@ -1222,37 +1211,42 @@ fn test_bonds() { SubtensorModule::epoch_dense(netuid, 1_000_000_000); } /* current_block: 4 + current_block: 5, activity_cutoff: 5000, Last update: [2, 4, 2, 2, 1, 1, 1, 1] + Inactive: [false, false, false, false, false, false, false, false] + Block at registration: [1, 1, 1, 1, 1, 1, 1, 1] + hotkeys: [(0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7)] + S: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] + validator_permits: [true, true, true, true, true, true, true, true] + max_allowed_validators: 8 + new_validator_permits: [true, true, true, true, true, true, true, true] + S: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] W: [[(0, 65535)], [(1, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] W (permit): [[(0, 65535)], [(1, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] W (permit+diag): [[], [], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] W (permit+diag+outdate): [[], [], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - W (mask+norm): [[], [], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] - R (before): [0, 0, 0, 0, 0.0699982906, 0.1400008542, 0.2099948723, 0.2800059812] C: [0, 0, 0, 0, 0.0999975584, 0.2000012207, 0.2999926754, 0.400008545] - Clipped Weights: [[], [], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] - Validator Trust: [0, 0, 0.9999999995, 0.9999999995, 0, 0, 0, 0] + W: [[], [], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] + Tv: [0, 0, 0.9999999995, 0.9999999995, 0, 0, 0, 0] R (after): [0, 0, 0, 0, 0.0699982906, 0.1400008542, 0.2099948723, 0.2800059812] T: [0, 0, 0, 0, 1, 1, 1, 1] I (=R): [0, 0, 0, 0, 0.0999975582, 0.2000012207, 0.2999926754, 0.4000085455] - B: [[(4, 65245), (5, 64957), (6, 64672), (7, 64390)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [], [], [], []] - B (outdatedmask): [[(4, 65245), (5, 64957), (6, 64672), (7, 64390)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [], [], [], []] - B (mask+norm): [[(4, 0.2491693716), (5, 0.248342649), (6, 0.247522744), (7, 0.246709707)], [(4, 0.250276876), (5, 0.25055245), (6, 0.2508257518), (7, 0.251096764)], [(4, 0.250276876), (5, 0.25055245), (6, 0.2508257518), (7, 0.251096764)], [(4, 0.250276876), (5, 0.25055245), (6, 0.2508257518), (7, 0.251096764)], [], [], [], []] - alpha values: [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1] - Exponential Moving Average Bonds: [[(4, 0.248616903), (5, 0.2472437813), (6, 0.2458835603), (7, 0.2445360073)], [(4, 0.249721952), (5, 0.2494438041), (6, 0.2491646945), (7, 0.248884411)], [(4, 0.2508305723), (5, 0.251656207), (6, 0.2524758724), (7, 0.2532897906)], [(4, 0.2508305723), (5, 0.251656207), (6, 0.2524758724), (7, 0.2532897906)], [], [], [], []] - Dividends: [0.097904461, 0.198416279, 0.3015768253, 0.402102434, 0, 0, 0, 0] - Normalized Server Emission: [0, 0, 0, 0, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] - Server Emission: [0, 0, 0, 0, 49998779, 100000610, 149996337, 200004272] - Normalized Validator Emission: [0.0489522305, 0.0992081393, 0.1507884127, 0.201051217, 0, 0, 0, 0] - Validator Emission: [48952230, 99208139, 150788412, 201051217, 0, 0, 0, 0] - Normalized Combined Emission: [0.0489522305, 0.0992081393, 0.1507884127, 0.201051217, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] - Combined Emission: [48952230, 99208139, 150788412, 201051217, 49998779, 100000610, 149996337, 200004272] - Pruning Scores: [0.0489522305, 0.0992081393, 0.1507884127, 0.201051217, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] + B: [[(4, 530), (5, 1060), (6, 1592), (7, 2122)], [(4, 1119), (5, 2240), (6, 3361), (7, 4481)], [(4, 1774), (5, 3550), (6, 5327), (7, 7103)], [(4, 1774), (5, 3550), (6, 5327), (7, 7103)], [], [], [], []] + B (outdatedmask): [[(4, 530), (5, 1060), (6, 1592), (7, 2122)], [(4, 1119), (5, 2240), (6, 3361), (7, 4481)], [(4, 1774), (5, 3550), (6, 5327), (7, 7103)], [(4, 1774), (5, 3550), (6, 5327), (7, 7103)], [], [], [], []] + B: [[(4, 0.0080872816), (5, 0.0161745632), (6, 0.0242923629), (7, 0.0323796445)], [(4, 0.0170748455), (5, 0.034180209), (6, 0.0512855726), (7, 0.068375677)], [(4, 0.0270695048), (5, 0.0541695277), (6, 0.0812848096), (7, 0.1083848325)], [(4, 0.0270695048), (5, 0.0541695277), (6, 0.0812848096), (7, 0.1083848325)], [], [], [], []] + alphas: [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1] + emaB: [[(4, 0.0072785532), (5, 0.0145571067), (6, 0.0218631264), (7, 0.0291416799)], [(4, 0.0153673608), (5, 0.030762188), (6, 0.0461570153), (7, 0.0615381093)], [(4, 0.03436231), (5, 0.0687526967), (6, 0.1031555962), (7, 0.1375472036)], [(4, 0.03436231), (5, 0.0687526967), (6, 0.1031555962), (7, 0.1375472036)], [], [], [], []] + emaB norm: [[(4, 0.0796597423), (5, 0.079623309), (6, 0.0796960597), (7, 0.0796712292)], [(4, 0.1681872709), (5, 0.168260579), (6, 0.1682528006), (7, 0.1682407067)], [(4, 0.3760764932), (5, 0.3760580558), (6, 0.3760255696), (7, 0.376044032)], [(4, 0.3760764932), (5, 0.3760580558), (6, 0.3760255696), (7, 0.376044032)], [], [], [], []] + total_bonds_per_validator: [0.079667945, 0.1682429651, 0.3760445435, 0.3760445435, 0, 0, 0, 0] + D: [0.0261337839, 0.1103787823, 0.3700660428, 0.493421391, 0, 0, 0, 0] + nE: [0.0130668918, 0.0551893911, 0.1850330213, 0.2467106953, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] + E: [13066891, 55189391, 185033021, 246710695, 49998779, 100000610, 149996337, 200004272] + P: [0.0130668918, 0.0551893911, 0.1850330213, 0.2467106953, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] */ let bonds = SubtensorModule::get_bonds(netuid); - assert_eq!(bonds[0][7], 63269); - assert_eq!(bonds[1][7], 64394); - assert_eq!(bonds[2][7], 65535); - assert_eq!(bonds[3][7], 65535); + assert_eq!(bonds[0][7], 1909); + assert_eq!(bonds[1][7], 4032); + assert_eq!(bonds[2][7], 9014); + assert_eq!(bonds[3][7], 9014); // === Set val3->srv4: 1 assert_ok!(SubtensorModule::set_weights( @@ -1269,37 +1263,42 @@ fn test_bonds() { SubtensorModule::epoch_dense(netuid, 1_000_000_000); } /* current_block: 5 - W: [[(0, 65535)], [(1, 65535)], [(2, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - W (permit): [[(0, 65535)], [(1, 65535)], [(2, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - W (permit+diag): [[], [], [], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - W (permit+diag+outdate): [[], [], [], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - W (mask+norm): [[], [], [], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] - R (before): [0, 0, 0, 0, 0.0399990233, 0.080000488, 0.11999707, 0.1600034179] - C: [0, 0, 0, 0, 0, 0, 0, 0] - Clipped Weights: [[], [], [], [], [], [], [], []] - Validator Trust: [0, 0, 0, 0, 0, 0, 0, 0] - R (after): [0, 0, 0, 0, 0, 0, 0, 0] - T: [0, 0, 0, 0, 0, 0, 0, 0] - I (=R): [0, 0, 0, 0, 0, 0, 0, 0] - B: [[(4, 64956), (5, 64385), (6, 63823), (7, 63270)], [(4, 65245), (5, 64958), (6, 64675), (7, 64395)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [], [], [], []] - B (outdatedmask): [[(4, 64956), (5, 64385), (6, 63823), (7, 63270)], [(4, 65245), (5, 64958), (6, 64675), (7, 64395)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [], [], [], []] - B (mask+norm): [[(4, 0.2486154223), (5, 0.247241881), (6, 0.2458816185), (7, 0.244535915)], [(4, 0.2497215534), (5, 0.249442232), (6, 0.2491639955), (7, 0.2488839931)], [(4, 0.250831512), (5, 0.2516579432), (6, 0.2524771928), (7, 0.2532900458)], [(4, 0.250831512), (5, 0.2516579432), (6, 0.2524771928), (7, 0.2532900458)], [], [], [], []] - alpha values: [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1] - Exponential Moving Average Bonds: [[(4, 0.2486154223), (5, 0.247241881), (6, 0.2458816185), (7, 0.244535915)], [(4, 0.2497215534), (5, 0.249442232), (6, 0.2491639955), (7, 0.248883993)], [(4, 0.2508315118), (5, 0.2516579432), (6, 0.2524771928), (7, 0.2532900458)], [(4, 0.2508315118), (5, 0.2516579432), (6, 0.2524771928), (7, 0.2532900458)], [], [], [], []] - Dividends: [0, 0, 0, 0, 0, 0, 0, 0] - Normalized Server Emission: [0, 0, 0, 0, 0, 0, 0, 0] - Server Emission: [0, 0, 0, 0, 0, 0, 0, 0] - Normalized Validator Emission: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] - Validator Emission: [99999999, 199999999, 299999999, 399999999, 0, 0, 0, 0] - Normalized Combined Emission: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] - Combined Emission: [99999999, 199999999, 299999999, 399999999, 0, 0, 0, 0] - Pruning Scores: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] + current_block: 6, activity_cutoff: 5000, Last update: [2, 4, 5, 2, 1, 1, 1, 1] + Inactive: [false, false, false, false, false, false, false, false] + Block at registration: [1, 1, 1, 1, 1, 1, 1, 1] + hotkeys: [(0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7)] + S: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] + validator_permits: [true, true, true, true, true, true, true, true] + max_allowed_validators: 8 + new_validator_permits: [true, true, true, true, true, true, true, true] + S: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] + W: [[(0, 65535)], [(1, 65535)], [(7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + W (permit): [[(0, 65535)], [(1, 65535)], [(7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + W (permit+diag): [[], [], [(7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + W (permit+diag+outdate): [[], [], [(7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + C: [0, 0, 0, 0, 0, 0, 0, 0.400008545] + W: [[], [], [(7, 0.400008545)], [(7, 0.400008545)], [], [], [], []] + Tv: [0, 0, 0.400008545, 0.400008545, 0, 0, 0, 0] + R (after): [0, 0, 0, 0, 0, 0, 0, 0.2800059812] + T: [0, 0, 0, 0, 0, 0, 0, 0.6087041323] + I (=R): [0, 0, 0, 0, 0, 0, 0, 1] + B: [[(4, 476), (5, 953), (6, 1432), (7, 1909)], [(4, 1007), (5, 2015), (6, 3024), (7, 4032)], [(4, 2251), (5, 4505), (6, 6760), (7, 9014)], [(4, 2251), (5, 4505), (6, 6760), (7, 9014)], [], [], [], []] + B (outdatedmask): [[(4, 476), (5, 953), (6, 1432), (7, 1909)], [(4, 1007), (5, 2015), (6, 3024), (7, 4032)], [(4, 2251), (5, 4505), (6, 6760), (7, 9014)], [(4, 2251), (5, 4505), (6, 6760), (7, 9014)], [], [], [], []] + B: [[(4, 0.0072632944), (5, 0.0145418479), (6, 0.0218509194), (7, 0.0291294728)], [(4, 0.015365835), (5, 0.030746929), (6, 0.0461432822), (7, 0.0615243763)], [(4, 0.0343480583), (5, 0.0687418936), (6, 0.103150988), (7, 0.1375448233)], [(4, 0.0343480583), (5, 0.0687418936), (6, 0.103150988), (7, 0.1375448233)], [], [], [], []] + alphas: [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1] + emaB: [[(4, 0.0065369648), (5, 0.0130876629), (6, 0.0196658273), (7, 0.0262165254)], [(4, 0.0138292515), (5, 0.027672236), (6, 0.041528954), (7, 0.0553719385)], [(4, 0.0309132524), (5, 0.0618677041), (6, 0.092835889), (7, 0.1637911955)], [(4, 0.0309132524), (5, 0.0618677041), (6, 0.092835889), (7, 0.1637911955)], [], [], [], []] + emaB norm: [[(4, 0.0795321616), (5, 0.0795625302), (6, 0.0796617707), (7, 0.0640723184)], [(4, 0.1682539685), (5, 0.168225079), (6, 0.168224299), (7, 0.1353271813)], [(4, 0.3761069346), (5, 0.3761061952), (6, 0.3760569647), (7, 0.40030025)], [(4, 0.3761069346), (5, 0.3761061952), (6, 0.3760569647), (7, 0.40030025)], [], [], [], []] + total_bonds_per_validator: [0.0640723184, 0.1353271813, 0.40030025, 0.40030025, 0, 0, 0, 0] + D: [0.020425828, 0.0862828067, 0.3828391563, 0.5104522086, 0, 0, 0, 0] + nE: [0.0102129139, 0.0431414032, 0.1914195782, 0.2552261043, 0, 0, 0, 0.5] + E: [10212913, 43141403, 191419578, 255226104, 0, 0, 0, 500000000] + P: [0.0102129139, 0.0431414032, 0.1914195782, 0.2552261043, 0, 0, 0, 0.5] */ let bonds = SubtensorModule::get_bonds(netuid); - assert_eq!(bonds[0][7], 62177); - assert_eq!(bonds[1][7], 63283); - assert_eq!(bonds[2][7], 65535); - assert_eq!(bonds[3][7], 65535); + assert_eq!(bonds[0][7], 1718); + assert_eq!(bonds[1][7], 3628); + assert_eq!(bonds[2][7], 10734); + assert_eq!(bonds[3][7], 10734); next_block(); if sparse { @@ -1308,25 +1307,42 @@ fn test_bonds() { SubtensorModule::epoch_dense(netuid, 1_000_000_000); } /* current_block: 6 - B: [[(4, 64956), (5, 64384), (6, 63822), (7, 63269)], [(4, 65245), (5, 64958), (6, 64675), (7, 64394)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [], [], [], []] - B (outdatedmask): [[(4, 64956), (5, 64384), (6, 63822), (7, 63269)], [(4, 65245), (5, 64958), (6, 64675), (7, 64394)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [], [], [], []] - B (mask+norm): [[(4, 0.2486154223), (5, 0.2472389904), (6, 0.2458787132), (7, 0.2445339402)], [(4, 0.2497215534), (5, 0.24944319), (6, 0.2491649555), (7, 0.248882052)], [(4, 0.250831512), (5, 0.2516589097), (6, 0.2524781656), (7, 0.2532920036)], [(4, 0.250831512), (5, 0.2516589097), (6, 0.2524781656), (7, 0.2532920036)], [], [], [], []] - alpha values: [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1] - Exponential Moving Average Bonds: [[(4, 0.2486154223), (5, 0.2472389904), (6, 0.2458787132), (7, 0.2423794107)], [(4, 0.2497215534), (5, 0.2494431897), (6, 0.2491649555), (7, 0.2466892123)], [(4, 0.2508315118), (5, 0.2516589097), (6, 0.2524781656), (7, 0.2554656884)], [(4, 0.2508315118), (5, 0.2516589097), (6, 0.2524781656), (7, 0.2554656884)], [], [], [], []] - Dividends: [0.0960292057, 0.195473444, 0.3036417211, 0.4048556287, 0, 0, 0, 0] - Normalized Server Emission: [0, 0, 0, 0, 0, 0, 0, 0.5] - Server Emission: [0, 0, 0, 0, 0, 0, 0, 500000000] - Normalized Validator Emission: [0.0480146029, 0.0977367219, 0.1518208606, 0.2024278142, 0, 0, 0, 0] - Validator Emission: [48014602, 97736721, 151820860, 202427814, 0, 0, 0, 0] - Normalized Combined Emission: [0.0480146029, 0.0977367219, 0.1518208606, 0.2024278142, 0, 0, 0, 0.5] - Combined Emission: [48014602, 97736721, 151820860, 202427814, 0, 0, 0, 500000000] - Pruning Scores: [0.0480146029, 0.0977367219, 0.1518208606, 0.2024278142, 0, 0, 0, 0.5] + current_block: 7, activity_cutoff: 5000, Last update: [2, 4, 5, 2, 1, 1, 1, 1] + Inactive: [false, false, false, false, false, false, false, false] + Block at registration: [1, 1, 1, 1, 1, 1, 1, 1] + hotkeys: [(0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7)] + S: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] + validator_permits: [true, true, true, true, true, true, true, true] + max_allowed_validators: 8 + new_validator_permits: [true, true, true, true, true, true, true, true] + S: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] + W: [[(0, 65535)], [(1, 65535)], [(7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + W (permit): [[(0, 65535)], [(1, 65535)], [(7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + W (permit+diag): [[], [], [(7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + W (permit+diag+outdate): [[], [], [(7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + C: [0, 0, 0, 0, 0, 0, 0, 0.400008545] + W: [[], [], [(7, 0.400008545)], [(7, 0.400008545)], [], [], [], []] + Tv: [0, 0, 0.400008545, 0.400008545, 0, 0, 0, 0] + R (after): [0, 0, 0, 0, 0, 0, 0, 0.2800059812] + T: [0, 0, 0, 0, 0, 0, 0, 0.6087041323] + I (=R): [0, 0, 0, 0, 0, 0, 0, 1] + B: [[(4, 428), (5, 857), (6, 1288), (7, 1718)], [(4, 906), (5, 1813), (6, 2721), (7, 3628)], [(4, 2025), (5, 4054), (6, 6083), (7, 10734)], [(4, 2025), (5, 4054), (6, 6083), (7, 10734)], [], [], [], []] + B (outdatedmask): [[(4, 428), (5, 857), (6, 1288), (7, 1718)], [(4, 906), (5, 1813), (6, 2721), (7, 3628)], [(4, 2025), (5, 4054), (6, 6083), (7, 10734)], [(4, 2025), (5, 4054), (6, 6083), (7, 10734)], [], [], [], []] + B: [[(4, 0.0065308614), (5, 0.0130769818), (6, 0.0196536202), (7, 0.0262149996)], [(4, 0.0138246738), (5, 0.0276646067), (6, 0.0415197986), (7, 0.0553597314)], [(4, 0.0308995193), (5, 0.0618600748), (6, 0.0928206302), (7, 0.163790341)], [(4, 0.0308995193), (5, 0.0618600748), (6, 0.0928206302), (7, 0.163790341)], [], [], [], []] + alphas: [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1] + emaB: [[(4, 0.0058777751), (5, 0.0117692836), (6, 0.017688258), (7, 0.0235934996)], [(4, 0.0124422063), (5, 0.0248981458), (6, 0.0373678186), (7, 0.0498237582)], [(4, 0.0278095673), (5, 0.0556740672), (6, 0.083538567), (7, 0.1874121614)], [(4, 0.0278095673), (5, 0.0556740672), (6, 0.083538567), (7, 0.1874121614)], [], [], [], []] + emaB norm: [[(4, 0.0794947986), (5, 0.0795138243), (6, 0.0796290569), (7, 0.052635678)], [(4, 0.168276373), (5, 0.1682130254), (6, 0.1682225657), (7, 0.111153807)], [(4, 0.376114414), (5, 0.376136575), (6, 0.3760741884), (7, 0.4181052572)], [(4, 0.376114414), (5, 0.376136575), (6, 0.3760741884), (7, 0.4181052572)], [], [], [], []] + total_bonds_per_validator: [0.052635678, 0.111153807, 0.4181052572, 0.4181052572, 0, 0, 0, 0] + D: [0.0164400174, 0.069434674, 0.391767989, 0.5223573192, 0, 0, 0, 0] + nE: [0.0082200086, 0.034717337, 0.1958839945, 0.2611786595, 0, 0, 0, 0.5] + E: [8220008, 34717336, 195883994, 261178659, 0, 0, 0, 500000000] + P: [0.0082200086, 0.034717337, 0.1958839945, 0.2611786595, 0, 0, 0, 0.5] */ let bonds = SubtensorModule::get_bonds(netuid); - assert_eq!(bonds[0][7], 61113); - assert_eq!(bonds[1][7], 62200); - assert_eq!(bonds[2][7], 65535); - assert_eq!(bonds[3][7], 65535); + assert_eq!(bonds[0][7], 1546); + assert_eq!(bonds[1][7], 3265); + assert_eq!(bonds[2][7], 12282); + assert_eq!(bonds[3][7], 12282); next_block(); if sparse { @@ -1335,25 +1351,42 @@ fn test_bonds() { SubtensorModule::epoch_dense(netuid, 1_000_000_000); } /* current_block: 7 - B: [[(4, 64956), (5, 64383), (6, 63821), (7, 62177)], [(4, 65245), (5, 64957), (6, 64674), (7, 63283)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [], [], [], []] - B (outdatedmask): [[(4, 64956), (5, 64383), (6, 63821), (7, 62177)], [(4, 65245), (5, 64957), (6, 64674), (7, 63283)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [], [], [], []] - B (mask+norm): [[(4, 0.2486154223), (5, 0.247237049), (6, 0.2458767553), (7, 0.2423771098)], [(4, 0.2497215534), (5, 0.2494412656), (6, 0.2491630227), (7, 0.2466884963)], [(4, 0.250831512), (5, 0.2516608424), (6, 0.2524801109), (7, 0.2554671967)], [(4, 0.250831512), (5, 0.2516608424), (6, 0.2524801109), (7, 0.2554671967)], [], [], [], []] - alpha values: [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1] - Exponential Moving Average Bonds: [[(4, 0.2486154223), (5, 0.2472370488), (6, 0.2458767553), (7, 0.2402415834)], [(4, 0.2497215534), (5, 0.2494412656), (6, 0.2491630227), (7, 0.2445149834)], [(4, 0.2508315118), (5, 0.2516608424), (6, 0.2524801109), (7, 0.2576217165)], [(4, 0.2508315118), (5, 0.2516608424), (6, 0.2524801109), (7, 0.2576217165)], [], [], [], []] - Dividends: [0.0948587805, 0.1930922437, 0.3051638464, 0.4068851292, 0, 0, 0, 0] - Normalized Server Emission: [0, 0, 0, 0, 0, 0, 0, 0.5] - Server Emission: [0, 0, 0, 0, 0, 0, 0, 500000000] - Normalized Validator Emission: [0.0474293903, 0.0965461219, 0.1525819232, 0.2034425645, 0, 0, 0, 0] - Validator Emission: [47429390, 96546121, 152581923, 203442564, 0, 0, 0, 0] - Normalized Combined Emission: [0.0474293903, 0.0965461219, 0.1525819232, 0.2034425645, 0, 0, 0, 0.5] - Combined Emission: [47429390, 96546121, 152581923, 203442564, 0, 0, 0, 500000000] - Pruning Scores: [0.0474293903, 0.0965461219, 0.1525819232, 0.2034425645, 0, 0, 0, 0.5] + current_block: 8, activity_cutoff: 5000, Last update: [2, 4, 5, 2, 1, 1, 1, 1] + Inactive: [false, false, false, false, false, false, false, false] + Block at registration: [1, 1, 1, 1, 1, 1, 1, 1] + hotkeys: [(0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7)] + S: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] + validator_permits: [true, true, true, true, true, true, true, true] + max_allowed_validators: 8 + new_validator_permits: [true, true, true, true, true, true, true, true] + S: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] + W: [[(0, 65535)], [(1, 65535)], [(7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + W (permit): [[(0, 65535)], [(1, 65535)], [(7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + W (permit+diag): [[], [], [(7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + W (permit+diag+outdate): [[], [], [(7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + C: [0, 0, 0, 0, 0, 0, 0, 0.400008545] + W: [[], [], [(7, 0.400008545)], [(7, 0.400008545)], [], [], [], []] + Tv: [0, 0, 0.400008545, 0.400008545, 0, 0, 0, 0] + R (after): [0, 0, 0, 0, 0, 0, 0, 0.2800059812] + T: [0, 0, 0, 0, 0, 0, 0, 0.6087041323] + I (=R): [0, 0, 0, 0, 0, 0, 0, 1] + B: [[(4, 385), (5, 771), (6, 1159), (7, 1546)], [(4, 815), (5, 1631), (6, 2448), (7, 3265)], [(4, 1822), (5, 3648), (6, 5474), (7, 12282)], [(4, 1822), (5, 3648), (6, 5474), (7, 12282)], [], [], [], []] + B (outdatedmask): [[(4, 385), (5, 771), (6, 1159), (7, 1546)], [(4, 815), (5, 1631), (6, 2448), (7, 3265)], [(4, 1822), (5, 3648), (6, 5474), (7, 12282)], [(4, 1822), (5, 3648), (6, 5474), (7, 12282)], [], [], [], []] + B: [[(4, 0.0058747234), (5, 0.0117647059), (6, 0.0176852064), (7, 0.0235904478)], [(4, 0.0124361028), (5, 0.0248874647), (6, 0.0373540856), (7, 0.0498207065)], [(4, 0.027801938), (5, 0.0556649119), (6, 0.0835278858), (7, 0.187411307)], [(4, 0.027801938), (5, 0.0556649119), (6, 0.0835278858), (7, 0.187411307)], [], [], [], []] + alphas: [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1] + emaB: [[(4, 0.005287251), (5, 0.0105882352), (6, 0.0159166856), (7, 0.0212314029)], [(4, 0.0111924924), (5, 0.0223987182), (6, 0.033618677), (7, 0.0448386357)], [(4, 0.025021744), (5, 0.0500984206), (6, 0.0751750972), (7, 0.2086710306)], [(4, 0.025021744), (5, 0.0500984206), (6, 0.0751750972), (7, 0.2086710306)], [], [], [], []] + emaB norm: [[(4, 0.0794797675), (5, 0.0795009276), (6, 0.0796289926), (7, 0.043919883)], [(4, 0.16824938), (5, 0.1681790059), (6, 0.1681896253), (7, 0.0927544753)], [(4, 0.3761354259), (5, 0.376160033), (6, 0.3760906907), (7, 0.4316628207)], [(4, 0.3761354259), (5, 0.376160033), (6, 0.3760906907), (7, 0.4316628207)], [], [], [], []] + total_bonds_per_validator: [0.043919883, 0.0927544753, 0.4316628207, 0.4316628207, 0, 0, 0, 0] + D: [0.0135093683, 0.0570609153, 0.398327021, 0.531102695, 0, 0, 0, 0] + nE: [0.006754684, 0.0285304575, 0.1991635105, 0.2655513475, 0, 0, 0, 0.5] + E: [6754684, 28530457, 199163510, 265551347, 0, 0, 0, 500000000] + P: [0.006754684, 0.0285304575, 0.1991635105, 0.2655513475, 0, 0, 0, 0.5] */ let bonds = SubtensorModule::get_bonds(netuid); - assert_eq!(bonds[0][7], 60076); - assert_eq!(bonds[1][7], 61145); - assert_eq!(bonds[2][7], 65535); - assert_eq!(bonds[3][7], 65535); + assert_eq!(bonds[0][7], 1391); + assert_eq!(bonds[1][7], 2938); + assert_eq!(bonds[2][7], 13675); + assert_eq!(bonds[3][7], 13675); next_block(); if sparse { @@ -1362,19 +1395,36 @@ fn test_bonds() { SubtensorModule::epoch_dense(netuid, 1_000_000_000); } /* current_block: 8 - B: [[(4, 64956), (5, 64382), (6, 63821), (7, 61113)], [(4, 65245), (5, 64956), (6, 64674), (7, 62200)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [], [], [], []] - B (outdatedmask): [[(4, 64956), (5, 64382), (6, 63821), (7, 61113)], [(4, 65245), (5, 64956), (6, 64674), (7, 62200)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [], [], [], []] - B (mask+norm): [[(4, 0.2486154223), (5, 0.247235108), (6, 0.2458767553), (7, 0.2402401103)], [(4, 0.2497215534), (5, 0.2494393412), (6, 0.2491630227), (7, 0.2445131945)], [(4, 0.250831512), (5, 0.2516627752), (6, 0.2524801109), (7, 0.2576233475)], [(4, 0.250831512), (5, 0.2516627752), (6, 0.2524801109), (7, 0.2576233475)], [], [], [], []] - alpha values: [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1] - Exponential Moving Average Bonds: [[(4, 0.2486154223), (5, 0.247235108), (6, 0.2458767553), (7, 0.2381234125)], [(4, 0.2497215534), (5, 0.2494393412), (6, 0.2491630227), (7, 0.2423588475)], [(4, 0.2508315118), (5, 0.2516627752), (6, 0.2524801109), (7, 0.2597588697)], [(4, 0.2508315118), (5, 0.2516627752), (6, 0.2524801109), (7, 0.2597588697)], [], [], [], []] - Dividends: [0.0937068302, 0.1907471363, 0.3066625856, 0.4088834478, 0, 0, 0, 0] - Normalized Server Emission: [0, 0, 0, 0, 0, 0, 0, 0.5] - Server Emission: [0, 0, 0, 0, 0, 0, 0, 500000000] - Normalized Validator Emission: [0.046853415, 0.0953735681, 0.1533312928, 0.2044417239, 0, 0, 0, 0] - Validator Emission: [46853414, 95373568, 153331292, 204441723, 0, 0, 0, 0] - Normalized Combined Emission: [0.046853415, 0.0953735681, 0.1533312928, 0.2044417239, 0, 0, 0, 0.5] - Combined Emission: [46853414, 95373568, 153331292, 204441723, 0, 0, 0, 500000000] - Pruning Scores: [0.046853415, 0.0953735681, 0.1533312928, 0.2044417239, 0, 0, 0, 0.5] + current_block: 9, activity_cutoff: 5000, Last update: [2, 4, 5, 2, 1, 1, 1, 1] + Inactive: [false, false, false, false, false, false, false, false] + Block at registration: [1, 1, 1, 1, 1, 1, 1, 1] + hotkeys: [(0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7)] + S: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] + validator_permits: [true, true, true, true, true, true, true, true] + max_allowed_validators: 8 + new_validator_permits: [true, true, true, true, true, true, true, true] + S: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] + W: [[(0, 65535)], [(1, 65535)], [(7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + W (permit): [[(0, 65535)], [(1, 65535)], [(7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + W (permit+diag): [[], [], [(7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + W (permit+diag+outdate): [[], [], [(7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + C: [0, 0, 0, 0, 0, 0, 0, 0.400008545] + W: [[], [], [(7, 0.400008545)], [(7, 0.400008545)], [], [], [], []] + Tv: [0, 0, 0.400008545, 0.400008545, 0, 0, 0, 0] + R (after): [0, 0, 0, 0, 0, 0, 0, 0.2800059812] + T: [0, 0, 0, 0, 0, 0, 0, 0.6087041323] + I (=R): [0, 0, 0, 0, 0, 0, 0, 1] + B: [[(4, 346), (5, 693), (6, 1043), (7, 1391)], [(4, 733), (5, 1467), (6, 2203), (7, 2938)], [(4, 1639), (5, 3283), (6, 4926), (7, 13675)], [(4, 1639), (5, 3283), (6, 4926), (7, 13675)], [], [], [], []] + B (outdatedmask): [[(4, 346), (5, 693), (6, 1043), (7, 1391)], [(4, 733), (5, 1467), (6, 2203), (7, 2938)], [(4, 1639), (5, 3283), (6, 4926), (7, 13675)], [(4, 1639), (5, 3283), (6, 4926), (7, 13675)], [], [], [], []] + B: [[(4, 0.0052796216), (5, 0.0105745022), (6, 0.0159151598), (7, 0.0212252995)], [(4, 0.011184863), (5, 0.0223849851), (6, 0.0336156252), (7, 0.0448310063)], [(4, 0.0250095369), (5, 0.0500953689), (6, 0.0751659418), (7, 0.2086671244)], [(4, 0.0250095369), (5, 0.0500953689), (6, 0.0751659418), (7, 0.2086671244)], [], [], [], []] + alphas: [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1] + emaB: [[(4, 0.0047516592), (5, 0.0095170517), (6, 0.0143236436), (7, 0.0191027694)], [(4, 0.0100663765), (5, 0.0201464866), (6, 0.0302540625), (7, 0.0403479056)], [(4, 0.022508583), (5, 0.0450858318), (6, 0.0676493475), (7, 0.2278012664)], [(4, 0.022508583), (5, 0.0450858318), (6, 0.0676493475), (7, 0.2278012664)], [], [], [], []] + emaB norm: [[(4, 0.0794124375), (5, 0.0794178303), (6, 0.079630477), (7, 0.037088924)], [(4, 0.1682350226), (5, 0.1681182678), (6, 0.168193617), (7, 0.0783373541)], [(4, 0.3761762697), (5, 0.3762319507), (6, 0.3760879529), (7, 0.4422868607)], [(4, 0.3761762697), (5, 0.3762319507), (6, 0.3760879529), (7, 0.4422868607)], [], [], [], []] + total_bonds_per_validator: [0.037088924, 0.0783373541, 0.4422868607, 0.4422868607, 0, 0, 0, 0] + D: [0.011274011, 0.0476247966, 0.403329082, 0.5377721095, 0, 0, 0, 0] + nE: [0.0056370054, 0.0238123983, 0.201664541, 0.2688860546, 0, 0, 0, 0.5] + E: [5637005, 23812398, 201664540, 268886054, 0, 0, 0, 500000000] + P: [0.0056370054, 0.0238123983, 0.201664541, 0.2688860546, 0, 0, 0, 0.5] */ }); } @@ -1455,40 +1505,35 @@ fn test_bonds_with_liquid_alpha() { /* n: 8 current_block: 3 activity_cutoff: 5000 - Last update: [2, 2, 2, 2, 1, 1, 1, 1] Inactive: [false, false, false, false, false, false, false, false] Block at registration: [1, 1, 1, 1, 1, 1, 1, 1] hotkeys: [(0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7)] - Normalised Stake: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] + S: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] validator_permits: [true, true, true, true, true, true, true, true] - max_allowed_validators: 64 + max_allowed_validators: 8 new_validator_permits: [true, true, true, true, true, true, true, true] - Active Stake: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] - Weights: [[(0, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, - Weights (permit): [[(0, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 327 - Weights (permit+diag): [[], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), - Weights (permit+diag+outdate): [[], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - Weights (mask+norm): [[], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] - R (before): [0, 0, 0, 0, 0.0899978022, 0.1800010982, 0.2699934072, 0.36000769] + S: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] + W: [[(0, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + W (permit): [[(0, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + W (permit+diag): [[], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + W (permit+diag+outdate): [[], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] C: [0, 0, 0, 0, 0.0999975584, 0.2000012207, 0.2999926754, 0.400008545] - Clipped Weights: [[], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] - Validator Trust: [0, 0.9999999995, 0.9999999995, 0.9999999995, 0, 0, 0, 0] + W: [[], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] + Tv: [0, 0.9999999995, 0.9999999995, 0.9999999995, 0, 0, 0, 0] R (after): [0, 0, 0, 0, 0.0899978022, 0.1800010982, 0.2699934072, 0.36000769] T: [0, 0, 0, 0, 1, 1, 1, 1] - Incentive (=Rank): [0, 0, 0, 0, 0.0999975582, 0.2000012207, 0.2999926754, 0.4000085455] - B: [[(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [], [], [], []] - B (outdatedmask): [[(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [], [], [], []] - B (mask+norm): [[(4, 0.25), (5, 0.25), (6, 0.25), (7, 0.25)], [(4, 0.25), (5, 0.25), (6, 0.25), (7, 0.25)], [(4, 0.25), (5, 0.25), (6, 0.25), (7, 0.25)], [(4, 0.25), (5, 0.25), (6, 0.25), (7, 0.25)], [], [], [], []] - alpha values: [0.7000076314, 0.7000076314, 0.7000076314, 0.7000076314, 0.8095842435, 0.8856769793, 0.9000076293, 0.9000076293] - Exponential Moving Average Bonds: [[(4, 0.1229952155), (5, 0.0488576517), (6, 0.0301549898), (7, 0.0233184719)], [(4, 0.292334928), (5, 0.3170474493), (6, 0.32328167), (7, 0.3255605092)], [(4, 0.292334928), (5, 0.3170474493), (6, 0.32328167), (7, 0.3255605092)], [(4, 0.292334928), (5, 0.3170474493), (6, 0.32328167), (7, 0.3255605092)], [], [], [], []] - Dividends: [0.0138551355, 0.2191433029, 0.3287149547, 0.4382866067, 0, 0, 0, 0] - Normalized Server Emission: [0, 0, 0, 0, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] - Server Emission: [0, 0, 0, 0, 49998779, 100000610, 149996337, 200004272] - Normalized Validator Emission: [0.0069275678, 0.1095716513, 0.1643574773, 0.2191433033, 0, 0, 0, 0] - Validator Emission: [6927567, 109571651, 164357477, 219143303, 0, 0, 0, 0] - Normalized Combined Emission: [0.0069275678, 0.1095716513, 0.1643574773, 0.2191433033, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] - Combined Emission: [6927567, 109571651, 164357477, 219143303, 49998779, 100000610, 149996337, 200004272] - Pruning Scores: [0.0069275678, 0.1095716513, 0.1643574773, 0.2191433033, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] + I (=R): [0, 0, 0, 0, 0.0999975582, 0.2000012207, 0.2999926754, 0.4000085455] + B: [[(4, 655), (5, 1310), (6, 1966), (7, 2621)], [(4, 655), (5, 1310), (6, 1966), (7, 2621)], [(4, 655), (5, 1310), (6, 1966), (7, 2621)], [(4, 655), (5, 1310), (6, 1966), (7, 2621)], [], [], [], []] + B (outdatedmask): [[(4, 655), (5, 1310), (6, 1966), (7, 2621)], [(4, 655), (5, 1310), (6, 1966), (7, 2621)], [(4, 655), (5, 1310), (6, 1966), (7, 2621)], [(4, 655), (5, 1310), (6, 1966), (7, 2621)], [], [], [], []] + B: [[(4, 0.0099946593), (5, 0.0199893187), (6, 0.029999237), (7, 0.0399938964)], [(4, 0.0099946593), (5, 0.0199893187), (6, 0.029999237), (7, 0.0399938964)], [(4, 0.0099946593), (5, 0.0199893187), (6, 0.029999237), (7, 0.0399938964)], [(4, 0.0099946593), (5, 0.0199893187), (6, 0.029999237), (7, 0.0399938964)], [], [], [], []] + alphas: [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1] + emaB: [[(4, 0.0089951933), (5, 0.0179903866), (6, 0.0269993132), (7, 0.0359945067)], [(4, 0.018994949), (5, 0.0379905086), (6, 0.0569985807), (7, 0.0759953612)], [(4, 0.018994949), (5, 0.0379905086), (6, 0.0569985807), (7, 0.0759953612)], [(4, 0.018994949), (5, 0.0379905086), (6, 0.0569985807), (7, 0.0759953612)], [], [], [], []] + emaB norm: [[(4, 0.1363320365), (5, 0.1363301442), (6, 0.136363573), (7, 0.1363528532)], [(4, 0.287889321), (5, 0.2878899518), (6, 0.2878788088), (7, 0.287882382)], [(4, 0.287889321), (5, 0.2878899518), (6, 0.2878788088), (7, 0.287882382)], [(4, 0.287889321), (5, 0.2878899518), (6, 0.2878788088), (7, 0.287882382)], [], [], [], []] + total_bonds_per_validator: [0.136349445, 0.2878835173, 0.2878835173, 0.2878835173, 0, 0, 0, 0] + D: [0.0499942757, 0.211112383, 0.3166685747, 0.422224766, 0, 0, 0, 0] + nE: [0.0249971377, 0.1055561914, 0.1583342873, 0.211112383, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] + E: [24997137, 105556191, 158334287, 211112383, 49998779, 100000610, 149996337, 200004272] + P: [0.0249971377, 0.1055561914, 0.1583342873, 0.211112383, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] */ // Expected bonds calculations @@ -1499,10 +1544,10 @@ fn test_bonds_with_liquid_alpha() { // Normalize ΔB: [0.25/7.5, 1.0/7.5, 2.25/7.5, 4.0/7.5] = [0.0333, 0.1333, 0.3, 0.5333] // Final bonds for netuid: [16383, 32767, 49151, 65535] - assert_eq!(bonds[0][4], 65535); // Note: Calculated as explained above - assert_eq!(bonds[1][4], 65535); // Note: Calculated as explained above - assert_eq!(bonds[2][4], 65535); // Note: Calculated as explained above - assert_eq!(bonds[3][4], 65535); // Note: Calculated as explained above + assert_eq!(bonds[0][4], 1247); // Note: Calculated as explained above + assert_eq!(bonds[1][4], 1247); // Note: Calculated as explained above + assert_eq!(bonds[2][4], 1247); // Note: Calculated as explained above + assert_eq!(bonds[3][4], 1247); // Note: Calculated as explained above // === Set self-weight only on val1 let uid = 0; @@ -1521,10 +1566,10 @@ fn test_bonds_with_liquid_alpha() { } let bonds = SubtensorModule::get_bonds(netuid); - assert_eq!(bonds[0][4], 27572); - assert_eq!(bonds[1][4], 65535); - assert_eq!(bonds[2][4], 65535); - assert_eq!(bonds[3][4], 65535); + assert_eq!(bonds[0][4], 1009); + assert_eq!(bonds[1][4], 2257); + assert_eq!(bonds[2][4], 2257); + assert_eq!(bonds[3][4], 2257); // === Set self-weight only on val2 let uid = 1; @@ -1550,42 +1595,38 @@ fn test_bonds_with_liquid_alpha() { Inactive: [false, false, false, false, false, false, false, false] Block at registration: [1, 1, 1, 1, 1, 1, 1, 1] hotkeys: [(0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7)] - Normalised Stake: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] + S: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] validator_permits: [true, true, true, true, true, true, true, true] - max_allowed_validators: 64 + max_allowed_validators: 8 new_validator_permits: [true, true, true, true, true, true, true, true] - Active Stake: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] - Weights: [[(0, 65535)], [(1, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - Weights (permit): [[(0, 65535)], [(1, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - Weights (permit+diag): [[], [], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - Weights (permit+diag+outdate): [[], [], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - Weights (mask+norm): [[], [], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] - R (before): [0, 0, 0, 0, 0.0699982906, 0.1400008542, 0.2099948723, 0.2800059812] + S: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] + W: [[(0, 65535)], [(1, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + W (permit): [[(0, 65535)], [(1, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + W (permit+diag): [[], [], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + W (permit+diag+outdate): [[], [], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] C: [0, 0, 0, 0, 0.0999975584, 0.2000012207, 0.2999926754, 0.400008545] - Clipped Weights: [[], [], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] - Validator Trust: [0, 0, 0.9999999995, 0.9999999995, 0, 0, 0, 0] + W: [[], [], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] + Tv: [0, 0, 0.9999999995, 0.9999999995, 0, 0, 0, 0] R (after): [0, 0, 0, 0, 0.0699982906, 0.1400008542, 0.2099948723, 0.2800059812] T: [0, 0, 0, 0, 1, 1, 1, 1] - Incentive (=Rank): [0, 0, 0, 0, 0.0999975582, 0.2000012207, 0.2999926754, 0.4000085455] - B: [[(4, 27572), (5, 10099), (6, 6112), (7, 4693)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [], [], [], []] - B (outdatedmask): [[(4, 27572), (5, 10099), (6, 6112), (7, 4693)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [], [], [], []] - B (mask+norm): [[(4, 0.1229921), (5, 0.048857303), (6, 0.0301504065), (7, 0.023313694)], [(4, 0.2923359666), (5, 0.3170475655), (6, 0.3232831976), (7, 0.3255621018)], [(4, 0.2923359666), (5, 0.3170475655), (6, 0.3232831976), (7, 0.3255621018)], [(4, 0.2923359666), (5, 0.3170475655), (6, 0.3232831976), (7, 0.3255621018)], [], [], [], []] - alpha values: [0.7000076314, 0.7000076314, 0.7000076314, 0.7000076314, 0.8095842435, 0.8856769793, 0.9000076293, 0.9000076293] - Exponential Moving Average Bonds: [[(4, 0.0728453742), (5, 0.0130473885), (6, 0.0051448268), (7, 0.0031164943)], [(4, 0.1731438267), (5, 0.0846678526), (6, 0.0551646315), (7, 0.0435200238)], [(4, 0.3770053994), (5, 0.4511423793), (6, 0.4698452707), (7, 0.4766817407)], [(4, 0.3770053994), (5, 0.4511423793), (6, 0.4698452707), (7, 0.4766817407)], [], [], [], []] - Dividends: [0.0037682566, 0.0405260534, 0.4095881525, 0.546117537, 0, 0, 0, 0] - Normalized Server Emission: [0, 0, 0, 0, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] - Server Emission: [0, 0, 0, 0, 49998779, 100000610, 149996337, 200004272] - Normalized Validator Emission: [0.0018841282, 0.0202630267, 0.2047940763, 0.2730587684, 0, 0, 0, 0] - Validator Emission: [1884128, 20263026, 204794076, 273058768, 0, 0, 0, 0] - Normalized Combined Emission: [0.0018841282, 0.0202630267, 0.2047940763, 0.2730587684, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] - Combined Emission: [1884128, 20263026, 204794076, 273058768, 49998779, 100000610, 149996337, 200004272] - Pruning Scores: [0.0018841282, 0.0202630267, 0.2047940763, 0.2730587684, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] + I (=R): [0, 0, 0, 0, 0.0999975582, 0.2000012207, 0.2999926754, 0.4000085455] + B: [[(4, 589), (5, 1178), (6, 1769), (7, 2358)], [(4, 1244), (5, 2489), (6, 3735), (7, 4980)], [(4, 1244), (5, 2489), (6, 3735), (7, 4980)], [(4, 1244), (5, 2489), (6, 3735), (7, 4980)], [], [], [], []] + B (outdatedmask): [[(4, 589), (5, 1178), (6, 1769), (7, 2358)], [(4, 1244), (5, 2489), (6, 3735), (7, 4980)], [(4, 1244), (5, 2489), (6, 3735), (7, 4980)], [(4, 1244), (5, 2489), (6, 3735), (7, 4980)], [], [], [], []] + B: [[(4, 0.008987564), (5, 0.0179751278), (6, 0.0269932097), (7, 0.0359807736)], [(4, 0.0189822232), (5, 0.0379797055), (6, 0.0569924468), (7, 0.075989929)], [(4, 0.0189822232), (5, 0.0379797055), (6, 0.0569924468), (7, 0.075989929)], [(4, 0.0189822232), (5, 0.0379797055), (6, 0.0569924468), (7, 0.075989929)], [], [], [], []] + alphas: [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1] + emaB: [[(4, 0.0080888073), (5, 0.016177615), (6, 0.0242938886), (7, 0.0323826962)], [(4, 0.0170840009), (5, 0.0341817348), (6, 0.051293202), (7, 0.068390936)], [(4, 0.0270837566), (5, 0.0541818568), (6, 0.0812924695), (7, 0.1083917904)], [(4, 0.0270837566), (5, 0.0541818568), (6, 0.0812924695), (7, 0.1083917904)], [], [], [], []] + emaB norm: [[(4, 0.1019507758), (5, 0.10192353), (6, 0.102001434), (7, 0.101974368)], [(4, 0.2153255814), (5, 0.2153545555), (6, 0.2153619886), (7, 0.215365714)], [(4, 0.3413618212), (5, 0.341360957), (6, 0.3413182884), (7, 0.3413299588)], [(4, 0.3413618212), (5, 0.341360957), (6, 0.3413182884), (7, 0.3413299588)], [], [], [], []] + total_bonds_per_validator: [0.1019699604, 0.215358351, 0.3413358429, 0.3413358429, 0, 0, 0, 0] + D: [0.034896868, 0.1474028623, 0.3504429725, 0.4672572967, 0, 0, 0, 0] + nE: [0.017448434, 0.073701431, 0.1752214862, 0.2336286483, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] + E: [17448433, 73701431, 175221486, 233628648, 49998779, 100000610, 149996337, 200004272] + P: [0.017448434, 0.073701431, 0.1752214862, 0.2336286483, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] */ - assert_eq!(bonds[0][4], 12662); - assert_eq!(bonds[1][4], 30097); - assert_eq!(bonds[2][4], 65535); - assert_eq!(bonds[3][4], 65535); + assert_eq!(bonds[0][4], 816); + assert_eq!(bonds[1][4], 1827); + assert_eq!(bonds[2][4], 3075); + assert_eq!(bonds[3][4], 3075); }); } @@ -1717,7 +1758,7 @@ fn test_active_stake() { assert_eq!(*i, 0); } for i in bond.iter().take(n as usize).skip((n / 2) as usize) { - assert_eq!(*i, I32F32::from_num(65_535)); // floor(0.5*(2^16-1))/(2^16-1), then max-upscale to 65_535 + assert_eq!(*i, I32F32::from_num(3276)); // floor(0.5*(2^16-1))/(2^16-1), then max-upscale to 65_535 } } let activity_cutoff: u64 = SubtensorModule::get_activity_cutoff(netuid) as u64; @@ -1739,26 +1780,28 @@ fn test_active_stake() { /* current_block: 5002; activity_cutoff: 5000 Last update: [5002, 1, 0, 0]; Inactive: [false, true, true, true]; Block at registration: [0, 0, 0, 0] Normalised Stake: [0.25, 0.25, 0.25, 0.25] - validator_permits: [true, true, true, true]; max_allowed_validators: 4; new_validator_permits: [true, true, true, true] + validator_permits: [true, true, true, true] Active Stake: [1, 0, 0, 0] - W: [[(2, 65535), (3, 65535)], [(2, 65535), (3, 65535)], [], []] - W (permit): [[(2, 65535), (3, 65535)], [(2, 65535), (3, 65535)], [], []] - W (permit+diag): [[(2, 65535), (3, 65535)], [(2, 65535), (3, 65535)], [], []] - W (permit+diag+outdate): [[(2, 65535), (3, 65535)], [(2, 65535), (3, 65535)], [], []] - W (mask+norm): [[(2, 0.5), (3, 0.5)], [(2, 0.5), (3, 0.5)], [], []] - R (before): [0, 0, 0.5, 0.5] - C: [0, 0, 0.5, 0.5] - Clipped W: [[(2, 0.5), (3, 0.5)], [(2, 0.5), (3, 0.5)], [], []] + Weights: [[(2, 65535), (3, 65535)], [(2, 65535), (3, 65535)], [], []] + Weights (permit): [[(2, 65535), (3, 65535)], [(2, 65535), (3, 65535)], [], []] + Weights (permit+diag): [[(2, 65535), (3, 65535)], [(2, 65535), (3, 65535)], [], []] + Weights (permit+diag+outdate): [[(2, 65535), (3, 65535)], [(2, 65535), (3, 65535)], [], []] + Weights (mask+norm): [[(2, 0.5), (3, 0.5)], [(2, 0.5), (3, 0.5)], [], []] + Ranks (before): [0, 0, 0.5, 0.5] + Consensus: [0, 0, 0.5, 0.5] + Clipped Weights: [[(2, 0.5), (3, 0.5)], [(2, 0.5), (3, 0.5)], [], []] Validator Trust: [1, 1, 0, 0] - R (after): [0, 0, 0.5, 0.5] - T: [0, 0, 1, 1] - I (=Rank): [0, 0, 0.5, 0.5] - B: [[(2, 65535), (3, 65535)], [(2, 65535), (3, 65535)], [], []] - B (outdatedmask): [[(2, 65535), (3, 65535)], [(2, 65535), (3, 65535)], [], []] - B (mask+norm): [[(2, 0.5), (3, 0.5)], [(2, 0.5), (3, 0.5)], [], []] - alpha values: [0.1, 0.1, 0.1, 0.1] - emaB: [[(2, 0.5), (3, 0.5)], [(2, 0.5), (3, 0.5)], [], []] - D: [1, 0, 0, 0] + Ranks (after): [0, 0, 0.5, 0.5] + Trust: [0, 0, 1, 1] + Incentive (=Rank): [0, 0, 0.5, 0.5] + Bonds: [[(2, 3276), (3, 3276)], [(2, 3276), (3, 3276)], [], []] + Bonds (outdatedmask): [[(2, 3276), (3, 3276)], [(2, 3276), (3, 3276)], [], []] + Bonds: (mask+norm) [[(2, 0.0499885557), (3, 0.0499885557)], [(2, 0.0499885557), (3, 0.0499885557)], [], []] + Alphas: [0.1, 0.1, 0.1, 0.1] + weights_for_bonds: [[(2, 0.5), (3, 0.5)], [(2, 0.5), (3, 0.5)], [], []] + emaB: [[(2, 0.0949897), (3, 0.0949897)], [(2, 0.0949897), (3, 0.0949897)], [], []] + total_bonds_per_validator: [0.5, 0.5, 0, 0] + Dividends: [1, 0, 0, 0] Normalized Server Emission: [0, 0, 0.25, 0.25] Server Emission: [0, 0, 250000000, 250000000] Normalized Validator Emission: [0.5, 0, 0, 0] @@ -1768,16 +1811,16 @@ fn test_active_stake() { Pruning Scores: [0.5, 0, 0.25, 0.25] */ let bonds = SubtensorModule::get_bonds(netuid); - assert_eq!(SubtensorModule::get_dividends_for_uid(netuid, 0), 65535); // Note D = floor((0.5 * 0.9 + 0.1) * 65_535) - assert_eq!(SubtensorModule::get_emission_for_uid(netuid, 0), 500000000); // Note E = 0.5 * 0.55 * 1_000_000_000 = 275_000_000 (discrepancy) + assert_eq!(SubtensorModule::get_dividends_for_uid(netuid, 0), 65535); + assert_eq!(SubtensorModule::get_emission_for_uid(netuid, 0), 500000000); for server in ((n / 2) as usize)..n as usize { - assert_eq!(bonds[0][server], I32F32::from_num(65_535)); // floor(0.55*(2^16-1))/(2^16-1), then max-upscale + assert_eq!(bonds[0][server], I32F32::from_num(6225)); } for validator in 1..(n / 2) { - assert_eq!(SubtensorModule::get_dividends_for_uid(netuid, validator), 0); // Note D = floor((0.5 * 0.9) * 65_535) - assert_eq!(SubtensorModule::get_emission_for_uid(netuid, validator), 0); // Note E = 0.5 * 0.45 * 1_000_000_000 = 225_000_000 (discrepancy) + assert_eq!(SubtensorModule::get_dividends_for_uid(netuid, validator), 0); + assert_eq!(SubtensorModule::get_emission_for_uid(netuid, validator), 0); for server in ((n / 2) as usize)..n as usize { - assert_eq!(bonds[validator as usize][server], I32F32::from_num(65535)); + assert_eq!(bonds[validator as usize][server], I32F32::from_num(6225)); // floor(0.45*(2^16-1))/(2^16-1), then max-upscale } } @@ -1801,30 +1844,29 @@ fn test_active_stake() { Inactive: [false, false, true, true] Block at registration: [0, 0, 0, 0] hotkeys: [(0, 0), (1, 1), (2, 2), (3, 3)] - ls: tao_weight: 0 Normalised Stake: [0.25, 0.25, 0.25, 0.25] validator_permits: [true, true, true, true] - max_allowed_validators: 4 - new_validator_permits: [true, true, true, true] Active Stake: [0.5, 0.5, 0, 0] - W: [[(2, 65535), (3, 65535)], [(2, 65535), (3, 65535)], [], []] - W (permit): [[(2, 65535), (3, 65535)], [(2, 65535), (3, 65535)], [], []] - W (permit+diag): [[(2, 65535), (3, 65535)], [(2, 65535), (3, 65535)], [], []] - W (permit+diag+outdate): [[(2, 65535), (3, 65535)], [(2, 65535), (3, 65535)], [], []] - W (mask+norm): [[(2, 0.5), (3, 0.5)], [(2, 0.5), (3, 0.5)], [], []] - R (before): [0, 0, 0.5, 0.5] - C: [0, 0, 0.5, 0.5] - Clipped W: [[(2, 0.5), (3, 0.5)], [(2, 0.5), (3, 0.5)], [], []] + Weights: [[(2, 65535), (3, 65535)], [(2, 65535), (3, 65535)], [], []] + Weights (permit): [[(2, 65535), (3, 65535)], [(2, 65535), (3, 65535)], [], []] + Weights (permit+diag): [[(2, 65535), (3, 65535)], [(2, 65535), (3, 65535)], [], []] + Weights (permit+diag+outdate): [[(2, 65535), (3, 65535)], [(2, 65535), (3, 65535)], [], []] + Weights (mask+norm): [[(2, 0.5), (3, 0.5)], [(2, 0.5), (3, 0.5)], [], []] + Ranks (before): [0, 0, 0.5, 0.5] + Consensus: [0, 0, 0.5, 0.5] + Clipped Weights: [[(2, 0.5), (3, 0.5)], [(2, 0.5), (3, 0.5)], [], []] Validator Trust: [1, 1, 0, 0] - R (after): [0, 0, 0.5, 0.5] - T: [0, 0, 1, 1] - I (=Rank): [0, 0, 0.5, 0.5] - B: [[(2, 65535), (3, 65535)], [(2, 65535), (3, 65535)], [], []] - B (outdatedmask): [[(2, 65535), (3, 65535)], [(2, 65535), (3, 65535)], [], []] - B (mask+norm): [[(2, 0.5), (3, 0.5)], [(2, 0.5), (3, 0.5)], [], []] - alpha values: [0.1, 0.1, 0.1, 0.1] - EmaB: [[(2, 0.5), (3, 0.5)], [(2, 0.5), (3, 0.5)], [], []] - D: [0.5, 0.5, 0, 0] + Ranks (after): [0, 0, 0.5, 0.5] + Trust: [0, 0, 1, 1] + Incentive (=Rank): [0, 0, 0.5, 0.5] + Bonds: [[(2, 6225), (3, 6225)], [(2, 6225), (3, 6225)], [], []] + Bonds (outdatedmask): [[(2, 6225), (3, 6225)], [(2, 6225), (3, 6225)], [], []] + Bonds: (mask+norm) [[(2, 0.0949874113), (3, 0.0949874113)], [(2, 0.0949874113), (3, 0.0949874113)], [], []] + Alphas: [0.1, 0.1, 0.1, 0.1] + weights_for_bonds: [[(2, 0.5), (3, 0.5)], [(2, 0.5), (3, 0.5)], [], []] + emaB: [[(2, 0.13548867), (3, 0.13548867)], [(2, 0.13548867), (3, 0.13548867)], [], []] + total_bonds_per_validator: [0.5, 0.5, 0, 0] + Dividends: [0.5, 0.5, 0, 0] Normalized Server Emission: [0, 0, 0.25, 0.25] Server Emission: [0, 0, 250000000, 250000000] Normalized Validator Emission: [0.25, 0.25, 0, 0] @@ -1834,15 +1876,15 @@ fn test_active_stake() { Pruning Scores: [0.25, 0.25, 0.25, 0.25] */ let bonds = SubtensorModule::get_bonds(netuid); - assert_eq!(SubtensorModule::get_dividends_for_uid(netuid, 0), 32767); // Note D = floor((0.55 * 0.9 + 0.5 * 0.1) * 65_535) - assert_eq!(SubtensorModule::get_emission_for_uid(netuid, 0), 250000000); // Note E = 0.5 * (0.55 * 0.9 + 0.5 * 0.1) * 1_000_000_000 = 272_500_000 (discrepancy) + assert_eq!(SubtensorModule::get_dividends_for_uid(netuid, 0), 32767); + assert_eq!(SubtensorModule::get_emission_for_uid(netuid, 0), 250000000); for server in ((n / 2) as usize)..n as usize { - assert_eq!(bonds[0][server], I32F32::from_num(65_535)); // floor((0.55 * 0.9 + 0.5 * 0.1)*(2^16-1))/(2^16-1), then max-upscale + assert_eq!(bonds[0][server], I32F32::from_num(8879)); } - assert_eq!(SubtensorModule::get_dividends_for_uid(netuid, 1), 32767); // Note D = floor((0.45 * 0.9 + 0.5 * 0.1) * 65_535) - assert_eq!(SubtensorModule::get_emission_for_uid(netuid, 1), 250000000); // Note E = 0.5 * (0.45 * 0.9 + 0.5 * 0.1) * 1_000_000_000 = 227_500_000 (discrepancy) + assert_eq!(SubtensorModule::get_dividends_for_uid(netuid, 1), 32767); + assert_eq!(SubtensorModule::get_emission_for_uid(netuid, 1), 250000000); for server in ((n / 2) as usize)..n as usize { - assert_eq!(bonds[1][server], I32F32::from_num(65_535)); // floor((0.45 * 0.9 + 0.5 * 0.1)/(0.55 * 0.9 + 0.5 * 0.1)*(2^16-1)) + assert_eq!(bonds[1][server], I32F32::from_num(8879)); } }); } @@ -2029,8 +2071,8 @@ fn test_outdated_weights() { let bonds = SubtensorModule::get_bonds(netuid); assert_eq!(SubtensorModule::get_dividends_for_uid(netuid, 0), 32767); // Note D = floor(0.5 * 65_535) assert_eq!(SubtensorModule::get_emission_for_uid(netuid, 0), 250000000); // Note E = 0.5 * 0.5 * 1_000_000_000 = 249311245 - assert_eq!(bonds[0][2], I32F32::from_num(65_535)); // floor(0.5*(2^16-1))/(2^16-1), then max-upscale - assert_eq!(bonds[0][3], I32F32::from_num(65_535)); // only uid0 has updated weights for new reg + assert_eq!(bonds[0][2], I32F32::from_num(8300)); + assert_eq!(bonds[0][3], I32F32::from_num(1965)); }); } @@ -2814,15 +2856,21 @@ fn test_compute_ema_bonds_sparse() { ]; let alpha = vec![I32F32::from_num(0.9), I32F32::from_num(0.8)]; + // Expected values + // EMA calculation for each bond: + // EMA = alpha * bond_delta + (1 - alpha) * bond + // For bond (0, 0): + // EMA = 0.9 * 0.1 + (1 - 0.9) * 0.5 = 0.09 + 0.05 = 0.14 + // For bond (0, 1): + // EMA = 0.8 * 0.2 + (1 - 0.8) * 0.6 = 0.16 + 0.12 = 0.28 + // For bond (1, 0): + // EMA = 0.9 * 0.3 + (1 - 0.9) * 0.7 = 0.27 + 0.07 = 0.34 + // For bond (1, 1): + // EMA = 0.8 * 0.4 + (1 - 0.8) * 0.8 = 0.32 + 0.16 = 0.48 + let expected_ema_bonds = vec![ - vec![ - (0, I32F32::from_num(0.130999)), - (1, I32F32::from_num(0.247999)), - ], - vec![ - (0, I32F32::from_num(0.312999)), - (1, I32F32::from_num(0.415999)), - ], + vec![(0, I32F32::from_num(0.14)), (1, I32F32::from_num(0.28))], + vec![(0, I32F32::from_num(0.34)), (1, I32F32::from_num(0.48))], ]; // Call the function @@ -3354,25 +3402,53 @@ fn run_epoch(netuid: u16, sparse: bool) { } } -fn run_epoch_check_bonds(netuid: u16, sparse: bool, target_bonds: &Vec>) { +fn run_epoch_and_check_bonds_dividends( + netuid: u16, + sparse: bool, + target_bonds: &[Vec], + target_dividends: &[f32], +) { run_epoch(netuid, sparse); let bonds = SubtensorModule::get_bonds(netuid); + let dividends = SubtensorModule::get_dividends(netuid); + // Check the bonds // server 1 assert_eq!(bonds[0][3], target_bonds[0][0]); assert_eq!(bonds[1][3], target_bonds[1][0]); assert_eq!(bonds[2][3], target_bonds[2][0]); - // server 2 assert_eq!(bonds[0][4], target_bonds[0][1]); assert_eq!(bonds[1][4], target_bonds[1][1]); assert_eq!(bonds[2][4], target_bonds[2][1]); + + // Check the dividends + let epsilon = I32F32::from_num(1e-3); + for (dividend, target_dividend) in dividends.iter().zip(target_dividends.iter()) { + assert_approx_eq( + u16_proportion_to_fixed(*dividend), + fixed(*target_dividend), + epsilon, + ); + } +} + +fn set_yuma_4_weights(netuid: u16, weights: Vec>) { + for (uid, weight) in weights.iter().enumerate() { + assert_ok!(SubtensorModule::set_weights( + RuntimeOrigin::signed(U256::from(uid as u64)), + netuid, + vec![3, 4], + weight.to_vec(), + 0 + )); + } } #[test] fn test_yuma_4_kappa_moves_first() { new_test_ext(1).execute_with(|| { - let sparse: bool = true; + let sparse: bool = false; let n: u16 = 5; // 3 validators, 2 servers let netuid: u16 = 1; let max_stake: u64 = 8; @@ -3383,7 +3459,7 @@ fn test_yuma_4_kappa_moves_first() { let stakes: Vec = vec![8, 1, 1, 0, 0]; setup_yuma_4_scenario(netuid, n, sparse, max_stake, stakes); - let targets_bonds = vec![ + let targets_bonds = [ vec![ vec![656, 0], vec![656, 0], @@ -3421,69 +3497,50 @@ fn test_yuma_4_kappa_moves_first() { ], ]; - for epoch in 0..5 { + let targets_dividends = [ + vec![0.8000, 0.1000, 0.1000, 0.0000, 0.0000], + vec![1.0000, 0.0000, 0.0000, 0.0000, 0.0000], + vec![0.9409, 0.0591, 0.0000, 0.0000, 0.0000], + vec![0.8882, 0.0744, 0.0374, 0.0000, 0.0000], + vec![0.8640, 0.0814, 0.0545, 0.0000, 0.0000], + vec![0.8502, 0.0854, 0.0644, 0.0000, 0.0000], + ]; + + for (epoch, (target_bonds, target_dividends)) in targets_bonds + .iter() + .zip(targets_dividends.iter()) + .enumerate() + { match epoch { 0 => { // Initially, consensus is achieved by all Validators - for uid in [0, 1, 2] { - assert_ok!(SubtensorModule::set_weights( - RuntimeOrigin::signed(U256::from(uid)), - netuid, - vec![3, 4], - vec![u16::MAX, 0], - 0 - )); - } + set_yuma_4_weights(netuid, vec![vec![u16::MAX, 0]; 3]); } 1 => { // Validator A -> Server 2 // Validator B -> Server 1 // Validator C -> Server 1 - for (uid, weights) in [vec![0, u16::MAX], vec![u16::MAX, 0], vec![u16::MAX, 0]] - .iter() - .enumerate() - { - assert_ok!(SubtensorModule::set_weights( - RuntimeOrigin::signed(U256::from(uid)), - netuid, - vec![3, 4], - weights.to_vec(), - 0 - )); - } + set_yuma_4_weights( + netuid, + vec![vec![0, u16::MAX], vec![u16::MAX, 0], vec![u16::MAX, 0]], + ); } 2 => { // Validator A -> Server 2 // Validator B -> Server 2 // Validator C -> Server 1 - for (uid, weights) in [vec![0, u16::MAX], vec![0, u16::MAX], vec![u16::MAX, 0]] - .iter() - .enumerate() - { - assert_ok!(SubtensorModule::set_weights( - RuntimeOrigin::signed(U256::from(uid)), - netuid, - vec![3, 4], - weights.to_vec(), - 0 - )); - } + set_yuma_4_weights( + netuid, + vec![vec![0, u16::MAX], vec![0, u16::MAX], vec![u16::MAX, 0]], + ); } 3 => { // Subsequent epochs All validators -> Server 2 - for uid in [0, 1, 2] { - assert_ok!(SubtensorModule::set_weights( - RuntimeOrigin::signed(U256::from(uid)), - netuid, - vec![3, 4], - vec![0, u16::MAX], - 0 - )); - } + set_yuma_4_weights(netuid, vec![vec![0, u16::MAX]; 3]); } _ => {} }; - run_epoch_check_bonds(netuid, sparse, &targets_bonds[epoch]); + run_epoch_and_check_bonds_dividends(netuid, sparse, target_bonds, target_dividends); } }) } @@ -3502,7 +3559,7 @@ fn test_yuma_4_kappa_moves_second() { let stakes: Vec = vec![8, 1, 1, 0, 0]; setup_yuma_4_scenario(netuid, n, sparse, max_stake, stakes); - let targets_bonds = vec![ + let targets_bonds = [ vec![ vec![656, 0], vec![656, 0], @@ -3539,70 +3596,50 @@ fn test_yuma_4_kappa_moves_second() { vec![0, 0], ], ]; + let targets_dividends = [ + vec![0.8000, 0.1000, 0.1000], + vec![0.8423, 0.0524, 0.1053], + vec![0.4233, 0.5767, 0.0000], + vec![0.5545, 0.4107, 0.0348], + vec![0.6184, 0.3298, 0.0518], + vec![0.6562, 0.2820, 0.0618], + ]; - for epoch in 0..5 { + for (epoch, (target_bonds, target_dividends)) in targets_bonds + .iter() + .zip(targets_dividends.iter()) + .enumerate() + { match epoch { 0 => { // Initially, consensus is achieved by all Validators - for uid in [0, 1, 2] { - assert_ok!(SubtensorModule::set_weights( - RuntimeOrigin::signed(U256::from(uid)), - netuid, - vec![3, 4], - vec![u16::MAX, 0], - 0 - )); - } + set_yuma_4_weights(netuid, vec![vec![u16::MAX, 0]; 3]); } 1 => { // Validator A -> Server 1 // Validator B -> Server 2 // Validator C -> Server 1 - for (uid, weights) in [vec![u16::MAX, 0], vec![0, u16::MAX], vec![u16::MAX, 0]] - .iter() - .enumerate() - { - assert_ok!(SubtensorModule::set_weights( - RuntimeOrigin::signed(U256::from(uid)), - netuid, - vec![3, 4], - weights.to_vec(), - 0 - )); - } + set_yuma_4_weights( + netuid, + vec![vec![u16::MAX, 0], vec![0, u16::MAX], vec![u16::MAX, 0]], + ); } 2 => { // Validator A -> Server 2 // Validator B -> Server 2 // Validator C -> Server 1 - for (uid, weights) in [vec![0, u16::MAX], vec![0, u16::MAX], vec![u16::MAX, 0]] - .iter() - .enumerate() - { - assert_ok!(SubtensorModule::set_weights( - RuntimeOrigin::signed(U256::from(uid)), - netuid, - vec![3, 4], - weights.to_vec(), - 0 - )); - } + set_yuma_4_weights( + netuid, + vec![vec![0, u16::MAX], vec![0, u16::MAX], vec![u16::MAX, 0]], + ); } 3 => { // Subsequent epochs All validators -> Server 2 - for uid in [0, 1, 2] { - assert_ok!(SubtensorModule::set_weights( - RuntimeOrigin::signed(U256::from(uid)), - netuid, - vec![3, 4], - vec![0, u16::MAX], - 0 - )); - } + set_yuma_4_weights(netuid, vec![vec![0, u16::MAX]; 3]); } _ => {} }; - run_epoch_check_bonds(netuid, sparse, &targets_bonds[epoch]); + run_epoch_and_check_bonds_dividends(netuid, sparse, target_bonds, target_dividends); } }) } @@ -3621,77 +3658,110 @@ fn test_yuma_4_kappa_moves_last() { let stakes: Vec = vec![8, 1, 1, 0, 0]; setup_yuma_4_scenario(netuid, n, sparse, max_stake, stakes); - let targets_bonds = vec![ + let targets_bonds = [ vec![vec![656, 0], vec![656, 0], vec![656, 0]], vec![vec![1305, 0], vec![649, 6553], vec![1305, 0]], vec![vec![1947, 0], vec![642, 12451], vec![1291, 6553]], vec![vec![1752, 656], vec![577, 12982], vec![1161, 7143]], vec![vec![1576, 1305], vec![519, 13508], vec![1044, 7727]], ]; + let targets_dividends = [ + vec![0.8000, 0.1000, 0.1000], + vec![0.8423, 0.0524, 0.1053], + vec![0.8895, 0.0367, 0.0738], + vec![0.2067, 0.5117, 0.2816], + vec![0.3294, 0.4265, 0.2440], + vec![0.4108, 0.3701, 0.2191], + ]; - for epoch in 0..5 { + for (epoch, (target_bonds, target_dividends)) in targets_bonds + .iter() + .zip(targets_dividends.iter()) + .enumerate() + { match epoch { 0 => { // Initially, consensus is achieved by all Validators - for uid in [0, 1, 2] { - assert_ok!(SubtensorModule::set_weights( - RuntimeOrigin::signed(U256::from(uid)), - netuid, - vec![3, 4], - vec![u16::MAX, 0], - 0 - )); - } + set_yuma_4_weights(netuid, vec![vec![u16::MAX, 0]; 3]); } 1 => { // Validator A -> Server 1 // Validator B -> Server 2 // Validator C -> Server 1 - for (uid, weights) in [vec![u16::MAX, 0], vec![0, u16::MAX], vec![u16::MAX, 0]] - .iter() - .enumerate() - { - assert_ok!(SubtensorModule::set_weights( - RuntimeOrigin::signed(U256::from(uid)), - netuid, - vec![3, 4], - weights.to_vec(), - 0 - )); - } + set_yuma_4_weights( + netuid, + vec![vec![u16::MAX, 0], vec![0, u16::MAX], vec![u16::MAX, 0]], + ); } 2 => { // Validator A -> Server 1 // Validator B -> Server 2 // Validator C -> Server 2 - for (uid, weights) in [vec![u16::MAX, 0], vec![0, u16::MAX], vec![0, u16::MAX]] - .iter() - .enumerate() - { - assert_ok!(SubtensorModule::set_weights( - RuntimeOrigin::signed(U256::from(uid)), - netuid, - vec![3, 4], - weights.to_vec(), - 0 - )); - } + set_yuma_4_weights( + netuid, + vec![vec![u16::MAX, 0], vec![0, u16::MAX], vec![0, u16::MAX]], + ); } 3 => { // Subsequent epochs All validators -> Server 2 - for uid in [0, 1, 2] { - assert_ok!(SubtensorModule::set_weights( - RuntimeOrigin::signed(U256::from(uid)), - netuid, - vec![3, 4], - vec![0, u16::MAX], - 0 - )); - } + set_yuma_4_weights(netuid, vec![vec![0, u16::MAX]; 3]); } _ => {} }; - run_epoch_check_bonds(netuid, sparse, &targets_bonds[epoch]); + run_epoch_and_check_bonds_dividends(netuid, sparse, target_bonds, target_dividends); + } + }) +} + +#[test] +fn test_yuma_4_one_epoch_switch() { + new_test_ext(1).execute_with(|| { + let sparse: bool = true; + let n: u16 = 5; // 3 validators, 2 servers + let netuid: u16 = 1; + let max_stake: u64 = 8; + + // Equal stake validators + let stakes: Vec = vec![33, 33, 34, 0, 0]; + + setup_yuma_4_scenario(netuid, n, sparse, max_stake, stakes); + + let targets_bonds = [ + vec![vec![656, 0], vec![656, 0], vec![656, 0]], + vec![vec![1305, 0], vec![1305, 0], vec![1305, 0]], + vec![vec![1291, 6553], vec![1947, 0], vec![1947, 0]], + vec![vec![1934, 5897], vec![2583, 0], vec![2583, 0]], + vec![vec![2570, 5307], vec![3213, 0], vec![3213, 0]], + ]; + let targets_dividends = [ + vec![0.33, 0.33, 0.34, 0., 0.], + vec![0.33, 0.33, 0.34, 0., 0.], + vec![0.246_231_48, 0.371_259_12, 0.382_509_4, 0., 0.], + vec![0.269_393_1, 0.359_851_15, 0.370_755_73, 0., 0.], + vec![0.282_665_13, 0.353_314_2, 0.364_020_68, 0., 0.], + ]; + + for (epoch, (target_bonds, target_dividends)) in targets_bonds + .iter() + .zip(targets_dividends.iter()) + .enumerate() + { + match epoch { + 2 => { + // Validator A -> Server 2 + // Validator B -> Server 1 + // Validator C -> Server 1 + set_yuma_4_weights( + netuid, + vec![vec![0, u16::MAX], vec![u16::MAX, 0], vec![u16::MAX, 0]], + ); + } + _ => { + // All validators -> Server 1 + set_yuma_4_weights(netuid, vec![vec![u16::MAX, 0]; 3]); + } + }; + run_epoch_and_check_bonds_dividends(netuid, sparse, target_bonds, target_dividends); } }) } diff --git a/pallets/subtensor/src/tests/math.rs b/pallets/subtensor/src/tests/math.rs index 1ab40869fe..b12e84852a 100644 --- a/pallets/subtensor/src/tests/math.rs +++ b/pallets/subtensor/src/tests/math.rs @@ -1256,6 +1256,26 @@ fn test_math_mat_vec_mul() { assert_mat_compare(&result, &target, I32F32::from_num(0)); } +#[test] +fn test_math_mat_vec_mul_sparse() { + let matrix: Vec = vec![1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12.]; + let matrix = vec_to_sparse_mat_fixed(&matrix, 4, false); + let vector: Vec = vec_to_fixed(&[1., 2., 3.]); + let target: Vec = vec![1., 4., 9., 4., 10., 18., 7., 16., 27., 10., 22., 36.]; + let target = vec_to_sparse_mat_fixed(&target, 4, false); + let result = mat_vec_mul_sparse(&matrix, &vector); + assert_sparse_mat_compare(&result, &target, I32F32::from_num(0)); + let vector_one: Vec = vec_to_fixed(&[1., 0., 0.]); + let target: Vec = vec![1., 0., 0., 4., 0., 0., 7., 0., 0., 10., 0., 0.]; + let target = vec_to_sparse_mat_fixed(&target, 4, false); + let result = mat_vec_mul_sparse(&matrix, &vector_one); + assert_sparse_mat_compare(&result, &target, I32F32::from_num(0)); + let vector_empty: Vec = vec_to_fixed(&[]); + let result = mat_vec_mul_sparse(&matrix, &vector_empty); + let target = vec![vec![]; 4]; + assert_sparse_mat_compare(&result, &target, I32F32::from_num(0)); +} + #[test] fn test_math_row_hadamard() { let vector: Vec = vec_to_fixed(&[1., 2., 3., 4.]); @@ -2156,19 +2176,11 @@ fn test_math_mat_ema() { let old = vec_to_mat_fixed(&old, 4, false); let new = vec_to_mat_fixed(&new, 4, false); let target = vec_to_mat_fixed(&target, 4, false); - let result = mat_ema_alpha_vec(&new, &old, &vec![I32F32::from_num(0.1); old.len()]); - assert_mat_compare(&result, &target, I32F32::from_num(0.000001)); - let old: Vec = vec![1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12.]; - let new: Vec = vec![ - 10., 20., 30., 40., 50., 60., 70., 80., 90., 100., 110., 120., + let result = mat_ema_alpha_vec(&new, &old, &[I32F32::from_num(0); 3]); + assert_mat_compare(&result, &target, I32F32::from_num(1e-4)); + let old: Vec = vec![ + 0.001, 0.002, 0.003, 0.004, 0.05, 0.006, 0.007, 0.008, 0.009, 0.010, 0.011, 0.012, ]; - let target: Vec = vec![1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12.]; - let old = vec_to_mat_fixed(&old, 4, false); - let new = vec_to_mat_fixed(&new, 4, false); - let target = vec_to_mat_fixed(&target, 4, false); - let result = mat_ema_alpha_vec(&new, &old, &vec![I32F32::from_num(0); old.len()]); - assert_mat_compare(&result, &target, I32F32::from_num(0.000001)); - let old: Vec = vec![1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12.]; let new: Vec = vec![ 0.1, 0.2, 3., 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.10, 0.11, 0.12, ]; @@ -2179,8 +2191,8 @@ fn test_math_mat_ema() { let old = vec_to_mat_fixed(&old, 4, false); let new = vec_to_mat_fixed(&new, 4, false); let target = vec_to_mat_fixed(&target, 4, false); - let result = mat_ema_alpha_vec(&new, &old, &vec![I32F32::from_num(1); old.len()]); - assert_mat_compare(&result, &target, I32F32::from_num(0.000001)); + let result = mat_ema_alpha_vec(&new, &old, &[I32F32::from_num(1); 3]); + assert_mat_compare(&result, &target, I32F32::from_num(1e-4)); } #[test] @@ -2190,7 +2202,7 @@ fn test_math_sparse_mat_ema() { ]; let new: Vec = vec![1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12.]; let target: Vec = vec![ - 0.1, 0.2, 1., 0.0759, 0.095, 0.11399, 0.133, 0.15199, 0.171, 0.19, 0.20899, 0.22799, + 0.19, 0.38, 1., 0.43599, 0.545, 0.65399, 0.763, 0.87199, 0.981, 1., 1., 1., ]; let old = vec_to_sparse_mat_fixed(&old, 4, false); let new = vec_to_sparse_mat_fixed(&new, 4, false); @@ -2204,22 +2216,14 @@ fn test_math_sparse_mat_ema() { 0.1, 0.2, 3., 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.10, 0.11, 0.12, ]; let target: Vec = vec![ - 0.0019, 0.003799, 0.032699, 0.00399, 0.0455, 0.00599, 0.007, 0.008, 0.00899, 0.0099, - 0.01099, 0.01199, + 0.0109, 0.0218, 0.30270, 0.007599, 0.05, 0.01139, 0.0133, 0.01519, 0.017, 0.01899, 0.02089, + 0.0227, ]; let old = vec_to_sparse_mat_fixed(&old, 4, false); let new = vec_to_sparse_mat_fixed(&new, 4, false); let target = vec_to_sparse_mat_fixed(&target, 4, false); let result = mat_ema_alpha_vec_sparse(&new, &old, &vec![I32F32::from_num(0.1); old.len()]); - assert_sparse_mat_compare(&result, &target, I32F32::from_num(0.000001)); - let old: Vec = vec![0., 2., 3., 4., 0., 6., 7., 8., 0., 10., 11., 12.]; - let new: Vec = vec![10., 20., 0., 40., 0., 60., 0., 80., 90., 100., 110., 120.]; - let target: Vec = vec![1., 3.8, 2.7, 7.6, 0., 11.4, 6.3, 15.2, 9., 19., 20.9, 22.8]; - let old = vec_to_sparse_mat_fixed(&old, 4, false); - let new = vec_to_sparse_mat_fixed(&new, 4, false); - let target = vec_to_sparse_mat_fixed(&target, 4, false); - let result = mat_ema_alpha_vec_sparse(&new, &old, &vec![I32F32::from_num(0.1); old.len()]); - assert_sparse_mat_compare(&result, &target, I32F32::from_num(0.000001)); + assert_sparse_mat_compare(&result, &target, I32F32::from_num(1e-4)); let old: Vec = vec![0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]; let new: Vec = vec![ 0.1, 0.2, 3., 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.10, 0.11, 0.12, @@ -2227,12 +2231,11 @@ fn test_math_sparse_mat_ema() { let target: Vec = vec![ 0.01, 0.02, 0.3, 0.00399, 0.005, 0.00599, 0.007, 0.00799, 0.009, 0.01, 0.011, 0.01199, ]; - let old = vec_to_sparse_mat_fixed(&old, 4, false); let new = vec_to_sparse_mat_fixed(&new, 4, false); let target = vec_to_sparse_mat_fixed(&target, 4, false); let result = mat_ema_alpha_vec_sparse(&new, &old, &vec![I32F32::from_num(0.1); old.len()]); - assert_sparse_mat_compare(&result, &target, I32F32::from_num(0.000001)); + assert_sparse_mat_compare(&result, &target, I32F32::from_num(1e-4)); let old: Vec = vec![0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]; let new: Vec = vec![0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]; let target: Vec = vec![0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]; @@ -2240,7 +2243,7 @@ fn test_math_sparse_mat_ema() { let new = vec_to_sparse_mat_fixed(&new, 4, false); let target = vec_to_sparse_mat_fixed(&target, 4, false); let result = mat_ema_alpha_vec_sparse(&new, &old, &vec![I32F32::from_num(0.1); old.len()]); - assert_sparse_mat_compare(&result, &target, I32F32::from_num(0.000001)); + assert_sparse_mat_compare(&result, &target, I32F32::from_num(1e-4)); let old: Vec = vec![1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]; let new: Vec = vec![0., 0., 0., 0., 2., 0., 0., 0., 0., 0., 0., 0.]; let target: Vec = vec![0.9, 0., 0., 0., 0.2, 0., 0., 0., 0., 0., 0., 0.]; @@ -2248,7 +2251,7 @@ fn test_math_sparse_mat_ema() { let new = vec_to_sparse_mat_fixed(&new, 4, false); let target = vec_to_sparse_mat_fixed(&target, 4, false); let result = mat_ema_alpha_vec_sparse(&new, &old, &vec![I32F32::from_num(0.1); old.len()]); - assert_sparse_mat_compare(&result, &target, I32F32::from_num(0.000001)); + assert_sparse_mat_compare(&result, &target, I32F32::from_num(1e-4)); } #[test] From 054f4729ddaeeb9000ec1431b353ec64f2ea8dd4 Mon Sep 17 00:00:00 2001 From: Andreea Popescu Date: Thu, 20 Feb 2025 06:19:10 +0000 Subject: [PATCH 22/45] rebase --- pallets/subtensor/src/epoch/math.rs | 5 --- scripts/map_consensus.py | 58 ++++++++++++++++++----------- 2 files changed, 36 insertions(+), 27 deletions(-) diff --git a/pallets/subtensor/src/epoch/math.rs b/pallets/subtensor/src/epoch/math.rs index 0b5c509512..abb0dc7737 100644 --- a/pallets/subtensor/src/epoch/math.rs +++ b/pallets/subtensor/src/epoch/math.rs @@ -90,11 +90,6 @@ pub fn vec_fixed_proportions_to_fixed(vec: Vec) -> Vec { vec.into_iter().map(fixed_proportion_to_fixed).collect() } -#[allow(dead_code)] -pub fn vec_u16_proportions_to_fixed(vec: Vec) -> Vec { - vec.into_iter().map(u16_proportion_to_fixed).collect() -} - #[allow(dead_code)] pub fn vec_fixed_proportions_to_u16(vec: Vec) -> Vec { vec.into_iter().map(fixed_proportion_to_u16).collect() diff --git a/scripts/map_consensus.py b/scripts/map_consensus.py index 8d022f8e11..1d09207bf3 100644 --- a/scripts/map_consensus.py +++ b/scripts/map_consensus.py @@ -16,7 +16,7 @@ def extract_data(filepath): A list of lists containing the numerical data, or None if an error occurs. """ try: - with open(filepath, 'r') as f: + with open(filepath, "r") as f: content = f.read() except FileNotFoundError: print(f"Error: File not found at {filepath}") @@ -31,8 +31,10 @@ def extract_data(filepath): # + Matches the previous group (number and comma) one or more times. # [0-9.]+ Matches the last number in the list. # \] Matches the closing square bracket. - - list_pattern = r'\[(?:[0-9.]+,\s*)+[0-9.]+\]' # Regular expression to match data rows + + list_pattern = ( + r"\[(?:[0-9.]+,\s*)+[0-9.]+\]" + ) # Regular expression to match data rows matches = re.findall(list_pattern, content) if not matches: @@ -45,10 +47,10 @@ def extract_data(filepath): # Extract numerical values from the matched string. # 1. match[1:-1]: Removes the square brackets from the beginning and end. # 2. .split(','): Splits the string into a list of strings at each comma. - # 3. [float(x.strip()) for x in ...]: Converts each string to a float + # 3. [float(x.strip()) for x in ...]: Converts each string to a float # after removing leading/trailing whitespace. - - row = [float(x.strip()) for x in match[1:-1].split(',')] + + row = [float(x.strip()) for x in match[1:-1].split(",")] data.append(row) except ValueError: print(f"Warning: Skipping invalid data row: {match}") @@ -68,8 +70,14 @@ def visualize_data(emission_data, output_filename="consensus_plot.svg"): avg_weight_devs = {} # Process the data to organize it by major stake - for major_stake, major_weight, minor_weight, avg_weight_dev, major_ratio in emission_data: - major_stake_str = f'{major_stake:.2f}' + for ( + major_stake, + major_weight, + minor_weight, + avg_weight_dev, + major_ratio, + ) in emission_data: + major_stake_str = f"{major_stake:.2f}" maj_idx, min_idx = int(round(50 * major_weight)), int(round(50 * minor_weight)) avg_weight_devs.setdefault(major_stake_str, np.zeros((51, 51))) @@ -78,46 +86,52 @@ def visualize_data(emission_data, output_filename="consensus_plot.svg"): major_ratios.setdefault(major_stake_str, np.zeros((51, 51))) major_ratios[major_stake_str][maj_idx][min_idx] = major_ratio - # Create the meshgrid for the contour plot x = np.linspace(0, 1, 51) y = np.linspace(0, 1, 51) - x, y = np.meshgrid(x, y, indexing='ij') + x, y = np.meshgrid(x, y, indexing="ij") # Set up the plot fig = plt.figure(figsize=(6, 6), dpi=70) ax = fig.gca() ax.set_xticks(np.arange(0, 1, 0.05)) - ax.set_yticks(np.arange(0, 1., 0.05)) - ax.set_xticklabels([f'{_:.2f}'[1:] for _ in np.arange(0, 1., 0.05)]) + ax.set_yticks(np.arange(0, 1.0, 0.05)) + ax.set_xticklabels([f"{_:.2f}"[1:] for _ in np.arange(0, 1.0, 0.05)]) plt.grid(linestyle="dotted", color=[0.85, 0.85, 0.85]) - # Define stakes and colors for contour lines - isolate = ['0.60'] # Stakes to highlight + isolate = ["0.60"] # Stakes to highlight stakes = [0.51, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95, 0.99] colors = cm.viridis(np.linspace(0, 1, len(stakes) + 1)) # Create contour lines for each stake for i, stake in enumerate(stakes): - contours = plt.contour(x, y, major_ratios[f'{stake:.2f}'], levels=[0., stake], colors=[colors[i + 1]]) - if f'{stake:.2f}' in isolate: - contours.collections[1].set_linewidth(3) # Highlight isolated stake + contours = plt.contour( + x, + y, + major_ratios[f"{stake:.2f}"], + levels=[0.0, stake], + colors=[colors[i + 1]], + ) + if f"{stake:.2f}" in isolate: + contours.collections[1].set_linewidth(3) # Highlight isolated stake plt.clabel(contours, inline=True, fontsize=10) # Add title and labels - plt.title(f'Major emission [$stake_{{maj}}=emission_{{maj}}$ retention lines]') - plt.ylabel('Minor self-weight') - plt.xlabel('Major self-weight') + plt.title(f"Major emission [$stake_{{maj}}=emission_{{maj}}$ retention lines]") + plt.ylabel("Minor self-weight") + plt.xlabel("Major self-weight") # Save the plot - plt.savefig(output_filename, format='svg') + plt.savefig(output_filename, format="svg") print(f"Plot saved to {output_filename}") if __name__ == "__main__": if len(sys.argv) < 2: - print("Usage: python scripts/map_consensus.py [optional_output_filename]") + print( + "Usage: python scripts/map_consensus.py [optional_output_filename]" + ) sys.exit(1) filepath = sys.argv[1] From c5497bec1e3a720bda63e77a1c43210b787f0a62 Mon Sep 17 00:00:00 2001 From: Andreea Popescu Date: Mon, 17 Mar 2025 13:32:38 +0000 Subject: [PATCH 23/45] cargo fmt --- pallets/subtensor/src/tests/consensus.rs | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/pallets/subtensor/src/tests/consensus.rs b/pallets/subtensor/src/tests/consensus.rs index bb8175120b..2e576572cc 100644 --- a/pallets/subtensor/src/tests/consensus.rs +++ b/pallets/subtensor/src/tests/consensus.rs @@ -8,10 +8,10 @@ use super::mock::*; use crate::*; use frame_support::assert_ok; -use rand::{distributions::Uniform, rngs::StdRng, seq::SliceRandom, thread_rng, Rng, SeedableRng}; +use rand::{Rng, SeedableRng, distributions::Uniform, rngs::StdRng, seq::SliceRandom, thread_rng}; use sp_core::U256; use std::time::Instant; -use substrate_fixed::transcendental::{cos, ln, sqrt, PI}; +use substrate_fixed::transcendental::{PI, cos, ln, sqrt}; use substrate_fixed::types::{I32F32, I64F64}; pub fn fixed(val: f32) -> I32F32 { @@ -319,11 +319,7 @@ fn split_graph( .iter() .map(|x: &I32F32| { let v: I32F32 = (stddev * x) + one; - if v < zero { - zero - } else { - v - } + if v < zero { zero } else { v } }) .collect(); inplace_normalize(&mut sample); @@ -348,11 +344,7 @@ fn split_graph( .iter() .map(|x: &I32F32| { let v: I32F32 = (weight_stddev * x) + one; - if v < zero { - zero - } else { - v - } + if v < zero { zero } else { v } }) .collect(); inplace_normalize(&mut sample); From e18b9dce08b7a082d0a81d013bd353df29111a64 Mon Sep 17 00:00:00 2001 From: Andreea Popescu Date: Wed, 19 Mar 2025 17:16:22 +0000 Subject: [PATCH 24/45] liquid alpha 2 impl --- pallets/subtensor/src/epoch/math.rs | 216 +++++++++++++--- pallets/subtensor/src/epoch/run_epoch.rs | 299 ++++++++++++++++------- 2 files changed, 388 insertions(+), 127 deletions(-) diff --git a/pallets/subtensor/src/epoch/math.rs b/pallets/subtensor/src/epoch/math.rs index abb0dc7737..e8c7919fa9 100644 --- a/pallets/subtensor/src/epoch/math.rs +++ b/pallets/subtensor/src/epoch/math.rs @@ -95,6 +95,18 @@ pub fn vec_fixed_proportions_to_u16(vec: Vec) -> Vec { vec.into_iter().map(fixed_proportion_to_u16).collect() } +#[allow(dead_code)] +pub fn mat_fixed_proportions_to_u16(mat: Vec>) -> Vec> { + mat.into_iter().map(vec_fixed_proportions_to_u16).collect() +} + +#[allow(dead_code)] +pub fn mat_fixed_proportions_to_fixed(mat: Vec>) -> Vec> { + mat.into_iter() + .map(vec_fixed_proportions_to_fixed) + .collect() +} + #[allow(dead_code)] // Max-upscale vector and convert to u16 so max_value = u16::MAX. Assumes non-negative normalized input. pub fn vec_max_upscale_to_u16(vec: &[I32F32]) -> Vec { @@ -1317,73 +1329,197 @@ pub fn sparse_threshold(w: &[Vec<(u16, I32F32)>], threshold: I32F32) -> Vec], old: &[Vec], alpha: I32F32) -> Vec> { + let Some(first_row) = new.first() else { + return vec![vec![]]; + }; + if first_row.is_empty() { + return vec![vec![]; 1]; + } + let one_minus_alpha: I32F32 = I32F32::saturating_from_num(1.0).saturating_sub(alpha); + new.iter() + .zip(old) + .map(|(new_row, old_row)| { + new_row + .iter() + .zip(old_row) + .map(|(new_elem, old_elem)| { + alpha + .saturating_mul(*new_elem) + .saturating_add(one_minus_alpha.saturating_mul(*old_elem)) + }) + .collect() + }) + .collect() +} + +// Return sparse matrix exponential moving average: `alpha * a_ij + one_minus_alpha * b_ij`. +// `alpha` is the EMA coefficient, how much to add of the new observation, typically small, +// higher alpha discounts older observations faster. +#[allow(dead_code, clippy::indexing_slicing)] +pub fn mat_ema_sparse( new: &[Vec<(u16, I32F32)>], old: &[Vec<(u16, I32F32)>], - alpha: &[I32F32], + alpha: I32F32, ) -> Vec> { - // Ensure the new and old matrices have the same number of rows. assert!(new.len() == old.len()); - let n = new.len(); // Assume square matrix, rows=cols + let n = new.len(); // assume square matrix, rows=cols let zero: I32F32 = I32F32::saturating_from_num(0.0); + let one_minus_alpha: I32F32 = I32F32::saturating_from_num(1.0).saturating_sub(alpha); let mut result: Vec> = vec![vec![]; n]; - - // Iterate over each row of the matrices. - for (i, (new_row, old_row)) in new.iter().zip(old).enumerate() { - // Initialize a row of zeros for the result matrix. + for i in 0..new.len() { let mut row: Vec = vec![zero; n]; - - // Process the new matrix values. - for (j, new_val) in new_row.iter() { - // Retrieve the alpha value for the current column. - let alpha_val: I32F32 = alpha.get(*j as usize).copied().unwrap_or(zero); - // Compute the EMA component for the new value using saturating multiplication. - if let Some(row_val) = row.get_mut(*j as usize) { - // Each validator can increase bonds by at most clamped_alpha per epoch towards the cap - // Validators allocate their purchase across miners based on weights - *row_val = alpha_val.saturating_mul(*new_val); + for (j, value) in new[i].iter() { + row[*j as usize] = row[*j as usize].saturating_add(alpha.saturating_mul(*value)); + } + for (j, value) in old[i].iter() { + row[*j as usize] = + row[*j as usize].saturating_add(one_minus_alpha.saturating_mul(*value)); + } + for (j, value) in row.iter().enumerate() { + if *value > zero { + result[i].push((j as u16, *value)) } } + } + result +} - // Process the old matrix values. - for (j, old_val) in old_row.iter() { - // Retrieve the alpha value for the current column. - let alpha_val: I32F32 = alpha.get(*j as usize).copied().unwrap_or(zero); - // Calculate the complement of the alpha value using saturating subtraction. - let one_minus_alpha: I32F32 = - I32F32::saturating_from_num(1.0).saturating_sub(alpha_val); - // Compute the EMA component for the old value and add it to the row using saturating operations. - if let Some(purchase_increment) = row.get_mut(*j as usize) { - // *row_val = row_val.saturating_add(one_minus_alpha.saturating_mul(*value)); +/// Return matrix exponential moving average: `alpha_j * a_ij + one_minus_alpha_j * b_ij`. +/// `alpha_` is the EMA coefficient passed as a vector per column. +#[allow(dead_code)] +pub fn mat_ema_alpha( + new: &[Vec], // Weights + old: &[Vec], // Bonds + alpha: &[Vec], +) -> Vec> { + // Check if the new matrix is empty or its first row is empty. + if new.is_empty() || new.first().is_none_or(|row| row.is_empty()) { + return vec![vec![]; 1]; + } + + // Ensure the dimensions of the new, old and alpha matrices match. + assert!(new.len() == old.len()); + assert!(new.len() == alpha.len()); + + // Initialize the result matrix with zeros, having the same dimensions as the new matrix. + let mut result: Vec> = + vec![ + vec![I32F32::saturating_from_num(0.0); new.first().map_or(0, |row| row.len())]; + new.len() + ]; + + // Iterate over each row of the matrices. + for (i, ((new_row, old_row), alpha_row)) in new.iter().zip(old).zip(alpha).enumerate() { + assert!(new_row.len() == old_row.len()); + assert!(new_row.len() == alpha_row.len()); + + // Iterate over each column of the current row. + for j in 0..new_row.len() { + // Compute the EMA for the current element using saturating operations. + if let (Some(new_val), Some(old_val), Some(alpha_val), Some(result_val)) = ( + new_row.get(j), + old_row.get(j), + alpha_row.get(j), + result.get_mut(i).and_then(|row| row.get_mut(j)), + ) { + // Calculate the complement of the alpha value + let one_minus_alpha = I32F32::saturating_from_num(1.0).saturating_sub(*alpha_val); + + // Bonds_decayed = Bonds * (1 - alpha) let decayed_val = one_minus_alpha.saturating_mul(*old_val); + + // Calculate remaining capacity to limit bonds purchase let remaining_capacity = I32F32::from_num(1.0) .saturating_sub(decayed_val) .max(I32F32::from_num(0.0)); + // Each validator can increase bonds by at most clamped_alpha per epoch towards the cap + // Validators allocate their purchase across miners based on weights + let purchase_increment = alpha_val.saturating_mul(*new_val); + // Ensure that purchase does not exceed remaining capacity - let purchase = (*purchase_increment).min(remaining_capacity); + let purchase = purchase_increment.min(remaining_capacity); - *purchase_increment = decayed_val + *result_val = decayed_val .saturating_add(purchase) .min(I32F32::from_num(1.0)); } } + } - // Collect the non-zero values into the result matrix. - for (j, value) in row.iter().enumerate() { - if *value > zero { - if let Some(result_row) = result.get_mut(i) { - result_row.push((j as u16, *value)); - log::trace!("result[{}][{}] = {}", i, j, value); - } + // Return the computed EMA matrix. + result +} + +/// Calculates the exponential moving average (EMA) for a sparse matrix using dynamic alpha values. +/// Return matrix exponential moving average: `alpha_j * a_ij + one_minus_alpha_j * b_ij`. +// `alpha` is the EMA coefficient, how much to add of the new observation, typically small, +// higher alpha discounts older observations faster. +// if liquid alpha off then the alpha vector will be constant +#[allow(dead_code)] +pub fn mat_ema_alpha_sparse( + new: &[Vec<(u16, I32F32)>], + old: &[Vec<(u16, I32F32)>], + alpha: &[Vec], +) -> Vec> { + // Ensure dimensions match. + assert!(new.len() == old.len()); + assert!(new.len() == alpha.len()); + + // The output vector of rows. + let mut result: Vec> = Vec::with_capacity(new.len()); + + let n = new.len(); // Assume square matrix, rows=cols + let zero: I32F32 = I32F32::saturating_from_num(0.0); + + // Iterate over each row of the matrices. + for (i, (new_row, old_row)) in new.iter().zip(old).enumerate() { + // Initialize a row of zeros for the result matrix. + let mut decayed_values: Vec = vec![zero; n]; + + let mut result_row: Vec<(u16, I32F32)> = Vec::new(); + + // Process the old matrix values. + for (j, old_val) in old_row.iter() { + let alpha_val = alpha[i][*j as usize]; + // Calculate the complement of the alpha value + let one_minus_alpha = I32F32::saturating_from_num(1.0).saturating_sub(alpha_val); + + // Bonds_decayed = Bonds * (1 - alpha) + let decayed_val = one_minus_alpha.saturating_mul(*old_val); + decayed_values[*j as usize] = decayed_val; + } + + // Process the new matrix values. + for (j, new_val) in new_row.iter() { + let alpha_val = alpha[i][*j as usize]; + let decayed_val = decayed_values[*j as usize]; + + // Calculate remaining capacity to limit bonds purchase + let remaining_capacity = I32F32::from_num(1.0) + .saturating_sub(decayed_val) + .max(I32F32::from_num(0.0)); + + // Each validator can increase bonds by at most clamped_alpha per epoch towards the cap + // Validators allocate their purchase across miners based on weights + let purchase_increment = alpha_val.saturating_mul(*new_val); + + // Ensure that purchase does not exceed remaining capacity + let purchase = purchase_increment.min(remaining_capacity); + + let result_val = decayed_val + .saturating_add(purchase) + .min(I32F32::from_num(1.0)); + if result_val > zero { + result_row.push(({ *j }, result_val)); } } + result.push(result_row); } // Return the computed EMA sparse matrix. diff --git a/pallets/subtensor/src/epoch/run_epoch.rs b/pallets/subtensor/src/epoch/run_epoch.rs index 5cb399039f..8c3392b952 100644 --- a/pallets/subtensor/src/epoch/run_epoch.rs +++ b/pallets/subtensor/src/epoch/run_epoch.rs @@ -200,18 +200,17 @@ impl Pallet { // Access network bonds. let mut bonds: Vec> = Self::get_bonds(netuid); inplace_mask_matrix(&outdated, &mut bonds); // mask outdated bonds - for bonds_row in &mut bonds { - *bonds_row = vec_fixed_proportions_to_fixed(bonds_row.clone()); - } - // inplace_col_normalize(&mut bonds); // sum_i b_ij = 1 + bonds = mat_fixed_proportions_to_fixed(bonds.clone()); // TODO log::trace!("B: {:?}", &bonds); - // Get alpha values - let alphas = Self::compute_liquid_alpha(netuid, consensus.clone()); - log::trace!("alphas: {:?}", &alphas); - // Compute the Exponential Moving Average (EMA) of bonds. - let ema_bonds = Self::compute_ema_bonds(&weights_for_bonds.clone(), &bonds, alphas); + let ema_bonds = Self::compute_ema_bonds( + netuid, + &weights_for_bonds, + &bonds, + &consensus, + &active_stake, + ); log::trace!("emaB: {:?}", &ema_bonds); // Normalize EMA bonds. @@ -599,13 +598,15 @@ impl Pallet { let bonds = result; log::trace!("Bonds: (mask+norm) {:?}", &bonds); - // Get alpha values - let alphas = Self::compute_liquid_alpha(netuid, consensus.clone()); - log::trace!("Alphas: {:?}", &alphas); - // Compute the Exponential Moving Average (EMA) of bonds. log::trace!("weights_for_bonds: {:?}", &weights_for_bonds); - let ema_bonds = Self::compute_ema_bonds_sparse(&weights_for_bonds.clone(), &bonds, alphas); + let ema_bonds = Self::compute_ema_bonds_sparse( + netuid, + &weights_for_bonds, + &bonds, + &consensus, + &active_stake, + ); log::trace!("emaB: {:?}", &ema_bonds); // Normalize EMA bonds. @@ -1013,115 +1014,239 @@ impl Pallet { log::trace!("alpha_clamped: {:?}", clamped_alpha); clamped_alpha } + /// Compute the Exponential Moving Average (EMA) of bonds based on the Liquid Alpha setting + /// + /// # Args: + /// * `netuid` - The network ID. + /// * `weights` - A vector of weights. + /// * `bonds` - A vector of bonds. + /// * `consensus` - A vector of consensus values. + /// * `active_stake` - A vector of active stake values. + /// + /// # Returns: + /// A vector of EMA bonds. + pub fn compute_ema_bonds( + netuid: u16, + weights: &[Vec], // weights_for_bonds + bonds: &[Vec], + consensus: &Vec, + active_stake: &Vec, + ) -> Vec> { + // Check if Liquid Alpha is enabled, consensus is not empty, and contains non-zero values. + if LiquidAlphaOn::::get(netuid) + && !consensus.is_empty() + && consensus + .iter() + .any(|&c| c != I32F32::saturating_from_num(0)) + { + // Liquid Alpha is enabled, compute the liquid alphas matrix. + let alphas: Vec> = + Self::compute_liquid_alphas(netuid, weights, bonds, consensus); + log::trace!("alphas: {:?}", &alphas); + + // Compute the Exponential Moving Average (EMA) of bonds using the provided clamped alpha values. + mat_ema_alpha(weights, bonds, &alphas) + } else { + // Liquid Alpha is disabled, compute the liquid alpha value. + let alpha: I32F32 = Self::compute_disabled_liquid_alpha(netuid); + + // Compute bonds delta column normalized. + let mut bonds_delta: Vec> = row_hadamard(weights, active_stake); // ΔB = W◦S + inplace_col_normalize(&mut bonds_delta); // sum_i b_ij = 1 + log::trace!("ΔB:\n{:?}\n", &bonds_delta); + + // Compute the Exponential Moving Average (EMA) of bonds using the calculated alpha value. + + // Return the computed EMA bonds. + mat_ema(&bonds_delta, bonds, alpha) + } + } - /// Compute the Exponential Moving Average (EMA) of bonds using the alpha values for a sparse matrix. + /// Compute the Exponential Moving Average (EMA) of bonds based on the Liquid Alpha setting /// /// # Args: + /// * `netuid` - The network ID. /// * `weights` - A vector of weights. /// * `bonds` - A vector of bonds. - /// * `alpha` - A vector of clamped alpha values (for liquid alpha) or constant alpha values. + /// * `consensus` - A vector of consensus values. + /// * `active_stake` - A vector of active stake values. /// /// # Returns: /// A vector of EMA bonds. pub fn compute_ema_bonds_sparse( + netuid: u16, weights: &[Vec<(u16, I32F32)>], bonds: &[Vec<(u16, I32F32)>], - alpha: Vec, + consensus: &Vec, + active_stake: &Vec, ) -> Vec> { - // Compute the Exponential Moving Average (EMA) of bonds using the provided clamped alpha values. - let ema_bonds = mat_ema_alpha_vec_sparse(weights, bonds, &alpha); + // Check if Liquid Alpha is enabled, consensus is not empty, and contains non-zero values. + if LiquidAlphaOn::::get(netuid) + && !consensus.is_empty() + && consensus + .iter() + .any(|&c| c != I32F32::saturating_from_num(0)) + { + // Liquid Alpha is enabled, compute the liquid alphas matrix. + let alphas: Vec> = + Self::compute_liquid_alphas_sparse(netuid, weights, bonds, consensus); + log::trace!("alphas: {:?}", &alphas); + + // Compute the Exponential Moving Average (EMA) of bonds using the provided clamped alpha values. + mat_ema_alpha_sparse(weights, bonds, &alphas) + } else { + let n: u16 = Self::get_subnetwork_n(netuid); - // Log the computed EMA bonds for debugging purposes. - log::trace!("Exponential Moving Average Bonds: {:?}", ema_bonds); + // Liquid Alpha is disabled, compute the liquid alpha value. + let alpha: I32F32 = Self::compute_disabled_liquid_alpha(netuid); - // Return the computed EMA bonds. - ema_bonds + // Compute bonds delta column normalized. + let mut bonds_delta: Vec> = + row_hadamard_sparse(weights, active_stake); // ΔB = W◦S + inplace_col_normalize_sparse(&mut bonds_delta, n); // sum_i b_ij = 1 + log::trace!("ΔB:\n{:?}\n", &bonds_delta); + + // Compute the Exponential Moving Average (EMA) of bonds using the calculated alpha value. + + // Return the computed EMA bonds. + mat_ema_sparse(&bonds_delta, bonds, alpha) + } } - /// Compute the Exponential Moving Average (EMA) of bonds using the alpha values. + /// Compute liquid alphas matrix + /// There is a separate alpha param for each validator-miner binding /// /// # Args: + /// * `netuid` - The network ID. /// * `weights` - A vector of weights. /// * `bonds` - A vector of bonds. - /// * `alpha` - A vector of clamped alpha values (for liquid alpha) or constant alpha values. + /// * `consensus` - A vector of consensus values. /// /// # Returns: - /// A vector of EMA bonds. - pub fn compute_ema_bonds( - weights: &[Vec], - bonds: &[Vec], - alpha: Vec, + /// A matrix of alphas + pub fn compute_liquid_alphas( + netuid: u16, + weights: &[Vec], // current epoch weights + bonds: &[Vec], // previous epoch bonds + consensus: &Vec, // previous epoch consensus weights ) -> Vec> { - // Compute the Exponential Moving Average (EMA) of bonds using the provided clamped alpha values. - let ema_bonds = mat_ema_alpha_vec(weights, bonds, &alpha); + assert!(weights.len() == bonds.len()); + let n = weights.len(); // Assume square matrix, rows=cols + + // Get the high and low alpha values for the network. + let alpha_sigmoid_steepness: I32F32 = I32F32::from_num(10.0); + let (alpha_low, alpha_high): (I32F32, I32F32) = Self::get_alpha_values_32(netuid); + + let mut alphas = Vec::new(); - // Log the computed EMA bonds for debugging purposes. - log::trace!("Exponential Moving Average Bonds: {:?}", ema_bonds); + for i in 0..n { + let mut row_alphas = Vec::new(); - // Return the computed EMA bonds. - ema_bonds + for j in 0..weights[i].len() { + let diff_buy = (weights[i][j] - consensus[j]) + .max(I32F32::from_num(0.0)) + .min(I32F32::from_num(1.0)); + let diff_sell = (bonds[i][j] - weights[i][j]) + .max(I32F32::from_num(0.0)) + .min(I32F32::from_num(1.0)); + + let combined_diff = if weights[i][j] >= bonds[i][j] { + diff_buy + } else { + diff_sell + }; + + // sigmoid = 1. / (1. + e^(-alpha_sigmoid_steepness * (combined_diff - 0.5))) + let sigmoid = I32F32::from_num(1.0).saturating_div( + I32F32::from_num(1.0) + + safe_exp( + -alpha_sigmoid_steepness + .saturating_mul(combined_diff - I32F32::from_num(0.5)), + ), + ); + let alpha = alpha_low + sigmoid * (alpha_high - alpha_low); + row_alphas.push(alpha.max(alpha_low).min(alpha_high)); + } + alphas.push(row_alphas); + } + alphas } - /// Compute liquid alphas based on the Liquid Alpha setting. + /// Compute liquid alphas sparse matrix + /// There is a separate alpha param for each validator-miner binding /// /// # Args: /// * `netuid` - The network ID. + /// * `weights` - A vector of weights. + /// * `bonds` - A vector of bonds. /// * `consensus` - A vector of consensus values. /// /// # Returns: - /// A vector of alphas - pub fn compute_liquid_alpha(netuid: u16, consensus: Vec) -> Vec { - // Check if Liquid Alpha is enabled, consensus is not empty, and contains non-zero values. - if LiquidAlphaOn::::get(netuid) - && !consensus.is_empty() - && consensus - .iter() - .any(|&c| c != I32F32::saturating_from_num(0)) - { - // Calculate the 75th percentile (high) and 25th percentile (low) of the consensus values. - let mut consensus_high = quantile(&consensus, 0.75); - let consensus_low = quantile(&consensus, 0.25); + /// A matrix of alphas (not sparse as very few values will be zero) + pub fn compute_liquid_alphas_sparse( + netuid: u16, + weights: &[Vec<(u16, I32F32)>], // current epoch weights + bonds: &[Vec<(u16, I32F32)>], // previous epoch bonds + consensus: &Vec, // previous epoch consensus weights + ) -> Vec> { + assert!(weights.len() == bonds.len()); + let n = weights.len() as u16; // Assume square matrix, rows=cols + // + let alpha_sigmoid_steepness: I32F32 = I32F32::from_num(10.0); + let (alpha_low, alpha_high): (I32F32, I32F32) = Self::get_alpha_values_32(netuid); + + let mut alphas = Vec::with_capacity(n as usize); + + // iterate over rows + for (w_row, b_row) in weights.iter().zip(bonds.iter()) { + let mut row_alphas = Vec::with_capacity(w_row.len()); + let mut w_iter = 0; + let mut b_iter = 0; + for j in 0..n { + while w_iter < w_row.len() && w_row[w_iter].0 < j { + w_iter += 1; + } + let w_val = if w_iter < w_row.len() && w_row[w_iter].0 == j { + w_row[w_iter].1 + } else { + I32F32::from_num(0.0) + }; - if consensus_high == consensus_low { - consensus_high = quantile(&consensus, 0.99); - } - if consensus_high == consensus_low { - consensus_high = I32F32::saturating_from_num(1.0); + while b_iter < b_row.len() && b_row[b_iter].0 < j { + b_iter += 1; + } + let b_val = if b_iter < b_row.len() && b_row[b_iter].0 == j { + b_row[b_iter].1 + } else { + I32F32::from_num(0.0) + }; + + let diff_buy = (w_val - consensus[j as usize]) + .max(I32F32::from_num(0.0)) + .min(I32F32::from_num(1.0)); + let diff_sell = (b_val - w_val) + .max(I32F32::from_num(0.0)) + .min(I32F32::from_num(1.0)); + let combined_diff = if w_val >= b_val { diff_buy } else { diff_sell }; + + // sigmoid = 1. / (1. + e^(-alpha_sigmoid_steepness * (combined_diff - 0.5))) + let sigmoid = I32F32::from_num(1.0).saturating_div( + I32F32::from_num(1.0) + + safe_exp( + -alpha_sigmoid_steepness + .saturating_mul(combined_diff - I32F32::from_num(0.5)), + ), + ); + let mut alpha = alpha_low + sigmoid * (alpha_high - alpha_low); + alpha = alpha.max(alpha_low).min(alpha_high); + row_alphas.push(alpha); } - log::trace!( - "consensus_high: {:?}, consensus_low: {:?}", - consensus_high, - consensus_low - ); - - // Get the high and low alpha values for the network. - let (alpha_low, alpha_high): (I32F32, I32F32) = Self::get_alpha_values_32(netuid); - // log::warn!("alpha_high: {:?}, alpha_low: {:?} ", alpha_high, alpha_low); - - // Calculate the logistic function parameters 'a' and 'b' based on alpha and consensus values. - let (a, b) = Self::calculate_logistic_params( - alpha_high, - alpha_low, - consensus_high, - consensus_low, - ); - - // Compute the alpha values using the logistic function parameters. - // alpha = 1 / (1 + math.e ** (-a * C + b)) # alpha to the old weight - let alpha = Self::compute_alpha_values(&consensus, a, b); - - // return 1 - alpha values clamped between alpha_high and alpha_low. - let clamped_alpha: Vec = Self::clamp_alpha_values(alpha, alpha_high, alpha_low); - return clamped_alpha - .iter() - .map(|a| I32F32::saturating_from_num(1.0).saturating_sub(*a)) - .collect(); + alphas.push(row_alphas); } + alphas + } - // Liquid Alpha is disabled - // or high and low consensus values do not meet the required conditions. - // return vector of constant alpha - + pub fn compute_disabled_liquid_alpha(netuid: u16) -> I32F32 { // Retrieve the bonds moving average for the given network ID and scale it down. let bonds_moving_average: I64F64 = I64F64::from_num(Self::get_bonds_moving_average(netuid)) .saturating_div(I64F64::from_num(1_000_000)); @@ -1131,7 +1256,7 @@ impl Pallet { let alpha: I32F32 = I32F32::from_num(1).saturating_sub(I32F32::from_num(bonds_moving_average)); - vec![alpha; consensus.len()] + alpha } pub fn do_set_alpha_values( From 875a0ff187383e58a55492ff655ad179bfb106aa Mon Sep 17 00:00:00 2001 From: Andreea Popescu Date: Wed, 19 Mar 2025 17:41:57 +0000 Subject: [PATCH 25/45] fix yuma4 tests --- pallets/subtensor/src/epoch/math.rs | 13 + pallets/subtensor/src/epoch/run_epoch.rs | 147 +------ pallets/subtensor/src/tests/epoch.rs | 507 +++++++---------------- 3 files changed, 171 insertions(+), 496 deletions(-) diff --git a/pallets/subtensor/src/epoch/math.rs b/pallets/subtensor/src/epoch/math.rs index e8c7919fa9..5737e31c97 100644 --- a/pallets/subtensor/src/epoch/math.rs +++ b/pallets/subtensor/src/epoch/math.rs @@ -1329,6 +1329,19 @@ pub fn sparse_threshold(w: &[Vec<(u16, I32F32)>], threshold: I32F32) -> Vec I32F32 { + // First, clamp the value to ensure it does not exceed the upper bound (high). + // If the value is greater than 'high', it will be set to 'high'. + // otherwise it remains unchanged. + value + .min(I32F32::from_num(high)) + // Next, clamp the value to ensure it does not go below the lower bound (_low). + // If the value (after the first clamping) is less than 'low', it will be set to 'low'. + // otherwise it remains unchanged. + .max(I32F32::from_num(low)) +} + // Return matrix exponential moving average: `alpha * a_ij + one_minus_alpha * b_ij`. // `alpha` is the EMA coefficient, how much to add of the new observation, typically small, // higher alpha discounts older observations faster. diff --git a/pallets/subtensor/src/epoch/run_epoch.rs b/pallets/subtensor/src/epoch/run_epoch.rs index 8c3392b952..2b3037ee94 100644 --- a/pallets/subtensor/src/epoch/run_epoch.rs +++ b/pallets/subtensor/src/epoch/run_epoch.rs @@ -893,127 +893,6 @@ impl Pallet { bonds } - /// Calculate the logistic function parameters 'a' and 'b' based on alpha and consensus values. - /// - /// # Args: - /// * `alpha_high` - The high alpha value. - /// * `alpha_low` - The low alpha value. - /// * `consensus_high` - The high consensus value. - /// * `consensus_low` - The low consensus value. - /// - /// # Returns: - /// A tuple containing the slope 'a' and intercept 'b' for the logistic function. - pub fn calculate_logistic_params( - alpha_high: I32F32, - alpha_low: I32F32, - consensus_high: I32F32, - consensus_low: I32F32, - ) -> (I32F32, I32F32) { - log::trace!("alpha_high: {:?}", alpha_high); - log::trace!("alpha_low: {:?}", alpha_low); - log::trace!("consensus_high: {:?}", consensus_high); - log::trace!("consensus_low: {:?}", consensus_low); - // Check for division by zero - // extra caution to ensure we never divide by zero - if consensus_high <= consensus_low || alpha_low == 0 || alpha_high == 0 { - // Return 0 for both 'a' and 'b' when consensus values are equal - return ( - I32F32::saturating_from_num(0.0), - I32F32::saturating_from_num(0.0), - ); - } - - // Calculate the slope 'a' of the logistic function. - // a = (ln((1 / alpha_high - 1)) - ln((1 / alpha_low - 1))) / (consensus_low - consensus_high) - let a = (safe_ln( - (I32F32::saturating_from_num(1.0).safe_div(alpha_high)) - .saturating_sub(I32F32::saturating_from_num(1.0)), - ) - .saturating_sub(safe_ln( - (I32F32::saturating_from_num(1.0).safe_div(alpha_low)) - .saturating_sub(I32F32::saturating_from_num(1.0)), - ))) - .safe_div(consensus_low.saturating_sub(consensus_high)); - log::trace!("a: {:?}", a); - - // Calculate the intercept 'b' of the logistic function. - // b = ln((1 / alpha_low - 1)) + a * consensus_low - let b = safe_ln( - (I32F32::saturating_from_num(1.0).safe_div(alpha_low)) - .saturating_sub(I32F32::saturating_from_num(1.0)), - ) - .saturating_add(a.saturating_mul(consensus_low)); - log::trace!("b: {:?}", b); - - // Return the calculated slope 'a' and intercept 'b'. - (a, b) - } - - /// Compute the alpha values using the logistic function parameters 'a' and 'b'. - /// - /// # Args: - /// * `consensus` - A vector of consensus values. - /// * `a` - The slope of the logistic function. - /// * `b` - The intercept of the logistic function. - /// - /// # Returns: - /// A vector of computed alpha values. - pub fn compute_alpha_values(consensus: &[I32F32], a: I32F32, b: I32F32) -> Vec { - // Compute the alpha values for each consensus value. - let alpha: Vec = consensus - .iter() - .map(|c| { - // Calculate the exponent value for the logistic function. - // exp_val = exp(b - a * c) - let exp_val = safe_exp(b.saturating_sub(a.saturating_mul(*c))); - - // Compute the alpha value using the logistic function formula. - // alpha = 1 / (1 + exp_val) - I32F32::saturating_from_num(1.0) - .safe_div(I32F32::saturating_from_num(1.0).saturating_add(exp_val)) - }) - .collect(); - - // Log the computed alpha values for debugging purposes. - log::trace!("alpha: {:?}", alpha); - - // Return the computed alpha values. - alpha - } - - /// Clamp the alpha values between alpha_high and alpha_low. - /// - /// # Args: - /// * `alpha` - A vector of alpha values. - /// * `alpha_high` - The high alpha value. - /// * `alpha_low` - The low alpha value. - /// - /// # Returns: - /// A vector of clamped alpha values. - pub fn clamp_alpha_values( - alpha: Vec, - alpha_high: I32F32, - alpha_low: I32F32, - ) -> Vec { - let clamped_alpha: Vec = alpha - .iter() - .map(|a| { - // First, clamp the value to ensure it does not exceed the upper bound (alpha_high). - // If 'a' is greater than 'alpha_high', it will be set to 'alpha_high'. - // If 'a' is less than or equal to 'alpha_high', it remains unchanged. - let clamped_a = a - .min(&alpha_high) - // Next, clamp the value to ensure it does not go below the lower bound (alpha_low). - // If the value (after the first clamping) is less than 'alpha_low', it will be set to 'alpha_low'. - // If the value is greater than or equal to 'alpha_low', it remains unchanged. - .max(&alpha_low); - // Return the clamped value. - *clamped_a - }) - .collect(); - log::trace!("alpha_clamped: {:?}", clamped_alpha); - clamped_alpha - } /// Compute the Exponential Moving Average (EMA) of bonds based on the Liquid Alpha setting /// /// # Args: @@ -1041,7 +920,7 @@ impl Pallet { { // Liquid Alpha is enabled, compute the liquid alphas matrix. let alphas: Vec> = - Self::compute_liquid_alphas(netuid, weights, bonds, consensus); + Self::compute_liquid_alpha_values(netuid, weights, bonds, consensus); log::trace!("alphas: {:?}", &alphas); // Compute the Exponential Moving Average (EMA) of bonds using the provided clamped alpha values. @@ -1089,7 +968,7 @@ impl Pallet { { // Liquid Alpha is enabled, compute the liquid alphas matrix. let alphas: Vec> = - Self::compute_liquid_alphas_sparse(netuid, weights, bonds, consensus); + Self::compute_liquid_alpha_values_sparse(netuid, weights, bonds, consensus); log::trace!("alphas: {:?}", &alphas); // Compute the Exponential Moving Average (EMA) of bonds using the provided clamped alpha values. @@ -1124,7 +1003,7 @@ impl Pallet { /// /// # Returns: /// A matrix of alphas - pub fn compute_liquid_alphas( + pub fn compute_liquid_alpha_values( netuid: u16, weights: &[Vec], // current epoch weights bonds: &[Vec], // previous epoch bonds @@ -1143,12 +1022,16 @@ impl Pallet { let mut row_alphas = Vec::new(); for j in 0..weights[i].len() { - let diff_buy = (weights[i][j] - consensus[j]) - .max(I32F32::from_num(0.0)) - .min(I32F32::from_num(1.0)); - let diff_sell = (bonds[i][j] - weights[i][j]) - .max(I32F32::from_num(0.0)) - .min(I32F32::from_num(1.0)); + let diff_buy = clamp_value( + weights[i][j] - consensus[j], + I32F32::from_num(0.0), + I32F32::from_num(1.0), + ); + let diff_sell = clamp_value( + bonds[i][j] - weights[i][j], + I32F32::from_num(0.0), + I32F32::from_num(1.0), + ); let combined_diff = if weights[i][j] >= bonds[i][j] { diff_buy @@ -1165,7 +1048,7 @@ impl Pallet { ), ); let alpha = alpha_low + sigmoid * (alpha_high - alpha_low); - row_alphas.push(alpha.max(alpha_low).min(alpha_high)); + row_alphas.push(clamp_value(alpha, alpha_low, alpha_high)); } alphas.push(row_alphas); } @@ -1183,7 +1066,7 @@ impl Pallet { /// /// # Returns: /// A matrix of alphas (not sparse as very few values will be zero) - pub fn compute_liquid_alphas_sparse( + pub fn compute_liquid_alpha_values_sparse( netuid: u16, weights: &[Vec<(u16, I32F32)>], // current epoch weights bonds: &[Vec<(u16, I32F32)>], // previous epoch bonds diff --git a/pallets/subtensor/src/tests/epoch.rs b/pallets/subtensor/src/tests/epoch.rs index d2a7645b86..e1bca93858 100644 --- a/pallets/subtensor/src/tests/epoch.rs +++ b/pallets/subtensor/src/tests/epoch.rs @@ -5,7 +5,9 @@ )] use super::mock::*; -use crate::epoch::math::{fixed, safe_exp, u16_proportion_to_fixed}; +use crate::epoch::math::{ + fixed, mat_fixed_proportions_to_fixed, safe_exp, u16_proportion_to_fixed, +}; use crate::*; use approx::assert_abs_diff_eq; @@ -2576,273 +2578,6 @@ fn test_validator_permits() { } } -#[test] -fn test_compute_alpha_values() { - // Define the consensus values. - let consensus = vec![ - I32F32::from_num(0.1), - I32F32::from_num(0.5), - I32F32::from_num(0.9), - ]; - // Define the logistic function parameters 'a' and 'b'. - let a = I32F32::from_num(1.0); - let b = I32F32::from_num(0.0); - - // Compute the alpha values using the function. - let alpha = SubtensorModule::compute_alpha_values(&consensus, a, b); - - // Ensure the length of the alpha vector matches the consensus vector. - assert_eq!(alpha.len(), consensus.len()); - - // Manually compute the expected alpha values for each consensus value. - // The logistic function is: 1 / (1 + exp(b - a * c)) - // where c is the consensus value. - - // For consensus[0] = 0.1: - // exp_val = exp(0.0 - 1.0 * 0.1) = exp(-0.1) - // alpha[0] = 1 / (1 + exp(-0.1)) ~ 0.9048374180359595 - let exp_val_0 = I32F32::from_num(0.9048374180359595); - let expected_alpha_0 = I32F32::from_num(1.0) / (I32F32::from_num(1.0) + exp_val_0); - - // For consensus[1] = 0.5: - // exp_val = exp(0.0 - 1.0 * 0.5) = exp(-0.5) - // alpha[1] = 1 / (1 + exp(-0.5)) ~ 0.6065306597126334 - let exp_val_1 = I32F32::from_num(0.6065306597126334); - let expected_alpha_1 = I32F32::from_num(1.0) / (I32F32::from_num(1.0) + exp_val_1); - - // For consensus[2] = 0.9: - // exp_val = exp(0.0 - 1.0 * 0.9) = exp(-0.9) - // alpha[2] = 1 / (1 + exp(-0.9)) ~ 0.4065696597405991 - let exp_val_2 = I32F32::from_num(0.4065696597405991); - let expected_alpha_2 = I32F32::from_num(1.0) / (I32F32::from_num(1.0) + exp_val_2); - - // Define an epsilon for approximate equality checks. - let epsilon = I32F32::from_num(1e-6); - - // Assert that the computed alpha values match the expected values within the epsilon. - assert_approx_eq(alpha[0], expected_alpha_0, epsilon); - assert_approx_eq(alpha[1], expected_alpha_1, epsilon); - assert_approx_eq(alpha[2], expected_alpha_2, epsilon); -} - -#[test] -fn test_compute_alpha_values_256_miners() { - // Define the consensus values for 256 miners. - let consensus: Vec = (0..256) - .map(|i| I32F32::from_num(i as f32 / 255.0)) - .collect(); - // Define the logistic function parameters 'a' and 'b'. - let a = I32F32::from_num(1.0); - let b = I32F32::from_num(0.0); - - // Compute the alpha values using the function. - let alpha = SubtensorModule::compute_alpha_values(&consensus, a, b); - - // Ensure the length of the alpha vector matches the consensus vector. - assert_eq!(alpha.len(), consensus.len()); - - // Define an epsilon for approximate equality checks. - let epsilon = I32F32::from_num(1e-6); - - for (i, &c) in consensus.iter().enumerate() { - // Use saturating subtraction and multiplication - let exponent = b - (a * c); - - // Use safe_exp instead of exp - let exp_val = safe_exp(exponent); - - // Use saturating addition and division - let expected_alpha = I32F32::from_num(1.0) / (I32F32::from_num(1.0) + exp_val); - - // Assert that the computed alpha values match the expected values within the epsilon. - assert_approx_eq(alpha[i], expected_alpha, epsilon); - } -} - -#[test] -fn test_clamp_alpha_values() { - // Define the alpha values. - let alpha = vec![ - I32F32::from_num(0.1), - I32F32::from_num(0.5), - I32F32::from_num(0.9), - ]; - // Define the high and low clamping values. - let alpha_high = I32F32::from_num(0.8); - let alpha_low = I32F32::from_num(0.2); - - // Compute the clamped alpha values using the function. - let clamped_alpha = SubtensorModule::clamp_alpha_values(alpha.clone(), alpha_high, alpha_low); - - // Ensure the length of the clamped alpha vector matches the original alpha vector. - assert_eq!(clamped_alpha.len(), alpha.len()); - - // Manually compute the expected clamped alpha values for each alpha value. - // The clamping logic is: max(alpha_low, min(alpha_high, a)) - - // For alpha[0] = 0.1: - // clamped_a = max(0.2, min(0.8, 0.1)) = max(0.2, 0.1) = 0.2 - let expected_clamped_alpha_0 = I32F32::from_num(0.2); - - // For alpha[1] = 0.5: - // clamped_a = max(0.2, min(0.8, 0.5)) = max(0.2, 0.5) = 0.5 - let expected_clamped_alpha_1 = I32F32::from_num(0.5); - - // For alpha[2] = 0.9: - // clamped_a = max(0.2, min(0.8, 0.9)) = max(0.2, 0.8) = 0.8 - let expected_clamped_alpha_2 = I32F32::from_num(0.8); - - // Assert that the computed clamped alpha values match the expected values. - assert_eq!(clamped_alpha[0], expected_clamped_alpha_0); - assert_eq!(clamped_alpha[1], expected_clamped_alpha_1); - assert_eq!(clamped_alpha[2], expected_clamped_alpha_2); -} - -#[test] -fn test_calculate_logistic_params() { - // Define test inputs - let alpha_high = I32F32::from_num(0.9); - let alpha_low = I32F32::from_num(0.1); - let consensus_high = I32F32::from_num(0.8); - let consensus_low = I32F32::from_num(0.2); - - // Expected values - // a = (ln((1 / alpha_high - 1)) - ln((1 / alpha_low - 1))) / (consensus_low - consensus_high) - // = (ln((1 / 0.9 - 1)) - ln((1 / 0.1 - 1))) / (0.2 - 0.8) - // = (ln(0.1111) - ln(9)) / -0.6 - // = (-2.1972 - 2.1972) / -0.6 - // = -4.3944 / -0.6 - // = 7.324 - let expected_a = I32F32::from_num(7.324); - - // b = ln((1 / alpha_low - 1)) + a * consensus_low - // = ln((1 / 0.1 - 1)) + 7.324 * 0.2 - // = ln(9) + 1.4648 - // = 2.1972 + 1.4648 - // = 3.662 - let expected_b = I32F32::from_num(3.662); - - // Call the function - let (a, b) = SubtensorModule::calculate_logistic_params( - alpha_high, - alpha_low, - consensus_high, - consensus_low, - ); - - // Assert the results - assert!( - (a - expected_a).abs() < I32F32::from_num(0.001), - "Expected a: {:?}, got: {:?}", - expected_a, - a - ); - assert!( - (b - expected_b).abs() < I32F32::from_num(0.001), - "Expected b: {:?}, got: {:?}", - expected_b, - b - ); -} - -#[test] -fn test_calculate_logistic_params_edge_cases() { - // Edge Case 1: Alpha values at their boundaries (0 and 1) - let alpha_high = I32F32::from_num(1.0); - let alpha_low = I32F32::from_num(0.0); - let consensus_high = I32F32::from_num(0.8); - let consensus_low = I32F32::from_num(0.2); - - // Call the function - let (a, b) = SubtensorModule::calculate_logistic_params( - alpha_high, - alpha_low, - consensus_high, - consensus_low, - ); - - // Assert the results - assert_eq!(a, I32F32::from_num(0.0), "Expected a to be 0, got: {:?}", a); - assert_eq!(b, I32F32::from_num(0.0), "Expected b to be 0, got: {:?}", b); - - // Edge Case 2: Consensus values at their boundaries (0 and 1) - let alpha_high = I32F32::from_num(0.9); - let alpha_low = I32F32::from_num(0.1); - let consensus_high = I32F32::from_num(1.0); - let consensus_low = I32F32::from_num(0.0); - - // Call the function - let (a, b) = SubtensorModule::calculate_logistic_params( - alpha_high, - alpha_low, - consensus_high, - consensus_low, - ); - - // Expected values - // a = (ln((1 / 0.9 - 1)) - ln((1 / 0.1 - 1))) / (0.0 - 1.0) - // = (ln(0.1111) - ln(9)) / -1.0 - // = (-2.1972 - 2.1972) / -1.0 - // = -4.3944 / -1.0 - // = 4.3944 - let expected_a = I32F32::from_num(4.3944); - - // b = ln((1 / 0.1 - 1)) + a * 0.0 - // = ln(9) + 0 - // = 2.1972 - let expected_b = I32F32::from_num(2.1972); - - // Assert the results - assert!( - (a - expected_a).abs() < I32F32::from_num(0.001), - "Expected a: {:?}, got: {:?}", - expected_a, - a - ); - assert!( - (b - expected_b).abs() < I32F32::from_num(0.001), - "Expected b: {:?}, got: {:?}", - expected_b, - b - ); - - // Edge Case 3: Alpha values being equal - let alpha_high = I32F32::from_num(0.5); - let alpha_low = I32F32::from_num(0.5); - let consensus_high = I32F32::from_num(0.8); - let consensus_low = I32F32::from_num(0.2); - - // Call the function - let (a, b) = SubtensorModule::calculate_logistic_params( - alpha_high, - alpha_low, - consensus_high, - consensus_low, - ); - - // Assert the results - assert_eq!(a, I32F32::from_num(0.0), "Expected a to be 0, got: {:?}", a); - assert_eq!(b, I32F32::from_num(0.0), "Expected b to be 0, got: {:?}", b); - - // Edge Case 4: Consensus values being equal - let alpha_high = I32F32::from_num(0.9); - let alpha_low = I32F32::from_num(0.1); - let consensus_high = I32F32::from_num(0.5); - let consensus_low = I32F32::from_num(0.5); - - // Call the function - let (a, b) = SubtensorModule::calculate_logistic_params( - alpha_high, - alpha_low, - consensus_high, - consensus_low, - ); - - // Assert the results - assert_eq!(a, I32F32::from_num(0.0), "Expected a to be 0, got: {:?}", a); - assert_eq!(b, I32F32::from_num(0.0), "Expected b to be 0, got: {:?}", b); -} - #[test] fn test_compute_ema_bonds_sparse() { // Define test inputs @@ -3349,6 +3084,7 @@ fn setup_yuma_4_scenario(netuid: u16, n: u16, sparse: bool, max_stake: u64, stak SubtensorModule::set_min_allowed_weights(netuid, 1); SubtensorModule::set_max_weight_limit(netuid, u16::MAX); SubtensorModule::set_bonds_penalty(netuid, 0); + // SubtensorModule::set_bonds_moving_average(netuid, 975_000); // === Register for key in 0..n as u64 { @@ -3381,8 +3117,9 @@ fn setup_yuma_4_scenario(netuid: u16, n: u16, sparse: bool, max_stake: u64, stak // Enable Liquid Alpha SubtensorModule::set_kappa(netuid, u16::MAX / 2); SubtensorModule::set_liquid_alpha_enabled(netuid, true); + SubtensorModule::set_kappa(netuid, u16::MAX / 2); - SubtensorModule::set_alpha_values_32(netuid, I32F32::from_num(0.9), I32F32::from_num(0.99)); + SubtensorModule::set_alpha_values_32(netuid, I32F32::from_num(0.1), I32F32::from_num(0.3)); // === Issue validator permits SubtensorModule::set_max_allowed_validators(netuid, 3); @@ -3405,25 +3142,26 @@ fn run_epoch(netuid: u16, sparse: bool) { fn run_epoch_and_check_bonds_dividends( netuid: u16, sparse: bool, - target_bonds: &[Vec], + target_bonds: &[Vec], target_dividends: &[f32], ) { run_epoch(netuid, sparse); - let bonds = SubtensorModule::get_bonds(netuid); + let mut bonds = SubtensorModule::get_bonds(netuid); + bonds = mat_fixed_proportions_to_fixed(bonds.clone()); let dividends = SubtensorModule::get_dividends(netuid); + let epsilon = I32F32::from_num(1e-3); // Check the bonds // server 1 - assert_eq!(bonds[0][3], target_bonds[0][0]); - assert_eq!(bonds[1][3], target_bonds[1][0]); - assert_eq!(bonds[2][3], target_bonds[2][0]); + assert_approx_eq(bonds[0][3], fixed(target_bonds[0][0]), epsilon); + assert_approx_eq(bonds[1][3], fixed(target_bonds[1][0]), epsilon); + assert_approx_eq(bonds[2][3], fixed(target_bonds[2][0]), epsilon); // server 2 - assert_eq!(bonds[0][4], target_bonds[0][1]); - assert_eq!(bonds[1][4], target_bonds[1][1]); - assert_eq!(bonds[2][4], target_bonds[2][1]); + assert_approx_eq(bonds[0][4], fixed(target_bonds[0][1]), epsilon); + assert_approx_eq(bonds[1][4], fixed(target_bonds[1][1]), epsilon); + assert_approx_eq(bonds[2][4], fixed(target_bonds[2][1]), epsilon); // Check the dividends - let epsilon = I32F32::from_num(1e-3); for (dividend, target_dividend) in dividends.iter().zip(target_dividends.iter()) { assert_approx_eq( u16_proportion_to_fixed(*dividend), @@ -3448,7 +3186,7 @@ fn set_yuma_4_weights(netuid: u16, weights: Vec>) { #[test] fn test_yuma_4_kappa_moves_first() { new_test_ext(1).execute_with(|| { - let sparse: bool = false; + let sparse: bool = true; let n: u16 = 5; // 3 validators, 2 servers let netuid: u16 = 1; let max_stake: u64 = 8; @@ -3461,49 +3199,44 @@ fn test_yuma_4_kappa_moves_first() { setup_yuma_4_scenario(netuid, n, sparse, max_stake, stakes); let targets_bonds = [ vec![ - vec![656, 0], - vec![656, 0], - vec![656, 0], - vec![0, 0], - vec![0, 0], + vec![0.1013, 0.0000], + vec![0.1013, 0.0000], + vec![0.1013, 0.0000], ], vec![ - vec![590, 656], - vec![7144, 0], - vec![7144, 0], - vec![0, 0], - vec![0, 0], + vec![0.0908, 0.1013], + vec![0.3697, 0.0000], + vec![0.3697, 0.0000], ], vec![ - vec![530, 1305], - vec![6429, 656], - vec![12983, 0], - vec![0, 0], - vec![0, 0], + vec![0.0815, 0.1924], + vec![0.3170, 0.1013], + vec![0.5580, 0.0000], ], vec![ - vec![476, 1947], - vec![5786, 1305], - vec![11684, 656], - vec![0, 0], - vec![0, 0], + vec![0.0731, 0.2742], + vec![0.2765, 0.1924], + vec![0.4306, 0.1013], ], vec![ - vec![428, 2583], - vec![5207, 1947], - vec![10515, 1305], - vec![0, 0], - vec![0, 0], + vec![0.0656, 0.3478], + vec![0.2435, 0.2742], + vec![0.3589, 0.1924], + ], + vec![ + vec![0.0588, 0.4139], + vec![0.2157, 0.3478], + vec![0.3089, 0.2742], ], ]; let targets_dividends = [ vec![0.8000, 0.1000, 0.1000, 0.0000, 0.0000], vec![1.0000, 0.0000, 0.0000, 0.0000, 0.0000], - vec![0.9409, 0.0591, 0.0000, 0.0000, 0.0000], - vec![0.8882, 0.0744, 0.0374, 0.0000, 0.0000], - vec![0.8640, 0.0814, 0.0545, 0.0000, 0.0000], - vec![0.8502, 0.0854, 0.0644, 0.0000, 0.0000], + vec![0.9382, 0.0618, 0.0000, 0.0000, 0.0000], + vec![0.8819, 0.0773, 0.0407, 0.0000, 0.0000], + vec![0.8564, 0.0844, 0.0592, 0.0000, 0.0000], + vec![0.8418, 0.0884, 0.0697, 0.0000, 0.0000], ]; for (epoch, (target_bonds, target_dividends)) in targets_bonds @@ -3548,7 +3281,7 @@ fn test_yuma_4_kappa_moves_first() { #[test] fn test_yuma_4_kappa_moves_second() { new_test_ext(1).execute_with(|| { - let sparse: bool = true; + let sparse: bool = false; let n: u16 = 5; // 3 validators, 2 servers let netuid: u16 = 1; let max_stake: u64 = 8; @@ -3561,48 +3294,43 @@ fn test_yuma_4_kappa_moves_second() { setup_yuma_4_scenario(netuid, n, sparse, max_stake, stakes); let targets_bonds = [ vec![ - vec![656, 0], - vec![656, 0], - vec![656, 0], - vec![0, 0], - vec![0, 0], + vec![0.1013, 0.0000], + vec![0.1013, 0.0000], + vec![0.1013, 0.0000], + ], + vec![ + vec![0.1924, 0.0000], + vec![0.0908, 0.2987], + vec![0.1924, 0.0000], ], vec![ - vec![1305, 0], - vec![649, 6553], - vec![1305, 0], - vec![0, 0], - vec![0, 0], + vec![0.1715, 0.1013], + vec![0.0815, 0.3697], + vec![0.4336, 0.0000], ], vec![ - vec![1174, 656], - vec![584, 7143], - vec![7728, 0], - vec![0, 0], - vec![0, 0], + vec![0.1531, 0.1924], + vec![0.0731, 0.4336], + vec![0.3608, 0.1013], ], vec![ - vec![1056, 1305], - vec![525, 7727], - vec![6955, 656], - vec![0, 0], - vec![0, 0], + vec![0.1369, 0.2742], + vec![0.0656, 0.4910], + vec![0.3103, 0.1924], ], vec![ - vec![950, 1947], - vec![472, 8305], - vec![6259, 1305], - vec![0, 0], - vec![0, 0], + vec![0.1225, 0.3478], + vec![0.0588, 0.5426], + vec![0.2712, 0.2742], ], ]; let targets_dividends = [ - vec![0.8000, 0.1000, 0.1000], - vec![0.8423, 0.0524, 0.1053], - vec![0.4233, 0.5767, 0.0000], - vec![0.5545, 0.4107, 0.0348], - vec![0.6184, 0.3298, 0.0518], - vec![0.6562, 0.2820, 0.0618], + vec![0.8000, 0.1000, 0.1000, 0.0000, 0.0000], + vec![0.8446, 0.0498, 0.1056, 0.0000, 0.0000], + vec![0.6868, 0.3132, 0.0000, 0.0000, 0.0000], + vec![0.7421, 0.2090, 0.0489, 0.0000, 0.0000], + vec![0.7625, 0.1706, 0.0669, 0.0000, 0.0000], + vec![0.7730, 0.1508, 0.0762, 0.0000, 0.0000], ]; for (epoch, (target_bonds, target_dividends)) in targets_bonds @@ -3659,19 +3387,44 @@ fn test_yuma_4_kappa_moves_last() { setup_yuma_4_scenario(netuid, n, sparse, max_stake, stakes); let targets_bonds = [ - vec![vec![656, 0], vec![656, 0], vec![656, 0]], - vec![vec![1305, 0], vec![649, 6553], vec![1305, 0]], - vec![vec![1947, 0], vec![642, 12451], vec![1291, 6553]], - vec![vec![1752, 656], vec![577, 12982], vec![1161, 7143]], - vec![vec![1576, 1305], vec![519, 13508], vec![1044, 7727]], + vec![ + vec![0.1013, 0.0000], + vec![0.1013, 0.0000], + vec![0.1013, 0.0000], + ], + vec![ + vec![0.1924, 0.0000], + vec![0.0908, 0.2987], + vec![0.1924, 0.0000], + ], + vec![ + vec![0.2742, 0.0000], + vec![0.0815, 0.5081], + vec![0.1715, 0.2987], + ], + vec![ + vec![0.2416, 0.1013], + vec![0.0731, 0.5580], + vec![0.1531, 0.3697], + ], + vec![ + vec![0.2141, 0.1924], + vec![0.0656, 0.6028], + vec![0.1369, 0.4336], + ], + vec![ + vec![0.1903, 0.2742], + vec![0.0588, 0.6430], + vec![0.1225, 0.4910], + ], ]; let targets_dividends = [ - vec![0.8000, 0.1000, 0.1000], - vec![0.8423, 0.0524, 0.1053], - vec![0.8895, 0.0367, 0.0738], - vec![0.2067, 0.5117, 0.2816], - vec![0.3294, 0.4265, 0.2440], - vec![0.4108, 0.3701, 0.2191], + vec![0.8000, 0.1000, 0.1000, 0.0000, 0.0000], + vec![0.8446, 0.0498, 0.1056, 0.0000, 0.0000], + vec![0.8966, 0.0333, 0.0701, 0.0000, 0.0000], + vec![0.4663, 0.3210, 0.2127, 0.0000, 0.0000], + vec![0.5976, 0.2340, 0.1683, 0.0000, 0.0000], + vec![0.6592, 0.1932, 0.1475, 0.0000, 0.0000], ]; for (epoch, (target_bonds, target_dividends)) in targets_bonds @@ -3727,18 +3480,44 @@ fn test_yuma_4_one_epoch_switch() { setup_yuma_4_scenario(netuid, n, sparse, max_stake, stakes); let targets_bonds = [ - vec![vec![656, 0], vec![656, 0], vec![656, 0]], - vec![vec![1305, 0], vec![1305, 0], vec![1305, 0]], - vec![vec![1291, 6553], vec![1947, 0], vec![1947, 0]], - vec![vec![1934, 5897], vec![2583, 0], vec![2583, 0]], - vec![vec![2570, 5307], vec![3213, 0], vec![3213, 0]], + vec![ + vec![0.1013, 0.0000], + vec![0.1013, 0.0000], + vec![0.1013, 0.0000], + ], + vec![ + vec![0.1924, 0.0000], + vec![0.1924, 0.0000], + vec![0.1924, 0.0000], + ], + vec![ + vec![0.2742, 0.0000], + vec![0.2742, 0.0000], + vec![0.1715, 0.2987], + ], + vec![ + vec![0.3478, 0.0000], + vec![0.3478, 0.0000], + vec![0.2554, 0.2618], + ], + vec![ + vec![0.4139, 0.0000], + vec![0.4139, 0.0000], + vec![0.3309, 0.2312], + ], + vec![ + vec![0.4733, 0.0000], + vec![0.4733, 0.0000], + vec![0.3987, 0.2051], + ], ]; let targets_dividends = [ - vec![0.33, 0.33, 0.34, 0., 0.], - vec![0.33, 0.33, 0.34, 0., 0.], - vec![0.246_231_48, 0.371_259_12, 0.382_509_4, 0., 0.], - vec![0.269_393_1, 0.359_851_15, 0.370_755_73, 0., 0.], - vec![0.282_665_13, 0.353_314_2, 0.364_020_68, 0., 0.], + vec![0.3300, 0.3300, 0.3400, 0.0000, 0.0000], + vec![0.3300, 0.3300, 0.3400, 0.0000, 0.0000], + vec![0.3782, 0.3782, 0.2436, 0.0000, 0.0000], + vec![0.3628, 0.3628, 0.2745, 0.0000, 0.0000], + vec![0.3541, 0.3541, 0.2917, 0.0000, 0.0000], + vec![0.3487, 0.3487, 0.3026, 0.0000, 0.0000], ]; for (epoch, (target_bonds, target_dividends)) in targets_bonds @@ -3748,12 +3527,12 @@ fn test_yuma_4_one_epoch_switch() { { match epoch { 2 => { - // Validator A -> Server 2 + // Validator A -> Server 1 // Validator B -> Server 1 - // Validator C -> Server 1 + // Validator C -> Server 2 set_yuma_4_weights( netuid, - vec![vec![0, u16::MAX], vec![u16::MAX, 0], vec![u16::MAX, 0]], + vec![vec![u16::MAX, 0], vec![u16::MAX, 0], vec![0, u16::MAX]], ); } _ => { From 197fd0b2afa88cdcd9ad1acd1b4d572e3c48bb2e Mon Sep 17 00:00:00 2001 From: Andreea Popescu Date: Thu, 20 Mar 2025 10:09:36 +0000 Subject: [PATCH 26/45] fix math tests --- pallets/subtensor/src/epoch/math.rs | 63 ----------- pallets/subtensor/src/tests/epoch.rs | 64 +---------- pallets/subtensor/src/tests/math.rs | 155 +++++++++++++++++---------- 3 files changed, 101 insertions(+), 181 deletions(-) diff --git a/pallets/subtensor/src/epoch/math.rs b/pallets/subtensor/src/epoch/math.rs index 5737e31c97..9ae6be617f 100644 --- a/pallets/subtensor/src/epoch/math.rs +++ b/pallets/subtensor/src/epoch/math.rs @@ -1539,69 +1539,6 @@ pub fn mat_ema_alpha_sparse( result } -/// Return matrix exponential moving average: `alpha_j * a_ij + one_minus_alpha_j * b_ij`. -/// `alpha_` is the EMA coefficient passed as a vector per column. -// if liquid alpha off then the alpha vector will be constant -#[allow(dead_code)] -pub fn mat_ema_alpha_vec( - new: &[Vec], - old: &[Vec], - alpha: &[I32F32], -) -> Vec> { - // Check if the new matrix is empty or its first row is empty. - if new.is_empty() || new.first().is_none_or(|row| row.is_empty()) { - return vec![vec![]; 1]; - } - - // Ensure the dimensions of the new and old matrices match. - assert!(new.len() == old.len()); - assert!(new.first().map_or(0, |row| row.len()) == alpha.len()); - - // Initialize the result matrix with zeros, having the same dimensions as the new matrix. - let mut result: Vec> = - vec![ - vec![I32F32::saturating_from_num(0.0); new.first().map_or(0, |row| row.len())]; - new.len() - ]; - - // Iterate over each row of the matrices. - for (i, (new_row, old_row)) in new.iter().zip(old).enumerate() { - assert!(new_row.len() == old_row.len()); - - // Iterate over each column of the current row. - for (j, &alpha_val) in alpha.iter().enumerate().take(new_row.len()) { - // Calculate the complement of the alpha value using saturating subtraction. - let one_minus_alpha = I32F32::saturating_from_num(1.0).saturating_sub(alpha_val); - - // Compute the EMA for the current element using saturating operations. - if let (Some(new_val), Some(old_val), Some(result_val)) = ( - new_row.get(j), - old_row.get(j), - result.get_mut(i).and_then(|row| row.get_mut(j)), - ) { - let decayed_val = one_minus_alpha.saturating_mul(*old_val); - let remaining_capacity = I32F32::from_num(1.0) - .saturating_sub(decayed_val) - .max(I32F32::from_num(0.0)); - - // Each validator can increase bonds by at most clamped_alpha per epoch towards the cap - // Validators allocate their purchase across miners based on weights - let purchase_increment = alpha_val.saturating_mul(*new_val); - - // Ensure that purchase does not exceed remaining capacity - let purchase = purchase_increment.min(remaining_capacity); - - *result_val = decayed_val - .saturating_add(purchase) - .min(I32F32::from_num(1.0)); - } - } - } - - // Return the computed EMA matrix. - result -} - /// Return the quantile of a vector of I32F32 values. pub fn quantile(data: &[I32F32], quantile: f64) -> I32F32 { // Clone the input data to avoid modifying the original vector. diff --git a/pallets/subtensor/src/tests/epoch.rs b/pallets/subtensor/src/tests/epoch.rs index e1bca93858..89812bfb27 100644 --- a/pallets/subtensor/src/tests/epoch.rs +++ b/pallets/subtensor/src/tests/epoch.rs @@ -5,9 +5,7 @@ )] use super::mock::*; -use crate::epoch::math::{ - fixed, mat_fixed_proportions_to_fixed, safe_exp, u16_proportion_to_fixed, -}; +use crate::epoch::math::{fixed, mat_fixed_proportions_to_fixed, u16_proportion_to_fixed}; use crate::*; use approx::assert_abs_diff_eq; @@ -2578,66 +2576,6 @@ fn test_validator_permits() { } } -#[test] -fn test_compute_ema_bonds_sparse() { - // Define test inputs - let weights = vec![ - vec![(0, I32F32::from_num(0.1)), (1, I32F32::from_num(0.2))], - vec![(0, I32F32::from_num(0.3)), (1, I32F32::from_num(0.4))], - ]; - let bonds = vec![ - vec![(0, I32F32::from_num(0.5)), (1, I32F32::from_num(0.6))], - vec![(0, I32F32::from_num(0.7)), (1, I32F32::from_num(0.8))], - ]; - let alpha = vec![I32F32::from_num(0.9), I32F32::from_num(0.8)]; - - // Expected values - // EMA calculation for each bond: - // EMA = alpha * bond_delta + (1 - alpha) * bond - // For bond (0, 0): - // EMA = 0.9 * 0.1 + (1 - 0.9) * 0.5 = 0.09 + 0.05 = 0.14 - // For bond (0, 1): - // EMA = 0.8 * 0.2 + (1 - 0.8) * 0.6 = 0.16 + 0.12 = 0.28 - // For bond (1, 0): - // EMA = 0.9 * 0.3 + (1 - 0.9) * 0.7 = 0.27 + 0.07 = 0.34 - // For bond (1, 1): - // EMA = 0.8 * 0.4 + (1 - 0.8) * 0.8 = 0.32 + 0.16 = 0.48 - - let expected_ema_bonds = vec![ - vec![(0, I32F32::from_num(0.14)), (1, I32F32::from_num(0.28))], - vec![(0, I32F32::from_num(0.34)), (1, I32F32::from_num(0.48))], - ]; - - // Call the function - let ema_bonds = SubtensorModule::compute_ema_bonds_sparse(&weights, &bonds, alpha); - - // Assert the results with an epsilon for approximate equality - let epsilon = I32F32::from_num(1e-6); - - assert_approx_eq_vec_of_vec(&ema_bonds, &expected_ema_bonds, epsilon); -} - -#[test] -fn test_compute_ema_bonds_sparse_empty() { - // Test with empty inputs - let weights: Vec> = vec![]; - let bonds: Vec> = vec![]; - let alpha: Vec = vec![]; - - // Expected values: Empty Vec - let expected_ema_bonds: Vec> = vec![]; - - // Call the function - let ema_bonds = SubtensorModule::compute_ema_bonds_sparse(&weights, &bonds, alpha); - - // Assert the results - assert_eq!( - ema_bonds, expected_ema_bonds, - "Expected EMA bonds: {:?}, got: {:?}", - expected_ema_bonds, ema_bonds - ); -} - #[test] fn test_get_set_alpha() { new_test_ext(1).execute_with(|| { diff --git a/pallets/subtensor/src/tests/math.rs b/pallets/subtensor/src/tests/math.rs index b12e84852a..01e02742b7 100644 --- a/pallets/subtensor/src/tests/math.rs +++ b/pallets/subtensor/src/tests/math.rs @@ -2150,19 +2150,20 @@ fn test_math_hadamard_sparse() { } #[test] -fn test_math_mat_ema() { +fn test_math_mat_ema_alpha() { let old: Vec = vec![ 0.1, 0.2, 3., 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.10, 0.11, 0.12, ]; let new: Vec = vec![1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12.]; let target: Vec = vec![ - 0.19, 0.38, 1., 0.4359, 0.545, 0.6539, 0.763, 0.8719, 0.981, 1., 1., 1., + 0.19, 0.38, 1., 0.436, 0.545, 0.6539, 0.763, 0.8719, 0.981, 1., 1., 1., ]; let old = vec_to_mat_fixed(&old, 4, false); let new = vec_to_mat_fixed(&new, 4, false); let target = vec_to_mat_fixed(&target, 4, false); - let result = mat_ema_alpha_vec(&new, &old, &[I32F32::from_num(0.1); 3]); + let alphas = vec_to_mat_fixed(&[0.1; 12], 4, false); + let result = mat_ema_alpha(&new, &old, &alphas); assert_mat_compare(&result, &target, I32F32::from_num(1e-4)); let old: Vec = vec![ 0.1, 0.2, 3., 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.10, 0.11, 0.12, @@ -2176,7 +2177,8 @@ fn test_math_mat_ema() { let old = vec_to_mat_fixed(&old, 4, false); let new = vec_to_mat_fixed(&new, 4, false); let target = vec_to_mat_fixed(&target, 4, false); - let result = mat_ema_alpha_vec(&new, &old, &[I32F32::from_num(0); 3]); + let alphas = vec_to_mat_fixed(&[0.; 12], 4, false); + let result = mat_ema_alpha(&new, &old, &alphas); assert_mat_compare(&result, &target, I32F32::from_num(1e-4)); let old: Vec = vec![ 0.001, 0.002, 0.003, 0.004, 0.05, 0.006, 0.007, 0.008, 0.009, 0.010, 0.011, 0.012, @@ -2191,12 +2193,13 @@ fn test_math_mat_ema() { let old = vec_to_mat_fixed(&old, 4, false); let new = vec_to_mat_fixed(&new, 4, false); let target = vec_to_mat_fixed(&target, 4, false); - let result = mat_ema_alpha_vec(&new, &old, &[I32F32::from_num(1); 3]); + let alphas = vec_to_mat_fixed(&[1.; 12], 4, false); + let result = mat_ema_alpha(&new, &old, &alphas); assert_mat_compare(&result, &target, I32F32::from_num(1e-4)); } #[test] -fn test_math_sparse_mat_ema() { +fn test_math_sparse_mat_ema_alpha() { let old: Vec = vec![ 0.1, 0.2, 3., 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.10, 0.11, 0.12, ]; @@ -2207,7 +2210,8 @@ fn test_math_sparse_mat_ema() { let old = vec_to_sparse_mat_fixed(&old, 4, false); let new = vec_to_sparse_mat_fixed(&new, 4, false); let target = vec_to_sparse_mat_fixed(&target, 4, false); - let result = mat_ema_alpha_vec_sparse(&new, &old, &vec![I32F32::from_num(0.1); old.len()]); + let alphas = vec_to_mat_fixed(&[0.1; 12], 4, false); + let result = mat_ema_alpha_sparse(&new, &old, &alphas); assert_sparse_mat_compare(&result, &target, I32F32::from_num(1e-4)); let old: Vec = vec![ 0.001, 0.002, 0.003, 0.004, 0.05, 0.006, 0.007, 0.008, 0.009, 0.010, 0.011, 0.012, @@ -2222,7 +2226,8 @@ fn test_math_sparse_mat_ema() { let old = vec_to_sparse_mat_fixed(&old, 4, false); let new = vec_to_sparse_mat_fixed(&new, 4, false); let target = vec_to_sparse_mat_fixed(&target, 4, false); - let result = mat_ema_alpha_vec_sparse(&new, &old, &vec![I32F32::from_num(0.1); old.len()]); + let alphas = vec_to_mat_fixed(&[0.1; 12], 4, false); + let result = mat_ema_alpha_sparse(&new, &old, &alphas); assert_sparse_mat_compare(&result, &target, I32F32::from_num(1e-4)); let old: Vec = vec![0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]; let new: Vec = vec![ @@ -2234,7 +2239,8 @@ fn test_math_sparse_mat_ema() { let old = vec_to_sparse_mat_fixed(&old, 4, false); let new = vec_to_sparse_mat_fixed(&new, 4, false); let target = vec_to_sparse_mat_fixed(&target, 4, false); - let result = mat_ema_alpha_vec_sparse(&new, &old, &vec![I32F32::from_num(0.1); old.len()]); + let alphas = vec_to_mat_fixed(&[0.1; 12], 4, false); + let result = mat_ema_alpha_sparse(&new, &old, &alphas); assert_sparse_mat_compare(&result, &target, I32F32::from_num(1e-4)); let old: Vec = vec![0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]; let new: Vec = vec![0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]; @@ -2242,16 +2248,18 @@ fn test_math_sparse_mat_ema() { let old = vec_to_sparse_mat_fixed(&old, 4, false); let new = vec_to_sparse_mat_fixed(&new, 4, false); let target = vec_to_sparse_mat_fixed(&target, 4, false); - let result = mat_ema_alpha_vec_sparse(&new, &old, &vec![I32F32::from_num(0.1); old.len()]); + let alphas = vec_to_mat_fixed(&[0.1; 12], 4, false); + let result = mat_ema_alpha_sparse(&new, &old, &alphas); assert_sparse_mat_compare(&result, &target, I32F32::from_num(1e-4)); let old: Vec = vec![1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]; let new: Vec = vec![0., 0., 0., 0., 2., 0., 0., 0., 0., 0., 0., 0.]; - let target: Vec = vec![0.9, 0., 0., 0., 0.2, 0., 0., 0., 0., 0., 0., 0.]; + let target: Vec = vec![0.0, 0., 0., 0., 0.2, 0., 0., 0., 0., 0., 0., 0.]; let old = vec_to_sparse_mat_fixed(&old, 4, false); let new = vec_to_sparse_mat_fixed(&new, 4, false); let target = vec_to_sparse_mat_fixed(&target, 4, false); - let result = mat_ema_alpha_vec_sparse(&new, &old, &vec![I32F32::from_num(0.1); old.len()]); - assert_sparse_mat_compare(&result, &target, I32F32::from_num(1e-4)); + let alphas = vec_to_mat_fixed(&[0.1; 12], 4, false); + let result = mat_ema_alpha_sparse(&new, &old, &alphas); + assert_sparse_mat_compare(&result, &target, I32F32::from_num(1e-1)); } #[test] @@ -2541,25 +2549,25 @@ fn test_checked_sum() { } #[test] -fn test_mat_ema_alpha_vec_sparse_empty() { +fn test_mat_ema_alpha_sparse_empty() { let new: Vec> = Vec::new(); let old: Vec> = Vec::new(); - let alpha: Vec = Vec::new(); - let result = mat_ema_alpha_vec_sparse(&new, &old, &alpha); + let alpha: Vec> = Vec::new(); + let result = mat_ema_alpha_sparse(&new, &old, &alpha); assert_eq!(result, Vec::>::new()); } #[test] -fn test_mat_ema_alpha_vec_sparse_single_element() { +fn test_mat_ema_alpha_sparse_single_element() { let new: Vec> = vec![vec![(0, I32F32::from_num(1.0))]]; let old: Vec> = vec![vec![(0, I32F32::from_num(2.0))]]; - let alpha: Vec = vec![I32F32::from_num(0.5)]; - let result = mat_ema_alpha_vec_sparse(&new, &old, &alpha); + let alpha = vec![vec![I32F32::from_num(0.5)]]; + let result = mat_ema_alpha_sparse(&new, &old, &alpha); assert_eq!(result, vec![vec![(0, I32F32::from_num(1.0))]]); } #[test] -fn test_mat_ema_alpha_vec_sparse_multiple_elements() { +fn test_mat_ema_alpha_sparse_multiple_elements() { let new: Vec> = vec![ vec![(0, I32F32::from_num(1.0)), (1, I32F32::from_num(2.0))], vec![(0, I32F32::from_num(3.0)), (1, I32F32::from_num(4.0))], @@ -2568,8 +2576,8 @@ fn test_mat_ema_alpha_vec_sparse_multiple_elements() { vec![(0, I32F32::from_num(5.0)), (1, I32F32::from_num(6.0))], vec![(0, I32F32::from_num(7.0)), (1, I32F32::from_num(8.0))], ]; - let alpha: Vec = vec![I32F32::from_num(0.1), I32F32::from_num(0.2)]; - let result = mat_ema_alpha_vec_sparse(&new, &old, &alpha); + let alpha = vec![vec![I32F32::from_num(0.1), I32F32::from_num(0.2)]; 2]; + let result = mat_ema_alpha_sparse(&new, &old, &alpha); let expected = vec![ vec![(0, I32F32::from_num(1.0)), (1, I32F32::from_num(1.0))], vec![(0, I32F32::from_num(1.0)), (1, I32F32::from_num(1.0))], @@ -2578,25 +2586,25 @@ fn test_mat_ema_alpha_vec_sparse_multiple_elements() { } #[test] -fn test_mat_ema_alpha_vec_sparse_zero_alpha() { +fn test_mat_ema_alpha_sparse_zero_alpha() { let new: Vec> = vec![vec![(0, I32F32::from_num(1.0))]]; let old: Vec> = vec![vec![(0, I32F32::from_num(2.0))]]; - let alpha: Vec = vec![I32F32::from_num(0.0)]; - let result = mat_ema_alpha_vec_sparse(&new, &old, &alpha); + let alpha = vec![vec![I32F32::from_num(0.1), I32F32::from_num(0.0)]]; + let result = mat_ema_alpha_sparse(&new, &old, &alpha); assert_eq!(result, vec![vec![(0, I32F32::from_num(1.0))]]); } #[test] -fn test_mat_ema_alpha_vec_sparse_one_alpha() { +fn test_mat_ema_alpha_sparse_one_alpha() { let new: Vec> = vec![vec![(0, I32F32::from_num(1.0))]]; let old: Vec> = vec![vec![(0, I32F32::from_num(2.0))]]; - let alpha: Vec = vec![I32F32::from_num(1.0)]; - let result = mat_ema_alpha_vec_sparse(&new, &old, &alpha); + let alpha = vec![vec![I32F32::from_num(1.0), I32F32::from_num(0.0)]]; + let result = mat_ema_alpha_sparse(&new, &old, &alpha); assert_eq!(result, vec![vec![(0, I32F32::from_num(1.0))]]); } #[test] -fn test_mat_ema_alpha_vec_sparse_mixed_alpha() { +fn test_mat_ema_alpha_sparse_mixed_alpha() { let new: Vec> = vec![ vec![(0, I32F32::from_num(1.0)), (1, I32F32::from_num(2.0))], vec![(0, I32F32::from_num(3.0)), (1, I32F32::from_num(4.0))], @@ -2605,8 +2613,8 @@ fn test_mat_ema_alpha_vec_sparse_mixed_alpha() { vec![(0, I32F32::from_num(5.0)), (1, I32F32::from_num(6.0))], vec![(0, I32F32::from_num(7.0)), (1, I32F32::from_num(8.0))], ]; - let alpha: Vec = vec![I32F32::from_num(0.3), I32F32::from_num(0.7)]; - let result = mat_ema_alpha_vec_sparse(&new, &old, &alpha); + let alpha = vec![vec![I32F32::from_num(0.3), I32F32::from_num(0.7)]; 2]; + let result = mat_ema_alpha_sparse(&new, &old, &alpha); assert_sparse_mat_compare( &result, &[ @@ -2618,7 +2626,7 @@ fn test_mat_ema_alpha_vec_sparse_mixed_alpha() { } #[test] -fn test_mat_ema_alpha_vec_sparse_sparse_matrix() { +fn test_mat_ema_alpha_sparse_sparse_matrix() { let new: Vec> = vec![ vec![(0, I32F32::from_num(1.0))], vec![(1, I32F32::from_num(4.0))], @@ -2627,8 +2635,8 @@ fn test_mat_ema_alpha_vec_sparse_sparse_matrix() { vec![(0, I32F32::from_num(5.0))], vec![(1, I32F32::from_num(8.0))], ]; - let alpha: Vec = vec![I32F32::from_num(0.5), I32F32::from_num(0.5)]; - let result = mat_ema_alpha_vec_sparse(&new, &old, &alpha); + let alpha = vec![vec![I32F32::from_num(0.5), I32F32::from_num(0.5)]; 2]; + let result = mat_ema_alpha_sparse(&new, &old, &alpha); assert_eq!( result, vec![ @@ -2639,65 +2647,102 @@ fn test_mat_ema_alpha_vec_sparse_sparse_matrix() { } #[test] -fn test_mat_ema_alpha_vec_basic() { +fn test_mat_ema_alpha_basic() { let new = mat_to_fixed(&[vec![1.0, 2.0, 3.0], vec![4.0, 5.0, 6.0]]); let old = mat_to_fixed(&[vec![0.5, 1.5, 2.5], vec![3.5, 4.5, 5.5]]); let alpha = vec![ - I32F32::from_num(0.5), - I32F32::from_num(0.5), - I32F32::from_num(0.5), + vec![ + I32F32::from_num(0.5), + I32F32::from_num(0.5), + I32F32::from_num(0.5), + ]; + 2 ]; let expected = mat_to_fixed(&[vec![0.75, 1.0, 1.0], vec![1.0, 1.0, 1.0]]); - let result = mat_ema_alpha_vec(&new, &old, &alpha); + let result = mat_ema_alpha(&new, &old, &alpha); assert_eq!(result, expected); } #[test] -fn test_mat_ema_alpha_vec_varying_alpha() { +fn test_mat_ema_alpha_varying_alpha() { let new = mat_to_fixed(&[vec![1.0, 2.0, 3.0], vec![4.0, 5.0, 6.0]]); let old = mat_to_fixed(&[vec![0.5, 1.5, 2.5], vec![3.5, 4.5, 5.5]]); let alpha = vec![ - I32F32::from_num(0.2), - I32F32::from_num(0.5), - I32F32::from_num(0.8), + vec![ + I32F32::from_num(0.2), + I32F32::from_num(0.5), + I32F32::from_num(0.8), + ]; + 2 ]; let expected = mat_to_fixed(&[vec![0.6, 1.0, 1.0], vec![1.0, 1.0, 1.0]]); - let result = mat_ema_alpha_vec(&new, &old, &alpha); + let result = mat_ema_alpha(&new, &old, &alpha); assert_mat_approx_eq(&result, &expected, I32F32::from_num(1e-6)); } #[test] -fn test_mat_ema_alpha_vec_empty_matrices() { +fn test_mat_ema_alpha_sparse_varying_alpha() { + let weights = vec![ + vec![(0, I32F32::from_num(0.1)), (1, I32F32::from_num(0.2))], + vec![(0, I32F32::from_num(0.3)), (1, I32F32::from_num(0.4))], + ]; + let bonds = vec![ + vec![(0, I32F32::from_num(0.5)), (1, I32F32::from_num(0.6))], + vec![(0, I32F32::from_num(0.7)), (1, I32F32::from_num(0.8))], + ]; + let alpha = vec![ + vec![I32F32::from_num(0.9), I32F32::from_num(0.8)], + vec![I32F32::from_num(0.5), I32F32::from_num(0.7)], + ]; + + let expected = vec![ + vec![(0, I32F32::from_num(0.14)), (1, I32F32::from_num(0.28))], + vec![ + (0, I32F32::from_num(0.499999)), + (1, I32F32::from_num(0.519999)), + ], + ]; + + let result = mat_ema_alpha_sparse(&weights, &bonds, &alpha); + // Assert the results with an epsilon for approximate equality + assert_sparse_mat_compare(&result, &expected, I32F32::from_num(1e-6)); +} + +#[test] +fn test_mat_ema_alpha_empty_matrices() { let new: Vec> = vec![]; let old: Vec> = vec![]; - let alpha: Vec = vec![]; + let alpha = vec![]; let expected: Vec> = vec![vec![]; 1]; - let result = mat_ema_alpha_vec(&new, &old, &alpha); + let result = mat_ema_alpha(&new, &old, &alpha); assert_eq!(result, expected); } #[test] -fn test_mat_ema_alpha_vec_single_element() { +fn test_mat_ema_alpha_single_element() { let new = mat_to_fixed(&[vec![1.0]]); let old = mat_to_fixed(&[vec![0.5]]); - let alpha = vec![I32F32::from_num(0.5)]; + let alpha = vec![vec![I32F32::from_num(0.5)]]; let expected = mat_to_fixed(&[vec![0.75]]); - let result = mat_ema_alpha_vec(&new, &old, &alpha); + let result = mat_ema_alpha(&new, &old, &alpha); assert_eq!(result, expected); } // TODO: (@sd): Should these be non panicking? #[test] #[should_panic(expected = "assertion failed")] -fn test_mat_ema_alpha_vec_mismatched_dimensions() { +fn test_mat_ema_alpha_mismatched_dimensions() { let new = mat_to_fixed(&[vec![1.0, 2.0], vec![3.0, 4.0]]); let old = mat_to_fixed(&[vec![1.0, 2.0, 3.0], vec![4.0, 5.0, 6.0]]); let alpha = vec![ - I32F32::from_num(0.5), - I32F32::from_num(0.5), - I32F32::from_num(0.5), + vec![ + I32F32::from_num(0.5), + I32F32::from_num(0.5), + I32F32::from_num(0.5), + ]; + 2 ]; - let _result = mat_ema_alpha_vec(&new, &old, &alpha); + let _result = mat_ema_alpha(&new, &old, &alpha); } #[test] From 37057d3f70349f78cbd1a0ef5f2da772e563237a Mon Sep 17 00:00:00 2001 From: Andreea Popescu Date: Thu, 20 Mar 2025 14:08:17 +0000 Subject: [PATCH 27/45] cleanup fixes --- pallets/subtensor/src/epoch/math.rs | 171 ++-- pallets/subtensor/src/epoch/run_epoch.rs | 28 +- pallets/subtensor/src/tests/epoch.rs | 954 ++++++++++++----------- 3 files changed, 559 insertions(+), 594 deletions(-) diff --git a/pallets/subtensor/src/epoch/math.rs b/pallets/subtensor/src/epoch/math.rs index 9ae6be617f..9d783acc11 100644 --- a/pallets/subtensor/src/epoch/math.rs +++ b/pallets/subtensor/src/epoch/math.rs @@ -55,11 +55,6 @@ pub fn u16_proportion_to_fixed(x: u16) -> I32F32 { I32F32::saturating_from_num(x).safe_div(I32F32::saturating_from_num(u16::MAX)) } -#[allow(dead_code)] -pub fn fixed_proportion_to_fixed(x: I32F32) -> I32F32 { - x.safe_div(I32F32::saturating_from_num(u16::MAX)) -} - #[allow(dead_code)] pub fn fixed_proportion_to_u16(x: I32F32) -> u16 { fixed_to_u16(x.saturating_mul(I32F32::saturating_from_num(u16::MAX))) @@ -85,28 +80,11 @@ pub fn vec_fixed64_to_u64(vec: Vec) -> Vec { vec.into_iter().map(fixed64_to_u64).collect() } -#[allow(dead_code)] -pub fn vec_fixed_proportions_to_fixed(vec: Vec) -> Vec { - vec.into_iter().map(fixed_proportion_to_fixed).collect() -} - #[allow(dead_code)] pub fn vec_fixed_proportions_to_u16(vec: Vec) -> Vec { vec.into_iter().map(fixed_proportion_to_u16).collect() } -#[allow(dead_code)] -pub fn mat_fixed_proportions_to_u16(mat: Vec>) -> Vec> { - mat.into_iter().map(vec_fixed_proportions_to_u16).collect() -} - -#[allow(dead_code)] -pub fn mat_fixed_proportions_to_fixed(mat: Vec>) -> Vec> { - mat.into_iter() - .map(vec_fixed_proportions_to_fixed) - .collect() -} - #[allow(dead_code)] // Max-upscale vector and convert to u16 so max_value = u16::MAX. Assumes non-negative normalized input. pub fn vec_max_upscale_to_u16(vec: &[I32F32]) -> Vec { @@ -1316,19 +1294,6 @@ pub fn hadamard_sparse( result } -// Return sparse matrix only with elements >= threshold of an input sparse matrix. -#[allow(dead_code)] -pub fn sparse_threshold(w: &[Vec<(u16, I32F32)>], threshold: I32F32) -> Vec> { - w.iter() - .map(|row| { - row.iter() - .filter(|(_, weight)| *weight >= threshold) - .copied() - .collect() - }) - .collect() -} - /// Clamp the input value between high and low. pub fn clamp_value(value: I32F32, low: I32F32, high: I32F32) -> I32F32 { // First, clamp the value to ensure it does not exceed the upper bound (high). @@ -1402,78 +1367,7 @@ pub fn mat_ema_sparse( result } -/// Return matrix exponential moving average: `alpha_j * a_ij + one_minus_alpha_j * b_ij`. -/// `alpha_` is the EMA coefficient passed as a vector per column. -#[allow(dead_code)] -pub fn mat_ema_alpha( - new: &[Vec], // Weights - old: &[Vec], // Bonds - alpha: &[Vec], -) -> Vec> { - // Check if the new matrix is empty or its first row is empty. - if new.is_empty() || new.first().is_none_or(|row| row.is_empty()) { - return vec![vec![]; 1]; - } - - // Ensure the dimensions of the new, old and alpha matrices match. - assert!(new.len() == old.len()); - assert!(new.len() == alpha.len()); - - // Initialize the result matrix with zeros, having the same dimensions as the new matrix. - let mut result: Vec> = - vec![ - vec![I32F32::saturating_from_num(0.0); new.first().map_or(0, |row| row.len())]; - new.len() - ]; - - // Iterate over each row of the matrices. - for (i, ((new_row, old_row), alpha_row)) in new.iter().zip(old).zip(alpha).enumerate() { - assert!(new_row.len() == old_row.len()); - assert!(new_row.len() == alpha_row.len()); - - // Iterate over each column of the current row. - for j in 0..new_row.len() { - // Compute the EMA for the current element using saturating operations. - if let (Some(new_val), Some(old_val), Some(alpha_val), Some(result_val)) = ( - new_row.get(j), - old_row.get(j), - alpha_row.get(j), - result.get_mut(i).and_then(|row| row.get_mut(j)), - ) { - // Calculate the complement of the alpha value - let one_minus_alpha = I32F32::saturating_from_num(1.0).saturating_sub(*alpha_val); - - // Bonds_decayed = Bonds * (1 - alpha) - let decayed_val = one_minus_alpha.saturating_mul(*old_val); - - // Calculate remaining capacity to limit bonds purchase - let remaining_capacity = I32F32::from_num(1.0) - .saturating_sub(decayed_val) - .max(I32F32::from_num(0.0)); - - // Each validator can increase bonds by at most clamped_alpha per epoch towards the cap - // Validators allocate their purchase across miners based on weights - let purchase_increment = alpha_val.saturating_mul(*new_val); - - // Ensure that purchase does not exceed remaining capacity - let purchase = purchase_increment.min(remaining_capacity); - - *result_val = decayed_val - .saturating_add(purchase) - .min(I32F32::from_num(1.0)); - } - } - } - - // Return the computed EMA matrix. - result -} - /// Calculates the exponential moving average (EMA) for a sparse matrix using dynamic alpha values. -/// Return matrix exponential moving average: `alpha_j * a_ij + one_minus_alpha_j * b_ij`. -// `alpha` is the EMA coefficient, how much to add of the new observation, typically small, -// higher alpha discounts older observations faster. -// if liquid alpha off then the alpha vector will be constant #[allow(dead_code)] pub fn mat_ema_alpha_sparse( new: &[Vec<(u16, I32F32)>], @@ -1539,6 +1433,71 @@ pub fn mat_ema_alpha_sparse( result } +/// Calculates the exponential moving average (EMA) for a dense matrix using dynamic alpha values. +#[allow(dead_code)] +pub fn mat_ema_alpha( + new: &[Vec], // Weights + old: &[Vec], // Bonds + alpha: &[Vec], +) -> Vec> { + // Check if the new matrix is empty or its first row is empty. + if new.is_empty() || new.first().is_none_or(|row| row.is_empty()) { + return vec![vec![]; 1]; + } + + // Ensure the dimensions of the new, old and alpha matrices match. + assert!(new.len() == old.len()); + assert!(new.len() == alpha.len()); + + // Initialize the result matrix with zeros, having the same dimensions as the new matrix. + let mut result: Vec> = + vec![ + vec![I32F32::saturating_from_num(0.0); new.first().map_or(0, |row| row.len())]; + new.len() + ]; + + // Iterate over each row of the matrices. + for (i, ((new_row, old_row), alpha_row)) in new.iter().zip(old).zip(alpha).enumerate() { + assert!(new_row.len() == old_row.len()); + assert!(new_row.len() == alpha_row.len()); + + // Iterate over each column of the current row. + for j in 0..new_row.len() { + // Compute the EMA for the current element using saturating operations. + if let (Some(new_val), Some(old_val), Some(alpha_val), Some(result_val)) = ( + new_row.get(j), + old_row.get(j), + alpha_row.get(j), + result.get_mut(i).and_then(|row| row.get_mut(j)), + ) { + // Calculate the complement of the alpha value + let one_minus_alpha = I32F32::saturating_from_num(1.0).saturating_sub(*alpha_val); + + // Bonds_decayed = Bonds * (1 - alpha) + let decayed_val = one_minus_alpha.saturating_mul(*old_val); + + // Calculate remaining capacity to limit bonds purchase + let remaining_capacity = I32F32::from_num(1.0) + .saturating_sub(decayed_val) + .max(I32F32::from_num(0.0)); + + // Each validator can increase bonds by at most clamped_alpha per epoch towards the cap + // Validators allocate their purchase across miners based on weights + let purchase_increment = alpha_val.saturating_mul(*new_val); + + // Ensure that purchase does not exceed remaining capacity + let purchase = purchase_increment.min(remaining_capacity); + + *result_val = decayed_val + .saturating_add(purchase) + .min(I32F32::from_num(1.0)); + } + } + } + + // Return the computed EMA matrix. + result +} /// Return the quantile of a vector of I32F32 values. pub fn quantile(data: &[I32F32], quantile: f64) -> I32F32 { // Clone the input data to avoid modifying the original vector. diff --git a/pallets/subtensor/src/epoch/run_epoch.rs b/pallets/subtensor/src/epoch/run_epoch.rs index 2b3037ee94..347828b6f3 100644 --- a/pallets/subtensor/src/epoch/run_epoch.rs +++ b/pallets/subtensor/src/epoch/run_epoch.rs @@ -200,7 +200,6 @@ impl Pallet { // Access network bonds. let mut bonds: Vec> = Self::get_bonds(netuid); inplace_mask_matrix(&outdated, &mut bonds); // mask outdated bonds - bonds = mat_fixed_proportions_to_fixed(bonds.clone()); // TODO log::trace!("B: {:?}", &bonds); // Compute the Exponential Moving Average (EMA) of bonds. @@ -587,16 +586,7 @@ impl Pallet { &block_at_registration, &|last_tempo, registered| last_tempo <= registered, ); - log::trace!("Bonds (outdatedmask): {:?}", &bonds); - - let mut result: Vec> = vec![vec![]; bonds.len()]; - for (i, sparse_row) in bonds.iter().enumerate() { - for (j, value) in sparse_row { - result[i].push((*j, fixed_proportion_to_fixed(*value))); - } - } - let bonds = result; - log::trace!("Bonds: (mask+norm) {:?}", &bonds); + log::trace!("Bonds: (mask) {:?}", &bonds); // Compute the Exponential Moving Average (EMA) of bonds. log::trace!("weights_for_bonds: {:?}", &weights_for_bonds); @@ -867,7 +857,7 @@ impl Pallet { bonds .get_mut(uid_i as usize) .expect("uid_i is filtered to be less than n; qed") - .push((uid_j, I32F32::saturating_from_num(bonds_ij))); + .push((uid_j, u16_proportion_to_fixed(bonds_ij))); } } bonds @@ -887,7 +877,7 @@ impl Pallet { .expect("uid_i has been filtered to be less than n; qed") .get_mut(uid_j as usize) .expect("uid_j has been filtered to be less than n; qed") = - I32F32::saturating_from_num(bonds_ij); + u16_proportion_to_fixed(bonds_ij); } } bonds @@ -932,16 +922,14 @@ impl Pallet { // Compute bonds delta column normalized. let mut bonds_delta: Vec> = row_hadamard(weights, active_stake); // ΔB = W◦S inplace_col_normalize(&mut bonds_delta); // sum_i b_ij = 1 - log::trace!("ΔB:\n{:?}\n", &bonds_delta); + log::trace!("ΔB: {:?}", &bonds_delta); // Compute the Exponential Moving Average (EMA) of bonds using the calculated alpha value. - - // Return the computed EMA bonds. mat_ema(&bonds_delta, bonds, alpha) } } - /// Compute the Exponential Moving Average (EMA) of bonds based on the Liquid Alpha setting + /// Compute the Exponential Moving Average (EMA) of bonds based on the Liquid Alpha setting for a sparse matrix. /// /// # Args: /// * `netuid` - The network ID. @@ -983,11 +971,9 @@ impl Pallet { let mut bonds_delta: Vec> = row_hadamard_sparse(weights, active_stake); // ΔB = W◦S inplace_col_normalize_sparse(&mut bonds_delta, n); // sum_i b_ij = 1 - log::trace!("ΔB:\n{:?}\n", &bonds_delta); + log::trace!("ΔB: {:?}", &bonds_delta); // Compute the Exponential Moving Average (EMA) of bonds using the calculated alpha value. - - // Return the computed EMA bonds. mat_ema_sparse(&bonds_delta, bonds, alpha) } } @@ -1065,7 +1051,7 @@ impl Pallet { /// * `consensus` - A vector of consensus values. /// /// # Returns: - /// A matrix of alphas (not sparse as very few values will be zero) + /// A dense matrix of alphas pub fn compute_liquid_alpha_values_sparse( netuid: u16, weights: &[Vec<(u16, I32F32)>], // current epoch weights diff --git a/pallets/subtensor/src/tests/epoch.rs b/pallets/subtensor/src/tests/epoch.rs index 89812bfb27..733372c728 100644 --- a/pallets/subtensor/src/tests/epoch.rs +++ b/pallets/subtensor/src/tests/epoch.rs @@ -5,7 +5,7 @@ )] use super::mock::*; -use crate::epoch::math::{fixed, mat_fixed_proportions_to_fixed, u16_proportion_to_fixed}; +use crate::epoch::math::{fixed, u16_proportion_to_fixed}; use crate::*; use approx::assert_abs_diff_eq; @@ -714,7 +714,7 @@ fn test_512_graph() { assert_eq!(SubtensorModule::get_dividends_for_uid(netuid, uid), 1023); // Note D = floor(1 / 64 * 65_535) = 1023 assert_eq!(SubtensorModule::get_emission_for_uid(netuid, uid), 7812500); // Note E = 0.5 / 200 * 1_000_000_000 = 7_812_500 assert_eq!(bonds[uid as usize][validator], 0.0); - assert_eq!(bonds[uid as usize][server], I32F32::from_num(38)); + assert_eq!(bonds[uid as usize][server], I32F32::from_num(276)); } for uid in servers { assert_eq!( @@ -1053,42 +1053,50 @@ fn test_bonds() { SubtensorModule::epoch_dense(netuid, 1_000_000_000); } /* n: 8 - current_block: 2, activity_cutoff: 5000, Last update: [2, 2, 2, 2, 1, 1, 1, 1] - Inactive: [false, false, false, false, false, false, false, false] + current_block: 2 + activity_cutoff: 5000 + Last update: [2, 2, 2, 2, 1, 1, 1, 1] Block at registration: [1, 1, 1, 1, 1, 1, 1, 1] - hotkeys: [(0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7)] - S: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] validator_permits: [true, true, true, true, true, true, true, true] max_allowed_validators: 8 new_validator_permits: [true, true, true, true, true, true, true, true] - S: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] - W: [[(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - W (permit): [[(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - W (permit+diag): [[(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - W (permit+diag+outdate): [[(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - C: [0, 0, 0, 0, 0.0999975584, 0.2000012207, 0.2999926754, 0.400008545] - W: [[(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] - Tv: [0.9999999995, 0.9999999995, 0.9999999995, 0.9999999995, 0, 0, 0, 0] - R (after): [0, 0, 0, 0, 0.099997558, 0.2000012202, 0.2999926745, 0.4000085443] - T: [0, 0, 0, 0, 1, 1, 1, 1] - I (=R): [0, 0, 0, 0, 0.0999975582, 0.2000012207, 0.2999926752, 0.4000085455] - B: [[], [], [], [], [], [], [], []] - B (outdatedmask): [[], [], [], [], [], [], [], []] - B: [[], [], [], [], [], [], [], []] - alphas: [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1] - emaB: [[(4, 0.0099997558), (5, 0.020000122), (6, 0.0299992675), (7, 0.0400008545)], [(4, 0.0099997558), (5, 0.020000122), (6, 0.0299992675), (7, 0.0400008545)], [(4, 0.0099997558), (5, 0.020000122), (6, 0.0299992675), (7, 0.0400008545)], [(4, 0.0099997558), (5, 0.020000122), (6, 0.0299992675), (7, 0.0400008545)], [], [], [], []] - emaB norm: [[(4, 0.25), (5, 0.25), (6, 0.25), (7, 0.25)], [(4, 0.25), (5, 0.25), (6, 0.25), (7, 0.25)], [(4, 0.25), (5, 0.25), (6, 0.25), (7, 0.25)], [(4, 0.25), (5, 0.25), (6, 0.25), (7, 0.25)], [], [], [], []] - total_bonds_per_validator: [0.2499999995, 0.2499999995, 0.2499999995, 0.2499999995, 0, 0, 0, 0] - D: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] - nE: [0.0499999998, 0.0999999999, 0.15, 0.2, 0.049998779, 0.1000006103, 0.1499963375, 0.2000042726] - E: [49999999, 99999999, 149999999, 199999999, 49998779, 100000610, 149996337, 200004272] - P: [0.0499999998, 0.0999999999, 0.15, 0.2, 0.049998779, 0.1000006103, 0.1499963375, 0.2000042726] + Active Stake: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] + Weights: [[(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + Weights (permit): [[(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + Weights (permit+diag): [[(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + Weights (permit+diag+outdate): [[(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + Weights (mask+norm): [[(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] + Ranks (before): [0, 0, 0, 0, 0.099997558, 0.2000012202, 0.2999926745, 0.4000085443] + Consensus: [0, 0, 0, 0, 0.0999975584, 0.2000012207, 0.2999926754, 0.400008545] + Clipped Weights: [[(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] + Validator Trust: [0.9999999995, 0.9999999995, 0.9999999995, 0.9999999995, 0, 0, 0, 0] + Ranks (after): [0, 0, 0, 0, 0.099997558, 0.2000012202, 0.2999926745, 0.4000085443] + Trust: [0, 0, 0, 0, 1, 1, 1, 1] + Incentive (=Rank): [0, 0, 0, 0, 0.0999975582, 0.2000012207, 0.2999926752, 0.4000085455] + Bonds: [[], [], [], [], [], [], [], []] + Bonds: (mask+norm) [[], [], [], [], [], [], [], []] + weights_for_bonds: [[(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] + ΔB: + , 0.1999999997), (7, 0.1999999997)], [(4, 0.299999999), (5, 0.2999999998), (6, 0.3), (7, 0.3)], [(4, 0.4000000013), (5, 0.4), (6, 0.4000000004), (7, 0.4000000001)], [], [], [], []] + + emaB: [[(4, 0.0099999998), (5, 0.0099999998), (6, 0.0099999998), (7, 0.0099999998)], [(4, 0.0199999998), (5, 0.0199999998), (6, 0.0199999998), (7, 0.0199999998)], [(4, 0.0299999998), (5, 0.0299999998), (6, 0.03), (7, 0.03)], [(4, 0.04), (5, 0.0399999998), (6, 0.04), (7, 0.04)], [], [], [], []] + emaB norm: [[(4, 0.0999999982), (5, 0.0999999985), (6, 0.099999998), (7, 0.099999998)], [(4, 0.199999999), (5, 0.1999999995), (6, 0.1999999986), (7, 0.1999999986)], [(4, 0.2999999996), (5, 0.3000000003), (6, 0.3000000012), (7, 0.3000000012)], [(4, 0.4000000027), (5, 0.4000000013), (6, 0.4000000018), (7, 0.4000000018)], [], [], [], []] + total_bonds_per_validator: [0.0999999975, 0.1999999979, 0.3000000003, 0.4000000008, 0, 0, 0, 0] + Dividends: [0.0333333318, 0.1333333314, 0.3000000005, 0.5333333358, 0, 0, 0, 0] + Normalized Server Emission: [0, 0, 0, 0, 0.049998779, 0.1000006103, 0.1499963375, 0.2000042726] + Server Emission: [0, 0, 0, 0, 49998779, 100000610, 149996337, 200004272] + Normalized Validator Emission: [0.016666666, 0.0666666657, 0.1500000001, 0.266666668, 0, 0, 0, 0] + Validator Emission: [16666665, 66666665, 150000000, 266666668, 0, 0, 0, 0] + Normalized Combined Emission: [0.016666666, 0.0666666657, 0.1500000001, 0.266666668, 0.049998779, 0.1000006103, 0.1499963375, 0.2000042726] + Combined Emission: [16666665, 66666665, 150000000, 266666668, 49998779, 100000610, 149996337, 200004272] + Pruning Scores: [0.016666666, 0.0666666657, 0.1500000001, 0.266666668, 0.049998779, 0.1000006103, 0.1499963375, 0.2000042726] */ + let bonds = SubtensorModule::get_bonds(netuid); assert_eq!(bonds[0][4], 655); - assert_eq!(bonds[1][4], 655); - assert_eq!(bonds[2][4], 655); - assert_eq!(bonds[3][4], 655); + assert_eq!(bonds[1][4], 1310); + assert_eq!(bonds[2][4], 1966); + assert_eq!(bonds[3][4], 2621); // === Set self-weight only on val1 let uid = 0; @@ -1106,41 +1114,46 @@ fn test_bonds() { SubtensorModule::epoch_dense(netuid, 1_000_000_000); } /* n: 8 - current_block: 3, activity_cutoff: 5000, Last update: [2, 2, 2, 2, 1, 1, 1, 1] - Inactive: [false, false, false, false, false, false, false, false] + current_block: 3 + activity_cutoff: 5000 + Last update: [2, 2, 2, 2, 1, 1, 1, 1] Block at registration: [1, 1, 1, 1, 1, 1, 1, 1] - hotkeys: [(0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7)] - S: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] validator_permits: [true, true, true, true, true, true, true, true] max_allowed_validators: 8 new_validator_permits: [true, true, true, true, true, true, true, true] - S: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] - W: [[(0, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - W (permit): [[(0, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - W (permit+diag): [[], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - W (permit+diag+outdate): [[], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - C: [0, 0, 0, 0, 0.0999975584, 0.2000012207, 0.2999926754, 0.400008545] - W: [[], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] - Tv: [0, 0.9999999995, 0.9999999995, 0.9999999995, 0, 0, 0, 0] - R (after): [0, 0, 0, 0, 0.0899978022, 0.1800010982, 0.2699934072, 0.36000769] - T: [0, 0, 0, 0, 1, 1, 1, 1] - I (=R): [0, 0, 0, 0, 0.0999975582, 0.2000012207, 0.2999926754, 0.4000085455] - B: [[(4, 655), (5, 1310), (6, 1966), (7, 2621)], [(4, 655), (5, 1310), (6, 1966), (7, 2621)], [(4, 655), (5, 1310), (6, 1966), (7, 2621)], [(4, 655), (5, 1310), (6, 1966), (7, 2621)], [], [], [], []] - B (outdatedmask): [[(4, 655), (5, 1310), (6, 1966), (7, 2621)], [(4, 655), (5, 1310), (6, 1966), (7, 2621)], [(4, 655), (5, 1310), (6, 1966), (7, 2621)], [(4, 655), (5, 1310), (6, 1966), (7, 2621)], [], [], [], []] - B: [[(4, 0.0099946593), (5, 0.0199893187), (6, 0.029999237), (7, 0.0399938964)], [(4, 0.0099946593), (5, 0.0199893187), (6, 0.029999237), (7, 0.0399938964)], [(4, 0.0099946593), (5, 0.0199893187), (6, 0.029999237), (7, 0.0399938964)], [(4, 0.0099946593), (5, 0.0199893187), (6, 0.029999237), (7, 0.0399938964)], [], [], [], []] - alphas: [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1] - emaB: [[(4, 0.0089951933), (5, 0.0179903866), (6, 0.0269993132), (7, 0.0359945067)], [(4, 0.018994949), (5, 0.0379905086), (6, 0.0569985807), (7, 0.0759953612)], [(4, 0.018994949), (5, 0.0379905086), (6, 0.0569985807), (7, 0.0759953612)], [(4, 0.018994949), (5, 0.0379905086), (6, 0.0569985807), (7, 0.0759953612)], [], [], [], []] - emaB norm: [[(4, 0.1363320365), (5, 0.1363301442), (6, 0.136363573), (7, 0.1363528532)], [(4, 0.287889321), (5, 0.2878899518), (6, 0.2878788088), (7, 0.287882382)], [(4, 0.287889321), (5, 0.2878899518), (6, 0.2878788088), (7, 0.287882382)], [(4, 0.287889321), (5, 0.2878899518), (6, 0.2878788088), (7, 0.287882382)], [], [], [], []] - total_bonds_per_validator: [0.136349445, 0.2878835173, 0.2878835173, 0.2878835173, 0, 0, 0, 0] - D: [0.0499942757, 0.211112383, 0.3166685747, 0.422224766, 0, 0, 0, 0] - nE: [0.0249971377, 0.1055561914, 0.1583342873, 0.211112383, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] - E: [24997137, 105556191, 158334287, 211112383, 49998779, 100000610, 149996337, 200004272] - P: [0.0249971377, 0.1055561914, 0.1583342873, 0.211112383, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] + Active Stake: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] + Weights: [[(0, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + Weights (permit): [[(0, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + Weights (permit+diag): [[], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + Weights (permit+diag+outdate): [[], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + Weights (mask+norm): [[], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0 + .400008545)], [], [], [], []] + Ranks (before): [0, 0, 0, 0, 0.0899978022, 0.1800010982, 0.2699934072, 0.36000769] + Consensus: [0, 0, 0, 0, 0.0999975584, 0.2000012207, 0.2999926754, 0.400008545] + Clipped Weights: [[], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] + Validator Trust: [0, 0.9999999995, 0.9999999995, 0.9999999995, 0, 0, 0, 0] + Ranks (after): [0, 0, 0, 0, 0.0899978022, 0.1800010982, 0.2699934072, 0.36000769] + Trust: [0, 0, 0, 0, 1, 1, 1, 1] + Incentive (=Rank): [0, 0, 0, 0, 0.0999975582, 0.2000012207, 0.2999926754, 0.4000085455] + Bonds: [[(4, 655), (5, 655), (6, 655), (7, 655)], [(4, 1310), (5, 1310), (6, 1310), (7, 1310)], [(4, 1966), (5, 1966), (6, 1966), (7, 1966)], [(4, 2621), (5, 2621), (6, 2621), (7, 2621)], [], [], [], []] + Bonds: (mask+norm) [[(4, 0.0099946593), (5, 0.0099946593), (6, 0.0099946593), (7, 0.0099946593)], [(4, 0.0199893187), (5, 0.0199893187), (6, 0.0199893187), (7, 0.0199893187)], [(4, 0.029999237), (5, 0.029999237), (6, 0.029999237), (7, 0.029999237)], [(4, 0.0399938964), (5, 0.0399938964), (6, 0.0399938964), (7, 0.0399938964)], [], [], [], []] + weights_for_bonds: [[], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] + emaB: [[(4, 0.0089951933), (5, 0.0089951933), (6, 0.0089951933), (7, 0.0089951933)], [(4, 0.0402126086), (5, 0.0402126086), (6, 0.0402126086), (7, 0.0402126086)], [(4, 0.0603326464), (5, 0.0603326464), (6, 0.0603326464), (7, 0.0603326464)], [(4, 0.0804389513), (5, 0.080438951), (6, 0.080438951), (7, 0.080438951)], [], [], [], []] + emaB norm: [[(4, 0.0473482562), (5, 0.0473482562), (6, 0.0473482562), (7, 0.0473482562)], [(4, 0.2116682583), (5, 0.2116682585), (6, 0.2116682585), (7, 0.2116682585)], [(4, 0.3175746764), (5, 0.3175746768), (6, 0.3175746768), (7, 0.3175746768)], [(4, 0.4234088087), (5, 0.423408808), (6, 0.423408808), (7, 0.423408808)], [], [], [], []] + total_bonds_per_validator: [0.0473482558, 0.2116682578, 0.3175746764, 0.4234088075, 0, 0, 0, 0] + Dividends: [0.0151901136, 0.1358134532, 0.3056498466, 0.5433465862, 0, 0, 0, 0] + Normalized Server Emission: [0, 0, 0, 0, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] + Server Emission: [0, 0, 0, 0, 49998779, 100000610, 149996337, 200004272] + Normalized Validator Emission: [0.0075950567, 0.0679067266, 0.1528249232, 0.271673293, 0, 0, 0, 0] + Validator Emission: [7595056, 67906726, 152824923, 271673293, 0, 0, 0, 0] + Normalized Combined Emission: [0.0075950567, 0.0679067266, 0.1528249232, 0.271673293, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] + Combined Emission: [7595056, 67906726, 152824923, 271673293, 49998779, 100000610, 149996337, 200004272] + Pruning Scores: [0.0075950567, 0.0679067266, 0.1528249232, 0.271673293, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] */ assert_eq!(bonds[0][4], 655); - assert_eq!(bonds[1][4], 655); - assert_eq!(bonds[2][4], 655); - assert_eq!(bonds[3][4], 655); + assert_eq!(bonds[1][4], 1310); + assert_eq!(bonds[2][4], 1966); + assert_eq!(bonds[3][4], 2621); // === Set self-weight only on val2 let uid = 1; @@ -1157,43 +1170,47 @@ fn test_bonds() { } else { SubtensorModule::epoch_dense(netuid, 1_000_000_000); } - /* current_block: 3 - current_block: 4, activity_cutoff: 5000, Last update: [2, 3, 2, 2, 1, 1, 1, 1] - Inactive: [false, false, false, false, false, false, false, false] + /* n: 8 + current_block: 4 + activity_cutoff: 5000 + Last update: [2, 3, 2, 2, 1, 1, 1, 1] Block at registration: [1, 1, 1, 1, 1, 1, 1, 1] - hotkeys: [(0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7)] - S: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] validator_permits: [true, true, true, true, true, true, true, true] max_allowed_validators: 8 new_validator_permits: [true, true, true, true, true, true, true, true] - S: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] - W: [[(0, 65535)], [(1, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - W (permit): [[(0, 65535)], [(1, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - W (permit+diag): [[], [], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - W (permit+diag+outdate): [[], [], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - C: [0, 0, 0, 0, 0.0999975584, 0.2000012207, 0.2999926754, 0.400008545] - W: [[], [], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] - Tv: [0, 0, 0.9999999995, 0.9999999995, 0, 0, 0, 0] - R (after): [0, 0, 0, 0, 0.0699982906, 0.1400008542, 0.2099948723, 0.2800059812] - T: [0, 0, 0, 0, 1, 1, 1, 1] - I (=R): [0, 0, 0, 0, 0.0999975582, 0.2000012207, 0.2999926754, 0.4000085455] - B: [[(4, 589), (5, 1178), (6, 1769), (7, 2358)], [(4, 1244), (5, 2489), (6, 3735), (7, 4980)], [(4, 1244), (5, 2489), (6, 3735), (7, 4980)], [(4, 1244), (5, 2489), (6, 3735), (7, 4980)], [], [], [], []] - B (outdatedmask): [[(4, 589), (5, 1178), (6, 1769), (7, 2358)], [(4, 1244), (5, 2489), (6, 3735), (7, 4980)], [(4, 1244), (5, 2489), (6, 3735), (7, 4980)], [(4, 1244), (5, 2489), (6, 3735), (7, 4980)], [], [], [], []] - B: [[(4, 0.008987564), (5, 0.0179751278), (6, 0.0269932097), (7, 0.0359807736)], [(4, 0.0189822232), (5, 0.0379797055), (6, 0.0569924468), (7, 0.075989929)], [(4, 0.0189822232), (5, 0.0379797055), (6, 0.0569924468), (7, 0.075989929)], [(4, 0.0189822232), (5, 0.0379797055), (6, 0.0569924468), (7, 0.075989929)], [], [], [], []] - alphas: [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1] - emaB: [[(4, 0.0080888073), (5, 0.016177615), (6, 0.0242938886), (7, 0.0323826962)], [(4, 0.0170840009), (5, 0.0341817348), (6, 0.051293202), (7, 0.068390936)], [(4, 0.0270837566), (5, 0.0541818568), (6, 0.0812924695), (7, 0.1083917904)], [(4, 0.0270837566), (5, 0.0541818568), (6, 0.0812924695), (7, 0.1083917904)], [], [], [], []] - emaB norm: [[(4, 0.1019507758), (5, 0.10192353), (6, 0.102001434), (7, 0.101974368)], [(4, 0.2153255814), (5, 0.2153545555), (6, 0.2153619886), (7, 0.215365714)], [(4, 0.3413618212), (5, 0.341360957), (6, 0.3413182884), (7, 0.3413299588)], [(4, 0.3413618212), (5, 0.341360957), (6, 0.3413182884), (7, 0.3413299588)], [], [], [], []] - total_bonds_per_validator: [0.1019699604, 0.215358351, 0.3413358429, 0.3413358429, 0, 0, 0, 0] - D: [0.034896868, 0.1474028623, 0.3504429725, 0.4672572967, 0, 0, 0, 0] - nE: [0.017448434, 0.073701431, 0.1752214862, 0.2336286483, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] - E: [17448433, 73701431, 175221486, 233628648, 49998779, 100000610, 149996337, 200004272] - P: [0.017448434, 0.073701431, 0.1752214862, 0.2336286483, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] + Active Stake: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] + Weights: [[(0, 65535)], [(1, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + Weights (permit): [[(0, 65535)], [(1, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + Weights (permit+diag): [[], [], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + Weights (permit+diag+outdate): [[], [], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + Weights (mask+norm): [[], [], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] + Ranks (before): [0, 0, 0, 0, 0.0699982906, 0.1400008542, 0.2099948723, 0.2800059812] + Consensus: [0, 0, 0, 0, 0.0999975584, 0.2000012207, 0.2999926754, 0.400008545] + Clipped Weights: [[], [], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] + Validator Trust: [0, 0, 0.9999999995, 0.9999999995, 0, 0, 0, 0] + Ranks (after): [0, 0, 0, 0, 0.0699982906, 0.1400008542, 0.2099948723, 0.2800059812] + Trust: [0, 0, 0, 0, 1, 1, 1, 1] + Incentive (=Rank): [0, 0, 0, 0, 0.0999975582, 0.2000012207, 0.2999926754, 0.4000085455] + Bonds: [[(4, 589), (5, 589), (6, 589), (7, 589)], [(4, 2635), (5, 2635), (6, 2635), (7, 2635)], [(4, 3953), (5, 3953), (6, 3953), (7, 3953)], [(4, 5271), (5, 5271), (6, 5271), (7, 5271)], [], [], [], []] + Bonds: (mask+norm) [[(4, 0.008987564), (5, 0.008987564), (6, 0.008987564), (7, 0.008987564)], [(4, 0.0402075227), (5, 0.0402075227), (6, 0.0402075227), (7, 0.0402075227)], [(4, 0.0603189135), (5, 0.0603189135), (6, 0.0603189135), (7, 0.0603189135)], [(4, 0.0804303044), (5, 0.0804303044), (6, 0.0804303044), (7, 0.0804303044)], [], [], [], []] + weights_for_bonds: [[], [], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] + emaB: [[(4, 0.0080888073), (5, 0.0080888073), (6, 0.0080888073), (7, 0.0080888073)], [(4, 0.0361867703), (5, 0.0361867703), (6, 0.0361867703), (7, 0.0361867703)], [(4, 0.0971441646), (5, 0.0971441648), (6, 0.0971441648), (7, 0.0971441648)], [(4, 0.1295301311), (5, 0.129530131), (6, 0.129530131), (7, 0.129530131)], [], [], [], []] + emaB norm: [[(4, 0.0298535195), (5, 0.0298535195), (6, 0.0298535195), (7, 0.0298535195)], [(4, 0.1335552211), (5, 0.1335552211), (6, 0.1335552211), (7, 0.1335552211)], [(4, 0.3585318692), (5, 0.3585318702), (6, 0.3585318702), (7, 0.3585318702)], [(4, 0.4780593896), (5, 0.4780593887), (6, 0.4780593887), (7, 0.4780593887)], [], [], [], []] + total_bonds_per_validator: [0.0298535188, 0.1335552207, 0.3585318697, 0.4780593882, 0, 0, 0, 0] + Dividends: [0.0090883898, 0.08131718, 0.3274465878, 0.5821478418, 0, 0, 0, 0] + Normalized Server Emission: [0, 0, 0, 0, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] + Server Emission: [0, 0, 0, 0, 49998779, 100000610, 149996337, 200004272] + Normalized Validator Emission: [0.0045441948, 0.04065859, 0.163723294, 0.291073921, 0, 0, 0, 0] + Validator Emission: [4544194, 40658589, 163723293, 291073920, 0, 0, 0, 0] + Normalized Combined Emission: [0.0045441948, 0.04065859, 0.163723294, 0.291073921, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] + Combined Emission: [4544194, 40658589, 163723293, 291073920, 49998779, 100000610, 149996337, 200004272] + Pruning Scores: [0.0045441948, 0.04065859, 0.163723294, 0.291073921, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] */ let bonds = SubtensorModule::get_bonds(netuid); assert_eq!(bonds[0][4], 530); - assert_eq!(bonds[1][4], 1119); - assert_eq!(bonds[2][4], 1774); - assert_eq!(bonds[3][4], 1774); + assert_eq!(bonds[1][4], 2371); + assert_eq!(bonds[2][4], 6366); + assert_eq!(bonds[3][4], 8488); // === Set self-weight only on val2 let uid = 1; @@ -1210,43 +1227,47 @@ fn test_bonds() { } else { SubtensorModule::epoch_dense(netuid, 1_000_000_000); } - /* current_block: 4 - current_block: 5, activity_cutoff: 5000, Last update: [2, 4, 2, 2, 1, 1, 1, 1] - Inactive: [false, false, false, false, false, false, false, false] + /* n: 8 + current_block: 5 + activity_cutoff: 5000 + Last update: [2, 4, 2, 2, 1, 1, 1, 1] Block at registration: [1, 1, 1, 1, 1, 1, 1, 1] - hotkeys: [(0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7)] - S: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] validator_permits: [true, true, true, true, true, true, true, true] max_allowed_validators: 8 new_validator_permits: [true, true, true, true, true, true, true, true] - S: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] - W: [[(0, 65535)], [(1, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - W (permit): [[(0, 65535)], [(1, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - W (permit+diag): [[], [], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - W (permit+diag+outdate): [[], [], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - C: [0, 0, 0, 0, 0.0999975584, 0.2000012207, 0.2999926754, 0.400008545] - W: [[], [], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] - Tv: [0, 0, 0.9999999995, 0.9999999995, 0, 0, 0, 0] - R (after): [0, 0, 0, 0, 0.0699982906, 0.1400008542, 0.2099948723, 0.2800059812] - T: [0, 0, 0, 0, 1, 1, 1, 1] - I (=R): [0, 0, 0, 0, 0.0999975582, 0.2000012207, 0.2999926754, 0.4000085455] - B: [[(4, 530), (5, 1060), (6, 1592), (7, 2122)], [(4, 1119), (5, 2240), (6, 3361), (7, 4481)], [(4, 1774), (5, 3550), (6, 5327), (7, 7103)], [(4, 1774), (5, 3550), (6, 5327), (7, 7103)], [], [], [], []] - B (outdatedmask): [[(4, 530), (5, 1060), (6, 1592), (7, 2122)], [(4, 1119), (5, 2240), (6, 3361), (7, 4481)], [(4, 1774), (5, 3550), (6, 5327), (7, 7103)], [(4, 1774), (5, 3550), (6, 5327), (7, 7103)], [], [], [], []] - B: [[(4, 0.0080872816), (5, 0.0161745632), (6, 0.0242923629), (7, 0.0323796445)], [(4, 0.0170748455), (5, 0.034180209), (6, 0.0512855726), (7, 0.068375677)], [(4, 0.0270695048), (5, 0.0541695277), (6, 0.0812848096), (7, 0.1083848325)], [(4, 0.0270695048), (5, 0.0541695277), (6, 0.0812848096), (7, 0.1083848325)], [], [], [], []] - alphas: [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1] - emaB: [[(4, 0.0072785532), (5, 0.0145571067), (6, 0.0218631264), (7, 0.0291416799)], [(4, 0.0153673608), (5, 0.030762188), (6, 0.0461570153), (7, 0.0615381093)], [(4, 0.03436231), (5, 0.0687526967), (6, 0.1031555962), (7, 0.1375472036)], [(4, 0.03436231), (5, 0.0687526967), (6, 0.1031555962), (7, 0.1375472036)], [], [], [], []] - emaB norm: [[(4, 0.0796597423), (5, 0.079623309), (6, 0.0796960597), (7, 0.0796712292)], [(4, 0.1681872709), (5, 0.168260579), (6, 0.1682528006), (7, 0.1682407067)], [(4, 0.3760764932), (5, 0.3760580558), (6, 0.3760255696), (7, 0.376044032)], [(4, 0.3760764932), (5, 0.3760580558), (6, 0.3760255696), (7, 0.376044032)], [], [], [], []] - total_bonds_per_validator: [0.079667945, 0.1682429651, 0.3760445435, 0.3760445435, 0, 0, 0, 0] - D: [0.0261337839, 0.1103787823, 0.3700660428, 0.493421391, 0, 0, 0, 0] - nE: [0.0130668918, 0.0551893911, 0.1850330213, 0.2467106953, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] - E: [13066891, 55189391, 185033021, 246710695, 49998779, 100000610, 149996337, 200004272] - P: [0.0130668918, 0.0551893911, 0.1850330213, 0.2467106953, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] + Active Stake: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] + Weights: [[(0, 65535)], [(1, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + Weights (permit): [[(0, 65535)], [(1, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + Weights (permit+diag): [[], [], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + Weights (permit+diag+outdate): [[], [], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + Weights (mask+norm): [[], [], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] + Ranks (before): [0, 0, 0, 0, 0.0699982906, 0.1400008542, 0.2099948723, 0.2800059812] + Consensus: [0, 0, 0, 0, 0.0999975584, 0.2000012207, 0.2999926754, 0.400008545] + Clipped Weights: [[], [], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] + Validator Trust: [0, 0, 0.9999999995, 0.9999999995, 0, 0, 0, 0] + Ranks (after): [0, 0, 0, 0, 0.0699982906, 0.1400008542, 0.2099948723, 0.2800059812] + Trust: [0, 0, 0, 0, 1, 1, 1, 1] + Incentive (=Rank): [0, 0, 0, 0, 0.0999975582, 0.2000012207, 0.2999926754, 0.4000085455] + Bonds: [[(4, 530), (5, 530), (6, 530), (7, 530)], [(4, 2371), (5, 2371), (6, 2371), (7, 2371)], [(4, 6366), (5, 6366), (6, 6366), (7, 6366)], [(4, 8488), (5, 8488), (6, 8488), (7, 8488)], [], [], [], []] + Bonds: (mask+norm) [[(4, 0.0080872816), (5, 0.0080872816), (6, 0.0080872816), (7, 0.0080872816)], [(4, 0.036179141), (5, 0.036179141), (6, 0.036179141), (7, 0.036179141)], [(4, 0.0971389334), (5, 0.0971389334), (6, 0.0971389334), (7, 0.0971389334)], [(4, 0.1295185778), (5, 0.1295185778), (6, 0.1295185778), (7, 0.1295185778)], [], [], [], []] + weights_for_bonds: [[], [], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] + emaB: [[(4, 0.0072785532), (5, 0.0072785532), (6, 0.0072785532), (7, 0.0072785532)], [(4, 0.0325612267), (5, 0.0325612267), (6, 0.0325612267), (7, 0.0325612267)], [(4, 0.1302821825), (5, 0.1302821827), (6, 0.1302821827), (7, 0.1302821827)], [(4, 0.1737095772), (5, 0.173709577), (6, 0.173709577), (7, 0.173709577)], [], [], [], []] + emaB norm: [[(4, 0.0211689514), (5, 0.0211689514), (6, 0.0211689514), (7, 0.0211689514)], [(4, 0.094701105), (5, 0.094701105), (6, 0.094701105), (7, 0.094701105)], [(4, 0.3789128321), (5, 0.3789128328), (6, 0.3789128328), (7, 0.3789128328)], [(4, 0.505217111), (5, 0.5052171105), (6, 0.5052171105), (7, 0.5052171105)], [], [], [], []] + total_bonds_per_validator: [0.021168951, 0.0947011046, 0.3789128324, 0.50521711, 0, 0, 0, 0] + Dividends: [0.0062849855, 0.0562328366, 0.3374935838, 0.599988594, 0, 0, 0, 0] + Normalized Server Emission: [0, 0, 0, 0, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] + Server Emission: [0, 0, 0, 0, 49998779, 100000610, 149996337, 200004272] + Normalized Validator Emission: [0.0031424926, 0.0281164183, 0.1687467918, 0.2999942969, 0, 0, 0, 0] + Validator Emission: [3142492, 28116418, 168746791, 299994296, 0, 0, 0, 0] + Normalized Combined Emission: [0.0031424926, 0.0281164183, 0.1687467918, 0.2999942969, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] + Combined Emission: [3142492, 28116418, 168746791, 299994296, 49998779, 100000610, 149996337, 200004272] + Pruning Scores: [0.0031424926, 0.0281164183, 0.1687467918, 0.2999942969, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] */ let bonds = SubtensorModule::get_bonds(netuid); - assert_eq!(bonds[0][7], 1909); - assert_eq!(bonds[1][7], 4032); - assert_eq!(bonds[2][7], 9014); - assert_eq!(bonds[3][7], 9014); + assert_eq!(bonds[0][7], 476); + assert_eq!(bonds[1][7], 2133); + assert_eq!(bonds[2][7], 8538); + assert_eq!(bonds[3][7], 11384); // === Set val3->srv4: 1 assert_ok!(SubtensorModule::set_weights( @@ -1262,43 +1283,48 @@ fn test_bonds() { } else { SubtensorModule::epoch_dense(netuid, 1_000_000_000); } - /* current_block: 5 - current_block: 6, activity_cutoff: 5000, Last update: [2, 4, 5, 2, 1, 1, 1, 1] - Inactive: [false, false, false, false, false, false, false, false] + /* n: 8 + current_block: 6 + activity_cutoff: 5000 + Last update: [2, 4, 5, 2, 1, 1, 1, 1] Block at registration: [1, 1, 1, 1, 1, 1, 1, 1] - hotkeys: [(0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7)] - S: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] validator_permits: [true, true, true, true, true, true, true, true] max_allowed_validators: 8 new_validator_permits: [true, true, true, true, true, true, true, true] - S: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] - W: [[(0, 65535)], [(1, 65535)], [(7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - W (permit): [[(0, 65535)], [(1, 65535)], [(7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - W (permit+diag): [[], [], [(7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - W (permit+diag+outdate): [[], [], [(7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - C: [0, 0, 0, 0, 0, 0, 0, 0.400008545] - W: [[], [], [(7, 0.400008545)], [(7, 0.400008545)], [], [], [], []] - Tv: [0, 0, 0.400008545, 0.400008545, 0, 0, 0, 0] - R (after): [0, 0, 0, 0, 0, 0, 0, 0.2800059812] - T: [0, 0, 0, 0, 0, 0, 0, 0.6087041323] - I (=R): [0, 0, 0, 0, 0, 0, 0, 1] - B: [[(4, 476), (5, 953), (6, 1432), (7, 1909)], [(4, 1007), (5, 2015), (6, 3024), (7, 4032)], [(4, 2251), (5, 4505), (6, 6760), (7, 9014)], [(4, 2251), (5, 4505), (6, 6760), (7, 9014)], [], [], [], []] - B (outdatedmask): [[(4, 476), (5, 953), (6, 1432), (7, 1909)], [(4, 1007), (5, 2015), (6, 3024), (7, 4032)], [(4, 2251), (5, 4505), (6, 6760), (7, 9014)], [(4, 2251), (5, 4505), (6, 6760), (7, 9014)], [], [], [], []] - B: [[(4, 0.0072632944), (5, 0.0145418479), (6, 0.0218509194), (7, 0.0291294728)], [(4, 0.015365835), (5, 0.030746929), (6, 0.0461432822), (7, 0.0615243763)], [(4, 0.0343480583), (5, 0.0687418936), (6, 0.103150988), (7, 0.1375448233)], [(4, 0.0343480583), (5, 0.0687418936), (6, 0.103150988), (7, 0.1375448233)], [], [], [], []] - alphas: [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1] - emaB: [[(4, 0.0065369648), (5, 0.0130876629), (6, 0.0196658273), (7, 0.0262165254)], [(4, 0.0138292515), (5, 0.027672236), (6, 0.041528954), (7, 0.0553719385)], [(4, 0.0309132524), (5, 0.0618677041), (6, 0.092835889), (7, 0.1637911955)], [(4, 0.0309132524), (5, 0.0618677041), (6, 0.092835889), (7, 0.1637911955)], [], [], [], []] - emaB norm: [[(4, 0.0795321616), (5, 0.0795625302), (6, 0.0796617707), (7, 0.0640723184)], [(4, 0.1682539685), (5, 0.168225079), (6, 0.168224299), (7, 0.1353271813)], [(4, 0.3761069346), (5, 0.3761061952), (6, 0.3760569647), (7, 0.40030025)], [(4, 0.3761069346), (5, 0.3761061952), (6, 0.3760569647), (7, 0.40030025)], [], [], [], []] - total_bonds_per_validator: [0.0640723184, 0.1353271813, 0.40030025, 0.40030025, 0, 0, 0, 0] - D: [0.020425828, 0.0862828067, 0.3828391563, 0.5104522086, 0, 0, 0, 0] - nE: [0.0102129139, 0.0431414032, 0.1914195782, 0.2552261043, 0, 0, 0, 0.5] - E: [10212913, 43141403, 191419578, 255226104, 0, 0, 0, 500000000] - P: [0.0102129139, 0.0431414032, 0.1914195782, 0.2552261043, 0, 0, 0, 0.5] + Active Stake: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] + Weights: [[(0, 65535)], [(1, 65535)], [(7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + Weights (permit): [[(0, 65535)], [(1, 65535)], [(7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + Weights (permit+diag): [[], [], [(7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + Weights (permit+diag+outdate): [[], [], [(7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + Weights (mask+norm): [[], [], [(7, 1)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] + Ranks (before): [0, 0, 0, 0, 0.0399990233, 0.080000488, 0.11999707, 0.4600034177] + Consensus: [0, 0, 0, 0, 0, 0, 0, 0.400008545] + Clipped Weights: [[], [], [(7, 0.400008545)], [(7, 0.400008545)], [], [], [], []] + Validator Trust: [0, 0, 0.400008545, 0.400008545, 0, 0, 0, 0] + Ranks (after): [0, 0, 0, 0, 0, 0, 0, 0.2800059812] + Trust: [0, 0, 0, 0, 0, 0, 0, 0.6087041323] + Incentive (=Rank): [0, 0, 0, 0, 0, 0, 0, 1] + Bonds: [[(4, 476), (5, 476), (6, 476), (7, 476)], [(4, 2133), (5, 2133), (6, 2133), (7, 2133)], [(4, 8538), (5, 8538), (6, 8538), (7, 8538)], [(4, 11384), (5, 11384), (6, 11384), (7, 11384)], [], [], [], []] + Bonds: (mask+norm) [[(4, 0.0072632944), (5, 0.0072632944), (6, 0.0072632944), (7, 0.0072632944)], [(4, 0.0325474937), (5, 0.0325474937), (6, 0.0325474937), (7, 0.0325474937)], [(4, 0.130281529), (5, 0.130281529), (6, 0.130281529), (7, 0.130281529)], [(4, 0.1737087052), (5, 0.1737087052), (6, 0.1737087052), (7, 0.1737087052)], [], [], [], []] + weights_for_bonds: [[], [], [(7, 0.400008545)], [(7, 0.400008545)], [], [], [], []] + emaB: [[(4, 0.0065369648), (5, 0.0065369648), (6, 0.0065369648), (7, 0.0065369648)], [(4, 0.0292927441), (5, 0.0292927441), (6, 0.0292927441), (7, 0.0292927441)], [(4, 0.117253376), (5, 0.117253376), (6, 0.117253376), (7, 0.1601105188)], [(4, 0.1563378347), (5, 0.1563378347), (6, 0.1563378347), (7, 0.2134806917)], [], [], [], []] + emaB norm: [[(4, 0.0211264472), (5, 0.0211264472), (6, 0.0211264472), (7, 0.0159663672)], [(4, 0.0946695658), (5, 0.0946695658), (6, 0.0946695658), (7, 0.0715467692)], [(4, 0.3789445655), (5, 0.3789445655), (6, 0.3789445655), (7, 0.3910657985)], [(4, 0.505259421), (5, 0.505259421), (6, 0.505259421), (7, 0.5214210646)], [], [], [], []] + total_bonds_per_validator: [0.0159663672, 0.0715467692, 0.3910657985, 0.5214210646, 0, 0, 0, 0] + Dividends: [0.0046713396, 0.0418654135, 0.3432467687, 0.610216478, 0, 0, 0, 0] + Normalized Server Emission: [0, 0, 0, 0, 0, 0, 0, 0.5] + Server Emission: [0, 0, 0, 0, 0, 0, 0, 500000000] + Normalized Validator Emission: [0.0023356697, 0.0209327068, 0.1716233843, 0.305108239, 0, 0, 0, 0] + Validator Emission: [2335669, 20932706, 171623384, 305108238, 0, 0, 0, 0] + Normalized Combined Emission: [0.0023356697, 0.0209327068, 0.1716233843, 0.305108239, 0, 0, 0, 0.5] + Combined Emission: [2335669, 20932706, 171623384, 305108238, 0, 0, 0, 500000000] + Pruning Scores: [0.0023356697, 0.0209327068, 0.1716233843, 0.305108239, 0, 0, 0, 0.5] + */ let bonds = SubtensorModule::get_bonds(netuid); - assert_eq!(bonds[0][7], 1718); - assert_eq!(bonds[1][7], 3628); - assert_eq!(bonds[2][7], 10734); - assert_eq!(bonds[3][7], 10734); + assert_eq!(bonds[0][7], 428); + assert_eq!(bonds[1][7], 1919); + assert_eq!(bonds[2][7], 10492); + assert_eq!(bonds[3][7], 13990); next_block(); if sparse { @@ -1306,43 +1332,47 @@ fn test_bonds() { } else { SubtensorModule::epoch_dense(netuid, 1_000_000_000); } - /* current_block: 6 - current_block: 7, activity_cutoff: 5000, Last update: [2, 4, 5, 2, 1, 1, 1, 1] - Inactive: [false, false, false, false, false, false, false, false] - Block at registration: [1, 1, 1, 1, 1, 1, 1, 1] - hotkeys: [(0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7)] - S: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] - validator_permits: [true, true, true, true, true, true, true, true] - max_allowed_validators: 8 - new_validator_permits: [true, true, true, true, true, true, true, true] - S: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] - W: [[(0, 65535)], [(1, 65535)], [(7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - W (permit): [[(0, 65535)], [(1, 65535)], [(7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - W (permit+diag): [[], [], [(7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - W (permit+diag+outdate): [[], [], [(7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - C: [0, 0, 0, 0, 0, 0, 0, 0.400008545] - W: [[], [], [(7, 0.400008545)], [(7, 0.400008545)], [], [], [], []] - Tv: [0, 0, 0.400008545, 0.400008545, 0, 0, 0, 0] - R (after): [0, 0, 0, 0, 0, 0, 0, 0.2800059812] - T: [0, 0, 0, 0, 0, 0, 0, 0.6087041323] - I (=R): [0, 0, 0, 0, 0, 0, 0, 1] - B: [[(4, 428), (5, 857), (6, 1288), (7, 1718)], [(4, 906), (5, 1813), (6, 2721), (7, 3628)], [(4, 2025), (5, 4054), (6, 6083), (7, 10734)], [(4, 2025), (5, 4054), (6, 6083), (7, 10734)], [], [], [], []] - B (outdatedmask): [[(4, 428), (5, 857), (6, 1288), (7, 1718)], [(4, 906), (5, 1813), (6, 2721), (7, 3628)], [(4, 2025), (5, 4054), (6, 6083), (7, 10734)], [(4, 2025), (5, 4054), (6, 6083), (7, 10734)], [], [], [], []] - B: [[(4, 0.0065308614), (5, 0.0130769818), (6, 0.0196536202), (7, 0.0262149996)], [(4, 0.0138246738), (5, 0.0276646067), (6, 0.0415197986), (7, 0.0553597314)], [(4, 0.0308995193), (5, 0.0618600748), (6, 0.0928206302), (7, 0.163790341)], [(4, 0.0308995193), (5, 0.0618600748), (6, 0.0928206302), (7, 0.163790341)], [], [], [], []] - alphas: [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1] - emaB: [[(4, 0.0058777751), (5, 0.0117692836), (6, 0.017688258), (7, 0.0235934996)], [(4, 0.0124422063), (5, 0.0248981458), (6, 0.0373678186), (7, 0.0498237582)], [(4, 0.0278095673), (5, 0.0556740672), (6, 0.083538567), (7, 0.1874121614)], [(4, 0.0278095673), (5, 0.0556740672), (6, 0.083538567), (7, 0.1874121614)], [], [], [], []] - emaB norm: [[(4, 0.0794947986), (5, 0.0795138243), (6, 0.0796290569), (7, 0.052635678)], [(4, 0.168276373), (5, 0.1682130254), (6, 0.1682225657), (7, 0.111153807)], [(4, 0.376114414), (5, 0.376136575), (6, 0.3760741884), (7, 0.4181052572)], [(4, 0.376114414), (5, 0.376136575), (6, 0.3760741884), (7, 0.4181052572)], [], [], [], []] - total_bonds_per_validator: [0.052635678, 0.111153807, 0.4181052572, 0.4181052572, 0, 0, 0, 0] - D: [0.0164400174, 0.069434674, 0.391767989, 0.5223573192, 0, 0, 0, 0] - nE: [0.0082200086, 0.034717337, 0.1958839945, 0.2611786595, 0, 0, 0, 0.5] - E: [8220008, 34717336, 195883994, 261178659, 0, 0, 0, 500000000] - P: [0.0082200086, 0.034717337, 0.1958839945, 0.2611786595, 0, 0, 0, 0.5] + /* n: 8 + current_block: 7 + activity_cutoff: 5000 + Last update: [2, 4, 5, 2, 1, 1, 1, 1] + Block at registration: [1, 1, 1, 1, 1, 1, 1, 1] + validator_permits: [true, true, true, true, true, true, true, true] + max_allowed_validators: 8 + new_validator_permits: [true, true, true, true, true, true, true, true] + Active Stake: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] + Weights: [[(0, 65535)], [(1, 65535)], [(7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + Weights (permit): [[(0, 65535)], [(1, 65535)], [(7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + Weights (permit+diag): [[], [], [(7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + Weights (permit+diag+outdate): [[], [], [(7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + Weights (mask+norm): [[], [], [(7, 1)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] + Ranks (before): [0, 0, 0, 0, 0.0399990233, 0.080000488, 0.11999707, 0.4600034177] + Consensus: [0, 0, 0, 0, 0, 0, 0, 0.400008545] + Clipped Weights: [[], [], [(7, 0.400008545)], [(7, 0.400008545)], [], [], [], []] + Validator Trust: [0, 0, 0.400008545, 0.400008545, 0, 0, 0, 0] + Ranks (after): [0, 0, 0, 0, 0, 0, 0, 0.2800059812] + Trust: [0, 0, 0, 0, 0, 0, 0, 0.6087041323] + Incentive (=Rank): [0, 0, 0, 0, 0, 0, 0, 1] + Bonds: [[(4, 428), (5, 428), (6, 428), (7, 428)], [(4, 1919), (5, 1919), (6, 1919), (7, 1919)], [(4, 7684), (5, 7684), (6, 7684), (7, 10492)], [(4, 10245), (5, 10245), (6, 10245), (7, 13990)], [], [], [], []] + Bonds: (mask+norm) [[(4, 0.0065308614), (5, 0.0065308614), (6, 0.0065308614), (7, 0.0065308614)], [(4, 0.029282063), (5, 0.029282063), (6, 0.029282063), (7, 0.029282063)], [(4, 0.1172503242), (5, 0.1172503242), (6, 0.1172503242), (7, 0.1600976577)], [(4, 0.1563286793), (5, 0.1563286793), (6, 0.1563286793), (7, 0.2134737163)], [], [], [], []] + weights_for_bonds: [[], [], [(7, 0.400008545)], [(7, 0.400008545)], [], [], [], []] + emaB: [[(4, 0.0058777751), (5, 0.0058777751), (6, 0.0058777751), (7, 0.0058777751)], [(4, 0.0263538565), (5, 0.0263538565), (6, 0.0263538565), (7, 0.0263538565)], [(4, 0.1055252918), (5, 0.1055252918), (6, 0.1055252918), (7, 0.1869450347)], [(4, 0.1406958112), (5, 0.1406958112), (6, 0.1406958112), (7, 0.2492692014)], [], [], [], []] + emaB norm: [[(4, 0.0211086995), (5, 0.0211086995), (6, 0.0211086995), (7, 0.0125473945)], [(4, 0.0946439134), (5, 0.0946439134), (6, 0.0946439134), (7, 0.0562580617)], [(4, 0.3789702114), (5, 0.3789702114), (6, 0.3789702114), (7, 0.3990749998)], [(4, 0.5052771752), (5, 0.5052771752), (6, 0.5052771752), (7, 0.5321195435)], [], [], [], []] + total_bonds_per_validator: [0.0125473945, 0.0562580617, 0.3990749998, 0.5321195435, 0, 0, 0, 0] + Dividends: [0.003636117, 0.0326061223, 0.3469446378, 0.6168131223, 0, 0, 0, 0] + Normalized Server Emission: [0, 0, 0, 0, 0, 0, 0, 0.5] + Server Emission: [0, 0, 0, 0, 0, 0, 0, 500000000] + Normalized Validator Emission: [0.0018180585, 0.016303061, 0.1734723188, 0.3084065611, 0, 0, 0, 0] + Validator Emission: [1818058, 16303061, 173472318, 308406561, 0, 0, 0, 0] + Normalized Combined Emission: [0.0018180585, 0.016303061, 0.1734723188, 0.3084065611, 0, 0, 0, 0.5] + Combined Emission: [1818058, 16303061, 173472318, 308406561, 0, 0, 0, 500000000] + Pruning Scores: [0.0018180585, 0.016303061, 0.1734723188, 0.3084065611, 0, 0, 0, 0.5] */ let bonds = SubtensorModule::get_bonds(netuid); - assert_eq!(bonds[0][7], 1546); - assert_eq!(bonds[1][7], 3265); - assert_eq!(bonds[2][7], 12282); - assert_eq!(bonds[3][7], 12282); + assert_eq!(bonds[0][7], 385); + assert_eq!(bonds[1][7], 1727); + assert_eq!(bonds[2][7], 12251); + assert_eq!(bonds[3][7], 16335); next_block(); if sparse { @@ -1350,43 +1380,47 @@ fn test_bonds() { } else { SubtensorModule::epoch_dense(netuid, 1_000_000_000); } - /* current_block: 7 - current_block: 8, activity_cutoff: 5000, Last update: [2, 4, 5, 2, 1, 1, 1, 1] - Inactive: [false, false, false, false, false, false, false, false] - Block at registration: [1, 1, 1, 1, 1, 1, 1, 1] - hotkeys: [(0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7)] - S: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] - validator_permits: [true, true, true, true, true, true, true, true] - max_allowed_validators: 8 - new_validator_permits: [true, true, true, true, true, true, true, true] - S: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] - W: [[(0, 65535)], [(1, 65535)], [(7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - W (permit): [[(0, 65535)], [(1, 65535)], [(7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - W (permit+diag): [[], [], [(7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - W (permit+diag+outdate): [[], [], [(7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - C: [0, 0, 0, 0, 0, 0, 0, 0.400008545] - W: [[], [], [(7, 0.400008545)], [(7, 0.400008545)], [], [], [], []] - Tv: [0, 0, 0.400008545, 0.400008545, 0, 0, 0, 0] - R (after): [0, 0, 0, 0, 0, 0, 0, 0.2800059812] - T: [0, 0, 0, 0, 0, 0, 0, 0.6087041323] - I (=R): [0, 0, 0, 0, 0, 0, 0, 1] - B: [[(4, 385), (5, 771), (6, 1159), (7, 1546)], [(4, 815), (5, 1631), (6, 2448), (7, 3265)], [(4, 1822), (5, 3648), (6, 5474), (7, 12282)], [(4, 1822), (5, 3648), (6, 5474), (7, 12282)], [], [], [], []] - B (outdatedmask): [[(4, 385), (5, 771), (6, 1159), (7, 1546)], [(4, 815), (5, 1631), (6, 2448), (7, 3265)], [(4, 1822), (5, 3648), (6, 5474), (7, 12282)], [(4, 1822), (5, 3648), (6, 5474), (7, 12282)], [], [], [], []] - B: [[(4, 0.0058747234), (5, 0.0117647059), (6, 0.0176852064), (7, 0.0235904478)], [(4, 0.0124361028), (5, 0.0248874647), (6, 0.0373540856), (7, 0.0498207065)], [(4, 0.027801938), (5, 0.0556649119), (6, 0.0835278858), (7, 0.187411307)], [(4, 0.027801938), (5, 0.0556649119), (6, 0.0835278858), (7, 0.187411307)], [], [], [], []] - alphas: [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1] - emaB: [[(4, 0.005287251), (5, 0.0105882352), (6, 0.0159166856), (7, 0.0212314029)], [(4, 0.0111924924), (5, 0.0223987182), (6, 0.033618677), (7, 0.0448386357)], [(4, 0.025021744), (5, 0.0500984206), (6, 0.0751750972), (7, 0.2086710306)], [(4, 0.025021744), (5, 0.0500984206), (6, 0.0751750972), (7, 0.2086710306)], [], [], [], []] - emaB norm: [[(4, 0.0794797675), (5, 0.0795009276), (6, 0.0796289926), (7, 0.043919883)], [(4, 0.16824938), (5, 0.1681790059), (6, 0.1681896253), (7, 0.0927544753)], [(4, 0.3761354259), (5, 0.376160033), (6, 0.3760906907), (7, 0.4316628207)], [(4, 0.3761354259), (5, 0.376160033), (6, 0.3760906907), (7, 0.4316628207)], [], [], [], []] - total_bonds_per_validator: [0.043919883, 0.0927544753, 0.4316628207, 0.4316628207, 0, 0, 0, 0] - D: [0.0135093683, 0.0570609153, 0.398327021, 0.531102695, 0, 0, 0, 0] - nE: [0.006754684, 0.0285304575, 0.1991635105, 0.2655513475, 0, 0, 0, 0.5] - E: [6754684, 28530457, 199163510, 265551347, 0, 0, 0, 500000000] - P: [0.006754684, 0.0285304575, 0.1991635105, 0.2655513475, 0, 0, 0, 0.5] + /* n: 8 + current_block: 8 + activity_cutoff: 5000 + Last update: [2, 4, 5, 2, 1, 1, 1, 1] + Block at registration: [1, 1, 1, 1, 1, 1, 1, 1] + validator_permits: [true, true, true, true, true, true, true, true] + max_allowed_validators: 8 + new_validator_permits: [true, true, true, true, true, true, true, true] + Active Stake: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] + Weights: [[(0, 65535)], [(1, 65535)], [(7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + Weights (permit): [[(0, 65535)], [(1, 65535)], [(7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + Weights (permit+diag): [[], [], [(7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + Weights (permit+diag+outdate): [[], [], [(7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + Weights (mask+norm): [[], [], [(7, 1)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] + Ranks (before): [0, 0, 0, 0, 0.0399990233, 0.080000488, 0.11999707, 0.4600034177] + Consensus: [0, 0, 0, 0, 0, 0, 0, 0.400008545] + Clipped Weights: [[], [], [(7, 0.400008545)], [(7, 0.400008545)], [], [], [], []] + Validator Trust: [0, 0, 0.400008545, 0.400008545, 0, 0, 0, 0] + Ranks (after): [0, 0, 0, 0, 0, 0, 0, 0.2800059812] + Trust: [0, 0, 0, 0, 0, 0, 0, 0.6087041323] + Incentive (=Rank): [0, 0, 0, 0, 0, 0, 0, 1] + Bonds: [[(4, 385), (5, 385), (6, 385), (7, 385)], [(4, 1727), (5, 1727), (6, 1727), (7, 1727)], [(4, 6915), (5, 6915), (6, 6915), (7, 12251)], [(4, 9220), (5, 9220), (6, 9220), (7, 16335)], [], [], [], []] + Bonds: (mask+norm) [[(4, 0.0058747234), (5, 0.0058747234), (6, 0.0058747234), (7, 0.0058747234)], [(4, 0.0263523308), (5, 0.0263523308), (6, 0.0263523308), (7, 0.0263523308)], [(4, 0.1055161364), (5, 0.1055161364), (6, 0.1055161364), (7, 0.1869382772)], [(4, 0.1406881819), (5, 0.1406881819), (6, 0.1406881819), (7, 0.2492561226)], [], [], [], []] + weights_for_bonds: [[], [], [(7, 0.400008545)], [(7, 0.400008545)], [], [], [], []] + emaB: [[(4, 0.005287251), (5, 0.005287251), (6, 0.005287251), (7, 0.005287251)], [(4, 0.0237170977), (5, 0.0237170977), (6, 0.0237170977), (7, 0.0237170977)], [(4, 0.0949645226), (5, 0.0949645226), (6, 0.0949645226), (7, 0.2111015923)], [(4, 0.1266193634), (5, 0.1266193634), (6, 0.1266193634), (7, 0.2814733672)], [], [], [], []] + emaB norm: [[(4, 0.0210993583), (5, 0.0210993583), (6, 0.0210993583), (7, 0.010137003)], [(4, 0.094645695), (5, 0.094645695), (6, 0.094645695), (7, 0.0454716997)], [(4, 0.3789664055), (5, 0.3789664055), (6, 0.3789664055), (7, 0.404735366)], [(4, 0.5052885406), (5, 0.5052885406), (6, 0.5052885406), (7, 0.539655931)], [], [], [], []] + total_bonds_per_validator: [0.010137003, 0.0454716997, 0.404735366, 0.539655931, 0, 0, 0, 0] + Dividends: [0.0029180378, 0.0261789719, 0.3495214381, 0.621381552, 0, 0, 0, 0] + Normalized Server Emission: [0, 0, 0, 0, 0, 0, 0, 0.5] + Server Emission: [0, 0, 0, 0, 0, 0, 0, 500000000] + Normalized Validator Emission: [0.0014590188, 0.013089486, 0.174760719, 0.310690776, 0, 0, 0, 0] + Validator Emission: [1459018, 13089485, 174760719, 310690775, 0, 0, 0, 0] + Normalized Combined Emission: [0.0014590188, 0.013089486, 0.174760719, 0.310690776, 0, 0, 0, 0.5] + Combined Emission: [1459018, 13089485, 174760719, 310690775, 0, 0, 0, 500000000] + Pruning Scores: [0.0014590188, 0.013089486, 0.174760719, 0.310690776, 0, 0, 0, 0.5] */ let bonds = SubtensorModule::get_bonds(netuid); - assert_eq!(bonds[0][7], 1391); - assert_eq!(bonds[1][7], 2938); - assert_eq!(bonds[2][7], 13675); - assert_eq!(bonds[3][7], 13675); + assert_eq!(bonds[0][7], 346); + assert_eq!(bonds[1][7], 1554); + assert_eq!(bonds[2][7], 13834); + assert_eq!(bonds[3][7], 18446); next_block(); if sparse { @@ -1394,38 +1428,6 @@ fn test_bonds() { } else { SubtensorModule::epoch_dense(netuid, 1_000_000_000); } - /* current_block: 8 - current_block: 9, activity_cutoff: 5000, Last update: [2, 4, 5, 2, 1, 1, 1, 1] - Inactive: [false, false, false, false, false, false, false, false] - Block at registration: [1, 1, 1, 1, 1, 1, 1, 1] - hotkeys: [(0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7)] - S: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] - validator_permits: [true, true, true, true, true, true, true, true] - max_allowed_validators: 8 - new_validator_permits: [true, true, true, true, true, true, true, true] - S: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] - W: [[(0, 65535)], [(1, 65535)], [(7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - W (permit): [[(0, 65535)], [(1, 65535)], [(7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - W (permit+diag): [[], [], [(7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - W (permit+diag+outdate): [[], [], [(7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - C: [0, 0, 0, 0, 0, 0, 0, 0.400008545] - W: [[], [], [(7, 0.400008545)], [(7, 0.400008545)], [], [], [], []] - Tv: [0, 0, 0.400008545, 0.400008545, 0, 0, 0, 0] - R (after): [0, 0, 0, 0, 0, 0, 0, 0.2800059812] - T: [0, 0, 0, 0, 0, 0, 0, 0.6087041323] - I (=R): [0, 0, 0, 0, 0, 0, 0, 1] - B: [[(4, 346), (5, 693), (6, 1043), (7, 1391)], [(4, 733), (5, 1467), (6, 2203), (7, 2938)], [(4, 1639), (5, 3283), (6, 4926), (7, 13675)], [(4, 1639), (5, 3283), (6, 4926), (7, 13675)], [], [], [], []] - B (outdatedmask): [[(4, 346), (5, 693), (6, 1043), (7, 1391)], [(4, 733), (5, 1467), (6, 2203), (7, 2938)], [(4, 1639), (5, 3283), (6, 4926), (7, 13675)], [(4, 1639), (5, 3283), (6, 4926), (7, 13675)], [], [], [], []] - B: [[(4, 0.0052796216), (5, 0.0105745022), (6, 0.0159151598), (7, 0.0212252995)], [(4, 0.011184863), (5, 0.0223849851), (6, 0.0336156252), (7, 0.0448310063)], [(4, 0.0250095369), (5, 0.0500953689), (6, 0.0751659418), (7, 0.2086671244)], [(4, 0.0250095369), (5, 0.0500953689), (6, 0.0751659418), (7, 0.2086671244)], [], [], [], []] - alphas: [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1] - emaB: [[(4, 0.0047516592), (5, 0.0095170517), (6, 0.0143236436), (7, 0.0191027694)], [(4, 0.0100663765), (5, 0.0201464866), (6, 0.0302540625), (7, 0.0403479056)], [(4, 0.022508583), (5, 0.0450858318), (6, 0.0676493475), (7, 0.2278012664)], [(4, 0.022508583), (5, 0.0450858318), (6, 0.0676493475), (7, 0.2278012664)], [], [], [], []] - emaB norm: [[(4, 0.0794124375), (5, 0.0794178303), (6, 0.079630477), (7, 0.037088924)], [(4, 0.1682350226), (5, 0.1681182678), (6, 0.168193617), (7, 0.0783373541)], [(4, 0.3761762697), (5, 0.3762319507), (6, 0.3760879529), (7, 0.4422868607)], [(4, 0.3761762697), (5, 0.3762319507), (6, 0.3760879529), (7, 0.4422868607)], [], [], [], []] - total_bonds_per_validator: [0.037088924, 0.0783373541, 0.4422868607, 0.4422868607, 0, 0, 0, 0] - D: [0.011274011, 0.0476247966, 0.403329082, 0.5377721095, 0, 0, 0, 0] - nE: [0.0056370054, 0.0238123983, 0.201664541, 0.2688860546, 0, 0, 0, 0.5] - E: [5637005, 23812398, 201664540, 268886054, 0, 0, 0, 500000000] - P: [0.0056370054, 0.0238123983, 0.201664541, 0.2688860546, 0, 0, 0, 0.5] - */ }); } @@ -1505,49 +1507,46 @@ fn test_bonds_with_liquid_alpha() { /* n: 8 current_block: 3 activity_cutoff: 5000 - Inactive: [false, false, false, false, false, false, false, false] + Last update: [2, 2, 2, 2, 1, 1, 1, 1] Block at registration: [1, 1, 1, 1, 1, 1, 1, 1] - hotkeys: [(0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7)] - S: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] validator_permits: [true, true, true, true, true, true, true, true] - max_allowed_validators: 8 + max_allowed_validators: 64 new_validator_permits: [true, true, true, true, true, true, true, true] - S: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] - W: [[(0, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - W (permit): [[(0, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - W (permit+diag): [[], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - W (permit+diag+outdate): [[], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - C: [0, 0, 0, 0, 0.0999975584, 0.2000012207, 0.2999926754, 0.400008545] - W: [[], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] - Tv: [0, 0.9999999995, 0.9999999995, 0.9999999995, 0, 0, 0, 0] - R (after): [0, 0, 0, 0, 0.0899978022, 0.1800010982, 0.2699934072, 0.36000769] - T: [0, 0, 0, 0, 1, 1, 1, 1] - I (=R): [0, 0, 0, 0, 0.0999975582, 0.2000012207, 0.2999926754, 0.4000085455] - B: [[(4, 655), (5, 1310), (6, 1966), (7, 2621)], [(4, 655), (5, 1310), (6, 1966), (7, 2621)], [(4, 655), (5, 1310), (6, 1966), (7, 2621)], [(4, 655), (5, 1310), (6, 1966), (7, 2621)], [], [], [], []] - B (outdatedmask): [[(4, 655), (5, 1310), (6, 1966), (7, 2621)], [(4, 655), (5, 1310), (6, 1966), (7, 2621)], [(4, 655), (5, 1310), (6, 1966), (7, 2621)], [(4, 655), (5, 1310), (6, 1966), (7, 2621)], [], [], [], []] - B: [[(4, 0.0099946593), (5, 0.0199893187), (6, 0.029999237), (7, 0.0399938964)], [(4, 0.0099946593), (5, 0.0199893187), (6, 0.029999237), (7, 0.0399938964)], [(4, 0.0099946593), (5, 0.0199893187), (6, 0.029999237), (7, 0.0399938964)], [(4, 0.0099946593), (5, 0.0199893187), (6, 0.029999237), (7, 0.0399938964)], [], [], [], []] - alphas: [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1] - emaB: [[(4, 0.0089951933), (5, 0.0179903866), (6, 0.0269993132), (7, 0.0359945067)], [(4, 0.018994949), (5, 0.0379905086), (6, 0.0569985807), (7, 0.0759953612)], [(4, 0.018994949), (5, 0.0379905086), (6, 0.0569985807), (7, 0.0759953612)], [(4, 0.018994949), (5, 0.0379905086), (6, 0.0569985807), (7, 0.0759953612)], [], [], [], []] - emaB norm: [[(4, 0.1363320365), (5, 0.1363301442), (6, 0.136363573), (7, 0.1363528532)], [(4, 0.287889321), (5, 0.2878899518), (6, 0.2878788088), (7, 0.287882382)], [(4, 0.287889321), (5, 0.2878899518), (6, 0.2878788088), (7, 0.287882382)], [(4, 0.287889321), (5, 0.2878899518), (6, 0.2878788088), (7, 0.287882382)], [], [], [], []] - total_bonds_per_validator: [0.136349445, 0.2878835173, 0.2878835173, 0.2878835173, 0, 0, 0, 0] - D: [0.0499942757, 0.211112383, 0.3166685747, 0.422224766, 0, 0, 0, 0] - nE: [0.0249971377, 0.1055561914, 0.1583342873, 0.211112383, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] - E: [24997137, 105556191, 158334287, 211112383, 49998779, 100000610, 149996337, 200004272] - P: [0.0249971377, 0.1055561914, 0.1583342873, 0.211112383, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] - */ + Active Stake: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] + Weights: [[(0, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + Weights (permit): [[(0, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + Weights (permit+diag): [[], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + Weights (permit+diag+outdate): [[], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + Weights (mask+norm): [[], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] + Ranks (before): [0, 0, 0, 0, 0.0899978022, 0.1800010982, 0.2699934072, 0.36000769] + Consensus: [0, 0, 0, 0, 0.0999975584, 0.2000012207, 0.2999926754, 0.400008545] + Clipped Weights: [[], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] + Validator Trust: [0, 0.9999999995, 0.9999999995, 0.9999999995, 0, 0, 0, 0] + Ranks (after): [0, 0, 0, 0, 0.0899978022, 0.1800010982, 0.2699934072, 0.36000769] + Trust: [0, 0, 0, 0, 1, 1, 1, 1] + Incentive (=Rank): [0, 0, 0, 0, 0.0999975582, 0.2000012207, 0.2999926754, 0.4000085455] + Bonds: [[(4, 4596), (5, 9192), (6, 13788), (7, 18385)], [(4, 4596), (5, 9192), (6, 13788), (7, 18385)], [(4, 4596), (5, 9192), (6, 13788), (7, 18385)], [(4, 4596), (5, 9192), (6, 13788), (7, 18385)], [], [], [], []] + Bonds: (mask+norm) [[(4, 0.0701304646), (5, 0.1402609292), (6, 0.2103913939), (7, 0.2805371175)], [(4, 0.0701304646), (5, 0.1402609292), (6, 0.2103913939), (7, 0.2805371175)], [(4, 0.0701304646), (5, 0.1402609292), (6, 0.2103913939), (7, 0.2805371175)], [(4, 0.0701304646), (5, 0.1402609292), (6, 0.2103913939), (7, 0.2805371175)], [], [], [], []] + weights_for_bonds: [[], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] + alphas: [[0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7026884612, 0.7053405554, 0.7104771058, 0.7200544013], [0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993], [0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993], [0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993], [0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993], [0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993], [0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993], [0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993]] + emaB: [[], [(4, 0.0910776372), (5, 0.1821595554), (6, 0.273232912), (7, 0.364327949)], [(4, 0.0910776372), (5, 0.1821595554), (6, 0.273232912), (7, 0.364327949)], [(4, 0.0910776372), (5, 0.1821595554), (6, 0.273232912), (7, 0.364327949)], [], [], [], []] + emaB norm: [[], [(4, 0.3333333333), (5, 0.3333333333), (6, 0.3333333333), (7, 0.3333333333)], [(4, 0.3333333333), (5, 0.3333333333), (6, 0.3333333333), (7, 0.3333333333)], [(4, 0.3333333333), (5, 0.3333333333), (6, 0.3333333333), (7, 0.3333333333)], [], [], [], []] + total_bonds_per_validator: [0, 0.3333333328, 0.3333333328, 0.3333333328, 0, 0, 0, 0] + Dividends: [0, 0.222222222, 0.333333333, 0.4444444447, 0, 0, 0, 0] + Normalized Server Emission: [0, 0, 0, 0, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] + Server Emission: [0, 0, 0, 0, 49998779, 100000610, 149996337, 200004272] + Normalized Validator Emission: [0, 0.111111111, 0.1666666665, 0.2222222222, 0, 0, 0, 0] + Validator Emission: [0, 111111111, 166666666, 222222222, 0, 0, 0, 0] + Normalized Combined Emission: [0, 0.111111111, 0.1666666665, 0.2222222222, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] + Combined Emission: [0, 111111111, 166666666, 222222222, 49998779, 100000610, 149996337, 200004272] + Pruning Scores: [0, 0.111111111, 0.1666666665, 0.2222222222, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] - // Expected bonds calculations - // For uid 0: - // Initial weights: [0.25, 0.5, 0.75, 1.0] - // Active stake: [1, 2, 3, 4] - // ΔB = W◦S = [0.25*1, 0.5*2, 0.75*3, 1.0*4] = [0.25, 1.0, 2.25, 4.0] - // Normalize ΔB: [0.25/7.5, 1.0/7.5, 2.25/7.5, 4.0/7.5] = [0.0333, 0.1333, 0.3, 0.5333] - // Final bonds for netuid: [16383, 32767, 49151, 65535] + */ - assert_eq!(bonds[0][4], 1247); // Note: Calculated as explained above - assert_eq!(bonds[1][4], 1247); // Note: Calculated as explained above - assert_eq!(bonds[2][4], 1247); // Note: Calculated as explained above - assert_eq!(bonds[3][4], 1247); // Note: Calculated as explained above + assert_eq!(bonds[0][4], 4596); // Note: Calculated as explained above + assert_eq!(bonds[1][4], 4596); // Note: Calculated as explained above + assert_eq!(bonds[2][4], 4596); // Note: Calculated as explained above + assert_eq!(bonds[3][4], 4596); // Note: Calculated as explained above // === Set self-weight only on val1 let uid = 0; @@ -1566,10 +1565,10 @@ fn test_bonds_with_liquid_alpha() { } let bonds = SubtensorModule::get_bonds(netuid); - assert_eq!(bonds[0][4], 1009); - assert_eq!(bonds[1][4], 2257); - assert_eq!(bonds[2][4], 2257); - assert_eq!(bonds[3][4], 2257); + assert_eq!(bonds[0][4], 0); + assert_eq!(bonds[1][4], 5968); + assert_eq!(bonds[2][4], 5968); + assert_eq!(bonds[3][4], 5968); // === Set self-weight only on val2 let uid = 1; @@ -1592,41 +1591,44 @@ fn test_bonds_with_liquid_alpha() { current_block: 4 activity_cutoff: 5000 Last update: [2, 3, 2, 2, 1, 1, 1, 1] - Inactive: [false, false, false, false, false, false, false, false] Block at registration: [1, 1, 1, 1, 1, 1, 1, 1] - hotkeys: [(0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7)] - S: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] validator_permits: [true, true, true, true, true, true, true, true] - max_allowed_validators: 8 + max_allowed_validators: 64 new_validator_permits: [true, true, true, true, true, true, true, true] - S: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] - W: [[(0, 65535)], [(1, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - W (permit): [[(0, 65535)], [(1, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - W (permit+diag): [[], [], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - W (permit+diag+outdate): [[], [], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - C: [0, 0, 0, 0, 0.0999975584, 0.2000012207, 0.2999926754, 0.400008545] - W: [[], [], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] - Tv: [0, 0, 0.9999999995, 0.9999999995, 0, 0, 0, 0] - R (after): [0, 0, 0, 0, 0.0699982906, 0.1400008542, 0.2099948723, 0.2800059812] - T: [0, 0, 0, 0, 1, 1, 1, 1] - I (=R): [0, 0, 0, 0, 0.0999975582, 0.2000012207, 0.2999926754, 0.4000085455] - B: [[(4, 589), (5, 1178), (6, 1769), (7, 2358)], [(4, 1244), (5, 2489), (6, 3735), (7, 4980)], [(4, 1244), (5, 2489), (6, 3735), (7, 4980)], [(4, 1244), (5, 2489), (6, 3735), (7, 4980)], [], [], [], []] - B (outdatedmask): [[(4, 589), (5, 1178), (6, 1769), (7, 2358)], [(4, 1244), (5, 2489), (6, 3735), (7, 4980)], [(4, 1244), (5, 2489), (6, 3735), (7, 4980)], [(4, 1244), (5, 2489), (6, 3735), (7, 4980)], [], [], [], []] - B: [[(4, 0.008987564), (5, 0.0179751278), (6, 0.0269932097), (7, 0.0359807736)], [(4, 0.0189822232), (5, 0.0379797055), (6, 0.0569924468), (7, 0.075989929)], [(4, 0.0189822232), (5, 0.0379797055), (6, 0.0569924468), (7, 0.075989929)], [(4, 0.0189822232), (5, 0.0379797055), (6, 0.0569924468), (7, 0.075989929)], [], [], [], []] - alphas: [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1] - emaB: [[(4, 0.0080888073), (5, 0.016177615), (6, 0.0242938886), (7, 0.0323826962)], [(4, 0.0170840009), (5, 0.0341817348), (6, 0.051293202), (7, 0.068390936)], [(4, 0.0270837566), (5, 0.0541818568), (6, 0.0812924695), (7, 0.1083917904)], [(4, 0.0270837566), (5, 0.0541818568), (6, 0.0812924695), (7, 0.1083917904)], [], [], [], []] - emaB norm: [[(4, 0.1019507758), (5, 0.10192353), (6, 0.102001434), (7, 0.101974368)], [(4, 0.2153255814), (5, 0.2153545555), (6, 0.2153619886), (7, 0.215365714)], [(4, 0.3413618212), (5, 0.341360957), (6, 0.3413182884), (7, 0.3413299588)], [(4, 0.3413618212), (5, 0.341360957), (6, 0.3413182884), (7, 0.3413299588)], [], [], [], []] - total_bonds_per_validator: [0.1019699604, 0.215358351, 0.3413358429, 0.3413358429, 0, 0, 0, 0] - D: [0.034896868, 0.1474028623, 0.3504429725, 0.4672572967, 0, 0, 0, 0] - nE: [0.017448434, 0.073701431, 0.1752214862, 0.2336286483, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] - E: [17448433, 73701431, 175221486, 233628648, 49998779, 100000610, 149996337, 200004272] - P: [0.017448434, 0.073701431, 0.1752214862, 0.2336286483, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] + Active Stake: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] + Weights: [[(0, 65535)], [(1, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + Weights (permit): [[(0, 65535)], [(1, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + Weights (permit+diag): [[], [], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + Weights (permit+diag+outdate): [[], [], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + Weights (mask+norm): [[], [], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] + Ranks (before): [0, 0, 0, 0, 0.0699982906, 0.1400008542, 0.2099948723, 0.2800059812] + Consensus: [0, 0, 0, 0, 0.0999975584, 0.2000012207, 0.2999926754, 0.400008545] + Clipped Weights: [[], [], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] + Validator Trust: [0, 0, 0.9999999995, 0.9999999995, 0, 0, 0, 0] + Ranks (after): [0, 0, 0, 0, 0.0699982906, 0.1400008542, 0.2099948723, 0.2800059812] + Trust: [0, 0, 0, 0, 1, 1, 1, 1] + Incentive (=Rank): [0, 0, 0, 0, 0.0999975582, 0.2000012207, 0.2999926754, 0.4000085455] + Bonds: [[], [(4, 5968), (5, 11937), (6, 17906), (7, 23876)], [(4, 5968), (5, 11937), (6, 17906), (7, 23876)], [(4, 5968), (5, 11937), (6, 17906), (7, 23876)], [], [], [], []] + Bonds: (mask+norm) [[], [(4, 0.0910658427), (5, 0.1821469443), (6, 0.273228046), (7, 0.3643244067)], [(4, 0.0910658427), (5, 0.1821469443), (6, 0.273228046), (7, 0.3643244067)], [(4, 0.0910658427), (5, 0.1821469443), (6, 0.273228046), (7, 0.3643244067)], [], [], [], []] + weights_for_bonds: [[], [], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] + alphas: [[0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993], [0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7033024912, 0.7080039687, 0.718774016, 0.74096124], [0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993], [0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993], [0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993], [0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993], [0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993], [0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993]] + emaB: [[], [], [(4, 0.0973300673), (5, 0.1946689729), (6, 0.291999317), (7, 0.3893513412)], [(4, 0.0973300673), (5, 0.1946689729), (6, 0.291999317), (7, 0.3893513412)], [], [], [], []] + emaB norm: [[], [], [(4, 0.5), (5, 0.5), (6, 0.5), (7, 0.5)], [(4, 0.5), (5, 0.5), (6, 0.5), (7, 0.5)], [], [], [], []] + total_bonds_per_validator: [0, 0, 0.4999999998, 0.4999999998, 0, 0, 0, 0] + Dividends: [0, 0, 0.4285714282, 0.5714285716, 0, 0, 0, 0] + Normalized Server Emission: [0, 0, 0, 0, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] + Server Emission: [0, 0, 0, 0, 49998779, 100000610, 149996337, 200004272] + Normalized Validator Emission: [0, 0, 0.214285714, 0.2857142857, 0, 0, 0, 0] + Validator Emission: [0, 0, 214285714, 285714285, 0, 0, 0, 0] + Normalized Combined Emission: [0, 0, 0.214285714, 0.2857142857, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] + Combined Emission: [0, 0, 214285714, 285714285, 49998779, 100000610, 149996337, 200004272] + Pruning Scores: [0, 0, 0.214285714, 0.2857142857, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726]/ */ - assert_eq!(bonds[0][4], 816); - assert_eq!(bonds[1][4], 1827); - assert_eq!(bonds[2][4], 3075); - assert_eq!(bonds[3][4], 3075); + assert_eq!(bonds[0][4], 0); + assert_eq!(bonds[1][4], 0); + assert_eq!(bonds[2][4], 6378); + assert_eq!(bonds[3][4], 6378); }); } @@ -1777,51 +1779,53 @@ fn test_active_stake() { } else { SubtensorModule::epoch_dense(netuid, 1_000_000_000); } - /* current_block: 5002; activity_cutoff: 5000 - Last update: [5002, 1, 0, 0]; Inactive: [false, true, true, true]; Block at registration: [0, 0, 0, 0] - Normalised Stake: [0.25, 0.25, 0.25, 0.25] - validator_permits: [true, true, true, true] - Active Stake: [1, 0, 0, 0] - Weights: [[(2, 65535), (3, 65535)], [(2, 65535), (3, 65535)], [], []] - Weights (permit): [[(2, 65535), (3, 65535)], [(2, 65535), (3, 65535)], [], []] - Weights (permit+diag): [[(2, 65535), (3, 65535)], [(2, 65535), (3, 65535)], [], []] - Weights (permit+diag+outdate): [[(2, 65535), (3, 65535)], [(2, 65535), (3, 65535)], [], []] - Weights (mask+norm): [[(2, 0.5), (3, 0.5)], [(2, 0.5), (3, 0.5)], [], []] - Ranks (before): [0, 0, 0.5, 0.5] - Consensus: [0, 0, 0.5, 0.5] - Clipped Weights: [[(2, 0.5), (3, 0.5)], [(2, 0.5), (3, 0.5)], [], []] - Validator Trust: [1, 1, 0, 0] - Ranks (after): [0, 0, 0.5, 0.5] - Trust: [0, 0, 1, 1] - Incentive (=Rank): [0, 0, 0.5, 0.5] - Bonds: [[(2, 3276), (3, 3276)], [(2, 3276), (3, 3276)], [], []] - Bonds (outdatedmask): [[(2, 3276), (3, 3276)], [(2, 3276), (3, 3276)], [], []] - Bonds: (mask+norm) [[(2, 0.0499885557), (3, 0.0499885557)], [(2, 0.0499885557), (3, 0.0499885557)], [], []] - Alphas: [0.1, 0.1, 0.1, 0.1] - weights_for_bonds: [[(2, 0.5), (3, 0.5)], [(2, 0.5), (3, 0.5)], [], []] - emaB: [[(2, 0.0949897), (3, 0.0949897)], [(2, 0.0949897), (3, 0.0949897)], [], []] - total_bonds_per_validator: [0.5, 0.5, 0, 0] - Dividends: [1, 0, 0, 0] - Normalized Server Emission: [0, 0, 0.25, 0.25] - Server Emission: [0, 0, 250000000, 250000000] - Normalized Validator Emission: [0.5, 0, 0, 0] - Validator Emission: [500000000, 0, 0, 0] - Normalized Combined Emission: [0.5, 0, 0.25, 0.25] - Combined Emission: [500000000, 0, 250000000, 250000000] - Pruning Scores: [0.5, 0, 0.25, 0.25] + /* + current_block: 5002 + activity_cutoff: 5000 + Last update: [5002, 1, 0, 0] + Block at registration: [0, 0, 0, 0] + validator_permits: [true, true, true, true] + max_allowed_validators: 4 + new_validator_permits: [true, true, true, true] + Active Stake: [1, 0, 0, 0] + Weights: [[(2, 65535), (3, 65535)], [(2, 65535), (3, 65535)], [], []] + Weights (permit): [[(2, 65535), (3, 65535)], [(2, 65535), (3, 65535)], [], []] + Weights (permit+diag): [[(2, 65535), (3, 65535)], [(2, 65535), (3, 65535)], [], []] + Weights (permit+diag+outdate): [[(2, 65535), (3, 65535)], [(2, 65535), (3, 65535)], [], []] + Weights (mask+norm): [[(2, 0.5), (3, 0.5)], [(2, 0.5), (3, 0.5)], [], []] + Ranks (before): [0, 0, 0.5, 0.5] + Consensus: [0, 0, 0.5, 0.5] + Clipped Weights: [[(2, 0.5), (3, 0.5)], [(2, 0.5), (3, 0.5)], [], []] + Validator Trust: [1, 1, 0, 0] + Ranks (after): [0, 0, 0.5, 0.5] + Trust: [0, 0, 1, 1] + Incentive (=Rank): [0, 0, 0.5, 0.5] + Bonds: [[(2, 3276), (3, 3276)], [(2, 3276), (3, 3276)], [], []] + Bonds: (mask+norm) [[(2, 0.0499885557), (3, 0.0499885557)], [(2, 0.0499885557), (3, 0.0499885557)], [], []] + weights_for_bonds: [[(2, 0.5), (3, 0.5)], [(2, 0.5), (3, 0.5)], [], []] + emaB: [[(2, 0.1449897), (3, 0.1449897)], [(2, 0.0449897), (3, 0.0449897)], [], []] + emaB norm: [[(2, 0.7631864299), (3, 0.7631864299)], [(2, 0.23681357), (3, 0.23681357)], [], []] + total_bonds_per_validator: [0.7631864296, 0.23681357, 0, 0] + Dividends: [1, 0, 0, 0] + Normalized Server Emission: [0, 0, 0.25, 0.25] + Server Emission: [0, 0, 250000000, 250000000] + Normalized Validator Emission: [0.5, 0, 0, 0] + Validator Emission: [500000000, 0, 0, 0] + Normalized Combined Emission: [0.5, 0, 0.25, 0.25] + Combined Emission: [500000000, 0, 250000000, 250000000] + Pruning Scores: [0.5, 0, 0.25, 0.25] */ let bonds = SubtensorModule::get_bonds(netuid); assert_eq!(SubtensorModule::get_dividends_for_uid(netuid, 0), 65535); assert_eq!(SubtensorModule::get_emission_for_uid(netuid, 0), 500000000); for server in ((n / 2) as usize)..n as usize { - assert_eq!(bonds[0][server], I32F32::from_num(6225)); + assert_eq!(bonds[0][server], I32F32::from_num(9501)); } for validator in 1..(n / 2) { assert_eq!(SubtensorModule::get_dividends_for_uid(netuid, validator), 0); assert_eq!(SubtensorModule::get_emission_for_uid(netuid, validator), 0); for server in ((n / 2) as usize)..n as usize { - assert_eq!(bonds[validator as usize][server], I32F32::from_num(6225)); - // floor(0.45*(2^16-1))/(2^16-1), then max-upscale + assert_eq!(bonds[validator as usize][server], I32F32::from_num(2948)); } } @@ -1839,52 +1843,52 @@ fn test_active_stake() { } else { SubtensorModule::epoch_dense(netuid, 1_000_000_000); } - /* current_block: 5003; activity_cutoff: 5000 - Last update: [5002, 5002, 0, 0]; Inactive: [false, false, true, true]; Block at registration: [0, 0, 0, 0] - Inactive: [false, false, true, true] - Block at registration: [0, 0, 0, 0] - hotkeys: [(0, 0), (1, 1), (2, 2), (3, 3)] - Normalised Stake: [0.25, 0.25, 0.25, 0.25] - validator_permits: [true, true, true, true] - Active Stake: [0.5, 0.5, 0, 0] - Weights: [[(2, 65535), (3, 65535)], [(2, 65535), (3, 65535)], [], []] - Weights (permit): [[(2, 65535), (3, 65535)], [(2, 65535), (3, 65535)], [], []] - Weights (permit+diag): [[(2, 65535), (3, 65535)], [(2, 65535), (3, 65535)], [], []] - Weights (permit+diag+outdate): [[(2, 65535), (3, 65535)], [(2, 65535), (3, 65535)], [], []] - Weights (mask+norm): [[(2, 0.5), (3, 0.5)], [(2, 0.5), (3, 0.5)], [], []] - Ranks (before): [0, 0, 0.5, 0.5] - Consensus: [0, 0, 0.5, 0.5] - Clipped Weights: [[(2, 0.5), (3, 0.5)], [(2, 0.5), (3, 0.5)], [], []] - Validator Trust: [1, 1, 0, 0] - Ranks (after): [0, 0, 0.5, 0.5] - Trust: [0, 0, 1, 1] - Incentive (=Rank): [0, 0, 0.5, 0.5] - Bonds: [[(2, 6225), (3, 6225)], [(2, 6225), (3, 6225)], [], []] - Bonds (outdatedmask): [[(2, 6225), (3, 6225)], [(2, 6225), (3, 6225)], [], []] - Bonds: (mask+norm) [[(2, 0.0949874113), (3, 0.0949874113)], [(2, 0.0949874113), (3, 0.0949874113)], [], []] - Alphas: [0.1, 0.1, 0.1, 0.1] - weights_for_bonds: [[(2, 0.5), (3, 0.5)], [(2, 0.5), (3, 0.5)], [], []] - emaB: [[(2, 0.13548867), (3, 0.13548867)], [(2, 0.13548867), (3, 0.13548867)], [], []] - total_bonds_per_validator: [0.5, 0.5, 0, 0] - Dividends: [0.5, 0.5, 0, 0] - Normalized Server Emission: [0, 0, 0.25, 0.25] - Server Emission: [0, 0, 250000000, 250000000] - Normalized Validator Emission: [0.25, 0.25, 0, 0] - Validator Emission: [250000000, 250000000, 0, 0] - Normalized Combined Emission: [0.25, 0.25, 0.25, 0.25] - Combined Emission: [250000000, 250000000, 250000000, 250000000] - Pruning Scores: [0.25, 0.25, 0.25, 0.25] + /* + current_block: 5003 + activity_cutoff: 5000 + Last update: [5002, 5002, 0, 0] + Block at registration: [0, 0, 0, 0] + validator_permits: [true, true, true, true] + max_allowed_validators: 4 + new_validator_permits: [true, true, true, true] + Active Stake: [0.5, 0.5, 0, 0] + Weights: [[(2, 65535), (3, 65535)], [(2, 65535), (3, 65535)], [], []] + Weights (permit): [[(2, 65535), (3, 65535)], [(2, 65535), (3, 65535)], [], []] + Weights (permit+diag): [[(2, 65535), (3, 65535)], [(2, 65535), (3, 65535)], [], []] + Weights (permit+diag+outdate): [[(2, 65535), (3, 65535)], [(2, 65535), (3, 65535)], [], []] + Weights (mask+norm): [[(2, 0.5), (3, 0.5)], [(2, 0.5), (3, 0.5)], [], []] + Ranks (before): [0, 0, 0.5, 0.5] + Consensus: [0, 0, 0.5, 0.5] + Clipped Weights: [[(2, 0.5), (3, 0.5)], [(2, 0.5), (3, 0.5)], [], []] + Validator Trust: [1, 1, 0, 0] + Ranks (after): [0, 0, 0.5, 0.5] + Trust: [0, 0, 1, 1] + Incentive (=Rank): [0, 0, 0.5, 0.5] + Bonds: [[(2, 9501), (3, 9501)], [(2, 2948), (3, 2948)], [], []] + Bonds: (mask+norm) [[(2, 0.144975967), (3, 0.144975967)], [(2, 0.0449835965), (3, 0.0449835965)], [], []] + weights_for_bonds: [[(2, 0.5), (3, 0.5)], [(2, 0.5), (3, 0.5)], [], []] + emaB: [[(2, 0.1804783703), (3, 0.1804783703)], [(2, 0.0904852368), (3, 0.0904852368)], [], []] + emaB norm: [[(2, 0.666061292), (3, 0.666061292)], [(2, 0.3339387078), (3, 0.3339387078)], [], []] + total_bonds_per_validator: [0.666061292, 0.3339387076, 0, 0] + Dividends: [0.6660612922, 0.3339387076, 0, 0] + Normalized Server Emission: [0, 0, 0.25, 0.25] + Server Emission: [0, 0, 250000000, 250000000] + Normalized Validator Emission: [0.333030646, 0.1669693538, 0, 0] + Validator Emission: [333030645, 166969353, 0, 0] + Normalized Combined Emission: [0.333030646, 0.1669693538, 0.25, 0.25] + Combined Emission: [333030645, 166969353, 250000000, 250000000] + Pruning Scores: [0.333030646, 0.1669693538, 0.25, 0.25] */ let bonds = SubtensorModule::get_bonds(netuid); - assert_eq!(SubtensorModule::get_dividends_for_uid(netuid, 0), 32767); - assert_eq!(SubtensorModule::get_emission_for_uid(netuid, 0), 250000000); + assert_eq!(SubtensorModule::get_dividends_for_uid(netuid, 0), 43650); + assert_eq!(SubtensorModule::get_emission_for_uid(netuid, 0), 333030645); for server in ((n / 2) as usize)..n as usize { - assert_eq!(bonds[0][server], I32F32::from_num(8879)); + assert_eq!(bonds[0][server], I32F32::from_num(11827)); } - assert_eq!(SubtensorModule::get_dividends_for_uid(netuid, 1), 32767); - assert_eq!(SubtensorModule::get_emission_for_uid(netuid, 1), 250000000); + assert_eq!(SubtensorModule::get_dividends_for_uid(netuid, 1), 21884); + assert_eq!(SubtensorModule::get_emission_for_uid(netuid, 1), 166969353); for server in ((n / 2) as usize)..n as usize { - assert_eq!(bonds[1][server], I32F32::from_num(8879)); + assert_eq!(bonds[1][server], I32F32::from_num(5929)); } }); } @@ -1969,33 +1973,43 @@ fn test_outdated_weights() { } else { SubtensorModule::epoch_dense(netuid, 1_000_000_000); } - /* current_block: 1; activity_cutoff: 5000 - Last update: [1, 1, 1, 1]; Inactive: [false, false, false, false]; Block at registration: [0, 0, 0, 0] - S: [0.25, 0.25, 0.25, 0.25]; S (mask): [0.25, 0.25, 0.25, 0.25]; S (mask+norm): [0.25, 0.25, 0.25, 0.25] - validator_permits: [true, true, true, true]; max_allowed_validators: 4; new_validator_permits: [true, true, true, true] - W: [[(2, 65535), (3, 32768)], [(2, 65535), (3, 32768)], [(2, 65535)], [(3, 65535)]] - W (permit): [[(2, 65535), (3, 32768)], [(2, 65535), (3, 32768)], [(2, 65535)], [(3, 65535)]] - W (permit+diag): [[(2, 65535), (3, 32768)], [(2, 65535), (3, 32768)], [], []] - W (permit+diag+outdate): [[(2, 65535), (3, 32768)], [(2, 65535), (3, 32768)], [], []] - W (mask+norm): [[(2, 0.6666632756), (3, 0.3333367242)], [(2, 0.6666632756), (3, 0.3333367242)], [], []] - R (before): [0, 0, 0.3333316376, 0.166668362] - C: [0, 0, 0.6666632756, 0.3333367242] - W: [[(2, 0.6666632756), (3, 0.3333367242)], [(2, 0.6666632756), (3, 0.3333367242)], [], []] - Tv: [0.9999999998, 0.9999999998, 0, 0] - R (after): [0, 0, 0.3333316376, 0.166668362] - T: [0, 0, 1, 1] - I (=R): [0, 0, 0.6666632756, 0.3333367242] - B: [[], [], [], []] - B (outdatedmask): [[], [], [], []] - B (mask+norm): [[], [], [], []] - ΔB: [[(2, 0.1666658188), (3, 0.083334181)], [(2, 0.1666658188), (3, 0.083334181)], [], []] - ΔB (norm): [[(2, 0.5), (3, 0.5)], [(2, 0.5), (3, 0.5)], [], []] - emaB: [[(2, 0.5), (3, 0.5)], [(2, 0.5), (3, 0.5)], [], []] - D: [0.5, 0.5, 0, 0] - nE: [0.25, 0.25, 0.3333316378, 0.166668362] - E: [250000000, 250000000, 333331637, 166668361] - P: [0.25, 0.25, 0.3333316378, 0.166668362] - P (u16): [49151, 49151, 65535, 32767] */ + /* + Number of Neurons in Network: 4 + current_block: 2 + activity_cutoff: 5000 + Last update: [2, 2, 2, 2] + Block at registration: [1, 1, 1, 1] + validator_permits: [true, true, true, true] + max_allowed_validators: 4 + new_validator_permits: [true, true, true, true] + Active Stake: [0.25, 0.25, 0.25, 0.25] + Weights: [[(2, 65535), (3, 32768)], [(2, 65535), (3, 32768)], [(2, 65535)], [(3, 65535)]] + Weights (permit): [[(2, 65535), (3, 32768)], [(2, 65535), (3, 32768)], [(2, 65535)], [(3, 65535)]] + Weights (permit+diag): [[(2, 65535), (3, 32768)], [(2, 65535), (3, 32768)], [], []] + Weights (permit+diag+outdate): [[(2, 65535), (3, 32768)], [(2, 65535), (3, 32768)], [], []] + Weights (mask+norm): [[(2, 0.6666632756), (3, 0.3333367242)], [(2, 0.6666632756), (3, 0.3333367242)], [], []] + Ranks (before): [0, 0, 0.3333316376, 0.166668362] + Consensus: [0, 0, 0.6666632756, 0.3333367242] + Clipped Weights: [[(2, 0.6666632756), (3, 0.3333367242)], [(2, 0.6666632756), (3, 0.3333367242)], [], []] + Validator Trust: [0.9999999998, 0.9999999998, 0, 0] + Ranks (after): [0, 0, 0.3333316376, 0.166668362] + Trust: [0, 0, 1, 1] + Incentive (=Rank): [0, 0, 0.6666632756, 0.3333367242] + Bonds: [[], [], [], []] + Bonds: (mask+norm) [[], [], [], []] + weights_for_bonds: [[(2, 0.6666632756), (3, 0.3333367242)], [(2, 0.6666632756), (3, 0.3333367242)], [], []] + emaB: [[(2, 0.05), (3, 0.05)], [(2, 0.05), (3, 0.05)], [], []] + emaB norm: [[(2, 0.5), (3, 0.5)], [(2, 0.5), (3, 0.5)], [], []] + total_bonds_per_validator: [0.4999999998, 0.4999999998, 0, 0] + Dividends: [0.5, 0.5, 0, 0] + Normalized Server Emission: [0, 0, 0.3333316378, 0.166668362] + Server Emission: [0, 0, 333331637, 166668361] + Normalized Validator Emission: [0.25, 0.25, 0, 0] + Validator Emission: [250000000, 250000000, 0, 0] + Normalized Combined Emission: [0.25, 0.25, 0.3333316378, 0.166668362] + Combined Emission: [250000000, 250000000, 333331637, 166668361] + Pruning Scores: [0.25, 0.25, 0.3333316378, 0.166668362] + */ // === Dereg server2 at uid3 (least emission) + register new key over uid3 let new_key: u64 = n as u64; // register a new key while at max capacity, which means the least incentive uid will be deregistered @@ -2038,41 +2052,48 @@ fn test_outdated_weights() { } else { SubtensorModule::epoch_dense(netuid, 1_000_000_000); } - /* current_block: 2; activity_cutoff: 5000 - Last update: [2, 1, 1, 1]; Inactive: [false, false, false, false]; Block at registration: [0, 0, 0, 1] - S: [0.3333333333, 0.3333333333, 0.3333333333, 0] - S (mask): [0.3333333333, 0.3333333333, 0.3333333333, 0] - S (mask+norm): [0.3333333333, 0.3333333333, 0.3333333333, 0] - validator_permits: [true, true, true, false]; max_allowed_validators: 4; new_validator_permits: [true, true, true, true] - W: [[(2, 65535), (3, 32768)], [(2, 65535), (3, 32768)], [(2, 65535)], [(3, 65535)]] - W (permit): [[(2, 65535), (3, 32768)], [(2, 65535), (3, 32768)], [(2, 65535)], [(3, 65535)]] - W (permit+diag): [[(2, 65535), (3, 32768)], [(2, 65535), (3, 32768)], [], []] - W (permit+diag+outdate): [[(2, 65535), (3, 32768)], [(2, 65535)], [], []] - W (mask+norm): [[(2, 0.6666632756), (3, 0.3333367242)], [(2, 1)], [], []] - R (before): [0, 0, 0.5555544249, 0.1111122412] - C: [0, 0, 0.6666632756, 0] - W: [[(2, 0.6666632756)], [(2, 0.6666632756)], [], []] - Tv: [0.6666632756, 0.6666632756, 0, 0] - R (after): [0, 0, 0.4444421832, 0] - T: [0, 0, 0.799997558, 0] - I (=R): [0, 0, 1, 0] - B: [[(2, 65535), (3, 65535)], [(2, 65535), (3, 65535)], [], []] - B (outdatedmask): [[(2, 65535), (3, 65535)], [(2, 65535)], [], []] - B (mask+norm): [[(2, 0.5), (3, 1)], [(2, 0.5)], [], []] - ΔB: [[(2, 0.2222210916)], [(2, 0.2222210916)], [], []] - ΔB (norm): [[(2, 0.5)], [(2, 0.5)], [], []] - emaB: [[(2, 0.5), (3, 1)], [(2, 0.5)], [], []] - emaB (max-upscale): [[(2, 1), (3, 1)], [(2, 1)], [], []] - D: [0.5, 0.5, 0, 0] - nE: [0.25, 0.25, 0.5, 0] - E: [250000000, 250000000, 500000000, 0] - P: [0.25, 0.25, 0.5, 0] - P (u16): [32767, 32767, 65535, 0] */ + /* + Number of Neurons in Network: 4 + current_block: 3 + activity_cutoff: 5000 + Last update: [3, 2, 2, 2] + Block at registration: [1, 1, 1, 2] + validator_permits: [true, true, true, true] + max_allowed_validators: 4 + new_validator_permits: [true, true, true, true] + Active Stake: [0.3333333333, 0.3333333333, 0.3333333333, 0] + Weights: [[(2, 65535), (3, 32768)], [(2, 65535), (3, 32768)], [(2, 65535)], [(3, 65535)]] + Weights (permit): [[(2, 65535), (3, 32768)], [(2, 65535), (3, 32768)], [(2, 65535)], [(3, 65535)]] + Weights (permit+diag): [[(2, 65535), (3, 32768)], [(2, 65535), (3, 32768)], [], []] + Weights (permit+diag+outdate): [[(2, 65535), (3, 32768)], [(2, 65535)], [], []] + Weights (mask+norm): [[(2, 0.6666632756), (3, 0.3333367242)], [(2, 1)], [], []] + Ranks (before): [0, 0, 0.5555544249, 0.1111122412] + Consensus: [0, 0, 0.6666632756, 0] + Clipped Weights: [[(2, 0.6666632756)], [(2, 0.6666632756)], [], []] + Validator Trust: [0.6666632756, 0.6666632756, 0, 0] + Ranks (after): [0, 0, 0.4444421832, 0] + Trust: [0, 0, 0.799997558, 0] + Incentive (=Rank): [0, 0, 1, 0] + Bonds: [[(2, 3276), (3, 3276)], [(2, 3276), (3, 3276)], [], []] + Bonds: (mask+norm) [[(2, 0.0499885557), (3, 0.0499885557)], [(2, 0.0499885557)], [], []] + weights_for_bonds: [[(2, 0.6666632756)], [(2, 0.6666632756)], [], []] + emaB: [[(2, 0.0949897), (3, 0.0449897)], [(2, 0.0949897)], [], []] + emaB norm: [[(2, 0.5), (3, 1)], [(2, 0.5)], [], []] + total_bonds_per_validator: [0.5, 0.5, 0, 0] + Dividends: [0.5, 0.5, 0, 0] + Normalized Server Emission: [0, 0, 0.5, 0] + Server Emission: [0, 0, 500000000, 0] + Normalized Validator Emission: [0.25, 0.25, 0, 0] + Validator Emission: [250000000, 250000000, 0, 0] + Normalized Combined Emission: [0.25, 0.25, 0.5, 0] + Combined Emission: [250000000, 250000000, 500000000, 0] + Pruning Scores: [0.25, 0.25, 0.5, 0] + */ let bonds = SubtensorModule::get_bonds(netuid); assert_eq!(SubtensorModule::get_dividends_for_uid(netuid, 0), 32767); // Note D = floor(0.5 * 65_535) assert_eq!(SubtensorModule::get_emission_for_uid(netuid, 0), 250000000); // Note E = 0.5 * 0.5 * 1_000_000_000 = 249311245 - assert_eq!(bonds[0][2], I32F32::from_num(8300)); - assert_eq!(bonds[0][3], I32F32::from_num(1965)); + assert_eq!(bonds[0][2], I32F32::from_num(6225)); + assert_eq!(bonds[0][3], I32F32::from_num(2948)); }); } @@ -2133,7 +2154,7 @@ fn test_zero_weights() { S: [1, 0]; S (mask): [1, 0]; S (mask+norm): [1, 0]; Block at registration: [0, 0] W: [[], []]; W (diagmask): [[], []]; W (diag+outdatemask): [[], []]; W (mask+norm): [[], []] R: [0, 0]; W (threshold): [[], []]; T: [0, 0]; C: [0.006693358, 0.006693358]; I: [0, 0] - B: [[], []]; B (outdatedmask): [[], []]; B (mask+norm): [[], []]; + B: [[], []]; B (mask+norm): [[], []]; ΔB: [[], []]; ΔB (norm): [[], []]; emaB: [[], []]; D: [0, 0] E: [1000000000, 0]; P: [1, 0] */ for validator in 0..(n / 2) { @@ -2169,7 +2190,7 @@ fn test_zero_weights() { W: [[], [(1, 1)]] W (diagmask): [[], []]; W (diag+outdatemask): [[], []]; W (mask+norm): [[], []] R: [0, 0]; W (threshold): [[], []]; T: [0, 0]; C: [0.006693358, 0.006693358]; I: [0, 0] - B: [[], []]: B (outdatedmask): [[], []]; B (mask+norm): [[], []] + B: [[], []]: B (mask+norm): [[], []] ΔB: [[], []]; ΔB (norm): [[], []]; emaB: [[], []]; D: [0, 0] E: [1000000000, 0]; P: [1, 0] */ for validator in 0..(n / 2) { @@ -2224,7 +2245,7 @@ fn test_zero_weights() { S: [1, 0]; S (mask): [1, 0]; S (mask+norm): [1, 0]; Block at registration: [0, 2]; W: [[(1, 1)], []]; W (diagmask): [[(1, 1)], []]; W (diag+outdatemask): [[], []]; W (mask+norm): [[], []]; R: [0, 0]; W (threshold): [[], []]; T: [0, 0]; C: [0.006693358, 0.006693358]; I: [0, 0]; - B: [[], []]; B (outdatedmask): [[], []]; B (mask+norm): [[], []]; + B: [[], []]; B (mask+norm): [[], []]; ΔB: [[], []]; ΔB (norm): [[], []]; emaB: [[], []]; D: [0, 0]; E: [1000000000, 0]; P: [1, 0] */ for validator in 0..(n / 2) { @@ -2258,7 +2279,7 @@ fn test_zero_weights() { S: [1, 0]; S (mask): [1, 0]; S (mask+norm): [1, 0]; Block at registration: [0, 2]; W: [[(1, 1)], []]; W (diagmask): [[(1, 1)], []]; W (diag+outdatemask): [[(1, 1)], []]; W (mask+norm): [[(1, 1)], []]; R: [0, 1]; W (threshold): [[(1, 1)], []]; T: [0, 1]; C: [0.006693358, 0.9933076561]; I: [0, 1]; - B: [[], []]; B (outdatedmask): [[], []]; B (mask+norm): [[], []]; + B: [[], []]; B (mask+norm): [[], []]; ΔB: [[(1, 1)], []]; ΔB (norm): [[(1, 1)], []]; emaB: [[(1, 1)], []]; D: [1, 0]; emaB (max-upscale): [[(1, 1)], []] E: [500000000, 500000000]; P: [0.5, 0.5] */ for validator in 0..n { @@ -3084,8 +3105,7 @@ fn run_epoch_and_check_bonds_dividends( target_dividends: &[f32], ) { run_epoch(netuid, sparse); - let mut bonds = SubtensorModule::get_bonds(netuid); - bonds = mat_fixed_proportions_to_fixed(bonds.clone()); + let bonds = SubtensorModule::get_bonds(netuid); let dividends = SubtensorModule::get_dividends(netuid); let epsilon = I32F32::from_num(1e-3); From f57481f315e9b7eda8e68f343eebfe8df836f648 Mon Sep 17 00:00:00 2001 From: Andreea Popescu Date: Thu, 20 Mar 2025 15:26:13 +0000 Subject: [PATCH 28/45] clippy refactor --- pallets/subtensor/src/epoch/math.rs | 80 ++++++------ pallets/subtensor/src/epoch/run_epoch.rs | 156 ++++++++++++----------- pallets/subtensor/src/tests/epoch.rs | 27 ---- 3 files changed, 120 insertions(+), 143 deletions(-) diff --git a/pallets/subtensor/src/epoch/math.rs b/pallets/subtensor/src/epoch/math.rs index 9d783acc11..e80c03e99a 100644 --- a/pallets/subtensor/src/epoch/math.rs +++ b/pallets/subtensor/src/epoch/math.rs @@ -1380,50 +1380,48 @@ pub fn mat_ema_alpha_sparse( // The output vector of rows. let mut result: Vec> = Vec::with_capacity(new.len()); - - let n = new.len(); // Assume square matrix, rows=cols let zero: I32F32 = I32F32::saturating_from_num(0.0); + let one = I32F32::saturating_from_num(1.0); // Iterate over each row of the matrices. - for (i, (new_row, old_row)) in new.iter().zip(old).enumerate() { + for ((new_row, old_row), alpha_row) in new.iter().zip(old).zip(alpha) { // Initialize a row of zeros for the result matrix. - let mut decayed_values: Vec = vec![zero; n]; + let mut decayed_values: Vec = vec![zero; alpha_row.len()]; let mut result_row: Vec<(u16, I32F32)> = Vec::new(); // Process the old matrix values. for (j, old_val) in old_row.iter() { - let alpha_val = alpha[i][*j as usize]; - // Calculate the complement of the alpha value - let one_minus_alpha = I32F32::saturating_from_num(1.0).saturating_sub(alpha_val); - - // Bonds_decayed = Bonds * (1 - alpha) - let decayed_val = one_minus_alpha.saturating_mul(*old_val); - decayed_values[*j as usize] = decayed_val; + if let (Some(alpha_val), Some(decayed_val)) = ( + alpha_row.get(*j as usize), + decayed_values.get_mut(*j as usize), + ) { + // Calculate the complement of the alpha value + let one_minus_alpha = one.saturating_sub(*alpha_val); + // Bonds_decayed = Bonds * (1 - alpha) + *decayed_val = one_minus_alpha.saturating_mul(*old_val); + } } // Process the new matrix values. for (j, new_val) in new_row.iter() { - let alpha_val = alpha[i][*j as usize]; - let decayed_val = decayed_values[*j as usize]; - - // Calculate remaining capacity to limit bonds purchase - let remaining_capacity = I32F32::from_num(1.0) - .saturating_sub(decayed_val) - .max(I32F32::from_num(0.0)); - - // Each validator can increase bonds by at most clamped_alpha per epoch towards the cap - // Validators allocate their purchase across miners based on weights - let purchase_increment = alpha_val.saturating_mul(*new_val); - - // Ensure that purchase does not exceed remaining capacity - let purchase = purchase_increment.min(remaining_capacity); - - let result_val = decayed_val - .saturating_add(purchase) - .min(I32F32::from_num(1.0)); - if result_val > zero { - result_row.push(({ *j }, result_val)); + if let (Some(alpha_val), Some(decayed_val)) = + (alpha_row.get(*j as usize), decayed_values.get(*j as usize)) + { + // Calculate remaining capacity to limit bonds purchase + let remaining_capacity = one.saturating_sub(*decayed_val).max(zero); + + // Each validator can increase bonds by at most clamped_alpha per epoch towards the cap + // Validators allocate their purchase across miners based on weights + let purchase_increment = alpha_val.saturating_mul(*new_val); + + // Ensure that purchase does not exceed remaining capacity + let purchase = purchase_increment.min(remaining_capacity); + + let result_val = decayed_val.saturating_add(purchase).min(one); + if result_val > zero { + result_row.push((*j, result_val)); + } } } result.push(result_row); @@ -1450,11 +1448,11 @@ pub fn mat_ema_alpha( assert!(new.len() == alpha.len()); // Initialize the result matrix with zeros, having the same dimensions as the new matrix. - let mut result: Vec> = - vec![ - vec![I32F32::saturating_from_num(0.0); new.first().map_or(0, |row| row.len())]; - new.len() - ]; + let zero: I32F32 = I32F32::saturating_from_num(0.0); + let one = I32F32::saturating_from_num(1.0); + let n = new.len(); // assume square matrix + + let mut result: Vec> = vec![vec![zero; n]; n]; // Iterate over each row of the matrices. for (i, ((new_row, old_row), alpha_row)) in new.iter().zip(old).zip(alpha).enumerate() { @@ -1471,15 +1469,13 @@ pub fn mat_ema_alpha( result.get_mut(i).and_then(|row| row.get_mut(j)), ) { // Calculate the complement of the alpha value - let one_minus_alpha = I32F32::saturating_from_num(1.0).saturating_sub(*alpha_val); + let one_minus_alpha = one.saturating_sub(*alpha_val); // Bonds_decayed = Bonds * (1 - alpha) let decayed_val = one_minus_alpha.saturating_mul(*old_val); // Calculate remaining capacity to limit bonds purchase - let remaining_capacity = I32F32::from_num(1.0) - .saturating_sub(decayed_val) - .max(I32F32::from_num(0.0)); + let remaining_capacity = one.saturating_sub(decayed_val).max(zero); // Each validator can increase bonds by at most clamped_alpha per epoch towards the cap // Validators allocate their purchase across miners based on weights @@ -1488,9 +1484,7 @@ pub fn mat_ema_alpha( // Ensure that purchase does not exceed remaining capacity let purchase = purchase_increment.min(remaining_capacity); - *result_val = decayed_val - .saturating_add(purchase) - .min(I32F32::from_num(1.0)); + *result_val = decayed_val.saturating_add(purchase).min(one); } } } diff --git a/pallets/subtensor/src/epoch/run_epoch.rs b/pallets/subtensor/src/epoch/run_epoch.rs index 347828b6f3..25fd599ccd 100644 --- a/pallets/subtensor/src/epoch/run_epoch.rs +++ b/pallets/subtensor/src/epoch/run_epoch.rs @@ -898,8 +898,8 @@ impl Pallet { netuid: u16, weights: &[Vec], // weights_for_bonds bonds: &[Vec], - consensus: &Vec, - active_stake: &Vec, + consensus: &[I32F32], + active_stake: &[I32F32], ) -> Vec> { // Check if Liquid Alpha is enabled, consensus is not empty, and contains non-zero values. if LiquidAlphaOn::::get(netuid) @@ -944,8 +944,8 @@ impl Pallet { netuid: u16, weights: &[Vec<(u16, I32F32)>], bonds: &[Vec<(u16, I32F32)>], - consensus: &Vec, - active_stake: &Vec, + consensus: &[I32F32], + active_stake: &[I32F32], ) -> Vec> { // Check if Liquid Alpha is enabled, consensus is not empty, and contains non-zero values. if LiquidAlphaOn::::get(netuid) @@ -993,10 +993,9 @@ impl Pallet { netuid: u16, weights: &[Vec], // current epoch weights bonds: &[Vec], // previous epoch bonds - consensus: &Vec, // previous epoch consensus weights + consensus: &[I32F32], // previous epoch consensus weights ) -> Vec> { assert!(weights.len() == bonds.len()); - let n = weights.len(); // Assume square matrix, rows=cols // Get the high and low alpha values for the network. let alpha_sigmoid_steepness: I32F32 = I32F32::from_num(10.0); @@ -1004,37 +1003,19 @@ impl Pallet { let mut alphas = Vec::new(); - for i in 0..n { + for (w_row, b_row) in weights.iter().zip(bonds.iter()) { let mut row_alphas = Vec::new(); - for j in 0..weights[i].len() { - let diff_buy = clamp_value( - weights[i][j] - consensus[j], - I32F32::from_num(0.0), - I32F32::from_num(1.0), - ); - let diff_sell = clamp_value( - bonds[i][j] - weights[i][j], - I32F32::from_num(0.0), - I32F32::from_num(1.0), + for ((weight, bond), cons) in w_row.iter().zip(b_row.iter()).zip(consensus.iter()) { + let alpha = Self::alpha_sigmoid( + *cons, + *weight, + *bond, + alpha_low, + alpha_high, + alpha_sigmoid_steepness, ); - - let combined_diff = if weights[i][j] >= bonds[i][j] { - diff_buy - } else { - diff_sell - }; - - // sigmoid = 1. / (1. + e^(-alpha_sigmoid_steepness * (combined_diff - 0.5))) - let sigmoid = I32F32::from_num(1.0).saturating_div( - I32F32::from_num(1.0) - + safe_exp( - -alpha_sigmoid_steepness - .saturating_mul(combined_diff - I32F32::from_num(0.5)), - ), - ); - let alpha = alpha_low + sigmoid * (alpha_high - alpha_low); - row_alphas.push(clamp_value(alpha, alpha_low, alpha_high)); + row_alphas.push(alpha); } alphas.push(row_alphas); } @@ -1056,58 +1037,56 @@ impl Pallet { netuid: u16, weights: &[Vec<(u16, I32F32)>], // current epoch weights bonds: &[Vec<(u16, I32F32)>], // previous epoch bonds - consensus: &Vec, // previous epoch consensus weights + consensus: &[I32F32], // previous epoch consensus weights ) -> Vec> { assert!(weights.len() == bonds.len()); - let n = weights.len() as u16; // Assume square matrix, rows=cols - // + let alpha_sigmoid_steepness: I32F32 = I32F32::from_num(10.0); let (alpha_low, alpha_high): (I32F32, I32F32) = Self::get_alpha_values_32(netuid); - let mut alphas = Vec::with_capacity(n as usize); + let mut alphas = Vec::with_capacity(consensus.len()); + let zero = I32F32::from_num(0.0); // iterate over rows for (w_row, b_row) in weights.iter().zip(bonds.iter()) { let mut row_alphas = Vec::with_capacity(w_row.len()); - let mut w_iter = 0; - let mut b_iter = 0; - for j in 0..n { - while w_iter < w_row.len() && w_row[w_iter].0 < j { - w_iter += 1; + let mut w_iter = w_row.iter().peekable(); + let mut b_iter = b_row.iter().peekable(); + for (j_pos, consensus_val) in consensus.iter().enumerate() { + let j = j_pos as u16; + + let mut weight = zero; + while let Some(&&(i, val)) = w_iter.peek() { + if i < j { + w_iter.next(); + } else { + if i == j { + weight = val; + } + break; + } } - let w_val = if w_iter < w_row.len() && w_row[w_iter].0 == j { - w_row[w_iter].1 - } else { - I32F32::from_num(0.0) - }; - while b_iter < b_row.len() && b_row[b_iter].0 < j { - b_iter += 1; + let mut bond = zero; + while let Some(&&(i, val)) = b_iter.peek() { + if i < j { + b_iter.next(); + } else { + if i == j { + bond = val; + } + break; + } } - let b_val = if b_iter < b_row.len() && b_row[b_iter].0 == j { - b_row[b_iter].1 - } else { - I32F32::from_num(0.0) - }; - - let diff_buy = (w_val - consensus[j as usize]) - .max(I32F32::from_num(0.0)) - .min(I32F32::from_num(1.0)); - let diff_sell = (b_val - w_val) - .max(I32F32::from_num(0.0)) - .min(I32F32::from_num(1.0)); - let combined_diff = if w_val >= b_val { diff_buy } else { diff_sell }; - - // sigmoid = 1. / (1. + e^(-alpha_sigmoid_steepness * (combined_diff - 0.5))) - let sigmoid = I32F32::from_num(1.0).saturating_div( - I32F32::from_num(1.0) - + safe_exp( - -alpha_sigmoid_steepness - .saturating_mul(combined_diff - I32F32::from_num(0.5)), - ), + + let alpha = Self::alpha_sigmoid( + *consensus_val, + weight, + bond, + alpha_low, + alpha_high, + alpha_sigmoid_steepness, ); - let mut alpha = alpha_low + sigmoid * (alpha_high - alpha_low); - alpha = alpha.max(alpha_low).min(alpha_high); row_alphas.push(alpha); } alphas.push(row_alphas); @@ -1115,6 +1094,37 @@ impl Pallet { alphas } + /// Helper function to compute the alpha value using a sigmoid function. + pub fn alpha_sigmoid( + consensus: I32F32, + weight: I32F32, + bond: I32F32, + alpha_low: I32F32, + alpha_high: I32F32, + alpha_sigmoid_steepness: I32F32, + ) -> I32F32 { + let zero = I32F32::from_num(0.0); + let one = I32F32::from_num(1.0); + + let diff_buy = clamp_value(weight.saturating_sub(consensus), zero, one); + let diff_sell = clamp_value(bond.saturating_sub(weight), zero, one); + let combined_diff = if weight >= bond { diff_buy } else { diff_sell }; + + // sigmoid = 1. / (1. + e^(-steepness * (combined_diff - 0.5))) + let sigmoid = one.saturating_div( + one.saturating_add(safe_exp( + I32F32::from_num(-1).saturating_mul( + alpha_sigmoid_steepness + .saturating_mul(combined_diff.saturating_sub(I32F32::from_num(0.5))), + ), + )), + ); + let alpha = + alpha_low.saturating_add(sigmoid.saturating_mul(alpha_high.saturating_sub(alpha_low))); + + clamp_value(alpha, alpha_low, alpha_high) + } + pub fn compute_disabled_liquid_alpha(netuid: u16) -> I32F32 { // Retrieve the bonds moving average for the given network ID and scale it down. let bonds_moving_average: I64F64 = I64F64::from_num(Self::get_bonds_moving_average(netuid)) diff --git a/pallets/subtensor/src/tests/epoch.rs b/pallets/subtensor/src/tests/epoch.rs index 733372c728..4422f4faf5 100644 --- a/pallets/subtensor/src/tests/epoch.rs +++ b/pallets/subtensor/src/tests/epoch.rs @@ -3002,33 +3002,6 @@ pub fn assert_approx_eq(left: I32F32, right: I32F32, epsilon: I32F32) { } } -/// Helper function to assert approximate equality of two vectors of vectors of tuples. -fn assert_approx_eq_vec_of_vec( - left: &[Vec<(u16, I32F32)>], - right: &[Vec<(u16, I32F32)>], - epsilon: I32F32, -) { - assert_eq!(left.len(), right.len(), "Vectors have different lengths"); - for (left_row, right_row) in left.iter().zip(right.iter()) { - assert_eq!( - left_row.len(), - right_row.len(), - "Rows have different lengths" - ); - for ((left_idx, left_val), (right_idx, right_val)) in left_row.iter().zip(right_row.iter()) - { - assert_eq!(left_idx, right_idx, "Indices are different"); - assert!( - (left_val - right_val).abs() < epsilon, - "Values are different: left = {:?}, right = {:?}, epsilon = {:?}", - left_val, - right_val, - epsilon - ); - } - } -} - // test Yuma 4 scenarios over a sequence of epochs. fn setup_yuma_4_scenario(netuid: u16, n: u16, sparse: bool, max_stake: u64, stakes: Vec) { let block_number = System::block_number(); From 9cdef41d68679972995b451becd0961740a6273c Mon Sep 17 00:00:00 2001 From: Andreea Popescu Date: Thu, 20 Mar 2025 16:38:17 +0000 Subject: [PATCH 29/45] add alpha sigmoid steepness param --- hyperparameters.md | 2 ++ pallets/admin-utils/src/lib.rs | 29 ++++++++++++++++++++++++++ pallets/admin-utils/src/tests/mock.rs | 2 ++ pallets/subtensor/src/lib.rs | 9 ++++++++ pallets/subtensor/src/macros/config.rs | 3 +++ pallets/subtensor/src/macros/events.rs | 2 ++ pallets/subtensor/src/tests/mock.rs | 2 ++ pallets/subtensor/src/utils/misc.rs | 8 +++++++ precompiles/src/subnet.rs | 22 +++++++++++++++++++ runtime/src/lib.rs | 4 +++- 10 files changed, 82 insertions(+), 1 deletion(-) diff --git a/hyperparameters.md b/hyperparameters.md index c8d2ce1106..049ace84d2 100644 --- a/hyperparameters.md +++ b/hyperparameters.md @@ -7,6 +7,7 @@ TxRateLimit: u64 = 1; // [1 @ 64,888] ### netuid 1 (text_prompting) ```rust Rho: u16 = 10; +AlphaSigmoidSteepness: u16 = 10.0 Kappa: u16 = 32_767; // 0.5 = 65535/2 MaxAllowedUids: u16 = 1024; Issuance: u64 = 0; @@ -46,6 +47,7 @@ WeightsSetRateLimit: u64 = 100; ### netuid 3 (causallmnext) ```rust Rho: u16 = 10; +AlphaSigmoidSteepness: u16 = 10.0 Kappa: u16 = 32_767; // 0.5 = 65535/2 MaxAllowedUids: u16 = 4096; Issuance: u64 = 0; diff --git a/pallets/admin-utils/src/lib.rs b/pallets/admin-utils/src/lib.rs index 19bbbee73b..0175401b7f 100644 --- a/pallets/admin-utils/src/lib.rs +++ b/pallets/admin-utils/src/lib.rs @@ -1476,6 +1476,35 @@ pub mod pallet { ); Ok(()) } + + /// + /// + /// # Arguments + /// * `origin` - The origin of the call, which must be the root account. + /// * `netuid` - The unique identifier for the subnet. + /// * `steepness` - The new steepness for the alpha sigmoid function. + /// + /// # Errors + /// * `BadOrigin` - If the caller is not the root account. + /// # Weight + /// Weight is handled by the `#[pallet::weight]` attribute. + #[pallet::call_index(66)] + #[pallet::weight((0, DispatchClass::Operational, Pays::No))] + pub fn sudo_set_alpha_sigmoid_steepness( + origin: OriginFor, + netuid: u16, + steepness: u16, + ) -> DispatchResult { + ensure_root(origin)?; + pallet_subtensor::Pallet::::set_alpha_sigmoid_steepness(netuid, steepness); + + log::debug!( + "AlphaSigmoidSteepnessSet( netuid: {:?}, steepness: {:?} )", + netuid, + steepness + ); + Ok(()) + } } } diff --git a/pallets/admin-utils/src/tests/mock.rs b/pallets/admin-utils/src/tests/mock.rs index 99c11b7165..6932632f4b 100644 --- a/pallets/admin-utils/src/tests/mock.rs +++ b/pallets/admin-utils/src/tests/mock.rs @@ -80,6 +80,7 @@ parameter_types! { pub const TransactionByteFee: Balance = 100; pub const SDebug:u64 = 1; pub const InitialRho: u16 = 30; + pub const InitialAlphaSigmoidSteepness: u16 = u16::MAX/10; // 10% steepness pub const InitialKappa: u16 = 32_767; pub const InitialTempo: u16 = 0; pub const SelfOwnership: u64 = 2; @@ -157,6 +158,7 @@ impl pallet_subtensor::Config for Test { type InitialAdjustmentAlpha = InitialAdjustmentAlpha; type InitialTargetRegistrationsPerInterval = InitialTargetRegistrationsPerInterval; type InitialRho = InitialRho; + type InitialAlphaSigmoidSteepness = InitialAlphaSigmoidSteepness; type InitialKappa = InitialKappa; type InitialMaxAllowedUids = InitialMaxAllowedUids; type InitialValidatorPruneLen = InitialValidatorPruneLen; diff --git a/pallets/subtensor/src/lib.rs b/pallets/subtensor/src/lib.rs index e360c307e1..a78001e66b 100644 --- a/pallets/subtensor/src/lib.rs +++ b/pallets/subtensor/src/lib.rs @@ -566,6 +566,11 @@ pub mod pallet { T::InitialRho::get() } #[pallet::type_value] + /// Default value for alpha sigmoid steepness. + pub fn DefaultAlphaSigmoidSteepness() -> u16 { + T::InitialAlphaSigmoidSteepness::get() + } + #[pallet::type_value] /// Default value for kappa parameter. pub fn DefaultKappa() -> u16 { T::InitialKappa::get() @@ -1215,6 +1220,10 @@ pub mod pallet { /// --- MAP ( netuid ) --> Rho pub type Rho = StorageMap<_, Identity, u16, u16, ValueQuery, DefaultRho>; #[pallet::storage] + /// --- MAP ( netuid ) --> AlphaSigmoidSteepness + pub type AlphaSigmoidSteepness = + StorageMap<_, Identity, u16, u16, ValueQuery, DefaultAlphaSigmoidSteepness>; + #[pallet::storage] /// --- MAP ( netuid ) --> Kappa pub type Kappa = StorageMap<_, Identity, u16, u16, ValueQuery, DefaultKappa>; #[pallet::storage] diff --git a/pallets/subtensor/src/macros/config.rs b/pallets/subtensor/src/macros/config.rs index cf4d97b65b..76e7840e74 100644 --- a/pallets/subtensor/src/macros/config.rs +++ b/pallets/subtensor/src/macros/config.rs @@ -102,6 +102,9 @@ mod config { /// Rho constant. #[pallet::constant] type InitialRho: Get; + /// AlphaSigmoidSteepness constant. + #[pallet::constant] + type InitialAlphaSigmoidSteepness: Get; /// Kappa constant. #[pallet::constant] type InitialKappa: Get; diff --git a/pallets/subtensor/src/macros/events.rs b/pallets/subtensor/src/macros/events.rs index 8c2e863d0e..771e3f545a 100644 --- a/pallets/subtensor/src/macros/events.rs +++ b/pallets/subtensor/src/macros/events.rs @@ -43,6 +43,8 @@ mod events { ActivityCutoffSet(u16, u16), /// Rho value is set. RhoSet(u16, u16), + /// steepness of the sigmoid used to compute alpha values. + AlphaSigmoidSteepnessSet(u16, u16), /// Kappa is set for a subnet. KappaSet(u16, u16), /// minimum allowed weight is set for a subnet. diff --git a/pallets/subtensor/src/tests/mock.rs b/pallets/subtensor/src/tests/mock.rs index 9729d55d1a..eb86dc8935 100644 --- a/pallets/subtensor/src/tests/mock.rs +++ b/pallets/subtensor/src/tests/mock.rs @@ -132,6 +132,7 @@ parameter_types! { pub const TransactionByteFee: Balance = 100; pub const SDebug:u64 = 1; pub const InitialRho: u16 = 30; + pub const InitialAlphaSigmoidSteepness: u16 = u16::MAX/10; pub const InitialKappa: u16 = 32_767; pub const InitialTempo: u16 = 360; pub const SelfOwnership: u64 = 2; @@ -366,6 +367,7 @@ impl crate::Config for Test { type InitialAdjustmentAlpha = InitialAdjustmentAlpha; type InitialTargetRegistrationsPerInterval = InitialTargetRegistrationsPerInterval; type InitialRho = InitialRho; + type InitialAlphaSigmoidSteepness = InitialAlphaSigmoidSteepness; type InitialKappa = InitialKappa; type InitialMaxAllowedUids = InitialMaxAllowedUids; type InitialValidatorPruneLen = InitialValidatorPruneLen; diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 6f2ea1ffa3..72eeb5bc5e 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -687,6 +687,14 @@ impl Pallet { (converted_low, converted_high) } + pub fn set_alpha_sigmoid_steepness(netuid: u16, steepness: u16) { + AlphaSigmoidSteepness::::insert(netuid, steepness); + } + pub fn get_alpha_sigmoid_steepness(netuid: u16) -> I32F32 { + let alpha = AlphaSigmoidSteepness::::get(netuid); + I32F32::saturating_from_num(alpha).safe_div(I32F32::saturating_from_num(u16::MAX)) + } + pub fn set_liquid_alpha_enabled(netuid: u16, enabled: bool) { LiquidAlphaOn::::set(netuid, enabled); } diff --git a/precompiles/src/subnet.rs b/precompiles/src/subnet.rs index e9bfc0c5f9..ae57584eb5 100644 --- a/precompiles/src/subnet.rs +++ b/precompiles/src/subnet.rs @@ -327,6 +327,12 @@ where Ok(pallet_subtensor::Rho::::get(netuid)) } + #[precompile::public("getAlphaSigmoidSteepness(uint16)")] + #[precompile::view] + fn get_alpha_sigmoid_steepness(_: &mut impl PrecompileHandle, netuid: u16) -> EvmResult { + Ok(pallet_subtensor::AlphaSigmoidSteepness::::get(netuid)) + } + #[precompile::public("setRho(uint16,uint16)")] #[precompile::payable] fn set_rho(handle: &mut impl PrecompileHandle, netuid: u16, rho: u16) -> EvmResult<()> { @@ -338,6 +344,22 @@ where ) } + #[precompile::public("setAlphaSigmoidSteepness(uint16,uint16)")] + #[precompile::payable] + fn set_alpha_sigmoid_steepness( + handle: &mut impl PrecompileHandle, + netuid: u16, + steepness: u16, + ) -> EvmResult<()> { + let call = + pallet_admin_utils::Call::::sudo_set_alpha_sigmoid_steepness { netuid, steepness }; + + handle.try_dispatch_runtime_call::( + call, + RawOrigin::Signed(handle.caller_account_id::()), + ) + } + #[precompile::public("getActivityCutoff(uint16)")] #[precompile::view] fn get_activity_cutoff(_: &mut impl PrecompileHandle, netuid: u16) -> EvmResult { diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 41117a6c5d..e7d0732cfa 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -990,7 +990,8 @@ pub const INITIAL_CHILDKEY_TAKE_RATELIMIT: u64 = 5; // Configure the pallet subtensor. parameter_types! { - pub const SubtensorInitialRho: u16 = 10; + pub const SubtensorInitialRho: u16 = u16::MAX/10; // 10% + pub const SubtensorInitialAlphaSigmoidSteepness: u16 = 1000; pub const SubtensorInitialKappa: u16 = 32_767; // 0.5 = 65535/2 pub const SubtensorInitialMaxAllowedUids: u16 = 4096; pub const SubtensorInitialIssuance: u64 = 0; @@ -1061,6 +1062,7 @@ impl pallet_subtensor::Config for Runtime { type TriumvirateInterface = TriumvirateVotes; type Scheduler = Scheduler; type InitialRho = SubtensorInitialRho; + type InitialAlphaSigmoidSteepness = SubtensorInitialAlphaSigmoidSteepness; type InitialKappa = SubtensorInitialKappa; type InitialMaxAllowedUids = SubtensorInitialMaxAllowedUids; type InitialBondsMovingAverage = SubtensorInitialBondsMovingAverage; From ae6d281b9fd0dc0ec9e1e74d58fca8c0a34c8137 Mon Sep 17 00:00:00 2001 From: Andreea Popescu Date: Fri, 21 Mar 2025 10:47:52 +0000 Subject: [PATCH 30/45] refactor bonds fetching --- pallets/subtensor/src/epoch/math.rs | 24 ++++++++++------- pallets/subtensor/src/epoch/run_epoch.rs | 34 +++++++++++++++++++----- pallets/subtensor/src/tests/epoch.rs | 2 +- 3 files changed, 43 insertions(+), 17 deletions(-) diff --git a/pallets/subtensor/src/epoch/math.rs b/pallets/subtensor/src/epoch/math.rs index e80c03e99a..365276ca9f 100644 --- a/pallets/subtensor/src/epoch/math.rs +++ b/pallets/subtensor/src/epoch/math.rs @@ -55,6 +55,11 @@ pub fn u16_proportion_to_fixed(x: u16) -> I32F32 { I32F32::saturating_from_num(x).safe_div(I32F32::saturating_from_num(u16::MAX)) } +#[allow(dead_code)] +pub fn fixed_to_fixed_proportion(x: I32F32) -> I32F32 { + x.safe_div(I32F32::saturating_from_num(u16::MAX)) +} + #[allow(dead_code)] pub fn fixed_proportion_to_u16(x: I32F32) -> u16 { fixed_to_u16(x.saturating_mul(I32F32::saturating_from_num(u16::MAX))) @@ -1450,24 +1455,21 @@ pub fn mat_ema_alpha( // Initialize the result matrix with zeros, having the same dimensions as the new matrix. let zero: I32F32 = I32F32::saturating_from_num(0.0); let one = I32F32::saturating_from_num(1.0); - let n = new.len(); // assume square matrix - let mut result: Vec> = vec![vec![zero; n]; n]; + let mut result: Vec> = Vec::with_capacity(new.len()); // Iterate over each row of the matrices. - for (i, ((new_row, old_row), alpha_row)) in new.iter().zip(old).zip(alpha).enumerate() { + for ((new_row, old_row), alpha_row) in new.iter().zip(old).zip(alpha) { assert!(new_row.len() == old_row.len()); assert!(new_row.len() == alpha_row.len()); + let mut result_row: Vec = Vec::new(); // Iterate over each column of the current row. for j in 0..new_row.len() { // Compute the EMA for the current element using saturating operations. - if let (Some(new_val), Some(old_val), Some(alpha_val), Some(result_val)) = ( - new_row.get(j), - old_row.get(j), - alpha_row.get(j), - result.get_mut(i).and_then(|row| row.get_mut(j)), - ) { + if let (Some(new_val), Some(old_val), Some(alpha_val)) = + (new_row.get(j), old_row.get(j), alpha_row.get(j)) + { // Calculate the complement of the alpha value let one_minus_alpha = one.saturating_sub(*alpha_val); @@ -1484,9 +1486,11 @@ pub fn mat_ema_alpha( // Ensure that purchase does not exceed remaining capacity let purchase = purchase_increment.min(remaining_capacity); - *result_val = decayed_val.saturating_add(purchase).min(one); + let result_val = decayed_val.saturating_add(purchase).min(one); + result_row.push(result_val); } } + result.push(result_row); } // Return the computed EMA matrix. diff --git a/pallets/subtensor/src/epoch/run_epoch.rs b/pallets/subtensor/src/epoch/run_epoch.rs index 25fd599ccd..c65e239867 100644 --- a/pallets/subtensor/src/epoch/run_epoch.rs +++ b/pallets/subtensor/src/epoch/run_epoch.rs @@ -198,7 +198,7 @@ impl Pallet { interpolate(&weights, &clipped_weights, bonds_penalty); // Access network bonds. - let mut bonds: Vec> = Self::get_bonds(netuid); + let mut bonds: Vec> = Self::get_bonds_fixed_proportion(netuid); inplace_mask_matrix(&outdated, &mut bonds); // mask outdated bonds log::trace!("B: {:?}", &bonds); @@ -573,7 +573,7 @@ impl Pallet { interpolate_sparse(&weights, &clipped_weights, n, bonds_penalty); // Access network bonds. - let mut bonds: Vec> = Self::get_bonds_sparse(netuid); + let mut bonds: Vec> = Self::get_bonds_sparse_fixed_proportion(netuid); log::trace!("Bonds: {:?}", &bonds); // Remove bonds referring to neurons that have registered since last tempo. @@ -857,7 +857,7 @@ impl Pallet { bonds .get_mut(uid_i as usize) .expect("uid_i is filtered to be less than n; qed") - .push((uid_j, u16_proportion_to_fixed(bonds_ij))); + .push((uid_j, u16_to_fixed(bonds_ij))); } } bonds @@ -877,12 +877,32 @@ impl Pallet { .expect("uid_i has been filtered to be less than n; qed") .get_mut(uid_j as usize) .expect("uid_j has been filtered to be less than n; qed") = - u16_proportion_to_fixed(bonds_ij); + u16_to_fixed(bonds_ij); } } bonds } + pub fn get_bonds_fixed_proportion(netuid: u16) -> Vec> { + let mut bonds = Self::get_bonds(netuid); + bonds.iter_mut().for_each(|bonds_row| { + bonds_row + .iter_mut() + .for_each(|bond| *bond = fixed_to_fixed_proportion(*bond)); + }); + bonds + } + + pub fn get_bonds_sparse_fixed_proportion(netuid: u16) -> Vec> { + let mut bonds = Self::get_bonds_sparse(netuid); + bonds.iter_mut().for_each(|bonds_row| { + bonds_row + .iter_mut() + .for_each(|(_, bond)| *bond = fixed_to_fixed_proportion(*bond)); + }); + bonds + } + /// Compute the Exponential Moving Average (EMA) of bonds based on the Liquid Alpha setting /// /// # Args: @@ -1006,9 +1026,11 @@ impl Pallet { for (w_row, b_row) in weights.iter().zip(bonds.iter()) { let mut row_alphas = Vec::new(); - for ((weight, bond), cons) in w_row.iter().zip(b_row.iter()).zip(consensus.iter()) { + for ((weight, bond), consensus_val) in + w_row.iter().zip(b_row.iter()).zip(consensus.iter()) + { let alpha = Self::alpha_sigmoid( - *cons, + *consensus_val, *weight, *bond, alpha_low, diff --git a/pallets/subtensor/src/tests/epoch.rs b/pallets/subtensor/src/tests/epoch.rs index 4422f4faf5..62b94e8331 100644 --- a/pallets/subtensor/src/tests/epoch.rs +++ b/pallets/subtensor/src/tests/epoch.rs @@ -3078,7 +3078,7 @@ fn run_epoch_and_check_bonds_dividends( target_dividends: &[f32], ) { run_epoch(netuid, sparse); - let bonds = SubtensorModule::get_bonds(netuid); + let bonds = SubtensorModule::get_bonds_fixed_proportion(netuid); let dividends = SubtensorModule::get_dividends(netuid); let epsilon = I32F32::from_num(1e-3); From fc06c55e447be089dd50a1b82bad34abaa69043a Mon Sep 17 00:00:00 2001 From: Andreea Popescu Date: Fri, 21 Mar 2025 11:56:05 +0000 Subject: [PATCH 31/45] use sigmoid steepness param --- pallets/admin-utils/src/tests/mock.rs | 2 +- pallets/subtensor/src/epoch/run_epoch.rs | 4 ++-- pallets/subtensor/src/tests/epoch.rs | 2 +- pallets/subtensor/src/tests/mock.rs | 2 +- pallets/subtensor/src/utils/misc.rs | 2 +- runtime/src/lib.rs | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pallets/admin-utils/src/tests/mock.rs b/pallets/admin-utils/src/tests/mock.rs index 6932632f4b..5f0d6bdcfa 100644 --- a/pallets/admin-utils/src/tests/mock.rs +++ b/pallets/admin-utils/src/tests/mock.rs @@ -80,7 +80,7 @@ parameter_types! { pub const TransactionByteFee: Balance = 100; pub const SDebug:u64 = 1; pub const InitialRho: u16 = 30; - pub const InitialAlphaSigmoidSteepness: u16 = u16::MAX/10; // 10% steepness + pub const InitialAlphaSigmoidSteepness: u16 = 10; pub const InitialKappa: u16 = 32_767; pub const InitialTempo: u16 = 0; pub const SelfOwnership: u64 = 2; diff --git a/pallets/subtensor/src/epoch/run_epoch.rs b/pallets/subtensor/src/epoch/run_epoch.rs index c65e239867..0d8d123c9e 100644 --- a/pallets/subtensor/src/epoch/run_epoch.rs +++ b/pallets/subtensor/src/epoch/run_epoch.rs @@ -1018,7 +1018,7 @@ impl Pallet { assert!(weights.len() == bonds.len()); // Get the high and low alpha values for the network. - let alpha_sigmoid_steepness: I32F32 = I32F32::from_num(10.0); + let alpha_sigmoid_steepness: I32F32 = Self::get_alpha_sigmoid_steepness(netuid); let (alpha_low, alpha_high): (I32F32, I32F32) = Self::get_alpha_values_32(netuid); let mut alphas = Vec::new(); @@ -1063,7 +1063,7 @@ impl Pallet { ) -> Vec> { assert!(weights.len() == bonds.len()); - let alpha_sigmoid_steepness: I32F32 = I32F32::from_num(10.0); + let alpha_sigmoid_steepness: I32F32 = Self::get_alpha_sigmoid_steepness(netuid); let (alpha_low, alpha_high): (I32F32, I32F32) = Self::get_alpha_values_32(netuid); let mut alphas = Vec::with_capacity(consensus.len()); diff --git a/pallets/subtensor/src/tests/epoch.rs b/pallets/subtensor/src/tests/epoch.rs index 62b94e8331..bb54392480 100644 --- a/pallets/subtensor/src/tests/epoch.rs +++ b/pallets/subtensor/src/tests/epoch.rs @@ -3016,7 +3016,7 @@ fn setup_yuma_4_scenario(netuid: u16, n: u16, sparse: bool, max_stake: u64, stak SubtensorModule::set_min_allowed_weights(netuid, 1); SubtensorModule::set_max_weight_limit(netuid, u16::MAX); SubtensorModule::set_bonds_penalty(netuid, 0); - // SubtensorModule::set_bonds_moving_average(netuid, 975_000); + SubtensorModule::set_alpha_sigmoid_steepness(netuid, 10); // === Register for key in 0..n as u64 { diff --git a/pallets/subtensor/src/tests/mock.rs b/pallets/subtensor/src/tests/mock.rs index eb86dc8935..dff78b7a28 100644 --- a/pallets/subtensor/src/tests/mock.rs +++ b/pallets/subtensor/src/tests/mock.rs @@ -132,7 +132,7 @@ parameter_types! { pub const TransactionByteFee: Balance = 100; pub const SDebug:u64 = 1; pub const InitialRho: u16 = 30; - pub const InitialAlphaSigmoidSteepness: u16 = u16::MAX/10; + pub const InitialAlphaSigmoidSteepness: u16 = 10; pub const InitialKappa: u16 = 32_767; pub const InitialTempo: u16 = 360; pub const SelfOwnership: u64 = 2; diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 72eeb5bc5e..e36f033a74 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -692,7 +692,7 @@ impl Pallet { } pub fn get_alpha_sigmoid_steepness(netuid: u16) -> I32F32 { let alpha = AlphaSigmoidSteepness::::get(netuid); - I32F32::saturating_from_num(alpha).safe_div(I32F32::saturating_from_num(u16::MAX)) + I32F32::saturating_from_num(alpha) } pub fn set_liquid_alpha_enabled(netuid: u16, enabled: bool) { diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index e7d0732cfa..a6e3350b5e 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -990,7 +990,7 @@ pub const INITIAL_CHILDKEY_TAKE_RATELIMIT: u64 = 5; // Configure the pallet subtensor. parameter_types! { - pub const SubtensorInitialRho: u16 = u16::MAX/10; // 10% + pub const SubtensorInitialRho: u16 = 10; pub const SubtensorInitialAlphaSigmoidSteepness: u16 = 1000; pub const SubtensorInitialKappa: u16 = 32_767; // 0.5 = 65535/2 pub const SubtensorInitialMaxAllowedUids: u16 = 4096; From bf6f6d7da83ac5fb877cdfaffedfe6389d33052e Mon Sep 17 00:00:00 2001 From: Andreea Popescu Date: Tue, 25 Mar 2025 10:05:01 +0000 Subject: [PATCH 32/45] yuma3 rename --- pallets/subtensor/src/tests/epoch.rs | 48 ++++++++++++++-------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/pallets/subtensor/src/tests/epoch.rs b/pallets/subtensor/src/tests/epoch.rs index bb54392480..d3c95bde4d 100644 --- a/pallets/subtensor/src/tests/epoch.rs +++ b/pallets/subtensor/src/tests/epoch.rs @@ -3003,7 +3003,7 @@ pub fn assert_approx_eq(left: I32F32, right: I32F32, epsilon: I32F32) { } // test Yuma 4 scenarios over a sequence of epochs. -fn setup_yuma_4_scenario(netuid: u16, n: u16, sparse: bool, max_stake: u64, stakes: Vec) { +fn setup_yuma_3_scenario(netuid: u16, n: u16, sparse: bool, max_stake: u64, stakes: Vec) { let block_number = System::block_number(); let tempo: u16 = u16::MAX - 1; // high tempo to skip automatic epochs in on_initialize, use manual epochs instead add_network(netuid, tempo, 0); @@ -3102,7 +3102,7 @@ fn run_epoch_and_check_bonds_dividends( } } -fn set_yuma_4_weights(netuid: u16, weights: Vec>) { +fn set_yuma_3_weights(netuid: u16, weights: Vec>) { for (uid, weight) in weights.iter().enumerate() { assert_ok!(SubtensorModule::set_weights( RuntimeOrigin::signed(U256::from(uid as u64)), @@ -3115,7 +3115,7 @@ fn set_yuma_4_weights(netuid: u16, weights: Vec>) { } #[test] -fn test_yuma_4_kappa_moves_first() { +fn test_yuma_3_kappa_moves_first() { new_test_ext(1).execute_with(|| { let sparse: bool = true; let n: u16 = 5; // 3 validators, 2 servers @@ -3127,7 +3127,7 @@ fn test_yuma_4_kappa_moves_first() { // Validator C: Small lazy validator (0.1) - moves last let stakes: Vec = vec![8, 1, 1, 0, 0]; - setup_yuma_4_scenario(netuid, n, sparse, max_stake, stakes); + setup_yuma_3_scenario(netuid, n, sparse, max_stake, stakes); let targets_bonds = [ vec![ vec![0.1013, 0.0000], @@ -3178,13 +3178,13 @@ fn test_yuma_4_kappa_moves_first() { match epoch { 0 => { // Initially, consensus is achieved by all Validators - set_yuma_4_weights(netuid, vec![vec![u16::MAX, 0]; 3]); + set_yuma_3_weights(netuid, vec![vec![u16::MAX, 0]; 3]); } 1 => { // Validator A -> Server 2 // Validator B -> Server 1 // Validator C -> Server 1 - set_yuma_4_weights( + set_yuma_3_weights( netuid, vec![vec![0, u16::MAX], vec![u16::MAX, 0], vec![u16::MAX, 0]], ); @@ -3193,14 +3193,14 @@ fn test_yuma_4_kappa_moves_first() { // Validator A -> Server 2 // Validator B -> Server 2 // Validator C -> Server 1 - set_yuma_4_weights( + set_yuma_3_weights( netuid, vec![vec![0, u16::MAX], vec![0, u16::MAX], vec![u16::MAX, 0]], ); } 3 => { // Subsequent epochs All validators -> Server 2 - set_yuma_4_weights(netuid, vec![vec![0, u16::MAX]; 3]); + set_yuma_3_weights(netuid, vec![vec![0, u16::MAX]; 3]); } _ => {} }; @@ -3210,7 +3210,7 @@ fn test_yuma_4_kappa_moves_first() { } #[test] -fn test_yuma_4_kappa_moves_second() { +fn test_yuma_3_kappa_moves_second() { new_test_ext(1).execute_with(|| { let sparse: bool = false; let n: u16 = 5; // 3 validators, 2 servers @@ -3222,7 +3222,7 @@ fn test_yuma_4_kappa_moves_second() { // Validator C: Small lazy validator (0.1) - moves last let stakes: Vec = vec![8, 1, 1, 0, 0]; - setup_yuma_4_scenario(netuid, n, sparse, max_stake, stakes); + setup_yuma_3_scenario(netuid, n, sparse, max_stake, stakes); let targets_bonds = [ vec![ vec![0.1013, 0.0000], @@ -3272,13 +3272,13 @@ fn test_yuma_4_kappa_moves_second() { match epoch { 0 => { // Initially, consensus is achieved by all Validators - set_yuma_4_weights(netuid, vec![vec![u16::MAX, 0]; 3]); + set_yuma_3_weights(netuid, vec![vec![u16::MAX, 0]; 3]); } 1 => { // Validator A -> Server 1 // Validator B -> Server 2 // Validator C -> Server 1 - set_yuma_4_weights( + set_yuma_3_weights( netuid, vec![vec![u16::MAX, 0], vec![0, u16::MAX], vec![u16::MAX, 0]], ); @@ -3287,14 +3287,14 @@ fn test_yuma_4_kappa_moves_second() { // Validator A -> Server 2 // Validator B -> Server 2 // Validator C -> Server 1 - set_yuma_4_weights( + set_yuma_3_weights( netuid, vec![vec![0, u16::MAX], vec![0, u16::MAX], vec![u16::MAX, 0]], ); } 3 => { // Subsequent epochs All validators -> Server 2 - set_yuma_4_weights(netuid, vec![vec![0, u16::MAX]; 3]); + set_yuma_3_weights(netuid, vec![vec![0, u16::MAX]; 3]); } _ => {} }; @@ -3304,7 +3304,7 @@ fn test_yuma_4_kappa_moves_second() { } #[test] -fn test_yuma_4_kappa_moves_last() { +fn test_yuma_3_kappa_moves_last() { new_test_ext(1).execute_with(|| { let sparse: bool = true; let n: u16 = 5; // 3 validators, 2 servers @@ -3316,7 +3316,7 @@ fn test_yuma_4_kappa_moves_last() { // Validator C: Small lazy validator (0.1) - moves second let stakes: Vec = vec![8, 1, 1, 0, 0]; - setup_yuma_4_scenario(netuid, n, sparse, max_stake, stakes); + setup_yuma_3_scenario(netuid, n, sparse, max_stake, stakes); let targets_bonds = [ vec![ vec![0.1013, 0.0000], @@ -3366,13 +3366,13 @@ fn test_yuma_4_kappa_moves_last() { match epoch { 0 => { // Initially, consensus is achieved by all Validators - set_yuma_4_weights(netuid, vec![vec![u16::MAX, 0]; 3]); + set_yuma_3_weights(netuid, vec![vec![u16::MAX, 0]; 3]); } 1 => { // Validator A -> Server 1 // Validator B -> Server 2 // Validator C -> Server 1 - set_yuma_4_weights( + set_yuma_3_weights( netuid, vec![vec![u16::MAX, 0], vec![0, u16::MAX], vec![u16::MAX, 0]], ); @@ -3381,14 +3381,14 @@ fn test_yuma_4_kappa_moves_last() { // Validator A -> Server 1 // Validator B -> Server 2 // Validator C -> Server 2 - set_yuma_4_weights( + set_yuma_3_weights( netuid, vec![vec![u16::MAX, 0], vec![0, u16::MAX], vec![0, u16::MAX]], ); } 3 => { // Subsequent epochs All validators -> Server 2 - set_yuma_4_weights(netuid, vec![vec![0, u16::MAX]; 3]); + set_yuma_3_weights(netuid, vec![vec![0, u16::MAX]; 3]); } _ => {} }; @@ -3398,7 +3398,7 @@ fn test_yuma_4_kappa_moves_last() { } #[test] -fn test_yuma_4_one_epoch_switch() { +fn test_yuma_3_one_epoch_switch() { new_test_ext(1).execute_with(|| { let sparse: bool = true; let n: u16 = 5; // 3 validators, 2 servers @@ -3408,7 +3408,7 @@ fn test_yuma_4_one_epoch_switch() { // Equal stake validators let stakes: Vec = vec![33, 33, 34, 0, 0]; - setup_yuma_4_scenario(netuid, n, sparse, max_stake, stakes); + setup_yuma_3_scenario(netuid, n, sparse, max_stake, stakes); let targets_bonds = [ vec![ @@ -3461,14 +3461,14 @@ fn test_yuma_4_one_epoch_switch() { // Validator A -> Server 1 // Validator B -> Server 1 // Validator C -> Server 2 - set_yuma_4_weights( + set_yuma_3_weights( netuid, vec![vec![u16::MAX, 0], vec![u16::MAX, 0], vec![0, u16::MAX]], ); } _ => { // All validators -> Server 1 - set_yuma_4_weights(netuid, vec![vec![u16::MAX, 0]; 3]); + set_yuma_3_weights(netuid, vec![vec![u16::MAX, 0]; 3]); } }; run_epoch_and_check_bonds_dividends(netuid, sparse, target_bonds, target_dividends); From d6c51f005216873b509f3425d2456943d5c45fa4 Mon Sep 17 00:00:00 2001 From: Andreea Popescu Date: Tue, 25 Mar 2025 11:12:11 +0000 Subject: [PATCH 33/45] more improved tests --- pallets/subtensor/src/tests/epoch.rs | 839 +++++++++++++++------------ 1 file changed, 479 insertions(+), 360 deletions(-) diff --git a/pallets/subtensor/src/tests/epoch.rs b/pallets/subtensor/src/tests/epoch.rs index d3c95bde4d..97d4fdf400 100644 --- a/pallets/subtensor/src/tests/epoch.rs +++ b/pallets/subtensor/src/tests/epoch.rs @@ -3049,13 +3049,10 @@ fn setup_yuma_3_scenario(netuid: u16, n: u16, sparse: bool, max_stake: u64, stak // Enable Liquid Alpha SubtensorModule::set_kappa(netuid, u16::MAX / 2); SubtensorModule::set_liquid_alpha_enabled(netuid, true); - SubtensorModule::set_kappa(netuid, u16::MAX / 2); - SubtensorModule::set_alpha_values_32(netuid, I32F32::from_num(0.1), I32F32::from_num(0.3)); // === Issue validator permits SubtensorModule::set_max_allowed_validators(netuid, 3); - assert_eq!(SubtensorModule::get_max_allowed_validators(netuid), 3); // run first epoch to set allowed validators // run to next block to ensure weights are set on nodes after their registration block @@ -3083,15 +3080,12 @@ fn run_epoch_and_check_bonds_dividends( let epsilon = I32F32::from_num(1e-3); // Check the bonds - // server 1 - assert_approx_eq(bonds[0][3], fixed(target_bonds[0][0]), epsilon); - assert_approx_eq(bonds[1][3], fixed(target_bonds[1][0]), epsilon); - assert_approx_eq(bonds[2][3], fixed(target_bonds[2][0]), epsilon); - // server 2 - assert_approx_eq(bonds[0][4], fixed(target_bonds[0][1]), epsilon); - assert_approx_eq(bonds[1][4], fixed(target_bonds[1][1]), epsilon); - assert_approx_eq(bonds[2][4], fixed(target_bonds[2][1]), epsilon); - + for (bond, target_bond) in bonds.iter().zip(target_bonds.iter()) { + // skip the 3 validators + for (b, t) in bond.iter().zip(target_bond.iter().skip(3)) { + assert_approx_eq(*b, fixed(*t), epsilon); + } + } // Check the dividends for (dividend, target_dividend) in dividends.iter().zip(target_dividends.iter()) { assert_approx_eq( @@ -3102,12 +3096,12 @@ fn run_epoch_and_check_bonds_dividends( } } -fn set_yuma_3_weights(netuid: u16, weights: Vec>) { +fn set_yuma_3_weights(netuid: u16, weights: Vec>, indices: Vec) { for (uid, weight) in weights.iter().enumerate() { assert_ok!(SubtensorModule::set_weights( RuntimeOrigin::signed(U256::from(uid as u64)), netuid, - vec![3, 4], + indices.clone(), weight.to_vec(), 0 )); @@ -3116,362 +3110,487 @@ fn set_yuma_3_weights(netuid: u16, weights: Vec>) { #[test] fn test_yuma_3_kappa_moves_first() { - new_test_ext(1).execute_with(|| { - let sparse: bool = true; - let n: u16 = 5; // 3 validators, 2 servers - let netuid: u16 = 1; - let max_stake: u64 = 8; - - // Validator A: kappa / Big validator (0.8) - moves first - // Validator B: Small eager validator (0.1) - moves second - // Validator C: Small lazy validator (0.1) - moves last - let stakes: Vec = vec![8, 1, 1, 0, 0]; - - setup_yuma_3_scenario(netuid, n, sparse, max_stake, stakes); - let targets_bonds = [ - vec![ - vec![0.1013, 0.0000], - vec![0.1013, 0.0000], - vec![0.1013, 0.0000], - ], - vec![ - vec![0.0908, 0.1013], - vec![0.3697, 0.0000], - vec![0.3697, 0.0000], - ], - vec![ - vec![0.0815, 0.1924], - vec![0.3170, 0.1013], - vec![0.5580, 0.0000], - ], - vec![ - vec![0.0731, 0.2742], - vec![0.2765, 0.1924], - vec![0.4306, 0.1013], - ], - vec![ - vec![0.0656, 0.3478], - vec![0.2435, 0.2742], - vec![0.3589, 0.1924], - ], - vec![ - vec![0.0588, 0.4139], - vec![0.2157, 0.3478], - vec![0.3089, 0.2742], - ], - ]; - - let targets_dividends = [ - vec![0.8000, 0.1000, 0.1000, 0.0000, 0.0000], - vec![1.0000, 0.0000, 0.0000, 0.0000, 0.0000], - vec![0.9382, 0.0618, 0.0000, 0.0000, 0.0000], - vec![0.8819, 0.0773, 0.0407, 0.0000, 0.0000], - vec![0.8564, 0.0844, 0.0592, 0.0000, 0.0000], - vec![0.8418, 0.0884, 0.0697, 0.0000, 0.0000], - ]; - - for (epoch, (target_bonds, target_dividends)) in targets_bonds - .iter() - .zip(targets_dividends.iter()) - .enumerate() - { - match epoch { - 0 => { - // Initially, consensus is achieved by all Validators - set_yuma_3_weights(netuid, vec![vec![u16::MAX, 0]; 3]); - } - 1 => { - // Validator A -> Server 2 - // Validator B -> Server 1 - // Validator C -> Server 1 - set_yuma_3_weights( - netuid, - vec![vec![0, u16::MAX], vec![u16::MAX, 0], vec![u16::MAX, 0]], - ); - } - 2 => { - // Validator A -> Server 2 - // Validator B -> Server 2 - // Validator C -> Server 1 - set_yuma_3_weights( - netuid, - vec![vec![0, u16::MAX], vec![0, u16::MAX], vec![u16::MAX, 0]], - ); - } - 3 => { - // Subsequent epochs All validators -> Server 2 - set_yuma_3_weights(netuid, vec![vec![0, u16::MAX]; 3]); - } - _ => {} - }; - run_epoch_and_check_bonds_dividends(netuid, sparse, target_bonds, target_dividends); - } - }) + for sparse in [true, false].iter() { + new_test_ext(1).execute_with(|| { + let n: u16 = 5; // 3 validators, 2 servers + let netuid: u16 = 1; + let max_stake: u64 = 8; + + // Validator A: kappa / Big validator (0.8) - moves first + // Validator B: Small eager validator (0.1) - moves second + // Validator C: Small lazy validator (0.1) - moves last + let stakes: Vec = vec![8, 1, 1, 0, 0]; + + setup_yuma_3_scenario(netuid, n, *sparse, max_stake, stakes); + let targets_bonds = [ + vec![ + vec![0.1013, 0.0000], + vec![0.1013, 0.0000], + vec![0.1013, 0.0000], + ], + vec![ + vec![0.0908, 0.1013], + vec![0.3697, 0.0000], + vec![0.3697, 0.0000], + ], + vec![ + vec![0.0815, 0.1924], + vec![0.3170, 0.1013], + vec![0.5580, 0.0000], + ], + vec![ + vec![0.0731, 0.2742], + vec![0.2765, 0.1924], + vec![0.4306, 0.1013], + ], + vec![ + vec![0.0656, 0.3478], + vec![0.2435, 0.2742], + vec![0.3589, 0.1924], + ], + vec![ + vec![0.0588, 0.4139], + vec![0.2157, 0.3478], + vec![0.3089, 0.2742], + ], + ]; + + let targets_dividends = [ + vec![0.8000, 0.1000, 0.1000, 0.0000, 0.0000], + vec![1.0000, 0.0000, 0.0000, 0.0000, 0.0000], + vec![0.9382, 0.0618, 0.0000, 0.0000, 0.0000], + vec![0.8819, 0.0773, 0.0407, 0.0000, 0.0000], + vec![0.8564, 0.0844, 0.0592, 0.0000, 0.0000], + vec![0.8418, 0.0884, 0.0697, 0.0000, 0.0000], + ]; + + for (epoch, (target_bonds, target_dividends)) in targets_bonds + .iter() + .zip(targets_dividends.iter()) + .enumerate() + { + match epoch { + 0 => { + // Initially, consensus is achieved by all Validators + set_yuma_3_weights(netuid, vec![vec![u16::MAX, 0]; 3], vec![3, 4]); + } + 1 => { + // Validator A -> Server 2 + // Validator B -> Server 1 + // Validator C -> Server 1 + set_yuma_3_weights( + netuid, + vec![vec![0, u16::MAX], vec![u16::MAX, 0], vec![u16::MAX, 0]], + vec![3, 4], + ); + } + 2 => { + // Validator A -> Server 2 + // Validator B -> Server 2 + // Validator C -> Server 1 + set_yuma_3_weights( + netuid, + vec![vec![0, u16::MAX], vec![0, u16::MAX], vec![u16::MAX, 0]], + vec![3, 4], + ); + } + 3 => { + // Subsequent epochs All validators -> Server 2 + set_yuma_3_weights(netuid, vec![vec![0, u16::MAX]; 3], vec![3, 4]); + } + _ => {} + }; + run_epoch_and_check_bonds_dividends(netuid, *sparse, target_bonds, target_dividends); + } + }) + } } #[test] fn test_yuma_3_kappa_moves_second() { - new_test_ext(1).execute_with(|| { - let sparse: bool = false; - let n: u16 = 5; // 3 validators, 2 servers - let netuid: u16 = 1; - let max_stake: u64 = 8; - - // Validator A: kappa / Big validator (0.8) - moves second - // Validator B: Small eager validator (0.1) - moves first - // Validator C: Small lazy validator (0.1) - moves last - let stakes: Vec = vec![8, 1, 1, 0, 0]; - - setup_yuma_3_scenario(netuid, n, sparse, max_stake, stakes); - let targets_bonds = [ - vec![ - vec![0.1013, 0.0000], - vec![0.1013, 0.0000], - vec![0.1013, 0.0000], - ], - vec![ - vec![0.1924, 0.0000], - vec![0.0908, 0.2987], - vec![0.1924, 0.0000], - ], - vec![ - vec![0.1715, 0.1013], - vec![0.0815, 0.3697], - vec![0.4336, 0.0000], - ], - vec![ - vec![0.1531, 0.1924], - vec![0.0731, 0.4336], - vec![0.3608, 0.1013], - ], - vec![ - vec![0.1369, 0.2742], - vec![0.0656, 0.4910], - vec![0.3103, 0.1924], - ], - vec![ - vec![0.1225, 0.3478], - vec![0.0588, 0.5426], - vec![0.2712, 0.2742], - ], - ]; - let targets_dividends = [ - vec![0.8000, 0.1000, 0.1000, 0.0000, 0.0000], - vec![0.8446, 0.0498, 0.1056, 0.0000, 0.0000], - vec![0.6868, 0.3132, 0.0000, 0.0000, 0.0000], - vec![0.7421, 0.2090, 0.0489, 0.0000, 0.0000], - vec![0.7625, 0.1706, 0.0669, 0.0000, 0.0000], - vec![0.7730, 0.1508, 0.0762, 0.0000, 0.0000], - ]; - - for (epoch, (target_bonds, target_dividends)) in targets_bonds - .iter() - .zip(targets_dividends.iter()) - .enumerate() - { - match epoch { - 0 => { - // Initially, consensus is achieved by all Validators - set_yuma_3_weights(netuid, vec![vec![u16::MAX, 0]; 3]); - } - 1 => { - // Validator A -> Server 1 - // Validator B -> Server 2 - // Validator C -> Server 1 - set_yuma_3_weights( - netuid, - vec![vec![u16::MAX, 0], vec![0, u16::MAX], vec![u16::MAX, 0]], - ); - } - 2 => { - // Validator A -> Server 2 - // Validator B -> Server 2 - // Validator C -> Server 1 - set_yuma_3_weights( - netuid, - vec![vec![0, u16::MAX], vec![0, u16::MAX], vec![u16::MAX, 0]], - ); - } - 3 => { - // Subsequent epochs All validators -> Server 2 - set_yuma_3_weights(netuid, vec![vec![0, u16::MAX]; 3]); - } - _ => {} - }; - run_epoch_and_check_bonds_dividends(netuid, sparse, target_bonds, target_dividends); - } - }) + for sparse in [true, false].iter() { + new_test_ext(1).execute_with(|| { + let n: u16 = 5; // 3 validators, 2 servers + let netuid: u16 = 1; + let max_stake: u64 = 8; + + // Validator A: kappa / Big validator (0.8) - moves second + // Validator B: Small eager validator (0.1) - moves first + // Validator C: Small lazy validator (0.1) - moves last + let stakes: Vec = vec![8, 1, 1, 0, 0]; + + setup_yuma_3_scenario(netuid, n, *sparse, max_stake, stakes); + let targets_bonds = [ + vec![ + vec![0.1013, 0.0000], + vec![0.1013, 0.0000], + vec![0.1013, 0.0000], + ], + vec![ + vec![0.1924, 0.0000], + vec![0.0908, 0.2987], + vec![0.1924, 0.0000], + ], + vec![ + vec![0.1715, 0.1013], + vec![0.0815, 0.3697], + vec![0.4336, 0.0000], + ], + vec![ + vec![0.1531, 0.1924], + vec![0.0731, 0.4336], + vec![0.3608, 0.1013], + ], + vec![ + vec![0.1369, 0.2742], + vec![0.0656, 0.4910], + vec![0.3103, 0.1924], + ], + vec![ + vec![0.1225, 0.3478], + vec![0.0588, 0.5426], + vec![0.2712, 0.2742], + ], + ]; + let targets_dividends = [ + vec![0.8000, 0.1000, 0.1000, 0.0000, 0.0000], + vec![0.8446, 0.0498, 0.1056, 0.0000, 0.0000], + vec![0.6868, 0.3132, 0.0000, 0.0000, 0.0000], + vec![0.7421, 0.2090, 0.0489, 0.0000, 0.0000], + vec![0.7625, 0.1706, 0.0669, 0.0000, 0.0000], + vec![0.7730, 0.1508, 0.0762, 0.0000, 0.0000], + ]; + + for (epoch, (target_bonds, target_dividends)) in targets_bonds + .iter() + .zip(targets_dividends.iter()) + .enumerate() + { + match epoch { + 0 => { + // Initially, consensus is achieved by all Validators + set_yuma_3_weights(netuid, vec![vec![u16::MAX, 0]; 3], vec![3, 4]); + } + 1 => { + // Validator A -> Server 1 + // Validator B -> Server 2 + // Validator C -> Server 1 + set_yuma_3_weights( + netuid, + vec![vec![u16::MAX, 0], vec![0, u16::MAX], vec![u16::MAX, 0]], + vec![3, 4], + ); + } + 2 => { + // Validator A -> Server 2 + // Validator B -> Server 2 + // Validator C -> Server 1 + set_yuma_3_weights( + netuid, + vec![vec![0, u16::MAX], vec![0, u16::MAX], vec![u16::MAX, 0]], + vec![3, 4], + ); + } + 3 => { + // Subsequent epochs All validators -> Server 2 + set_yuma_3_weights(netuid, vec![vec![0, u16::MAX]; 3], vec![3, 4]); + } + _ => {} + }; + run_epoch_and_check_bonds_dividends(netuid, *sparse, target_bonds, target_dividends); + } + }) + } } #[test] fn test_yuma_3_kappa_moves_last() { - new_test_ext(1).execute_with(|| { - let sparse: bool = true; - let n: u16 = 5; // 3 validators, 2 servers - let netuid: u16 = 1; - let max_stake: u64 = 8; - - // Validator A: kappa / Big validator (0.8) - moves last - // Validator B: Small eager validator (0.1) - moves first - // Validator C: Small lazy validator (0.1) - moves second - let stakes: Vec = vec![8, 1, 1, 0, 0]; - - setup_yuma_3_scenario(netuid, n, sparse, max_stake, stakes); - let targets_bonds = [ - vec![ - vec![0.1013, 0.0000], - vec![0.1013, 0.0000], - vec![0.1013, 0.0000], - ], - vec![ - vec![0.1924, 0.0000], - vec![0.0908, 0.2987], - vec![0.1924, 0.0000], - ], - vec![ - vec![0.2742, 0.0000], - vec![0.0815, 0.5081], - vec![0.1715, 0.2987], - ], - vec![ - vec![0.2416, 0.1013], - vec![0.0731, 0.5580], - vec![0.1531, 0.3697], - ], - vec![ - vec![0.2141, 0.1924], - vec![0.0656, 0.6028], - vec![0.1369, 0.4336], - ], - vec![ - vec![0.1903, 0.2742], - vec![0.0588, 0.6430], - vec![0.1225, 0.4910], - ], - ]; - let targets_dividends = [ - vec![0.8000, 0.1000, 0.1000, 0.0000, 0.0000], - vec![0.8446, 0.0498, 0.1056, 0.0000, 0.0000], - vec![0.8966, 0.0333, 0.0701, 0.0000, 0.0000], - vec![0.4663, 0.3210, 0.2127, 0.0000, 0.0000], - vec![0.5976, 0.2340, 0.1683, 0.0000, 0.0000], - vec![0.6592, 0.1932, 0.1475, 0.0000, 0.0000], - ]; - - for (epoch, (target_bonds, target_dividends)) in targets_bonds - .iter() - .zip(targets_dividends.iter()) - .enumerate() - { - match epoch { - 0 => { - // Initially, consensus is achieved by all Validators - set_yuma_3_weights(netuid, vec![vec![u16::MAX, 0]; 3]); - } - 1 => { - // Validator A -> Server 1 - // Validator B -> Server 2 - // Validator C -> Server 1 - set_yuma_3_weights( - netuid, - vec![vec![u16::MAX, 0], vec![0, u16::MAX], vec![u16::MAX, 0]], - ); - } - 2 => { - // Validator A -> Server 1 - // Validator B -> Server 2 - // Validator C -> Server 2 - set_yuma_3_weights( - netuid, - vec![vec![u16::MAX, 0], vec![0, u16::MAX], vec![0, u16::MAX]], - ); - } - 3 => { - // Subsequent epochs All validators -> Server 2 - set_yuma_3_weights(netuid, vec![vec![0, u16::MAX]; 3]); - } - _ => {} - }; - run_epoch_and_check_bonds_dividends(netuid, sparse, target_bonds, target_dividends); - } - }) + for sparse in [true, false].iter() { + new_test_ext(1).execute_with(|| { + let n: u16 = 5; // 3 validators, 2 servers + let netuid: u16 = 1; + let max_stake: u64 = 8; + + // Validator A: kappa / Big validator (0.8) - moves last + // Validator B: Small eager validator (0.1) - moves first + // Validator C: Small lazy validator (0.1) - moves second + let stakes: Vec = vec![8, 1, 1, 0, 0]; + + setup_yuma_3_scenario(netuid, n, *sparse, max_stake, stakes); + let targets_bonds = [ + vec![ + vec![0.1013, 0.0000], + vec![0.1013, 0.0000], + vec![0.1013, 0.0000], + ], + vec![ + vec![0.1924, 0.0000], + vec![0.0908, 0.2987], + vec![0.1924, 0.0000], + ], + vec![ + vec![0.2742, 0.0000], + vec![0.0815, 0.5081], + vec![0.1715, 0.2987], + ], + vec![ + vec![0.2416, 0.1013], + vec![0.0731, 0.5580], + vec![0.1531, 0.3697], + ], + vec![ + vec![0.2141, 0.1924], + vec![0.0656, 0.6028], + vec![0.1369, 0.4336], + ], + vec![ + vec![0.1903, 0.2742], + vec![0.0588, 0.6430], + vec![0.1225, 0.4910], + ], + ]; + let targets_dividends = [ + vec![0.8000, 0.1000, 0.1000, 0.0000, 0.0000], + vec![0.8446, 0.0498, 0.1056, 0.0000, 0.0000], + vec![0.8966, 0.0333, 0.0701, 0.0000, 0.0000], + vec![0.4663, 0.3210, 0.2127, 0.0000, 0.0000], + vec![0.5976, 0.2340, 0.1683, 0.0000, 0.0000], + vec![0.6592, 0.1932, 0.1475, 0.0000, 0.0000], + ]; + + for (epoch, (target_bonds, target_dividends)) in targets_bonds + .iter() + .zip(targets_dividends.iter()) + .enumerate() + { + match epoch { + 0 => { + // Initially, consensus is achieved by all Validators + set_yuma_3_weights(netuid, vec![vec![u16::MAX, 0]; 3], vec![3, 4]); + } + 1 => { + // Validator A -> Server 1 + // Validator B -> Server 2 + // Validator C -> Server 1 + set_yuma_3_weights( + netuid, + vec![vec![u16::MAX, 0], vec![0, u16::MAX], vec![u16::MAX, 0]], + vec![3, 4], + ); + } + 2 => { + // Validator A -> Server 1 + // Validator B -> Server 2 + // Validator C -> Server 2 + set_yuma_3_weights( + netuid, + vec![vec![u16::MAX, 0], vec![0, u16::MAX], vec![0, u16::MAX]], + vec![3, 4], + ); + } + 3 => { + // Subsequent epochs All validators -> Server 2 + set_yuma_3_weights(netuid, vec![vec![0, u16::MAX]; 3], vec![3, 4]); + } + _ => {} + }; + run_epoch_and_check_bonds_dividends(netuid, *sparse, target_bonds, target_dividends); + } + }) + } } #[test] fn test_yuma_3_one_epoch_switch() { - new_test_ext(1).execute_with(|| { - let sparse: bool = true; - let n: u16 = 5; // 3 validators, 2 servers - let netuid: u16 = 1; - let max_stake: u64 = 8; - - // Equal stake validators - let stakes: Vec = vec![33, 33, 34, 0, 0]; - - setup_yuma_3_scenario(netuid, n, sparse, max_stake, stakes); - - let targets_bonds = [ - vec![ - vec![0.1013, 0.0000], - vec![0.1013, 0.0000], - vec![0.1013, 0.0000], - ], - vec![ - vec![0.1924, 0.0000], - vec![0.1924, 0.0000], - vec![0.1924, 0.0000], - ], - vec![ - vec![0.2742, 0.0000], - vec![0.2742, 0.0000], - vec![0.1715, 0.2987], - ], - vec![ - vec![0.3478, 0.0000], - vec![0.3478, 0.0000], - vec![0.2554, 0.2618], - ], - vec![ - vec![0.4139, 0.0000], - vec![0.4139, 0.0000], - vec![0.3309, 0.2312], - ], - vec![ - vec![0.4733, 0.0000], - vec![0.4733, 0.0000], - vec![0.3987, 0.2051], - ], - ]; - let targets_dividends = [ - vec![0.3300, 0.3300, 0.3400, 0.0000, 0.0000], - vec![0.3300, 0.3300, 0.3400, 0.0000, 0.0000], - vec![0.3782, 0.3782, 0.2436, 0.0000, 0.0000], - vec![0.3628, 0.3628, 0.2745, 0.0000, 0.0000], - vec![0.3541, 0.3541, 0.2917, 0.0000, 0.0000], - vec![0.3487, 0.3487, 0.3026, 0.0000, 0.0000], - ]; - - for (epoch, (target_bonds, target_dividends)) in targets_bonds - .iter() - .zip(targets_dividends.iter()) - .enumerate() - { - match epoch { - 2 => { - // Validator A -> Server 1 - // Validator B -> Server 1 - // Validator C -> Server 2 - set_yuma_3_weights( - netuid, - vec![vec![u16::MAX, 0], vec![u16::MAX, 0], vec![0, u16::MAX]], - ); - } - _ => { - // All validators -> Server 1 - set_yuma_3_weights(netuid, vec![vec![u16::MAX, 0]; 3]); - } - }; - run_epoch_and_check_bonds_dividends(netuid, sparse, target_bonds, target_dividends); - } - }) + for sparse in [true, false].iter() { + new_test_ext(1).execute_with(|| { + let n: u16 = 5; // 3 validators, 2 servers + let netuid: u16 = 1; + let max_stake: u64 = 8; + + // Equal stake validators + let stakes: Vec = vec![33, 33, 34, 0, 0]; + + setup_yuma_3_scenario(netuid, n, *sparse, max_stake, stakes); + + let targets_bonds = [ + vec![ + vec![0.1013, 0.0000], + vec![0.1013, 0.0000], + vec![0.1013, 0.0000], + ], + vec![ + vec![0.1924, 0.0000], + vec![0.1924, 0.0000], + vec![0.1924, 0.0000], + ], + vec![ + vec![0.2742, 0.0000], + vec![0.2742, 0.0000], + vec![0.1715, 0.2987], + ], + vec![ + vec![0.3478, 0.0000], + vec![0.3478, 0.0000], + vec![0.2554, 0.2618], + ], + vec![ + vec![0.4139, 0.0000], + vec![0.4139, 0.0000], + vec![0.3309, 0.2312], + ], + vec![ + vec![0.4733, 0.0000], + vec![0.4733, 0.0000], + vec![0.3987, 0.2051], + ], + ]; + let targets_dividends = [ + vec![0.3300, 0.3300, 0.3400, 0.0000, 0.0000], + vec![0.3300, 0.3300, 0.3400, 0.0000, 0.0000], + vec![0.3782, 0.3782, 0.2436, 0.0000, 0.0000], + vec![0.3628, 0.3628, 0.2745, 0.0000, 0.0000], + vec![0.3541, 0.3541, 0.2917, 0.0000, 0.0000], + vec![0.3487, 0.3487, 0.3026, 0.0000, 0.0000], + ]; + + for (epoch, (target_bonds, target_dividends)) in targets_bonds + .iter() + .zip(targets_dividends.iter()) + .enumerate() + { + match epoch { + 2 => { + // Validator A -> Server 1 + // Validator B -> Server 1 + // Validator C -> Server 2 + set_yuma_3_weights( + netuid, + vec![vec![u16::MAX, 0], vec![u16::MAX, 0], vec![0, u16::MAX]], + vec![3, 4], + ); + } + _ => { + // All validators -> Server 1 + set_yuma_3_weights(netuid, vec![vec![u16::MAX, 0]; 3], vec![3, 4]); + } + }; + run_epoch_and_check_bonds_dividends(netuid, *sparse, target_bonds, target_dividends); + } + }) + } +} + +#[test] +fn test_yuma_3_stable_miner() { + for sparse in [true, false].iter() { + new_test_ext(1).execute_with(|| { + let netuid: u16 = 1; + let n: u16 = 6; // 3 validators, 3 servers + let max_stake: u64 = 8; + + // Validator A: kappa / Big validator (0.8) + // Validator B: Small eager validator (0.1) + // Validator C: Small lazy validator (0.1) + let stakes: Vec = vec![8, 1, 1, 0, 0, 0]; + + setup_yuma_3_scenario(netuid, n, *sparse, max_stake, stakes); + let targets_bonds = [ + vec![ + vec![0.0507, 0.0000, 0.0507], + vec![0.0507, 0.0000, 0.0507], + vec![0.0507, 0.0000, 0.0507], + ], + vec![ + vec![0.0962, 0.0000, 0.0962], + vec![0.0455, 0.1000, 0.0962], + vec![0.0962, 0.0000, 0.0962], + ], + vec![ + vec![0.0863, 0.0507, 0.1371], + vec![0.0408, 0.1405, 0.1371], + vec![0.1770, 0.0000, 0.1371], + ], + vec![ + vec![0.0774, 0.0962, 0.1739], + vec![0.0367, 0.1770, 0.1739], + vec![0.1579, 0.0507, 0.1739], + ], + vec![ + vec![0.0694, 0.1371, 0.2069], + vec![0.0329, 0.2097, 0.2069], + vec![0.1411, 0.0962, 0.2069], + ], + vec![ + vec![0.0623, 0.1739, 0.2366], + vec![0.0296, 0.2391, 0.2366], + vec![0.1263, 0.1371, 0.2366], + ], + ]; + let targets_dividends = [ + vec![0.8000, 0.1000, 0.1000, 0.0000, 0.0000, 0.0000], + vec![0.8226, 0.0745, 0.1028, 0.0000, 0.0000, 0.0000], + vec![0.7750, 0.1685, 0.0565, 0.0000, 0.0000, 0.0000], + vec![0.7864, 0.1372, 0.0764, 0.0000, 0.0000, 0.0000], + vec![0.7912, 0.1241, 0.0847, 0.0000, 0.0000, 0.0000], + vec![0.7937, 0.1173, 0.0890, 0.0000, 0.0000, 0.0000], + ]; + + for (epoch, (target_bonds, target_dividends)) in targets_bonds + .iter() + .zip(targets_dividends.iter()) + .enumerate() + { + match epoch { + 0 => { + // all validators 0.5 for first and third server + set_yuma_3_weights( + netuid, + vec![vec![u16::MAX / 2, 0, u16::MAX / 2]; 3], + vec![3, 4, 5], + ); + } + 1 => { + // one of small validators moves 0.5 to seconds server + set_yuma_3_weights( + netuid, + vec![ + vec![u16::MAX / 2, 0, u16::MAX / 2], + vec![0, u16::MAX / 2, u16::MAX / 2], + vec![u16::MAX / 2, 0, u16::MAX / 2], + ], + vec![3, 4, 5], + ); + } + 2 => { + // big validator follows + set_yuma_3_weights( + netuid, + vec![ + vec![0, u16::MAX / 2, u16::MAX / 2], + vec![0, u16::MAX / 2, u16::MAX / 2], + vec![u16::MAX / 2, 0, u16::MAX / 2], + ], + vec![3, 4, 5], + ); + } + 3 => { + // Subsequent epochs all validators have moves + set_yuma_3_weights( + netuid, + vec![vec![0, u16::MAX / 2, u16::MAX / 2]; 3], + vec![3, 4, 5], + ); + } + _ => {} + }; + run_epoch_and_check_bonds_dividends( + netuid, + *sparse, + target_bonds, + target_dividends, + ); + } + }) + } } From b5d766b1f8eb51969ba844ec7cf567caa5880ec8 Mon Sep 17 00:00:00 2001 From: Andreea Popescu Date: Tue, 25 Mar 2025 12:23:56 +0000 Subject: [PATCH 34/45] fix rebase --- pallets/subtensor/src/epoch/run_epoch.rs | 4 +-- pallets/subtensor/src/tests/epoch.rs | 34 +++++++++++++++++++----- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/pallets/subtensor/src/epoch/run_epoch.rs b/pallets/subtensor/src/epoch/run_epoch.rs index 0d8d123c9e..07df343997 100644 --- a/pallets/subtensor/src/epoch/run_epoch.rs +++ b/pallets/subtensor/src/epoch/run_epoch.rs @@ -68,7 +68,7 @@ impl Pallet { .iter() .map(|registered| last_tempo <= *registered) .collect(); - log::trace!("Recently registered:\n{:?}\n", &recently_registered); + log::trace!("Recently registered: {:?}", &recently_registered); // =========== // == Stake == @@ -199,7 +199,7 @@ impl Pallet { // Access network bonds. let mut bonds: Vec> = Self::get_bonds_fixed_proportion(netuid); - inplace_mask_matrix(&outdated, &mut bonds); // mask outdated bonds + inplace_mask_cols(&recently_registered, &mut bonds); // mask outdated bonds log::trace!("B: {:?}", &bonds); // Compute the Exponential Moving Average (EMA) of bonds. diff --git a/pallets/subtensor/src/tests/epoch.rs b/pallets/subtensor/src/tests/epoch.rs index 97d4fdf400..3eb7f441d8 100644 --- a/pallets/subtensor/src/tests/epoch.rs +++ b/pallets/subtensor/src/tests/epoch.rs @@ -3002,10 +3002,10 @@ pub fn assert_approx_eq(left: I32F32, right: I32F32, epsilon: I32F32) { } } -// test Yuma 4 scenarios over a sequence of epochs. +// test Yuma 3 scenarios over a sequence of epochs. fn setup_yuma_3_scenario(netuid: u16, n: u16, sparse: bool, max_stake: u64, stakes: Vec) { let block_number = System::block_number(); - let tempo: u16 = u16::MAX - 1; // high tempo to skip automatic epochs in on_initialize, use manual epochs instead + let tempo: u16 = 1; // high tempo to skip automatic epochs in on_initialize, use manual epochs instead add_network(netuid, tempo, 0); SubtensorModule::set_max_allowed_uids(netuid, n); @@ -3060,7 +3060,7 @@ fn setup_yuma_3_scenario(netuid: u16, n: u16, sparse: bool, max_stake: u64, stak } fn run_epoch(netuid: u16, sparse: bool) { - next_block(); + next_block_no_epoch(netuid); if sparse { SubtensorModule::epoch(netuid, 1_000_000_000); } else { @@ -3200,7 +3200,12 @@ fn test_yuma_3_kappa_moves_first() { } _ => {} }; - run_epoch_and_check_bonds_dividends(netuid, *sparse, target_bonds, target_dividends); + run_epoch_and_check_bonds_dividends( + netuid, + *sparse, + target_bonds, + target_dividends, + ); } }) } @@ -3297,7 +3302,12 @@ fn test_yuma_3_kappa_moves_second() { } _ => {} }; - run_epoch_and_check_bonds_dividends(netuid, *sparse, target_bonds, target_dividends); + run_epoch_and_check_bonds_dividends( + netuid, + *sparse, + target_bonds, + target_dividends, + ); } }) } @@ -3394,7 +3404,12 @@ fn test_yuma_3_kappa_moves_last() { } _ => {} }; - run_epoch_and_check_bonds_dividends(netuid, *sparse, target_bonds, target_dividends); + run_epoch_and_check_bonds_dividends( + netuid, + *sparse, + target_bonds, + target_dividends, + ); } }) } @@ -3475,7 +3490,12 @@ fn test_yuma_3_one_epoch_switch() { set_yuma_3_weights(netuid, vec![vec![u16::MAX, 0]; 3], vec![3, 4]); } }; - run_epoch_and_check_bonds_dividends(netuid, *sparse, target_bonds, target_dividends); + run_epoch_and_check_bonds_dividends( + netuid, + *sparse, + target_bonds, + target_dividends, + ); } }) } From 4cda7e27960533126145cb641ee056ba0e26ff4c Mon Sep 17 00:00:00 2001 From: Andreea Popescu Date: Tue, 25 Mar 2025 15:04:46 +0000 Subject: [PATCH 35/45] fix rebase tests --- pallets/subtensor/src/tests/epoch.rs | 350 +++++++++++---------------- 1 file changed, 146 insertions(+), 204 deletions(-) diff --git a/pallets/subtensor/src/tests/epoch.rs b/pallets/subtensor/src/tests/epoch.rs index 3eb7f441d8..9bb9f5a6e7 100644 --- a/pallets/subtensor/src/tests/epoch.rs +++ b/pallets/subtensor/src/tests/epoch.rs @@ -714,7 +714,7 @@ fn test_512_graph() { assert_eq!(SubtensorModule::get_dividends_for_uid(netuid, uid), 1023); // Note D = floor(1 / 64 * 65_535) = 1023 assert_eq!(SubtensorModule::get_emission_for_uid(netuid, uid), 7812500); // Note E = 0.5 / 200 * 1_000_000_000 = 7_812_500 assert_eq!(bonds[uid as usize][validator], 0.0); - assert_eq!(bonds[uid as usize][server], I32F32::from_num(276)); + assert_eq!(bonds[uid as usize][server], I32F32::from_num(102)); } for uid in servers { assert_eq!( @@ -1052,51 +1052,47 @@ fn test_bonds() { } else { SubtensorModule::epoch_dense(netuid, 1_000_000_000); } - /* n: 8 - current_block: 2 - activity_cutoff: 5000 - Last update: [2, 2, 2, 2, 1, 1, 1, 1] - Block at registration: [1, 1, 1, 1, 1, 1, 1, 1] - validator_permits: [true, true, true, true, true, true, true, true] - max_allowed_validators: 8 - new_validator_permits: [true, true, true, true, true, true, true, true] - Active Stake: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] - Weights: [[(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - Weights (permit): [[(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - Weights (permit+diag): [[(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - Weights (permit+diag+outdate): [[(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - Weights (mask+norm): [[(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] - Ranks (before): [0, 0, 0, 0, 0.099997558, 0.2000012202, 0.2999926745, 0.4000085443] - Consensus: [0, 0, 0, 0, 0.0999975584, 0.2000012207, 0.2999926754, 0.400008545] - Clipped Weights: [[(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] - Validator Trust: [0.9999999995, 0.9999999995, 0.9999999995, 0.9999999995, 0, 0, 0, 0] - Ranks (after): [0, 0, 0, 0, 0.099997558, 0.2000012202, 0.2999926745, 0.4000085443] - Trust: [0, 0, 0, 0, 1, 1, 1, 1] - Incentive (=Rank): [0, 0, 0, 0, 0.0999975582, 0.2000012207, 0.2999926752, 0.4000085455] - Bonds: [[], [], [], [], [], [], [], []] - Bonds: (mask+norm) [[], [], [], [], [], [], [], []] - weights_for_bonds: [[(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] - ΔB: - , 0.1999999997), (7, 0.1999999997)], [(4, 0.299999999), (5, 0.2999999998), (6, 0.3), (7, 0.3)], [(4, 0.4000000013), (5, 0.4), (6, 0.4000000004), (7, 0.4000000001)], [], [], [], []] - - emaB: [[(4, 0.0099999998), (5, 0.0099999998), (6, 0.0099999998), (7, 0.0099999998)], [(4, 0.0199999998), (5, 0.0199999998), (6, 0.0199999998), (7, 0.0199999998)], [(4, 0.0299999998), (5, 0.0299999998), (6, 0.03), (7, 0.03)], [(4, 0.04), (5, 0.0399999998), (6, 0.04), (7, 0.04)], [], [], [], []] - emaB norm: [[(4, 0.0999999982), (5, 0.0999999985), (6, 0.099999998), (7, 0.099999998)], [(4, 0.199999999), (5, 0.1999999995), (6, 0.1999999986), (7, 0.1999999986)], [(4, 0.2999999996), (5, 0.3000000003), (6, 0.3000000012), (7, 0.3000000012)], [(4, 0.4000000027), (5, 0.4000000013), (6, 0.4000000018), (7, 0.4000000018)], [], [], [], []] - total_bonds_per_validator: [0.0999999975, 0.1999999979, 0.3000000003, 0.4000000008, 0, 0, 0, 0] - Dividends: [0.0333333318, 0.1333333314, 0.3000000005, 0.5333333358, 0, 0, 0, 0] - Normalized Server Emission: [0, 0, 0, 0, 0.049998779, 0.1000006103, 0.1499963375, 0.2000042726] - Server Emission: [0, 0, 0, 0, 49998779, 100000610, 149996337, 200004272] - Normalized Validator Emission: [0.016666666, 0.0666666657, 0.1500000001, 0.266666668, 0, 0, 0, 0] - Validator Emission: [16666665, 66666665, 150000000, 266666668, 0, 0, 0, 0] - Normalized Combined Emission: [0.016666666, 0.0666666657, 0.1500000001, 0.266666668, 0.049998779, 0.1000006103, 0.1499963375, 0.2000042726] - Combined Emission: [16666665, 66666665, 150000000, 266666668, 49998779, 100000610, 149996337, 200004272] - Pruning Scores: [0.016666666, 0.0666666657, 0.1500000001, 0.266666668, 0.049998779, 0.1000006103, 0.1499963375, 0.2000042726] - */ + /* current_block: 2 + Block at registration: [1, 1, 1, 1, 1, 1, 1, 1] + Active Stake: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] + Weights: [[(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149 + ), (7, 65535)], [], [], [], []] + Weights (permit): [[(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), + (6, 49149), (7, 65535)], [], [], [], []] + Weights (mask+norm): [[(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584) + , (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] + Ranks (before): [0, 0, 0, 0, 0.099997558, 0.2000012202, 0.2999926745, 0.4000085443] + Consensus: [0, 0, 0, 0, 0.0999975584, 0.2000012207, 0.2999926754, 0.400008545] + Clipped Weights: [[(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5 + , 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] + Validator Trust: [0.9999999995, 0.9999999995, 0.9999999995, 0.9999999995, 0, 0, 0, 0] + Ranks (after): [0, 0, 0, 0, 0.099997558, 0.2000012202, 0.2999926745, 0.4000085443] + Trust: [0, 0, 0, 0, 1, 1, 1, 1] + Incentive (=Rank): [0, 0, 0, 0, 0.0999975582, 0.2000012207, 0.2999926752, 0.4000085455] + Bonds: [[], [], [], [], [], [], [], []] + Bonds: (mask) [[], [], [], [], [], [], [], []] + weights_for_bonds: [[(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), + (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] + ΔB: [[(4, 0.0999999996), (5, 0.0999999999), (6, 0.0999999994), (7, 0.0999999996)], [(4, 0.1999999995), (5, 0.2), (6, 0.1999999997), (7, 0.1999999997)], [(4, 0.299999999), (5, 0.2999999998), (6, + 0.3), (7, 0.3)], [(4, 0.4000000013), (5, 0.4), (6, 0.4000000004), (7, 0.4000000001)], [], [], [], []] + emaB: [[(4, 0.0099999998), (5, 0.0099999998), (6, 0.0099999998), (7, 0.0099999998)], [(4, 0.0199999998), (5, 0.0199999998), (6, 0.0199999998), (7, 0.0199999998)], [(4, 0.0299999998), (5, 0.0299999998), (6, 0.03), (7, 0.03)], [(4, 0.04), (5, 0.0399999998), (6, 0.04), (7, 0.04)], [], [], [], []] + emaB norm: [[(4, 0.0999999982), (5, 0.0999999985), (6, 0.099999998), (7, 0.099999998)], [(4, 0.199999999), (5, 0.1999999995), (6, 0.1999999986), (7, 0.1999999986)], [(4, 0.2999999996), (5, 0.3000000003), (6, 0.3000000012), (7, 0.3000000012)], [(4, 0.4000000027), (5, 0.4000000013), (6, 0.4000000018), (7, 0.4000000018)], [], [], [], []] + total_bonds_per_validator: [0.0999999975, 0.1999999979, 0.3000000003, 0.4000000008, 0, 0, 0, 0] + Dividends: [0.0333333318, 0.1333333314, 0.3000000005, 0.5333333358, 0, 0, 0, 0] + Normalized Server Emission: [0, 0, 0, 0, 0.049998779, 0.1000006103, 0.1499963375, 0.2000042726] + Server Emission: [0, 0, 0, 0, 49998779, 100000610, 149996337, 200004272] + Normalized Validator Emission: [0.016666666, 0.0666666657, 0.1500000001, 0.266666668, 0, 0, 0, 0] + Validator Emission: [16666665, 66666665, 150000000, 266666668, 0, 0, 0, 0] + Normalized Combined Emission: [0.016666666, 0.0666666657, 0.1500000001, 0.266666668, 0.049998779, 0.1000006103, 0.1499963375, 0.2000042726] + Combined Emission: [16666665, 66666665, 150000000, 266666668, 49998779, 100000610, 149996337, 200004272] + Pruning Scores: [0.016666666, 0.0666666657, 0.1500000001, 0.266666668, 0.049998779, 0.1000006103, 0.1499963375, 0.2000042726] + s: [[0, 0, 0, 0, 655, 655, 655, 655], [0, 0, 0, 0, 1310, 1310, 1310, 1310], [0, 0, 0, 0, 1966, 1966, 1966, 1966], [0, 0, 0, 0, 2621, 2621, 2621, 2621], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]] + */ let bonds = SubtensorModule::get_bonds(netuid); - assert_eq!(bonds[0][4], 655); - assert_eq!(bonds[1][4], 1310); - assert_eq!(bonds[2][4], 1966); - assert_eq!(bonds[3][4], 2621); + for (i, target_bond) in [655, 1310, 1966, 2621].iter().enumerate() { + assert_eq!(bonds[i][4], *target_bond); + } // === Set self-weight only on val1 let uid = 0; @@ -1113,21 +1109,12 @@ fn test_bonds() { } else { SubtensorModule::epoch_dense(netuid, 1_000_000_000); } - /* n: 8 - current_block: 3 - activity_cutoff: 5000 - Last update: [2, 2, 2, 2, 1, 1, 1, 1] + /* current_block: 3 Block at registration: [1, 1, 1, 1, 1, 1, 1, 1] - validator_permits: [true, true, true, true, true, true, true, true] - max_allowed_validators: 8 - new_validator_permits: [true, true, true, true, true, true, true, true] Active Stake: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] Weights: [[(0, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] Weights (permit): [[(0, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - Weights (permit+diag): [[], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - Weights (permit+diag+outdate): [[], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - Weights (mask+norm): [[], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0 - .400008545)], [], [], [], []] + Weights (mask+norm): [[], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] Ranks (before): [0, 0, 0, 0, 0.0899978022, 0.1800010982, 0.2699934072, 0.36000769] Consensus: [0, 0, 0, 0, 0.0999975584, 0.2000012207, 0.2999926754, 0.400008545] Clipped Weights: [[], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] @@ -1135,25 +1122,25 @@ fn test_bonds() { Ranks (after): [0, 0, 0, 0, 0.0899978022, 0.1800010982, 0.2699934072, 0.36000769] Trust: [0, 0, 0, 0, 1, 1, 1, 1] Incentive (=Rank): [0, 0, 0, 0, 0.0999975582, 0.2000012207, 0.2999926754, 0.4000085455] - Bonds: [[(4, 655), (5, 655), (6, 655), (7, 655)], [(4, 1310), (5, 1310), (6, 1310), (7, 1310)], [(4, 1966), (5, 1966), (6, 1966), (7, 1966)], [(4, 2621), (5, 2621), (6, 2621), (7, 2621)], [], [], [], []] - Bonds: (mask+norm) [[(4, 0.0099946593), (5, 0.0099946593), (6, 0.0099946593), (7, 0.0099946593)], [(4, 0.0199893187), (5, 0.0199893187), (6, 0.0199893187), (7, 0.0199893187)], [(4, 0.029999237), (5, 0.029999237), (6, 0.029999237), (7, 0.029999237)], [(4, 0.0399938964), (5, 0.0399938964), (6, 0.0399938964), (7, 0.0399938964)], [], [], [], []] + Bonds: [[(4, 0.0099946593), (5, 0.0099946593), (6, 0.0099946593), (7, 0.0099946593)], [(4, 0.0199893187), (5, 0.0199893187), (6, 0.0199893187), (7, 0.0199893187)], [(4, 0.029999237), (5, 0.029999237), (6, 0.029999237), (7, 0.029999237)], [(4, 0.0399938964), (5, 0.0399938964), (6, 0.0399938964), (7, 0.0399938964)], [], [], [], []] + Bonds: (mask) [[], [], [], [], [], [], [], []] weights_for_bonds: [[], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] - emaB: [[(4, 0.0089951933), (5, 0.0089951933), (6, 0.0089951933), (7, 0.0089951933)], [(4, 0.0402126086), (5, 0.0402126086), (6, 0.0402126086), (7, 0.0402126086)], [(4, 0.0603326464), (5, 0.0603326464), (6, 0.0603326464), (7, 0.0603326464)], [(4, 0.0804389513), (5, 0.080438951), (6, 0.080438951), (7, 0.080438951)], [], [], [], []] - emaB norm: [[(4, 0.0473482562), (5, 0.0473482562), (6, 0.0473482562), (7, 0.0473482562)], [(4, 0.2116682583), (5, 0.2116682585), (6, 0.2116682585), (7, 0.2116682585)], [(4, 0.3175746764), (5, 0.3175746768), (6, 0.3175746768), (7, 0.3175746768)], [(4, 0.4234088087), (5, 0.423408808), (6, 0.423408808), (7, 0.423408808)], [], [], [], []] - total_bonds_per_validator: [0.0473482558, 0.2116682578, 0.3175746764, 0.4234088075, 0, 0, 0, 0] - Dividends: [0.0151901136, 0.1358134532, 0.3056498466, 0.5433465862, 0, 0, 0, 0] + ΔB: [[], [(4, 0.2222222215), (5, 0.222222222), (6, 0.2222222218), (7, 0.2222222218)], [(4, 0.3333333323), (5, 0.3333333333), (6, 0.3333333333), (7, 0.3333333333)], [(4, 0.4444444457), (5, 0.4444444443), (6, 0.4444444447), (7, 0.4444444445)], [], [], [], []] + emaB: [[], [(4, 0.022222222), (5, 0.022222222), (6, 0.022222222), (7, 0.022222222)], [(4, 0.0333333332), (5, 0.0333333332), (6, 0.0333333332), (7, 0.0333333332)], [(4, 0.0444444446), (5, 0.0444444444), (6, 0.0444444444), (7, 0.0444444444)], [], [], [], []] + emaB norm: [[], [(4, 0.2222222209), (5, 0.2222222213), (6, 0.2222222213), (7, 0.2222222213)], [(4, 0.3333333323), (5, 0.3333333333), (6, 0.3333333333), (7, 0.3333333333)], [(4, 0.4444444464), (5, 0.4444444452), (6, 0.4444444452), (7, 0.4444444452)], [], [], [], []] + total_bonds_per_validator: [0, 0.2222222209, 0.3333333328, 0.444444445, 0, 0, 0, 0] + Dividends: [0, 0.1379310335, 0.310344827, 0.5517241391, 0, 0, 0, 0] Normalized Server Emission: [0, 0, 0, 0, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] Server Emission: [0, 0, 0, 0, 49998779, 100000610, 149996337, 200004272] - Normalized Validator Emission: [0.0075950567, 0.0679067266, 0.1528249232, 0.271673293, 0, 0, 0, 0] - Validator Emission: [7595056, 67906726, 152824923, 271673293, 0, 0, 0, 0] - Normalized Combined Emission: [0.0075950567, 0.0679067266, 0.1528249232, 0.271673293, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] - Combined Emission: [7595056, 67906726, 152824923, 271673293, 49998779, 100000610, 149996337, 200004272] - Pruning Scores: [0.0075950567, 0.0679067266, 0.1528249232, 0.271673293, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] + Normalized Validator Emission: [0, 0.0689655168, 0.1551724134, 0.2758620696, 0, 0, 0, 0] + Validator Emission: [0, 68965516, 155172413, 275862069, 0, 0, 0, 0] + Normalized Combined Emission: [0, 0.0689655168, 0.1551724134, 0.2758620696, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] + Combined Emission: [0, 68965516, 155172413, 275862069, 49998779, 100000610, 149996337, 200004272] + Pruning Scores: [0, 0.0689655168, 0.1551724134, 0.2758620696, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] */ - assert_eq!(bonds[0][4], 655); - assert_eq!(bonds[1][4], 1310); - assert_eq!(bonds[2][4], 1966); - assert_eq!(bonds[3][4], 2621); + for (i, target_bond) in [655, 1310, 1966, 2621].iter().enumerate() { + assert_eq!(bonds[i][4], *target_bond); + } // === Set self-weight only on val2 let uid = 1; @@ -1170,19 +1157,11 @@ fn test_bonds() { } else { SubtensorModule::epoch_dense(netuid, 1_000_000_000); } - /* n: 8 - current_block: 4 - activity_cutoff: 5000 - Last update: [2, 3, 2, 2, 1, 1, 1, 1] + /* current_block: 4 Block at registration: [1, 1, 1, 1, 1, 1, 1, 1] - validator_permits: [true, true, true, true, true, true, true, true] - max_allowed_validators: 8 - new_validator_permits: [true, true, true, true, true, true, true, true] Active Stake: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] Weights: [[(0, 65535)], [(1, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] Weights (permit): [[(0, 65535)], [(1, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - Weights (permit+diag): [[], [], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - Weights (permit+diag+outdate): [[], [], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] Weights (mask+norm): [[], [], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] Ranks (before): [0, 0, 0, 0, 0.0699982906, 0.1400008542, 0.2099948723, 0.2800059812] Consensus: [0, 0, 0, 0, 0.0999975584, 0.2000012207, 0.2999926754, 0.400008545] @@ -1191,26 +1170,26 @@ fn test_bonds() { Ranks (after): [0, 0, 0, 0, 0.0699982906, 0.1400008542, 0.2099948723, 0.2800059812] Trust: [0, 0, 0, 0, 1, 1, 1, 1] Incentive (=Rank): [0, 0, 0, 0, 0.0999975582, 0.2000012207, 0.2999926754, 0.4000085455] - Bonds: [[(4, 589), (5, 589), (6, 589), (7, 589)], [(4, 2635), (5, 2635), (6, 2635), (7, 2635)], [(4, 3953), (5, 3953), (6, 3953), (7, 3953)], [(4, 5271), (5, 5271), (6, 5271), (7, 5271)], [], [], [], []] - Bonds: (mask+norm) [[(4, 0.008987564), (5, 0.008987564), (6, 0.008987564), (7, 0.008987564)], [(4, 0.0402075227), (5, 0.0402075227), (6, 0.0402075227), (7, 0.0402075227)], [(4, 0.0603189135), (5, 0.0603189135), (6, 0.0603189135), (7, 0.0603189135)], [(4, 0.0804303044), (5, 0.0804303044), (6, 0.0804303044), (7, 0.0804303044)], [], [], [], []] + Bonds: [[], [(4, 0.0222171359), (5, 0.0222171359), (6, 0.0222171359), (7, 0.0222171359)], [(4, 0.0333257038), (5, 0.0333257038), (6, 0.0333257038), (7, 0.0333257038)], [(4, 0.0444342718), (5, 0.0444342718), (6, 0.0444342718), (7, 0.0444342718)], [], [], [], []] + Bonds: (mask) [[], [], [], [], [], [], [], []] weights_for_bonds: [[], [], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] - emaB: [[(4, 0.0080888073), (5, 0.0080888073), (6, 0.0080888073), (7, 0.0080888073)], [(4, 0.0361867703), (5, 0.0361867703), (6, 0.0361867703), (7, 0.0361867703)], [(4, 0.0971441646), (5, 0.0971441648), (6, 0.0971441648), (7, 0.0971441648)], [(4, 0.1295301311), (5, 0.129530131), (6, 0.129530131), (7, 0.129530131)], [], [], [], []] - emaB norm: [[(4, 0.0298535195), (5, 0.0298535195), (6, 0.0298535195), (7, 0.0298535195)], [(4, 0.1335552211), (5, 0.1335552211), (6, 0.1335552211), (7, 0.1335552211)], [(4, 0.3585318692), (5, 0.3585318702), (6, 0.3585318702), (7, 0.3585318702)], [(4, 0.4780593896), (5, 0.4780593887), (6, 0.4780593887), (7, 0.4780593887)], [], [], [], []] - total_bonds_per_validator: [0.0298535188, 0.1335552207, 0.3585318697, 0.4780593882, 0, 0, 0, 0] - Dividends: [0.0090883898, 0.08131718, 0.3274465878, 0.5821478418, 0, 0, 0, 0] + ΔB: [[], [], [(4, 0.428571427), (5, 0.4285714284), (6, 0.4285714284), (7, 0.4285714284)], [(4, 0.5714285728), (5, 0.5714285714), (6, 0.5714285714), (7, 0.5714285714)], [], [], [], []] + emaB: [[], [], [(4, 0.0428571426), (5, 0.0428571429), (6, 0.0428571429), (7, 0.0428571429)], [(4, 0.0571428572), (5, 0.057142857), (6, 0.057142857), (7, 0.057142857)], [], [], [], []] + emaB norm: [[], [], [(4, 0.4285714268), (5, 0.428571429), (6, 0.428571429), (7, 0.428571429)], [(4, 0.571428573), (5, 0.5714285707), (6, 0.5714285707), (7, 0.5714285707)], [], [], [], []] + total_bonds_per_validator: [0, 0, 0.4285714284, 0.5714285704, 0, 0, 0, 0] + Dividends: [0, 0, 0.36, 0.6399999997, 0, 0, 0, 0] Normalized Server Emission: [0, 0, 0, 0, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] Server Emission: [0, 0, 0, 0, 49998779, 100000610, 149996337, 200004272] - Normalized Validator Emission: [0.0045441948, 0.04065859, 0.163723294, 0.291073921, 0, 0, 0, 0] - Validator Emission: [4544194, 40658589, 163723293, 291073920, 0, 0, 0, 0] - Normalized Combined Emission: [0.0045441948, 0.04065859, 0.163723294, 0.291073921, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] - Combined Emission: [4544194, 40658589, 163723293, 291073920, 49998779, 100000610, 149996337, 200004272] - Pruning Scores: [0.0045441948, 0.04065859, 0.163723294, 0.291073921, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] + Normalized Validator Emission: [0, 0, 0.18, 0.3199999998, 0, 0, 0, 0] + Validator Emission: [0, 0, 179999999, 319999999, 0, 0, 0, 0] + Normalized Combined Emission: [0, 0, 0.18, 0.3199999998, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] + Combined Emission: [0, 0, 179999999, 319999999, 49998779, 100000610, 149996337, 200004272] + Pruning Scores: [0, 0, 0.18, 0.3199999998, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] */ let bonds = SubtensorModule::get_bonds(netuid); - assert_eq!(bonds[0][4], 530); - assert_eq!(bonds[1][4], 2371); - assert_eq!(bonds[2][4], 6366); - assert_eq!(bonds[3][4], 8488); + for (i, target_bond) in [0, 0, 2808, 3744].iter().enumerate() { + assert_eq!(bonds[i][4], *target_bond); + } // === Set self-weight only on val2 let uid = 1; @@ -1227,19 +1206,11 @@ fn test_bonds() { } else { SubtensorModule::epoch_dense(netuid, 1_000_000_000); } - /* n: 8 - current_block: 5 - activity_cutoff: 5000 - Last update: [2, 4, 2, 2, 1, 1, 1, 1] + /* current_block: 5 Block at registration: [1, 1, 1, 1, 1, 1, 1, 1] - validator_permits: [true, true, true, true, true, true, true, true] - max_allowed_validators: 8 - new_validator_permits: [true, true, true, true, true, true, true, true] Active Stake: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] Weights: [[(0, 65535)], [(1, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] Weights (permit): [[(0, 65535)], [(1, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - Weights (permit+diag): [[], [], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - Weights (permit+diag+outdate): [[], [], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] Weights (mask+norm): [[], [], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] Ranks (before): [0, 0, 0, 0, 0.0699982906, 0.1400008542, 0.2099948723, 0.2800059812] Consensus: [0, 0, 0, 0, 0.0999975584, 0.2000012207, 0.2999926754, 0.400008545] @@ -1248,26 +1219,26 @@ fn test_bonds() { Ranks (after): [0, 0, 0, 0, 0.0699982906, 0.1400008542, 0.2099948723, 0.2800059812] Trust: [0, 0, 0, 0, 1, 1, 1, 1] Incentive (=Rank): [0, 0, 0, 0, 0.0999975582, 0.2000012207, 0.2999926754, 0.4000085455] - Bonds: [[(4, 530), (5, 530), (6, 530), (7, 530)], [(4, 2371), (5, 2371), (6, 2371), (7, 2371)], [(4, 6366), (5, 6366), (6, 6366), (7, 6366)], [(4, 8488), (5, 8488), (6, 8488), (7, 8488)], [], [], [], []] - Bonds: (mask+norm) [[(4, 0.0080872816), (5, 0.0080872816), (6, 0.0080872816), (7, 0.0080872816)], [(4, 0.036179141), (5, 0.036179141), (6, 0.036179141), (7, 0.036179141)], [(4, 0.0971389334), (5, 0.0971389334), (6, 0.0971389334), (7, 0.0971389334)], [(4, 0.1295185778), (5, 0.1295185778), (6, 0.1295185778), (7, 0.1295185778)], [], [], [], []] + Bonds: [[], [], [(4, 0.0428473335), (5, 0.0428473335), (6, 0.0428473335), (7, 0.0428473335)], [(4, 0.057129778), (5, 0.057129778), (6, 0.057129778), (7, 0.057129778)], [], [], [], []] + Bonds: (mask) [[], [], [], [], [], [], [], []] weights_for_bonds: [[], [], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] - emaB: [[(4, 0.0072785532), (5, 0.0072785532), (6, 0.0072785532), (7, 0.0072785532)], [(4, 0.0325612267), (5, 0.0325612267), (6, 0.0325612267), (7, 0.0325612267)], [(4, 0.1302821825), (5, 0.1302821827), (6, 0.1302821827), (7, 0.1302821827)], [(4, 0.1737095772), (5, 0.173709577), (6, 0.173709577), (7, 0.173709577)], [], [], [], []] - emaB norm: [[(4, 0.0211689514), (5, 0.0211689514), (6, 0.0211689514), (7, 0.0211689514)], [(4, 0.094701105), (5, 0.094701105), (6, 0.094701105), (7, 0.094701105)], [(4, 0.3789128321), (5, 0.3789128328), (6, 0.3789128328), (7, 0.3789128328)], [(4, 0.505217111), (5, 0.5052171105), (6, 0.5052171105), (7, 0.5052171105)], [], [], [], []] - total_bonds_per_validator: [0.021168951, 0.0947011046, 0.3789128324, 0.50521711, 0, 0, 0, 0] - Dividends: [0.0062849855, 0.0562328366, 0.3374935838, 0.599988594, 0, 0, 0, 0] + ΔB: [[], [], [(4, 0.428571427), (5, 0.4285714284), (6, 0.4285714284), (7, 0.4285714284)], [(4, 0.5714285728), (5, 0.5714285714), (6, 0.5714285714), (7, 0.5714285714)], [], [], [], []] + emaB: [[], [], [(4, 0.0428571426), (5, 0.0428571429), (6, 0.0428571429), (7, 0.0428571429)], [(4, 0.0571428572), (5, 0.057142857), (6, 0.057142857), (7, 0.057142857)], [], [], [], []] + emaB norm: [[], [], [(4, 0.4285714268), (5, 0.428571429), (6, 0.428571429), (7, 0.428571429)], [(4, 0.571428573), (5, 0.5714285707), (6, 0.5714285707), (7, 0.5714285707)], [], [], [], []] + total_bonds_per_validator: [0, 0, 0.4285714284, 0.5714285704, 0, 0, 0, 0] + Dividends: [0, 0, 0.36, 0.6399999997, 0, 0, 0, 0] Normalized Server Emission: [0, 0, 0, 0, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] Server Emission: [0, 0, 0, 0, 49998779, 100000610, 149996337, 200004272] - Normalized Validator Emission: [0.0031424926, 0.0281164183, 0.1687467918, 0.2999942969, 0, 0, 0, 0] - Validator Emission: [3142492, 28116418, 168746791, 299994296, 0, 0, 0, 0] - Normalized Combined Emission: [0.0031424926, 0.0281164183, 0.1687467918, 0.2999942969, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] - Combined Emission: [3142492, 28116418, 168746791, 299994296, 49998779, 100000610, 149996337, 200004272] - Pruning Scores: [0.0031424926, 0.0281164183, 0.1687467918, 0.2999942969, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] + Normalized Validator Emission: [0, 0, 0.18, 0.3199999998, 0, 0, 0, 0] + Validator Emission: [0, 0, 179999999, 319999999, 0, 0, 0, 0] + Normalized Combined Emission: [0, 0, 0.18, 0.3199999998, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] + Combined Emission: [0, 0, 179999999, 319999999, 49998779, 100000610, 149996337, 200004272] + Pruning Scores: [0, 0, 0.18, 0.3199999998, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] */ let bonds = SubtensorModule::get_bonds(netuid); - assert_eq!(bonds[0][7], 476); - assert_eq!(bonds[1][7], 2133); - assert_eq!(bonds[2][7], 8538); - assert_eq!(bonds[3][7], 11384); + for (i, target_bond) in [0, 0, 2808, 3744].iter().enumerate() { + assert_eq!(bonds[i][7], *target_bond); + } // === Set val3->srv4: 1 assert_ok!(SubtensorModule::set_weights( @@ -1283,19 +1254,11 @@ fn test_bonds() { } else { SubtensorModule::epoch_dense(netuid, 1_000_000_000); } - /* n: 8 - current_block: 6 - activity_cutoff: 5000 - Last update: [2, 4, 5, 2, 1, 1, 1, 1] + /* current_block: 6 Block at registration: [1, 1, 1, 1, 1, 1, 1, 1] - validator_permits: [true, true, true, true, true, true, true, true] - max_allowed_validators: 8 - new_validator_permits: [true, true, true, true, true, true, true, true] Active Stake: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] Weights: [[(0, 65535)], [(1, 65535)], [(7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] Weights (permit): [[(0, 65535)], [(1, 65535)], [(7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - Weights (permit+diag): [[], [], [(7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - Weights (permit+diag+outdate): [[], [], [(7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] Weights (mask+norm): [[], [], [(7, 1)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] Ranks (before): [0, 0, 0, 0, 0.0399990233, 0.080000488, 0.11999707, 0.4600034177] Consensus: [0, 0, 0, 0, 0, 0, 0, 0.400008545] @@ -1304,47 +1267,38 @@ fn test_bonds() { Ranks (after): [0, 0, 0, 0, 0, 0, 0, 0.2800059812] Trust: [0, 0, 0, 0, 0, 0, 0, 0.6087041323] Incentive (=Rank): [0, 0, 0, 0, 0, 0, 0, 1] - Bonds: [[(4, 476), (5, 476), (6, 476), (7, 476)], [(4, 2133), (5, 2133), (6, 2133), (7, 2133)], [(4, 8538), (5, 8538), (6, 8538), (7, 8538)], [(4, 11384), (5, 11384), (6, 11384), (7, 11384)], [], [], [], []] - Bonds: (mask+norm) [[(4, 0.0072632944), (5, 0.0072632944), (6, 0.0072632944), (7, 0.0072632944)], [(4, 0.0325474937), (5, 0.0325474937), (6, 0.0325474937), (7, 0.0325474937)], [(4, 0.130281529), (5, 0.130281529), (6, 0.130281529), (7, 0.130281529)], [(4, 0.1737087052), (5, 0.1737087052), (6, 0.1737087052), (7, 0.1737087052)], [], [], [], []] + Bonds: [[], [], [(4, 0.0428473335), (5, 0.0428473335), (6, 0.0428473335), (7, 0.0428473335)], [(4, 0.057129778), (5, 0.057129778), (6, 0.057129778), (7, 0.057129778)], [], [], [], []] + Bonds: (mask) [[], [], [], [], [], [], [], []] weights_for_bonds: [[], [], [(7, 0.400008545)], [(7, 0.400008545)], [], [], [], []] - emaB: [[(4, 0.0065369648), (5, 0.0065369648), (6, 0.0065369648), (7, 0.0065369648)], [(4, 0.0292927441), (5, 0.0292927441), (6, 0.0292927441), (7, 0.0292927441)], [(4, 0.117253376), (5, 0.117253376), (6, 0.117253376), (7, 0.1601105188)], [(4, 0.1563378347), (5, 0.1563378347), (6, 0.1563378347), (7, 0.2134806917)], [], [], [], []] - emaB norm: [[(4, 0.0211264472), (5, 0.0211264472), (6, 0.0211264472), (7, 0.0159663672)], [(4, 0.0946695658), (5, 0.0946695658), (6, 0.0946695658), (7, 0.0715467692)], [(4, 0.3789445655), (5, 0.3789445655), (6, 0.3789445655), (7, 0.3910657985)], [(4, 0.505259421), (5, 0.505259421), (6, 0.505259421), (7, 0.5214210646)], [], [], [], []] - total_bonds_per_validator: [0.0159663672, 0.0715467692, 0.3910657985, 0.5214210646, 0, 0, 0, 0] - Dividends: [0.0046713396, 0.0418654135, 0.3432467687, 0.610216478, 0, 0, 0, 0] + ΔB: [[], [], [(7, 0.4285714284)], [(7, 0.5714285714)], [], [], [], []] + emaB: [[], [], [(7, 0.0428571429)], [(7, 0.057142857)], [], [], [], []] + emaB norm: [[], [], [(7, 0.428571429)], [(7, 0.5714285707)], [], [], [], []] + total_bonds_per_validator: [0, 0, 0.428571429, 0.5714285707, 0, 0, 0, 0] + Dividends: [0, 0, 0.3600000006, 0.6399999992, 0, 0, 0, 0] Normalized Server Emission: [0, 0, 0, 0, 0, 0, 0, 0.5] Server Emission: [0, 0, 0, 0, 0, 0, 0, 500000000] - Normalized Validator Emission: [0.0023356697, 0.0209327068, 0.1716233843, 0.305108239, 0, 0, 0, 0] - Validator Emission: [2335669, 20932706, 171623384, 305108238, 0, 0, 0, 0] - Normalized Combined Emission: [0.0023356697, 0.0209327068, 0.1716233843, 0.305108239, 0, 0, 0, 0.5] - Combined Emission: [2335669, 20932706, 171623384, 305108238, 0, 0, 0, 500000000] - Pruning Scores: [0.0023356697, 0.0209327068, 0.1716233843, 0.305108239, 0, 0, 0, 0.5] - + Normalized Validator Emission: [0, 0, 0.1800000002, 0.3199999996, 0, 0, 0, 0] + Validator Emission: [0, 0, 180000000, 319999999, 0, 0, 0, 0] + Normalized Combined Emission: [0, 0, 0.1800000002, 0.3199999996, 0, 0, 0, 0.5] + Combined Emission: [0, 0, 180000000, 319999999, 0, 0, 0, 500000000] + Pruning Scores: [0, 0, 0.1800000002, 0.3199999996, 0, 0, 0, 0.5] */ let bonds = SubtensorModule::get_bonds(netuid); - assert_eq!(bonds[0][7], 428); - assert_eq!(bonds[1][7], 1919); - assert_eq!(bonds[2][7], 10492); - assert_eq!(bonds[3][7], 13990); + for (i, target_bond) in [0, 0, 2808, 3744].iter().enumerate() { + assert_eq!(bonds[i][7], *target_bond); + } next_block(); if sparse { SubtensorModule::epoch(netuid, 1_000_000_000); } else { SubtensorModule::epoch_dense(netuid, 1_000_000_000); } - /* n: 8 - current_block: 7 - activity_cutoff: 5000 - Last update: [2, 4, 5, 2, 1, 1, 1, 1] + /* current_block: 7 Block at registration: [1, 1, 1, 1, 1, 1, 1, 1] - validator_permits: [true, true, true, true, true, true, true, true] - max_allowed_validators: 8 - new_validator_permits: [true, true, true, true, true, true, true, true] Active Stake: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] Weights: [[(0, 65535)], [(1, 65535)], [(7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] Weights (permit): [[(0, 65535)], [(1, 65535)], [(7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - Weights (permit+diag): [[], [], [(7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - Weights (permit+diag+outdate): [[], [], [(7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] Weights (mask+norm): [[], [], [(7, 1)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] Ranks (before): [0, 0, 0, 0, 0.0399990233, 0.080000488, 0.11999707, 0.4600034177] Consensus: [0, 0, 0, 0, 0, 0, 0, 0.400008545] @@ -1353,26 +1307,26 @@ fn test_bonds() { Ranks (after): [0, 0, 0, 0, 0, 0, 0, 0.2800059812] Trust: [0, 0, 0, 0, 0, 0, 0, 0.6087041323] Incentive (=Rank): [0, 0, 0, 0, 0, 0, 0, 1] - Bonds: [[(4, 428), (5, 428), (6, 428), (7, 428)], [(4, 1919), (5, 1919), (6, 1919), (7, 1919)], [(4, 7684), (5, 7684), (6, 7684), (7, 10492)], [(4, 10245), (5, 10245), (6, 10245), (7, 13990)], [], [], [], []] - Bonds: (mask+norm) [[(4, 0.0065308614), (5, 0.0065308614), (6, 0.0065308614), (7, 0.0065308614)], [(4, 0.029282063), (5, 0.029282063), (6, 0.029282063), (7, 0.029282063)], [(4, 0.1172503242), (5, 0.1172503242), (6, 0.1172503242), (7, 0.1600976577)], [(4, 0.1563286793), (5, 0.1563286793), (6, 0.1563286793), (7, 0.2134737163)], [], [], [], []] + Bonds: [[], [], [(7, 0.0428473335)], [(7, 0.057129778)], [], [], [], []] + Bonds: (mask) [[], [], [], [], [], [], [], []] weights_for_bonds: [[], [], [(7, 0.400008545)], [(7, 0.400008545)], [], [], [], []] - emaB: [[(4, 0.0058777751), (5, 0.0058777751), (6, 0.0058777751), (7, 0.0058777751)], [(4, 0.0263538565), (5, 0.0263538565), (6, 0.0263538565), (7, 0.0263538565)], [(4, 0.1055252918), (5, 0.1055252918), (6, 0.1055252918), (7, 0.1869450347)], [(4, 0.1406958112), (5, 0.1406958112), (6, 0.1406958112), (7, 0.2492692014)], [], [], [], []] - emaB norm: [[(4, 0.0211086995), (5, 0.0211086995), (6, 0.0211086995), (7, 0.0125473945)], [(4, 0.0946439134), (5, 0.0946439134), (6, 0.0946439134), (7, 0.0562580617)], [(4, 0.3789702114), (5, 0.3789702114), (6, 0.3789702114), (7, 0.3990749998)], [(4, 0.5052771752), (5, 0.5052771752), (6, 0.5052771752), (7, 0.5321195435)], [], [], [], []] - total_bonds_per_validator: [0.0125473945, 0.0562580617, 0.3990749998, 0.5321195435, 0, 0, 0, 0] - Dividends: [0.003636117, 0.0326061223, 0.3469446378, 0.6168131223, 0, 0, 0, 0] + ΔB: [[], [], [(7, 0.4285714284)], [(7, 0.5714285714)], [], [], [], []] + emaB: [[], [], [(7, 0.0428571429)], [(7, 0.057142857)], [], [], [], []] + emaB norm: [[], [], [(7, 0.428571429)], [(7, 0.5714285707)], [], [], [], []] + total_bonds_per_validator: [0, 0, 0.428571429, 0.5714285707, 0, 0, 0, 0] + Dividends: [0, 0, 0.3600000006, 0.6399999992, 0, 0, 0, 0] Normalized Server Emission: [0, 0, 0, 0, 0, 0, 0, 0.5] Server Emission: [0, 0, 0, 0, 0, 0, 0, 500000000] - Normalized Validator Emission: [0.0018180585, 0.016303061, 0.1734723188, 0.3084065611, 0, 0, 0, 0] - Validator Emission: [1818058, 16303061, 173472318, 308406561, 0, 0, 0, 0] - Normalized Combined Emission: [0.0018180585, 0.016303061, 0.1734723188, 0.3084065611, 0, 0, 0, 0.5] - Combined Emission: [1818058, 16303061, 173472318, 308406561, 0, 0, 0, 500000000] - Pruning Scores: [0.0018180585, 0.016303061, 0.1734723188, 0.3084065611, 0, 0, 0, 0.5] + Normalized Validator Emission: [0, 0, 0.1800000002, 0.3199999996, 0, 0, 0, 0] + Validator Emission: [0, 0, 180000000, 319999999, 0, 0, 0, 0] + Normalized Combined Emission: [0, 0, 0.1800000002, 0.3199999996, 0, 0, 0, 0.5] + Combined Emission: [0, 0, 180000000, 319999999, 0, 0, 0, 500000000] + Pruning Scores: [0, 0, 0.1800000002, 0.3199999996, 0, 0, 0, 0.5] */ let bonds = SubtensorModule::get_bonds(netuid); - assert_eq!(bonds[0][7], 385); - assert_eq!(bonds[1][7], 1727); - assert_eq!(bonds[2][7], 12251); - assert_eq!(bonds[3][7], 16335); + for (i, target_bond) in [0, 0, 2808, 3744].iter().enumerate() { + assert_eq!(bonds[i][7], *target_bond); + } next_block(); if sparse { @@ -1380,19 +1334,11 @@ fn test_bonds() { } else { SubtensorModule::epoch_dense(netuid, 1_000_000_000); } - /* n: 8 - current_block: 8 - activity_cutoff: 5000 - Last update: [2, 4, 5, 2, 1, 1, 1, 1] + /* current_block: 8 Block at registration: [1, 1, 1, 1, 1, 1, 1, 1] - validator_permits: [true, true, true, true, true, true, true, true] - max_allowed_validators: 8 - new_validator_permits: [true, true, true, true, true, true, true, true] Active Stake: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] Weights: [[(0, 65535)], [(1, 65535)], [(7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] Weights (permit): [[(0, 65535)], [(1, 65535)], [(7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - Weights (permit+diag): [[], [], [(7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - Weights (permit+diag+outdate): [[], [], [(7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] Weights (mask+norm): [[], [], [(7, 1)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] Ranks (before): [0, 0, 0, 0, 0.0399990233, 0.080000488, 0.11999707, 0.4600034177] Consensus: [0, 0, 0, 0, 0, 0, 0, 0.400008545] @@ -1401,26 +1347,26 @@ fn test_bonds() { Ranks (after): [0, 0, 0, 0, 0, 0, 0, 0.2800059812] Trust: [0, 0, 0, 0, 0, 0, 0, 0.6087041323] Incentive (=Rank): [0, 0, 0, 0, 0, 0, 0, 1] - Bonds: [[(4, 385), (5, 385), (6, 385), (7, 385)], [(4, 1727), (5, 1727), (6, 1727), (7, 1727)], [(4, 6915), (5, 6915), (6, 6915), (7, 12251)], [(4, 9220), (5, 9220), (6, 9220), (7, 16335)], [], [], [], []] - Bonds: (mask+norm) [[(4, 0.0058747234), (5, 0.0058747234), (6, 0.0058747234), (7, 0.0058747234)], [(4, 0.0263523308), (5, 0.0263523308), (6, 0.0263523308), (7, 0.0263523308)], [(4, 0.1055161364), (5, 0.1055161364), (6, 0.1055161364), (7, 0.1869382772)], [(4, 0.1406881819), (5, 0.1406881819), (6, 0.1406881819), (7, 0.2492561226)], [], [], [], []] + Bonds: [[], [], [(7, 0.0428473335)], [(7, 0.057129778)], [], [], [], []] + Bonds: (mask) [[], [], [], [], [], [], [], []] weights_for_bonds: [[], [], [(7, 0.400008545)], [(7, 0.400008545)], [], [], [], []] - emaB: [[(4, 0.005287251), (5, 0.005287251), (6, 0.005287251), (7, 0.005287251)], [(4, 0.0237170977), (5, 0.0237170977), (6, 0.0237170977), (7, 0.0237170977)], [(4, 0.0949645226), (5, 0.0949645226), (6, 0.0949645226), (7, 0.2111015923)], [(4, 0.1266193634), (5, 0.1266193634), (6, 0.1266193634), (7, 0.2814733672)], [], [], [], []] - emaB norm: [[(4, 0.0210993583), (5, 0.0210993583), (6, 0.0210993583), (7, 0.010137003)], [(4, 0.094645695), (5, 0.094645695), (6, 0.094645695), (7, 0.0454716997)], [(4, 0.3789664055), (5, 0.3789664055), (6, 0.3789664055), (7, 0.404735366)], [(4, 0.5052885406), (5, 0.5052885406), (6, 0.5052885406), (7, 0.539655931)], [], [], [], []] - total_bonds_per_validator: [0.010137003, 0.0454716997, 0.404735366, 0.539655931, 0, 0, 0, 0] - Dividends: [0.0029180378, 0.0261789719, 0.3495214381, 0.621381552, 0, 0, 0, 0] + ΔB: [[], [], [(7, 0.4285714284)], [(7, 0.5714285714)], [], [], [], []] + emaB: [[], [], [(7, 0.0428571429)], [(7, 0.057142857)], [], [], [], []] + emaB norm: [[], [], [(7, 0.428571429)], [(7, 0.5714285707)], [], [], [], []] + total_bonds_per_validator: [0, 0, 0.428571429, 0.5714285707, 0, 0, 0, 0] + Dividends: [0, 0, 0.3600000006, 0.6399999992, 0, 0, 0, 0] Normalized Server Emission: [0, 0, 0, 0, 0, 0, 0, 0.5] Server Emission: [0, 0, 0, 0, 0, 0, 0, 500000000] - Normalized Validator Emission: [0.0014590188, 0.013089486, 0.174760719, 0.310690776, 0, 0, 0, 0] - Validator Emission: [1459018, 13089485, 174760719, 310690775, 0, 0, 0, 0] - Normalized Combined Emission: [0.0014590188, 0.013089486, 0.174760719, 0.310690776, 0, 0, 0, 0.5] - Combined Emission: [1459018, 13089485, 174760719, 310690775, 0, 0, 0, 500000000] - Pruning Scores: [0.0014590188, 0.013089486, 0.174760719, 0.310690776, 0, 0, 0, 0.5] + Normalized Validator Emission: [0, 0, 0.1800000002, 0.3199999996, 0, 0, 0, 0] + Validator Emission: [0, 0, 180000000, 319999999, 0, 0, 0, 0] + Normalized Combined Emission: [0, 0, 0.1800000002, 0.3199999996, 0, 0, 0, 0.5] + Combined Emission: [0, 0, 180000000, 319999999, 0, 0, 0, 500000000] + Pruning Scores: [0, 0, 0.1800000002, 0.3199999996, 0, 0, 0, 0.5] */ let bonds = SubtensorModule::get_bonds(netuid); - assert_eq!(bonds[0][7], 346); - assert_eq!(bonds[1][7], 1554); - assert_eq!(bonds[2][7], 13834); - assert_eq!(bonds[3][7], 18446); + for (i, target_bond) in [0, 0, 2808, 3744].iter().enumerate() { + assert_eq!(bonds[i][7], *target_bond); + } next_block(); if sparse { @@ -1542,11 +1488,9 @@ fn test_bonds_with_liquid_alpha() { Pruning Scores: [0, 0.111111111, 0.1666666665, 0.2222222222, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] */ - - assert_eq!(bonds[0][4], 4596); // Note: Calculated as explained above - assert_eq!(bonds[1][4], 4596); // Note: Calculated as explained above - assert_eq!(bonds[2][4], 4596); // Note: Calculated as explained above - assert_eq!(bonds[3][4], 4596); // Note: Calculated as explained above + for (i, target_bond) in [4596, 4596, 4596, 4596].iter().enumerate() { + assert_eq!(bonds[i][4], *target_bond); + } // === Set self-weight only on val1 let uid = 0; @@ -1565,10 +1509,9 @@ fn test_bonds_with_liquid_alpha() { } let bonds = SubtensorModule::get_bonds(netuid); - assert_eq!(bonds[0][4], 0); - assert_eq!(bonds[1][4], 5968); - assert_eq!(bonds[2][4], 5968); - assert_eq!(bonds[3][4], 5968); + for (i, target_bond) in [0, 5968, 5968, 5968].iter().enumerate() { + assert_eq!(bonds[i][4], *target_bond); + } // === Set self-weight only on val2 let uid = 1; @@ -1625,10 +1568,9 @@ fn test_bonds_with_liquid_alpha() { Pruning Scores: [0, 0, 0.214285714, 0.2857142857, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726]/ */ - assert_eq!(bonds[0][4], 0); - assert_eq!(bonds[1][4], 0); - assert_eq!(bonds[2][4], 6378); - assert_eq!(bonds[3][4], 6378); + for (i, target_bond) in [0, 0, 6378, 6378].iter().enumerate() { + assert_eq!(bonds[i][4], *target_bond); + } }); } From fddbf005fcc273ec9d61d1da7c81a08ea5b7f63c Mon Sep 17 00:00:00 2001 From: andreea-popescu-reef <160024917+andreea-popescu-reef@users.noreply.github.com> Date: Mon, 31 Mar 2025 20:35:00 -0400 Subject: [PATCH 36/45] Update pallets/subtensor/src/epoch/math.rs Co-authored-by: Cameron Fairchild --- pallets/subtensor/src/epoch/math.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/pallets/subtensor/src/epoch/math.rs b/pallets/subtensor/src/epoch/math.rs index 365276ca9f..8b64b09c95 100644 --- a/pallets/subtensor/src/epoch/math.rs +++ b/pallets/subtensor/src/epoch/math.rs @@ -1300,6 +1300,7 @@ pub fn hadamard_sparse( } /// Clamp the input value between high and low. +/// Note: assumes high > low pub fn clamp_value(value: I32F32, low: I32F32, high: I32F32) -> I32F32 { // First, clamp the value to ensure it does not exceed the upper bound (high). // If the value is greater than 'high', it will be set to 'high'. From eb53de38962da9edbdfdfb9745d1040bf94b4e0e Mon Sep 17 00:00:00 2001 From: andreea-popescu-reef <160024917+andreea-popescu-reef@users.noreply.github.com> Date: Mon, 31 Mar 2025 20:35:28 -0400 Subject: [PATCH 37/45] Update pallets/subtensor/src/epoch/math.rs Co-authored-by: Cameron Fairchild --- pallets/subtensor/src/epoch/math.rs | 2 +- pallets/subtensor/src/epoch/run_epoch.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pallets/subtensor/src/epoch/math.rs b/pallets/subtensor/src/epoch/math.rs index 8b64b09c95..a2108bd197 100644 --- a/pallets/subtensor/src/epoch/math.rs +++ b/pallets/subtensor/src/epoch/math.rs @@ -56,7 +56,7 @@ pub fn u16_proportion_to_fixed(x: u16) -> I32F32 { } #[allow(dead_code)] -pub fn fixed_to_fixed_proportion(x: I32F32) -> I32F32 { +pub fn fixed_to_fixed_u16_proportion(x: I32F32) -> I32F32 { x.safe_div(I32F32::saturating_from_num(u16::MAX)) } diff --git a/pallets/subtensor/src/epoch/run_epoch.rs b/pallets/subtensor/src/epoch/run_epoch.rs index 07df343997..356a7ad785 100644 --- a/pallets/subtensor/src/epoch/run_epoch.rs +++ b/pallets/subtensor/src/epoch/run_epoch.rs @@ -888,7 +888,7 @@ impl Pallet { bonds.iter_mut().for_each(|bonds_row| { bonds_row .iter_mut() - .for_each(|bond| *bond = fixed_to_fixed_proportion(*bond)); + .for_each(|bond| *bond = fixed_to_fixed_u16_proportion(*bond)); }); bonds } @@ -898,7 +898,7 @@ impl Pallet { bonds.iter_mut().for_each(|bonds_row| { bonds_row .iter_mut() - .for_each(|(_, bond)| *bond = fixed_to_fixed_proportion(*bond)); + .for_each(|(_, bond)| *bond = fixed_to_fixed_u16_proportion(*bond)); }); bonds } From d480c6c5c81cc9b35b95d42487ab681f8a78a2f7 Mon Sep 17 00:00:00 2001 From: Andreea Popescu Date: Tue, 1 Apr 2025 02:01:16 +0100 Subject: [PATCH 38/45] simplify alphas matrix computation --- pallets/subtensor/src/epoch/math.rs | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/pallets/subtensor/src/epoch/math.rs b/pallets/subtensor/src/epoch/math.rs index a2108bd197..5898ced70c 100644 --- a/pallets/subtensor/src/epoch/math.rs +++ b/pallets/subtensor/src/epoch/math.rs @@ -1414,17 +1414,11 @@ pub fn mat_ema_alpha_sparse( if let (Some(alpha_val), Some(decayed_val)) = (alpha_row.get(*j as usize), decayed_values.get(*j as usize)) { - // Calculate remaining capacity to limit bonds purchase - let remaining_capacity = one.saturating_sub(*decayed_val).max(zero); - // Each validator can increase bonds by at most clamped_alpha per epoch towards the cap // Validators allocate their purchase across miners based on weights - let purchase_increment = alpha_val.saturating_mul(*new_val); - - // Ensure that purchase does not exceed remaining capacity - let purchase = purchase_increment.min(remaining_capacity); + let purchase_increment = alpha_val.saturating_mul(*new_val).max(zero); + let result_val = decayed_val.saturating_add(purchase_increment).min(one); - let result_val = decayed_val.saturating_add(purchase).min(one); if result_val > zero { result_row.push((*j, result_val)); } @@ -1477,17 +1471,10 @@ pub fn mat_ema_alpha( // Bonds_decayed = Bonds * (1 - alpha) let decayed_val = one_minus_alpha.saturating_mul(*old_val); - // Calculate remaining capacity to limit bonds purchase - let remaining_capacity = one.saturating_sub(decayed_val).max(zero); - // Each validator can increase bonds by at most clamped_alpha per epoch towards the cap // Validators allocate their purchase across miners based on weights - let purchase_increment = alpha_val.saturating_mul(*new_val); - - // Ensure that purchase does not exceed remaining capacity - let purchase = purchase_increment.min(remaining_capacity); - - let result_val = decayed_val.saturating_add(purchase).min(one); + let purchase_increment = alpha_val.saturating_mul(*new_val).max(zero); + let result_val = decayed_val.saturating_add(purchase_increment).min(one); result_row.push(result_val); } } From 7fb65556dbe271c34aee39ed1f34266231f9a49b Mon Sep 17 00:00:00 2001 From: Andreea Popescu Date: Tue, 8 Apr 2025 23:30:46 +0100 Subject: [PATCH 39/45] add Yuma3 toggle --- evm-tests/src/contracts/subnet.ts | 21 ++++++++++- .../subnet.precompile.hyperparameter.test.ts | 19 +++++++++- pallets/admin-utils/src/lib.rs | 26 +++++++++++++ pallets/admin-utils/src/tests/mock.rs | 2 + pallets/subtensor/src/lib.rs | 8 ++++ pallets/subtensor/src/macros/config.rs | 2 + pallets/subtensor/src/tests/mock.rs | 2 + pallets/subtensor/src/utils/misc.rs | 8 ++++ precompiles/src/solidity/subnet.abi | 37 +++++++++++++++++++ precompiles/src/solidity/subnet.sol | 7 ++++ precompiles/src/subnet.rs | 21 +++++++++++ runtime/src/lib.rs | 2 + 12 files changed, 152 insertions(+), 3 deletions(-) diff --git a/evm-tests/src/contracts/subnet.ts b/evm-tests/src/contracts/subnet.ts index 9b6fe00596..9ddc2da873 100644 --- a/evm-tests/src/contracts/subnet.ts +++ b/evm-tests/src/contracts/subnet.ts @@ -572,6 +572,25 @@ export const ISubnetABI = [ stateMutability: "view", type: "function", }, + { + inputs: [ + { + internalType: "uint16", + name: "netuid", + type: "uint16", + }, + ], + name: "getYuma3Enabled", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool", + }, + ], + stateMutability: "view", + type: "function", + }, { inputs: [ { @@ -886,4 +905,4 @@ export const ISubnetABI = [ stateMutability: "payable", type: "function" }, -]; \ No newline at end of file +]; diff --git a/evm-tests/test/subnet.precompile.hyperparameter.test.ts b/evm-tests/test/subnet.precompile.hyperparameter.test.ts index 1805b85ce9..6ddc29e7bc 100644 --- a/evm-tests/test/subnet.precompile.hyperparameter.test.ts +++ b/evm-tests/test/subnet.precompile.hyperparameter.test.ts @@ -80,7 +80,7 @@ describe("Test the Subnet precompile contract", () => { assert.equal(valueFromContract, onchainValue); } - // minDifficulty hyperparameter + // minDifficulty hyperparameter // // disabled: only by sudo // @@ -406,6 +406,21 @@ describe("Test the Subnet precompile contract", () => { assert.equal(valueFromContract, onchainValue); } + // yuma3Enabled hyperparameter + { + const newValue = true; + const tx = await contract.setYuma3Enabled(netuid, newValue); + await tx.wait(); + + let onchainValue = await api.query.SubtensorModule.Yuma3Enabled.getValue(netuid) + + let valueFromContract = Boolean( + await contract.getYuma3Enabled(netuid) + ); + assert.equal(valueFromContract, newValue) + assert.equal(valueFromContract, onchainValue); + } + // alphaValues hyperparameter { const newValue = [118, 52429]; @@ -439,4 +454,4 @@ describe("Test the Subnet precompile contract", () => { assert.equal(valueFromContract, onchainValue); } }) -}); \ No newline at end of file +}); diff --git a/pallets/admin-utils/src/lib.rs b/pallets/admin-utils/src/lib.rs index 0175401b7f..6b3bfb8e82 100644 --- a/pallets/admin-utils/src/lib.rs +++ b/pallets/admin-utils/src/lib.rs @@ -1505,6 +1505,32 @@ pub mod pallet { ); Ok(()) } + + /// Enables or disables Yuma3 for a given subnet. + /// + /// # Parameters + /// - `origin`: The origin of the call, which must be the root account or subnet owner. + /// - `netuid`: The unique identifier for the subnet. + /// - `enabled`: A boolean flag to enable or disable Yuma3. + /// + /// # Weight + /// This function has a fixed weight of 0 and is classified as an operational transaction that does not incur any fees. + #[pallet::call_index(67)] + #[pallet::weight((0, DispatchClass::Operational, Pays::No))] + pub fn sudo_set_yuma3_enabled( + origin: OriginFor, + netuid: u16, + enabled: bool, + ) -> DispatchResult { + pallet_subtensor::Pallet::::ensure_subnet_owner_or_root(origin, netuid)?; + pallet_subtensor::Pallet::::set_yuma3_enabled(netuid, enabled); + log::debug!( + "Yuma3EnableToggled( netuid: {:?}, Enabled: {:?} ) ", + netuid, + enabled + ); + Ok(()) + } } } diff --git a/pallets/admin-utils/src/tests/mock.rs b/pallets/admin-utils/src/tests/mock.rs index 5f0d6bdcfa..1fade2a6d5 100644 --- a/pallets/admin-utils/src/tests/mock.rs +++ b/pallets/admin-utils/src/tests/mock.rs @@ -130,6 +130,7 @@ parameter_types! { pub const InitialAlphaHigh: u16 = 58982; // Represents 0.9 as per the production default pub const InitialAlphaLow: u16 = 45875; // Represents 0.7 as per the production default pub const InitialLiquidAlphaOn: bool = false; // Default value for LiquidAlphaOn + pub const InitialYuma3On: bool = false; // Default value for Yuma3On // pub const InitialHotkeyEmissionTempo: u64 = 1; // (DEPRECATED) // pub const InitialNetworkMaxStake: u64 = u64::MAX; // (DEPRECATED) pub const InitialColdkeySwapScheduleDuration: u64 = 5 * 24 * 60 * 60 / 12; // 5 days @@ -197,6 +198,7 @@ impl pallet_subtensor::Config for Test { type AlphaHigh = InitialAlphaHigh; type AlphaLow = InitialAlphaLow; type LiquidAlphaOn = InitialLiquidAlphaOn; + type Yuma3On = InitialYuma3On; type Preimages = (); type InitialColdkeySwapScheduleDuration = InitialColdkeySwapScheduleDuration; type InitialDissolveNetworkScheduleDuration = InitialDissolveNetworkScheduleDuration; diff --git a/pallets/subtensor/src/lib.rs b/pallets/subtensor/src/lib.rs index a78001e66b..049173bdce 100644 --- a/pallets/subtensor/src/lib.rs +++ b/pallets/subtensor/src/lib.rs @@ -730,6 +730,11 @@ pub mod pallet { false } #[pallet::type_value] + /// -- ITEM (switches liquid alpha on) + pub fn DefaultYuma3() -> bool { + false + } + #[pallet::type_value] /// (alpha_low: 0.7, alpha_high: 0.9) pub fn DefaultAlphaValues() -> (u16, u16) { (45875, 58982) @@ -1356,6 +1361,9 @@ pub mod pallet { pub type LiquidAlphaOn = StorageMap<_, Blake2_128Concat, u16, bool, ValueQuery, DefaultLiquidAlpha>; #[pallet::storage] + /// --- MAP ( netuid ) --> Whether or not Yuma3 is enabled + pub type Yuma3On = StorageMap<_, Blake2_128Concat, u16, bool, ValueQuery, DefaultYuma3>; + #[pallet::storage] /// MAP ( netuid ) --> (alpha_low, alpha_high) pub type AlphaValues = StorageMap<_, Identity, u16, (u16, u16), ValueQuery, DefaultAlphaValues>; diff --git a/pallets/subtensor/src/macros/config.rs b/pallets/subtensor/src/macros/config.rs index 76e7840e74..628e3609af 100644 --- a/pallets/subtensor/src/macros/config.rs +++ b/pallets/subtensor/src/macros/config.rs @@ -198,6 +198,8 @@ mod config { /// A flag to indicate if Liquid Alpha is enabled. #[pallet::constant] type LiquidAlphaOn: Get; + /// A flag to indicate if Yuma3 is enabled. + type Yuma3On: Get; // /// Initial hotkey emission tempo. // #[pallet::constant] // type InitialHotkeyEmissionTempo: Get; diff --git a/pallets/subtensor/src/tests/mock.rs b/pallets/subtensor/src/tests/mock.rs index dff78b7a28..c9f6697237 100644 --- a/pallets/subtensor/src/tests/mock.rs +++ b/pallets/subtensor/src/tests/mock.rs @@ -181,6 +181,7 @@ parameter_types! { pub const InitialAlphaHigh: u16 = 58982; // Represents 0.9 as per the production default pub const InitialAlphaLow: u16 = 45875; // Represents 0.7 as per the production default pub const InitialLiquidAlphaOn: bool = false; // Default value for LiquidAlphaOn + pub const InitialYuma3On: bool = false; // Default value for Yuma3On // pub const InitialNetworkMaxStake: u64 = u64::MAX; // (DEPRECATED) pub const InitialColdkeySwapScheduleDuration: u64 = 5 * 24 * 60 * 60 / 12; // Default as 5 days pub const InitialDissolveNetworkScheduleDuration: u64 = 5 * 24 * 60 * 60 / 12; // Default as 5 days @@ -406,6 +407,7 @@ impl crate::Config for Test { type AlphaHigh = InitialAlphaHigh; type AlphaLow = InitialAlphaLow; type LiquidAlphaOn = InitialLiquidAlphaOn; + type Yuma3On = InitialYuma3On; type Preimages = Preimage; type InitialColdkeySwapScheduleDuration = InitialColdkeySwapScheduleDuration; type InitialDissolveNetworkScheduleDuration = InitialDissolveNetworkScheduleDuration; diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index e36f033a74..caea51d285 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -703,6 +703,14 @@ impl Pallet { LiquidAlphaOn::::get(netuid) } + pub fn set_yuma3_enabled(netuid: u16, enabled: bool) { + Yuma3On::::set(netuid, enabled); + } + + pub fn get_yuma3_enabled(netuid: u16) -> bool { + Yuma3On::::get(netuid) + } + /// Set the duration for coldkey swap /// /// # Arguments diff --git a/precompiles/src/solidity/subnet.abi b/precompiles/src/solidity/subnet.abi index e2a3e569da..a2849a0cbe 100644 --- a/precompiles/src/solidity/subnet.abi +++ b/precompiles/src/solidity/subnet.abi @@ -194,6 +194,25 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "netuid", + "type": "uint16" + } + ], + "name": "getYuma3Enabled", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [ { @@ -668,6 +687,24 @@ "stateMutability": "payable", "type": "function" }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "netuid", + "type": "uint16" + }, + { + "internalType": "bool", + "name": "yuma3Enabled", + "type": "bool" + } + ], + "name": "setYuma3Enabled", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, { "inputs": [ { diff --git a/precompiles/src/solidity/subnet.sol b/precompiles/src/solidity/subnet.sol index d5ef0916d9..2fa9d3f550 100644 --- a/precompiles/src/solidity/subnet.sol +++ b/precompiles/src/solidity/subnet.sol @@ -152,6 +152,13 @@ interface ISubnet { bool liquidAlphaEnabled ) external payable; + function getYuma3Enabled(uint16 netuid) external view returns (bool); + + function setYuma3Enabled( + uint16 netuid, + bool yuma3Enabled + ) external payable; + function getAlphaValues( uint16 netuid ) external view returns (uint16, uint16); diff --git a/precompiles/src/subnet.rs b/precompiles/src/subnet.rs index ae57584eb5..ad1ce61ff7 100644 --- a/precompiles/src/subnet.rs +++ b/precompiles/src/subnet.rs @@ -575,6 +575,27 @@ where ) } + #[precompile::public("getYuma3Enabled(uint16)")] + #[precompile::view] + fn get_yuma3_enabled(_: &mut impl PrecompileHandle, netuid: u16) -> EvmResult { + Ok(pallet_subtensor::Yuma3On::::get(netuid)) + } + + #[precompile::public("setYuma3Enabled(uint16,bool)")] + #[precompile::payable] + fn set_yuma3_enabled( + handle: &mut impl PrecompileHandle, + netuid: u16, + enabled: bool, + ) -> EvmResult<()> { + let call = pallet_admin_utils::Call::::sudo_set_yuma3_enabled { netuid, enabled }; + + handle.try_dispatch_runtime_call::( + call, + RawOrigin::Signed(handle.caller_account_id::()), + ) + } + #[precompile::public("getAlphaValues(uint16)")] #[precompile::view] fn get_alpha_values(_: &mut impl PrecompileHandle, netuid: u16) -> EvmResult<(u16, u16)> { diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index a6e3350b5e..d058cd3bfc 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -1040,6 +1040,7 @@ parameter_types! { pub const InitialAlphaHigh: u16 = 58982; // Represents 0.9 as per the production default pub const InitialAlphaLow: u16 = 45875; // Represents 0.7 as per the production default pub const InitialLiquidAlphaOn: bool = false; // Default value for LiquidAlphaOn + pub const InitialYuma3On: bool = false; // Default value for Yuma3On // pub const SubtensorInitialNetworkMaxStake: u64 = u64::MAX; // (DEPRECATED) pub const InitialColdkeySwapScheduleDuration: BlockNumber = 5 * 24 * 60 * 60 / 12; // 5 days pub const InitialDissolveNetworkScheduleDuration: BlockNumber = 5 * 24 * 60 * 60 / 12; // 5 days @@ -1110,6 +1111,7 @@ impl pallet_subtensor::Config for Runtime { type AlphaHigh = InitialAlphaHigh; type AlphaLow = InitialAlphaLow; type LiquidAlphaOn = InitialLiquidAlphaOn; + type Yuma3On = InitialYuma3On; type InitialTaoWeight = SubtensorInitialTaoWeight; type Preimages = Preimage; type InitialColdkeySwapScheduleDuration = InitialColdkeySwapScheduleDuration; From be623f009e8830b29e4dbe9e7f80637648943748 Mon Sep 17 00:00:00 2001 From: Andreea Popescu Date: Tue, 8 Apr 2025 23:36:14 +0100 Subject: [PATCH 40/45] revert original yuma --- pallets/subtensor/src/epoch/run_epoch.rs | 287 +++++++++++++++++------ 1 file changed, 217 insertions(+), 70 deletions(-) diff --git a/pallets/subtensor/src/epoch/run_epoch.rs b/pallets/subtensor/src/epoch/run_epoch.rs index 356a7ad785..28bbb89d07 100644 --- a/pallets/subtensor/src/epoch/run_epoch.rs +++ b/pallets/subtensor/src/epoch/run_epoch.rs @@ -197,37 +197,67 @@ impl Pallet { let weights_for_bonds: Vec> = interpolate(&weights, &clipped_weights, bonds_penalty); - // Access network bonds. - let mut bonds: Vec> = Self::get_bonds_fixed_proportion(netuid); - inplace_mask_cols(&recently_registered, &mut bonds); // mask outdated bonds - log::trace!("B: {:?}", &bonds); + let mut dividends: Vec; + let mut ema_bonds: Vec>; + if Yuma3On::::get(netuid) { + // Access network bonds. + let mut bonds: Vec> = Self::get_bonds_fixed_proportion(netuid); + inplace_mask_cols(&recently_registered, &mut bonds); // mask outdated bonds + log::trace!("B: {:?}", &bonds); + + // Compute the Exponential Moving Average (EMA) of bonds. + ema_bonds = Self::compute_bonds( + netuid, + &weights_for_bonds, + &bonds, + &consensus, + &active_stake, + ); + log::trace!("emaB: {:?}", &ema_bonds); + + // Normalize EMA bonds. + let mut ema_bonds_norm = ema_bonds.clone(); + inplace_col_normalize(&mut ema_bonds_norm); + log::trace!("emaB norm: {:?}", &ema_bonds_norm); + + // # === Dividend Calculation=== + let total_bonds_per_validator: Vec = + row_sum(&mat_vec_mul(&ema_bonds_norm, &incentive)); + log::trace!( + "total_bonds_per_validator: {:?}", + &total_bonds_per_validator + ); + + dividends = vec_mul(&total_bonds_per_validator, &active_stake); + inplace_normalize(&mut dividends); + log::trace!("D: {:?}", ÷nds); + } else { + // original Yuma - liquid alpha disabled + // Access network bonds. + let mut bonds: Vec> = Self::get_bonds(netuid); + // Remove bonds referring to neurons that have registered since last tempo. + inplace_mask_cols(&recently_registered, &mut bonds); // mask recently registered bonds + inplace_col_normalize(&mut bonds); // sum_i b_ij = 1 + log::trace!("B: {:?}", &bonds); - // Compute the Exponential Moving Average (EMA) of bonds. - let ema_bonds = Self::compute_ema_bonds( - netuid, - &weights_for_bonds, - &bonds, - &consensus, - &active_stake, - ); - log::trace!("emaB: {:?}", &ema_bonds); + // Compute bonds delta column normalized. + let mut bonds_delta: Vec> = row_hadamard(&weights_for_bonds, &active_stake); // ΔB = W◦S + inplace_col_normalize(&mut bonds_delta); // sum_i b_ij = 1 + log::trace!("ΔB: {:?}", &bonds_delta); - // Normalize EMA bonds. - let mut ema_bonds_norm = ema_bonds.clone(); - inplace_col_normalize(&mut ema_bonds_norm); - log::trace!("emaB norm: {:?}", &ema_bonds_norm); + // Compute the Exponential Moving Average (EMA) of bonds. + ema_bonds = Self::compute_ema_bonds_normal(&bonds_delta, &bonds, netuid); + inplace_col_normalize(&mut ema_bonds); // sum_i b_ij = 1 + log::trace!("emaB: {:?}", &ema_bonds); - // # === Dividend Calculation=== - let total_bonds_per_validator: Vec = - row_sum(&mat_vec_mul(&ema_bonds_norm, &incentive)); - log::trace!( - "total_bonds_per_validator: {:?}", - &total_bonds_per_validator - ); + // Compute dividends: d_i = SUM(j) b_ij * inc_j + dividends = matmul_transpose(&ema_bonds, &incentive); + inplace_normalize(&mut dividends); + log::trace!("Dividends: {:?}", ÷nds); - let mut dividends: Vec = vec_mul(&total_bonds_per_validator, &active_stake); - inplace_normalize(&mut dividends); - log::trace!("D: {:?}", ÷nds); + // Column max-upscale EMA bonds for storage: max_i w_ij = 1. + inplace_col_max_upscale(&mut ema_bonds); + } // ================================= // == Emission and Pruning scores == @@ -572,49 +602,98 @@ impl Pallet { let weights_for_bonds: Vec> = interpolate_sparse(&weights, &clipped_weights, n, bonds_penalty); - // Access network bonds. - let mut bonds: Vec> = Self::get_bonds_sparse_fixed_proportion(netuid); - log::trace!("Bonds: {:?}", &bonds); - - // Remove bonds referring to neurons that have registered since last tempo. - // Mask if: the last tempo block happened *before* the registration block - // ==> last_tempo <= registered - let last_tempo: u64 = current_block.saturating_sub(tempo); - bonds = scalar_vec_mask_sparse_matrix( - &bonds, - last_tempo, - &block_at_registration, - &|last_tempo, registered| last_tempo <= registered, - ); - log::trace!("Bonds: (mask) {:?}", &bonds); - - // Compute the Exponential Moving Average (EMA) of bonds. - log::trace!("weights_for_bonds: {:?}", &weights_for_bonds); - let ema_bonds = Self::compute_ema_bonds_sparse( - netuid, - &weights_for_bonds, - &bonds, - &consensus, - &active_stake, - ); - log::trace!("emaB: {:?}", &ema_bonds); - - // Normalize EMA bonds. - let mut ema_bonds_norm = ema_bonds.clone(); - inplace_col_normalize_sparse(&mut ema_bonds_norm, n); // sum_i b_ij = 1 - log::trace!("emaB norm: {:?}", &ema_bonds_norm); + let mut dividends: Vec; + let mut ema_bonds: Vec>; + if Yuma3On::::get(netuid) { + // Access network bonds. + let mut bonds = Self::get_bonds_sparse_fixed_proportion(netuid); + log::trace!("Bonds: {:?}", &bonds); + + // Remove bonds referring to neurons that have registered since last tempo. + // Mask if: the last tempo block happened *before* the registration block + // ==> last_tempo <= registered + let last_tempo: u64 = current_block.saturating_sub(tempo); + bonds = scalar_vec_mask_sparse_matrix( + &bonds, + last_tempo, + &block_at_registration, + &|last_tempo, registered| last_tempo <= registered, + ); + log::trace!("Bonds: (mask) {:?}", &bonds); + + // Compute the Exponential Moving Average (EMA) of bonds. + log::trace!("weights_for_bonds: {:?}", &weights_for_bonds); + ema_bonds = Self::compute_bonds_sparse( + netuid, + &weights_for_bonds, + &bonds, + &consensus, + &active_stake, + ); + log::trace!("emaB: {:?}", &ema_bonds); + + // Normalize EMA bonds. + let mut ema_bonds_norm = ema_bonds.clone(); + inplace_col_normalize_sparse(&mut ema_bonds_norm, n); // sum_i b_ij = 1 + log::trace!("emaB norm: {:?}", &ema_bonds_norm); + + // # === Dividend Calculation=== + let total_bonds_per_validator: Vec = + row_sum_sparse(&mat_vec_mul_sparse(&ema_bonds_norm, &incentive)); + log::trace!( + "total_bonds_per_validator: {:?}", + &total_bonds_per_validator + ); + + dividends = vec_mul(&total_bonds_per_validator, &active_stake); + inplace_normalize(&mut dividends); + log::trace!("Dividends: {:?}", ÷nds); + } else { + // original Yuma - liquid alpha disabled + // Access network bonds. + let mut bonds: Vec> = Self::get_bonds_sparse(netuid); + log::trace!("B: {:?}", &bonds); + + // Remove bonds referring to neurons that have registered since last tempo. + // Mask if: the last tempo block happened *before* the registration block + // ==> last_tempo <= registered + let last_tempo: u64 = current_block.saturating_sub(tempo); + bonds = scalar_vec_mask_sparse_matrix( + &bonds, + last_tempo, + &block_at_registration, + &|last_tempo, registered| last_tempo <= registered, + ); + log::trace!("B (outdatedmask): {:?}", &bonds); + + // Normalize remaining bonds: sum_i b_ij = 1. + inplace_col_normalize_sparse(&mut bonds, n); + log::trace!("B (mask+norm): {:?}", &bonds); - // # === Dividend Calculation=== - let total_bonds_per_validator: Vec = - row_sum_sparse(&mat_vec_mul_sparse(&ema_bonds_norm, &incentive)); - log::trace!( - "total_bonds_per_validator: {:?}", - &total_bonds_per_validator - ); + // Compute bonds delta column normalized. + let mut bonds_delta: Vec> = + row_hadamard_sparse(&weights_for_bonds, &active_stake); // ΔB = W◦S (outdated W masked) + log::trace!("ΔB: {:?}", &bonds_delta); - let mut dividends: Vec = vec_mul(&total_bonds_per_validator, &active_stake); - inplace_normalize(&mut dividends); - log::trace!("Dividends: {:?}", ÷nds); + // Normalize bonds delta. + inplace_col_normalize_sparse(&mut bonds_delta, n); // sum_i b_ij = 1 + log::trace!("ΔB (norm): {:?}", &bonds_delta); + + // Compute the Exponential Moving Average (EMA) of bonds. + ema_bonds = Self::compute_ema_bonds_normal_sparse(&bonds_delta, &bonds, netuid); + // Normalize EMA bonds. + inplace_col_normalize_sparse(&mut ema_bonds, n); // sum_i b_ij = 1 + log::trace!("Exponential Moving Average Bonds: {:?}", &ema_bonds); + + // Compute dividends: d_i = SUM(j) b_ij * inc_j. + // range: I32F32(0, 1) + dividends = matmul_transpose_sparse(&ema_bonds, &incentive); + inplace_normalize(&mut dividends); + log::trace!("Dividends: {:?}", ÷nds); + + // Column max-upscale EMA bonds for storage: max_i w_ij = 1. + inplace_col_max_upscale_sparse(&mut ema_bonds, n); + } // ================================= // == Emission and Pruning scores == @@ -903,6 +982,74 @@ impl Pallet { bonds } + /// Compute the Exponential Moving Average (EMA) of bonds using a normal alpha value for a sparse matrix. + /// + /// # Args: + /// * `bonds_delta` - A vector of bond deltas. + /// * `bonds` - A vector of bonds. + /// * `netuid` - The network ID. + /// + /// # Returns: + /// A vector of EMA bonds. + pub fn compute_ema_bonds_normal_sparse( + bonds_delta: &[Vec<(u16, I32F32)>], + bonds: &[Vec<(u16, I32F32)>], + netuid: u16, + ) -> Vec> { + // Retrieve the bonds moving average for the given network ID and scale it down. + let bonds_moving_average: I64F64 = + I64F64::saturating_from_num(Self::get_bonds_moving_average(netuid)) + .safe_div(I64F64::saturating_from_num(1_000_000)); + + // Calculate the alpha value for the EMA calculation. + // Alpha is derived by subtracting the scaled bonds moving average from 1. + let alpha: I32F32 = I32F32::saturating_from_num(1) + .saturating_sub(I32F32::saturating_from_num(bonds_moving_average)); + + // Compute the Exponential Moving Average (EMA) of bonds using the calculated alpha value. + let ema_bonds = mat_ema_sparse(bonds_delta, bonds, alpha); + + // Log the computed EMA bonds for debugging purposes. + log::trace!("Exponential Moving Average Bonds Normal: {:?}", ema_bonds); + + // Return the computed EMA bonds. + ema_bonds + } + + /// Compute the Exponential Moving Average (EMA) of bonds using a normal alpha value. + /// + /// # Args: + /// * `bonds_delta` - A vector of bond deltas. + /// * `bonds` - A vector of bonds. + /// * `netuid` - The network ID. + /// + /// # Returns: + /// A vector of EMA bonds. + pub fn compute_ema_bonds_normal( + bonds_delta: &[Vec], + bonds: &[Vec], + netuid: u16, + ) -> Vec> { + // Retrieve the bonds moving average for the given network ID and scale it down. + let bonds_moving_average: I64F64 = + I64F64::saturating_from_num(Self::get_bonds_moving_average(netuid)) + .safe_div(I64F64::saturating_from_num(1_000_000)); + + // Calculate the alpha value for the EMA calculation. + // Alpha is derived by subtracting the scaled bonds moving average from 1. + let alpha: I32F32 = I32F32::saturating_from_num(1) + .saturating_sub(I32F32::saturating_from_num(bonds_moving_average)); + + // Compute the Exponential Moving Average (EMA) of bonds using the calculated alpha value. + let ema_bonds = mat_ema(bonds_delta, bonds, alpha); + + // Log the computed EMA bonds for debugging purposes. + log::trace!("Exponential Moving Average Bonds Normal: {:?}", ema_bonds); + + // Return the computed EMA bonds. + ema_bonds + } + /// Compute the Exponential Moving Average (EMA) of bonds based on the Liquid Alpha setting /// /// # Args: @@ -914,7 +1061,7 @@ impl Pallet { /// /// # Returns: /// A vector of EMA bonds. - pub fn compute_ema_bonds( + pub fn compute_bonds( netuid: u16, weights: &[Vec], // weights_for_bonds bonds: &[Vec], @@ -960,7 +1107,7 @@ impl Pallet { /// /// # Returns: /// A vector of EMA bonds. - pub fn compute_ema_bonds_sparse( + pub fn compute_bonds_sparse( netuid: u16, weights: &[Vec<(u16, I32F32)>], bonds: &[Vec<(u16, I32F32)>], From 564745ae21fe77c26089d7b938cf7b182279971e Mon Sep 17 00:00:00 2001 From: Andreea Popescu Date: Wed, 9 Apr 2025 00:17:08 +0100 Subject: [PATCH 41/45] revert no liquid alpha tests --- pallets/subtensor/src/epoch/run_epoch.rs | 2 +- pallets/subtensor/src/tests/epoch.rs | 1159 ++++++++-------------- 2 files changed, 423 insertions(+), 738 deletions(-) diff --git a/pallets/subtensor/src/epoch/run_epoch.rs b/pallets/subtensor/src/epoch/run_epoch.rs index 28bbb89d07..a8885047b9 100644 --- a/pallets/subtensor/src/epoch/run_epoch.rs +++ b/pallets/subtensor/src/epoch/run_epoch.rs @@ -252,7 +252,7 @@ impl Pallet { // Compute dividends: d_i = SUM(j) b_ij * inc_j dividends = matmul_transpose(&ema_bonds, &incentive); - inplace_normalize(&mut dividends); + inplace_normalize(&mut dividends); log::trace!("Dividends: {:?}", ÷nds); // Column max-upscale EMA bonds for storage: max_i w_ij = 1. diff --git a/pallets/subtensor/src/tests/epoch.rs b/pallets/subtensor/src/tests/epoch.rs index 9bb9f5a6e7..9b9e3e8727 100644 --- a/pallets/subtensor/src/tests/epoch.rs +++ b/pallets/subtensor/src/tests/epoch.rs @@ -714,7 +714,8 @@ fn test_512_graph() { assert_eq!(SubtensorModule::get_dividends_for_uid(netuid, uid), 1023); // Note D = floor(1 / 64 * 65_535) = 1023 assert_eq!(SubtensorModule::get_emission_for_uid(netuid, uid), 7812500); // Note E = 0.5 / 200 * 1_000_000_000 = 7_812_500 assert_eq!(bonds[uid as usize][validator], 0.0); - assert_eq!(bonds[uid as usize][server], I32F32::from_num(102)); + assert_eq!(bonds[uid as usize][server], I32F32::from_num(65_535)); + // Note B_ij = floor(1 / 64 * 65_535) / 65_535 = 1023 / 65_535, then max-upscaled to 65_535 } for uid in servers { assert_eq!( @@ -982,599 +983,310 @@ fn test_512_graph_random_weights() { // }); // } -// Test bonds exponential moving average over a sequence of epochs. +// Test bonds exponential moving average over a sequence of epochs - no liquid alpha #[test] fn test_bonds() { new_test_ext(1).execute_with(|| { - let sparse: bool = true; - let n: u16 = 8; - let netuid: u16 = 1; - let tempo: u16 = u16::MAX - 1; // high tempo to skip automatic epochs in on_initialize, use manual epochs instead - let max_stake: u64 = 4; - let stakes: Vec = vec![1, 2, 3, 4, 0, 0, 0, 0]; + let sparse: bool = true; + let n: u16 = 8; + let netuid: u16 = 1; + let tempo: u16 = 1; + let max_stake: u64 = 4; + let stakes: Vec = vec![1, 2, 3, 4, 0, 0, 0, 0]; let block_number = System::block_number(); - add_network(netuid, tempo, 0); - SubtensorModule::set_max_allowed_uids(netuid, n); - assert_eq!(SubtensorModule::get_max_allowed_uids(netuid), n); - SubtensorModule::set_max_registrations_per_block(netuid, n); - SubtensorModule::set_target_registrations_per_interval(netuid, n); - SubtensorModule::set_weights_set_rate_limit(netuid, 0); - SubtensorModule::set_min_allowed_weights(netuid, 1); - SubtensorModule::set_max_weight_limit(netuid, u16::MAX); - SubtensorModule::set_bonds_penalty(netuid, u16::MAX); - - // === Register [validator1, validator2, validator3, validator4, server1, server2, server3, server4] - for key in 0..n as u64 { - SubtensorModule::add_balance_to_coldkey_account(&U256::from(key), max_stake); - let (nonce, work): (u64, Vec) = SubtensorModule::create_work_for_block_number( - netuid, - block_number, - key * 1_000_000, - &U256::from(key), - ); - assert_ok!(SubtensorModule::register( - <::RuntimeOrigin>::signed(U256::from(key)), - netuid, - block_number, - nonce, - work, - U256::from(key), - U256::from(key) - )); - SubtensorModule::increase_stake_for_hotkey_and_coldkey_on_subnet( - &U256::from(key), - &U256::from(key), - netuid, - stakes[key as usize], - ); - } - assert_eq!(SubtensorModule::get_max_allowed_uids(netuid), n); - assert_eq!(SubtensorModule::get_subnetwork_n(netuid), n); - - // === Issue validator permits - SubtensorModule::set_max_allowed_validators(netuid, n); - assert_eq!(SubtensorModule::get_max_allowed_validators(netuid), n); - SubtensorModule::epoch(netuid, 1_000_000_000); // run first epoch to set allowed validators - next_block(); // run to next block to ensure weights are set on nodes after their registration block - - // === Set weights [val->srv1: 0.1, val->srv2: 0.2, val->srv3: 0.3, val->srv4: 0.4] - for uid in 0..(n / 2) as u64 { - assert_ok!(SubtensorModule::set_weights( - RuntimeOrigin::signed(U256::from(uid)), - netuid, - ((n / 2)..n).collect(), - vec![u16::MAX / 4, u16::MAX / 2, (u16::MAX / 4) * 3, u16::MAX], - 0 - )); - } - if sparse { - SubtensorModule::epoch(netuid, 1_000_000_000); - } else { - SubtensorModule::epoch_dense(netuid, 1_000_000_000); - } - /* current_block: 2 - Block at registration: [1, 1, 1, 1, 1, 1, 1, 1] - Active Stake: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] - Weights: [[(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149 - ), (7, 65535)], [], [], [], []] - Weights (permit): [[(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), - (6, 49149), (7, 65535)], [], [], [], []] - Weights (mask+norm): [[(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584) - , (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] - Ranks (before): [0, 0, 0, 0, 0.099997558, 0.2000012202, 0.2999926745, 0.4000085443] - Consensus: [0, 0, 0, 0, 0.0999975584, 0.2000012207, 0.2999926754, 0.400008545] - Clipped Weights: [[(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5 - , 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] - Validator Trust: [0.9999999995, 0.9999999995, 0.9999999995, 0.9999999995, 0, 0, 0, 0] - Ranks (after): [0, 0, 0, 0, 0.099997558, 0.2000012202, 0.2999926745, 0.4000085443] - Trust: [0, 0, 0, 0, 1, 1, 1, 1] - Incentive (=Rank): [0, 0, 0, 0, 0.0999975582, 0.2000012207, 0.2999926752, 0.4000085455] - Bonds: [[], [], [], [], [], [], [], []] - Bonds: (mask) [[], [], [], [], [], [], [], []] - weights_for_bonds: [[(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), - (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] - ΔB: [[(4, 0.0999999996), (5, 0.0999999999), (6, 0.0999999994), (7, 0.0999999996)], [(4, 0.1999999995), (5, 0.2), (6, 0.1999999997), (7, 0.1999999997)], [(4, 0.299999999), (5, 0.2999999998), (6, - 0.3), (7, 0.3)], [(4, 0.4000000013), (5, 0.4), (6, 0.4000000004), (7, 0.4000000001)], [], [], [], []] - emaB: [[(4, 0.0099999998), (5, 0.0099999998), (6, 0.0099999998), (7, 0.0099999998)], [(4, 0.0199999998), (5, 0.0199999998), (6, 0.0199999998), (7, 0.0199999998)], [(4, 0.0299999998), (5, 0.0299999998), (6, 0.03), (7, 0.03)], [(4, 0.04), (5, 0.0399999998), (6, 0.04), (7, 0.04)], [], [], [], []] - emaB norm: [[(4, 0.0999999982), (5, 0.0999999985), (6, 0.099999998), (7, 0.099999998)], [(4, 0.199999999), (5, 0.1999999995), (6, 0.1999999986), (7, 0.1999999986)], [(4, 0.2999999996), (5, 0.3000000003), (6, 0.3000000012), (7, 0.3000000012)], [(4, 0.4000000027), (5, 0.4000000013), (6, 0.4000000018), (7, 0.4000000018)], [], [], [], []] - total_bonds_per_validator: [0.0999999975, 0.1999999979, 0.3000000003, 0.4000000008, 0, 0, 0, 0] - Dividends: [0.0333333318, 0.1333333314, 0.3000000005, 0.5333333358, 0, 0, 0, 0] - Normalized Server Emission: [0, 0, 0, 0, 0.049998779, 0.1000006103, 0.1499963375, 0.2000042726] - Server Emission: [0, 0, 0, 0, 49998779, 100000610, 149996337, 200004272] - Normalized Validator Emission: [0.016666666, 0.0666666657, 0.1500000001, 0.266666668, 0, 0, 0, 0] - Validator Emission: [16666665, 66666665, 150000000, 266666668, 0, 0, 0, 0] - Normalized Combined Emission: [0.016666666, 0.0666666657, 0.1500000001, 0.266666668, 0.049998779, 0.1000006103, 0.1499963375, 0.2000042726] - Combined Emission: [16666665, 66666665, 150000000, 266666668, 49998779, 100000610, 149996337, 200004272] - Pruning Scores: [0.016666666, 0.0666666657, 0.1500000001, 0.266666668, 0.049998779, 0.1000006103, 0.1499963375, 0.2000042726] - s: [[0, 0, 0, 0, 655, 655, 655, 655], [0, 0, 0, 0, 1310, 1310, 1310, 1310], [0, 0, 0, 0, 1966, 1966, 1966, 1966], [0, 0, 0, 0, 2621, 2621, 2621, 2621], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]] - */ - - let bonds = SubtensorModule::get_bonds(netuid); - for (i, target_bond) in [655, 1310, 1966, 2621].iter().enumerate() { - assert_eq!(bonds[i][4], *target_bond); - } - - // === Set self-weight only on val1 - let uid = 0; - assert_ok!(SubtensorModule::set_weights( - RuntimeOrigin::signed(U256::from(uid)), - netuid, - vec![uid], - vec![u16::MAX], - 0 - )); - next_block(); - if sparse { - SubtensorModule::epoch(netuid, 1_000_000_000); - } else { - SubtensorModule::epoch_dense(netuid, 1_000_000_000); - } - /* current_block: 3 - Block at registration: [1, 1, 1, 1, 1, 1, 1, 1] - Active Stake: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] - Weights: [[(0, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - Weights (permit): [[(0, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - Weights (mask+norm): [[], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] - Ranks (before): [0, 0, 0, 0, 0.0899978022, 0.1800010982, 0.2699934072, 0.36000769] - Consensus: [0, 0, 0, 0, 0.0999975584, 0.2000012207, 0.2999926754, 0.400008545] - Clipped Weights: [[], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] - Validator Trust: [0, 0.9999999995, 0.9999999995, 0.9999999995, 0, 0, 0, 0] - Ranks (after): [0, 0, 0, 0, 0.0899978022, 0.1800010982, 0.2699934072, 0.36000769] - Trust: [0, 0, 0, 0, 1, 1, 1, 1] - Incentive (=Rank): [0, 0, 0, 0, 0.0999975582, 0.2000012207, 0.2999926754, 0.4000085455] - Bonds: [[(4, 0.0099946593), (5, 0.0099946593), (6, 0.0099946593), (7, 0.0099946593)], [(4, 0.0199893187), (5, 0.0199893187), (6, 0.0199893187), (7, 0.0199893187)], [(4, 0.029999237), (5, 0.029999237), (6, 0.029999237), (7, 0.029999237)], [(4, 0.0399938964), (5, 0.0399938964), (6, 0.0399938964), (7, 0.0399938964)], [], [], [], []] - Bonds: (mask) [[], [], [], [], [], [], [], []] - weights_for_bonds: [[], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] - ΔB: [[], [(4, 0.2222222215), (5, 0.222222222), (6, 0.2222222218), (7, 0.2222222218)], [(4, 0.3333333323), (5, 0.3333333333), (6, 0.3333333333), (7, 0.3333333333)], [(4, 0.4444444457), (5, 0.4444444443), (6, 0.4444444447), (7, 0.4444444445)], [], [], [], []] - emaB: [[], [(4, 0.022222222), (5, 0.022222222), (6, 0.022222222), (7, 0.022222222)], [(4, 0.0333333332), (5, 0.0333333332), (6, 0.0333333332), (7, 0.0333333332)], [(4, 0.0444444446), (5, 0.0444444444), (6, 0.0444444444), (7, 0.0444444444)], [], [], [], []] - emaB norm: [[], [(4, 0.2222222209), (5, 0.2222222213), (6, 0.2222222213), (7, 0.2222222213)], [(4, 0.3333333323), (5, 0.3333333333), (6, 0.3333333333), (7, 0.3333333333)], [(4, 0.4444444464), (5, 0.4444444452), (6, 0.4444444452), (7, 0.4444444452)], [], [], [], []] - total_bonds_per_validator: [0, 0.2222222209, 0.3333333328, 0.444444445, 0, 0, 0, 0] - Dividends: [0, 0.1379310335, 0.310344827, 0.5517241391, 0, 0, 0, 0] - Normalized Server Emission: [0, 0, 0, 0, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] - Server Emission: [0, 0, 0, 0, 49998779, 100000610, 149996337, 200004272] - Normalized Validator Emission: [0, 0.0689655168, 0.1551724134, 0.2758620696, 0, 0, 0, 0] - Validator Emission: [0, 68965516, 155172413, 275862069, 0, 0, 0, 0] - Normalized Combined Emission: [0, 0.0689655168, 0.1551724134, 0.2758620696, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] - Combined Emission: [0, 68965516, 155172413, 275862069, 49998779, 100000610, 149996337, 200004272] - Pruning Scores: [0, 0.0689655168, 0.1551724134, 0.2758620696, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] - */ - for (i, target_bond) in [655, 1310, 1966, 2621].iter().enumerate() { - assert_eq!(bonds[i][4], *target_bond); - } - - // === Set self-weight only on val2 - let uid = 1; - assert_ok!(SubtensorModule::set_weights( - RuntimeOrigin::signed(U256::from(uid)), - netuid, - vec![uid], - vec![u16::MAX], - 0 - )); - next_block(); - if sparse { - SubtensorModule::epoch(netuid, 1_000_000_000); - } else { - SubtensorModule::epoch_dense(netuid, 1_000_000_000); - } - /* current_block: 4 - Block at registration: [1, 1, 1, 1, 1, 1, 1, 1] - Active Stake: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] - Weights: [[(0, 65535)], [(1, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - Weights (permit): [[(0, 65535)], [(1, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - Weights (mask+norm): [[], [], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] - Ranks (before): [0, 0, 0, 0, 0.0699982906, 0.1400008542, 0.2099948723, 0.2800059812] - Consensus: [0, 0, 0, 0, 0.0999975584, 0.2000012207, 0.2999926754, 0.400008545] - Clipped Weights: [[], [], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] - Validator Trust: [0, 0, 0.9999999995, 0.9999999995, 0, 0, 0, 0] - Ranks (after): [0, 0, 0, 0, 0.0699982906, 0.1400008542, 0.2099948723, 0.2800059812] - Trust: [0, 0, 0, 0, 1, 1, 1, 1] - Incentive (=Rank): [0, 0, 0, 0, 0.0999975582, 0.2000012207, 0.2999926754, 0.4000085455] - Bonds: [[], [(4, 0.0222171359), (5, 0.0222171359), (6, 0.0222171359), (7, 0.0222171359)], [(4, 0.0333257038), (5, 0.0333257038), (6, 0.0333257038), (7, 0.0333257038)], [(4, 0.0444342718), (5, 0.0444342718), (6, 0.0444342718), (7, 0.0444342718)], [], [], [], []] - Bonds: (mask) [[], [], [], [], [], [], [], []] - weights_for_bonds: [[], [], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] - ΔB: [[], [], [(4, 0.428571427), (5, 0.4285714284), (6, 0.4285714284), (7, 0.4285714284)], [(4, 0.5714285728), (5, 0.5714285714), (6, 0.5714285714), (7, 0.5714285714)], [], [], [], []] - emaB: [[], [], [(4, 0.0428571426), (5, 0.0428571429), (6, 0.0428571429), (7, 0.0428571429)], [(4, 0.0571428572), (5, 0.057142857), (6, 0.057142857), (7, 0.057142857)], [], [], [], []] - emaB norm: [[], [], [(4, 0.4285714268), (5, 0.428571429), (6, 0.428571429), (7, 0.428571429)], [(4, 0.571428573), (5, 0.5714285707), (6, 0.5714285707), (7, 0.5714285707)], [], [], [], []] - total_bonds_per_validator: [0, 0, 0.4285714284, 0.5714285704, 0, 0, 0, 0] - Dividends: [0, 0, 0.36, 0.6399999997, 0, 0, 0, 0] - Normalized Server Emission: [0, 0, 0, 0, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] - Server Emission: [0, 0, 0, 0, 49998779, 100000610, 149996337, 200004272] - Normalized Validator Emission: [0, 0, 0.18, 0.3199999998, 0, 0, 0, 0] - Validator Emission: [0, 0, 179999999, 319999999, 0, 0, 0, 0] - Normalized Combined Emission: [0, 0, 0.18, 0.3199999998, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] - Combined Emission: [0, 0, 179999999, 319999999, 49998779, 100000610, 149996337, 200004272] - Pruning Scores: [0, 0, 0.18, 0.3199999998, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] - */ - let bonds = SubtensorModule::get_bonds(netuid); - for (i, target_bond) in [0, 0, 2808, 3744].iter().enumerate() { - assert_eq!(bonds[i][4], *target_bond); - } - - // === Set self-weight only on val2 - let uid = 1; - assert_ok!(SubtensorModule::set_weights( - RuntimeOrigin::signed(U256::from(uid)), - netuid, - vec![uid], - vec![u16::MAX], - 0 - )); - next_block(); - if sparse { - SubtensorModule::epoch(netuid, 1_000_000_000); - } else { - SubtensorModule::epoch_dense(netuid, 1_000_000_000); - } - /* current_block: 5 - Block at registration: [1, 1, 1, 1, 1, 1, 1, 1] - Active Stake: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] - Weights: [[(0, 65535)], [(1, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - Weights (permit): [[(0, 65535)], [(1, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - Weights (mask+norm): [[], [], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] - Ranks (before): [0, 0, 0, 0, 0.0699982906, 0.1400008542, 0.2099948723, 0.2800059812] - Consensus: [0, 0, 0, 0, 0.0999975584, 0.2000012207, 0.2999926754, 0.400008545] - Clipped Weights: [[], [], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] - Validator Trust: [0, 0, 0.9999999995, 0.9999999995, 0, 0, 0, 0] - Ranks (after): [0, 0, 0, 0, 0.0699982906, 0.1400008542, 0.2099948723, 0.2800059812] - Trust: [0, 0, 0, 0, 1, 1, 1, 1] - Incentive (=Rank): [0, 0, 0, 0, 0.0999975582, 0.2000012207, 0.2999926754, 0.4000085455] - Bonds: [[], [], [(4, 0.0428473335), (5, 0.0428473335), (6, 0.0428473335), (7, 0.0428473335)], [(4, 0.057129778), (5, 0.057129778), (6, 0.057129778), (7, 0.057129778)], [], [], [], []] - Bonds: (mask) [[], [], [], [], [], [], [], []] - weights_for_bonds: [[], [], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] - ΔB: [[], [], [(4, 0.428571427), (5, 0.4285714284), (6, 0.4285714284), (7, 0.4285714284)], [(4, 0.5714285728), (5, 0.5714285714), (6, 0.5714285714), (7, 0.5714285714)], [], [], [], []] - emaB: [[], [], [(4, 0.0428571426), (5, 0.0428571429), (6, 0.0428571429), (7, 0.0428571429)], [(4, 0.0571428572), (5, 0.057142857), (6, 0.057142857), (7, 0.057142857)], [], [], [], []] - emaB norm: [[], [], [(4, 0.4285714268), (5, 0.428571429), (6, 0.428571429), (7, 0.428571429)], [(4, 0.571428573), (5, 0.5714285707), (6, 0.5714285707), (7, 0.5714285707)], [], [], [], []] - total_bonds_per_validator: [0, 0, 0.4285714284, 0.5714285704, 0, 0, 0, 0] - Dividends: [0, 0, 0.36, 0.6399999997, 0, 0, 0, 0] - Normalized Server Emission: [0, 0, 0, 0, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] - Server Emission: [0, 0, 0, 0, 49998779, 100000610, 149996337, 200004272] - Normalized Validator Emission: [0, 0, 0.18, 0.3199999998, 0, 0, 0, 0] - Validator Emission: [0, 0, 179999999, 319999999, 0, 0, 0, 0] - Normalized Combined Emission: [0, 0, 0.18, 0.3199999998, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] - Combined Emission: [0, 0, 179999999, 319999999, 49998779, 100000610, 149996337, 200004272] - Pruning Scores: [0, 0, 0.18, 0.3199999998, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] - */ - let bonds = SubtensorModule::get_bonds(netuid); - for (i, target_bond) in [0, 0, 2808, 3744].iter().enumerate() { - assert_eq!(bonds[i][7], *target_bond); - } - - // === Set val3->srv4: 1 - assert_ok!(SubtensorModule::set_weights( - RuntimeOrigin::signed(U256::from(2)), - netuid, - vec![7], - vec![u16::MAX], - 0 - )); - next_block(); - if sparse { - SubtensorModule::epoch(netuid, 1_000_000_000); - } else { - SubtensorModule::epoch_dense(netuid, 1_000_000_000); - } - /* current_block: 6 - Block at registration: [1, 1, 1, 1, 1, 1, 1, 1] - Active Stake: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] - Weights: [[(0, 65535)], [(1, 65535)], [(7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - Weights (permit): [[(0, 65535)], [(1, 65535)], [(7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - Weights (mask+norm): [[], [], [(7, 1)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] - Ranks (before): [0, 0, 0, 0, 0.0399990233, 0.080000488, 0.11999707, 0.4600034177] - Consensus: [0, 0, 0, 0, 0, 0, 0, 0.400008545] - Clipped Weights: [[], [], [(7, 0.400008545)], [(7, 0.400008545)], [], [], [], []] - Validator Trust: [0, 0, 0.400008545, 0.400008545, 0, 0, 0, 0] - Ranks (after): [0, 0, 0, 0, 0, 0, 0, 0.2800059812] - Trust: [0, 0, 0, 0, 0, 0, 0, 0.6087041323] - Incentive (=Rank): [0, 0, 0, 0, 0, 0, 0, 1] - Bonds: [[], [], [(4, 0.0428473335), (5, 0.0428473335), (6, 0.0428473335), (7, 0.0428473335)], [(4, 0.057129778), (5, 0.057129778), (6, 0.057129778), (7, 0.057129778)], [], [], [], []] - Bonds: (mask) [[], [], [], [], [], [], [], []] - weights_for_bonds: [[], [], [(7, 0.400008545)], [(7, 0.400008545)], [], [], [], []] - ΔB: [[], [], [(7, 0.4285714284)], [(7, 0.5714285714)], [], [], [], []] - emaB: [[], [], [(7, 0.0428571429)], [(7, 0.057142857)], [], [], [], []] - emaB norm: [[], [], [(7, 0.428571429)], [(7, 0.5714285707)], [], [], [], []] - total_bonds_per_validator: [0, 0, 0.428571429, 0.5714285707, 0, 0, 0, 0] - Dividends: [0, 0, 0.3600000006, 0.6399999992, 0, 0, 0, 0] - Normalized Server Emission: [0, 0, 0, 0, 0, 0, 0, 0.5] - Server Emission: [0, 0, 0, 0, 0, 0, 0, 500000000] - Normalized Validator Emission: [0, 0, 0.1800000002, 0.3199999996, 0, 0, 0, 0] - Validator Emission: [0, 0, 180000000, 319999999, 0, 0, 0, 0] - Normalized Combined Emission: [0, 0, 0.1800000002, 0.3199999996, 0, 0, 0, 0.5] - Combined Emission: [0, 0, 180000000, 319999999, 0, 0, 0, 500000000] - Pruning Scores: [0, 0, 0.1800000002, 0.3199999996, 0, 0, 0, 0.5] - */ - let bonds = SubtensorModule::get_bonds(netuid); - - for (i, target_bond) in [0, 0, 2808, 3744].iter().enumerate() { - assert_eq!(bonds[i][7], *target_bond); - } - next_block(); - if sparse { - SubtensorModule::epoch(netuid, 1_000_000_000); - } else { - SubtensorModule::epoch_dense(netuid, 1_000_000_000); - } - /* current_block: 7 - Block at registration: [1, 1, 1, 1, 1, 1, 1, 1] - Active Stake: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] - Weights: [[(0, 65535)], [(1, 65535)], [(7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - Weights (permit): [[(0, 65535)], [(1, 65535)], [(7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - Weights (mask+norm): [[], [], [(7, 1)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] - Ranks (before): [0, 0, 0, 0, 0.0399990233, 0.080000488, 0.11999707, 0.4600034177] - Consensus: [0, 0, 0, 0, 0, 0, 0, 0.400008545] - Clipped Weights: [[], [], [(7, 0.400008545)], [(7, 0.400008545)], [], [], [], []] - Validator Trust: [0, 0, 0.400008545, 0.400008545, 0, 0, 0, 0] - Ranks (after): [0, 0, 0, 0, 0, 0, 0, 0.2800059812] - Trust: [0, 0, 0, 0, 0, 0, 0, 0.6087041323] - Incentive (=Rank): [0, 0, 0, 0, 0, 0, 0, 1] - Bonds: [[], [], [(7, 0.0428473335)], [(7, 0.057129778)], [], [], [], []] - Bonds: (mask) [[], [], [], [], [], [], [], []] - weights_for_bonds: [[], [], [(7, 0.400008545)], [(7, 0.400008545)], [], [], [], []] - ΔB: [[], [], [(7, 0.4285714284)], [(7, 0.5714285714)], [], [], [], []] - emaB: [[], [], [(7, 0.0428571429)], [(7, 0.057142857)], [], [], [], []] - emaB norm: [[], [], [(7, 0.428571429)], [(7, 0.5714285707)], [], [], [], []] - total_bonds_per_validator: [0, 0, 0.428571429, 0.5714285707, 0, 0, 0, 0] - Dividends: [0, 0, 0.3600000006, 0.6399999992, 0, 0, 0, 0] - Normalized Server Emission: [0, 0, 0, 0, 0, 0, 0, 0.5] - Server Emission: [0, 0, 0, 0, 0, 0, 0, 500000000] - Normalized Validator Emission: [0, 0, 0.1800000002, 0.3199999996, 0, 0, 0, 0] - Validator Emission: [0, 0, 180000000, 319999999, 0, 0, 0, 0] - Normalized Combined Emission: [0, 0, 0.1800000002, 0.3199999996, 0, 0, 0, 0.5] - Combined Emission: [0, 0, 180000000, 319999999, 0, 0, 0, 500000000] - Pruning Scores: [0, 0, 0.1800000002, 0.3199999996, 0, 0, 0, 0.5] - */ - let bonds = SubtensorModule::get_bonds(netuid); - for (i, target_bond) in [0, 0, 2808, 3744].iter().enumerate() { - assert_eq!(bonds[i][7], *target_bond); - } - - next_block(); - if sparse { - SubtensorModule::epoch(netuid, 1_000_000_000); - } else { - SubtensorModule::epoch_dense(netuid, 1_000_000_000); - } - /* current_block: 8 - Block at registration: [1, 1, 1, 1, 1, 1, 1, 1] - Active Stake: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] - Weights: [[(0, 65535)], [(1, 65535)], [(7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - Weights (permit): [[(0, 65535)], [(1, 65535)], [(7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - Weights (mask+norm): [[], [], [(7, 1)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] - Ranks (before): [0, 0, 0, 0, 0.0399990233, 0.080000488, 0.11999707, 0.4600034177] - Consensus: [0, 0, 0, 0, 0, 0, 0, 0.400008545] - Clipped Weights: [[], [], [(7, 0.400008545)], [(7, 0.400008545)], [], [], [], []] - Validator Trust: [0, 0, 0.400008545, 0.400008545, 0, 0, 0, 0] - Ranks (after): [0, 0, 0, 0, 0, 0, 0, 0.2800059812] - Trust: [0, 0, 0, 0, 0, 0, 0, 0.6087041323] - Incentive (=Rank): [0, 0, 0, 0, 0, 0, 0, 1] - Bonds: [[], [], [(7, 0.0428473335)], [(7, 0.057129778)], [], [], [], []] - Bonds: (mask) [[], [], [], [], [], [], [], []] - weights_for_bonds: [[], [], [(7, 0.400008545)], [(7, 0.400008545)], [], [], [], []] - ΔB: [[], [], [(7, 0.4285714284)], [(7, 0.5714285714)], [], [], [], []] - emaB: [[], [], [(7, 0.0428571429)], [(7, 0.057142857)], [], [], [], []] - emaB norm: [[], [], [(7, 0.428571429)], [(7, 0.5714285707)], [], [], [], []] - total_bonds_per_validator: [0, 0, 0.428571429, 0.5714285707, 0, 0, 0, 0] - Dividends: [0, 0, 0.3600000006, 0.6399999992, 0, 0, 0, 0] - Normalized Server Emission: [0, 0, 0, 0, 0, 0, 0, 0.5] - Server Emission: [0, 0, 0, 0, 0, 0, 0, 500000000] - Normalized Validator Emission: [0, 0, 0.1800000002, 0.3199999996, 0, 0, 0, 0] - Validator Emission: [0, 0, 180000000, 319999999, 0, 0, 0, 0] - Normalized Combined Emission: [0, 0, 0.1800000002, 0.3199999996, 0, 0, 0, 0.5] - Combined Emission: [0, 0, 180000000, 319999999, 0, 0, 0, 500000000] - Pruning Scores: [0, 0, 0.1800000002, 0.3199999996, 0, 0, 0, 0.5] - */ - let bonds = SubtensorModule::get_bonds(netuid); - for (i, target_bond) in [0, 0, 2808, 3744].iter().enumerate() { - assert_eq!(bonds[i][7], *target_bond); - } - - next_block(); - if sparse { - SubtensorModule::epoch(netuid, 1_000_000_000); - } else { - SubtensorModule::epoch_dense(netuid, 1_000_000_000); - } - }); -} - -// SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --package pallet-subtensor --lib -- tests::epoch::test_512_graph_random_weights --exact --show-output --nocapture -#[test] -fn test_bonds_with_liquid_alpha() { - new_test_ext(1).execute_with(|| { - let sparse: bool = true; - let n: u16 = 8; - let netuid: u16 = 1; - let tempo: u16 = 1; - let max_stake: u64 = 4; - let stakes: Vec = vec![1, 2, 3, 4, 0, 0, 0, 0]; - let block_number = System::block_number(); - add_network(netuid, tempo, 0); - SubtensorModule::set_max_allowed_uids(netuid, n); - SubtensorModule::set_max_registrations_per_block(netuid, n); - SubtensorModule::set_target_registrations_per_interval(netuid, n); - SubtensorModule::set_weights_set_rate_limit(netuid, 0); - SubtensorModule::set_min_allowed_weights(netuid, 1); - SubtensorModule::set_max_weight_limit(netuid, u16::MAX); - - // Register validators and servers - for key in 0..n as u64 { - SubtensorModule::add_balance_to_coldkey_account(&U256::from(key), max_stake); - let (nonce, work): (u64, Vec) = SubtensorModule::create_work_for_block_number( - netuid, - block_number, - key * 1_000_000, - &U256::from(key), - ); - assert_ok!(SubtensorModule::register( - RuntimeOrigin::signed(U256::from(key)), - netuid, - block_number, - nonce, - work, - U256::from(key), - U256::from(key) - )); - SubtensorModule::increase_stake_for_hotkey_and_coldkey_on_subnet( - &U256::from(key), - &U256::from(key), - netuid, - stakes[key as usize], - ); - } + add_network(netuid, tempo, 0); + SubtensorModule::set_max_allowed_uids( netuid, n ); + assert_eq!(SubtensorModule::get_max_allowed_uids(netuid), n); + SubtensorModule::set_max_registrations_per_block( netuid, n ); + SubtensorModule::set_target_registrations_per_interval(netuid, n); + SubtensorModule::set_weights_set_rate_limit( netuid, 0 ); + SubtensorModule::set_min_allowed_weights( netuid, 1 ); + SubtensorModule::set_max_weight_limit( netuid, u16::MAX ); + SubtensorModule::set_bonds_penalty(netuid, u16::MAX); + + + // === Register [validator1, validator2, validator3, validator4, server1, server2, server3, server4] + for key in 0..n as u64 { + SubtensorModule::add_balance_to_coldkey_account( &U256::from(key), max_stake ); + let (nonce, work): (u64, Vec) = SubtensorModule::create_work_for_block_number( netuid, block_number, key * 1_000_000, &U256::from(key)); + assert_ok!(SubtensorModule::register(<::RuntimeOrigin>::signed(U256::from(key)), netuid, block_number, nonce, work, U256::from(key), U256::from(key))); + SubtensorModule::increase_stake_for_hotkey_and_coldkey_on_subnet( &U256::from(key), &U256::from(key), netuid, stakes[key as usize] ); + } + assert_eq!(SubtensorModule::get_max_allowed_uids(netuid), n); + assert_eq!(SubtensorModule::get_subnetwork_n(netuid), n); + + // === Issue validator permits + SubtensorModule::set_max_allowed_validators(netuid, n); + assert_eq!( SubtensorModule::get_max_allowed_validators(netuid), n); + SubtensorModule::epoch( netuid, 1_000_000_000 ); // run first epoch to set allowed validators + next_block_no_epoch(netuid); // run to next block to ensure weights are set on nodes after their registration block - // Initilize with first epoch - SubtensorModule::epoch(netuid, 1_000_000_000); + // === Set weights [val->srv1: 0.1, val->srv2: 0.2, val->srv3: 0.3, val->srv4: 0.4] + for uid in 0..(n/2) as u64 { + assert_ok!(SubtensorModule::set_weights(RuntimeOrigin::signed(U256::from(uid)), netuid, ((n/2)..n).collect(), vec![ u16::MAX/4, u16::MAX/2, (u16::MAX/4)*3, u16::MAX], 0)); + } + if sparse { SubtensorModule::epoch( netuid, 1_000_000_000 ); } + else { SubtensorModule::epoch_dense( netuid, 1_000_000_000 ); } + /* n: 8 + current_block: 1; activity_cutoff: 5000; Last update: [1, 1, 1, 1, 0, 0, 0, 0] + Inactive: [false, false, false, false, false, false, false, false] + Block at registration: [0, 0, 0, 0, 0, 0, 0, 0] + hotkeys: [(0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7)] + S: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] + validator_permits: [true, true, true, true, true, true, true, true] + max_allowed_validators: 8 + new_validator_permits: [true, true, true, true, true, true, true, true] + S: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] + W: [[(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + W (permit): [[(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + W (permit+diag): [[(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + W (permit+diag+outdate): [[(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + W (mask+norm): [[(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] + R (before): [0, 0, 0, 0, 0.099997558, 0.2000012202, 0.2999926745, 0.4000085443] + C: [0, 0, 0, 0, 0.0999975584, 0.2000012207, 0.2999926754, 0.400008545] + W: [[(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] + Tv: [0.9999999995, 0.9999999995, 0.9999999995, 0.9999999995, 0, 0, 0, 0] + R (after): [0, 0, 0, 0, 0.099997558, 0.2000012202, 0.2999926745, 0.4000085443] + T: [0, 0, 0, 0, 1, 1, 1, 1] + I (=R): [0, 0, 0, 0, 0.0999975582, 0.2000012207, 0.2999926752, 0.4000085455] + B: [[], [], [], [], [], [], [], []] + B (outdatedmask): [[], [], [], [], [], [], [], []] + B (mask+norm): [[], [], [], [], [], [], [], []] + ΔB: [[(4, 0.0099997558), (5, 0.020000122), (6, 0.0299992673), (7, 0.0400008543)], [(4, 0.0199995115), (5, 0.040000244), (6, 0.0599985349), (7, 0.0800017088)], [(4, 0.0299992673), (5, 0.060000366), (6, 0.0899978024), (7, 0.1200025633)], [(4, 0.0399990233), (5, 0.080000488), (6, 0.11999707), (7, 0.1600034179)], [], [], [], []] + ΔB (norm): [[(4, 0.0999999996), (5, 0.0999999999), (6, 0.0999999994), (7, 0.0999999996)], [(4, 0.1999999995), (5, 0.2), (6, 0.1999999997), (7, 0.1999999997)], [(4, 0.299999999), (5, 0.2999999998), (6, 0.3), (7, 0.3)], [(4, 0.4000000013), (5, 0.4), (6, 0.4000000004), (7, 0.4000000001)], [], [], [], []] + emaB: [[(4, 0.0999999982), (5, 0.0999999985), (6, 0.099999998), (7, 0.099999998)], [(4, 0.199999999), (5, 0.1999999995), (6, 0.1999999986), (7, 0.1999999986)], [(4, 0.2999999996), (5, 0.3000000003), (6, 0.3000000012), (7, 0.3000000012)], [(4, 0.4000000027), (5, 0.4000000013), (6, 0.4000000018), (7, 0.4000000018)], [], [], [], []] + D: [0.0999999978, 0.1999999983, 0.3000000012, 0.4000000022, 0, 0, 0, 0] + nE: [0.0499999989, 0.0999999992, 0.1500000006, 0.2000000011, 0.049998779, 0.1000006103, 0.1499963375, 0.2000042726] + E: [49999998, 99999999, 150000000, 200000001, 49998779, 100000610, 149996337, 200004272] + P: [0.0499999989, 0.0999999992, 0.1500000006, 0.2000000011, 0.049998779, 0.1000006103, 0.1499963375, 0.2000042726] + emaB: [[(4, 0.2499999937), (5, 0.2499999953), (6, 0.2499999937), (7, 0.2499999937)], [(4, 0.4999999942), (5, 0.499999997), (6, 0.4999999942), (7, 0.4999999942)], [(4, 0.7499999937), (5, 0.7499999981), (6, 0.7499999995), (7, 0.7499999995)], [(4, 1), (5, 1), (6, 1), (7, 1)], [], [], [], []] */ + let bonds = SubtensorModule::get_bonds( netuid ); + assert_eq!(bonds[0][4], 16383); + assert_eq!(bonds[1][4], 32767); + assert_eq!(bonds[2][4], 49151); + assert_eq!(bonds[3][4], 65535); + + // === Set self-weight only on val1 + let uid = 0; + assert_ok!(SubtensorModule::set_weights(RuntimeOrigin::signed(U256::from(uid)), netuid, vec![uid], vec![u16::MAX], 0)); next_block_no_epoch(netuid); - // Set weights - for uid in 0..(n / 2) { - SubtensorModule::set_validator_permit_for_uid(netuid, uid, true); - assert_ok!(SubtensorModule::set_weights( - RuntimeOrigin::signed(U256::from(uid)), - netuid, - ((n / 2)..n).collect(), - vec![u16::MAX / 4, u16::MAX / 2, (u16::MAX / 4) * 3, u16::MAX], - 0 - )); - } + if sparse { SubtensorModule::epoch( netuid, 1_000_000_000 ); } + else { SubtensorModule::epoch_dense( netuid, 1_000_000_000 ); } + /* n: 8 + current_block: 2 + activity_cutoff: 5000 + Last update: [1, 1, 1, 1, 0, 0, 0, 0] + Inactive: [false, false, false, false, false, false, false, false] + Block at registration: [0, 0, 0, 0, 0, 0, 0, 0] + hotkeys: [(0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7)] + S: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] + validator_permits: [true, true, true, true, true, true, true, true] + max_allowed_validators: 8 + new_validator_permits: [true, true, true, true, true, true, true, true] + S: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] + W: [[(0, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + W (permit): [[(0, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + W (permit+diag): [[], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + W (permit+diag+outdate): [[], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + W (mask+norm): [[], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] + R (before): [0, 0, 0, 0, 0.0899978022, 0.1800010982, 0.2699934072, 0.36000769] + C: [0, 0, 0, 0, 0.0999975584, 0.2000012207, 0.2999926754, 0.400008545] + W: [[], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] + Tv: [0, 0.9999999995, 0.9999999995, 0.9999999995, 0, 0, 0, 0] + R (after): [0, 0, 0, 0, 0.0899978022, 0.1800010982, 0.2699934072, 0.36000769] + T: [0, 0, 0, 0, 1, 1, 1, 1] + I (=R): [0, 0, 0, 0, 0.0999975582, 0.2000012207, 0.2999926754, 0.4000085455] + B: [[(4, 16383), (5, 16383), (6, 16383), (7, 16383)], [(4, 32767), (5, 32767), (6, 32767), (7, 32767)], [(4, 49151), (5, 49151), (6, 49151), (7, 49151)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [], [], [], []] + B (outdatedmask): [[(4, 16383), (5, 16383), (6, 16383), (7, 16383)], [(4, 32767), (5, 32767), (6, 32767), (7, 32767)], [(4, 49151), (5, 49151), (6, 49151), (7, 49151)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [], [], [], []] + B (mask+norm): [[(4, 0.0999963377), (5, 0.0999963377), (6, 0.0999963377), (7, 0.0999963377)], [(4, 0.1999987792), (5, 0.1999987792), (6, 0.1999987792), (7, 0.1999987792)], [(4, 0.3000012205), (5, 0.3000012205), (6, 0.3000012205), (7, 0.3000012205)], [(4, 0.400003662), (5, 0.400003662), (6, 0.400003662), (7, 0.400003662)], [], [], [], []] + ΔB: [[], [(4, 0.0199995115), (5, 0.040000244), (6, 0.0599985349), (7, 0.0800017088)], [(4, 0.0299992673), (5, 0.060000366), (6, 0.0899978024), (7, 0.1200025633)], [(4, 0.0399990233), (5, 0.080000488), (6, 0.11999707), (7, 0.1600034179)], [], [], [], []] + ΔB (norm): [[], [(4, 0.2222222215), (5, 0.222222222), (6, 0.2222222218), (7, 0.2222222218)], [(4, 0.3333333323), (5, 0.3333333333), (6, 0.3333333333), (7, 0.3333333333)], [(4, 0.4444444457), (5, 0.4444444443), (6, 0.4444444447), (7, 0.4444444445)], [], [], [], []] + emaB: [[(4, 0.0899967037), (5, 0.0899967037), (6, 0.0899967037), (7, 0.0899967037)], [(4, 0.2022211235), (5, 0.2022211235), (6, 0.2022211235), (7, 0.2022211235)], [(4, 0.3033344317), (5, 0.3033344317), (6, 0.3033344317), (7, 0.3033344317)], [(4, 0.4044477409), (5, 0.4044477406), (6, 0.4044477406), (7, 0.4044477406)], [], [], [], []] + D: [0.0899967032, 0.2022211233, 0.303334432, 0.404447741, 0, 0, 0, 0] + nE: [0.0449983515, 0.1011105615, 0.1516672159, 0.2022238704, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] + E: [44998351, 101110561, 151667215, 202223870, 49998779, 100000610, 149996337, 200004272] + P: [0.0449983515, 0.1011105615, 0.1516672159, 0.2022238704, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] + emaB: [[(4, 0.2225175085), (5, 0.2225175085), (6, 0.2225175085), (7, 0.2225175085)], [(4, 0.499993208), (5, 0.4999932083), (6, 0.4999932083), (7, 0.4999932083)], [(4, 0.7499966028), (5, 0.7499966032), (6, 0.7499966032), (7, 0.7499966032)], [(4, 1), (5, 1), (6, 1), (7, 1)], [], [], [], []] */ + let bonds = SubtensorModule::get_bonds( netuid ); + assert_eq!(bonds[0][4], 14582); + assert_eq!(bonds[1][4], 32767); + assert_eq!(bonds[2][4], 49151); + assert_eq!(bonds[3][4], 65535); + + // === Set self-weight only on val2 + let uid = 1; + assert_ok!(SubtensorModule::set_weights(RuntimeOrigin::signed(U256::from(uid)), netuid, vec![uid], vec![u16::MAX], 0)); + next_block_no_epoch(netuid); - // Enable Liquid Alpha - SubtensorModule::set_liquid_alpha_enabled(netuid, true); - // Run epoch with Liquid Alpha - if sparse { - SubtensorModule::epoch(netuid, 1_000_000_000); - } else { - SubtensorModule::epoch_dense(netuid, 1_000_000_000); - } + if sparse { SubtensorModule::epoch( netuid, 1_000_000_000 ); } + else { SubtensorModule::epoch_dense( netuid, 1_000_000_000 ); } + /* current_block: 3 + W: [[(0, 65535)], [(1, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + W (permit): [[(0, 65535)], [(1, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + W (permit+diag): [[], [], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + W (permit+diag+outdate): [[], [], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + W (mask+norm): [[], [], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] + R (before): [0, 0, 0, 0, 0.0699982906, 0.1400008542, 0.2099948723, 0.2800059812] + C: [0, 0, 0, 0, 0.0999975584, 0.2000012207, 0.2999926754, 0.400008545] + W: [[], [], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] + Tv: [0, 0, 0.9999999995, 0.9999999995, 0, 0, 0, 0] + R (after): [0, 0, 0, 0, 0.0699982906, 0.1400008542, 0.2099948723, 0.2800059812] + T: [0, 0, 0, 0, 1, 1, 1, 1] + I (=R): [0, 0, 0, 0, 0.0999975582, 0.2000012207, 0.2999926754, 0.4000085455] + B: [[(4, 14582), (5, 14582), (6, 14582), (7, 14582)], [(4, 32767), (5, 32767), (6, 32767), (7, 32767)], [(4, 49151), (5, 49151), (6, 49151), (7, 49151)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [], [], [], []] + B (outdatedmask): [[(4, 14582), (5, 14582), (6, 14582), (7, 14582)], [(4, 32767), (5, 32767), (6, 32767), (7, 32767)], [(4, 49151), (5, 49151), (6, 49151), (7, 49151)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [], [], [], []] + B (mask+norm): [[(4, 0.0899929027), (5, 0.0899929027), (6, 0.0899929027), (7, 0.0899929027)], [(4, 0.2022217421), (5, 0.2022217421), (6, 0.2022217421), (7, 0.2022217421)], [(4, 0.303335699), (5, 0.303335699), (6, 0.303335699), (7, 0.303335699)], [(4, 0.404449656), (5, 0.404449656), (6, 0.404449656), (7, 0.404449656)], [], [], [], []] + ΔB: [[], [], [(4, 0.0299992673), (5, 0.060000366), (6, 0.0899978024), (7, 0.1200025633)], [(4, 0.0399990233), (5, 0.080000488), (6, 0.11999707), (7, 0.1600034179)], [], [], [], []] + ΔB (norm): [[], [], [(4, 0.428571427), (5, 0.4285714284), (6, 0.4285714284), (7, 0.4285714284)], [(4, 0.5714285728), (5, 0.5714285714), (6, 0.5714285714), (7, 0.5714285714)], [], [], [], []] + emaB: [[(4, 0.0809936123), (5, 0.0809936123), (6, 0.0809936123), (7, 0.0809936123)], [(4, 0.181999568), (5, 0.181999568), (6, 0.181999568), (7, 0.181999568)], [(4, 0.3158592717), (5, 0.315859272), (6, 0.315859272), (7, 0.315859272)], [(4, 0.4211475477), (5, 0.4211475474), (6, 0.4211475474), (7, 0.4211475474)], [], [], [], []] + D: [0.0809936118, 0.1819995677, 0.3158592721, 0.421147548, 0, 0, 0, 0] + nE: [0.040496806, 0.0909997837, 0.157929636, 0.2105737738, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] + E: [40496805, 90999783, 157929636, 210573773, 49998779, 100000610, 149996337, 200004272] + P: [0.040496806, 0.0909997837, 0.157929636, 0.2105737738, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] + emaB: [[(4, 0.192316476), (5, 0.192316476), (6, 0.192316476), (7, 0.192316476)], [(4, 0.4321515555), (5, 0.4321515558), (6, 0.4321515558), (7, 0.4321515558)], [(4, 0.7499967015), (5, 0.7499967027), (6, 0.7499967027), (7, 0.7499967027)], [(4, 1), (5, 1), (6, 1), (7, 1)], [], [], [], []] */ + let bonds = SubtensorModule::get_bonds( netuid ); + assert_eq!(bonds[0][4], 12603); + assert_eq!(bonds[1][4], 28321); + assert_eq!(bonds[2][4], 49151); + assert_eq!(bonds[3][4], 65535); + + // === Set self-weight only on val3 + let uid = 2; + assert_ok!(SubtensorModule::set_weights(RuntimeOrigin::signed(U256::from(uid)), netuid, vec![uid], vec![u16::MAX], 0)); + next_block_no_epoch(netuid); - // Check bonds and emissions - let bonds = SubtensorModule::get_bonds(netuid); + if sparse { SubtensorModule::epoch( netuid, 1_000_000_000 ); } + else { SubtensorModule::epoch_dense( netuid, 1_000_000_000 ); } + /* current_block: 4 + W: [[(0, 65535)], [(1, 65535)], [(2, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + W (permit): [[(0, 65535)], [(1, 65535)], [(2, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + W (permit+diag): [[], [], [], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + W (permit+diag+outdate): [[], [], [], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + W (mask+norm): [[], [], [], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] + R (before): [0, 0, 0, 0, 0.0399990233, 0.080000488, 0.11999707, 0.1600034179] + C: [0, 0, 0, 0, 0, 0, 0, 0] + W: [[], [], [], [], [], [], [], []] + Tv: [0, 0, 0, 0, 0, 0, 0, 0] + R (after): [0, 0, 0, 0, 0, 0, 0, 0] + T: [0, 0, 0, 0, 0, 0, 0, 0] + I (=R): [0, 0, 0, 0, 0, 0, 0, 0] + B: [[(4, 12603), (5, 12603), (6, 12603), (7, 12603)], [(4, 28321), (5, 28321), (6, 28321), (7, 28321)], [(4, 49151), (5, 49151), (6, 49151), (7, 49151)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [], [], [], []] + B (outdatedmask): [[(4, 12603), (5, 12603), (6, 12603), (7, 12603)], [(4, 28321), (5, 28321), (6, 28321), (7, 28321)], [(4, 49151), (5, 49151), (6, 49151), (7, 49151)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [], [], [], []] + B (mask+norm): [[(4, 0.0809909387), (5, 0.0809909387), (6, 0.0809909387), (7, 0.0809909387)], [(4, 0.1819998713), (5, 0.1819998713), (6, 0.1819998713), (7, 0.1819998713)], [(4, 0.3158601632), (5, 0.3158601632), (6, 0.3158601632), (7, 0.3158601632)], [(4, 0.4211490264), (5, 0.4211490264), (6, 0.4211490264), (7, 0.4211490264)], [], [], [], []] + ΔB: [[], [], [], [], [], [], [], []] + ΔB (norm): [[], [], [], [], [], [], [], []] + emaB: [[(4, 0.0809909385), (5, 0.0809909385), (6, 0.0809909385), (7, 0.0809909385)], [(4, 0.1819998713), (5, 0.1819998713), (6, 0.1819998713), (7, 0.1819998713)], [(4, 0.3158601632), (5, 0.3158601632), (6, 0.3158601632), (7, 0.3158601632)], [(4, 0.4211490266), (5, 0.4211490266), (6, 0.4211490266), (7, 0.4211490266)], [], [], [], []] + D: [0, 0, 0, 0, 0, 0, 0, 0] + nE: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] + E: [99999999, 199999999, 299999999, 399999999, 0, 0, 0, 0] + P: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] + emaB: [[(4, 0.1923094518), (5, 0.1923094518), (6, 0.1923094518), (7, 0.1923094518)], [(4, 0.4321507583), (5, 0.4321507583), (6, 0.4321507583), (7, 0.4321507583)], [(4, 0.7499961846), (5, 0.7499961846), (6, 0.7499961846), (7, 0.7499961846)], [(4, 1), (5, 1), (6, 1), (7, 1)], [], [], [], []] */ + let bonds = SubtensorModule::get_bonds( netuid ); + assert_eq!(bonds[0][7], 12602); + assert_eq!(bonds[1][7], 28320); + assert_eq!(bonds[2][7], 49150); + assert_eq!(bonds[3][7], 65535); + + // === Set val3->srv4: 1 + assert_ok!(SubtensorModule::set_weights(RuntimeOrigin::signed(U256::from(2)), netuid, vec![7], vec![u16::MAX], 0)); + next_block_no_epoch(netuid); - /* n: 8 - current_block: 3 - activity_cutoff: 5000 - Last update: [2, 2, 2, 2, 1, 1, 1, 1] - Block at registration: [1, 1, 1, 1, 1, 1, 1, 1] - validator_permits: [true, true, true, true, true, true, true, true] - max_allowed_validators: 64 - new_validator_permits: [true, true, true, true, true, true, true, true] - Active Stake: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] - Weights: [[(0, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - Weights (permit): [[(0, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - Weights (permit+diag): [[], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - Weights (permit+diag+outdate): [[], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - Weights (mask+norm): [[], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] - Ranks (before): [0, 0, 0, 0, 0.0899978022, 0.1800010982, 0.2699934072, 0.36000769] - Consensus: [0, 0, 0, 0, 0.0999975584, 0.2000012207, 0.2999926754, 0.400008545] - Clipped Weights: [[], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] - Validator Trust: [0, 0.9999999995, 0.9999999995, 0.9999999995, 0, 0, 0, 0] - Ranks (after): [0, 0, 0, 0, 0.0899978022, 0.1800010982, 0.2699934072, 0.36000769] - Trust: [0, 0, 0, 0, 1, 1, 1, 1] - Incentive (=Rank): [0, 0, 0, 0, 0.0999975582, 0.2000012207, 0.2999926754, 0.4000085455] - Bonds: [[(4, 4596), (5, 9192), (6, 13788), (7, 18385)], [(4, 4596), (5, 9192), (6, 13788), (7, 18385)], [(4, 4596), (5, 9192), (6, 13788), (7, 18385)], [(4, 4596), (5, 9192), (6, 13788), (7, 18385)], [], [], [], []] - Bonds: (mask+norm) [[(4, 0.0701304646), (5, 0.1402609292), (6, 0.2103913939), (7, 0.2805371175)], [(4, 0.0701304646), (5, 0.1402609292), (6, 0.2103913939), (7, 0.2805371175)], [(4, 0.0701304646), (5, 0.1402609292), (6, 0.2103913939), (7, 0.2805371175)], [(4, 0.0701304646), (5, 0.1402609292), (6, 0.2103913939), (7, 0.2805371175)], [], [], [], []] - weights_for_bonds: [[], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] - alphas: [[0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7026884612, 0.7053405554, 0.7104771058, 0.7200544013], [0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993], [0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993], [0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993], [0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993], [0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993], [0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993], [0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993]] - emaB: [[], [(4, 0.0910776372), (5, 0.1821595554), (6, 0.273232912), (7, 0.364327949)], [(4, 0.0910776372), (5, 0.1821595554), (6, 0.273232912), (7, 0.364327949)], [(4, 0.0910776372), (5, 0.1821595554), (6, 0.273232912), (7, 0.364327949)], [], [], [], []] - emaB norm: [[], [(4, 0.3333333333), (5, 0.3333333333), (6, 0.3333333333), (7, 0.3333333333)], [(4, 0.3333333333), (5, 0.3333333333), (6, 0.3333333333), (7, 0.3333333333)], [(4, 0.3333333333), (5, 0.3333333333), (6, 0.3333333333), (7, 0.3333333333)], [], [], [], []] - total_bonds_per_validator: [0, 0.3333333328, 0.3333333328, 0.3333333328, 0, 0, 0, 0] - Dividends: [0, 0.222222222, 0.333333333, 0.4444444447, 0, 0, 0, 0] - Normalized Server Emission: [0, 0, 0, 0, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] - Server Emission: [0, 0, 0, 0, 49998779, 100000610, 149996337, 200004272] - Normalized Validator Emission: [0, 0.111111111, 0.1666666665, 0.2222222222, 0, 0, 0, 0] - Validator Emission: [0, 111111111, 166666666, 222222222, 0, 0, 0, 0] - Normalized Combined Emission: [0, 0.111111111, 0.1666666665, 0.2222222222, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] - Combined Emission: [0, 111111111, 166666666, 222222222, 49998779, 100000610, 149996337, 200004272] - Pruning Scores: [0, 0.111111111, 0.1666666665, 0.2222222222, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] - - */ - for (i, target_bond) in [4596, 4596, 4596, 4596].iter().enumerate() { - assert_eq!(bonds[i][4], *target_bond); - } + if sparse { SubtensorModule::epoch( netuid, 1_000_000_000 ); } + else { SubtensorModule::epoch_dense( netuid, 1_000_000_000 ); } + /* current_block: 5 + W: [[(0, 65535)], [(1, 65535)], [(7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + W (permit): [[(0, 65535)], [(1, 65535)], [(7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + W (permit+diag): [[], [], [(7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + W (permit+diag+outdate): [[], [], [(7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] + W (mask+norm): [[], [], [(7, 1)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] + R (before): [0, 0, 0, 0, 0.0399990233, 0.080000488, 0.11999707, 0.4600034177] + C: [0, 0, 0, 0, 0, 0, 0, 0.400008545] + W: [[], [], [(7, 0.400008545)], [(7, 0.400008545)], [], [], [], []] + Tv: [0, 0, 0.400008545, 0.400008545, 0, 0, 0, 0] + R (after): [0, 0, 0, 0, 0, 0, 0, 0.2800059812] + T: [0, 0, 0, 0, 0, 0, 0, 0.6087041323] + I (=R): [0, 0, 0, 0, 0, 0, 0, 1] + B: [[(4, 12602), (5, 12602), (6, 12602), (7, 12602)], [(4, 28320), (5, 28320), (6, 28320), (7, 28320)], [(4, 49150), (5, 49150), (6, 49150), (7, 49150)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [], [], [], []] + B (outdatedmask): [[(4, 12602), (5, 12602), (6, 12602), (7, 12602)], [(4, 28320), (5, 28320), (6, 28320), (7, 28320)], [(4, 49150), (5, 49150), (6, 49150), (7, 49150)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [], [], [], []] + B (mask+norm): [[(4, 0.0809860737), (5, 0.0809860737), (6, 0.0809860737), (7, 0.0809860737)], [(4, 0.1819969537), (5, 0.1819969537), (6, 0.1819969537), (7, 0.1819969537)], [(4, 0.3158598263), (5, 0.3158598263), (6, 0.3158598263), (7, 0.3158598263)], [(4, 0.4211571459), (5, 0.4211571459), (6, 0.4211571459), (7, 0.4211571459)], [], [], [], []] + ΔB: [[], [], [(7, 0.1200025633)], [(7, 0.1600034179)], [], [], [], []] + ΔB (norm): [[], [], [(7, 0.4285714284)], [(7, 0.5714285714)], [], [], [], []] + emaB: [[(4, 0.0809860737), (5, 0.0809860737), (6, 0.0809860737), (7, 0.0728874663)], [(4, 0.1819969537), (5, 0.1819969537), (6, 0.1819969537), (7, 0.1637972582)], [(4, 0.3158598263), (5, 0.3158598263), (6, 0.3158598263), (7, 0.3271309866)], [(4, 0.421157146), (5, 0.421157146), (6, 0.421157146), (7, 0.4361842885)], [], [], [], []] + D: [0.0728874663, 0.1637972582, 0.3271309866, 0.4361842885, 0, 0, 0, 0] + nE: [0.0364437331, 0.081898629, 0.1635654932, 0.2180921442, 0, 0, 0, 0.5] + E: [36443733, 81898628, 163565493, 218092144, 0, 0, 0, 500000000] + P: [0.0364437331, 0.081898629, 0.1635654932, 0.2180921442, 0, 0, 0, 0.5] + emaB: [[(4, 0.1922941932), (5, 0.1922941932), (6, 0.1922941932), (7, 0.1671024568)], [(4, 0.4321354993), (5, 0.4321354993), (6, 0.4321354993), (7, 0.3755230587)], [(4, 0.7499809256), (5, 0.7499809256), (6, 0.7499809256), (7, 0.749983425)], [(4, 1), (5, 1), (6, 1), (7, 1)], [], [], [], []] */ + let bonds = SubtensorModule::get_bonds( netuid ); + assert_eq!(bonds[0][7], 10951); + assert_eq!(bonds[1][7], 24609); + assert_eq!(bonds[2][7], 49150); + assert_eq!(bonds[3][7], 65535); - // === Set self-weight only on val1 - let uid = 0; - assert_ok!(SubtensorModule::set_weights( - RuntimeOrigin::signed(U256::from(uid)), - netuid, - vec![uid], - vec![u16::MAX], - 0 - )); next_block_no_epoch(netuid); - if sparse { - SubtensorModule::epoch(netuid, 1_000_000_000); - } else { - SubtensorModule::epoch_dense(netuid, 1_000_000_000); - } - let bonds = SubtensorModule::get_bonds(netuid); - for (i, target_bond) in [0, 5968, 5968, 5968].iter().enumerate() { - assert_eq!(bonds[i][4], *target_bond); - } + if sparse { SubtensorModule::epoch( netuid, 1_000_000_000 ); } + else { SubtensorModule::epoch_dense( netuid, 1_000_000_000 ); } + /* current_block: 6 + B: [[(4, 12601), (5, 12601), (6, 12601), (7, 10951)], [(4, 28319), (5, 28319), (6, 28319), (7, 24609)], [(4, 49149), (5, 49149), (6, 49149), (7, 49150)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [], [], [], []] + B (outdatedmask): [[(4, 12601), (5, 12601), (6, 12601), (7, 10951)], [(4, 28319), (5, 28319), (6, 28319), (7, 24609)], [(4, 49149), (5, 49149), (6, 49149), (7, 49150)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [], [], [], []] + B (mask+norm): [[(4, 0.0809812085), (5, 0.0809812085), (6, 0.0809812085), (7, 0.0728876167)], [(4, 0.181994036), (5, 0.181994036), (6, 0.181994036), (7, 0.163792472)], [(4, 0.3158594894), (5, 0.3158594894), (6, 0.3158594894), (7, 0.3271323503)], [(4, 0.4211652656), (5, 0.4211652656), (6, 0.4211652656), (7, 0.4361875602)], [], [], [], []] + ΔB: [[], [], [(7, 0.1200025633)], [(7, 0.1600034179)], [], [], [], []] + ΔB (norm): [[], [], [(7, 0.4285714284)], [(7, 0.5714285714)], [], [], [], []] + emaB: [[(4, 0.0809812082), (5, 0.0809812082), (6, 0.0809812082), (7, 0.0655988548)], [(4, 0.181994036), (5, 0.181994036), (6, 0.181994036), (7, 0.1474132247)], [(4, 0.3158594896), (5, 0.3158594896), (6, 0.3158594896), (7, 0.3372762585)], [(4, 0.4211652658), (5, 0.4211652658), (6, 0.4211652658), (7, 0.4497116616)], [], [], [], []] + D: [0.0655988548, 0.1474132247, 0.3372762585, 0.4497116616, 0, 0, 0, 0] + nE: [0.0327994274, 0.0737066122, 0.1686381293, 0.2248558307, 0, 0, 0, 0.5] + E: [32799427, 73706612, 168638129, 224855830, 0, 0, 0, 500000000] + P: [0.0327994274, 0.0737066122, 0.1686381293, 0.2248558307, 0, 0, 0, 0.5] + emaB: [[(4, 0.1922789337), (5, 0.1922789337), (6, 0.1922789337), (7, 0.1458686984)], [(4, 0.4321202405), (5, 0.4321202405), (6, 0.4321202405), (7, 0.3277949789)], [(4, 0.749965667), (5, 0.749965667), (6, 0.749965667), (7, 0.74998335)], [(4, 1), (5, 1), (6, 1), (7, 1)], [], [], [], []] */ + let bonds = SubtensorModule::get_bonds( netuid ); + assert_eq!(bonds[0][7], 9559); + assert_eq!(bonds[1][7], 21482); + assert_eq!(bonds[2][7], 49150); + assert_eq!(bonds[3][7], 65535); - // === Set self-weight only on val2 - let uid = 1; - assert_ok!(SubtensorModule::set_weights( - RuntimeOrigin::signed(U256::from(uid)), - netuid, - vec![uid], - vec![u16::MAX], - 0 - )); next_block_no_epoch(netuid); - if sparse { - SubtensorModule::epoch(netuid, 1_000_000_000); - } else { - SubtensorModule::epoch_dense(netuid, 1_000_000_000); - } - let bonds = SubtensorModule::get_bonds(netuid); - /* n: 8 - current_block: 4 - activity_cutoff: 5000 - Last update: [2, 3, 2, 2, 1, 1, 1, 1] - Block at registration: [1, 1, 1, 1, 1, 1, 1, 1] - validator_permits: [true, true, true, true, true, true, true, true] - max_allowed_validators: 64 - new_validator_permits: [true, true, true, true, true, true, true, true] - Active Stake: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0] - Weights: [[(0, 65535)], [(1, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - Weights (permit): [[(0, 65535)], [(1, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - Weights (permit+diag): [[], [], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - Weights (permit+diag+outdate): [[], [], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [(4, 16383), (5, 32767), (6, 49149), (7, 65535)], [], [], [], []] - Weights (mask+norm): [[], [], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] - Ranks (before): [0, 0, 0, 0, 0.0699982906, 0.1400008542, 0.2099948723, 0.2800059812] - Consensus: [0, 0, 0, 0, 0.0999975584, 0.2000012207, 0.2999926754, 0.400008545] - Clipped Weights: [[], [], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] - Validator Trust: [0, 0, 0.9999999995, 0.9999999995, 0, 0, 0, 0] - Ranks (after): [0, 0, 0, 0, 0.0699982906, 0.1400008542, 0.2099948723, 0.2800059812] - Trust: [0, 0, 0, 0, 1, 1, 1, 1] - Incentive (=Rank): [0, 0, 0, 0, 0.0999975582, 0.2000012207, 0.2999926754, 0.4000085455] - Bonds: [[], [(4, 5968), (5, 11937), (6, 17906), (7, 23876)], [(4, 5968), (5, 11937), (6, 17906), (7, 23876)], [(4, 5968), (5, 11937), (6, 17906), (7, 23876)], [], [], [], []] - Bonds: (mask+norm) [[], [(4, 0.0910658427), (5, 0.1821469443), (6, 0.273228046), (7, 0.3643244067)], [(4, 0.0910658427), (5, 0.1821469443), (6, 0.273228046), (7, 0.3643244067)], [(4, 0.0910658427), (5, 0.1821469443), (6, 0.273228046), (7, 0.3643244067)], [], [], [], []] - weights_for_bonds: [[], [], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [(4, 0.0999975584), (5, 0.2000012207), (6, 0.2999926754), (7, 0.400008545)], [], [], [], []] - alphas: [[0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993], [0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7033024912, 0.7080039687, 0.718774016, 0.74096124], [0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993], [0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993], [0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993], [0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993], [0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993], [0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993, 0.7013461993]] - emaB: [[], [], [(4, 0.0973300673), (5, 0.1946689729), (6, 0.291999317), (7, 0.3893513412)], [(4, 0.0973300673), (5, 0.1946689729), (6, 0.291999317), (7, 0.3893513412)], [], [], [], []] - emaB norm: [[], [], [(4, 0.5), (5, 0.5), (6, 0.5), (7, 0.5)], [(4, 0.5), (5, 0.5), (6, 0.5), (7, 0.5)], [], [], [], []] - total_bonds_per_validator: [0, 0, 0.4999999998, 0.4999999998, 0, 0, 0, 0] - Dividends: [0, 0, 0.4285714282, 0.5714285716, 0, 0, 0, 0] - Normalized Server Emission: [0, 0, 0, 0, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] - Server Emission: [0, 0, 0, 0, 49998779, 100000610, 149996337, 200004272] - Normalized Validator Emission: [0, 0, 0.214285714, 0.2857142857, 0, 0, 0, 0] - Validator Emission: [0, 0, 214285714, 285714285, 0, 0, 0, 0] - Normalized Combined Emission: [0, 0, 0.214285714, 0.2857142857, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726] - Combined Emission: [0, 0, 214285714, 285714285, 49998779, 100000610, 149996337, 200004272] - Pruning Scores: [0, 0, 0.214285714, 0.2857142857, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726]/ - */ - - for (i, target_bond) in [0, 0, 6378, 6378].iter().enumerate() { - assert_eq!(bonds[i][4], *target_bond); - } - }); + if sparse { SubtensorModule::epoch( netuid, 1_000_000_000 ); } + else { SubtensorModule::epoch_dense( netuid, 1_000_000_000 ); } + /* current_block: 7 + B: [[(4, 12600), (5, 12600), (6, 12600), (7, 9559)], [(4, 28318), (5, 28318), (6, 28318), (7, 21482)], [(4, 49148), (5, 49148), (6, 49148), (7, 49150)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [], [], [], []] + B (outdatedmask): [[(4, 12600), (5, 12600), (6, 12600), (7, 9559)], [(4, 28318), (5, 28318), (6, 28318), (7, 21482)], [(4, 49148), (5, 49148), (6, 49148), (7, 49150)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [], [], [], []] + B (mask+norm): [[(4, 0.0809763432), (5, 0.0809763432), (6, 0.0809763432), (7, 0.065595707)], [(4, 0.1819911182), (5, 0.1819911182), (6, 0.1819911182), (7, 0.1474136391)], [(4, 0.3158591525), (5, 0.3158591525), (6, 0.3158591525), (7, 0.337276807)], [(4, 0.4211733856), (5, 0.4211733856), (6, 0.4211733856), (7, 0.4497138464)], [], [], [], []] + ΔB: [[], [], [(7, 0.1200025633)], [(7, 0.1600034179)], [], [], [], []] + ΔB (norm): [[], [], [(7, 0.4285714284)], [(7, 0.5714285714)], [], [], [], []] + emaB: [[(4, 0.080976343), (5, 0.080976343), (6, 0.080976343), (7, 0.0590361361)], [(4, 0.181991118), (5, 0.181991118), (6, 0.181991118), (7, 0.1326722752)], [(4, 0.3158591525), (5, 0.3158591525), (6, 0.3158591525), (7, 0.3464062694)], [(4, 0.4211733858), (5, 0.4211733858), (6, 0.4211733858), (7, 0.4618853189)], [], [], [], []] + D: [0.0590361361, 0.1326722752, 0.3464062694, 0.4618853189, 0, 0, 0, 0] + nE: [0.029518068, 0.0663361375, 0.1732031347, 0.2309426593, 0, 0, 0, 0.5] + E: [29518068, 66336137, 173203134, 230942659, 0, 0, 0, 500000000] + P: [0.029518068, 0.0663361375, 0.1732031347, 0.2309426593, 0, 0, 0, 0.5] + emaB: [[(4, 0.192263675), (5, 0.192263675), (6, 0.192263675), (7, 0.1278155716)], [(4, 0.4321049813), (5, 0.4321049813), (6, 0.4321049813), (7, 0.2872407278)], [(4, 0.7499504078), (5, 0.7499504078), (6, 0.7499504078), (7, 0.7499832863)], [(4, 1), (5, 1), (6, 1), (7, 1)], [], [], [], []] */ + let bonds = SubtensorModule::get_bonds( netuid ); + assert_eq!(bonds[0][7], 8376); + assert_eq!(bonds[1][7], 18824); + assert_eq!(bonds[2][7], 49150); + assert_eq!(bonds[3][7], 65535); + + next_block_no_epoch(netuid); + + if sparse { SubtensorModule::epoch( netuid, 1_000_000_000 ); } + else { SubtensorModule::epoch_dense( netuid, 1_000_000_000 ); } + /* current_block: 8 + B: [[(4, 12599), (5, 12599), (6, 12599), (7, 8376)], [(4, 28317), (5, 28317), (6, 28317), (7, 18824)], [(4, 49147), (5, 49147), (6, 49147), (7, 49150)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [], [], [], []] + B (outdatedmask): [[(4, 12599), (5, 12599), (6, 12599), (7, 8376)], [(4, 28317), (5, 28317), (6, 28317), (7, 18824)], [(4, 49147), (5, 49147), (6, 49147), (7, 49150)], [(4, 65535), (5, 65535), (6, 65535), (7, 65535)], [], [], [], []] + B (mask+norm): [[(4, 0.0809714776), (5, 0.0809714776), (6, 0.0809714776), (7, 0.0590337245)], [(4, 0.1819882002), (5, 0.1819882002), (6, 0.1819882002), (7, 0.1326708249)], [(4, 0.3158588156), (5, 0.3158588156), (6, 0.3158588156), (7, 0.3464073015)], [(4, 0.421181506), (5, 0.421181506), (6, 0.421181506), (7, 0.4618881487)], [], [], [], []] + ΔB: [[], [], [(7, 0.1200025633)], [(7, 0.1600034179)], [], [], [], []] + ΔB (norm): [[], [], [(7, 0.4285714284)], [(7, 0.5714285714)], [], [], [], []] + emaB: [[(4, 0.0809714776), (5, 0.0809714776), (6, 0.0809714776), (7, 0.053130352)], [(4, 0.1819882002), (5, 0.1819882002), (6, 0.1819882002), (7, 0.1194037423)], [(4, 0.3158588156), (5, 0.3158588156), (6, 0.3158588156), (7, 0.3546237142)], [(4, 0.4211815062), (5, 0.4211815062), (6, 0.4211815062), (7, 0.472842191)], [], [], [], []] + D: [0.053130352, 0.1194037423, 0.3546237142, 0.472842191, 0, 0, 0, 0] + nE: [0.026565176, 0.0597018711, 0.177311857, 0.2364210954, 0, 0, 0, 0.5] + E: [26565175, 59701871, 177311856, 236421095, 0, 0, 0, 500000000] + P: [0.026565176, 0.0597018711, 0.177311857, 0.2364210954, 0, 0, 0, 0.5] + emaB: [[(4, 0.1922484161), (5, 0.1922484161), (6, 0.1922484161), (7, 0.1123638137)], [(4, 0.4320897225), (5, 0.4320897225), (6, 0.4320897225), (7, 0.2525234516)], [(4, 0.7499351487), (5, 0.7499351487), (6, 0.7499351487), (7, 0.7499832308)], [(4, 1), (5, 1), (6, 1), (7, 1)], [], [], [], []] */ + }); } -// #[test] fn test_set_alpha_disabled() { new_test_ext(1).execute_with(|| { @@ -1702,7 +1414,7 @@ fn test_active_stake() { assert_eq!(*i, 0); } for i in bond.iter().take(n as usize).skip((n / 2) as usize) { - assert_eq!(*i, I32F32::from_num(3276)); // floor(0.5*(2^16-1))/(2^16-1), then max-upscale to 65_535 + assert_eq!(*i, I32F32::from_num(65_535)); // floor(0.5*(2^16-1))/(2^16-1), then max-upscale to 65_535 } } let activity_cutoff: u64 = SubtensorModule::get_activity_cutoff(netuid) as u64; @@ -1721,53 +1433,50 @@ fn test_active_stake() { } else { SubtensorModule::epoch_dense(netuid, 1_000_000_000); } - /* - current_block: 5002 - activity_cutoff: 5000 - Last update: [5002, 1, 0, 0] - Block at registration: [0, 0, 0, 0] - validator_permits: [true, true, true, true] - max_allowed_validators: 4 - new_validator_permits: [true, true, true, true] - Active Stake: [1, 0, 0, 0] - Weights: [[(2, 65535), (3, 65535)], [(2, 65535), (3, 65535)], [], []] - Weights (permit): [[(2, 65535), (3, 65535)], [(2, 65535), (3, 65535)], [], []] - Weights (permit+diag): [[(2, 65535), (3, 65535)], [(2, 65535), (3, 65535)], [], []] - Weights (permit+diag+outdate): [[(2, 65535), (3, 65535)], [(2, 65535), (3, 65535)], [], []] - Weights (mask+norm): [[(2, 0.5), (3, 0.5)], [(2, 0.5), (3, 0.5)], [], []] - Ranks (before): [0, 0, 0.5, 0.5] - Consensus: [0, 0, 0.5, 0.5] - Clipped Weights: [[(2, 0.5), (3, 0.5)], [(2, 0.5), (3, 0.5)], [], []] - Validator Trust: [1, 1, 0, 0] - Ranks (after): [0, 0, 0.5, 0.5] - Trust: [0, 0, 1, 1] - Incentive (=Rank): [0, 0, 0.5, 0.5] - Bonds: [[(2, 3276), (3, 3276)], [(2, 3276), (3, 3276)], [], []] - Bonds: (mask+norm) [[(2, 0.0499885557), (3, 0.0499885557)], [(2, 0.0499885557), (3, 0.0499885557)], [], []] - weights_for_bonds: [[(2, 0.5), (3, 0.5)], [(2, 0.5), (3, 0.5)], [], []] - emaB: [[(2, 0.1449897), (3, 0.1449897)], [(2, 0.0449897), (3, 0.0449897)], [], []] - emaB norm: [[(2, 0.7631864299), (3, 0.7631864299)], [(2, 0.23681357), (3, 0.23681357)], [], []] - total_bonds_per_validator: [0.7631864296, 0.23681357, 0, 0] - Dividends: [1, 0, 0, 0] - Normalized Server Emission: [0, 0, 0.25, 0.25] - Server Emission: [0, 0, 250000000, 250000000] - Normalized Validator Emission: [0.5, 0, 0, 0] - Validator Emission: [500000000, 0, 0, 0] - Normalized Combined Emission: [0.5, 0, 0.25, 0.25] - Combined Emission: [500000000, 0, 250000000, 250000000] - Pruning Scores: [0.5, 0, 0.25, 0.25] - */ + /* current_block: 5002; activity_cutoff: 5000 + Last update: [5002, 1, 0, 0]; Inactive: [false, true, true, true]; Block at registration: [0, 0, 0, 0] + S: [0.25, 0.25, 0.25, 0.25]; S (mask): [0.25, 0, 0, 0]; S (mask+norm): [1, 0, 0, 0] + validator_permits: [true, true, true, true]; max_allowed_validators: 4; new_validator_permits: [true, true, true, true] + W: [[(2, 0.4999923704), (3, 0.4999923704)], [(2, 0.4999923704), (3, 0.4999923704)], [], []] + W (permit): [[(2, 0.4999923704), (3, 0.4999923704)], [(2, 0.4999923704), (3, 0.4999923704)], [], []] + W (permit+diag): [[(2, 0.4999923704), (3, 0.4999923704)], [(2, 0.4999923704), (3, 0.4999923704)], [], []] + W (permit+diag+outdate): [[(2, 0.4999923704), (3, 0.4999923704)], [(2, 0.4999923704), (3, 0.4999923704)], [], []] + W (mask+norm): [[(2, 0.5), (3, 0.5)], [(2, 0.5), (3, 0.5)], [], []] + R: [0, 0, 0.5, 0.5] + W (threshold): [[(2, 1), (3, 1)], [(2, 1), (3, 1)], [], []] + T: [0, 0, 1, 1] + C: [0.006693358, 0.006693358, 0.9933076561, 0.9933076561] + I: [0, 0, 0.5, 0.5] + B: [[(2, 0.4999923704), (3, 0.4999923704)], [(2, 0.4999923704), (3, 0.4999923704)], [], []] + B (outdatedmask): [[(2, 0.4999923704), (3, 0.4999923704)], [(2, 0.4999923704), (3, 0.4999923704)], [], []] + B (mask+norm): [[(2, 0.5), (3, 0.5)], [(2, 0.5), (3, 0.5)], [], []] + ΔB: [[(2, 0.5), (3, 0.5)], [(2, 0), (3, 0)], [], []] + ΔB (norm): [[(2, 1), (3, 1)], [(2, 0), (3, 0)], [], []] + emaB: [[(2, 0.55), (3, 0.55)], [(2, 0.45), (3, 0.45)], [], []] + emaB (max-upscale): [[(2, 1), (3, 1)], [(2, 1), (3, 1)], [], []] + D: [0.55, 0.4499999997, 0, 0] + nE: [0.275, 0.2249999999, 0.25, 0.25] + E: [274999999, 224999999, 250000000, 250000000] + P: [0.275, 0.2249999999, 0.25, 0.25] + P (u16): [65535, 53619, 59577, 59577] */ let bonds = SubtensorModule::get_bonds(netuid); - assert_eq!(SubtensorModule::get_dividends_for_uid(netuid, 0), 65535); - assert_eq!(SubtensorModule::get_emission_for_uid(netuid, 0), 500000000); + assert_eq!(SubtensorModule::get_dividends_for_uid(netuid, 0), 36044); // Note D = floor((0.5 * 0.9 + 0.1) * 65_535) + assert_eq!(SubtensorModule::get_emission_for_uid(netuid, 0), 274999999); // Note E = 0.5 * 0.55 * 1_000_000_000 = 275_000_000 (discrepancy) for server in ((n / 2) as usize)..n as usize { - assert_eq!(bonds[0][server], I32F32::from_num(9501)); + assert_eq!(bonds[0][server], I32F32::from_num(65_535)); // floor(0.55*(2^16-1))/(2^16-1), then max-upscale } for validator in 1..(n / 2) { - assert_eq!(SubtensorModule::get_dividends_for_uid(netuid, validator), 0); - assert_eq!(SubtensorModule::get_emission_for_uid(netuid, validator), 0); + assert_eq!( + SubtensorModule::get_dividends_for_uid(netuid, validator), + 29490 + ); // Note D = floor((0.5 * 0.9) * 65_535) + assert_eq!( + SubtensorModule::get_emission_for_uid(netuid, validator), + 224999999 + ); // Note E = 0.5 * 0.45 * 1_000_000_000 = 225_000_000 (discrepancy) for server in ((n / 2) as usize)..n as usize { - assert_eq!(bonds[validator as usize][server], I32F32::from_num(2948)); + assert_eq!(bonds[validator as usize][server], I32F32::from_num(53619)); + // floor(0.45*(2^16-1))/(2^16-1), then max-upscale } } @@ -1785,52 +1494,42 @@ fn test_active_stake() { } else { SubtensorModule::epoch_dense(netuid, 1_000_000_000); } - /* - current_block: 5003 - activity_cutoff: 5000 - Last update: [5002, 5002, 0, 0] - Block at registration: [0, 0, 0, 0] - validator_permits: [true, true, true, true] - max_allowed_validators: 4 - new_validator_permits: [true, true, true, true] - Active Stake: [0.5, 0.5, 0, 0] - Weights: [[(2, 65535), (3, 65535)], [(2, 65535), (3, 65535)], [], []] - Weights (permit): [[(2, 65535), (3, 65535)], [(2, 65535), (3, 65535)], [], []] - Weights (permit+diag): [[(2, 65535), (3, 65535)], [(2, 65535), (3, 65535)], [], []] - Weights (permit+diag+outdate): [[(2, 65535), (3, 65535)], [(2, 65535), (3, 65535)], [], []] - Weights (mask+norm): [[(2, 0.5), (3, 0.5)], [(2, 0.5), (3, 0.5)], [], []] - Ranks (before): [0, 0, 0.5, 0.5] - Consensus: [0, 0, 0.5, 0.5] - Clipped Weights: [[(2, 0.5), (3, 0.5)], [(2, 0.5), (3, 0.5)], [], []] - Validator Trust: [1, 1, 0, 0] - Ranks (after): [0, 0, 0.5, 0.5] - Trust: [0, 0, 1, 1] - Incentive (=Rank): [0, 0, 0.5, 0.5] - Bonds: [[(2, 9501), (3, 9501)], [(2, 2948), (3, 2948)], [], []] - Bonds: (mask+norm) [[(2, 0.144975967), (3, 0.144975967)], [(2, 0.0449835965), (3, 0.0449835965)], [], []] - weights_for_bonds: [[(2, 0.5), (3, 0.5)], [(2, 0.5), (3, 0.5)], [], []] - emaB: [[(2, 0.1804783703), (3, 0.1804783703)], [(2, 0.0904852368), (3, 0.0904852368)], [], []] - emaB norm: [[(2, 0.666061292), (3, 0.666061292)], [(2, 0.3339387078), (3, 0.3339387078)], [], []] - total_bonds_per_validator: [0.666061292, 0.3339387076, 0, 0] - Dividends: [0.6660612922, 0.3339387076, 0, 0] - Normalized Server Emission: [0, 0, 0.25, 0.25] - Server Emission: [0, 0, 250000000, 250000000] - Normalized Validator Emission: [0.333030646, 0.1669693538, 0, 0] - Validator Emission: [333030645, 166969353, 0, 0] - Normalized Combined Emission: [0.333030646, 0.1669693538, 0.25, 0.25] - Combined Emission: [333030645, 166969353, 250000000, 250000000] - Pruning Scores: [0.333030646, 0.1669693538, 0.25, 0.25] - */ + /* current_block: 5003; activity_cutoff: 5000 + Last update: [5002, 5002, 0, 0]; Inactive: [false, false, true, true]; Block at registration: [0, 0, 0, 0] + S: [0.25, 0.25, 0.25, 0.25]; S (mask): [0.25, 0.25, 0, 0]; S (mask+norm): [0.5, 0.5, 0, 0] + validator_permits: [true, true, true, true]; max_allowed_validators: 4; new_validator_permits: [true, true, true, true] + W: [[(2, 0.4999923704), (3, 0.4999923704)], [(2, 0.4999923704), (3, 0.4999923704)], [], []] + W (permit): [[(2, 0.4999923704), (3, 0.4999923704)], [(2, 0.4999923704), (3, 0.4999923704)], [], []] + W (permit+diag): [[(2, 0.4999923704), (3, 0.4999923704)], [(2, 0.4999923704), (3, 0.4999923704)], [], []] + W (permit+diag+outdate): [[(2, 0.4999923704), (3, 0.4999923704)], [(2, 0.4999923704), (3, 0.4999923704)], [], []] + W (mask+norm): [[(2, 0.5), (3, 0.5)], [(2, 0.5), (3, 0.5)], [], []] + R: [0, 0, 0.5, 0.5] + W (threshold): [[(2, 1), (3, 1)], [(2, 1), (3, 1)], [], []] + T: [0, 0, 1, 1] + C: [0.006693358, 0.006693358, 0.9933076561, 0.9933076561] + I: [0, 0, 0.5, 0.5] + B: [[(2, 65535), (3, 65535)], [(2, 53619), (3, 53619)], [], []] + B (outdatedmask): [[(2, 65535), (3, 65535)], [(2, 53619), (3, 53619)], [], []] + B (mask+norm): [[(2, 0.5500025176), (3, 0.5500025176)], [(2, 0.4499974821), (3, 0.4499974821)], [], []] + ΔB: [[(2, 0.25), (3, 0.25)], [(2, 0.25), (3, 0.25)], [], []] + ΔB (norm): [[(2, 0.5), (3, 0.5)], [(2, 0.5), (3, 0.5)], [], []] + emaB: [[(2, 0.545002266), (3, 0.545002266)], [(2, 0.4549977337), (3, 0.4549977337)], [], []] + emaB (max-upscale): [[(2, 1), (3, 1)], [(2, 0.8348547556), (3, 0.8348547556)], [], []] + D: [0.545002266, 0.4549977337, 0, 0] + nE: [0.272501133, 0.2274988669, 0.25, 0.25] + E: [272501132, 227498866, 250000000, 250000000] + P: [0.272501133, 0.2274988669, 0.25, 0.25] + P (u16): [65535, 54711, 60123, 60123] */ let bonds = SubtensorModule::get_bonds(netuid); - assert_eq!(SubtensorModule::get_dividends_for_uid(netuid, 0), 43650); - assert_eq!(SubtensorModule::get_emission_for_uid(netuid, 0), 333030645); + assert_eq!(SubtensorModule::get_dividends_for_uid(netuid, 0), 35716); // Note D = floor((0.55 * 0.9 + 0.5 * 0.1) * 65_535) + assert_eq!(SubtensorModule::get_emission_for_uid(netuid, 0), 272501132); // Note E = 0.5 * (0.55 * 0.9 + 0.5 * 0.1) * 1_000_000_000 = 272_500_000 (discrepancy) for server in ((n / 2) as usize)..n as usize { - assert_eq!(bonds[0][server], I32F32::from_num(11827)); + assert_eq!(bonds[0][server], I32F32::from_num(65_535)); // floor((0.55 * 0.9 + 0.5 * 0.1)*(2^16-1))/(2^16-1), then max-upscale } - assert_eq!(SubtensorModule::get_dividends_for_uid(netuid, 1), 21884); - assert_eq!(SubtensorModule::get_emission_for_uid(netuid, 1), 166969353); + assert_eq!(SubtensorModule::get_dividends_for_uid(netuid, 1), 29818); // Note D = floor((0.45 * 0.9 + 0.5 * 0.1) * 65_535) + assert_eq!(SubtensorModule::get_emission_for_uid(netuid, 1), 227498866); // Note E = 0.5 * (0.45 * 0.9 + 0.5 * 0.1) * 1_000_000_000 = 227_500_000 (discrepancy) for server in ((n / 2) as usize)..n as usize { - assert_eq!(bonds[1][server], I32F32::from_num(5929)); + assert_eq!(bonds[1][server], I32F32::from_num(54712)); // floor((0.45 * 0.9 + 0.5 * 0.1)/(0.55 * 0.9 + 0.5 * 0.1)*(2^16-1)) } }); } @@ -1915,43 +1614,33 @@ fn test_outdated_weights() { } else { SubtensorModule::epoch_dense(netuid, 1_000_000_000); } - /* - Number of Neurons in Network: 4 - current_block: 2 - activity_cutoff: 5000 - Last update: [2, 2, 2, 2] - Block at registration: [1, 1, 1, 1] - validator_permits: [true, true, true, true] - max_allowed_validators: 4 - new_validator_permits: [true, true, true, true] - Active Stake: [0.25, 0.25, 0.25, 0.25] - Weights: [[(2, 65535), (3, 32768)], [(2, 65535), (3, 32768)], [(2, 65535)], [(3, 65535)]] - Weights (permit): [[(2, 65535), (3, 32768)], [(2, 65535), (3, 32768)], [(2, 65535)], [(3, 65535)]] - Weights (permit+diag): [[(2, 65535), (3, 32768)], [(2, 65535), (3, 32768)], [], []] - Weights (permit+diag+outdate): [[(2, 65535), (3, 32768)], [(2, 65535), (3, 32768)], [], []] - Weights (mask+norm): [[(2, 0.6666632756), (3, 0.3333367242)], [(2, 0.6666632756), (3, 0.3333367242)], [], []] - Ranks (before): [0, 0, 0.3333316376, 0.166668362] - Consensus: [0, 0, 0.6666632756, 0.3333367242] - Clipped Weights: [[(2, 0.6666632756), (3, 0.3333367242)], [(2, 0.6666632756), (3, 0.3333367242)], [], []] - Validator Trust: [0.9999999998, 0.9999999998, 0, 0] - Ranks (after): [0, 0, 0.3333316376, 0.166668362] - Trust: [0, 0, 1, 1] - Incentive (=Rank): [0, 0, 0.6666632756, 0.3333367242] - Bonds: [[], [], [], []] - Bonds: (mask+norm) [[], [], [], []] - weights_for_bonds: [[(2, 0.6666632756), (3, 0.3333367242)], [(2, 0.6666632756), (3, 0.3333367242)], [], []] - emaB: [[(2, 0.05), (3, 0.05)], [(2, 0.05), (3, 0.05)], [], []] - emaB norm: [[(2, 0.5), (3, 0.5)], [(2, 0.5), (3, 0.5)], [], []] - total_bonds_per_validator: [0.4999999998, 0.4999999998, 0, 0] - Dividends: [0.5, 0.5, 0, 0] - Normalized Server Emission: [0, 0, 0.3333316378, 0.166668362] - Server Emission: [0, 0, 333331637, 166668361] - Normalized Validator Emission: [0.25, 0.25, 0, 0] - Validator Emission: [250000000, 250000000, 0, 0] - Normalized Combined Emission: [0.25, 0.25, 0.3333316378, 0.166668362] - Combined Emission: [250000000, 250000000, 333331637, 166668361] - Pruning Scores: [0.25, 0.25, 0.3333316378, 0.166668362] - */ + /* current_block: 1; activity_cutoff: 5000 + Last update: [1, 1, 1, 1]; Inactive: [false, false, false, false]; Block at registration: [0, 0, 0, 0] + S: [0.25, 0.25, 0.25, 0.25]; S (mask): [0.25, 0.25, 0.25, 0.25]; S (mask+norm): [0.25, 0.25, 0.25, 0.25] + validator_permits: [true, true, true, true]; max_allowed_validators: 4; new_validator_permits: [true, true, true, true] + W: [[(2, 65535), (3, 32768)], [(2, 65535), (3, 32768)], [(2, 65535)], [(3, 65535)]] + W (permit): [[(2, 65535), (3, 32768)], [(2, 65535), (3, 32768)], [(2, 65535)], [(3, 65535)]] + W (permit+diag): [[(2, 65535), (3, 32768)], [(2, 65535), (3, 32768)], [], []] + W (permit+diag+outdate): [[(2, 65535), (3, 32768)], [(2, 65535), (3, 32768)], [], []] + W (mask+norm): [[(2, 0.6666632756), (3, 0.3333367242)], [(2, 0.6666632756), (3, 0.3333367242)], [], []] + R (before): [0, 0, 0.3333316376, 0.166668362] + C: [0, 0, 0.6666632756, 0.3333367242] + W: [[(2, 0.6666632756), (3, 0.3333367242)], [(2, 0.6666632756), (3, 0.3333367242)], [], []] + Tv: [0.9999999998, 0.9999999998, 0, 0] + R (after): [0, 0, 0.3333316376, 0.166668362] + T: [0, 0, 1, 1] + I (=R): [0, 0, 0.6666632756, 0.3333367242] + B: [[], [], [], []] + B (outdatedmask): [[], [], [], []] + B (mask+norm): [[], [], [], []] + ΔB: [[(2, 0.1666658188), (3, 0.083334181)], [(2, 0.1666658188), (3, 0.083334181)], [], []] + ΔB (norm): [[(2, 0.5), (3, 0.5)], [(2, 0.5), (3, 0.5)], [], []] + emaB: [[(2, 0.5), (3, 0.5)], [(2, 0.5), (3, 0.5)], [], []] + D: [0.5, 0.5, 0, 0] + nE: [0.25, 0.25, 0.3333316378, 0.166668362] + E: [250000000, 250000000, 333331637, 166668361] + P: [0.25, 0.25, 0.3333316378, 0.166668362] + P (u16): [49151, 49151, 65535, 32767] */ // === Dereg server2 at uid3 (least emission) + register new key over uid3 let new_key: u64 = n as u64; // register a new key while at max capacity, which means the least incentive uid will be deregistered @@ -1994,48 +1683,41 @@ fn test_outdated_weights() { } else { SubtensorModule::epoch_dense(netuid, 1_000_000_000); } - /* - Number of Neurons in Network: 4 - current_block: 3 - activity_cutoff: 5000 - Last update: [3, 2, 2, 2] - Block at registration: [1, 1, 1, 2] - validator_permits: [true, true, true, true] - max_allowed_validators: 4 - new_validator_permits: [true, true, true, true] - Active Stake: [0.3333333333, 0.3333333333, 0.3333333333, 0] - Weights: [[(2, 65535), (3, 32768)], [(2, 65535), (3, 32768)], [(2, 65535)], [(3, 65535)]] - Weights (permit): [[(2, 65535), (3, 32768)], [(2, 65535), (3, 32768)], [(2, 65535)], [(3, 65535)]] - Weights (permit+diag): [[(2, 65535), (3, 32768)], [(2, 65535), (3, 32768)], [], []] - Weights (permit+diag+outdate): [[(2, 65535), (3, 32768)], [(2, 65535)], [], []] - Weights (mask+norm): [[(2, 0.6666632756), (3, 0.3333367242)], [(2, 1)], [], []] - Ranks (before): [0, 0, 0.5555544249, 0.1111122412] - Consensus: [0, 0, 0.6666632756, 0] - Clipped Weights: [[(2, 0.6666632756)], [(2, 0.6666632756)], [], []] - Validator Trust: [0.6666632756, 0.6666632756, 0, 0] - Ranks (after): [0, 0, 0.4444421832, 0] - Trust: [0, 0, 0.799997558, 0] - Incentive (=Rank): [0, 0, 1, 0] - Bonds: [[(2, 3276), (3, 3276)], [(2, 3276), (3, 3276)], [], []] - Bonds: (mask+norm) [[(2, 0.0499885557), (3, 0.0499885557)], [(2, 0.0499885557)], [], []] - weights_for_bonds: [[(2, 0.6666632756)], [(2, 0.6666632756)], [], []] - emaB: [[(2, 0.0949897), (3, 0.0449897)], [(2, 0.0949897)], [], []] - emaB norm: [[(2, 0.5), (3, 1)], [(2, 0.5)], [], []] - total_bonds_per_validator: [0.5, 0.5, 0, 0] - Dividends: [0.5, 0.5, 0, 0] - Normalized Server Emission: [0, 0, 0.5, 0] - Server Emission: [0, 0, 500000000, 0] - Normalized Validator Emission: [0.25, 0.25, 0, 0] - Validator Emission: [250000000, 250000000, 0, 0] - Normalized Combined Emission: [0.25, 0.25, 0.5, 0] - Combined Emission: [250000000, 250000000, 500000000, 0] - Pruning Scores: [0.25, 0.25, 0.5, 0] - */ + /* current_block: 2; activity_cutoff: 5000 + Last update: [2, 1, 1, 1]; Inactive: [false, false, false, false]; Block at registration: [0, 0, 0, 1] + S: [0.3333333333, 0.3333333333, 0.3333333333, 0] + S (mask): [0.3333333333, 0.3333333333, 0.3333333333, 0] + S (mask+norm): [0.3333333333, 0.3333333333, 0.3333333333, 0] + validator_permits: [true, true, true, false]; max_allowed_validators: 4; new_validator_permits: [true, true, true, true] + W: [[(2, 65535), (3, 32768)], [(2, 65535), (3, 32768)], [(2, 65535)], [(3, 65535)]] + W (permit): [[(2, 65535), (3, 32768)], [(2, 65535), (3, 32768)], [(2, 65535)], [(3, 65535)]] + W (permit+diag): [[(2, 65535), (3, 32768)], [(2, 65535), (3, 32768)], [], []] + W (permit+diag+outdate): [[(2, 65535), (3, 32768)], [(2, 65535)], [], []] + W (mask+norm): [[(2, 0.6666632756), (3, 0.3333367242)], [(2, 1)], [], []] + R (before): [0, 0, 0.5555544249, 0.1111122412] + C: [0, 0, 0.6666632756, 0] + W: [[(2, 0.6666632756)], [(2, 0.6666632756)], [], []] + Tv: [0.6666632756, 0.6666632756, 0, 0] + R (after): [0, 0, 0.4444421832, 0] + T: [0, 0, 0.799997558, 0] + I (=R): [0, 0, 1, 0] + B: [[(2, 65535), (3, 65535)], [(2, 65535), (3, 65535)], [], []] + B (outdatedmask): [[(2, 65535), (3, 65535)], [(2, 65535)], [], []] + B (mask+norm): [[(2, 0.5), (3, 1)], [(2, 0.5)], [], []] + ΔB: [[(2, 0.2222210916)], [(2, 0.2222210916)], [], []] + ΔB (norm): [[(2, 0.5)], [(2, 0.5)], [], []] + emaB: [[(2, 0.5), (3, 1)], [(2, 0.5)], [], []] + emaB (max-upscale): [[(2, 1), (3, 1)], [(2, 1)], [], []] + D: [0.5, 0.5, 0, 0] + nE: [0.25, 0.25, 0.5, 0] + E: [250000000, 250000000, 500000000, 0] + P: [0.25, 0.25, 0.5, 0] + P (u16): [32767, 32767, 65535, 0] */ let bonds = SubtensorModule::get_bonds(netuid); assert_eq!(SubtensorModule::get_dividends_for_uid(netuid, 0), 32767); // Note D = floor(0.5 * 65_535) assert_eq!(SubtensorModule::get_emission_for_uid(netuid, 0), 250000000); // Note E = 0.5 * 0.5 * 1_000_000_000 = 249311245 - assert_eq!(bonds[0][2], I32F32::from_num(6225)); - assert_eq!(bonds[0][3], I32F32::from_num(2948)); + assert_eq!(bonds[0][2], I32F32::from_num(65_535)); // floor(0.5*(2^16-1))/(2^16-1), then max-upscale + assert_eq!(bonds[0][3], I32F32::from_num(65_535)); // only uid0 has updated weights for new reg }); } @@ -2993,6 +2675,9 @@ fn setup_yuma_3_scenario(netuid: u16, n: u16, sparse: bool, max_stake: u64, stak SubtensorModule::set_liquid_alpha_enabled(netuid, true); SubtensorModule::set_alpha_values_32(netuid, I32F32::from_num(0.1), I32F32::from_num(0.3)); + // Enable Yuma3 + SubtensorModule::set_yuma3_enabled(netuid, true); + // === Issue validator permits SubtensorModule::set_max_allowed_validators(netuid, 3); From f511bbbbcac70f0b7e447f91f1f0241831d71a19 Mon Sep 17 00:00:00 2001 From: Andreea Popescu Date: Wed, 9 Apr 2025 18:16:51 +0100 Subject: [PATCH 42/45] fix liquid_alpha disabled --- pallets/subtensor/src/epoch/run_epoch.rs | 36 ++-------- pallets/subtensor/src/tests/epoch.rs | 90 ++++++++++++++++++++++++ 2 files changed, 94 insertions(+), 32 deletions(-) diff --git a/pallets/subtensor/src/epoch/run_epoch.rs b/pallets/subtensor/src/epoch/run_epoch.rs index a8885047b9..667ffc17f9 100644 --- a/pallets/subtensor/src/epoch/run_epoch.rs +++ b/pallets/subtensor/src/epoch/run_epoch.rs @@ -206,13 +206,7 @@ impl Pallet { log::trace!("B: {:?}", &bonds); // Compute the Exponential Moving Average (EMA) of bonds. - ema_bonds = Self::compute_bonds( - netuid, - &weights_for_bonds, - &bonds, - &consensus, - &active_stake, - ); + ema_bonds = Self::compute_bonds(netuid, &weights_for_bonds, &bonds, &consensus); log::trace!("emaB: {:?}", &ema_bonds); // Normalize EMA bonds. @@ -623,13 +617,7 @@ impl Pallet { // Compute the Exponential Moving Average (EMA) of bonds. log::trace!("weights_for_bonds: {:?}", &weights_for_bonds); - ema_bonds = Self::compute_bonds_sparse( - netuid, - &weights_for_bonds, - &bonds, - &consensus, - &active_stake, - ); + ema_bonds = Self::compute_bonds_sparse(netuid, &weights_for_bonds, &bonds, &consensus); log::trace!("emaB: {:?}", &ema_bonds); // Normalize EMA bonds. @@ -1066,7 +1054,6 @@ impl Pallet { weights: &[Vec], // weights_for_bonds bonds: &[Vec], consensus: &[I32F32], - active_stake: &[I32F32], ) -> Vec> { // Check if Liquid Alpha is enabled, consensus is not empty, and contains non-zero values. if LiquidAlphaOn::::get(netuid) @@ -1086,13 +1073,8 @@ impl Pallet { // Liquid Alpha is disabled, compute the liquid alpha value. let alpha: I32F32 = Self::compute_disabled_liquid_alpha(netuid); - // Compute bonds delta column normalized. - let mut bonds_delta: Vec> = row_hadamard(weights, active_stake); // ΔB = W◦S - inplace_col_normalize(&mut bonds_delta); // sum_i b_ij = 1 - log::trace!("ΔB: {:?}", &bonds_delta); - // Compute the Exponential Moving Average (EMA) of bonds using the calculated alpha value. - mat_ema(&bonds_delta, bonds, alpha) + mat_ema(weights, bonds, alpha) } } @@ -1112,7 +1094,6 @@ impl Pallet { weights: &[Vec<(u16, I32F32)>], bonds: &[Vec<(u16, I32F32)>], consensus: &[I32F32], - active_stake: &[I32F32], ) -> Vec> { // Check if Liquid Alpha is enabled, consensus is not empty, and contains non-zero values. if LiquidAlphaOn::::get(netuid) @@ -1129,19 +1110,11 @@ impl Pallet { // Compute the Exponential Moving Average (EMA) of bonds using the provided clamped alpha values. mat_ema_alpha_sparse(weights, bonds, &alphas) } else { - let n: u16 = Self::get_subnetwork_n(netuid); - // Liquid Alpha is disabled, compute the liquid alpha value. let alpha: I32F32 = Self::compute_disabled_liquid_alpha(netuid); - // Compute bonds delta column normalized. - let mut bonds_delta: Vec> = - row_hadamard_sparse(weights, active_stake); // ΔB = W◦S - inplace_col_normalize_sparse(&mut bonds_delta, n); // sum_i b_ij = 1 - log::trace!("ΔB: {:?}", &bonds_delta); - // Compute the Exponential Moving Average (EMA) of bonds using the calculated alpha value. - mat_ema_sparse(&bonds_delta, bonds, alpha) + mat_ema_sparse(weights, bonds, alpha) } } @@ -1303,7 +1276,6 @@ impl Pallet { // Alpha is derived by subtracting the scaled bonds moving average from 1. let alpha: I32F32 = I32F32::from_num(1).saturating_sub(I32F32::from_num(bonds_moving_average)); - alpha } diff --git a/pallets/subtensor/src/tests/epoch.rs b/pallets/subtensor/src/tests/epoch.rs index 9b9e3e8727..24a20fd16a 100644 --- a/pallets/subtensor/src/tests/epoch.rs +++ b/pallets/subtensor/src/tests/epoch.rs @@ -2641,6 +2641,7 @@ fn setup_yuma_3_scenario(netuid: u16, n: u16, sparse: bool, max_stake: u64, stak SubtensorModule::set_max_weight_limit(netuid, u16::MAX); SubtensorModule::set_bonds_penalty(netuid, 0); SubtensorModule::set_alpha_sigmoid_steepness(netuid, 10); + SubtensorModule::set_bonds_moving_average(netuid, 975_000); // === Register for key in 0..n as u64 { @@ -3128,6 +3129,95 @@ fn test_yuma_3_one_epoch_switch() { } } +#[test] +fn test_yuma_3_liquid_alpha_disabled() { + for sparse in [true, false].iter() { + new_test_ext(1).execute_with(|| { + let netuid: u16 = 1; + let n: u16 = 5; // 3 validators, 2 servers + let max_stake: u64 = 8; + + // Equal stake validators + let stakes: Vec = vec![33, 33, 34, 0, 0]; + + setup_yuma_3_scenario(netuid, n, *sparse, max_stake, stakes); + + // disable liquid alpha + SubtensorModule::set_liquid_alpha_enabled(netuid, false); + + let targets_bonds = [ + vec![ + vec![0.0000, 0.0250, 0.0000], + vec![0.0000, 0.0250, 0.0000], + vec![0.0000, 0.0250, 0.0000], + ], + vec![ + vec![0.0000, 0.0494, 0.0000], + vec![0.0000, 0.0494, 0.0000], + vec![0.0000, 0.0494, 0.0000], + ], + vec![ + vec![0.0000, 0.0731, 0.0000], + vec![0.0000, 0.0731, 0.0000], + vec![0.0000, 0.0481, 0.0250], + ], + vec![ + vec![0.0000, 0.0963, 0.0000], + vec![0.0000, 0.0963, 0.0000], + vec![0.0000, 0.0719, 0.0244], + ], + vec![ + vec![0.0000, 0.1189, 0.0000], + vec![0.0000, 0.1189, 0.0000], + vec![0.0000, 0.0951, 0.0238], + ], + vec![ + vec![0.0000, 0.1409, 0.0000], + vec![0.0000, 0.1409, 0.0000], + vec![0.0000, 0.1178, 0.0232], + ], + ]; + let targets_dividends = [ + vec![0.3300, 0.3300, 0.3400, 0.0000, 0.0000], + vec![0.3300, 0.3300, 0.3400, 0.0000, 0.0000], + vec![0.3734, 0.3734, 0.2532, 0.0000, 0.0000], + vec![0.3611, 0.3611, 0.2779, 0.0000, 0.0000], + vec![0.3541, 0.3541, 0.2919, 0.0000, 0.0000], + vec![0.3495, 0.3495, 0.3009, 0.0000, 0.0000], + ]; + + for (epoch, (target_bonds, target_dividends)) in targets_bonds + .iter() + .zip(targets_dividends.iter()) + .enumerate() + { + match epoch { + 2 => { + // Validator A -> Server 1 + // Validator B -> Server 1 + // Validator C -> Server 2 + set_yuma_3_weights( + netuid, + vec![vec![u16::MAX, 0], vec![u16::MAX, 0], vec![0, u16::MAX]], + vec![3, 4], + ); + } + _ => { + // All validators -> Server 1 + set_yuma_3_weights(netuid, vec![vec![u16::MAX, 0]; 3], vec![3, 4]); + } + }; + run_epoch_and_check_bonds_dividends( + netuid, + *sparse, + target_bonds, + target_dividends, + ); + } + }) + } +} + #[test] fn test_yuma_3_stable_miner() { for sparse in [true, false].iter() { From b6b7473fcf14362fe4941bea4e24153e2aa2f0ae Mon Sep 17 00:00:00 2001 From: Cameron Fairchild Date: Mon, 21 Apr 2025 13:35:26 -0400 Subject: [PATCH 43/45] cargo lock --- Cargo.lock | 1425 ++++++++++++++++++++++++++-------------------------- 1 file changed, 718 insertions(+), 707 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ce6924d7b4..d7b618fb7a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -23,18 +23,18 @@ dependencies = [ [[package]] name = "addr2line" -version = "0.24.1" +version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5fb1d8e4442bd405fdfd1dacb42792696b0cf9cb15882e5d097b742a676d375" +checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" dependencies = [ - "gimli 0.31.0", + "gimli 0.29.0", ] [[package]] -name = "adler2" -version = "2.0.0" +name = "adler" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] name = "aead" @@ -68,7 +68,7 @@ dependencies = [ "cipher 0.4.4", "ctr", "ghash", - "subtle 2.6.1", + "subtle 2.6.0", ] [[package]] @@ -127,9 +127,9 @@ dependencies = [ [[package]] name = "anstream" -version = "0.6.15" +version = "0.6.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64e15c1ab1f89faffbf04a634d5e1962e9074f2741eef6d97f3c4e322426d526" +checksum = "418c75fa768af9c03be99d17643f93f79bbba589895012a80e3452a19ddda15b" dependencies = [ "anstyle", "anstyle-parse", @@ -142,33 +142,33 @@ dependencies = [ [[package]] name = "anstyle" -version = "1.0.8" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1" +checksum = "038dfcf04a5feb68e9c60b21c9625a54c2c0616e79b72b0fd87075a056ae1d1b" [[package]] name = "anstyle-parse" -version = "0.2.5" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb47de1e80c2b463c735db5b217a0ddc39d612e7ac9e2e96a5aed1f57616c1cb" +checksum = "c03a11a9034d92058ceb6ee011ce58af4a9bf61491aa7e1e59ecd24bd40d22d4" dependencies = [ "utf8parse", ] [[package]] name = "anstyle-query" -version = "1.1.1" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d36fc52c7f6c869915e99412912f22093507da8d9e942ceaf66fe4b7c14422a" +checksum = "ad186efb764318d35165f1758e7dcef3b10628e26d41a44bc5550652e6804391" dependencies = [ "windows-sys 0.52.0", ] [[package]] name = "anstyle-wincon" -version = "3.0.4" +version = "3.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bf74e1b6e971609db8ca7a9ce79fd5768ab6ae46441c572e46cf596f59e57f8" +checksum = "61a38449feb7068f52bb06c12759005cf459ee52bb4adc1d5a7c4322d716fb19" dependencies = [ "anstyle", "windows-sys 0.52.0", @@ -176,9 +176,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.89" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6" +checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" [[package]] name = "approx" @@ -200,7 +200,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.100", ] [[package]] @@ -381,7 +381,7 @@ dependencies = [ "num-bigint", "num-traits", "paste", - "rustc_version 0.4.1", + "rustc_version 0.4.0", "zeroize", ] @@ -545,15 +545,15 @@ checksum = "5d5dde061bd34119e902bbb2d9b90c5692635cf59fb91d582c2b68043f1b8293" [[package]] name = "arrayref" -version = "0.3.9" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76a2e8124351fda1ef8aaaa3bbd7ebbcb486bbcd4225aca0aa0d84bb2db8fecb" +checksum = "6b4930d2cb77ce62f89ee5d5289b4ac049559b1c45539271f5ed4fdc7db34545" [[package]] name = "arrayvec" -version = "0.7.6" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[package]] name = "asn1-rs" @@ -567,7 +567,7 @@ dependencies = [ "nom", "num-traits", "rusticata-macros", - "thiserror", + "thiserror 1.0.61", "time", ] @@ -583,7 +583,7 @@ dependencies = [ "nom", "num-traits", "rusticata-macros", - "thiserror", + "thiserror 1.0.61", "time", ] @@ -607,7 +607,7 @@ checksum = "965c2d33e53cb6b267e148a4cb0760bc01f4904c1cd4bb4002a085bb016d1490" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.100", "synstructure 0.13.1", ] @@ -630,7 +630,7 @@ checksum = "7b18050c2cd6fe86c3a76584ef5e0baf286d038cda203eb6223df2cc413565f7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.100", ] [[package]] @@ -652,9 +652,9 @@ dependencies = [ [[package]] name = "async-io" -version = "2.3.4" +version = "2.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "444b0228950ee6501b3568d3c93bf1176a1fdbc3b758dcd9475046d30f4dc7e8" +checksum = "0d6baa8f0178795da0e71bc42c9e5d13261aac7ee549853162e66a241ba17964" dependencies = [ "async-lock", "cfg-if", @@ -663,10 +663,10 @@ dependencies = [ "futures-lite", "parking", "polling", - "rustix 0.38.37", + "rustix 0.38.34", "slab", "tracing", - "windows-sys 0.59.0", + "windows-sys 0.52.0", ] [[package]] @@ -682,13 +682,13 @@ dependencies = [ [[package]] name = "async-trait" -version = "0.1.83" +version = "0.1.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "721cae7de5c34fbb2acd27e21e6d2cf7b886dce0c27388d46c4e6c47ea4318dd" +checksum = "c6fa2087f2753a7da8cc1c0dbfcf89579dd57458e36769de5ac750b4671737ca" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.100", ] [[package]] @@ -732,34 +732,34 @@ dependencies = [ [[package]] name = "auto_impl" -version = "1.2.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c87f3f15e7794432337fc718554eaa4dc8f04c9677a950ffe366f20a162ae42" +checksum = "ffdcb70bdbc4d478427380519163274ac86e52916e10f0a8889adf0f96d3fee7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.100", ] [[package]] name = "autocfg" -version = "1.4.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "backtrace" -version = "0.3.74" +version = "0.3.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d82cb332cdfaed17ae235a638438ac4d4839913cc2af585c3c6746e8f8bee1a" +checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" dependencies = [ - "addr2line 0.24.1", + "addr2line 0.22.0", + "cc", "cfg-if", "libc", "miniz_oxide", - "object 0.36.4", + "object 0.36.0", "rustc-demangle", - "windows-targets 0.52.6", ] [[package]] @@ -819,13 +819,13 @@ dependencies = [ "lazy_static", "lazycell", "peeking_take_while", - "prettyplease 0.2.22", + "prettyplease 0.2.20", "proc-macro2", "quote", "regex", "rustc-hash 1.1.0", "shlex", - "syn 2.0.90", + "syn 2.0.100", ] [[package]] @@ -852,9 +852,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.6.0" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" [[package]] name = "bitvec" @@ -913,9 +913,9 @@ dependencies = [ [[package]] name = "blake3" -version = "1.5.4" +version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d82033247fd8e890df8f740e407ad4d038debb9eb1f40533fffb32e7d17dc6f7" +checksum = "30cca6d3674597c30ddf2c587bf8d9d65c9a84d2326d941cc79c9842dfe0ef52" dependencies = [ "arrayref", "arrayvec", @@ -998,9 +998,9 @@ checksum = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" [[package]] name = "bytemuck" -version = "1.18.0" +version = "1.16.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94bbb0ad554ad961ddc5da507a12a29b14e4ae5bda06b19f575a3e6079d2e2ae" +checksum = "b236fc92302c97ed75b38da1f4917b5cdda4984745740f153a5d3059e48d725e" [[package]] name = "byteorder" @@ -1010,9 +1010,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.7.2" +version = "1.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" +checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a" [[package]] name = "bzip2-sys" @@ -1037,9 +1037,9 @@ dependencies = [ [[package]] name = "camino" -version = "1.1.9" +version = "1.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b96ec4966b5813e2c0507c1f86115c8c5abaadc3980879c3424042a02fd1ad3" +checksum = "e0ec6b951b160caa93cc0c7b209e5a3bff7aae9062213451ac99493cd844c239" dependencies = [ "serde", ] @@ -1064,7 +1064,7 @@ dependencies = [ "semver 1.0.23", "serde", "serde_json", - "thiserror", + "thiserror 1.0.61", ] [[package]] @@ -1075,9 +1075,9 @@ checksum = "fd6c0e7b807d60291f42f33f58480c0bfafe28ed08286446f45e463728cf9c1c" [[package]] name = "cc" -version = "1.2.16" +version = "1.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be714c154be609ec7f5dad223a33bf1482fff90472de28f7362806e6d4832b8c" +checksum = "8e3a13707ac958681c13b39b458c073d0d9bc8a22cb1b2f4c8e55eb72c13f362" dependencies = [ "jobserver", "libc", @@ -1160,7 +1160,7 @@ dependencies = [ "num-traits", "serde", "wasm-bindgen", - "windows-targets 0.52.6", + "windows-targets 0.52.5", ] [[package]] @@ -1222,9 +1222,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.19" +version = "4.5.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7be5744db7978a28d9df86a214130d106a89ce49644cbc4e3f0c22c3fba30615" +checksum = "0fbb260a053428790f3de475e304ff84cdbc4face759ea7a3e64c1edd938a7fc" dependencies = [ "clap_builder", "clap_derive", @@ -1232,9 +1232,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.19" +version = "4.5.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5fbc17d3ef8278f55b282b2a2e75ae6f6c7d4bb70ed3d0382375104bfafdb4b" +checksum = "64b17d7ea74e9f833c7dbf2cbe4fb12ff26783eda4782a8975b72f895c9b4d99" dependencies = [ "anstream", "anstyle", @@ -1245,21 +1245,21 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.5.18" +version = "4.5.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ac6a0c7b1a9e9a5186361f67dfa1b88213572f427fb9ab038efb2bd8c582dab" +checksum = "501d359d5f3dcaf6ecdeee48833ae73ec6e42723a1e52419c79abf9507eec0a0" dependencies = [ "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.100", ] [[package]] name = "clap_lex" -version = "0.7.2" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97" +checksum = "4b82cf0babdbd58558212896d1a4272303a57bdb245c2bf1147185fb45640e70" [[package]] name = "codespan-reporting" @@ -1273,9 +1273,9 @@ dependencies = [ [[package]] name = "colorchoice" -version = "1.0.2" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0" +checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422" [[package]] name = "combine" @@ -1293,7 +1293,7 @@ version = "7.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b34115915337defe99b2aff5c2ce6771e5fbc4079f4b506301f5cf394c8452f7" dependencies = [ - "strum 0.26.3", + "strum 0.26.2", "strum_macros 0.26.4", "unicode-width", ] @@ -1354,9 +1354,9 @@ dependencies = [ [[package]] name = "constant_time_eq" -version = "0.3.1" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c74b8349d32d297c9134b8c88677813a227df8f779daa29bfc29c183fe3dca6" +checksum = "f7144d30dcf0fafbce74250a3963025d8d52177934239851c917d29f1df280c2" [[package]] name = "constcat" @@ -1382,9 +1382,9 @@ dependencies = [ [[package]] name = "core-foundation-sys" -version = "0.8.7" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" +checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" [[package]] name = "core2" @@ -1406,9 +1406,9 @@ dependencies = [ [[package]] name = "cpufeatures" -version = "0.2.14" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "608697df725056feaccfa42cffdaeeec3fccc4ffc38358ecd19b243e716a78e0" +checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504" dependencies = [ "libc", ] @@ -1583,7 +1583,7 @@ checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" dependencies = [ "generic-array 0.14.7", "rand_core", - "subtle 2.6.1", + "subtle 2.6.0", "zeroize", ] @@ -1615,7 +1615,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b584a330336237c1eecd3e94266efb216c56ed91225d634cb2991c5f3fd1aeab" dependencies = [ "generic-array 0.14.7", - "subtle 2.6.1", + "subtle 2.6.0", ] [[package]] @@ -1638,8 +1638,8 @@ dependencies = [ "curve25519-dalek-derive", "digest 0.10.7", "fiat-crypto", - "rustc_version 0.4.1", - "subtle 2.6.1", + "rustc_version 0.4.0", + "subtle 2.6.0", "zeroize", ] @@ -1651,14 +1651,14 @@ checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.100", ] [[package]] name = "cxx" -version = "1.0.128" +version = "1.0.124" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54ccead7d199d584d139148b04b4a368d1ec7556a1d9ea2548febb1b9d49f9a4" +checksum = "273dcfd3acd4e1e276af13ed2a43eea7001318823e7a726a6b3ed39b4acc0b82" dependencies = [ "cc", "cxxbridge-flags", @@ -1668,9 +1668,9 @@ dependencies = [ [[package]] name = "cxx-build" -version = "1.0.128" +version = "1.0.124" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c77953e99f01508f89f55c494bfa867171ef3a6c8cea03d26975368f2121a5c1" +checksum = "d8b2766fbd92be34e9ed143898fce6c572dc009de39506ed6903e5a05b68914e" dependencies = [ "cc", "codespan-reporting", @@ -1678,31 +1678,31 @@ dependencies = [ "proc-macro2", "quote", "scratch", - "syn 2.0.90", + "syn 2.0.100", ] [[package]] name = "cxxbridge-flags" -version = "1.0.128" +version = "1.0.124" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65777e06cc48f0cb0152024c77d6cf9e4bdb4408e7b48bea993d42fa0f5b02b6" +checksum = "839fcd5e43464614ffaa989eaf1c139ef1f0c51672a1ed08023307fa1b909ccd" [[package]] name = "cxxbridge-macro" -version = "1.0.128" +version = "1.0.124" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98532a60dedaebc4848cb2cba5023337cc9ea3af16a5b062633fabfd9f18fb60" +checksum = "4b2c1c1776b986979be68bb2285da855f8d8a35851a769fca8740df7c3d07877" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.100", ] [[package]] name = "darling" -version = "0.20.10" +version = "0.20.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f63b86c8a8826a49b8c21f08a2d07338eec8d900540f8630dc76284be802989" +checksum = "83b2eb4d90d12bdda5ed17de686c2acb4c57914f8f921b8da7e112b5a36f3fe1" dependencies = [ "darling_core", "darling_macro", @@ -1710,27 +1710,27 @@ dependencies = [ [[package]] name = "darling_core" -version = "0.20.10" +version = "0.20.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95133861a8032aaea082871032f5815eb9e98cef03fa916ab4500513994df9e5" +checksum = "622687fe0bac72a04e5599029151f5796111b90f1baaa9b544d807a5e31cd120" dependencies = [ "fnv", "ident_case", "proc-macro2", "quote", "strsim", - "syn 2.0.90", + "syn 2.0.100", ] [[package]] name = "darling_macro" -version = "0.20.10" +version = "0.20.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" +checksum = "733cabb43482b1a1b53eee8583c2b9e8684d592215ea83efd305dd31bc2f0178" dependencies = [ "darling_core", "quote", - "syn 2.0.90", + "syn 2.0.100", ] [[package]] @@ -1839,7 +1839,7 @@ checksum = "d65d7ce8132b7c0e54497a4d9a55a1c2a0912a0d786cf894472ba818fba45762" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.100", ] [[package]] @@ -1851,8 +1851,8 @@ dependencies = [ "convert_case", "proc-macro2", "quote", - "rustc_version 0.4.1", - "syn 2.0.90", + "rustc_version 0.4.0", + "syn 2.0.100", ] [[package]] @@ -1888,7 +1888,7 @@ dependencies = [ "block-buffer 0.10.4", "const-oid", "crypto-common", - "subtle 2.6.1", + "subtle 2.6.0", ] [[package]] @@ -1941,7 +1941,7 @@ checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.100", ] [[package]] @@ -1965,9 +1965,9 @@ dependencies = [ "proc-macro2", "quote", "regex", - "syn 2.0.90", + "syn 2.0.100", "termcolor", - "toml 0.8.19", + "toml 0.8.14", "walkdir", ] @@ -2052,7 +2052,7 @@ dependencies = [ "rand_core", "serde", "sha2 0.10.8", - "subtle 2.6.1", + "subtle 2.6.0", "zeroize", ] @@ -2073,9 +2073,9 @@ dependencies = [ [[package]] name = "either" -version = "1.13.0" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" +checksum = "3dca9240753cf90908d7e4aac30f630662b02aebaa1b58a3cadabdb23385b58b" dependencies = [ "serde", ] @@ -2096,7 +2096,7 @@ dependencies = [ "rand_core", "sec1", "serdect", - "subtle 2.6.1", + "subtle 2.6.0", "zeroize", ] @@ -2127,7 +2127,7 @@ dependencies = [ "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.100", ] [[package]] @@ -2147,7 +2147,7 @@ checksum = "de0d48a183585823424a4ce1aa132d174a6a81bd540895822eb4c8373a8e49e8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.100", ] [[package]] @@ -2337,10 +2337,10 @@ dependencies = [ "blake2 0.10.6", "file-guard", "fs-err", - "prettyplease 0.2.22", + "prettyplease 0.2.20", "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.100", ] [[package]] @@ -2357,9 +2357,9 @@ checksum = "2acce4a10f12dc2fb14a218589d4f1f62ef011b2d0cc4b3cb1bba8e94da14649" [[package]] name = "fastrand" -version = "2.1.1" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" +checksum = "9fc0510504f03c51ada170672ac806f1f105a88aa97a5281117e1ddc3368e51a" [[package]] name = "fc-api" @@ -2386,7 +2386,7 @@ dependencies = [ "sp-block-builder", "sp-consensus", "sp-runtime", - "thiserror", + "thiserror 1.0.61", ] [[package]] @@ -2492,7 +2492,7 @@ dependencies = [ "sp-storage 21.0.0", "sp-timestamp", "substrate-prometheus-endpoint", - "thiserror", + "thiserror 1.0.61", "tokio", ] @@ -2535,7 +2535,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e182f7dbc2ef73d9ef67351c5fbbea084729c48362d3ce9dd44c28e32e277fe5" dependencies = [ "libc", - "thiserror", + "thiserror 1.0.61", ] [[package]] @@ -2545,7 +2545,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" dependencies = [ "rand_core", - "subtle 2.6.1", + "subtle 2.6.0", ] [[package]] @@ -2576,14 +2576,14 @@ dependencies = [ [[package]] name = "filetime" -version = "0.2.25" +version = "0.2.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35c0522e981e68cbfa8c3f978441a5f34b30b96e146b33cd3359176b50fe8586" +checksum = "1ee447700ac8aa0b2f2bd7bc4462ad686ba06baa6727ac149a2d6277f0d240fd" dependencies = [ "cfg-if", "libc", - "libredox", - "windows-sys 0.59.0", + "redox_syscall 0.4.1", + "windows-sys 0.52.0", ] [[package]] @@ -2648,9 +2648,9 @@ checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" [[package]] name = "foldhash" -version = "0.1.3" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f81ec6369c545a7d40e4589b5597581fa1c441fe1cce96dd1de43159910a36a2" +checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" [[package]] name = "foreign-types" @@ -2691,7 +2691,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8835f84f38484cc86f110a805655697908257fb9a7af005234060891557198e9" dependencies = [ "nonempty", - "thiserror", + "thiserror 1.0.61", ] [[package]] @@ -2864,7 +2864,7 @@ dependencies = [ "sp-storage 21.0.0", "sp-trie", "sp-wasm-interface 21.0.1", - "thiserror", + "thiserror 1.0.61", "thousands", ] @@ -2971,7 +2971,7 @@ dependencies = [ "proc-macro2", "quote", "sp-crypto-hashing 0.1.0 (git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-stable2409)", - "syn 2.0.90", + "syn 2.0.100", ] [[package]] @@ -2981,10 +2981,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3363df38464c47a73eb521a4f648bfcc7537a82d70347ef8af3f73b6d019e910" dependencies = [ "frame-support-procedural-tools-derive 11.0.0", - "proc-macro-crate 3.2.0", + "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.100", ] [[package]] @@ -2993,10 +2993,10 @@ version = "13.0.0" source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-stable2409#87971b3e92721bdf10bf40b410eaae779d494ca0" dependencies = [ "frame-support-procedural-tools-derive 12.0.0", - "proc-macro-crate 3.2.0", + "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.100", ] [[package]] @@ -3007,7 +3007,7 @@ checksum = "68672b9ec6fe72d259d3879dc212c5e42e977588cdac830c76f54d9f492aeb58" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.100", ] [[package]] @@ -3017,7 +3017,7 @@ source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-stable dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.100", ] [[package]] @@ -3102,9 +3102,9 @@ checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" [[package]] name = "futures" -version = "0.3.31" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65bc07b1a8bc7c85c5f2e110c476c7389b4554ba72af57d8445ea63a576b0876" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" dependencies = [ "futures-channel", "futures-core", @@ -3127,9 +3127,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.31" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" dependencies = [ "futures-core", "futures-sink", @@ -3137,15 +3137,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.31" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" [[package]] name = "futures-executor" -version = "0.3.31" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e28d1d997f585e54aebc3f97d39e72338912123a67330d723fdbb564d646c9f" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" dependencies = [ "futures-core", "futures-task", @@ -3166,9 +3166,9 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.31" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" [[package]] name = "futures-lite" @@ -3182,13 +3182,13 @@ dependencies = [ [[package]] name = "futures-macro" -version = "0.3.31" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.100", ] [[package]] @@ -3203,15 +3203,15 @@ dependencies = [ [[package]] name = "futures-sink" -version = "0.3.31" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" [[package]] name = "futures-task" -version = "0.3.31" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" [[package]] name = "futures-timer" @@ -3221,9 +3221,9 @@ checksum = "f288b0a4f20f9a56b5d1da57e2227c661b7b16168e2f72365f57b63326e29b24" [[package]] name = "futures-util" -version = "0.3.31" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" dependencies = [ "futures-channel", "futures-core", @@ -3330,9 +3330,9 @@ dependencies = [ [[package]] name = "gimli" -version = "0.31.0" +version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32085ea23f3234fc7846555e85283ba4de91e21016dc0455a16286d87a292d64" +checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" [[package]] name = "glob" @@ -3368,7 +3368,7 @@ checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" dependencies = [ "ff", "rand_core", - "subtle 2.6.1", + "subtle 2.6.0", ] [[package]] @@ -3383,7 +3383,7 @@ dependencies = [ "futures-sink", "futures-util", "http 0.2.12", - "indexmap 2.6.0", + "indexmap 2.2.6", "slab", "tokio", "tokio-util", @@ -3392,17 +3392,17 @@ dependencies = [ [[package]] name = "h2" -version = "0.4.6" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" +checksum = "75249d144030531f8dee69fe9cea04d3edf809a017ae445e2abdff6629e86633" dependencies = [ "atomic-waker", "bytes", "fnv", "futures-core", "futures-sink", - "http 1.1.0", - "indexmap 2.6.0", + "http 1.3.1", + "indexmap 2.2.6", "slab", "tokio", "tokio-util", @@ -3426,7 +3426,7 @@ dependencies = [ "pest_derive", "serde", "serde_json", - "thiserror", + "thiserror 1.0.61", ] [[package]] @@ -3494,11 +3494,11 @@ dependencies = [ [[package]] name = "hashlink" -version = "0.9.1" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ba4ff7128dee98c7dc9794b6a411377e1404dba1c97deb8d1a55297bd25d8af" +checksum = "7382cf6263419f2d8df38c55d7da83da5c18aef87fc7a7fc1fb1e344edfe14c1" dependencies = [ - "hashbrown 0.14.5", + "hashbrown 0.15.2", ] [[package]] @@ -3618,9 +3618,9 @@ dependencies = [ [[package]] name = "http" -version = "1.1.0" +version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" +checksum = "f4a85d31aea989eead29a3aaf9e1115a180df8282431156e533de47660892565" dependencies = [ "bytes", "fnv", @@ -3645,27 +3645,27 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" dependencies = [ "bytes", - "http 1.1.0", + "http 1.3.1", ] [[package]] name = "http-body-util" -version = "0.1.2" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" +checksum = "b021d93e26becf5dc7e1b75b1bed1fd93124b374ceb73f43d4d4eafec896a64a" dependencies = [ "bytes", - "futures-util", - "http 1.1.0", + "futures-core", + "http 1.3.1", "http-body 1.0.1", "pin-project-lite", ] [[package]] name = "httparse" -version = "1.9.5" +version = "1.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d71d3574edd2771538b901e6549113b4006ece66150fb69c0fb6d9a2adae946" +checksum = "0fcc0b4a115bf80b728eb8ea024ad5bd707b615bfed49e0665b6e0f86fd082d9" [[package]] name = "httpdate" @@ -3681,9 +3681,9 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "hyper" -version = "0.14.30" +version = "0.14.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a152ddd61dfaec7273fe8419ab357f33aee0d914c5f4efbf0d96fa749eea5ec9" +checksum = "f361cde2f109281a220d4307746cdfd5ee3f410da58a70377762396775634b33" dependencies = [ "bytes", "futures-channel", @@ -3705,15 +3705,15 @@ dependencies = [ [[package]] name = "hyper" -version = "1.5.0" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbbff0a806a4728c99295b254c8838933b5b082d75e3cb70c8dab21fdfbcfa9a" +checksum = "cc2b571658e38e0c01b1fdca3bbbe93c00d3d71693ff2770043f8c29bc7d6f80" dependencies = [ "bytes", "futures-channel", "futures-util", - "h2 0.4.6", - "http 1.1.0", + "h2 0.4.9", + "http 1.3.1", "http-body 1.0.1", "httparse", "httpdate", @@ -3731,7 +3731,7 @@ checksum = "ec3efd23720e2049821a693cbc7e65ea87c72f1c58ff2f9522ff332b1491e590" dependencies = [ "futures-util", "http 0.2.12", - "hyper 0.14.30", + "hyper 0.14.29", "log", "rustls 0.21.12", "rustls-native-certs", @@ -3741,15 +3741,15 @@ dependencies = [ [[package]] name = "hyper-util" -version = "0.1.10" +version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df2dcfbe0677734ab2f3ffa7fa7bfd4706bfdc1ef393f2ee30184aed67e631b4" +checksum = "497bbc33a26fdd4af9ed9c70d63f61cf56a938375fbb32df34db9b1cd6d643f2" dependencies = [ "bytes", "futures-util", - "http 1.1.0", + "http 1.3.1", "http-body 1.0.1", - "hyper 1.5.0", + "hyper 1.6.0", "pin-project-lite", "tokio", "tower-service", @@ -3757,9 +3757,9 @@ dependencies = [ [[package]] name = "iana-time-zone" -version = "0.1.61" +version = "0.1.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "235e081f3925a06703c2d0117ea8b91f042756fd6e7a6e5d901e8ca1a996b220" +checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141" dependencies = [ "android_system_properties", "core-foundation-sys", @@ -3855,7 +3855,7 @@ dependencies = [ "bytes", "futures", "http 0.2.12", - "hyper 0.14.30", + "hyper 0.14.29", "log", "rand", "tokio", @@ -3933,12 +3933,12 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.6.0" +version = "2.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" +checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" dependencies = [ "equivalent", - "hashbrown 0.15.2", + "hashbrown 0.14.5", ] [[package]] @@ -3999,26 +3999,26 @@ dependencies = [ [[package]] name = "ipnet" -version = "2.10.0" +version = "2.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "187674a687eed5fe42285b40c6291f9a01517d415fad1c3cbc6a9f778af7fcd4" +checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" [[package]] name = "is-terminal" -version = "0.4.13" +version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "261f68e344040fbd0edea105bef17c66edf46f984ddb1115b775ce31be948f4b" +checksum = "f23ff5ef2b80d608d61efee834934d862cd92461afc0560dedf493e4c033738b" dependencies = [ - "hermit-abi 0.4.0", + "hermit-abi 0.3.9", "libc", "windows-sys 0.52.0", ] [[package]] name = "is_terminal_polyfill" -version = "1.70.1" +version = "1.70.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" +checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800" [[package]] name = "itertools" @@ -4055,27 +4055,27 @@ checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" [[package]] name = "jobserver" -version = "0.1.32" +version = "0.1.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48d1dbcbbeb6a7fec7e059840aa538bd62aaccf972c7346c4d9d2059312853d0" +checksum = "d2b099aaa34a9751c5bf0878add70444e1ed2dd73f347be99003d4577277de6e" dependencies = [ "libc", ] [[package]] name = "js-sys" -version = "0.3.70" +version = "0.3.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" +checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" dependencies = [ "wasm-bindgen", ] [[package]] name = "jsonrpsee" -version = "0.24.7" +version = "0.24.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5c71d8c1a731cc4227c2f698d377e7848ca12c8a48866fc5e6951c43a4db843" +checksum = "37b26c20e2178756451cfeb0661fb74c47dd5988cb7e3939de7e9241fd604d42" dependencies = [ "jsonrpsee-core", "jsonrpsee-proc-macros", @@ -4087,51 +4087,51 @@ dependencies = [ [[package]] name = "jsonrpsee-core" -version = "0.24.7" +version = "0.24.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2882f6f8acb9fdaec7cefc4fd607119a9bd709831df7d7672a1d3b644628280" +checksum = "456196007ca3a14db478346f58c7238028d55ee15c1df15115596e411ff27925" dependencies = [ "async-trait", "bytes", "futures-util", - "http 1.1.0", + "http 1.3.1", "http-body 1.0.1", "http-body-util", "jsonrpsee-types", "parking_lot 0.12.3", "rand", - "rustc-hash 2.0.0", + "rustc-hash 2.1.1", "serde", "serde_json", - "thiserror", + "thiserror 1.0.61", "tokio", "tracing", ] [[package]] name = "jsonrpsee-proc-macros" -version = "0.24.7" +version = "0.24.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c06c01ae0007548e73412c08e2285ffe5d723195bf268bce67b1b77c3bb2a14d" +checksum = "5e65763c942dfc9358146571911b0cd1c361c2d63e2d2305622d40d36376ca80" dependencies = [ "heck 0.5.0", - "proc-macro-crate 3.2.0", + "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.100", ] [[package]] name = "jsonrpsee-server" -version = "0.24.7" +version = "0.24.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82ad8ddc14be1d4290cd68046e7d1d37acd408efed6d3ca08aefcc3ad6da069c" +checksum = "55e363146da18e50ad2b51a0a7925fc423137a0b1371af8235b1c231a0647328" dependencies = [ "futures-util", - "http 1.1.0", + "http 1.3.1", "http-body 1.0.1", "http-body-util", - "hyper 1.5.0", + "hyper 1.6.0", "hyper-util", "jsonrpsee-core", "jsonrpsee-types", @@ -4140,7 +4140,7 @@ dependencies = [ "serde", "serde_json", "soketto", - "thiserror", + "thiserror 1.0.61", "tokio", "tokio-stream", "tokio-util", @@ -4150,21 +4150,21 @@ dependencies = [ [[package]] name = "jsonrpsee-types" -version = "0.24.7" +version = "0.24.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a178c60086f24cc35bb82f57c651d0d25d99c4742b4d335de04e97fa1f08a8a1" +checksum = "08a8e70baf945b6b5752fc8eb38c918a48f1234daf11355e07106d963f860089" dependencies = [ - "http 1.1.0", + "http 1.3.1", "serde", "serde_json", - "thiserror", + "thiserror 1.0.61", ] [[package]] name = "k256" -version = "0.13.4" +version = "0.13.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6e3919bbaa2945715f0bb6d3934a173d1e9a59ac23767fbaaef277265a7411b" +checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" dependencies = [ "cfg-if", "ecdsa", @@ -4224,9 +4224,9 @@ dependencies = [ [[package]] name = "lazy_static" -version = "1.5.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "lazycell" @@ -4236,18 +4236,18 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.159" +version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" [[package]] name = "libloading" -version = "0.8.5" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4" +checksum = "0c2a198fb6b0eada2a8df47933734e6d35d350665a33a3593d7164fa52c75c19" dependencies = [ "cfg-if", - "windows-targets 0.52.6", + "windows-targets 0.52.5", ] [[package]] @@ -4290,7 +4290,7 @@ dependencies = [ "multiaddr 0.18.2", "pin-project", "rw-stream-sink", - "thiserror", + "thiserror 1.0.61", ] [[package]] @@ -4331,7 +4331,7 @@ dependencies = [ "libp2p-identity", "log", "multiaddr 0.18.2", - "multihash 0.19.2", + "multihash 0.19.3", "multistream-select", "once_cell", "parking_lot 0.12.3", @@ -4340,7 +4340,7 @@ dependencies = [ "rand", "rw-stream-sink", "smallvec", - "thiserror", + "thiserror 1.0.61", "unsigned-varint 0.7.2", "void", ] @@ -4380,24 +4380,24 @@ dependencies = [ "quick-protobuf", "quick-protobuf-codec", "smallvec", - "thiserror", + "thiserror 1.0.61", "void", ] [[package]] name = "libp2p-identity" -version = "0.2.9" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55cca1eb2bc1fd29f099f3daaab7effd01e1a54b7c577d0ed082521034d912e8" +checksum = "257b5621d159b32282eac446bed6670c39c7dc68a200a992d8f056afa0066f6d" dependencies = [ "bs58 0.5.1", "ed25519-dalek", "hkdf", - "multihash 0.19.2", + "multihash 0.19.3", "quick-protobuf", "rand", "sha2 0.10.8", - "thiserror", + "thiserror 1.0.61", "tracing", "zeroize", ] @@ -4425,7 +4425,7 @@ dependencies = [ "rand", "sha2 0.10.8", "smallvec", - "thiserror", + "thiserror 1.0.61", "uint", "unsigned-varint 0.7.2", "void", @@ -4482,14 +4482,14 @@ dependencies = [ "libp2p-identity", "log", "multiaddr 0.18.2", - "multihash 0.19.2", + "multihash 0.19.3", "once_cell", "quick-protobuf", "rand", "sha2 0.10.8", "snow", "static_assertions", - "thiserror", + "thiserror 1.0.61", "x25519-dalek", "zeroize", ] @@ -4532,7 +4532,7 @@ dependencies = [ "ring 0.16.20", "rustls 0.21.12", "socket2 0.5.7", - "thiserror", + "thiserror 1.0.61", "tokio", ] @@ -4587,7 +4587,7 @@ dependencies = [ "proc-macro-warning 0.4.2", "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.100", ] [[package]] @@ -4621,7 +4621,7 @@ dependencies = [ "ring 0.16.20", "rustls 0.21.12", "rustls-webpki", - "thiserror", + "thiserror 1.0.61", "x509-parser 0.15.1", "yasna", ] @@ -4672,7 +4672,7 @@ dependencies = [ "pin-project-lite", "rw-stream-sink", "soketto", - "thiserror", + "thiserror 1.0.61", "url", "webpki-roots", ] @@ -4686,7 +4686,7 @@ dependencies = [ "futures", "libp2p-core", "log", - "thiserror", + "thiserror 1.0.61", "yamux", ] @@ -4696,9 +4696,8 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d" dependencies = [ - "bitflags 2.6.0", + "bitflags 2.5.0", "libc", - "redox_syscall 0.5.7", ] [[package]] @@ -4743,7 +4742,7 @@ checksum = "5be9b9bb642d8522a44d533eab56c16c738301965504753b03ad1de3425d5451" dependencies = [ "crunchy", "digest 0.9.0", - "subtle 2.6.1", + "subtle 2.6.0", ] [[package]] @@ -4777,9 +4776,9 @@ dependencies = [ [[package]] name = "libz-sys" -version = "1.1.20" +version = "1.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2d16453e800a8cf6dd2fc3eb4bc99b786a9b90c663b8559a5b1a041bf89e472" +checksum = "c15da26e5af7e25c90b37a2d75cdbf940cf4a55316de9d84c679c9b8bfabf82e" dependencies = [ "cc", "pkg-config", @@ -4857,7 +4856,7 @@ dependencies = [ "futures", "futures-timer", "hex-literal", - "indexmap 2.6.0", + "indexmap 2.2.6", "libc", "mockall 0.12.1", "multiaddr 0.17.1", @@ -4881,7 +4880,7 @@ dependencies = [ "socket2 0.5.7", "static_assertions", "str0m", - "thiserror", + "thiserror 1.0.61", "tokio", "tokio-stream", "tokio-tungstenite", @@ -4910,9 +4909,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.22" +version = "0.4.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" +checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94" [[package]] name = "lru" @@ -4943,18 +4942,19 @@ dependencies = [ [[package]] name = "lz4" -version = "1.28.0" +version = "1.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d1febb2b4a79ddd1980eede06a8f7902197960aa0383ffcfdd62fe723036725" +checksum = "d6eab492fe7f8651add23237ea56dbf11b3c4ff762ab83d40a47f11433421f91" dependencies = [ + "libc", "lz4-sys", ] [[package]] name = "lz4-sys" -version = "1.11.1+lz4-1.10.0" +version = "1.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6bd8c0d6c6ed0cd30b3652886bb8711dc4bb01d637a68105a3d5158039b418e6" +checksum = "e9764018d143cc854c9f17f0b907de70f14393b1f502da6375dce70f00514eb3" dependencies = [ "cc", "libc", @@ -4978,7 +4978,7 @@ dependencies = [ "macro_magic_core", "macro_magic_macros", "quote", - "syn 2.0.90", + "syn 2.0.100", ] [[package]] @@ -4992,7 +4992,7 @@ dependencies = [ "macro_magic_core_macros", "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.100", ] [[package]] @@ -5003,7 +5003,7 @@ checksum = "b02abfe41815b5bd98dbd4260173db2c116dda171dc0fe7838cb206333b83308" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.100", ] [[package]] @@ -5014,7 +5014,7 @@ checksum = "73ea28ee64b88876bf45277ed9a5817c1817df061a74f2b988971a12570e5869" dependencies = [ "macro_magic_core", "quote", - "syn 2.0.90", + "syn 2.0.100", ] [[package]] @@ -5040,9 +5040,9 @@ checksum = "2532096657941c2fea9c289d370a250971c689d4f143798ff67113ec042024a5" [[package]] name = "matrixmultiply" -version = "0.3.9" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9380b911e3e96d10c1f415da0876389aaf1b56759054eeb0de7df940c456ba1a" +checksum = "7574c1cf36da4798ab73da5b215bbf444f50718207754cb522201d78d1cd0ff2" dependencies = [ "autocfg", "rawpointer", @@ -5060,7 +5060,7 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b2cffa4ad52c6f791f4f8b15f0c05f9824b2ced1160e88cc393d64fff9a8ac64" dependencies = [ - "rustix 0.38.37", + "rustix 0.38.34", ] [[package]] @@ -5074,9 +5074,9 @@ dependencies = [ [[package]] name = "memmap2" -version = "0.9.5" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd3f7eed9d3848f8b98834af67102b720745c4ec028fcd0aa0239277e7de374f" +checksum = "fe751422e4a8caa417e13c3ea66452215d7d63e19e604f4980461212f3ae1322" dependencies = [ "libc", ] @@ -5133,23 +5133,22 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" [[package]] name = "miniz_oxide" -version = "0.8.0" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2d80299ef12ff69b16a84bb182e3b9df68b5a91574d3d4fa6e41b65deec4df1" +checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" dependencies = [ - "adler2", + "adler", ] [[package]] name = "mio" -version = "1.0.2" +version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80e04d1dcff3aae0704555fe5fee3bcfaf3d1fdf8a7e521d5b9d2b42acb52cec" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" dependencies = [ - "hermit-abi 0.3.9", "libc", "wasi", - "windows-sys 0.52.0", + "windows-sys 0.48.0", ] [[package]] @@ -5172,8 +5171,8 @@ dependencies = [ "rand", "rand_chacha", "rand_distr", - "subtle 2.6.1", - "thiserror", + "subtle 2.6.0", + "thiserror 1.0.61", "zeroize", ] @@ -5203,7 +5202,7 @@ dependencies = [ "fragile", "lazy_static", "mockall_derive 0.12.1", - "predicates 3.1.2", + "predicates 3.1.3", "predicates-tree", ] @@ -5228,7 +5227,7 @@ dependencies = [ "cfg-if", "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.100", ] [[package]] @@ -5261,7 +5260,7 @@ dependencies = [ "data-encoding", "libp2p-identity", "multibase", - "multihash 0.19.2", + "multihash 0.19.3", "percent-encoding", "serde", "static_assertions", @@ -5316,9 +5315,9 @@ dependencies = [ [[package]] name = "multihash" -version = "0.19.2" +version = "0.19.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc41f430805af9d1cf4adae4ed2149c759b877b01d909a1f40256188d09345d2" +checksum = "6b430e7953c29dd6a09afc29ff0bb69c6e306329ee6794700aee27b76a1aea8d" dependencies = [ "core2", "unsigned-varint 0.8.0", @@ -5376,13 +5375,13 @@ dependencies = [ [[package]] name = "nalgebra-macros" -version = "0.2.2" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "254a5372af8fc138e36684761d3c0cdb758a4410e938babcff1c860ce14ddbfc" +checksum = "91761aed67d03ad966ef783ae962ef9bbaca728d2dd7ceb7939ec110fffad998" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 1.0.109", ] [[package]] @@ -5396,9 +5395,9 @@ dependencies = [ [[package]] name = "native-tls" -version = "0.2.12" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" +checksum = "87de3442987e9dbec73158d5c715e7ad9072fda936bb03d19d7fa10e00520f0e" dependencies = [ "libc", "log", @@ -5459,7 +5458,7 @@ dependencies = [ "anyhow", "byteorder", "paste", - "thiserror", + "thiserror 1.0.61", ] [[package]] @@ -5473,7 +5472,7 @@ dependencies = [ "log", "netlink-packet-core", "netlink-sys", - "thiserror", + "thiserror 1.0.61", "tokio", ] @@ -5498,7 +5497,7 @@ checksum = "a4a43439bf756eed340bdf8feba761e2d50c7d47175d87545cd5cbe4a137c4d1" dependencies = [ "cc", "libc", - "thiserror", + "thiserror 1.0.61", "winapi", ] @@ -5542,7 +5541,7 @@ dependencies = [ "futures", "hex", "jsonrpsee", - "memmap2 0.9.5", + "memmap2 0.9.4", "node-subtensor-runtime", "num-traits", "pallet-commitments", @@ -5598,7 +5597,7 @@ dependencies = [ "subtensor-custom-rpc", "subtensor-custom-rpc-runtime-api", "subtensor-runtime-common", - "thiserror", + "thiserror 1.0.61", ] [[package]] @@ -5742,9 +5741,9 @@ dependencies = [ [[package]] name = "num-bigint" -version = "0.4.6" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9" +checksum = "c165a9ab64cf766f73521c0dd2cfdff64f488b8f0b3e621face3462d3db536d7" dependencies = [ "num-integer", "num-traits", @@ -5841,10 +5840,10 @@ version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af1844ef2428cc3e1cb900be36181049ef3d3193c63e43026cfe202983b27a56" dependencies = [ - "proc-macro-crate 3.2.0", + "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.100", ] [[package]] @@ -5870,9 +5869,9 @@ dependencies = [ [[package]] name = "object" -version = "0.36.4" +version = "0.36.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "084f1a5821ac4c651660a94a7153d27ac9d8a53736203f58b31945ded098070a" +checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" dependencies = [ "memchr", ] @@ -5897,12 +5896,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.20.1" +version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82881c4be219ab5faaf2ad5e5e5ecdff8c66bd7402ca3160975c93b24961afd1" -dependencies = [ - "portable-atomic", -] +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "opaque-debug" @@ -5922,7 +5918,7 @@ version = "0.10.72" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fedfea7d58a1f73118430a55da6a286e7b044961736ce96a16a17068ea25e5da" dependencies = [ - "bitflags 2.6.0", + "bitflags 2.5.0", "cfg-if", "foreign-types", "libc", @@ -5939,7 +5935,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.100", ] [[package]] @@ -5950,9 +5946,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-src" -version = "300.4.0+3.4.0" +version = "300.5.0+3.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a709e02f2b4aca747929cca5ed248880847c650233cf8b8cdc48f40aaf4898a6" +checksum = "e8ce546f549326b0e6052b649198487d91320875da901e7bd11a06d1ee3f9c2f" dependencies = [ "cc", ] @@ -6659,7 +6655,7 @@ version = "3.6.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d830939c76d294956402033aee57a6da7b438f2294eb94864c37b0569053a42c" dependencies = [ - "proc-macro-crate 3.2.0", + "proc-macro-crate 3.1.0", "proc-macro2", "quote", "syn 1.0.109", @@ -6702,9 +6698,9 @@ checksum = "e1ad0aff30c1da14b1254fcb2af73e1fa9a28670e584a626f53a369d0e157304" [[package]] name = "parking" -version = "2.2.1" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f38d5652c16fde515bb1ecef450ab0f6a219d619a7274976324d5e377f7dceba" +checksum = "bb813b8af86854136c6922af0598d719255ecb2179515e6e7730d468f05c9cae" [[package]] name = "parking_lot" @@ -6749,9 +6745,9 @@ checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" dependencies = [ "cfg-if", "libc", - "redox_syscall 0.5.7", + "redox_syscall 0.5.2", "smallvec", - "windows-targets 0.52.6", + "windows-targets 0.52.5", ] [[package]] @@ -6768,7 +6764,7 @@ checksum = "346f04948ba92c43e8469c1ee6736c7563d71012b17d40745260fe106aac2166" dependencies = [ "base64ct", "rand_core", - "subtle 2.6.1", + "subtle 2.6.0", ] [[package]] @@ -6810,20 +6806,20 @@ checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" [[package]] name = "pest" -version = "2.7.13" +version = "2.7.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fdbef9d1d47087a895abd220ed25eb4ad973a5e26f6a4367b038c25e28dfc2d9" +checksum = "560131c633294438da9f7c4b08189194b20946c8274c6b9e38881a7874dc8ee8" dependencies = [ "memchr", - "thiserror", + "thiserror 1.0.61", "ucd-trie", ] [[package]] name = "pest_derive" -version = "2.7.13" +version = "2.7.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d3a6e3394ec80feb3b6393c725571754c6188490265c61aaf260810d6b95aa0" +checksum = "26293c9193fbca7b1a3bf9b79dc1e388e927e6cacaa78b4a3ab705a1d3d41459" dependencies = [ "pest", "pest_generator", @@ -6831,22 +6827,22 @@ dependencies = [ [[package]] name = "pest_generator" -version = "2.7.13" +version = "2.7.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94429506bde1ca69d1b5601962c73f4172ab4726571a59ea95931218cb0e930e" +checksum = "3ec22af7d3fb470a85dd2ca96b7c577a1eb4ef6f1683a9fe9a8c16e136c04687" dependencies = [ "pest", "pest_meta", "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.100", ] [[package]] name = "pest_meta" -version = "2.7.13" +version = "2.7.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac8a071862e93690b6e34e9a5fb8e33ff3734473ac0245b27232222c4906a33f" +checksum = "d7a240022f37c361ec1878d646fc5b7d7c4d28d5946e1a80ad5a7a4f4ca0bdcd" dependencies = [ "once_cell", "pest", @@ -6860,7 +6856,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4c5cc86750666a3ed20bdaf5ca2a0344f9c67674cae0515bec2da16fbaa47db" dependencies = [ "fixedbitset", - "indexmap 2.6.0", + "indexmap 2.2.6", ] [[package]] @@ -6880,7 +6876,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.100", ] [[package]] @@ -6907,9 +6903,9 @@ dependencies = [ [[package]] name = "pkg-config" -version = "0.3.31" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" +checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" [[package]] name = "polkavm" @@ -6960,7 +6956,7 @@ dependencies = [ "polkavm-common", "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.100", ] [[package]] @@ -6970,7 +6966,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ba81f7b5faac81e528eb6158a6f3c9e0bb1008e0ffa19653bc8dea925ecb429" dependencies = [ "polkavm-derive-impl", - "syn 2.0.90", + "syn 2.0.100", ] [[package]] @@ -6996,17 +6992,17 @@ checksum = "26e85d3456948e650dff0cfc85603915847faf893ed1e66b020bb82ef4557120" [[package]] name = "polling" -version = "3.7.3" +version = "3.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc2790cd301dec6cd3b7a025e4815cf825724a51c98dccfe6a3e55f05ffb6511" +checksum = "a3ed00ed3fbf728b5816498ecd316d1716eecaced9c0c8d2c5a6740ca214985b" dependencies = [ "cfg-if", "concurrent-queue", "hermit-abi 0.4.0", "pin-project-lite", - "rustix 0.38.37", + "rustix 0.38.34", "tracing", - "windows-sys 0.59.0", + "windows-sys 0.52.0", ] [[package]] @@ -7034,9 +7030,9 @@ dependencies = [ [[package]] name = "portable-atomic" -version = "1.9.0" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc9c68a3f6da06753e9335d63e27f6b9754dd1920d941135b7ea8224f141adb2" +checksum = "7170ef9988bc169ba16dd36a7fa041e5c4cbeb6a35b76d4c03daded371eae7c0" [[package]] name = "powerfmt" @@ -7046,12 +7042,9 @@ checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" [[package]] name = "ppv-lite86" -version = "0.2.20" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" -dependencies = [ - "zerocopy", -] +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "precompile-utils" @@ -7084,7 +7077,7 @@ source = "git+https://github.com/opentensor/frontier?rev=635bdac882#635bdac88233 dependencies = [ "case", "num_enum", - "prettyplease 0.2.22", + "prettyplease 0.2.20", "proc-macro2", "quote", "sp-crypto-hashing 0.1.0 (git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-stable2409)", @@ -7107,9 +7100,9 @@ dependencies = [ [[package]] name = "predicates" -version = "3.1.2" +version = "3.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e9086cc7640c29a356d1a29fd134380bee9d8f79a17410aa76e7ad295f42c97" +checksum = "a5d19ee57562043d37e82899fade9a22ebab7be9cef5026b07fda9cdd4293573" dependencies = [ "anstyle", "predicates-core", @@ -7117,15 +7110,15 @@ dependencies = [ [[package]] name = "predicates-core" -version = "1.0.8" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae8177bee8e75d6846599c6b9ff679ed51e882816914eec639944d7c9aa11931" +checksum = "b794032607612e7abeb4db69adb4e33590fa6cf1149e95fd7cb00e634b92f174" [[package]] name = "predicates-tree" -version = "1.0.11" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41b740d195ed3166cd147c8047ec98db0e22ec019eb8eeb76d343b795304fb13" +checksum = "368ba315fb8c5052ab692e68a0eefec6ec57b23a36959c14496f0b0df2c0cecf" dependencies = [ "predicates-core", "termtree", @@ -7143,12 +7136,12 @@ dependencies = [ [[package]] name = "prettyplease" -version = "0.2.22" +version = "0.2.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "479cf940fbbb3426c32c5d5176f62ad57549a0bb84773423ba8be9d089f5faba" +checksum = "5f12335488a2f3b0a83b14edad48dca9879ce89b2edd10e80237e4e852dd645e" dependencies = [ "proc-macro2", - "syn 2.0.90", + "syn 2.0.100", ] [[package]] @@ -7171,17 +7164,17 @@ version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e17d47ce914bf4de440332250b0edd23ce48c005f59fab39d3335866b114f11a" dependencies = [ - "thiserror", + "thiserror 1.0.61", "toml 0.5.11", ] [[package]] name = "proc-macro-crate" -version = "3.2.0" +version = "3.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ecf48c7ca261d60b74ab1a7b20da18bede46776b2e55535cb958eb595c5fa7b" +checksum = "6d37c51ca738a55da99dc0c4a34860fd675453b8b36209178c2249bb13651284" dependencies = [ - "toml_edit", + "toml_edit 0.21.1", ] [[package]] @@ -7216,7 +7209,7 @@ checksum = "3d1eaa7fa0aa1929ffdf7eeb6eac234dde6268914a14ad44d23521ab6a9b258e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.100", ] [[package]] @@ -7227,14 +7220,14 @@ checksum = "834da187cfe638ae8abb0203f0b33e5ccdb02a28e7199f2f47b3e2754f50edca" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.100", ] [[package]] name = "proc-macro2" -version = "1.0.92" +version = "1.0.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0" +checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778" dependencies = [ "unicode-ident", ] @@ -7255,7 +7248,7 @@ dependencies = [ "quote", "regex", "sp-crypto-hashing 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 2.0.90", + "syn 2.0.100", ] [[package]] @@ -7269,7 +7262,7 @@ dependencies = [ "lazy_static", "memchr", "parking_lot 0.12.3", - "thiserror", + "thiserror 1.0.61", ] [[package]] @@ -7292,7 +7285,7 @@ checksum = "440f724eba9f6996b75d63681b0a92b06947f1457076d503a4d2e2c8f56442b8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.100", ] [[package]] @@ -7350,11 +7343,11 @@ dependencies = [ "multimap", "once_cell", "petgraph", - "prettyplease 0.2.22", + "prettyplease 0.2.20", "prost 0.12.6", "prost-types 0.12.6", "regex", - "syn 2.0.90", + "syn 2.0.100", "tempfile", ] @@ -7381,7 +7374,7 @@ dependencies = [ "itertools 0.12.1", "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.100", ] [[package]] @@ -7404,9 +7397,9 @@ dependencies = [ [[package]] name = "psm" -version = "0.1.23" +version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa37f80ca58604976033fae9515a8a2989fc13797d953f7c04fb8fa36a11f205" +checksum = "5787f7cda34e3033a72192c018bc5883100330f362ef279a8cbccfce8bb4e874" dependencies = [ "cc", ] @@ -7450,7 +7443,7 @@ dependencies = [ "asynchronous-codec", "bytes", "quick-protobuf", - "thiserror", + "thiserror 1.0.61", "unsigned-varint 0.7.2", ] @@ -7466,7 +7459,7 @@ dependencies = [ "quinn-udp 0.3.2", "rustc-hash 1.1.0", "rustls 0.20.9", - "thiserror", + "thiserror 1.0.61", "tokio", "tracing", "webpki", @@ -7485,7 +7478,7 @@ dependencies = [ "quinn-udp 0.4.1", "rustc-hash 1.1.0", "rustls 0.21.12", - "thiserror", + "thiserror 1.0.61", "tokio", "tracing", ] @@ -7502,7 +7495,7 @@ dependencies = [ "rustc-hash 1.1.0", "rustls 0.20.9", "slab", - "thiserror", + "thiserror 1.0.61", "tinyvec", "tracing", "webpki", @@ -7520,7 +7513,7 @@ dependencies = [ "rustc-hash 1.1.0", "rustls 0.21.12", "slab", - "thiserror", + "thiserror 1.0.61", "tinyvec", "tracing", ] @@ -7553,9 +7546,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.37" +version = "1.0.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" dependencies = [ "proc-macro2", ] @@ -7617,11 +7610,11 @@ dependencies = [ [[package]] name = "raw-cpuid" -version = "11.2.0" +version = "11.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ab240315c661615f2ee9f0f2cd32d5a7343a84d5ebcccb99d46e6637565e7b0" +checksum = "e29830cbb1290e404f24c73af91c5d8d631ce7e128691e9477556b540cd01ecd" dependencies = [ - "bitflags 2.6.0", + "bitflags 2.5.0", ] [[package]] @@ -7673,22 +7666,31 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.5.7" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" +checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" dependencies = [ - "bitflags 2.6.0", + "bitflags 1.3.2", +] + +[[package]] +name = "redox_syscall" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c82cf8cff14456045f55ec4241383baeff27af886adb72ffb2162f99911de0fd" +dependencies = [ + "bitflags 2.5.0", ] [[package]] name = "redox_users" -version = "0.4.6" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43" +checksum = "bd283d9651eeda4b2a83a43c1c91b266c40fd76ecd39a50a8c630ae69dc72891" dependencies = [ "getrandom", "libredox", - "thiserror", + "thiserror 1.0.61", ] [[package]] @@ -7708,7 +7710,7 @@ checksum = "bcc303e793d3734489387d205e9b186fac9c6cfacedd98cbb2e8a5943595f3e6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.100", ] [[package]] @@ -7738,14 +7740,14 @@ dependencies = [ [[package]] name = "regex" -version = "1.11.0" +version = "1.10.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38200e5ee88914975b69f657f0801b6f6dccafd44fd9326302a4aaeecfacb1d8" +checksum = "b91213439dad192326a0d7c6ee3955910425f441d7038e0d6933b0aec5c4517f" dependencies = [ "aho-corasick", "memchr", - "regex-automata 0.4.8", - "regex-syntax 0.8.5", + "regex-automata 0.4.7", + "regex-syntax 0.8.4", ] [[package]] @@ -7759,13 +7761,13 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.8" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "368758f23274712b504848e9d5a6f010445cc8b87a7cdb4d7cbee666c1288da3" +checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" dependencies = [ "aho-corasick", "memchr", - "regex-syntax 0.8.5", + "regex-syntax 0.8.4", ] [[package]] @@ -7776,9 +7778,9 @@ checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" [[package]] name = "regex-syntax" -version = "0.8.5" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" +checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" [[package]] name = "resolv-conf" @@ -7797,7 +7799,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" dependencies = [ "hmac 0.12.1", - "subtle 2.6.1", + "subtle 2.6.0", ] [[package]] @@ -7817,14 +7819,15 @@ dependencies = [ [[package]] name = "ring" -version = "0.17.13" +version = "0.17.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70ac5d832aa16abd7d1def883a8545280c20a60f523a370aa3a9617c2b8550ee" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" dependencies = [ "cc", "cfg-if", "getrandom", "libc", + "spin 0.9.8", "untrusted 0.9.0", "windows-sys 0.52.0", ] @@ -7898,7 +7901,7 @@ dependencies = [ "netlink-packet-route", "netlink-proto", "nix", - "thiserror", + "thiserror 1.0.61", "tokio", ] @@ -7926,9 +7929,9 @@ checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" [[package]] name = "rustc-hash" -version = "2.0.0" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" +checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d" [[package]] name = "rustc-hex" @@ -7947,9 +7950,9 @@ dependencies = [ [[package]] name = "rustc_version" -version = "0.4.1" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" +checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" dependencies = [ "semver 1.0.23", ] @@ -7979,11 +7982,11 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.37" +version = "0.38.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8acb788b847c24f28525660c4d7758620a7210875711f79e7f663cc152726811" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" dependencies = [ - "bitflags 2.6.0", + "bitflags 2.5.0", "errno", "libc", "linux-raw-sys 0.4.14", @@ -8008,7 +8011,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f56a14d1f48b391359b22f731fd4bd7e43c97f3c50eee276f3aa09c94784d3e" dependencies = [ "log", - "ring 0.17.13", + "ring 0.17.8", "rustls-webpki", "sct", ] @@ -8040,7 +8043,7 @@ version = "0.101.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b6275d1ee7a1cd780b64aca7726599a1dbc893b1e64144529e55c3c2f745765" dependencies = [ - "ring 0.17.13", + "ring 0.17.8", "untrusted 0.9.0", ] @@ -8111,7 +8114,7 @@ dependencies = [ "log", "sp-core", "sp-wasm-interface 21.0.1", - "thiserror", + "thiserror 1.0.61", ] [[package]] @@ -8159,7 +8162,7 @@ dependencies = [ "array-bytes", "docify", "log", - "memmap2 0.9.5", + "memmap2 0.9.4", "parity-scale-codec", "sc-chain-spec-derive", "sc-client-api", @@ -8183,10 +8186,10 @@ name = "sc-chain-spec-derive" version = "12.0.0" source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-stable2409#87971b3e92721bdf10bf40b410eaae779d494ca0" dependencies = [ - "proc-macro-crate 3.2.0", + "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.100", ] [[package]] @@ -8226,7 +8229,7 @@ dependencies = [ "sp-panic-handler", "sp-runtime", "sp-version", - "thiserror", + "thiserror 1.0.61", "tokio", ] @@ -8304,7 +8307,7 @@ dependencies = [ "sp-runtime", "sp-state-machine", "substrate-prometheus-endpoint", - "thiserror", + "thiserror 1.0.61", ] [[package]] @@ -8333,7 +8336,7 @@ dependencies = [ "sp-keystore", "sp-runtime", "substrate-prometheus-endpoint", - "thiserror", + "thiserror 1.0.61", ] [[package]] @@ -8369,7 +8372,7 @@ dependencies = [ "sp-keystore", "sp-runtime", "substrate-prometheus-endpoint", - "thiserror", + "thiserror 1.0.61", ] [[package]] @@ -8426,7 +8429,7 @@ dependencies = [ "sp-keystore", "sp-runtime", "substrate-prometheus-endpoint", - "thiserror", + "thiserror 1.0.61", ] [[package]] @@ -8446,7 +8449,7 @@ dependencies = [ "sp-blockchain", "sp-core", "sp-runtime", - "thiserror", + "thiserror 1.0.61", ] [[package]] @@ -8481,7 +8484,7 @@ dependencies = [ "sp-runtime", "sp-timestamp", "substrate-prometheus-endpoint", - "thiserror", + "thiserror 1.0.61", ] [[package]] @@ -8539,7 +8542,7 @@ dependencies = [ "sc-allocator", "sp-maybe-compressed-blob", "sp-wasm-interface 21.0.1", - "thiserror", + "thiserror 1.0.61", "wasm-instrument", ] @@ -8600,7 +8603,7 @@ dependencies = [ "sp-application-crypto", "sp-core", "sp-keystore", - "thiserror", + "thiserror 1.0.61", ] [[package]] @@ -8629,7 +8632,7 @@ dependencies = [ "sp-keystore", "sp-mixnet", "sp-runtime", - "thiserror", + "thiserror 1.0.61", ] [[package]] @@ -8674,7 +8677,7 @@ dependencies = [ "sp-core", "sp-runtime", "substrate-prometheus-endpoint", - "thiserror", + "thiserror 1.0.61", "tokio", "tokio-stream", "unsigned-varint 0.7.2", @@ -8738,7 +8741,7 @@ dependencies = [ "sp-blockchain", "sp-core", "sp-runtime", - "thiserror", + "thiserror 1.0.61", ] [[package]] @@ -8773,7 +8776,7 @@ dependencies = [ "sp-core", "sp-runtime", "substrate-prometheus-endpoint", - "thiserror", + "thiserror 1.0.61", "tokio", "tokio-stream", ] @@ -8808,9 +8811,9 @@ dependencies = [ "litep2p", "log", "multiaddr 0.18.2", - "multihash 0.19.2", + "multihash 0.19.3", "rand", - "thiserror", + "thiserror 1.0.61", "zeroize", ] @@ -8824,7 +8827,7 @@ dependencies = [ "fnv", "futures", "futures-timer", - "hyper 0.14.30", + "hyper 0.14.29", "hyper-rustls", "log", "num_cpus", @@ -8906,7 +8909,7 @@ dependencies = [ "sp-rpc", "sp-runtime", "sp-version", - "thiserror", + "thiserror 1.0.61", ] [[package]] @@ -8918,9 +8921,9 @@ dependencies = [ "forwarded-header-value", "futures", "governor", - "http 1.1.0", + "http 1.3.1", "http-body-util", - "hyper 1.5.0", + "hyper 1.6.0", "ip_network", "jsonrpsee", "log", @@ -8960,7 +8963,7 @@ dependencies = [ "sp-rpc", "sp-runtime", "sp-version", - "thiserror", + "thiserror 1.0.61", "tokio", "tokio-stream", ] @@ -9023,7 +9026,7 @@ dependencies = [ "static_init", "substrate-prometheus-endpoint", "tempfile", - "thiserror", + "thiserror 1.0.61", "tokio", "tracing", "tracing-futures", @@ -9077,7 +9080,7 @@ dependencies = [ "sc-utils", "serde", "serde_json", - "thiserror", + "thiserror 1.0.61", "wasm-timer", ] @@ -9104,7 +9107,7 @@ dependencies = [ "sp-rpc", "sp-runtime", "sp-tracing 17.0.1", - "thiserror", + "thiserror 1.0.61", "tracing", "tracing-log", "tracing-subscriber 0.3.18", @@ -9115,10 +9118,10 @@ name = "sc-tracing-proc-macro" version = "11.0.0" source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-stable2409#87971b3e92721bdf10bf40b410eaae779d494ca0" dependencies = [ - "proc-macro-crate 3.2.0", + "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.100", ] [[package]] @@ -9145,7 +9148,7 @@ dependencies = [ "sp-tracing 17.0.1", "sp-transaction-pool", "substrate-prometheus-endpoint", - "thiserror", + "thiserror 1.0.61", ] [[package]] @@ -9161,7 +9164,7 @@ dependencies = [ "sp-blockchain", "sp-core", "sp-runtime", - "thiserror", + "thiserror 1.0.61", ] [[package]] @@ -9222,7 +9225,7 @@ version = "2.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2d35494501194174bda522a32605929eefc9ecf7e0a326c26db1fdd85881eb62" dependencies = [ - "proc-macro-crate 3.2.0", + "proc-macro-crate 3.1.0", "proc-macro2", "quote", "syn 1.0.109", @@ -9236,11 +9239,11 @@ checksum = "f0cded6518aa0bd6c1be2b88ac81bf7044992f0f154bfbabd5ad34f43512abcb" [[package]] name = "schannel" -version = "0.1.24" +version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9aaafd5a2b6e3d657ff009d82fbd630b6bd54dd4eb06f21693925cdf80f9b8b" +checksum = "fbc91545643bcf3a0bbb6569265615222618bdf33ce4ffbbd13c4bbd4c093534" dependencies = [ - "windows-sys 0.59.0", + "windows-sys 0.52.0", ] [[package]] @@ -9269,7 +9272,7 @@ dependencies = [ "rand_core", "serde_bytes", "sha2 0.10.8", - "subtle 2.6.1", + "subtle 2.6.0", "zeroize", ] @@ -9291,7 +9294,7 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "da046153aa2352493d6cb7da4b6e5c0c057d8a1d0a9aa8560baffdd945acd414" dependencies = [ - "ring 0.17.13", + "ring 0.17.8", "untrusted 0.9.0", ] @@ -9307,7 +9310,7 @@ dependencies = [ "log", "rand", "slab", - "thiserror", + "thiserror 1.0.61", ] [[package]] @@ -9321,7 +9324,7 @@ dependencies = [ "generic-array 0.14.7", "pkcs8", "serdect", - "subtle 2.6.1", + "subtle 2.6.0", "zeroize", ] @@ -9354,11 +9357,11 @@ dependencies = [ [[package]] name = "security-framework" -version = "2.11.1" +version = "2.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" +checksum = "c627723fd09706bacdb5cf41499e95098555af3c3c29d014dc3c458ef6be11c0" dependencies = [ - "bitflags 2.6.0", + "bitflags 2.5.0", "core-foundation", "core-foundation-sys", "libc", @@ -9367,9 +9370,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.12.0" +version = "2.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" +checksum = "317936bbbd05227752583946b9e66d7ce3b489f84e11a94a510b4437fef407d7" dependencies = [ "core-foundation-sys", "libc", @@ -9416,9 +9419,9 @@ checksum = "cd0b0ec5f1c1ca621c432a25813d8d60c88abe6d3e08a3eb9cf37d97a0fe3d73" [[package]] name = "serde" -version = "1.0.216" +version = "1.0.219" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b9781016e935a97e8beecf0c933758c97a5520d32930e460142b4cd80c6338e" +checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6" dependencies = [ "serde_derive", ] @@ -9434,9 +9437,9 @@ dependencies = [ [[package]] name = "serde_bytes" -version = "0.11.15" +version = "0.11.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "387cc504cb06bb40a96c8e04e951fe01854cf6bc921053c954e4a606d9675c6a" +checksum = "8b8497c313fd43ab992087548117643f6fcd935cbf36f176ffda0aacf9591734" dependencies = [ "serde", ] @@ -9453,20 +9456,20 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.216" +version = "1.0.219" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46f859dbbf73865c6627ed570e78961cd3ac92407a2d117204c49232485da55e" +checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.100", ] [[package]] name = "serde_json" -version = "1.0.128" +version = "1.0.140" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373" dependencies = [ "itoa", "memchr", @@ -9476,9 +9479,9 @@ dependencies = [ [[package]] name = "serde_spanned" -version = "0.6.8" +version = "0.6.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87607cb1398ed59d48732e575a4c28a7a8ebf2454b964fe3f224f2afc07909e1" +checksum = "79e674e01f999af37c49f70a6ede167a8a60b2503e56c5599532a65baa5969a0" dependencies = [ "serde", ] @@ -9520,7 +9523,7 @@ dependencies = [ "darling", "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.100", ] [[package]] @@ -9661,7 +9664,7 @@ version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cae9a3fcdadafb6d97f4c0e007e4247b114ee0f119f650c3cbf3a8b3a1479694" dependencies = [ - "bitflags 2.6.0", + "bitflags 2.5.0", ] [[package]] @@ -9714,10 +9717,10 @@ dependencies = [ "chacha20poly1305", "curve25519-dalek", "rand_core", - "ring 0.17.13", - "rustc_version 0.4.1", + "ring 0.17.8", + "rustc_version 0.4.0", "sha2 0.10.8", - "subtle 2.6.1", + "subtle 2.6.0", ] [[package]] @@ -9742,14 +9745,14 @@ dependencies = [ [[package]] name = "soketto" -version = "0.8.0" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37468c595637c10857701c990f93a40ce0e357cedb0953d1c26c8d8027f9bb53" +checksum = "2e859df029d160cb88608f5d7df7fb4753fd20fdfb4de5644f3d8b8440841721" dependencies = [ "base64 0.22.1", "bytes", "futures", - "http 1.1.0", + "http 1.3.1", "httparse", "log", "rand", @@ -9775,7 +9778,7 @@ dependencies = [ "sp-state-machine", "sp-trie", "sp-version", - "thiserror", + "thiserror 1.0.61", ] [[package]] @@ -9786,10 +9789,10 @@ dependencies = [ "Inflector", "blake2 0.10.6", "expander", - "proc-macro-crate 3.2.0", + "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.100", ] [[package]] @@ -9821,7 +9824,7 @@ dependencies = [ [[package]] name = "sp-ark-bls12-381" version = "0.4.2" -source = "git+https://github.com/paritytech/substrate-curves#caa2eed74beb885dd07c7db5f916f2281dad818f" +source = "git+https://github.com/paritytech/substrate-curves#f08093a5f7c32778eae1295430ec064dccd062a6" dependencies = [ "ark-bls12-381-ext", "sp-crypto-ec-utils 0.10.0", @@ -9852,7 +9855,7 @@ dependencies = [ "sp-database", "sp-runtime", "sp-state-machine", - "thiserror", + "thiserror 1.0.61", "tracing", ] @@ -9868,7 +9871,7 @@ dependencies = [ "sp-inherents", "sp-runtime", "sp-state-machine", - "thiserror", + "thiserror 1.0.61", ] [[package]] @@ -9973,7 +9976,7 @@ dependencies = [ "sp-storage 21.0.0", "ss58-registry", "substrate-bip39", - "thiserror", + "thiserror 1.0.61", "tracing", "w3f-bls", "zeroize", @@ -9982,7 +9985,7 @@ dependencies = [ [[package]] name = "sp-crypto-ec-utils" version = "0.10.0" -source = "git+https://github.com/paritytech/polkadot-sdk#8614dc0e055d06de4a3774ac1da0a422b33f34e2" +source = "git+https://github.com/paritytech/polkadot-sdk#c4b3c1c6c6e492c4196e06fbba824a58e8119a3b" dependencies = [ "ark-bls12-377", "ark-bls12-377-ext", @@ -10053,7 +10056,7 @@ source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-stable dependencies = [ "quote", "sp-crypto-hashing 0.1.0 (git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-stable2409)", - "syn 2.0.90", + "syn 2.0.100", ] [[package]] @@ -10072,23 +10075,23 @@ source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-stable dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.100", ] [[package]] name = "sp-debug-derive" version = "14.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#8614dc0e055d06de4a3774ac1da0a422b33f34e2" +source = "git+https://github.com/paritytech/polkadot-sdk#c4b3c1c6c6e492c4196e06fbba824a58e8119a3b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.100", ] [[package]] name = "sp-externalities" version = "0.25.0" -source = "git+https://github.com/paritytech/polkadot-sdk#8614dc0e055d06de4a3774ac1da0a422b33f34e2" +source = "git+https://github.com/paritytech/polkadot-sdk#c4b3c1c6c6e492c4196e06fbba824a58e8119a3b" dependencies = [ "environmental", "parity-scale-codec", @@ -10127,7 +10130,7 @@ dependencies = [ "parity-scale-codec", "scale-info", "sp-runtime", - "thiserror", + "thiserror 1.0.61", ] [[package]] @@ -10163,7 +10166,7 @@ source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-stable dependencies = [ "sp-core", "sp-runtime", - "strum 0.26.3", + "strum 0.26.2", ] [[package]] @@ -10182,7 +10185,7 @@ name = "sp-maybe-compressed-blob" version = "11.0.0" source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-stable2409#87971b3e92721bdf10bf40b410eaae779d494ca0" dependencies = [ - "thiserror", + "thiserror 1.0.61", "zstd 0.12.4", ] @@ -10266,7 +10269,7 @@ dependencies = [ [[package]] name = "sp-runtime-interface" version = "24.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#8614dc0e055d06de4a3774ac1da0a422b33f34e2" +source = "git+https://github.com/paritytech/polkadot-sdk#c4b3c1c6c6e492c4196e06fbba824a58e8119a3b" dependencies = [ "bytes", "impl-trait-for-tuples", @@ -10304,14 +10307,14 @@ dependencies = [ [[package]] name = "sp-runtime-interface-proc-macro" version = "17.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#8614dc0e055d06de4a3774ac1da0a422b33f34e2" +source = "git+https://github.com/paritytech/polkadot-sdk#c4b3c1c6c6e492c4196e06fbba824a58e8119a3b" dependencies = [ "Inflector", "expander", - "proc-macro-crate 3.2.0", + "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.100", ] [[package]] @@ -10321,10 +10324,10 @@ source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-stable dependencies = [ "Inflector", "expander", - "proc-macro-crate 3.2.0", + "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.100", ] [[package]] @@ -10369,7 +10372,7 @@ dependencies = [ "sp-externalities 0.29.0", "sp-panic-handler", "sp-trie", - "thiserror", + "thiserror 1.0.61", "tracing", "trie-db", ] @@ -10394,7 +10397,7 @@ dependencies = [ "sp-externalities 0.29.0", "sp-runtime", "sp-runtime-interface 28.0.0", - "thiserror", + "thiserror 1.0.61", "x25519-dalek", ] @@ -10406,12 +10409,12 @@ source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-stable [[package]] name = "sp-std" version = "14.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#8614dc0e055d06de4a3774ac1da0a422b33f34e2" +source = "git+https://github.com/paritytech/polkadot-sdk#c4b3c1c6c6e492c4196e06fbba824a58e8119a3b" [[package]] name = "sp-storage" version = "19.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#8614dc0e055d06de4a3774ac1da0a422b33f34e2" +source = "git+https://github.com/paritytech/polkadot-sdk#c4b3c1c6c6e492c4196e06fbba824a58e8119a3b" dependencies = [ "impl-serde", "parity-scale-codec", @@ -10441,13 +10444,13 @@ dependencies = [ "parity-scale-codec", "sp-inherents", "sp-runtime", - "thiserror", + "thiserror 1.0.61", ] [[package]] name = "sp-tracing" version = "16.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#8614dc0e055d06de4a3774ac1da0a422b33f34e2" +source = "git+https://github.com/paritytech/polkadot-sdk#c4b3c1c6c6e492c4196e06fbba824a58e8119a3b" dependencies = [ "parity-scale-codec", "tracing", @@ -10506,7 +10509,7 @@ dependencies = [ "schnellru", "sp-core", "sp-externalities 0.29.0", - "thiserror", + "thiserror 1.0.61", "tracing", "trie-db", "trie-root", @@ -10526,7 +10529,7 @@ dependencies = [ "sp-runtime", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-stable2409)", "sp-version-proc-macro", - "thiserror", + "thiserror 1.0.61", ] [[package]] @@ -10537,15 +10540,14 @@ dependencies = [ "parity-scale-codec", "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.100", ] [[package]] name = "sp-wasm-interface" version = "20.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#8614dc0e055d06de4a3774ac1da0a422b33f34e2" +source = "git+https://github.com/paritytech/polkadot-sdk#c4b3c1c6c6e492c4196e06fbba824a58e8119a3b" dependencies = [ - "anyhow", "impl-trait-for-tuples", "log", "parity-scale-codec", @@ -10611,21 +10613,11 @@ dependencies = [ "der", ] -[[package]] -name = "sqlformat" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7bba3a93db0cc4f7bdece8bb09e77e2e785c20bfebf79eb8340ed80708048790" -dependencies = [ - "nom", - "unicode_categories", -] - [[package]] name = "sqlx" -version = "0.8.2" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93334716a037193fac19df402f8571269c84a00852f6a7066b5d2616dcd64d3e" +checksum = "f3c3a85280daca669cfd3bcb68a337882a8bc57ec882f72c5d13a430613a738e" dependencies = [ "sqlx-core", "sqlx-macros", @@ -10634,37 +10626,32 @@ dependencies = [ [[package]] name = "sqlx-core" -version = "0.8.2" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4d8060b456358185f7d50c55d9b5066ad956956fddec42ee2e8567134a8936e" +checksum = "f743f2a3cea30a58cd479013f75550e879009e3a02f616f18ca699335aa248c3" dependencies = [ - "atoi", - "byteorder", + "base64 0.22.1", "bytes", "crc", "crossbeam-queue", "either", "event-listener 5.3.1", - "futures-channel", "futures-core", "futures-intrusive", "futures-io", "futures-util", - "hashbrown 0.14.5", - "hashlink 0.9.1", - "hex", - "indexmap 2.6.0", + "hashbrown 0.15.2", + "hashlink 0.10.0", + "indexmap 2.2.6", "log", "memchr", "native-tls", "once_cell", - "paste", "percent-encoding", "serde", "sha2 0.10.8", "smallvec", - "sqlformat", - "thiserror", + "thiserror 2.0.12", "tokio", "tokio-stream", "tracing", @@ -10673,22 +10660,22 @@ dependencies = [ [[package]] name = "sqlx-macros" -version = "0.8.2" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cac0692bcc9de3b073e8d747391827297e075c7710ff6276d9f7a1f3d58c6657" +checksum = "7f4200e0fde19834956d4252347c12a083bdcb237d7a1a1446bffd8768417dce" dependencies = [ "proc-macro2", "quote", "sqlx-core", "sqlx-macros-core", - "syn 2.0.90", + "syn 2.0.100", ] [[package]] name = "sqlx-macros-core" -version = "0.8.2" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1804e8a7c7865599c9c79be146dc8a9fd8cc86935fa641d3ea58e5f0688abaa5" +checksum = "882ceaa29cade31beca7129b6beeb05737f44f82dbe2a9806ecea5a7093d00b7" dependencies = [ "dotenvy", "either", @@ -10702,7 +10689,7 @@ dependencies = [ "sha2 0.10.8", "sqlx-core", "sqlx-sqlite", - "syn 2.0.90", + "syn 2.0.100", "tempfile", "tokio", "url", @@ -10710,9 +10697,9 @@ dependencies = [ [[package]] name = "sqlx-sqlite" -version = "0.8.2" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5b2cf34a45953bfd3daaf3db0f7a7878ab9b7a6b91b422d24a7a9e4c857b680" +checksum = "c26083e9a520e8eb87a06b12347679b142dc2ea29e6e409f805644a7a979a5bc" dependencies = [ "atoi", "flume", @@ -10727,15 +10714,16 @@ dependencies = [ "serde", "serde_urlencoded", "sqlx-core", + "thiserror 2.0.12", "tracing", "url", ] [[package]] name = "ss58-registry" -version = "1.50.0" +version = "1.47.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43fce22ed1df64d04b262351c8f9d5c6da4f76f79f25ad15529792f893fad25d" +checksum = "4743ce898933fbff7bbf414f497c459a782d496269644b3d650a398ae6a487ba" dependencies = [ "Inflector", "num-format", @@ -10821,7 +10809,7 @@ dependencies = [ "sctp-proto", "serde", "sha-1", - "thiserror", + "thiserror 1.0.61", "tracing", ] @@ -10839,9 +10827,9 @@ checksum = "063e6045c0e62079840579a7e47a355ae92f60eb74daaf156fb1e84ba164e63f" [[package]] name = "strum" -version = "0.26.3" +version = "0.26.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fec0f0aef304996cf250b31b5a10dee7980c85da9d759361292b8bca5a18f06" +checksum = "5d8cec3501a5194c432b2b7976db6b7d10ec95c253208b45f83f7136aa985e29" dependencies = [ "strum_macros 0.26.4", ] @@ -10869,7 +10857,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.90", + "syn 2.0.100", ] [[package]] @@ -10926,11 +10914,11 @@ version = "0.17.0" source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-stable2409#87971b3e92721bdf10bf40b410eaae779d494ca0" dependencies = [ "http-body-util", - "hyper 1.5.0", + "hyper 1.6.0", "hyper-util", "log", "prometheus", - "thiserror", + "thiserror 1.0.61", "tokio", ] @@ -10956,9 +10944,9 @@ dependencies = [ "sp-maybe-compressed-blob", "sp-tracing 17.0.1", "sp-version", - "strum 0.26.3", + "strum 0.26.2", "tempfile", - "toml 0.8.19", + "toml 0.8.14", "walkdir", "wasm-opt", ] @@ -10973,7 +10961,7 @@ dependencies = [ "quote", "rayon", "subtensor-linting", - "syn 2.0.90", + "syn 2.0.100", "walkdir", ] @@ -11011,7 +10999,7 @@ dependencies = [ "proc-macro2", "procedural-fork", "quote", - "syn 2.0.90", + "syn 2.0.100", ] [[package]] @@ -11021,7 +11009,7 @@ dependencies = [ "ahash 0.8.11", "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.100", ] [[package]] @@ -11066,7 +11054,7 @@ dependencies = [ "anyhow", "clap", "semver 1.0.23", - "toml_edit", + "toml_edit 0.22.14", ] [[package]] @@ -11077,9 +11065,9 @@ checksum = "2d67a5a62ba6e01cb2192ff309324cb4875d0c451d55fe2319433abe7a05a8ee" [[package]] name = "subtle" -version = "2.6.1" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" +checksum = "0d0208408ba0c3df17ed26eb06992cb1a1268d41b2c0e12e65203fbe3972cee5" [[package]] name = "syn" @@ -11094,9 +11082,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.90" +version = "2.0.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "919d3b74a5dd0ccd15aeb8f93e7006bd9e14c295087c9896a110f490752bcf31" +checksum = "b09a44accad81e1ba1cd74a32461ba89dee89095ba17b32f5d03683b1b1fc2a0" dependencies = [ "proc-macro2", "quote", @@ -11123,7 +11111,7 @@ checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.100", ] [[package]] @@ -11155,21 +11143,20 @@ checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" [[package]] name = "target-lexicon" -version = "0.12.16" +version = "0.12.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1" +checksum = "e1fc403891a21bcfb7c37834ba66a547a8f402146eba7265b5a6d88059c9ff2f" [[package]] name = "tempfile" -version = "3.13.0" +version = "3.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f2c9fc62d0beef6951ccffd757e241266a2c833136efbe35af6cd2567dca5b" +checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1" dependencies = [ "cfg-if", "fastrand", - "once_cell", - "rustix 0.38.37", - "windows-sys 0.59.0", + "rustix 0.38.34", + "windows-sys 0.52.0", ] [[package]] @@ -11183,12 +11170,12 @@ dependencies = [ [[package]] name = "terminal_size" -version = "0.4.0" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f599bd7ca042cfdf8f4512b277c02ba102247820f9d9d4a9f521f496751a6ef" +checksum = "21bebf2b7c9e0a515f6e0f8c51dc0f8e4696391e6f1ff30379559f8365fb0df7" dependencies = [ - "rustix 0.38.37", - "windows-sys 0.59.0", + "rustix 0.38.34", + "windows-sys 0.48.0", ] [[package]] @@ -11199,22 +11186,42 @@ checksum = "3369f5ac52d5eb6ab48c6b4ffdc8efbcad6b89c765749064ba298f2c68a16a76" [[package]] name = "thiserror" -version = "1.0.64" +version = "1.0.61" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c546c80d6be4bc6a00c0f01730c08df82eaa7a7a61f11d656526506112cc1709" +dependencies = [ + "thiserror-impl 1.0.61", +] + +[[package]] +name = "thiserror" +version = "2.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "567b8a2dae586314f7be2a752ec7474332959c6460e02bde30d702a66d488708" +dependencies = [ + "thiserror-impl 2.0.12", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d50af8abc119fb8bb6dbabcfa89656f46f84aa0ac7688088608076ad2b459a84" +checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533" dependencies = [ - "thiserror-impl", + "proc-macro2", + "quote", + "syn 2.0.100", ] [[package]] name = "thiserror-impl" -version = "1.0.64" +version = "2.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3" +checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.100", ] [[package]] @@ -11294,9 +11301,9 @@ dependencies = [ [[package]] name = "tinyvec" -version = "1.8.0" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" +checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" dependencies = [ "tinyvec_macros", ] @@ -11337,31 +11344,32 @@ dependencies = [ [[package]] name = "tokio" -version = "1.40.0" +version = "1.38.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2b070231665d27ad9ec9b8df639893f46727666c6767db40317fbe920a5d998" +checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" dependencies = [ "backtrace", "bytes", "libc", "mio", + "num_cpus", "parking_lot 0.12.3", "pin-project-lite", "signal-hook-registry", "socket2 0.5.7", "tokio-macros", - "windows-sys 0.52.0", + "windows-sys 0.48.0", ] [[package]] name = "tokio-macros" -version = "2.4.0" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" +checksum = "5f5ae998a069d4b5aba8ee9dad856af7d520c3699e6159b185c2acd48155d39a" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.100", ] [[package]] @@ -11376,9 +11384,9 @@ dependencies = [ [[package]] name = "tokio-stream" -version = "0.1.16" +version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f4e6ce100d0eb49a2734f8c0812bcd324cf357d21810932c5df6b96ef2b86f1" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" dependencies = [ "futures-core", "pin-project-lite", @@ -11403,9 +11411,9 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.7.12" +version = "0.7.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" +checksum = "9cf6b47b3771c49ac75ad09a6162f53ad4b8088b76ac60e8ec1455b31a189fe1" dependencies = [ "bytes", "futures-core", @@ -11426,36 +11434,47 @@ dependencies = [ [[package]] name = "toml" -version = "0.8.19" +version = "0.8.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1ed1f98e3fdc28d6d910e6737ae6ab1a93bf1985935a1193e68f93eeb68d24e" +checksum = "6f49eb2ab21d2f26bd6db7bf383edc527a7ebaee412d17af4d40fdccd442f335" dependencies = [ "serde", "serde_spanned", "toml_datetime", - "toml_edit", + "toml_edit 0.22.14", ] [[package]] name = "toml_datetime" -version = "0.6.8" +version = "0.6.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" +checksum = "4badfd56924ae69bcc9039335b2e017639ce3f9b001c393c1b2d1ef846ce2cbf" dependencies = [ "serde", ] [[package]] name = "toml_edit" -version = "0.22.22" +version = "0.21.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ae48d6208a266e853d946088ed816055e556cc6028c5e8e2b84d9fa5dd7c7f5" +checksum = "6a8534fd7f78b5405e860340ad6575217ce99f38d4d5c8f2442cb5ecb50090e1" dependencies = [ - "indexmap 2.6.0", + "indexmap 2.2.6", + "toml_datetime", + "winnow 0.5.40", +] + +[[package]] +name = "toml_edit" +version = "0.22.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f21c7aaf97f1bd9ca9d4f9e73b0a6c74bd5afef56f2bc931943a6e1c37e04e38" +dependencies = [ + "indexmap 2.2.6", "serde", "serde_spanned", "toml_datetime", - "winnow", + "winnow 0.6.13", ] [[package]] @@ -11479,9 +11498,9 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e9cd434a998747dd2c4276bc96ee2e0c7a2eadf3cae88e52be55a05fa9053f5" dependencies = [ - "bitflags 2.6.0", + "bitflags 2.5.0", "bytes", - "http 1.1.0", + "http 1.3.1", "http-body 1.0.1", "http-body-util", "pin-project-lite", @@ -11491,15 +11510,15 @@ dependencies = [ [[package]] name = "tower-layer" -version = "0.3.3" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" +checksum = "c20c8dbed6283a09604c3e69b4b7eeb54e298b8a600d4d5ecb5ad39de609f1d0" [[package]] name = "tower-service" -version = "0.3.3" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" +checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" [[package]] name = "tracing" @@ -11521,7 +11540,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.100", ] [[package]] @@ -11624,7 +11643,7 @@ dependencies = [ "rand", "smallvec", "socket2 0.4.10", - "thiserror", + "thiserror 1.0.61", "tinyvec", "tokio", "tracing", @@ -11649,7 +11668,7 @@ dependencies = [ "once_cell", "rand", "smallvec", - "thiserror", + "thiserror 1.0.61", "tinyvec", "tokio", "tracing", @@ -11671,7 +11690,7 @@ dependencies = [ "rand", "resolv-conf", "smallvec", - "thiserror", + "thiserror 1.0.61", "tokio", "tracing", "trust-dns-proto 0.23.2", @@ -11704,7 +11723,7 @@ dependencies = [ "rand", "rustls 0.21.12", "sha1", - "thiserror", + "thiserror 1.0.61", "url", "utf-8", ] @@ -11738,9 +11757,9 @@ checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" [[package]] name = "ucd-trie" -version = "0.1.7" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2896d95c02a80c6d6a5d6e953d479f5ddf2dfdb6a244441010e373ac0fb88971" +checksum = "ed646292ffc8188ef8ea4d1e0e0150fb15a5c2e12ad9b8fc191ae7a8a7f3c4b9" [[package]] name = "uint" @@ -11756,15 +11775,15 @@ dependencies = [ [[package]] name = "unicode-bidi" -version = "0.3.17" +version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ab17db44d7388991a428b2ee655ce0c212e862eff1768a455c58f9aad6e7893" +checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" [[package]] name = "unicode-ident" -version = "1.0.13" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "unicode-normalization" @@ -11777,21 +11796,15 @@ dependencies = [ [[package]] name = "unicode-width" -version = "0.1.14" +version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" +checksum = "0336d538f7abc86d282a4189614dfaa90810dfc2c6f6427eaf88e16311dd225d" [[package]] name = "unicode-xid" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" - -[[package]] -name = "unicode_categories" -version = "0.1.1" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39ec24b3121d976906ece63c9daad25b85969647682eee313cb5779fdd69e14e" +checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" [[package]] name = "universal-hash" @@ -11800,7 +11813,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc1de2c688dc15305988b563c3854064043356019f97a4b46276fe734c4f07ea" dependencies = [ "crypto-common", - "subtle 2.6.1", + "subtle 2.6.0", ] [[package]] @@ -11874,9 +11887,9 @@ checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" [[package]] name = "version_check" -version = "0.9.5" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "void" @@ -11904,7 +11917,7 @@ dependencies = [ "rand_core", "sha2 0.10.8", "sha3", - "thiserror", + "thiserror 1.0.61", "zeroize", ] @@ -11935,35 +11948,34 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.93" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" +checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" dependencies = [ "cfg-if", - "once_cell", "wasm-bindgen-macro", ] [[package]] name = "wasm-bindgen-backend" -version = "0.2.93" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" +checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" dependencies = [ "bumpalo", "log", "once_cell", "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.100", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-futures" -version = "0.4.43" +version = "0.4.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61e9300f63a621e96ed275155c108eb6f843b6a26d053f122ab69724559dc8ed" +checksum = "76bc14366121efc8dbb487ab05bcc9d346b3b5ec0eaa76e46594cabbe51762c0" dependencies = [ "cfg-if", "js-sys", @@ -11973,9 +11985,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.93" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" +checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -11983,22 +11995,22 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.93" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" +checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.100", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.93" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" +checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" [[package]] name = "wasm-instrument" @@ -12020,7 +12032,7 @@ dependencies = [ "strum 0.24.1", "strum_macros 0.24.3", "tempfile", - "thiserror", + "thiserror 1.0.61", "wasm-opt-cxx-sys", "wasm-opt-sys", ] @@ -12147,7 +12159,7 @@ dependencies = [ "log", "object 0.30.4", "target-lexicon", - "thiserror", + "thiserror 1.0.61", "wasmparser", "wasmtime-cranelift-shared", "wasmtime-environ", @@ -12182,7 +12194,7 @@ dependencies = [ "object 0.30.4", "serde", "target-lexicon", - "thiserror", + "thiserror 1.0.61", "wasmparser", "wasmtime-types", ] @@ -12265,15 +12277,15 @@ checksum = "a4f6fffd2a1011887d57f07654dd112791e872e3ff4a2e626aee8059ee17f06f" dependencies = [ "cranelift-entity", "serde", - "thiserror", + "thiserror 1.0.61", "wasmparser", ] [[package]] name = "web-sys" -version = "0.3.70" +version = "0.3.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0" +checksum = "77afa9a11836342370f4817622a2f0f418b134426d91a82dfb48f532d2ec13ef" dependencies = [ "js-sys", "wasm-bindgen", @@ -12285,7 +12297,7 @@ version = "0.22.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed63aea5ce73d0ff405984102c42de94fc55a6b75765d621c65262469b3c9b53" dependencies = [ - "ring 0.17.13", + "ring 0.17.8", "untrusted 0.9.0", ] @@ -12304,14 +12316,14 @@ dependencies = [ "either", "home", "once_cell", - "rustix 0.38.37", + "rustix 0.38.34", ] [[package]] name = "wide" -version = "0.7.28" +version = "0.7.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b828f995bf1e9622031f8009f8481a85406ce1f4d4588ff746d872043e855690" +checksum = "8a040b111774ab63a19ef46bbc149398ab372b4ccdcfd719e9814dbd7dfd76c8" dependencies = [ "bytemuck", "safe_arch", @@ -12341,11 +12353,11 @@ checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-util" -version = "0.1.9" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" +checksum = "4d4cc384e1e73b93bafa6fb4f1df8c41695c8a91cf9c4c64358067d15a7b6c6b" dependencies = [ - "windows-sys 0.59.0", + "windows-sys 0.52.0", ] [[package]] @@ -12379,7 +12391,7 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" dependencies = [ - "windows-targets 0.52.6", + "windows-targets 0.52.5", ] [[package]] @@ -12421,16 +12433,7 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets 0.52.6", -] - -[[package]] -name = "windows-sys" -version = "0.59.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" -dependencies = [ - "windows-targets 0.52.6", + "windows-targets 0.52.5", ] [[package]] @@ -12465,18 +12468,18 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.52.6" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" dependencies = [ - "windows_aarch64_gnullvm 0.52.6", - "windows_aarch64_msvc 0.52.6", - "windows_i686_gnu 0.52.6", + "windows_aarch64_gnullvm 0.52.5", + "windows_aarch64_msvc 0.52.5", + "windows_i686_gnu 0.52.5", "windows_i686_gnullvm", - "windows_i686_msvc 0.52.6", - "windows_x86_64_gnu 0.52.6", - "windows_x86_64_gnullvm 0.52.6", - "windows_x86_64_msvc 0.52.6", + "windows_i686_msvc 0.52.5", + "windows_x86_64_gnu 0.52.5", + "windows_x86_64_gnullvm 0.52.5", + "windows_x86_64_msvc 0.52.5", ] [[package]] @@ -12493,9 +12496,9 @@ checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" [[package]] name = "windows_aarch64_gnullvm" -version = "0.52.6" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" [[package]] name = "windows_aarch64_msvc" @@ -12511,9 +12514,9 @@ checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" [[package]] name = "windows_aarch64_msvc" -version = "0.52.6" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" [[package]] name = "windows_i686_gnu" @@ -12529,15 +12532,15 @@ checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" [[package]] name = "windows_i686_gnu" -version = "0.52.6" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" [[package]] name = "windows_i686_gnullvm" -version = "0.52.6" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" [[package]] name = "windows_i686_msvc" @@ -12553,9 +12556,9 @@ checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" [[package]] name = "windows_i686_msvc" -version = "0.52.6" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" [[package]] name = "windows_x86_64_gnu" @@ -12571,9 +12574,9 @@ checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" [[package]] name = "windows_x86_64_gnu" -version = "0.52.6" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" [[package]] name = "windows_x86_64_gnullvm" @@ -12589,9 +12592,9 @@ checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" [[package]] name = "windows_x86_64_gnullvm" -version = "0.52.6" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" [[package]] name = "windows_x86_64_msvc" @@ -12607,15 +12610,24 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "windows_x86_64_msvc" -version = "0.52.6" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" [[package]] name = "winnow" -version = "0.6.20" +version = "0.5.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36c1fec1a2bb5866f07c25f68c26e565c4c200aebb96d7e55710c19d3e8ac49b" +checksum = "f593a95398737aeed53e489c785df13f3618e41dbcd6718c6addbf1395aa6876" +dependencies = [ + "memchr", +] + +[[package]] +name = "winnow" +version = "0.6.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59b5e5f6c299a3c7890b876a2a587f3115162487e704907d9b6cd29473052ba1" dependencies = [ "memchr", ] @@ -12664,7 +12676,7 @@ dependencies = [ "nom", "oid-registry 0.6.1", "rusticata-macros", - "thiserror", + "thiserror 1.0.61", "time", ] @@ -12681,7 +12693,7 @@ dependencies = [ "nom", "oid-registry 0.7.1", "rusticata-macros", - "thiserror", + "thiserror 1.0.61", "time", ] @@ -12693,14 +12705,14 @@ dependencies = [ "Inflector", "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.100", ] [[package]] name = "xml-rs" -version = "0.8.22" +version = "0.8.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af4e2e2f7cba5a093896c1e150fbfe177d1883e7448200efb81d40b9d339ef26" +checksum = "a62ce76d9b56901b19a74f19431b0d8b3bc7ca4ad685a746dfd78ca8f4fc6bda" [[package]] name = "xmltree" @@ -12737,23 +12749,22 @@ dependencies = [ [[package]] name = "zerocopy" -version = "0.7.35" +version = "0.7.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +checksum = "ae87e3fcd617500e5d106f0380cf7b77f3c6092aae37191433159dda23cfb087" dependencies = [ - "byteorder", "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.7.35" +version = "0.7.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +checksum = "15e934569e47891f7d9411f1a451d947a60e000ab3bd24fbb970f000387d1b3b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.100", ] [[package]] @@ -12773,7 +12784,7 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.100", ] [[package]] @@ -12816,9 +12827,9 @@ dependencies = [ [[package]] name = "zstd-sys" -version = "2.0.13+zstd.1.5.6" +version = "2.0.11+zstd.1.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38ff0f21cfee8f97d94cef41359e0c89aa6113028ab0291aa8ca0038995a95aa" +checksum = "75652c55c0b6f3e6f12eb786fe1bc960396bf05a1eb3bf1f3691c3610ac2e6d4" dependencies = [ "cc", "pkg-config", From 8fdee515a6ad8d92bd2f5a3b1e4d07d2d62aa255 Mon Sep 17 00:00:00 2001 From: Cameron Fairchild Date: Mon, 21 Apr 2025 13:35:35 -0400 Subject: [PATCH 44/45] fmt --- pallets/admin-utils/src/lib.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pallets/admin-utils/src/lib.rs b/pallets/admin-utils/src/lib.rs index f462d5cd14..f1fbcc405d 100644 --- a/pallets/admin-utils/src/lib.rs +++ b/pallets/admin-utils/src/lib.rs @@ -1528,11 +1528,11 @@ pub mod pallet { "Yuma3EnableToggled( netuid: {:?}, Enabled: {:?} ) ", netuid, enabled - ); + ); Ok(()) } - /// Enables or disables subtoken trading for a given subnet. + /// Enables or disables subtoken trading for a given subnet. /// /// # Arguments /// * `origin` - The origin of the call, which must be the root account. @@ -1542,11 +1542,11 @@ pub mod pallet { /// # Errors /// * `BadOrigin` - If the caller is not the root account. /// - /// # Weight + /// # Weight /// Weight is handled by the `#[pallet::weight]` attribute. - #[pallet::call_index(66)] - #[pallet::weight((0, DispatchClass::Operational, Pays::No))] - pub fn sudo_set_subtoken_enabled( + #[pallet::call_index(66)] + #[pallet::weight((0, DispatchClass::Operational, Pays::No))] + pub fn sudo_set_subtoken_enabled( origin: OriginFor, netuid: u16, subtoken_enabled: bool, From c28ecc6cfd5cc043d8ca513a402a22a04427a16f Mon Sep 17 00:00:00 2001 From: Cameron Fairchild Date: Mon, 5 May 2025 10:51:09 -0400 Subject: [PATCH 45/45] chore: fmt --- pallets/admin-utils/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pallets/admin-utils/src/lib.rs b/pallets/admin-utils/src/lib.rs index a0a3c74abe..9d978061a1 100644 --- a/pallets/admin-utils/src/lib.rs +++ b/pallets/admin-utils/src/lib.rs @@ -1539,7 +1539,7 @@ pub mod pallet { enabled ); Ok(()) - } + } /// Sets or updates the hotkey account associated with the owner of a specific subnet. ///