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

@@ -382,7 +382,7 @@ struct MissedBlock {
///
/// The intention of this struct is to provide users with more logging and Prometheus metrics around
/// validators that they are interested in.
pub struct ValidatorMonitor<T: EthSpec> {
pub struct ValidatorMonitor<E: EthSpec> {
/// The validators that require additional monitoring.
validators: HashMap<PublicKeyBytes, MonitoredValidator>,
/// A map of validator index (state.validators) to a validator public key.
@@ -399,12 +399,12 @@ pub struct ValidatorMonitor<T: EthSpec> {
// A beacon proposer cache
beacon_proposer_cache: Arc<Mutex<BeaconProposerCache>>,
// Unaggregated attestations generated by the committee index at each slot.
unaggregated_attestations: HashMap<Slot, Attestation<T>>,
unaggregated_attestations: HashMap<Slot, Attestation<E>>,
log: Logger,
_phantom: PhantomData<T>,
_phantom: PhantomData<E>,
}
impl<T: EthSpec> ValidatorMonitor<T> {
impl<E: EthSpec> ValidatorMonitor<E> {
pub fn new(
config: ValidatorMonitorConfig,
beacon_proposer_cache: Arc<Mutex<BeaconProposerCache>>,
@@ -460,7 +460,7 @@ impl<T: EthSpec> ValidatorMonitor<T> {
}
/// Add an unaggregated attestation
pub fn set_unaggregated_attestation(&mut self, attestation: Attestation<T>) {
pub fn set_unaggregated_attestation(&mut self, attestation: Attestation<E>) {
let unaggregated_attestations = &mut self.unaggregated_attestations;
// Pruning, this removes the oldest key/pair of the hashmap if it's greater than MAX_UNAGGREGATED_ATTESTATION_HASHMAP_LENGTH
@@ -473,7 +473,7 @@ impl<T: EthSpec> ValidatorMonitor<T> {
self.unaggregated_attestations.insert(slot, attestation);
}
pub fn get_unaggregated_attestation(&self, slot: Slot) -> Option<&Attestation<T>> {
pub fn get_unaggregated_attestation(&self, slot: Slot) -> Option<&Attestation<E>> {
self.unaggregated_attestations.get(&slot)
}
@@ -482,7 +482,7 @@ impl<T: EthSpec> ValidatorMonitor<T> {
pub fn process_valid_state(
&mut self,
current_epoch: Epoch,
state: &BeaconState<T>,
state: &BeaconState<E>,
spec: &ChainSpec,
) {
// Add any new validator indices.
@@ -585,19 +585,19 @@ impl<T: EthSpec> ValidatorMonitor<T> {
// Prune missed blocks that are prior to last finalized epochs - MISSED_BLOCK_LOOKBACK_EPOCHS
let finalized_epoch = state.finalized_checkpoint().epoch;
self.missed_blocks.retain(|missed_block| {
let epoch = missed_block.slot.epoch(T::slots_per_epoch());
let epoch = missed_block.slot.epoch(E::slots_per_epoch());
epoch + Epoch::new(MISSED_BLOCK_LOOKBACK_EPOCHS) >= finalized_epoch
});
}
/// Add missed non-finalized blocks for the monitored validators
fn add_validators_missed_blocks(&mut self, state: &BeaconState<T>) {
fn add_validators_missed_blocks(&mut self, state: &BeaconState<E>) {
// Define range variables
let current_slot = state.slot();
let current_epoch = current_slot.epoch(T::slots_per_epoch());
let current_epoch = current_slot.epoch(E::slots_per_epoch());
// start_slot needs to be coherent with what can be retrieved from the beacon_proposer_cache
let start_slot = current_epoch.start_slot(T::slots_per_epoch())
- Slot::new(MISSED_BLOCK_LOOKBACK_EPOCHS * T::slots_per_epoch());
let start_slot = current_epoch.start_slot(E::slots_per_epoch())
- Slot::new(MISSED_BLOCK_LOOKBACK_EPOCHS * E::slots_per_epoch());
let end_slot = current_slot.saturating_sub(MISSED_BLOCK_LAG_SLOTS).as_u64();
@@ -617,7 +617,7 @@ impl<T: EthSpec> ValidatorMonitor<T> {
{
// Found missed block
if block_root == prev_block_root {
let slot_epoch = slot.epoch(T::slots_per_epoch());
let slot_epoch = slot.epoch(E::slots_per_epoch());
if let Ok(shuffling_decision_block) =
state.proposer_shuffling_decision_root_at_epoch(slot_epoch, *block_root)
@@ -638,7 +638,7 @@ impl<T: EthSpec> ValidatorMonitor<T> {
}
// Only add missed blocks for the proposer if it's in the list of monitored validators
let slot_in_epoch = slot % T::slots_per_epoch();
let slot_in_epoch = slot % E::slots_per_epoch();
if let Some(proposer_index) = proposers_per_epoch
.as_ref()
.and_then(|(proposers, _)| proposers.get(slot_in_epoch.as_usize()))
@@ -697,13 +697,13 @@ impl<T: EthSpec> ValidatorMonitor<T> {
) -> Option<SmallVec<[usize; TYPICAL_SLOTS_PER_EPOCH]>> {
let mut cache = self.beacon_proposer_cache.lock();
cache
.get_epoch::<T>(shuffling_decision_block, epoch)
.get_epoch::<E>(shuffling_decision_block, epoch)
.cloned()
}
/// Process the unaggregated attestations generated by the service `attestation_simulator_service`
/// and check if the attestation qualifies for a reward matching the flags source/target/head
fn process_unaggregated_attestations(&mut self, state: &BeaconState<T>, spec: &ChainSpec) {
fn process_unaggregated_attestations(&mut self, state: &BeaconState<E>, spec: &ChainSpec) {
let current_slot = state.slot();
// Ensures that we process attestation when there have been skipped slots between blocks
@@ -721,7 +721,7 @@ impl<T: EthSpec> ValidatorMonitor<T> {
for slot in attested_slots {
if let Some(unaggregated_attestation) = unaggregated_attestations.remove(&slot) {
// Don't process this attestation, it's too old to be processed by this state.
if slot.epoch(T::slots_per_epoch()) < state.previous_epoch() {
if slot.epoch(E::slots_per_epoch()) < state.previous_epoch() {
continue;
}
@@ -790,7 +790,7 @@ impl<T: EthSpec> ValidatorMonitor<T> {
pub fn process_validator_statuses(
&self,
epoch: Epoch,
summary: &EpochProcessingSummary<T>,
summary: &EpochProcessingSummary<E>,
spec: &ChainSpec,
) -> Result<(), EpochProcessingError> {
let mut attestation_success = Vec::new();
@@ -1005,7 +1005,7 @@ impl<T: EthSpec> ValidatorMonitor<T> {
self.log,
"Current epoch sync signatures";
"included" => summary.sync_signature_block_inclusions,
"expected" => T::slots_per_epoch(),
"expected" => E::slots_per_epoch(),
"epoch" => current_epoch,
"validator" => id,
);
@@ -1139,7 +1139,7 @@ impl<T: EthSpec> ValidatorMonitor<T> {
pub fn register_gossip_block<S: SlotClock>(
&self,
seen_timestamp: Duration,
block: BeaconBlockRef<'_, T>,
block: BeaconBlockRef<'_, E>,
block_root: Hash256,
slot_clock: &S,
) {
@@ -1150,7 +1150,7 @@ impl<T: EthSpec> ValidatorMonitor<T> {
pub fn register_api_block<S: SlotClock>(
&self,
seen_timestamp: Duration,
block: BeaconBlockRef<'_, T>,
block: BeaconBlockRef<'_, E>,
block_root: Hash256,
slot_clock: &S,
) {
@@ -1161,11 +1161,11 @@ impl<T: EthSpec> ValidatorMonitor<T> {
&self,
src: &str,
seen_timestamp: Duration,
block: BeaconBlockRef<'_, T>,
block: BeaconBlockRef<'_, E>,
block_root: Hash256,
slot_clock: &S,
) {
let epoch = block.slot().epoch(T::slots_per_epoch());
let epoch = block.slot().epoch(E::slots_per_epoch());
if let Some(validator) = self.get_validator(block.proposer_index()) {
let id = &validator.id;
let delay = get_block_delay_ms(seen_timestamp, block, slot_clock);
@@ -1200,7 +1200,7 @@ impl<T: EthSpec> ValidatorMonitor<T> {
pub fn register_gossip_unaggregated_attestation<S: SlotClock>(
&self,
seen_timestamp: Duration,
indexed_attestation: &IndexedAttestation<T>,
indexed_attestation: &IndexedAttestation<E>,
slot_clock: &S,
) {
self.register_unaggregated_attestation(
@@ -1215,7 +1215,7 @@ impl<T: EthSpec> ValidatorMonitor<T> {
pub fn register_api_unaggregated_attestation<S: SlotClock>(
&self,
seen_timestamp: Duration,
indexed_attestation: &IndexedAttestation<T>,
indexed_attestation: &IndexedAttestation<E>,
slot_clock: &S,
) {
self.register_unaggregated_attestation(
@@ -1230,11 +1230,11 @@ impl<T: EthSpec> ValidatorMonitor<T> {
&self,
src: &str,
seen_timestamp: Duration,
indexed_attestation: &IndexedAttestation<T>,
indexed_attestation: &IndexedAttestation<E>,
slot_clock: &S,
) {
let data = &indexed_attestation.data;
let epoch = data.slot.epoch(T::slots_per_epoch());
let epoch = data.slot.epoch(E::slots_per_epoch());
let delay = get_message_delay_ms(
seen_timestamp,
data.slot,
@@ -1283,8 +1283,8 @@ impl<T: EthSpec> ValidatorMonitor<T> {
pub fn register_gossip_aggregated_attestation<S: SlotClock>(
&self,
seen_timestamp: Duration,
signed_aggregate_and_proof: &SignedAggregateAndProof<T>,
indexed_attestation: &IndexedAttestation<T>,
signed_aggregate_and_proof: &SignedAggregateAndProof<E>,
indexed_attestation: &IndexedAttestation<E>,
slot_clock: &S,
) {
self.register_aggregated_attestation(
@@ -1300,8 +1300,8 @@ impl<T: EthSpec> ValidatorMonitor<T> {
pub fn register_api_aggregated_attestation<S: SlotClock>(
&self,
seen_timestamp: Duration,
signed_aggregate_and_proof: &SignedAggregateAndProof<T>,
indexed_attestation: &IndexedAttestation<T>,
signed_aggregate_and_proof: &SignedAggregateAndProof<E>,
indexed_attestation: &IndexedAttestation<E>,
slot_clock: &S,
) {
self.register_aggregated_attestation(
@@ -1317,12 +1317,12 @@ impl<T: EthSpec> ValidatorMonitor<T> {
&self,
src: &str,
seen_timestamp: Duration,
signed_aggregate_and_proof: &SignedAggregateAndProof<T>,
indexed_attestation: &IndexedAttestation<T>,
signed_aggregate_and_proof: &SignedAggregateAndProof<E>,
indexed_attestation: &IndexedAttestation<E>,
slot_clock: &S,
) {
let data = &indexed_attestation.data;
let epoch = data.slot.epoch(T::slots_per_epoch());
let epoch = data.slot.epoch(E::slots_per_epoch());
let delay = get_message_delay_ms(
seen_timestamp,
data.slot,
@@ -1410,7 +1410,7 @@ impl<T: EthSpec> ValidatorMonitor<T> {
/// Note: Blocks that get orphaned will skew the inclusion distance calculation.
pub fn register_attestation_in_block(
&self,
indexed_attestation: &IndexedAttestation<T>,
indexed_attestation: &IndexedAttestation<E>,
parent_slot: Slot,
spec: &ChainSpec,
) {
@@ -1421,7 +1421,7 @@ impl<T: EthSpec> ValidatorMonitor<T> {
let inclusion_distance = parent_slot.saturating_sub(data.slot) + 1;
let delay = inclusion_distance - spec.min_attestation_inclusion_delay;
let epoch = data.slot.epoch(T::slots_per_epoch());
let epoch = data.slot.epoch(E::slots_per_epoch());
indexed_attestation.attesting_indices.iter().for_each(|i| {
if let Some(validator) = self.get_validator(*i) {
@@ -1501,7 +1501,7 @@ impl<T: EthSpec> ValidatorMonitor<T> {
if let Some(validator) = self.get_validator(sync_committee_message.validator_index) {
let id = &validator.id;
let epoch = sync_committee_message.slot.epoch(T::slots_per_epoch());
let epoch = sync_committee_message.slot.epoch(E::slots_per_epoch());
let delay = get_message_delay_ms(
seen_timestamp,
sync_committee_message.slot,
@@ -1544,7 +1544,7 @@ impl<T: EthSpec> ValidatorMonitor<T> {
pub fn register_gossip_sync_committee_contribution<S: SlotClock>(
&self,
seen_timestamp: Duration,
sync_contribution: &SignedContributionAndProof<T>,
sync_contribution: &SignedContributionAndProof<E>,
participant_pubkeys: &[PublicKeyBytes],
slot_clock: &S,
) {
@@ -1561,7 +1561,7 @@ impl<T: EthSpec> ValidatorMonitor<T> {
pub fn register_api_sync_committee_contribution<S: SlotClock>(
&self,
seen_timestamp: Duration,
sync_contribution: &SignedContributionAndProof<T>,
sync_contribution: &SignedContributionAndProof<E>,
participant_pubkeys: &[PublicKeyBytes],
slot_clock: &S,
) {
@@ -1579,12 +1579,12 @@ impl<T: EthSpec> ValidatorMonitor<T> {
&self,
src: &str,
seen_timestamp: Duration,
sync_contribution: &SignedContributionAndProof<T>,
sync_contribution: &SignedContributionAndProof<E>,
participant_pubkeys: &[PublicKeyBytes],
slot_clock: &S,
) {
let slot = sync_contribution.message.contribution.slot;
let epoch = slot.epoch(T::slots_per_epoch());
let epoch = slot.epoch(E::slots_per_epoch());
let beacon_block_root = sync_contribution.message.contribution.beacon_block_root;
let delay = get_message_delay_ms(
seen_timestamp,
@@ -1665,7 +1665,7 @@ impl<T: EthSpec> ValidatorMonitor<T> {
beacon_block_root: Hash256,
participant_pubkeys: Vec<&PublicKeyBytes>,
) {
let epoch = slot.epoch(T::slots_per_epoch());
let epoch = slot.epoch(E::slots_per_epoch());
for validator_pubkey in participant_pubkeys {
if let Some(validator) = self.validators.get(validator_pubkey) {
@@ -1752,7 +1752,7 @@ impl<T: EthSpec> ValidatorMonitor<T> {
fn register_proposer_slashing(&self, src: &str, slashing: &ProposerSlashing) {
let proposer = slashing.signed_header_1.message.proposer_index;
let slot = slashing.signed_header_1.message.slot;
let epoch = slot.epoch(T::slots_per_epoch());
let epoch = slot.epoch(E::slots_per_epoch());
let root_1 = slashing.signed_header_1.message.canonical_root();
let root_2 = slashing.signed_header_2.message.canonical_root();
@@ -1783,21 +1783,21 @@ impl<T: EthSpec> ValidatorMonitor<T> {
}
/// Register an attester slashing from the gossip network.
pub fn register_gossip_attester_slashing(&self, slashing: &AttesterSlashing<T>) {
pub fn register_gossip_attester_slashing(&self, slashing: &AttesterSlashing<E>) {
self.register_attester_slashing("gossip", slashing)
}
/// Register an attester slashing from the HTTP API.
pub fn register_api_attester_slashing(&self, slashing: &AttesterSlashing<T>) {
pub fn register_api_attester_slashing(&self, slashing: &AttesterSlashing<E>) {
self.register_attester_slashing("api", slashing)
}
/// Register an attester slashing included in a *valid* `BeaconBlock`.
pub fn register_block_attester_slashing(&self, slashing: &AttesterSlashing<T>) {
pub fn register_block_attester_slashing(&self, slashing: &AttesterSlashing<E>) {
self.register_attester_slashing("block", slashing)
}
fn register_attester_slashing(&self, src: &str, slashing: &AttesterSlashing<T>) {
fn register_attester_slashing(&self, src: &str, slashing: &AttesterSlashing<E>) {
let data = &slashing.attestation_1.data;
let attestation_1_indices: HashSet<u64> = slashing
.attestation_1
@@ -1814,7 +1814,7 @@ impl<T: EthSpec> ValidatorMonitor<T> {
.filter_map(|index| self.get_validator(*index))
.for_each(|validator| {
let id = &validator.id;
let epoch = data.slot.epoch(T::slots_per_epoch());
let epoch = data.slot.epoch(E::slots_per_epoch());
self.aggregatable_metric(id, |label| {
metrics::inc_counter_vec(
@@ -1848,8 +1848,8 @@ impl<T: EthSpec> ValidatorMonitor<T> {
);
if let Some(slot) = slot_clock.now() {
let epoch = slot.epoch(T::slots_per_epoch());
let slot_in_epoch = slot % T::slots_per_epoch();
let epoch = slot.epoch(E::slots_per_epoch());
let slot_in_epoch = slot % E::slots_per_epoch();
// Only start to report on the current epoch once we've progressed past the point where
// all attestation should be included in a block.
@@ -2072,9 +2072,9 @@ fn u64_to_i64(n: impl Into<u64>) -> i64 {
}
/// Returns the delay between the start of `block.slot` and `seen_timestamp`.
pub fn get_block_delay_ms<T: EthSpec, S: SlotClock, P: AbstractExecPayload<T>>(
pub fn get_block_delay_ms<E: EthSpec, S: SlotClock, P: AbstractExecPayload<E>>(
seen_timestamp: Duration,
block: BeaconBlockRef<'_, T, P>,
block: BeaconBlockRef<'_, E, P>,
slot_clock: &S,
) -> Duration {
get_slot_delay_ms::<S>(seen_timestamp, block.slot(), slot_clock)