-
Notifications
You must be signed in to change notification settings - Fork 857
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
Clamp benchmark ranks to respect MaxRank #7720
base: master
Are you sure you want to change the base?
Changes from all commits
55b720f
3481b97
2296b32
283bff9
cf353eb
bf7d20d
6c6ff9c
f08a7af
10e987c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0 | ||
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json | ||
|
||
title: Clamp Core Fellowship Benchmarks to Runtime MaxRank Configuration | ||
|
||
doc: | ||
- audience: Runtime Dev | ||
description: | | ||
Enables reliable benchmarking for constrained configurations like `MaxRank=1` while | ||
maintaining compatibility with larger rank ranges. | ||
|
||
crates: | ||
- name: pallet-core-fellowship | ||
bump: minor |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -163,6 +163,13 @@ impl< | |
} | ||
} | ||
|
||
pub struct ConvertU16ToU32<Inner>(PhantomData<Inner>); | ||
impl<Inner: Get<u16>> Get<u32> for ConvertU16ToU32<Inner> { | ||
fn get() -> u32 { | ||
Inner::get() as u32 | ||
} | ||
} | ||
|
||
/// The status of a single member. | ||
#[derive(Encode, Decode, Eq, PartialEq, Clone, TypeInfo, MaxEncodedLen, RuntimeDebug)] | ||
pub struct MemberStatus<BlockNumber> { | ||
|
@@ -238,15 +245,18 @@ pub mod pallet { | |
/// | ||
/// Increasing this value is supported, but decreasing it may lead to a broken state. | ||
#[pallet::constant] | ||
type MaxRank: Get<u32>; | ||
type MaxRank: Get<u16>; | ||
} | ||
|
||
pub type ParamsOf<T, I> = | ||
ParamsType<<T as Config<I>>::Balance, BlockNumberFor<T>, <T as Config<I>>::MaxRank>; | ||
pub type ParamsOf<T, I> = ParamsType< | ||
<T as Config<I>>::Balance, | ||
BlockNumberFor<T>, | ||
ConvertU16ToU32<<T as Config<I>>::MaxRank>, | ||
>; | ||
pub type PartialParamsOf<T, I> = ParamsType< | ||
Option<<T as Config<I>>::Balance>, | ||
Option<BlockNumberFor<T>>, | ||
<T as Config<I>>::MaxRank, | ||
ConvertU16ToU32<<T as Config<I>>::MaxRank>, | ||
>; | ||
pub type MemberStatusOf<T> = MemberStatus<BlockNumberFor<T>>; | ||
pub type RankOf<T, I> = <<T as Config<I>>::Members as RankedMembers>::Rank; | ||
|
@@ -523,7 +533,7 @@ pub mod pallet { | |
/// This is useful for out-of-band promotions, hence it has its own `FastPromoteOrigin` to | ||
/// be (possibly) more restrictive than `PromoteOrigin`. Note that the member must already | ||
/// be inducted. | ||
#[pallet::weight(T::WeightInfo::promote_fast(*to_rank as u32))] | ||
#[pallet::weight(T::WeightInfo::promote_fast(*to_rank))] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would need to run benchmark command for this 🙏 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why? Generally we have now these weight updates once a week, that should be fine to be done as part of them. |
||
#[pallet::call_index(10)] | ||
pub fn promote_fast( | ||
origin: OriginFor<T>, | ||
|
@@ -534,7 +544,7 @@ pub mod pallet { | |
Ok(allow_rank) => ensure!(allow_rank >= to_rank, Error::<T, I>::NoPermission), | ||
Err(origin) => ensure_root(origin)?, | ||
} | ||
ensure!(to_rank as u32 <= T::MaxRank::get(), Error::<T, I>::InvalidRank); | ||
ensure!(to_rank <= T::MaxRank::get(), Error::<T, I>::InvalidRank); | ||
let curr_rank = T::Members::rank_of(&who).ok_or(Error::<T, I>::Unranked)?; | ||
ensure!(to_rank > curr_rank, Error::<T, I>::UnexpectedRank); | ||
|
||
|
@@ -681,8 +691,8 @@ pub mod pallet { | |
/// | ||
/// Only elements in the base slice which has a new value in the new slice will be updated. | ||
pub(crate) fn set_partial_params_slice<S>( | ||
base_slice: &mut BoundedVec<S, <T as Config<I>>::MaxRank>, | ||
new_slice: BoundedVec<Option<S>, <T as Config<I>>::MaxRank>, | ||
base_slice: &mut BoundedVec<S, ConvertU16ToU32<T::MaxRank>>, | ||
new_slice: BoundedVec<Option<S>, ConvertU16ToU32<T::MaxRank>>, | ||
) { | ||
for (base_element, new_element) in base_slice.iter_mut().zip(new_slice) { | ||
if let Some(element) = new_element { | ||
|
@@ -713,9 +723,10 @@ pub mod pallet { | |
/// Rank 1 becomes index 0, rank `RANK_COUNT` becomes index `RANK_COUNT - 1`. Any rank not | ||
/// in the range `1..=RANK_COUNT` is `None`. | ||
pub(crate) fn rank_to_index(rank: RankOf<T, I>) -> Option<usize> { | ||
match TryInto::<usize>::try_into(rank) { | ||
Ok(r) if r as u32 <= <T as Config<I>>::MaxRank::get() && r > 0 => Some(r - 1), | ||
_ => return None, | ||
if rank == 0 || rank > T::MaxRank::get() { | ||
None | ||
} else { | ||
Some((rank - 1) as usize) | ||
} | ||
} | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fine for now. After the pr got merged, could you do a commit to the upstream crate that has the
Get
trait to introduce some sort ofGetInto
converter type: