Skip to content

Commit

Permalink
feat: kick collators without sufficient escrow balance
Browse files Browse the repository at this point in the history
Signed-off-by: Gregory Hill <gregorydhill@outlook.com>
  • Loading branch information
gregdhill committed Aug 31, 2022
1 parent 8bf8392 commit 4c37762
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions crates/collator-selection/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,25 +428,31 @@ pub mod pallet {
}

/// Kicks out candidates that did not produce a block in the kick threshold
/// and refund their deposits.
/// or whose free balance drops below the minimum and refund their deposits.
pub fn kick_stale_candidates(candidates: Vec<CandidateInfo<T::AccountId, BalanceOf<T>>>) -> Vec<T::AccountId> {
// TODO: also kick candidates when escrow balance drops
let now = frame_system::Pallet::<T>::block_number();
let kick_threshold = T::KickThreshold::get();
let candidacy_bond = Self::candidacy_bond();
candidates
.into_iter()
.filter_map(|c| {
let last_block = <LastAuthoredBlock<T>>::get(c.who.clone());
let since_last = now.saturating_sub(last_block);
if since_last < kick_threshold || Self::candidates().len() as u32 <= T::MinCandidates::get() {
// total balance excludes reserved
let balance = T::StakingCurrency::total_balance(&c.who);
if Self::candidates().len() as u32 <= T::MinCandidates::get() {
// don't kick if not enough candidates
Some(c.who)
} else {
} else if since_last > kick_threshold || balance < candidacy_bond {
// kick if stale OR balance is not sufficient
let outcome = Self::try_remove_candidate(&c.who);
if let Err(why) = outcome {
log::warn!("Failed to remove candidate {:?}", why);
debug_assert!(false, "failed to remove candidate {:?}", why);
}
None
} else {
Some(c.who)
}
})
.collect()
Expand Down

0 comments on commit 4c37762

Please sign in to comment.