Skip to content

Commit

Permalink
Rename to get_max_effective_balance
Browse files Browse the repository at this point in the history
  • Loading branch information
pawanjay176 committed Sep 28, 2024
1 parent 77e4d58 commit 78e37b1
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 12 deletions.
3 changes: 1 addition & 2 deletions consensus/state_processing/src/per_block_processing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -579,8 +579,7 @@ pub fn get_expected_withdrawals<E: EthSpec>(
.get_execution_withdrawal_address(spec)
.ok_or(BlockProcessingError::WithdrawalCredentialsInvalid)?,
amount: balance.safe_sub(
validator
.get_validator_max_effective_balance(spec, state.fork_name_unchecked()),
validator.get_max_effective_balance(spec, state.fork_name_unchecked()),
)?,
});
withdrawal_index.safe_add_assign(1)?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1027,8 +1027,7 @@ fn process_single_effective_balance_update(
) -> Result<(), Error> {
// Use the higher effective balance limit if post-Electra and compounding withdrawal credentials
// are set.
let effective_balance_limit =
validator.get_validator_max_effective_balance(spec, state_ctxt.fork_name);
let effective_balance_limit = validator.get_max_effective_balance(spec, state_ctxt.fork_name);

let old_effective_balance = validator.effective_balance;
let new_effective_balance = if balance.safe_add(eb_ctxt.downward_threshold)?
Expand Down
2 changes: 1 addition & 1 deletion consensus/types/src/beacon_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2131,7 +2131,7 @@ impl<E: EthSpec> BeaconState<E> {
let max_effective_balance = self
.validators()
.get(validator_index)
.map(|validator| validator.get_validator_max_effective_balance(spec, current_fork))
.map(|validator| validator.get_max_effective_balance(spec, current_fork))
.ok_or(Error::UnknownValidator(validator_index))?;
Ok(std::cmp::min(
*self
Expand Down
10 changes: 3 additions & 7 deletions consensus/types/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ impl Validator {
spec: &ChainSpec,
current_fork: ForkName,
) -> bool {
let max_effective_balance = self.get_validator_max_effective_balance(spec, current_fork);
let max_effective_balance = self.get_max_effective_balance(spec, current_fork);
let has_max_effective_balance = self.effective_balance == max_effective_balance;
let has_excess_balance = balance > max_effective_balance;
self.has_execution_withdrawal_credential(spec)
Expand All @@ -251,11 +251,7 @@ impl Validator {
}

/// Returns the max effective balance for a validator in gwei.
pub fn get_validator_max_effective_balance(
&self,
spec: &ChainSpec,
current_fork: ForkName,
) -> u64 {
pub fn get_max_effective_balance(&self, spec: &ChainSpec, current_fork: ForkName) -> u64 {
if current_fork >= ForkName::Electra {
if self.has_compounding_withdrawal_credential(spec) {
spec.max_effective_balance_electra
Expand All @@ -273,7 +269,7 @@ impl Validator {
spec: &ChainSpec,
current_fork: ForkName,
) -> u64 {
let max_effective_balance = self.get_validator_max_effective_balance(spec, current_fork);
let max_effective_balance = self.get_max_effective_balance(spec, current_fork);
std::cmp::min(validator_balance, max_effective_balance)
}
}
Expand Down

0 comments on commit 78e37b1

Please sign in to comment.