mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-10 12:11:59 +00:00
Use E for EthSpec globally (#5264)
* Use `E` for `EthSpec` globally * Fix tests * Merge branch 'unstable' into e-ethspec * Merge branch 'unstable' into e-ethspec # Conflicts: # beacon_node/execution_layer/src/engine_api.rs # beacon_node/execution_layer/src/engine_api/http.rs # beacon_node/execution_layer/src/engine_api/json_structures.rs # beacon_node/execution_layer/src/test_utils/handle_rpc.rs # beacon_node/store/src/partial_beacon_state.rs # consensus/types/src/beacon_block.rs # consensus/types/src/beacon_block_body.rs # consensus/types/src/beacon_state.rs # consensus/types/src/config_and_preset.rs # consensus/types/src/execution_payload.rs # consensus/types/src/execution_payload_header.rs # consensus/types/src/light_client_optimistic_update.rs # consensus/types/src/payload.rs # lcli/src/parse_ssz.rs
This commit is contained in:
@@ -24,8 +24,8 @@ impl BaseRewardPerIncrement {
|
||||
/// shown to be a significant optimisation.
|
||||
///
|
||||
/// Spec v1.1.0
|
||||
pub fn get_base_reward<T: EthSpec>(
|
||||
state: &BeaconState<T>,
|
||||
pub fn get_base_reward<E: EthSpec>(
|
||||
state: &BeaconState<E>,
|
||||
index: usize,
|
||||
base_reward_per_increment: BaseRewardPerIncrement,
|
||||
spec: &ChainSpec,
|
||||
|
||||
@@ -3,8 +3,8 @@ use safe_arith::SafeArith;
|
||||
use types::*;
|
||||
|
||||
/// Returns the base reward for some validator.
|
||||
pub fn get_base_reward<T: EthSpec>(
|
||||
state: &BeaconState<T>,
|
||||
pub fn get_base_reward<E: EthSpec>(
|
||||
state: &BeaconState<E>,
|
||||
index: usize,
|
||||
// Should be == get_total_active_balance(state, spec)
|
||||
total_active_balance: u64,
|
||||
@@ -18,7 +18,7 @@ pub fn get_base_reward<T: EthSpec>(
|
||||
.map_err(Into::into)
|
||||
}
|
||||
|
||||
pub fn get_base_reward_from_effective_balance<T: EthSpec>(
|
||||
pub fn get_base_reward_from_effective_balance<E: EthSpec>(
|
||||
effective_balance: u64,
|
||||
total_active_balance: u64,
|
||||
spec: &ChainSpec,
|
||||
|
||||
@@ -16,8 +16,8 @@ use types::{AttestationData, BeaconState, ChainSpec, EthSpec};
|
||||
///
|
||||
/// This function will return an error if the source of the attestation doesn't match the
|
||||
/// state's relevant justified checkpoint.
|
||||
pub fn get_attestation_participation_flag_indices<T: EthSpec>(
|
||||
state: &BeaconState<T>,
|
||||
pub fn get_attestation_participation_flag_indices<E: EthSpec>(
|
||||
state: &BeaconState<E>,
|
||||
data: &AttestationData,
|
||||
inclusion_delay: u64,
|
||||
spec: &ChainSpec,
|
||||
@@ -41,7 +41,7 @@ pub fn get_attestation_participation_flag_indices<T: EthSpec>(
|
||||
|
||||
// Participation flag indices
|
||||
let mut participation_flag_indices = SmallVec::new();
|
||||
if is_matching_source && inclusion_delay <= T::slots_per_epoch().integer_sqrt() {
|
||||
if is_matching_source && inclusion_delay <= E::slots_per_epoch().integer_sqrt() {
|
||||
participation_flag_indices.push(TIMELY_SOURCE_FLAG_INDEX);
|
||||
}
|
||||
match state {
|
||||
@@ -49,7 +49,7 @@ pub fn get_attestation_participation_flag_indices<T: EthSpec>(
|
||||
| &BeaconState::Altair(_)
|
||||
| &BeaconState::Merge(_)
|
||||
| &BeaconState::Capella(_) => {
|
||||
if is_matching_target && inclusion_delay <= T::slots_per_epoch() {
|
||||
if is_matching_target && inclusion_delay <= E::slots_per_epoch() {
|
||||
participation_flag_indices.push(TIMELY_TARGET_FLAG_INDEX);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use types::*;
|
||||
|
||||
/// Returns validator indices which participated in the attestation, sorted by increasing index.
|
||||
pub fn get_attesting_indices<T: EthSpec>(
|
||||
pub fn get_attesting_indices<E: EthSpec>(
|
||||
committee: &[usize],
|
||||
bitlist: &BitList<T::MaxValidatorsPerCommittee>,
|
||||
bitlist: &BitList<E::MaxValidatorsPerCommittee>,
|
||||
) -> Result<Vec<u64>, BeaconStateError> {
|
||||
if bitlist.len() != committee.len() {
|
||||
return Err(BeaconStateError::InvalidBitfield);
|
||||
@@ -23,10 +23,10 @@ pub fn get_attesting_indices<T: EthSpec>(
|
||||
}
|
||||
|
||||
/// Shortcut for getting the attesting indices while fetching the committee from the state's cache.
|
||||
pub fn get_attesting_indices_from_state<T: EthSpec>(
|
||||
state: &BeaconState<T>,
|
||||
att: &Attestation<T>,
|
||||
pub fn get_attesting_indices_from_state<E: EthSpec>(
|
||||
state: &BeaconState<E>,
|
||||
att: &Attestation<E>,
|
||||
) -> Result<Vec<u64>, BeaconStateError> {
|
||||
let committee = state.get_beacon_committee(att.data.slot, att.data.index)?;
|
||||
get_attesting_indices::<T>(committee.committee, &att.aggregation_bits)
|
||||
get_attesting_indices::<E>(committee.committee, &att.aggregation_bits)
|
||||
}
|
||||
|
||||
@@ -7,11 +7,11 @@ type Result<T> = std::result::Result<T, BlockOperationError<Invalid>>;
|
||||
/// Convert `attestation` to (almost) indexed-verifiable form.
|
||||
///
|
||||
/// Spec v0.12.1
|
||||
pub fn get_indexed_attestation<T: EthSpec>(
|
||||
pub fn get_indexed_attestation<E: EthSpec>(
|
||||
committee: &[usize],
|
||||
attestation: &Attestation<T>,
|
||||
) -> Result<IndexedAttestation<T>> {
|
||||
let attesting_indices = get_attesting_indices::<T>(committee, &attestation.aggregation_bits)?;
|
||||
attestation: &Attestation<E>,
|
||||
) -> Result<IndexedAttestation<E>> {
|
||||
let attesting_indices = get_attesting_indices::<E>(committee, &attestation.aggregation_bits)?;
|
||||
|
||||
Ok(IndexedAttestation {
|
||||
attesting_indices: VariableList::new(attesting_indices)?,
|
||||
|
||||
@@ -3,8 +3,8 @@ use std::cmp::max;
|
||||
use types::{BeaconStateError as Error, *};
|
||||
|
||||
/// Initiate the exit of the validator of the given `index`.
|
||||
pub fn initiate_validator_exit<T: EthSpec>(
|
||||
state: &mut BeaconState<T>,
|
||||
pub fn initiate_validator_exit<E: EthSpec>(
|
||||
state: &mut BeaconState<E>,
|
||||
index: usize,
|
||||
spec: &ChainSpec,
|
||||
) -> Result<(), Error> {
|
||||
|
||||
@@ -12,11 +12,11 @@ use types::{
|
||||
};
|
||||
|
||||
/// Slash the validator with index `slashed_index`.
|
||||
pub fn slash_validator<T: EthSpec>(
|
||||
state: &mut BeaconState<T>,
|
||||
pub fn slash_validator<E: EthSpec>(
|
||||
state: &mut BeaconState<E>,
|
||||
slashed_index: usize,
|
||||
opt_whistleblower_index: Option<usize>,
|
||||
ctxt: &mut ConsensusContext<T>,
|
||||
ctxt: &mut ConsensusContext<E>,
|
||||
spec: &ChainSpec,
|
||||
) -> Result<(), BlockProcessingError> {
|
||||
let epoch = state.current_epoch();
|
||||
@@ -27,7 +27,7 @@ pub fn slash_validator<T: EthSpec>(
|
||||
validator.slashed = true;
|
||||
validator.withdrawable_epoch = cmp::max(
|
||||
validator.withdrawable_epoch,
|
||||
epoch.safe_add(T::EpochsPerSlashingsVector::to_u64())?,
|
||||
epoch.safe_add(E::EpochsPerSlashingsVector::to_u64())?,
|
||||
);
|
||||
let validator_effective_balance = validator.effective_balance;
|
||||
state.set_slashings(
|
||||
|
||||
@@ -54,8 +54,8 @@ pub fn initialize_progressive_balances_cache<E: EthSpec>(
|
||||
}
|
||||
|
||||
/// Updates the `ProgressiveBalancesCache` when a new target attestation has been processed.
|
||||
pub fn update_progressive_balances_on_attestation<T: EthSpec>(
|
||||
state: &mut BeaconState<T>,
|
||||
pub fn update_progressive_balances_on_attestation<E: EthSpec>(
|
||||
state: &mut BeaconState<E>,
|
||||
epoch: Epoch,
|
||||
validator_index: usize,
|
||||
) -> Result<(), BlockProcessingError> {
|
||||
@@ -72,18 +72,18 @@ pub fn update_progressive_balances_on_attestation<T: EthSpec>(
|
||||
}
|
||||
|
||||
/// Updates the `ProgressiveBalancesCache` when a target attester has been slashed.
|
||||
pub fn update_progressive_balances_on_slashing<T: EthSpec>(
|
||||
state: &mut BeaconState<T>,
|
||||
pub fn update_progressive_balances_on_slashing<E: EthSpec>(
|
||||
state: &mut BeaconState<E>,
|
||||
validator_index: usize,
|
||||
) -> Result<(), BlockProcessingError> {
|
||||
if is_progressive_balances_enabled(state) {
|
||||
let previous_epoch_participation = state.previous_epoch_participation()?;
|
||||
let is_previous_epoch_target_attester =
|
||||
is_target_attester_in_epoch::<T>(previous_epoch_participation, validator_index)?;
|
||||
is_target_attester_in_epoch::<E>(previous_epoch_participation, validator_index)?;
|
||||
|
||||
let current_epoch_participation = state.current_epoch_participation()?;
|
||||
let is_current_epoch_target_attester =
|
||||
is_target_attester_in_epoch::<T>(current_epoch_participation, validator_index)?;
|
||||
is_target_attester_in_epoch::<E>(current_epoch_participation, validator_index)?;
|
||||
|
||||
let validator_effective_balance = state.get_effective_balance(validator_index)?;
|
||||
|
||||
@@ -98,8 +98,8 @@ pub fn update_progressive_balances_on_slashing<T: EthSpec>(
|
||||
}
|
||||
|
||||
/// Updates the `ProgressiveBalancesCache` on epoch transition.
|
||||
pub fn update_progressive_balances_on_epoch_transition<T: EthSpec>(
|
||||
state: &mut BeaconState<T>,
|
||||
pub fn update_progressive_balances_on_epoch_transition<E: EthSpec>(
|
||||
state: &mut BeaconState<E>,
|
||||
spec: &ChainSpec,
|
||||
) -> Result<(), EpochProcessingError> {
|
||||
if is_progressive_balances_enabled(state) {
|
||||
@@ -129,8 +129,8 @@ pub fn update_progressive_balances_metrics(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn is_target_attester_in_epoch<T: EthSpec>(
|
||||
epoch_participation: &VariableList<ParticipationFlags, T::ValidatorRegistryLimit>,
|
||||
fn is_target_attester_in_epoch<E: EthSpec>(
|
||||
epoch_participation: &VariableList<ParticipationFlags, E::ValidatorRegistryLimit>,
|
||||
validator_index: usize,
|
||||
) -> Result<bool, BlockProcessingError> {
|
||||
let participation_flags = epoch_participation
|
||||
|
||||
Reference in New Issue
Block a user