Skip to content
Snippets Groups Projects
Unverified Commit 4b282522 authored by bgallois's avatar bgallois
Browse files

fix #219

parent 656963a0
No related branches found
No related tags found
No related merge requests found
Pipeline #36561 failed
...@@ -172,9 +172,15 @@ pub mod pallet { ...@@ -172,9 +172,15 @@ pub mod pallet {
who: T::AccountId, who: T::AccountId,
}, },
/// Distance rule was found valid. /// Distance rule was found valid.
EvaluatedValid { idty_index: T::IdtyIndex }, EvaluatedValid {
idty_index: T::IdtyIndex,
distance: Perbill,
},
/// Distance rule was found invalid. /// Distance rule was found invalid.
EvaluatedInvalid { idty_index: T::IdtyIndex }, EvaluatedInvalid {
idty_index: T::IdtyIndex,
distance: Perbill,
},
} }
// ERRORS // // ERRORS //
...@@ -313,7 +319,7 @@ pub mod pallet { ...@@ -313,7 +319,7 @@ pub mod pallet {
) -> DispatchResult { ) -> DispatchResult {
ensure_root(origin)?; ensure_root(origin)?;
Self::do_valid_distance_status(identity); Self::do_valid_distance_status(identity, Perbill::one());
Ok(()) Ok(())
} }
} }
...@@ -509,11 +515,17 @@ pub mod pallet { ...@@ -509,11 +515,17 @@ pub mod pallet {
} }
/// Set the distance status using IdtyIndex and AccountId /// Set the distance status using IdtyIndex and AccountId
pub fn do_valid_distance_status(idty: <T as pallet_identity::Config>::IdtyIndex) { pub fn do_valid_distance_status(
idty: <T as pallet_identity::Config>::IdtyIndex,
distance: Perbill,
) {
// callback // callback
T::OnValidDistanceStatus::on_valid_distance_status(idty); T::OnValidDistanceStatus::on_valid_distance_status(idty);
// deposit event // deposit event
Self::deposit_event(Event::EvaluatedValid { idty_index: idty }); Self::deposit_event(Event::EvaluatedValid {
idty_index: idty,
distance: distance,
});
} }
pub fn do_evaluation(index: u32) -> Weight { pub fn do_evaluation(index: u32) -> Weight {
...@@ -532,15 +544,16 @@ pub mod pallet { ...@@ -532,15 +544,16 @@ pub mod pallet {
for (idty, median_acc) in current_pool.evaluations.into_iter() { for (idty, median_acc) in current_pool.evaluations.into_iter() {
// distance result // distance result
let mut distance_result: Option<bool> = None; let mut distance_result: Option<bool> = None;
let mut distance = Perbill::zero();
// get result of the computation // get result of the computation
if let Some(median_result) = median_acc.get_median() { if let Some(median_result) = median_acc.get_median() {
let median = match median_result { distance = match median_result {
MedianResult::One(m) => m, MedianResult::One(m) => m,
MedianResult::Two(m1, m2) => m1 + (m2 - m1) / 2, // Avoid overflow (since max is 1) MedianResult::Two(m1, m2) => m1 + (m2 - m1) / 2, // Avoid overflow (since max is 1)
}; };
// update distance result // update distance result
distance_result = Some(median >= T::MinAccessibleReferees::get()); distance_result = Some(distance >= T::MinAccessibleReferees::get());
} }
// take requester and perform unreserve or slash // take requester and perform unreserve or slash
...@@ -566,7 +579,7 @@ pub mod pallet { ...@@ -566,7 +579,7 @@ pub mod pallet {
&requester, &requester,
<T as Config>::EvaluationPrice::get(), <T as Config>::EvaluationPrice::get(),
); );
Self::do_valid_distance_status(idty); Self::do_valid_distance_status(idty, distance);
weight = weight.saturating_add( weight = weight.saturating_add(
<T as pallet::Config>::WeightInfo::do_evaluation_success() <T as pallet::Config>::WeightInfo::do_evaluation_success()
.saturating_sub( .saturating_sub(
...@@ -580,7 +593,10 @@ pub mod pallet { ...@@ -580,7 +593,10 @@ pub mod pallet {
&requester, &requester,
<T as Config>::EvaluationPrice::get(), <T as Config>::EvaluationPrice::get(),
); );
Self::deposit_event(Event::EvaluatedInvalid { idty_index: idty }); Self::deposit_event(Event::EvaluatedInvalid {
idty_index: idty,
distance,
});
weight = weight.saturating_add( weight = weight.saturating_add(
<T as pallet::Config>::WeightInfo::do_evaluation_failure() <T as pallet::Config>::WeightInfo::do_evaluation_failure()
.saturating_sub( .saturating_sub(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment