Skip to content

Commit 96ef419

Browse files
committed
remove generic E from RequestType
1 parent d0dbeea commit 96ef419

File tree

14 files changed

+60
-60
lines changed

14 files changed

+60
-60
lines changed

beacon_node/lighthouse_network/src/rpc/codec.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ impl<E: EthSpec> Encoder<RpcResponse<E>> for SSZSnappyInboundCodec<E> {
142142

143143
// Decoder for inbound streams: Decodes RPC requests from peers
144144
impl<E: EthSpec> Decoder for SSZSnappyInboundCodec<E> {
145-
type Item = RequestType<E>;
145+
type Item = RequestType;
146146
type Error = RPCError;
147147

148148
fn decode(&mut self, src: &mut BytesMut) -> Result<Option<Self::Item>, Self::Error> {
@@ -321,10 +321,10 @@ impl<E: EthSpec> SSZSnappyOutboundCodec<E> {
321321
}
322322

323323
// Encoder for outbound streams: Encodes RPC Requests to peers
324-
impl<E: EthSpec> Encoder<RequestType<E>> for SSZSnappyOutboundCodec<E> {
324+
impl<E: EthSpec> Encoder<RequestType> for SSZSnappyOutboundCodec<E> {
325325
type Error = RPCError;
326326

327-
fn encode(&mut self, item: RequestType<E>, dst: &mut BytesMut) -> Result<(), Self::Error> {
327+
fn encode(&mut self, item: RequestType, dst: &mut BytesMut) -> Result<(), Self::Error> {
328328
let bytes = match item {
329329
RequestType::Status(req) => req.as_ssz_bytes(),
330330
RequestType::Goodbye(req) => req.as_ssz_bytes(),
@@ -543,11 +543,11 @@ fn handle_length(
543543
/// Decodes an `InboundRequest` from the byte stream.
544544
/// `decoded_buffer` should be an ssz-encoded bytestream with
545545
// length = length-prefix received in the beginning of the stream.
546-
fn handle_rpc_request<E: EthSpec>(
546+
fn handle_rpc_request(
547547
versioned_protocol: SupportedProtocol,
548548
decoded_buffer: &[u8],
549549
spec: &ChainSpec,
550-
) -> Result<Option<RequestType<E>>, RPCError> {
550+
) -> Result<Option<RequestType>, RPCError> {
551551
match versioned_protocol {
552552
SupportedProtocol::StatusV1 => Ok(Some(RequestType::Status(
553553
StatusMessage::from_ssz_bytes(decoded_buffer)?,
@@ -1009,6 +1009,7 @@ mod tests {
10091009
BlobsByRangeRequest {
10101010
start_slot: 0,
10111011
count: 10,
1012+
max_blobs_per_block: Spec::max_blobs_per_block(),
10121013
}
10131014
}
10141015

@@ -1154,7 +1155,7 @@ mod tests {
11541155
}
11551156

11561157
/// Verifies that requests we send are encoded in a way that we would correctly decode too.
1157-
fn encode_then_decode_request(req: RequestType<Spec>, fork_name: ForkName, spec: &ChainSpec) {
1158+
fn encode_then_decode_request(req: RequestType, fork_name: ForkName, spec: &ChainSpec) {
11581159
let fork_context = Arc::new(fork_context(fork_name));
11591160
let max_packet_size = max_rpc_size(&fork_context, spec.max_chunk_size as usize);
11601161
let protocol = ProtocolId::new(req.versioned_protocol(), Encoding::SSZSnappy);
@@ -1745,7 +1746,7 @@ mod tests {
17451746
fn test_encode_then_decode_request() {
17461747
let chain_spec = Spec::default_spec();
17471748

1748-
let requests: &[RequestType<Spec>] = &[
1749+
let requests: &[RequestType] = &[
17491750
RequestType::Ping(ping_message()),
17501751
RequestType::Status(status_message()),
17511752
RequestType::Goodbye(GoodbyeReason::Fault),

beacon_node/lighthouse_network/src/rpc/handler.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use slog::{crit, debug, trace};
2020
use smallvec::SmallVec;
2121
use std::{
2222
collections::{hash_map::Entry, VecDeque},
23+
marker::PhantomData,
2324
pin::Pin,
2425
sync::Arc,
2526
task::{Context, Poll},
@@ -96,7 +97,7 @@ where
9697
events_out: SmallVec<[HandlerEvent<Id, E>; 4]>,
9798

9899
/// Queue of outbound substreams to open.
99-
dial_queue: SmallVec<[(Id, RequestType<E>); 4]>,
100+
dial_queue: SmallVec<[(Id, RequestType); 4]>,
100101

101102
/// Current number of concurrent outbound substreams being opened.
102103
dial_negotiated: u32,
@@ -206,7 +207,7 @@ pub enum OutboundSubstreamState<E: EthSpec> {
206207
/// The framed negotiated substream.
207208
substream: Box<OutboundFramed<Stream, E>>,
208209
/// Keeps track of the actual request sent.
209-
request: RequestType<E>,
210+
request: RequestType,
210211
},
211212
/// Closing an outbound substream>
212213
Closing(Box<OutboundFramed<Stream, E>>),
@@ -274,7 +275,7 @@ where
274275
}
275276

276277
/// Opens an outbound substream with a request.
277-
fn send_request(&mut self, id: Id, req: RequestType<E>) {
278+
fn send_request(&mut self, id: Id, req: RequestType) {
278279
match self.state {
279280
HandlerState::Active => {
280281
self.dial_queue.push((id, req));
@@ -330,7 +331,7 @@ where
330331
type ToBehaviour = HandlerEvent<Id, E>;
331332
type InboundProtocol = RPCProtocol<E>;
332333
type OutboundProtocol = OutboundRequestContainer<E>;
333-
type OutboundOpenInfo = (Id, RequestType<E>); // Keep track of the id and the request
334+
type OutboundOpenInfo = (Id, RequestType); // Keep track of the id and the request
334335
type InboundOpenInfo = ();
335336

336337
fn listen_protocol(&self) -> SubstreamProtocol<Self::InboundProtocol, ()> {
@@ -788,6 +789,7 @@ where
788789
req: req.clone(),
789790
fork_context: self.fork_context.clone(),
790791
max_rpc_size: self.listen_protocol().upgrade().max_rpc_size,
792+
phantom: PhantomData,
791793
},
792794
(),
793795
)
@@ -905,7 +907,7 @@ where
905907
fn on_fully_negotiated_outbound(
906908
&mut self,
907909
substream: OutboundFramed<Stream, E>,
908-
(id, request): (Id, RequestType<E>),
910+
(id, request): (Id, RequestType),
909911
) {
910912
self.dial_negotiated -= 1;
911913
// Reset any io-retries counter.
@@ -961,7 +963,7 @@ where
961963
}
962964
fn on_dial_upgrade_error(
963965
&mut self,
964-
request_info: (Id, RequestType<E>),
966+
request_info: (Id, RequestType),
965967
error: StreamUpgradeError<RPCError>,
966968
) {
967969
let (id, req) = request_info;

beacon_node/lighthouse_network/src/rpc/methods.rs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use ssz_derive::{Decode, Encode};
88
use ssz_types::{typenum::U256, VariableList};
99
use std::collections::BTreeMap;
1010
use std::fmt::Display;
11-
use std::marker::PhantomData;
1211
use std::ops::Deref;
1312
use std::sync::Arc;
1413
use strum::IntoStaticStr;
@@ -93,27 +92,19 @@ pub struct Ping {
9392
variant_attributes(derive(Clone, Debug, PartialEq, Serialize),)
9493
)]
9594
#[derive(Clone, Debug, PartialEq)]
96-
pub struct MetadataRequest<E> {
97-
_phantom_data: PhantomData<E>,
98-
}
95+
pub struct MetadataRequest;
9996

100-
impl<E: EthSpec> MetadataRequest<E> {
97+
impl MetadataRequest {
10198
pub fn new_v1() -> Self {
102-
Self::V1(MetadataRequestV1 {
103-
_phantom_data: PhantomData,
104-
})
99+
Self::V1(MetadataRequestV1 {})
105100
}
106101

107102
pub fn new_v2() -> Self {
108-
Self::V2(MetadataRequestV2 {
109-
_phantom_data: PhantomData,
110-
})
103+
Self::V2(MetadataRequestV2 {})
111104
}
112105

113106
pub fn new_v3() -> Self {
114-
Self::V3(MetadataRequestV3 {
115-
_phantom_data: PhantomData,
116-
})
107+
Self::V3(MetadataRequestV3 {})
117108
}
118109
}
119110

@@ -323,11 +314,14 @@ pub struct BlobsByRangeRequest {
323314

324315
/// The number of slots from the start slot.
325316
pub count: u64,
317+
318+
/// maximum number of blobs in a single block.
319+
pub max_blobs_per_block: usize,
326320
}
327321

328322
impl BlobsByRangeRequest {
329-
pub fn max_blobs_requested<E: EthSpec>(&self) -> u64 {
330-
self.count.saturating_mul(E::max_blobs_per_block() as u64)
323+
pub fn max_blobs_requested(&self) -> u64 {
324+
self.count.saturating_mul(self.max_blobs_per_block as u64)
331325
}
332326
}
333327

beacon_node/lighthouse_network/src/rpc/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub enum RPCSend<Id, E: EthSpec> {
6161
///
6262
/// The `Id` is given by the application making the request. These
6363
/// go over *outbound* connections.
64-
Request(Id, RequestType<E>),
64+
Request(Id, RequestType),
6565
/// A response sent from Lighthouse.
6666
///
6767
/// The `SubstreamId` must correspond to the RPC-given ID of the original request received from the
@@ -79,7 +79,7 @@ pub enum RPCReceived<Id, E: EthSpec> {
7979
///
8080
/// The `SubstreamId` is given by the `RPCHandler` as it identifies this request with the
8181
/// *inbound* substream over which it is managed.
82-
Request(Request<E>),
82+
Request(Request),
8383
/// A response received from the outside.
8484
///
8585
/// The `Id` corresponds to the application given ID of the original request sent to the
@@ -113,10 +113,10 @@ impl RequestId {
113113

114114
/// An Rpc Request.
115115
#[derive(Debug, Clone)]
116-
pub struct Request<E> {
116+
pub struct Request {
117117
pub id: RequestId,
118118
pub substream_id: SubstreamId,
119-
pub r#type: RequestType<E>,
119+
pub r#type: RequestType,
120120
}
121121

122122
impl<E: EthSpec, Id: std::fmt::Debug> std::fmt::Display for RPCSend<Id, E> {
@@ -221,7 +221,7 @@ impl<Id: ReqId, E: EthSpec> RPC<Id, E> {
221221
/// Submits an RPC request.
222222
///
223223
/// The peer must be connected for this to succeed.
224-
pub fn send_request(&mut self, peer_id: PeerId, request_id: Id, req: RequestType<E>) {
224+
pub fn send_request(&mut self, peer_id: PeerId, request_id: Id, req: RequestType) {
225225
let event = if let Some(self_limiter) = self.self_limiter.as_mut() {
226226
match self_limiter.allows(peer_id, request_id, req) {
227227
Ok(event) => event,

beacon_node/lighthouse_network/src/rpc/outbound.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use futures::future::BoxFuture;
77
use futures::prelude::{AsyncRead, AsyncWrite};
88
use futures::{FutureExt, SinkExt};
99
use libp2p::core::{OutboundUpgrade, UpgradeInfo};
10+
use std::marker::PhantomData;
1011
use std::sync::Arc;
1112
use tokio_util::{
1213
codec::Framed,
@@ -19,13 +20,14 @@ use types::{EthSpec, ForkContext};
1920
// `OutboundUpgrade`
2021

2122
#[derive(Debug, Clone)]
22-
pub struct OutboundRequestContainer<E: EthSpec> {
23-
pub req: RequestType<E>,
23+
pub struct OutboundRequestContainer<E> {
24+
pub req: RequestType,
2425
pub fork_context: Arc<ForkContext>,
2526
pub max_rpc_size: usize,
27+
pub phantom: PhantomData<E>,
2628
}
2729

28-
impl<E: EthSpec> UpgradeInfo for OutboundRequestContainer<E> {
30+
impl<E> UpgradeInfo for OutboundRequestContainer<E> {
2931
type Info = ProtocolId;
3032
type InfoIter = Vec<Self::Info>;
3133

beacon_node/lighthouse_network/src/rpc/protocol.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ pub fn rpc_data_column_limits<E: EthSpec>() -> RpcLimits {
643643
// The inbound protocol reads the request, decodes it and returns the stream to the protocol
644644
// handler to respond to once ready.
645645

646-
pub type InboundOutput<TSocket, E> = (RequestType<E>, InboundFramed<TSocket, E>);
646+
pub type InboundOutput<TSocket, E> = (RequestType, InboundFramed<TSocket, E>);
647647
pub type InboundFramed<TSocket, E> =
648648
Framed<std::pin::Pin<Box<TimeoutStream<Compat<TSocket>>>>, SSZSnappyInboundCodec<E>>;
649649

@@ -711,7 +711,7 @@ where
711711
}
712712

713713
#[derive(Debug, Clone, PartialEq)]
714-
pub enum RequestType<E> {
714+
pub enum RequestType {
715715
Status(StatusMessage),
716716
Goodbye(GoodbyeReason),
717717
BlocksByRange(OldBlocksByRangeRequest),
@@ -724,11 +724,11 @@ pub enum RequestType<E> {
724724
LightClientOptimisticUpdate,
725725
LightClientFinalityUpdate,
726726
Ping(Ping),
727-
MetaData(MetadataRequest<E>),
727+
MetaData(MetadataRequest),
728728
}
729729

730730
/// Implements the encoding per supported protocol for `RPCRequest`.
731-
impl<E: EthSpec> RequestType<E> {
731+
impl RequestType {
732732
/* These functions are used in the handler for stream management */
733733

734734
/// Maximum number of responses expected for this request.
@@ -738,7 +738,7 @@ impl<E: EthSpec> RequestType<E> {
738738
RequestType::Goodbye(_) => 0,
739739
RequestType::BlocksByRange(req) => *req.count(),
740740
RequestType::BlocksByRoot(req) => req.block_roots().len() as u64,
741-
RequestType::BlobsByRange(req) => req.max_blobs_requested::<E>(),
741+
RequestType::BlobsByRange(req) => req.max_blobs_requested(),
742742
RequestType::BlobsByRoot(req) => req.blob_ids.len() as u64,
743743
RequestType::DataColumnsByRoot(req) => req.data_column_ids.len() as u64,
744744
RequestType::DataColumnsByRange(req) => req.max_requested(),
@@ -973,7 +973,7 @@ impl std::error::Error for RPCError {
973973
}
974974
}
975975

976-
impl<E: EthSpec> std::fmt::Display for RequestType<E> {
976+
impl std::fmt::Display for RequestType {
977977
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
978978
match self {
979979
RequestType::Status(status) => write!(f, "Status Message: {}", status),

beacon_node/lighthouse_network/src/rpc/rate_limiter.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use std::pin::Pin;
99
use std::task::{Context, Poll};
1010
use std::time::{Duration, Instant};
1111
use tokio::time::Interval;
12-
use types::EthSpec;
1312

1413
/// Nanoseconds since a given time.
1514
// Maintained as u64 to reduce footprint
@@ -252,7 +251,7 @@ pub trait RateLimiterItem {
252251
fn max_responses(&self) -> u64;
253252
}
254253

255-
impl<E: EthSpec> RateLimiterItem for super::RequestType<E> {
254+
impl RateLimiterItem for super::RequestType {
256255
fn protocol(&self) -> Protocol {
257256
self.versioned_protocol().protocol()
258257
}

beacon_node/lighthouse_network/src/rpc/self_limiter.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ use super::{
1919

2020
/// A request that was rate limited or waiting on rate limited requests for the same peer and
2121
/// protocol.
22-
struct QueuedRequest<Id: ReqId, E: EthSpec> {
23-
req: RequestType<E>,
22+
struct QueuedRequest<Id: ReqId> {
23+
req: RequestType,
2424
request_id: Id,
2525
}
2626

2727
pub(crate) struct SelfRateLimiter<Id: ReqId, E: EthSpec> {
2828
/// Requests queued for sending per peer. This requests are stored when the self rate
2929
/// limiter rejects them. Rate limiting is based on a Peer and Protocol basis, therefore
3030
/// are stored in the same way.
31-
delayed_requests: HashMap<(PeerId, Protocol), VecDeque<QueuedRequest<Id, E>>>,
31+
delayed_requests: HashMap<(PeerId, Protocol), VecDeque<QueuedRequest<Id>>>,
3232
/// The delay required to allow a peer's outbound request per protocol.
3333
next_peer_request: DelayQueue<(PeerId, Protocol)>,
3434
/// Rate limiter for our own requests.
@@ -70,7 +70,7 @@ impl<Id: ReqId, E: EthSpec> SelfRateLimiter<Id, E> {
7070
&mut self,
7171
peer_id: PeerId,
7272
request_id: Id,
73-
req: RequestType<E>,
73+
req: RequestType,
7474
) -> Result<BehaviourAction<Id, E>, Error> {
7575
let protocol = req.versioned_protocol().protocol();
7676
// First check that there are not already other requests waiting to be sent.
@@ -101,9 +101,9 @@ impl<Id: ReqId, E: EthSpec> SelfRateLimiter<Id, E> {
101101
limiter: &mut RateLimiter,
102102
peer_id: PeerId,
103103
request_id: Id,
104-
req: RequestType<E>,
104+
req: RequestType,
105105
log: &Logger,
106-
) -> Result<BehaviourAction<Id, E>, (QueuedRequest<Id, E>, Duration)> {
106+
) -> Result<BehaviourAction<Id, E>, (QueuedRequest<Id>, Duration)> {
107107
match limiter.allows(&peer_id, &req) {
108108
Ok(()) => Ok(BehaviourAction::NotifyHandler {
109109
peer_id,

beacon_node/lighthouse_network/src/service/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ pub enum NetworkEvent<E: EthSpec> {
8383
/// Identifier of the request. All responses to this request must use this id.
8484
id: PeerRequestId,
8585
/// Request the peer sent.
86-
request: rpc::Request<E>,
86+
request: rpc::Request,
8787
},
8888
ResponseReceived {
8989
/// Peer that sent the response.
@@ -933,7 +933,7 @@ impl<E: EthSpec> Network<E> {
933933
&mut self,
934934
peer_id: PeerId,
935935
request_id: AppRequestId,
936-
request: RequestType<E>,
936+
request: RequestType,
937937
) -> Result<(), (AppRequestId, RPCError)> {
938938
// Check if the peer is connected before sending an RPC request
939939
if !self.swarm.is_connected(&peer_id) {
@@ -1146,7 +1146,7 @@ impl<E: EthSpec> Network<E> {
11461146
/// Sends a METADATA response to a peer.
11471147
fn send_meta_data_response(
11481148
&mut self,
1149-
_req: MetadataRequest<E>,
1149+
_req: MetadataRequest,
11501150
id: PeerRequestId,
11511151
request_id: rpc::RequestId,
11521152
peer_id: PeerId,

beacon_node/lighthouse_network/tests/rpc_tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ fn test_blobs_by_range_chunked_rpc() {
327327
let rpc_request = RequestType::BlobsByRange(BlobsByRangeRequest {
328328
start_slot: 0,
329329
count: slot_count,
330+
max_blobs_per_block: E::max_blobs_per_block(),
330331
});
331332

332333
// BlocksByRange Response

0 commit comments

Comments
 (0)