Skip to content

Commit

Permalink
remove unused page_size fn arg + fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
re-gius committed Dec 19, 2024
1 parent 3702ce5 commit 489fc9d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
3 changes: 1 addition & 2 deletions substrate/frame/staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1200,8 +1200,7 @@ impl<T: Config> EraInfo<T> {
.defensive_saturating_add((page_size as usize).defensive_saturating_sub(1))
.saturating_div(page_size as usize);

let (exposure_metadata, exposure_pages) =
exposure.into_pages::<T::MaxExposurePageSize>(page_size);
let (exposure_metadata, exposure_pages) = exposure.into_pages::<T::MaxExposurePageSize>();
defensive_assert!(exposure_pages.len() == expected_page_count, "unexpected page count");

<ErasStakersOverview<T>>::insert(era, &validator, &exposure_metadata);
Expand Down
3 changes: 2 additions & 1 deletion substrate/frame/staking/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6574,10 +6574,11 @@ fn can_page_exposure() {
Exposure { total: total_stake, own: own_stake, others };

// when
MaxExposurePageSize::set(3);
let (exposure_metadata, exposure_page): (
PagedExposureMetadata<Balance>,
Vec<ExposurePage<AccountId, Balance, MaxExposurePageSize>>,
) = exposure.clone().into_pages::<MaxExposurePageSize>(3);
) = exposure.clone().into_pages::<MaxExposurePageSize>();

// then
// 7 pages of nominators.
Expand Down
7 changes: 4 additions & 3 deletions substrate/primitives/staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,15 +382,16 @@ impl<AccountId: Clone, Balance: HasCompact + AtLeast32BitUnsigned + Copy + MaxEn
Exposure<AccountId, Balance>
{
/// Splits an `Exposure` into `PagedExposureMetadata` and multiple chunks of
/// `IndividualExposure` with each chunk having maximum of `page_size` elements.
/// `IndividualExposure` with each chunk having at least 1 element and a maximum of
/// `MaxExposurePageSize::get()` elements.
pub fn into_pages<MaxExposurePageSize>(
self,
page_size: Page,
) -> (PagedExposureMetadata<Balance>, Vec<ExposurePage<AccountId, Balance, MaxExposurePageSize>>)
where
MaxExposurePageSize: Get<u32>,
{
let individual_chunks = self.others.chunks(page_size as usize);
debug_assert!(MaxExposurePageSize::get() >= 1);
let individual_chunks = self.others.chunks(MaxExposurePageSize::get() as usize);
let mut exposure_pages: Vec<ExposurePage<AccountId, Balance, MaxExposurePageSize>> =
Vec::with_capacity(individual_chunks.len());

Expand Down

0 comments on commit 489fc9d

Please sign in to comment.