Skip to content
Snippets Groups Projects
Commit a0a6426e authored by Pascal Engélibert's avatar Pascal Engélibert :bicyclist:
Browse files

Rename pool accessors

parent 2adc775f
No related branches found
No related tags found
1 merge request!105Distance Oracle
......@@ -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(),
)
......
......@@ -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()),
......
......@@ -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(),
......
No preview for this file type
......@@ -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(),
));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment