Skip to content

Commit c4246dc

Browse files
committed
prevent division by zero
1 parent 4a3156e commit c4246dc

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

pallets/subtensor/src/weights.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,10 @@ impl<T: Config> Pallet<T> {
426426
pub fn can_commit(netuid: u16, who: &T::AccountId) -> bool {
427427
if let Some((_hash, commit_block)) = WeightCommits::<T>::get(netuid, who) {
428428
let interval: u64 = Self::get_weight_commit_interval();
429+
if interval == 0 {
430+
return true; //prevent division by 0
431+
}
432+
429433
let current_block: u64 = Self::get_current_block_as_u64();
430434
let interval_start: u64 = current_block - (current_block % interval);
431435
let last_commit_interval_start: u64 = commit_block - (commit_block % interval);
@@ -445,6 +449,10 @@ impl<T: Config> Pallet<T> {
445449

446450
pub fn is_reveal_block_range(commit_block: u64) -> bool {
447451
let interval: u64 = Self::get_weight_commit_interval();
452+
if interval == 0 {
453+
return true; //prevent division by 0
454+
}
455+
448456
let commit_interval_start: u64 = commit_block - (commit_block % interval); // Find the start of the interval in which the commit occurred
449457
let reveal_interval_start: u64 = commit_interval_start + interval; // Start of the next interval after the commit interval
450458
let current_block: u64 = Self::get_current_block_as_u64();

0 commit comments

Comments
 (0)