mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-01 05:41:03 +00:00
Alliance pallet: retirement notice call (#11970)
* Alliance pallet: retirement notice * add alliance pallet to benchmark list for dev chain * fix type * ".git/.scripts/bench-bot.sh" pallet dev pallet_alliance * ".git/.scripts/bench-bot.sh" pallet dev pallet_alliance * link weight generated by bench for retirement_notice method * migration to clear UpForKicking storage prefix * rename migration from v1 to v0_to_v1 * Apply suggestions from code review Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com> * rename `retirement-notice to give-retirement-notice * Apply suggestions from code review Co-authored-by: Squirrel <gilescope@gmail.com> * review fixes: update doc, saturating add, BlockNumber type alias * add suffix to duratin consts *_IN_BLOCKS * ".git/.scripts/bench-bot.sh" pallet dev pallet_alliance * add negative tests (#11995) * add negative tests * remove tests powerless asserts checking against announcment origin * assert bad origin from announcement origin checks Co-authored-by: muharem <ismailov.m.h@gmail.com> Co-authored-by: command-bot <> Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com> Co-authored-by: Squirrel <gilescope@gmail.com>
This commit is contained in:
@@ -60,6 +60,8 @@
|
||||
//!
|
||||
//! #### For Members (All)
|
||||
//!
|
||||
//! - `give_retirement_notice` - Give a retirement notice and start a retirement period required to
|
||||
//! pass in order to retire.
|
||||
//! - `retire` - Retire from the Alliance and release the caller's deposit.
|
||||
//!
|
||||
//! #### For Members (Founders/Fellows)
|
||||
@@ -93,13 +95,14 @@ mod tests;
|
||||
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
mod benchmarking;
|
||||
pub mod migration;
|
||||
mod types;
|
||||
pub mod weights;
|
||||
|
||||
use frame_support::pallet_prelude::*;
|
||||
use frame_system::pallet_prelude::*;
|
||||
use sp_runtime::{
|
||||
traits::{StaticLookup, Zero},
|
||||
traits::{Saturating, StaticLookup, Zero},
|
||||
RuntimeDebug,
|
||||
};
|
||||
use sp_std::{convert::TryInto, prelude::*};
|
||||
@@ -124,6 +127,9 @@ pub use pallet::*;
|
||||
pub use types::*;
|
||||
pub use weights::*;
|
||||
|
||||
/// The log target of this pallet.
|
||||
pub const LOG_TARGET: &str = "runtime::alliance";
|
||||
|
||||
/// Simple index type for proposal counting.
|
||||
pub type ProposalIndex = u32;
|
||||
|
||||
@@ -198,6 +204,7 @@ pub enum MemberRole {
|
||||
Founder,
|
||||
Fellow,
|
||||
Ally,
|
||||
Retiring,
|
||||
}
|
||||
|
||||
/// The type of item that may be deemed unscrupulous.
|
||||
@@ -218,6 +225,7 @@ pub mod pallet {
|
||||
|
||||
#[pallet::pallet]
|
||||
#[pallet::generate_store(pub (super) trait Store)]
|
||||
#[pallet::storage_version(migration::STORAGE_VERSION)]
|
||||
pub struct Pallet<T, I = ()>(PhantomData<(T, I)>);
|
||||
|
||||
#[pallet::config]
|
||||
@@ -308,6 +316,10 @@ pub mod pallet {
|
||||
|
||||
/// Weight information for extrinsics in this pallet.
|
||||
type WeightInfo: WeightInfo;
|
||||
|
||||
/// The number of blocks a member must wait between giving a retirement notice and retiring.
|
||||
/// Supposed to be greater than time required to `kick_member`.
|
||||
type RetirementPeriod: Get<Self::BlockNumber>;
|
||||
}
|
||||
|
||||
#[pallet::error]
|
||||
@@ -324,8 +336,6 @@ pub mod pallet {
|
||||
NotAlly,
|
||||
/// Account is not a founder.
|
||||
NotFounder,
|
||||
/// This member is up for being kicked from the Alliance and cannot perform this operation.
|
||||
UpForKicking,
|
||||
/// Account does not have voting rights.
|
||||
NoVotingRights,
|
||||
/// Account is already an elevated (fellow) member.
|
||||
@@ -357,6 +367,12 @@ pub mod pallet {
|
||||
TooManyMembers,
|
||||
/// Number of announcements exceeds `MaxAnnouncementsCount`.
|
||||
TooManyAnnouncements,
|
||||
/// Account already gave retirement notice
|
||||
AlreadyRetiring,
|
||||
/// Account did not give a retirement notice required to retire.
|
||||
RetirementNoticeNotGiven,
|
||||
/// Retirement period has not passed.
|
||||
RetirementPeriodNotPassed,
|
||||
}
|
||||
|
||||
#[pallet::event]
|
||||
@@ -382,6 +398,8 @@ pub mod pallet {
|
||||
},
|
||||
/// An ally has been elevated to Fellow.
|
||||
AllyElevated { ally: T::AccountId },
|
||||
/// A member gave retirement notice and their retirement period started.
|
||||
MemberRetirementPeriodStarted { member: T::AccountId },
|
||||
/// A member has retired with its deposit unreserved.
|
||||
MemberRetired { member: T::AccountId, unreserved: Option<BalanceOf<T, I>> },
|
||||
/// A member has been kicked out with its deposit slashed.
|
||||
@@ -485,12 +503,12 @@ pub mod pallet {
|
||||
ValueQuery,
|
||||
>;
|
||||
|
||||
/// A set of members that are (potentially) being kicked out. They cannot retire until the
|
||||
/// motion is settled.
|
||||
/// A set of members who gave a retirement notice. They can retire after the end of retirement
|
||||
/// period stored as a future block number.
|
||||
#[pallet::storage]
|
||||
#[pallet::getter(fn up_for_kicking)]
|
||||
pub type UpForKicking<T: Config<I>, I: 'static = ()> =
|
||||
StorageMap<_, Blake2_128Concat, T::AccountId, bool, ValueQuery>;
|
||||
#[pallet::getter(fn retiring_members)]
|
||||
pub type RetiringMembers<T: Config<I>, I: 'static = ()> =
|
||||
StorageMap<_, Blake2_128Concat, T::AccountId, T::BlockNumber, OptionQuery>;
|
||||
|
||||
/// The current list of accounts deemed unscrupulous. These accounts non grata cannot submit
|
||||
/// candidacy.
|
||||
@@ -525,11 +543,6 @@ pub mod pallet {
|
||||
let proposor = ensure_signed(origin)?;
|
||||
ensure!(Self::has_voting_rights(&proposor), Error::<T, I>::NoVotingRights);
|
||||
|
||||
if let Some(Call::kick_member { who }) = proposal.is_sub_type() {
|
||||
let strike = T::Lookup::lookup(who.clone())?;
|
||||
<UpForKicking<T, I>>::insert(strike, true);
|
||||
}
|
||||
|
||||
T::ProposalProvider::propose_proposal(proposor, threshold, proposal, length_bound)?;
|
||||
Ok(())
|
||||
}
|
||||
@@ -783,15 +796,40 @@ pub mod pallet {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// As a member, give a retirement notice and start a retirement period required to pass in
|
||||
/// order to retire.
|
||||
#[pallet::weight(T::WeightInfo::give_retirement_notice())]
|
||||
pub fn give_retirement_notice(origin: OriginFor<T>) -> DispatchResult {
|
||||
let who = ensure_signed(origin)?;
|
||||
let role = Self::member_role_of(&who).ok_or(Error::<T, I>::NotMember)?;
|
||||
ensure!(role.ne(&MemberRole::Retiring), Error::<T, I>::AlreadyRetiring);
|
||||
|
||||
Self::remove_member(&who, role)?;
|
||||
Self::add_member(&who, MemberRole::Retiring)?;
|
||||
<RetiringMembers<T, I>>::insert(
|
||||
&who,
|
||||
frame_system::Pallet::<T>::block_number()
|
||||
.saturating_add(T::RetirementPeriod::get()),
|
||||
);
|
||||
|
||||
Self::deposit_event(Event::MemberRetirementPeriodStarted { member: who });
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// As a member, retire from the alliance and unreserve the deposit.
|
||||
/// This can only be done once you have `give_retirement_notice` and it has expired.
|
||||
#[pallet::weight(T::WeightInfo::retire())]
|
||||
pub fn retire(origin: OriginFor<T>) -> DispatchResult {
|
||||
let who = ensure_signed(origin)?;
|
||||
// A member up for kicking cannot retire.
|
||||
ensure!(!Self::is_up_for_kicking(&who), Error::<T, I>::UpForKicking);
|
||||
let retirement_period_end = RetiringMembers::<T, I>::get(&who)
|
||||
.ok_or(Error::<T, I>::RetirementNoticeNotGiven)?;
|
||||
ensure!(
|
||||
frame_system::Pallet::<T>::block_number() >= retirement_period_end,
|
||||
Error::<T, I>::RetirementPeriodNotPassed
|
||||
);
|
||||
|
||||
let role = Self::member_role_of(&who).ok_or(Error::<T, I>::NotMember)?;
|
||||
Self::remove_member(&who, role)?;
|
||||
Self::remove_member(&who, MemberRole::Retiring)?;
|
||||
<RetiringMembers<T, I>>::remove(&who);
|
||||
let deposit = DepositOf::<T, I>::take(&who);
|
||||
if let Some(deposit) = deposit {
|
||||
let err_amount = T::Currency::unreserve(&who, deposit);
|
||||
@@ -814,8 +852,6 @@ pub mod pallet {
|
||||
T::Slashed::on_unbalanced(T::Currency::slash_reserved(&member, deposit).0);
|
||||
}
|
||||
|
||||
<UpForKicking<T, I>>::remove(&member);
|
||||
|
||||
Self::deposit_event(Event::MemberKicked { member, slashed: deposit });
|
||||
Ok(())
|
||||
}
|
||||
@@ -930,11 +966,6 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
|
||||
founders.into()
|
||||
}
|
||||
|
||||
/// Check if an account's forced removal is up for consideration.
|
||||
fn is_up_for_kicking(who: &T::AccountId) -> bool {
|
||||
<UpForKicking<T, I>>::contains_key(&who)
|
||||
}
|
||||
|
||||
/// Add a user to the sorted alliance member set.
|
||||
fn add_member(who: &T::AccountId, role: MemberRole) -> DispatchResult {
|
||||
<Members<T, I>>::try_mutate(role, |members| -> DispatchResult {
|
||||
|
||||
Reference in New Issue
Block a user