Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Allow PeerIds in requests to network bridge.
  • Loading branch information
eskimor committed Mar 9, 2021
commit cd37370a2f1cb6ef5ffcd0ec44298ef4215ed1f7
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use futures::{FutureExt, SinkExt};

use polkadot_erasure_coding::branch_hash;
use polkadot_node_network_protocol::request_response::{
request::{OutgoingRequest, RequestError, Requests},
request::{OutgoingRequest, RequestError, Requests, Recipient},
v1::{AvailabilityFetchingRequest, AvailabilityFetchingResponse},
};
use polkadot_primitives::v1::{
Expand Down Expand Up @@ -330,7 +330,7 @@ impl RunningTask {
validator: &AuthorityDiscoveryId,
) -> std::result::Result<AvailabilityFetchingResponse, TaskError> {
let (full_request, response_recv) =
OutgoingRequest::new(validator.clone(), self.request);
OutgoingRequest::new(Recipient::Authority(validator.clone()), self.request);
let requests = Requests::AvailabilityFetching(full_request);

self.sender
Expand Down
22 changes: 13 additions & 9 deletions node/network/bridge/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use sc_network::{IfDisconnected, NetworkService, OutboundFailure, RequestFailure

use polkadot_node_network_protocol::{
peer_set::PeerSet,
request_response::{OutgoingRequest, Requests},
request_response::{OutgoingRequest, Requests, Recipient},
PeerId, UnifiedReputationChange as Rep,
};
use polkadot_primitives::v1::{Block, Hash};
Expand Down Expand Up @@ -212,14 +212,18 @@ impl Network for Arc<NetworkService<Block, Hash>> {
},
) = req.encode_request();

let peer_id = authority_discovery
.get_addresses_by_authority_id(peer)
.await
.and_then(|addrs| {
addrs
.into_iter()
.find_map(|addr| peer_id_from_multiaddr(&addr))
});
let peer_id = match peer {
Recipient::Peer(peer_id) => Some(peer_id),
Recipient::Authority(authority) =>
authority_discovery
.get_addresses_by_authority_id(authority)
.await
.and_then(|addrs| {
addrs
.into_iter()
.find_map(|addr| peer_id_from_multiaddr(&addr))
}),
};

let peer_id = match peer_id {
None => {
Expand Down
13 changes: 11 additions & 2 deletions node/network/protocol/src/request_response/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,23 @@ impl Requests {
}
}

/// Potential recipients of an outgoing request.
#[derive(Debug)]
pub enum Recipient {
/// Recipient is a regular peer and we know its peer id.
Peer(PeerId),
/// Recipient is a validator, we address it via this `AuthorityDiscoveryId`.
Authority(AuthorityDiscoveryId),
}

/// A request to be sent to the network bridge, including a sender for sending responses/failures.
///
/// The network implementation will make use of that sender for informing the requesting subsystem
/// about responses/errors.
#[derive(Debug)]
pub struct OutgoingRequest<Req> {
/// Intendent recipient of this request.
pub peer: AuthorityDiscoveryId,
pub peer: Recipient,
/// The actual request to send over the wire.
pub payload: Req,
/// Sender which is used by networking to get us back a response.
Expand Down Expand Up @@ -100,7 +109,7 @@ where
/// It will contain a sender that is used by the networking for sending back responses. The
/// connected receiver is returned as the second element in the returned tuple.
pub fn new(
peer: AuthorityDiscoveryId,
peer: Recipient,
payload: Req,
) -> (
Self,
Expand Down