Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use E for EthSpec globally #5264

Merged
merged 4 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion account_manager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
}

/// Run the account manager, returning an error if the operation did not succeed.
pub fn run<T: EthSpec>(matches: &ArgMatches<'_>, env: Environment<T>) -> Result<(), String> {
pub fn run<E: EthSpec>(matches: &ArgMatches<'_>, env: Environment<E>) -> Result<(), String> {
match matches.subcommand() {
(wallet::CMD, Some(matches)) => wallet::cli_run(matches)?,
(validator::CMD, Some(matches)) => validator::cli_run(matches, env)?,
Expand Down
4 changes: 2 additions & 2 deletions account_manager/src/validator/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
)
}

pub fn cli_run<T: EthSpec>(
pub fn cli_run<E: EthSpec>(
matches: &ArgMatches,
env: Environment<T>,
env: Environment<E>,
validator_dir: PathBuf,
) -> Result<(), String> {
let spec = env.core_context().eth2_config.spec;
Expand Down
4 changes: 2 additions & 2 deletions account_manager/src/validator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
.subcommand(exit::cli_app())
}

pub fn cli_run<T: EthSpec>(matches: &ArgMatches, env: Environment<T>) -> Result<(), String> {
pub fn cli_run<E: EthSpec>(matches: &ArgMatches, env: Environment<E>) -> Result<(), String> {
let validator_base_dir = if matches.value_of("datadir").is_some() {
let path: PathBuf = clap_utils::parse_required(matches, "datadir")?;
path.join(DEFAULT_VALIDATOR_DIR)
Expand All @@ -49,7 +49,7 @@ pub fn cli_run<T: EthSpec>(matches: &ArgMatches, env: Environment<T>) -> Result<
eprintln!("validator-dir path: {:?}", validator_base_dir);

match matches.subcommand() {
(create::CMD, Some(matches)) => create::cli_run::<T>(matches, env, validator_base_dir),
(create::CMD, Some(matches)) => create::cli_run::<E>(matches, env, validator_base_dir),
(modify::CMD, Some(matches)) => modify::cli_run(matches, validator_base_dir),
(import::CMD, Some(matches)) => import::cli_run(matches, validator_base_dir),
(list::CMD, Some(_)) => list::cli_run(validator_base_dir),
Expand Down
6 changes: 3 additions & 3 deletions account_manager/src/validator/slashing_protection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
)
}

pub fn cli_run<T: EthSpec>(
pub fn cli_run<E: EthSpec>(
matches: &ArgMatches<'_>,
env: Environment<T>,
env: Environment<E>,
validator_base_dir: PathBuf,
) -> Result<(), String> {
let slashing_protection_db_path = validator_base_dir.join(SLASHING_PROTECTION_FILENAME);
Expand All @@ -64,7 +64,7 @@ pub fn cli_run<T: EthSpec>(
.ok_or("Unable to get testnet configuration from the environment")?;

let genesis_validators_root = eth2_network_config
.genesis_validators_root::<T>()?
.genesis_validators_root::<E>()?
.ok_or_else(|| "Unable to get genesis state, has genesis occurred?".to_string())?;

match matches.subcommand() {
Expand Down
8 changes: 4 additions & 4 deletions beacon_node/beacon_chain/src/attestation_verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1121,13 +1121,13 @@ pub fn verify_attestation_signature<T: BeaconChainTypes>(

/// Verifies that the `attestation.data.target.root` is indeed the target root of the block at
/// `attestation.data.beacon_block_root`.
pub fn verify_attestation_target_root<T: EthSpec>(
pub fn verify_attestation_target_root<E: EthSpec>(
head_block: &ProtoBlock,
attestation: &Attestation<T>,
attestation: &Attestation<E>,
) -> Result<(), Error> {
// Check the attestation target root.
let head_block_epoch = head_block.slot.epoch(T::slots_per_epoch());
let attestation_epoch = attestation.data.slot.epoch(T::slots_per_epoch());
let head_block_epoch = head_block.slot.epoch(E::slots_per_epoch());
let attestation_epoch = attestation.data.slot.epoch(E::slots_per_epoch());
if head_block_epoch > attestation_epoch {
// The epoch references an invalid head block from a future epoch.
//
Expand Down
32 changes: 16 additions & 16 deletions beacon_node/beacon_chain/src/attester_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub struct CommitteeLengths {

impl CommitteeLengths {
/// Instantiate `Self` using `state.current_epoch()`.
pub fn new<T: EthSpec>(state: &BeaconState<T>, spec: &ChainSpec) -> Result<Self, Error> {
pub fn new<E: EthSpec>(state: &BeaconState<E>, spec: &ChainSpec) -> Result<Self, Error> {
let active_validator_indices_len = if let Ok(committee_cache) =
state.committee_cache(RelativeEpoch::Current)
{
Expand All @@ -102,21 +102,21 @@ impl CommitteeLengths {
}

/// Get the count of committees per each slot of `self.epoch`.
pub fn get_committee_count_per_slot<T: EthSpec>(
pub fn get_committee_count_per_slot<E: EthSpec>(
&self,
spec: &ChainSpec,
) -> Result<usize, Error> {
T::get_committee_count_per_slot(self.active_validator_indices_len, spec).map_err(Into::into)
E::get_committee_count_per_slot(self.active_validator_indices_len, spec).map_err(Into::into)
}

/// Get the length of the committee at the given `slot` and `committee_index`.
pub fn get_committee_length<T: EthSpec>(
pub fn get_committee_length<E: EthSpec>(
&self,
slot: Slot,
committee_index: CommitteeIndex,
spec: &ChainSpec,
) -> Result<CommitteeLength, Error> {
let slots_per_epoch = T::slots_per_epoch();
let slots_per_epoch = E::slots_per_epoch();
let request_epoch = slot.epoch(slots_per_epoch);

// Sanity check.
Expand All @@ -128,7 +128,7 @@ impl CommitteeLengths {
}

let slots_per_epoch = slots_per_epoch as usize;
let committees_per_slot = self.get_committee_count_per_slot::<T>(spec)?;
let committees_per_slot = self.get_committee_count_per_slot::<E>(spec)?;
let index_in_epoch = compute_committee_index_in_epoch(
slot,
slots_per_epoch,
Expand Down Expand Up @@ -162,7 +162,7 @@ pub struct AttesterCacheValue {

impl AttesterCacheValue {
/// Instantiate `Self` using `state.current_epoch()`.
pub fn new<T: EthSpec>(state: &BeaconState<T>, spec: &ChainSpec) -> Result<Self, Error> {
pub fn new<E: EthSpec>(state: &BeaconState<E>, spec: &ChainSpec) -> Result<Self, Error> {
let current_justified_checkpoint = state.current_justified_checkpoint();
let committee_lengths = CommitteeLengths::new(state, spec)?;
Ok(Self {
Expand All @@ -172,14 +172,14 @@ impl AttesterCacheValue {
}

/// Get the justified checkpoint and committee length for some `slot` and `committee_index`.
fn get<T: EthSpec>(
fn get<E: EthSpec>(
&self,
slot: Slot,
committee_index: CommitteeIndex,
spec: &ChainSpec,
) -> Result<(JustifiedCheckpoint, CommitteeLength), Error> {
self.committee_lengths
.get_committee_length::<T>(slot, committee_index, spec)
.get_committee_length::<E>(slot, committee_index, spec)
.map(|committee_length| (self.current_justified_checkpoint, committee_length))
}
}
Expand Down Expand Up @@ -216,12 +216,12 @@ impl AttesterCacheKey {
/// ## Errors
///
/// May error if `epoch` is out of the range of `state.block_roots`.
pub fn new<T: EthSpec>(
pub fn new<E: EthSpec>(
epoch: Epoch,
state: &BeaconState<T>,
state: &BeaconState<E>,
latest_block_root: Hash256,
) -> Result<Self, Error> {
let slots_per_epoch = T::slots_per_epoch();
let slots_per_epoch = E::slots_per_epoch();
let decision_slot = epoch.start_slot(slots_per_epoch).saturating_sub(1_u64);

let decision_root = if decision_slot.epoch(slots_per_epoch) == epoch {
Expand Down Expand Up @@ -255,7 +255,7 @@ pub struct AttesterCache {
impl AttesterCache {
/// Get the justified checkpoint and committee length for the `slot` and `committee_index` in
/// the state identified by the cache `key`.
pub fn get<T: EthSpec>(
pub fn get<E: EthSpec>(
&self,
key: &AttesterCacheKey,
slot: Slot,
Expand All @@ -265,14 +265,14 @@ impl AttesterCache {
self.cache
.read()
.get(key)
.map(|cache_item| cache_item.get::<T>(slot, committee_index, spec))
.map(|cache_item| cache_item.get::<E>(slot, committee_index, spec))
.transpose()
}

/// Cache the `state.current_epoch()` values if they are not already present in the state.
pub fn maybe_cache_state<T: EthSpec>(
pub fn maybe_cache_state<E: EthSpec>(
&self,
state: &BeaconState<T>,
state: &BeaconState<E>,
latest_block_root: Hash256,
spec: &ChainSpec,
) -> Result<(), Error> {
Expand Down
22 changes: 11 additions & 11 deletions beacon_node/beacon_chain/src/beacon_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,14 +215,14 @@ impl TryInto<Hash256> for AvailabilityProcessingStatus {
}

/// The result of a chain segment processing.
pub enum ChainSegmentResult<T: EthSpec> {
pub enum ChainSegmentResult<E: EthSpec> {
/// Processing this chain segment finished successfully.
Successful { imported_blocks: usize },
/// There was an error processing this chain segment. Before the error, some blocks could
/// have been imported.
Failed {
imported_blocks: usize,
error: BlockError<T>,
error: BlockError<E>,
},
}

Expand Down Expand Up @@ -493,9 +493,9 @@ pub struct BeaconChain<T: BeaconChainTypes> {
pub block_production_state: Arc<Mutex<Option<(Hash256, BlockProductionPreState<T::EthSpec>)>>>,
}

pub enum BeaconBlockResponseWrapper<T: EthSpec> {
Full(BeaconBlockResponse<T, FullPayload<T>>),
Blinded(BeaconBlockResponse<T, BlindedPayload<T>>),
pub enum BeaconBlockResponseWrapper<E: EthSpec> {
Full(BeaconBlockResponse<E, FullPayload<E>>),
Blinded(BeaconBlockResponse<E, BlindedPayload<E>>),
}

impl<E: EthSpec> BeaconBlockResponseWrapper<E> {
Expand Down Expand Up @@ -530,13 +530,13 @@ impl<E: EthSpec> BeaconBlockResponseWrapper<E> {
}

/// The components produced when the local beacon node creates a new block to extend the chain
pub struct BeaconBlockResponse<T: EthSpec, Payload: AbstractExecPayload<T>> {
pub struct BeaconBlockResponse<E: EthSpec, Payload: AbstractExecPayload<E>> {
/// The newly produced beacon block
pub block: BeaconBlock<T, Payload>,
pub block: BeaconBlock<E, Payload>,
/// The post-state after applying the new block
pub state: BeaconState<T>,
pub state: BeaconState<E>,
/// The Blobs / Proofs associated with the new block
pub blob_items: Option<(KzgProofs<T>, BlobsList<T>)>,
pub blob_items: Option<(KzgProofs<E>, BlobsList<E>)>,
/// The execution layer reward for the block
pub execution_payload_value: Uint256,
/// The consensus layer reward to the proposer
Expand Down Expand Up @@ -6758,8 +6758,8 @@ impl From<BeaconStateError> for Error {
}
}

impl<T: EthSpec> ChainSegmentResult<T> {
pub fn into_block_error(self) -> Result<(), BlockError<T>> {
impl<E: EthSpec> ChainSegmentResult<E> {
pub fn into_block_error(self) -> Result<(), BlockError<E>> {
match self {
ChainSegmentResult::Failed { error, .. } => Err(error),
ChainSegmentResult::Successful { .. } => Ok(()),
Expand Down
8 changes: 4 additions & 4 deletions beacon_node/beacon_chain/src/beacon_proposer_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,19 @@ impl Default for BeaconProposerCache {
impl BeaconProposerCache {
/// If it is cached, returns the proposer for the block at `slot` where the block has the
/// ancestor block root of `shuffling_decision_block` at `end_slot(slot.epoch() - 1)`.
pub fn get_slot<T: EthSpec>(
pub fn get_slot<E: EthSpec>(
&mut self,
shuffling_decision_block: Hash256,
slot: Slot,
) -> Option<Proposer> {
let epoch = slot.epoch(T::slots_per_epoch());
let epoch = slot.epoch(E::slots_per_epoch());
let key = (epoch, shuffling_decision_block);
if let Some(cache) = self.cache.get(&key) {
// This `if` statement is likely unnecessary, but it feels like good practice.
if epoch == cache.epoch {
cache
.proposers
.get(slot.as_usize() % T::SlotsPerEpoch::to_usize())
.get(slot.as_usize() % E::SlotsPerEpoch::to_usize())
.map(|&index| Proposer {
index,
fork: cache.fork,
Expand All @@ -98,7 +98,7 @@ impl BeaconProposerCache {
/// The nth slot in the returned `SmallVec` will be equal to the nth slot in the given `epoch`.
/// E.g., if `epoch == 1` then `smallvec[0]` refers to slot 32 (assuming `SLOTS_PER_EPOCH ==
/// 32`).
pub fn get_epoch<T: EthSpec>(
pub fn get_epoch<E: EthSpec>(
&mut self,
shuffling_decision_block: Hash256,
epoch: Epoch,
Expand Down
Loading