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

Remove instanciation and dep to certification

(cherry picked from commit f8152c2b)
parent cbdd5057
No related branches found
No related tags found
No related merge requests found
......@@ -5848,7 +5848,6 @@ dependencies = [
"frame-system",
"pallet-authority-members",
"pallet-authorship",
"pallet-certification",
"pallet-identity",
"pallet-membership",
"pallet-session",
......
......@@ -163,7 +163,7 @@ To work, the integration tests need to have the runtime metadata up to date, her
them:
```bash
subxt metadata -f bytes > resources/metadata.scale
subxt metadata -f bytes --version 14 > resources/metadata.scale
```
If you don't have subxt, install it: `cargo install subxt-cli`
......
......@@ -16,7 +16,6 @@ std = [
'frame-support/std',
'pallet-authority-members/std',
'pallet-authorship/std',
'pallet-certification/std',
'pallet-identity/std',
'pallet-membership/std',
'pallet-session/std',
......@@ -29,7 +28,6 @@ std = [
[dependencies]
pallet-authority-members = { path = "../authority-members", default-features = false }
pallet-certification = { path = "../certification", default-features = false }
pallet-identity = { path = "../identity", default-features = false }
pallet-membership = { path = "../membership", default-features = false }
sp-distance = { path = "../../primitives/distance", default-features = false }
......
......@@ -53,12 +53,11 @@ pub mod pallet {
// #[pallet::generate_store(pub(super) trait Store)] // deprecated
#[pallet::storage_version(STORAGE_VERSION)]
#[pallet::without_storage_info]
pub struct Pallet<T, I = ()>(PhantomData<(T, I)>);
pub struct Pallet<T>(PhantomData<T>);
#[pallet::config]
pub trait Config<I: 'static = ()>:
pub trait Config:
frame_system::Config
+ pallet_authorship::Config
+ pallet_certification::Config<I, IdtyIndex = IdtyIndex>
+ pallet_identity::Config<IdtyIndex = IdtyIndex>
+ pallet_session::Config
{
......@@ -81,40 +80,40 @@ pub mod pallet {
/// Identities queued for distance evaluation
#[pallet::storage]
#[pallet::getter(fn evaluation_pool_0)]
pub type EvaluationPool0<T: Config<I>, I: 'static = ()> = StorageValue<
pub type EvaluationPool0<T: Config> = StorageValue<
_,
EvaluationPool<
<T as frame_system::Config>::AccountId,
<T as pallet_certification::Config<I>>::IdtyIndex,
<T as pallet_identity::Config>::IdtyIndex,
>,
ValueQuery,
>;
/// Identities queued for distance evaluation
#[pallet::storage]
#[pallet::getter(fn evaluation_pool_1)]
pub type EvaluationPool1<T: Config<I>, I: 'static = ()> = StorageValue<
pub type EvaluationPool1<T: Config> = StorageValue<
_,
EvaluationPool<
<T as frame_system::Config>::AccountId,
<T as pallet_certification::Config<I>>::IdtyIndex,
<T as pallet_identity::Config>::IdtyIndex,
>,
ValueQuery,
>;
/// Identities queued for distance evaluation
#[pallet::storage]
#[pallet::getter(fn evaluation_pool_2)]
pub type EvaluationPool2<T: Config<I>, I: 'static = ()> = StorageValue<
pub type EvaluationPool2<T: Config> = StorageValue<
_,
EvaluationPool<
<T as frame_system::Config>::AccountId,
<T as pallet_certification::Config<I>>::IdtyIndex,
<T as pallet_identity::Config>::IdtyIndex,
>,
ValueQuery,
>;
/// Block for which the distance rule must be checked
#[pallet::storage]
pub type EvaluationBlock<T: Config<I>, I: 'static = ()> =
pub type EvaluationBlock<T: Config> =
StorageValue<_, <T as frame_system::Config>::Hash, ValueQuery>;
/// Distance evaluation status by identity
......@@ -124,10 +123,10 @@ pub mod pallet {
/// * `.1` is the status of the evaluation.
#[pallet::storage]
#[pallet::getter(fn identity_distance_status)]
pub type IdentityDistanceStatus<T: Config<I>, I: 'static = ()> = StorageMap<
pub type IdentityDistanceStatus<T: Config> = StorageMap<
_,
Twox64Concat,
<T as pallet_certification::Config<I>>::IdtyIndex,
<T as pallet_identity::Config>::IdtyIndex,
(<T as frame_system::Config>::AccountId, DistanceStatus),
OptionQuery,
>;
......@@ -135,12 +134,12 @@ pub mod pallet {
/// Identities by distance status expiration session index
#[pallet::storage]
#[pallet::getter(fn distance_status_expire_on)]
pub type DistanceStatusExpireOn<T: Config<I>, I: 'static = ()> = StorageMap<
pub type DistanceStatusExpireOn<T: Config> = StorageMap<
_,
Twox64Concat,
u32,
BoundedVec<
<T as pallet_certification::Config<I>>::IdtyIndex,
<T as pallet_identity::Config>::IdtyIndex,
ConstU32<MAX_EVALUATIONS_PER_SESSION>,
>,
ValueQuery,
......@@ -148,7 +147,7 @@ pub mod pallet {
/// Did evaluation get updated in this block?
#[pallet::storage]
pub(super) type DidUpdate<T: Config<I>, I: 'static = ()> = StorageValue<_, bool, ValueQuery>;
pub(super) type DidUpdate<T: Config> = StorageValue<_, bool, ValueQuery>;
// session_index % 3:
// storage_id + 0 => pending
......@@ -159,7 +158,7 @@ pub mod pallet {
// ERRORS //
#[pallet::error]
pub enum Error<T, I = ()> {
pub enum Error<T> {
AlreadyInEvaluation,
CannotReserve,
ManyEvaluationsByAuthor,
......@@ -173,7 +172,7 @@ pub mod pallet {
}
#[pallet::hooks]
impl<T: Config<I>, I: 'static> Hooks<BlockNumberFor<T>> for Pallet<T, I> {
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
/// dummy `on_initialize` to return the weight used in `on_finalize`.
fn on_initialize(_n: BlockNumberFor<T>) -> Weight {
// weight of `on_finalize`
......@@ -186,14 +185,14 @@ pub mod pallet {
/// - 1 storage deletion (codec `O(1)`).
/// # </weight>
fn on_finalize(_n: BlockNumberFor<T>) {
DidUpdate::<T, I>::take();
DidUpdate::<T>::take();
}
}
// CALLS //
#[pallet::call]
impl<T: Config<I>, I: 'static> Pallet<T, I> {
impl<T: Config> Pallet<T> {
/// Request an identity to be evaluated
#[pallet::call_index(0)]
#[pallet::weight(0)]
......@@ -201,15 +200,15 @@ pub mod pallet {
pub fn request_distance_evaluation(origin: OriginFor<T>) -> DispatchResultWithPostInfo {
let who = ensure_signed(origin)?;
let idty = pallet_identity::IdentityIndexOf::<T>::get(&who)
.ok_or(Error::<T, I>::NoIdentity)?;
let idty =
pallet_identity::IdentityIndexOf::<T>::get(&who).ok_or(Error::<T>::NoIdentity)?;
ensure!(
IdentityDistanceStatus::<T, I>::get(idty).is_none(),
Error::<T, I>::AlreadyInEvaluation
IdentityDistanceStatus::<T>::get(idty).is_none(),
Error::<T>::AlreadyInEvaluation
);
Pallet::<T, I>::do_request_distance_evaluation(who, idty)?;
Pallet::<T>::do_request_distance_evaluation(who, idty)?;
Ok(().into())
}
......@@ -223,14 +222,14 @@ pub mod pallet {
) -> DispatchResult {
ensure_none(origin)?;
ensure!(
!DidUpdate::<T, I>::exists(),
Error::<T, I>::ManyEvaluationsInBlock,
!DidUpdate::<T>::exists(),
Error::<T>::ManyEvaluationsInBlock,
);
let author = pallet_authorship::Pallet::<T>::author().ok_or(Error::<T, I>::NoAuthor)?;
let author = pallet_authorship::Pallet::<T>::author().ok_or(Error::<T>::NoAuthor)?;
Pallet::<T, I>::do_update_evaluation(author, computation_result)?;
Pallet::<T>::do_update_evaluation(author, computation_result)?;
DidUpdate::<T, I>::set(true);
DidUpdate::<T>::set(true);
Ok(())
}
......@@ -245,7 +244,7 @@ pub mod pallet {
) -> DispatchResult {
ensure_root(origin)?;
Pallet::<T, I>::do_update_evaluation(evaluator, computation_result)
Pallet::<T>::do_update_evaluation(evaluator, computation_result)
}
/// Set the distance evaluation status of an identity
......@@ -260,18 +259,18 @@ pub mod pallet {
// #[pallet::weight(T::WeightInfo::force_set_distance_status())]
pub fn force_set_distance_status(
origin: OriginFor<T>,
identity: <T as pallet_certification::Config<I>>::IdtyIndex,
identity: <T as pallet_identity::Config>::IdtyIndex,
status: Option<(<T as frame_system::Config>::AccountId, DistanceStatus)>,
) -> DispatchResult {
ensure_root(origin)?;
IdentityDistanceStatus::<T, I>::set(identity, status);
DistanceStatusExpireOn::<T, I>::mutate(
IdentityDistanceStatus::<T>::set(identity, status);
DistanceStatusExpireOn::<T>::mutate(
pallet_session::CurrentIndex::<T>::get() + T::ResultExpiration::get(),
move |identities| {
identities
.try_push(identity)
.map_err(|_| Error::<T, I>::ManyEvaluationsInBlock.into())
.map_err(|_| Error::<T>::ManyEvaluationsInBlock.into())
},
)
}
......@@ -279,7 +278,7 @@ pub mod pallet {
// INTERNAL FUNCTIONS //
impl<T: Config<I>, I: 'static> Pallet<T, I> {
impl<T: Config> Pallet<T> {
/// Mutate the evaluation pool containing:
/// * when this session begins: the evaluation results to be applied
/// * when this session ends: the evaluation requests
......@@ -288,7 +287,7 @@ pub mod pallet {
F: FnOnce(
&mut EvaluationPool<
<T as frame_system::Config>::AccountId,
<T as pallet_certification::Config<I>>::IdtyIndex,
<T as pallet_identity::Config>::IdtyIndex,
>,
) -> R,
>(
......@@ -296,9 +295,9 @@ pub mod pallet {
f: F,
) -> R {
match index % 3 {
0 => EvaluationPool2::<T, I>::mutate(f),
1 => EvaluationPool0::<T, I>::mutate(f),
2 => EvaluationPool1::<T, I>::mutate(f),
0 => EvaluationPool2::<T>::mutate(f),
1 => EvaluationPool0::<T>::mutate(f),
2 => EvaluationPool1::<T>::mutate(f),
_ => unreachable!("index % 3 < 3"),
}
}
......@@ -308,7 +307,7 @@ pub mod pallet {
F: FnOnce(
&mut EvaluationPool<
<T as frame_system::Config>::AccountId,
<T as pallet_certification::Config<I>>::IdtyIndex,
<T as pallet_identity::Config>::IdtyIndex,
>,
) -> R,
>(
......@@ -316,9 +315,9 @@ pub mod pallet {
f: F,
) -> R {
match index % 3 {
0 => EvaluationPool0::<T, I>::mutate(f),
1 => EvaluationPool1::<T, I>::mutate(f),
2 => EvaluationPool2::<T, I>::mutate(f),
0 => EvaluationPool0::<T>::mutate(f),
1 => EvaluationPool1::<T>::mutate(f),
2 => EvaluationPool2::<T>::mutate(f),
_ => unreachable!("index % 3 < 3"),
}
}
......@@ -331,41 +330,38 @@ pub mod pallet {
index: SessionIndex,
) -> EvaluationPool<
<T as frame_system::Config>::AccountId,
<T as pallet_certification::Config<I>>::IdtyIndex,
<T as pallet_identity::Config>::IdtyIndex,
> {
match index % 3 {
0 => EvaluationPool2::<T, I>::take(),
1 => EvaluationPool0::<T, I>::take(),
2 => EvaluationPool1::<T, I>::take(),
0 => EvaluationPool2::<T>::take(),
1 => EvaluationPool0::<T>::take(),
2 => EvaluationPool1::<T>::take(),
_ => unreachable!("index % 3 < 3"),
}
}
fn do_request_distance_evaluation(
who: T::AccountId,
idty_index: <T as pallet_certification::Config<I>>::IdtyIndex,
idty_index: <T as pallet_identity::Config>::IdtyIndex,
) -> Result<(), DispatchError> {
Pallet::<T, I>::mutate_current_pool(
Pallet::<T>::mutate_current_pool(
pallet_session::CurrentIndex::<T>::get(),
|current_pool| {
ensure!(
current_pool.evaluations.len() < (MAX_EVALUATIONS_PER_SESSION as usize),
Error::<T, I>::QueueFull
Error::<T>::QueueFull
);
T::Currency::reserve(&who, <T as Config<I>>::EvaluationPrice::get())?;
T::Currency::reserve(&who, <T as Config>::EvaluationPrice::get())?;
current_pool
.evaluations
.try_push((idty_index, median::MedianAcc::new()))
.map_err(|_| Error::<T, I>::QueueFull)?;
.map_err(|_| Error::<T>::QueueFull)?;
IdentityDistanceStatus::<T, I>::insert(
idty_index,
(who, DistanceStatus::Pending),
);
IdentityDistanceStatus::<T>::insert(idty_index, (who, DistanceStatus::Pending));
DistanceStatusExpireOn::<T, I>::mutate(
DistanceStatusExpireOn::<T>::mutate(
pallet_session::CurrentIndex::<T>::get() + T::ResultExpiration::get(),
move |identities| identities.try_push(idty_index).ok(),
);
......@@ -379,18 +375,16 @@ pub mod pallet {
evaluator: <T as frame_system::Config>::AccountId,
computation_result: ComputationResult,
) -> DispatchResult {
Pallet::<T, I>::mutate_next_pool(
pallet_session::CurrentIndex::<T>::get(),
|result_pool| {
Pallet::<T>::mutate_next_pool(pallet_session::CurrentIndex::<T>::get(), |result_pool| {
ensure!(
computation_result.distances.len() == result_pool.evaluations.len(),
Error::<T, I>::WrongResultLength
Error::<T>::WrongResultLength
);
if result_pool
.evaluators
.try_insert(evaluator)
.map_err(|_| Error::<T, I>::TooManyEvaluators)?
.map_err(|_| Error::<T>::TooManyEvaluators)?
{
for (distance_value, (_identity, median_acc)) in computation_result
.distances
......@@ -402,27 +396,26 @@ pub mod pallet {
Ok(())
} else {
Err(Error::<T, I>::ManyEvaluationsByAuthor.into())
Err(Error::<T>::ManyEvaluationsByAuthor.into())
}
},
)
})
}
}
impl<T: Config<I>, I: 'static> pallet_authority_members::OnNewSession for Pallet<T, I> {
impl<T: Config> pallet_authority_members::OnNewSession for Pallet<T> {
fn on_new_session(index: SessionIndex) -> Weight {
EvaluationBlock::<T, I>::set(frame_system::Pallet::<T>::parent_hash());
EvaluationBlock::<T>::set(frame_system::Pallet::<T>::parent_hash());
// Make results expire
DistanceStatusExpireOn::<T, I>::remove(index);
DistanceStatusExpireOn::<T>::remove(index);
// Apply the results from the current pool (which was previous session's result pool)
// We take the results so the pool is left empty for the new session.
#[allow(clippy::type_complexity)]
let current_pool: EvaluationPool<
<T as frame_system::Config>::AccountId,
<T as pallet_certification::Config<I>>::IdtyIndex,
> = Pallet::<T, I>::take_current_pool(index);
<T as pallet_identity::Config>::IdtyIndex,
> = Pallet::<T>::take_current_pool(index);
for (idty, median_acc) in current_pool.evaluations.into_iter() {
if let Some(median_result) = median_acc.get_median() {
let median = match median_result {
......@@ -430,29 +423,28 @@ pub mod pallet {
MedianResult::Two(m1, m2) => m1 + (m2 - m1) / 2, // Avoid overflow (since max is 1)
};
if median >= T::MinAccessibleReferees::get() {
IdentityDistanceStatus::<T, I>::mutate(idty, |entry| {
IdentityDistanceStatus::<T>::mutate(idty, |entry| {
entry.as_mut().map(|(account_id, status)| {
T::Currency::unreserve(
account_id,
<T as Config<I>>::EvaluationPrice::get(),
<T as Config>::EvaluationPrice::get(),
);
*status = DistanceStatus::Valid;
})
});
} else if let Some((account_id, _status)) =
IdentityDistanceStatus::<T, I>::take(idty)
IdentityDistanceStatus::<T>::take(idty)
{
<T as Config<I>>::Currency::slash_reserved(
<T as Config>::Currency::slash_reserved(
&account_id,
<T as Config<I>>::EvaluationPrice::get(),
<T as Config>::EvaluationPrice::get(),
);
}
} else if let Some((account_id, _status)) =
IdentityDistanceStatus::<T, I>::take(idty)
} else if let Some((account_id, _status)) = IdentityDistanceStatus::<T>::take(idty)
{
<T as Config<I>>::Currency::unreserve(
<T as Config>::Currency::unreserve(
&account_id,
<T as Config<I>>::EvaluationPrice::get(),
<T as Config>::EvaluationPrice::get(),
);
}
}
......@@ -461,8 +453,8 @@ pub mod pallet {
}
#[pallet::inherent]
impl<T: Config<I>, I: 'static> ProvideInherent for Pallet<T, I> {
type Call = Call<T, I>;
impl<T: Config> ProvideInherent for Pallet<T> {
type Call = Call<T>;
type Error = InherentError;
const INHERENT_IDENTIFIER: InherentIdentifier = INHERENT_IDENTIFIER;
......
......@@ -14,7 +14,7 @@
// You should have received a copy of the GNU Affero General Public License
// along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>.
pub trait HandleNegativeEvaluation<T: crate::Config<I>, I: 'static> {
pub trait HandleNegativeEvaluation<T: crate::Config> {
/// Do something with the reserved amount on the account,
/// when distance evaluation result is negative.
fn handle_negative_evaluation(account_id: T::AccountId);
......
......@@ -28,11 +28,11 @@ use sp_runtime::traits::IsMember;
pub struct OnNewSessionHandler<Runtime>(core::marker::PhantomData<Runtime>);
impl<Runtime> pallet_authority_members::traits::OnNewSession for OnNewSessionHandler<Runtime>
where
Runtime: pallet_provide_randomness::Config + pallet_distance::Config<Instance1>,
Runtime: pallet_provide_randomness::Config + pallet_distance::Config,
{
fn on_new_session(index: sp_staking::SessionIndex) -> Weight {
pallet_provide_randomness::Pallet::<Runtime>::on_new_epoch();
pallet_distance::Pallet::<Runtime, Instance1>::on_new_session(index)
pallet_distance::Pallet::<Runtime>::on_new_session(index)
}
}
......
......@@ -431,7 +431,7 @@ parameter_types! {
use frame_support::instances::Instance1;
impl pallet_duniter_wot::Config<Instance1> for Runtime {
type FirstIssuableOn = WotFirstCertIssuableOn;
type IsDistanceOk = common_runtime::providers::MainWotIsDistanceOk<Runtime, Instance1>;
type IsDistanceOk = common_runtime::providers::MainWotIsDistanceOk<Runtime>;
type IsSubWot = frame_support::traits::ConstBool<false>;
type MinCertForMembership = WotMinCertForMembership;
type MinCertForCreateIdtyRight = WotMinCertForCreateIdtyRight;
......@@ -485,7 +485,7 @@ parameter_types! {
parameter_types! {
pub const MinAccessibleReferees: Perbill = Perbill::from_percent(80);
}
impl pallet_distance::Config<Instance1> for Runtime {
impl pallet_distance::Config for Runtime {
type Currency = Balances;
type EvaluationPrice = frame_support::traits::ConstU64<1000>;
type MinAccessibleReferees = MinAccessibleReferees;
......
......@@ -107,18 +107,16 @@ where
}
}
pub struct MainWotIsDistanceOk<T, I>(PhantomData<(T, I)>);
pub struct MainWotIsDistanceOk<T>(PhantomData<T>);
impl<T, I>
pallet_duniter_wot::traits::IsDistanceOk<<T as pallet_certification::Config<I>>::IdtyIndex>
for MainWotIsDistanceOk<T, I>
impl<T> pallet_duniter_wot::traits::IsDistanceOk<<T as pallet_identity::Config>::IdtyIndex>
for MainWotIsDistanceOk<T>
where
T: pallet_distance::Config<I>,
I: 'static,
T: pallet_distance::Config,
{
fn is_distance_ok(idty_id: &<T as pallet_certification::Config<I>>::IdtyIndex) -> bool {
fn is_distance_ok(idty_id: &<T as pallet_identity::Config>::IdtyIndex) -> bool {
matches!(
pallet_distance::Pallet::<T, I>::identity_distance_status(idty_id),
pallet_distance::Pallet::<T>::identity_distance_status(idty_id),
Some((_, pallet_distance::DistanceStatus::Valid))
)
}
......
......@@ -279,7 +279,7 @@ construct_runtime!(
Identity: pallet_identity::{Pallet, Call, Config<T>, Storage, Event<T>} = 41,
Membership: pallet_membership::<Instance1>::{Pallet, Call, Config<T>, Storage, Event<T>} = 42,
Cert: pallet_certification::<Instance1>::{Pallet, Call, Config<T>, Storage, Event<T>} = 43,
Distance: pallet_distance::<Instance1>::{Pallet, Call, Storage, Inherent} = 44,
Distance: pallet_distance::{Pallet, Call, Storage, Inherent} = 44,
// Smith Sub-Wot
SmithSubWot: pallet_duniter_wot::<Instance2>::{Pallet} = 50,
......
......@@ -335,7 +335,7 @@ construct_runtime!(
Identity: pallet_identity::{Pallet, Call, Config<T>, Storage, Event<T>} = 41,
Membership: pallet_membership::<Instance1>::{Pallet, Call, Config<T>, Storage, Event<T>} = 42,
Cert: pallet_certification::<Instance1>::{Pallet, Call, Config<T>, Storage, Event<T>} = 43,
Distance: pallet_distance::<Instance1>::{Pallet, Call, Storage, Inherent} = 44,
Distance: pallet_distance::{Pallet, Call, Storage, Inherent} = 44,
// Smith Sub-Wot
SmithSubWot: pallet_duniter_wot::<Instance2>::{Pallet} = 50,
......
......@@ -295,7 +295,7 @@ construct_runtime!(
Identity: pallet_identity::{Pallet, Call, Config<T>, Storage, Event<T>} = 41,
Membership: pallet_membership::<Instance1>::{Pallet, Call, Config<T>, Storage, Event<T>} = 42,
Cert: pallet_certification::<Instance1>::{Pallet, Call, Config<T>, Storage, Event<T>} = 43,
Distance: pallet_distance::<Instance1>::{Pallet, Call, Storage, Inherent} = 44,
Distance: pallet_distance::{Pallet, Call, Storage, Inherent} = 44,
// Smith Sub-Wot
SmithSubWot: pallet_duniter_wot::<Instance2>::{Pallet} = 50,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment