diff --git a/pallets/distance/src/benchmarking.rs b/pallets/distance/src/benchmarking.rs index 7b8d7c85045df01eb3011c23135965bdb32cb60b..cf11d85e33cc670cd7569a9c146849054010170c 100644 --- a/pallets/distance/src/benchmarking.rs +++ b/pallets/distance/src/benchmarking.rs @@ -163,7 +163,13 @@ mod benchmarks { #[extrinsic_call] _(RawOrigin::Root, idty); - assert_has_event::<T>(Event::<T>::EvaluatedValid { idty_index: idty }.into()); + assert_has_event::<T>( + Event::<T>::EvaluatedValid { + idty_index: idty, + distance: Perbill::one(), + } + .into(), + ); } #[benchmark] @@ -211,7 +217,13 @@ mod benchmarks { Pallet::<T>::do_evaluation(0); } - assert_has_event::<T>(Event::<T>::EvaluatedValid { idty_index: idty }.into()); + assert_has_event::<T>( + Event::<T>::EvaluatedValid { + idty_index: idty, + distance: Perbill::one(), + } + .into(), + ); Ok(()) } @@ -249,7 +261,13 @@ mod benchmarks { Pallet::<T>::do_evaluation(0); } - assert_has_event::<T>(Event::<T>::EvaluatedInvalid { idty_index: idty }.into()); + assert_has_event::<T>( + Event::<T>::EvaluatedInvalid { + idty_index: idty, + distance: Perbill::zero(), + } + .into(), + ); Ok(()) } diff --git a/pallets/distance/src/lib.rs b/pallets/distance/src/lib.rs index f42651850489f2c1e23ce28aa477f8660073a61d..76d580b2d2913510698b1c60591fa1aa495da2e1 100644 --- a/pallets/distance/src/lib.rs +++ b/pallets/distance/src/lib.rs @@ -172,9 +172,15 @@ pub mod pallet { who: T::AccountId, }, /// Distance rule was found valid. - EvaluatedValid { idty_index: T::IdtyIndex }, + EvaluatedValid { + idty_index: T::IdtyIndex, + distance: Perbill, + }, /// Distance rule was found invalid. - EvaluatedInvalid { idty_index: T::IdtyIndex }, + EvaluatedInvalid { + idty_index: T::IdtyIndex, + distance: Perbill, + }, } // ERRORS // @@ -313,7 +319,7 @@ pub mod pallet { ) -> DispatchResult { ensure_root(origin)?; - Self::do_valid_distance_status(identity); + Self::do_valid_distance_status(identity, Perbill::one()); Ok(()) } } @@ -509,11 +515,17 @@ pub mod pallet { } /// 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 T::OnValidDistanceStatus::on_valid_distance_status(idty); // deposit event - Self::deposit_event(Event::EvaluatedValid { idty_index: idty }); + Self::deposit_event(Event::EvaluatedValid { + idty_index: idty, + distance, + }); } pub fn do_evaluation(index: u32) -> Weight { @@ -530,57 +542,44 @@ 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; - - // 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() { - let median = 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(median >= 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(), ); - Self::do_valid_distance_status(idty); + Self::do_valid_distance_status(idty, distance); weight = weight.saturating_add( <T as pallet::Config>::WeightInfo::do_evaluation_success() .saturating_sub( <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(), ); - Self::deposit_event(Event::EvaluatedInvalid { idty_index: idty }); + Self::deposit_event(Event::EvaluatedInvalid { + idty_index: idty, + distance, + }); weight = weight.saturating_add( <T as pallet::Config>::WeightInfo::do_evaluation_failure() .saturating_sub( @@ -588,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 } diff --git a/pallets/smith-members/src/lib.rs b/pallets/smith-members/src/lib.rs index b62b99ccc748fcfe38a542708dbccad3d558110e..9b33a6b561e7a910dfa39996e08e175baf602e6c 100644 --- a/pallets/smith-members/src/lib.rs +++ b/pallets/smith-members/src/lib.rs @@ -133,20 +133,20 @@ pub mod pallet { pub enum Event<T: Config> { /// An identity is being inivited to become a smith. InvitationSent { - receiver: T::IdtyIndex, issuer: T::IdtyIndex, + receiver: T::IdtyIndex, }, /// The invitation has been accepted. InvitationAccepted { idty_index: T::IdtyIndex }, /// Certification received SmithCertAdded { - receiver: T::IdtyIndex, issuer: T::IdtyIndex, + receiver: T::IdtyIndex, }, /// Certification lost SmithCertRemoved { - receiver: T::IdtyIndex, issuer: T::IdtyIndex, + receiver: T::IdtyIndex, }, /// A smith gathered enough certifications to become an authority (can call `go_online()`). SmithMembershipAdded { idty_index: T::IdtyIndex }, @@ -362,7 +362,7 @@ impl<T: Config> Pallet<T> { existing.received_certs = vec![]; Smiths::<T>::insert(receiver, existing); ExpiresOn::<T>::append(new_expires_on, receiver); - Self::deposit_event(Event::<T>::InvitationSent { receiver, issuer }); + Self::deposit_event(Event::<T>::InvitationSent { issuer, receiver }); } fn check_accept_invitation(receiver: T::IdtyIndex) -> DispatchResultWithPostInfo { @@ -444,7 +444,7 @@ impl<T: Config> Pallet<T> { // - adds a certification in receiver received list smith_meta.received_certs.push(issuer); smith_meta.received_certs.sort(); - Self::deposit_event(Event::<T>::SmithCertAdded { receiver, issuer }); + Self::deposit_event(Event::<T>::SmithCertAdded { issuer, receiver }); // - receiving a certification either lead us to Pending or Smith status let previous_status = smith_meta.status; @@ -521,8 +521,8 @@ impl<T: Config> Pallet<T> { if let Ok(index) = smith_meta.issued_certs.binary_search(&receiver) { smith_meta.issued_certs.remove(index); Self::deposit_event(Event::<T>::SmithCertRemoved { - receiver, issuer: lost_cert_issuer, + receiver, }); } } diff --git a/resources/metadata.scale b/resources/metadata.scale index 09d2d0c332f4be6fb1e2059bd328b2aadc812988..c98d5a3d9e7f0de953152c86bcc286c8a0e08255 100644 Binary files a/resources/metadata.scale and b/resources/metadata.scale differ diff --git a/runtime/common/src/providers.rs b/runtime/common/src/providers.rs index c947ce58856bd7dd997448a57bbfe9be65580f1d..829be1a07e64d033fd9f68b85c31db1f0612a670 100644 --- a/runtime/common/src/providers.rs +++ b/runtime/common/src/providers.rs @@ -97,7 +97,10 @@ macro_rules! impl_benchmark_setup_handler { <T as pallet_certification::Config>::IdtyIndex: From<u32>, { fn force_valid_distance_status(idty_id: &IdtyIndex) -> () { - let _ = pallet_distance::Pallet::<T>::do_valid_distance_status(*idty_id); + let _ = pallet_distance::Pallet::<T>::do_valid_distance_status( + *idty_id, + sp_runtime::Perbill::one(), + ); } fn add_cert(issuer: &IdtyIndex, receiver: &IdtyIndex) { diff --git a/runtime/gdev/tests/integration_tests.rs b/runtime/gdev/tests/integration_tests.rs index b91e0ee903832c74c7f68dbcb3e653fb952d5b8f..b4ed381a485794f5da7ac96ef7f623a14c0884bc 100644 --- a/runtime/gdev/tests/integration_tests.rs +++ b/runtime/gdev/tests/integration_tests.rs @@ -373,7 +373,10 @@ fn test_validate_identity_when_claim() { // Pass 3rd evaluation period run_to_block(3 * eval_period); System::assert_has_event(RuntimeEvent::Distance( - pallet_distance::Event::EvaluatedValid { idty_index: 5 }, + pallet_distance::Event::EvaluatedValid { + idty_index: 5, + distance: Perbill::one(), + }, )); // eve can not claim her membership manually because it is done automatically