Skip to content

Commit

Permalink
Implement NetworkRequest for litep2p (#7073)
Browse files Browse the repository at this point in the history
# 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 <>
  • Loading branch information
AndreiEres authored Jan 7, 2025
1 parent d2c157a commit be20c65
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
16 changes: 16 additions & 0 deletions prdoc/pr_7073.prdoc
Original file line number Diff line number Diff line change
@@ -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
26 changes: 18 additions & 8 deletions substrate/client/network/src/litep2p/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -526,13 +526,23 @@ impl NetworkStateInfo for Litep2pNetworkService {
impl NetworkRequest for Litep2pNetworkService {
async fn request(
&self,
_target: PeerId,
_protocol: ProtocolName,
_request: Vec<u8>,
_fallback_request: Option<(Vec<u8>, ProtocolName)>,
_connect: IfDisconnected,
target: PeerId,
protocol: ProtocolName,
request: Vec<u8>,
fallback_request: Option<(Vec<u8>, ProtocolName)>,
connect: IfDisconnected,
) -> Result<(Vec<u8>, 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(
Expand Down

0 comments on commit be20c65

Please sign in to comment.