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,4 @@
#![allow(clippy::unit_arg)]
use crate::error;
use crate::service::NetworkMessage;
use crate::sync::MessageProcessor;

View File

@@ -161,7 +161,7 @@ fn network_service(
match network_recv.poll() {
Ok(Async::Ready(Some(message))) => match message {
NetworkMessage::RPC(peer_id, rpc_event) => {
trace!(log, "Sending RPC"; "RPC" => format!("{}", rpc_event));
trace!(log, "Sending RPC"; "rpc" => format!("{}", rpc_event));
libp2p_service.lock().swarm.send_rpc(peer_id, rpc_event);
}
NetworkMessage::Propagate {
@@ -184,7 +184,7 @@ fn network_service(
} else {
trace!(log, "Propagating gossipsub message";
"propagation_peer" => format!("{:?}", propagation_source),
"message_id" => format!("{}", message_id),
"message_id" => message_id.to_string(),
);
libp2p_service
.lock()
@@ -231,7 +231,7 @@ fn network_service(
match locked_service.poll() {
Ok(Async::Ready(Some(event))) => match event {
Libp2pEvent::RPC(peer_id, rpc_event) => {
trace!(log, "Received RPC"; "RPC" => format!("{}", rpc_event));
trace!(log, "Received RPC"; "rpc" => format!("{}", rpc_event));
// if we received a Goodbye message, drop and ban the peer
if let RPCEvent::Request(_, RPCRequest::Goodbye(_)) = rpc_event {

View File

@@ -107,18 +107,18 @@ pub enum SyncMessage<T: EthSpec> {
BlocksByRangeResponse {
peer_id: PeerId,
request_id: RequestId,
beacon_block: Option<BeaconBlock<T>>,
beacon_block: Option<Box<BeaconBlock<T>>>,
},
/// A `BlocksByRoot` response has been received.
BlocksByRootResponse {
peer_id: PeerId,
request_id: RequestId,
beacon_block: Option<BeaconBlock<T>>,
beacon_block: Option<Box<BeaconBlock<T>>>,
},
/// A block with an unknown parent has been received.
UnknownBlock(PeerId, BeaconBlock<T>),
UnknownBlock(PeerId, Box<BeaconBlock<T>>),
/// A peer has sent an object that references a block that is unknown. This triggers the
/// manager to attempt to find the block matching the unknown hash.
@@ -520,7 +520,6 @@ impl<T: BeaconChainTypes> SyncManager<T> {
parent_request.failed_attempts += 1;
parent_request.state = BlockRequestsState::Queued;
parent_request.last_submitted_peer = peer_id;
return;
}
}
}
@@ -549,7 +548,7 @@ impl<T: BeaconChainTypes> SyncManager<T> {
BlockProcessingOutcome::Processed { block_root } => {
info!(self.log, "Processed block"; "block" => format!("{}", block_root));
}
BlockProcessingOutcome::ParentUnknown { parent: _ } => {
BlockProcessingOutcome::ParentUnknown { .. } => {
// We don't know of the blocks parent, begin a parent lookup search
self.add_unknown_block(peer_id, block);
}
@@ -580,10 +579,10 @@ impl<T: BeaconChainTypes> SyncManager<T> {
// make sure this block is not already being searched for
// TODO: Potentially store a hashset of blocks for O(1) lookups
for parent_req in self.parent_queue.iter() {
if let Some(_) = parent_req
if parent_req
.downloaded_blocks
.iter()
.find(|d_block| d_block == &&block)
.any(|d_block| d_block == &block)
{
// we are already searching for this block, ignore it
return;
@@ -915,14 +914,14 @@ impl<T: BeaconChainTypes> SyncManager<T> {
// check if the chain exists
if let Some(chain) = self.chain.upgrade() {
match chain.process_block(block.clone()) {
Ok(BlockProcessingOutcome::ParentUnknown { parent: _ }) => {
Ok(BlockProcessingOutcome::ParentUnknown { .. }) => {
// need to keep looking for parents
completed_request.downloaded_blocks.push(block);
completed_request.state = BlockRequestsState::Queued;
re_run_poll = true;
break;
}
Ok(BlockProcessingOutcome::Processed { block_root: _ })
Ok(BlockProcessingOutcome::Processed { .. })
| Ok(BlockProcessingOutcome::BlockIsAlreadyKnown { .. }) => {}
Ok(outcome) => {
// it's a future slot or an invalid block, remove it and try again
@@ -965,13 +964,8 @@ impl<T: BeaconChainTypes> SyncManager<T> {
}
// remove any fully processed parent chains
self.parent_queue.retain(|req| {
if req.state == BlockRequestsState::ReadyToProcess {
false
} else {
true
}
});
self.parent_queue
.retain(|req| req.state != BlockRequestsState::ReadyToProcess);
re_run_poll
}
}
@@ -1172,17 +1166,21 @@ impl<T: BeaconChainTypes> Future for SyncManager<T> {
request_id,
beacon_block,
} => {
self.blocks_by_range_response(peer_id, request_id, beacon_block);
self.blocks_by_range_response(
peer_id,
request_id,
beacon_block.map(|b| *b),
);
}
SyncMessage::BlocksByRootResponse {
peer_id,
request_id,
beacon_block,
} => {
self.blocks_by_root_response(peer_id, request_id, beacon_block);
self.blocks_by_root_response(peer_id, request_id, beacon_block.map(|b| *b));
}
SyncMessage::UnknownBlock(peer_id, block) => {
self.add_unknown_block(peer_id, block);
self.add_unknown_block(peer_id, *block);
}
SyncMessage::UnknownBlockHash(peer_id, block_hash) => {
self.search_for_block(peer_id, block_hash);
@@ -1228,7 +1226,7 @@ impl<T: BeaconChainTypes> Future for SyncManager<T> {
}
// Shutdown the thread if the chain has termined
if let None = self.chain.upgrade() {
if self.chain.upgrade().is_none() {
return Ok(Async::Ready(()));
}
@@ -1240,6 +1238,6 @@ impl<T: BeaconChainTypes> Future for SyncManager<T> {
// update the state of the manager
self.update_state();
return Ok(Async::NotReady);
Ok(Async::NotReady)
}
}

View File

@@ -6,7 +6,7 @@ use beacon_chain::{
use eth2_libp2p::rpc::methods::*;
use eth2_libp2p::rpc::{RPCEvent, RPCRequest, RPCResponse, RequestId};
use eth2_libp2p::PeerId;
use slog::{debug, error, info, o, trace, warn};
use slog::{debug, info, o, trace, warn};
use ssz::Encode;
use std::sync::Arc;
use store::Store;
@@ -396,6 +396,7 @@ impl<T: BeaconChainTypes> MessageProcessor<T> {
request_id: RequestId,
beacon_block: Option<BeaconBlock<T::EthSpec>>,
) {
let beacon_block = beacon_block.map(Box::new);
trace!(
self.log,
"Received BlocksByRange Response";
@@ -416,6 +417,7 @@ impl<T: BeaconChainTypes> MessageProcessor<T> {
request_id: RequestId,
beacon_block: Option<BeaconBlock<T::EthSpec>>,
) {
let beacon_block = beacon_block.map(Box::new);
trace!(
self.log,
"Received BlocksByRoot Response";
@@ -442,11 +444,11 @@ impl<T: BeaconChainTypes> MessageProcessor<T> {
"peer_id" => format!("{:?}",peer_id));
SHOULD_FORWARD_GOSSIP_BLOCK
}
BlockProcessingOutcome::ParentUnknown { parent: _ } => {
BlockProcessingOutcome::ParentUnknown { .. } => {
// Inform the sync manager to find parents for this block
trace!(self.log, "Block with unknown parent received";
"peer_id" => format!("{:?}",peer_id));
self.send_to_sync(SyncMessage::UnknownBlock(peer_id, block.clone()));
self.send_to_sync(SyncMessage::UnknownBlock(peer_id, Box::new(block.clone())));
SHOULD_FORWARD_GOSSIP_BLOCK
}
BlockProcessingOutcome::FutureSlot {
@@ -473,13 +475,8 @@ impl<T: BeaconChainTypes> MessageProcessor<T> {
SHOULD_NOT_FORWARD_GOSSIP_BLOCK //TODO: Decide if we want to forward these
}
},
Err(e) => {
error!(
self.log,
"Error processing gossip beacon block";
"error" => format!("{:?}", e),
"block slot" => block.slot
);
Err(_) => {
// error is logged during the processing therefore no error is logged here
trace!(
self.log,
"Erroneous gossip beacon block ssz";
@@ -523,13 +520,13 @@ impl<T: BeaconChainTypes> MessageProcessor<T> {
self.network.disconnect(peer_id, GoodbyeReason::Fault);
}
},
Err(e) => {
Err(_) => {
// error is logged during the processing therefore no error is logged here
trace!(
self.log,
"Erroneous gossip attestation ssz";
"ssz" => format!("0x{}", hex::encode(msg.as_ssz_bytes())),
);
error!(self.log, "Invalid gossip attestation"; "error" => format!("{:?}", e));
}
}
}