diff --git a/substrate/client/network/src/litep2p/shim/request_response/mod.rs b/substrate/client/network/src/litep2p/shim/request_response/mod.rs index 82d01c01236f..a77acb464144 100644 --- a/substrate/client/network/src/litep2p/shim/request_response/mod.rs +++ b/substrate/client/network/src/litep2p/shim/request_response/mod.rs @@ -24,7 +24,7 @@ use crate::{ peer_store::PeerStoreProvider, request_responses::{IncomingRequest, OutgoingResponse}, service::{metrics::Metrics, traits::RequestResponseConfig as RequestResponseConfigT}, - IfDisconnected, ProtocolName, RequestFailure, + IfDisconnected, OutboundFailure, ProtocolName, RequestFailure, }; use futures::{channel::oneshot, future::BoxFuture, stream::FuturesUnordered, StreamExt}; @@ -369,10 +369,12 @@ impl RequestResponseProtocol { return }; - let error = match error { - RequestResponseError::NotConnected => Some(RequestFailure::NotConnected), - RequestResponseError::Rejected | RequestResponseError::Timeout => - Some(RequestFailure::Refused), + let status = match error { + RequestResponseError::NotConnected => + Some((RequestFailure::NotConnected, "not-connected")), + RequestResponseError::Rejected => Some((RequestFailure::Refused, "rejected")), + RequestResponseError::Timeout => + Some((RequestFailure::Network(OutboundFailure::Timeout), "timeout")), RequestResponseError::Canceled => { log::debug!( target: LOG_TARGET, @@ -387,7 +389,7 @@ impl RequestResponseProtocol { "{}: tried to send too large request to {peer:?} ({request_id:?})", self.protocol, ); - Some(RequestFailure::Refused) + Some((RequestFailure::Refused, "payload-too-large")) }, RequestResponseError::UnsupportedProtocol => match fallback_request { Some((request, protocol)) => match self.request_tx.get(&protocol) { @@ -426,15 +428,15 @@ impl RequestResponseProtocol { peer, ); - Some(RequestFailure::Refused) + Some((RequestFailure::Refused, "invalid-fallback-protocol")) }, }, - None => Some(RequestFailure::Refused), + None => Some((RequestFailure::Refused, "unsupported-protocol")), }, }; - if let Some(error) = error { - self.metrics.register_outbound_request_failure(error.to_string().as_ref()); + if let Some((error, reason)) = status { + self.metrics.register_outbound_request_failure(reason); let _ = tx.send(Err(error)); } }