mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-01 03:33:47 +00:00
Remove get_active_balance
This commit is contained in:
@@ -941,21 +941,23 @@ fn process_pending_consolidations<E: EthSpec>(
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate the active balance while we have the source validator loaded. This is a safe
|
// Calculate the consolidated balance
|
||||||
// reordering.
|
let max_effective_balance =
|
||||||
let source_balance = *state
|
source_validator.get_max_effective_balance(spec, state_ctxt.fork_name);
|
||||||
.balances()
|
let source_effective_balance = std::cmp::min(
|
||||||
.get(source_index)
|
*state
|
||||||
.ok_or(BeaconStateError::UnknownValidator(source_index))?;
|
.balances()
|
||||||
let active_balance =
|
.get(source_index)
|
||||||
source_validator.get_active_balance(source_balance, spec, state_ctxt.fork_name);
|
.ok_or(BeaconStateError::UnknownValidator(source_index))?,
|
||||||
|
max_effective_balance,
|
||||||
|
);
|
||||||
|
|
||||||
// Churn any target excess active balance of target and raise its max.
|
// Churn any target excess active balance of target and raise its max.
|
||||||
state.switch_to_compounding_validator(target_index, spec)?;
|
state.switch_to_compounding_validator(target_index, spec)?;
|
||||||
|
|
||||||
// Move active balance to target. Excess balance is withdrawable.
|
// Move active balance to target. Excess balance is withdrawable.
|
||||||
decrease_balance(state, source_index, active_balance)?;
|
decrease_balance(state, source_index, source_effective_balance)?;
|
||||||
increase_balance(state, target_index, active_balance)?;
|
increase_balance(state, target_index, source_effective_balance)?;
|
||||||
|
|
||||||
affected_validators.insert(source_index);
|
affected_validators.insert(source_index);
|
||||||
affected_validators.insert(target_index);
|
affected_validators.insert(target_index);
|
||||||
|
|||||||
@@ -2121,27 +2121,6 @@ impl<E: EthSpec> BeaconState<E> {
|
|||||||
.map_err(Into::into)
|
.map_err(Into::into)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get active balance for the given `validator_index`.
|
|
||||||
pub fn get_active_balance(
|
|
||||||
&self,
|
|
||||||
validator_index: usize,
|
|
||||||
spec: &ChainSpec,
|
|
||||||
current_fork: ForkName,
|
|
||||||
) -> Result<u64, Error> {
|
|
||||||
let max_effective_balance = self
|
|
||||||
.validators()
|
|
||||||
.get(validator_index)
|
|
||||||
.map(|validator| validator.get_max_effective_balance(spec, current_fork))
|
|
||||||
.ok_or(Error::UnknownValidator(validator_index))?;
|
|
||||||
Ok(std::cmp::min(
|
|
||||||
*self
|
|
||||||
.balances()
|
|
||||||
.get(validator_index)
|
|
||||||
.ok_or(Error::UnknownValidator(validator_index))?,
|
|
||||||
max_effective_balance,
|
|
||||||
))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_pending_balance_to_withdraw(&self, validator_index: usize) -> Result<u64, Error> {
|
pub fn get_pending_balance_to_withdraw(&self, validator_index: usize) -> Result<u64, Error> {
|
||||||
let mut pending_balance = 0;
|
let mut pending_balance = 0;
|
||||||
for withdrawal in self
|
for withdrawal in self
|
||||||
|
|||||||
@@ -262,16 +262,6 @@ impl Validator {
|
|||||||
spec.max_effective_balance
|
spec.max_effective_balance
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_active_balance(
|
|
||||||
&self,
|
|
||||||
validator_balance: u64,
|
|
||||||
spec: &ChainSpec,
|
|
||||||
current_fork: ForkName,
|
|
||||||
) -> u64 {
|
|
||||||
let max_effective_balance = self.get_max_effective_balance(spec, current_fork);
|
|
||||||
std::cmp::min(validator_balance, max_effective_balance)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Validator {
|
impl Default for Validator {
|
||||||
|
|||||||
Reference in New Issue
Block a user