Skip to content

Commit

Permalink
apply review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Chralt98 committed Mar 26, 2024
1 parent 141adb3 commit 3a9520a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions zrml/court/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ rand_chacha = { workspace = true }
scale-info = { workspace = true, features = ["derive"] }
sp-arithmetic = { workspace = true }
sp-runtime = { workspace = true }
zeitgeist-macros = { workspace = true }
zeitgeist-primitives = { workspace = true }
zrml-market-commons = { workspace = true }

Expand Down
19 changes: 9 additions & 10 deletions zrml/court/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ use sp_runtime::{
traits::{AccountIdConversion, CheckedDiv, Hash, Saturating, StaticLookup, Zero},
DispatchError, Perbill, SaturatedConversion,
};
use zeitgeist_macros::unreachable_non_terminating;
use zeitgeist_primitives::{
math::checked_ops_res::{CheckedAddRes, CheckedRemRes, CheckedSubRes},
traits::{DisputeApi, DisputeMaxWeightApi, DisputeResolutionApi},
Expand Down Expand Up @@ -1202,13 +1203,10 @@ mod pallet {
};

if current_period_index != pool_item.uneligible_index {
let uneligible_stake = amount.checked_sub_res(&pool_item.stake)?;
Ok(uneligible_stake)
amount.checked_sub_res(&pool_item.stake)
} else {
let additional_uneligible_stake = amount.checked_sub_res(&pool_item.stake)?;
let uneligible_stake =
pool_item.uneligible_stake.checked_add_res(&additional_uneligible_stake)?;
Ok(uneligible_stake)
pool_item.uneligible_stake.checked_add_res(&additional_uneligible_stake)
}
}

Expand All @@ -1227,10 +1225,7 @@ mod pallet {
p: &CourtPoolOf<T>,
lowest_stake: BalanceOf<T>,
) -> bool {
let mut sorted = p.clone();
sorted.sort_by_key(|pool_item| (pool_item.stake, pool_item.court_participant.clone()));
p.len() == sorted.len()
&& p.iter().zip(sorted.iter()).all(|(a, b)| lowest_stake <= a.stake && a == b)
p.windows(2).all(|w| w[0].stake <= w[1].stake && lowest_stake <= w[0].stake)
}

fn remove_weakest_if_full(
Expand All @@ -1242,7 +1237,11 @@ mod pallet {
let lowest_stake = lowest_item
.map(|pool_item| pool_item.stake)
.unwrap_or_else(<BalanceOf<T>>::zero);
debug_assert!(Self::is_sorted_and_all_greater_than_lowest(&p, lowest_stake));
unreachable_non_terminating!(
Self::is_sorted_and_all_greater_than_lowest(&p, lowest_stake),
LOG_TARGET,
"Pool is not sorted or not all stakes are greater than the lowest stake.",

This comment has been minimized.

Copy link
@sea212

sea212 Mar 27, 2024

Member

I think it would be good to know what pool is causing the issue, would significantly reduce the debugging effort.

);
ensure!(amount > lowest_stake, Error::<T>::AmountBelowLowestJuror);
p.remove(0);
}
Expand Down

0 comments on commit 3a9520a

Please sign in to comment.