mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-14 18:32:42 +00:00
Remove generic Id param from RequestId (#6032)
* rename RequestId's for better context, and move them to lighthouse_network crate. * remove unrequired generic AppReqId from RequestID
This commit is contained in:
@@ -21,7 +21,7 @@ use crate::types::{
|
||||
use crate::EnrExt;
|
||||
use crate::Eth2Enr;
|
||||
use crate::{error, metrics, Enr, NetworkGlobals, PubsubMessage, TopicHash};
|
||||
use api_types::{PeerRequestId, Request, RequestId, Response};
|
||||
use api_types::{AppRequestId, PeerRequestId, Request, RequestId, Response};
|
||||
use futures::stream::StreamExt;
|
||||
use gossipsub::{
|
||||
IdentTopic as Topic, MessageAcceptance, MessageAuthenticity, MessageId, PublishError,
|
||||
@@ -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, E: EthSpec> {
|
||||
pub enum NetworkEvent<E: EthSpec> {
|
||||
/// We have successfully dialed and connected to a peer.
|
||||
PeerConnectedOutgoing(PeerId),
|
||||
/// A peer has successfully dialed and connected to us.
|
||||
@@ -67,7 +67,7 @@ pub enum NetworkEvent<AppReqId: ReqId, E: EthSpec> {
|
||||
/// An RPC Request that was sent failed.
|
||||
RPCFailed {
|
||||
/// The id of the failed request.
|
||||
id: AppReqId,
|
||||
id: AppRequestId,
|
||||
/// The peer to which this request was sent.
|
||||
peer_id: PeerId,
|
||||
/// The error of the failed request.
|
||||
@@ -85,7 +85,7 @@ pub enum NetworkEvent<AppReqId: ReqId, E: EthSpec> {
|
||||
/// Peer that sent the response.
|
||||
peer_id: PeerId,
|
||||
/// Id of the request to which the peer is responding.
|
||||
id: AppReqId,
|
||||
id: AppRequestId,
|
||||
/// Response the peer sent.
|
||||
response: Response<E>,
|
||||
},
|
||||
@@ -108,8 +108,8 @@ pub enum NetworkEvent<AppReqId: ReqId, E: 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, E: EthSpec> {
|
||||
swarm: libp2p::swarm::Swarm<Behaviour<AppReqId, E>>,
|
||||
pub struct Network<E: EthSpec> {
|
||||
swarm: libp2p::swarm::Swarm<Behaviour<E>>,
|
||||
/* Auxiliary Fields */
|
||||
/// A collections of variables accessible outside the network service.
|
||||
network_globals: Arc<NetworkGlobals<E>>,
|
||||
@@ -132,7 +132,7 @@ pub struct Network<AppReqId: ReqId, E: EthSpec> {
|
||||
}
|
||||
|
||||
/// Implements the combined behaviour for the libp2p service.
|
||||
impl<AppReqId: ReqId, E: EthSpec> Network<AppReqId, E> {
|
||||
impl<E: EthSpec> Network<E> {
|
||||
pub async fn new(
|
||||
executor: task_executor::TaskExecutor,
|
||||
mut ctx: ServiceContext<'_>,
|
||||
@@ -592,7 +592,7 @@ impl<AppReqId: ReqId, E: EthSpec> Network<AppReqId, E> {
|
||||
&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>, E> {
|
||||
pub fn eth2_rpc_mut(&mut self) -> &mut RPC<RequestId, E> {
|
||||
&mut self.swarm.behaviour_mut().eth2_rpc
|
||||
}
|
||||
/// Discv5 Discovery protocol.
|
||||
@@ -613,7 +613,7 @@ impl<AppReqId: ReqId, E: EthSpec> Network<AppReqId, E> {
|
||||
&self.swarm.behaviour().gossipsub
|
||||
}
|
||||
/// The Eth2 RPC specified in the wire-0 protocol.
|
||||
pub fn eth2_rpc(&self) -> &RPC<RequestId<AppReqId>, E> {
|
||||
pub fn eth2_rpc(&self) -> &RPC<RequestId, E> {
|
||||
&self.swarm.behaviour().eth2_rpc
|
||||
}
|
||||
/// Discv5 Discovery protocol.
|
||||
@@ -920,9 +920,9 @@ impl<AppReqId: ReqId, E: EthSpec> Network<AppReqId, E> {
|
||||
pub fn send_request(
|
||||
&mut self,
|
||||
peer_id: PeerId,
|
||||
request_id: AppReqId,
|
||||
request_id: AppRequestId,
|
||||
request: Request,
|
||||
) -> Result<(), (AppReqId, RPCError)> {
|
||||
) -> Result<(), (AppRequestId, RPCError)> {
|
||||
// Check if the peer is connected before sending an RPC request
|
||||
if !self.swarm.is_connected(&peer_id) {
|
||||
return Err((request_id, RPCError::Disconnected));
|
||||
@@ -1157,10 +1157,10 @@ impl<AppReqId: ReqId, E: EthSpec> Network<AppReqId, E> {
|
||||
#[must_use = "return the response"]
|
||||
fn build_response(
|
||||
&mut self,
|
||||
id: RequestId<AppReqId>,
|
||||
id: RequestId,
|
||||
peer_id: PeerId,
|
||||
response: Response<E>,
|
||||
) -> Option<NetworkEvent<AppReqId, E>> {
|
||||
) -> Option<NetworkEvent<E>> {
|
||||
match id {
|
||||
RequestId::Application(id) => Some(NetworkEvent::ResponseReceived {
|
||||
peer_id,
|
||||
@@ -1178,7 +1178,7 @@ impl<AppReqId: ReqId, E: EthSpec> Network<AppReqId, E> {
|
||||
id: PeerRequestId,
|
||||
peer_id: PeerId,
|
||||
request: Request,
|
||||
) -> NetworkEvent<AppReqId, E> {
|
||||
) -> NetworkEvent<E> {
|
||||
// Increment metrics
|
||||
match &request {
|
||||
Request::Status(_) => {
|
||||
@@ -1244,7 +1244,7 @@ impl<AppReqId: ReqId, E: EthSpec> Network<AppReqId, E> {
|
||||
/* Sub-behaviour event handling functions */
|
||||
|
||||
/// Handle a gossipsub event.
|
||||
fn inject_gs_event(&mut self, event: gossipsub::Event) -> Option<NetworkEvent<AppReqId, E>> {
|
||||
fn inject_gs_event(&mut self, event: gossipsub::Event) -> Option<NetworkEvent<E>> {
|
||||
match event {
|
||||
gossipsub::Event::Message {
|
||||
propagation_source,
|
||||
@@ -1383,10 +1383,7 @@ impl<AppReqId: ReqId, E: EthSpec> Network<AppReqId, E> {
|
||||
}
|
||||
|
||||
/// Handle an RPC event.
|
||||
fn inject_rpc_event(
|
||||
&mut self,
|
||||
event: RPCMessage<RequestId<AppReqId>, E>,
|
||||
) -> Option<NetworkEvent<AppReqId, E>> {
|
||||
fn inject_rpc_event(&mut self, event: RPCMessage<RequestId, E>) -> Option<NetworkEvent<E>> {
|
||||
let peer_id = event.peer_id;
|
||||
|
||||
// Do not permit Inbound events from peers that are being disconnected, or RPC requests.
|
||||
@@ -1619,10 +1616,7 @@ impl<AppReqId: ReqId, E: EthSpec> Network<AppReqId, E> {
|
||||
}
|
||||
|
||||
/// Handle an identify event.
|
||||
fn inject_identify_event(
|
||||
&mut self,
|
||||
event: identify::Event,
|
||||
) -> Option<NetworkEvent<AppReqId, E>> {
|
||||
fn inject_identify_event(&mut self, event: identify::Event) -> Option<NetworkEvent<E>> {
|
||||
match event {
|
||||
identify::Event::Received { peer_id, mut info } => {
|
||||
if info.listen_addrs.len() > MAX_IDENTIFY_ADDRESSES {
|
||||
@@ -1643,7 +1637,7 @@ impl<AppReqId: ReqId, E: EthSpec> Network<AppReqId, E> {
|
||||
}
|
||||
|
||||
/// Handle a peer manager event.
|
||||
fn inject_pm_event(&mut self, event: PeerManagerEvent) -> Option<NetworkEvent<AppReqId, E>> {
|
||||
fn inject_pm_event(&mut self, event: PeerManagerEvent) -> Option<NetworkEvent<E>> {
|
||||
match event {
|
||||
PeerManagerEvent::PeerConnectedIncoming(peer_id) => {
|
||||
Some(NetworkEvent::PeerConnectedIncoming(peer_id))
|
||||
@@ -1747,7 +1741,7 @@ impl<AppReqId: ReqId, E: EthSpec> Network<AppReqId, E> {
|
||||
/// 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, E>> {
|
||||
pub fn poll_network(&mut self, cx: &mut Context) -> Poll<NetworkEvent<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 {
|
||||
@@ -1889,7 +1883,7 @@ impl<AppReqId: ReqId, E: EthSpec> Network<AppReqId, E> {
|
||||
Poll::Pending
|
||||
}
|
||||
|
||||
pub async fn next_event(&mut self) -> NetworkEvent<AppReqId, E> {
|
||||
pub async fn next_event(&mut self) -> NetworkEvent<E> {
|
||||
futures::future::poll_fn(|cx| self.poll_network(cx)).await
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user