Skip to content
21 changes: 19 additions & 2 deletions crates/networking/p2p/rlpx/connection/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -804,8 +804,25 @@ async fn handle_peer_message(state: &mut Established, message: Message) -> Resul
}

if let Err(e) = state.blockchain.add_transaction_to_pool(tx.clone()).await {
log_peer_warn(&state.node, &format!("Error adding transaction: {e}"));
continue;
match e {
// Some of the more common mempool errors are logged at debug level, we might want to move all of them to debug in the future
ethrex_blockchain::error::MempoolError::NonceTooLow
| ethrex_blockchain::error::MempoolError::NotEnoughBalance
| ethrex_blockchain::error::MempoolError::UnderpricedReplacement => {
log_peer_debug(
&state.node,
&format!("Error adding transaction common: {e}"),
);
continue;
}
_ => {
log_peer_warn(
&state.node,
&format!("Error adding transaction: {e}"),
);
continue;
}
}
}
}
state
Expand Down
6 changes: 3 additions & 3 deletions crates/networking/p2p/rlpx/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ pub fn snappy_decompress(msg_data: &[u8]) -> Result<Vec<u8>, RLPDecodeError> {
}

pub(crate) fn log_peer_debug(node: &Node, text: &str) {
debug!("[{0}]: {1}", node, text)
debug!("{0}/[{1}]: {2}", node.client_name(), node, text)
}

pub(crate) fn log_peer_error(node: &Node, text: &str) {
error!("[{0}]: {1}", node, text)
error!("{0}/[{1}]: {2}", node.client_name(), node, text)
}
pub(crate) fn log_peer_warn(node: &Node, text: &str) {
warn!("[{0}]: {1}", node, text)
warn!("{0}/[{1}]: {2}", node.client_name(), node, text)
}

#[cfg(test)]
Expand Down
13 changes: 13 additions & 0 deletions crates/networking/p2p/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,19 @@ impl Node {
}
}

pub fn client_name(&self) -> &str {
self.version
.as_deref()
.and_then(|version| {
let base = version
.split_once('/')
.map(|(name, _)| name.trim())
.unwrap_or_else(|| version.trim());
if base.is_empty() { None } else { Some(base) }
})
.unwrap_or("unknown")
}

pub fn from_enode_url(enode: &str) -> Result<Self, NodeError> {
let public_key = H512::from_str(&enode[8..136])
.map_err(|_| NodeError::ParseError("Could not parse public_key".into()))?;
Expand Down
Loading