From caeaf3b2d12bc3460ed68f10d2f43e529e292926 Mon Sep 17 00:00:00 2001 From: cgeek <cem.moreau@gmail.com> Date: Wed, 27 Dec 2023 20:46:12 +0100 Subject: [PATCH] refac(smith-members): SmithInactivityMaxDuration --- node/src/chain_spec/gtest.rs | 2 +- pallets/smith-members/src/lib.rs | 12 ++++++------ pallets/smith-members/src/mock.rs | 2 +- runtime/common/src/pallets_config.rs | 2 +- runtime/g1/src/parameters.rs | 2 +- runtime/gdev/src/lib.rs | 3 +-- runtime/gtest/src/parameters.rs | 2 +- 7 files changed, 12 insertions(+), 13 deletions(-) diff --git a/node/src/chain_spec/gtest.rs b/node/src/chain_spec/gtest.rs index 485e0db18..4b1ee27f2 100644 --- a/node/src/chain_spec/gtest.rs +++ b/node/src/chain_spec/gtest.rs @@ -99,7 +99,7 @@ fn get_parameters(_: &Option<GenesisParameters>) -> CommonParameters { distance_min_accessible_referees: Perbill::from_percent(80), // TODO: generalize distance_max_depth: 5, // TODO: generalize smith_sub_wot_min_cert_for_membership: parameters::SmithWotMinCertForMembership::get(), - smith_inactivity_max_duration: parameters::InactivityMaxDuration::get(), + smith_inactivity_max_duration: parameters::SmithInactivityMaxDuration::get(), smith_cert_max_by_issuer: parameters::SmithMaxByIssuer::get(), cert_cert_period: parameters::CertPeriod::get(), treasury_spend_period: <Runtime as pallet_treasury::Config>::SpendPeriod::get(), diff --git a/pallets/smith-members/src/lib.rs b/pallets/smith-members/src/lib.rs index f65e3cf4d..4d7e3325b 100644 --- a/pallets/smith-members/src/lib.rs +++ b/pallets/smith-members/src/lib.rs @@ -112,7 +112,7 @@ pub mod pallet { type MinCertForMembership: Get<u32>; /// Maximum duration of inactivity before a smith is removed #[pallet::constant] - type InactivityMaxDuration: Get<u32>; + type SmithInactivityMaxDuration: Get<u32>; } /// Events type. @@ -188,14 +188,14 @@ pub mod pallet { expires_on: if *is_online { None } else { - Some(CurrentSession::<T>::get() + T::InactivityMaxDuration::get()) + Some(CurrentSession::<T>::get() + T::SmithInactivityMaxDuration::get()) }, issued_certs: vec![], received_certs: issuers_, }, ); ExpiresOn::<T>::append( - CurrentSession::<T>::get() + T::InactivityMaxDuration::get(), + CurrentSession::<T>::get() + T::SmithInactivityMaxDuration::get(), receiver, ); } @@ -335,7 +335,7 @@ impl<T: Config> Pallet<T> { } fn do_invite_smith(issuer: T::IdtyIndex, receiver: T::IdtyIndex) { - let new_expires_on = CurrentSession::<T>::get() + T::InactivityMaxDuration::get(); + let new_expires_on = CurrentSession::<T>::get() + T::SmithInactivityMaxDuration::get(); // TODO: another way to write this? if Smiths::<T>::get(receiver).is_some() { Smiths::<T>::mutate(receiver, |maybe_smith_meta| { @@ -439,7 +439,7 @@ impl<T: Config> Pallet<T> { SmithStatus::Pending }; // expiry postponed - let new_expires_on = CurrentSession::<T>::get() + T::InactivityMaxDuration::get(); + let new_expires_on = CurrentSession::<T>::get() + T::SmithInactivityMaxDuration::get(); maybe_smith_meta.expires_on = Some(new_expires_on); Self::deposit_event(Event::<T>::CertificationReceived { idty_index: receiver, @@ -523,7 +523,7 @@ impl<T: Config> Pallet<T> { let maybe_smith_meta = maybe_smith_meta.as_mut().expect("checked earlier"); // As long as the smith is online, it cannot expire let new_expires_on = - CurrentSession::<T>::get() + T::InactivityMaxDuration::get(); + CurrentSession::<T>::get() + T::SmithInactivityMaxDuration::get(); maybe_smith_meta.expires_on = Some(new_expires_on); ExpiresOn::<T>::append(new_expires_on, idty_index); }); diff --git a/pallets/smith-members/src/mock.rs b/pallets/smith-members/src/mock.rs index c8f700312..0e525d9b4 100644 --- a/pallets/smith-members/src/mock.rs +++ b/pallets/smith-members/src/mock.rs @@ -91,7 +91,7 @@ impl pallet_smith_members::Config for Runtime { type IdtyIdOf = ConvertInto; type MinCertForMembership = ConstU32<2>; type MaxByIssuer = ConstU32<3>; - type InactivityMaxDuration = ConstU32<5>; + type SmithInactivityMaxDuration = ConstU32<5>; type OnSmithDelete = (); type IdtyIdOfAuthorityId = ConvertInto; type MemberId = u64; diff --git a/runtime/common/src/pallets_config.rs b/runtime/common/src/pallets_config.rs index bd0986770..da194a77e 100644 --- a/runtime/common/src/pallets_config.rs +++ b/runtime/common/src/pallets_config.rs @@ -531,7 +531,7 @@ macro_rules! pallets_config { type IdtyIdOf = common_runtime::providers::IdentityIndexOf<Self>; type MinCertForMembership = SmithWotMinCertForMembership; type MaxByIssuer = SmithMaxByIssuer; - type InactivityMaxDuration = InactivityMaxDuration; + type SmithInactivityMaxDuration = SmithInactivityMaxDuration; type OnSmithDelete = OnSmithDeletedHandler<Runtime>; type IdtyIdOfAuthorityId = sp_runtime::traits::ConvertInto; type MemberId = IdtyIndex; diff --git a/runtime/g1/src/parameters.rs b/runtime/g1/src/parameters.rs index e0c55b2b3..22ef4efa4 100644 --- a/runtime/g1/src/parameters.rs +++ b/runtime/g1/src/parameters.rs @@ -123,7 +123,7 @@ parameter_types! { parameter_types! { pub const SmithWotMinCertForMembership: u32 = 3; pub const SmithMaxByIssuer: u32 = 12; - pub const InactivityMaxDuration: u32 = 48; + pub const SmithInactivityMaxDuration: u32 = 48; } /*************/ diff --git a/runtime/gdev/src/lib.rs b/runtime/gdev/src/lib.rs index 1514f5f87..eb148cd25 100644 --- a/runtime/gdev/src/lib.rs +++ b/runtime/gdev/src/lib.rs @@ -267,8 +267,7 @@ common_runtime::pallets_config! { pub type SmithMaxByIssuer = pallet_duniter_test_parameters::SmithCertMaxByIssuer<Runtime>; pub type SmithWotMinCertForMembership = pallet_duniter_test_parameters::SmithWotMinCertForMembership<Runtime>; - // TODO: prefix with "Smith" - pub type InactivityMaxDuration = + pub type SmithInactivityMaxDuration = pallet_duniter_test_parameters::SmithInactivityMaxDuration<Runtime>; impl pallet_duniter_test_parameters::Config for Runtime { diff --git a/runtime/gtest/src/parameters.rs b/runtime/gtest/src/parameters.rs index e91c3df18..252ae211a 100644 --- a/runtime/gtest/src/parameters.rs +++ b/runtime/gtest/src/parameters.rs @@ -124,7 +124,7 @@ parameter_types! { parameter_types! { pub const SmithWotMinCertForMembership: u32 = 3; pub const SmithMaxByIssuer: u32 = 100; - pub const InactivityMaxDuration: u32 = 48; + pub const SmithInactivityMaxDuration: u32 = 48; } /*************/ -- GitLab