mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-21 22:04:44 +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:
@@ -207,7 +207,7 @@ mod tests {
|
||||
use crate::rpc::rate_limiter::Quota;
|
||||
use crate::rpc::self_limiter::SelfRateLimiter;
|
||||
use crate::rpc::{Ping, Protocol, RequestType};
|
||||
use crate::service::api_types::{AppRequestId, RequestId, SingleLookupReqId, SyncRequestId};
|
||||
use crate::service::api_types::{AppRequestId, SingleLookupReqId, SyncRequestId};
|
||||
use libp2p::PeerId;
|
||||
use logging::create_test_tracing_subscriber;
|
||||
use std::time::Duration;
|
||||
@@ -226,7 +226,7 @@ mod tests {
|
||||
Hash256::ZERO,
|
||||
&MainnetEthSpec::default_spec(),
|
||||
));
|
||||
let mut limiter: SelfRateLimiter<RequestId, MainnetEthSpec> =
|
||||
let mut limiter: SelfRateLimiter<AppRequestId, MainnetEthSpec> =
|
||||
SelfRateLimiter::new(config, fork_context).unwrap();
|
||||
let peer_id = PeerId::random();
|
||||
let lookup_id = 0;
|
||||
@@ -234,12 +234,12 @@ mod tests {
|
||||
for i in 1..=5u32 {
|
||||
let _ = limiter.allows(
|
||||
peer_id,
|
||||
RequestId::Application(AppRequestId::Sync(SyncRequestId::SingleBlock {
|
||||
AppRequestId::Sync(SyncRequestId::SingleBlock {
|
||||
id: SingleLookupReqId {
|
||||
lookup_id,
|
||||
req_id: i,
|
||||
},
|
||||
})),
|
||||
}),
|
||||
RequestType::Ping(Ping { data: i as u64 }),
|
||||
);
|
||||
}
|
||||
@@ -256,9 +256,9 @@ mod tests {
|
||||
for i in 2..=5u32 {
|
||||
assert!(matches!(
|
||||
iter.next().unwrap().request_id,
|
||||
RequestId::Application(AppRequestId::Sync(SyncRequestId::SingleBlock {
|
||||
AppRequestId::Sync(SyncRequestId::SingleBlock {
|
||||
id: SingleLookupReqId { req_id, .. },
|
||||
})) if req_id == i,
|
||||
}) if req_id == i,
|
||||
));
|
||||
}
|
||||
|
||||
@@ -281,9 +281,9 @@ mod tests {
|
||||
for i in 3..=5 {
|
||||
assert!(matches!(
|
||||
iter.next().unwrap().request_id,
|
||||
RequestId::Application(AppRequestId::Sync(SyncRequestId::SingleBlock {
|
||||
AppRequestId::Sync(SyncRequestId::SingleBlock {
|
||||
id: SingleLookupReqId { req_id, .. },
|
||||
})) if req_id == i,
|
||||
}) if req_id == i,
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user