Clean up network logging and code (#643)

* Apply clippy lints to beacon node

* Remove unnecessary logging and correct formatting

* Apply reviewers suggestions
This commit is contained in:
Age Manning
2019-11-29 22:25:36 +11:00
committed by GitHub
parent 3a05c6f924
commit cbe8dd96b2
13 changed files with 58 additions and 81 deletions

View File

@@ -1,3 +1,6 @@
#![allow(clippy::type_complexity)]
#![allow(clippy::cognitive_complexity)]
use super::methods::{RPCErrorResponse, RequestId};
use super::protocol::{RPCError, RPCProtocol, RPCRequest};
use super::RPCEvent;
@@ -174,7 +177,6 @@ where
}
/// Opens an outbound substream with a request.
#[inline]
pub fn send_request(&mut self, rpc_event: RPCEvent) {
self.keep_alive = KeepAlive::Yes;
@@ -194,12 +196,10 @@ where
type OutboundProtocol = RPCRequest;
type OutboundOpenInfo = RPCEvent; // Keep track of the id and the request
#[inline]
fn listen_protocol(&self) -> SubstreamProtocol<Self::InboundProtocol> {
self.listen_protocol.clone()
}
#[inline]
fn inject_fully_negotiated_inbound(
&mut self,
out: <RPCProtocol as InboundUpgrade<TSubstream>>::Output,
@@ -225,7 +225,6 @@ where
self.current_substream_id += 1;
}
#[inline]
fn inject_fully_negotiated_outbound(
&mut self,
out: <RPCRequest as OutboundUpgrade<TSubstream>>::Output,
@@ -263,14 +262,11 @@ where
// Note: If the substream has closed due to inactivity, or the substream is in the
// wrong state a response will fail silently.
#[inline]
fn inject_event(&mut self, rpc_event: Self::InEvent) {
match rpc_event {
RPCEvent::Request(_, _) => self.send_request(rpc_event),
RPCEvent::Response(rpc_id, response) => {
// check if the stream matching the response still exists
trace!(self.log, "Checking for outbound stream");
// variables indicating if the response is an error response or a multi-part
// response
let res_is_error = response.is_error();
@@ -280,7 +276,6 @@ where
Some((substream_state, _)) => {
match std::mem::replace(substream_state, InboundSubstreamState::Poisoned) {
InboundSubstreamState::ResponseIdle(substream) => {
trace!(self.log, "Stream is idle, sending message"; "message" => format!("{}", response));
// close the stream if there is no response
if let RPCErrorResponse::StreamTermination(_) = response {
trace!(self.log, "Stream termination sent. Ending the stream");
@@ -298,7 +293,6 @@ where
if res_is_multiple =>
{
// the stream is in use, add the request to a pending queue
trace!(self.log, "Adding message to queue"; "message" => format!("{}", response));
(*self
.queued_outbound_items
.entry(rpc_id)
@@ -338,7 +332,6 @@ where
}
}
#[inline]
fn inject_dial_upgrade_error(
&mut self,
_: Self::OutboundOpenInfo,
@@ -351,7 +344,6 @@ where
}
}
#[inline]
fn connection_keep_alive(&self) -> KeepAlive {
self.keep_alive
}
@@ -384,7 +376,6 @@ where
.poll()
.map_err(|_| ProtocolsHandlerUpgrErr::Timer)?
{
trace!(self.log, "Closing expired inbound stream");
self.inbound_substreams.remove(stream_id.get_ref());
}
@@ -394,7 +385,6 @@ where
.poll()
.map_err(|_| ProtocolsHandlerUpgrErr::Timer)?
{
trace!(self.log, "Closing expired outbound stream");
self.outbound_substreams.remove(stream_id.get_ref());
}
@@ -403,7 +393,7 @@ where
// Drain all queued items until all messages have been processed for this stream
// TODO Improve this code logic
let mut new_items_to_send = true;
while new_items_to_send == true {
while new_items_to_send {
new_items_to_send = false;
match self.inbound_substreams.entry(request_id) {
Entry::Occupied(mut entry) => {
@@ -418,7 +408,6 @@ where
match substream.poll() {
Ok(Async::Ready(raw_substream)) => {
// completed the send
trace!(self.log, "RPC message sent");
// close the stream if required
if closing {
@@ -426,7 +415,6 @@ where
InboundSubstreamState::Closing(raw_substream)
} else {
// check for queued chunks and update the stream
trace!(self.log, "Checking for queued items");
entry.get_mut().0 = apply_queued_responses(
raw_substream,
&mut self
@@ -454,7 +442,6 @@ where
};
}
InboundSubstreamState::ResponseIdle(substream) => {
trace!(self.log, "Idle stream searching queue");
entry.get_mut().0 = apply_queued_responses(
substream,
&mut self.queued_outbound_items.get_mut(&request_id),
@@ -500,12 +487,11 @@ where
request,
} => match substream.poll() {
Ok(Async::Ready(Some(response))) => {
trace!(self.log, "Message received"; "message" => format!("{}", response));
if request.multiple_responses() {
entry.get_mut().0 =
OutboundSubstreamState::RequestPendingResponse {
substream,
request: request,
request,
};
let delay_key = &entry.get().1;
self.outbound_substreams_delay