Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
6e388f0
Add set_partial_params dispatchable function
chungquantin Mar 26, 2024
64ca32d
Optimize set_partial_params and assert ParamsChanged event
chungquantin Mar 27, 2024
3cf3103
Update documentation and add prdoc
chungquantin Mar 28, 2024
68fe4ff
Reformat the prdoc
chungquantin Mar 28, 2024
1859790
Refractor partial_params method to avoid unwrap()
chungquantin Apr 18, 2024
e7c3307
Add weight and benchmark for set_partial_params
chungquantin Apr 18, 2024
efe9457
Merge branch 'master' into chungquantin/fellowship_core_set_params
chungquantin Apr 18, 2024
cdab265
Config set_partial_params in westend collectives
chungquantin Apr 18, 2024
0c558c6
Merge branch 'chungquantin/fellowship_core_set_params' of https://git…
chungquantin Apr 18, 2024
3238144
Merge branch 'master' into chungquantin/fellowship_core_set_params
chungquantin May 27, 2024
c3d9474
Update lib.rs
chungquantin May 27, 2024
d22c388
Migrate to BoundedVec with configured MaxRank
chungquantin Jun 3, 2024
cc4f5b5
Merge branch 'master' into chungquantin/fellowship_core_set_params
chungquantin Jun 3, 2024
a85b371
Update substrate/frame/core-fellowship/src/lib.rs
chungquantin Jun 3, 2024
2f8c071
Fix benchmarking code for the set_partial_params
chungquantin Jun 4, 2024
a77b512
Merge branch 'chungquantin/fellowship_core_set_params' of https://git…
chungquantin Jun 4, 2024
149dd53
hotfix benchmarking for set_partial_params
chungquantin Jun 15, 2024
71f9dee
Update prdoc/pr_3843.prdoc
chungquantin Jun 16, 2024
6f02d9a
Merge branch 'master' into chungquantin/fellowship_core_set_params
chungquantin Jun 16, 2024
488b532
fix prdoc style
chungquantin Jun 16, 2024
229c87b
add collectives-westend-runtime to prdoc
chungquantin Jun 16, 2024
087d00d
Update substrate/frame/core-fellowship/src/lib.rs
chungquantin Jun 18, 2024
0a00ddd
Format benchmarking.rs
chungquantin Jun 18, 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
46 changes: 46 additions & 0 deletions substrate/frame/core-fellowship/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ pub mod pallet {
}

pub type ParamsOf<T, I> = ParamsType<<T as Config<I>>::Balance, BlockNumberFor<T>, RANK_COUNT>;
pub type PartialParamsOf<T, I> =
ParamsType<Option<<T as Config<I>>::Balance>, Option<BlockNumberFor<T>>, RANK_COUNT>;
pub type MemberStatusOf<T> = MemberStatus<BlockNumberFor<T>>;
pub type RankOf<T, I> = <<T as Config<I>>::Members as RankedMembers>::Rank;

Expand Down Expand Up @@ -530,9 +532,53 @@ pub mod pallet {

Ok(Pays::No.into())
}

/// Set the parameters.
///
/// - `origin`: An origin complying with `ParamsOrigin` or root.
/// - `params`: The new parameters for the pallet.
#[pallet::weight(T::WeightInfo::set_params())]
Comment thread
chungquantin marked this conversation as resolved.
Outdated
#[pallet::call_index(9)]
pub fn set_partial_params(
origin: OriginFor<T>,
partial_params: Box<PartialParamsOf<T, I>>,
) -> DispatchResult {
T::ParamsOrigin::ensure_origin_or_root(origin)?;
let params = Params::<T, I>::mutate(|p| {
Self::set_partial_params_slice(&mut p.active_salary, partial_params.active_salary);
Self::set_partial_params_slice(
&mut p.passive_salary,
partial_params.passive_salary,
);
Self::set_partial_params_slice(
&mut p.demotion_period,
partial_params.demotion_period,
);
Self::set_partial_params_slice(
&mut p.min_promotion_period,
partial_params.min_promotion_period,
);
if let Some(new_offboard_timeout) = partial_params.offboard_timeout {
p.offboard_timeout = new_offboard_timeout;
}
return p.clone();
Comment thread
chungquantin marked this conversation as resolved.
Outdated
});
Self::deposit_event(Event::<T, I>::ParamsChanged { params });
Ok(())
}
}

impl<T: Config<I>, I: 'static> Pallet<T, I> {
pub(crate) fn set_partial_params_slice<S>(
base_vec: &mut [S; RANK_COUNT],
new_vec: [Option<S>; RANK_COUNT],
) {
for (base_element, new_element) in base_vec.iter_mut().zip(new_vec) {
if new_element.is_some() {
*base_element = new_element.unwrap();
Comment thread
chungquantin marked this conversation as resolved.
Outdated
}
}
}
/// Convert a rank into a `0..RANK_COUNT` index suitable for the arrays in Params.
///
/// Rank 1 becomes index 0, rank `RANK_COUNT` becomes index `RANK_COUNT - 1`. Any rank not
Expand Down
34 changes: 34 additions & 0 deletions substrate/frame/core-fellowship/src/tests/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,40 @@ fn set_params_works() {
});
}

#[test]
fn set_partial_params_works() {
new_test_ext().execute_with(|| {
let params = ParamsType {
active_salary: [None; 9],
passive_salary: [None; 9],
demotion_period: [None, Some(10), None, None, None, None, None, None, None],
min_promotion_period: [None; 9],
offboard_timeout: Some(2),
};
assert_noop!(
CoreFellowship::set_partial_params(signed(2), Box::new(params.clone())),
DispatchError::BadOrigin
);
assert_ok!(CoreFellowship::set_partial_params(signed(1), Box::new(params)));
Comment thread
chungquantin marked this conversation as resolved.

// Update params from the base params value declared in `new_test_ext`
let raw_updated_params = ParamsType {
active_salary: [10, 20, 30, 40, 50, 60, 70, 80, 90],
passive_salary: [1, 2, 3, 4, 5, 6, 7, 8, 9],
demotion_period: [2, 10, 6, 8, 10, 12, 14, 16, 18],
min_promotion_period: [3, 6, 9, 12, 15, 18, 21, 24, 27],
offboard_timeout: 2,
};
// Updated params stored in Params storage value
let updated_params = Params::<Test>::get();
assert_eq!(raw_updated_params, updated_params);

System::assert_last_event(
Event::<Test, _>::ParamsChanged { params: updated_params }.into(),
);
});
}

#[test]
fn induct_works() {
new_test_ext().execute_with(|| {
Expand Down