Skip to content
Snippets Groups Projects

Fix #219 and #220

Merged Benjamin Gallois requested to merge 220-fix-smith-members-events into master
1 file
+ 22
30
Compare changes
  • Side-by-side
  • Inline
+ 22
30
@@ -542,39 +542,23 @@ pub mod pallet {
> = Pallet::<T>::take_current_pool(index);
for (idty, median_acc) in current_pool.evaluations.into_iter() {
// distance result
let mut distance_result: Option<bool> = None;
let mut distance = Perbill::zero();
// get result of the computation
let mut distance_result: Option<Perbill> = None;
// Retrieve the result of the computation from the median accumulator
if let Some(median_result) = median_acc.get_median() {
distance = match median_result {
let distance = match median_result {
MedianResult::One(m) => m,
MedianResult::Two(m1, m2) => m1 + (m2 - m1) / 2, // Avoid overflow (since max is 1)
};
// update distance result
distance_result = Some(distance >= T::MinAccessibleReferees::get());
// Update distance result
distance_result = Some(distance);
}
// take requester and perform unreserve or slash
// If there's a pending evaluation request with the provided identity
if let Some(requester) = PendingEvaluationRequest::<T>::take(idty) {
match distance_result {
None => {
// no result, unreserve
T::Currency::unreserve(
&requester,
<T as Config>::EvaluationPrice::get(),
);
weight = weight.saturating_add(
<T as pallet::Config>::WeightInfo::do_evaluation_failure()
.saturating_sub(
<T as pallet::Config>::WeightInfo::do_evaluation_overhead(),
),
);
}
Some(true) => {
// positive result, unreserve and apply
// If distance_result is available
if let Some(distance) = distance_result {
if distance >= T::MinAccessibleReferees::get() {
// Positive result, unreserve and apply
T::Currency::unreserve(
&requester,
<T as Config>::EvaluationPrice::get(),
@@ -586,9 +570,8 @@ pub mod pallet {
<T as pallet::Config>::WeightInfo::do_evaluation_overhead(),
),
);
}
Some(false) => {
// negative result, slash and deposit event
} else {
// Negative result, slash and deposit event
let _ = T::Currency::slash_reserved(
&requester,
<T as Config>::EvaluationPrice::get(),
@@ -604,9 +587,18 @@ pub mod pallet {
),
);
}
} else {
// No result, unreserve
T::Currency::unreserve(&requester, <T as Config>::EvaluationPrice::get());
weight = weight.saturating_add(
<T as pallet::Config>::WeightInfo::do_evaluation_failure()
.saturating_sub(
<T as pallet::Config>::WeightInfo::do_evaluation_overhead(),
),
);
}
}
// if evaluation happened without request, it's ok to do nothing
// If evaluation happened without request, it's ok to do nothing
}
weight
}
Loading