mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-18 13:28:33 +00:00
RPC RequestId Cleanup (#7238)
I've been working at updating another library to latest Lighthouse and got very confused with RPC request Ids. There were types that had fields called `request_id` and `id`. And interchangeably could have types `PeerRequestId`, `rpc::RequestId`, `AppRequestId`, `api_types::RequestId` or even `Request.id`. I couldn't keep track of which Id was linked to what and what each type meant. So this PR mainly does a few things: - Changes the field naming to match the actual type. So any field that has an `AppRequestId` will be named `app_request_id` rather than `id` or `request_id` for example. - I simplified the types. I removed the two different `RequestId` types (one in Lighthouse_network the other in the rpc) and grouped them into one. It has one downside tho. I had to add a few unreachable lines of code in the beacon processor, which the extra type would prevent, but I feel like it might be worth it. Happy to add an extra type to avoid those few lines. - I also removed the concept of `PeerRequestId` which sometimes went alongside a `request_id`. There were times were had a `PeerRequest` and a `Request` being returned, both of which contain a `RequestId` so we had redundant information. I've simplified the logic by removing `PeerRequestId` and made a `ResponseId`. I think if you look at the code changes, it simplifies things a bit and removes the redundant extra info. I think with this PR things are a little bit easier to reasonable about what is going on with all these RPC Ids. NOTE: I did this with the help of AI, so probably should be checked
This commit is contained in:
@@ -10,14 +10,15 @@ use beacon_processor::{work_reprocessing_queue::ReprocessQueueMessage, BeaconPro
|
||||
use futures::channel::mpsc::Sender;
|
||||
use futures::future::OptionFuture;
|
||||
use futures::prelude::*;
|
||||
use lighthouse_network::rpc::{RequestId, RequestType};
|
||||
use lighthouse_network::rpc::InboundRequestId;
|
||||
use lighthouse_network::rpc::RequestType;
|
||||
use lighthouse_network::service::Network;
|
||||
use lighthouse_network::types::GossipKind;
|
||||
use lighthouse_network::Enr;
|
||||
use lighthouse_network::{prometheus_client::registry::Registry, MessageAcceptance};
|
||||
use lighthouse_network::{
|
||||
rpc::{GoodbyeReason, RpcErrorResponse},
|
||||
Context, PeerAction, PeerRequestId, PubsubMessage, ReportSource, Response, Subnet,
|
||||
Context, PeerAction, PubsubMessage, ReportSource, Response, Subnet,
|
||||
};
|
||||
use lighthouse_network::{
|
||||
service::api_types::AppRequestId,
|
||||
@@ -61,22 +62,20 @@ pub enum NetworkMessage<E: EthSpec> {
|
||||
SendRequest {
|
||||
peer_id: PeerId,
|
||||
request: RequestType<E>,
|
||||
request_id: AppRequestId,
|
||||
app_request_id: AppRequestId,
|
||||
},
|
||||
/// Send a successful Response to the libp2p service.
|
||||
SendResponse {
|
||||
peer_id: PeerId,
|
||||
request_id: RequestId,
|
||||
inbound_request_id: InboundRequestId,
|
||||
response: Response<E>,
|
||||
id: PeerRequestId,
|
||||
},
|
||||
/// Sends an error response to an RPC request.
|
||||
SendErrorResponse {
|
||||
peer_id: PeerId,
|
||||
request_id: RequestId,
|
||||
inbound_request_id: InboundRequestId,
|
||||
error: RpcErrorResponse,
|
||||
reason: String,
|
||||
id: PeerRequestId,
|
||||
},
|
||||
/// Publish a list of messages to the gossipsub protocol.
|
||||
Publish { messages: Vec<PubsubMessage<E>> },
|
||||
@@ -488,30 +487,34 @@ impl<T: BeaconChainTypes> NetworkService<T> {
|
||||
}
|
||||
NetworkEvent::RequestReceived {
|
||||
peer_id,
|
||||
id,
|
||||
request,
|
||||
inbound_request_id,
|
||||
request_type,
|
||||
} => {
|
||||
self.send_to_router(RouterMessage::RPCRequestReceived {
|
||||
peer_id,
|
||||
id,
|
||||
request,
|
||||
inbound_request_id,
|
||||
request_type,
|
||||
});
|
||||
}
|
||||
NetworkEvent::ResponseReceived {
|
||||
peer_id,
|
||||
id,
|
||||
app_request_id,
|
||||
response,
|
||||
} => {
|
||||
self.send_to_router(RouterMessage::RPCResponseReceived {
|
||||
peer_id,
|
||||
request_id: id,
|
||||
app_request_id,
|
||||
response,
|
||||
});
|
||||
}
|
||||
NetworkEvent::RPCFailed { id, peer_id, error } => {
|
||||
NetworkEvent::RPCFailed {
|
||||
app_request_id,
|
||||
peer_id,
|
||||
error,
|
||||
} => {
|
||||
self.send_to_router(RouterMessage::RPCFailed {
|
||||
peer_id,
|
||||
request_id: id,
|
||||
app_request_id,
|
||||
error,
|
||||
});
|
||||
}
|
||||
@@ -601,35 +604,34 @@ impl<T: BeaconChainTypes> NetworkService<T> {
|
||||
NetworkMessage::SendRequest {
|
||||
peer_id,
|
||||
request,
|
||||
request_id,
|
||||
app_request_id,
|
||||
} => {
|
||||
if let Err((request_id, error)) =
|
||||
self.libp2p.send_request(peer_id, request_id, request)
|
||||
if let Err((app_request_id, error)) =
|
||||
self.libp2p.send_request(peer_id, app_request_id, request)
|
||||
{
|
||||
self.send_to_router(RouterMessage::RPCFailed {
|
||||
peer_id,
|
||||
request_id,
|
||||
app_request_id,
|
||||
error,
|
||||
});
|
||||
}
|
||||
}
|
||||
NetworkMessage::SendResponse {
|
||||
peer_id,
|
||||
inbound_request_id,
|
||||
response,
|
||||
id,
|
||||
request_id,
|
||||
} => {
|
||||
self.libp2p.send_response(peer_id, id, request_id, response);
|
||||
self.libp2p
|
||||
.send_response(peer_id, inbound_request_id, response);
|
||||
}
|
||||
NetworkMessage::SendErrorResponse {
|
||||
peer_id,
|
||||
error,
|
||||
id,
|
||||
request_id,
|
||||
inbound_request_id,
|
||||
reason,
|
||||
} => {
|
||||
self.libp2p
|
||||
.send_error_response(peer_id, id, request_id, error, reason);
|
||||
.send_error_response(peer_id, inbound_request_id, error, reason);
|
||||
}
|
||||
NetworkMessage::ValidationResult {
|
||||
propagation_source,
|
||||
|
||||
Reference in New Issue
Block a user