Skip to content

Commit

Permalink
Add extra logging detail for wiremode warnings (#3216)
Browse files Browse the repository at this point in the history
<!--- Provide a general summary of your changes in the Title above -->

## Description
<!--- Describe your changes in detail -->
Minor log warning improvements for the case where a wire format byte is not received 

## Motivation and Context
<!--- Why is this change required? What problem does it solve? -->
<!--- If it fixes an open issue, please link to the issue here. -->
Adding more log info for some observed warnings 

## How Has This Been Tested?
<!--- Please describe in detail how you tested your changes. -->
<!--- Include details of your testing environment, and the tests you ran to -->
<!--- see how your change affects other areas of the code, etc. -->
Replaced existing base node and started syncing a new node successfully 

## Checklist:
<!--- Go over all the following points, and put an `x` in all the boxes that apply. -->
* [x] I'm merging against the `development` branch.
* [x] I have squashed my commits into a single commit.
  • Loading branch information
Byron Hambly authored Aug 22, 2021
1 parent 8a0b3c6 commit db4c0b9
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 20 deletions.
60 changes: 41 additions & 19 deletions comms/src/connection_manager/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ use super::{
};
use crate::{
bounded_executor::BoundedExecutor,
connection_manager::{liveness::LivenessSession, types::OneshotTrigger, wire_mode::WireMode},
connection_manager::{
liveness::LivenessSession,
types::OneshotTrigger,
wire_mode::{WireMode, LIVENESS_WIRE_MODE},
},
multiaddr::Multiaddr,
multiplexing::Yamux,
noise::NoiseConfig,
Expand All @@ -56,6 +60,7 @@ use log::*;
use std::{
convert::TryInto,
future::Future,
io::{Error, ErrorKind},
sync::{
atomic::{AtomicUsize, Ordering},
Arc,
Expand Down Expand Up @@ -168,22 +173,34 @@ where
}
}

async fn read_wire_format(socket: &mut TTransport::Output, time_to_first_byte: Duration) -> Option<WireMode> {
async fn read_wire_format(
socket: &mut TTransport::Output,
time_to_first_byte: Duration,
) -> Result<WireMode, Error> {
let mut buf = [0u8; 1];
match time::timeout(time_to_first_byte, socket.read_exact(&mut buf))
.await
.ok()?
{
Ok(_) => match buf[0].try_into().ok() {
Some(wf) => Some(wf),
None => {
warn!(target: LOG_TARGET, "Invalid wire format byte '{}'", buf[0]);
None
match time::timeout(time_to_first_byte, socket.read_exact(&mut buf)).await {
Ok(result) => match result {
Ok(_) => match buf[0].try_into().ok() {
Some(wf) => Ok(wf),
None => {
warn!(target: LOG_TARGET, "Invalid wire format byte '{}'", buf[0]);
Err(ErrorKind::InvalidData.into())
},
},
Err(err) => {
warn!(
target: LOG_TARGET,
"Failed to read wire format byte due to error: {}", err
);
Err(err)
},
},
Err(err) => {
warn!(target: LOG_TARGET, "Failed to read first byte: {}", err);
None
Err(elapsed) => {
warn!(
target: LOG_TARGET,
"Failed to read wire format byte within timeout of {:#?}. {}", time_to_first_byte, elapsed
);
Err(elapsed.into())
},
}
}
Expand Down Expand Up @@ -227,7 +244,7 @@ where

let inbound_fut = async move {
match Self::read_wire_format(&mut socket, config.time_to_first_byte).await {
Some(WireMode::Comms(byte)) if byte == config.network_info.network_byte => {
Ok(WireMode::Comms(byte)) if byte == config.network_info.network_byte => {
let this_node_id_str = node_identity.node_id().short_str();
let result = Self::perform_socket_upgrade_procedure(
node_identity,
Expand Down Expand Up @@ -268,7 +285,7 @@ where
},
}
},
Some(WireMode::Comms(byte)) => {
Ok(WireMode::Comms(byte)) => {
warn!(
target: LOG_TARGET,
"Peer at address '{}' sent invalid wire format byte. Expected {:x?} got: {:x?} ",
Expand All @@ -277,7 +294,7 @@ where
byte,
);
},
Some(WireMode::Liveness) => {
Ok(WireMode::Liveness) => {
if liveness_session_count.load(Ordering::SeqCst) > 0 &&
Self::is_address_in_liveness_cidr_range(&peer_addr, &config.liveness_cidr_allowlist)
{
Expand All @@ -295,10 +312,15 @@ where
let _ = socket.close().await;
}
},
None => {
Err(err) => {
warn!(
target: LOG_TARGET,
"Peer at address '{}' failed to send valid wire format", peer_addr
"Peer at address '{}' failed to send wire format. Expected network byte {:x?} or liveness \
byte {:x?} not received. Error: {}",
peer_addr,
config.network_info.network_byte,
LIVENESS_WIRE_MODE,
err
);
},
}
Expand Down
2 changes: 1 addition & 1 deletion comms/src/connection_manager/wire_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

use std::convert::TryFrom;

const LIVENESS_WIRE_MODE: u8 = 0x46; // E
pub(crate) const LIVENESS_WIRE_MODE: u8 = 0x46; // E

pub enum WireMode {
Comms(u8),
Expand Down

0 comments on commit db4c0b9

Please sign in to comment.