diff --git a/end2end-tests/tests/common/distance.rs b/end2end-tests/tests/common/distance.rs index 5b946ca93eb0a38a7c40feb7103ccf41398e03ca..e1a8f1ecaa6e002400aa0f456eac9284b99e0d8a 100644 --- a/end2end-tests/tests/common/distance.rs +++ b/end2end-tests/tests/common/distance.rs @@ -30,7 +30,7 @@ pub async fn request_evaluation(client: &Client, origin: AccountKeyring) -> Resu client .tx() .create_signed( - &gdev::tx().distance().evaluate_distance(), + &gdev::tx().distance().request_distance_evaluation(), &origin, BaseExtrinsicParamsBuilder::new(), ) diff --git a/end2end-tests/tests/cucumber_tests.rs b/end2end-tests/tests/cucumber_tests.rs index 1c3d02f341f90d79b14afaafec72577cb8021f15..47206990acae821ed80271ffa695a5f18a7a6a1e 100644 --- a/end2end-tests/tests/cucumber_tests.rs +++ b/end2end-tests/tests/cucumber_tests.rs @@ -516,8 +516,8 @@ async fn should_have_distance_ok(world: &mut DuniterWorld, who: String) -> Resul .read(&gdev::storage().distance().identity_distance_status(idty_id)) .await? { - Some(gdev::runtime_types::pallet_distance::types::DistanceStatus::Valid) => Ok(()), - Some(gdev::runtime_types::pallet_distance::types::DistanceStatus::Pending) => { + Some((_, gdev::runtime_types::pallet_distance::types::DistanceStatus::Valid)) => Ok(()), + Some((_, gdev::runtime_types::pallet_distance::types::DistanceStatus::Pending)) => { Err(anyhow::anyhow!("pending distance status").into()) } None => Err(anyhow::anyhow!("no distance status").into()), diff --git a/pallets/distance/src/lib.rs b/pallets/distance/src/lib.rs index fc5737ea9095854df10c165e72fa11c164433565..9f668c474551f922fb9b75f260a62a5ec11ee2c4 100644 --- a/pallets/distance/src/lib.rs +++ b/pallets/distance/src/lib.rs @@ -191,7 +191,7 @@ pub mod pallet { impl<T: Config<I>, I: 'static> Pallet<T, I> { /// Request an identity to be evaluated #[pallet::weight(1_000_000_000)] - pub fn evaluate_distance(origin: OriginFor<T>) -> DispatchResultWithPostInfo { + pub fn request_distance_evaluation(origin: OriginFor<T>) -> DispatchResultWithPostInfo { let who = ensure_signed(origin)?; let idty = pallet_identity::IdentityIndexOf::<T>::get(&who) @@ -202,7 +202,7 @@ pub mod pallet { Error::<T, I>::AlreadyInEvaluation ); - Pallet::<T, I>::do_evaluate_distance(who, idty)?; + Pallet::<T, I>::do_request_distance_evaluation(who, idty)?; Ok(().into()) } @@ -261,7 +261,9 @@ pub mod pallet { // INTERNAL FUNCTIONS // impl<T: Config<I>, I: 'static> Pallet<T, I> { - /// Mutate the evaluation pool containing the results to be applied on this session. + /// Mutate the evaluation pool containing: + /// * when this session begins: the evaluation results to be applied + /// * when this session ends: the evaluation requests fn mutate_current_pool< R, F: FnOnce( @@ -283,8 +285,32 @@ pub mod pallet { _ => unreachable!("index % 3 < 3"), } } + /// Mutate the evaluation pool containing the results sent by evaluators on this session. + fn mutate_next_pool< + R, + F: FnOnce( + &mut EvaluationPool< + <T as frame_system::Config>::AccountId, + <T as pallet_certification::Config<I>>::IdtyIndex, + <T as Config<I>>::MaxEvaluationsPerSession, + 100, //<T as Config<I>>::MaxEvaluatorsPerSession, + >, + ) -> R, + >( + index: SessionIndex, + f: F, + ) -> R { + match index % 3 { + 0 => EvaluationPool0::<T, I>::mutate(f), + 1 => EvaluationPool1::<T, I>::mutate(f), + 2 => EvaluationPool2::<T, I>::mutate(f), + _ => unreachable!("index % 3 < 3"), + } + } - /// Take the evaluation pool containing the results to be applied on this session. + /// Take (and leave empty) the evaluation pool containing: + /// * when this session begins: the evaluation results to be applied + /// * when this session ends: the evaluation requests #[allow(clippy::type_complexity)] fn take_current_pool( index: SessionIndex, @@ -302,7 +328,7 @@ pub mod pallet { } } - fn do_evaluate_distance( + fn do_request_distance_evaluation( who: T::AccountId, idty_index: <T as pallet_certification::Config<I>>::IdtyIndex, ) -> Result<(), DispatchError> { @@ -341,8 +367,8 @@ pub mod pallet { evaluator: <T as frame_system::Config>::AccountId, computation_result: ComputationResult, ) -> DispatchResult { - Pallet::<T, I>::mutate_current_pool( - pallet_session::CurrentIndex::<T>::get().wrapping_add(1), + Pallet::<T, I>::mutate_next_pool( + pallet_session::CurrentIndex::<T>::get(), |result_pool| { ensure!( computation_result.distances.len() == result_pool.0.len(), diff --git a/resources/metadata.scale b/resources/metadata.scale index cff4a76115715c21574516f2db1f6534fc94a9c8..d90bf7356f6d8550b1fd195e26baaf03f741875d 100644 Binary files a/resources/metadata.scale and b/resources/metadata.scale differ diff --git a/runtime/gdev/tests/integration_tests.rs b/runtime/gdev/tests/integration_tests.rs index 47f7eef77afc2609f5e0ab99d0c78161fee7deac..79b29cb936850abbffd885eff40f7c8d672ca8d3 100644 --- a/runtime/gdev/tests/integration_tests.rs +++ b/runtime/gdev/tests/integration_tests.rs @@ -144,7 +144,7 @@ fn test_validate_identity_when_claim() { 5 )); - assert_ok!(Distance::evaluate_distance( + assert_ok!(Distance::request_distance_evaluation( frame_system::RawOrigin::Signed(AccountKeyring::Eve.to_account_id()).into(), )); @@ -202,7 +202,7 @@ fn test_membership_renewal() { .with_initial_balances(vec![(AccountKeyring::Alice.to_account_id(), 2000)]) .build() .execute_with(|| { - assert_ok!(Distance::evaluate_distance( + assert_ok!(Distance::request_distance_evaluation( frame_system::RawOrigin::Signed(AccountKeyring::Alice.to_account_id()).into(), ));