mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 08:11:04 +00:00
Network sync refactoring (part 6) (#11940)
* Extract `NetworkKVProvider` trait in `sc-authority-discovery` and remove unnecessary dependency * Extract `NetworkSyncForkRequest` trait in `sc-finality-grandpa` * Relax requirements on `SyncOracle` trait, remove extra native methods from `NetworkService` that are already provided by trait impls * Move `NetworkSigner` trait from `sc-authority-discovery` into `sc-network-common` and de-duplicate methods on `NetworkService` * Move `NetworkKVProvider` trait from `sc-authority-discovery` into `sc-network-common` and de-duplicate methods on `NetworkService` * Minimize `sc-authority-discovery` dependency on `sc-network` * Move `NetworkSyncForkRequest` trait from `sc-finality-grandpa` to `sc-network-common` and de-duplicate methods in `NetworkService` * Extract `NetworkStatusProvider` trait and de-duplicate methods on `NetworkService` * Extract `NetworkPeers` trait and de-duplicate methods on `NetworkService` * Extract `NetworkEventStream` trait and de-duplicate methods on `NetworkService` * Move more methods from `NetworkService` into `NetworkPeers` trait * Move `NetworkStateInfo` trait into `sc-network-common` * Extract `NetworkNotification` trait and de-duplicate methods on `NetworkService` * Extract `NetworkRequest` trait and de-duplicate methods on `NetworkService` * Remove `NetworkService::local_peer_id()`, it is already provided by `NetworkStateInfo` impl * Extract `NetworkTransaction` trait and de-duplicate methods on `NetworkService` * Extract `NetworkBlock` trait and de-duplicate methods on `NetworkService` * Remove dependencies on `NetworkService` from most of the methods of `sc-service` * Address simple review comments
This commit is contained in:
@@ -50,7 +50,9 @@ use libp2p::{
|
||||
NetworkBehaviourAction, PollParameters,
|
||||
},
|
||||
};
|
||||
use sc_network_common::request_responses::{IncomingRequest, OutgoingResponse, ProtocolConfig};
|
||||
use sc_network_common::request_responses::{
|
||||
IfDisconnected, IncomingRequest, OutgoingResponse, ProtocolConfig, RequestFailure,
|
||||
};
|
||||
use std::{
|
||||
borrow::Cow,
|
||||
collections::{hash_map::Entry, HashMap},
|
||||
@@ -118,26 +120,6 @@ impl From<(Cow<'static, str>, RequestId)> for ProtocolRequestId {
|
||||
}
|
||||
}
|
||||
|
||||
/// When sending a request, what to do on a disconnected recipient.
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
||||
pub enum IfDisconnected {
|
||||
/// Try to connect to the peer.
|
||||
TryConnect,
|
||||
/// Just fail if the destination is not yet connected.
|
||||
ImmediateError,
|
||||
}
|
||||
|
||||
/// Convenience functions for `IfDisconnected`.
|
||||
impl IfDisconnected {
|
||||
/// Shall we connect to a disconnected peer?
|
||||
pub fn should_connect(self) -> bool {
|
||||
match self {
|
||||
Self::TryConnect => true,
|
||||
Self::ImmediateError => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Implementation of `NetworkBehaviour` that provides support for request-response protocols.
|
||||
pub struct RequestResponsesBehaviour {
|
||||
/// The multiple sub-protocols, by name.
|
||||
@@ -787,23 +769,6 @@ pub enum RegisterError {
|
||||
DuplicateProtocol(Cow<'static, str>),
|
||||
}
|
||||
|
||||
/// Error in a request.
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
#[allow(missing_docs)]
|
||||
pub enum RequestFailure {
|
||||
#[error("We are not currently connected to the requested peer.")]
|
||||
NotConnected,
|
||||
#[error("Given protocol hasn't been registered.")]
|
||||
UnknownProtocol,
|
||||
#[error("Remote has closed the substream before answering, thereby signaling that it considers the request as valid, but refused to answer it.")]
|
||||
Refused,
|
||||
#[error("The remote replied, but the local node is no longer interested in the response.")]
|
||||
Obsolete,
|
||||
/// Problem on the network.
|
||||
#[error("Problem on the network: {0}")]
|
||||
Network(OutboundFailure),
|
||||
}
|
||||
|
||||
/// Error when processing a request sent by a remote.
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum ResponseFailure {
|
||||
|
||||
Reference in New Issue
Block a user