Skip to content

Commit 969d12d

Browse files
authored
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
1 parent f8fdb71 commit 969d12d

File tree

230 files changed

+2743
-2792
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

230 files changed

+2743
-2792
lines changed

account_manager/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
2222
}
2323

2424
/// Run the account manager, returning an error if the operation did not succeed.
25-
pub fn run<T: EthSpec>(matches: &ArgMatches<'_>, env: Environment<T>) -> Result<(), String> {
25+
pub fn run<E: EthSpec>(matches: &ArgMatches<'_>, env: Environment<E>) -> Result<(), String> {
2626
match matches.subcommand() {
2727
(wallet::CMD, Some(matches)) => wallet::cli_run(matches)?,
2828
(validator::CMD, Some(matches)) => validator::cli_run(matches, env)?,

account_manager/src/validator/create.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,9 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
112112
)
113113
}
114114

115-
pub fn cli_run<T: EthSpec>(
115+
pub fn cli_run<E: EthSpec>(
116116
matches: &ArgMatches,
117-
env: Environment<T>,
117+
env: Environment<E>,
118118
validator_dir: PathBuf,
119119
) -> Result<(), String> {
120120
let spec = env.core_context().eth2_config.spec;

account_manager/src/validator/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
3939
.subcommand(exit::cli_app())
4040
}
4141

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

5151
match matches.subcommand() {
52-
(create::CMD, Some(matches)) => create::cli_run::<T>(matches, env, validator_base_dir),
52+
(create::CMD, Some(matches)) => create::cli_run::<E>(matches, env, validator_base_dir),
5353
(modify::CMD, Some(matches)) => modify::cli_run(matches, validator_base_dir),
5454
(import::CMD, Some(matches)) => import::cli_run(matches, validator_base_dir),
5555
(list::CMD, Some(_)) => list::cli_run(validator_base_dir),

account_manager/src/validator/slashing_protection.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
5353
)
5454
}
5555

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

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

7070
match matches.subcommand() {

beacon_node/beacon_chain/src/attestation_verification.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1121,13 +1121,13 @@ pub fn verify_attestation_signature<T: BeaconChainTypes>(
11211121

11221122
/// Verifies that the `attestation.data.target.root` is indeed the target root of the block at
11231123
/// `attestation.data.beacon_block_root`.
1124-
pub fn verify_attestation_target_root<T: EthSpec>(
1124+
pub fn verify_attestation_target_root<E: EthSpec>(
11251125
head_block: &ProtoBlock,
1126-
attestation: &Attestation<T>,
1126+
attestation: &Attestation<E>,
11271127
) -> Result<(), Error> {
11281128
// Check the attestation target root.
1129-
let head_block_epoch = head_block.slot.epoch(T::slots_per_epoch());
1130-
let attestation_epoch = attestation.data.slot.epoch(T::slots_per_epoch());
1129+
let head_block_epoch = head_block.slot.epoch(E::slots_per_epoch());
1130+
let attestation_epoch = attestation.data.slot.epoch(E::slots_per_epoch());
11311131
if head_block_epoch > attestation_epoch {
11321132
// The epoch references an invalid head block from a future epoch.
11331133
//

beacon_node/beacon_chain/src/attester_cache.rs

+16-16
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ pub struct CommitteeLengths {
8484

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

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

112112
/// Get the length of the committee at the given `slot` and `committee_index`.
113-
pub fn get_committee_length<T: EthSpec>(
113+
pub fn get_committee_length<E: EthSpec>(
114114
&self,
115115
slot: Slot,
116116
committee_index: CommitteeIndex,
117117
spec: &ChainSpec,
118118
) -> Result<CommitteeLength, Error> {
119-
let slots_per_epoch = T::slots_per_epoch();
119+
let slots_per_epoch = E::slots_per_epoch();
120120
let request_epoch = slot.epoch(slots_per_epoch);
121121

122122
// Sanity check.
@@ -128,7 +128,7 @@ impl CommitteeLengths {
128128
}
129129

130130
let slots_per_epoch = slots_per_epoch as usize;
131-
let committees_per_slot = self.get_committee_count_per_slot::<T>(spec)?;
131+
let committees_per_slot = self.get_committee_count_per_slot::<E>(spec)?;
132132
let index_in_epoch = compute_committee_index_in_epoch(
133133
slot,
134134
slots_per_epoch,
@@ -162,7 +162,7 @@ pub struct AttesterCacheValue {
162162

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

174174
/// Get the justified checkpoint and committee length for some `slot` and `committee_index`.
175-
fn get<T: EthSpec>(
175+
fn get<E: EthSpec>(
176176
&self,
177177
slot: Slot,
178178
committee_index: CommitteeIndex,
179179
spec: &ChainSpec,
180180
) -> Result<(JustifiedCheckpoint, CommitteeLength), Error> {
181181
self.committee_lengths
182-
.get_committee_length::<T>(slot, committee_index, spec)
182+
.get_committee_length::<E>(slot, committee_index, spec)
183183
.map(|committee_length| (self.current_justified_checkpoint, committee_length))
184184
}
185185
}
@@ -216,12 +216,12 @@ impl AttesterCacheKey {
216216
/// ## Errors
217217
///
218218
/// May error if `epoch` is out of the range of `state.block_roots`.
219-
pub fn new<T: EthSpec>(
219+
pub fn new<E: EthSpec>(
220220
epoch: Epoch,
221-
state: &BeaconState<T>,
221+
state: &BeaconState<E>,
222222
latest_block_root: Hash256,
223223
) -> Result<Self, Error> {
224-
let slots_per_epoch = T::slots_per_epoch();
224+
let slots_per_epoch = E::slots_per_epoch();
225225
let decision_slot = epoch.start_slot(slots_per_epoch).saturating_sub(1_u64);
226226

227227
let decision_root = if decision_slot.epoch(slots_per_epoch) == epoch {
@@ -255,7 +255,7 @@ pub struct AttesterCache {
255255
impl AttesterCache {
256256
/// Get the justified checkpoint and committee length for the `slot` and `committee_index` in
257257
/// the state identified by the cache `key`.
258-
pub fn get<T: EthSpec>(
258+
pub fn get<E: EthSpec>(
259259
&self,
260260
key: &AttesterCacheKey,
261261
slot: Slot,
@@ -265,14 +265,14 @@ impl AttesterCache {
265265
self.cache
266266
.read()
267267
.get(key)
268-
.map(|cache_item| cache_item.get::<T>(slot, committee_index, spec))
268+
.map(|cache_item| cache_item.get::<E>(slot, committee_index, spec))
269269
.transpose()
270270
}
271271

272272
/// Cache the `state.current_epoch()` values if they are not already present in the state.
273-
pub fn maybe_cache_state<T: EthSpec>(
273+
pub fn maybe_cache_state<E: EthSpec>(
274274
&self,
275-
state: &BeaconState<T>,
275+
state: &BeaconState<E>,
276276
latest_block_root: Hash256,
277277
spec: &ChainSpec,
278278
) -> Result<(), Error> {

beacon_node/beacon_chain/src/beacon_chain.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -215,14 +215,14 @@ impl TryInto<Hash256> for AvailabilityProcessingStatus {
215215
}
216216

217217
/// The result of a chain segment processing.
218-
pub enum ChainSegmentResult<T: EthSpec> {
218+
pub enum ChainSegmentResult<E: EthSpec> {
219219
/// Processing this chain segment finished successfully.
220220
Successful { imported_blocks: usize },
221221
/// There was an error processing this chain segment. Before the error, some blocks could
222222
/// have been imported.
223223
Failed {
224224
imported_blocks: usize,
225-
error: BlockError<T>,
225+
error: BlockError<E>,
226226
},
227227
}
228228

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

496-
pub enum BeaconBlockResponseWrapper<T: EthSpec> {
497-
Full(BeaconBlockResponse<T, FullPayload<T>>),
498-
Blinded(BeaconBlockResponse<T, BlindedPayload<T>>),
496+
pub enum BeaconBlockResponseWrapper<E: EthSpec> {
497+
Full(BeaconBlockResponse<E, FullPayload<E>>),
498+
Blinded(BeaconBlockResponse<E, BlindedPayload<E>>),
499499
}
500500

501501
impl<E: EthSpec> BeaconBlockResponseWrapper<E> {
@@ -530,13 +530,13 @@ impl<E: EthSpec> BeaconBlockResponseWrapper<E> {
530530
}
531531

532532
/// The components produced when the local beacon node creates a new block to extend the chain
533-
pub struct BeaconBlockResponse<T: EthSpec, Payload: AbstractExecPayload<T>> {
533+
pub struct BeaconBlockResponse<E: EthSpec, Payload: AbstractExecPayload<E>> {
534534
/// The newly produced beacon block
535-
pub block: BeaconBlock<T, Payload>,
535+
pub block: BeaconBlock<E, Payload>,
536536
/// The post-state after applying the new block
537-
pub state: BeaconState<T>,
537+
pub state: BeaconState<E>,
538538
/// The Blobs / Proofs associated with the new block
539-
pub blob_items: Option<(KzgProofs<T>, BlobsList<T>)>,
539+
pub blob_items: Option<(KzgProofs<E>, BlobsList<E>)>,
540540
/// The execution layer reward for the block
541541
pub execution_payload_value: Uint256,
542542
/// The consensus layer reward to the proposer
@@ -6758,8 +6758,8 @@ impl From<BeaconStateError> for Error {
67586758
}
67596759
}
67606760

6761-
impl<T: EthSpec> ChainSegmentResult<T> {
6762-
pub fn into_block_error(self) -> Result<(), BlockError<T>> {
6761+
impl<E: EthSpec> ChainSegmentResult<E> {
6762+
pub fn into_block_error(self) -> Result<(), BlockError<E>> {
67636763
match self {
67646764
ChainSegmentResult::Failed { error, .. } => Err(error),
67656765
ChainSegmentResult::Successful { .. } => Ok(()),

beacon_node/beacon_chain/src/beacon_proposer_cache.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,19 @@ impl Default for BeaconProposerCache {
6868
impl BeaconProposerCache {
6969
/// If it is cached, returns the proposer for the block at `slot` where the block has the
7070
/// ancestor block root of `shuffling_decision_block` at `end_slot(slot.epoch() - 1)`.
71-
pub fn get_slot<T: EthSpec>(
71+
pub fn get_slot<E: EthSpec>(
7272
&mut self,
7373
shuffling_decision_block: Hash256,
7474
slot: Slot,
7575
) -> Option<Proposer> {
76-
let epoch = slot.epoch(T::slots_per_epoch());
76+
let epoch = slot.epoch(E::slots_per_epoch());
7777
let key = (epoch, shuffling_decision_block);
7878
if let Some(cache) = self.cache.get(&key) {
7979
// This `if` statement is likely unnecessary, but it feels like good practice.
8080
if epoch == cache.epoch {
8181
cache
8282
.proposers
83-
.get(slot.as_usize() % T::SlotsPerEpoch::to_usize())
83+
.get(slot.as_usize() % E::SlotsPerEpoch::to_usize())
8484
.map(|&index| Proposer {
8585
index,
8686
fork: cache.fork,
@@ -98,7 +98,7 @@ impl BeaconProposerCache {
9898
/// The nth slot in the returned `SmallVec` will be equal to the nth slot in the given `epoch`.
9999
/// E.g., if `epoch == 1` then `smallvec[0]` refers to slot 32 (assuming `SLOTS_PER_EPOCH ==
100100
/// 32`).
101-
pub fn get_epoch<T: EthSpec>(
101+
pub fn get_epoch<E: EthSpec>(
102102
&mut self,
103103
shuffling_decision_block: Hash256,
104104
epoch: Epoch,

0 commit comments

Comments
 (0)