mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-15 02:42:38 +00:00
Use E for EthSpec globally (#5264)
* Use `E` for `EthSpec` globally * Fix tests * Merge branch 'unstable' into e-ethspec * Merge branch 'unstable' into e-ethspec # Conflicts: # beacon_node/execution_layer/src/engine_api.rs # beacon_node/execution_layer/src/engine_api/http.rs # beacon_node/execution_layer/src/engine_api/json_structures.rs # beacon_node/execution_layer/src/test_utils/handle_rpc.rs # beacon_node/store/src/partial_beacon_state.rs # consensus/types/src/beacon_block.rs # consensus/types/src/beacon_block_body.rs # consensus/types/src/beacon_state.rs # consensus/types/src/config_and_preset.rs # consensus/types/src/execution_payload.rs # consensus/types/src/execution_payload_header.rs # consensus/types/src/light_client_optimistic_update.rs # consensus/types/src/payload.rs # lcli/src/parse_ssz.rs
This commit is contained in:
@@ -51,41 +51,41 @@ impl<T> ReqId for T where T: Send + 'static + std::fmt::Debug + Copy + Clone {}
|
||||
|
||||
/// RPC events sent from Lighthouse.
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum RPCSend<Id, TSpec: EthSpec> {
|
||||
pub enum RPCSend<Id, E: EthSpec> {
|
||||
/// A request sent from Lighthouse.
|
||||
///
|
||||
/// The `Id` is given by the application making the request. These
|
||||
/// go over *outbound* connections.
|
||||
Request(Id, OutboundRequest<TSpec>),
|
||||
Request(Id, OutboundRequest<E>),
|
||||
/// A response sent from Lighthouse.
|
||||
///
|
||||
/// The `SubstreamId` must correspond to the RPC-given ID of the original request received from the
|
||||
/// peer. The second parameter is a single chunk of a response. These go over *inbound*
|
||||
/// connections.
|
||||
Response(SubstreamId, RPCCodedResponse<TSpec>),
|
||||
Response(SubstreamId, RPCCodedResponse<E>),
|
||||
/// Lighthouse has requested to terminate the connection with a goodbye message.
|
||||
Shutdown(Id, GoodbyeReason),
|
||||
}
|
||||
|
||||
/// RPC events received from outside Lighthouse.
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum RPCReceived<Id, T: EthSpec> {
|
||||
pub enum RPCReceived<Id, E: EthSpec> {
|
||||
/// A request received from the outside.
|
||||
///
|
||||
/// The `SubstreamId` is given by the `RPCHandler` as it identifies this request with the
|
||||
/// *inbound* substream over which it is managed.
|
||||
Request(SubstreamId, InboundRequest<T>),
|
||||
Request(SubstreamId, InboundRequest<E>),
|
||||
/// A response received from the outside.
|
||||
///
|
||||
/// The `Id` corresponds to the application given ID of the original request sent to the
|
||||
/// peer. The second parameter is a single chunk of a response. These go over *outbound*
|
||||
/// connections.
|
||||
Response(Id, RPCResponse<T>),
|
||||
Response(Id, RPCResponse<E>),
|
||||
/// Marks a request as completed
|
||||
EndOfStream(Id, ResponseTermination),
|
||||
}
|
||||
|
||||
impl<T: EthSpec, Id: std::fmt::Debug> std::fmt::Display for RPCSend<Id, T> {
|
||||
impl<E: EthSpec, Id: std::fmt::Debug> std::fmt::Display for RPCSend<Id, E> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
RPCSend::Request(id, req) => write!(f, "RPC Request(id: {:?}, {})", id, req),
|
||||
@@ -97,16 +97,16 @@ impl<T: EthSpec, Id: std::fmt::Debug> std::fmt::Display for RPCSend<Id, T> {
|
||||
|
||||
/// Messages sent to the user from the RPC protocol.
|
||||
#[derive(Debug)]
|
||||
pub struct RPCMessage<Id, TSpec: EthSpec> {
|
||||
pub struct RPCMessage<Id, E: EthSpec> {
|
||||
/// The peer that sent the message.
|
||||
pub peer_id: PeerId,
|
||||
/// Handler managing this message.
|
||||
pub conn_id: ConnectionId,
|
||||
/// The message that was sent.
|
||||
pub event: HandlerEvent<Id, TSpec>,
|
||||
pub event: HandlerEvent<Id, E>,
|
||||
}
|
||||
|
||||
type BehaviourAction<Id, TSpec> = ToSwarm<RPCMessage<Id, TSpec>, RPCSend<Id, TSpec>>;
|
||||
type BehaviourAction<Id, E> = ToSwarm<RPCMessage<Id, E>, RPCSend<Id, E>>;
|
||||
|
||||
pub struct NetworkParams {
|
||||
pub max_chunk_size: usize,
|
||||
@@ -116,13 +116,13 @@ pub struct NetworkParams {
|
||||
|
||||
/// Implements the libp2p `NetworkBehaviour` trait and therefore manages network-level
|
||||
/// logic.
|
||||
pub struct RPC<Id: ReqId, TSpec: EthSpec> {
|
||||
pub struct RPC<Id: ReqId, E: EthSpec> {
|
||||
/// Rate limiter
|
||||
limiter: Option<RateLimiter>,
|
||||
/// Rate limiter for our own requests.
|
||||
self_limiter: Option<SelfRateLimiter<Id, TSpec>>,
|
||||
self_limiter: Option<SelfRateLimiter<Id, E>>,
|
||||
/// Queue of events to be processed.
|
||||
events: Vec<BehaviourAction<Id, TSpec>>,
|
||||
events: Vec<BehaviourAction<Id, E>>,
|
||||
fork_context: Arc<ForkContext>,
|
||||
enable_light_client_server: bool,
|
||||
/// Slog logger for RPC behaviour.
|
||||
@@ -131,7 +131,7 @@ pub struct RPC<Id: ReqId, TSpec: EthSpec> {
|
||||
network_params: NetworkParams,
|
||||
}
|
||||
|
||||
impl<Id: ReqId, TSpec: EthSpec> RPC<Id, TSpec> {
|
||||
impl<Id: ReqId, E: EthSpec> RPC<Id, E> {
|
||||
pub fn new(
|
||||
fork_context: Arc<ForkContext>,
|
||||
enable_light_client_server: bool,
|
||||
@@ -170,7 +170,7 @@ impl<Id: ReqId, TSpec: EthSpec> RPC<Id, TSpec> {
|
||||
&mut self,
|
||||
peer_id: PeerId,
|
||||
id: (ConnectionId, SubstreamId),
|
||||
event: RPCCodedResponse<TSpec>,
|
||||
event: RPCCodedResponse<E>,
|
||||
) {
|
||||
self.events.push(ToSwarm::NotifyHandler {
|
||||
peer_id,
|
||||
@@ -182,7 +182,7 @@ impl<Id: ReqId, TSpec: EthSpec> RPC<Id, TSpec> {
|
||||
/// Submits an RPC request.
|
||||
///
|
||||
/// The peer must be connected for this to succeed.
|
||||
pub fn send_request(&mut self, peer_id: PeerId, request_id: Id, req: OutboundRequest<TSpec>) {
|
||||
pub fn send_request(&mut self, peer_id: PeerId, request_id: Id, req: OutboundRequest<E>) {
|
||||
let event = if let Some(self_limiter) = self.self_limiter.as_mut() {
|
||||
match self_limiter.allows(peer_id, request_id, req) {
|
||||
Ok(event) => event,
|
||||
@@ -213,13 +213,13 @@ impl<Id: ReqId, TSpec: EthSpec> RPC<Id, TSpec> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<Id, TSpec> NetworkBehaviour for RPC<Id, TSpec>
|
||||
impl<Id, E> NetworkBehaviour for RPC<Id, E>
|
||||
where
|
||||
TSpec: EthSpec,
|
||||
E: EthSpec,
|
||||
Id: ReqId,
|
||||
{
|
||||
type ConnectionHandler = RPCHandler<Id, TSpec>;
|
||||
type ToSwarm = RPCMessage<Id, TSpec>;
|
||||
type ConnectionHandler = RPCHandler<Id, E>;
|
||||
type ToSwarm = RPCMessage<Id, E>;
|
||||
|
||||
fn handle_established_inbound_connection(
|
||||
&mut self,
|
||||
@@ -394,9 +394,9 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<Id, TSpec> slog::KV for RPCMessage<Id, TSpec>
|
||||
impl<Id, E> slog::KV for RPCMessage<Id, E>
|
||||
where
|
||||
TSpec: EthSpec,
|
||||
E: EthSpec,
|
||||
Id: ReqId,
|
||||
{
|
||||
fn serialize(
|
||||
|
||||
Reference in New Issue
Block a user