From 51f9a34a6b1a886120c0100c0fd9892de2fa02e4 Mon Sep 17 00:00:00 2001 From: ndkazu Date: Mon, 8 Jul 2024 22:26:37 +0900 Subject: [PATCH 01/37] Removed libp2p dependancy from sc_network_sync --- substrate/client/network/sync/src/engine.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/client/network/sync/src/engine.rs b/substrate/client/network/sync/src/engine.rs index bb6e7a98a810..fe95e5d12b53 100644 --- a/substrate/client/network/sync/src/engine.rs +++ b/substrate/client/network/sync/src/engine.rs @@ -47,7 +47,7 @@ use futures::{ future::{BoxFuture, Fuse}, FutureExt, StreamExt, }; -use libp2p::request_response::OutboundFailure; +use sc_network::request_responses::OutboundFailure; use log::{debug, error, trace, warn}; use prometheus_endpoint::{ register, Counter, Gauge, MetricSource, Opts, PrometheusError, Registry, SourcedGauge, U64, From b4e3f5aad03c042bb9954746361bbfbabb6f047a Mon Sep 17 00:00:00 2001 From: ndkazu Date: Tue, 9 Jul 2024 10:56:17 +0900 Subject: [PATCH 02/37] Preparing an alternative to libp2p dependant OutBoundFailure --- Cargo.lock | 1 - .../client/network/src/request_responses.rs | 44 ++++++++++++++++++- substrate/client/network/sync/Cargo.toml | 1 - substrate/client/network/sync/src/engine.rs | 3 +- 4 files changed, 43 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 046f9a15bbdd..e582bd68093c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17926,7 +17926,6 @@ dependencies = [ "fork-tree", "futures", "futures-timer", - "libp2p", "log", "mockall 0.11.4", "parity-scale-codec", diff --git a/substrate/client/network/src/request_responses.rs b/substrate/client/network/src/request_responses.rs index 3671d76ea630..4dec4d874326 100644 --- a/substrate/client/network/src/request_responses.rs +++ b/substrate/client/network/src/request_responses.rs @@ -51,7 +51,7 @@ use libp2p::{ ConnectionDenied, ConnectionId, NetworkBehaviour, PollParameters, THandler, THandlerInEvent, THandlerOutEvent, ToSwarm, }, - PeerId, + PeerId, }; use std::{ @@ -62,10 +62,44 @@ use std::{ sync::Arc, task::{Context, Poll}, time::{Duration, Instant}, + fmt::{Display,Formatter}, + fmt, }; pub use libp2p::request_response::{Config, InboundFailure, OutboundFailure, RequestId}; +/// Adding a custom OutBoundFailure, not depending on libp2p +#[derive(Debug, thiserror::Error)] +#[allow(missing_docs)] +pub enum CustomOutboundFailure{ + DialFailure, + Timeout, + ConnectionClosed, + UnsupportedProtocols, +} + +/// Implement Display trait +impl Display for CustomOutboundFailure{ + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result{ + match self { + CustomOutboundFailure::DialFailure => write!(f, "DialFailure"), + CustomOutboundFailure::Timeout => write!(f, "Timeout"), + CustomOutboundFailure::ConnectionClosed => write!(f, "ConnectionClosed"), + CustomOutboundFailure::UnsupportedProtocols => write!(f, "UnsupportedProtocols"), + } + } +} + +/// In preparation for a CustomOutBoundFailure Event +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] +pub struct OutboundRequestId(u64); + +impl fmt::Display for OutboundRequestId { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{}", self.0) + } +} + /// Error in a request. #[derive(Debug, thiserror::Error)] #[allow(missing_docs)] @@ -248,6 +282,12 @@ pub enum Event { /// Reputation changes. changes: Vec, }, + + /*CustomOutboundFailure { + peer: PeerId, + request_id: OutboundRequestId, + error: CustomOutboundFailure, + }*/ } /// Combination of a protocol name and a request id. @@ -1734,4 +1774,4 @@ mod tests { ); }); } -} +} \ No newline at end of file diff --git a/substrate/client/network/sync/Cargo.toml b/substrate/client/network/sync/Cargo.toml index 17e3e2119d7e..97cd5bfd8916 100644 --- a/substrate/client/network/sync/Cargo.toml +++ b/substrate/client/network/sync/Cargo.toml @@ -25,7 +25,6 @@ async-trait = { workspace = true } codec = { features = ["derive"], workspace = true, default-features = true } futures = { workspace = true } futures-timer = { workspace = true } -libp2p = { workspace = true } log = { workspace = true, default-features = true } mockall = { workspace = true } prost = { workspace = true } diff --git a/substrate/client/network/sync/src/engine.rs b/substrate/client/network/sync/src/engine.rs index fe95e5d12b53..3cd0440127df 100644 --- a/substrate/client/network/sync/src/engine.rs +++ b/substrate/client/network/sync/src/engine.rs @@ -47,7 +47,6 @@ use futures::{ future::{BoxFuture, Fuse}, FutureExt, StreamExt, }; -use sc_network::request_responses::OutboundFailure; use log::{debug, error, trace, warn}; use prometheus_endpoint::{ register, Counter, Gauge, MetricSource, Opts, PrometheusError, Registry, SourcedGauge, U64, @@ -61,7 +60,7 @@ use sc_consensus::{import_queue::ImportQueueService, IncomingBlock}; use sc_network::{ config::{FullNetworkConfiguration, NotificationHandshake, ProtocolId, SetConfig}, peer_store::PeerStoreProvider, - request_responses::{IfDisconnected, RequestFailure}, + request_responses::{IfDisconnected, RequestFailure, OutboundFailure}, service::{ traits::{Direction, NotificationConfig, NotificationEvent, ValidationResult}, NotificationMetrics, From 6a1fcf1259e7e2aef8876ac91acf3684fa36c743 Mon Sep 17 00:00:00 2001 From: ndkazu Date: Thu, 11 Jul 2024 08:38:37 +0900 Subject: [PATCH 03/37] Agnostic sc-network-sync --- substrate/client/network/src/request_responses.rs | 4 +++- substrate/client/network/src/service.rs | 11 +++++++++++ substrate/client/network/sync/src/engine.rs | 13 ++++++++----- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/substrate/client/network/src/request_responses.rs b/substrate/client/network/src/request_responses.rs index 4dec4d874326..334b9971769b 100644 --- a/substrate/client/network/src/request_responses.rs +++ b/substrate/client/network/src/request_responses.rs @@ -103,7 +103,7 @@ impl fmt::Display for OutboundRequestId { /// Error in a request. #[derive(Debug, thiserror::Error)] #[allow(missing_docs)] -pub enum RequestFailure { +pub enum RequestFailure{ #[error("We are not currently connected to the requested peer.")] NotConnected, #[error("Given protocol hasn't been registered.")] @@ -114,6 +114,8 @@ pub enum RequestFailure { Obsolete, #[error("Problem on the network: {0}")] Network(OutboundFailure), + #[error("Problem on the network: {0}")] + Network2(CustomOutboundFailure), } /// Configuration for a single request-response protocol. diff --git a/substrate/client/network/src/service.rs b/substrate/client/network/src/service.rs index 3a685787c48e..1f8f6e1ca10e 100644 --- a/substrate/client/network/src/service.rs +++ b/substrate/client/network/src/service.rs @@ -90,6 +90,8 @@ use sc_utils::mpsc::{tracing_unbounded, TracingUnboundedReceiver, TracingUnbound use sp_runtime::traits::Block as BlockT; pub use behaviour::{InboundFailure, OutboundFailure, ResponseFailure}; +// Import our custom type +pub use crate::request_responses::CustomOutboundFailure; pub use libp2p::identity::{DecodingError, Keypair, PublicKey}; pub use metrics::NotificationMetrics; pub use protocol::NotificationsSink; @@ -1530,6 +1532,7 @@ where .with_label_values(&[&protocol]) .observe(duration.as_secs_f64()); }, + // we also could remove Network cases here like we did in engine Err(err) => { let reason = match err { RequestFailure::NotConnected => "not-connected", @@ -1543,6 +1546,14 @@ where "connection-closed", RequestFailure::Network(OutboundFailure::UnsupportedProtocols) => "unsupported", + RequestFailure::Network2(CustomOutboundFailure::DialFailure) => + "dial-failure", + RequestFailure::Network2(CustomOutboundFailure::Timeout) => "timeout", + RequestFailure::Network2(CustomOutboundFailure::ConnectionClosed) => + "connection-closed", + RequestFailure::Network2(CustomOutboundFailure::UnsupportedProtocols) => + "unsupported", + }; metrics diff --git a/substrate/client/network/sync/src/engine.rs b/substrate/client/network/sync/src/engine.rs index 3cd0440127df..c96bfa70a7d4 100644 --- a/substrate/client/network/sync/src/engine.rs +++ b/substrate/client/network/sync/src/engine.rs @@ -60,7 +60,7 @@ use sc_consensus::{import_queue::ImportQueueService, IncomingBlock}; use sc_network::{ config::{FullNetworkConfiguration, NotificationHandshake, ProtocolId, SetConfig}, peer_store::PeerStoreProvider, - request_responses::{IfDisconnected, RequestFailure, OutboundFailure}, + request_responses::{IfDisconnected, RequestFailure, CustomOutboundFailure}, service::{ traits::{Direction, NotificationConfig, NotificationEvent, ValidationResult}, NotificationMetrics, @@ -1271,18 +1271,19 @@ where Ok(Err(e)) => { debug!(target: LOG_TARGET, "Request to peer {peer_id:?} failed: {e:?}."); + // Using Our custom type Network2(CustomOutboundFailure) match e { - RequestFailure::Network(OutboundFailure::Timeout) => { + RequestFailure::Network2(CustomOutboundFailure::Timeout) => { self.network_service.report_peer(peer_id, rep::TIMEOUT); self.network_service .disconnect_peer(peer_id, self.block_announce_protocol_name.clone()); }, - RequestFailure::Network(OutboundFailure::UnsupportedProtocols) => { + RequestFailure::Network2(CustomOutboundFailure::UnsupportedProtocols) => { self.network_service.report_peer(peer_id, rep::BAD_PROTOCOL); self.network_service .disconnect_peer(peer_id, self.block_announce_protocol_name.clone()); }, - RequestFailure::Network(OutboundFailure::DialFailure) => { + RequestFailure::Network2(CustomOutboundFailure::DialFailure) => { self.network_service .disconnect_peer(peer_id, self.block_announce_protocol_name.clone()); }, @@ -1291,7 +1292,7 @@ where self.network_service .disconnect_peer(peer_id, self.block_announce_protocol_name.clone()); }, - RequestFailure::Network(OutboundFailure::ConnectionClosed) | + RequestFailure::Network2(CustomOutboundFailure::ConnectionClosed) | RequestFailure::NotConnected => { self.network_service .disconnect_peer(peer_id, self.block_announce_protocol_name.clone()); @@ -1306,6 +1307,8 @@ where response receiver.", ); }, + //If OutboundFailure is used, + RequestFailure::Network(_) => {debug_assert!(false, "Don't use deprecated Network");}, } }, Err(oneshot::Canceled) => { From b33728b56689e5428c3b933c0e46b393130bbb7a Mon Sep 17 00:00:00 2001 From: Kazunobu Ndong <33208377+ndkazu@users.noreply.github.com> Date: Tue, 16 Jul 2024 19:29:51 +0900 Subject: [PATCH 04/37] Update substrate/client/network/src/request_responses.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bastian Köcher --- substrate/client/network/src/request_responses.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/client/network/src/request_responses.rs b/substrate/client/network/src/request_responses.rs index 334b9971769b..dd9865bc8c9a 100644 --- a/substrate/client/network/src/request_responses.rs +++ b/substrate/client/network/src/request_responses.rs @@ -51,7 +51,7 @@ use libp2p::{ ConnectionDenied, ConnectionId, NetworkBehaviour, PollParameters, THandler, THandlerInEvent, THandlerOutEvent, ToSwarm, }, - PeerId, + PeerId, }; use std::{ From d8fbc300221985a0f2f9bfa99ee47d84a14de373 Mon Sep 17 00:00:00 2001 From: ndkazu Date: Tue, 16 Jul 2024 19:44:50 +0900 Subject: [PATCH 05/37] Remove crate libp2p from sc-authority-discovery --- substrate/client/authority-discovery/Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/substrate/client/authority-discovery/Cargo.toml b/substrate/client/authority-discovery/Cargo.toml index 309c9c542a0b..168de218d3b5 100644 --- a/substrate/client/authority-discovery/Cargo.toml +++ b/substrate/client/authority-discovery/Cargo.toml @@ -24,7 +24,6 @@ codec = { workspace = true } futures = { workspace = true } futures-timer = { workspace = true } ip_network = { workspace = true } -libp2p = { features = ["ed25519", "kad"], workspace = true } multihash = { workspace = true } linked_hash_set = { workspace = true } log = { workspace = true, default-features = true } From 2f09ebdfd0a51260cc394aec07bbb5618248f70d Mon Sep 17 00:00:00 2001 From: ndkazu Date: Wed, 17 Jul 2024 21:01:00 +0900 Subject: [PATCH 06/37] Removed event --- substrate/client/network/src/request_responses.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/substrate/client/network/src/request_responses.rs b/substrate/client/network/src/request_responses.rs index dd9865bc8c9a..6ab08e78d1ea 100644 --- a/substrate/client/network/src/request_responses.rs +++ b/substrate/client/network/src/request_responses.rs @@ -285,11 +285,6 @@ pub enum Event { changes: Vec, }, - /*CustomOutboundFailure { - peer: PeerId, - request_id: OutboundRequestId, - error: CustomOutboundFailure, - }*/ } /// Combination of a protocol name and a request id. From d0e208424e6b3e771cd24abac28e7c8a7cd72ce9 Mon Sep 17 00:00:00 2001 From: ndkazu Date: Wed, 17 Jul 2024 22:05:55 +0900 Subject: [PATCH 07/37] Add a custom InboundFailure --- .../client/network/src/request_responses.rs | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/substrate/client/network/src/request_responses.rs b/substrate/client/network/src/request_responses.rs index 6ab08e78d1ea..356a3efd758a 100644 --- a/substrate/client/network/src/request_responses.rs +++ b/substrate/client/network/src/request_responses.rs @@ -68,9 +68,10 @@ use std::{ pub use libp2p::request_response::{Config, InboundFailure, OutboundFailure, RequestId}; -/// Adding a custom OutBoundFailure, not depending on libp2p +/// Adding a custom OutboundFailure, not depending on libp2p #[derive(Debug, thiserror::Error)] #[allow(missing_docs)] +#[error("dial-failure")] pub enum CustomOutboundFailure{ DialFailure, Timeout, @@ -78,18 +79,18 @@ pub enum CustomOutboundFailure{ UnsupportedProtocols, } -/// Implement Display trait -impl Display for CustomOutboundFailure{ - fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result{ - match self { - CustomOutboundFailure::DialFailure => write!(f, "DialFailure"), - CustomOutboundFailure::Timeout => write!(f, "Timeout"), - CustomOutboundFailure::ConnectionClosed => write!(f, "ConnectionClosed"), - CustomOutboundFailure::UnsupportedProtocols => write!(f, "UnsupportedProtocols"), - } - } +/// Adding a custom InboundFailure, not depending on libp2p +#[derive(Debug, thiserror::Error)] +#[allow(missing_docs)] +#[error("dial-failure")] +pub enum CustomInboundFailure{ + Timeout, + ConnectionClosed, + UnsupportedProtocols, + ResponseOmission, } + /// In preparation for a CustomOutBoundFailure Event #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] pub struct OutboundRequestId(u64); @@ -866,7 +867,7 @@ impl NetworkBehaviour for RequestResponsesBehaviour { } if response_tx - .send(Err(RequestFailure::Network(error.clone()))) + .send(Err(RequestFailure::Network2(CustomOutboundFailure::Timeout))) .is_err() { log::debug!( @@ -893,7 +894,7 @@ impl NetworkBehaviour for RequestResponsesBehaviour { peer, protocol: protocol.clone(), duration: started.elapsed(), - result: Err(RequestFailure::Network(error)), + result: Err(RequestFailure::Network2(CustomOutboundFailure::ConnectionClosed)), }; return Poll::Ready(ToSwarm::GenerateEvent(out)) @@ -1367,7 +1368,7 @@ mod tests { } match response_receiver.unwrap().await.unwrap().unwrap_err() { - RequestFailure::Network(OutboundFailure::ConnectionClosed) => {}, + RequestFailure::Network2(CustomOutboundFailure::ConnectionClosed) => {}, _ => panic!(), } }); @@ -1738,7 +1739,7 @@ mod tests { SwarmEvent::Behaviour(Event::RequestFinished { result, .. }) => { assert_matches!( result.unwrap_err(), - RequestFailure::Network(OutboundFailure::UnsupportedProtocols) + RequestFailure::Network2(CustomOutboundFailure::UnsupportedProtocols) ); break }, From 3f7e5ad0aafcaeadcebe97e9e5b31b20b1abb880 Mon Sep 17 00:00:00 2001 From: ndkazu Date: Thu, 18 Jul 2024 16:58:07 +0900 Subject: [PATCH 08/37] Removed the variant Network --- Cargo.lock | 1 - .../src/task/strategy/full.rs | 4 ++-- .../src/task/strategy/mod.rs | 3 ++- polkadot/node/network/bridge/src/network.rs | 3 ++- .../protocol/src/request_response/outgoing.rs | 5 +++-- .../client/network/src/request_responses.rs | 6 ++---- substrate/client/network/src/service.rs | 20 +++++++------------ substrate/client/network/sync/src/engine.rs | 2 +- 8 files changed, 19 insertions(+), 25 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b7559572dc1d..2da83da84a85 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17039,7 +17039,6 @@ dependencies = [ "futures", "futures-timer", "ip_network", - "libp2p", "linked_hash_set", "log", "multihash 0.19.1", diff --git a/polkadot/node/network/availability-recovery/src/task/strategy/full.rs b/polkadot/node/network/availability-recovery/src/task/strategy/full.rs index 1d7fbe8ea3c8..ce0e8ad86af3 100644 --- a/polkadot/node/network/availability-recovery/src/task/strategy/full.rs +++ b/polkadot/node/network/availability-recovery/src/task/strategy/full.rs @@ -26,7 +26,7 @@ use polkadot_node_primitives::AvailableData; use polkadot_node_subsystem::{messages::NetworkBridgeTxMessage, overseer, RecoveryError}; use polkadot_primitives::ValidatorIndex; use sc_network::{IfDisconnected, OutboundFailure, RequestFailure}; - +use sc_network::service::CustomOutboundFailure; use futures::{channel::oneshot, SinkExt}; use rand::seq::SliceRandom; @@ -153,7 +153,7 @@ impl RecoveryStrategy RequestError::InvalidResponse(_) => common_params.metrics.on_full_request_invalid(), RequestError::NetworkError(req_failure) => { - if let RequestFailure::Network(OutboundFailure::Timeout) = req_failure { + if let RequestFailure::Network2(CustomOutboundFailure::Timeout) = req_failure { common_params.metrics.on_full_request_timeout(); } else { common_params.metrics.on_full_request_error(); diff --git a/polkadot/node/network/availability-recovery/src/task/strategy/mod.rs b/polkadot/node/network/availability-recovery/src/task/strategy/mod.rs index 1403277c8a95..73e2f441c43d 100644 --- a/polkadot/node/network/availability-recovery/src/task/strategy/mod.rs +++ b/polkadot/node/network/availability-recovery/src/task/strategy/mod.rs @@ -30,6 +30,7 @@ use crate::{ }; use codec::Decode; +use sc_network::service::CustomOutboundFailure; use futures::{channel::oneshot, SinkExt}; use polkadot_erasure_coding::branch_hash; #[cfg(not(test))] @@ -565,7 +566,7 @@ impl State { RequestError::NetworkError(err) => { // No debug logs on general network errors - that became very // spammy occasionally. - if let RequestFailure::Network(OutboundFailure::Timeout) = err { + if let RequestFailure::Network2(CustomOutboundFailure::Timeout) = err { metrics.on_chunk_request_timeout(strategy_type); } else { metrics.on_chunk_request_error(strategy_type); diff --git a/polkadot/node/network/bridge/src/network.rs b/polkadot/node/network/bridge/src/network.rs index b31359f48a56..5aa29fc7d461 100644 --- a/polkadot/node/network/bridge/src/network.rs +++ b/polkadot/node/network/bridge/src/network.rs @@ -23,6 +23,7 @@ use async_trait::async_trait; use parking_lot::Mutex; use codec::Encode; +use sc_network::service::CustomOutboundFailure; use sc_network::{ config::parse_addr, multiaddr::Multiaddr, service::traits::NetworkService, types::ProtocolName, @@ -299,7 +300,7 @@ impl Network for Arc { None => { gum::debug!(target: LOG_TARGET, "Discovering authority failed"); match pending_response - .send(Err(RequestFailure::Network(OutboundFailure::DialFailure))) + .send(Err(RequestFailure::Network2(CustomOutboundFailure::DialFailure))) { Err(_) => { gum::debug!(target: LOG_TARGET, "Sending failed request response failed.") diff --git a/polkadot/node/network/protocol/src/request_response/outgoing.rs b/polkadot/node/network/protocol/src/request_response/outgoing.rs index 27f0f34bf8d4..03b7c046008c 100644 --- a/polkadot/node/network/protocol/src/request_response/outgoing.rs +++ b/polkadot/node/network/protocol/src/request_response/outgoing.rs @@ -23,6 +23,7 @@ use sc_network as network; use sc_network_types::PeerId; use polkadot_primitives::AuthorityDiscoveryId; +use sc_network::service::CustomOutboundFailure; use super::{v1, v2, IsRequest, Protocol}; @@ -96,8 +97,8 @@ impl RequestError { match self { Self::Canceled(_) | Self::NetworkError(network::RequestFailure::Obsolete) | - Self::NetworkError(network::RequestFailure::Network( - network::OutboundFailure::Timeout, + Self::NetworkError(network::RequestFailure::Network2( + CustomOutboundFailure::Timeout, )) => true, _ => false, } diff --git a/substrate/client/network/src/request_responses.rs b/substrate/client/network/src/request_responses.rs index 356a3efd758a..f3f523d56977 100644 --- a/substrate/client/network/src/request_responses.rs +++ b/substrate/client/network/src/request_responses.rs @@ -114,8 +114,6 @@ pub enum RequestFailure{ #[error("The remote replied, but the local node is no longer interested in the response.")] Obsolete, #[error("Problem on the network: {0}")] - Network(OutboundFailure), - #[error("Problem on the network: {0}")] Network2(CustomOutboundFailure), } @@ -911,7 +909,7 @@ impl NetworkBehaviour for RequestResponsesBehaviour { let out = Event::InboundRequest { peer, protocol: protocol.clone(), - result: Err(ResponseFailure::Network(error)), + result: Err(ResponseFailure::Network2(CustomInboundFailure::Timeout)), }; return Poll::Ready(ToSwarm::GenerateEvent(out)) }, @@ -985,7 +983,7 @@ pub enum RegisterError { pub enum ResponseFailure { /// Problem on the network. #[error("Problem on the network: {0}")] - Network(InboundFailure), + Network2(CustomInboundFailure), } /// Implements the libp2p [`Codec`] trait. Defines how streams of bytes are turned diff --git a/substrate/client/network/src/service.rs b/substrate/client/network/src/service.rs index 1f8f6e1ca10e..b4fc72548ff4 100644 --- a/substrate/client/network/src/service.rs +++ b/substrate/client/network/src/service.rs @@ -91,7 +91,7 @@ use sp_runtime::traits::Block as BlockT; pub use behaviour::{InboundFailure, OutboundFailure, ResponseFailure}; // Import our custom type -pub use crate::request_responses::CustomOutboundFailure; +pub use crate::request_responses::{CustomOutboundFailure,CustomInboundFailure}; pub use libp2p::identity::{DecodingError, Keypair, PublicKey}; pub use metrics::NotificationMetrics; pub use protocol::NotificationsSink; @@ -1216,7 +1216,7 @@ where // 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)), + Err(_) => Err(RequestFailure::Network2(CustomOutboundFailure::ConnectionClosed)), } } @@ -1494,17 +1494,17 @@ where }, Err(err) => { let reason = match err { - ResponseFailure::Network(InboundFailure::Timeout) => + ResponseFailure::Network2(CustomInboundFailure::Timeout) => Some("timeout"), - ResponseFailure::Network(InboundFailure::UnsupportedProtocols) => + ResponseFailure::Network2(CustomInboundFailure::UnsupportedProtocols) => // `UnsupportedProtocols` is reported for every single // inbound request whenever a request with an unsupported // protocol is received. This is not reported in order to // avoid confusions. None, - ResponseFailure::Network(InboundFailure::ResponseOmission) => + ResponseFailure::Network2(CustomInboundFailure::ResponseOmission) => Some("busy-omitted"), - ResponseFailure::Network(InboundFailure::ConnectionClosed) => + ResponseFailure::Network2(CustomInboundFailure::ConnectionClosed) => Some("connection-closed"), }; @@ -1539,13 +1539,7 @@ where RequestFailure::UnknownProtocol => "unknown-protocol", RequestFailure::Refused => "refused", RequestFailure::Obsolete => "obsolete", - RequestFailure::Network(OutboundFailure::DialFailure) => - "dial-failure", - RequestFailure::Network(OutboundFailure::Timeout) => "timeout", - RequestFailure::Network(OutboundFailure::ConnectionClosed) => - "connection-closed", - RequestFailure::Network(OutboundFailure::UnsupportedProtocols) => - "unsupported", + RequestFailure::Network2(CustomOutboundFailure::DialFailure) => "dial-failure", RequestFailure::Network2(CustomOutboundFailure::Timeout) => "timeout", diff --git a/substrate/client/network/sync/src/engine.rs b/substrate/client/network/sync/src/engine.rs index c96bfa70a7d4..cd13d976d13d 100644 --- a/substrate/client/network/sync/src/engine.rs +++ b/substrate/client/network/sync/src/engine.rs @@ -1308,7 +1308,7 @@ where ); }, //If OutboundFailure is used, - RequestFailure::Network(_) => {debug_assert!(false, "Don't use deprecated Network");}, + RequestFailure::Network2(_) => {debug_assert!(false, "Don't use deprecated Network");}, } }, Err(oneshot::Canceled) => { From 6dd1bd3b84062f8b5ad454c8153d7ac70833f479 Mon Sep 17 00:00:00 2001 From: ndkazu Date: Sat, 20 Jul 2024 12:13:22 +0900 Subject: [PATCH 09/37] Changed the type of --- .../client/network/src/request_responses.rs | 73 ++++++++++++++++--- 1 file changed, 63 insertions(+), 10 deletions(-) diff --git a/substrate/client/network/src/request_responses.rs b/substrate/client/network/src/request_responses.rs index f3f523d56977..cfb0739fd179 100644 --- a/substrate/client/network/src/request_responses.rs +++ b/substrate/client/network/src/request_responses.rs @@ -95,12 +95,25 @@ pub enum CustomInboundFailure{ #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] pub struct OutboundRequestId(u64); + impl fmt::Display for OutboundRequestId { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.0) } } +/// In preparation for a CustomOutBoundFailure Event +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] +pub struct InboundRequestId(u64); + + +impl fmt::Display for InboundRequestId { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{}", self.0) + } +} + + /// Error in a request. #[derive(Debug, thiserror::Error)] #[allow(missing_docs)] @@ -242,6 +255,46 @@ impl IfDisconnected { } } } +#[derive(Debug)] +pub enum Event0 { + /// An incoming message (request or response). + Message { + /// The peer who sent the message. + peer: PeerId, + /// The incoming message. + message: Message, + }, + /// An outbound request failed. + CustomOutboundFailure { + /// The peer to whom the request was sent. + peer: PeerId, + /// The (local) ID of the failed request. + request_id: OutboundRequestId, + /// The error that occurred. + error: CustomOutboundFailure, + }, + /// An inbound request failed. + CustomInboundFailure { + /// The peer from whom the request was received. + peer: PeerId, + /// The ID of the failed inbound request. + request_id: InboundRequestId, + /// The error that occurred. + error: CustomInboundFailure, + }, + + /// A response to an inbound request has been sent. + /// + /// When this event is received, the response has been flushed on + /// the underlying transport connection. + CustomResponseSent { + /// The peer to whom the response was sent. + peer: PeerId, + /// The ID of the inbound request whose response was sent. + request_id: InboundRequestId, + }, + +} /// Event generated by the [`RequestResponsesBehaviour`]. #[derive(Debug)] @@ -459,10 +512,10 @@ impl RequestResponsesBehaviour { } } -impl NetworkBehaviour for RequestResponsesBehaviour { +impl NetworkBehaviour for RequestResponsesBehaviour { type ConnectionHandler = MultiHandler as NetworkBehaviour>::ConnectionHandler>; - type ToSwarm = Event; + type ToSwarm = Event0; fn handle_pending_inbound_connection( &mut self, @@ -718,7 +771,7 @@ impl NetworkBehaviour for RequestResponsesBehaviour { match ev { // Received a request from a remote. - request_response::Event::Message { + Event0::Message { peer, message: Message::Request { request_id, request, channel, .. }, } => { @@ -780,7 +833,7 @@ impl NetworkBehaviour for RequestResponsesBehaviour { }, // Received a response from a remote to one of our requests. - request_response::Event::Message { + Event0::Message { peer, message: Message::Response { request_id, response }, .. @@ -827,7 +880,7 @@ impl NetworkBehaviour for RequestResponsesBehaviour { }, // One of our requests has failed. - request_response::Event::OutboundFailure { + Event0::CustomOutboundFailure { peer, request_id, error, @@ -844,7 +897,7 @@ impl NetworkBehaviour for RequestResponsesBehaviour { }) => { // Try using the fallback request if the protocol was not // supported. - if let OutboundFailure::UnsupportedProtocols = error { + if let CustomOutboundFailure::UnsupportedProtocols = error { if let Some((fallback_request, fallback_protocol)) = fallback_request { @@ -892,7 +945,7 @@ impl NetworkBehaviour for RequestResponsesBehaviour { peer, protocol: protocol.clone(), duration: started.elapsed(), - result: Err(RequestFailure::Network2(CustomOutboundFailure::ConnectionClosed)), + result: Err(RequestFailure::Network2(error)), }; return Poll::Ready(ToSwarm::GenerateEvent(out)) @@ -900,7 +953,7 @@ impl NetworkBehaviour for RequestResponsesBehaviour { // An inbound request failed, either while reading the request or due to // failing to send a response. - request_response::Event::InboundFailure { + Event0::CustomInboundFailure { request_id, peer, error, .. } => { self.pending_responses_arrival_time @@ -909,13 +962,13 @@ impl NetworkBehaviour for RequestResponsesBehaviour { let out = Event::InboundRequest { peer, protocol: protocol.clone(), - result: Err(ResponseFailure::Network2(CustomInboundFailure::Timeout)), + result: Err(ResponseFailure::Network2(error)), }; return Poll::Ready(ToSwarm::GenerateEvent(out)) }, // A response to an inbound request has been sent. - request_response::Event::ResponseSent { request_id, peer } => { + Event0::CustomResponseSent { request_id, peer } => { let arrival_time = self .pending_responses_arrival_time .remove(&(protocol.clone(), request_id).into()) From 372f9fcbd729a68d08dbade8741a886cb4de1f75 Mon Sep 17 00:00:00 2001 From: ndkazu Date: Wed, 24 Jul 2024 22:16:56 +0900 Subject: [PATCH 10/37] Replaced Network2 by Network, and added comments to enums --- .../src/litep2p/shim/request_response/mod.rs | 3 ++- .../client/network/src/request_responses.rs | 26 ++++++++++++------- substrate/client/network/src/service.rs | 18 ++++++------- substrate/client/network/sync/src/engine.rs | 12 ++++----- 4 files changed, 34 insertions(+), 25 deletions(-) diff --git a/substrate/client/network/src/litep2p/shim/request_response/mod.rs b/substrate/client/network/src/litep2p/shim/request_response/mod.rs index a77acb464144..00f38a2a4e27 100644 --- a/substrate/client/network/src/litep2p/shim/request_response/mod.rs +++ b/substrate/client/network/src/litep2p/shim/request_response/mod.rs @@ -28,6 +28,7 @@ use crate::{ }; use futures::{channel::oneshot, future::BoxFuture, stream::FuturesUnordered, StreamExt}; +use crate::service::CustomOutboundFailure; use litep2p::{ protocol::request_response::{ DialOptions, RequestResponseError, RequestResponseEvent, RequestResponseHandle, @@ -374,7 +375,7 @@ impl RequestResponseProtocol { Some((RequestFailure::NotConnected, "not-connected")), RequestResponseError::Rejected => Some((RequestFailure::Refused, "rejected")), RequestResponseError::Timeout => - Some((RequestFailure::Network(OutboundFailure::Timeout), "timeout")), + Some((RequestFailure::Network(CustomOutboundFailure::Timeout), "timeout")), RequestResponseError::Canceled => { log::debug!( target: LOG_TARGET, diff --git a/substrate/client/network/src/request_responses.rs b/substrate/client/network/src/request_responses.rs index cfb0739fd179..eff766bbc917 100644 --- a/substrate/client/network/src/request_responses.rs +++ b/substrate/client/network/src/request_responses.rs @@ -73,9 +73,13 @@ pub use libp2p::request_response::{Config, InboundFailure, OutboundFailure, Requ #[allow(missing_docs)] #[error("dial-failure")] pub enum CustomOutboundFailure{ + /// The request could not be sent because a dialing attempt failed. DialFailure, + /// The request timed out before a response was received. Timeout, + /// The connection closed before a response was received. ConnectionClosed, + /// The remote supports none of the requested protocols. UnsupportedProtocols, } @@ -84,9 +88,13 @@ pub enum CustomOutboundFailure{ #[allow(missing_docs)] #[error("dial-failure")] pub enum CustomInboundFailure{ + /// The inbound request timed out, either while reading the incoming request or before a response is sent Timeout, + /// The connection closed before a response could be send. ConnectionClosed, + /// The local peer supports none of the protocols requested by the remote. UnsupportedProtocols, + /// The local peer failed to respond to an inbound request ResponseOmission, } @@ -127,7 +135,7 @@ pub enum RequestFailure{ #[error("The remote replied, but the local node is no longer interested in the response.")] Obsolete, #[error("Problem on the network: {0}")] - Network2(CustomOutboundFailure), + Network(CustomOutboundFailure), } /// Configuration for a single request-response protocol. @@ -512,10 +520,10 @@ impl RequestResponsesBehaviour { } } -impl NetworkBehaviour for RequestResponsesBehaviour { +impl NetworkBehaviour for RequestResponsesBehaviour { type ConnectionHandler = MultiHandler as NetworkBehaviour>::ConnectionHandler>; - type ToSwarm = Event0; + type ToSwarm = Event; fn handle_pending_inbound_connection( &mut self, @@ -918,7 +926,7 @@ impl NetworkBehaviour for RequestResponsesBehaviour { } if response_tx - .send(Err(RequestFailure::Network2(CustomOutboundFailure::Timeout))) + .send(Err(RequestFailure::Network(CustomOutboundFailure::Timeout))) .is_err() { log::debug!( @@ -945,7 +953,7 @@ impl NetworkBehaviour for RequestResponsesBehaviour { peer, protocol: protocol.clone(), duration: started.elapsed(), - result: Err(RequestFailure::Network2(error)), + result: Err(RequestFailure::Network(error)), }; return Poll::Ready(ToSwarm::GenerateEvent(out)) @@ -962,7 +970,7 @@ impl NetworkBehaviour for RequestResponsesBehaviour { let out = Event::InboundRequest { peer, protocol: protocol.clone(), - result: Err(ResponseFailure::Network2(error)), + result: Err(ResponseFailure::Network(error)), }; return Poll::Ready(ToSwarm::GenerateEvent(out)) }, @@ -1036,7 +1044,7 @@ pub enum RegisterError { pub enum ResponseFailure { /// Problem on the network. #[error("Problem on the network: {0}")] - Network2(CustomInboundFailure), + Network(CustomInboundFailure), } /// Implements the libp2p [`Codec`] trait. Defines how streams of bytes are turned @@ -1419,7 +1427,7 @@ mod tests { } match response_receiver.unwrap().await.unwrap().unwrap_err() { - RequestFailure::Network2(CustomOutboundFailure::ConnectionClosed) => {}, + RequestFailure::Network(CustomOutboundFailure::ConnectionClosed) => {}, _ => panic!(), } }); @@ -1790,7 +1798,7 @@ mod tests { SwarmEvent::Behaviour(Event::RequestFinished { result, .. }) => { assert_matches!( result.unwrap_err(), - RequestFailure::Network2(CustomOutboundFailure::UnsupportedProtocols) + RequestFailure::Network(CustomOutboundFailure::UnsupportedProtocols) ); break }, diff --git a/substrate/client/network/src/service.rs b/substrate/client/network/src/service.rs index 513656670d80..714551009d13 100644 --- a/substrate/client/network/src/service.rs +++ b/substrate/client/network/src/service.rs @@ -1219,7 +1219,7 @@ where // 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::Network2(CustomOutboundFailure::ConnectionClosed)), + Err(_) => Err(RequestFailure::Network(CustomOutboundFailure::ConnectionClosed)), } } @@ -1495,17 +1495,17 @@ where }, Err(err) => { let reason = match err { - ResponseFailure::Network2(CustomInboundFailure::Timeout) => + ResponseFailure::Network(CustomInboundFailure::Timeout) => Some("timeout"), - ResponseFailure::Network2(CustomInboundFailure::UnsupportedProtocols) => + ResponseFailure::Network(CustomInboundFailure::UnsupportedProtocols) => // `UnsupportedProtocols` is reported for every single // inbound request whenever a request with an unsupported // protocol is received. This is not reported in order to // avoid confusions. None, - ResponseFailure::Network2(CustomInboundFailure::ResponseOmission) => + ResponseFailure::Network(CustomInboundFailure::ResponseOmission) => Some("busy-omitted"), - ResponseFailure::Network2(CustomInboundFailure::ConnectionClosed) => + ResponseFailure::Network(CustomInboundFailure::ConnectionClosed) => Some("connection-closed"), }; @@ -1541,12 +1541,12 @@ where RequestFailure::Refused => "refused", RequestFailure::Obsolete => "obsolete", - RequestFailure::Network2(CustomOutboundFailure::DialFailure) => + RequestFailure::Network(CustomOutboundFailure::DialFailure) => "dial-failure", - RequestFailure::Network2(CustomOutboundFailure::Timeout) => "timeout", - RequestFailure::Network2(CustomOutboundFailure::ConnectionClosed) => + RequestFailure::Network(CustomOutboundFailure::Timeout) => "timeout", + RequestFailure::Network(CustomOutboundFailure::ConnectionClosed) => "connection-closed", - RequestFailure::Network2(CustomOutboundFailure::UnsupportedProtocols) => + RequestFailure::Network(CustomOutboundFailure::UnsupportedProtocols) => "unsupported", }; diff --git a/substrate/client/network/sync/src/engine.rs b/substrate/client/network/sync/src/engine.rs index cd13d976d13d..0eb970c6635c 100644 --- a/substrate/client/network/sync/src/engine.rs +++ b/substrate/client/network/sync/src/engine.rs @@ -1271,19 +1271,19 @@ where Ok(Err(e)) => { debug!(target: LOG_TARGET, "Request to peer {peer_id:?} failed: {e:?}."); - // Using Our custom type Network2(CustomOutboundFailure) + // Using Our custom type Network(CustomOutboundFailure) match e { - RequestFailure::Network2(CustomOutboundFailure::Timeout) => { + RequestFailure::Network(CustomOutboundFailure::Timeout) => { self.network_service.report_peer(peer_id, rep::TIMEOUT); self.network_service .disconnect_peer(peer_id, self.block_announce_protocol_name.clone()); }, - RequestFailure::Network2(CustomOutboundFailure::UnsupportedProtocols) => { + RequestFailure::Network(CustomOutboundFailure::UnsupportedProtocols) => { self.network_service.report_peer(peer_id, rep::BAD_PROTOCOL); self.network_service .disconnect_peer(peer_id, self.block_announce_protocol_name.clone()); }, - RequestFailure::Network2(CustomOutboundFailure::DialFailure) => { + RequestFailure::Network(CustomOutboundFailure::DialFailure) => { self.network_service .disconnect_peer(peer_id, self.block_announce_protocol_name.clone()); }, @@ -1292,7 +1292,7 @@ where self.network_service .disconnect_peer(peer_id, self.block_announce_protocol_name.clone()); }, - RequestFailure::Network2(CustomOutboundFailure::ConnectionClosed) | + RequestFailure::Network(CustomOutboundFailure::ConnectionClosed) | RequestFailure::NotConnected => { self.network_service .disconnect_peer(peer_id, self.block_announce_protocol_name.clone()); @@ -1308,7 +1308,7 @@ where ); }, //If OutboundFailure is used, - RequestFailure::Network2(_) => {debug_assert!(false, "Don't use deprecated Network");}, + RequestFailure::Network(_) => {debug_assert!(false, "Don't use deprecated Network");}, } }, Err(oneshot::Canceled) => { From 28830feaca59dbbe2bf706dfa1e7d0c02f7e2bf2 Mon Sep 17 00:00:00 2001 From: ndkazu Date: Wed, 24 Jul 2024 22:18:14 +0900 Subject: [PATCH 11/37] Replaced Network2 by Network --- .../network/availability-recovery/src/task/strategy/full.rs | 2 +- .../node/network/availability-recovery/src/task/strategy/mod.rs | 2 +- polkadot/node/network/bridge/src/network.rs | 2 +- polkadot/node/network/protocol/src/request_response/outgoing.rs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/polkadot/node/network/availability-recovery/src/task/strategy/full.rs b/polkadot/node/network/availability-recovery/src/task/strategy/full.rs index ce0e8ad86af3..e5cdb0808750 100644 --- a/polkadot/node/network/availability-recovery/src/task/strategy/full.rs +++ b/polkadot/node/network/availability-recovery/src/task/strategy/full.rs @@ -153,7 +153,7 @@ impl RecoveryStrategy RequestError::InvalidResponse(_) => common_params.metrics.on_full_request_invalid(), RequestError::NetworkError(req_failure) => { - if let RequestFailure::Network2(CustomOutboundFailure::Timeout) = req_failure { + if let RequestFailure::Network(CustomOutboundFailure::Timeout) = req_failure { common_params.metrics.on_full_request_timeout(); } else { common_params.metrics.on_full_request_error(); diff --git a/polkadot/node/network/availability-recovery/src/task/strategy/mod.rs b/polkadot/node/network/availability-recovery/src/task/strategy/mod.rs index 73e2f441c43d..92f768bbbd79 100644 --- a/polkadot/node/network/availability-recovery/src/task/strategy/mod.rs +++ b/polkadot/node/network/availability-recovery/src/task/strategy/mod.rs @@ -566,7 +566,7 @@ impl State { RequestError::NetworkError(err) => { // No debug logs on general network errors - that became very // spammy occasionally. - if let RequestFailure::Network2(CustomOutboundFailure::Timeout) = err { + if let RequestFailure::Network(CustomOutboundFailure::Timeout) = err { metrics.on_chunk_request_timeout(strategy_type); } else { metrics.on_chunk_request_error(strategy_type); diff --git a/polkadot/node/network/bridge/src/network.rs b/polkadot/node/network/bridge/src/network.rs index 5aa29fc7d461..f1b25b5ff6dd 100644 --- a/polkadot/node/network/bridge/src/network.rs +++ b/polkadot/node/network/bridge/src/network.rs @@ -300,7 +300,7 @@ impl Network for Arc { None => { gum::debug!(target: LOG_TARGET, "Discovering authority failed"); match pending_response - .send(Err(RequestFailure::Network2(CustomOutboundFailure::DialFailure))) + .send(Err(RequestFailure::Network(CustomOutboundFailure::DialFailure))) { Err(_) => { gum::debug!(target: LOG_TARGET, "Sending failed request response failed.") diff --git a/polkadot/node/network/protocol/src/request_response/outgoing.rs b/polkadot/node/network/protocol/src/request_response/outgoing.rs index 03b7c046008c..ee4376cc0d7f 100644 --- a/polkadot/node/network/protocol/src/request_response/outgoing.rs +++ b/polkadot/node/network/protocol/src/request_response/outgoing.rs @@ -97,7 +97,7 @@ impl RequestError { match self { Self::Canceled(_) | Self::NetworkError(network::RequestFailure::Obsolete) | - Self::NetworkError(network::RequestFailure::Network2( + Self::NetworkError(network::RequestFailure::Network( CustomOutboundFailure::Timeout, )) => true, _ => false, From f02b17c7939de3d81f88101d51028c187b5b449c Mon Sep 17 00:00:00 2001 From: ndkazu Date: Fri, 26 Jul 2024 21:21:23 +0900 Subject: [PATCH 12/37] Removed Event0, Need to remove ToSwarm dependance to libp2p --- substrate/client/network/src/behaviour.rs | 1 + .../client/network/src/request_responses.rs | 103 ++++++++++-------- 2 files changed, 59 insertions(+), 45 deletions(-) diff --git a/substrate/client/network/src/behaviour.rs b/substrate/client/network/src/behaviour.rs index 68816a10980d..5c42a0158ad6 100644 --- a/substrate/client/network/src/behaviour.rs +++ b/substrate/client/network/src/behaviour.rs @@ -341,6 +341,7 @@ impl From for BehaviourOut { BehaviourOut::RequestFinished { peer, protocol, duration, result }, request_responses::Event::ReputationChanges { peer, changes } => BehaviourOut::ReputationChanges { peer, changes }, + _ => BehaviourOut::None, } } } diff --git a/substrate/client/network/src/request_responses.rs b/substrate/client/network/src/request_responses.rs index eff766bbc917..2766ab1348ef 100644 --- a/substrate/client/network/src/request_responses.rs +++ b/substrate/client/network/src/request_responses.rs @@ -44,7 +44,7 @@ use crate::{ use futures::{channel::oneshot, prelude::*}; use libp2p::{ core::{Endpoint, Multiaddr}, - request_response::{self, Behaviour, Codec, Message, ProtocolSupport, ResponseChannel}, + request_response::{self, Behaviour, Codec, ProtocolSupport, ResponseChannel}, swarm::{ behaviour::{ConnectionClosed, FromSwarm}, handler::multi::MultiHandler, @@ -83,6 +83,21 @@ pub enum CustomOutboundFailure{ UnsupportedProtocols, } +#[derive(Debug, thiserror::Error)] +#[allow(missing_docs)] +#[error("dial-failure")] +pub enum CustomMessage{ + Request{ + request_id: InboundRequestId, + request: Vec, + channel: ResponseChannel> + }, + Response{ + request_id: OutboundRequestId, + response: Vec, + } +} + /// Adding a custom InboundFailure, not depending on libp2p #[derive(Debug, thiserror::Error)] #[allow(missing_docs)] @@ -263,50 +278,11 @@ impl IfDisconnected { } } } -#[derive(Debug)] -pub enum Event0 { - /// An incoming message (request or response). - Message { - /// The peer who sent the message. - peer: PeerId, - /// The incoming message. - message: Message, - }, - /// An outbound request failed. - CustomOutboundFailure { - /// The peer to whom the request was sent. - peer: PeerId, - /// The (local) ID of the failed request. - request_id: OutboundRequestId, - /// The error that occurred. - error: CustomOutboundFailure, - }, - /// An inbound request failed. - CustomInboundFailure { - /// The peer from whom the request was received. - peer: PeerId, - /// The ID of the failed inbound request. - request_id: InboundRequestId, - /// The error that occurred. - error: CustomInboundFailure, - }, - /// A response to an inbound request has been sent. - /// - /// When this event is received, the response has been flushed on - /// the underlying transport connection. - CustomResponseSent { - /// The peer to whom the response was sent. - peer: PeerId, - /// The ID of the inbound request whose response was sent. - request_id: InboundRequestId, - }, - -} /// Event generated by the [`RequestResponsesBehaviour`]. #[derive(Debug)] -pub enum Event { +pub enum Event{ /// A remote sent a request and either we have successfully answered it or an error happened. /// /// This event is generated for statistics purposes. @@ -344,6 +320,43 @@ pub enum Event { /// Reputation changes. changes: Vec, }, + /// An incoming message (request or response). + Message { + /// The peer who sent the message. + peer: PeerId, + /// The incoming message. + message: CustomMessage, + }, + /// An outbound request failed. + CustomOutboundFailure { + /// The peer to whom the request was sent. + peer: PeerId, + /// The (local) ID of the failed request. + request_id: OutboundRequestId, + /// The error that occurred. + error: CustomOutboundFailure, + }, + /// An inbound request failed. + CustomInboundFailure { + /// The peer from whom the request was received. + peer: PeerId, + /// The ID of the failed inbound request. + request_id: InboundRequestId, + /// The error that occurred. + error: CustomInboundFailure, + }, + + /// A response to an inbound request has been sent. + /// + /// When this event is received, the response has been flushed on + /// the underlying transport connection. + CustomResponseSent { + /// The peer to whom the response was sent. + peer: PeerId, + /// The ID of the inbound request whose response was sent. + request_id: InboundRequestId, + }, + } @@ -779,9 +792,9 @@ impl NetworkBehaviour for RequestResponsesBehaviour { match ev { // Received a request from a remote. - Event0::Message { + Event::Message { peer, - message: Message::Request { request_id, request, channel, .. }, + message: CustomMessage::Request { request_id, request, channel, .. }, } => { self.pending_responses_arrival_time .insert((protocol.clone(), request_id).into(), Instant::now()); @@ -841,9 +854,9 @@ impl NetworkBehaviour for RequestResponsesBehaviour { }, // Received a response from a remote to one of our requests. - Event0::Message { + Event::Message { peer, - message: Message::Response { request_id, response }, + message: CustomMessage::Response { request_id, response }, .. } => { let (started, delivered) = match self From 54c54c5c6cf9a2fee5c285b4dbd18ba3421afdfd Mon Sep 17 00:00:00 2001 From: ndkazu Date: Tue, 3 Sep 2024 14:52:22 +0900 Subject: [PATCH 13/37] Ready for review --- .../src/litep2p/shim/request_response/mod.rs | 2 +- .../client/network/src/request_responses.rs | 26 ++++++++++--------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/substrate/client/network/src/litep2p/shim/request_response/mod.rs b/substrate/client/network/src/litep2p/shim/request_response/mod.rs index 00f38a2a4e27..0985d2e6d0e6 100644 --- a/substrate/client/network/src/litep2p/shim/request_response/mod.rs +++ b/substrate/client/network/src/litep2p/shim/request_response/mod.rs @@ -24,7 +24,7 @@ use crate::{ peer_store::PeerStoreProvider, request_responses::{IncomingRequest, OutgoingResponse}, service::{metrics::Metrics, traits::RequestResponseConfig as RequestResponseConfigT}, - IfDisconnected, OutboundFailure, ProtocolName, RequestFailure, + IfDisconnected, ProtocolName, RequestFailure, }; use futures::{channel::oneshot, future::BoxFuture, stream::FuturesUnordered, StreamExt}; diff --git a/substrate/client/network/src/request_responses.rs b/substrate/client/network/src/request_responses.rs index 2766ab1348ef..00b9423b1f83 100644 --- a/substrate/client/network/src/request_responses.rs +++ b/substrate/client/network/src/request_responses.rs @@ -62,7 +62,6 @@ use std::{ sync::Arc, task::{Context, Poll}, time::{Duration, Instant}, - fmt::{Display,Formatter}, fmt, }; @@ -752,7 +751,9 @@ impl NetworkBehaviour for RequestResponsesBehaviour { } let mut fallback_requests = vec![]; + let mut error_bis_out= CustomOutboundFailure::Timeout; + let error_bis_in = CustomInboundFailure::Timeout; // Poll request-responses protocols. for (protocol, (ref mut behaviour, ref mut resp_builder)) in &mut self.protocols { 'poll_protocol: while let Poll::Ready(ev) = behaviour.poll(cx, params) { @@ -792,9 +793,9 @@ impl NetworkBehaviour for RequestResponsesBehaviour { match ev { // Received a request from a remote. - Event::Message { + request_response::Event::Message { peer, - message: CustomMessage::Request { request_id, request, channel, .. }, + message: request_response::Message::Request { request_id, request, channel, .. }, } => { self.pending_responses_arrival_time .insert((protocol.clone(), request_id).into(), Instant::now()); @@ -854,9 +855,9 @@ impl NetworkBehaviour for RequestResponsesBehaviour { }, // Received a response from a remote to one of our requests. - Event::Message { + request_response::Event::Message { peer, - message: CustomMessage::Response { request_id, response }, + message: request_response::Message::Response { request_id, response }, .. } => { let (started, delivered) = match self @@ -901,7 +902,7 @@ impl NetworkBehaviour for RequestResponsesBehaviour { }, // One of our requests has failed. - Event0::CustomOutboundFailure { + request_response::Event::OutboundFailure { peer, request_id, error, @@ -918,7 +919,8 @@ impl NetworkBehaviour for RequestResponsesBehaviour { }) => { // Try using the fallback request if the protocol was not // supported. - if let CustomOutboundFailure::UnsupportedProtocols = error { + if let OutboundFailure::UnsupportedProtocols = error { + error_bis_out = CustomOutboundFailure::UnsupportedProtocols; if let Some((fallback_request, fallback_protocol)) = fallback_request { @@ -966,7 +968,7 @@ impl NetworkBehaviour for RequestResponsesBehaviour { peer, protocol: protocol.clone(), duration: started.elapsed(), - result: Err(RequestFailure::Network(error)), + result: Err(RequestFailure::Network(error_bis_out)), }; return Poll::Ready(ToSwarm::GenerateEvent(out)) @@ -974,8 +976,8 @@ impl NetworkBehaviour for RequestResponsesBehaviour { // An inbound request failed, either while reading the request or due to // failing to send a response. - Event0::CustomInboundFailure { - request_id, peer, error, .. + request_response::Event::InboundFailure { + request_id, peer, .. } => { self.pending_responses_arrival_time .remove(&(protocol.clone(), request_id).into()); @@ -983,13 +985,13 @@ impl NetworkBehaviour for RequestResponsesBehaviour { let out = Event::InboundRequest { peer, protocol: protocol.clone(), - result: Err(ResponseFailure::Network(error)), + result: Err(ResponseFailure::Network(error_bis_in)), }; return Poll::Ready(ToSwarm::GenerateEvent(out)) }, // A response to an inbound request has been sent. - Event0::CustomResponseSent { request_id, peer } => { + request_response::Event::ResponseSent { request_id, peer } => { let arrival_time = self .pending_responses_arrival_time .remove(&(protocol.clone(), request_id).into()) From ae006e1bf2d4d37c6760f23f885943b2d1c04874 Mon Sep 17 00:00:00 2001 From: ndkazu Date: Fri, 6 Sep 2024 01:08:44 +0900 Subject: [PATCH 14/37] First corrections --- Cargo.lock | 1 + .../src/task/strategy/full.rs | 2 +- .../src/task/strategy/mod.rs | 2 +- polkadot/node/network/bridge/src/network.rs | 2 +- .../protocol/src/request_response/outgoing.rs | 2 +- .../client/authority-discovery/Cargo.toml | 1 + substrate/client/network/src/behaviour.rs | 52 +++++- .../src/litep2p/shim/request_response/mod.rs | 2 +- .../src/protocol/notifications/behaviour.rs | 3 +- .../client/network/src/request_responses.rs | 156 ++++++++---------- substrate/client/network/src/service.rs | 38 +++-- substrate/client/network/sync/src/engine.rs | 5 - 12 files changed, 155 insertions(+), 111 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5e2ba07e30f4..82374eeb3b5c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17283,6 +17283,7 @@ dependencies = [ "futures", "futures-timer", "ip_network", + "libp2p", "linked_hash_set", "log", "multihash 0.19.1", diff --git a/polkadot/node/network/availability-recovery/src/task/strategy/full.rs b/polkadot/node/network/availability-recovery/src/task/strategy/full.rs index e5cdb0808750..c90c6477131c 100644 --- a/polkadot/node/network/availability-recovery/src/task/strategy/full.rs +++ b/polkadot/node/network/availability-recovery/src/task/strategy/full.rs @@ -26,7 +26,7 @@ use polkadot_node_primitives::AvailableData; use polkadot_node_subsystem::{messages::NetworkBridgeTxMessage, overseer, RecoveryError}; use polkadot_primitives::ValidatorIndex; use sc_network::{IfDisconnected, OutboundFailure, RequestFailure}; -use sc_network::service::CustomOutboundFailure; +use sc_network::request_responses::CustomOutboundFailure; use futures::{channel::oneshot, SinkExt}; use rand::seq::SliceRandom; diff --git a/polkadot/node/network/availability-recovery/src/task/strategy/mod.rs b/polkadot/node/network/availability-recovery/src/task/strategy/mod.rs index 92f768bbbd79..789b70eafdb3 100644 --- a/polkadot/node/network/availability-recovery/src/task/strategy/mod.rs +++ b/polkadot/node/network/availability-recovery/src/task/strategy/mod.rs @@ -30,7 +30,7 @@ use crate::{ }; use codec::Decode; -use sc_network::service::CustomOutboundFailure; +use sc_network::request_responses::CustomOutboundFailure; use futures::{channel::oneshot, SinkExt}; use polkadot_erasure_coding::branch_hash; #[cfg(not(test))] diff --git a/polkadot/node/network/bridge/src/network.rs b/polkadot/node/network/bridge/src/network.rs index 3780a80a5eaf..f7232ed53b84 100644 --- a/polkadot/node/network/bridge/src/network.rs +++ b/polkadot/node/network/bridge/src/network.rs @@ -23,7 +23,7 @@ use async_trait::async_trait; use parking_lot::Mutex; use codec::Encode; -use sc_network::service::CustomOutboundFailure; +use sc_network::request_responses::CustomOutboundFailure; use sc_network::{ config::parse_addr, multiaddr::Multiaddr, service::traits::NetworkService, types::ProtocolName, diff --git a/polkadot/node/network/protocol/src/request_response/outgoing.rs b/polkadot/node/network/protocol/src/request_response/outgoing.rs index ee4376cc0d7f..9c526c378d00 100644 --- a/polkadot/node/network/protocol/src/request_response/outgoing.rs +++ b/polkadot/node/network/protocol/src/request_response/outgoing.rs @@ -23,7 +23,7 @@ use sc_network as network; use sc_network_types::PeerId; use polkadot_primitives::AuthorityDiscoveryId; -use sc_network::service::CustomOutboundFailure; +use sc_network::request_responses::CustomOutboundFailure; use super::{v1, v2, IsRequest, Protocol}; diff --git a/substrate/client/authority-discovery/Cargo.toml b/substrate/client/authority-discovery/Cargo.toml index fc88d07ef936..09381ec6b553 100644 --- a/substrate/client/authority-discovery/Cargo.toml +++ b/substrate/client/authority-discovery/Cargo.toml @@ -24,6 +24,7 @@ codec = { workspace = true } futures = { workspace = true } futures-timer = { workspace = true } ip_network = { workspace = true } +libp2p = { features = ["ed25519", "kad"], workspace = true } multihash = { workspace = true } linked_hash_set = { workspace = true } log = { workspace = true, default-features = true } diff --git a/substrate/client/network/src/behaviour.rs b/substrate/client/network/src/behaviour.rs index f7403c2f150c..56c77f884929 100644 --- a/substrate/client/network/src/behaviour.rs +++ b/substrate/client/network/src/behaviour.rs @@ -23,7 +23,10 @@ use crate::{ peer_store::PeerStoreProvider, protocol::{CustomMessageOutcome, NotificationsSink, Protocol}, protocol_controller::SetId, - request_responses::{self, IfDisconnected, ProtocolConfig, RequestFailure}, + request_responses::{ + self, CustomInboundFailure, CustomMessage, CustomOutboundFailure, IfDisconnected, + InboundRequestId, OutboundRequestId, ProtocolConfig, RequestFailure, + }, service::traits::Direction, types::ProtocolName, ReputationChange, @@ -102,6 +105,44 @@ pub enum BehaviourOut { /// A request protocol handler issued reputation changes for the given peer. ReputationChanges { peer: PeerId, changes: Vec }, + /// An incoming message (request or response). + Message { + /// The peer who sent the message. + peer: PeerId, + /// The incoming message. + message: CustomMessage, + }, + + /// An outbound request failed. + CustomOutboundFailure { + /// The peer to whom the request was sent. + peer: PeerId, + /// The (local) ID of the failed request. + request_id: OutboundRequestId, + /// The error that occurred. + error: CustomOutboundFailure, + }, + /// An inbound request failed. + CustomInboundFailure { + /// The peer from whom the request was received. + peer: PeerId, + /// The ID of the failed inbound request. + request_id: InboundRequestId, + /// The error that occurred. + error: CustomInboundFailure, + }, + + /// A response to an inbound request has been sent. + /// + /// When this event is received, the response has been flushed on + /// the underlying transport connection. + CustomResponseSent { + /// The peer to whom the response was sent. + peer: PeerId, + /// The ID of the inbound request whose response was sent. + request_id: InboundRequestId, + }, + /// Opened a substream with the given node with the given notifications protocol. /// /// The protocol is always one of the notification protocols that have been registered. @@ -356,7 +397,14 @@ impl From for BehaviourOut { BehaviourOut::RequestFinished { peer, protocol, duration, result }, request_responses::Event::ReputationChanges { peer, changes } => BehaviourOut::ReputationChanges { peer, changes }, - _ => BehaviourOut::None, + request_responses::Event::Message { peer, message } => + BehaviourOut::Message { peer, message }, + request_responses::Event::CustomOutboundFailure { peer, request_id, error } => + BehaviourOut::CustomOutboundFailure { peer, request_id, error }, + request_responses::Event::CustomInboundFailure { peer, request_id, error } => + BehaviourOut::CustomInboundFailure { peer, request_id, error }, + request_responses::Event::CustomResponseSent { peer, request_id } => + BehaviourOut::CustomResponseSent { peer, request_id }, } } } diff --git a/substrate/client/network/src/litep2p/shim/request_response/mod.rs b/substrate/client/network/src/litep2p/shim/request_response/mod.rs index 0985d2e6d0e6..6aa8a51bb533 100644 --- a/substrate/client/network/src/litep2p/shim/request_response/mod.rs +++ b/substrate/client/network/src/litep2p/shim/request_response/mod.rs @@ -27,8 +27,8 @@ use crate::{ IfDisconnected, ProtocolName, RequestFailure, }; +use crate::request_responses::CustomOutboundFailure; use futures::{channel::oneshot, future::BoxFuture, stream::FuturesUnordered, StreamExt}; -use crate::service::CustomOutboundFailure; use litep2p::{ protocol::request_response::{ DialOptions, RequestResponseError, RequestResponseEvent, RequestResponseHandle, diff --git a/substrate/client/network/src/protocol/notifications/behaviour.rs b/substrate/client/network/src/protocol/notifications/behaviour.rs index cb4f089995e3..6436b0864504 100644 --- a/substrate/client/network/src/protocol/notifications/behaviour.rs +++ b/substrate/client/network/src/protocol/notifications/behaviour.rs @@ -2413,7 +2413,8 @@ mod tests { } fn development_notifs( - ) -> (Notifications, ProtocolController, Box) { + ) -> (Notifications, ProtocolController, Box) + { let (protocol_handle_pair, notif_service) = crate::protocol::notifications::service::notification_service("/proto/1".into()); let (to_notifications, from_controller) = diff --git a/substrate/client/network/src/request_responses.rs b/substrate/client/network/src/request_responses.rs index 00b9423b1f83..742c73833c45 100644 --- a/substrate/client/network/src/request_responses.rs +++ b/substrate/client/network/src/request_responses.rs @@ -56,13 +56,12 @@ use libp2p::{ use std::{ collections::{hash_map::Entry, HashMap}, - io, iter, + fmt, io, iter, ops::Deref, pin::Pin, sync::Arc, task::{Context, Poll}, time::{Duration, Instant}, - fmt, }; pub use libp2p::request_response::{Config, InboundFailure, OutboundFailure, RequestId}; @@ -71,75 +70,65 @@ pub use libp2p::request_response::{Config, InboundFailure, OutboundFailure, Requ #[derive(Debug, thiserror::Error)] #[allow(missing_docs)] #[error("dial-failure")] -pub enum CustomOutboundFailure{ +pub enum CustomOutboundFailure { /// The request could not be sent because a dialing attempt failed. DialFailure, /// The request timed out before a response was received. - Timeout, + Timeout, /// The connection closed before a response was received. - ConnectionClosed, + ConnectionClosed, /// The remote supports none of the requested protocols. - UnsupportedProtocols, + UnsupportedProtocols, } #[derive(Debug, thiserror::Error)] #[allow(missing_docs)] #[error("dial-failure")] -pub enum CustomMessage{ - Request{ - request_id: InboundRequestId, - request: Vec, - channel: ResponseChannel> - }, - Response{ - request_id: OutboundRequestId, - response: Vec, - } +pub enum CustomMessage { + Request { request_id: InboundRequestId, request: Vec, channel: ResponseChannel> }, + Response { request_id: OutboundRequestId, response: Vec }, } /// Adding a custom InboundFailure, not depending on libp2p #[derive(Debug, thiserror::Error)] #[allow(missing_docs)] #[error("dial-failure")] -pub enum CustomInboundFailure{ - /// The inbound request timed out, either while reading the incoming request or before a response is sent +pub enum CustomInboundFailure { + /// The inbound request timed out, either while reading the incoming request or before a + /// response is sent Timeout, /// The connection closed before a response could be send. - ConnectionClosed, + ConnectionClosed, /// The local peer supports none of the protocols requested by the remote. - UnsupportedProtocols, - /// The local peer failed to respond to an inbound request - ResponseOmission, + UnsupportedProtocols, + /// The local peer failed to respond to an inbound request + ResponseOmission, } - -/// In preparation for a CustomOutBoundFailure Event +/// In preparation for a CustomOutBoundFailure Event #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] pub struct OutboundRequestId(u64); - impl fmt::Display for OutboundRequestId { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", self.0) - } + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{}", self.0) + } } -/// In preparation for a CustomOutBoundFailure Event +/// In preparation for a CustomOutBoundFailure Event #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] pub struct InboundRequestId(u64); - impl fmt::Display for InboundRequestId { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", self.0) - } + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{}", self.0) + } } - /// Error in a request. #[derive(Debug, thiserror::Error)] #[allow(missing_docs)] -pub enum RequestFailure{ +pub enum RequestFailure { #[error("We are not currently connected to the requested peer.")] NotConnected, #[error("Given protocol hasn't been registered.")] @@ -278,10 +267,9 @@ impl IfDisconnected { } } - /// Event generated by the [`RequestResponsesBehaviour`]. #[derive(Debug)] -pub enum Event{ +pub enum Event { /// A remote sent a request and either we have successfully answered it or an error happened. /// /// This event is generated for statistics purposes. @@ -320,43 +308,43 @@ pub enum Event{ changes: Vec, }, /// An incoming message (request or response). - Message { - /// The peer who sent the message. - peer: PeerId, - /// The incoming message. - message: CustomMessage, - }, - /// An outbound request failed. - CustomOutboundFailure { - /// The peer to whom the request was sent. - peer: PeerId, - /// The (local) ID of the failed request. - request_id: OutboundRequestId, - /// The error that occurred. - error: CustomOutboundFailure, - }, - /// An inbound request failed. - CustomInboundFailure { - /// The peer from whom the request was received. - peer: PeerId, - /// The ID of the failed inbound request. - request_id: InboundRequestId, - /// The error that occurred. - error: CustomInboundFailure, - }, + Message { + /// The peer who sent the message. + peer: PeerId, + /// The incoming message. + message: CustomMessage, + }, - /// A response to an inbound request has been sent. - /// - /// When this event is received, the response has been flushed on - /// the underlying transport connection. - CustomResponseSent { - /// The peer to whom the response was sent. - peer: PeerId, - /// The ID of the inbound request whose response was sent. - request_id: InboundRequestId, - }, + /// An outbound request failed. + CustomOutboundFailure { + /// The peer to whom the request was sent. + peer: PeerId, + /// The (local) ID of the failed request. + request_id: OutboundRequestId, + /// The error that occurred. + error: CustomOutboundFailure, + }, + /// An inbound request failed. + CustomInboundFailure { + /// The peer from whom the request was received. + peer: PeerId, + /// The ID of the failed inbound request. + request_id: InboundRequestId, + /// The error that occurred. + error: CustomInboundFailure, + }, + /// A response to an inbound request has been sent. + /// + /// When this event is received, the response has been flushed on + /// the underlying transport connection. + CustomResponseSent { + /// The peer to whom the response was sent. + peer: PeerId, + /// The ID of the inbound request whose response was sent. + request_id: InboundRequestId, + }, } /// Combination of a protocol name and a request id. @@ -751,9 +739,7 @@ impl NetworkBehaviour for RequestResponsesBehaviour { } let mut fallback_requests = vec![]; - let mut error_bis_out= CustomOutboundFailure::Timeout; - - let error_bis_in = CustomInboundFailure::Timeout; + // Poll request-responses protocols. for (protocol, (ref mut behaviour, ref mut resp_builder)) in &mut self.protocols { 'poll_protocol: while let Poll::Ready(ev) = behaviour.poll(cx, params) { @@ -795,7 +781,10 @@ impl NetworkBehaviour for RequestResponsesBehaviour { // Received a request from a remote. request_response::Event::Message { peer, - message: request_response::Message::Request { request_id, request, channel, .. }, + message: + request_response::Message::Request { + request_id, request, channel, .. + }, } => { self.pending_responses_arrival_time .insert((protocol.clone(), request_id).into(), Instant::now()); @@ -919,8 +908,8 @@ impl NetworkBehaviour for RequestResponsesBehaviour { }) => { // Try using the fallback request if the protocol was not // supported. - if let OutboundFailure::UnsupportedProtocols = error { - error_bis_out = CustomOutboundFailure::UnsupportedProtocols; + if let OutboundFailure::UnsupportedProtocols = error { + let error_bis_out = CustomOutboundFailure::UnsupportedProtocols; if let Some((fallback_request, fallback_protocol)) = fallback_request { @@ -941,7 +930,9 @@ impl NetworkBehaviour for RequestResponsesBehaviour { } if response_tx - .send(Err(RequestFailure::Network(CustomOutboundFailure::Timeout))) + .send(Err(RequestFailure::Network( + CustomOutboundFailure::Timeout, + ))) .is_err() { log::debug!( @@ -963,7 +954,7 @@ impl NetworkBehaviour for RequestResponsesBehaviour { continue }, }; - + let error_bis_out = CustomOutboundFailure::Timeout; let out = Event::RequestFinished { peer, protocol: protocol.clone(), @@ -976,9 +967,8 @@ impl NetworkBehaviour for RequestResponsesBehaviour { // An inbound request failed, either while reading the request or due to // failing to send a response. - request_response::Event::InboundFailure { - request_id, peer, .. - } => { + request_response::Event::InboundFailure { request_id, peer, .. } => { + let error_bis_in = CustomInboundFailure::Timeout; self.pending_responses_arrival_time .remove(&(protocol.clone(), request_id).into()); self.send_feedback.remove(&(protocol.clone(), request_id).into()); @@ -1846,4 +1836,4 @@ mod tests { ); }); } -} \ No newline at end of file +} diff --git a/substrate/client/network/src/service.rs b/substrate/client/network/src/service.rs index 23adb3025e21..3beb5d187eab 100644 --- a/substrate/client/network/src/service.rs +++ b/substrate/client/network/src/service.rs @@ -90,8 +90,8 @@ use sc_utils::mpsc::{tracing_unbounded, TracingUnboundedReceiver, TracingUnbound use sp_runtime::traits::Block as BlockT; pub use behaviour::{InboundFailure, OutboundFailure, ResponseFailure}; -// Import our custom type -pub use crate::request_responses::{CustomOutboundFailure,CustomInboundFailure}; +// Import our custom type +use crate::request_responses::{CustomInboundFailure, CustomOutboundFailure}; pub use libp2p::identity::{DecodingError, Keypair, PublicKey}; pub use metrics::NotificationMetrics; pub use protocol::NotificationsSink; @@ -1519,16 +1519,20 @@ where let reason = match err { ResponseFailure::Network(CustomInboundFailure::Timeout) => Some("timeout"), - ResponseFailure::Network(CustomInboundFailure::UnsupportedProtocols) => + ResponseFailure::Network( + CustomInboundFailure::UnsupportedProtocols, + ) => // `UnsupportedProtocols` is reported for every single // inbound request whenever a request with an unsupported // protocol is received. This is not reported in order to // avoid confusions. None, - ResponseFailure::Network(CustomInboundFailure::ResponseOmission) => - Some("busy-omitted"), - ResponseFailure::Network(CustomInboundFailure::ConnectionClosed) => - Some("connection-closed"), + ResponseFailure::Network( + CustomInboundFailure::ResponseOmission, + ) => Some("busy-omitted"), + ResponseFailure::Network( + CustomInboundFailure::ConnectionClosed, + ) => Some("connection-closed"), }; if let Some(reason) = reason { @@ -1555,22 +1559,23 @@ where .with_label_values(&[&protocol]) .observe(duration.as_secs_f64()); }, - // we also could remove Network cases here like we did in engine Err(err) => { let reason = match err { RequestFailure::NotConnected => "not-connected", RequestFailure::UnknownProtocol => "unknown-protocol", RequestFailure::Refused => "refused", RequestFailure::Obsolete => "obsolete", - + RequestFailure::Network(CustomOutboundFailure::DialFailure) => "dial-failure", - RequestFailure::Network(CustomOutboundFailure::Timeout) => "timeout", - RequestFailure::Network(CustomOutboundFailure::ConnectionClosed) => - "connection-closed", - RequestFailure::Network(CustomOutboundFailure::UnsupportedProtocols) => - "unsupported", - + RequestFailure::Network(CustomOutboundFailure::Timeout) => + "timeout", + RequestFailure::Network( + CustomOutboundFailure::ConnectionClosed, + ) => "connection-closed", + RequestFailure::Network( + CustomOutboundFailure::UnsupportedProtocols, + ) => "unsupported", }; metrics @@ -1697,6 +1702,9 @@ where SwarmEvent::Behaviour(BehaviourOut::None) => { // Ignored event from lower layers. }, + SwarmEvent::Behaviour(_) => { + // Ignored event from lower layers. + }, SwarmEvent::ConnectionEstablished { peer_id, endpoint, diff --git a/substrate/client/network/sync/src/engine.rs b/substrate/client/network/sync/src/engine.rs index 1e8bf6a2ca3e..926066165a4a 100644 --- a/substrate/client/network/sync/src/engine.rs +++ b/substrate/client/network/sync/src/engine.rs @@ -42,10 +42,7 @@ use crate::{ }; use codec::{Decode, DecodeAll, Encode}; - use futures::{channel::oneshot, FutureExt, StreamExt}; -use libp2p::request_response::OutboundFailure; - use log::{debug, error, trace, warn}; use prometheus_endpoint::{ register, Counter, Gauge, MetricSource, Opts, PrometheusError, Registry, SourcedGauge, U64, @@ -1234,8 +1231,6 @@ where response receiver.", ); }, - //If OutboundFailure is used, - RequestFailure::Network(_) => {debug_assert!(false, "Don't use deprecated Network");}, } }, Err(oneshot::Canceled) => { From a52c9d4920a8567bb1e933cb4ef75a59b75f5195 Mon Sep 17 00:00:00 2001 From: ndkazu Date: Fri, 6 Sep 2024 01:19:24 +0900 Subject: [PATCH 15/37] Second round of corrections --- substrate/client/network/src/service.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/substrate/client/network/src/service.rs b/substrate/client/network/src/service.rs index 3beb5d187eab..9fd4370a3b54 100644 --- a/substrate/client/network/src/service.rs +++ b/substrate/client/network/src/service.rs @@ -1702,9 +1702,18 @@ where SwarmEvent::Behaviour(BehaviourOut::None) => { // Ignored event from lower layers. }, - SwarmEvent::Behaviour(_) => { + SwarmEvent::Behaviour(BehaviourOut::Message{ peer, message }) => { + // Ignored event from lower layers. + }, + SwarmEvent::Behaviour(BehaviourOut::CustomOutboundFailure{ peer,request_id,error }) => { + // Ignored event from lower layers. + }, + SwarmEvent::Behaviour(BehaviourOut::CustomInboundFailure{ peer,request_id,error }) => { // Ignored event from lower layers. }, + SwarmEvent::Behaviour(BehaviourOut::CustomResponseSent{ peer,request_id }) => { + // Ignored event from lower layers. + }, SwarmEvent::ConnectionEstablished { peer_id, endpoint, From 73860e647c86f13a45568b61215b4223a72aadce Mon Sep 17 00:00:00 2001 From: ndkazu Date: Fri, 6 Sep 2024 01:20:33 +0900 Subject: [PATCH 16/37] cargo +nightly fmt --- bridges/modules/xcm-bridge-hub/src/lib.rs | 37 ++++++++++--------- .../src/on_demand/parachains.rs | 3 +- .../messages/src/message_race_strategy.rs | 6 ++- .../primitives/router/src/inbound/mod.rs | 3 +- .../runtime/runtime-common/src/lib.rs | 3 +- cumulus/pallets/parachain-system/src/lib.rs | 3 +- .../asset-hub-rococo/src/tests/teleport.rs | 4 +- .../asset-hub-westend/src/tests/teleport.rs | 4 +- .../people-rococo/src/tests/teleport.rs | 4 +- .../people-westend/src/tests/teleport.rs | 4 +- .../assets/asset-hub-rococo/src/lib.rs | 3 +- .../assets/asset-hub-westend/src/lib.rs | 3 +- .../assets/test-utils/src/test_cases.rs | 3 +- .../test-utils/src/test_cases/mod.rs | 11 +++--- cumulus/primitives/utility/src/lib.rs | 6 ++- polkadot/node/core/approval-voting/src/lib.rs | 7 +++- .../node/core/approval-voting/src/tests.rs | 3 +- .../common/src/worker/security/change_root.rs | 3 +- .../approval-distribution/src/tests.rs | 3 +- .../src/task/strategy/chunks.rs | 7 ++-- .../src/task/strategy/full.rs | 11 ++++-- .../src/task/strategy/mod.rs | 6 ++- .../subsystem-bench/src/lib/statement/mod.rs | 16 ++++---- .../subsystem-types/src/runtime_client.rs | 3 +- polkadot/runtime/parachains/src/hrmp.rs | 2 +- .../parachains/src/paras_inherent/mod.rs | 25 +++++++------ polkadot/runtime/parachains/src/ump_tests.rs | 7 ++-- polkadot/runtime/westend/src/lib.rs | 3 +- polkadot/statement-table/src/generic.rs | 6 ++- .../parachain/xcm_config.rs | 2 +- .../relay_chain/xcm_config.rs | 2 +- polkadot/xcm/pallet-xcm-benchmarks/src/lib.rs | 2 +- .../xcm/xcm-builder/src/asset_conversion.rs | 8 +++- .../xcm-builder/src/nonfungibles_adapter.rs | 9 ++++- .../xcm-runtime-apis/tests/fee_estimation.rs | 2 +- .../client/cli/src/params/node_key_params.rs | 4 +- .../consensus/grandpa/src/aux_schema.rs | 4 +- substrate/client/db/src/lib.rs | 3 +- .../client/network/src/request_responses.rs | 5 ++- substrate/client/network/src/service.rs | 20 +++++++--- substrate/client/network/sync/src/engine.rs | 5 ++- .../rpc-spec-v2/src/chain_head/test_utils.rs | 3 +- substrate/frame/bags-list/src/list/tests.rs | 2 +- .../balances/src/tests/currency_tests.rs | 6 +-- substrate/frame/bounties/src/lib.rs | 12 +++--- substrate/frame/child-bounties/src/lib.rs | 13 ++++--- .../examples/offchain-worker/src/tests.rs | 22 ++++++----- substrate/frame/nis/src/lib.rs | 16 ++++---- substrate/frame/referenda/src/types.rs | 3 +- substrate/frame/revive/proc-macro/src/lib.rs | 25 +++++++------ substrate/frame/society/src/tests.rs | 2 +- substrate/frame/staking/src/tests.rs | 2 +- .../procedural/src/pallet/parse/call.rs | 23 ++++++------ .../support/src/storage/types/double_map.rs | 3 +- .../traits/try_runtime/decode_entire_state.rs | 6 ++- substrate/frame/support/test/tests/pallet.rs | 5 ++- .../frame/transaction-payment/src/tests.rs | 6 ++- substrate/frame/utility/src/lib.rs | 4 +- substrate/frame/vesting/src/tests.rs | 10 ++--- .../utils/wasm-builder/src/wasm_project.rs | 7 ++-- 60 files changed, 257 insertions(+), 178 deletions(-) diff --git a/bridges/modules/xcm-bridge-hub/src/lib.rs b/bridges/modules/xcm-bridge-hub/src/lib.rs index 02d578386a75..b183d3cb4e37 100644 --- a/bridges/modules/xcm-bridge-hub/src/lib.rs +++ b/bridges/modules/xcm-bridge-hub/src/lib.rs @@ -1474,25 +1474,26 @@ mod tests { let lane_id = LaneId::from_inner(Either::Left(H256::default())); let lane_id_mismatch = LaneId::from_inner(Either::Left(H256::from([1u8; 32]))); - let test_bridge_state = |id, - bridge, - (lane_id, bridge_id), - (inbound_lane_id, outbound_lane_id), - expected_error: Option| { - Bridges::::insert(id, bridge); - LaneToBridge::::insert(lane_id, bridge_id); + let test_bridge_state = + |id, + bridge, + (lane_id, bridge_id), + (inbound_lane_id, outbound_lane_id), + expected_error: Option| { + Bridges::::insert(id, bridge); + LaneToBridge::::insert(lane_id, bridge_id); - let lanes_manager = LanesManagerOf::::new(); - lanes_manager.create_inbound_lane(inbound_lane_id).unwrap(); - lanes_manager.create_outbound_lane(outbound_lane_id).unwrap(); - - let result = XcmOverBridge::do_try_state(); - if let Some(e) = expected_error { - assert_err!(result, e); - } else { - assert_ok!(result); - } - }; + let lanes_manager = LanesManagerOf::::new(); + lanes_manager.create_inbound_lane(inbound_lane_id).unwrap(); + lanes_manager.create_outbound_lane(outbound_lane_id).unwrap(); + + let result = XcmOverBridge::do_try_state(); + if let Some(e) = expected_error { + assert_err!(result, e); + } else { + assert_ok!(result); + } + }; let cleanup = |bridge_id, lane_ids| { Bridges::::remove(bridge_id); for lane_id in lane_ids { diff --git a/bridges/relays/lib-substrate-relay/src/on_demand/parachains.rs b/bridges/relays/lib-substrate-relay/src/on_demand/parachains.rs index 2ef86f48ecbe..96eba0af988c 100644 --- a/bridges/relays/lib-substrate-relay/src/on_demand/parachains.rs +++ b/bridges/relays/lib-substrate-relay/src/on_demand/parachains.rs @@ -664,7 +664,8 @@ impl<'a, P: SubstrateParachainsPipeline, SourceRelayClnt, TargetClnt> for ( &'a OnDemandParachainsRelay, &'a ParachainsSource, - ) where + ) +where SourceRelayClnt: Client, TargetClnt: Client, { diff --git a/bridges/relays/messages/src/message_race_strategy.rs b/bridges/relays/messages/src/message_race_strategy.rs index 3a532331d79d..1303fcfedebd 100644 --- a/bridges/relays/messages/src/message_race_strategy.rs +++ b/bridges/relays/messages/src/message_race_strategy.rs @@ -67,7 +67,8 @@ impl< TargetHeaderHash, SourceNoncesRange, Proof, - > where + > +where SourceHeaderHash: Clone, SourceHeaderNumber: Clone + Ord, SourceNoncesRange: NoncesRange, @@ -189,7 +190,8 @@ impl< TargetHeaderHash, SourceNoncesRange, Proof, - > where + > +where SourceHeaderHash: Clone + Debug + Send + Sync, SourceHeaderNumber: Clone + Ord + Debug + Send + Sync, SourceNoncesRange: NoncesRange + Debug + Send + Sync, diff --git a/bridges/snowbridge/primitives/router/src/inbound/mod.rs b/bridges/snowbridge/primitives/router/src/inbound/mod.rs index 54e47a7a8b6a..4179e8b37a42 100644 --- a/bridges/snowbridge/primitives/router/src/inbound/mod.rs +++ b/bridges/snowbridge/primitives/router/src/inbound/mod.rs @@ -128,7 +128,8 @@ impl where + > +where CreateAssetCall: Get, CreateAssetDeposit: Get, InboundQueuePalletInstance: Get, diff --git a/bridges/snowbridge/runtime/runtime-common/src/lib.rs b/bridges/snowbridge/runtime/runtime-common/src/lib.rs index aae45520ff4b..0b1a74b232a0 100644 --- a/bridges/snowbridge/runtime/runtime-common/src/lib.rs +++ b/bridges/snowbridge/runtime/runtime-common/src/lib.rs @@ -50,7 +50,8 @@ impl where + > +where Balance: BaseArithmetic + Unsigned + Copy + From + Into + Debug, AccountId: Clone + FullCodec, FeeAssetLocation: Get, diff --git a/cumulus/pallets/parachain-system/src/lib.rs b/cumulus/pallets/parachain-system/src/lib.rs index bf136dc0644c..c49445dffd35 100644 --- a/cumulus/pallets/parachain-system/src/lib.rs +++ b/cumulus/pallets/parachain-system/src/lib.rs @@ -366,7 +366,8 @@ pub mod pallet { let maximum_channels = host_config .hrmp_max_message_num_per_candidate - .min(>::take()) as usize; + .min(>::take()) + as usize; // Note: this internally calls the `GetChannelInfo` implementation for this // pallet, which draws on the `RelevantMessagingState`. That in turn has diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs index c8da801a14bf..d16bf620cdfb 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs @@ -265,7 +265,9 @@ fn limited_teleport_native_assets_from_system_para_to_relay_fails() { let delivery_fees = AssetHubRococo::execute_with(|| { xcm_helpers::teleport_assets_delivery_fees::< ::XcmSender, - >(test.args.assets.clone(), 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) + >( + test.args.assets.clone(), 0, test.args.weight_limit, test.args.beneficiary, test.args.dest + ) }); // Sender's balance is reduced diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs index 15d39858acca..c0f31d20513d 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs @@ -265,7 +265,9 @@ fn limited_teleport_native_assets_from_system_para_to_relay_fails() { let delivery_fees = AssetHubWestend::execute_with(|| { xcm_helpers::teleport_assets_delivery_fees::< ::XcmSender, - >(test.args.assets.clone(), 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) + >( + test.args.assets.clone(), 0, test.args.weight_limit, test.args.beneficiary, test.args.dest + ) }); // Sender's balance is reduced diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/teleport.rs index 44e6b3934f0e..2619ca7591d0 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/teleport.rs @@ -107,7 +107,9 @@ fn limited_teleport_native_assets_from_system_para_to_relay_fails() { let delivery_fees = PeopleRococo::execute_with(|| { xcm_helpers::teleport_assets_delivery_fees::< ::XcmSender, - >(test.args.assets.clone(), 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) + >( + test.args.assets.clone(), 0, test.args.weight_limit, test.args.beneficiary, test.args.dest + ) }); // Sender's balance is reduced diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-westend/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-westend/src/tests/teleport.rs index 83888031723f..d9a2c23ac0c6 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-westend/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-westend/src/tests/teleport.rs @@ -107,7 +107,9 @@ fn limited_teleport_native_assets_from_system_para_to_relay_fails() { let delivery_fees = PeopleWestend::execute_with(|| { xcm_helpers::teleport_assets_delivery_fees::< ::XcmSender, - >(test.args.assets.clone(), 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) + >( + test.args.assets.clone(), 0, test.args.weight_limit, test.args.beneficiary, test.args.dest + ) }); // Sender's balance is reduced diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs index 2f3fb6b68c4a..96a2fd5bf292 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs @@ -546,7 +546,8 @@ impl InstanceFilter for ProxyType { RuntimeCall::Utility { .. } | RuntimeCall::Multisig { .. } | RuntimeCall::NftFractionalization { .. } | - RuntimeCall::Nfts { .. } | RuntimeCall::Uniques { .. } + RuntimeCall::Nfts { .. } | + RuntimeCall::Uniques { .. } ) }, ProxyType::AssetOwner => matches!( diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs index 97dbe7c361c1..5d988f89d25c 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs @@ -542,7 +542,8 @@ impl InstanceFilter for ProxyType { RuntimeCall::Utility { .. } | RuntimeCall::Multisig { .. } | RuntimeCall::NftFractionalization { .. } | - RuntimeCall::Nfts { .. } | RuntimeCall::Uniques { .. } + RuntimeCall::Nfts { .. } | + RuntimeCall::Uniques { .. } ) }, ProxyType::AssetOwner => matches!( diff --git a/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs b/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs index 67b585ecfe86..c80222142304 100644 --- a/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs +++ b/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs @@ -1143,7 +1143,8 @@ pub fn create_and_manage_foreign_assets_for_local_consensus_parachain_assets_wor .with_balances(vec![( foreign_creator_as_account_id.clone(), existential_deposit + - asset_deposit + metadata_deposit_base + + asset_deposit + + metadata_deposit_base + metadata_deposit_per_byte_eta + buy_execution_fee_amount.into() + buy_execution_fee_amount.into(), diff --git a/cumulus/parachains/runtimes/bridge-hubs/test-utils/src/test_cases/mod.rs b/cumulus/parachains/runtimes/bridge-hubs/test-utils/src/test_cases/mod.rs index de117982b26f..b8c2359f8aca 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/test-utils/src/test_cases/mod.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/test-utils/src/test_cases/mod.rs @@ -504,11 +504,12 @@ pub fn message_dispatch_routing_works< // 2. this message is sent from other global consensus with destination of this Runtime // sibling parachain (HRMP) - let bridging_message = test_data::simulate_message_exporter_on_bridged_chain::< - BridgedNetwork, - NetworkWithParentCount, - AlwaysLatest, - >((RuntimeNetwork::get(), [Parachain(sibling_parachain_id)].into())); + let bridging_message = + test_data::simulate_message_exporter_on_bridged_chain::< + BridgedNetwork, + NetworkWithParentCount, + AlwaysLatest, + >((RuntimeNetwork::get(), [Parachain(sibling_parachain_id)].into())); // 2.1. WITHOUT opened hrmp channel -> RoutingError let result = diff --git a/cumulus/primitives/utility/src/lib.rs b/cumulus/primitives/utility/src/lib.rs index 3ebcb44fa439..a9566661bb39 100644 --- a/cumulus/primitives/utility/src/lib.rs +++ b/cumulus/primitives/utility/src/lib.rs @@ -381,7 +381,8 @@ impl< FungiblesAssetMatcher, OnUnbalanced, AccountId, - > where + > +where Fungibles::Balance: Into, { fn new() -> Self { @@ -541,7 +542,8 @@ impl< FungiblesAssetMatcher, OnUnbalanced, AccountId, - > where + > +where Fungibles::Balance: Into, { fn drop(&mut self) { diff --git a/polkadot/node/core/approval-voting/src/lib.rs b/polkadot/node/core/approval-voting/src/lib.rs index 942922cba6df..78a0567168d0 100644 --- a/polkadot/node/core/approval-voting/src/lib.rs +++ b/polkadot/node/core/approval-voting/src/lib.rs @@ -2415,7 +2415,12 @@ fn schedule_wakeup_action( last_assignment_tick.map(|l| l + APPROVAL_DELAY).filter(|t| t > &tick_now), next_no_show, ) - .map(|tick| Action::ScheduleWakeup { block_hash, block_number, candidate_hash, tick }) + .map(|tick| Action::ScheduleWakeup { + block_hash, + block_number, + candidate_hash, + tick, + }) }, RequiredTranches::Pending { considered, next_no_show, clock_drift, .. } => { // select the minimum of `next_no_show`, or the tick of the next non-empty tranche diff --git a/polkadot/node/core/approval-voting/src/tests.rs b/polkadot/node/core/approval-voting/src/tests.rs index 7126f209a94f..8a3102f22d0d 100644 --- a/polkadot/node/core/approval-voting/src/tests.rs +++ b/polkadot/node/core/approval-voting/src/tests.rs @@ -263,7 +263,8 @@ where _relay_vrf_story: polkadot_node_primitives::approval::v1::RelayVRFStory, _assignment: &polkadot_node_primitives::approval::v2::AssignmentCertV2, _backing_groups: Vec, - ) -> Result { + ) -> Result + { self.1(validator_index) } } diff --git a/polkadot/node/core/pvf/common/src/worker/security/change_root.rs b/polkadot/node/core/pvf/common/src/worker/security/change_root.rs index 9ec66906819f..fcfaf6541c29 100644 --- a/polkadot/node/core/pvf/common/src/worker/security/change_root.rs +++ b/polkadot/node/core/pvf/common/src/worker/security/change_root.rs @@ -124,7 +124,8 @@ fn try_restrict(worker_info: &WorkerInfo) -> Result<()> { libc::MS_BIND | libc::MS_REC | libc::MS_NOEXEC | libc::MS_NODEV | libc::MS_NOSUID | - libc::MS_NOATIME | additional_flags, + libc::MS_NOATIME | + additional_flags, ptr::null(), // ignored when MS_BIND is used ) < 0 { diff --git a/polkadot/node/network/approval-distribution/src/tests.rs b/polkadot/node/network/approval-distribution/src/tests.rs index 4ee9320e0e45..83b5eb7684b9 100644 --- a/polkadot/node/network/approval-distribution/src/tests.rs +++ b/polkadot/node/network/approval-distribution/src/tests.rs @@ -535,7 +535,8 @@ impl AssignmentCriteria for MockAssignmentCriteria { _relay_vrf_story: polkadot_node_primitives::approval::v1::RelayVRFStory, _assignment: &polkadot_node_primitives::approval::v2::AssignmentCertV2, _backing_groups: Vec, - ) -> Result { + ) -> Result + { self.tranche } } diff --git a/polkadot/node/network/availability-recovery/src/task/strategy/chunks.rs b/polkadot/node/network/availability-recovery/src/task/strategy/chunks.rs index b6376a5b543e..f4bb8b925059 100644 --- a/polkadot/node/network/availability-recovery/src/task/strategy/chunks.rs +++ b/polkadot/node/network/availability-recovery/src/task/strategy/chunks.rs @@ -107,9 +107,10 @@ impl FetchChunks { state: &mut State, common_params: &RecoveryParams, ) -> Result { - let recovery_duration = common_params - .metrics - .time_erasure_recovery(RecoveryStrategy::::strategy_type(self)); + let recovery_duration = + common_params + .metrics + .time_erasure_recovery(RecoveryStrategy::::strategy_type(self)); // Send request to reconstruct available data from chunks. let (avilable_data_tx, available_data_rx) = oneshot::channel(); diff --git a/polkadot/node/network/availability-recovery/src/task/strategy/full.rs b/polkadot/node/network/availability-recovery/src/task/strategy/full.rs index c90c6477131c..61a629582add 100644 --- a/polkadot/node/network/availability-recovery/src/task/strategy/full.rs +++ b/polkadot/node/network/availability-recovery/src/task/strategy/full.rs @@ -19,16 +19,17 @@ use crate::{ ErasureTask, PostRecoveryCheck, LOG_TARGET, }; +use futures::{channel::oneshot, SinkExt}; use polkadot_node_network_protocol::request_response::{ self as req_res, outgoing::RequestError, OutgoingRequest, Recipient, Requests, }; use polkadot_node_primitives::AvailableData; use polkadot_node_subsystem::{messages::NetworkBridgeTxMessage, overseer, RecoveryError}; use polkadot_primitives::ValidatorIndex; -use sc_network::{IfDisconnected, OutboundFailure, RequestFailure}; -use sc_network::request_responses::CustomOutboundFailure; -use futures::{channel::oneshot, SinkExt}; use rand::seq::SliceRandom; +use sc_network::{ + request_responses::CustomOutboundFailure, IfDisconnected, OutboundFailure, RequestFailure, +}; /// Parameters specific to the `FetchFull` strategy. pub struct FetchFullParams { @@ -153,7 +154,9 @@ impl RecoveryStrategy RequestError::InvalidResponse(_) => common_params.metrics.on_full_request_invalid(), RequestError::NetworkError(req_failure) => { - if let RequestFailure::Network(CustomOutboundFailure::Timeout) = req_failure { + if let RequestFailure::Network(CustomOutboundFailure::Timeout) = + req_failure + { common_params.metrics.on_full_request_timeout(); } else { common_params.metrics.on_full_request_error(); diff --git a/polkadot/node/network/availability-recovery/src/task/strategy/mod.rs b/polkadot/node/network/availability-recovery/src/task/strategy/mod.rs index 789b70eafdb3..b3d5786cae5e 100644 --- a/polkadot/node/network/availability-recovery/src/task/strategy/mod.rs +++ b/polkadot/node/network/availability-recovery/src/task/strategy/mod.rs @@ -30,7 +30,6 @@ use crate::{ }; use codec::Decode; -use sc_network::request_responses::CustomOutboundFailure; use futures::{channel::oneshot, SinkExt}; use polkadot_erasure_coding::branch_hash; #[cfg(not(test))] @@ -44,7 +43,10 @@ use polkadot_node_subsystem::{ overseer, RecoveryError, }; use polkadot_primitives::{AuthorityDiscoveryId, BlakeTwo256, ChunkIndex, HashT, ValidatorIndex}; -use sc_network::{IfDisconnected, OutboundFailure, ProtocolName, RequestFailure}; +use sc_network::{ + request_responses::CustomOutboundFailure, IfDisconnected, OutboundFailure, ProtocolName, + RequestFailure, +}; use std::{ collections::{BTreeMap, HashMap, VecDeque}, time::Duration, diff --git a/polkadot/node/subsystem-bench/src/lib/statement/mod.rs b/polkadot/node/subsystem-bench/src/lib/statement/mod.rs index bd47505f56ae..8cb7eee22b2d 100644 --- a/polkadot/node/subsystem-bench/src/lib/statement/mod.rs +++ b/polkadot/node/subsystem-bench/src/lib/statement/mod.rs @@ -114,14 +114,14 @@ fn build_overseer( state.pvd.clone(), state.own_backing_group.clone(), ); - let (statement_req_receiver, statement_req_cfg) = IncomingRequest::get_config_receiver::< - Block, - sc_network::NetworkWorker, - >(&ReqProtocolNames::new(GENESIS_HASH, None)); - let (candidate_req_receiver, candidate_req_cfg) = IncomingRequest::get_config_receiver::< - Block, - sc_network::NetworkWorker, - >(&ReqProtocolNames::new(GENESIS_HASH, None)); + let (statement_req_receiver, statement_req_cfg) = + IncomingRequest::get_config_receiver::>( + &ReqProtocolNames::new(GENESIS_HASH, None), + ); + let (candidate_req_receiver, candidate_req_cfg) = + IncomingRequest::get_config_receiver::>( + &ReqProtocolNames::new(GENESIS_HASH, None), + ); let keystore = make_keystore(); let subsystem = StatementDistributionSubsystem::new( keystore.clone(), diff --git a/polkadot/node/subsystem-types/src/runtime_client.rs b/polkadot/node/subsystem-types/src/runtime_client.rs index 7938223df23b..a8af8b7996f9 100644 --- a/polkadot/node/subsystem-types/src/runtime_client.rs +++ b/polkadot/node/subsystem-types/src/runtime_client.rs @@ -665,7 +665,8 @@ where fn number( &self, hash: Block::Hash, - ) -> sc_client_api::blockchain::Result::Header as HeaderT>::Number>> { + ) -> sc_client_api::blockchain::Result::Header as HeaderT>::Number>> + { self.client.number(hash) } diff --git a/polkadot/runtime/parachains/src/hrmp.rs b/polkadot/runtime/parachains/src/hrmp.rs index b149404b41b8..220543f00ec3 100644 --- a/polkadot/runtime/parachains/src/hrmp.rs +++ b/polkadot/runtime/parachains/src/hrmp.rs @@ -945,7 +945,7 @@ impl Pallet { outgoing_paras.len() as u32 )) .saturating_add(::WeightInfo::force_process_hrmp_close( - outgoing_paras.len() as u32 + outgoing_paras.len() as u32, )) } diff --git a/polkadot/runtime/parachains/src/paras_inherent/mod.rs b/polkadot/runtime/parachains/src/paras_inherent/mod.rs index 84d8299cd29c..70c4ba72d58e 100644 --- a/polkadot/runtime/parachains/src/paras_inherent/mod.rs +++ b/polkadot/runtime/parachains/src/paras_inherent/mod.rs @@ -1216,18 +1216,19 @@ fn filter_backed_statements_from_disabled_validators< // Get relay parent block number of the candidate. We need this to get the group index // assigned to this core at this block number - let relay_parent_block_number = - match allowed_relay_parents.acquire_info(bc.descriptor().relay_parent(), None) { - Some((_, block_num)) => block_num, - None => { - log::debug!( - target: LOG_TARGET, - "Relay parent {:?} for candidate is not in the allowed relay parents. Dropping the candidate.", - bc.descriptor().relay_parent() - ); - return false - }, - }; + let relay_parent_block_number = match allowed_relay_parents + .acquire_info(bc.descriptor().relay_parent(), None) + { + Some((_, block_num)) => block_num, + None => { + log::debug!( + target: LOG_TARGET, + "Relay parent {:?} for candidate is not in the allowed relay parents. Dropping the candidate.", + bc.descriptor().relay_parent() + ); + return false + }, + }; // Get the group index for the core let group_idx = match scheduler::Pallet::::group_assigned_to_core( diff --git a/polkadot/runtime/parachains/src/ump_tests.rs b/polkadot/runtime/parachains/src/ump_tests.rs index d914bf8b6661..91571859ecf0 100644 --- a/polkadot/runtime/parachains/src/ump_tests.rs +++ b/polkadot/runtime/parachains/src/ump_tests.rs @@ -462,10 +462,11 @@ fn verify_relay_dispatch_queue_size_is_externally_accessible() { fn assert_queue_size(para: ParaId, count: u32, size: u32) { #[allow(deprecated)] - let raw_queue_size = sp_io::storage::get(&well_known_keys::relay_dispatch_queue_size(para)).expect( - "enqueuing a message should create the dispatch queue\ + let raw_queue_size = sp_io::storage::get(&well_known_keys::relay_dispatch_queue_size(para)) + .expect( + "enqueuing a message should create the dispatch queue\ and it should be accessible via the well known keys", - ); + ); let (c, s) = <(u32, u32)>::decode(&mut &raw_queue_size[..]) .expect("the dispatch queue size should be decodable into (u32, u32)"); assert_eq!((c, s), (count, size)); diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index b02c2d8c671e..479ed83f7236 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -1113,7 +1113,8 @@ impl InstanceFilter for ProxyType { matches!( c, RuntimeCall::Staking(..) | - RuntimeCall::Session(..) | RuntimeCall::Utility(..) | + RuntimeCall::Session(..) | + RuntimeCall::Utility(..) | RuntimeCall::FastUnstake(..) | RuntimeCall::VoterList(..) | RuntimeCall::NominationPools(..) diff --git a/polkadot/statement-table/src/generic.rs b/polkadot/statement-table/src/generic.rs index 1e90338a0f18..e3c470fcdeec 100644 --- a/polkadot/statement-table/src/generic.rs +++ b/polkadot/statement-table/src/generic.rs @@ -245,7 +245,8 @@ impl CandidateData { pub fn attested( &self, validity_threshold: usize, - ) -> Option> { + ) -> Option> + { let valid_votes = self.validity_votes.len(); if valid_votes < validity_threshold { return None @@ -321,7 +322,8 @@ impl Table { digest: &Ctx::Digest, context: &Ctx, minimum_backing_votes: u32, - ) -> Option> { + ) -> Option> + { self.candidate_votes.get(digest).and_then(|data| { let v_threshold = context.get_group_size(&data.group_id).map_or(usize::MAX, |len| { effective_minimum_backing_votes(len, minimum_backing_votes) diff --git a/polkadot/xcm/docs/src/cookbook/relay_token_transactor/parachain/xcm_config.rs b/polkadot/xcm/docs/src/cookbook/relay_token_transactor/parachain/xcm_config.rs index 99f17693093e..7cb230f6e006 100644 --- a/polkadot/xcm/docs/src/cookbook/relay_token_transactor/parachain/xcm_config.rs +++ b/polkadot/xcm/docs/src/cookbook/relay_token_transactor/parachain/xcm_config.rs @@ -152,7 +152,7 @@ impl pallet_xcm::Config for Runtime { // We turn off sending for these tests type SendXcmOrigin = EnsureXcmOrigin; type XcmRouter = super::super::network::ParachainXcmRouter; // Provided by xcm-simulator - // Anyone can execute XCM programs + // Anyone can execute XCM programs type ExecuteXcmOrigin = EnsureXcmOrigin; // We execute any type of program type XcmExecuteFilter = Everything; diff --git a/polkadot/xcm/docs/src/cookbook/relay_token_transactor/relay_chain/xcm_config.rs b/polkadot/xcm/docs/src/cookbook/relay_token_transactor/relay_chain/xcm_config.rs index 987bb3f9ab66..a31e664d8216 100644 --- a/polkadot/xcm/docs/src/cookbook/relay_token_transactor/relay_chain/xcm_config.rs +++ b/polkadot/xcm/docs/src/cookbook/relay_token_transactor/relay_chain/xcm_config.rs @@ -125,7 +125,7 @@ impl pallet_xcm::Config for Runtime { // No one can call `send` type SendXcmOrigin = EnsureXcmOrigin; type XcmRouter = super::super::network::RelayChainXcmRouter; // Provided by xcm-simulator - // Anyone can execute XCM programs + // Anyone can execute XCM programs type ExecuteXcmOrigin = EnsureXcmOrigin; // We execute any type of program type XcmExecuteFilter = Everything; diff --git a/polkadot/xcm/pallet-xcm-benchmarks/src/lib.rs b/polkadot/xcm/pallet-xcm-benchmarks/src/lib.rs index 4a12bb7f47c6..210b8f656377 100644 --- a/polkadot/xcm/pallet-xcm-benchmarks/src/lib.rs +++ b/polkadot/xcm/pallet-xcm-benchmarks/src/lib.rs @@ -72,7 +72,7 @@ pub fn generate_holding_assets(max_assets: u32) -> Assets { let fungibles_amount: u128 = 100; let holding_fungibles = max_assets / 2; let holding_non_fungibles = max_assets - holding_fungibles - 1; // -1 because of adding `Here` asset - // add count of `holding_fungibles` + // add count of `holding_fungibles` (0..holding_fungibles) .map(|i| { Asset { diff --git a/polkadot/xcm/xcm-builder/src/asset_conversion.rs b/polkadot/xcm/xcm-builder/src/asset_conversion.rs index 16ae05c20795..6d090b04886c 100644 --- a/polkadot/xcm/xcm-builder/src/asset_conversion.rs +++ b/polkadot/xcm/xcm-builder/src/asset_conversion.rs @@ -137,7 +137,13 @@ impl< ConvertClassId: MaybeEquivalence, ConvertInstanceId: MaybeEquivalence, > MatchesNonFungibles - for MatchedConvertedConcreteId + for MatchedConvertedConcreteId< + ClassId, + InstanceId, + MatchClassId, + ConvertClassId, + ConvertInstanceId, + > { fn matches_nonfungibles(a: &Asset) -> result::Result<(ClassId, InstanceId), MatchError> { let (instance, class) = match (&a.fun, &a.id) { diff --git a/polkadot/xcm/xcm-builder/src/nonfungibles_adapter.rs b/polkadot/xcm/xcm-builder/src/nonfungibles_adapter.rs index b111a05a4f1f..006c28954bce 100644 --- a/polkadot/xcm/xcm-builder/src/nonfungibles_adapter.rs +++ b/polkadot/xcm/xcm-builder/src/nonfungibles_adapter.rs @@ -270,7 +270,14 @@ impl< CheckAsset: AssetChecking, CheckingAccount: Get>, > TransactAsset - for NonFungiblesAdapter + for NonFungiblesAdapter< + Assets, + Matcher, + AccountIdConverter, + AccountId, + CheckAsset, + CheckingAccount, + > { fn can_check_in(origin: &Location, what: &Asset, context: &XcmContext) -> XcmResult { NonFungiblesMutateAdapter::< diff --git a/polkadot/xcm/xcm-runtime-apis/tests/fee_estimation.rs b/polkadot/xcm/xcm-runtime-apis/tests/fee_estimation.rs index e5dac7c7a04e..c742410ab9c3 100644 --- a/polkadot/xcm/xcm-runtime-apis/tests/fee_estimation.rs +++ b/polkadot/xcm/xcm-runtime-apis/tests/fee_estimation.rs @@ -197,7 +197,7 @@ fn fee_estimation_for_teleport() { fn dry_run_reserve_asset_transfer() { sp_tracing::init_for_tests(); let who = 1; // AccountId = u64. - // Native token used for fees. + // Native token used for fees. let balances = vec![(who, DeliveryFees::get() + ExistentialDeposit::get())]; // Relay token is the one we want to transfer. let assets = vec![(1, who, 100)]; // id, account_id, balance. diff --git a/substrate/client/cli/src/params/node_key_params.rs b/substrate/client/cli/src/params/node_key_params.rs index cdd637888114..70671bff8c05 100644 --- a/substrate/client/cli/src/params/node_key_params.rs +++ b/substrate/client/cli/src/params/node_key_params.rs @@ -116,8 +116,8 @@ impl NodeKeyParams { .clone() .unwrap_or_else(|| net_config_dir.join(NODE_KEY_ED25519_FILE)); if !self.unsafe_force_node_key_generation && - role.is_authority() && !is_dev && - !key_path.exists() + role.is_authority() && + !is_dev && !key_path.exists() { return Err(Error::NetworkKeyNotFound(key_path)) } diff --git a/substrate/client/consensus/grandpa/src/aux_schema.rs b/substrate/client/consensus/grandpa/src/aux_schema.rs index 8ec882591be9..c42310dcd72c 100644 --- a/substrate/client/consensus/grandpa/src/aux_schema.rs +++ b/substrate/client/consensus/grandpa/src/aux_schema.rs @@ -743,7 +743,9 @@ mod test { substrate_test_runtime_client::runtime::Block, _, _, - >(&client, H256::random(), 0, || unreachable!()) + >( + &client, H256::random(), 0, || unreachable!() + ) .unwrap(); assert_eq!( diff --git a/substrate/client/db/src/lib.rs b/substrate/client/db/src/lib.rs index ba0cbc09d53d..f505223c0304 100644 --- a/substrate/client/db/src/lib.rs +++ b/substrate/client/db/src/lib.rs @@ -1708,7 +1708,8 @@ impl Backend { ); } } else if number > best_num + One::one() && - number > One::one() && self.blockchain.header(parent_hash)?.is_none() + number > One::one() && + self.blockchain.header(parent_hash)?.is_none() { let gap = (best_num + One::one(), number - One::one()); transaction.set(columns::META, meta_keys::BLOCK_GAP, &gap.encode()); diff --git a/substrate/client/network/src/request_responses.rs b/substrate/client/network/src/request_responses.rs index 742c73833c45..4920d986c1fd 100644 --- a/substrate/client/network/src/request_responses.rs +++ b/substrate/client/network/src/request_responses.rs @@ -739,7 +739,7 @@ impl NetworkBehaviour for RequestResponsesBehaviour { } let mut fallback_requests = vec![]; - + // Poll request-responses protocols. for (protocol, (ref mut behaviour, ref mut resp_builder)) in &mut self.protocols { 'poll_protocol: while let Poll::Ready(ev) = behaviour.poll(cx, params) { @@ -909,7 +909,8 @@ impl NetworkBehaviour for RequestResponsesBehaviour { // Try using the fallback request if the protocol was not // supported. if let OutboundFailure::UnsupportedProtocols = error { - let error_bis_out = CustomOutboundFailure::UnsupportedProtocols; + let error_bis_out = + CustomOutboundFailure::UnsupportedProtocols; if let Some((fallback_request, fallback_protocol)) = fallback_request { diff --git a/substrate/client/network/src/service.rs b/substrate/client/network/src/service.rs index 9fd4370a3b54..57745fa96349 100644 --- a/substrate/client/network/src/service.rs +++ b/substrate/client/network/src/service.rs @@ -1702,18 +1702,26 @@ where SwarmEvent::Behaviour(BehaviourOut::None) => { // Ignored event from lower layers. }, - SwarmEvent::Behaviour(BehaviourOut::Message{ peer, message }) => { + SwarmEvent::Behaviour(BehaviourOut::Message { peer, message }) => { // Ignored event from lower layers. - }, - SwarmEvent::Behaviour(BehaviourOut::CustomOutboundFailure{ peer,request_id,error }) => { + }, + SwarmEvent::Behaviour(BehaviourOut::CustomOutboundFailure { + peer, + request_id, + error, + }) => { // Ignored event from lower layers. }, - SwarmEvent::Behaviour(BehaviourOut::CustomInboundFailure{ peer,request_id,error }) => { + SwarmEvent::Behaviour(BehaviourOut::CustomInboundFailure { + peer, + request_id, + error, + }) => { // Ignored event from lower layers. }, - SwarmEvent::Behaviour(BehaviourOut::CustomResponseSent{ peer,request_id }) => { + SwarmEvent::Behaviour(BehaviourOut::CustomResponseSent { peer, request_id }) => { // Ignored event from lower layers. - }, + }, SwarmEvent::ConnectionEstablished { peer_id, endpoint, diff --git a/substrate/client/network/sync/src/engine.rs b/substrate/client/network/sync/src/engine.rs index 926066165a4a..89faafda661b 100644 --- a/substrate/client/network/sync/src/engine.rs +++ b/substrate/client/network/sync/src/engine.rs @@ -56,7 +56,7 @@ use sc_consensus::{import_queue::ImportQueueService, IncomingBlock}; use sc_network::{ config::{FullNetworkConfiguration, NotificationHandshake, ProtocolId, SetConfig}, peer_store::PeerStoreProvider, - request_responses::{IfDisconnected, RequestFailure, CustomOutboundFailure}, + request_responses::{CustomOutboundFailure, IfDisconnected, RequestFailure}, service::{ traits::{Direction, NotificationConfig, NotificationEvent, ValidationResult}, NotificationMetrics, @@ -844,7 +844,8 @@ where } if !self.default_peers_set_no_slot_connected_peers.remove(&peer_id) && - info.inbound && info.info.roles.is_full() + info.inbound && + info.info.roles.is_full() { match self.num_in_peers.checked_sub(1) { Some(value) => { diff --git a/substrate/client/rpc-spec-v2/src/chain_head/test_utils.rs b/substrate/client/rpc-spec-v2/src/chain_head/test_utils.rs index ab5be1f24e5d..8eab4173f53b 100644 --- a/substrate/client/rpc-spec-v2/src/chain_head/test_utils.rs +++ b/substrate/client/rpc-spec-v2/src/chain_head/test_utils.rs @@ -346,7 +346,8 @@ where fn number( &self, hash: Block::Hash, - ) -> sc_client_api::blockchain::Result::Header as HeaderT>::Number>> { + ) -> sc_client_api::blockchain::Result::Header as HeaderT>::Number>> + { self.client.number(hash) } diff --git a/substrate/frame/bags-list/src/list/tests.rs b/substrate/frame/bags-list/src/list/tests.rs index e5fff76d75c7..fc4c4fbd088b 100644 --- a/substrate/frame/bags-list/src/list/tests.rs +++ b/substrate/frame/bags-list/src/list/tests.rs @@ -778,7 +778,7 @@ mod bags { assert_eq!(bag_1000.iter().count(), 3); bag_1000.insert_node_unchecked(node(4, None, None, bag_1000.bag_upper)); // panics in debug assert_eq!(bag_1000.iter().count(), 3); // in release we expect it to silently ignore the - // request. + // request. }); } diff --git a/substrate/frame/balances/src/tests/currency_tests.rs b/substrate/frame/balances/src/tests/currency_tests.rs index 2243859458be..a4984b34f6db 100644 --- a/substrate/frame/balances/src/tests/currency_tests.rs +++ b/substrate/frame/balances/src/tests/currency_tests.rs @@ -1017,7 +1017,7 @@ fn slash_consumed_slash_full_works() { ExtBuilder::default().existential_deposit(100).build_and_execute_with(|| { Balances::make_free_balance_be(&1, 1_000); assert_ok!(System::inc_consumers(&1)); // <-- Reference counter added here is enough for all tests - // Slashed completed in full + // Slashed completed in full assert_eq!(Balances::slash(&1, 900), (NegativeImbalance::new(900), 0)); // Account is still alive assert!(System::account_exists(&1)); @@ -1029,7 +1029,7 @@ fn slash_consumed_slash_over_works() { ExtBuilder::default().existential_deposit(100).build_and_execute_with(|| { Balances::make_free_balance_be(&1, 1_000); assert_ok!(System::inc_consumers(&1)); // <-- Reference counter added here is enough for all tests - // Slashed completed in full + // Slashed completed in full assert_eq!(Balances::slash(&1, 1_000), (NegativeImbalance::new(900), 100)); // Account is still alive assert!(System::account_exists(&1)); @@ -1041,7 +1041,7 @@ fn slash_consumed_slash_partial_works() { ExtBuilder::default().existential_deposit(100).build_and_execute_with(|| { Balances::make_free_balance_be(&1, 1_000); assert_ok!(System::inc_consumers(&1)); // <-- Reference counter added here is enough for all tests - // Slashed completed in full + // Slashed completed in full assert_eq!(Balances::slash(&1, 800), (NegativeImbalance::new(800), 0)); // Account is still alive assert!(System::account_exists(&1)); diff --git a/substrate/frame/bounties/src/lib.rs b/substrate/frame/bounties/src/lib.rs index 7b89a6e3e76f..e30d6fa2d143 100644 --- a/substrate/frame/bounties/src/lib.rs +++ b/substrate/frame/bounties/src/lib.rs @@ -459,12 +459,12 @@ pub mod pallet { Bounties::::try_mutate_exists(bounty_id, |maybe_bounty| -> DispatchResult { let bounty = maybe_bounty.as_mut().ok_or(Error::::InvalidIndex)?; - let slash_curator = |curator: &T::AccountId, - curator_deposit: &mut BalanceOf| { - let imbalance = T::Currency::slash_reserved(curator, *curator_deposit).0; - T::OnSlash::on_unbalanced(imbalance); - *curator_deposit = Zero::zero(); - }; + let slash_curator = + |curator: &T::AccountId, curator_deposit: &mut BalanceOf| { + let imbalance = T::Currency::slash_reserved(curator, *curator_deposit).0; + T::OnSlash::on_unbalanced(imbalance); + *curator_deposit = Zero::zero(); + }; match bounty.status { BountyStatus::Proposed | BountyStatus::Approved | BountyStatus::Funded => { diff --git a/substrate/frame/child-bounties/src/lib.rs b/substrate/frame/child-bounties/src/lib.rs index 911fd4c4c49f..660a30ca5d26 100644 --- a/substrate/frame/child-bounties/src/lib.rs +++ b/substrate/frame/child-bounties/src/lib.rs @@ -473,12 +473,13 @@ pub mod pallet { let child_bounty = maybe_child_bounty.as_mut().ok_or(BountiesError::::InvalidIndex)?; - let slash_curator = |curator: &T::AccountId, - curator_deposit: &mut BalanceOf| { - let imbalance = T::Currency::slash_reserved(curator, *curator_deposit).0; - T::OnSlash::on_unbalanced(imbalance); - *curator_deposit = Zero::zero(); - }; + let slash_curator = + |curator: &T::AccountId, curator_deposit: &mut BalanceOf| { + let imbalance = + T::Currency::slash_reserved(curator, *curator_deposit).0; + T::OnSlash::on_unbalanced(imbalance); + *curator_deposit = Zero::zero(); + }; match child_bounty.status { ChildBountyStatus::Added => { diff --git a/substrate/frame/examples/offchain-worker/src/tests.rs b/substrate/frame/examples/offchain-worker/src/tests.rs index b665cbbb62ae..741adbe6d26a 100644 --- a/substrate/frame/examples/offchain-worker/src/tests.rs +++ b/substrate/frame/examples/offchain-worker/src/tests.rs @@ -266,11 +266,12 @@ fn should_submit_unsigned_transaction_on_chain_for_any_account() { { assert_eq!(body, price_payload); - let signature_valid = - ::Public, - frame_system::pallet_prelude::BlockNumberFor, - > as SignedPayload>::verify::(&price_payload, signature); + let signature_valid = ::Public, + frame_system::pallet_prelude::BlockNumberFor, + > as SignedPayload>::verify::( + &price_payload, signature + ); assert!(signature_valid); } @@ -320,11 +321,12 @@ fn should_submit_unsigned_transaction_on_chain_for_all_accounts() { { assert_eq!(body, price_payload); - let signature_valid = - ::Public, - frame_system::pallet_prelude::BlockNumberFor, - > as SignedPayload>::verify::(&price_payload, signature); + let signature_valid = ::Public, + frame_system::pallet_prelude::BlockNumberFor, + > as SignedPayload>::verify::( + &price_payload, signature + ); assert!(signature_valid); } diff --git a/substrate/frame/nis/src/lib.rs b/substrate/frame/nis/src/lib.rs index 016daa4cb78b..87e2276e768d 100644 --- a/substrate/frame/nis/src/lib.rs +++ b/substrate/frame/nis/src/lib.rs @@ -756,15 +756,13 @@ pub mod pallet { .map(|_| ()) // We ignore this error as it just means the amount we're trying to deposit is // dust and the beneficiary account doesn't exist. - .or_else( - |e| { - if e == TokenError::CannotCreate.into() { - Ok(()) - } else { - Err(e) - } - }, - )?; + .or_else(|e| { + if e == TokenError::CannotCreate.into() { + Ok(()) + } else { + Err(e) + } + })?; summary.receipts_on_hold.saturating_reduce(on_hold); } T::Currency::release(&HoldReason::NftReceipt.into(), &who, amount, Exact)?; diff --git a/substrate/frame/referenda/src/types.rs b/substrate/frame/referenda/src/types.rs index 1039b288b2ae..e83f28b472cd 100644 --- a/substrate/frame/referenda/src/types.rs +++ b/substrate/frame/referenda/src/types.rs @@ -258,7 +258,8 @@ impl< Tally: Eq + PartialEq + Debug + Encode + Decode + TypeInfo + Clone, AccountId: Eq + PartialEq + Debug + Encode + Decode + TypeInfo + Clone, ScheduleAddress: Eq + PartialEq + Debug + Encode + Decode + TypeInfo + Clone, - > ReferendumInfo + > + ReferendumInfo { /// Take the Decision Deposit from `self`, if there is one. Returns an `Err` if `self` is not /// in a valid state for the Decision Deposit to be refunded. diff --git a/substrate/frame/revive/proc-macro/src/lib.rs b/substrate/frame/revive/proc-macro/src/lib.rs index 95f4110a2d76..012b4bfab9a9 100644 --- a/substrate/frame/revive/proc-macro/src/lib.rs +++ b/substrate/frame/revive/proc-macro/src/lib.rs @@ -349,18 +349,19 @@ where let Some(ident) = path.path.get_ident() else { panic!("Type needs to be ident"); }; - let size = - if ident == "i8" || - ident == "i16" || ident == "i32" || - ident == "u8" || ident == "u16" || - ident == "u32" - { - 1 - } else if ident == "i64" || ident == "u64" { - 2 - } else { - panic!("Pass by value only supports primitives"); - }; + let size = if ident == "i8" || + ident == "i16" || + ident == "i32" || + ident == "u8" || + ident == "u16" || + ident == "u32" + { + 1 + } else if ident == "i64" || ident == "u64" { + 2 + } else { + panic!("Pass by value only supports primitives"); + }; registers_used += size; if registers_used > ALLOWED_REGISTERS { return quote! { diff --git a/substrate/frame/society/src/tests.rs b/substrate/frame/society/src/tests.rs index df8e844cdad9..2a13f99855b5 100644 --- a/substrate/frame/society/src/tests.rs +++ b/substrate/frame/society/src/tests.rs @@ -281,7 +281,7 @@ fn bidding_works() { // No more candidates satisfy the requirements assert_eq!(candidacies(), vec![]); assert_ok!(Society::defender_vote(Origin::signed(10), true)); // Keep defender around - // Next period + // Next period run_to_block(16); // Same members assert_eq!(members(), vec![10, 30, 40, 50]); diff --git a/substrate/frame/staking/src/tests.rs b/substrate/frame/staking/src/tests.rs index ab2c00ca9ccc..dd178a95bec5 100644 --- a/substrate/frame/staking/src/tests.rs +++ b/substrate/frame/staking/src/tests.rs @@ -7995,7 +7995,7 @@ mod ledger_recovery { assert_eq!(Balances::balance_locked(crate::STAKING_ID, &333), lock_333_before); // OK assert_eq!(Bonded::::get(&333), Some(444)); // OK assert!(Payee::::get(&333).is_some()); // OK - // however, ledger associated with its controller was killed. + // however, ledger associated with its controller was killed. assert!(Ledger::::get(&444).is_none()); // NOK // side effects on 444 - ledger, bonded, payee, lock should be completely removed. diff --git a/substrate/frame/support/procedural/src/pallet/parse/call.rs b/substrate/frame/support/procedural/src/pallet/parse/call.rs index 4e09b86fddec..336bfe1e77dc 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/call.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/call.rs @@ -403,18 +403,19 @@ impl CallDef { } for (feeless_arg, arg) in feeless_check.inputs.iter().skip(1).zip(args.iter()) { - let feeless_arg_type = - if let syn::Pat::Type(syn::PatType { ty, .. }) = feeless_arg.clone() { - if let syn::Type::Reference(pat) = *ty { - pat.elem.clone() - } else { - let msg = "Invalid pallet::call, feeless_if closure argument must be a reference"; - return Err(syn::Error::new(ty.span(), msg)) - } + let feeless_arg_type = if let syn::Pat::Type(syn::PatType { ty, .. }) = + feeless_arg.clone() + { + if let syn::Type::Reference(pat) = *ty { + pat.elem.clone() } else { - let msg = "Invalid pallet::call, feeless_if closure argument must be a type ascription pattern"; - return Err(syn::Error::new(feeless_arg.span(), msg)) - }; + let msg = "Invalid pallet::call, feeless_if closure argument must be a reference"; + return Err(syn::Error::new(ty.span(), msg)) + } + } else { + let msg = "Invalid pallet::call, feeless_if closure argument must be a type ascription pattern"; + return Err(syn::Error::new(feeless_arg.span(), msg)) + }; if feeless_arg_type != arg.2 { let msg = diff --git a/substrate/frame/support/src/storage/types/double_map.rs b/substrate/frame/support/src/storage/types/double_map.rs index 3d227feb902f..1b3adbe60209 100644 --- a/substrate/frame/support/src/storage/types/double_map.rs +++ b/substrate/frame/support/src/storage/types/double_map.rs @@ -129,7 +129,8 @@ impl OnEmpty, MaxValues, >, - > where + > +where Prefix: StorageInstance, Hasher1: crate::hash::StorageHasher, Hasher2: crate::hash::StorageHasher, diff --git a/substrate/frame/support/src/traits/try_runtime/decode_entire_state.rs b/substrate/frame/support/src/traits/try_runtime/decode_entire_state.rs index 8dbeecd8e860..a7465c87fb27 100644 --- a/substrate/frame/support/src/traits/try_runtime/decode_entire_state.rs +++ b/substrate/frame/support/src/traits/try_runtime/decode_entire_state.rs @@ -197,7 +197,8 @@ impl TryDecodeEntireS QueryKind, OnEmpty, MaxValues, - > where + > +where Prefix: CountedStorageMapInstance, Hasher: StorageHasher, Key: FullCodec, @@ -229,7 +230,8 @@ impl QueryKind, OnEmpty, MaxValues, - > where + > +where Prefix: StorageInstance, Hasher1: StorageHasher, Key1: FullCodec, diff --git a/substrate/frame/support/test/tests/pallet.rs b/substrate/frame/support/test/tests/pallet.rs index eed8a22e8e79..72e796db5a12 100644 --- a/substrate/frame/support/test/tests/pallet.rs +++ b/substrate/frame/support/test/tests/pallet.rs @@ -2424,9 +2424,10 @@ fn post_runtime_upgrade_detects_storage_version_issues() { // any storage version "enabled". assert!( ExecutiveWithUpgradePallet4::try_runtime_upgrade(UpgradeCheckSelect::PreAndPost) - .unwrap_err() == "On chain storage version set, while the pallet \ + .unwrap_err() == + "On chain storage version set, while the pallet \ doesn't have the `#[pallet::storage_version(VERSION)]` attribute." - .into() + .into() ); }); } diff --git a/substrate/frame/transaction-payment/src/tests.rs b/substrate/frame/transaction-payment/src/tests.rs index 35d5322a6f33..bac89967d6af 100644 --- a/substrate/frame/transaction-payment/src/tests.rs +++ b/substrate/frame/transaction-payment/src/tests.rs @@ -273,8 +273,10 @@ fn signed_ext_length_fee_is_also_updated_per_congestion() { NextFeeMultiplier::::put(Multiplier::saturating_from_rational(3, 2)); let len = 10; - assert_ok!(ChargeTransactionPayment::::from(10) // tipped - .pre_dispatch(&1, CALL, &info_from_weight(Weight::from_parts(3, 0)), len)); + assert_ok!( + ChargeTransactionPayment::::from(10) // tipped + .pre_dispatch(&1, CALL, &info_from_weight(Weight::from_parts(3, 0)), len) + ); assert_eq!( Balances::free_balance(1), 100 // original diff --git a/substrate/frame/utility/src/lib.rs b/substrate/frame/utility/src/lib.rs index 3ce5b4ff8649..9db46ecec42b 100644 --- a/substrate/frame/utility/src/lib.rs +++ b/substrate/frame/utility/src/lib.rs @@ -134,8 +134,8 @@ pub mod pallet { fn batched_calls_limit() -> u32 { let allocator_limit = sp_core::MAX_POSSIBLE_ALLOCATION; let call_size = ((core::mem::size_of::<::RuntimeCall>() as u32 + - CALL_ALIGN - 1) / CALL_ALIGN) * - CALL_ALIGN; + CALL_ALIGN - 1) / + CALL_ALIGN) * CALL_ALIGN; // The margin to take into account vec doubling capacity. let margin_factor = 3; diff --git a/substrate/frame/vesting/src/tests.rs b/substrate/frame/vesting/src/tests.rs index 004da0dfbfa1..57cb59f27a4d 100644 --- a/substrate/frame/vesting/src/tests.rs +++ b/substrate/frame/vesting/src/tests.rs @@ -182,7 +182,7 @@ fn unvested_balance_should_not_transfer() { ExtBuilder::default().existential_deposit(10).build().execute_with(|| { let user1_free_balance = Balances::free_balance(&1); assert_eq!(user1_free_balance, 100); // Account 1 has free balance - // Account 1 has only 5 units vested at block 1 (plus 50 unvested) + // Account 1 has only 5 units vested at block 1 (plus 50 unvested) assert_eq!(Vesting::vesting_balance(&1), Some(45)); // Account 1 cannot send more than vested amount... assert_noop!(Balances::transfer_allow_death(Some(1).into(), 2, 56), TokenError::Frozen); @@ -194,7 +194,7 @@ fn vested_balance_should_transfer() { ExtBuilder::default().existential_deposit(10).build().execute_with(|| { let user1_free_balance = Balances::free_balance(&1); assert_eq!(user1_free_balance, 100); // Account 1 has free balance - // Account 1 has only 5 units vested at block 1 (plus 50 unvested) + // Account 1 has only 5 units vested at block 1 (plus 50 unvested) assert_eq!(Vesting::vesting_balance(&1), Some(45)); assert_ok!(Vesting::vest(Some(1).into())); assert_ok!(Balances::transfer_allow_death(Some(1).into(), 2, 55)); @@ -232,7 +232,7 @@ fn vested_balance_should_transfer_using_vest_other() { ExtBuilder::default().existential_deposit(10).build().execute_with(|| { let user1_free_balance = Balances::free_balance(&1); assert_eq!(user1_free_balance, 100); // Account 1 has free balance - // Account 1 has only 5 units vested at block 1 (plus 50 unvested) + // Account 1 has only 5 units vested at block 1 (plus 50 unvested) assert_eq!(Vesting::vesting_balance(&1), Some(45)); assert_ok!(Vesting::vest_other(Some(2).into(), 1)); assert_ok!(Balances::transfer_allow_death(Some(1).into(), 2, 55)); @@ -286,7 +286,7 @@ fn extra_balance_should_transfer() { assert_eq!(Vesting::vesting_balance(&2), Some(200)); assert_ok!(Vesting::vest(Some(2).into())); assert_ok!(Balances::transfer_allow_death(Some(2).into(), 3, 100)); // Account 2 can send extra - // units gained + // units gained }); } @@ -296,7 +296,7 @@ fn liquid_funds_should_transfer_with_delayed_vesting() { let user12_free_balance = Balances::free_balance(&12); assert_eq!(user12_free_balance, 2560); // Account 12 has free balance - // Account 12 has liquid funds + // Account 12 has liquid funds assert_eq!(Vesting::vesting_balance(&12), Some(user12_free_balance - 256 * 5)); // Account 12 has delayed vesting diff --git a/substrate/utils/wasm-builder/src/wasm_project.rs b/substrate/utils/wasm-builder/src/wasm_project.rs index a6eda078fde0..5bd7f7432314 100644 --- a/substrate/utils/wasm-builder/src/wasm_project.rs +++ b/substrate/utils/wasm-builder/src/wasm_project.rs @@ -601,9 +601,10 @@ fn project_enabled_features( // We don't want to enable the `std`/`default` feature for the wasm build and // we need to check if the feature is enabled by checking the env variable. *f != "std" && - *f != "default" && env::var(format!("CARGO_FEATURE_{}", feature_env)) - .map(|v| v == "1") - .unwrap_or_default() + *f != "default" && + env::var(format!("CARGO_FEATURE_{}", feature_env)) + .map(|v| v == "1") + .unwrap_or_default() }) .map(|d| d.0.clone()) .collect::>(); From db03bc50b5bf8d729c5064d4191f4e0e6b155852 Mon Sep 17 00:00:00 2001 From: ndkazu Date: Sat, 7 Sep 2024 14:14:41 +0900 Subject: [PATCH 17/37] Revert "cargo +nightly fmt" This reverts commit 73860e647c86f13a45568b61215b4223a72aadce. --- bridges/modules/xcm-bridge-hub/src/lib.rs | 37 +++++++++---------- .../src/on_demand/parachains.rs | 3 +- .../messages/src/message_race_strategy.rs | 6 +-- .../primitives/router/src/inbound/mod.rs | 3 +- .../runtime/runtime-common/src/lib.rs | 3 +- cumulus/pallets/parachain-system/src/lib.rs | 3 +- .../asset-hub-rococo/src/tests/teleport.rs | 4 +- .../asset-hub-westend/src/tests/teleport.rs | 4 +- .../people-rococo/src/tests/teleport.rs | 4 +- .../people-westend/src/tests/teleport.rs | 4 +- .../assets/asset-hub-rococo/src/lib.rs | 3 +- .../assets/asset-hub-westend/src/lib.rs | 3 +- .../assets/test-utils/src/test_cases.rs | 3 +- .../test-utils/src/test_cases/mod.rs | 11 +++--- cumulus/primitives/utility/src/lib.rs | 6 +-- polkadot/node/core/approval-voting/src/lib.rs | 7 +--- .../node/core/approval-voting/src/tests.rs | 3 +- .../common/src/worker/security/change_root.rs | 3 +- .../approval-distribution/src/tests.rs | 3 +- .../src/task/strategy/chunks.rs | 7 ++-- .../src/task/strategy/full.rs | 11 ++---- .../src/task/strategy/mod.rs | 6 +-- .../subsystem-bench/src/lib/statement/mod.rs | 16 ++++---- .../subsystem-types/src/runtime_client.rs | 3 +- polkadot/runtime/parachains/src/hrmp.rs | 2 +- .../parachains/src/paras_inherent/mod.rs | 25 ++++++------- polkadot/runtime/parachains/src/ump_tests.rs | 7 ++-- polkadot/runtime/westend/src/lib.rs | 3 +- polkadot/statement-table/src/generic.rs | 6 +-- .../parachain/xcm_config.rs | 2 +- .../relay_chain/xcm_config.rs | 2 +- polkadot/xcm/pallet-xcm-benchmarks/src/lib.rs | 2 +- .../xcm/xcm-builder/src/asset_conversion.rs | 8 +--- .../xcm-builder/src/nonfungibles_adapter.rs | 9 +---- .../xcm-runtime-apis/tests/fee_estimation.rs | 2 +- .../client/cli/src/params/node_key_params.rs | 4 +- .../consensus/grandpa/src/aux_schema.rs | 4 +- substrate/client/db/src/lib.rs | 3 +- .../client/network/src/request_responses.rs | 5 +-- substrate/client/network/src/service.rs | 20 +++------- substrate/client/network/sync/src/engine.rs | 5 +-- .../rpc-spec-v2/src/chain_head/test_utils.rs | 3 +- substrate/frame/bags-list/src/list/tests.rs | 2 +- .../balances/src/tests/currency_tests.rs | 6 +-- substrate/frame/bounties/src/lib.rs | 12 +++--- substrate/frame/child-bounties/src/lib.rs | 13 +++---- .../examples/offchain-worker/src/tests.rs | 22 +++++------ substrate/frame/nis/src/lib.rs | 16 ++++---- substrate/frame/referenda/src/types.rs | 3 +- substrate/frame/revive/proc-macro/src/lib.rs | 25 ++++++------- substrate/frame/society/src/tests.rs | 2 +- substrate/frame/staking/src/tests.rs | 2 +- .../procedural/src/pallet/parse/call.rs | 23 ++++++------ .../support/src/storage/types/double_map.rs | 3 +- .../traits/try_runtime/decode_entire_state.rs | 6 +-- substrate/frame/support/test/tests/pallet.rs | 5 +-- .../frame/transaction-payment/src/tests.rs | 6 +-- substrate/frame/utility/src/lib.rs | 4 +- substrate/frame/vesting/src/tests.rs | 10 ++--- .../utils/wasm-builder/src/wasm_project.rs | 7 ++-- 60 files changed, 178 insertions(+), 257 deletions(-) diff --git a/bridges/modules/xcm-bridge-hub/src/lib.rs b/bridges/modules/xcm-bridge-hub/src/lib.rs index b183d3cb4e37..02d578386a75 100644 --- a/bridges/modules/xcm-bridge-hub/src/lib.rs +++ b/bridges/modules/xcm-bridge-hub/src/lib.rs @@ -1474,26 +1474,25 @@ mod tests { let lane_id = LaneId::from_inner(Either::Left(H256::default())); let lane_id_mismatch = LaneId::from_inner(Either::Left(H256::from([1u8; 32]))); - let test_bridge_state = - |id, - bridge, - (lane_id, bridge_id), - (inbound_lane_id, outbound_lane_id), - expected_error: Option| { - Bridges::::insert(id, bridge); - LaneToBridge::::insert(lane_id, bridge_id); + let test_bridge_state = |id, + bridge, + (lane_id, bridge_id), + (inbound_lane_id, outbound_lane_id), + expected_error: Option| { + Bridges::::insert(id, bridge); + LaneToBridge::::insert(lane_id, bridge_id); - let lanes_manager = LanesManagerOf::::new(); - lanes_manager.create_inbound_lane(inbound_lane_id).unwrap(); - lanes_manager.create_outbound_lane(outbound_lane_id).unwrap(); - - let result = XcmOverBridge::do_try_state(); - if let Some(e) = expected_error { - assert_err!(result, e); - } else { - assert_ok!(result); - } - }; + let lanes_manager = LanesManagerOf::::new(); + lanes_manager.create_inbound_lane(inbound_lane_id).unwrap(); + lanes_manager.create_outbound_lane(outbound_lane_id).unwrap(); + + let result = XcmOverBridge::do_try_state(); + if let Some(e) = expected_error { + assert_err!(result, e); + } else { + assert_ok!(result); + } + }; let cleanup = |bridge_id, lane_ids| { Bridges::::remove(bridge_id); for lane_id in lane_ids { diff --git a/bridges/relays/lib-substrate-relay/src/on_demand/parachains.rs b/bridges/relays/lib-substrate-relay/src/on_demand/parachains.rs index 96eba0af988c..2ef86f48ecbe 100644 --- a/bridges/relays/lib-substrate-relay/src/on_demand/parachains.rs +++ b/bridges/relays/lib-substrate-relay/src/on_demand/parachains.rs @@ -664,8 +664,7 @@ impl<'a, P: SubstrateParachainsPipeline, SourceRelayClnt, TargetClnt> for ( &'a OnDemandParachainsRelay, &'a ParachainsSource, - ) -where + ) where SourceRelayClnt: Client, TargetClnt: Client, { diff --git a/bridges/relays/messages/src/message_race_strategy.rs b/bridges/relays/messages/src/message_race_strategy.rs index 1303fcfedebd..3a532331d79d 100644 --- a/bridges/relays/messages/src/message_race_strategy.rs +++ b/bridges/relays/messages/src/message_race_strategy.rs @@ -67,8 +67,7 @@ impl< TargetHeaderHash, SourceNoncesRange, Proof, - > -where + > where SourceHeaderHash: Clone, SourceHeaderNumber: Clone + Ord, SourceNoncesRange: NoncesRange, @@ -190,8 +189,7 @@ impl< TargetHeaderHash, SourceNoncesRange, Proof, - > -where + > where SourceHeaderHash: Clone + Debug + Send + Sync, SourceHeaderNumber: Clone + Ord + Debug + Send + Sync, SourceNoncesRange: NoncesRange + Debug + Send + Sync, diff --git a/bridges/snowbridge/primitives/router/src/inbound/mod.rs b/bridges/snowbridge/primitives/router/src/inbound/mod.rs index 4179e8b37a42..54e47a7a8b6a 100644 --- a/bridges/snowbridge/primitives/router/src/inbound/mod.rs +++ b/bridges/snowbridge/primitives/router/src/inbound/mod.rs @@ -128,8 +128,7 @@ impl -where + > where CreateAssetCall: Get, CreateAssetDeposit: Get, InboundQueuePalletInstance: Get, diff --git a/bridges/snowbridge/runtime/runtime-common/src/lib.rs b/bridges/snowbridge/runtime/runtime-common/src/lib.rs index 0b1a74b232a0..aae45520ff4b 100644 --- a/bridges/snowbridge/runtime/runtime-common/src/lib.rs +++ b/bridges/snowbridge/runtime/runtime-common/src/lib.rs @@ -50,8 +50,7 @@ impl -where + > where Balance: BaseArithmetic + Unsigned + Copy + From + Into + Debug, AccountId: Clone + FullCodec, FeeAssetLocation: Get, diff --git a/cumulus/pallets/parachain-system/src/lib.rs b/cumulus/pallets/parachain-system/src/lib.rs index 7c2903280a7e..882dcb68fbbe 100644 --- a/cumulus/pallets/parachain-system/src/lib.rs +++ b/cumulus/pallets/parachain-system/src/lib.rs @@ -366,8 +366,7 @@ pub mod pallet { let maximum_channels = host_config .hrmp_max_message_num_per_candidate - .min(>::take()) - as usize; + .min(>::take()) as usize; // Note: this internally calls the `GetChannelInfo` implementation for this // pallet, which draws on the `RelevantMessagingState`. That in turn has diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs index d16bf620cdfb..c8da801a14bf 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs @@ -265,9 +265,7 @@ fn limited_teleport_native_assets_from_system_para_to_relay_fails() { let delivery_fees = AssetHubRococo::execute_with(|| { xcm_helpers::teleport_assets_delivery_fees::< ::XcmSender, - >( - test.args.assets.clone(), 0, test.args.weight_limit, test.args.beneficiary, test.args.dest - ) + >(test.args.assets.clone(), 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) }); // Sender's balance is reduced diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs index c0f31d20513d..15d39858acca 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs @@ -265,9 +265,7 @@ fn limited_teleport_native_assets_from_system_para_to_relay_fails() { let delivery_fees = AssetHubWestend::execute_with(|| { xcm_helpers::teleport_assets_delivery_fees::< ::XcmSender, - >( - test.args.assets.clone(), 0, test.args.weight_limit, test.args.beneficiary, test.args.dest - ) + >(test.args.assets.clone(), 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) }); // Sender's balance is reduced diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/teleport.rs index 2619ca7591d0..44e6b3934f0e 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/teleport.rs @@ -107,9 +107,7 @@ fn limited_teleport_native_assets_from_system_para_to_relay_fails() { let delivery_fees = PeopleRococo::execute_with(|| { xcm_helpers::teleport_assets_delivery_fees::< ::XcmSender, - >( - test.args.assets.clone(), 0, test.args.weight_limit, test.args.beneficiary, test.args.dest - ) + >(test.args.assets.clone(), 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) }); // Sender's balance is reduced diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-westend/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-westend/src/tests/teleport.rs index d9a2c23ac0c6..83888031723f 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-westend/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-westend/src/tests/teleport.rs @@ -107,9 +107,7 @@ fn limited_teleport_native_assets_from_system_para_to_relay_fails() { let delivery_fees = PeopleWestend::execute_with(|| { xcm_helpers::teleport_assets_delivery_fees::< ::XcmSender, - >( - test.args.assets.clone(), 0, test.args.weight_limit, test.args.beneficiary, test.args.dest - ) + >(test.args.assets.clone(), 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) }); // Sender's balance is reduced diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs index 96a2fd5bf292..2f3fb6b68c4a 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs @@ -546,8 +546,7 @@ impl InstanceFilter for ProxyType { RuntimeCall::Utility { .. } | RuntimeCall::Multisig { .. } | RuntimeCall::NftFractionalization { .. } | - RuntimeCall::Nfts { .. } | - RuntimeCall::Uniques { .. } + RuntimeCall::Nfts { .. } | RuntimeCall::Uniques { .. } ) }, ProxyType::AssetOwner => matches!( diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs index 5d988f89d25c..97dbe7c361c1 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs @@ -542,8 +542,7 @@ impl InstanceFilter for ProxyType { RuntimeCall::Utility { .. } | RuntimeCall::Multisig { .. } | RuntimeCall::NftFractionalization { .. } | - RuntimeCall::Nfts { .. } | - RuntimeCall::Uniques { .. } + RuntimeCall::Nfts { .. } | RuntimeCall::Uniques { .. } ) }, ProxyType::AssetOwner => matches!( diff --git a/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs b/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs index c80222142304..67b585ecfe86 100644 --- a/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs +++ b/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs @@ -1143,8 +1143,7 @@ pub fn create_and_manage_foreign_assets_for_local_consensus_parachain_assets_wor .with_balances(vec![( foreign_creator_as_account_id.clone(), existential_deposit + - asset_deposit + - metadata_deposit_base + + asset_deposit + metadata_deposit_base + metadata_deposit_per_byte_eta + buy_execution_fee_amount.into() + buy_execution_fee_amount.into(), diff --git a/cumulus/parachains/runtimes/bridge-hubs/test-utils/src/test_cases/mod.rs b/cumulus/parachains/runtimes/bridge-hubs/test-utils/src/test_cases/mod.rs index b8c2359f8aca..de117982b26f 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/test-utils/src/test_cases/mod.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/test-utils/src/test_cases/mod.rs @@ -504,12 +504,11 @@ pub fn message_dispatch_routing_works< // 2. this message is sent from other global consensus with destination of this Runtime // sibling parachain (HRMP) - let bridging_message = - test_data::simulate_message_exporter_on_bridged_chain::< - BridgedNetwork, - NetworkWithParentCount, - AlwaysLatest, - >((RuntimeNetwork::get(), [Parachain(sibling_parachain_id)].into())); + let bridging_message = test_data::simulate_message_exporter_on_bridged_chain::< + BridgedNetwork, + NetworkWithParentCount, + AlwaysLatest, + >((RuntimeNetwork::get(), [Parachain(sibling_parachain_id)].into())); // 2.1. WITHOUT opened hrmp channel -> RoutingError let result = diff --git a/cumulus/primitives/utility/src/lib.rs b/cumulus/primitives/utility/src/lib.rs index 4f0626529b6c..e568c79bb6a0 100644 --- a/cumulus/primitives/utility/src/lib.rs +++ b/cumulus/primitives/utility/src/lib.rs @@ -385,8 +385,7 @@ impl< FungiblesAssetMatcher, OnUnbalanced, AccountId, - > -where + > where Fungibles::Balance: Into, { fn new() -> Self { @@ -546,8 +545,7 @@ impl< FungiblesAssetMatcher, OnUnbalanced, AccountId, - > -where + > where Fungibles::Balance: Into, { fn drop(&mut self) { diff --git a/polkadot/node/core/approval-voting/src/lib.rs b/polkadot/node/core/approval-voting/src/lib.rs index 78a0567168d0..942922cba6df 100644 --- a/polkadot/node/core/approval-voting/src/lib.rs +++ b/polkadot/node/core/approval-voting/src/lib.rs @@ -2415,12 +2415,7 @@ fn schedule_wakeup_action( last_assignment_tick.map(|l| l + APPROVAL_DELAY).filter(|t| t > &tick_now), next_no_show, ) - .map(|tick| Action::ScheduleWakeup { - block_hash, - block_number, - candidate_hash, - tick, - }) + .map(|tick| Action::ScheduleWakeup { block_hash, block_number, candidate_hash, tick }) }, RequiredTranches::Pending { considered, next_no_show, clock_drift, .. } => { // select the minimum of `next_no_show`, or the tick of the next non-empty tranche diff --git a/polkadot/node/core/approval-voting/src/tests.rs b/polkadot/node/core/approval-voting/src/tests.rs index 8a3102f22d0d..7126f209a94f 100644 --- a/polkadot/node/core/approval-voting/src/tests.rs +++ b/polkadot/node/core/approval-voting/src/tests.rs @@ -263,8 +263,7 @@ where _relay_vrf_story: polkadot_node_primitives::approval::v1::RelayVRFStory, _assignment: &polkadot_node_primitives::approval::v2::AssignmentCertV2, _backing_groups: Vec, - ) -> Result - { + ) -> Result { self.1(validator_index) } } diff --git a/polkadot/node/core/pvf/common/src/worker/security/change_root.rs b/polkadot/node/core/pvf/common/src/worker/security/change_root.rs index fcfaf6541c29..9ec66906819f 100644 --- a/polkadot/node/core/pvf/common/src/worker/security/change_root.rs +++ b/polkadot/node/core/pvf/common/src/worker/security/change_root.rs @@ -124,8 +124,7 @@ fn try_restrict(worker_info: &WorkerInfo) -> Result<()> { libc::MS_BIND | libc::MS_REC | libc::MS_NOEXEC | libc::MS_NODEV | libc::MS_NOSUID | - libc::MS_NOATIME | - additional_flags, + libc::MS_NOATIME | additional_flags, ptr::null(), // ignored when MS_BIND is used ) < 0 { diff --git a/polkadot/node/network/approval-distribution/src/tests.rs b/polkadot/node/network/approval-distribution/src/tests.rs index 83b5eb7684b9..4ee9320e0e45 100644 --- a/polkadot/node/network/approval-distribution/src/tests.rs +++ b/polkadot/node/network/approval-distribution/src/tests.rs @@ -535,8 +535,7 @@ impl AssignmentCriteria for MockAssignmentCriteria { _relay_vrf_story: polkadot_node_primitives::approval::v1::RelayVRFStory, _assignment: &polkadot_node_primitives::approval::v2::AssignmentCertV2, _backing_groups: Vec, - ) -> Result - { + ) -> Result { self.tranche } } diff --git a/polkadot/node/network/availability-recovery/src/task/strategy/chunks.rs b/polkadot/node/network/availability-recovery/src/task/strategy/chunks.rs index f4bb8b925059..b6376a5b543e 100644 --- a/polkadot/node/network/availability-recovery/src/task/strategy/chunks.rs +++ b/polkadot/node/network/availability-recovery/src/task/strategy/chunks.rs @@ -107,10 +107,9 @@ impl FetchChunks { state: &mut State, common_params: &RecoveryParams, ) -> Result { - let recovery_duration = - common_params - .metrics - .time_erasure_recovery(RecoveryStrategy::::strategy_type(self)); + let recovery_duration = common_params + .metrics + .time_erasure_recovery(RecoveryStrategy::::strategy_type(self)); // Send request to reconstruct available data from chunks. let (avilable_data_tx, available_data_rx) = oneshot::channel(); diff --git a/polkadot/node/network/availability-recovery/src/task/strategy/full.rs b/polkadot/node/network/availability-recovery/src/task/strategy/full.rs index 61a629582add..c90c6477131c 100644 --- a/polkadot/node/network/availability-recovery/src/task/strategy/full.rs +++ b/polkadot/node/network/availability-recovery/src/task/strategy/full.rs @@ -19,17 +19,16 @@ use crate::{ ErasureTask, PostRecoveryCheck, LOG_TARGET, }; -use futures::{channel::oneshot, SinkExt}; use polkadot_node_network_protocol::request_response::{ self as req_res, outgoing::RequestError, OutgoingRequest, Recipient, Requests, }; use polkadot_node_primitives::AvailableData; use polkadot_node_subsystem::{messages::NetworkBridgeTxMessage, overseer, RecoveryError}; use polkadot_primitives::ValidatorIndex; +use sc_network::{IfDisconnected, OutboundFailure, RequestFailure}; +use sc_network::request_responses::CustomOutboundFailure; +use futures::{channel::oneshot, SinkExt}; use rand::seq::SliceRandom; -use sc_network::{ - request_responses::CustomOutboundFailure, IfDisconnected, OutboundFailure, RequestFailure, -}; /// Parameters specific to the `FetchFull` strategy. pub struct FetchFullParams { @@ -154,9 +153,7 @@ impl RecoveryStrategy RequestError::InvalidResponse(_) => common_params.metrics.on_full_request_invalid(), RequestError::NetworkError(req_failure) => { - if let RequestFailure::Network(CustomOutboundFailure::Timeout) = - req_failure - { + if let RequestFailure::Network(CustomOutboundFailure::Timeout) = req_failure { common_params.metrics.on_full_request_timeout(); } else { common_params.metrics.on_full_request_error(); diff --git a/polkadot/node/network/availability-recovery/src/task/strategy/mod.rs b/polkadot/node/network/availability-recovery/src/task/strategy/mod.rs index b3d5786cae5e..789b70eafdb3 100644 --- a/polkadot/node/network/availability-recovery/src/task/strategy/mod.rs +++ b/polkadot/node/network/availability-recovery/src/task/strategy/mod.rs @@ -30,6 +30,7 @@ use crate::{ }; use codec::Decode; +use sc_network::request_responses::CustomOutboundFailure; use futures::{channel::oneshot, SinkExt}; use polkadot_erasure_coding::branch_hash; #[cfg(not(test))] @@ -43,10 +44,7 @@ use polkadot_node_subsystem::{ overseer, RecoveryError, }; use polkadot_primitives::{AuthorityDiscoveryId, BlakeTwo256, ChunkIndex, HashT, ValidatorIndex}; -use sc_network::{ - request_responses::CustomOutboundFailure, IfDisconnected, OutboundFailure, ProtocolName, - RequestFailure, -}; +use sc_network::{IfDisconnected, OutboundFailure, ProtocolName, RequestFailure}; use std::{ collections::{BTreeMap, HashMap, VecDeque}, time::Duration, diff --git a/polkadot/node/subsystem-bench/src/lib/statement/mod.rs b/polkadot/node/subsystem-bench/src/lib/statement/mod.rs index 8cb7eee22b2d..bd47505f56ae 100644 --- a/polkadot/node/subsystem-bench/src/lib/statement/mod.rs +++ b/polkadot/node/subsystem-bench/src/lib/statement/mod.rs @@ -114,14 +114,14 @@ fn build_overseer( state.pvd.clone(), state.own_backing_group.clone(), ); - let (statement_req_receiver, statement_req_cfg) = - IncomingRequest::get_config_receiver::>( - &ReqProtocolNames::new(GENESIS_HASH, None), - ); - let (candidate_req_receiver, candidate_req_cfg) = - IncomingRequest::get_config_receiver::>( - &ReqProtocolNames::new(GENESIS_HASH, None), - ); + let (statement_req_receiver, statement_req_cfg) = IncomingRequest::get_config_receiver::< + Block, + sc_network::NetworkWorker, + >(&ReqProtocolNames::new(GENESIS_HASH, None)); + let (candidate_req_receiver, candidate_req_cfg) = IncomingRequest::get_config_receiver::< + Block, + sc_network::NetworkWorker, + >(&ReqProtocolNames::new(GENESIS_HASH, None)); let keystore = make_keystore(); let subsystem = StatementDistributionSubsystem::new( keystore.clone(), diff --git a/polkadot/node/subsystem-types/src/runtime_client.rs b/polkadot/node/subsystem-types/src/runtime_client.rs index a8af8b7996f9..7938223df23b 100644 --- a/polkadot/node/subsystem-types/src/runtime_client.rs +++ b/polkadot/node/subsystem-types/src/runtime_client.rs @@ -665,8 +665,7 @@ where fn number( &self, hash: Block::Hash, - ) -> sc_client_api::blockchain::Result::Header as HeaderT>::Number>> - { + ) -> sc_client_api::blockchain::Result::Header as HeaderT>::Number>> { self.client.number(hash) } diff --git a/polkadot/runtime/parachains/src/hrmp.rs b/polkadot/runtime/parachains/src/hrmp.rs index 220543f00ec3..b149404b41b8 100644 --- a/polkadot/runtime/parachains/src/hrmp.rs +++ b/polkadot/runtime/parachains/src/hrmp.rs @@ -945,7 +945,7 @@ impl Pallet { outgoing_paras.len() as u32 )) .saturating_add(::WeightInfo::force_process_hrmp_close( - outgoing_paras.len() as u32, + outgoing_paras.len() as u32 )) } diff --git a/polkadot/runtime/parachains/src/paras_inherent/mod.rs b/polkadot/runtime/parachains/src/paras_inherent/mod.rs index 70c4ba72d58e..84d8299cd29c 100644 --- a/polkadot/runtime/parachains/src/paras_inherent/mod.rs +++ b/polkadot/runtime/parachains/src/paras_inherent/mod.rs @@ -1216,19 +1216,18 @@ fn filter_backed_statements_from_disabled_validators< // Get relay parent block number of the candidate. We need this to get the group index // assigned to this core at this block number - let relay_parent_block_number = match allowed_relay_parents - .acquire_info(bc.descriptor().relay_parent(), None) - { - Some((_, block_num)) => block_num, - None => { - log::debug!( - target: LOG_TARGET, - "Relay parent {:?} for candidate is not in the allowed relay parents. Dropping the candidate.", - bc.descriptor().relay_parent() - ); - return false - }, - }; + let relay_parent_block_number = + match allowed_relay_parents.acquire_info(bc.descriptor().relay_parent(), None) { + Some((_, block_num)) => block_num, + None => { + log::debug!( + target: LOG_TARGET, + "Relay parent {:?} for candidate is not in the allowed relay parents. Dropping the candidate.", + bc.descriptor().relay_parent() + ); + return false + }, + }; // Get the group index for the core let group_idx = match scheduler::Pallet::::group_assigned_to_core( diff --git a/polkadot/runtime/parachains/src/ump_tests.rs b/polkadot/runtime/parachains/src/ump_tests.rs index 91571859ecf0..d914bf8b6661 100644 --- a/polkadot/runtime/parachains/src/ump_tests.rs +++ b/polkadot/runtime/parachains/src/ump_tests.rs @@ -462,11 +462,10 @@ fn verify_relay_dispatch_queue_size_is_externally_accessible() { fn assert_queue_size(para: ParaId, count: u32, size: u32) { #[allow(deprecated)] - let raw_queue_size = sp_io::storage::get(&well_known_keys::relay_dispatch_queue_size(para)) - .expect( - "enqueuing a message should create the dispatch queue\ + let raw_queue_size = sp_io::storage::get(&well_known_keys::relay_dispatch_queue_size(para)).expect( + "enqueuing a message should create the dispatch queue\ and it should be accessible via the well known keys", - ); + ); let (c, s) = <(u32, u32)>::decode(&mut &raw_queue_size[..]) .expect("the dispatch queue size should be decodable into (u32, u32)"); assert_eq!((c, s), (count, size)); diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index 479ed83f7236..b02c2d8c671e 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -1113,8 +1113,7 @@ impl InstanceFilter for ProxyType { matches!( c, RuntimeCall::Staking(..) | - RuntimeCall::Session(..) | - RuntimeCall::Utility(..) | + RuntimeCall::Session(..) | RuntimeCall::Utility(..) | RuntimeCall::FastUnstake(..) | RuntimeCall::VoterList(..) | RuntimeCall::NominationPools(..) diff --git a/polkadot/statement-table/src/generic.rs b/polkadot/statement-table/src/generic.rs index e3c470fcdeec..1e90338a0f18 100644 --- a/polkadot/statement-table/src/generic.rs +++ b/polkadot/statement-table/src/generic.rs @@ -245,8 +245,7 @@ impl CandidateData { pub fn attested( &self, validity_threshold: usize, - ) -> Option> - { + ) -> Option> { let valid_votes = self.validity_votes.len(); if valid_votes < validity_threshold { return None @@ -322,8 +321,7 @@ impl Table { digest: &Ctx::Digest, context: &Ctx, minimum_backing_votes: u32, - ) -> Option> - { + ) -> Option> { self.candidate_votes.get(digest).and_then(|data| { let v_threshold = context.get_group_size(&data.group_id).map_or(usize::MAX, |len| { effective_minimum_backing_votes(len, minimum_backing_votes) diff --git a/polkadot/xcm/docs/src/cookbook/relay_token_transactor/parachain/xcm_config.rs b/polkadot/xcm/docs/src/cookbook/relay_token_transactor/parachain/xcm_config.rs index 7cb230f6e006..99f17693093e 100644 --- a/polkadot/xcm/docs/src/cookbook/relay_token_transactor/parachain/xcm_config.rs +++ b/polkadot/xcm/docs/src/cookbook/relay_token_transactor/parachain/xcm_config.rs @@ -152,7 +152,7 @@ impl pallet_xcm::Config for Runtime { // We turn off sending for these tests type SendXcmOrigin = EnsureXcmOrigin; type XcmRouter = super::super::network::ParachainXcmRouter; // Provided by xcm-simulator - // Anyone can execute XCM programs + // Anyone can execute XCM programs type ExecuteXcmOrigin = EnsureXcmOrigin; // We execute any type of program type XcmExecuteFilter = Everything; diff --git a/polkadot/xcm/docs/src/cookbook/relay_token_transactor/relay_chain/xcm_config.rs b/polkadot/xcm/docs/src/cookbook/relay_token_transactor/relay_chain/xcm_config.rs index a31e664d8216..987bb3f9ab66 100644 --- a/polkadot/xcm/docs/src/cookbook/relay_token_transactor/relay_chain/xcm_config.rs +++ b/polkadot/xcm/docs/src/cookbook/relay_token_transactor/relay_chain/xcm_config.rs @@ -125,7 +125,7 @@ impl pallet_xcm::Config for Runtime { // No one can call `send` type SendXcmOrigin = EnsureXcmOrigin; type XcmRouter = super::super::network::RelayChainXcmRouter; // Provided by xcm-simulator - // Anyone can execute XCM programs + // Anyone can execute XCM programs type ExecuteXcmOrigin = EnsureXcmOrigin; // We execute any type of program type XcmExecuteFilter = Everything; diff --git a/polkadot/xcm/pallet-xcm-benchmarks/src/lib.rs b/polkadot/xcm/pallet-xcm-benchmarks/src/lib.rs index 210b8f656377..4a12bb7f47c6 100644 --- a/polkadot/xcm/pallet-xcm-benchmarks/src/lib.rs +++ b/polkadot/xcm/pallet-xcm-benchmarks/src/lib.rs @@ -72,7 +72,7 @@ pub fn generate_holding_assets(max_assets: u32) -> Assets { let fungibles_amount: u128 = 100; let holding_fungibles = max_assets / 2; let holding_non_fungibles = max_assets - holding_fungibles - 1; // -1 because of adding `Here` asset - // add count of `holding_fungibles` + // add count of `holding_fungibles` (0..holding_fungibles) .map(|i| { Asset { diff --git a/polkadot/xcm/xcm-builder/src/asset_conversion.rs b/polkadot/xcm/xcm-builder/src/asset_conversion.rs index 6d090b04886c..16ae05c20795 100644 --- a/polkadot/xcm/xcm-builder/src/asset_conversion.rs +++ b/polkadot/xcm/xcm-builder/src/asset_conversion.rs @@ -137,13 +137,7 @@ impl< ConvertClassId: MaybeEquivalence, ConvertInstanceId: MaybeEquivalence, > MatchesNonFungibles - for MatchedConvertedConcreteId< - ClassId, - InstanceId, - MatchClassId, - ConvertClassId, - ConvertInstanceId, - > + for MatchedConvertedConcreteId { fn matches_nonfungibles(a: &Asset) -> result::Result<(ClassId, InstanceId), MatchError> { let (instance, class) = match (&a.fun, &a.id) { diff --git a/polkadot/xcm/xcm-builder/src/nonfungibles_adapter.rs b/polkadot/xcm/xcm-builder/src/nonfungibles_adapter.rs index 006c28954bce..b111a05a4f1f 100644 --- a/polkadot/xcm/xcm-builder/src/nonfungibles_adapter.rs +++ b/polkadot/xcm/xcm-builder/src/nonfungibles_adapter.rs @@ -270,14 +270,7 @@ impl< CheckAsset: AssetChecking, CheckingAccount: Get>, > TransactAsset - for NonFungiblesAdapter< - Assets, - Matcher, - AccountIdConverter, - AccountId, - CheckAsset, - CheckingAccount, - > + for NonFungiblesAdapter { fn can_check_in(origin: &Location, what: &Asset, context: &XcmContext) -> XcmResult { NonFungiblesMutateAdapter::< diff --git a/polkadot/xcm/xcm-runtime-apis/tests/fee_estimation.rs b/polkadot/xcm/xcm-runtime-apis/tests/fee_estimation.rs index c742410ab9c3..e5dac7c7a04e 100644 --- a/polkadot/xcm/xcm-runtime-apis/tests/fee_estimation.rs +++ b/polkadot/xcm/xcm-runtime-apis/tests/fee_estimation.rs @@ -197,7 +197,7 @@ fn fee_estimation_for_teleport() { fn dry_run_reserve_asset_transfer() { sp_tracing::init_for_tests(); let who = 1; // AccountId = u64. - // Native token used for fees. + // Native token used for fees. let balances = vec![(who, DeliveryFees::get() + ExistentialDeposit::get())]; // Relay token is the one we want to transfer. let assets = vec![(1, who, 100)]; // id, account_id, balance. diff --git a/substrate/client/cli/src/params/node_key_params.rs b/substrate/client/cli/src/params/node_key_params.rs index 70671bff8c05..cdd637888114 100644 --- a/substrate/client/cli/src/params/node_key_params.rs +++ b/substrate/client/cli/src/params/node_key_params.rs @@ -116,8 +116,8 @@ impl NodeKeyParams { .clone() .unwrap_or_else(|| net_config_dir.join(NODE_KEY_ED25519_FILE)); if !self.unsafe_force_node_key_generation && - role.is_authority() && - !is_dev && !key_path.exists() + role.is_authority() && !is_dev && + !key_path.exists() { return Err(Error::NetworkKeyNotFound(key_path)) } diff --git a/substrate/client/consensus/grandpa/src/aux_schema.rs b/substrate/client/consensus/grandpa/src/aux_schema.rs index c42310dcd72c..8ec882591be9 100644 --- a/substrate/client/consensus/grandpa/src/aux_schema.rs +++ b/substrate/client/consensus/grandpa/src/aux_schema.rs @@ -743,9 +743,7 @@ mod test { substrate_test_runtime_client::runtime::Block, _, _, - >( - &client, H256::random(), 0, || unreachable!() - ) + >(&client, H256::random(), 0, || unreachable!()) .unwrap(); assert_eq!( diff --git a/substrate/client/db/src/lib.rs b/substrate/client/db/src/lib.rs index 3391dace82a7..eadb26254a18 100644 --- a/substrate/client/db/src/lib.rs +++ b/substrate/client/db/src/lib.rs @@ -1696,8 +1696,7 @@ impl Backend { block_gap_updated = true; } } else if number > best_num + One::one() && - number > One::one() && - self.blockchain.header(parent_hash)?.is_none() + number > One::one() && self.blockchain.header(parent_hash)?.is_none() { let gap = (best_num + One::one(), number - One::one()); transaction.set(columns::META, meta_keys::BLOCK_GAP, &gap.encode()); diff --git a/substrate/client/network/src/request_responses.rs b/substrate/client/network/src/request_responses.rs index 4920d986c1fd..742c73833c45 100644 --- a/substrate/client/network/src/request_responses.rs +++ b/substrate/client/network/src/request_responses.rs @@ -739,7 +739,7 @@ impl NetworkBehaviour for RequestResponsesBehaviour { } let mut fallback_requests = vec![]; - + // Poll request-responses protocols. for (protocol, (ref mut behaviour, ref mut resp_builder)) in &mut self.protocols { 'poll_protocol: while let Poll::Ready(ev) = behaviour.poll(cx, params) { @@ -909,8 +909,7 @@ impl NetworkBehaviour for RequestResponsesBehaviour { // Try using the fallback request if the protocol was not // supported. if let OutboundFailure::UnsupportedProtocols = error { - let error_bis_out = - CustomOutboundFailure::UnsupportedProtocols; + let error_bis_out = CustomOutboundFailure::UnsupportedProtocols; if let Some((fallback_request, fallback_protocol)) = fallback_request { diff --git a/substrate/client/network/src/service.rs b/substrate/client/network/src/service.rs index 57745fa96349..9fd4370a3b54 100644 --- a/substrate/client/network/src/service.rs +++ b/substrate/client/network/src/service.rs @@ -1702,26 +1702,18 @@ where SwarmEvent::Behaviour(BehaviourOut::None) => { // Ignored event from lower layers. }, - SwarmEvent::Behaviour(BehaviourOut::Message { peer, message }) => { + SwarmEvent::Behaviour(BehaviourOut::Message{ peer, message }) => { // Ignored event from lower layers. - }, - SwarmEvent::Behaviour(BehaviourOut::CustomOutboundFailure { - peer, - request_id, - error, - }) => { + }, + SwarmEvent::Behaviour(BehaviourOut::CustomOutboundFailure{ peer,request_id,error }) => { // Ignored event from lower layers. }, - SwarmEvent::Behaviour(BehaviourOut::CustomInboundFailure { - peer, - request_id, - error, - }) => { + SwarmEvent::Behaviour(BehaviourOut::CustomInboundFailure{ peer,request_id,error }) => { // Ignored event from lower layers. }, - SwarmEvent::Behaviour(BehaviourOut::CustomResponseSent { peer, request_id }) => { + SwarmEvent::Behaviour(BehaviourOut::CustomResponseSent{ peer,request_id }) => { // Ignored event from lower layers. - }, + }, SwarmEvent::ConnectionEstablished { peer_id, endpoint, diff --git a/substrate/client/network/sync/src/engine.rs b/substrate/client/network/sync/src/engine.rs index 89faafda661b..926066165a4a 100644 --- a/substrate/client/network/sync/src/engine.rs +++ b/substrate/client/network/sync/src/engine.rs @@ -56,7 +56,7 @@ use sc_consensus::{import_queue::ImportQueueService, IncomingBlock}; use sc_network::{ config::{FullNetworkConfiguration, NotificationHandshake, ProtocolId, SetConfig}, peer_store::PeerStoreProvider, - request_responses::{CustomOutboundFailure, IfDisconnected, RequestFailure}, + request_responses::{IfDisconnected, RequestFailure, CustomOutboundFailure}, service::{ traits::{Direction, NotificationConfig, NotificationEvent, ValidationResult}, NotificationMetrics, @@ -844,8 +844,7 @@ where } if !self.default_peers_set_no_slot_connected_peers.remove(&peer_id) && - info.inbound && - info.info.roles.is_full() + info.inbound && info.info.roles.is_full() { match self.num_in_peers.checked_sub(1) { Some(value) => { diff --git a/substrate/client/rpc-spec-v2/src/chain_head/test_utils.rs b/substrate/client/rpc-spec-v2/src/chain_head/test_utils.rs index fa10fde388f9..073ee34a79f3 100644 --- a/substrate/client/rpc-spec-v2/src/chain_head/test_utils.rs +++ b/substrate/client/rpc-spec-v2/src/chain_head/test_utils.rs @@ -343,8 +343,7 @@ where fn number( &self, hash: Block::Hash, - ) -> sc_client_api::blockchain::Result::Header as HeaderT>::Number>> - { + ) -> sc_client_api::blockchain::Result::Header as HeaderT>::Number>> { self.client.number(hash) } diff --git a/substrate/frame/bags-list/src/list/tests.rs b/substrate/frame/bags-list/src/list/tests.rs index fc4c4fbd088b..e5fff76d75c7 100644 --- a/substrate/frame/bags-list/src/list/tests.rs +++ b/substrate/frame/bags-list/src/list/tests.rs @@ -778,7 +778,7 @@ mod bags { assert_eq!(bag_1000.iter().count(), 3); bag_1000.insert_node_unchecked(node(4, None, None, bag_1000.bag_upper)); // panics in debug assert_eq!(bag_1000.iter().count(), 3); // in release we expect it to silently ignore the - // request. + // request. }); } diff --git a/substrate/frame/balances/src/tests/currency_tests.rs b/substrate/frame/balances/src/tests/currency_tests.rs index a4984b34f6db..2243859458be 100644 --- a/substrate/frame/balances/src/tests/currency_tests.rs +++ b/substrate/frame/balances/src/tests/currency_tests.rs @@ -1017,7 +1017,7 @@ fn slash_consumed_slash_full_works() { ExtBuilder::default().existential_deposit(100).build_and_execute_with(|| { Balances::make_free_balance_be(&1, 1_000); assert_ok!(System::inc_consumers(&1)); // <-- Reference counter added here is enough for all tests - // Slashed completed in full + // Slashed completed in full assert_eq!(Balances::slash(&1, 900), (NegativeImbalance::new(900), 0)); // Account is still alive assert!(System::account_exists(&1)); @@ -1029,7 +1029,7 @@ fn slash_consumed_slash_over_works() { ExtBuilder::default().existential_deposit(100).build_and_execute_with(|| { Balances::make_free_balance_be(&1, 1_000); assert_ok!(System::inc_consumers(&1)); // <-- Reference counter added here is enough for all tests - // Slashed completed in full + // Slashed completed in full assert_eq!(Balances::slash(&1, 1_000), (NegativeImbalance::new(900), 100)); // Account is still alive assert!(System::account_exists(&1)); @@ -1041,7 +1041,7 @@ fn slash_consumed_slash_partial_works() { ExtBuilder::default().existential_deposit(100).build_and_execute_with(|| { Balances::make_free_balance_be(&1, 1_000); assert_ok!(System::inc_consumers(&1)); // <-- Reference counter added here is enough for all tests - // Slashed completed in full + // Slashed completed in full assert_eq!(Balances::slash(&1, 800), (NegativeImbalance::new(800), 0)); // Account is still alive assert!(System::account_exists(&1)); diff --git a/substrate/frame/bounties/src/lib.rs b/substrate/frame/bounties/src/lib.rs index e30d6fa2d143..7b89a6e3e76f 100644 --- a/substrate/frame/bounties/src/lib.rs +++ b/substrate/frame/bounties/src/lib.rs @@ -459,12 +459,12 @@ pub mod pallet { Bounties::::try_mutate_exists(bounty_id, |maybe_bounty| -> DispatchResult { let bounty = maybe_bounty.as_mut().ok_or(Error::::InvalidIndex)?; - let slash_curator = - |curator: &T::AccountId, curator_deposit: &mut BalanceOf| { - let imbalance = T::Currency::slash_reserved(curator, *curator_deposit).0; - T::OnSlash::on_unbalanced(imbalance); - *curator_deposit = Zero::zero(); - }; + let slash_curator = |curator: &T::AccountId, + curator_deposit: &mut BalanceOf| { + let imbalance = T::Currency::slash_reserved(curator, *curator_deposit).0; + T::OnSlash::on_unbalanced(imbalance); + *curator_deposit = Zero::zero(); + }; match bounty.status { BountyStatus::Proposed | BountyStatus::Approved | BountyStatus::Funded => { diff --git a/substrate/frame/child-bounties/src/lib.rs b/substrate/frame/child-bounties/src/lib.rs index 660a30ca5d26..911fd4c4c49f 100644 --- a/substrate/frame/child-bounties/src/lib.rs +++ b/substrate/frame/child-bounties/src/lib.rs @@ -473,13 +473,12 @@ pub mod pallet { let child_bounty = maybe_child_bounty.as_mut().ok_or(BountiesError::::InvalidIndex)?; - let slash_curator = - |curator: &T::AccountId, curator_deposit: &mut BalanceOf| { - let imbalance = - T::Currency::slash_reserved(curator, *curator_deposit).0; - T::OnSlash::on_unbalanced(imbalance); - *curator_deposit = Zero::zero(); - }; + let slash_curator = |curator: &T::AccountId, + curator_deposit: &mut BalanceOf| { + let imbalance = T::Currency::slash_reserved(curator, *curator_deposit).0; + T::OnSlash::on_unbalanced(imbalance); + *curator_deposit = Zero::zero(); + }; match child_bounty.status { ChildBountyStatus::Added => { diff --git a/substrate/frame/examples/offchain-worker/src/tests.rs b/substrate/frame/examples/offchain-worker/src/tests.rs index 741adbe6d26a..b665cbbb62ae 100644 --- a/substrate/frame/examples/offchain-worker/src/tests.rs +++ b/substrate/frame/examples/offchain-worker/src/tests.rs @@ -266,12 +266,11 @@ fn should_submit_unsigned_transaction_on_chain_for_any_account() { { assert_eq!(body, price_payload); - let signature_valid = ::Public, - frame_system::pallet_prelude::BlockNumberFor, - > as SignedPayload>::verify::( - &price_payload, signature - ); + let signature_valid = + ::Public, + frame_system::pallet_prelude::BlockNumberFor, + > as SignedPayload>::verify::(&price_payload, signature); assert!(signature_valid); } @@ -321,12 +320,11 @@ fn should_submit_unsigned_transaction_on_chain_for_all_accounts() { { assert_eq!(body, price_payload); - let signature_valid = ::Public, - frame_system::pallet_prelude::BlockNumberFor, - > as SignedPayload>::verify::( - &price_payload, signature - ); + let signature_valid = + ::Public, + frame_system::pallet_prelude::BlockNumberFor, + > as SignedPayload>::verify::(&price_payload, signature); assert!(signature_valid); } diff --git a/substrate/frame/nis/src/lib.rs b/substrate/frame/nis/src/lib.rs index 87e2276e768d..016daa4cb78b 100644 --- a/substrate/frame/nis/src/lib.rs +++ b/substrate/frame/nis/src/lib.rs @@ -756,13 +756,15 @@ pub mod pallet { .map(|_| ()) // We ignore this error as it just means the amount we're trying to deposit is // dust and the beneficiary account doesn't exist. - .or_else(|e| { - if e == TokenError::CannotCreate.into() { - Ok(()) - } else { - Err(e) - } - })?; + .or_else( + |e| { + if e == TokenError::CannotCreate.into() { + Ok(()) + } else { + Err(e) + } + }, + )?; summary.receipts_on_hold.saturating_reduce(on_hold); } T::Currency::release(&HoldReason::NftReceipt.into(), &who, amount, Exact)?; diff --git a/substrate/frame/referenda/src/types.rs b/substrate/frame/referenda/src/types.rs index e83f28b472cd..1039b288b2ae 100644 --- a/substrate/frame/referenda/src/types.rs +++ b/substrate/frame/referenda/src/types.rs @@ -258,8 +258,7 @@ impl< Tally: Eq + PartialEq + Debug + Encode + Decode + TypeInfo + Clone, AccountId: Eq + PartialEq + Debug + Encode + Decode + TypeInfo + Clone, ScheduleAddress: Eq + PartialEq + Debug + Encode + Decode + TypeInfo + Clone, - > - ReferendumInfo + > ReferendumInfo { /// Take the Decision Deposit from `self`, if there is one. Returns an `Err` if `self` is not /// in a valid state for the Decision Deposit to be refunded. diff --git a/substrate/frame/revive/proc-macro/src/lib.rs b/substrate/frame/revive/proc-macro/src/lib.rs index 012b4bfab9a9..95f4110a2d76 100644 --- a/substrate/frame/revive/proc-macro/src/lib.rs +++ b/substrate/frame/revive/proc-macro/src/lib.rs @@ -349,19 +349,18 @@ where let Some(ident) = path.path.get_ident() else { panic!("Type needs to be ident"); }; - let size = if ident == "i8" || - ident == "i16" || - ident == "i32" || - ident == "u8" || - ident == "u16" || - ident == "u32" - { - 1 - } else if ident == "i64" || ident == "u64" { - 2 - } else { - panic!("Pass by value only supports primitives"); - }; + let size = + if ident == "i8" || + ident == "i16" || ident == "i32" || + ident == "u8" || ident == "u16" || + ident == "u32" + { + 1 + } else if ident == "i64" || ident == "u64" { + 2 + } else { + panic!("Pass by value only supports primitives"); + }; registers_used += size; if registers_used > ALLOWED_REGISTERS { return quote! { diff --git a/substrate/frame/society/src/tests.rs b/substrate/frame/society/src/tests.rs index 2a13f99855b5..df8e844cdad9 100644 --- a/substrate/frame/society/src/tests.rs +++ b/substrate/frame/society/src/tests.rs @@ -281,7 +281,7 @@ fn bidding_works() { // No more candidates satisfy the requirements assert_eq!(candidacies(), vec![]); assert_ok!(Society::defender_vote(Origin::signed(10), true)); // Keep defender around - // Next period + // Next period run_to_block(16); // Same members assert_eq!(members(), vec![10, 30, 40, 50]); diff --git a/substrate/frame/staking/src/tests.rs b/substrate/frame/staking/src/tests.rs index dd178a95bec5..ab2c00ca9ccc 100644 --- a/substrate/frame/staking/src/tests.rs +++ b/substrate/frame/staking/src/tests.rs @@ -7995,7 +7995,7 @@ mod ledger_recovery { assert_eq!(Balances::balance_locked(crate::STAKING_ID, &333), lock_333_before); // OK assert_eq!(Bonded::::get(&333), Some(444)); // OK assert!(Payee::::get(&333).is_some()); // OK - // however, ledger associated with its controller was killed. + // however, ledger associated with its controller was killed. assert!(Ledger::::get(&444).is_none()); // NOK // side effects on 444 - ledger, bonded, payee, lock should be completely removed. diff --git a/substrate/frame/support/procedural/src/pallet/parse/call.rs b/substrate/frame/support/procedural/src/pallet/parse/call.rs index 336bfe1e77dc..4e09b86fddec 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/call.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/call.rs @@ -403,19 +403,18 @@ impl CallDef { } for (feeless_arg, arg) in feeless_check.inputs.iter().skip(1).zip(args.iter()) { - let feeless_arg_type = if let syn::Pat::Type(syn::PatType { ty, .. }) = - feeless_arg.clone() - { - if let syn::Type::Reference(pat) = *ty { - pat.elem.clone() + let feeless_arg_type = + if let syn::Pat::Type(syn::PatType { ty, .. }) = feeless_arg.clone() { + if let syn::Type::Reference(pat) = *ty { + pat.elem.clone() + } else { + let msg = "Invalid pallet::call, feeless_if closure argument must be a reference"; + return Err(syn::Error::new(ty.span(), msg)) + } } else { - let msg = "Invalid pallet::call, feeless_if closure argument must be a reference"; - return Err(syn::Error::new(ty.span(), msg)) - } - } else { - let msg = "Invalid pallet::call, feeless_if closure argument must be a type ascription pattern"; - return Err(syn::Error::new(feeless_arg.span(), msg)) - }; + let msg = "Invalid pallet::call, feeless_if closure argument must be a type ascription pattern"; + return Err(syn::Error::new(feeless_arg.span(), msg)) + }; if feeless_arg_type != arg.2 { let msg = diff --git a/substrate/frame/support/src/storage/types/double_map.rs b/substrate/frame/support/src/storage/types/double_map.rs index 1b3adbe60209..3d227feb902f 100644 --- a/substrate/frame/support/src/storage/types/double_map.rs +++ b/substrate/frame/support/src/storage/types/double_map.rs @@ -129,8 +129,7 @@ impl OnEmpty, MaxValues, >, - > -where + > where Prefix: StorageInstance, Hasher1: crate::hash::StorageHasher, Hasher2: crate::hash::StorageHasher, diff --git a/substrate/frame/support/src/traits/try_runtime/decode_entire_state.rs b/substrate/frame/support/src/traits/try_runtime/decode_entire_state.rs index a7465c87fb27..8dbeecd8e860 100644 --- a/substrate/frame/support/src/traits/try_runtime/decode_entire_state.rs +++ b/substrate/frame/support/src/traits/try_runtime/decode_entire_state.rs @@ -197,8 +197,7 @@ impl TryDecodeEntireS QueryKind, OnEmpty, MaxValues, - > -where + > where Prefix: CountedStorageMapInstance, Hasher: StorageHasher, Key: FullCodec, @@ -230,8 +229,7 @@ impl QueryKind, OnEmpty, MaxValues, - > -where + > where Prefix: StorageInstance, Hasher1: StorageHasher, Key1: FullCodec, diff --git a/substrate/frame/support/test/tests/pallet.rs b/substrate/frame/support/test/tests/pallet.rs index 72e796db5a12..eed8a22e8e79 100644 --- a/substrate/frame/support/test/tests/pallet.rs +++ b/substrate/frame/support/test/tests/pallet.rs @@ -2424,10 +2424,9 @@ fn post_runtime_upgrade_detects_storage_version_issues() { // any storage version "enabled". assert!( ExecutiveWithUpgradePallet4::try_runtime_upgrade(UpgradeCheckSelect::PreAndPost) - .unwrap_err() == - "On chain storage version set, while the pallet \ + .unwrap_err() == "On chain storage version set, while the pallet \ doesn't have the `#[pallet::storage_version(VERSION)]` attribute." - .into() + .into() ); }); } diff --git a/substrate/frame/transaction-payment/src/tests.rs b/substrate/frame/transaction-payment/src/tests.rs index bac89967d6af..35d5322a6f33 100644 --- a/substrate/frame/transaction-payment/src/tests.rs +++ b/substrate/frame/transaction-payment/src/tests.rs @@ -273,10 +273,8 @@ fn signed_ext_length_fee_is_also_updated_per_congestion() { NextFeeMultiplier::::put(Multiplier::saturating_from_rational(3, 2)); let len = 10; - assert_ok!( - ChargeTransactionPayment::::from(10) // tipped - .pre_dispatch(&1, CALL, &info_from_weight(Weight::from_parts(3, 0)), len) - ); + assert_ok!(ChargeTransactionPayment::::from(10) // tipped + .pre_dispatch(&1, CALL, &info_from_weight(Weight::from_parts(3, 0)), len)); assert_eq!( Balances::free_balance(1), 100 // original diff --git a/substrate/frame/utility/src/lib.rs b/substrate/frame/utility/src/lib.rs index 9db46ecec42b..3ce5b4ff8649 100644 --- a/substrate/frame/utility/src/lib.rs +++ b/substrate/frame/utility/src/lib.rs @@ -134,8 +134,8 @@ pub mod pallet { fn batched_calls_limit() -> u32 { let allocator_limit = sp_core::MAX_POSSIBLE_ALLOCATION; let call_size = ((core::mem::size_of::<::RuntimeCall>() as u32 + - CALL_ALIGN - 1) / - CALL_ALIGN) * CALL_ALIGN; + CALL_ALIGN - 1) / CALL_ALIGN) * + CALL_ALIGN; // The margin to take into account vec doubling capacity. let margin_factor = 3; diff --git a/substrate/frame/vesting/src/tests.rs b/substrate/frame/vesting/src/tests.rs index 57cb59f27a4d..004da0dfbfa1 100644 --- a/substrate/frame/vesting/src/tests.rs +++ b/substrate/frame/vesting/src/tests.rs @@ -182,7 +182,7 @@ fn unvested_balance_should_not_transfer() { ExtBuilder::default().existential_deposit(10).build().execute_with(|| { let user1_free_balance = Balances::free_balance(&1); assert_eq!(user1_free_balance, 100); // Account 1 has free balance - // Account 1 has only 5 units vested at block 1 (plus 50 unvested) + // Account 1 has only 5 units vested at block 1 (plus 50 unvested) assert_eq!(Vesting::vesting_balance(&1), Some(45)); // Account 1 cannot send more than vested amount... assert_noop!(Balances::transfer_allow_death(Some(1).into(), 2, 56), TokenError::Frozen); @@ -194,7 +194,7 @@ fn vested_balance_should_transfer() { ExtBuilder::default().existential_deposit(10).build().execute_with(|| { let user1_free_balance = Balances::free_balance(&1); assert_eq!(user1_free_balance, 100); // Account 1 has free balance - // Account 1 has only 5 units vested at block 1 (plus 50 unvested) + // Account 1 has only 5 units vested at block 1 (plus 50 unvested) assert_eq!(Vesting::vesting_balance(&1), Some(45)); assert_ok!(Vesting::vest(Some(1).into())); assert_ok!(Balances::transfer_allow_death(Some(1).into(), 2, 55)); @@ -232,7 +232,7 @@ fn vested_balance_should_transfer_using_vest_other() { ExtBuilder::default().existential_deposit(10).build().execute_with(|| { let user1_free_balance = Balances::free_balance(&1); assert_eq!(user1_free_balance, 100); // Account 1 has free balance - // Account 1 has only 5 units vested at block 1 (plus 50 unvested) + // Account 1 has only 5 units vested at block 1 (plus 50 unvested) assert_eq!(Vesting::vesting_balance(&1), Some(45)); assert_ok!(Vesting::vest_other(Some(2).into(), 1)); assert_ok!(Balances::transfer_allow_death(Some(1).into(), 2, 55)); @@ -286,7 +286,7 @@ fn extra_balance_should_transfer() { assert_eq!(Vesting::vesting_balance(&2), Some(200)); assert_ok!(Vesting::vest(Some(2).into())); assert_ok!(Balances::transfer_allow_death(Some(2).into(), 3, 100)); // Account 2 can send extra - // units gained + // units gained }); } @@ -296,7 +296,7 @@ fn liquid_funds_should_transfer_with_delayed_vesting() { let user12_free_balance = Balances::free_balance(&12); assert_eq!(user12_free_balance, 2560); // Account 12 has free balance - // Account 12 has liquid funds + // Account 12 has liquid funds assert_eq!(Vesting::vesting_balance(&12), Some(user12_free_balance - 256 * 5)); // Account 12 has delayed vesting diff --git a/substrate/utils/wasm-builder/src/wasm_project.rs b/substrate/utils/wasm-builder/src/wasm_project.rs index 5bd7f7432314..a6eda078fde0 100644 --- a/substrate/utils/wasm-builder/src/wasm_project.rs +++ b/substrate/utils/wasm-builder/src/wasm_project.rs @@ -601,10 +601,9 @@ fn project_enabled_features( // We don't want to enable the `std`/`default` feature for the wasm build and // we need to check if the feature is enabled by checking the env variable. *f != "std" && - *f != "default" && - env::var(format!("CARGO_FEATURE_{}", feature_env)) - .map(|v| v == "1") - .unwrap_or_default() + *f != "default" && env::var(format!("CARGO_FEATURE_{}", feature_env)) + .map(|v| v == "1") + .unwrap_or_default() }) .map(|d| d.0.clone()) .collect::>(); From f194e5f3e2658f1dffc28156f429c2914023de33 Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Mon, 9 Sep 2024 07:18:26 +0000 Subject: [PATCH 18/37] ".git/.scripts/commands/fmt/fmt.sh" --- .../src/task/strategy/full.rs | 11 ++++++---- .../src/task/strategy/mod.rs | 6 ++++-- .../src/protocol/notifications/behaviour.rs | 3 +-- .../client/network/src/request_responses.rs | 5 +++-- substrate/client/network/src/service.rs | 20 +++++++++++++------ substrate/client/network/sync/src/engine.rs | 2 +- 6 files changed, 30 insertions(+), 17 deletions(-) diff --git a/polkadot/node/network/availability-recovery/src/task/strategy/full.rs b/polkadot/node/network/availability-recovery/src/task/strategy/full.rs index c90c6477131c..61a629582add 100644 --- a/polkadot/node/network/availability-recovery/src/task/strategy/full.rs +++ b/polkadot/node/network/availability-recovery/src/task/strategy/full.rs @@ -19,16 +19,17 @@ use crate::{ ErasureTask, PostRecoveryCheck, LOG_TARGET, }; +use futures::{channel::oneshot, SinkExt}; use polkadot_node_network_protocol::request_response::{ self as req_res, outgoing::RequestError, OutgoingRequest, Recipient, Requests, }; use polkadot_node_primitives::AvailableData; use polkadot_node_subsystem::{messages::NetworkBridgeTxMessage, overseer, RecoveryError}; use polkadot_primitives::ValidatorIndex; -use sc_network::{IfDisconnected, OutboundFailure, RequestFailure}; -use sc_network::request_responses::CustomOutboundFailure; -use futures::{channel::oneshot, SinkExt}; use rand::seq::SliceRandom; +use sc_network::{ + request_responses::CustomOutboundFailure, IfDisconnected, OutboundFailure, RequestFailure, +}; /// Parameters specific to the `FetchFull` strategy. pub struct FetchFullParams { @@ -153,7 +154,9 @@ impl RecoveryStrategy RequestError::InvalidResponse(_) => common_params.metrics.on_full_request_invalid(), RequestError::NetworkError(req_failure) => { - if let RequestFailure::Network(CustomOutboundFailure::Timeout) = req_failure { + if let RequestFailure::Network(CustomOutboundFailure::Timeout) = + req_failure + { common_params.metrics.on_full_request_timeout(); } else { common_params.metrics.on_full_request_error(); diff --git a/polkadot/node/network/availability-recovery/src/task/strategy/mod.rs b/polkadot/node/network/availability-recovery/src/task/strategy/mod.rs index 789b70eafdb3..b3d5786cae5e 100644 --- a/polkadot/node/network/availability-recovery/src/task/strategy/mod.rs +++ b/polkadot/node/network/availability-recovery/src/task/strategy/mod.rs @@ -30,7 +30,6 @@ use crate::{ }; use codec::Decode; -use sc_network::request_responses::CustomOutboundFailure; use futures::{channel::oneshot, SinkExt}; use polkadot_erasure_coding::branch_hash; #[cfg(not(test))] @@ -44,7 +43,10 @@ use polkadot_node_subsystem::{ overseer, RecoveryError, }; use polkadot_primitives::{AuthorityDiscoveryId, BlakeTwo256, ChunkIndex, HashT, ValidatorIndex}; -use sc_network::{IfDisconnected, OutboundFailure, ProtocolName, RequestFailure}; +use sc_network::{ + request_responses::CustomOutboundFailure, IfDisconnected, OutboundFailure, ProtocolName, + RequestFailure, +}; use std::{ collections::{BTreeMap, HashMap, VecDeque}, time::Duration, diff --git a/substrate/client/network/src/protocol/notifications/behaviour.rs b/substrate/client/network/src/protocol/notifications/behaviour.rs index 6436b0864504..cb4f089995e3 100644 --- a/substrate/client/network/src/protocol/notifications/behaviour.rs +++ b/substrate/client/network/src/protocol/notifications/behaviour.rs @@ -2413,8 +2413,7 @@ mod tests { } fn development_notifs( - ) -> (Notifications, ProtocolController, Box) - { + ) -> (Notifications, ProtocolController, Box) { let (protocol_handle_pair, notif_service) = crate::protocol::notifications::service::notification_service("/proto/1".into()); let (to_notifications, from_controller) = diff --git a/substrate/client/network/src/request_responses.rs b/substrate/client/network/src/request_responses.rs index 742c73833c45..4920d986c1fd 100644 --- a/substrate/client/network/src/request_responses.rs +++ b/substrate/client/network/src/request_responses.rs @@ -739,7 +739,7 @@ impl NetworkBehaviour for RequestResponsesBehaviour { } let mut fallback_requests = vec![]; - + // Poll request-responses protocols. for (protocol, (ref mut behaviour, ref mut resp_builder)) in &mut self.protocols { 'poll_protocol: while let Poll::Ready(ev) = behaviour.poll(cx, params) { @@ -909,7 +909,8 @@ impl NetworkBehaviour for RequestResponsesBehaviour { // Try using the fallback request if the protocol was not // supported. if let OutboundFailure::UnsupportedProtocols = error { - let error_bis_out = CustomOutboundFailure::UnsupportedProtocols; + let error_bis_out = + CustomOutboundFailure::UnsupportedProtocols; if let Some((fallback_request, fallback_protocol)) = fallback_request { diff --git a/substrate/client/network/src/service.rs b/substrate/client/network/src/service.rs index 9fd4370a3b54..57745fa96349 100644 --- a/substrate/client/network/src/service.rs +++ b/substrate/client/network/src/service.rs @@ -1702,18 +1702,26 @@ where SwarmEvent::Behaviour(BehaviourOut::None) => { // Ignored event from lower layers. }, - SwarmEvent::Behaviour(BehaviourOut::Message{ peer, message }) => { + SwarmEvent::Behaviour(BehaviourOut::Message { peer, message }) => { // Ignored event from lower layers. - }, - SwarmEvent::Behaviour(BehaviourOut::CustomOutboundFailure{ peer,request_id,error }) => { + }, + SwarmEvent::Behaviour(BehaviourOut::CustomOutboundFailure { + peer, + request_id, + error, + }) => { // Ignored event from lower layers. }, - SwarmEvent::Behaviour(BehaviourOut::CustomInboundFailure{ peer,request_id,error }) => { + SwarmEvent::Behaviour(BehaviourOut::CustomInboundFailure { + peer, + request_id, + error, + }) => { // Ignored event from lower layers. }, - SwarmEvent::Behaviour(BehaviourOut::CustomResponseSent{ peer,request_id }) => { + SwarmEvent::Behaviour(BehaviourOut::CustomResponseSent { peer, request_id }) => { // Ignored event from lower layers. - }, + }, SwarmEvent::ConnectionEstablished { peer_id, endpoint, diff --git a/substrate/client/network/sync/src/engine.rs b/substrate/client/network/sync/src/engine.rs index 926066165a4a..daeae4324cd8 100644 --- a/substrate/client/network/sync/src/engine.rs +++ b/substrate/client/network/sync/src/engine.rs @@ -56,7 +56,7 @@ use sc_consensus::{import_queue::ImportQueueService, IncomingBlock}; use sc_network::{ config::{FullNetworkConfiguration, NotificationHandshake, ProtocolId, SetConfig}, peer_store::PeerStoreProvider, - request_responses::{IfDisconnected, RequestFailure, CustomOutboundFailure}, + request_responses::{CustomOutboundFailure, IfDisconnected, RequestFailure}, service::{ traits::{Direction, NotificationConfig, NotificationEvent, ValidationResult}, NotificationMetrics, From 6ac72b34cadafb2a5a74953a5ff673c3b39b5549 Mon Sep 17 00:00:00 2001 From: ndkazu Date: Mon, 9 Sep 2024 22:28:37 +0900 Subject: [PATCH 19/37] Removed all #[error(dial-failure)] --- .../client/network/src/request_responses.rs | 35 +++++++++++++++++-- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/substrate/client/network/src/request_responses.rs b/substrate/client/network/src/request_responses.rs index 4920d986c1fd..836ac6930215 100644 --- a/substrate/client/network/src/request_responses.rs +++ b/substrate/client/network/src/request_responses.rs @@ -62,6 +62,7 @@ use std::{ sync::Arc, task::{Context, Poll}, time::{Duration, Instant}, + fmt::{Display,Formatter}, }; pub use libp2p::request_response::{Config, InboundFailure, OutboundFailure, RequestId}; @@ -69,7 +70,6 @@ pub use libp2p::request_response::{Config, InboundFailure, OutboundFailure, Requ /// Adding a custom OutboundFailure, not depending on libp2p #[derive(Debug, thiserror::Error)] #[allow(missing_docs)] -#[error("dial-failure")] pub enum CustomOutboundFailure { /// The request could not be sent because a dialing attempt failed. DialFailure, @@ -81,18 +81,36 @@ pub enum CustomOutboundFailure { UnsupportedProtocols, } +impl Display for CustomOutboundFailure{ + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result{ + match self { + CustomOutboundFailure::DialFailure => write!(f, "DialFailure"), + CustomOutboundFailure::Timeout => write!(f, "Timeout"), + CustomOutboundFailure::ConnectionClosed => write!(f, "ConnectionClosed"), + CustomOutboundFailure::UnsupportedProtocols => write!(f, "UnsupportedProtocols"), + } + } +} + #[derive(Debug, thiserror::Error)] #[allow(missing_docs)] -#[error("dial-failure")] pub enum CustomMessage { Request { request_id: InboundRequestId, request: Vec, channel: ResponseChannel> }, Response { request_id: OutboundRequestId, response: Vec }, } +impl Display for CustomMessage { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + match self { + CustomMessage::Request {request_id,request,channel} => write!(f, "MessageRequest({:?}, {:?}, {:?})",request_id,request,channel), + CustomMessage::Response {request_id,response} => write!(f, "MessageResponse({:?}, {:?})",request_id, response), + } + } +} + /// Adding a custom InboundFailure, not depending on libp2p #[derive(Debug, thiserror::Error)] #[allow(missing_docs)] -#[error("dial-failure")] pub enum CustomInboundFailure { /// The inbound request timed out, either while reading the incoming request or before a /// response is sent @@ -105,6 +123,17 @@ pub enum CustomInboundFailure { ResponseOmission, } +impl Display for CustomInboundFailure{ + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result{ + match self { + CustomInboundFailure::Timeout => write!(f, "Timeout"), + CustomInboundFailure::ConnectionClosed => write!(f, "ConnectionClosed"), + CustomInboundFailure::UnsupportedProtocols => write!(f, "UnsupportedProtocols"), + CustomInboundFailure::ResponseOmission => write!(f, "ResponseOmission"), + } + } +} + /// In preparation for a CustomOutBoundFailure Event #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] pub struct OutboundRequestId(u64); From 53ea246c445c0fb878f4e20b11e703f5abbf2f4b Mon Sep 17 00:00:00 2001 From: ndkazu Date: Thu, 12 Sep 2024 23:05:40 +0900 Subject: [PATCH 20/37] Replaced CustomOutboundFailure by OutboundFailure --- .../src/task/strategy/full.rs | 4 +-- .../src/task/strategy/mod.rs | 4 +-- polkadot/node/network/bridge/src/network.rs | 6 ++-- .../protocol/src/request_response/outgoing.rs | 4 +-- substrate/client/network/src/behaviour.rs | 12 +++---- substrate/client/network/src/lib.rs | 2 +- .../src/litep2p/shim/request_response/mod.rs | 4 +-- .../client/network/src/request_responses.rs | 36 +++++++++---------- substrate/client/network/src/service.rs | 16 ++++----- substrate/client/network/sync/src/engine.rs | 12 +++---- 10 files changed, 50 insertions(+), 50 deletions(-) diff --git a/polkadot/node/network/availability-recovery/src/task/strategy/full.rs b/polkadot/node/network/availability-recovery/src/task/strategy/full.rs index 61a629582add..6c4e44a28da2 100644 --- a/polkadot/node/network/availability-recovery/src/task/strategy/full.rs +++ b/polkadot/node/network/availability-recovery/src/task/strategy/full.rs @@ -28,7 +28,7 @@ use polkadot_node_subsystem::{messages::NetworkBridgeTxMessage, overseer, Recove use polkadot_primitives::ValidatorIndex; use rand::seq::SliceRandom; use sc_network::{ - request_responses::CustomOutboundFailure, IfDisconnected, OutboundFailure, RequestFailure, + request_responses::OutboundFailure, IfDisconnected, RequestFailure, }; /// Parameters specific to the `FetchFull` strategy. @@ -154,7 +154,7 @@ impl RecoveryStrategy RequestError::InvalidResponse(_) => common_params.metrics.on_full_request_invalid(), RequestError::NetworkError(req_failure) => { - if let RequestFailure::Network(CustomOutboundFailure::Timeout) = + if let RequestFailure::Network(OutboundFailure::Timeout) = req_failure { common_params.metrics.on_full_request_timeout(); diff --git a/polkadot/node/network/availability-recovery/src/task/strategy/mod.rs b/polkadot/node/network/availability-recovery/src/task/strategy/mod.rs index b3d5786cae5e..4549e1cb276d 100644 --- a/polkadot/node/network/availability-recovery/src/task/strategy/mod.rs +++ b/polkadot/node/network/availability-recovery/src/task/strategy/mod.rs @@ -44,7 +44,7 @@ use polkadot_node_subsystem::{ }; use polkadot_primitives::{AuthorityDiscoveryId, BlakeTwo256, ChunkIndex, HashT, ValidatorIndex}; use sc_network::{ - request_responses::CustomOutboundFailure, IfDisconnected, OutboundFailure, ProtocolName, + request_responses::OutboundFailure, IfDisconnected, ProtocolName, RequestFailure, }; use std::{ @@ -568,7 +568,7 @@ impl State { RequestError::NetworkError(err) => { // No debug logs on general network errors - that became very // spammy occasionally. - if let RequestFailure::Network(CustomOutboundFailure::Timeout) = err { + if let RequestFailure::Network(OutboundFailure::Timeout) = err { metrics.on_chunk_request_timeout(strategy_type); } else { metrics.on_chunk_request_error(strategy_type); diff --git a/polkadot/node/network/bridge/src/network.rs b/polkadot/node/network/bridge/src/network.rs index f7232ed53b84..e166765c4951 100644 --- a/polkadot/node/network/bridge/src/network.rs +++ b/polkadot/node/network/bridge/src/network.rs @@ -23,11 +23,11 @@ use async_trait::async_trait; use parking_lot::Mutex; use codec::Encode; -use sc_network::request_responses::CustomOutboundFailure; +use sc_network::request_responses::OutboundFailure; use sc_network::{ config::parse_addr, multiaddr::Multiaddr, service::traits::NetworkService, types::ProtocolName, - IfDisconnected, MessageSink, OutboundFailure, ReputationChange, RequestFailure, + IfDisconnected, MessageSink, ReputationChange, RequestFailure, }; use polkadot_node_network_protocol::{ @@ -315,7 +315,7 @@ impl Network for Arc { None => { gum::debug!(target: LOG_TARGET, "Discovering authority failed"); match pending_response - .send(Err(RequestFailure::Network(CustomOutboundFailure::DialFailure))) + .send(Err(RequestFailure::Network(OutboundFailure::DialFailure))) { Err(_) => { gum::debug!(target: LOG_TARGET, "Sending failed request response failed.") diff --git a/polkadot/node/network/protocol/src/request_response/outgoing.rs b/polkadot/node/network/protocol/src/request_response/outgoing.rs index 9c526c378d00..92e4d605994a 100644 --- a/polkadot/node/network/protocol/src/request_response/outgoing.rs +++ b/polkadot/node/network/protocol/src/request_response/outgoing.rs @@ -23,7 +23,7 @@ use sc_network as network; use sc_network_types::PeerId; use polkadot_primitives::AuthorityDiscoveryId; -use sc_network::request_responses::CustomOutboundFailure; +use sc_network::request_responses::OutboundFailure; use super::{v1, v2, IsRequest, Protocol}; @@ -98,7 +98,7 @@ impl RequestError { Self::Canceled(_) | Self::NetworkError(network::RequestFailure::Obsolete) | Self::NetworkError(network::RequestFailure::Network( - CustomOutboundFailure::Timeout, + OutboundFailure::Timeout, )) => true, _ => false, } diff --git a/substrate/client/network/src/behaviour.rs b/substrate/client/network/src/behaviour.rs index 56c77f884929..86482fafc4d2 100644 --- a/substrate/client/network/src/behaviour.rs +++ b/substrate/client/network/src/behaviour.rs @@ -24,7 +24,7 @@ use crate::{ protocol::{CustomMessageOutcome, NotificationsSink, Protocol}, protocol_controller::SetId, request_responses::{ - self, CustomInboundFailure, CustomMessage, CustomOutboundFailure, IfDisconnected, + self, CustomInboundFailure, CustomMessage, OutboundFailure, IfDisconnected, InboundRequestId, OutboundRequestId, ProtocolConfig, RequestFailure, }, service::traits::Direction, @@ -51,7 +51,7 @@ use std::{ time::{Duration, Instant}, }; -pub use crate::request_responses::{InboundFailure, OutboundFailure, ResponseFailure}; +pub use crate::request_responses::{InboundFailure, ResponseFailure}; /// General behaviour of the network. Combines all protocols together. #[derive(NetworkBehaviour)] @@ -114,13 +114,13 @@ pub enum BehaviourOut { }, /// An outbound request failed. - CustomOutboundFailure { + OutboundFailure { /// The peer to whom the request was sent. peer: PeerId, /// The (local) ID of the failed request. request_id: OutboundRequestId, /// The error that occurred. - error: CustomOutboundFailure, + error: OutboundFailure, }, /// An inbound request failed. CustomInboundFailure { @@ -399,8 +399,8 @@ impl From for BehaviourOut { BehaviourOut::ReputationChanges { peer, changes }, request_responses::Event::Message { peer, message } => BehaviourOut::Message { peer, message }, - request_responses::Event::CustomOutboundFailure { peer, request_id, error } => - BehaviourOut::CustomOutboundFailure { peer, request_id, error }, + request_responses::Event::OutboundFailure { peer, request_id, error } => + BehaviourOut::OutboundFailure { peer, request_id, error }, request_responses::Event::CustomInboundFailure { peer, request_id, error } => BehaviourOut::CustomInboundFailure { peer, request_id, error }, request_responses::Event::CustomResponseSent { peer, request_id } => diff --git a/substrate/client/network/src/lib.rs b/substrate/client/network/src/lib.rs index 99a972f914e2..3ee362f90096 100644 --- a/substrate/client/network/src/lib.rs +++ b/substrate/client/network/src/lib.rs @@ -286,7 +286,7 @@ pub use service::{ NotificationSender as NotificationSenderT, NotificationSenderError, NotificationSenderReady, NotificationService, }, - DecodingError, Keypair, NetworkService, NetworkWorker, NotificationSender, OutboundFailure, + DecodingError, Keypair, NetworkService, NetworkWorker, NotificationSender, PublicKey, }; pub use types::ProtocolName; diff --git a/substrate/client/network/src/litep2p/shim/request_response/mod.rs b/substrate/client/network/src/litep2p/shim/request_response/mod.rs index 0e5e9aa07301..864aa040c119 100644 --- a/substrate/client/network/src/litep2p/shim/request_response/mod.rs +++ b/substrate/client/network/src/litep2p/shim/request_response/mod.rs @@ -27,7 +27,7 @@ use crate::{ IfDisconnected, ProtocolName, RequestFailure, }; -use crate::request_responses::CustomOutboundFailure; +use crate::request_responses::OutboundFailure; use futures::{channel::oneshot, future::BoxFuture, stream::FuturesUnordered, StreamExt}; use litep2p::{ error::{ImmediateDialError, NegotiationError, SubstreamError}, @@ -402,7 +402,7 @@ impl RequestResponseProtocol { Some((RequestFailure::Refused, reason)) }, RequestResponseError::Timeout => - Some((RequestFailure::Network(CustomOutboundFailure::Timeout), "timeout")), + Some((RequestFailure::Network(OutboundFailure::Timeout), "timeout")), RequestResponseError::Canceled => { log::debug!( target: LOG_TARGET, diff --git a/substrate/client/network/src/request_responses.rs b/substrate/client/network/src/request_responses.rs index 836ac6930215..06cb56528a38 100644 --- a/substrate/client/network/src/request_responses.rs +++ b/substrate/client/network/src/request_responses.rs @@ -65,12 +65,12 @@ use std::{ fmt::{Display,Formatter}, }; -pub use libp2p::request_response::{Config, InboundFailure, OutboundFailure, RequestId}; +pub use libp2p::request_response::{Config, InboundFailure, RequestId}; /// Adding a custom OutboundFailure, not depending on libp2p #[derive(Debug, thiserror::Error)] #[allow(missing_docs)] -pub enum CustomOutboundFailure { +pub enum OutboundFailure { /// The request could not be sent because a dialing attempt failed. DialFailure, /// The request timed out before a response was received. @@ -81,13 +81,13 @@ pub enum CustomOutboundFailure { UnsupportedProtocols, } -impl Display for CustomOutboundFailure{ +impl Display for OutboundFailure{ fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result{ match self { - CustomOutboundFailure::DialFailure => write!(f, "DialFailure"), - CustomOutboundFailure::Timeout => write!(f, "Timeout"), - CustomOutboundFailure::ConnectionClosed => write!(f, "ConnectionClosed"), - CustomOutboundFailure::UnsupportedProtocols => write!(f, "UnsupportedProtocols"), + OutboundFailure::DialFailure => write!(f, "DialFailure"), + OutboundFailure::Timeout => write!(f, "Timeout"), + OutboundFailure::ConnectionClosed => write!(f, "ConnectionClosed"), + OutboundFailure::UnsupportedProtocols => write!(f, "UnsupportedProtocols"), } } } @@ -134,7 +134,7 @@ impl Display for CustomInboundFailure{ } } -/// In preparation for a CustomOutBoundFailure Event +/// In preparation for a OutboundFailure Event #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] pub struct OutboundRequestId(u64); @@ -144,7 +144,7 @@ impl fmt::Display for OutboundRequestId { } } -/// In preparation for a CustomOutBoundFailure Event +/// In preparation for a OutboundFailure Event #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] pub struct InboundRequestId(u64); @@ -167,7 +167,7 @@ pub enum RequestFailure { #[error("The remote replied, but the local node is no longer interested in the response.")] Obsolete, #[error("Problem on the network: {0}")] - Network(CustomOutboundFailure), + Network(OutboundFailure), } /// Configuration for a single request-response protocol. @@ -345,13 +345,13 @@ pub enum Event { }, /// An outbound request failed. - CustomOutboundFailure { + OutboundFailure { /// The peer to whom the request was sent. peer: PeerId, /// The (local) ID of the failed request. request_id: OutboundRequestId, /// The error that occurred. - error: CustomOutboundFailure, + error: OutboundFailure, }, /// An inbound request failed. @@ -937,9 +937,9 @@ impl NetworkBehaviour for RequestResponsesBehaviour { }) => { // Try using the fallback request if the protocol was not // supported. - if let OutboundFailure::UnsupportedProtocols = error { + if let request_response::OutboundFailure::UnsupportedProtocols = error { let error_bis_out = - CustomOutboundFailure::UnsupportedProtocols; + OutboundFailure::UnsupportedProtocols; if let Some((fallback_request, fallback_protocol)) = fallback_request { @@ -961,7 +961,7 @@ impl NetworkBehaviour for RequestResponsesBehaviour { if response_tx .send(Err(RequestFailure::Network( - CustomOutboundFailure::Timeout, + OutboundFailure::Timeout, ))) .is_err() { @@ -984,7 +984,7 @@ impl NetworkBehaviour for RequestResponsesBehaviour { continue }, }; - let error_bis_out = CustomOutboundFailure::Timeout; + let error_bis_out = OutboundFailure::Timeout; let out = Event::RequestFinished { peer, protocol: protocol.clone(), @@ -1462,7 +1462,7 @@ mod tests { } match response_receiver.unwrap().await.unwrap().unwrap_err() { - RequestFailure::Network(CustomOutboundFailure::ConnectionClosed) => {}, + RequestFailure::Network(OutboundFailure::ConnectionClosed) => {}, _ => panic!(), } }); @@ -1833,7 +1833,7 @@ mod tests { SwarmEvent::Behaviour(Event::RequestFinished { result, .. }) => { assert_matches!( result.unwrap_err(), - RequestFailure::Network(CustomOutboundFailure::UnsupportedProtocols) + RequestFailure::Network(OutboundFailure::UnsupportedProtocols) ); break }, diff --git a/substrate/client/network/src/service.rs b/substrate/client/network/src/service.rs index 57745fa96349..a2775012d4b2 100644 --- a/substrate/client/network/src/service.rs +++ b/substrate/client/network/src/service.rs @@ -89,9 +89,9 @@ use sc_network_common::{ use sc_utils::mpsc::{tracing_unbounded, TracingUnboundedReceiver, TracingUnboundedSender}; use sp_runtime::traits::Block as BlockT; -pub use behaviour::{InboundFailure, OutboundFailure, ResponseFailure}; +pub use behaviour::{InboundFailure, ResponseFailure}; // Import our custom type -use crate::request_responses::{CustomInboundFailure, CustomOutboundFailure}; +use crate::request_responses::{CustomInboundFailure, OutboundFailure}; pub use libp2p::identity::{DecodingError, Keypair, PublicKey}; pub use metrics::NotificationMetrics; pub use protocol::NotificationsSink; @@ -1232,7 +1232,7 @@ where // 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(CustomOutboundFailure::ConnectionClosed)), + Err(_) => Err(RequestFailure::Network(OutboundFailure::ConnectionClosed)), } } @@ -1566,15 +1566,15 @@ where RequestFailure::Refused => "refused", RequestFailure::Obsolete => "obsolete", - RequestFailure::Network(CustomOutboundFailure::DialFailure) => + RequestFailure::Network(OutboundFailure::DialFailure) => "dial-failure", - RequestFailure::Network(CustomOutboundFailure::Timeout) => + RequestFailure::Network(OutboundFailure::Timeout) => "timeout", RequestFailure::Network( - CustomOutboundFailure::ConnectionClosed, + OutboundFailure::ConnectionClosed, ) => "connection-closed", RequestFailure::Network( - CustomOutboundFailure::UnsupportedProtocols, + OutboundFailure::UnsupportedProtocols, ) => "unsupported", }; @@ -1705,7 +1705,7 @@ where SwarmEvent::Behaviour(BehaviourOut::Message { peer, message }) => { // Ignored event from lower layers. }, - SwarmEvent::Behaviour(BehaviourOut::CustomOutboundFailure { + SwarmEvent::Behaviour(BehaviourOut::OutboundFailure { peer, request_id, error, diff --git a/substrate/client/network/sync/src/engine.rs b/substrate/client/network/sync/src/engine.rs index 538484489118..17480a1884b0 100644 --- a/substrate/client/network/sync/src/engine.rs +++ b/substrate/client/network/sync/src/engine.rs @@ -56,7 +56,7 @@ use sc_consensus::{import_queue::ImportQueueService, IncomingBlock}; use sc_network::{ config::{FullNetworkConfiguration, NotificationHandshake, ProtocolId, SetConfig}, peer_store::PeerStoreProvider, - request_responses::{CustomOutboundFailure, IfDisconnected, RequestFailure}, + request_responses::{OutboundFailure, IfDisconnected, RequestFailure}, service::{ traits::{Direction, NotificationConfig, NotificationEvent, ValidationResult}, NotificationMetrics, @@ -1196,19 +1196,19 @@ where Ok(Err(e)) => { debug!(target: LOG_TARGET, "Request to peer {peer_id:?} failed: {e:?}."); - // Using Our custom type Network(CustomOutboundFailure) + // Using Our custom type Network(OutboundFailure) match e { - RequestFailure::Network(CustomOutboundFailure::Timeout) => { + RequestFailure::Network(OutboundFailure::Timeout) => { self.network_service.report_peer(peer_id, rep::TIMEOUT); self.network_service .disconnect_peer(peer_id, self.block_announce_protocol_name.clone()); }, - RequestFailure::Network(CustomOutboundFailure::UnsupportedProtocols) => { + RequestFailure::Network(OutboundFailure::UnsupportedProtocols) => { self.network_service.report_peer(peer_id, rep::BAD_PROTOCOL); self.network_service .disconnect_peer(peer_id, self.block_announce_protocol_name.clone()); }, - RequestFailure::Network(CustomOutboundFailure::DialFailure) => { + RequestFailure::Network(OutboundFailure::DialFailure) => { self.network_service .disconnect_peer(peer_id, self.block_announce_protocol_name.clone()); }, @@ -1217,7 +1217,7 @@ where self.network_service .disconnect_peer(peer_id, self.block_announce_protocol_name.clone()); }, - RequestFailure::Network(CustomOutboundFailure::ConnectionClosed) | + RequestFailure::Network(OutboundFailure::ConnectionClosed) | RequestFailure::NotConnected => { self.network_service .disconnect_peer(peer_id, self.block_announce_protocol_name.clone()); From da7adc3fb24eca502b43a78aa452432a3b90070b Mon Sep 17 00:00:00 2001 From: ndkazu Date: Fri, 13 Sep 2024 14:18:07 +0900 Subject: [PATCH 21/37] first round of corrections --- .../src/task/strategy/full.rs | 13 +-- .../src/task/strategy/mod.rs | 7 +- polkadot/node/network/bridge/src/network.rs | 5 +- substrate/client/network/src/behaviour.rs | 64 ++--------- substrate/client/network/src/protocol.rs | 12 +-- .../client/network/src/request_responses.rs | 101 ++---------------- substrate/client/network/src/service.rs | 33 ++---- substrate/client/network/sync/src/engine.rs | 1 - 8 files changed, 41 insertions(+), 195 deletions(-) diff --git a/polkadot/node/network/availability-recovery/src/task/strategy/full.rs b/polkadot/node/network/availability-recovery/src/task/strategy/full.rs index 6c4e44a28da2..ed39f516490d 100644 --- a/polkadot/node/network/availability-recovery/src/task/strategy/full.rs +++ b/polkadot/node/network/availability-recovery/src/task/strategy/full.rs @@ -19,17 +19,16 @@ use crate::{ ErasureTask, PostRecoveryCheck, LOG_TARGET, }; -use futures::{channel::oneshot, SinkExt}; use polkadot_node_network_protocol::request_response::{ self as req_res, outgoing::RequestError, OutgoingRequest, Recipient, Requests, }; use polkadot_node_primitives::AvailableData; use polkadot_node_subsystem::{messages::NetworkBridgeTxMessage, overseer, RecoveryError}; use polkadot_primitives::ValidatorIndex; +use sc_network::{IfDisconnected, OutboundFailure, RequestFailure}; + +use futures::{channel::oneshot, SinkExt}; use rand::seq::SliceRandom; -use sc_network::{ - request_responses::OutboundFailure, IfDisconnected, RequestFailure, -}; /// Parameters specific to the `FetchFull` strategy. pub struct FetchFullParams { @@ -154,9 +153,7 @@ impl RecoveryStrategy RequestError::InvalidResponse(_) => common_params.metrics.on_full_request_invalid(), RequestError::NetworkError(req_failure) => { - if let RequestFailure::Network(OutboundFailure::Timeout) = - req_failure - { + if let RequestFailure::Network(OutboundFailure::Timeout) = req_failure { common_params.metrics.on_full_request_timeout(); } else { common_params.metrics.on_full_request_error(); @@ -174,4 +171,4 @@ impl RecoveryStrategy } } } -} +} \ No newline at end of file diff --git a/polkadot/node/network/availability-recovery/src/task/strategy/mod.rs b/polkadot/node/network/availability-recovery/src/task/strategy/mod.rs index 4549e1cb276d..eed24587ce8d 100644 --- a/polkadot/node/network/availability-recovery/src/task/strategy/mod.rs +++ b/polkadot/node/network/availability-recovery/src/task/strategy/mod.rs @@ -43,10 +43,7 @@ use polkadot_node_subsystem::{ overseer, RecoveryError, }; use polkadot_primitives::{AuthorityDiscoveryId, BlakeTwo256, ChunkIndex, HashT, ValidatorIndex}; -use sc_network::{ - request_responses::OutboundFailure, IfDisconnected, ProtocolName, - RequestFailure, -}; +use sc_network::{IfDisconnected, OutboundFailure, ProtocolName, RequestFailure}; use std::{ collections::{BTreeMap, HashMap, VecDeque}, time::Duration, @@ -1558,4 +1555,4 @@ mod tests { assert_eq!(is_unavailable(0, 0, 0, 3), true); assert_eq!(is_unavailable(2, 3, 2, 10), true); } -} +} \ No newline at end of file diff --git a/polkadot/node/network/bridge/src/network.rs b/polkadot/node/network/bridge/src/network.rs index e166765c4951..926141d4dc18 100644 --- a/polkadot/node/network/bridge/src/network.rs +++ b/polkadot/node/network/bridge/src/network.rs @@ -23,11 +23,10 @@ use async_trait::async_trait; use parking_lot::Mutex; use codec::Encode; -use sc_network::request_responses::OutboundFailure; use sc_network::{ config::parse_addr, multiaddr::Multiaddr, service::traits::NetworkService, types::ProtocolName, - IfDisconnected, MessageSink, ReputationChange, RequestFailure, + IfDisconnected, MessageSink, OutboundFailure, ReputationChange, RequestFailure, }; use polkadot_node_network_protocol::{ @@ -365,4 +364,4 @@ pub async fn get_peer_id_by_authority_id( .into_iter() .flat_map(|list| list.into_iter()) .find_map(|addr| parse_addr(addr).ok().map(|(p, _)| p)) -} +} \ No newline at end of file diff --git a/substrate/client/network/src/behaviour.rs b/substrate/client/network/src/behaviour.rs index 86482fafc4d2..aa26dd1d6209 100644 --- a/substrate/client/network/src/behaviour.rs +++ b/substrate/client/network/src/behaviour.rs @@ -21,11 +21,11 @@ use crate::{ event::DhtEvent, peer_info, peer_store::PeerStoreProvider, - protocol::{CustomMessageOutcome, NotificationsSink, Protocol}, + protocol::{MessageOutcome, NotificationsSink, Protocol}, protocol_controller::SetId, request_responses::{ - self, CustomInboundFailure, CustomMessage, OutboundFailure, IfDisconnected, - InboundRequestId, OutboundRequestId, ProtocolConfig, RequestFailure, + self, OutboundFailure, IfDisconnected, + ProtocolConfig, RequestFailure, }, service::traits::Direction, types::ProtocolName, @@ -105,44 +105,6 @@ pub enum BehaviourOut { /// A request protocol handler issued reputation changes for the given peer. ReputationChanges { peer: PeerId, changes: Vec }, - /// An incoming message (request or response). - Message { - /// The peer who sent the message. - peer: PeerId, - /// The incoming message. - message: CustomMessage, - }, - - /// An outbound request failed. - OutboundFailure { - /// The peer to whom the request was sent. - peer: PeerId, - /// The (local) ID of the failed request. - request_id: OutboundRequestId, - /// The error that occurred. - error: OutboundFailure, - }, - /// An inbound request failed. - CustomInboundFailure { - /// The peer from whom the request was received. - peer: PeerId, - /// The ID of the failed inbound request. - request_id: InboundRequestId, - /// The error that occurred. - error: CustomInboundFailure, - }, - - /// A response to an inbound request has been sent. - /// - /// When this event is received, the response has been flushed on - /// the underlying transport connection. - CustomResponseSent { - /// The peer to whom the response was sent. - peer: PeerId, - /// The ID of the inbound request whose response was sent. - request_id: InboundRequestId, - }, - /// Opened a substream with the given node with the given notifications protocol. /// /// The protocol is always one of the notification protocols that have been registered. @@ -357,10 +319,10 @@ impl Behaviour { } } -impl From for BehaviourOut { - fn from(event: CustomMessageOutcome) -> Self { +impl From for BehaviourOut { + fn from(event: MessageOutcome) -> Self { match event { - CustomMessageOutcome::NotificationStreamOpened { + MessageOutcome::NotificationStreamOpened { remote, set_id, direction, @@ -375,14 +337,14 @@ impl From for BehaviourOut { received_handshake, notifications_sink, }, - CustomMessageOutcome::NotificationStreamReplaced { + MessageOutcome::NotificationStreamReplaced { remote, set_id, notifications_sink, } => BehaviourOut::NotificationStreamReplaced { remote, set_id, notifications_sink }, - CustomMessageOutcome::NotificationStreamClosed { remote, set_id } => + MessageOutcome::NotificationStreamClosed { remote, set_id } => BehaviourOut::NotificationStreamClosed { remote, set_id }, - CustomMessageOutcome::NotificationsReceived { remote, set_id, notification } => + MessageOutcome::NotificationsReceived { remote, set_id, notification } => BehaviourOut::NotificationsReceived { remote, set_id, notification }, } } @@ -397,14 +359,6 @@ impl From for BehaviourOut { BehaviourOut::RequestFinished { peer, protocol, duration, result }, request_responses::Event::ReputationChanges { peer, changes } => BehaviourOut::ReputationChanges { peer, changes }, - request_responses::Event::Message { peer, message } => - BehaviourOut::Message { peer, message }, - request_responses::Event::OutboundFailure { peer, request_id, error } => - BehaviourOut::OutboundFailure { peer, request_id, error }, - request_responses::Event::CustomInboundFailure { peer, request_id, error } => - BehaviourOut::CustomInboundFailure { peer, request_id, error }, - request_responses::Event::CustomResponseSent { peer, request_id } => - BehaviourOut::CustomResponseSent { peer, request_id }, } } } diff --git a/substrate/client/network/src/protocol.rs b/substrate/client/network/src/protocol.rs index 977c4c4de663..95104830d6bf 100644 --- a/substrate/client/network/src/protocol.rs +++ b/substrate/client/network/src/protocol.rs @@ -182,7 +182,7 @@ impl Protocol { /// Outcome of an incoming custom message. #[derive(Debug)] #[must_use] -pub enum CustomMessageOutcome { +pub enum MessageOutcome { /// Notification protocols have been opened with a remote. NotificationStreamOpened { remote: PeerId, @@ -226,7 +226,7 @@ pub enum CustomMessageOutcome { impl NetworkBehaviour for Protocol { type ConnectionHandler = ::ConnectionHandler; - type ToSwarm = CustomMessageOutcome; + type ToSwarm = MessageOutcome; fn handle_established_inbound_connection( &mut self, @@ -329,7 +329,7 @@ impl NetworkBehaviour for Protocol { None } else { match self.role_available(&peer_id, &received_handshake) { - true => Some(CustomMessageOutcome::NotificationStreamOpened { + true => Some(MessageOutcome::NotificationStreamOpened { remote: peer_id, set_id, direction, @@ -351,7 +351,7 @@ impl NetworkBehaviour for Protocol { None } else { (!self.bad_handshake_streams.contains(&peer_id)).then_some( - CustomMessageOutcome::NotificationStreamReplaced { + MessageOutcome::NotificationStreamReplaced { remote: peer_id, set_id, notifications_sink, @@ -364,7 +364,7 @@ impl NetworkBehaviour for Protocol { None } else { (!self.bad_handshake_streams.remove(&peer_id)).then_some( - CustomMessageOutcome::NotificationStreamClosed { remote: peer_id, set_id }, + MessageOutcome::NotificationStreamClosed { remote: peer_id, set_id }, ) } }, @@ -376,7 +376,7 @@ impl NetworkBehaviour for Protocol { None } else { (!self.bad_handshake_streams.contains(&peer_id)).then_some( - CustomMessageOutcome::NotificationsReceived { + MessageOutcome::NotificationsReceived { remote: peer_id, set_id, notification: message.freeze().into(), diff --git a/substrate/client/network/src/request_responses.rs b/substrate/client/network/src/request_responses.rs index 06cb56528a38..d8d7d515905e 100644 --- a/substrate/client/network/src/request_responses.rs +++ b/substrate/client/network/src/request_responses.rs @@ -65,11 +65,10 @@ use std::{ fmt::{Display,Formatter}, }; -pub use libp2p::request_response::{Config, InboundFailure, RequestId}; +pub use libp2p::request_response::{Config, RequestId}; /// Adding a custom OutboundFailure, not depending on libp2p #[derive(Debug, thiserror::Error)] -#[allow(missing_docs)] pub enum OutboundFailure { /// The request could not be sent because a dialing attempt failed. DialFailure, @@ -94,24 +93,7 @@ impl Display for OutboundFailure{ #[derive(Debug, thiserror::Error)] #[allow(missing_docs)] -pub enum CustomMessage { - Request { request_id: InboundRequestId, request: Vec, channel: ResponseChannel> }, - Response { request_id: OutboundRequestId, response: Vec }, -} - -impl Display for CustomMessage { - fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { - match self { - CustomMessage::Request {request_id,request,channel} => write!(f, "MessageRequest({:?}, {:?}, {:?})",request_id,request,channel), - CustomMessage::Response {request_id,response} => write!(f, "MessageResponse({:?}, {:?})",request_id, response), - } - } -} - -/// Adding a custom InboundFailure, not depending on libp2p -#[derive(Debug, thiserror::Error)] -#[allow(missing_docs)] -pub enum CustomInboundFailure { +pub enum InboundFailure { /// The inbound request timed out, either while reading the incoming request or before a /// response is sent Timeout, @@ -123,37 +105,17 @@ pub enum CustomInboundFailure { ResponseOmission, } -impl Display for CustomInboundFailure{ +impl Display for InboundFailure{ fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result{ match self { - CustomInboundFailure::Timeout => write!(f, "Timeout"), - CustomInboundFailure::ConnectionClosed => write!(f, "ConnectionClosed"), - CustomInboundFailure::UnsupportedProtocols => write!(f, "UnsupportedProtocols"), - CustomInboundFailure::ResponseOmission => write!(f, "ResponseOmission"), + InboundFailure::Timeout => write!(f, "Timeout"), + InboundFailure::ConnectionClosed => write!(f, "ConnectionClosed"), + InboundFailure::UnsupportedProtocols => write!(f, "UnsupportedProtocols"), + InboundFailure::ResponseOmission => write!(f, "ResponseOmission"), } } } -/// In preparation for a OutboundFailure Event -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] -pub struct OutboundRequestId(u64); - -impl fmt::Display for OutboundRequestId { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", self.0) - } -} - -/// In preparation for a OutboundFailure Event -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] -pub struct InboundRequestId(u64); - -impl fmt::Display for InboundRequestId { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", self.0) - } -} - /// Error in a request. #[derive(Debug, thiserror::Error)] #[allow(missing_docs)] @@ -336,44 +298,7 @@ pub enum Event { /// Reputation changes. changes: Vec, }, - /// An incoming message (request or response). - Message { - /// The peer who sent the message. - peer: PeerId, - /// The incoming message. - message: CustomMessage, - }, - - /// An outbound request failed. - OutboundFailure { - /// The peer to whom the request was sent. - peer: PeerId, - /// The (local) ID of the failed request. - request_id: OutboundRequestId, - /// The error that occurred. - error: OutboundFailure, - }, - - /// An inbound request failed. - CustomInboundFailure { - /// The peer from whom the request was received. - peer: PeerId, - /// The ID of the failed inbound request. - request_id: InboundRequestId, - /// The error that occurred. - error: CustomInboundFailure, - }, - - /// A response to an inbound request has been sent. - /// - /// When this event is received, the response has been flushed on - /// the underlying transport connection. - CustomResponseSent { - /// The peer to whom the response was sent. - peer: PeerId, - /// The ID of the inbound request whose response was sent. - request_id: InboundRequestId, - }, + } /// Combination of a protocol name and a request id. @@ -938,8 +863,6 @@ impl NetworkBehaviour for RequestResponsesBehaviour { // Try using the fallback request if the protocol was not // supported. if let request_response::OutboundFailure::UnsupportedProtocols = error { - let error_bis_out = - OutboundFailure::UnsupportedProtocols; if let Some((fallback_request, fallback_protocol)) = fallback_request { @@ -984,12 +907,11 @@ impl NetworkBehaviour for RequestResponsesBehaviour { continue }, }; - let error_bis_out = OutboundFailure::Timeout; let out = Event::RequestFinished { peer, protocol: protocol.clone(), duration: started.elapsed(), - result: Err(RequestFailure::Network(error_bis_out)), + result: Err(RequestFailure::Network(OutboundFailure::Timeout)), }; return Poll::Ready(ToSwarm::GenerateEvent(out)) @@ -998,14 +920,13 @@ impl NetworkBehaviour for RequestResponsesBehaviour { // An inbound request failed, either while reading the request or due to // failing to send a response. request_response::Event::InboundFailure { request_id, peer, .. } => { - let error_bis_in = CustomInboundFailure::Timeout; self.pending_responses_arrival_time .remove(&(protocol.clone(), request_id).into()); self.send_feedback.remove(&(protocol.clone(), request_id).into()); let out = Event::InboundRequest { peer, protocol: protocol.clone(), - result: Err(ResponseFailure::Network(error_bis_in)), + result: Err(ResponseFailure::Network(InboundFailure::Timeout)), }; return Poll::Ready(ToSwarm::GenerateEvent(out)) }, @@ -1079,7 +1000,7 @@ pub enum RegisterError { pub enum ResponseFailure { /// Problem on the network. #[error("Problem on the network: {0}")] - Network(CustomInboundFailure), + Network( InboundFailure), } /// Implements the libp2p [`Codec`] trait. Defines how streams of bytes are turned diff --git a/substrate/client/network/src/service.rs b/substrate/client/network/src/service.rs index a2775012d4b2..d69739ab659c 100644 --- a/substrate/client/network/src/service.rs +++ b/substrate/client/network/src/service.rs @@ -89,9 +89,9 @@ use sc_network_common::{ use sc_utils::mpsc::{tracing_unbounded, TracingUnboundedReceiver, TracingUnboundedSender}; use sp_runtime::traits::Block as BlockT; -pub use behaviour::{InboundFailure, ResponseFailure}; +pub use behaviour:: ResponseFailure; // Import our custom type -use crate::request_responses::{CustomInboundFailure, OutboundFailure}; +use crate::request_responses::{ InboundFailure, OutboundFailure}; pub use libp2p::identity::{DecodingError, Keypair, PublicKey}; pub use metrics::NotificationMetrics; pub use protocol::NotificationsSink; @@ -1517,10 +1517,10 @@ where }, Err(err) => { let reason = match err { - ResponseFailure::Network(CustomInboundFailure::Timeout) => + ResponseFailure::Network( InboundFailure::Timeout) => Some("timeout"), ResponseFailure::Network( - CustomInboundFailure::UnsupportedProtocols, + InboundFailure::UnsupportedProtocols, ) => // `UnsupportedProtocols` is reported for every single // inbound request whenever a request with an unsupported @@ -1528,10 +1528,10 @@ where // avoid confusions. None, ResponseFailure::Network( - CustomInboundFailure::ResponseOmission, + InboundFailure::ResponseOmission, ) => Some("busy-omitted"), ResponseFailure::Network( - CustomInboundFailure::ConnectionClosed, + InboundFailure::ConnectionClosed, ) => Some("connection-closed"), }; @@ -1565,7 +1565,6 @@ where RequestFailure::UnknownProtocol => "unknown-protocol", RequestFailure::Refused => "refused", RequestFailure::Obsolete => "obsolete", - RequestFailure::Network(OutboundFailure::DialFailure) => "dial-failure", RequestFailure::Network(OutboundFailure::Timeout) => @@ -1702,26 +1701,6 @@ where SwarmEvent::Behaviour(BehaviourOut::None) => { // Ignored event from lower layers. }, - SwarmEvent::Behaviour(BehaviourOut::Message { peer, message }) => { - // Ignored event from lower layers. - }, - SwarmEvent::Behaviour(BehaviourOut::OutboundFailure { - peer, - request_id, - error, - }) => { - // Ignored event from lower layers. - }, - SwarmEvent::Behaviour(BehaviourOut::CustomInboundFailure { - peer, - request_id, - error, - }) => { - // Ignored event from lower layers. - }, - SwarmEvent::Behaviour(BehaviourOut::CustomResponseSent { peer, request_id }) => { - // Ignored event from lower layers. - }, SwarmEvent::ConnectionEstablished { peer_id, endpoint, diff --git a/substrate/client/network/sync/src/engine.rs b/substrate/client/network/sync/src/engine.rs index 17480a1884b0..4f53f5984f09 100644 --- a/substrate/client/network/sync/src/engine.rs +++ b/substrate/client/network/sync/src/engine.rs @@ -1196,7 +1196,6 @@ where Ok(Err(e)) => { debug!(target: LOG_TARGET, "Request to peer {peer_id:?} failed: {e:?}."); - // Using Our custom type Network(OutboundFailure) match e { RequestFailure::Network(OutboundFailure::Timeout) => { self.network_service.report_peer(peer_id, rep::TIMEOUT); From aab86143094767fb89a322059a0a77073f889248 Mon Sep 17 00:00:00 2001 From: ndkazu Date: Fri, 13 Sep 2024 15:41:18 +0900 Subject: [PATCH 22/37] Reverted where it was necessary --- .../network/availability-recovery/src/task/strategy/full.rs | 2 +- .../network/availability-recovery/src/task/strategy/mod.rs | 2 +- polkadot/node/network/bridge/src/network.rs | 2 +- .../node/network/protocol/src/request_response/outgoing.rs | 3 +-- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/polkadot/node/network/availability-recovery/src/task/strategy/full.rs b/polkadot/node/network/availability-recovery/src/task/strategy/full.rs index ed39f516490d..1d7fbe8ea3c8 100644 --- a/polkadot/node/network/availability-recovery/src/task/strategy/full.rs +++ b/polkadot/node/network/availability-recovery/src/task/strategy/full.rs @@ -171,4 +171,4 @@ impl RecoveryStrategy } } } -} \ No newline at end of file +} diff --git a/polkadot/node/network/availability-recovery/src/task/strategy/mod.rs b/polkadot/node/network/availability-recovery/src/task/strategy/mod.rs index eed24587ce8d..1403277c8a95 100644 --- a/polkadot/node/network/availability-recovery/src/task/strategy/mod.rs +++ b/polkadot/node/network/availability-recovery/src/task/strategy/mod.rs @@ -1555,4 +1555,4 @@ mod tests { assert_eq!(is_unavailable(0, 0, 0, 3), true); assert_eq!(is_unavailable(2, 3, 2, 10), true); } -} \ No newline at end of file +} diff --git a/polkadot/node/network/bridge/src/network.rs b/polkadot/node/network/bridge/src/network.rs index 926141d4dc18..1f438df2d148 100644 --- a/polkadot/node/network/bridge/src/network.rs +++ b/polkadot/node/network/bridge/src/network.rs @@ -364,4 +364,4 @@ pub async fn get_peer_id_by_authority_id( .into_iter() .flat_map(|list| list.into_iter()) .find_map(|addr| parse_addr(addr).ok().map(|(p, _)| p)) -} \ No newline at end of file +} diff --git a/polkadot/node/network/protocol/src/request_response/outgoing.rs b/polkadot/node/network/protocol/src/request_response/outgoing.rs index 92e4d605994a..27f0f34bf8d4 100644 --- a/polkadot/node/network/protocol/src/request_response/outgoing.rs +++ b/polkadot/node/network/protocol/src/request_response/outgoing.rs @@ -23,7 +23,6 @@ use sc_network as network; use sc_network_types::PeerId; use polkadot_primitives::AuthorityDiscoveryId; -use sc_network::request_responses::OutboundFailure; use super::{v1, v2, IsRequest, Protocol}; @@ -98,7 +97,7 @@ impl RequestError { Self::Canceled(_) | Self::NetworkError(network::RequestFailure::Obsolete) | Self::NetworkError(network::RequestFailure::Network( - OutboundFailure::Timeout, + network::OutboundFailure::Timeout, )) => true, _ => false, } From 812734c3789136ba59e2c43adf5e4cecb27c368e Mon Sep 17 00:00:00 2001 From: ndkazu Date: Fri, 13 Sep 2024 15:41:50 +0900 Subject: [PATCH 23/37] corrections --- substrate/client/network/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/substrate/client/network/src/lib.rs b/substrate/client/network/src/lib.rs index 3ee362f90096..e0d590551c8c 100644 --- a/substrate/client/network/src/lib.rs +++ b/substrate/client/network/src/lib.rs @@ -290,6 +290,7 @@ pub use service::{ PublicKey, }; pub use types::ProtocolName; +pub use crate::request_responses::OutboundFailure; /// The maximum allowed number of established connections per peer. /// From 67fe2108b4c7c755457930f638e398b002ac89c5 Mon Sep 17 00:00:00 2001 From: ndkazu Date: Mon, 16 Sep 2024 10:37:19 +0900 Subject: [PATCH 24/37] Created a prdoc --- prdoc/pr_4974.prdoc | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 prdoc/pr_4974.prdoc diff --git a/prdoc/pr_4974.prdoc b/prdoc/pr_4974.prdoc new file mode 100644 index 000000000000..72b6957f0d33 --- /dev/null +++ b/prdoc/pr_4974.prdoc @@ -0,0 +1,15 @@ +# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0 +# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json + +title: "Remove libp2p dependency from sc-network-sync" + +doc: + - audience: Node Dev + description: | + This PR removes `libp2p::request_response::OutboundFailure` from `substrate/client/network/sync/src/engine.rs`. + +crates: + - name: sc-network + bump: patch + - name: sc-network-sync + bump: patch \ No newline at end of file From 73d4005418763ceb98ce193809d5d93d3d1b4226 Mon Sep 17 00:00:00 2001 From: ndkazu Date: Tue, 17 Sep 2024 22:50:39 +0900 Subject: [PATCH 25/37] implemented From<...> for OutbounFailure & InboundFailure --- substrate/client/network/src/behaviour.rs | 21 ++++----- substrate/client/network/src/protocol.rs | 12 ++--- .../client/network/src/request_responses.rs | 44 ++++++++++++++----- substrate/client/network/src/service.rs | 4 +- 4 files changed, 49 insertions(+), 32 deletions(-) diff --git a/substrate/client/network/src/behaviour.rs b/substrate/client/network/src/behaviour.rs index aa26dd1d6209..9a6324dafd37 100644 --- a/substrate/client/network/src/behaviour.rs +++ b/substrate/client/network/src/behaviour.rs @@ -21,12 +21,9 @@ use crate::{ event::DhtEvent, peer_info, peer_store::PeerStoreProvider, - protocol::{MessageOutcome, NotificationsSink, Protocol}, + protocol::{CustomMessageOutcome, NotificationsSink, Protocol}, protocol_controller::SetId, - request_responses::{ - self, OutboundFailure, IfDisconnected, - ProtocolConfig, RequestFailure, - }, + request_responses::{self, IfDisconnected, ProtocolConfig, RequestFailure}, service::traits::Direction, types::ProtocolName, ReputationChange, @@ -51,7 +48,7 @@ use std::{ time::{Duration, Instant}, }; -pub use crate::request_responses::{InboundFailure, ResponseFailure}; +pub use crate::request_responses::{InboundFailure, OutboundFailure, ResponseFailure}; /// General behaviour of the network. Combines all protocols together. #[derive(NetworkBehaviour)] @@ -319,10 +316,10 @@ impl Behaviour { } } -impl From for BehaviourOut { - fn from(event: MessageOutcome) -> Self { +impl From for BehaviourOut { + fn from(event: CustomMessageOutcome) -> Self { match event { - MessageOutcome::NotificationStreamOpened { + CustomMessageOutcome::NotificationStreamOpened { remote, set_id, direction, @@ -337,14 +334,14 @@ impl From for BehaviourOut { received_handshake, notifications_sink, }, - MessageOutcome::NotificationStreamReplaced { + CustomMessageOutcome::NotificationStreamReplaced { remote, set_id, notifications_sink, } => BehaviourOut::NotificationStreamReplaced { remote, set_id, notifications_sink }, - MessageOutcome::NotificationStreamClosed { remote, set_id } => + CustomMessageOutcome::NotificationStreamClosed { remote, set_id } => BehaviourOut::NotificationStreamClosed { remote, set_id }, - MessageOutcome::NotificationsReceived { remote, set_id, notification } => + CustomMessageOutcome::NotificationsReceived { remote, set_id, notification } => BehaviourOut::NotificationsReceived { remote, set_id, notification }, } } diff --git a/substrate/client/network/src/protocol.rs b/substrate/client/network/src/protocol.rs index 95104830d6bf..977c4c4de663 100644 --- a/substrate/client/network/src/protocol.rs +++ b/substrate/client/network/src/protocol.rs @@ -182,7 +182,7 @@ impl Protocol { /// Outcome of an incoming custom message. #[derive(Debug)] #[must_use] -pub enum MessageOutcome { +pub enum CustomMessageOutcome { /// Notification protocols have been opened with a remote. NotificationStreamOpened { remote: PeerId, @@ -226,7 +226,7 @@ pub enum MessageOutcome { impl NetworkBehaviour for Protocol { type ConnectionHandler = ::ConnectionHandler; - type ToSwarm = MessageOutcome; + type ToSwarm = CustomMessageOutcome; fn handle_established_inbound_connection( &mut self, @@ -329,7 +329,7 @@ impl NetworkBehaviour for Protocol { None } else { match self.role_available(&peer_id, &received_handshake) { - true => Some(MessageOutcome::NotificationStreamOpened { + true => Some(CustomMessageOutcome::NotificationStreamOpened { remote: peer_id, set_id, direction, @@ -351,7 +351,7 @@ impl NetworkBehaviour for Protocol { None } else { (!self.bad_handshake_streams.contains(&peer_id)).then_some( - MessageOutcome::NotificationStreamReplaced { + CustomMessageOutcome::NotificationStreamReplaced { remote: peer_id, set_id, notifications_sink, @@ -364,7 +364,7 @@ impl NetworkBehaviour for Protocol { None } else { (!self.bad_handshake_streams.remove(&peer_id)).then_some( - MessageOutcome::NotificationStreamClosed { remote: peer_id, set_id }, + CustomMessageOutcome::NotificationStreamClosed { remote: peer_id, set_id }, ) } }, @@ -376,7 +376,7 @@ impl NetworkBehaviour for Protocol { None } else { (!self.bad_handshake_streams.contains(&peer_id)).then_some( - MessageOutcome::NotificationsReceived { + CustomMessageOutcome::NotificationsReceived { remote: peer_id, set_id, notification: message.freeze().into(), diff --git a/substrate/client/network/src/request_responses.rs b/substrate/client/network/src/request_responses.rs index d8d7d515905e..b420fe729939 100644 --- a/substrate/client/network/src/request_responses.rs +++ b/substrate/client/network/src/request_responses.rs @@ -91,6 +91,17 @@ impl Display for OutboundFailure{ } } +impl From for OutboundFailure{ + fn from(out: request_response::OutboundFailure) -> Self { + match out{ + request_response::OutboundFailure::DialFailure => OutboundFailure::DialFailure, + request_response::OutboundFailure::Timeout => OutboundFailure::Timeout, + request_response::OutboundFailure::ConnectionClosed => OutboundFailure::ConnectionClosed, + request_response::OutboundFailure::UnsupportedProtocols => OutboundFailure::UnsupportedProtocols, + } + } +} + #[derive(Debug, thiserror::Error)] #[allow(missing_docs)] pub enum InboundFailure { @@ -116,6 +127,17 @@ impl Display for InboundFailure{ } } +impl From for InboundFailure{ + fn from(out: request_response::InboundFailure) -> Self { + match out{ + request_response::InboundFailure::ResponseOmission => InboundFailure::ResponseOmission, + request_response::InboundFailure::Timeout => InboundFailure::Timeout, + request_response::InboundFailure::ConnectionClosed => InboundFailure::ConnectionClosed, + request_response::InboundFailure::UnsupportedProtocols => InboundFailure::UnsupportedProtocols, + } + } +} + /// Error in a request. #[derive(Debug, thiserror::Error)] #[allow(missing_docs)] @@ -298,7 +320,6 @@ pub enum Event { /// Reputation changes. changes: Vec, }, - } /// Combination of a protocol name and a request id. @@ -735,9 +756,9 @@ impl NetworkBehaviour for RequestResponsesBehaviour { // Received a request from a remote. request_response::Event::Message { peer, - message: - request_response::Message::Request { - request_id, request, channel, .. + message: + request_response::Message::Request { + request_id, request, channel, .. }, } => { self.pending_responses_arrival_time @@ -883,9 +904,7 @@ impl NetworkBehaviour for RequestResponsesBehaviour { } if response_tx - .send(Err(RequestFailure::Network( - OutboundFailure::Timeout, - ))) + .send(Err(RequestFailure::Network(error.clone().into()))) .is_err() { log::debug!( @@ -907,11 +926,12 @@ impl NetworkBehaviour for RequestResponsesBehaviour { continue }, }; + let out = Event::RequestFinished { peer, protocol: protocol.clone(), duration: started.elapsed(), - result: Err(RequestFailure::Network(OutboundFailure::Timeout)), + result: Err(RequestFailure::Network(error.into())), }; return Poll::Ready(ToSwarm::GenerateEvent(out)) @@ -919,14 +939,16 @@ impl NetworkBehaviour for RequestResponsesBehaviour { // An inbound request failed, either while reading the request or due to // failing to send a response. - request_response::Event::InboundFailure { request_id, peer, .. } => { + request_response::Event::InboundFailure { + request_id, peer, error, .. + } => { self.pending_responses_arrival_time .remove(&(protocol.clone(), request_id).into()); self.send_feedback.remove(&(protocol.clone(), request_id).into()); let out = Event::InboundRequest { peer, protocol: protocol.clone(), - result: Err(ResponseFailure::Network(InboundFailure::Timeout)), + result: Err(ResponseFailure::Network(error.into())), }; return Poll::Ready(ToSwarm::GenerateEvent(out)) }, @@ -1000,7 +1022,7 @@ pub enum RegisterError { pub enum ResponseFailure { /// Problem on the network. #[error("Problem on the network: {0}")] - Network( InboundFailure), + Network(InboundFailure), } /// Implements the libp2p [`Codec`] trait. Defines how streams of bytes are turned diff --git a/substrate/client/network/src/service.rs b/substrate/client/network/src/service.rs index d69739ab659c..3459f11ab323 100644 --- a/substrate/client/network/src/service.rs +++ b/substrate/client/network/src/service.rs @@ -89,9 +89,7 @@ use sc_network_common::{ use sc_utils::mpsc::{tracing_unbounded, TracingUnboundedReceiver, TracingUnboundedSender}; use sp_runtime::traits::Block as BlockT; -pub use behaviour:: ResponseFailure; -// Import our custom type -use crate::request_responses::{ InboundFailure, OutboundFailure}; +pub use behaviour::{InboundFailure, OutboundFailure, ResponseFailure}; pub use libp2p::identity::{DecodingError, Keypair, PublicKey}; pub use metrics::NotificationMetrics; pub use protocol::NotificationsSink; From 2fcf160b4912d6df1ff724130c14f4d698a20548 Mon Sep 17 00:00:00 2001 From: ndkazu Date: Tue, 17 Sep 2024 22:53:54 +0900 Subject: [PATCH 26/37] Reverted changes unrelated to the purpose of the PR --- substrate/client/network/src/lib.rs | 3 +-- substrate/client/network/src/service.rs | 16 ++++++---------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/substrate/client/network/src/lib.rs b/substrate/client/network/src/lib.rs index e0d590551c8c..99a972f914e2 100644 --- a/substrate/client/network/src/lib.rs +++ b/substrate/client/network/src/lib.rs @@ -286,11 +286,10 @@ pub use service::{ NotificationSender as NotificationSenderT, NotificationSenderError, NotificationSenderReady, NotificationService, }, - DecodingError, Keypair, NetworkService, NetworkWorker, NotificationSender, + DecodingError, Keypair, NetworkService, NetworkWorker, NotificationSender, OutboundFailure, PublicKey, }; pub use types::ProtocolName; -pub use crate::request_responses::OutboundFailure; /// The maximum allowed number of established connections per peer. /// diff --git a/substrate/client/network/src/service.rs b/substrate/client/network/src/service.rs index 3459f11ab323..1562bea4e796 100644 --- a/substrate/client/network/src/service.rs +++ b/substrate/client/network/src/service.rs @@ -1515,22 +1515,18 @@ where }, Err(err) => { let reason = match err { - ResponseFailure::Network( InboundFailure::Timeout) => + ResponseFailure::Network(InboundFailure::Timeout) => Some("timeout"), - ResponseFailure::Network( - InboundFailure::UnsupportedProtocols, - ) => + ResponseFailure::Network(InboundFailure::UnsupportedProtocols) => // `UnsupportedProtocols` is reported for every single // inbound request whenever a request with an unsupported // protocol is received. This is not reported in order to // avoid confusions. None, - ResponseFailure::Network( - InboundFailure::ResponseOmission, - ) => Some("busy-omitted"), - ResponseFailure::Network( - InboundFailure::ConnectionClosed, - ) => Some("connection-closed"), + ResponseFailure::Network(InboundFailure::ResponseOmission) => + Some("busy-omitted"), + ResponseFailure::Network(InboundFailure::ConnectionClosed) => + Some("connection-closed"), }; if let Some(reason) = reason { From c2abf705a17524204e4fb2ed4b38cb032e92b8e7 Mon Sep 17 00:00:00 2001 From: ndkazu Date: Tue, 17 Sep 2024 22:56:34 +0900 Subject: [PATCH 27/37] more revert --- substrate/client/network/src/service.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/substrate/client/network/src/service.rs b/substrate/client/network/src/service.rs index 1562bea4e796..71d0b45aa06d 100644 --- a/substrate/client/network/src/service.rs +++ b/substrate/client/network/src/service.rs @@ -1561,14 +1561,11 @@ where RequestFailure::Obsolete => "obsolete", RequestFailure::Network(OutboundFailure::DialFailure) => "dial-failure", - RequestFailure::Network(OutboundFailure::Timeout) => - "timeout", - RequestFailure::Network( - OutboundFailure::ConnectionClosed, - ) => "connection-closed", - RequestFailure::Network( - OutboundFailure::UnsupportedProtocols, - ) => "unsupported", + RequestFailure::Network(OutboundFailure::Timeout) => "timeout", + RequestFailure::Network(OutboundFailure::ConnectionClosed) => + "connection-closed", + RequestFailure::Network(OutboundFailure::UnsupportedProtocols) => + "unsupported", }; metrics From 34cdc57528ba53d6a190f8a744dd64b2ce6d39f4 Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Tue, 17 Sep 2024 14:24:54 +0000 Subject: [PATCH 28/37] ".git/.scripts/commands/fmt/fmt.sh" --- .../client/network/src/request_responses.rs | 50 +++++++++++-------- substrate/client/network/sync/src/engine.rs | 2 +- 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/substrate/client/network/src/request_responses.rs b/substrate/client/network/src/request_responses.rs index b420fe729939..8573c92ca392 100644 --- a/substrate/client/network/src/request_responses.rs +++ b/substrate/client/network/src/request_responses.rs @@ -56,13 +56,14 @@ use libp2p::{ use std::{ collections::{hash_map::Entry, HashMap}, - fmt, io, iter, + fmt, + fmt::{Display, Formatter}, + io, iter, ops::Deref, pin::Pin, sync::Arc, task::{Context, Poll}, time::{Duration, Instant}, - fmt::{Display,Formatter}, }; pub use libp2p::request_response::{Config, RequestId}; @@ -80,8 +81,8 @@ pub enum OutboundFailure { UnsupportedProtocols, } -impl Display for OutboundFailure{ - fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result{ +impl Display for OutboundFailure { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { match self { OutboundFailure::DialFailure => write!(f, "DialFailure"), OutboundFailure::Timeout => write!(f, "Timeout"), @@ -91,20 +92,22 @@ impl Display for OutboundFailure{ } } -impl From for OutboundFailure{ +impl From for OutboundFailure { fn from(out: request_response::OutboundFailure) -> Self { - match out{ + match out { request_response::OutboundFailure::DialFailure => OutboundFailure::DialFailure, request_response::OutboundFailure::Timeout => OutboundFailure::Timeout, - request_response::OutboundFailure::ConnectionClosed => OutboundFailure::ConnectionClosed, - request_response::OutboundFailure::UnsupportedProtocols => OutboundFailure::UnsupportedProtocols, + request_response::OutboundFailure::ConnectionClosed => + OutboundFailure::ConnectionClosed, + request_response::OutboundFailure::UnsupportedProtocols => + OutboundFailure::UnsupportedProtocols, } } } #[derive(Debug, thiserror::Error)] #[allow(missing_docs)] -pub enum InboundFailure { +pub enum InboundFailure { /// The inbound request timed out, either while reading the incoming request or before a /// response is sent Timeout, @@ -116,24 +119,25 @@ pub enum InboundFailure { ResponseOmission, } -impl Display for InboundFailure{ - fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result{ +impl Display for InboundFailure { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { match self { - InboundFailure::Timeout => write!(f, "Timeout"), - InboundFailure::ConnectionClosed => write!(f, "ConnectionClosed"), - InboundFailure::UnsupportedProtocols => write!(f, "UnsupportedProtocols"), - InboundFailure::ResponseOmission => write!(f, "ResponseOmission"), + InboundFailure::Timeout => write!(f, "Timeout"), + InboundFailure::ConnectionClosed => write!(f, "ConnectionClosed"), + InboundFailure::UnsupportedProtocols => write!(f, "UnsupportedProtocols"), + InboundFailure::ResponseOmission => write!(f, "ResponseOmission"), } } } -impl From for InboundFailure{ +impl From for InboundFailure { fn from(out: request_response::InboundFailure) -> Self { - match out{ + match out { request_response::InboundFailure::ResponseOmission => InboundFailure::ResponseOmission, request_response::InboundFailure::Timeout => InboundFailure::Timeout, request_response::InboundFailure::ConnectionClosed => InboundFailure::ConnectionClosed, - request_response::InboundFailure::UnsupportedProtocols => InboundFailure::UnsupportedProtocols, + request_response::InboundFailure::UnsupportedProtocols => + InboundFailure::UnsupportedProtocols, } } } @@ -756,9 +760,9 @@ impl NetworkBehaviour for RequestResponsesBehaviour { // Received a request from a remote. request_response::Event::Message { peer, - message: - request_response::Message::Request { - request_id, request, channel, .. + message: + request_response::Message::Request { + request_id, request, channel, .. }, } => { self.pending_responses_arrival_time @@ -883,7 +887,9 @@ impl NetworkBehaviour for RequestResponsesBehaviour { }) => { // Try using the fallback request if the protocol was not // supported. - if let request_response::OutboundFailure::UnsupportedProtocols = error { + if let request_response::OutboundFailure::UnsupportedProtocols = + error + { if let Some((fallback_request, fallback_protocol)) = fallback_request { diff --git a/substrate/client/network/sync/src/engine.rs b/substrate/client/network/sync/src/engine.rs index 02d753e4301a..96c1750b3116 100644 --- a/substrate/client/network/sync/src/engine.rs +++ b/substrate/client/network/sync/src/engine.rs @@ -55,7 +55,7 @@ use sc_consensus::{import_queue::ImportQueueService, IncomingBlock}; use sc_network::{ config::{FullNetworkConfiguration, NotificationHandshake, ProtocolId, SetConfig}, peer_store::PeerStoreProvider, - request_responses::{OutboundFailure, IfDisconnected, RequestFailure}, + request_responses::{IfDisconnected, OutboundFailure, RequestFailure}, service::{ traits::{Direction, NotificationConfig, NotificationEvent, ValidationResult}, NotificationMetrics, From 1ee40e1ee5214e30382f280a1cca1ffeadc182aa Mon Sep 17 00:00:00 2001 From: ndkazu Date: Tue, 17 Sep 2024 23:28:20 +0900 Subject: [PATCH 29/37] Added newline at EOF --- prdoc/pr_4974.prdoc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/prdoc/pr_4974.prdoc b/prdoc/pr_4974.prdoc index 72b6957f0d33..8a32e437f2e8 100644 --- a/prdoc/pr_4974.prdoc +++ b/prdoc/pr_4974.prdoc @@ -12,4 +12,5 @@ crates: - name: sc-network bump: patch - name: sc-network-sync - bump: patch \ No newline at end of file + bump: patch + \ No newline at end of file From a354c2eb92620146969761f79f3f0bcdc7f1c127 Mon Sep 17 00:00:00 2001 From: ndkazu Date: Wed, 18 Sep 2024 00:38:36 +0900 Subject: [PATCH 30/37] Further corrections --- .../src/litep2p/shim/request_response/mod.rs | 3 +-- .../client/network/src/request_responses.rs | 22 ++++++++++--------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/substrate/client/network/src/litep2p/shim/request_response/mod.rs b/substrate/client/network/src/litep2p/shim/request_response/mod.rs index 864aa040c119..bfd7a60ef9fe 100644 --- a/substrate/client/network/src/litep2p/shim/request_response/mod.rs +++ b/substrate/client/network/src/litep2p/shim/request_response/mod.rs @@ -24,10 +24,9 @@ use crate::{ peer_store::PeerStoreProvider, request_responses::{IncomingRequest, OutgoingResponse}, service::{metrics::Metrics, traits::RequestResponseConfig as RequestResponseConfigT}, - IfDisconnected, ProtocolName, RequestFailure, + IfDisconnected, OutboundFailure, ProtocolName, RequestFailure, }; -use crate::request_responses::OutboundFailure; use futures::{channel::oneshot, future::BoxFuture, stream::FuturesUnordered, StreamExt}; use litep2p::{ error::{ImmediateDialError, NegotiationError, SubstreamError}, diff --git a/substrate/client/network/src/request_responses.rs b/substrate/client/network/src/request_responses.rs index 8573c92ca392..f14d5f580ef2 100644 --- a/substrate/client/network/src/request_responses.rs +++ b/substrate/client/network/src/request_responses.rs @@ -68,7 +68,8 @@ use std::{ pub use libp2p::request_response::{Config, RequestId}; -/// Adding a custom OutboundFailure, not depending on libp2p +/// Possible failures occurring in the context of sending an outbound request and receiving the response. + #[derive(Debug, thiserror::Error)] pub enum OutboundFailure { /// The request could not be sent because a dialing attempt failed. @@ -84,10 +85,10 @@ pub enum OutboundFailure { impl Display for OutboundFailure { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { match self { - OutboundFailure::DialFailure => write!(f, "DialFailure"), - OutboundFailure::Timeout => write!(f, "Timeout"), - OutboundFailure::ConnectionClosed => write!(f, "ConnectionClosed"), - OutboundFailure::UnsupportedProtocols => write!(f, "UnsupportedProtocols"), + OutboundFailure::DialFailure => write!(f, "Failed to dial the requested peer"), + OutboundFailure::Timeout => write!(f, "Timeout while waiting for a response"), + OutboundFailure::ConnectionClosed => write!(f, "Connection was closed before a response was received"), + OutboundFailure::UnsupportedProtocols => write!(f, "The remote supports none of the requested protocols"), } } } @@ -105,8 +106,9 @@ impl From for OutboundFailure { } } +/// Possible failures occurring in the context of receiving an inbound request and sending a response. + #[derive(Debug, thiserror::Error)] -#[allow(missing_docs)] pub enum InboundFailure { /// The inbound request timed out, either while reading the incoming request or before a /// response is sent @@ -122,10 +124,10 @@ pub enum InboundFailure { impl Display for InboundFailure { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { match self { - InboundFailure::Timeout => write!(f, "Timeout"), - InboundFailure::ConnectionClosed => write!(f, "ConnectionClosed"), - InboundFailure::UnsupportedProtocols => write!(f, "UnsupportedProtocols"), - InboundFailure::ResponseOmission => write!(f, "ResponseOmission"), + InboundFailure::Timeout => write!(f, "Timeout while receiving request or sending response"), + InboundFailure::ConnectionClosed => write!(f, "Connection was closed before a response could be sent"), + InboundFailure::UnsupportedProtocols => write!(f, "The local peer supports none of the protocols requested by the remote"), + InboundFailure::ResponseOmission => write!(f, "The response channel was dropped without sending a response to the remote"), } } } From abc6f68341b4795a0e82c63caf9a9924f0a32efc Mon Sep 17 00:00:00 2001 From: ndkazu Date: Wed, 18 Sep 2024 00:43:34 +0900 Subject: [PATCH 31/37] correcting format --- substrate/client/network/src/request_responses.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/substrate/client/network/src/request_responses.rs b/substrate/client/network/src/request_responses.rs index f14d5f580ef2..e99f80f71731 100644 --- a/substrate/client/network/src/request_responses.rs +++ b/substrate/client/network/src/request_responses.rs @@ -68,7 +68,8 @@ use std::{ pub use libp2p::request_response::{Config, RequestId}; -/// Possible failures occurring in the context of sending an outbound request and receiving the response. +/// Possible failures occurring in the context of sending an outbound request and receiving the +/// response. #[derive(Debug, thiserror::Error)] pub enum OutboundFailure { @@ -106,7 +107,8 @@ impl From for OutboundFailure { } } -/// Possible failures occurring in the context of receiving an inbound request and sending a response. +/// Possible failures occurring in the context of receiving an inbound request and sending a +/// response. #[derive(Debug, thiserror::Error)] pub enum InboundFailure { From dfcc68932aeba3f04a6b2409dfdfc8442f9c7f6f Mon Sep 17 00:00:00 2001 From: ndkazu Date: Wed, 18 Sep 2024 00:51:52 +0900 Subject: [PATCH 32/37] more format correction --- .../client/network/src/request_responses.rs | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/substrate/client/network/src/request_responses.rs b/substrate/client/network/src/request_responses.rs index e99f80f71731..1b0effeee1f4 100644 --- a/substrate/client/network/src/request_responses.rs +++ b/substrate/client/network/src/request_responses.rs @@ -88,8 +88,10 @@ impl Display for OutboundFailure { match self { OutboundFailure::DialFailure => write!(f, "Failed to dial the requested peer"), OutboundFailure::Timeout => write!(f, "Timeout while waiting for a response"), - OutboundFailure::ConnectionClosed => write!(f, "Connection was closed before a response was received"), - OutboundFailure::UnsupportedProtocols => write!(f, "The remote supports none of the requested protocols"), + OutboundFailure::ConnectionClosed => + write!(f, "Connection was closed before a response was received"), + OutboundFailure::UnsupportedProtocols => + write!(f, "The remote supports none of the requested protocols"), } } } @@ -126,10 +128,16 @@ pub enum InboundFailure { impl Display for InboundFailure { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { match self { - InboundFailure::Timeout => write!(f, "Timeout while receiving request or sending response"), - InboundFailure::ConnectionClosed => write!(f, "Connection was closed before a response could be sent"), - InboundFailure::UnsupportedProtocols => write!(f, "The local peer supports none of the protocols requested by the remote"), - InboundFailure::ResponseOmission => write!(f, "The response channel was dropped without sending a response to the remote"), + InboundFailure::Timeout => + write!(f, "Timeout while receiving request or sending response"), + InboundFailure::ConnectionClosed => + write!(f, "Connection was closed before a response could be sent"), + InboundFailure::UnsupportedProtocols => + write!(f, "The local peer supports none of the protocols requested by the remote"), + InboundFailure::ResponseOmission => write!( + f, + "The response channel was dropped without sending a response to the remote" + ), } } } From 7bb250faa54de0f1696482a6190b078228c6d356 Mon Sep 17 00:00:00 2001 From: ndkazu Date: Wed, 18 Sep 2024 00:59:56 +0900 Subject: [PATCH 33/37] removed space --- substrate/client/network/src/request_responses.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/substrate/client/network/src/request_responses.rs b/substrate/client/network/src/request_responses.rs index 1b0effeee1f4..80529372b96d 100644 --- a/substrate/client/network/src/request_responses.rs +++ b/substrate/client/network/src/request_responses.rs @@ -70,7 +70,6 @@ pub use libp2p::request_response::{Config, RequestId}; /// Possible failures occurring in the context of sending an outbound request and receiving the /// response. - #[derive(Debug, thiserror::Error)] pub enum OutboundFailure { /// The request could not be sent because a dialing attempt failed. @@ -111,7 +110,6 @@ impl From for OutboundFailure { /// Possible failures occurring in the context of receiving an inbound request and sending a /// response. - #[derive(Debug, thiserror::Error)] pub enum InboundFailure { /// The inbound request timed out, either while reading the incoming request or before a From ba729b5b458456fde2362b8e9346fd5829c251c1 Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Tue, 17 Sep 2024 16:02:21 +0000 Subject: [PATCH 34/37] ".git/.scripts/commands/fmt/fmt.sh" --- .../client/network/src/request_responses.rs | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/substrate/client/network/src/request_responses.rs b/substrate/client/network/src/request_responses.rs index 80529372b96d..40296e6a973a 100644 --- a/substrate/client/network/src/request_responses.rs +++ b/substrate/client/network/src/request_responses.rs @@ -87,10 +87,10 @@ impl Display for OutboundFailure { match self { OutboundFailure::DialFailure => write!(f, "Failed to dial the requested peer"), OutboundFailure::Timeout => write!(f, "Timeout while waiting for a response"), - OutboundFailure::ConnectionClosed => - write!(f, "Connection was closed before a response was received"), - OutboundFailure::UnsupportedProtocols => - write!(f, "The remote supports none of the requested protocols"), + OutboundFailure::ConnectionClosed => + write!(f, "Connection was closed before a response was received"), + OutboundFailure::UnsupportedProtocols => + write!(f, "The remote supports none of the requested protocols"), } } } @@ -126,16 +126,16 @@ pub enum InboundFailure { impl Display for InboundFailure { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { match self { - InboundFailure::Timeout => - write!(f, "Timeout while receiving request or sending response"), - InboundFailure::ConnectionClosed => - write!(f, "Connection was closed before a response could be sent"), - InboundFailure::UnsupportedProtocols => - write!(f, "The local peer supports none of the protocols requested by the remote"), + InboundFailure::Timeout => + write!(f, "Timeout while receiving request or sending response"), + InboundFailure::ConnectionClosed => + write!(f, "Connection was closed before a response could be sent"), + InboundFailure::UnsupportedProtocols => + write!(f, "The local peer supports none of the protocols requested by the remote"), InboundFailure::ResponseOmission => write!( - f, - "The response channel was dropped without sending a response to the remote" - ), + f, + "The response channel was dropped without sending a response to the remote" + ), } } } From c969d2681ee2e92388fa8a66d9c620342d055f0e Mon Sep 17 00:00:00 2001 From: ndkazu Date: Wed, 18 Sep 2024 01:35:23 +0900 Subject: [PATCH 35/37] Latest review corrections --- .../client/network/src/request_responses.rs | 46 +++++-------------- 1 file changed, 11 insertions(+), 35 deletions(-) diff --git a/substrate/client/network/src/request_responses.rs b/substrate/client/network/src/request_responses.rs index 40296e6a973a..c2652273ca82 100644 --- a/substrate/client/network/src/request_responses.rs +++ b/substrate/client/network/src/request_responses.rs @@ -44,7 +44,7 @@ use crate::{ use futures::{channel::oneshot, prelude::*}; use libp2p::{ core::{Endpoint, Multiaddr}, - request_response::{self, Behaviour, Codec, ProtocolSupport, ResponseChannel}, + request_response::{self, Behaviour, Codec, Message, ProtocolSupport, ResponseChannel}, swarm::{ behaviour::{ConnectionClosed, FromSwarm}, handler::multi::MultiHandler, @@ -56,8 +56,6 @@ use libp2p::{ use std::{ collections::{hash_map::Entry, HashMap}, - fmt, - fmt::{Display, Formatter}, io, iter, ops::Deref, pin::Pin, @@ -73,28 +71,19 @@ pub use libp2p::request_response::{Config, RequestId}; #[derive(Debug, thiserror::Error)] pub enum OutboundFailure { /// The request could not be sent because a dialing attempt failed. + #[error("Failed to dial the requested peer")] DialFailure, /// The request timed out before a response was received. + #[error("Timeout while waiting for a response")] Timeout, /// The connection closed before a response was received. + #[error("Connection was closed before a response was received")] ConnectionClosed, /// The remote supports none of the requested protocols. + #[error("The remote supports none of the requested protocols")] UnsupportedProtocols, } -impl Display for OutboundFailure { - fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { - match self { - OutboundFailure::DialFailure => write!(f, "Failed to dial the requested peer"), - OutboundFailure::Timeout => write!(f, "Timeout while waiting for a response"), - OutboundFailure::ConnectionClosed => - write!(f, "Connection was closed before a response was received"), - OutboundFailure::UnsupportedProtocols => - write!(f, "The remote supports none of the requested protocols"), - } - } -} - impl From for OutboundFailure { fn from(out: request_response::OutboundFailure) -> Self { match out { @@ -114,32 +103,19 @@ impl From for OutboundFailure { pub enum InboundFailure { /// The inbound request timed out, either while reading the incoming request or before a /// response is sent + #[error("Timeout while receiving request or sending response")] Timeout, /// The connection closed before a response could be send. + #[error("Connection was closed before a response could be sent")] ConnectionClosed, /// The local peer supports none of the protocols requested by the remote. + #[error("The local peer supports none of the protocols requested by the remote")] UnsupportedProtocols, /// The local peer failed to respond to an inbound request + #[error("The response channel was dropped without sending a response to the remote")] ResponseOmission, } -impl Display for InboundFailure { - fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { - match self { - InboundFailure::Timeout => - write!(f, "Timeout while receiving request or sending response"), - InboundFailure::ConnectionClosed => - write!(f, "Connection was closed before a response could be sent"), - InboundFailure::UnsupportedProtocols => - write!(f, "The local peer supports none of the protocols requested by the remote"), - InboundFailure::ResponseOmission => write!( - f, - "The response channel was dropped without sending a response to the remote" - ), - } - } -} - impl From for InboundFailure { fn from(out: request_response::InboundFailure) -> Self { match out { @@ -771,7 +747,7 @@ impl NetworkBehaviour for RequestResponsesBehaviour { request_response::Event::Message { peer, message: - request_response::Message::Request { + Message::Request { request_id, request, channel, .. }, } => { @@ -835,7 +811,7 @@ impl NetworkBehaviour for RequestResponsesBehaviour { // Received a response from a remote to one of our requests. request_response::Event::Message { peer, - message: request_response::Message::Response { request_id, response }, + message: Message::Response { request_id, response }, .. } => { let (started, delivered) = match self From e226706db2e3b9b6ec0b833daa0d703431b98c20 Mon Sep 17 00:00:00 2001 From: ndkazu Date: Wed, 18 Sep 2024 06:47:28 +0900 Subject: [PATCH 36/37] Manual Formatting --- substrate/client/network/src/request_responses.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/substrate/client/network/src/request_responses.rs b/substrate/client/network/src/request_responses.rs index c2652273ca82..6c2631924df4 100644 --- a/substrate/client/network/src/request_responses.rs +++ b/substrate/client/network/src/request_responses.rs @@ -746,10 +746,7 @@ impl NetworkBehaviour for RequestResponsesBehaviour { // Received a request from a remote. request_response::Event::Message { peer, - message: - Message::Request { - request_id, request, channel, .. - }, + message: Message::Request { request_id, request, channel, .. }, } => { self.pending_responses_arrival_time .insert((protocol.clone(), request_id).into(), Instant::now()); From f1e0164f67f0467559d3286554869dfd5f3b1f41 Mon Sep 17 00:00:00 2001 From: Dmitry Markin Date: Wed, 18 Sep 2024 05:29:11 +0000 Subject: [PATCH 37/37] Correct newline at EOF in prdoc --- prdoc/pr_4974.prdoc | 1 - 1 file changed, 1 deletion(-) diff --git a/prdoc/pr_4974.prdoc b/prdoc/pr_4974.prdoc index 8a32e437f2e8..f764ea3f46fd 100644 --- a/prdoc/pr_4974.prdoc +++ b/prdoc/pr_4974.prdoc @@ -13,4 +13,3 @@ crates: bump: patch - name: sc-network-sync bump: patch - \ No newline at end of file