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

@@ -53,24 +53,24 @@ impl CommitteeStore {
}
}
struct PackingEfficiencyHandler<T: EthSpec> {
struct PackingEfficiencyHandler<E: EthSpec> {
current_slot: Slot,
current_epoch: Epoch,
prior_skip_slots: u64,
available_attestations: HashSet<UniqueAttestation>,
included_attestations: HashMap<UniqueAttestation, u64>,
committee_store: CommitteeStore,
_phantom: PhantomData<T>,
_phantom: PhantomData<E>,
}
impl<T: EthSpec> PackingEfficiencyHandler<T> {
impl<E: EthSpec> PackingEfficiencyHandler<E> {
fn new(
start_epoch: Epoch,
starting_state: BeaconState<T>,
starting_state: BeaconState<E>,
spec: &ChainSpec,
) -> Result<Self, PackingEfficiencyError> {
let mut handler = PackingEfficiencyHandler {
current_slot: start_epoch.start_slot(T::slots_per_epoch()),
current_slot: start_epoch.start_slot(E::slots_per_epoch()),
current_epoch: start_epoch,
prior_skip_slots: 0,
available_attestations: HashSet::new(),
@@ -85,27 +85,27 @@ impl<T: EthSpec> PackingEfficiencyHandler<T> {
fn update_slot(&mut self, slot: Slot) {
self.current_slot = slot;
if slot % T::slots_per_epoch() == 0 {
self.current_epoch = Epoch::new(slot.as_u64() / T::slots_per_epoch());
if slot % E::slots_per_epoch() == 0 {
self.current_epoch = Epoch::new(slot.as_u64() / E::slots_per_epoch());
}
}
fn prune_included_attestations(&mut self) {
let epoch = self.current_epoch;
self.included_attestations.retain(|x, _| {
x.slot >= Epoch::new(epoch.as_u64().saturating_sub(2)).start_slot(T::slots_per_epoch())
x.slot >= Epoch::new(epoch.as_u64().saturating_sub(2)).start_slot(E::slots_per_epoch())
});
}
fn prune_available_attestations(&mut self) {
let slot = self.current_slot;
self.available_attestations
.retain(|x| x.slot >= (slot.as_u64().saturating_sub(T::slots_per_epoch())));
.retain(|x| x.slot >= (slot.as_u64().saturating_sub(E::slots_per_epoch())));
}
fn apply_block(
&mut self,
block: &SignedBeaconBlock<T, BlindedPayload<T>>,
block: &SignedBeaconBlock<E, BlindedPayload<E>>,
) -> Result<usize, PackingEfficiencyError> {
let block_body = block.message().body();
let attestations = block_body.attestations();
@@ -158,7 +158,7 @@ impl<T: EthSpec> PackingEfficiencyHandler<T> {
fn compute_epoch(
&mut self,
epoch: Epoch,
state: &BeaconState<T>,
state: &BeaconState<E>,
spec: &ChainSpec,
) -> Result<(), PackingEfficiencyError> {
// Free some memory by pruning old attestations from the included set.

View File

@@ -4594,9 +4594,9 @@ pub fn serve<T: BeaconChainTypes>(
}
/// Publish a message to the libp2p pubsub network.
fn publish_pubsub_message<T: EthSpec>(
network_tx: &UnboundedSender<NetworkMessage<T>>,
message: PubsubMessage<T>,
fn publish_pubsub_message<E: EthSpec>(
network_tx: &UnboundedSender<NetworkMessage<E>>,
message: PubsubMessage<E>,
) -> Result<(), warp::Rejection> {
publish_network_message(
network_tx,
@@ -4607,17 +4607,17 @@ fn publish_pubsub_message<T: EthSpec>(
}
/// Publish a message to the libp2p pubsub network.
fn publish_pubsub_messages<T: EthSpec>(
network_tx: &UnboundedSender<NetworkMessage<T>>,
messages: Vec<PubsubMessage<T>>,
fn publish_pubsub_messages<E: EthSpec>(
network_tx: &UnboundedSender<NetworkMessage<E>>,
messages: Vec<PubsubMessage<E>>,
) -> Result<(), warp::Rejection> {
publish_network_message(network_tx, NetworkMessage::Publish { messages })
}
/// Publish a message to the libp2p network.
fn publish_network_message<T: EthSpec>(
network_tx: &UnboundedSender<NetworkMessage<T>>,
message: NetworkMessage<T>,
fn publish_network_message<E: EthSpec>(
network_tx: &UnboundedSender<NetworkMessage<E>>,
message: NetworkMessage<E>,
) -> Result<(), warp::Rejection> {
network_tx.send(message).map_err(|e| {
warp_utils::reject::custom_server_error(format!(

View File

@@ -27,10 +27,10 @@ fn end_of_epoch_state<T: BeaconChainTypes>(
/// ## Notes
///
/// Will mutate `state`, transitioning it to the next epoch.
fn get_epoch_processing_summary<T: EthSpec>(
state: &mut BeaconState<T>,
fn get_epoch_processing_summary<E: EthSpec>(
state: &mut BeaconState<E>,
spec: &ChainSpec,
) -> Result<EpochProcessingSummary<T>, warp::reject::Rejection> {
) -> Result<EpochProcessingSummary<E>, warp::reject::Rejection> {
process_epoch(state, spec)
.map_err(|e| warp_utils::reject::custom_server_error(format!("{:?}", e)))
}