mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-23 20:05:49 +00:00
[FRAME] Make core-fellowship ans salary work for swapped members (#3156)
Fixup for https://github.com/paritytech/polkadot-sdk/pull/2587 to make the `core-fellowship` crate work with swapped members. Adds a `MemberSwappedHandler` to the `ranked-collective` pallet that are implemented by `core-fellowship+salary`. There is are exhaustive tests [here](https://github.com/paritytech/polkadot-sdk/blob/72aa7ac17a0e5b16faab5d2992aa2db2e01b05d0/substrate/frame/core-fellowship/src/tests/integration.rs#L338) and [here](https://github.com/paritytech/polkadot-sdk/blob/ab3cdb05a5ebc1ff841f8dda67edef0ea40bbba5/substrate/frame/salary/src/tests/integration.rs#L224) to check that adding member `1` is equivalent to adding member `0` and then swapping. --------- Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
This commit is contained in:
committed by
GitHub
parent
6ea472ad5a
commit
07e55006ad
@@ -54,7 +54,10 @@ use sp_std::{marker::PhantomData, prelude::*};
|
||||
use frame_support::{
|
||||
dispatch::{DispatchResultWithPostInfo, PostDispatchInfo},
|
||||
ensure, impl_ensure_origin_with_arg_ignoring_arg,
|
||||
traits::{EnsureOrigin, EnsureOriginWithArg, PollStatus, Polling, RankedMembers, VoteTally},
|
||||
traits::{
|
||||
EnsureOrigin, EnsureOriginWithArg, PollStatus, Polling, RankedMembers,
|
||||
RankedMembersSwapHandler, VoteTally,
|
||||
},
|
||||
CloneNoBound, EqNoBound, PartialEqNoBound, RuntimeDebugNoBound,
|
||||
};
|
||||
|
||||
@@ -365,6 +368,13 @@ impl_ensure_origin_with_arg_ignoring_arg! {
|
||||
{}
|
||||
}
|
||||
|
||||
/// Helper functions to setup benchmarking.
|
||||
#[impl_trait_for_tuples::impl_for_tuples(8)]
|
||||
pub trait BenchmarkSetup<AccountId> {
|
||||
/// Ensure that this member is registered correctly.
|
||||
fn ensure_member(acc: &AccountId);
|
||||
}
|
||||
|
||||
#[frame_support::pallet]
|
||||
pub mod pallet {
|
||||
use super::*;
|
||||
@@ -402,11 +412,21 @@ pub mod pallet {
|
||||
/// "a rank of at least the poll class".
|
||||
type MinRankOfClass: Convert<ClassOf<Self, I>, Rank>;
|
||||
|
||||
/// An external handler that will be notified when two members are swapped.
|
||||
type MemberSwappedHandler: RankedMembersSwapHandler<
|
||||
<Pallet<Self, I> as RankedMembers>::AccountId,
|
||||
<Pallet<Self, I> as RankedMembers>::Rank,
|
||||
>;
|
||||
|
||||
/// Convert a rank_delta into a number of votes the rank gets.
|
||||
///
|
||||
/// Rank_delta is defined as the number of ranks above the minimum required to take part
|
||||
/// in the poll.
|
||||
type VoteWeight: Convert<Rank, Votes>;
|
||||
|
||||
/// Setup a member for benchmarking.
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
type BenchmarkSetup: BenchmarkSetup<Self::AccountId>;
|
||||
}
|
||||
|
||||
/// The number of members in the collective who have at least the rank according to the index
|
||||
@@ -679,7 +699,12 @@ pub mod pallet {
|
||||
Self::do_remove_member_from_rank(&who, rank)?;
|
||||
Self::do_add_member_to_rank(new_who.clone(), rank, false)?;
|
||||
|
||||
Self::deposit_event(Event::MemberExchanged { who, new_who });
|
||||
Self::deposit_event(Event::MemberExchanged {
|
||||
who: who.clone(),
|
||||
new_who: new_who.clone(),
|
||||
});
|
||||
T::MemberSwappedHandler::swapped(&who, &new_who, rank);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user