Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exchange member with a new account and same rank in the ranked collec… #2587

Merged
merged 41 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
07b93db
exchange member with a new account and same rank in the ranked collec…
dharjeezy Dec 3, 2023
66b2f08
Merge branch 'master' into dami/change-account
dharjeezy Dec 11, 2023
fbf91f3
address concerns and benchmarks
dharjeezy Dec 11, 2023
8d68ca5
Merge remote-tracking branch 'origin/dami/change-account' into dami/c…
dharjeezy Dec 11, 2023
cd50907
change comment
dharjeezy Dec 11, 2023
05f6ee6
fmt
dharjeezy Dec 11, 2023
255ad1f
weight
dharjeezy Dec 21, 2023
4df260b
Merge branch 'master' into dami/change-account
dharjeezy Dec 21, 2023
413ce7f
Merge branch 'master' into dami/change-account
dharjeezy Dec 21, 2023
89a8c29
Merge branch 'master' into dami/change-account
dharjeezy Jan 2, 2024
6dc14e9
Merge branch 'paritytech:master' into dami/change-account
dharjeezy Jan 17, 2024
279ed33
Merge branch 'master' of https://github.com/dharjeezy/polkadot-sdk in…
dharjeezy Jan 18, 2024
f7d68ef
boolean flag to toggle emission of events
dharjeezy Jan 18, 2024
065c619
Merge remote-tracking branch 'origin/dami/change-account' into dami/c…
dharjeezy Jan 18, 2024
ec954ad
doc
dharjeezy Jan 18, 2024
205c2d8
Merge branch 'master' into dami/change-account
dharjeezy Jan 18, 2024
3d0c8f7
subtle changes
dharjeezy Jan 21, 2024
b92210e
Merge remote-tracking branch 'origin/dami/change-account' into dami/c…
dharjeezy Jan 21, 2024
3115f39
Merge branch 'master' into dami/change-account
dharjeezy Jan 21, 2024
fd68eb1
Merge branch 'master' into dami/change-account
dharjeezy Jan 22, 2024
59bb68a
Merge branch 'master' into dami/change-account
dharjeezy Jan 24, 2024
a33fe94
Merge branch 'master' into dami/change-account
dharjeezy Jan 24, 2024
b7078b0
Merge branch 'master' of https://github.com/paritytech/polkadot-sdk i…
Jan 24, 2024
7d25b5c
".git/.scripts/commands/bench/bench.sh" --subcommand=runtime --runtim…
Jan 24, 2024
fdbbe76
nit
dharjeezy Jan 24, 2024
2758890
Merge remote-tracking branch 'origin/dami/change-account' into dami/c…
dharjeezy Jan 24, 2024
239831c
Merge branch 'master' into dami/change-account
dharjeezy Jan 25, 2024
99fc1b7
nit
dharjeezy Jan 25, 2024
76963a1
Merge remote-tracking branch 'origin/dami/change-account' into dami/c…
dharjeezy Jan 25, 2024
5c6b2cf
nit
dharjeezy Jan 25, 2024
0cb7494
nit
dharjeezy Jan 25, 2024
f58c20a
nit
dharjeezy Jan 25, 2024
0da55a7
Merge branch 'master' into dami/change-account
dharjeezy Jan 25, 2024
7ed5a3d
nit
dharjeezy Jan 26, 2024
598c2bc
Merge branch 'master' into dami/change-account
dharjeezy Jan 26, 2024
3f03aaf
Merge branch 'master' into dami/change-account
dharjeezy Jan 26, 2024
6e9e14d
fmt
ggwpez Jan 26, 2024
0920307
Add prdoc
ggwpez Jan 26, 2024
43773cb
Merge branch 'master' into dami/change-account
ggwpez Jan 26, 2024
684beb3
helper method
dharjeezy Jan 30, 2024
754184f
Merge branch 'master' into dami/change-account
dharjeezy Jan 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions polkadot/runtime/rococo/src/governance/fellowship.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,11 @@ impl pallet_ranked_collective::Config<FellowshipCollectiveInstance> for Runtime
TryMapSuccess<origins::EnsureFellowship, CheckedReduceBy<ConstU16<2>>>,
>,
>;
// Exchange is by any of:
// - Root can exchange arbitrarily.
// - the Fellows origin;
type ExchangeOrigin =
EitherOf<EnsureRootWithSuccess<Self::AccountId, ConstU16<65535>>, Fellows>;
type Polls = FellowshipReferenda;
type MinRankOfClass = sp_runtime::traits::Identity;
type VoteWeight = pallet_ranked_collective::Geometric;
Expand Down
91 changes: 54 additions & 37 deletions polkadot/runtime/rococo/src/weights/pallet_ranked_collective.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
//! Autogenerated weights for `pallet_ranked_collective`
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2023-07-11, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! DATE: 2024-01-24, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! WORST CASE MAP SIZE: `1000000`
//! HOSTNAME: `runner-xerhrdyb-project-163-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz`
//! EXECUTION: `Some(Wasm)`, WASM-EXECUTION: `Compiled`, CHAIN: `Some("rococo-dev")`, DB CACHE: 1024
//! HOSTNAME: `runner-grjcggob-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz`
//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("rococo-dev")`, DB CACHE: 1024

// Executed Command:
// target/production/polkadot
Expand All @@ -29,14 +29,13 @@
// --steps=50
// --repeat=20
// --extrinsic=*
// --execution=wasm
// --wasm-execution=compiled
// --heap-pages=4096
// --json-file=/builds/parity/mirrors/polkadot/.git/.artifacts/bench.json
// --json-file=/builds/parity/mirrors/polkadot-sdk/.git/.artifacts/bench.json
// --pallet=pallet_ranked_collective
// --chain=rococo-dev
// --header=./file_header.txt
// --output=./runtime/rococo/src/weights/
// --header=./polkadot/file_header.txt
// --output=./polkadot/runtime/rococo/src/weights/

#![cfg_attr(rustfmt, rustfmt_skip)]
#![allow(unused_parens)]
Expand All @@ -61,8 +60,8 @@ impl<T: frame_system::Config> pallet_ranked_collective::WeightInfo for WeightInf
// Proof Size summary in bytes:
// Measured: `42`
// Estimated: `3507`
// Minimum execution time: 17_632_000 picoseconds.
Weight::from_parts(18_252_000, 0)
// Minimum execution time: 13_480_000 picoseconds.
Weight::from_parts(13_786_000, 0)
.saturating_add(Weight::from_parts(0, 3507))
.saturating_add(T::DbWeight::get().reads(2))
.saturating_add(T::DbWeight::get().writes(4))
Expand All @@ -71,24 +70,24 @@ impl<T: frame_system::Config> pallet_ranked_collective::WeightInfo for WeightInf
/// Proof: `FellowshipCollective::Members` (`max_values`: None, `max_size`: Some(42), added: 2517, mode: `MaxEncodedLen`)
/// Storage: `FellowshipCollective::MemberCount` (r:11 w:11)
/// Proof: `FellowshipCollective::MemberCount` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`)
/// Storage: `FellowshipCollective::IdToIndex` (r:11 w:11)
/// Storage: `FellowshipCollective::IdToIndex` (r:11 w:22)
/// Proof: `FellowshipCollective::IdToIndex` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`)
/// Storage: `FellowshipCollective::IndexToId` (r:11 w:11)
/// Storage: `FellowshipCollective::IndexToId` (r:11 w:22)
/// Proof: `FellowshipCollective::IndexToId` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`)
/// The range of component `r` is `[0, 10]`.
fn remove_member(r: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `517 + r * (281 ±0)`
// Measured: `516 + r * (281 ±0)`
// Estimated: `3519 + r * (2529 ±0)`
// Minimum execution time: 27_960_000 picoseconds.
Weight::from_parts(30_632_408, 0)
// Minimum execution time: 28_771_000 picoseconds.
Weight::from_parts(29_256_825, 0)
.saturating_add(Weight::from_parts(0, 3519))
// Standard Error: 22_806
.saturating_add(Weight::from_parts(13_000_901, 0).saturating_mul(r.into()))
// Standard Error: 21_594
.saturating_add(Weight::from_parts(14_649_527, 0).saturating_mul(r.into()))
.saturating_add(T::DbWeight::get().reads(4))
.saturating_add(T::DbWeight::get().reads((3_u64).saturating_mul(r.into())))
.saturating_add(T::DbWeight::get().writes(4))
.saturating_add(T::DbWeight::get().writes((3_u64).saturating_mul(r.into())))
.saturating_add(T::DbWeight::get().writes(6))
.saturating_add(T::DbWeight::get().writes((5_u64).saturating_mul(r.into())))
.saturating_add(Weight::from_parts(0, 2529).saturating_mul(r.into()))
}
/// Storage: `FellowshipCollective::Members` (r:1 w:1)
Expand All @@ -104,34 +103,34 @@ impl<T: frame_system::Config> pallet_ranked_collective::WeightInfo for WeightInf
// Proof Size summary in bytes:
// Measured: `214 + r * (17 ±0)`
// Estimated: `3507`
// Minimum execution time: 19_900_000 picoseconds.
Weight::from_parts(20_908_316, 0)
// Minimum execution time: 16_117_000 picoseconds.
Weight::from_parts(16_978_453, 0)
.saturating_add(Weight::from_parts(0, 3507))
// Standard Error: 4_878
.saturating_add(Weight::from_parts(330_385, 0).saturating_mul(r.into()))
// Standard Error: 4_511
.saturating_add(Weight::from_parts(324_261, 0).saturating_mul(r.into()))
.saturating_add(T::DbWeight::get().reads(2))
.saturating_add(T::DbWeight::get().writes(4))
}
/// Storage: `FellowshipCollective::Members` (r:1 w:1)
/// Proof: `FellowshipCollective::Members` (`max_values`: None, `max_size`: Some(42), added: 2517, mode: `MaxEncodedLen`)
/// Storage: `FellowshipCollective::MemberCount` (r:1 w:1)
/// Proof: `FellowshipCollective::MemberCount` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`)
/// Storage: `FellowshipCollective::IdToIndex` (r:1 w:1)
/// Storage: `FellowshipCollective::IdToIndex` (r:1 w:2)
/// Proof: `FellowshipCollective::IdToIndex` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`)
/// Storage: `FellowshipCollective::IndexToId` (r:1 w:1)
/// Storage: `FellowshipCollective::IndexToId` (r:1 w:2)
/// Proof: `FellowshipCollective::IndexToId` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`)
/// The range of component `r` is `[0, 10]`.
fn demote_member(r: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `532 + r * (72 ±0)`
// Estimated: `3519`
// Minimum execution time: 27_697_000 picoseconds.
Weight::from_parts(30_341_815, 0)
// Minimum execution time: 28_995_000 picoseconds.
Weight::from_parts(31_343_215, 0)
.saturating_add(Weight::from_parts(0, 3519))
// Standard Error: 17_010
.saturating_add(Weight::from_parts(642_213, 0).saturating_mul(r.into()))
// Standard Error: 16_438
.saturating_add(Weight::from_parts(637_462, 0).saturating_mul(r.into()))
.saturating_add(T::DbWeight::get().reads(4))
.saturating_add(T::DbWeight::get().writes(4))
.saturating_add(T::DbWeight::get().writes(6))
}
/// Storage: `FellowshipCollective::Members` (r:1 w:0)
/// Proof: `FellowshipCollective::Members` (`max_values`: None, `max_size`: Some(42), added: 2517, mode: `MaxEncodedLen`)
Expand All @@ -143,10 +142,10 @@ impl<T: frame_system::Config> pallet_ranked_collective::WeightInfo for WeightInf
/// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(38963), added: 41438, mode: `MaxEncodedLen`)
fn vote() -> Weight {
// Proof Size summary in bytes:
// Measured: `638`
// Measured: `603`
// Estimated: `83866`
// Minimum execution time: 48_275_000 picoseconds.
Weight::from_parts(49_326_000, 0)
// Minimum execution time: 38_820_000 picoseconds.
Weight::from_parts(40_240_000, 0)
.saturating_add(Weight::from_parts(0, 83866))
.saturating_add(T::DbWeight::get().reads(5))
.saturating_add(T::DbWeight::get().writes(4))
Expand All @@ -160,16 +159,34 @@ impl<T: frame_system::Config> pallet_ranked_collective::WeightInfo for WeightInf
/// The range of component `n` is `[0, 100]`.
fn cleanup_poll(n: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `434 + n * (50 ±0)`
// Measured: `400 + n * (50 ±0)`
// Estimated: `4365 + n * (2540 ±0)`
// Minimum execution time: 15_506_000 picoseconds.
Weight::from_parts(17_634_029, 0)
// Minimum execution time: 12_972_000 picoseconds.
Weight::from_parts(15_829_333, 0)
.saturating_add(Weight::from_parts(0, 4365))
// Standard Error: 2_117
.saturating_add(Weight::from_parts(1_126_879, 0).saturating_mul(n.into()))
// Standard Error: 1_754
.saturating_add(Weight::from_parts(1_116_520, 0).saturating_mul(n.into()))
.saturating_add(T::DbWeight::get().reads(2))
.saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(n.into())))
.saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(n.into())))
.saturating_add(Weight::from_parts(0, 2540).saturating_mul(n.into()))
}
/// Storage: `FellowshipCollective::Members` (r:2 w:2)
/// Proof: `FellowshipCollective::Members` (`max_values`: None, `max_size`: Some(42), added: 2517, mode: `MaxEncodedLen`)
/// Storage: `FellowshipCollective::MemberCount` (r:2 w:2)
/// Proof: `FellowshipCollective::MemberCount` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`)
/// Storage: `FellowshipCollective::IdToIndex` (r:2 w:4)
/// Proof: `FellowshipCollective::IdToIndex` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`)
/// Storage: `FellowshipCollective::IndexToId` (r:0 w:2)
/// Proof: `FellowshipCollective::IndexToId` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`)
fn exchange_member() -> Weight {
// Proof Size summary in bytes:
// Measured: `337`
// Estimated: `6048`
// Minimum execution time: 44_601_000 picoseconds.
Weight::from_parts(45_714_000, 0)
.saturating_add(Weight::from_parts(0, 6048))
.saturating_add(T::DbWeight::get().reads(6))
.saturating_add(T::DbWeight::get().writes(10))
}
}
1 change: 1 addition & 0 deletions substrate/bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,7 @@ impl pallet_ranked_collective::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type PromoteOrigin = EnsureRootWithSuccess<AccountId, ConstU16<65535>>;
type DemoteOrigin = EnsureRootWithSuccess<AccountId, ConstU16<65535>>;
type ExchangeOrigin = EnsureRootWithSuccess<AccountId, ConstU16<65535>>;
type Polls = RankedPolls;
type MinRankOfClass = traits::Identity;
type VoteWeight = pallet_ranked_collective::Geometric;
Expand Down
15 changes: 15 additions & 0 deletions substrate/frame/ranked-collective/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,5 +173,20 @@ benchmarks_instance_pallet! {
assert_eq!(Voting::<T, I>::iter().count(), 0);
}

exchange_member {
let who = make_member::<T, I>(1);
let who_lookup = T::Lookup::unlookup(who.clone());
let new_who = account::<T::AccountId>("new-member", 0, SEED);
let new_who_lookup = T::Lookup::unlookup(new_who.clone());
let origin =
T::ExchangeOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
let call = Call::<T, I>::exchange_member { who: who_lookup, new_who:new_who_lookup};
}: { call.dispatch_bypass_filter(origin)? }
ggwpez marked this conversation as resolved.
Show resolved Hide resolved
verify {
assert_eq!(Members::<T, I>::get(&new_who).unwrap().rank, 1);
assert_eq!(Members::<T, I>::get(&who), None);
assert_last_event::<T, I>(Event::MemberExchanged { who, new_who }.into());
}

impl_benchmark_test_suite!(RankedCollective, crate::tests::new_test_ext(), crate::tests::Test);
}
72 changes: 60 additions & 12 deletions substrate/frame/ranked-collective/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ impl<T: Config<I>, I: 'static, M: GetMaxVoters<Class = ClassOf<T, I>>>
crate::Pallet::<T, I>::do_add_member_to_rank(
who,
T::MinRankOfClass::convert(class.clone()),
true,
)
.expect("could not add members for benchmarks");
}
Expand Down Expand Up @@ -299,7 +300,7 @@ impl<T: Config<I>, I: 'static> EnsureOriginWithArg<T::RuntimeOrigin, Rank> for E
#[cfg(feature = "runtime-benchmarks")]
fn try_successful_origin(min_rank: &Rank) -> Result<T::RuntimeOrigin, ()> {
let who = frame_benchmarking::account::<T::AccountId>("successful_origin", 0, 0);
crate::Pallet::<T, I>::do_add_member_to_rank(who.clone(), *min_rank)
crate::Pallet::<T, I>::do_add_member_to_rank(who.clone(), *min_rank, true)
.expect("Could not add members for benchmarks");
Ok(frame_system::RawOrigin::Signed(who).into())
}
Expand Down Expand Up @@ -352,7 +353,7 @@ impl<T: Config<I>, I: 'static, const MIN_RANK: u16> EnsureOrigin<T::RuntimeOrigi
#[cfg(feature = "runtime-benchmarks")]
fn try_successful_origin() -> Result<T::RuntimeOrigin, ()> {
let who = frame_benchmarking::account::<T::AccountId>("successful_origin", 0, 0);
crate::Pallet::<T, I>::do_add_member_to_rank(who.clone(), MIN_RANK)
crate::Pallet::<T, I>::do_add_member_to_rank(who.clone(), MIN_RANK, true)
.expect("Could not add members for benchmarks");
Ok(frame_system::RawOrigin::Signed(who).into())
}
Expand Down Expand Up @@ -390,6 +391,9 @@ pub mod pallet {
/// maximum rank *from which* the demotion/removal may be.
type DemoteOrigin: EnsureOrigin<Self::RuntimeOrigin, Success = Rank>;

/// The origin that can swap the account of a member.
type ExchangeOrigin: EnsureOrigin<Self::RuntimeOrigin>;

/// The polling system used for our voting.
type Polls: Polling<TallyOf<Self, I>, Votes = Votes, Moment = BlockNumberFor<Self>>;

Expand Down Expand Up @@ -454,6 +458,8 @@ pub mod pallet {
/// The member `who` has voted for the `poll` with the given `vote` leading to an updated
/// `tally`.
Voted { who: T::AccountId, poll: PollIndexOf<T, I>, vote: VoteRecord, tally: TallyOf<T, I> },
dharjeezy marked this conversation as resolved.
Show resolved Hide resolved
/// The member `who` had their `AccountId` changed to `new_who`.
MemberExchanged { who: T::AccountId, new_who: T::AccountId },
}

#[pallet::error]
Expand All @@ -476,6 +482,8 @@ pub mod pallet {
InvalidWitness,
/// The origin is not sufficiently privileged to do the operation.
NoPermission,
/// The new member to exchange is the same as the old member
SameMember,
}

#[pallet::call]
Expand All @@ -492,7 +500,7 @@ pub mod pallet {
pub fn add_member(origin: OriginFor<T>, who: AccountIdLookupOf<T>) -> DispatchResult {
let _ = T::PromoteOrigin::ensure_origin(origin)?;
let who = T::Lookup::lookup(who)?;
Self::do_add_member(who)
Self::do_add_member(who, true)
}

/// Increment the rank of an existing member by one.
Expand All @@ -506,7 +514,7 @@ pub mod pallet {
pub fn promote_member(origin: OriginFor<T>, who: AccountIdLookupOf<T>) -> DispatchResult {
let max_rank = T::PromoteOrigin::ensure_origin(origin)?;
let who = T::Lookup::lookup(who)?;
Self::do_promote_member(who, Some(max_rank))
Self::do_promote_member(who, Some(max_rank), true)
}

/// Decrement the rank of an existing member by one. If the member is already at rank zero,
Expand Down Expand Up @@ -650,6 +658,37 @@ pub mod pallet {
pays_fee: Pays::No,
})
}

/// Exchanges a member with a new account and the same existing rank.
///
/// - `origin`: Must be the `ExchangeOrigin`.
/// - `who`: Account of existing member of rank greater than zero to be exchanged.
/// - `new_who`: New Account of existing member of rank greater than zero to exchanged to.
#[pallet::call_index(6)]
#[pallet::weight(T::WeightInfo::exchange_member())]
pub fn exchange_member(
origin: OriginFor<T>,
who: AccountIdLookupOf<T>,
new_who: AccountIdLookupOf<T>,
) -> DispatchResult {
T::ExchangeOrigin::ensure_origin(origin)?;
let who = T::Lookup::lookup(who)?;
dharjeezy marked this conversation as resolved.
Show resolved Hide resolved
let new_who = T::Lookup::lookup(new_who)?;

ensure!(who != new_who, Error::<T, I>::SameMember);

let MemberRecord { rank, .. } = Self::ensure_member(&who)?;

for r in 0..=rank {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you make an equivalent of do_remove_member_to_rank that does these two operations, it would be a good counterpart to do_add_member_to_rank, it would make the code a bit nicer, and you can use it in other places as well.

Self::remove_from_rank(&who, r)?;
}
Members::<T, I>::remove(&who);

Self::do_add_member_to_rank(new_who.clone(), rank, false)?;

Self::deposit_event(Event::MemberExchanged { who, new_who });
bkchr marked this conversation as resolved.
Show resolved Hide resolved
Ok(())
}
}

impl<T: Config<I>, I: 'static> Pallet<T, I> {
Expand Down Expand Up @@ -683,7 +722,7 @@ pub mod pallet {
/// Adds a member into the ranked collective at level 0.
///
/// No origin checks are executed.
pub fn do_add_member(who: T::AccountId) -> DispatchResult {
pub fn do_add_member(who: T::AccountId, emit_event: bool) -> DispatchResult {
ensure!(!Members::<T, I>::contains_key(&who), Error::<T, I>::AlreadyMember);
let index = MemberCount::<T, I>::get(0);
let count = index.checked_add(1).ok_or(Overflow)?;
Expand All @@ -692,7 +731,9 @@ pub mod pallet {
IdToIndex::<T, I>::insert(0, &who, index);
IndexToId::<T, I>::insert(0, index, &who);
MemberCount::<T, I>::insert(0, count);
Self::deposit_event(Event::MemberAdded { who });
if emit_event {
Self::deposit_event(Event::MemberAdded { who });
}
Ok(())
}

Expand All @@ -703,6 +744,7 @@ pub mod pallet {
pub fn do_promote_member(
who: T::AccountId,
maybe_max_rank: Option<Rank>,
emit_event: bool,
) -> DispatchResult {
let record = Self::ensure_member(&who)?;
let rank = record.rank.checked_add(1).ok_or(Overflow)?;
Expand All @@ -714,7 +756,9 @@ pub mod pallet {
IdToIndex::<T, I>::insert(rank, &who, index);
IndexToId::<T, I>::insert(rank, index, &who);
Members::<T, I>::insert(&who, MemberRecord { rank });
Self::deposit_event(Event::RankChanged { who, rank });
if emit_event {
Self::deposit_event(Event::RankChanged { who, rank });
}
Ok(())
}

Expand Down Expand Up @@ -747,10 +791,14 @@ pub mod pallet {

/// Add a member to the rank collective, and continue to promote them until a certain rank
/// is reached.
pub fn do_add_member_to_rank(who: T::AccountId, rank: Rank) -> DispatchResult {
Self::do_add_member(who.clone())?;
pub fn do_add_member_to_rank(
who: T::AccountId,
rank: Rank,
emit_event: bool,
) -> DispatchResult {
Self::do_add_member(who.clone(), emit_event)?;
for _ in 0..rank {
Self::do_promote_member(who.clone(), None)?;
Self::do_promote_member(who.clone(), None, emit_event)?;
}
Ok(())
}
Expand Down Expand Up @@ -778,11 +826,11 @@ pub mod pallet {
}

fn induct(who: &Self::AccountId) -> DispatchResult {
Self::do_add_member(who.clone())
Self::do_add_member(who.clone(), true)
}

fn promote(who: &Self::AccountId) -> DispatchResult {
Self::do_promote_member(who.clone(), None)
Self::do_promote_member(who.clone(), None, true)
}

fn demote(who: &Self::AccountId) -> DispatchResult {
Expand Down
Loading
Loading