add electra fork enabled fn to ForkName impl (#36)

* add electra fork enabled fn to ForkName impl

* remove inadvertent file
This commit is contained in:
Eitan Seri-Levi
2024-06-18 22:50:07 +02:00
committed by dapplion
parent 9e84779522
commit 7af3f2eb35
13 changed files with 31 additions and 21 deletions

View File

@@ -1,5 +1,4 @@
use crate::slot_data::SlotData;
use crate::ForkName;
use crate::{test_utils::TestRandom, Hash256, Slot};
use derivative::Derivative;
use safe_arith::ArithError;
@@ -95,7 +94,7 @@ impl<E: EthSpec> Attestation<E> {
data: AttestationData,
spec: &ChainSpec,
) -> Result<Self, Error> {
if spec.fork_name_at_slot::<E>(data.slot) >= ForkName::Electra {
if spec.fork_name_at_slot::<E>(data.slot).electra_enabled() {
let mut committee_bits: BitVector<E::MaxCommitteesPerSlot> = BitVector::default();
committee_bits
.set(committee_index, true)

View File

@@ -376,7 +376,7 @@ impl ChainSpec {
state: &BeaconState<E>,
) -> u64 {
let fork_name = state.fork_name_unchecked();
if fork_name >= ForkName::Electra {
if fork_name.electra_enabled() {
self.min_slashing_penalty_quotient_electra
} else if fork_name >= ForkName::Bellatrix {
self.min_slashing_penalty_quotient_bellatrix

View File

@@ -119,6 +119,10 @@ impl ForkName {
ForkName::Electra => None,
}
}
pub fn electra_enabled(self) -> bool {
self >= ForkName::Electra
}
}
/// Map a fork name into a fork-versioned superstruct type like `BeaconBlock`.

View File

@@ -63,7 +63,7 @@ impl Validator {
spec: &ChainSpec,
current_fork: ForkName,
) -> bool {
if current_fork >= ForkName::Electra {
if current_fork.electra_enabled() {
self.is_eligible_for_activation_queue_electra(spec)
} else {
self.is_eligible_for_activation_queue_base(spec)
@@ -162,7 +162,7 @@ impl Validator {
spec: &ChainSpec,
current_fork: ForkName,
) -> bool {
if current_fork >= ForkName::Electra {
if current_fork.electra_enabled() {
self.is_fully_withdrawable_at_electra(balance, epoch, spec)
} else {
self.is_fully_withdrawable_at_capella(balance, epoch, spec)
@@ -202,7 +202,7 @@ impl Validator {
spec: &ChainSpec,
current_fork: ForkName,
) -> bool {
if current_fork >= ForkName::Electra {
if current_fork.electra_enabled() {
self.is_partially_withdrawable_validator_electra(balance, spec)
} else {
self.is_partially_withdrawable_validator_capella(balance, spec)