Skip to content

Commit 7b027b7

Browse files
authored
Merge pull request #2244 from opentensor/fix-cargo-audit
Fix cargo audit
2 parents 675111c + a60b5e6 commit 7b027b7

File tree

26 files changed

+174
-162
lines changed

26 files changed

+174
-162
lines changed

.github/workflows/cargo-audit.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,6 @@ jobs:
4646
cargo audit --ignore RUSTSEC-2023-0091 \
4747
--ignore RUSTSEC-2024-0438 \
4848
--ignore RUSTSEC-2025-0009 \
49-
--ignore RUSTSEC-2025-0055
49+
--ignore RUSTSEC-2025-0055 \
50+
--ignore RUSTSEC-2025-0073 \
51+
--ignore RUSTSEC-2025-0118

.github/workflows/check-rust.yml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
- name: Install Rust Nightly
3939
uses: actions-rs/toolchain@v1
4040
with:
41-
toolchain: nightly
41+
toolchain: stable
4242
components: rustfmt
4343

4444
- name: Utilize Shared Rust Cache
@@ -48,7 +48,22 @@ jobs:
4848
cache-on-failure: true
4949

5050
- name: cargo fmt
51-
run: cargo +nightly fmt --check --all
51+
run: |
52+
set -euo pipefail
53+
# Run cargo fmt and capture both stdout and stderr
54+
output=$(cargo fmt --check --all 2>&1) || {
55+
echo "❌ cargo fmt failed with non-zero exit code"
56+
echo "$output"
57+
exit 1
58+
}
59+
# Check for panic/ICE messages even if exit code was 0
60+
if echo "$output" | grep -qiE "(the compiler unexpectedly panicked|panicked at|Internal Compiler Error|ICE|error: the compiler unexpectedly panicked)"; then
61+
echo "❌ rustfmt panicked (ICE detected) - this should fail the build"
62+
echo "$output"
63+
exit 1
64+
fi
65+
echo "$output"
66+
echo "✅ cargo fmt completed successfully"
5267
5368
cargo-clippy-default-features:
5469
name: cargo clippy

chain-extensions/src/tests.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -757,12 +757,12 @@ impl SubtensorExtensionEnv<AccountId> for MockEnv {
757757
}
758758

759759
fn charge_weight(&mut self, weight: Weight) -> Result<(), DispatchError> {
760-
if let Some(expected) = self.expected_weight {
761-
if weight != expected {
762-
return Err(DispatchError::Other(
763-
"unexpected weight charged by mock env",
764-
));
765-
}
760+
if let Some(expected) = self.expected_weight
761+
&& weight != expected
762+
{
763+
return Err(DispatchError::Other(
764+
"unexpected weight charged by mock env",
765+
));
766766
}
767767
self.charged_weight = Some(weight);
768768
Ok(())

node/src/command.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ fn start_babe_service(arg_matches: &ArgMatches) -> Result<(), sc_cli::Error> {
272272
{
273273
log::info!("Failed to aquire DB lock, trying again in 1s...");
274274
std::thread::sleep(std::time::Duration::from_secs(1));
275-
return start_babe_service(arg_matches);
275+
start_babe_service(arg_matches)
276276
// Unknown error, return it.
277277
} else {
278278
log::error!("Failed to start Babe service: {e:?}");

node/src/consensus/aura_consensus.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ impl ConsensusMechanism for AuraConsensus {
120120
Self {}
121121
}
122122

123-
fn build_biq(&mut self) -> Result<BIQ, sc_service::Error>
123+
fn build_biq(&mut self) -> Result<BIQ<'_>, sc_service::Error>
124124
where
125125
NumberFor<Block>: BlockNumberOps,
126126
{

node/src/consensus/babe_consensus.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ impl ConsensusMechanism for BabeConsensus {
128128
}
129129
}
130130

131-
fn build_biq(&mut self) -> Result<BIQ, sc_service::Error>
131+
fn build_biq(&mut self) -> Result<BIQ<'_>, sc_service::Error>
132132
where
133133
NumberFor<Block>: BlockNumberOps,
134134
{

node/src/consensus/consensus_mechanism.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ pub trait ConsensusMechanism {
7777
fn new() -> Self;
7878

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

8282
/// Returns the slot duration.
8383
fn slot_duration(&self, client: &FullClient) -> Result<SlotDuration, ServiceError>;

pallets/subtensor/src/coinbase/block_step.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,9 @@ impl<T: Config + pallet_drand::Config> Pallet<T> {
229229
if next_value >= U110F18::saturating_from_num(Self::get_max_difficulty(netuid)) {
230230
Self::get_max_difficulty(netuid)
231231
} else if next_value <= U110F18::saturating_from_num(Self::get_min_difficulty(netuid)) {
232-
return Self::get_min_difficulty(netuid);
232+
Self::get_min_difficulty(netuid)
233233
} else {
234-
return next_value.saturating_to_num::<u64>();
234+
next_value.saturating_to_num::<u64>()
235235
}
236236
}
237237

@@ -263,9 +263,9 @@ impl<T: Config + pallet_drand::Config> Pallet<T> {
263263
if next_value >= U110F18::saturating_from_num(Self::get_max_burn(netuid)) {
264264
Self::get_max_burn(netuid)
265265
} else if next_value <= U110F18::saturating_from_num(Self::get_min_burn(netuid)) {
266-
return Self::get_min_burn(netuid);
266+
Self::get_min_burn(netuid)
267267
} else {
268-
return next_value.saturating_to_num::<u64>().into();
268+
next_value.saturating_to_num::<u64>().into()
269269
}
270270
}
271271

pallets/subtensor/src/coinbase/run_coinbase.rs

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -491,10 +491,11 @@ impl<T: Config> Pallet<T> {
491491

492492
// Insert subnet owner hotkey in the beginning of the list if valid and not
493493
// already present
494-
if let Ok(owner_hk) = SubnetOwnerHotkey::<T>::try_get(netuid) {
495-
if Uids::<T>::get(netuid, &owner_hk).is_some() && !owner_hotkeys.contains(&owner_hk) {
496-
owner_hotkeys.insert(0, owner_hk);
497-
}
494+
if let Ok(owner_hk) = SubnetOwnerHotkey::<T>::try_get(netuid)
495+
&& Uids::<T>::get(netuid, &owner_hk).is_some()
496+
&& !owner_hotkeys.contains(&owner_hk)
497+
{
498+
owner_hotkeys.insert(0, owner_hk);
498499
}
499500

500501
owner_hotkeys
@@ -508,22 +509,22 @@ impl<T: Config> Pallet<T> {
508509
root_alpha_dividends: BTreeMap<T::AccountId, U96F32>,
509510
) {
510511
// Distribute the owner cut.
511-
if let Ok(owner_coldkey) = SubnetOwner::<T>::try_get(netuid) {
512-
if let Ok(owner_hotkey) = SubnetOwnerHotkey::<T>::try_get(netuid) {
513-
// Increase stake for owner hotkey and coldkey.
514-
log::debug!(
515-
"owner_hotkey: {owner_hotkey:?} owner_coldkey: {owner_coldkey:?}, owner_cut: {owner_cut:?}"
516-
);
517-
let real_owner_cut = Self::increase_stake_for_hotkey_and_coldkey_on_subnet(
518-
&owner_hotkey,
519-
&owner_coldkey,
520-
netuid,
521-
owner_cut,
522-
);
523-
// If the subnet is leased, notify the lease logic that owner cut has been distributed.
524-
if let Some(lease_id) = SubnetUidToLeaseId::<T>::get(netuid) {
525-
Self::distribute_leased_network_dividends(lease_id, real_owner_cut);
526-
}
512+
if let Ok(owner_coldkey) = SubnetOwner::<T>::try_get(netuid)
513+
&& let Ok(owner_hotkey) = SubnetOwnerHotkey::<T>::try_get(netuid)
514+
{
515+
// Increase stake for owner hotkey and coldkey.
516+
log::debug!(
517+
"owner_hotkey: {owner_hotkey:?} owner_coldkey: {owner_coldkey:?}, owner_cut: {owner_cut:?}"
518+
);
519+
let real_owner_cut = Self::increase_stake_for_hotkey_and_coldkey_on_subnet(
520+
&owner_hotkey,
521+
&owner_coldkey,
522+
netuid,
523+
owner_cut,
524+
);
525+
// If the subnet is leased, notify the lease logic that owner cut has been distributed.
526+
if let Some(lease_id) = SubnetUidToLeaseId::<T>::get(netuid) {
527+
Self::distribute_leased_network_dividends(lease_id, real_owner_cut);
527528
}
528529
}
529530

pallets/subtensor/src/epoch/math.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -335,10 +335,10 @@ pub fn inplace_row_normalize_sparse(sparse_matrix: &mut [Vec<(u16, I32F32)>]) {
335335

336336
// Sum across each row (dim=0) of a matrix.
337337
pub fn row_sum(x: &[Vec<I32F32>]) -> Vec<I32F32> {
338-
if let Some(first_row) = x.first() {
339-
if first_row.is_empty() {
340-
return vec![];
341-
}
338+
if let Some(first_row) = x.first()
339+
&& first_row.is_empty()
340+
{
341+
return vec![];
342342
}
343343
x.iter().map(|row| row.iter().sum()).collect()
344344
}
@@ -424,10 +424,10 @@ pub fn inplace_col_max_upscale_sparse(sparse_matrix: &mut [Vec<(u16, I32F32)>],
424424
// Pass 1: compute per-column max
425425
for sparse_row in sparse_matrix.iter() {
426426
for (j, value) in sparse_row.iter() {
427-
if let Some(m) = col_max.get_mut(*j as usize) {
428-
if *m < *value {
429-
*m = *value;
430-
}
427+
if let Some(m) = col_max.get_mut(*j as usize)
428+
&& *m < *value
429+
{
430+
*m = *value;
431431
}
432432
}
433433
}
@@ -1147,10 +1147,10 @@ pub fn weighted_median_col_sparse(
11471147
while let (Some(&s), Some(sparse_row)) = (stake_it.next(), score_it.next()) {
11481148
if s > zero {
11491149
for &(c, val) in sparse_row.iter() {
1150-
if let Some(col_vec) = use_score.get_mut(c as usize) {
1151-
if let Some(cell) = col_vec.get_mut(k) {
1152-
*cell = val;
1153-
}
1150+
if let Some(col_vec) = use_score.get_mut(c as usize)
1151+
&& let Some(cell) = col_vec.get_mut(k)
1152+
{
1153+
*cell = val;
11541154
}
11551155
}
11561156
k = k.saturating_add(1);
@@ -1289,10 +1289,10 @@ pub fn interpolate_sparse(
12891289
let v1 = row1.get(j).unwrap_or(&zero);
12901290
let v2 = row2.get(j).unwrap_or(&zero);
12911291
let interp = v1.saturating_add(ratio.saturating_mul(v2.saturating_sub(*v1)));
1292-
if zero < interp {
1293-
if let Some(res) = result.get_mut(i) {
1294-
res.push((j as u16, interp));
1295-
}
1292+
if zero < interp
1293+
&& let Some(res) = result.get_mut(i)
1294+
{
1295+
res.push((j as u16, interp));
12961296
}
12971297
}
12981298
}
@@ -1338,10 +1338,10 @@ pub fn mat_vec_mul_sparse(
13381338
for (j, value) in matrix_row.iter() {
13391339
if let Some(vector_value) = vector.get(*j as usize) {
13401340
let new_value = value.saturating_mul(*vector_value);
1341-
if new_value != I32F32::saturating_from_num(0.0) {
1342-
if let Some(result_row) = result.get_mut(i) {
1343-
result_row.push((*j, new_value));
1344-
}
1341+
if new_value != I32F32::saturating_from_num(0.0)
1342+
&& let Some(result_row) = result.get_mut(i)
1343+
{
1344+
result_row.push((*j, new_value));
13451345
}
13461346
}
13471347
}

0 commit comments

Comments
 (0)