mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-19 21:04:41 +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:
@@ -11,13 +11,13 @@ use tree_hash::TreeHash;
|
||||
use types::*;
|
||||
|
||||
/// Initialize a `BeaconState` from genesis data.
|
||||
pub fn initialize_beacon_state_from_eth1<T: EthSpec>(
|
||||
pub fn initialize_beacon_state_from_eth1<E: EthSpec>(
|
||||
eth1_block_hash: Hash256,
|
||||
eth1_timestamp: u64,
|
||||
deposits: Vec<Deposit>,
|
||||
execution_payload_header: Option<ExecutionPayloadHeader<T>>,
|
||||
execution_payload_header: Option<ExecutionPayloadHeader<E>>,
|
||||
spec: &ChainSpec,
|
||||
) -> Result<BeaconState<T>, BlockProcessingError> {
|
||||
) -> Result<BeaconState<E>, BlockProcessingError> {
|
||||
let genesis_time = eth2_genesis_time(eth1_timestamp, spec)?;
|
||||
let eth1_data = Eth1Data {
|
||||
// Temporary deposit root
|
||||
@@ -51,7 +51,7 @@ pub fn initialize_beacon_state_from_eth1<T: EthSpec>(
|
||||
// https://github.com/ethereum/eth2.0-specs/pull/2323
|
||||
if spec
|
||||
.altair_fork_epoch
|
||||
.map_or(false, |fork_epoch| fork_epoch == T::genesis_epoch())
|
||||
.map_or(false, |fork_epoch| fork_epoch == E::genesis_epoch())
|
||||
{
|
||||
upgrade_to_altair(&mut state, spec)?;
|
||||
|
||||
@@ -61,7 +61,7 @@ pub fn initialize_beacon_state_from_eth1<T: EthSpec>(
|
||||
// Similarly, perform an upgrade to the merge if configured from genesis.
|
||||
if spec
|
||||
.bellatrix_fork_epoch
|
||||
.map_or(false, |fork_epoch| fork_epoch == T::genesis_epoch())
|
||||
.map_or(false, |fork_epoch| fork_epoch == E::genesis_epoch())
|
||||
{
|
||||
// this will set state.latest_execution_payload_header = ExecutionPayloadHeaderMerge::default()
|
||||
upgrade_to_bellatrix(&mut state, spec)?;
|
||||
@@ -79,7 +79,7 @@ pub fn initialize_beacon_state_from_eth1<T: EthSpec>(
|
||||
// Upgrade to capella if configured from genesis
|
||||
if spec
|
||||
.capella_fork_epoch
|
||||
.map_or(false, |fork_epoch| fork_epoch == T::genesis_epoch())
|
||||
.map_or(false, |fork_epoch| fork_epoch == E::genesis_epoch())
|
||||
{
|
||||
upgrade_to_capella(&mut state, spec)?;
|
||||
|
||||
@@ -96,7 +96,7 @@ pub fn initialize_beacon_state_from_eth1<T: EthSpec>(
|
||||
// Upgrade to deneb if configured from genesis
|
||||
if spec
|
||||
.deneb_fork_epoch
|
||||
.map_or(false, |fork_epoch| fork_epoch == T::genesis_epoch())
|
||||
.map_or(false, |fork_epoch| fork_epoch == E::genesis_epoch())
|
||||
{
|
||||
upgrade_to_deneb(&mut state, spec)?;
|
||||
|
||||
@@ -113,7 +113,7 @@ pub fn initialize_beacon_state_from_eth1<T: EthSpec>(
|
||||
// Upgrade to electra if configured from genesis.
|
||||
if spec
|
||||
.electra_fork_epoch
|
||||
.map_or(false, |fork_epoch| fork_epoch == T::genesis_epoch())
|
||||
.map_or(false, |fork_epoch| fork_epoch == E::genesis_epoch())
|
||||
{
|
||||
upgrade_to_electra(&mut state, spec)?;
|
||||
|
||||
@@ -137,9 +137,9 @@ pub fn initialize_beacon_state_from_eth1<T: EthSpec>(
|
||||
}
|
||||
|
||||
/// Determine whether a candidate genesis state is suitable for starting the chain.
|
||||
pub fn is_valid_genesis_state<T: EthSpec>(state: &BeaconState<T>, spec: &ChainSpec) -> bool {
|
||||
pub fn is_valid_genesis_state<E: EthSpec>(state: &BeaconState<E>, spec: &ChainSpec) -> bool {
|
||||
state
|
||||
.get_active_validator_indices(T::genesis_epoch(), spec)
|
||||
.get_active_validator_indices(E::genesis_epoch(), spec)
|
||||
.map_or(false, |active_validators| {
|
||||
state.genesis_time() >= spec.min_genesis_time
|
||||
&& active_validators.len() as u64 >= spec.min_genesis_active_validator_count
|
||||
@@ -147,8 +147,8 @@ pub fn is_valid_genesis_state<T: EthSpec>(state: &BeaconState<T>, spec: &ChainSp
|
||||
}
|
||||
|
||||
/// Activate genesis validators, if their balance is acceptable.
|
||||
pub fn process_activations<T: EthSpec>(
|
||||
state: &mut BeaconState<T>,
|
||||
pub fn process_activations<E: EthSpec>(
|
||||
state: &mut BeaconState<E>,
|
||||
spec: &ChainSpec,
|
||||
) -> Result<(), Error> {
|
||||
let (validators, balances, _) = state.validators_and_balances_and_progressive_balances_mut();
|
||||
@@ -162,8 +162,8 @@ pub fn process_activations<T: EthSpec>(
|
||||
spec.max_effective_balance,
|
||||
);
|
||||
if validator.effective_balance == spec.max_effective_balance {
|
||||
validator.activation_eligibility_epoch = T::genesis_epoch();
|
||||
validator.activation_epoch = T::genesis_epoch();
|
||||
validator.activation_eligibility_epoch = E::genesis_epoch();
|
||||
validator.activation_epoch = E::genesis_epoch();
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user