Skip to content

Commit

Permalink
Fix the logic to take the first top n
Browse files Browse the repository at this point in the history
  • Loading branch information
jaypan authored and Jay Pan committed Dec 18, 2024
1 parent 2e1dd53 commit 6ebcd91
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pallets/parachain-staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,9 +540,10 @@ pub mod pallet {
}

/// The maximum number of collator candidates selected at each round.
/// precompiles will call this
#[pallet::storage]
#[pallet::getter(fn max_selected_candidates)]
pub(crate) type MaxSelectedCandidates<T: Config> = StorageValue<_, u32, ValueQuery>;
pub type MaxSelectedCandidates<T: Config> = StorageValue<_, u32, ValueQuery>;

/// Current round number and next round scheduled transition.
#[pallet::storage]
Expand Down
2 changes: 2 additions & 0 deletions precompiles/parachain-staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ where
.map(|stake_info| {
H256::from(<AccountIdOf<Runtime> as Into<[u8; 32]>>::into(stake_info.owner))
})
.take(parachain_staking::MaxSelectedCandidates::<Runtime>::get() as usize)
.collect::<Vec<H256>>();
let candidate_list = all_collators.into_iter().filter(|x| top_candiate.contains(&x.owner));
Ok(candidate_list.collect::<Vec<CollatorInfo>>())
Expand All @@ -112,6 +113,7 @@ where
.map(|stake_info| {
H256::from(<AccountIdOf<Runtime> as Into<[u8; 32]>>::into(stake_info.owner))
})
.take(parachain_staking::MaxSelectedCandidates::<Runtime>::get() as usize)
.collect::<Vec<H256>>();
let candidate_list = all_collators.into_iter().filter(|x| !top_candiate.contains(&x.owner));
Ok(candidate_list.collect::<Vec<CollatorInfo>>())
Expand Down

0 comments on commit 6ebcd91

Please sign in to comment.