From 9cc67d323b4f3353ac0e50fb2293653cebbb9a3b Mon Sep 17 00:00:00 2001 From: Loris Moulin Date: Tue, 2 Dec 2025 16:08:01 +0100 Subject: [PATCH 01/16] bump rust to 1.89 --- rust-toolchain.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain.toml b/rust-toolchain.toml index bfb378c468..55003ecad6 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,5 +1,5 @@ [toolchain] -channel = "1.88" # rustc 1.88.0 (6b00bc388 2025-06-23) +channel = "1.89" # rustc 1.89.0 (29483883e 2025-08-04) components = [ "cargo", "clippy", From 97dfd331d726df407b8df772d579f818e7208436 Mon Sep 17 00:00:00 2001 From: Loris Moulin Date: Tue, 2 Dec 2025 16:08:07 +0100 Subject: [PATCH 02/16] fix cargo audit --- .github/workflows/cargo-audit.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/cargo-audit.yml b/.github/workflows/cargo-audit.yml index 9bd9795f17..04046c11d4 100644 --- a/.github/workflows/cargo-audit.yml +++ b/.github/workflows/cargo-audit.yml @@ -46,4 +46,6 @@ jobs: cargo audit --ignore RUSTSEC-2023-0091 \ --ignore RUSTSEC-2024-0438 \ --ignore RUSTSEC-2025-0009 \ - --ignore RUSTSEC-2025-0055 + --ignore RUSTSEC-2025-0055 \ + --ignore RUSTSEC-2025-0073 \ + --ignore RUSTSEC-2025-0118 From 00d17112a8536be19cf98e3ffa3cda0a6859b784 Mon Sep 17 00:00:00 2001 From: Loris Moulin Date: Tue, 2 Dec 2025 21:35:14 +0100 Subject: [PATCH 03/16] allow unused for utility pallet id --- pallets/utility/src/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pallets/utility/src/lib.rs b/pallets/utility/src/lib.rs index c54413c2ea..96dfd26157 100644 --- a/pallets/utility/src/lib.rs +++ b/pallets/utility/src/lib.rs @@ -636,7 +636,8 @@ pub mod pallet { } /// A pallet identifier. These are per pallet and should be stored in a registry somewhere. -#[freeze_struct("7e600c53ace0630a")] +#[allow(unused)] +#[freeze_struct("8b0fb6b91f673972")] #[derive(Clone, Copy, Eq, PartialEq, Encode, Decode)] struct IndexedUtilityPalletId(u16); From 6239aa58811e117805f41056ce6aee093fc036ab Mon Sep 17 00:00:00 2001 From: Loris Moulin Date: Tue, 2 Dec 2025 21:43:01 +0100 Subject: [PATCH 04/16] cargo clippy --- node/src/command.rs | 2 +- pallets/subtensor/src/coinbase/block_step.rs | 8 +++--- .../subtensor/src/coinbase/run_coinbase.rs | 10 +++----- pallets/subtensor/src/epoch/math.rs | 25 ++++++++----------- pallets/subtensor/src/epoch/run_epoch.rs | 5 ++-- pallets/subtensor/src/staking/stake_utils.rs | 10 +++----- pallets/subtensor/src/subnets/registration.rs | 13 ++++------ pallets/subtensor/src/subnets/serving.rs | 5 ++-- pallets/subtensor/src/subnets/uids.rs | 5 ++-- pallets/subtensor/src/subnets/weights.rs | 5 ++-- pallets/subtensor/src/swap/swap_hotkey.rs | 20 ++++++--------- pallets/swap/src/pallet/impls.rs | 5 ++-- pallets/utility/src/lib.rs | 4 +-- support/linting/src/require_freeze_struct.rs | 5 ++-- 14 files changed, 49 insertions(+), 73 deletions(-) diff --git a/node/src/command.rs b/node/src/command.rs index 67cb200e43..3350c1443e 100644 --- a/node/src/command.rs +++ b/node/src/command.rs @@ -272,7 +272,7 @@ fn start_babe_service(arg_matches: &ArgMatches) -> Result<(), sc_cli::Error> { { log::info!("Failed to aquire DB lock, trying again in 1s..."); std::thread::sleep(std::time::Duration::from_secs(1)); - return start_babe_service(arg_matches); + start_babe_service(arg_matches) // Unknown error, return it. } else { log::error!("Failed to start Babe service: {e:?}"); diff --git a/pallets/subtensor/src/coinbase/block_step.rs b/pallets/subtensor/src/coinbase/block_step.rs index 21f7866459..97b0b08b58 100644 --- a/pallets/subtensor/src/coinbase/block_step.rs +++ b/pallets/subtensor/src/coinbase/block_step.rs @@ -227,9 +227,9 @@ impl Pallet { if next_value >= U110F18::saturating_from_num(Self::get_max_difficulty(netuid)) { Self::get_max_difficulty(netuid) } else if next_value <= U110F18::saturating_from_num(Self::get_min_difficulty(netuid)) { - return Self::get_min_difficulty(netuid); + Self::get_min_difficulty(netuid) } else { - return next_value.saturating_to_num::(); + next_value.saturating_to_num::() } } @@ -261,9 +261,9 @@ impl Pallet { if next_value >= U110F18::saturating_from_num(Self::get_max_burn(netuid)) { Self::get_max_burn(netuid) } else if next_value <= U110F18::saturating_from_num(Self::get_min_burn(netuid)) { - return Self::get_min_burn(netuid); + Self::get_min_burn(netuid) } else { - return next_value.saturating_to_num::().into(); + next_value.saturating_to_num::().into() } } diff --git a/pallets/subtensor/src/coinbase/run_coinbase.rs b/pallets/subtensor/src/coinbase/run_coinbase.rs index 3b82ec86d5..09ddd9d379 100644 --- a/pallets/subtensor/src/coinbase/run_coinbase.rs +++ b/pallets/subtensor/src/coinbase/run_coinbase.rs @@ -498,11 +498,10 @@ impl Pallet { // Insert subnet owner hotkey in the beginning of the list if valid and not // already present - if let Ok(owner_hk) = SubnetOwnerHotkey::::try_get(netuid) { - if Uids::::get(netuid, &owner_hk).is_some() && !owner_hotkeys.contains(&owner_hk) { + if let Ok(owner_hk) = SubnetOwnerHotkey::::try_get(netuid) + && Uids::::get(netuid, &owner_hk).is_some() && !owner_hotkeys.contains(&owner_hk) { owner_hotkeys.insert(0, owner_hk); } - } owner_hotkeys } @@ -515,8 +514,8 @@ impl Pallet { root_alpha_dividends: BTreeMap, ) { // Distribute the owner cut. - if let Ok(owner_coldkey) = SubnetOwner::::try_get(netuid) { - if let Ok(owner_hotkey) = SubnetOwnerHotkey::::try_get(netuid) { + if let Ok(owner_coldkey) = SubnetOwner::::try_get(netuid) + && let Ok(owner_hotkey) = SubnetOwnerHotkey::::try_get(netuid) { // Increase stake for owner hotkey and coldkey. log::debug!( "owner_hotkey: {owner_hotkey:?} owner_coldkey: {owner_coldkey:?}, owner_cut: {owner_cut:?}" @@ -532,7 +531,6 @@ impl Pallet { Self::distribute_leased_network_dividends(lease_id, real_owner_cut); } } - } // Distribute mining incentives. let subnet_owner_coldkey = SubnetOwner::::get(netuid); diff --git a/pallets/subtensor/src/epoch/math.rs b/pallets/subtensor/src/epoch/math.rs index 2cbbfae77d..113d58075f 100644 --- a/pallets/subtensor/src/epoch/math.rs +++ b/pallets/subtensor/src/epoch/math.rs @@ -335,11 +335,10 @@ pub fn inplace_row_normalize_sparse(sparse_matrix: &mut [Vec<(u16, I32F32)>]) { // Sum across each row (dim=0) of a matrix. pub fn row_sum(x: &[Vec]) -> Vec { - if let Some(first_row) = x.first() { - if first_row.is_empty() { + if let Some(first_row) = x.first() + && first_row.is_empty() { return vec![]; } - } x.iter().map(|row| row.iter().sum()).collect() } @@ -424,11 +423,10 @@ pub fn inplace_col_max_upscale_sparse(sparse_matrix: &mut [Vec<(u16, I32F32)>], // Pass 1: compute per-column max for sparse_row in sparse_matrix.iter() { for (j, value) in sparse_row.iter() { - if let Some(m) = col_max.get_mut(*j as usize) { - if *m < *value { + if let Some(m) = col_max.get_mut(*j as usize) + && *m < *value { *m = *value; } - } } } @@ -1147,11 +1145,10 @@ pub fn weighted_median_col_sparse( while let (Some(&s), Some(sparse_row)) = (stake_it.next(), score_it.next()) { if s > zero { for &(c, val) in sparse_row.iter() { - if let Some(col_vec) = use_score.get_mut(c as usize) { - if let Some(cell) = col_vec.get_mut(k) { + if let Some(col_vec) = use_score.get_mut(c as usize) + && let Some(cell) = col_vec.get_mut(k) { *cell = val; } - } } k = k.saturating_add(1); } @@ -1289,11 +1286,10 @@ pub fn interpolate_sparse( let v1 = row1.get(j).unwrap_or(&zero); let v2 = row2.get(j).unwrap_or(&zero); let interp = v1.saturating_add(ratio.saturating_mul(v2.saturating_sub(*v1))); - if zero < interp { - if let Some(res) = result.get_mut(i) { + if zero < interp + && let Some(res) = result.get_mut(i) { res.push((j as u16, interp)); } - } } } result @@ -1338,11 +1334,10 @@ pub fn mat_vec_mul_sparse( 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) { - if let Some(result_row) = result.get_mut(i) { + if new_value != I32F32::saturating_from_num(0.0) + && let Some(result_row) = result.get_mut(i) { result_row.push((*j, new_value)); } - } } } } diff --git a/pallets/subtensor/src/epoch/run_epoch.rs b/pallets/subtensor/src/epoch/run_epoch.rs index 5e4dd1f43e..b631b8c6a9 100644 --- a/pallets/subtensor/src/epoch/run_epoch.rs +++ b/pallets/subtensor/src/epoch/run_epoch.rs @@ -761,11 +761,10 @@ impl Pallet { // ---------- v3 ------------------------------------------------------ for (_epoch, q) in TimelockedWeightCommits::::iter_prefix(netuid_index) { for (who, cb, ..) in q.iter() { - if !Self::is_commit_expired(netuid, *cb) { - if let Some(cell) = uid_of(who).and_then(|i| commit_blocks.get_mut(i)) { + if !Self::is_commit_expired(netuid, *cb) + && let Some(cell) = uid_of(who).and_then(|i| commit_blocks.get_mut(i)) { *cell = (*cell).min(*cb); } - } } } diff --git a/pallets/subtensor/src/staking/stake_utils.rs b/pallets/subtensor/src/staking/stake_utils.rs index 402f999db3..ab8c130b09 100644 --- a/pallets/subtensor/src/staking/stake_utils.rs +++ b/pallets/subtensor/src/staking/stake_utils.rs @@ -562,12 +562,11 @@ impl Pallet { // We expect a negative value here let mut actual_alpha = 0; - if let Ok(value) = alpha_share_pool.try_get_value(coldkey) { - if value >= amount { + if let Ok(value) = alpha_share_pool.try_get_value(coldkey) + && value >= amount { actual_alpha = alpha_share_pool.update_value_for_one(coldkey, (amount as i64).neg()); } - } // Get the negation of the removed alpha, and clamp at 0. // This ensures we return a positive value, but only if @@ -1200,11 +1199,10 @@ impl Pallet { // Ensure that if partial execution is not allowed, the amount will not cause // slippage over desired - if let Some(allow_partial) = maybe_allow_partial { - if !allow_partial { + if let Some(allow_partial) = maybe_allow_partial + && !allow_partial { ensure!(alpha_amount <= max_amount, Error::::SlippageTooHigh); } - } } if check_transfer_toggle { diff --git a/pallets/subtensor/src/subnets/registration.rs b/pallets/subtensor/src/subnets/registration.rs index b71aa68a0a..f6c29fcea6 100644 --- a/pallets/subtensor/src/subnets/registration.rs +++ b/pallets/subtensor/src/subnets/registration.rs @@ -425,16 +425,14 @@ impl Pallet { // Insert subnet owner hotkey in the beginning of the list if valid and not // already present - if let Ok(owner_hk) = SubnetOwnerHotkey::::try_get(netuid) { - if let Some(owner_uid) = Uids::::get(netuid, &owner_hk) { - if !immune_tuples.contains(&(owner_uid, owner_hk.clone())) { + if let Ok(owner_hk) = SubnetOwnerHotkey::::try_get(netuid) + && let Some(owner_uid) = Uids::::get(netuid, &owner_hk) + && !immune_tuples.contains(&(owner_uid, owner_hk.clone())) { immune_tuples.insert(0, (owner_uid, owner_hk.clone())); if immune_tuples.len() > limit { immune_tuples.truncate(limit); } } - } - } immune_tuples } @@ -467,11 +465,10 @@ impl Pallet { let immortal_hotkeys = Self::get_immune_owner_hotkeys(netuid, &subnet_owner_coldkey); for neuron_uid in 0..neurons_n { // Do not deregister the owner's owned hotkeys - if let Ok(hotkey) = Self::get_hotkey_for_net_and_uid(netuid, neuron_uid) { - if immortal_hotkeys.contains(&hotkey) { + if let Ok(hotkey) = Self::get_hotkey_for_net_and_uid(netuid, neuron_uid) + && immortal_hotkeys.contains(&hotkey) { continue; } - } let pruning_score: u16 = Self::get_pruning_score_for_uid(netuid, neuron_uid); let block_at_registration: u64 = diff --git a/pallets/subtensor/src/subnets/serving.rs b/pallets/subtensor/src/subnets/serving.rs index cdaf39e51b..4015f4c0de 100644 --- a/pallets/subtensor/src/subnets/serving.rs +++ b/pallets/subtensor/src/subnets/serving.rs @@ -84,11 +84,10 @@ impl Pallet { )?; // Check+insert certificate - if let Some(certificate) = certificate { - if let Ok(certificate) = NeuronCertificateOf::try_from(certificate) { + if let Some(certificate) = certificate + && let Ok(certificate) = NeuronCertificateOf::try_from(certificate) { NeuronCertificates::::insert(netuid, hotkey_id.clone(), certificate) } - } // We insert the axon meta. let mut prev_axon = Self::get_axon_info(netuid, &hotkey_id); diff --git a/pallets/subtensor/src/subnets/uids.rs b/pallets/subtensor/src/subnets/uids.rs index fda21bc33f..07faeb89b3 100644 --- a/pallets/subtensor/src/subnets/uids.rs +++ b/pallets/subtensor/src/subnets/uids.rs @@ -64,15 +64,14 @@ impl Pallet { let old_hotkey: T::AccountId = Keys::::get(netuid, uid_to_replace); // Do not replace owner hotkey from `SubnetOwnerHotkey` - if let Ok(sn_owner_hotkey) = SubnetOwnerHotkey::::try_get(netuid) { - if sn_owner_hotkey == old_hotkey.clone() { + if let Ok(sn_owner_hotkey) = SubnetOwnerHotkey::::try_get(netuid) + && sn_owner_hotkey == old_hotkey.clone() { log::warn!( "replace_neuron: Skipped replacement because neuron is the subnet owner hotkey. \ netuid: {netuid:?}, uid_to_replace: {uid_to_replace:?}, new_hotkey: {new_hotkey:?}, owner_hotkey: {sn_owner_hotkey:?}" ); return; } - } // 2. Remove previous set memberships. Uids::::remove(netuid, old_hotkey.clone()); diff --git a/pallets/subtensor/src/subnets/weights.rs b/pallets/subtensor/src/subnets/weights.rs index f1a2df56e2..580a956817 100644 --- a/pallets/subtensor/src/subnets/weights.rs +++ b/pallets/subtensor/src/subnets/weights.rs @@ -1109,8 +1109,8 @@ impl Pallet { current_block: u64, ) -> bool { let maybe_netuid_and_subid = Self::get_netuid_and_subid(netuid_index); - if let Ok((netuid, _)) = maybe_netuid_and_subid { - if Self::is_uid_exist_on_network(netuid, neuron_uid) { + if let Ok((netuid, _)) = maybe_netuid_and_subid + && Self::is_uid_exist_on_network(netuid, neuron_uid) { // --- 1. Ensure that the diff between current and last_set weights is greater than limit. let last_set_weights: u64 = Self::get_last_update_for_uid(netuid_index, neuron_uid); if last_set_weights == 0 { @@ -1119,7 +1119,6 @@ impl Pallet { return current_block.saturating_sub(last_set_weights) >= Self::get_weights_set_rate_limit(netuid); } - } // --- 3. Non registered peers cant pass. Neither can non-existing mecid false diff --git a/pallets/subtensor/src/swap/swap_hotkey.rs b/pallets/subtensor/src/swap/swap_hotkey.rs index 38f1f85df8..f494e0039f 100644 --- a/pallets/subtensor/src/swap/swap_hotkey.rs +++ b/pallets/subtensor/src/swap/swap_hotkey.rs @@ -369,23 +369,21 @@ impl Pallet { // 3.3 Swap Prometheus. // Prometheus( netuid, hotkey ) -> prometheus -- the prometheus data that a hotkey has in the network. - if is_network_member { - if let Ok(old_prometheus_info) = Prometheus::::try_get(netuid, old_hotkey) { + if is_network_member + && let Ok(old_prometheus_info) = Prometheus::::try_get(netuid, old_hotkey) { Prometheus::::remove(netuid, old_hotkey); Prometheus::::insert(netuid, new_hotkey, old_prometheus_info); weight.saturating_accrue(T::DbWeight::get().reads_writes(1, 2)); } - } // 3.4. Swap axons. // Axons( netuid, hotkey ) -> axon -- the axon that the hotkey has. - if is_network_member { - if let Ok(old_axon_info) = Axons::::try_get(netuid, old_hotkey) { + if is_network_member + && let Ok(old_axon_info) = Axons::::try_get(netuid, old_hotkey) { Axons::::remove(netuid, old_hotkey); Axons::::insert(netuid, new_hotkey, old_axon_info); weight.saturating_accrue(T::DbWeight::get().reads_writes(1, 2)); } - } // 3.5 Swap WeightCommits // WeightCommits( hotkey ) --> Vec -- the weight commits for the hotkey. @@ -404,8 +402,8 @@ impl Pallet { // 3.6. Swap the subnet loaded emission. // LoadedEmission( netuid ) --> Vec<(hotkey, u64)> -- the loaded emission for the subnet. - if is_network_member { - if let Some(mut old_loaded_emission) = LoadedEmission::::get(netuid) { + if is_network_member + && let Some(mut old_loaded_emission) = LoadedEmission::::get(netuid) { for emission in old_loaded_emission.iter_mut() { if emission.0 == *old_hotkey { emission.0 = new_hotkey.clone(); @@ -415,19 +413,17 @@ impl Pallet { LoadedEmission::::insert(netuid, old_loaded_emission); weight.saturating_accrue(T::DbWeight::get().reads_writes(1, 2)); } - } // 3.7. Swap neuron TLS certificates. // NeuronCertificates( netuid, hotkey ) -> Vec -- the neuron certificate for the hotkey. - if is_network_member { - if let Ok(old_neuron_certificates) = + if is_network_member + && let Ok(old_neuron_certificates) = NeuronCertificates::::try_get(netuid, old_hotkey) { NeuronCertificates::::remove(netuid, old_hotkey); NeuronCertificates::::insert(netuid, new_hotkey, old_neuron_certificates); weight.saturating_accrue(T::DbWeight::get().reads_writes(1, 2)); } - } // 4. Swap ChildKeys. // 5. Swap ParentKeys. // 6. Swap PendingChildKeys. diff --git a/pallets/swap/src/pallet/impls.rs b/pallets/swap/src/pallet/impls.rs index eb7d27d1a6..a7d7cdd32b 100644 --- a/pallets/swap/src/pallet/impls.rs +++ b/pallets/swap/src/pallet/impls.rs @@ -261,13 +261,12 @@ impl Pallet { // Should persist changes // Check if reserves are overused - if let Ok(ref swap_result) = result { - if reserve < swap_result.amount_paid_out { + if let Ok(ref swap_result) = result + && reserve < swap_result.amount_paid_out { return TransactionOutcome::Commit(Err( Error::::InsufficientLiquidity.into() )); } - } TransactionOutcome::Commit(result) } diff --git a/pallets/utility/src/lib.rs b/pallets/utility/src/lib.rs index 96dfd26157..9ec9600cff 100644 --- a/pallets/utility/src/lib.rs +++ b/pallets/utility/src/lib.rs @@ -144,9 +144,7 @@ pub mod pallet { fn batched_calls_limit() -> u32 { let allocator_limit = sp_core::MAX_POSSIBLE_ALLOCATION; let call_size = (core::mem::size_of::<::RuntimeCall>() as u32) - .div_ceil(CALL_ALIGN) - .checked_mul(CALL_ALIGN) - .unwrap_or(u32::MAX); + .div_ceil(CALL_ALIGN).saturating_mul(CALL_ALIGN); // The margin to take into account vec doubling capacity. let margin_factor = 3; diff --git a/support/linting/src/require_freeze_struct.rs b/support/linting/src/require_freeze_struct.rs index b697c5b824..c29c5a9a2f 100644 --- a/support/linting/src/require_freeze_struct.rs +++ b/support/linting/src/require_freeze_struct.rs @@ -54,15 +54,14 @@ fn is_freeze_struct(attr: &Attribute) -> bool { } fn is_derive_encode_or_decode(attr: &Attribute) -> bool { - if let Meta::List(MetaList { path, tokens, .. }) = &attr.meta { - if path.is_ident("derive") { + if let Meta::List(MetaList { path, tokens, .. }) = &attr.meta + && path.is_ident("derive") { let nested: Punctuated = parse_quote!(#tokens); return nested.iter().any(|nested| { nested.segments.iter().any(|seg| seg.ident == "Encode") || nested.segments.iter().any(|seg| seg.ident == "Decode") }); } - } false } From 861cb74174fffd2af512b3dff73db83a23896ecd Mon Sep 17 00:00:00 2001 From: Loris Moulin Date: Tue, 2 Dec 2025 21:45:01 +0100 Subject: [PATCH 05/16] cargo fmt --- .../subtensor/src/coinbase/run_coinbase.rs | 39 ++++++++------- pallets/subtensor/src/epoch/math.rs | 35 +++++++------ pallets/subtensor/src/epoch/run_epoch.rs | 7 +-- pallets/subtensor/src/staking/stake_utils.rs | 15 +++--- pallets/subtensor/src/subnets/registration.rs | 20 ++++---- pallets/subtensor/src/subnets/serving.rs | 7 +-- pallets/subtensor/src/subnets/uids.rs | 13 ++--- pallets/subtensor/src/subnets/weights.rs | 19 +++---- pallets/subtensor/src/swap/swap_hotkey.rs | 50 +++++++++---------- pallets/swap/src/pallet/impls.rs | 11 ++-- pallets/utility/src/lib.rs | 3 +- support/linting/src/require_freeze_struct.rs | 15 +++--- 12 files changed, 126 insertions(+), 108 deletions(-) diff --git a/pallets/subtensor/src/coinbase/run_coinbase.rs b/pallets/subtensor/src/coinbase/run_coinbase.rs index 09ddd9d379..308e1602e5 100644 --- a/pallets/subtensor/src/coinbase/run_coinbase.rs +++ b/pallets/subtensor/src/coinbase/run_coinbase.rs @@ -499,9 +499,11 @@ impl Pallet { // Insert subnet owner hotkey in the beginning of the list if valid and not // already present if let Ok(owner_hk) = SubnetOwnerHotkey::::try_get(netuid) - && Uids::::get(netuid, &owner_hk).is_some() && !owner_hotkeys.contains(&owner_hk) { - owner_hotkeys.insert(0, owner_hk); - } + && Uids::::get(netuid, &owner_hk).is_some() + && !owner_hotkeys.contains(&owner_hk) + { + owner_hotkeys.insert(0, owner_hk); + } owner_hotkeys } @@ -515,22 +517,23 @@ impl Pallet { ) { // Distribute the owner cut. if let Ok(owner_coldkey) = SubnetOwner::::try_get(netuid) - && let Ok(owner_hotkey) = SubnetOwnerHotkey::::try_get(netuid) { - // Increase stake for owner hotkey and coldkey. - log::debug!( - "owner_hotkey: {owner_hotkey:?} owner_coldkey: {owner_coldkey:?}, owner_cut: {owner_cut:?}" - ); - let real_owner_cut = Self::increase_stake_for_hotkey_and_coldkey_on_subnet( - &owner_hotkey, - &owner_coldkey, - netuid, - owner_cut, - ); - // If the subnet is leased, notify the lease logic that owner cut has been distributed. - if let Some(lease_id) = SubnetUidToLeaseId::::get(netuid) { - Self::distribute_leased_network_dividends(lease_id, real_owner_cut); - } + && let Ok(owner_hotkey) = SubnetOwnerHotkey::::try_get(netuid) + { + // Increase stake for owner hotkey and coldkey. + log::debug!( + "owner_hotkey: {owner_hotkey:?} owner_coldkey: {owner_coldkey:?}, owner_cut: {owner_cut:?}" + ); + let real_owner_cut = Self::increase_stake_for_hotkey_and_coldkey_on_subnet( + &owner_hotkey, + &owner_coldkey, + netuid, + owner_cut, + ); + // If the subnet is leased, notify the lease logic that owner cut has been distributed. + if let Some(lease_id) = SubnetUidToLeaseId::::get(netuid) { + Self::distribute_leased_network_dividends(lease_id, real_owner_cut); } + } // Distribute mining incentives. let subnet_owner_coldkey = SubnetOwner::::get(netuid); diff --git a/pallets/subtensor/src/epoch/math.rs b/pallets/subtensor/src/epoch/math.rs index 113d58075f..ee165e7670 100644 --- a/pallets/subtensor/src/epoch/math.rs +++ b/pallets/subtensor/src/epoch/math.rs @@ -336,9 +336,10 @@ pub fn inplace_row_normalize_sparse(sparse_matrix: &mut [Vec<(u16, I32F32)>]) { // Sum across each row (dim=0) of a matrix. pub fn row_sum(x: &[Vec]) -> Vec { if let Some(first_row) = x.first() - && first_row.is_empty() { - return vec![]; - } + && first_row.is_empty() + { + return vec![]; + } x.iter().map(|row| row.iter().sum()).collect() } @@ -424,9 +425,10 @@ pub fn inplace_col_max_upscale_sparse(sparse_matrix: &mut [Vec<(u16, I32F32)>], for sparse_row in sparse_matrix.iter() { for (j, value) in sparse_row.iter() { if let Some(m) = col_max.get_mut(*j as usize) - && *m < *value { - *m = *value; - } + && *m < *value + { + *m = *value; + } } } @@ -1146,9 +1148,10 @@ pub fn weighted_median_col_sparse( if s > zero { for &(c, val) in sparse_row.iter() { if let Some(col_vec) = use_score.get_mut(c as usize) - && let Some(cell) = col_vec.get_mut(k) { - *cell = val; - } + && let Some(cell) = col_vec.get_mut(k) + { + *cell = val; + } } k = k.saturating_add(1); } @@ -1287,9 +1290,10 @@ pub fn interpolate_sparse( let v2 = row2.get(j).unwrap_or(&zero); let interp = v1.saturating_add(ratio.saturating_mul(v2.saturating_sub(*v1))); if zero < interp - && let Some(res) = result.get_mut(i) { - res.push((j as u16, interp)); - } + && let Some(res) = result.get_mut(i) + { + res.push((j as u16, interp)); + } } } result @@ -1335,9 +1339,10 @@ pub fn mat_vec_mul_sparse( 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) - && let Some(result_row) = result.get_mut(i) { - result_row.push((*j, new_value)); - } + && let Some(result_row) = result.get_mut(i) + { + result_row.push((*j, new_value)); + } } } } diff --git a/pallets/subtensor/src/epoch/run_epoch.rs b/pallets/subtensor/src/epoch/run_epoch.rs index b631b8c6a9..01b8dea858 100644 --- a/pallets/subtensor/src/epoch/run_epoch.rs +++ b/pallets/subtensor/src/epoch/run_epoch.rs @@ -762,9 +762,10 @@ impl Pallet { for (_epoch, q) in TimelockedWeightCommits::::iter_prefix(netuid_index) { for (who, cb, ..) in q.iter() { if !Self::is_commit_expired(netuid, *cb) - && let Some(cell) = uid_of(who).and_then(|i| commit_blocks.get_mut(i)) { - *cell = (*cell).min(*cb); - } + && let Some(cell) = uid_of(who).and_then(|i| commit_blocks.get_mut(i)) + { + *cell = (*cell).min(*cb); + } } } diff --git a/pallets/subtensor/src/staking/stake_utils.rs b/pallets/subtensor/src/staking/stake_utils.rs index ab8c130b09..d803dc7d25 100644 --- a/pallets/subtensor/src/staking/stake_utils.rs +++ b/pallets/subtensor/src/staking/stake_utils.rs @@ -563,10 +563,10 @@ impl Pallet { // We expect a negative value here let mut actual_alpha = 0; if let Ok(value) = alpha_share_pool.try_get_value(coldkey) - && value >= amount { - actual_alpha = - alpha_share_pool.update_value_for_one(coldkey, (amount as i64).neg()); - } + && value >= amount + { + actual_alpha = alpha_share_pool.update_value_for_one(coldkey, (amount as i64).neg()); + } // Get the negation of the removed alpha, and clamp at 0. // This ensures we return a positive value, but only if @@ -1200,9 +1200,10 @@ impl Pallet { // Ensure that if partial execution is not allowed, the amount will not cause // slippage over desired if let Some(allow_partial) = maybe_allow_partial - && !allow_partial { - ensure!(alpha_amount <= max_amount, Error::::SlippageTooHigh); - } + && !allow_partial + { + ensure!(alpha_amount <= max_amount, Error::::SlippageTooHigh); + } } if check_transfer_toggle { diff --git a/pallets/subtensor/src/subnets/registration.rs b/pallets/subtensor/src/subnets/registration.rs index f6c29fcea6..ac86f5b933 100644 --- a/pallets/subtensor/src/subnets/registration.rs +++ b/pallets/subtensor/src/subnets/registration.rs @@ -427,12 +427,13 @@ impl Pallet { // already present if let Ok(owner_hk) = SubnetOwnerHotkey::::try_get(netuid) && let Some(owner_uid) = Uids::::get(netuid, &owner_hk) - && !immune_tuples.contains(&(owner_uid, owner_hk.clone())) { - immune_tuples.insert(0, (owner_uid, owner_hk.clone())); - if immune_tuples.len() > limit { - immune_tuples.truncate(limit); - } - } + && !immune_tuples.contains(&(owner_uid, owner_hk.clone())) + { + immune_tuples.insert(0, (owner_uid, owner_hk.clone())); + if immune_tuples.len() > limit { + immune_tuples.truncate(limit); + } + } immune_tuples } @@ -466,9 +467,10 @@ impl Pallet { for neuron_uid in 0..neurons_n { // Do not deregister the owner's owned hotkeys if let Ok(hotkey) = Self::get_hotkey_for_net_and_uid(netuid, neuron_uid) - && immortal_hotkeys.contains(&hotkey) { - continue; - } + && immortal_hotkeys.contains(&hotkey) + { + continue; + } let pruning_score: u16 = Self::get_pruning_score_for_uid(netuid, neuron_uid); let block_at_registration: u64 = diff --git a/pallets/subtensor/src/subnets/serving.rs b/pallets/subtensor/src/subnets/serving.rs index 4015f4c0de..d11eb479d3 100644 --- a/pallets/subtensor/src/subnets/serving.rs +++ b/pallets/subtensor/src/subnets/serving.rs @@ -85,9 +85,10 @@ impl Pallet { // Check+insert certificate if let Some(certificate) = certificate - && let Ok(certificate) = NeuronCertificateOf::try_from(certificate) { - NeuronCertificates::::insert(netuid, hotkey_id.clone(), certificate) - } + && let Ok(certificate) = NeuronCertificateOf::try_from(certificate) + { + NeuronCertificates::::insert(netuid, hotkey_id.clone(), certificate) + } // We insert the axon meta. let mut prev_axon = Self::get_axon_info(netuid, &hotkey_id); diff --git a/pallets/subtensor/src/subnets/uids.rs b/pallets/subtensor/src/subnets/uids.rs index 07faeb89b3..7de883e6ba 100644 --- a/pallets/subtensor/src/subnets/uids.rs +++ b/pallets/subtensor/src/subnets/uids.rs @@ -65,13 +65,14 @@ impl Pallet { // Do not replace owner hotkey from `SubnetOwnerHotkey` if let Ok(sn_owner_hotkey) = SubnetOwnerHotkey::::try_get(netuid) - && sn_owner_hotkey == old_hotkey.clone() { - log::warn!( - "replace_neuron: Skipped replacement because neuron is the subnet owner hotkey. \ + && sn_owner_hotkey == old_hotkey.clone() + { + log::warn!( + "replace_neuron: Skipped replacement because neuron is the subnet owner hotkey. \ netuid: {netuid:?}, uid_to_replace: {uid_to_replace:?}, new_hotkey: {new_hotkey:?}, owner_hotkey: {sn_owner_hotkey:?}" - ); - return; - } + ); + return; + } // 2. Remove previous set memberships. Uids::::remove(netuid, old_hotkey.clone()); diff --git a/pallets/subtensor/src/subnets/weights.rs b/pallets/subtensor/src/subnets/weights.rs index 580a956817..56acbef9c7 100644 --- a/pallets/subtensor/src/subnets/weights.rs +++ b/pallets/subtensor/src/subnets/weights.rs @@ -1110,15 +1110,16 @@ impl Pallet { ) -> bool { let maybe_netuid_and_subid = Self::get_netuid_and_subid(netuid_index); if let Ok((netuid, _)) = maybe_netuid_and_subid - && Self::is_uid_exist_on_network(netuid, neuron_uid) { - // --- 1. Ensure that the diff between current and last_set weights is greater than limit. - let last_set_weights: u64 = Self::get_last_update_for_uid(netuid_index, neuron_uid); - if last_set_weights == 0 { - return true; - } // (Storage default) Never set weights. - return current_block.saturating_sub(last_set_weights) - >= Self::get_weights_set_rate_limit(netuid); - } + && Self::is_uid_exist_on_network(netuid, neuron_uid) + { + // --- 1. Ensure that the diff between current and last_set weights is greater than limit. + let last_set_weights: u64 = Self::get_last_update_for_uid(netuid_index, neuron_uid); + if last_set_weights == 0 { + return true; + } // (Storage default) Never set weights. + return current_block.saturating_sub(last_set_weights) + >= Self::get_weights_set_rate_limit(netuid); + } // --- 3. Non registered peers cant pass. Neither can non-existing mecid false diff --git a/pallets/subtensor/src/swap/swap_hotkey.rs b/pallets/subtensor/src/swap/swap_hotkey.rs index f494e0039f..4fdf87fb7b 100644 --- a/pallets/subtensor/src/swap/swap_hotkey.rs +++ b/pallets/subtensor/src/swap/swap_hotkey.rs @@ -370,20 +370,20 @@ impl Pallet { // 3.3 Swap Prometheus. // Prometheus( netuid, hotkey ) -> prometheus -- the prometheus data that a hotkey has in the network. if is_network_member - && let Ok(old_prometheus_info) = Prometheus::::try_get(netuid, old_hotkey) { - Prometheus::::remove(netuid, old_hotkey); - Prometheus::::insert(netuid, new_hotkey, old_prometheus_info); - weight.saturating_accrue(T::DbWeight::get().reads_writes(1, 2)); - } + && let Ok(old_prometheus_info) = Prometheus::::try_get(netuid, old_hotkey) + { + Prometheus::::remove(netuid, old_hotkey); + Prometheus::::insert(netuid, new_hotkey, old_prometheus_info); + weight.saturating_accrue(T::DbWeight::get().reads_writes(1, 2)); + } // 3.4. Swap axons. // Axons( netuid, hotkey ) -> axon -- the axon that the hotkey has. - if is_network_member - && let Ok(old_axon_info) = Axons::::try_get(netuid, old_hotkey) { - Axons::::remove(netuid, old_hotkey); - Axons::::insert(netuid, new_hotkey, old_axon_info); - weight.saturating_accrue(T::DbWeight::get().reads_writes(1, 2)); - } + if is_network_member && let Ok(old_axon_info) = Axons::::try_get(netuid, old_hotkey) { + Axons::::remove(netuid, old_hotkey); + Axons::::insert(netuid, new_hotkey, old_axon_info); + weight.saturating_accrue(T::DbWeight::get().reads_writes(1, 2)); + } // 3.5 Swap WeightCommits // WeightCommits( hotkey ) --> Vec -- the weight commits for the hotkey. @@ -402,28 +402,28 @@ impl Pallet { // 3.6. Swap the subnet loaded emission. // LoadedEmission( netuid ) --> Vec<(hotkey, u64)> -- the loaded emission for the subnet. - if is_network_member - && let Some(mut old_loaded_emission) = LoadedEmission::::get(netuid) { - for emission in old_loaded_emission.iter_mut() { - if emission.0 == *old_hotkey { - emission.0 = new_hotkey.clone(); - } + if is_network_member && let Some(mut old_loaded_emission) = LoadedEmission::::get(netuid) + { + for emission in old_loaded_emission.iter_mut() { + if emission.0 == *old_hotkey { + emission.0 = new_hotkey.clone(); } - LoadedEmission::::remove(netuid); - LoadedEmission::::insert(netuid, old_loaded_emission); - weight.saturating_accrue(T::DbWeight::get().reads_writes(1, 2)); } + LoadedEmission::::remove(netuid); + LoadedEmission::::insert(netuid, old_loaded_emission); + weight.saturating_accrue(T::DbWeight::get().reads_writes(1, 2)); + } // 3.7. Swap neuron TLS certificates. // NeuronCertificates( netuid, hotkey ) -> Vec -- the neuron certificate for the hotkey. if is_network_member && let Ok(old_neuron_certificates) = NeuronCertificates::::try_get(netuid, old_hotkey) - { - NeuronCertificates::::remove(netuid, old_hotkey); - NeuronCertificates::::insert(netuid, new_hotkey, old_neuron_certificates); - weight.saturating_accrue(T::DbWeight::get().reads_writes(1, 2)); - } + { + NeuronCertificates::::remove(netuid, old_hotkey); + NeuronCertificates::::insert(netuid, new_hotkey, old_neuron_certificates); + weight.saturating_accrue(T::DbWeight::get().reads_writes(1, 2)); + } // 4. Swap ChildKeys. // 5. Swap ParentKeys. // 6. Swap PendingChildKeys. diff --git a/pallets/swap/src/pallet/impls.rs b/pallets/swap/src/pallet/impls.rs index a7d7cdd32b..6600bb2bc7 100644 --- a/pallets/swap/src/pallet/impls.rs +++ b/pallets/swap/src/pallet/impls.rs @@ -262,11 +262,12 @@ impl Pallet { // Check if reserves are overused if let Ok(ref swap_result) = result - && reserve < swap_result.amount_paid_out { - return TransactionOutcome::Commit(Err( - Error::::InsufficientLiquidity.into() - )); - } + && reserve < swap_result.amount_paid_out + { + return TransactionOutcome::Commit(Err( + Error::::InsufficientLiquidity.into() + )); + } TransactionOutcome::Commit(result) } diff --git a/pallets/utility/src/lib.rs b/pallets/utility/src/lib.rs index 9ec9600cff..d9f9bca281 100644 --- a/pallets/utility/src/lib.rs +++ b/pallets/utility/src/lib.rs @@ -144,7 +144,8 @@ pub mod pallet { fn batched_calls_limit() -> u32 { let allocator_limit = sp_core::MAX_POSSIBLE_ALLOCATION; let call_size = (core::mem::size_of::<::RuntimeCall>() as u32) - .div_ceil(CALL_ALIGN).saturating_mul(CALL_ALIGN); + .div_ceil(CALL_ALIGN) + .saturating_mul(CALL_ALIGN); // The margin to take into account vec doubling capacity. let margin_factor = 3; diff --git a/support/linting/src/require_freeze_struct.rs b/support/linting/src/require_freeze_struct.rs index c29c5a9a2f..288f2a2b1a 100644 --- a/support/linting/src/require_freeze_struct.rs +++ b/support/linting/src/require_freeze_struct.rs @@ -55,13 +55,14 @@ fn is_freeze_struct(attr: &Attribute) -> bool { fn is_derive_encode_or_decode(attr: &Attribute) -> bool { if let Meta::List(MetaList { path, tokens, .. }) = &attr.meta - && path.is_ident("derive") { - let nested: Punctuated = parse_quote!(#tokens); - return nested.iter().any(|nested| { - nested.segments.iter().any(|seg| seg.ident == "Encode") - || nested.segments.iter().any(|seg| seg.ident == "Decode") - }); - } + && path.is_ident("derive") + { + let nested: Punctuated = parse_quote!(#tokens); + return nested.iter().any(|nested| { + nested.segments.iter().any(|seg| seg.ident == "Encode") + || nested.segments.iter().any(|seg| seg.ident == "Decode") + }); + } false } From a07f80afc8653eac6611a393a17b1259a886b9ae Mon Sep 17 00:00:00 2001 From: Loris Moulin Date: Tue, 2 Dec 2025 21:48:20 +0100 Subject: [PATCH 06/16] fix lifetimes --- node/src/consensus/aura_consensus.rs | 2 +- node/src/consensus/babe_consensus.rs | 2 +- node/src/consensus/consensus_mechanism.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/node/src/consensus/aura_consensus.rs b/node/src/consensus/aura_consensus.rs index 57012733f6..57b5559fd3 100644 --- a/node/src/consensus/aura_consensus.rs +++ b/node/src/consensus/aura_consensus.rs @@ -120,7 +120,7 @@ impl ConsensusMechanism for AuraConsensus { Self {} } - fn build_biq(&mut self) -> Result + fn build_biq(&mut self) -> Result, sc_service::Error> where NumberFor: BlockNumberOps, { diff --git a/node/src/consensus/babe_consensus.rs b/node/src/consensus/babe_consensus.rs index 8c9a974d20..42d3022512 100644 --- a/node/src/consensus/babe_consensus.rs +++ b/node/src/consensus/babe_consensus.rs @@ -128,7 +128,7 @@ impl ConsensusMechanism for BabeConsensus { } } - fn build_biq(&mut self) -> Result + fn build_biq(&mut self) -> Result, sc_service::Error> where NumberFor: BlockNumberOps, { diff --git a/node/src/consensus/consensus_mechanism.rs b/node/src/consensus/consensus_mechanism.rs index 359b89f6ef..a500f5efe0 100644 --- a/node/src/consensus/consensus_mechanism.rs +++ b/node/src/consensus/consensus_mechanism.rs @@ -77,7 +77,7 @@ pub trait ConsensusMechanism { fn new() -> Self; /// Builds a `BIQ` that uses the ConsensusMechanism. - fn build_biq(&mut self) -> Result; + fn build_biq(&mut self) -> Result, sc_service::Error>; /// Returns the slot duration. fn slot_duration(&self, client: &FullClient) -> Result; From f23fa5ec30cae99bbd1b87a11de8d7b3144102fe Mon Sep 17 00:00:00 2001 From: Loris Moulin Date: Tue, 2 Dec 2025 21:50:44 +0100 Subject: [PATCH 07/16] fix comments --- pallets/subtensor/src/macros/dispatches.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pallets/subtensor/src/macros/dispatches.rs b/pallets/subtensor/src/macros/dispatches.rs index ef36b17921..e4763d8c34 100644 --- a/pallets/subtensor/src/macros/dispatches.rs +++ b/pallets/subtensor/src/macros/dispatches.rs @@ -49,7 +49,7 @@ mod dispatches { /// /// * 'weights' (Vec): /// - The u16 integer encoded weights. Interpreted as rational - /// values in the range [0,1]. They must sum to in32::MAX. + /// values in the range [0,1]. They must sum to in32::MAX. /// /// * 'version_key' ( u64 ): /// - The network version key to check if the validator is up to date. @@ -128,7 +128,7 @@ mod dispatches { /// /// * 'weights' (Vec): /// - The u16 integer encoded weights. Interpreted as rational - /// values in the range [0,1]. They must sum to in32::MAX. + /// values in the range [0,1]. They must sum to in32::MAX. /// /// * 'version_key' ( u64 ): /// - The network version key to check if the validator is up to date. From d50248973c8b41e5e15c3734b6188c4465214e7c Mon Sep 17 00:00:00 2001 From: Loris Moulin Date: Tue, 2 Dec 2025 21:54:23 +0100 Subject: [PATCH 08/16] commit Cargo.lock --- pallets/utility/src/tests.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pallets/utility/src/tests.rs b/pallets/utility/src/tests.rs index 8b0a9274c2..03b4acbbf2 100644 --- a/pallets/utility/src/tests.rs +++ b/pallets/utility/src/tests.rs @@ -133,12 +133,11 @@ impl pallet_timestamp::Config for Test { type WeightInfo = (); } -const MOTION_DURATION_IN_BLOCKS: BlockNumber = 3; parameter_types! { pub const MultisigDepositBase: u64 = 1; pub const MultisigDepositFactor: u64 = 1; pub const MaxSignatories: u32 = 3; - pub const MotionDuration: BlockNumber = MOTION_DURATION_IN_BLOCKS; + pub const MotionDuration: BlockNumber = 3; pub const MaxProposals: u32 = 100; pub const MaxMembers: u32 = 100; pub MaxProposalWeight: Weight = BlockWeights::get().max_block.saturating_div(2); From cebf5bbb522c9d16388d46d4136492c04f8c2f38 Mon Sep 17 00:00:00 2001 From: Loris Moulin Date: Mon, 8 Dec 2025 16:11:19 +0100 Subject: [PATCH 09/16] cargo fmt --- pallets/shield/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pallets/shield/src/lib.rs b/pallets/shield/src/lib.rs index 7f6c7ba75e..e60bb2a6dc 100644 --- a/pallets/shield/src/lib.rs +++ b/pallets/shield/src/lib.rs @@ -279,8 +279,8 @@ pub mod pallet { /// Client‑side: /// /// 1. Read `NextKey` (ML‑KEM public key bytes) from storage. - /// 2. Sign your extrinsic so that it can be executed when added to the pool, - /// i.e. you may need to increment the nonce if you submit using the same account. + /// 2. Sign your extrinsic so that it can be executed when added to the pool, + /// i.e. you may need to increment the nonce if you submit using the same account. /// 3. `commitment = Hashing::hash(signed_extrinsic)`. /// 4. Encrypt: /// From 566d91c67f19b2f4b6566e6ea2a998cfeac98713 Mon Sep 17 00:00:00 2001 From: Loris Moulin Date: Tue, 16 Dec 2025 14:31:47 +0100 Subject: [PATCH 10/16] cargo clippy --- pallets/subtensor/src/subnets/registration.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pallets/subtensor/src/subnets/registration.rs b/pallets/subtensor/src/subnets/registration.rs index dcaf07b2de..739613d2f1 100644 --- a/pallets/subtensor/src/subnets/registration.rs +++ b/pallets/subtensor/src/subnets/registration.rs @@ -522,11 +522,10 @@ impl Pallet { let can_prune_non_immune = free_count > min_free; // Prefer non‑immune if allowed; otherwise fall back to immune. - if can_prune_non_immune { - if let Some((_, _, uid)) = best_non_immune { + if can_prune_non_immune + && let Some((_, _, uid)) = best_non_immune { return Some(uid); } - } best_immune.map(|(_, _, uid)| uid) } From 1418eaaece52bffea36ed5bf30f0cb20a411a9b1 Mon Sep 17 00:00:00 2001 From: Loris Moulin Date: Tue, 16 Dec 2025 14:33:06 +0100 Subject: [PATCH 11/16] cargo fmt --- pallets/subtensor/src/subnets/registration.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pallets/subtensor/src/subnets/registration.rs b/pallets/subtensor/src/subnets/registration.rs index 739613d2f1..a7771857bb 100644 --- a/pallets/subtensor/src/subnets/registration.rs +++ b/pallets/subtensor/src/subnets/registration.rs @@ -522,10 +522,9 @@ impl Pallet { let can_prune_non_immune = free_count > min_free; // Prefer non‑immune if allowed; otherwise fall back to immune. - if can_prune_non_immune - && let Some((_, _, uid)) = best_non_immune { - return Some(uid); - } + if can_prune_non_immune && let Some((_, _, uid)) = best_non_immune { + return Some(uid); + } best_immune.map(|(_, _, uid)| uid) } From d01216d2c880408530755ac88f7a12f58e8acd51 Mon Sep 17 00:00:00 2001 From: Loris Moulin Date: Tue, 16 Dec 2025 14:41:49 +0100 Subject: [PATCH 12/16] fix script --- scripts/fix_rust.sh | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/scripts/fix_rust.sh b/scripts/fix_rust.sh index 9d2af2904b..4824c7d53e 100755 --- a/scripts/fix_rust.sh +++ b/scripts/fix_rust.sh @@ -11,12 +11,12 @@ commit_if_changes() { fi } -# Step 1: Run cargo check and commit changes to Cargo.lock if any. +# Step 1: Run cargo check and commit changes to Cargo.lock if any cargo check --workspace commit_if_changes "commit Cargo.lock" # Step 2: Run cargo clippy with fixes and commit changes if any. -cargo clippy --fix --workspace --all-features +cargo clippy --fix --workspace --all-features --all-targets commit_if_changes "cargo clippy" # Step 3: Run cargo fix and commit changes if any. @@ -24,5 +24,10 @@ cargo fix --workspace --all-features --all-targets commit_if_changes "cargo fix" # Step 4: Run cargo fmt and commit changes if any. -cargo fmt +cargo +nightly fmt --all commit_if_changes "cargo fmt" + +if command -v zepter >/dev/null 2>&1; then + echo "zepter detected, running 'zepter run check'..." + zepter run check +fi \ No newline at end of file From dd4b320376d549a3f0459ccc404024658854af9f Mon Sep 17 00:00:00 2001 From: Loris Moulin Date: Tue, 16 Dec 2025 14:43:24 +0100 Subject: [PATCH 13/16] cargo clippy --- chain-extensions/src/tests.rs | 5 ++--- pallets/subtensor/src/tests/networks.rs | 5 ++--- pallets/subtensor/src/tests/weights.rs | 5 ++--- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/chain-extensions/src/tests.rs b/chain-extensions/src/tests.rs index 094b0987e2..b1e8faa485 100644 --- a/chain-extensions/src/tests.rs +++ b/chain-extensions/src/tests.rs @@ -757,13 +757,12 @@ impl SubtensorExtensionEnv for MockEnv { } fn charge_weight(&mut self, weight: Weight) -> Result<(), DispatchError> { - if let Some(expected) = self.expected_weight { - if weight != expected { + if let Some(expected) = self.expected_weight + && weight != expected { return Err(DispatchError::Other( "unexpected weight charged by mock env", )); } - } self.charged_weight = Some(weight); Ok(()) } diff --git a/pallets/subtensor/src/tests/networks.rs b/pallets/subtensor/src/tests/networks.rs index 60637e0b1f..00b894ac5a 100644 --- a/pallets/subtensor/src/tests/networks.rs +++ b/pallets/subtensor/src/tests/networks.rs @@ -1930,8 +1930,8 @@ fn massive_dissolve_refund_and_reregistration_flow_is_lossless_and_cleans_state( // Capture **pair‑level** α snapshot per net (pre‑LP). for ((hot, cold, net), amt) in Alpha::::iter() { - if let Some(&ni) = net_index.get(&net) { - if lp_sets_per_net[ni].contains(&cold) { + if let Some(&ni) = net_index.get(&net) + && lp_sets_per_net[ni].contains(&cold) { let a: u128 = amt.saturating_to_num(); if a > 0 { alpha_pairs_per_net @@ -1940,7 +1940,6 @@ fn massive_dissolve_refund_and_reregistration_flow_is_lossless_and_cleans_state( .push(((hot, cold), a)); } } - } } // ──────────────────────────────────────────────────────────────────── diff --git a/pallets/subtensor/src/tests/weights.rs b/pallets/subtensor/src/tests/weights.rs index 21d37984e4..20ace5ee0d 100644 --- a/pallets/subtensor/src/tests/weights.rs +++ b/pallets/subtensor/src/tests/weights.rs @@ -4383,8 +4383,8 @@ fn test_highly_concurrent_commits_and_reveals_with_multiple_hotkeys() { // Attempt unauthorized reveal let unauthorized_hotkey = hotkeys[0]; let target_hotkey = hotkeys[1]; - if let Some(commits) = commit_info_map.get(&target_hotkey) { - if let Some((_commit_hash, salt, uids, values, version_key)) = commits.first() { + if let Some(commits) = commit_info_map.get(&target_hotkey) + && let Some((_commit_hash, salt, uids, values, version_key)) = commits.first() { assert_err!( SubtensorModule::reveal_weights( RuntimeOrigin::signed(unauthorized_hotkey), @@ -4397,7 +4397,6 @@ fn test_highly_concurrent_commits_and_reveals_with_multiple_hotkeys() { Error::::InvalidRevealCommitHashNotMatch ); } - } let non_committing_hotkey: ::AccountId = U256::from(9999); assert_err!( From 983abce16ea02be5350a05134f264e2e27298303 Mon Sep 17 00:00:00 2001 From: Loris Moulin Date: Tue, 16 Dec 2025 14:44:28 +0100 Subject: [PATCH 14/16] cargo fmt --- chain-extensions/src/tests.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/chain-extensions/src/tests.rs b/chain-extensions/src/tests.rs index b1e8faa485..bd6f46c8ab 100644 --- a/chain-extensions/src/tests.rs +++ b/chain-extensions/src/tests.rs @@ -758,11 +758,12 @@ impl SubtensorExtensionEnv for MockEnv { fn charge_weight(&mut self, weight: Weight) -> Result<(), DispatchError> { if let Some(expected) = self.expected_weight - && weight != expected { - return Err(DispatchError::Other( - "unexpected weight charged by mock env", - )); - } + && weight != expected + { + return Err(DispatchError::Other( + "unexpected weight charged by mock env", + )); + } self.charged_weight = Some(weight); Ok(()) } From 58d55d5f62af13b7e6fe5b8553ba0853bf016a4f Mon Sep 17 00:00:00 2001 From: Loris Moulin Date: Tue, 16 Dec 2025 14:52:29 +0100 Subject: [PATCH 15/16] fix cargo fmt in ci to error on ice --- .github/workflows/check-rust.yml | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/.github/workflows/check-rust.yml b/.github/workflows/check-rust.yml index 6cdc56f26a..2ca0ae6c5c 100644 --- a/.github/workflows/check-rust.yml +++ b/.github/workflows/check-rust.yml @@ -48,7 +48,22 @@ jobs: cache-on-failure: true - name: cargo fmt - run: cargo +nightly fmt --check --all + run: | + set -euo pipefail + # Run cargo fmt and capture both stdout and stderr + output=$(cargo +nightly fmt --check --all 2>&1) || { + echo "❌ cargo fmt failed with non-zero exit code" + echo "$output" + exit 1 + } + # Check for panic/ICE messages even if exit code was 0 + if echo "$output" | grep -qiE "(the compiler unexpectedly panicked|panicked at|Internal Compiler Error|ICE|error: the compiler unexpectedly panicked)"; then + echo "❌ rustfmt panicked (ICE detected) - this should fail the build" + echo "$output" + exit 1 + fi + echo "$output" + echo "✅ cargo fmt completed successfully" cargo-clippy-default-features: name: cargo clippy From a60b5e62f94d8e64dae30ff77dfa748d831e9f01 Mon Sep 17 00:00:00 2001 From: Loris Moulin Date: Tue, 16 Dec 2025 14:57:29 +0100 Subject: [PATCH 16/16] use stable cargo fmt --- .github/workflows/check-rust.yml | 4 ++-- scripts/fix_rust.sh | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/check-rust.yml b/.github/workflows/check-rust.yml index 2ca0ae6c5c..4b975959d0 100644 --- a/.github/workflows/check-rust.yml +++ b/.github/workflows/check-rust.yml @@ -38,7 +38,7 @@ jobs: - name: Install Rust Nightly uses: actions-rs/toolchain@v1 with: - toolchain: nightly + toolchain: stable components: rustfmt - name: Utilize Shared Rust Cache @@ -51,7 +51,7 @@ jobs: run: | set -euo pipefail # Run cargo fmt and capture both stdout and stderr - output=$(cargo +nightly fmt --check --all 2>&1) || { + output=$(cargo fmt --check --all 2>&1) || { echo "❌ cargo fmt failed with non-zero exit code" echo "$output" exit 1 diff --git a/scripts/fix_rust.sh b/scripts/fix_rust.sh index 4824c7d53e..08e983a432 100755 --- a/scripts/fix_rust.sh +++ b/scripts/fix_rust.sh @@ -24,7 +24,7 @@ cargo fix --workspace --all-features --all-targets commit_if_changes "cargo fix" # Step 4: Run cargo fmt and commit changes if any. -cargo +nightly fmt --all +cargo fmt --all commit_if_changes "cargo fmt" if command -v zepter >/dev/null 2>&1; then