Skip to content
Snippets Groups Projects

Change distance evaluation period from Sessions to Blocks

Merged Benjamin Gallois requested to merge 202-distance-oracle-reevaluation into master
4 files
+ 291
44
Compare changes
  • Side-by-side
  • Inline
Files
4
@@ -20,6 +20,8 @@ use super::*;
@@ -20,6 +20,8 @@ use super::*;
use codec::Encode;
use codec::Encode;
use frame_benchmarking::v2::*;
use frame_benchmarking::v2::*;
 
use frame_support::traits::Get;
 
use frame_support::traits::OnInitialize;
use frame_support::traits::{Currency, OnFinalize};
use frame_support::traits::{Currency, OnFinalize};
use frame_system::pallet_prelude::BlockNumberFor;
use frame_system::pallet_prelude::BlockNumberFor;
use frame_system::RawOrigin;
use frame_system::RawOrigin;
@@ -164,6 +166,103 @@ mod benchmarks {
@@ -164,6 +166,103 @@ mod benchmarks {
assert_has_event::<T>(Event::<T>::EvaluatedValid { idty_index: idty }.into());
assert_has_event::<T>(Event::<T>::EvaluatedValid { idty_index: idty }.into());
}
}
 
#[benchmark]
 
fn on_initialize_overhead() {
 
// Benchmark on_initialize with no on_finalize and no do_evaluation.
 
let block_number: BlockNumberFor<T> = (T::EvaluationPeriod::get() + 1).into();
 
 
#[block]
 
{
 
Pallet::<T>::on_initialize(block_number);
 
}
 
}
 
 
#[benchmark]
 
fn do_evaluation_success() -> Result<(), BenchmarkError> {
 
// Benchmark do_evaluation in case of one success.
 
CurrentPoolIndex::<T>::put(0);
 
frame_system::pallet::Pallet::<T>::set_block_number(1u32.into());
 
let idty = T::IdtyIndex::one();
 
let caller: T::AccountId = pallet_identity::Identities::<T>::get(idty)
 
.unwrap()
 
.owner_key;
 
let _ =
 
<Balances<T> as Currency<_>>::make_free_balance_be(&caller, T::Balance::max_value());
 
Pallet::<T>::request_distance_evaluation(RawOrigin::Signed(caller.clone()).into())?;
 
assert_has_event::<T>(
 
Event::<T>::EvaluationRequested {
 
idty_index: idty,
 
who: caller.clone(),
 
}
 
.into(),
 
);
 
 
CurrentPoolIndex::<T>::put(2);
 
Pallet::<T>::force_update_evaluation(
 
RawOrigin::Root.into(),
 
caller,
 
ComputationResult {
 
distances: vec![Perbill::one()],
 
},
 
)?;
 
 
#[block]
 
{
 
Pallet::<T>::do_evaluation(0);
 
}
 
 
assert_has_event::<T>(Event::<T>::EvaluatedValid { idty_index: idty }.into());
 
Ok(())
 
}
 
 
#[benchmark]
 
fn do_evaluation_echec() -> Result<(), BenchmarkError> {
 
// Benchmark do_evaluation in case of one echec.
 
CurrentPoolIndex::<T>::put(0);
 
frame_system::pallet::Pallet::<T>::set_block_number(1u32.into());
 
let idty = T::IdtyIndex::one();
 
let caller: T::AccountId = pallet_identity::Identities::<T>::get(idty)
 
.unwrap()
 
.owner_key;
 
let _ =
 
<Balances<T> as Currency<_>>::make_free_balance_be(&caller, T::Balance::max_value());
 
Pallet::<T>::request_distance_evaluation(RawOrigin::Signed(caller.clone()).into())?;
 
assert_has_event::<T>(
 
Event::<T>::EvaluationRequested {
 
idty_index: idty,
 
who: caller.clone(),
 
}
 
.into(),
 
);
 
 
CurrentPoolIndex::<T>::put(2);
 
Pallet::<T>::force_update_evaluation(
 
RawOrigin::Root.into(),
 
caller,
 
ComputationResult {
 
distances: vec![Perbill::zero()],
 
},
 
)?;
 
 
#[block]
 
{
 
Pallet::<T>::do_evaluation(0);
 
}
 
 
assert_has_event::<T>(Event::<T>::EvaluatedInvalid { idty_index: idty }.into());
 
Ok(())
 
}
 
 
#[benchmark]
 
fn do_evaluation_overhead() -> Result<(), BenchmarkError> {
 
#[block]
 
{
 
Pallet::<T>::do_evaluation(0);
 
}
 
 
Ok(())
 
}
 
#[benchmark]
#[benchmark]
fn on_finalize() {
fn on_finalize() {
DidUpdate::<T>::set(true);
DidUpdate::<T>::set(true);
Loading