From be20c65743cefdaa5a3bfb29c2fc668fc57d8925 Mon Sep 17 00:00:00 2001 From: Andrei Eres Date: Tue, 7 Jan 2025 13:59:23 +0100 Subject: [PATCH] Implement NetworkRequest for litep2p (#7073) # Description Implements NetworkRequest::request for litep2p that we need for networking benchmarks ## Review Notes Duplicates implementation for NetworkService https://github.com/paritytech/polkadot-sdk/blob/5bf9dd2aa9bf944434203128783925bdc2ad8c01/substrate/client/network/src/service.rs#L1186-L1205 --------- Co-authored-by: command-bot <> --- prdoc/pr_7073.prdoc | 16 ++++++++++++ .../client/network/src/litep2p/service.rs | 26 +++++++++++++------ 2 files changed, 34 insertions(+), 8 deletions(-) create mode 100644 prdoc/pr_7073.prdoc diff --git a/prdoc/pr_7073.prdoc b/prdoc/pr_7073.prdoc new file mode 100644 index 000000000000..3bcd129d0317 --- /dev/null +++ b/prdoc/pr_7073.prdoc @@ -0,0 +1,16 @@ +title: Implement NetworkRequest for litep2p +doc: +- audience: Node Dev + description: |- + # Description + + Implements NetworkRequest::request for litep2p that we need for networking benchmarks + + + ## Review Notes + + Duplicates implementation for NetworkService + https://github.com/paritytech/polkadot-sdk/blob/5bf9dd2aa9bf944434203128783925bdc2ad8c01/substrate/client/network/src/service.rs#L1186-L1205 +crates: +- name: sc-network + bump: patch diff --git a/substrate/client/network/src/litep2p/service.rs b/substrate/client/network/src/litep2p/service.rs index d270e90efdf5..2d4a117d1563 100644 --- a/substrate/client/network/src/litep2p/service.rs +++ b/substrate/client/network/src/litep2p/service.rs @@ -28,8 +28,8 @@ use crate::{ peer_store::PeerStoreProvider, service::out_events, Event, IfDisconnected, NetworkDHTProvider, NetworkEventStream, NetworkPeers, NetworkRequest, - NetworkSigner, NetworkStateInfo, NetworkStatus, NetworkStatusProvider, ProtocolName, - RequestFailure, Signature, + NetworkSigner, NetworkStateInfo, NetworkStatus, NetworkStatusProvider, OutboundFailure, + ProtocolName, RequestFailure, Signature, }; use codec::DecodeAll; @@ -526,13 +526,23 @@ impl NetworkStateInfo for Litep2pNetworkService { impl NetworkRequest for Litep2pNetworkService { async fn request( &self, - _target: PeerId, - _protocol: ProtocolName, - _request: Vec, - _fallback_request: Option<(Vec, ProtocolName)>, - _connect: IfDisconnected, + target: PeerId, + protocol: ProtocolName, + request: Vec, + fallback_request: Option<(Vec, ProtocolName)>, + connect: IfDisconnected, ) -> Result<(Vec, ProtocolName), RequestFailure> { - unimplemented!(); + let (tx, rx) = oneshot::channel(); + + self.start_request(target, protocol, request, fallback_request, tx, connect); + + match rx.await { + Ok(v) => v, + // The channel can only be closed if the network worker no longer exists. If the + // network worker no longer exists, then all connections to `target` are necessarily + // closed, and we legitimately report this situation as a "ConnectionClosed". + Err(_) => Err(RequestFailure::Network(OutboundFailure::ConnectionClosed)), + } } fn start_request(