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 a91239c
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions crates/collator-selection/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,17 +428,22 @@ 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);
// don't kick if not stale AND balance is sufficient OR below min candidates
if (since_last < kick_threshold && balance > candidacy_bond)
|| Self::candidates().len() as u32 <= T::MinCandidates::get()
{
Some(c.who)
} else {
let outcome = Self::try_remove_candidate(&c.who);
Expand Down

0 comments on commit a91239c

Please sign in to comment.