Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/cargo-audit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:?}");
Expand Down
2 changes: 1 addition & 1 deletion node/src/consensus/aura_consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ impl ConsensusMechanism for AuraConsensus {
Self {}
}

fn build_biq(&mut self) -> Result<BIQ, sc_service::Error>
fn build_biq(&mut self) -> Result<BIQ<'_>, sc_service::Error>
where
NumberFor<Block>: BlockNumberOps,
{
Expand Down
2 changes: 1 addition & 1 deletion node/src/consensus/babe_consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ impl ConsensusMechanism for BabeConsensus {
}
}

fn build_biq(&mut self) -> Result<BIQ, sc_service::Error>
fn build_biq(&mut self) -> Result<BIQ<'_>, sc_service::Error>
where
NumberFor<Block>: BlockNumberOps,
{
Expand Down
2 changes: 1 addition & 1 deletion node/src/consensus/consensus_mechanism.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pub trait ConsensusMechanism {
fn new() -> Self;

/// Builds a `BIQ` that uses the ConsensusMechanism.
fn build_biq(&mut self) -> Result<BIQ, sc_service::Error>;
fn build_biq(&mut self) -> Result<BIQ<'_>, sc_service::Error>;

/// Returns the slot duration.
fn slot_duration(&self, client: &FullClient) -> Result<SlotDuration, ServiceError>;
Expand Down
8 changes: 4 additions & 4 deletions pallets/subtensor/src/coinbase/block_step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,9 @@ impl<T: Config + pallet_drand::Config> Pallet<T> {
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::<u64>();
next_value.saturating_to_num::<u64>()
}
}

Expand Down Expand Up @@ -261,9 +261,9 @@ impl<T: Config + pallet_drand::Config> Pallet<T> {
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::<u64>().into();
next_value.saturating_to_num::<u64>().into()
}
}

Expand Down
41 changes: 21 additions & 20 deletions pallets/subtensor/src/coinbase/run_coinbase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,10 +498,11 @@ impl<T: Config> Pallet<T> {

// Insert subnet owner hotkey in the beginning of the list if valid and not
// already present
if let Ok(owner_hk) = SubnetOwnerHotkey::<T>::try_get(netuid) {
if Uids::<T>::get(netuid, &owner_hk).is_some() && !owner_hotkeys.contains(&owner_hk) {
owner_hotkeys.insert(0, owner_hk);
}
if let Ok(owner_hk) = SubnetOwnerHotkey::<T>::try_get(netuid)
&& Uids::<T>::get(netuid, &owner_hk).is_some()
&& !owner_hotkeys.contains(&owner_hk)
{
owner_hotkeys.insert(0, owner_hk);
}

owner_hotkeys
Expand All @@ -515,22 +516,22 @@ impl<T: Config> Pallet<T> {
root_alpha_dividends: BTreeMap<T::AccountId, U96F32>,
) {
// Distribute the owner cut.
if let Ok(owner_coldkey) = SubnetOwner::<T>::try_get(netuid) {
if let Ok(owner_hotkey) = SubnetOwnerHotkey::<T>::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::<T>::get(netuid) {
Self::distribute_leased_network_dividends(lease_id, real_owner_cut);
}
if let Ok(owner_coldkey) = SubnetOwner::<T>::try_get(netuid)
&& let Ok(owner_hotkey) = SubnetOwnerHotkey::<T>::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::<T>::get(netuid) {
Self::distribute_leased_network_dividends(lease_id, real_owner_cut);
}
}

Expand Down
40 changes: 20 additions & 20 deletions pallets/subtensor/src/epoch/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +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<I32F32>]) -> Vec<I32F32> {
if let Some(first_row) = x.first() {
if first_row.is_empty() {
return vec![];
}
if let Some(first_row) = x.first()
&& first_row.is_empty()
{
return vec![];
}
x.iter().map(|row| row.iter().sum()).collect()
}
Expand Down Expand Up @@ -424,10 +424,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 {
*m = *value;
}
if let Some(m) = col_max.get_mut(*j as usize)
&& *m < *value
{
*m = *value;
}
}
}
Expand Down Expand Up @@ -1147,10 +1147,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) {
*cell = val;
}
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);
Expand Down Expand Up @@ -1289,10 +1289,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) {
res.push((j as u16, interp));
}
if zero < interp
&& let Some(res) = result.get_mut(i)
{
res.push((j as u16, interp));
}
}
}
Expand Down Expand Up @@ -1338,10 +1338,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) {
result_row.push((*j, new_value));
}
if new_value != I32F32::saturating_from_num(0.0)
&& let Some(result_row) = result.get_mut(i)
{
result_row.push((*j, new_value));
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions pallets/subtensor/src/epoch/run_epoch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -761,10 +761,10 @@ impl<T: Config> Pallet<T> {
// ---------- v3 ------------------------------------------------------
for (_epoch, q) in TimelockedWeightCommits::<T>::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)) {
*cell = (*cell).min(*cb);
}
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);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions pallets/subtensor/src/macros/dispatches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ mod dispatches {
///
/// * 'weights' (Vec<u16>):
/// - 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.
Expand Down Expand Up @@ -128,7 +128,7 @@ mod dispatches {
///
/// * 'weights' (Vec<u16>):
/// - 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.
Expand Down
17 changes: 8 additions & 9 deletions pallets/subtensor/src/staking/stake_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -562,11 +562,10 @@ impl<T: Config> Pallet<T> {

// 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 {
actual_alpha =
alpha_share_pool.update_value_for_one(coldkey, (amount as i64).neg());
}
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.
Expand Down Expand Up @@ -1200,10 +1199,10 @@ impl<T: Config> Pallet<T> {

// 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 {
ensure!(alpha_amount <= max_amount, Error::<T>::SlippageTooHigh);
}
if let Some(allow_partial) = maybe_allow_partial
&& !allow_partial
{
ensure!(alpha_amount <= max_amount, Error::<T>::SlippageTooHigh);
}
}

Expand Down
23 changes: 11 additions & 12 deletions pallets/subtensor/src/subnets/registration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,14 +425,13 @@ impl<T: Config> Pallet<T> {

// Insert subnet owner hotkey in the beginning of the list if valid and not
// already present
if let Ok(owner_hk) = SubnetOwnerHotkey::<T>::try_get(netuid) {
if let Some(owner_uid) = Uids::<T>::get(netuid, &owner_hk) {
if !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);
}
}
if let Ok(owner_hk) = SubnetOwnerHotkey::<T>::try_get(netuid)
&& let Some(owner_uid) = Uids::<T>::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);
}
}

Expand Down Expand Up @@ -467,10 +466,10 @@ impl<T: Config> Pallet<T> {
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) {
continue;
}
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);
Expand Down
8 changes: 4 additions & 4 deletions pallets/subtensor/src/subnets/serving.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ impl<T: Config> Pallet<T> {
)?;

// Check+insert certificate
if let Some(certificate) = certificate {
if let Ok(certificate) = NeuronCertificateOf::try_from(certificate) {
NeuronCertificates::<T>::insert(netuid, hotkey_id.clone(), certificate)
}
if let Some(certificate) = certificate
&& let Ok(certificate) = NeuronCertificateOf::try_from(certificate)
{
NeuronCertificates::<T>::insert(netuid, hotkey_id.clone(), certificate)
}

// We insert the axon meta.
Expand Down
14 changes: 7 additions & 7 deletions pallets/subtensor/src/subnets/uids.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ impl<T: Config> Pallet<T> {
let old_hotkey: T::AccountId = Keys::<T>::get(netuid, uid_to_replace);

// Do not replace owner hotkey from `SubnetOwnerHotkey`
if let Ok(sn_owner_hotkey) = SubnetOwnerHotkey::<T>::try_get(netuid) {
if sn_owner_hotkey == old_hotkey.clone() {
log::warn!(
"replace_neuron: Skipped replacement because neuron is the subnet owner hotkey. \
if let Ok(sn_owner_hotkey) = SubnetOwnerHotkey::<T>::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;
}
);
return;
}

// 2. Remove previous set memberships.
Expand Down
20 changes: 10 additions & 10 deletions pallets/subtensor/src/subnets/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1109,16 +1109,16 @@ impl<T: Config> Pallet<T> {
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) {
// --- 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);
}
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);
}

// --- 3. Non registered peers cant pass. Neither can non-existing mecid
Expand Down
Loading
Loading