mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-11 18:04:18 +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:
@@ -372,11 +372,11 @@ impl<T: BeaconChainTypes> SyncNetworkContext<T> {
|
||||
);
|
||||
|
||||
let request = RequestType::Status(status_message.clone());
|
||||
let request_id = AppRequestId::Router;
|
||||
let app_request_id = AppRequestId::Router;
|
||||
let _ = self.send_network_msg(NetworkMessage::SendRequest {
|
||||
peer_id,
|
||||
request,
|
||||
request_id,
|
||||
app_request_id,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -595,7 +595,7 @@ impl<T: BeaconChainTypes> SyncNetworkContext<T> {
|
||||
.send(NetworkMessage::SendRequest {
|
||||
peer_id,
|
||||
request: RequestType::BlocksByRoot(request.into_request(&self.fork_context)),
|
||||
request_id: AppRequestId::Sync(SyncRequestId::SingleBlock { id }),
|
||||
app_request_id: AppRequestId::Sync(SyncRequestId::SingleBlock { id }),
|
||||
})
|
||||
.map_err(|_| RpcRequestSendError::NetworkSendError)?;
|
||||
|
||||
@@ -684,7 +684,7 @@ impl<T: BeaconChainTypes> SyncNetworkContext<T> {
|
||||
.send(NetworkMessage::SendRequest {
|
||||
peer_id,
|
||||
request: RequestType::BlobsByRoot(request.clone().into_request(&self.fork_context)),
|
||||
request_id: AppRequestId::Sync(SyncRequestId::SingleBlob { id }),
|
||||
app_request_id: AppRequestId::Sync(SyncRequestId::SingleBlob { id }),
|
||||
})
|
||||
.map_err(|_| RpcRequestSendError::NetworkSendError)?;
|
||||
|
||||
@@ -733,7 +733,7 @@ impl<T: BeaconChainTypes> SyncNetworkContext<T> {
|
||||
self.send_network_msg(NetworkMessage::SendRequest {
|
||||
peer_id,
|
||||
request: RequestType::DataColumnsByRoot(request.clone().into_request(&self.chain.spec)),
|
||||
request_id: AppRequestId::Sync(SyncRequestId::DataColumnsByRoot(id)),
|
||||
app_request_id: AppRequestId::Sync(SyncRequestId::DataColumnsByRoot(id)),
|
||||
})?;
|
||||
|
||||
debug!(
|
||||
@@ -839,7 +839,7 @@ impl<T: BeaconChainTypes> SyncNetworkContext<T> {
|
||||
.send(NetworkMessage::SendRequest {
|
||||
peer_id,
|
||||
request: RequestType::BlocksByRange(request.clone().into()),
|
||||
request_id: AppRequestId::Sync(SyncRequestId::BlocksByRange(id)),
|
||||
app_request_id: AppRequestId::Sync(SyncRequestId::BlocksByRange(id)),
|
||||
})
|
||||
.map_err(|_| RpcRequestSendError::NetworkSendError)?;
|
||||
|
||||
@@ -880,7 +880,7 @@ impl<T: BeaconChainTypes> SyncNetworkContext<T> {
|
||||
.send(NetworkMessage::SendRequest {
|
||||
peer_id,
|
||||
request: RequestType::BlobsByRange(request.clone()),
|
||||
request_id: AppRequestId::Sync(SyncRequestId::BlobsByRange(id)),
|
||||
app_request_id: AppRequestId::Sync(SyncRequestId::BlobsByRange(id)),
|
||||
})
|
||||
.map_err(|_| RpcRequestSendError::NetworkSendError)?;
|
||||
|
||||
@@ -919,7 +919,7 @@ impl<T: BeaconChainTypes> SyncNetworkContext<T> {
|
||||
self.send_network_msg(NetworkMessage::SendRequest {
|
||||
peer_id,
|
||||
request: RequestType::DataColumnsByRange(request.clone()),
|
||||
request_id: AppRequestId::Sync(SyncRequestId::DataColumnsByRange(id)),
|
||||
app_request_id: AppRequestId::Sync(SyncRequestId::DataColumnsByRange(id)),
|
||||
})
|
||||
.map_err(|_| RpcRequestSendError::NetworkSendError)?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user