Skip to content
Snippets Groups Projects
Unverified Commit 2f875f47 authored by bgallois's avatar bgallois
Browse files

allocate quota for membership instead of identity fix...

allocate quota for membership instead of identity fix #247
parent e512f2c3
No related branches found
No related tags found
No related merge requests found
Pipeline #39823 failed
...@@ -9550,6 +9550,7 @@ dependencies = [ ...@@ -9550,6 +9550,7 @@ dependencies = [
"scale-info", "scale-info",
"sp-core", "sp-core",
"sp-io", "sp-io",
"sp-membership",
"sp-runtime", "sp-runtime",
] ]
......
...@@ -16,6 +16,7 @@ runtime-benchmarks = [ ...@@ -16,6 +16,7 @@ runtime-benchmarks = [
"frame-system/runtime-benchmarks", "frame-system/runtime-benchmarks",
"pallet-balances/runtime-benchmarks", "pallet-balances/runtime-benchmarks",
"pallet-identity/runtime-benchmarks", "pallet-identity/runtime-benchmarks",
"sp-membership/runtime-benchmarks",
"sp-runtime/runtime-benchmarks", "sp-runtime/runtime-benchmarks",
] ]
try-runtime = [ try-runtime = [
...@@ -23,8 +24,8 @@ try-runtime = [ ...@@ -23,8 +24,8 @@ try-runtime = [
"frame-system/try-runtime", "frame-system/try-runtime",
"pallet-balances/runtime-benchmarks", "pallet-balances/runtime-benchmarks",
"pallet-balances/try-runtime", "pallet-balances/try-runtime",
"pallet-identity/runtime-benchmarks",
"pallet-identity/try-runtime", "pallet-identity/try-runtime",
"sp-membership/try-runtime",
"sp-runtime/try-runtime", "sp-runtime/try-runtime",
] ]
std = [ std = [
...@@ -34,6 +35,7 @@ std = [ ...@@ -34,6 +35,7 @@ std = [
"frame-system/std", "frame-system/std",
"pallet-balances/std", "pallet-balances/std",
"pallet-identity/std", "pallet-identity/std",
"sp-membership/std",
"scale-info/std", "scale-info/std",
"sp-core/std", "sp-core/std",
"sp-io/std", "sp-io/std",
...@@ -50,6 +52,7 @@ frame-support = { workspace = true } ...@@ -50,6 +52,7 @@ frame-support = { workspace = true }
frame-system = { workspace = true } frame-system = { workspace = true }
pallet-balances = { workspace = true } pallet-balances = { workspace = true }
pallet-identity = { workspace = true } pallet-identity = { workspace = true }
sp-membership = { workspace = true }
scale-info = { workspace = true, features = ["derive"] } scale-info = { workspace = true, features = ["derive"] }
sp-core = { workspace = true } sp-core = { workspace = true }
sp-runtime = { workspace = true } sp-runtime = { workspace = true }
......
...@@ -360,17 +360,20 @@ impl<T: Config> RefundFee<T> for Pallet<T> { ...@@ -360,17 +360,20 @@ impl<T: Config> RefundFee<T> for Pallet<T> {
/// Checks if an identity is eligible for a refund. /// Checks if an identity is eligible for a refund.
/// ///
/// This function returns `true` for all identities, regardless of their status. /// This function returns `true` only if the identity exists and has a status of `Member`.
/// If the identity has no quotas or has been deleted, the refund request is still queued, /// If the identity does not exist or has a different status, it returns `false`, and the refund request will not be processed.
/// but when handled, no refund will be issued (and `NoQuotaForIdty` may be raised). ///
fn is_eligible_for_refund<T: pallet_identity::Config>(_identity: IdtyId<T>) -> bool { fn is_eligible_for_refund<T: pallet_identity::Config>(idty_index: IdtyId<T>) -> bool {
true pallet_identity::Identities::<T>::get(idty_index).map_or_else(
|| false,
|id| id.status == pallet_identity::IdtyStatus::Member,
)
} }
/// Implementing the on new identity event handler for the pallet. /// Implementing the on new membership event handler for the pallet.
impl<T: Config> pallet_identity::traits::OnNewIdty<T> for Pallet<T> { impl<T: Config> sp_membership::traits::OnNewMembership<IdtyId<T>> for Pallet<T> {
/// This implementation initializes the identity quota for the newly created identity. /// This implementation initializes the identity quota for the newly created identity.
fn on_created(idty_index: &IdtyId<T>, _creator: &T::IdtyIndex) { fn on_created(idty_index: &IdtyId<T>) {
IdtyQuota::<T>::insert( IdtyQuota::<T>::insert(
idty_index, idty_index,
Quota { Quota {
...@@ -379,10 +382,12 @@ impl<T: Config> pallet_identity::traits::OnNewIdty<T> for Pallet<T> { ...@@ -379,10 +382,12 @@ impl<T: Config> pallet_identity::traits::OnNewIdty<T> for Pallet<T> {
}, },
); );
} }
fn on_renewed(_idty_index: &IdtyId<T>) {}
} }
/// Implementing the on remove identity event handler for the pallet. /// Implementing the on remove identity event handler for the pallet.
impl<T: Config> pallet_identity::traits::OnRemoveIdty<T> for Pallet<T> { impl<T: Config> sp_membership::traits::OnRemoveMembership<IdtyId<T>> for Pallet<T> {
/// This implementation removes the identity quota associated with the removed identity. /// This implementation removes the identity quota associated with the removed identity.
fn on_removed(idty_id: &IdtyId<T>) -> Weight { fn on_removed(idty_id: &IdtyId<T>) -> Weight {
let mut weight = Weight::zero(); let mut weight = Weight::zero();
...@@ -394,9 +399,4 @@ impl<T: Config> pallet_identity::traits::OnRemoveIdty<T> for Pallet<T> { ...@@ -394,9 +399,4 @@ impl<T: Config> pallet_identity::traits::OnRemoveIdty<T> for Pallet<T> {
add_db_reads_writes(1, 1); add_db_reads_writes(1, 1);
weight weight
} }
/// This implementation removes the identity quota associated with the removed identity.
fn on_revoked(idty_id: &IdtyId<T>) -> Weight {
Self::on_removed(idty_id)
}
} }
...@@ -38,33 +38,28 @@ where ...@@ -38,33 +38,28 @@ where
/// Runtime handler for OnNewIdty, calling all implementations of /// Runtime handler for OnNewIdty, calling all implementations of
/// OnNewIdty and implementing logic at the runtime level. /// OnNewIdty and implementing logic at the runtime level.
pub struct OnNewIdtyHandler<Runtime>(core::marker::PhantomData<Runtime>); pub struct OnNewIdtyHandler<Runtime>(core::marker::PhantomData<Runtime>);
impl<Runtime: pallet_duniter_wot::Config + pallet_quota::Config> impl<Runtime: pallet_duniter_wot::Config> pallet_identity::traits::OnNewIdty<Runtime>
pallet_identity::traits::OnNewIdty<Runtime> for OnNewIdtyHandler<Runtime> for OnNewIdtyHandler<Runtime>
{ {
fn on_created(idty_index: &IdtyIndex, creator: &IdtyIndex) { fn on_created(idty_index: &IdtyIndex, creator: &IdtyIndex) {
pallet_duniter_wot::Pallet::<Runtime>::on_created(idty_index, creator); pallet_duniter_wot::Pallet::<Runtime>::on_created(idty_index, creator);
pallet_quota::Pallet::<Runtime>::on_created(idty_index, creator);
} }
} }
/// Runtime handler for OnRemoveIdty, calling all implementations of /// Runtime handler for OnRemoveIdty, calling all implementations of
/// OnRemoveIdty and implementing logic at the runtime level. /// OnRemoveIdty and implementing logic at the runtime level.
pub struct OnRemoveIdtyHandler<Runtime>(core::marker::PhantomData<Runtime>); pub struct OnRemoveIdtyHandler<Runtime>(core::marker::PhantomData<Runtime>);
impl< impl<Runtime: pallet_duniter_wot::Config + pallet_duniter_account::Config>
Runtime: pallet_duniter_wot::Config + pallet_quota::Config + pallet_duniter_account::Config, pallet_identity::traits::OnRemoveIdty<Runtime> for OnRemoveIdtyHandler<Runtime>
> pallet_identity::traits::OnRemoveIdty<Runtime> for OnRemoveIdtyHandler<Runtime>
{ {
fn on_removed(idty_index: &IdtyIndex) -> Weight { fn on_removed(idty_index: &IdtyIndex) -> Weight {
pallet_duniter_wot::Pallet::<Runtime>::on_removed(idty_index) pallet_duniter_wot::Pallet::<Runtime>::on_removed(idty_index)
.saturating_add(pallet_quota::Pallet::<Runtime>::on_removed(idty_index))
} }
fn on_revoked(idty_index: &IdtyIndex) -> Weight { fn on_revoked(idty_index: &IdtyIndex) -> Weight {
pallet_duniter_wot::Pallet::<Runtime>::on_revoked(idty_index) pallet_duniter_wot::Pallet::<Runtime>::on_revoked(idty_index).saturating_add(
.saturating_add(pallet_duniter_account::Pallet::<Runtime>::on_revoked( pallet_duniter_account::Pallet::<Runtime>::on_revoked(idty_index),
idty_index, )
))
.saturating_add(pallet_quota::Pallet::<Runtime>::on_revoked(idty_index))
} }
} }
...@@ -75,13 +70,16 @@ impl< ...@@ -75,13 +70,16 @@ impl<
Runtime: frame_system::Config<AccountId = AccountId> Runtime: frame_system::Config<AccountId = AccountId>
+ pallet_identity::Config<IdtyData = IdtyData, IdtyIndex = IdtyIndex> + pallet_identity::Config<IdtyData = IdtyData, IdtyIndex = IdtyIndex>
+ pallet_duniter_wot::Config + pallet_duniter_wot::Config
+ pallet_universal_dividend::Config, + pallet_universal_dividend::Config
+ pallet_quota::Config,
> sp_membership::traits::OnNewMembership<IdtyIndex> for OnNewMembershipHandler<Runtime> > sp_membership::traits::OnNewMembership<IdtyIndex> for OnNewMembershipHandler<Runtime>
{ {
fn on_created(idty_index: &IdtyIndex) { fn on_created(idty_index: &IdtyIndex) {
// duniter-wot related actions // duniter-wot related actions
pallet_duniter_wot::Pallet::<Runtime>::on_created(idty_index); pallet_duniter_wot::Pallet::<Runtime>::on_created(idty_index);
pallet_quota::Pallet::<Runtime>::on_created(idty_index);
// When main membership is acquired, it starts getting right to UD. // When main membership is acquired, it starts getting right to UD.
pallet_identity::Identities::<Runtime>::mutate_exists(idty_index, |idty_val_opt| { pallet_identity::Identities::<Runtime>::mutate_exists(idty_index, |idty_val_opt| {
if let Some(ref mut idty_val) = idty_val_opt { if let Some(ref mut idty_val) = idty_val_opt {
...@@ -107,6 +105,7 @@ impl< ...@@ -107,6 +105,7 @@ impl<
+ pallet_identity::Config<IdtyData = IdtyData, IdtyIndex = IdtyIndex> + pallet_identity::Config<IdtyData = IdtyData, IdtyIndex = IdtyIndex>
+ pallet_smith_members::Config<IdtyIndex = IdtyIndex> + pallet_smith_members::Config<IdtyIndex = IdtyIndex>
+ pallet_duniter_wot::Config + pallet_duniter_wot::Config
+ pallet_quota::Config
+ pallet_universal_dividend::Config, + pallet_universal_dividend::Config,
> sp_membership::traits::OnRemoveMembership<IdtyIndex> for OnRemoveMembershipHandler<Runtime> > sp_membership::traits::OnRemoveMembership<IdtyIndex> for OnRemoveMembershipHandler<Runtime>
{ {
...@@ -127,7 +126,8 @@ impl< ...@@ -127,7 +126,8 @@ impl<
} }
} }
}); });
weight += Runtime::DbWeight::get().reads_writes(1, 1); weight.saturating_add(pallet_quota::Pallet::<Runtime>::on_removed(idty_index));
weight.saturating_add(Runtime::DbWeight::get().reads_writes(1, 1));
// When membership is removed, also remove from smith member. // When membership is removed, also remove from smith member.
weight.saturating_add( weight.saturating_add(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment