Skip to content
Snippets Groups Projects
Commit c1cee127 authored by bgallois's avatar bgallois Committed by Hugo Trentesaux
Browse files

allocate quota for membership instead of identity fix...

allocate quota for membership instead of identity fix #247
parent db241e71
No related branches found
No related tags found
1 merge request!315Allocate quota for membership instead of identity
......@@ -9547,6 +9547,7 @@ dependencies = [
"scale-info",
"sp-core",
"sp-io",
"sp-membership",
"sp-runtime",
]
......
......@@ -31,12 +31,14 @@ Feature: Distance fail
When bob certifies ferdie
Then ferdie should be certified by bob
Then ferdie should have 0 ĞD reserved
Then ferdie should have 1449 cĞD
# 700 + 750 - 2(one transaction fee, not a member yet)
Then ferdie should have 1448 cĞD
When ferdie requests distance evaluation
Then ferdie should have 10 ĞD reserved
Then ferdie should have 449 cĞD
# 1448 - 1000 - 2(one transaction fee, not a member yet)
Then ferdie should have 446 cĞD
When 7 blocks later
Then treasury should contain 102 cĞD
Then treasury should contain 105 cĞD
When alice runs distance oracle
When 7 blocks later
Then ferdie should be certified by alice
......@@ -45,6 +47,6 @@ Feature: Distance fail
Then ferdie identity should be unvalidated
# Ferdie got his reserve slashed
Then ferdie should have 0 ĞD reserved
Then ferdie should have 449 cĞD
Then ferdie should have 446 cĞD
# Slashed amount is transfered to treasury
Then treasury should contain 1102 cĞD
Then treasury should contain 1105 cĞD
......@@ -24,13 +24,15 @@ Feature: Identity creation
Then dave should be certified by bob
Then dave should be certified by charlie
Then dave should have 0 ĞD reserved
Then dave should have 1449 cĞD
# 700 + 750 - 2(one transaction fee, not a member yet)
Then dave should have 1448 cĞD
When dave requests distance evaluation
Then dave should have 10 ĞD reserved
Then dave should have 449 cĞD
# 1448 - 1000 - 2(one transaction fee, not a member yet)
Then dave should have 446 cĞD
When 7 blocks later
When alice runs distance oracle
When 7 blocks later
Then dave identity should be member
Then dave should have 0 ĞD reserved
Then dave should have 1449 cĞD
Then dave should have 1446 cĞD
......@@ -16,6 +16,7 @@ runtime-benchmarks = [
"frame-system/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"pallet-identity/runtime-benchmarks",
"sp-membership/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
try-runtime = [
......@@ -23,8 +24,8 @@ try-runtime = [
"frame-system/try-runtime",
"pallet-balances/runtime-benchmarks",
"pallet-balances/try-runtime",
"pallet-identity/runtime-benchmarks",
"pallet-identity/try-runtime",
"sp-membership/try-runtime",
"sp-runtime/try-runtime",
]
std = [
......@@ -34,6 +35,7 @@ std = [
"frame-system/std",
"pallet-balances/std",
"pallet-identity/std",
"sp-membership/std",
"scale-info/std",
"sp-core/std",
"sp-io/std",
......@@ -50,6 +52,7 @@ frame-support = { workspace = true }
frame-system = { workspace = true }
pallet-balances = { workspace = true }
pallet-identity = { workspace = true }
sp-membership = { workspace = true }
scale-info = { workspace = true, features = ["derive"] }
sp-core = { workspace = true }
sp-runtime = { workspace = true }
......
......@@ -360,17 +360,20 @@ impl<T: Config> RefundFee<T> for Pallet<T> {
/// Checks if an identity is eligible for a refund.
///
/// This function returns `true` for all identities, regardless of their status.
/// If the identity has no quotas or has been deleted, the refund request is still queued,
/// 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 {
true
/// This function returns `true` only if the identity exists and has a status of `Member`.
/// If the identity does not exist or has a different status, it returns `false`, and the refund request will not be processed.
///
fn is_eligible_for_refund<T: pallet_identity::Config>(idty_index: IdtyId<T>) -> bool {
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.
impl<T: Config> pallet_identity::traits::OnNewIdty<T> for Pallet<T> {
/// Implementing the on new membership event handler for the pallet.
impl<T: Config> sp_membership::traits::OnNewMembership<IdtyId<T>> for Pallet<T> {
/// 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(
idty_index,
Quota {
......@@ -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.
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.
fn on_removed(idty_id: &IdtyId<T>) -> Weight {
let mut weight = Weight::zero();
......@@ -394,9 +399,4 @@ impl<T: Config> pallet_identity::traits::OnRemoveIdty<T> for Pallet<T> {
add_db_reads_writes(1, 1);
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
/// Runtime handler for OnNewIdty, calling all implementations of
/// OnNewIdty and implementing logic at the runtime level.
pub struct OnNewIdtyHandler<Runtime>(core::marker::PhantomData<Runtime>);
impl<Runtime: pallet_duniter_wot::Config + pallet_quota::Config>
pallet_identity::traits::OnNewIdty<Runtime> for OnNewIdtyHandler<Runtime>
impl<Runtime: pallet_duniter_wot::Config> pallet_identity::traits::OnNewIdty<Runtime>
for OnNewIdtyHandler<Runtime>
{
fn on_created(idty_index: &IdtyIndex, creator: &IdtyIndex) {
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
/// OnRemoveIdty and implementing logic at the runtime level.
pub struct OnRemoveIdtyHandler<Runtime>(core::marker::PhantomData<Runtime>);
impl<
Runtime: pallet_duniter_wot::Config + pallet_quota::Config + pallet_duniter_account::Config,
> pallet_identity::traits::OnRemoveIdty<Runtime> for OnRemoveIdtyHandler<Runtime>
impl<Runtime: pallet_duniter_wot::Config + pallet_duniter_account::Config>
pallet_identity::traits::OnRemoveIdty<Runtime> for OnRemoveIdtyHandler<Runtime>
{
fn on_removed(idty_index: &IdtyIndex) -> Weight {
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 {
pallet_duniter_wot::Pallet::<Runtime>::on_revoked(idty_index)
.saturating_add(pallet_duniter_account::Pallet::<Runtime>::on_revoked(
idty_index,
))
.saturating_add(pallet_quota::Pallet::<Runtime>::on_revoked(idty_index))
pallet_duniter_wot::Pallet::<Runtime>::on_revoked(idty_index).saturating_add(
pallet_duniter_account::Pallet::<Runtime>::on_revoked(idty_index),
)
}
}
......@@ -75,13 +70,16 @@ impl<
Runtime: frame_system::Config<AccountId = AccountId>
+ pallet_identity::Config<IdtyData = IdtyData, IdtyIndex = IdtyIndex>
+ pallet_duniter_wot::Config
+ pallet_universal_dividend::Config,
+ pallet_universal_dividend::Config
+ pallet_quota::Config,
> sp_membership::traits::OnNewMembership<IdtyIndex> for OnNewMembershipHandler<Runtime>
{
fn on_created(idty_index: &IdtyIndex) {
// duniter-wot related actions
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.
pallet_identity::Identities::<Runtime>::mutate_exists(idty_index, |idty_val_opt| {
if let Some(ref mut idty_val) = idty_val_opt {
......@@ -107,6 +105,7 @@ impl<
+ pallet_identity::Config<IdtyData = IdtyData, IdtyIndex = IdtyIndex>
+ pallet_smith_members::Config<IdtyIndex = IdtyIndex>
+ pallet_duniter_wot::Config
+ pallet_quota::Config
+ pallet_universal_dividend::Config,
> sp_membership::traits::OnRemoveMembership<IdtyIndex> for OnRemoveMembershipHandler<Runtime>
{
......@@ -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.
weight.saturating_add(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment