fn slash(&mut self, mut value: Balance, minimum_balance: Balance) -> Balance {
        let pre_total = self.total;
        let total = &mut self.total;
        let active = &mut self.active;

        let slash_out_of =
            |total_remaining: &mut Balance, target: &mut Balance, value: &mut Balance| {
                let mut slash_from_target = (*value).min(*target);

                if !slash_from_target.is_zero() {
                    *target -= slash_from_target;

                    // don't leave a dust balance in the staking system.
                    if *target <= minimum_balance {
                        slash_from_target += *target;
                        *value += sp_std::mem::replace(target, Zero::zero());
                    }

                    *total_remaining = total_remaining.saturating_sub(slash_from_target);
                    *value -= slash_from_target;
                }
            };

        slash_out_of(total, active, &mut value);

        let i = self
            .unlocking
            .iter_mut()
            .map(|chunk| {
                slash_out_of(total, &mut chunk.value, &mut value);
                chunk.value
            })
            .take_while(|value| value.is_zero()) // take all fully-consumed chunks out.
            .count();

        // kill all drained chunks.
        let _ = self.unlocking.drain(..i);

        pre_total.saturating_sub(*total)
    }
/// Slash the validator for a given amount of balance. This can grow the value
/// of the slash in the case that the validator has less than `minimum_balance`
/// active funds. Returns the amount of funds actually slashed.
///
/// Slashes from `active` funds first, and then `unlocking`, starting with the
/// chunks that are closest to unlocking.
Slash the validator for a given amount of balance. This can grow the value
of the slash in the case that the validator has less than `minimum_balance`
active funds. Returns the amount of funds actually slashed.

Slashes from `active` funds first, and then `unlocking`, starting with the
chunks that are closest to unlocking.
Slash the validator for a given amount of balance . This can grow the value of the slash in the case that the validator has less than ` minimum_balance ` active funds . Returns the amount of funds actually slashed . Slashes from ` active ` funds first and then ` unlocking ` starting with the chunks that are closest to unlocking .
fn slash(&mut self, mut value: Balance, minimum_balance: Balance) -> Balance {
        let pre_total = self.total;
        let total = &mut self.total;
        let active = &mut self.active;
        let slash_out_of =
            |total_remaining: &mut Balance, target: &mut Balance, value: &mut Balance| {
                let mut slash_from_target = (*value).min(*target);
                if !slash_from_target.is_zero() {
                    *target -= slash_from_target;
                    // don't leave a dust balance in the staking system.
                    if *target <= minimum_balance {
                        slash_from_target += *target;
                        *value += sp_std::mem::replace(target, Zero::zero());
                    }
                    *total_remaining = total_remaining.saturating_sub(slash_from_target);
                    *value -= slash_from_target;
                }
            };
        slash_out_of(total, active, &mut value);
        let i = self
            .unlocking
            .iter_mut()
            .map(|chunk| {
                slash_out_of(total, &mut chunk.value, &mut value);
                chunk.value
            })
            .take_while(|value| value.is_zero()) // take all fully-consumed chunks out.
            .count();
        // kill all drained chunks.
        let _ = self.unlocking.drain(..i);
        pre_total.saturating_sub(*total)
    }
fn slash ( & mut self , mut value : Balance , minimum_balance : Balance ) -> Balance { let pre_total = self . total ; let total = & mut self . total ; let active = & mut self . active ; let slash_out_of = | total_remaining : & mut Balance , target : & mut Balance , value : & mut Balance | { let mut slash_from_target = ( * value ) . min ( * target ) ; if ! slash_from_target . is_zero ( ) { * target -= slash_from_target ; // don't leave a dust balance in the staking system. if * target <= minimum_balance { slash_from_target += * target ; * value += sp_std :: mem :: replace ( target , Zero :: zero ( ) ) ; } * total_remaining = total_remaining . saturating_sub ( slash_from_target ) ; * value -= slash_from_target ; } } ; slash_out_of ( total , active , & mut value ) ; let i = self . unlocking . iter_mut ( ) . map ( | chunk | { slash_out_of ( total , & mut chunk . value , & mut value ) ; chunk . value } ) . take_while ( | value | value . is_zero ( ) ) // take all fully-consumed chunks out. . count ( ) ; // kill all drained chunks. let _ = self . unlocking . drain ( .. i ) ; pre_total . saturating_sub ( * total ) }
Slash the validator for a given amount of balance.
Slash the validator for a given amount of balance .
&mut self
value
Balance
minimum_balance
Balance