mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-28 15:37:56 +00:00
*: Update to libp2p v0.33.0 (#7759)
* *: Update to libp2p v0.33.0 * client/network: Consistently track request arrival time With https://github.com/libp2p/rust-libp2p/pull/1886/ one is guaranteed to receive either a `ResponseSent` or a `InboundFailure` event for each received inbound request via `RequestResponseEvent::Message`. Given this guarantee there is no need to track arrival times in a best-effort manner and thus there is no need to use a LRU cache for arrival times. * client/offchain: Adjust to PeerId API changes
This commit is contained in:
@@ -23,7 +23,7 @@ derive_more = "0.99.2"
|
||||
either = "1.5.3"
|
||||
futures = "0.3.4"
|
||||
futures-timer = "3.0.1"
|
||||
libp2p = { version = "0.32.2", default-features = false, features = ["kad"] }
|
||||
libp2p = { version = "0.33.0", default-features = false, features = ["kad"] }
|
||||
log = "0.4.8"
|
||||
prometheus-endpoint = { package = "substrate-prometheus-endpoint", path = "../../utils/prometheus", version = "0.8.0"}
|
||||
prost = "0.6.1"
|
||||
|
||||
@@ -19,7 +19,7 @@ regex = "1.4.2"
|
||||
tokio = { version = "0.2.21", features = [ "signal", "rt-core", "rt-threaded", "blocking" ] }
|
||||
futures = "0.3.4"
|
||||
fdlimit = "0.2.1"
|
||||
libp2p = "0.32.2"
|
||||
libp2p = "0.33.0"
|
||||
parity-scale-codec = "1.3.0"
|
||||
hex = "0.4.2"
|
||||
rand = "0.7.3"
|
||||
|
||||
@@ -17,7 +17,7 @@ targets = ["x86_64-unknown-linux-gnu"]
|
||||
[dependencies]
|
||||
futures = "0.3.4"
|
||||
futures-timer = "3.0.1"
|
||||
libp2p = { version = "0.32.2", default-features = false }
|
||||
libp2p = { version = "0.33.0", default-features = false }
|
||||
log = "0.4.8"
|
||||
lru = "0.6.1"
|
||||
sc-network = { version = "0.8.0", path = "../network" }
|
||||
|
||||
@@ -36,7 +36,6 @@ ip_network = "0.3.4"
|
||||
linked-hash-map = "0.5.2"
|
||||
linked_hash_set = "0.1.3"
|
||||
log = "0.4.8"
|
||||
lru = "0.6.1"
|
||||
nohash-hasher = "0.2.0"
|
||||
parking_lot = "0.11.1"
|
||||
pin-project = "0.4.6"
|
||||
@@ -64,13 +63,13 @@ wasm-timer = "0.2"
|
||||
zeroize = "1.2.0"
|
||||
|
||||
[dependencies.libp2p]
|
||||
version = "0.32.2"
|
||||
version = "0.33.0"
|
||||
default-features = false
|
||||
features = ["identify", "kad", "mdns", "mplex", "noise", "ping", "request-response", "tcp-async-std", "websocket", "yamux"]
|
||||
|
||||
[dev-dependencies]
|
||||
assert_matches = "1.3"
|
||||
libp2p = { version = "0.32.2", default-features = false }
|
||||
libp2p = { version = "0.33.0", default-features = false }
|
||||
quickcheck = "0.9.0"
|
||||
rand = "0.7.2"
|
||||
sp-keyring = { version = "2.0.0", path = "../../primitives/keyring" }
|
||||
|
||||
@@ -90,7 +90,7 @@ pub enum BehaviourOut<B: BlockT> {
|
||||
protocol: Cow<'static, str>,
|
||||
/// If `Ok`, contains the time elapsed between when we received the request and when we
|
||||
/// sent back the response. If `Err`, the error that happened.
|
||||
result: Result<Option<Duration>, ResponseFailure>,
|
||||
result: Result<Duration, ResponseFailure>,
|
||||
},
|
||||
|
||||
/// A request initiated using [`Behaviour::send_request`] has succeeded or failed.
|
||||
@@ -419,7 +419,7 @@ impl<B: BlockT, H: ExHashT> NetworkBehaviourEventProcess<block_requests::Event<B
|
||||
self.events.push_back(BehaviourOut::InboundRequest {
|
||||
peer,
|
||||
protocol: self.block_requests.protocol_name().to_owned().into(),
|
||||
result: Ok(Some(total_handling_time)),
|
||||
result: Ok(total_handling_time),
|
||||
});
|
||||
},
|
||||
block_requests::Event::Response { peer, response, request_duration } => {
|
||||
|
||||
@@ -50,7 +50,6 @@ use libp2p::{
|
||||
PollParameters, ProtocolsHandler,
|
||||
},
|
||||
};
|
||||
use lru::LruCache;
|
||||
use std::{
|
||||
borrow::Cow, collections::{hash_map::Entry, HashMap}, convert::TryFrom as _, io, iter,
|
||||
pin::Pin, task::{Context, Poll}, time::{Duration, Instant},
|
||||
@@ -129,12 +128,11 @@ pub enum Event {
|
||||
peer: PeerId,
|
||||
/// Name of the protocol in question.
|
||||
protocol: Cow<'static, str>,
|
||||
/// If `Ok`, contains the time elapsed between when we received the request and when we
|
||||
/// sent back the response. If `Err`, the error that happened.
|
||||
/// Whether handling the request was successful or unsuccessful.
|
||||
///
|
||||
/// Note: Given that response time is tracked on a best-effort basis only, `Ok(time)` can be
|
||||
/// `None`.
|
||||
result: Result<Option<Duration>, ResponseFailure>,
|
||||
/// When successful contains the time elapsed between when we received the request and when
|
||||
/// we sent back the response. When unsuccessful contains the failure reason.
|
||||
result: Result<Duration, ResponseFailure>,
|
||||
},
|
||||
|
||||
/// A request initiated using [`RequestResponsesBehaviour::send_request`] has succeeded or
|
||||
@@ -164,7 +162,7 @@ pub struct RequestResponsesBehaviour {
|
||||
>,
|
||||
|
||||
/// Whenever an incoming request arrives, the arrival [`Instant`] is recorded here.
|
||||
pending_responses_arrival_time: LruCache<RequestId, Instant>,
|
||||
pending_responses_arrival_time: HashMap<RequestId, Instant>,
|
||||
}
|
||||
|
||||
/// Generated by the response builder and waiting to be processed.
|
||||
@@ -206,7 +204,7 @@ impl RequestResponsesBehaviour {
|
||||
Ok(Self {
|
||||
protocols,
|
||||
pending_responses: Default::default(),
|
||||
pending_responses_arrival_time: LruCache::new(1_000),
|
||||
pending_responses_arrival_time: Default::default(),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -367,9 +365,8 @@ impl NetworkBehaviour for RequestResponsesBehaviour {
|
||||
|
||||
if let Some((protocol, _)) = self.protocols.get_mut(&*protocol_name) {
|
||||
if let Err(_) = protocol.send_response(inner_channel, Ok(response)) {
|
||||
// Note: In case this happened due to a timeout, the corresponding
|
||||
// `RequestResponse` behaviour will emit an `InboundFailure::Timeout` event.
|
||||
self.pending_responses_arrival_time.pop(&request_id);
|
||||
// Note: Failure is handled further below when receiving `InboundFailure`
|
||||
// event from `RequestResponse` behaviour.
|
||||
log::debug!(
|
||||
target: "sub-libp2p",
|
||||
"Failed to send response for {:?} on protocol {:?} due to a \
|
||||
@@ -425,7 +422,7 @@ impl NetworkBehaviour for RequestResponsesBehaviour {
|
||||
peer,
|
||||
message: RequestResponseMessage::Request { request_id, request, channel, .. },
|
||||
} => {
|
||||
self.pending_responses_arrival_time.put(
|
||||
self.pending_responses_arrival_time.insert(
|
||||
request_id.clone(),
|
||||
Instant::now(),
|
||||
);
|
||||
@@ -495,7 +492,7 @@ impl NetworkBehaviour for RequestResponsesBehaviour {
|
||||
// An inbound request failed, either while reading the request or due to failing
|
||||
// to send a response.
|
||||
RequestResponseEvent::InboundFailure { request_id, peer, error, .. } => {
|
||||
self.pending_responses_arrival_time.pop(&request_id);
|
||||
self.pending_responses_arrival_time.remove(&request_id);
|
||||
let out = Event::InboundRequest {
|
||||
peer,
|
||||
protocol: protocol.clone(),
|
||||
@@ -504,14 +501,9 @@ impl NetworkBehaviour for RequestResponsesBehaviour {
|
||||
return Poll::Ready(NetworkBehaviourAction::GenerateEvent(out));
|
||||
}
|
||||
RequestResponseEvent::ResponseSent { request_id, peer } => {
|
||||
let arrival_time = self.pending_responses_arrival_time.pop(&request_id)
|
||||
.map(|t| t.elapsed());
|
||||
if arrival_time.is_none() {
|
||||
log::debug!(
|
||||
"Expected to find arrival time for sent response. Is the LRU \
|
||||
cache size set too small?",
|
||||
);
|
||||
}
|
||||
let arrival_time = self.pending_responses_arrival_time.remove(&request_id)
|
||||
.map(|t| t.elapsed())
|
||||
.expect("To find request arrival time for answered request.");
|
||||
|
||||
let out = Event::InboundRequest {
|
||||
peer,
|
||||
|
||||
@@ -1373,14 +1373,11 @@ impl<B: BlockT + 'static, H: ExHashT> Future for NetworkWorker<B, H> {
|
||||
Poll::Ready(SwarmEvent::Behaviour(BehaviourOut::InboundRequest { protocol, result, .. })) => {
|
||||
if let Some(metrics) = this.metrics.as_ref() {
|
||||
match result {
|
||||
Ok(Some(serve_time)) => {
|
||||
Ok(serve_time) => {
|
||||
metrics.requests_in_success_total
|
||||
.with_label_values(&[&protocol])
|
||||
.observe(serve_time.as_secs_f64());
|
||||
}
|
||||
// Response time tracking is happening on a best-effort basis. Ignore
|
||||
// the event in case response time could not be provided.
|
||||
Ok(None) => {},
|
||||
Err(err) => {
|
||||
let reason = match err {
|
||||
ResponseFailure::Network(InboundFailure::Timeout) => "timeout",
|
||||
@@ -1388,6 +1385,8 @@ impl<B: BlockT + 'static, H: ExHashT> Future for NetworkWorker<B, H> {
|
||||
"unsupported",
|
||||
ResponseFailure::Network(InboundFailure::ResponseOmission) =>
|
||||
"busy-omitted",
|
||||
ResponseFailure::Network(InboundFailure::ConnectionClosed) =>
|
||||
"connection-closed",
|
||||
};
|
||||
|
||||
metrics.requests_in_failure_total
|
||||
|
||||
@@ -19,7 +19,7 @@ parking_lot = "0.10.0"
|
||||
futures = "0.3.4"
|
||||
futures-timer = "3.0.1"
|
||||
rand = "0.7.2"
|
||||
libp2p = { version = "0.32.2", default-features = false }
|
||||
libp2p = { version = "0.33.0", default-features = false }
|
||||
sp-consensus = { version = "0.8.0", path = "../../../primitives/consensus/common" }
|
||||
sc-consensus = { version = "0.8.0", path = "../../consensus/common" }
|
||||
sc-client-api = { version = "2.0.0", path = "../../api" }
|
||||
|
||||
@@ -187,9 +187,9 @@ impl<Storage: OffchainStorage> OffchainExt for Api<Storage> {
|
||||
|
||||
fn set_authorized_nodes(&mut self, nodes: Vec<OpaquePeerId>, authorized_only: bool) {
|
||||
let peer_ids: HashSet<PeerId> = nodes.into_iter()
|
||||
.filter_map(|node| PeerId::from_bytes(node.0).ok())
|
||||
.filter_map(|node| PeerId::from_bytes(&node.0).ok())
|
||||
.collect();
|
||||
|
||||
|
||||
self.network_provider.set_authorized_peers(peer_ids);
|
||||
self.network_provider.set_authorized_only(authorized_only);
|
||||
}
|
||||
@@ -213,7 +213,7 @@ impl NetworkState {
|
||||
|
||||
impl From<NetworkState> for OpaqueNetworkState {
|
||||
fn from(state: NetworkState) -> OpaqueNetworkState {
|
||||
let enc = Encode::encode(&state.peer_id.into_bytes());
|
||||
let enc = Encode::encode(&state.peer_id.to_bytes());
|
||||
let peer_id = OpaquePeerId::new(enc);
|
||||
|
||||
let external_addresses: Vec<OpaqueMultiaddr> = state
|
||||
@@ -239,7 +239,7 @@ impl TryFrom<OpaqueNetworkState> for NetworkState {
|
||||
let inner_vec = state.peer_id.0;
|
||||
|
||||
let bytes: Vec<u8> = Decode::decode(&mut &inner_vec[..]).map_err(|_| ())?;
|
||||
let peer_id = PeerId::from_bytes(bytes).map_err(|_| ())?;
|
||||
let peer_id = PeerId::from_bytes(&bytes).map_err(|_| ())?;
|
||||
|
||||
let external_addresses: Result<Vec<Multiaddr>, Self::Error> = state.external_addresses
|
||||
.iter()
|
||||
|
||||
@@ -16,7 +16,7 @@ targets = ["x86_64-unknown-linux-gnu"]
|
||||
|
||||
[dependencies]
|
||||
futures = "0.3.4"
|
||||
libp2p = { version = "0.32.2", default-features = false }
|
||||
libp2p = { version = "0.33.0", default-features = false }
|
||||
sp-utils = { version = "2.0.0", path = "../../primitives/utils"}
|
||||
log = "0.4.8"
|
||||
serde_json = "1.0.41"
|
||||
|
||||
@@ -19,7 +19,7 @@ parking_lot = "0.10.0"
|
||||
futures = "0.3.4"
|
||||
futures-timer = "3.0.1"
|
||||
wasm-timer = "0.2.5"
|
||||
libp2p = { version = "0.32.2", default-features = false, features = ["dns", "tcp-async-std", "wasm-ext", "websocket"] }
|
||||
libp2p = { version = "0.33.0", default-features = false, features = ["dns", "tcp-async-std", "wasm-ext", "websocket"] }
|
||||
log = "0.4.8"
|
||||
pin-project = "0.4.6"
|
||||
rand = "0.7.2"
|
||||
|
||||
Reference in New Issue
Block a user