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:
Mac L
2024-04-03 02:12:25 +11:00
committed by GitHub
parent f8fdb71f50
commit 969d12dc6f
230 changed files with 2743 additions and 2792 deletions

View File

@@ -66,7 +66,7 @@ impl From<safe_arith::ArithError> for Error {
/// - `genesis_time`: beacon chain genesis time.
/// - `current_slot`: current beacon chain slot.
/// - `spec`: current beacon chain specification.
fn get_sync_status<T: EthSpec>(
fn get_sync_status<E: EthSpec>(
latest_cached_block: Option<&Eth1Block>,
head_block: Option<&Eth1Block>,
genesis_time: u64,
@@ -84,7 +84,7 @@ fn get_sync_status<T: EthSpec>(
// that are *before* genesis, so that we can indicate to users that we're actually adequately
// cached for where they are in time.
let voting_target_timestamp = if let Some(current_slot) = current_slot {
let period = T::SlotsPerEth1VotingPeriod::to_u64();
let period = E::SlotsPerEth1VotingPeriod::to_u64();
let voting_period_start_slot = (current_slot / period) * period;
let period_start = slot_start_seconds(
@@ -97,7 +97,7 @@ fn get_sync_status<T: EthSpec>(
} else {
// The number of seconds in an eth1 voting period.
let voting_period_duration =
T::slots_per_eth1_voting_period() as u64 * spec.seconds_per_slot;
E::slots_per_eth1_voting_period() as u64 * spec.seconds_per_slot;
let now = SystemTime::now().duration_since(UNIX_EPOCH).ok()?.as_secs();
@@ -315,10 +315,10 @@ where
}
}
pub trait Eth1ChainBackend<T: EthSpec>: Sized + Send + Sync {
pub trait Eth1ChainBackend<E: EthSpec>: Sized + Send + Sync {
/// Returns the `Eth1Data` that should be included in a block being produced for the given
/// `state`.
fn eth1_data(&self, beacon_state: &BeaconState<T>, spec: &ChainSpec)
fn eth1_data(&self, beacon_state: &BeaconState<E>, spec: &ChainSpec)
-> Result<Eth1Data, Error>;
/// Returns all `Deposits` between `state.eth1_deposit_index` and
@@ -330,7 +330,7 @@ pub trait Eth1ChainBackend<T: EthSpec>: Sized + Send + Sync {
/// be more than `MAX_DEPOSIT_COUNT` or the churn may be too high.
fn queued_deposits(
&self,
beacon_state: &BeaconState<T>,
beacon_state: &BeaconState<E>,
eth1_data_vote: &Eth1Data,
spec: &ChainSpec,
) -> Result<Vec<Deposit>, Error>;
@@ -364,13 +364,13 @@ pub trait Eth1ChainBackend<T: EthSpec>: Sized + Send + Sync {
/// Never creates deposits, therefore the validator set is static.
///
/// This was used in the 2019 Canada interop workshops.
pub struct DummyEth1ChainBackend<T: EthSpec>(PhantomData<T>);
pub struct DummyEth1ChainBackend<E: EthSpec>(PhantomData<E>);
impl<T: EthSpec> Eth1ChainBackend<T> for DummyEth1ChainBackend<T> {
impl<E: EthSpec> Eth1ChainBackend<E> for DummyEth1ChainBackend<E> {
/// Produce some deterministic junk based upon the current epoch.
fn eth1_data(&self, state: &BeaconState<T>, _spec: &ChainSpec) -> Result<Eth1Data, Error> {
fn eth1_data(&self, state: &BeaconState<E>, _spec: &ChainSpec) -> Result<Eth1Data, Error> {
let current_epoch = state.current_epoch();
let slots_per_voting_period = T::slots_per_eth1_voting_period() as u64;
let slots_per_voting_period = E::slots_per_eth1_voting_period() as u64;
let current_voting_period: u64 = current_epoch.as_u64() / slots_per_voting_period;
let deposit_root = hash(&int_to_bytes32(current_voting_period));
@@ -386,7 +386,7 @@ impl<T: EthSpec> Eth1ChainBackend<T> for DummyEth1ChainBackend<T> {
/// The dummy back-end never produces deposits.
fn queued_deposits(
&self,
_: &BeaconState<T>,
_: &BeaconState<E>,
_: &Eth1Data,
_: &ChainSpec,
) -> Result<Vec<Deposit>, Error> {
@@ -419,7 +419,7 @@ impl<T: EthSpec> Eth1ChainBackend<T> for DummyEth1ChainBackend<T> {
}
}
impl<T: EthSpec> Default for DummyEth1ChainBackend<T> {
impl<E: EthSpec> Default for DummyEth1ChainBackend<E> {
fn default() -> Self {
Self(PhantomData)
}
@@ -431,13 +431,13 @@ impl<T: EthSpec> Default for DummyEth1ChainBackend<T> {
/// The `core` connects to some external eth1 client (e.g., Parity/Geth) and polls it for
/// information.
#[derive(Clone)]
pub struct CachingEth1Backend<T: EthSpec> {
pub struct CachingEth1Backend<E: EthSpec> {
pub core: HttpService,
log: Logger,
_phantom: PhantomData<T>,
_phantom: PhantomData<E>,
}
impl<T: EthSpec> CachingEth1Backend<T> {
impl<E: EthSpec> CachingEth1Backend<E> {
/// Instantiates `self` with empty caches.
///
/// Does not connect to the eth1 node or start any tasks to keep the cache updated.
@@ -465,9 +465,9 @@ impl<T: EthSpec> CachingEth1Backend<T> {
}
}
impl<T: EthSpec> Eth1ChainBackend<T> for CachingEth1Backend<T> {
fn eth1_data(&self, state: &BeaconState<T>, spec: &ChainSpec) -> Result<Eth1Data, Error> {
let period = T::SlotsPerEth1VotingPeriod::to_u64();
impl<E: EthSpec> Eth1ChainBackend<E> for CachingEth1Backend<E> {
fn eth1_data(&self, state: &BeaconState<E>, spec: &ChainSpec) -> Result<Eth1Data, Error> {
let period = E::SlotsPerEth1VotingPeriod::to_u64();
let voting_period_start_slot = (state.slot() / period) * period;
let voting_period_start_seconds = slot_start_seconds(
state.genesis_time(),
@@ -535,7 +535,7 @@ impl<T: EthSpec> Eth1ChainBackend<T> for CachingEth1Backend<T> {
fn queued_deposits(
&self,
state: &BeaconState<T>,
state: &BeaconState<E>,
eth1_data_vote: &Eth1Data,
_spec: &ChainSpec,
) -> Result<Vec<Deposit>, Error> {
@@ -551,7 +551,7 @@ impl<T: EthSpec> Eth1ChainBackend<T> for CachingEth1Backend<T> {
Ordering::Equal => Ok(vec![]),
Ordering::Less => {
let next = deposit_index;
let last = std::cmp::min(deposit_count, next + T::MaxDeposits::to_u64());
let last = std::cmp::min(deposit_count, next + E::MaxDeposits::to_u64());
self.core
.deposits()
@@ -626,8 +626,8 @@ where
/// Collect all valid votes that are cast during the current voting period.
/// Return hashmap with count of each vote cast.
fn collect_valid_votes<T: EthSpec>(
state: &BeaconState<T>,
fn collect_valid_votes<E: EthSpec>(
state: &BeaconState<E>,
votes_to_consider: &HashMap<Eth1Data, BlockNumber>,
) -> Eth1DataVoteCount {
let mut valid_votes = HashMap::new();