Skip to content

Commit

Permalink
Fix issue 15
Browse files Browse the repository at this point in the history
  • Loading branch information
Moliholy committed Dec 9, 2024
1 parent 1d206a9 commit 542debb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1847,15 +1847,15 @@ pub mod pallet {
let now = Self::current_block_number();
let kick_threshold = T::KickThreshold::get();
let min_collators = T::MinEligibleCollators::get();
let candidacy_bond = MinCandidacyBond::<T>::get();
let min_candidacy_bond = MinCandidacyBond::<T>::get();
Candidates::<T>::iter()
.filter_map(|(who, info)| {
let last_block = LastAuthoredBlock::<T>::get(who.clone());
let since_last = now.saturating_sub(last_block);
let is_lazy = since_last >= kick_threshold;
let bond = Self::get_bond(&who);

if Self::eligible_collators() <= min_collators || (!is_lazy && bond.saturating_add(info.stake) >= candidacy_bond) {
if Self::eligible_collators() <= min_collators || (!is_lazy && bond >= min_candidacy_bond) {
// Either this is a good collator (not lazy) or we are at the minimum
// that the system needs. They get to stay, as long as they have sufficient deposit plus stake.
Some(info)
Expand Down
17 changes: 2 additions & 15 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,6 @@ mod set_min_candidacy_bond {
let candidate_5 = CandidateInfo { stake: 0, stakers: 0 };

register_candidates(3..=5);
lock_for_staking(3..=5);
assert_eq!(
candidate_list(),
vec![(5, candidate_5.clone()), (3, candidate_3.clone()), (4, candidate_4.clone())]
Expand Down Expand Up @@ -616,21 +615,9 @@ mod set_min_candidacy_bond {
bond_amount: 20,
}));
assert_eq!(MinCandidacyBond::<Test>::get(), 20);
assert_ok!(CollatorStaking::stake(
RuntimeOrigin::signed(5),
vec![StakeTarget { candidate: 5, stake: 20 }].try_into().unwrap()
));
let new_candidate_5 = CandidateInfo { stake: 20, stakers: 1 };
assert_eq!(
candidate_list(),
vec![
(3, candidate_3.clone()),
(4, candidate_4.clone()),
(5, new_candidate_5.clone())
]
);
assert_ok!(CollatorStaking::update_candidacy_bond(RuntimeOrigin::signed(5), 20));
CollatorStaking::kick_stale_candidates();
assert_eq!(candidate_list(), vec![(5, new_candidate_5)]);
assert_eq!(candidate_list(), vec![(5, candidate_5)]);
});
}
}
Expand Down

0 comments on commit 542debb

Please sign in to comment.