Merge branch 'electra-epoch-proc' of https://github.com/sigp/lighthouse into electra-engine-api

This commit is contained in:
realbigsean
2024-05-10 10:00:42 -04:00
4 changed files with 369 additions and 42 deletions

View File

@@ -1,6 +1,6 @@
use crate::{
test_utils::TestRandom, Address, BeaconState, ChainSpec, Epoch, EthSpec, ForkName, Hash256,
PublicKeyBytes,
test_utils::TestRandom, Address, BeaconState, ChainSpec, Checkpoint, Epoch, EthSpec, ForkName,
Hash256, PublicKeyBytes,
};
use serde::{Deserialize, Serialize};
use ssz_derive::{Decode, Encode};
@@ -87,15 +87,25 @@ impl Validator {
}
/// Returns `true` if the validator is eligible to be activated.
///
/// Spec v0.12.1
pub fn is_eligible_for_activation<E: EthSpec>(
&self,
state: &BeaconState<E>,
spec: &ChainSpec,
) -> bool {
self.is_eligible_for_activation_with_finalized_checkpoint(
&state.finalized_checkpoint(),
spec,
)
}
/// Returns `true` if the validator is eligible to be activated.
pub fn is_eligible_for_activation_with_finalized_checkpoint(
&self,
finalized_checkpoint: &Checkpoint,
spec: &ChainSpec,
) -> bool {
// Placement in queue is finalized
self.activation_eligibility_epoch <= state.finalized_checkpoint().epoch
self.activation_eligibility_epoch <= finalized_checkpoint.epoch
// Has not yet been activated
&& self.activation_epoch == spec.far_future_epoch
}
@@ -267,6 +277,16 @@ impl Validator {
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_validator_max_effective_balance(spec, current_fork);
std::cmp::min(validator_balance, max_effective_balance)
}
}
impl Default for Validator {