Skip to content

Commit cc06539

Browse files
committed
refactor: remove panic
1 parent e05c98b commit cc06539

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

pallets/subtensor/src/migration.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,25 @@ pub fn migration5_total_issuance<T: Config>(test: bool) -> Weight {
5151

5252
// Retrieve the total balance sum
5353
let total_balance = T::Currency::total_issuance();
54-
let total_balance_sum: u64 = total_balance
55-
.try_into()
56-
.unwrap_or_else(|_| panic!("Conversion must be within range"));
57-
weight = weight.saturating_add(T::DbWeight::get().reads(1));
54+
match TryInto::<u64>::try_into(total_balance) {
55+
Ok(total_balance_sum) => {
56+
weight = weight.saturating_add(T::DbWeight::get().reads(1));
5857

59-
// Compute the total issuance value
60-
let total_issuance_value: u64 = stake_sum + total_balance_sum + locked_sum;
58+
// Compute the total issuance value
59+
let total_issuance_value: u64 = stake_sum + total_balance_sum + locked_sum;
6160

62-
// Update the total issuance in storage
63-
TotalIssuance::<T>::put(total_issuance_value);
64-
}
61+
// Update the total issuance in storage
62+
TotalIssuance::<T>::put(total_issuance_value);
6563

66-
// Update the storage version to 6
67-
StorageVersion::new(6).put::<Pallet<T>>();
68-
weight = weight.saturating_add(T::DbWeight::get().writes(1));
64+
// Update the storage version to 6
65+
StorageVersion::new(6).put::<Pallet<T>>();
66+
weight = weight.saturating_add(T::DbWeight::get().writes(1));
67+
}
68+
Err(_) => {
69+
log::error!("Failed to convert total balance to u64, bailing");
70+
}
71+
}
72+
}
6973

7074
weight // Return the computed weight of the migration process
7175
}

0 commit comments

Comments
 (0)