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

@@ -44,8 +44,8 @@ pub enum Request {
BlobsByRoot(BlobsByRootRequest),
}
impl<TSpec: EthSpec> std::convert::From<Request> for OutboundRequest<TSpec> {
fn from(req: Request) -> OutboundRequest<TSpec> {
impl<E: EthSpec> std::convert::From<Request> for OutboundRequest<E> {
fn from(req: Request) -> OutboundRequest<E> {
match req {
Request::BlocksByRoot(r) => OutboundRequest::BlocksByRoot(r),
Request::BlocksByRange(r) => match r {
@@ -81,23 +81,23 @@ impl<TSpec: EthSpec> std::convert::From<Request> for OutboundRequest<TSpec> {
// Behaviour. For all protocol reponses managed by RPC see `RPCResponse` and
// `RPCCodedResponse`.
#[derive(Debug, Clone, PartialEq)]
pub enum Response<TSpec: EthSpec> {
pub enum Response<E: EthSpec> {
/// A Status message.
Status(StatusMessage),
/// A response to a get BLOCKS_BY_RANGE request. A None response signals the end of the batch.
BlocksByRange(Option<Arc<SignedBeaconBlock<TSpec>>>),
BlocksByRange(Option<Arc<SignedBeaconBlock<E>>>),
/// A response to a get BLOBS_BY_RANGE request. A None response signals the end of the batch.
BlobsByRange(Option<Arc<BlobSidecar<TSpec>>>),
BlobsByRange(Option<Arc<BlobSidecar<E>>>),
/// A response to a get BLOCKS_BY_ROOT request.
BlocksByRoot(Option<Arc<SignedBeaconBlock<TSpec>>>),
BlocksByRoot(Option<Arc<SignedBeaconBlock<E>>>),
/// A response to a get BLOBS_BY_ROOT request.
BlobsByRoot(Option<Arc<BlobSidecar<TSpec>>>),
BlobsByRoot(Option<Arc<BlobSidecar<E>>>),
/// A response to a LightClientUpdate request.
LightClientBootstrap(Arc<LightClientBootstrap<TSpec>>),
LightClientBootstrap(Arc<LightClientBootstrap<E>>),
}
impl<TSpec: EthSpec> std::convert::From<Response<TSpec>> for RPCCodedResponse<TSpec> {
fn from(resp: Response<TSpec>) -> RPCCodedResponse<TSpec> {
impl<E: EthSpec> std::convert::From<Response<E>> for RPCCodedResponse<E> {
fn from(resp: Response<E>) -> RPCCodedResponse<E> {
match resp {
Response::BlocksByRoot(r) => match r {
Some(b) => RPCCodedResponse::Success(RPCResponse::BlocksByRoot(b)),

View File

@@ -16,19 +16,19 @@ pub type SubscriptionFilter =
pub type Gossipsub = gossipsub::Behaviour<SnappyTransform, SubscriptionFilter>;
#[derive(NetworkBehaviour)]
pub(crate) struct Behaviour<AppReqId, TSpec>
pub(crate) struct Behaviour<AppReqId, E>
where
AppReqId: ReqId,
TSpec: EthSpec,
E: EthSpec,
{
/// Keep track of active and pending connections to enforce hard limits.
pub connection_limits: libp2p::connection_limits::Behaviour,
/// The peer manager that keeps track of peer's reputation and status.
pub peer_manager: PeerManager<TSpec>,
pub peer_manager: PeerManager<E>,
/// The Eth2 RPC specified in the wire-0 protocol.
pub eth2_rpc: RPC<RequestId<AppReqId>, TSpec>,
pub eth2_rpc: RPC<RequestId<AppReqId>, E>,
/// Discv5 Discovery protocol.
pub discovery: Discovery<TSpec>,
pub discovery: Discovery<E>,
/// Keep regular connection to peers and disconnect if absent.
// NOTE: The id protocol is used for initial interop. This will be removed by mainnet.
/// Provides IP addresses and peer information.

View File

@@ -35,7 +35,7 @@ pub fn lighthouse_gossip_thresholds() -> PeerScoreThresholds {
}
}
pub struct PeerScoreSettings<TSpec: EthSpec> {
pub struct PeerScoreSettings<E: EthSpec> {
slot: Duration,
epoch: Duration,
@@ -50,11 +50,11 @@ pub struct PeerScoreSettings<TSpec: EthSpec> {
target_committee_size: usize,
target_aggregators_per_committee: usize,
attestation_subnet_count: u64,
phantom: PhantomData<TSpec>,
phantom: PhantomData<E>,
}
impl<TSpec: EthSpec> PeerScoreSettings<TSpec> {
pub fn new(chain_spec: &ChainSpec, gs_config: &GossipsubConfig) -> PeerScoreSettings<TSpec> {
impl<E: EthSpec> PeerScoreSettings<E> {
pub fn new(chain_spec: &ChainSpec, gs_config: &GossipsubConfig) -> PeerScoreSettings<E> {
let slot = Duration::from_secs(chain_spec.seconds_per_slot);
let beacon_attestation_subnet_weight = 1.0 / chain_spec.attestation_subnet_count as f64;
let max_positive_score = (MAX_IN_MESH_SCORE + MAX_FIRST_MESSAGE_DELIVERIES_SCORE)
@@ -67,7 +67,7 @@ impl<TSpec: EthSpec> PeerScoreSettings<TSpec> {
PeerScoreSettings {
slot,
epoch: slot * TSpec::slots_per_epoch() as u32,
epoch: slot * E::slots_per_epoch() as u32,
beacon_attestation_subnet_weight,
max_positive_score,
decay_interval: max(Duration::from_secs(1), slot),
@@ -104,7 +104,7 @@ impl<TSpec: EthSpec> PeerScoreSettings<TSpec> {
let target_value = Self::decay_convergence(
params.behaviour_penalty_decay,
10.0 / TSpec::slots_per_epoch() as f64,
10.0 / E::slots_per_epoch() as f64,
) - params.behaviour_penalty_threshold;
params.behaviour_penalty_weight = thresholds.gossip_threshold / target_value.powi(2);
@@ -125,7 +125,7 @@ impl<TSpec: EthSpec> PeerScoreSettings<TSpec> {
Self::get_topic_params(
self,
VOLUNTARY_EXIT_WEIGHT,
4.0 / TSpec::slots_per_epoch() as f64,
4.0 / E::slots_per_epoch() as f64,
self.epoch * 100,
None,
),
@@ -135,7 +135,7 @@ impl<TSpec: EthSpec> PeerScoreSettings<TSpec> {
Self::get_topic_params(
self,
ATTESTER_SLASHING_WEIGHT,
1.0 / 5.0 / TSpec::slots_per_epoch() as f64,
1.0 / 5.0 / E::slots_per_epoch() as f64,
self.epoch * 100,
None,
),
@@ -145,7 +145,7 @@ impl<TSpec: EthSpec> PeerScoreSettings<TSpec> {
Self::get_topic_params(
self,
PROPOSER_SLASHING_WEIGHT,
1.0 / 5.0 / TSpec::slots_per_epoch() as f64,
1.0 / 5.0 / E::slots_per_epoch() as f64,
self.epoch * 100,
None,
),
@@ -181,15 +181,15 @@ impl<TSpec: EthSpec> PeerScoreSettings<TSpec> {
) -> error::Result<(TopicScoreParams, TopicScoreParams, TopicScoreParams)> {
let (aggregators_per_slot, committees_per_slot) =
self.expected_aggregator_count_per_slot(active_validators)?;
let multiple_bursts_per_subnet_per_epoch = committees_per_slot as u64
>= 2 * self.attestation_subnet_count / TSpec::slots_per_epoch();
let multiple_bursts_per_subnet_per_epoch =
committees_per_slot as u64 >= 2 * self.attestation_subnet_count / E::slots_per_epoch();
let beacon_block_params = Self::get_topic_params(
self,
BEACON_BLOCK_WEIGHT,
1.0,
self.epoch * 20,
Some((TSpec::slots_per_epoch() * 5, 3.0, self.epoch, current_slot)),
Some((E::slots_per_epoch() * 5, 3.0, self.epoch, current_slot)),
);
let beacon_aggregate_proof_params = Self::get_topic_params(
@@ -197,14 +197,14 @@ impl<TSpec: EthSpec> PeerScoreSettings<TSpec> {
BEACON_AGGREGATE_PROOF_WEIGHT,
aggregators_per_slot,
self.epoch,
Some((TSpec::slots_per_epoch() * 2, 4.0, self.epoch, current_slot)),
Some((E::slots_per_epoch() * 2, 4.0, self.epoch, current_slot)),
);
let beacon_attestation_subnet_params = Self::get_topic_params(
self,
self.beacon_attestation_subnet_weight,
active_validators as f64
/ self.attestation_subnet_count as f64
/ TSpec::slots_per_epoch() as f64,
/ E::slots_per_epoch() as f64,
self.epoch
* (if multiple_bursts_per_subnet_per_epoch {
1
@@ -212,7 +212,7 @@ impl<TSpec: EthSpec> PeerScoreSettings<TSpec> {
4
}),
Some((
TSpec::slots_per_epoch()
E::slots_per_epoch()
* (if multiple_bursts_per_subnet_per_epoch {
4
} else {
@@ -220,7 +220,7 @@ impl<TSpec: EthSpec> PeerScoreSettings<TSpec> {
}),
16.0,
if multiple_bursts_per_subnet_per_epoch {
self.slot * (TSpec::slots_per_epoch() as u32 / 2 + 1)
self.slot * (E::slots_per_epoch() as u32 / 2 + 1)
} else {
self.epoch * 3
},
@@ -260,14 +260,14 @@ impl<TSpec: EthSpec> PeerScoreSettings<TSpec> {
&self,
active_validators: usize,
) -> error::Result<(f64, usize)> {
let committees_per_slot = TSpec::get_committee_count_per_slot_with(
let committees_per_slot = E::get_committee_count_per_slot_with(
active_validators,
self.max_committees_per_slot,
self.target_committee_size,
)
.map_err(|e| format!("Could not get committee count from spec: {:?}", e))?;
let committees = committees_per_slot * TSpec::slots_per_epoch() as usize;
let committees = committees_per_slot * E::slots_per_epoch() as usize;
let smaller_committee_size = active_validators / committees;
let num_larger_committees = active_validators - smaller_committee_size * committees;
@@ -286,7 +286,7 @@ impl<TSpec: EthSpec> PeerScoreSettings<TSpec> {
/ modulo_smaller as f64
+ (num_larger_committees * (smaller_committee_size + 1)) as f64
/ modulo_larger as f64)
/ TSpec::slots_per_epoch() as f64,
/ E::slots_per_epoch() as f64,
committees_per_slot,
))
}

View File

@@ -57,7 +57,7 @@ const MAX_IDENTIFY_ADDRESSES: usize = 10;
/// The types of events than can be obtained from polling the behaviour.
#[derive(Debug)]
pub enum NetworkEvent<AppReqId: ReqId, TSpec: EthSpec> {
pub enum NetworkEvent<AppReqId: ReqId, E: EthSpec> {
/// We have successfully dialed and connected to a peer.
PeerConnectedOutgoing(PeerId),
/// A peer has successfully dialed and connected to us.
@@ -87,7 +87,7 @@ pub enum NetworkEvent<AppReqId: ReqId, TSpec: EthSpec> {
/// Id of the request to which the peer is responding.
id: AppReqId,
/// Response the peer sent.
response: Response<TSpec>,
response: Response<E>,
},
PubsubMessage {
/// The gossipsub message id. Used when propagating blocks after validation.
@@ -97,7 +97,7 @@ pub enum NetworkEvent<AppReqId: ReqId, TSpec: EthSpec> {
/// The topic that this message was sent on.
topic: TopicHash,
/// The message itself.
message: PubsubMessage<TSpec>,
message: PubsubMessage<E>,
},
/// Inform the network to send a Status to this peer.
StatusPeer(PeerId),
@@ -108,11 +108,11 @@ pub enum NetworkEvent<AppReqId: ReqId, TSpec: EthSpec> {
/// Builds the network behaviour that manages the core protocols of eth2.
/// This core behaviour is managed by `Behaviour` which adds peer management to all core
/// behaviours.
pub struct Network<AppReqId: ReqId, TSpec: EthSpec> {
swarm: libp2p::swarm::Swarm<Behaviour<AppReqId, TSpec>>,
pub struct Network<AppReqId: ReqId, E: EthSpec> {
swarm: libp2p::swarm::Swarm<Behaviour<AppReqId, E>>,
/* Auxiliary Fields */
/// A collections of variables accessible outside the network service.
network_globals: Arc<NetworkGlobals<TSpec>>,
network_globals: Arc<NetworkGlobals<E>>,
/// Keeps track of the current EnrForkId for upgrading gossipsub topics.
// NOTE: This can be accessed via the network_globals ENR. However we keep it here for quick
// lookups for every gossipsub message send.
@@ -121,7 +121,7 @@ pub struct Network<AppReqId: ReqId, TSpec: EthSpec> {
network_dir: PathBuf,
fork_context: Arc<ForkContext>,
/// Gossipsub score parameters.
score_settings: PeerScoreSettings<TSpec>,
score_settings: PeerScoreSettings<E>,
/// The interval for updating gossipsub scores
update_gossipsub_scores: tokio::time::Interval,
gossip_cache: GossipCache,
@@ -132,12 +132,12 @@ pub struct Network<AppReqId: ReqId, TSpec: EthSpec> {
}
/// Implements the combined behaviour for the libp2p service.
impl<AppReqId: ReqId, TSpec: EthSpec> Network<AppReqId, TSpec> {
impl<AppReqId: ReqId, E: EthSpec> Network<AppReqId, E> {
pub async fn new(
executor: task_executor::TaskExecutor,
mut ctx: ServiceContext<'_>,
log: &slog::Logger,
) -> error::Result<(Self, Arc<NetworkGlobals<TSpec>>)> {
) -> error::Result<(Self, Arc<NetworkGlobals<E>>)> {
let log = log.new(o!("service"=> "libp2p"));
let mut config = ctx.config.clone();
@@ -156,7 +156,7 @@ impl<AppReqId: ReqId, TSpec: EthSpec> Network<AppReqId, TSpec> {
// set up a collection of variables accessible outside of the network crate
let network_globals = {
// Create an ENR or load from disk if appropriate
let enr = crate::discovery::enr::build_or_load_enr::<TSpec>(
let enr = crate::discovery::enr::build_or_load_enr::<E>(
local_keypair.clone(),
&config,
&ctx.enr_fork_id,
@@ -185,7 +185,7 @@ impl<AppReqId: ReqId, TSpec: EthSpec> Network<AppReqId, TSpec> {
let gossip_cache = {
let slot_duration = std::time::Duration::from_secs(ctx.chain_spec.seconds_per_slot);
let half_epoch = std::time::Duration::from_secs(
ctx.chain_spec.seconds_per_slot * TSpec::slots_per_epoch() / 2,
ctx.chain_spec.seconds_per_slot * E::slots_per_epoch() / 2,
);
GossipCache::builder()
@@ -210,7 +210,7 @@ impl<AppReqId: ReqId, TSpec: EthSpec> Network<AppReqId, TSpec> {
let params = {
// Construct a set of gossipsub peer scoring parameters
// We don't know the number of active validators and the current slot yet
let active_validators = TSpec::minimum_validator_count();
let active_validators = E::minimum_validator_count();
let current_slot = Slot::new(0);
score_settings.get_peer_score_params(
active_validators,
@@ -257,7 +257,7 @@ impl<AppReqId: ReqId, TSpec: EthSpec> Network<AppReqId, TSpec> {
ctx.fork_context.clone(),
gossipsub_config_params,
ctx.chain_spec.seconds_per_slot,
TSpec::slots_per_epoch(),
E::slots_per_epoch(),
);
// If metrics are enabled for libp2p build the configuration
@@ -290,7 +290,7 @@ impl<AppReqId: ReqId, TSpec: EthSpec> Network<AppReqId, TSpec> {
// If we are using metrics, then register which topics we want to make sure to keep
// track of
if ctx.libp2p_registry.is_some() {
let topics_to_keep_metrics_for = attestation_sync_committee_topics::<TSpec>()
let topics_to_keep_metrics_for = attestation_sync_committee_topics::<E>()
.map(|gossip_kind| {
Topic::from(GossipTopic::new(
gossip_kind,
@@ -592,11 +592,11 @@ impl<AppReqId: ReqId, TSpec: EthSpec> Network<AppReqId, TSpec> {
&mut self.swarm.behaviour_mut().gossipsub
}
/// The Eth2 RPC specified in the wire-0 protocol.
pub fn eth2_rpc_mut(&mut self) -> &mut RPC<RequestId<AppReqId>, TSpec> {
pub fn eth2_rpc_mut(&mut self) -> &mut RPC<RequestId<AppReqId>, E> {
&mut self.swarm.behaviour_mut().eth2_rpc
}
/// Discv5 Discovery protocol.
pub fn discovery_mut(&mut self) -> &mut Discovery<TSpec> {
pub fn discovery_mut(&mut self) -> &mut Discovery<E> {
&mut self.swarm.behaviour_mut().discovery
}
/// Provides IP addresses and peer information.
@@ -604,7 +604,7 @@ impl<AppReqId: ReqId, TSpec: EthSpec> Network<AppReqId, TSpec> {
&mut self.swarm.behaviour_mut().identify
}
/// The peer manager that keeps track of peer's reputation and status.
pub fn peer_manager_mut(&mut self) -> &mut PeerManager<TSpec> {
pub fn peer_manager_mut(&mut self) -> &mut PeerManager<E> {
&mut self.swarm.behaviour_mut().peer_manager
}
@@ -613,11 +613,11 @@ impl<AppReqId: ReqId, TSpec: EthSpec> Network<AppReqId, TSpec> {
&self.swarm.behaviour().gossipsub
}
/// The Eth2 RPC specified in the wire-0 protocol.
pub fn eth2_rpc(&self) -> &RPC<RequestId<AppReqId>, TSpec> {
pub fn eth2_rpc(&self) -> &RPC<RequestId<AppReqId>, E> {
&self.swarm.behaviour().eth2_rpc
}
/// Discv5 Discovery protocol.
pub fn discovery(&self) -> &Discovery<TSpec> {
pub fn discovery(&self) -> &Discovery<E> {
&self.swarm.behaviour().discovery
}
/// Provides IP addresses and peer information.
@@ -625,7 +625,7 @@ impl<AppReqId: ReqId, TSpec: EthSpec> Network<AppReqId, TSpec> {
&self.swarm.behaviour().identify
}
/// The peer manager that keeps track of peer's reputation and status.
pub fn peer_manager(&self) -> &PeerManager<TSpec> {
pub fn peer_manager(&self) -> &PeerManager<E> {
&self.swarm.behaviour().peer_manager
}
@@ -669,13 +669,13 @@ impl<AppReqId: ReqId, TSpec: EthSpec> Network<AppReqId, TSpec> {
}
// Subscribe to core topics for the new fork
for kind in fork_core_topics::<TSpec>(&new_fork, &self.fork_context.spec) {
for kind in fork_core_topics::<E>(&new_fork, &self.fork_context.spec) {
let topic = GossipTopic::new(kind, GossipEncoding::default(), new_fork_digest);
self.subscribe(topic);
}
// Register the new topics for metrics
let topics_to_keep_metrics_for = attestation_sync_committee_topics::<TSpec>()
let topics_to_keep_metrics_for = attestation_sync_committee_topics::<E>()
.map(|gossip_kind| {
Topic::from(GossipTopic::new(
gossip_kind,
@@ -782,7 +782,7 @@ impl<AppReqId: ReqId, TSpec: EthSpec> Network<AppReqId, TSpec> {
}
/// Publishes a list of messages on the pubsub (gossipsub) behaviour, choosing the encoding.
pub fn publish(&mut self, messages: Vec<PubsubMessage<TSpec>>) {
pub fn publish(&mut self, messages: Vec<PubsubMessage<E>>) {
for message in messages {
for topic in message.topics(GossipEncoding::default(), self.enr_fork_id.fork_digest) {
let message_data = message.encode(GossipEncoding::default());
@@ -926,7 +926,7 @@ impl<AppReqId: ReqId, TSpec: EthSpec> Network<AppReqId, TSpec> {
}
/// Send a successful response to a peer over RPC.
pub fn send_response(&mut self, peer_id: PeerId, id: PeerRequestId, response: Response<TSpec>) {
pub fn send_response(&mut self, peer_id: PeerId, id: PeerRequestId, response: Response<E>) {
self.eth2_rpc_mut()
.send_response(peer_id, id, response.into())
}
@@ -1063,13 +1063,13 @@ impl<AppReqId: ReqId, TSpec: EthSpec> Network<AppReqId, TSpec> {
let local_attnets = self
.discovery_mut()
.local_enr()
.attestation_bitfield::<TSpec>()
.attestation_bitfield::<E>()
.expect("Local discovery must have attestation bitfield");
let local_syncnets = self
.discovery_mut()
.local_enr()
.sync_committee_bitfield::<TSpec>()
.sync_committee_bitfield::<E>()
.expect("Local discovery must have sync committee bitfield");
{
@@ -1122,7 +1122,7 @@ impl<AppReqId: ReqId, TSpec: EthSpec> Network<AppReqId, TSpec> {
/// Sends a METADATA response to a peer.
fn send_meta_data_response(
&mut self,
req: MetadataRequest<TSpec>,
req: MetadataRequest<E>,
id: PeerRequestId,
peer_id: PeerId,
) {
@@ -1142,8 +1142,8 @@ impl<AppReqId: ReqId, TSpec: EthSpec> Network<AppReqId, TSpec> {
&mut self,
id: RequestId<AppReqId>,
peer_id: PeerId,
response: Response<TSpec>,
) -> Option<NetworkEvent<AppReqId, TSpec>> {
response: Response<E>,
) -> Option<NetworkEvent<AppReqId, E>> {
match id {
RequestId::Application(id) => Some(NetworkEvent::ResponseReceived {
peer_id,
@@ -1161,7 +1161,7 @@ impl<AppReqId: ReqId, TSpec: EthSpec> Network<AppReqId, TSpec> {
id: PeerRequestId,
peer_id: PeerId,
request: Request,
) -> NetworkEvent<AppReqId, TSpec> {
) -> NetworkEvent<AppReqId, E> {
// Increment metrics
match &request {
Request::Status(_) => {
@@ -1193,7 +1193,7 @@ impl<AppReqId: ReqId, TSpec: EthSpec> Network<AppReqId, TSpec> {
/// Dial cached Enrs in discovery service that are in the given `subnet_id` and aren't
/// in Connected, Dialing or Banned state.
fn dial_cached_enrs_in_subnet(&mut self, subnet: Subnet) {
let predicate = subnet_predicate::<TSpec>(vec![subnet], &self.log);
let predicate = subnet_predicate::<E>(vec![subnet], &self.log);
let peers_to_dial: Vec<Enr> = self
.discovery()
.cached_enrs()
@@ -1219,10 +1219,7 @@ impl<AppReqId: ReqId, TSpec: EthSpec> Network<AppReqId, TSpec> {
/* Sub-behaviour event handling functions */
/// Handle a gossipsub event.
fn inject_gs_event(
&mut self,
event: gossipsub::Event,
) -> Option<NetworkEvent<AppReqId, TSpec>> {
fn inject_gs_event(&mut self, event: gossipsub::Event) -> Option<NetworkEvent<AppReqId, E>> {
match event {
gossipsub::Event::Message {
propagation_source,
@@ -1363,8 +1360,8 @@ impl<AppReqId: ReqId, TSpec: EthSpec> Network<AppReqId, TSpec> {
/// Handle an RPC event.
fn inject_rpc_event(
&mut self,
event: RPCMessage<RequestId<AppReqId>, TSpec>,
) -> Option<NetworkEvent<AppReqId, TSpec>> {
event: RPCMessage<RequestId<AppReqId>, E>,
) -> Option<NetworkEvent<AppReqId, E>> {
let peer_id = event.peer_id;
if !self.peer_manager().is_connected(&peer_id) {
@@ -1570,7 +1567,7 @@ impl<AppReqId: ReqId, TSpec: EthSpec> Network<AppReqId, TSpec> {
fn inject_identify_event(
&mut self,
event: identify::Event,
) -> Option<NetworkEvent<AppReqId, TSpec>> {
) -> Option<NetworkEvent<AppReqId, E>> {
match event {
identify::Event::Received { peer_id, mut info } => {
if info.listen_addrs.len() > MAX_IDENTIFY_ADDRESSES {
@@ -1591,10 +1588,7 @@ impl<AppReqId: ReqId, TSpec: EthSpec> Network<AppReqId, TSpec> {
}
/// Handle a peer manager event.
fn inject_pm_event(
&mut self,
event: PeerManagerEvent,
) -> Option<NetworkEvent<AppReqId, TSpec>> {
fn inject_pm_event(&mut self, event: PeerManagerEvent) -> Option<NetworkEvent<AppReqId, E>> {
match event {
PeerManagerEvent::PeerConnectedIncoming(peer_id) => {
Some(NetworkEvent::PeerConnectedIncoming(peer_id))
@@ -1694,7 +1688,7 @@ impl<AppReqId: ReqId, TSpec: EthSpec> Network<AppReqId, TSpec> {
/// Poll the p2p networking stack.
///
/// This will poll the swarm and do maintenance routines.
pub fn poll_network(&mut self, cx: &mut Context) -> Poll<NetworkEvent<AppReqId, TSpec>> {
pub fn poll_network(&mut self, cx: &mut Context) -> Poll<NetworkEvent<AppReqId, E>> {
while let Poll::Ready(Some(swarm_event)) = self.swarm.poll_next_unpin(cx) {
let maybe_event = match swarm_event {
SwarmEvent::Behaviour(behaviour_event) => match behaviour_event {
@@ -1836,7 +1830,7 @@ impl<AppReqId: ReqId, TSpec: EthSpec> Network<AppReqId, TSpec> {
Poll::Pending
}
pub async fn next_event(&mut self) -> NetworkEvent<AppReqId, TSpec> {
pub async fn next_event(&mut self) -> NetworkEvent<AppReqId, E> {
futures::future::poll_fn(|cx| self.poll_network(cx)).await
}
}