mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-14 02:12:33 +00:00
Better handling of RPC errors and RPC conn with the PeerManager (#1047)
This commit is contained in:
@@ -10,7 +10,10 @@ use crate::error;
|
||||
use crate::service::NetworkMessage;
|
||||
use beacon_chain::{AttestationType, BeaconChain, BeaconChainTypes, BlockError};
|
||||
use eth2_libp2p::{
|
||||
rpc::{RPCError, RPCErrorResponse, RPCRequest, RPCResponse, RequestId, ResponseTermination},
|
||||
rpc::{
|
||||
RPCCodedResponse, RPCError, RPCRequest, RPCResponse, RPCResponseErrorCode, RequestId,
|
||||
ResponseTermination,
|
||||
},
|
||||
MessageId, NetworkGlobals, PeerId, PubsubMessage, RPCEvent,
|
||||
};
|
||||
use futures::future::Future;
|
||||
@@ -123,7 +126,7 @@ impl<T: BeaconChainTypes> Router<T> {
|
||||
match rpc_message {
|
||||
RPCEvent::Request(id, req) => self.handle_rpc_request(peer_id, id, req),
|
||||
RPCEvent::Response(id, resp) => self.handle_rpc_response(peer_id, id, resp),
|
||||
RPCEvent::Error(id, error) => self.handle_rpc_error(peer_id, id, error),
|
||||
RPCEvent::Error(id, _protocol, error) => self.handle_rpc_error(peer_id, id, error),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,23 +167,35 @@ impl<T: BeaconChainTypes> Router<T> {
|
||||
&mut self,
|
||||
peer_id: PeerId,
|
||||
request_id: RequestId,
|
||||
error_response: RPCErrorResponse<T::EthSpec>,
|
||||
error_response: RPCCodedResponse<T::EthSpec>,
|
||||
) {
|
||||
// an error could have occurred.
|
||||
match error_response {
|
||||
RPCErrorResponse::InvalidRequest(error) => {
|
||||
warn!(self.log, "Peer indicated invalid request";"peer_id" => format!("{:?}", peer_id), "error" => error.as_string());
|
||||
self.handle_rpc_error(peer_id, request_id, RPCError::RPCErrorResponse);
|
||||
RPCCodedResponse::InvalidRequest(error) => {
|
||||
warn!(self.log, "Peer indicated invalid request"; "peer_id" => format!("{:?}", peer_id), "error" => error.as_string());
|
||||
self.handle_rpc_error(
|
||||
peer_id,
|
||||
request_id,
|
||||
RPCError::ErrorResponse(RPCResponseErrorCode::InvalidRequest),
|
||||
);
|
||||
}
|
||||
RPCErrorResponse::ServerError(error) => {
|
||||
warn!(self.log, "Peer internal server error";"peer_id" => format!("{:?}", peer_id), "error" => error.as_string());
|
||||
self.handle_rpc_error(peer_id, request_id, RPCError::RPCErrorResponse);
|
||||
RPCCodedResponse::ServerError(error) => {
|
||||
warn!(self.log, "Peer internal server error"; "peer_id" => format!("{:?}", peer_id), "error" => error.as_string());
|
||||
self.handle_rpc_error(
|
||||
peer_id,
|
||||
request_id,
|
||||
RPCError::ErrorResponse(RPCResponseErrorCode::ServerError),
|
||||
);
|
||||
}
|
||||
RPCErrorResponse::Unknown(error) => {
|
||||
warn!(self.log, "Unknown peer error";"peer" => format!("{:?}", peer_id), "error" => error.as_string());
|
||||
self.handle_rpc_error(peer_id, request_id, RPCError::RPCErrorResponse);
|
||||
RPCCodedResponse::Unknown(error) => {
|
||||
warn!(self.log, "Unknown peer error"; "peer" => format!("{:?}", peer_id), "error" => error.as_string());
|
||||
self.handle_rpc_error(
|
||||
peer_id,
|
||||
request_id,
|
||||
RPCError::ErrorResponse(RPCResponseErrorCode::Unknown),
|
||||
);
|
||||
}
|
||||
RPCErrorResponse::Success(response) => match response {
|
||||
RPCCodedResponse::Success(response) => match response {
|
||||
RPCResponse::Status(status_message) => {
|
||||
self.processor.on_status_response(peer_id, status_message);
|
||||
}
|
||||
@@ -205,7 +220,7 @@ impl<T: BeaconChainTypes> Router<T> {
|
||||
unreachable!("Meta data must be handled in the behaviour");
|
||||
}
|
||||
},
|
||||
RPCErrorResponse::StreamTermination(response_type) => {
|
||||
RPCCodedResponse::StreamTermination(response_type) => {
|
||||
// have received a stream termination, notify the processing functions
|
||||
match response_type {
|
||||
ResponseTermination::BlocksByRange => {
|
||||
|
||||
@@ -5,7 +5,7 @@ use beacon_chain::{
|
||||
BlockProcessingOutcome, GossipVerifiedBlock,
|
||||
};
|
||||
use eth2_libp2p::rpc::methods::*;
|
||||
use eth2_libp2p::rpc::{RPCEvent, RPCRequest, RPCResponse, RequestId};
|
||||
use eth2_libp2p::rpc::{RPCCodedResponse, RPCEvent, RPCRequest, RPCResponse, RequestId};
|
||||
use eth2_libp2p::{NetworkGlobals, PeerId};
|
||||
use slog::{debug, error, o, trace, warn};
|
||||
use ssz::Encode;
|
||||
@@ -314,7 +314,7 @@ impl<T: BeaconChainTypes> Processor<T> {
|
||||
self.network.send_rpc_error_response(
|
||||
peer_id,
|
||||
request_id,
|
||||
RPCErrorResponse::StreamTermination(ResponseTermination::BlocksByRoot),
|
||||
RPCCodedResponse::StreamTermination(ResponseTermination::BlocksByRoot),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -413,7 +413,7 @@ impl<T: BeaconChainTypes> Processor<T> {
|
||||
self.network.send_rpc_error_response(
|
||||
peer_id,
|
||||
request_id,
|
||||
RPCErrorResponse::StreamTermination(ResponseTermination::BlocksByRange),
|
||||
RPCCodedResponse::StreamTermination(ResponseTermination::BlocksByRange),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -691,16 +691,16 @@ impl<T: EthSpec> HandlerNetworkContext<T> {
|
||||
) {
|
||||
self.send_rpc_event(
|
||||
peer_id,
|
||||
RPCEvent::Response(request_id, RPCErrorResponse::Success(rpc_response)),
|
||||
RPCEvent::Response(request_id, RPCCodedResponse::Success(rpc_response)),
|
||||
);
|
||||
}
|
||||
|
||||
/// Send an RPCErrorResponse. This handles errors and stream terminations.
|
||||
/// Send an RPCCodedResponse. This handles errors and stream terminations.
|
||||
pub fn send_rpc_error_response(
|
||||
&mut self,
|
||||
peer_id: PeerId,
|
||||
request_id: RequestId,
|
||||
rpc_error_response: RPCErrorResponse<T>,
|
||||
rpc_error_response: RPCCodedResponse<T>,
|
||||
) {
|
||||
self.send_rpc_event(peer_id, RPCEvent::Response(request_id, rpc_error_response));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user