fn stake_and_activating(
        &self,
        target_epoch: Epoch,
        history: Option<&StakeHistory>,
    ) -> (u64, u64) {
        let delegated_stake = self.stake;

        if self.is_bootstrap() {
            // fully effective immediately
            (delegated_stake, 0)
        } else if self.activation_epoch == self.deactivation_epoch {
            // activated but instantly deactivated; no stake at all regardless of target_epoch
            // this must be after the bootstrap check and before all-is-activating check
            (0, 0)
        } else if target_epoch == self.activation_epoch {
            // all is activating
            (0, delegated_stake)
        } else if target_epoch < self.activation_epoch {
            // not yet enabled
            (0, 0)
        } else if let Some((history, mut prev_epoch, mut prev_cluster_stake)) =
            history.and_then(|history| {
                history
                    .get(self.activation_epoch)
                    .map(|cluster_stake_at_activation_epoch| {
                        (
                            history,
                            self.activation_epoch,
                            cluster_stake_at_activation_epoch,
                        )
                    })
            })
        {
            // target_epoch > self.activation_epoch

            // loop from my activation epoch until the target epoch summing up my entitlement
            // current effective stake is updated using its previous epoch's cluster stake
            let mut current_epoch;
            let mut current_effective_stake = 0;
            loop {
                current_epoch = prev_epoch + 1;
                // if there is no activating stake at prev epoch, we should have been
                // fully effective at this moment
                if prev_cluster_stake.activating == 0 {
                    break;
                }

                // how much of the growth in stake this account is
                //  entitled to take
                let remaining_activating_stake = delegated_stake - current_effective_stake;
                let weight =
                    remaining_activating_stake as f64 / prev_cluster_stake.activating as f64;

                // portion of newly effective cluster stake I'm entitled to at current epoch
                let newly_effective_cluster_stake =
                    prev_cluster_stake.effective as f64 * self.warmup_cooldown_rate;
                let newly_effective_stake =
                    ((weight * newly_effective_cluster_stake) as u64).max(1);

                current_effective_stake += newly_effective_stake;
                if current_effective_stake >= delegated_stake {
                    current_effective_stake = delegated_stake;
                    break;
                }

                if current_epoch >= target_epoch || current_epoch >= self.deactivation_epoch {
                    break;
                }
                if let Some(current_cluster_stake) = history.get(current_epoch) {
                    prev_epoch = current_epoch;
                    prev_cluster_stake = current_cluster_stake;
                } else {
                    break;
                }
            }

            (
                current_effective_stake,
                delegated_stake - current_effective_stake,
            )
        } else {
            // no history or I've dropped out of history, so assume fully effective
            (delegated_stake, 0)
        }
    }
// returned tuple is (effective, activating) stake
returned tuple is (effective, activating) stake
returned tuple is ( effective activating ) stake
fn stake_and_activating(
        &self,
        target_epoch: Epoch,
        history: Option<&StakeHistory>,
    ) -> (u64, u64) {
        let delegated_stake = self.stake;
        if self.is_bootstrap() {
            // fully effective immediately
            (delegated_stake, 0)
        } else if self.activation_epoch == self.deactivation_epoch {
            // activated but instantly deactivated; no stake at all regardless of target_epoch
            // this must be after the bootstrap check and before all-is-activating check
            (0, 0)
        } else if target_epoch == self.activation_epoch {
            // all is activating
            (0, delegated_stake)
        } else if target_epoch < self.activation_epoch {
            // not yet enabled
            (0, 0)
        } else if let Some((history, mut prev_epoch, mut prev_cluster_stake)) =
            history.and_then(|history| {
                history
                    .get(self.activation_epoch)
                    .map(|cluster_stake_at_activation_epoch| {
                        (
                            history,
                            self.activation_epoch,
                            cluster_stake_at_activation_epoch,
                        )
                    })
            })
        {
            // target_epoch > self.activation_epoch
            // loop from my activation epoch until the target epoch summing up my entitlement
            // current effective stake is updated using its previous epoch's cluster stake
            let mut current_epoch;
            let mut current_effective_stake = 0;
            loop {
                current_epoch = prev_epoch + 1;
                // if there is no activating stake at prev epoch, we should have been
                // fully effective at this moment
                if prev_cluster_stake.activating == 0 {
                    break;
                }
                // how much of the growth in stake this account is
                //  entitled to take
                let remaining_activating_stake = delegated_stake - current_effective_stake;
                let weight =
                    remaining_activating_stake as f64 / prev_cluster_stake.activating as f64;
                // portion of newly effective cluster stake I'm entitled to at current epoch
                let newly_effective_cluster_stake =
                    prev_cluster_stake.effective as f64 * self.warmup_cooldown_rate;
                let newly_effective_stake =
                    ((weight * newly_effective_cluster_stake) as u64).max(1);
                current_effective_stake += newly_effective_stake;
                if current_effective_stake >= delegated_stake {
                    current_effective_stake = delegated_stake;
                    break;
                }
                if current_epoch >= target_epoch || current_epoch >= self.deactivation_epoch {
                    break;
                }
                if let Some(current_cluster_stake) = history.get(current_epoch) {
                    prev_epoch = current_epoch;
                    prev_cluster_stake = current_cluster_stake;
                } else {
                    break;
                }
            }
            (
                current_effective_stake,
                delegated_stake - current_effective_stake,
            )
        } else {
            // no history or I've dropped out of history, so assume fully effective
            (delegated_stake, 0)
        }
    }
fn stake_and_activating ( & self , target_epoch : Epoch , history : Option < & StakeHistory > , ) -> ( u64 , u64 ) { let delegated_stake = self . stake ; if self . is_bootstrap ( ) { // fully effective immediately ( delegated_stake , 0 ) } else if self . activation_epoch == self . deactivation_epoch { // activated but instantly deactivated; no stake at all regardless of target_epoch // this must be after the bootstrap check and before all-is-activating check ( 0 , 0 ) } else if target_epoch == self . activation_epoch { // all is activating ( 0 , delegated_stake ) } else if target_epoch < self . activation_epoch { // not yet enabled ( 0 , 0 ) } else if let Some ( ( history , mut prev_epoch , mut prev_cluster_stake ) ) = history . and_then ( | history | { history . get ( self . activation_epoch ) . map ( | cluster_stake_at_activation_epoch | { ( history , self . activation_epoch , cluster_stake_at_activation_epoch , ) } ) } ) { // target_epoch > self.activation_epoch // loop from my activation epoch until the target epoch summing up my entitlement // current effective stake is updated using its previous epoch's cluster stake let mut current_epoch ; let mut current_effective_stake = 0 ; loop { current_epoch = prev_epoch + 1 ; // if there is no activating stake at prev epoch, we should have been // fully effective at this moment if prev_cluster_stake . activating == 0 { break ; } // how much of the growth in stake this account is //  entitled to take let remaining_activating_stake = delegated_stake - current_effective_stake ; let weight = remaining_activating_stake as f64 / prev_cluster_stake . activating as f64 ; // portion of newly effective cluster stake I'm entitled to at current epoch let newly_effective_cluster_stake = prev_cluster_stake . effective as f64 * self . warmup_cooldown_rate ; let newly_effective_stake = ( ( weight * newly_effective_cluster_stake ) as u64 ) . max ( 1 ) ; current_effective_stake += newly_effective_stake ; if current_effective_stake >= delegated_stake { current_effective_stake = delegated_stake ; break ; } if current_epoch >= target_epoch || current_epoch >= self . deactivation_epoch { break ; } if let Some ( current_cluster_stake ) = history . get ( current_epoch ) { prev_epoch = current_epoch ; prev_cluster_stake = current_cluster_stake ; } else { break ; } } ( current_effective_stake , delegated_stake - current_effective_stake , ) } else { // no history or I've dropped out of history, so assume fully effective ( delegated_stake , 0 ) } }
returned tuple is (effective, activating) stake
returned tuple is ( effective activating ) stake
&self
target_epoch
Epoch
history
Option<&StakeHistory>