From 51f9a34a6b1a886120c0100c0fd9892de2fa02e4 Mon Sep 17 00:00:00 2001 From: ndkazu Date: Mon, 8 Jul 2024 22:26:37 +0900 Subject: [PATCH 01/80] 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/80] 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/80] 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/80] 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/80] 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/80] 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/80] 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/80] 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/80] 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/80] 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/80] 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/80] 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/80] 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/80] 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/80] 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/80] 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/80] 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/80] ".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/80] 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/80] 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/80] 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/80] 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/80] 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/80] 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/80] 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/80] 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/80] 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/80] ".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/80] 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/80] 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/80] 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/80] 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/80] 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/80] ".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/80] 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/80] 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/80] 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 From b0e1fd16de4a97cd2f9d1d10a8be82de8c62eef1 Mon Sep 17 00:00:00 2001 From: ndkazu Date: Wed, 25 Sep 2024 20:00:21 +0900 Subject: [PATCH 38/80] Starting --- Cargo.lock | 2 + substrate/client/network/types/Cargo.toml | 2 + substrate/client/network/types/src/lib.rs | 2 +- substrate/client/network/types/src/rec.rs | 108 ++++++++++++++++++++++ 4 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 substrate/client/network/types/src/rec.rs diff --git a/Cargo.lock b/Cargo.lock index 18517f94788a..a6f1c919606e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -19356,8 +19356,10 @@ name = "sc-network-types" version = "0.10.0" dependencies = [ "bs58", + "bytes", "ed25519-dalek", "libp2p-identity", + "libp2p-kad", "litep2p", "log", "multiaddr 0.18.1", diff --git a/substrate/client/network/types/Cargo.toml b/substrate/client/network/types/Cargo.toml index 655f104111e4..0cbb43bd4232 100644 --- a/substrate/client/network/types/Cargo.toml +++ b/substrate/client/network/types/Cargo.toml @@ -11,8 +11,10 @@ documentation = "https://docs.rs/sc-network-types" [dependencies] bs58 = { workspace = true, default-features = true } +bytes = { version = "1.4.0", default-features = false } ed25519-dalek = { workspace = true, default-features = true } libp2p-identity = { features = ["ed25519", "peerid", "rand"], workspace = true } +libp2p-kad = { version = "0.44.6", default-features = false } litep2p = { workspace = true } log = { workspace = true, default-features = true } multiaddr = { workspace = true } diff --git a/substrate/client/network/types/src/lib.rs b/substrate/client/network/types/src/lib.rs index 5684e38ab2e8..89422a95efd1 100644 --- a/substrate/client/network/types/src/lib.rs +++ b/substrate/client/network/types/src/lib.rs @@ -19,6 +19,6 @@ pub mod ed25519; pub mod multiaddr; pub mod multihash; - +pub mod rec; mod peer_id; pub use peer_id::PeerId; diff --git a/substrate/client/network/types/src/rec.rs b/substrate/client/network/types/src/rec.rs new file mode 100644 index 000000000000..c57a744aecc5 --- /dev/null +++ b/substrate/client/network/types/src/rec.rs @@ -0,0 +1,108 @@ + + +use std::{ + borrow::Borrow, + collections::{hash_map::Entry, HashMap}, + io, iter, + ops::Deref, + pin::Pin, + sync::Arc, + task::{Context, Poll}, + time::{Duration, Instant}, +}; +use bytes::Bytes; +use crate::{PeerId, multihash::Multihash, multiaddr::Multiaddr}; +//use libp2p_kad::behaviour::PeerRecord as PR; + + +/// The (opaque) key of a record. +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[derive(Clone, Debug, PartialEq, Eq, Hash)] +pub struct Key(Bytes); + +impl Key { + /// Creates a new key from the bytes of the input. + pub fn new>(key: &K) -> Self { + Key(Bytes::copy_from_slice(key.as_ref())) + } + + /// Copies the bytes of the key into a new vector. + pub fn to_vec(&self) -> Vec { + Vec::from(&self.0[..]) + } +} + +impl Borrow<[u8]> for Key { + fn borrow(&self) -> &[u8] { + &self.0[..] + } +} + +impl AsRef<[u8]> for Key { + fn as_ref(&self) -> &[u8] { + &self.0[..] + } +} + +impl From> for Key { + fn from(v: Vec) -> Key { + Key(Bytes::from(v)) + } +} + +impl From for Key { + fn from(m: Multihash) -> Key { + Key::from(m.to_bytes()) + } +} + +/// A record stored in the DHT. +#[derive(Clone, Debug, Eq, PartialEq)] +pub struct Record { + /// Key of the record. + pub key: Key, + /// Value of the record. + pub value: Vec, + /// The (original) publisher of the record. + pub publisher: Option, + /// The expiration time as measured by a local, monotonic clock. + pub expires: Option, +} + +impl Record { + /// Creates a new record for insertion into the DHT. + pub fn new(key: K, value: Vec) -> Self + where + K: Into, + { + Record { + key: key.into(), + value, + publisher: None, + expires: None, + } + } + + /// Checks whether the record is expired w.r.t. the given `Instant`. + pub fn is_expired(&self, now: Instant) -> bool { + self.expires.map_or(false, |t| now >= t) + } +} + +/// A record either received by the given peer or retrieved from the local +/// record store. +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct PeerRecord { + /// The peer from whom the record was received. `None` if the record was + /// retrieved from local storage. + pub peer: Option, + pub record: Record, +} + +impl From for PeerRecord { + fn from(out: libp2p_kad::PeerRecord) -> Self { + let peer = out.peer; + let record = out.record; + PeerRecord {peer, record} + } +} \ No newline at end of file From 141fbbc0e4d8d141b7142870cadbca7c5ac448ef Mon Sep 17 00:00:00 2001 From: ndkazu Date: Thu, 26 Sep 2024 10:15:32 +0900 Subject: [PATCH 39/80] Preparing new types --- substrate/client/network/types/src/rec.rs | 28 ++++++++++++++++++----- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/substrate/client/network/types/src/rec.rs b/substrate/client/network/types/src/rec.rs index c57a744aecc5..957641dcbfc5 100644 --- a/substrate/client/network/types/src/rec.rs +++ b/substrate/client/network/types/src/rec.rs @@ -12,8 +12,6 @@ use std::{ }; use bytes::Bytes; use crate::{PeerId, multihash::Multihash, multiaddr::Multiaddr}; -//use libp2p_kad::behaviour::PeerRecord as PR; - /// The (opaque) key of a record. #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] @@ -89,6 +87,19 @@ impl Record { } } +impl From for Record { + fn from(out: libp2p_kad::Record) -> Self { + let vec: Vec = out.key.to_vec(); + let key: Key = vec.into(); + let mut publisher: Option = None; + let mut expires: Option = None; + if let Some(x) = out.publisher{ + publisher = Some(x.into()); + } + Record {key, value: out.value, publisher, expires: out.expires} + } +} + /// A record either received by the given peer or retrieved from the local /// record store. #[derive(Debug, Clone, PartialEq, Eq)] @@ -99,10 +110,15 @@ pub struct PeerRecord { pub record: Record, } -impl From for PeerRecord { +impl From for PeerRecord { fn from(out: libp2p_kad::PeerRecord) -> Self { - let peer = out.peer; - let record = out.record; - PeerRecord {peer, record} + let mut peer: Option = None; + if let Some(x) = out.peer{ + peer = Some(x.into()); + } + let record = out.record.into(); + PeerRecord {peer: peer, record} + + } } \ No newline at end of file From 086c976e129a147e3f91c018e228e062c68f57f8 Mon Sep 17 00:00:00 2001 From: ndkazu Date: Thu, 26 Sep 2024 16:14:10 +0900 Subject: [PATCH 40/80] libp2p still used in tests --- .../client/authority-discovery/src/worker.rs | 32 +++++++++---------- substrate/client/network/src/behaviour.rs | 10 +++--- substrate/client/network/src/event.rs | 5 +-- substrate/client/network/src/litep2p/mod.rs | 20 ++++++------ .../client/network/src/litep2p/service.rs | 3 +- substrate/client/network/src/service.rs | 9 +++--- .../client/network/src/service/traits.rs | 4 +-- substrate/client/network/types/src/rec.rs | 10 ++++++ 8 files changed, 51 insertions(+), 42 deletions(-) diff --git a/substrate/client/authority-discovery/src/worker.rs b/substrate/client/authority-discovery/src/worker.rs index 6f4fbac77e05..9512441efe00 100644 --- a/substrate/client/authority-discovery/src/worker.rs +++ b/substrate/client/authority-discovery/src/worker.rs @@ -34,7 +34,7 @@ use futures::{channel::mpsc, future, stream::Fuse, FutureExt, Stream, StreamExt} use addr_cache::AddrCache; use codec::{Decode, Encode}; use ip_network::IpNetwork; -use libp2p::kad::{PeerRecord, Record}; +use sc_network_types::rec::{PeerRecord, Record, Key}; use linked_hash_set::LinkedHashSet; use log::{debug, error, trace}; @@ -580,7 +580,7 @@ where debug!(target: LOG_TARGET, "Value for hash '{:?}' found on Dht.", v.record.key); - if let Err(e) = self.handle_dht_value_found_event(v) { + if let Err(e) = self.handle_dht_value_found_event(v.into()) { if let Some(metrics) = &self.metrics { metrics.handle_value_found_event_failure.inc(); } @@ -592,7 +592,7 @@ where metrics.dht_event_received.with_label_values(&["value_not_found"]).inc(); } - if self.in_flight_lookups.remove(&hash).is_some() { + if self.in_flight_lookups.remove::(&hash.to_vec().into()).is_some() { debug!(target: LOG_TARGET, "Value for hash '{:?}' not found on Dht.", hash) } else { debug!( @@ -602,7 +602,7 @@ where } }, DhtEvent::ValuePut(hash) => { - if !self.latest_published_kad_keys.contains(&hash) { + if !self.latest_published_kad_keys.contains::(&hash.to_vec().into()) { return; } @@ -618,7 +618,7 @@ where debug!(target: LOG_TARGET, "Successfully put hash '{:?}' on Dht.", hash) }, DhtEvent::ValuePutFailed(hash) => { - if !self.latest_published_kad_keys.contains(&hash) { + if !self.latest_published_kad_keys.contains::(&hash.to_vec().into()) { // Not a value we have published or received multiple times. return; } @@ -646,7 +646,7 @@ where async fn handle_put_record_requested( &mut self, - record_key: KademliaKey, + record_key: Key, record_value: Vec, publisher: Option, expires: Option, @@ -656,7 +656,7 @@ where // Make sure we don't ever work with an outdated set of authorities // and that we do not update known_authorithies too often. let best_hash = self.client.best_hash().await?; - if !self.known_authorities.contains_key(&record_key) && + if !self.known_authorities.contains_key::(&record_key.to_vec().into()) && self.authorities_queried_at .map(|authorities_queried_at| authorities_queried_at != best_hash) .unwrap_or(true) @@ -678,7 +678,7 @@ where } let authority_id = - self.known_authorities.get(&record_key).ok_or(Error::UnknownAuthority)?; + self.known_authorities.get::(&record_key.to_vec().into()).ok_or(Error::UnknownAuthority)?; let signed_record = Self::check_record_signed_with_authority_id(record_value.as_slice(), authority_id)?; self.check_record_signed_with_network_key( @@ -697,7 +697,7 @@ where }) .unwrap_or_default(); // 0 is a sane default for records that do not have creation time present. - let current_record_info = self.last_known_records.get(&record_key); + let current_record_info = self.last_known_records.get::(&record_key.to_vec().into()); // If record creation time is older than the current record creation time, // we don't store it since we want to give higher priority to newer records. if let Some(current_record_info) = current_record_info { @@ -712,7 +712,7 @@ where } } - self.network.store_record(record_key, record_value, Some(publisher), expires); + self.network.store_record(record_key.to_vec().into(), record_value, Some(publisher), expires); Ok(()) } @@ -767,10 +767,10 @@ where let remote_key = peer_record.record.key.clone(); let authority_id: AuthorityId = - if let Some(authority_id) = self.in_flight_lookups.remove(&remote_key) { - self.known_lookups.insert(remote_key.clone(), authority_id.clone()); + if let Some(authority_id) = self.in_flight_lookups.remove::(&remote_key.to_vec().into()) { + self.known_lookups.insert(remote_key.clone().to_vec().into(), authority_id.clone()); authority_id - } else if let Some(authority_id) = self.known_lookups.get(&remote_key) { + } else if let Some(authority_id) = self.known_lookups.get::(&remote_key.to_vec().into()) { authority_id.clone() } else { return Err(Error::ReceivingUnexpectedRecord); @@ -835,7 +835,7 @@ where let addr_cache_needs_update = self.handle_new_record( &authority_id, - remote_key.clone(), + remote_key.clone().to_vec().into(), RecordInfo { creation_time: records_creation_time, peers_with_record: answering_peer_id.into_iter().collect(), @@ -870,7 +870,7 @@ where if new_record.creation_time > current_record_info.creation_time { let peers_that_need_updating = current_record_info.peers_with_record.clone(); self.network.put_record_to( - new_record.record.clone(), + new_record.record.clone().into(), peers_that_need_updating.clone(), // If this is empty it means we received the answer from our node local // storage, so we need to update that as well. @@ -907,7 +907,7 @@ where authority_id, new_record.creation_time, current_record_info.creation_time, ); self.network.put_record_to( - current_record_info.record.clone(), + current_record_info.record.clone().into(), new_record.peers_with_record.clone(), // If this is empty it means we received the answer from our node local // storage, so we need to update that as well. diff --git a/substrate/client/network/src/behaviour.rs b/substrate/client/network/src/behaviour.rs index 9a6324dafd37..b2abeba31e6f 100644 --- a/substrate/client/network/src/behaviour.rs +++ b/substrate/client/network/src/behaviour.rs @@ -379,18 +379,18 @@ impl From for BehaviourOut { }, DiscoveryOut::Discovered(peer_id) => BehaviourOut::Discovered(peer_id), DiscoveryOut::ValueFound(results, duration) => - BehaviourOut::Dht(DhtEvent::ValueFound(results), Some(duration)), + BehaviourOut::Dht(DhtEvent::ValueFound(results.into()), Some(duration)), DiscoveryOut::ValueNotFound(key, duration) => - BehaviourOut::Dht(DhtEvent::ValueNotFound(key), Some(duration)), + BehaviourOut::Dht(DhtEvent::ValueNotFound(key.to_vec().into()), Some(duration)), DiscoveryOut::ValuePut(key, duration) => - BehaviourOut::Dht(DhtEvent::ValuePut(key), Some(duration)), + BehaviourOut::Dht(DhtEvent::ValuePut(key.to_vec().into()), Some(duration)), DiscoveryOut::PutRecordRequest(record_key, record_value, publisher, expires) => BehaviourOut::Dht( - DhtEvent::PutRecordRequest(record_key, record_value, publisher, expires), + DhtEvent::PutRecordRequest(record_key.to_vec().into(), record_value, publisher, expires), None, ), DiscoveryOut::ValuePutFailed(key, duration) => - BehaviourOut::Dht(DhtEvent::ValuePutFailed(key), Some(duration)), + BehaviourOut::Dht(DhtEvent::ValuePutFailed(key.to_vec().into()), Some(duration)), DiscoveryOut::RandomKademliaStarted => BehaviourOut::RandomKademliaStarted, } } diff --git a/substrate/client/network/src/event.rs b/substrate/client/network/src/event.rs index 5400d11cb6ac..9d0354de1be3 100644 --- a/substrate/client/network/src/event.rs +++ b/substrate/client/network/src/event.rs @@ -22,11 +22,8 @@ use crate::types::ProtocolName; use bytes::Bytes; -use libp2p::{ - kad::{record::Key, PeerRecord}, - PeerId, -}; +use sc_network_types::{PeerId, rec::{Key,PeerRecord}}; use sc_network_common::role::ObservedRole; /// Events generated by DHT as a response to get_value and put_value requests. diff --git a/substrate/client/network/src/litep2p/mod.rs b/substrate/client/network/src/litep2p/mod.rs index 277f0759729c..5544e1d994d4 100644 --- a/substrate/client/network/src/litep2p/mod.rs +++ b/substrate/client/network/src/litep2p/mod.rs @@ -702,12 +702,12 @@ impl NetworkBackend for Litep2pNetworkBac None => return, Some(command) => match command { NetworkServiceCommand::GetValue{ key } => { - let query_id = self.discovery.get_value(key.clone()).await; - self.pending_get_values.insert(query_id, (key, Instant::now())); + let query_id = self.discovery.get_value(key.clone().to_vec().into()).await; + self.pending_get_values.insert(query_id, (key.to_vec().into(), Instant::now())); } NetworkServiceCommand::PutValue { key, value } => { - let query_id = self.discovery.put_value(key.clone(), value).await; - self.pending_put_values.insert(query_id, (key, Instant::now())); + let query_id = self.discovery.put_value(key.clone().to_vec().into(), value).await; + self.pending_put_values.insert(query_id, (key.to_vec().into(), Instant::now())); } NetworkServiceCommand::PutValueTo { record, peers, update_local_storage} => { let kademlia_key = record.key.to_vec().into(); @@ -716,7 +716,7 @@ impl NetworkBackend for Litep2pNetworkBac } NetworkServiceCommand::StoreRecord { key, value, publisher, expires } => { - self.discovery.store_record(key, value, publisher.map(Into::into), expires).await; + self.discovery.store_record(key.to_vec().into(), value, publisher.map(Into::into), expires).await; } NetworkServiceCommand::EventStream { tx } => { self.event_streams.push(tx); @@ -835,7 +835,7 @@ impl NetworkBackend for Litep2pNetworkBac self.event_streams.send( Event::Dht( DhtEvent::ValueFound( - record + record.into() ) ) ); @@ -863,7 +863,7 @@ impl NetworkBackend for Litep2pNetworkBac ); self.event_streams.send(Event::Dht( - DhtEvent::ValuePut(libp2p::kad::RecordKey::new(&key)) + DhtEvent::ValuePut(sc_network_types::rec::Key::new::(&key.to_vec().into())) )); if let Some(ref metrics) = self.metrics { @@ -889,7 +889,7 @@ impl NetworkBackend for Litep2pNetworkBac ); self.event_streams.send(Event::Dht( - DhtEvent::ValuePutFailed(libp2p::kad::RecordKey::new(&key)) + DhtEvent::ValuePutFailed(sc_network_types::rec::Key::new::(&key.to_vec().into())) )); if let Some(ref metrics) = self.metrics { @@ -907,7 +907,7 @@ impl NetworkBackend for Litep2pNetworkBac ); self.event_streams.send(Event::Dht( - DhtEvent::ValueNotFound(libp2p::kad::RecordKey::new(&key)) + DhtEvent::ValueNotFound(sc_network_types::rec::Key::new::(&key.to_vec().into())) )); if let Some(ref metrics) = self.metrics { @@ -944,7 +944,7 @@ impl NetworkBackend for Litep2pNetworkBac Some(DiscoveryEvent::IncomingRecord { record: Record { key, value, publisher, expires }} ) => { self.event_streams.send(Event::Dht( DhtEvent::PutRecordRequest( - libp2p::kad::RecordKey::new(&key), + sc_network_types::rec::Key::new::(&key.to_vec().into()), value, publisher.map(Into::into), expires, diff --git a/substrate/client/network/src/litep2p/service.rs b/substrate/client/network/src/litep2p/service.rs index 693217f5ad94..5c5151ddaeb6 100644 --- a/substrate/client/network/src/litep2p/service.rs +++ b/substrate/client/network/src/litep2p/service.rs @@ -35,7 +35,8 @@ use crate::{ use crate::litep2p::Record; use codec::DecodeAll; use futures::{channel::oneshot, stream::BoxStream}; -use libp2p::{identity::SigningError, kad::record::Key as KademliaKey}; +use libp2p::{identity::SigningError}; +use sc_network_types::rec::Key as KademliaKey; use litep2p::{ addresses::PublicAddresses, crypto::ed25519::Keypair, types::multiaddr::Multiaddr as LiteP2pMultiaddr, diff --git a/substrate/client/network/src/service.rs b/substrate/client/network/src/service.rs index 71d0b45aa06d..5edb41091321 100644 --- a/substrate/client/network/src/service.rs +++ b/substrate/client/network/src/service.rs @@ -68,7 +68,7 @@ use libp2p::{ core::{upgrade, ConnectedPoint, Endpoint}, identify::Info as IdentifyInfo, identity::ed25519, - kad::{record::Key as KademliaKey, Record}, + kad::Record, multiaddr::{self, Multiaddr}, swarm::{ Config as SwarmConfig, ConnectionError, ConnectionId, DialError, Executor, ListenError, @@ -76,6 +76,7 @@ use libp2p::{ }, PeerId, }; +use sc_network_types::rec::Key as KademliaKey; use log::{debug, error, info, trace, warn}; use metrics::{Histogram, MetricSources, Metrics}; use parking_lot::Mutex; @@ -1455,9 +1456,9 @@ where fn handle_worker_message(&mut self, msg: ServiceToWorkerMsg) { match msg { ServiceToWorkerMsg::GetValue(key) => - self.network_service.behaviour_mut().get_value(key), + self.network_service.behaviour_mut().get_value(key.to_vec().into()), ServiceToWorkerMsg::PutValue(key, value) => - self.network_service.behaviour_mut().put_value(key, value), + self.network_service.behaviour_mut().put_value(key.to_vec().into(), value), ServiceToWorkerMsg::PutRecordTo { record, peers, update_local_storage } => self .network_service .behaviour_mut() @@ -1465,7 +1466,7 @@ where ServiceToWorkerMsg::StoreRecord(key, value, publisher, expires) => self .network_service .behaviour_mut() - .store_record(key, value, publisher, expires), + .store_record(key.to_vec().into(), value, publisher, expires), ServiceToWorkerMsg::AddKnownAddress(peer_id, addr) => self.network_service.behaviour_mut().add_known_address(peer_id, addr), ServiceToWorkerMsg::EventStream(sender) => self.event_streams.push(sender), diff --git a/substrate/client/network/src/service/traits.rs b/substrate/client/network/src/service/traits.rs index bd4f83c7fd44..4aebe31686c4 100644 --- a/substrate/client/network/src/service/traits.rs +++ b/substrate/client/network/src/service/traits.rs @@ -37,7 +37,7 @@ use prometheus_endpoint::Registry; use sc_client_api::BlockBackend; use sc_network_common::{role::ObservedRole, ExHashT}; -use sc_network_types::{multiaddr::Multiaddr, PeerId}; +pub use sc_network_types::{multiaddr::Multiaddr, PeerId, rec::Key as KademliaKey}; use sp_runtime::traits::Block as BlockT; use std::{ @@ -49,7 +49,7 @@ use std::{ time::{Duration, Instant}, }; -pub use libp2p::{identity::SigningError, kad::record::Key as KademliaKey}; +pub use libp2p::{identity::SigningError}; /// Supertrait defining the services provided by [`NetworkBackend`] service handle. pub trait NetworkService: diff --git a/substrate/client/network/types/src/rec.rs b/substrate/client/network/types/src/rec.rs index 957641dcbfc5..be9579b8da71 100644 --- a/substrate/client/network/types/src/rec.rs +++ b/substrate/client/network/types/src/rec.rs @@ -99,6 +99,16 @@ impl From for Record { Record {key, value: out.value, publisher, expires: out.expires} } } +impl From for libp2p_kad::Record { + fn from(a:Record) -> libp2p_kad::Record { + //let key: KademliaKey = a.key.to_vec().into(); + let mut peer: Option = None; + if let Some(x) = a.publisher { + peer = Some(x.into()); + } + libp2p_kad::Record {key: a.key.to_vec().into(), value: a.value, publisher: peer, expires: a.expires} + } +} /// A record either received by the given peer or retrieved from the local /// record store. From 5c02af747eaed2d098146a7b3486a50db489a042 Mon Sep 17 00:00:00 2001 From: ndkazu Date: Fri, 27 Sep 2024 21:59:28 +0900 Subject: [PATCH 41/80] some corrections --- substrate/client/network/src/litep2p/mod.rs | 4 ++-- substrate/client/network/types/src/rec.rs | 13 +++---------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/substrate/client/network/src/litep2p/mod.rs b/substrate/client/network/src/litep2p/mod.rs index 5544e1d994d4..4346e17fad52 100644 --- a/substrate/client/network/src/litep2p/mod.rs +++ b/substrate/client/network/src/litep2p/mod.rs @@ -702,11 +702,11 @@ impl NetworkBackend for Litep2pNetworkBac None => return, Some(command) => match command { NetworkServiceCommand::GetValue{ key } => { - let query_id = self.discovery.get_value(key.clone().to_vec().into()).await; + let query_id = self.discovery.get_value(key.to_vec().into()).await; self.pending_get_values.insert(query_id, (key.to_vec().into(), Instant::now())); } NetworkServiceCommand::PutValue { key, value } => { - let query_id = self.discovery.put_value(key.clone().to_vec().into(), value).await; + let query_id = self.discovery.put_value(key.to_vec().into(), value).await; self.pending_put_values.insert(query_id, (key.to_vec().into(), Instant::now())); } NetworkServiceCommand::PutValueTo { record, peers, update_local_storage} => { diff --git a/substrate/client/network/types/src/rec.rs b/substrate/client/network/types/src/rec.rs index be9579b8da71..0ceb841fe46f 100644 --- a/substrate/client/network/types/src/rec.rs +++ b/substrate/client/network/types/src/rec.rs @@ -2,16 +2,10 @@ use std::{ borrow::Borrow, - collections::{hash_map::Entry, HashMap}, - io, iter, - ops::Deref, - pin::Pin, - sync::Arc, - task::{Context, Poll}, - time::{Duration, Instant}, + time:: Instant, }; use bytes::Bytes; -use crate::{PeerId, multihash::Multihash, multiaddr::Multiaddr}; +use crate::{PeerId, multihash::Multihash}; /// The (opaque) key of a record. #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] @@ -92,7 +86,6 @@ impl From for Record { let vec: Vec = out.key.to_vec(); let key: Key = vec.into(); let mut publisher: Option = None; - let mut expires: Option = None; if let Some(x) = out.publisher{ publisher = Some(x.into()); } @@ -127,7 +120,7 @@ impl From for PeerRecord { peer = Some(x.into()); } let record = out.record.into(); - PeerRecord {peer: peer, record} + PeerRecord {peer, record} } From b13248ffc431395f319226a4fae29ceced57250e Mon Sep 17 00:00:00 2001 From: ndkazu Date: Fri, 27 Sep 2024 22:01:25 +0900 Subject: [PATCH 42/80] License --- substrate/client/network/types/src/rec.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/substrate/client/network/types/src/rec.rs b/substrate/client/network/types/src/rec.rs index 0ceb841fe46f..4fe409492b96 100644 --- a/substrate/client/network/types/src/rec.rs +++ b/substrate/client/network/types/src/rec.rs @@ -1,4 +1,20 @@ +// This file is part of Substrate. +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . use std::{ borrow::Borrow, From a1ed2696b41d1197ed49cb31dfaaff084fda1eaf Mon Sep 17 00:00:00 2001 From: ndkazu Date: Fri, 27 Sep 2024 23:02:06 +0900 Subject: [PATCH 43/80] Fix clippy --- substrate/client/network/types/src/rec.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/substrate/client/network/types/src/rec.rs b/substrate/client/network/types/src/rec.rs index 4fe409492b96..7d9db3ffeabd 100644 --- a/substrate/client/network/types/src/rec.rs +++ b/substrate/client/network/types/src/rec.rs @@ -24,7 +24,6 @@ use bytes::Bytes; use crate::{PeerId, multihash::Multihash}; /// The (opaque) key of a record. -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[derive(Clone, Debug, PartialEq, Eq, Hash)] pub struct Key(Bytes); From c0baae586f781c93f5b91875979634bbbf415ca7 Mon Sep 17 00:00:00 2001 From: ndkazu Date: Sat, 28 Sep 2024 17:16:53 +0900 Subject: [PATCH 44/80] PRdoc --- prdoc/pr_5842.prdoc | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 prdoc/pr_5842.prdoc diff --git a/prdoc/pr_5842.prdoc b/prdoc/pr_5842.prdoc new file mode 100644 index 000000000000..c45a4f91404c --- /dev/null +++ b/prdoc/pr_5842.prdoc @@ -0,0 +1,17 @@ +# 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: Get rid of libp2p dependency in sc-authority-discovery + +doc: + - audience: + - Node Dev + description: | + Removes `libp2p` types in authority-discovery, and replace them with network backend agnostic types from `sc-network-types`. + The `sc-network` interface is therefore updated accordingly. + +crates: + - name: sc-network + bump: patch + - name: sc-authority-discovery + bump: patch From c944af928f04940bdfc45a7b303ac04e72dfb7b8 Mon Sep 17 00:00:00 2001 From: ndkazu Date: Sat, 28 Sep 2024 17:19:29 +0900 Subject: [PATCH 45/80] PRdoc --- prdoc/pr_5842.prdoc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/prdoc/pr_5842.prdoc b/prdoc/pr_5842.prdoc index c45a4f91404c..011afd044cea 100644 --- a/prdoc/pr_5842.prdoc +++ b/prdoc/pr_5842.prdoc @@ -4,8 +4,7 @@ title: Get rid of libp2p dependency in sc-authority-discovery doc: - - audience: - - Node Dev + - audience: Node Dev description: | Removes `libp2p` types in authority-discovery, and replace them with network backend agnostic types from `sc-network-types`. The `sc-network` interface is therefore updated accordingly. @@ -13,5 +12,5 @@ doc: crates: - name: sc-network bump: patch - - name: sc-authority-discovery + - name: sc-authority bump: patch From bc2e56e850d282c4e5404ba87b514a86ca2ad1b2 Mon Sep 17 00:00:00 2001 From: ndkazu Date: Sat, 28 Sep 2024 17:20:54 +0900 Subject: [PATCH 46/80] PRdoc --- prdoc/pr_5842.prdoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prdoc/pr_5842.prdoc b/prdoc/pr_5842.prdoc index 011afd044cea..e38de38e718f 100644 --- a/prdoc/pr_5842.prdoc +++ b/prdoc/pr_5842.prdoc @@ -12,5 +12,5 @@ doc: crates: - name: sc-network bump: patch - - name: sc-authority + - name: sc-authority-discovery bump: patch From 1efb0b23af56ff7df66d98edc398d24747e11363 Mon Sep 17 00:00:00 2001 From: ndkazu Date: Sat, 28 Sep 2024 17:43:54 +0900 Subject: [PATCH 47/80] Removed libp2p from sc-authority-discovery --- substrate/client/network/types/src/rec.rs | 40 +++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/substrate/client/network/types/src/rec.rs b/substrate/client/network/types/src/rec.rs index 7d9db3ffeabd..5e8685c88c21 100644 --- a/substrate/client/network/types/src/rec.rs +++ b/substrate/client/network/types/src/rec.rs @@ -18,6 +18,8 @@ use std::{ borrow::Borrow, + error::Error, + fmt, time:: Instant, }; use bytes::Bytes; @@ -138,5 +140,43 @@ impl From for PeerRecord { PeerRecord {peer, record} + } +} + +/// An error during signing of a message. +#[derive(Debug)] +pub struct SigningError { + msg: String, + source: Option>, +} + +/// An error during encoding of key material. +impl SigningError { + #[cfg(all(not(target_arch = "wasm32")))] + pub(crate) fn new(msg: S) -> Self { + Self { + msg: msg.to_string(), + source: None, + } + } + + #[cfg(all(not(target_arch = "wasm32")))] + pub(crate) fn source(self, source: impl Error + Send + Sync + 'static) -> Self { + Self { + source: Some(Box::new(source)), + ..self + } + } +} + +impl fmt::Display for SigningError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "Key signing error: {}", self.msg) + } +} + +impl Error for SigningError { + fn source(&self) -> Option<&(dyn Error + 'static)> { + self.source.as_ref().map(|s| &**s as &dyn Error) } } \ No newline at end of file From f9e5edbd7c998c274c89fa14d12038c6751781e9 Mon Sep 17 00:00:00 2001 From: ndkazu Date: Sat, 28 Sep 2024 17:44:16 +0900 Subject: [PATCH 48/80] Removed libp2p from sc-authority-discovery --- substrate/client/authority-discovery/Cargo.toml | 1 - substrate/client/authority-discovery/src/tests.rs | 2 +- substrate/client/authority-discovery/src/worker/tests.rs | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/substrate/client/authority-discovery/Cargo.toml b/substrate/client/authority-discovery/Cargo.toml index 09381ec6b553..fc88d07ef936 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 } diff --git a/substrate/client/authority-discovery/src/tests.rs b/substrate/client/authority-discovery/src/tests.rs index acfd0e61de01..a73515ee00d2 100644 --- a/substrate/client/authority-discovery/src/tests.rs +++ b/substrate/client/authority-discovery/src/tests.rs @@ -25,7 +25,7 @@ use crate::{ }; use futures::{channel::mpsc::channel, executor::LocalPool, task::LocalSpawn}; -use libp2p::identity::ed25519; +use sc_network_types::ed25519; use std::{collections::HashSet, sync::Arc}; use sc_network::{multiaddr::Protocol, Multiaddr, PeerId}; diff --git a/substrate/client/authority-discovery/src/worker/tests.rs b/substrate/client/authority-discovery/src/worker/tests.rs index d71a85db8b81..444644c1ac34 100644 --- a/substrate/client/authority-discovery/src/worker/tests.rs +++ b/substrate/client/authority-discovery/src/worker/tests.rs @@ -30,7 +30,7 @@ use futures::{ sink::SinkExt, task::LocalSpawn, }; -use libp2p::{identity::SigningError, kad::record::Key as KademliaKey}; +use sc_network_types::rec{SigningError, Key as KademliaKey, } use prometheus_endpoint::prometheus::default_registry; use sc_client_api::HeaderBackend; From 568c1e68ba4bc67e3d8cd27cdbc32148913c8a60 Mon Sep 17 00:00:00 2001 From: ndkazu Date: Sat, 28 Sep 2024 17:44:34 +0900 Subject: [PATCH 49/80] Removed libp2p from sc-authority-discovery --- Cargo.lock | 1 - 1 file changed, 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index b76d1f5251ea..3b021bdfe5e9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -18377,7 +18377,6 @@ dependencies = [ "futures", "futures-timer", "ip_network", - "libp2p", "linked_hash_set", "log", "multihash 0.19.1", From 6052d781ac9c37eb8d240df48c5a03a367c91a59 Mon Sep 17 00:00:00 2001 From: ndkazu Date: Mon, 30 Sep 2024 23:43:03 +0900 Subject: [PATCH 50/80] cargo clippy --- substrate/client/network/types/src/rec.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/substrate/client/network/types/src/rec.rs b/substrate/client/network/types/src/rec.rs index 5e8685c88c21..76e620c0ca83 100644 --- a/substrate/client/network/types/src/rec.rs +++ b/substrate/client/network/types/src/rec.rs @@ -151,8 +151,9 @@ pub struct SigningError { } /// An error during encoding of key material. +#[allow(dead_code)] impl SigningError { - #[cfg(all(not(target_arch = "wasm32")))] + #[cfg(not(target_arch = "wasm32"))] pub(crate) fn new(msg: S) -> Self { Self { msg: msg.to_string(), @@ -160,7 +161,7 @@ impl SigningError { } } - #[cfg(all(not(target_arch = "wasm32")))] + #[cfg(not(target_arch = "wasm32"))] pub(crate) fn source(self, source: impl Error + Send + Sync + 'static) -> Self { Self { source: Some(Box::new(source)), From f3cf4dfd353ac88f6160ac458d932412b9124674 Mon Sep 17 00:00:00 2001 From: ndkazu Date: Tue, 1 Oct 2024 00:06:16 +0900 Subject: [PATCH 51/80] Clippy --- substrate/client/authority-discovery/src/worker/schema/tests.rs | 2 +- substrate/client/authority-discovery/src/worker/tests.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/substrate/client/authority-discovery/src/worker/schema/tests.rs b/substrate/client/authority-discovery/src/worker/schema/tests.rs index 557fa9641f97..ca742f983655 100644 --- a/substrate/client/authority-discovery/src/worker/schema/tests.rs +++ b/substrate/client/authority-discovery/src/worker/schema/tests.rs @@ -26,7 +26,7 @@ mod schema_v2 { use super::*; use codec::Encode; -use libp2p::identity::Keypair; +use sc_network_types::ed25519::Keypair; use prost::Message; use sc_network::{Multiaddr, PeerId}; diff --git a/substrate/client/authority-discovery/src/worker/tests.rs b/substrate/client/authority-discovery/src/worker/tests.rs index 444644c1ac34..a17b50bb27b2 100644 --- a/substrate/client/authority-discovery/src/worker/tests.rs +++ b/substrate/client/authority-discovery/src/worker/tests.rs @@ -30,7 +30,7 @@ use futures::{ sink::SinkExt, task::LocalSpawn, }; -use sc_network_types::rec{SigningError, Key as KademliaKey, } +use sc_network_types::rec::{SigningError, Key as KademliaKey, } use prometheus_endpoint::prometheus::default_registry; use sc_client_api::HeaderBackend; From ddde1b1ba6199dfd42fcf739532ceea722972026 Mon Sep 17 00:00:00 2001 From: ndkazu Date: Tue, 1 Oct 2024 14:19:40 +0900 Subject: [PATCH 52/80] Removed all libp2p dependency from sc-authority-discovery --- .../src/worker/schema/tests.rs | 12 ++++++------ .../authority-discovery/src/worker/tests.rs | 10 +++++----- substrate/client/network/src/discovery.rs | 4 ++-- substrate/client/network/src/litep2p/mod.rs | 2 +- .../client/network/src/litep2p/service.rs | 4 ++-- substrate/client/network/src/service.rs | 5 ++--- substrate/client/network/src/service/traits.rs | 3 +-- substrate/client/network/types/src/rec.rs | 18 ++++++++++++++++++ 8 files changed, 37 insertions(+), 21 deletions(-) diff --git a/substrate/client/authority-discovery/src/worker/schema/tests.rs b/substrate/client/authority-discovery/src/worker/schema/tests.rs index ca742f983655..f3bb67f5fb34 100644 --- a/substrate/client/authority-discovery/src/worker/schema/tests.rs +++ b/substrate/client/authority-discovery/src/worker/schema/tests.rs @@ -61,7 +61,7 @@ fn v2_decodes_v1() { #[test] fn v1_decodes_v2() { - let peer_secret = Keypair::generate_ed25519(); + let peer_secret = Keypair::generate(); let peer_public = peer_secret.public(); let peer_id = peer_public.to_peer_id(); let multiaddress: Multiaddr = @@ -73,7 +73,7 @@ fn v1_decodes_v2() { let record_v2 = schema_v2::AuthorityRecord { addresses: vec_addresses.clone() }; let mut vec_record_v2 = vec![]; record_v2.encode(&mut vec_record_v2).unwrap(); - let vec_peer_public = peer_public.encode_protobuf(); + let vec_peer_public = peer_public.to_bytes().to_vec(); let peer_signature_v2 = PeerSignature { public_key: vec_peer_public, signature: vec_peer_signature }; let signed_record_v2 = SignedAuthorityRecord { @@ -97,7 +97,7 @@ fn v1_decodes_v2() { #[test] fn v1_decodes_v3() { - let peer_secret = Keypair::generate_ed25519(); + let peer_secret = Keypair::generate(); let peer_public = peer_secret.public(); let peer_id = peer_public.to_peer_id(); let multiaddress: Multiaddr = @@ -112,7 +112,7 @@ fn v1_decodes_v3() { }; let mut vec_record_v3 = vec![]; record_v3.encode(&mut vec_record_v3).unwrap(); - let vec_peer_public = peer_public.encode_protobuf(); + let vec_peer_public = peer_public.to_bytes().to_vec(); let peer_signature_v3 = PeerSignature { public_key: vec_peer_public, signature: vec_peer_signature }; let signed_record_v3 = SignedAuthorityRecord { @@ -136,7 +136,7 @@ fn v1_decodes_v3() { #[test] fn v3_decodes_v2() { - let peer_secret = Keypair::generate_ed25519(); + let peer_secret = Keypair::generate(); let peer_public = peer_secret.public(); let peer_id = peer_public.to_peer_id(); let multiaddress: Multiaddr = @@ -148,7 +148,7 @@ fn v3_decodes_v2() { let record_v2 = schema_v2::AuthorityRecord { addresses: vec_addresses.clone() }; let mut vec_record_v2 = vec![]; record_v2.encode(&mut vec_record_v2).unwrap(); - let vec_peer_public = peer_public.encode_protobuf(); + let vec_peer_public = peer_public.to_bytes().to_vec(); let peer_signature_v2 = schema_v2::PeerSignature { public_key: vec_peer_public, signature: vec_peer_signature }; let signed_record_v2 = schema_v2::SignedAuthorityRecord { diff --git a/substrate/client/authority-discovery/src/worker/tests.rs b/substrate/client/authority-discovery/src/worker/tests.rs index a17b50bb27b2..55cd1f8a5ae1 100644 --- a/substrate/client/authority-discovery/src/worker/tests.rs +++ b/substrate/client/authority-discovery/src/worker/tests.rs @@ -30,11 +30,11 @@ use futures::{ sink::SinkExt, task::LocalSpawn, }; -use sc_network_types::rec::{SigningError, Key as KademliaKey, } +use sc_network_types::rec:: Key as KademliaKey; use prometheus_endpoint::prometheus::default_registry; - +use sc_network::service::signature::SigningError; use sc_client_api::HeaderBackend; -use sc_network::{service::signature::Keypair, Signature}; +use sc_network::{PublicKey, service::signature::Keypair, Signature}; use sc_network_types::{ multiaddr::{Multiaddr, Protocol}, PeerId, @@ -167,7 +167,7 @@ impl NetworkSigner for TestNetwork { fn sign_with_local_identity( &self, msg: Vec, - ) -> std::result::Result { + ) -> std::result::Result { Signature::sign_message(msg, &self.identity) } @@ -178,7 +178,7 @@ impl NetworkSigner for TestNetwork { signature: &Vec, message: &Vec, ) -> std::result::Result { - let public_key = libp2p::identity::PublicKey::try_decode_protobuf(&public_key) + let public_key = PublicKey::try_decode_protobuf(&public_key) .map_err(|error| error.to_string())?; let peer_id: PeerId = peer_id.into(); let remote: PeerId = public_key.to_peer_id().into(); diff --git a/substrate/client/network/src/discovery.rs b/substrate/client/network/src/discovery.rs index 86c66c22701c..ca3641e76716 100644 --- a/substrate/client/network/src/discovery.rs +++ b/substrate/client/network/src/discovery.rs @@ -1130,7 +1130,7 @@ mod tests { // the first swarm via `with_permanent_addresses`. let mut swarms = (0..25) .map(|i| { - let keypair = Keypair::generate_ed25519(); + let keypair = Keypair::generate(); let transport = MemoryTransport::new() .upgrade(upgrade::Version::V1) @@ -1263,7 +1263,7 @@ mod tests { let unsupported_protocol_id = ProtocolId::from("b"); let mut discovery = { - let keypair = Keypair::generate_ed25519(); + let keypair = Keypair::generate(); let mut config = DiscoveryConfig::new(keypair.public().to_peer_id()); config .allow_private_ip(true) diff --git a/substrate/client/network/src/litep2p/mod.rs b/substrate/client/network/src/litep2p/mod.rs index 4346e17fad52..7cf67a631741 100644 --- a/substrate/client/network/src/litep2p/mod.rs +++ b/substrate/client/network/src/litep2p/mod.rs @@ -711,7 +711,7 @@ impl NetworkBackend for Litep2pNetworkBac } NetworkServiceCommand::PutValueTo { record, peers, update_local_storage} => { let kademlia_key = record.key.to_vec().into(); - let query_id = self.discovery.put_value_to_peers(record, peers, update_local_storage).await; + let query_id = self.discovery.put_value_to_peers(record.into(), peers, update_local_storage).await; self.pending_put_values.insert(query_id, (kademlia_key, Instant::now())); } diff --git a/substrate/client/network/src/litep2p/service.rs b/substrate/client/network/src/litep2p/service.rs index 5c5151ddaeb6..00fcf3eb19ae 100644 --- a/substrate/client/network/src/litep2p/service.rs +++ b/substrate/client/network/src/litep2p/service.rs @@ -32,7 +32,7 @@ use crate::{ RequestFailure, Signature, }; -use crate::litep2p::Record; +use sc_network_types::rec::Record; use codec::DecodeAll; use futures::{channel::oneshot, stream::BoxStream}; use libp2p::{identity::SigningError}; @@ -269,7 +269,7 @@ impl NetworkDHTProvider for Litep2pNetworkService { fn put_record_to( &self, - record: libp2p::kad::Record, + record: Record, peers: HashSet, update_local_storage: bool, ) { diff --git a/substrate/client/network/src/service.rs b/substrate/client/network/src/service.rs index 5edb41091321..17879698b343 100644 --- a/substrate/client/network/src/service.rs +++ b/substrate/client/network/src/service.rs @@ -68,7 +68,6 @@ use libp2p::{ core::{upgrade, ConnectedPoint, Endpoint}, identify::Info as IdentifyInfo, identity::ed25519, - kad::Record, multiaddr::{self, Multiaddr}, swarm::{ Config as SwarmConfig, ConnectionError, ConnectionId, DialError, Executor, ListenError, @@ -76,7 +75,7 @@ use libp2p::{ }, PeerId, }; -use sc_network_types::rec::Key as KademliaKey; +use sc_network_types::rec::{Record, Key as KademliaKey}; use log::{debug, error, info, trace, warn}; use metrics::{Histogram, MetricSources, Metrics}; use parking_lot::Mutex; @@ -1462,7 +1461,7 @@ where ServiceToWorkerMsg::PutRecordTo { record, peers, update_local_storage } => self .network_service .behaviour_mut() - .put_record_to(record, peers, update_local_storage), + .put_record_to(record.into(), peers, update_local_storage), ServiceToWorkerMsg::StoreRecord(key, value, publisher, expires) => self .network_service .behaviour_mut() diff --git a/substrate/client/network/src/service/traits.rs b/substrate/client/network/src/service/traits.rs index 4aebe31686c4..6242e609c801 100644 --- a/substrate/client/network/src/service/traits.rs +++ b/substrate/client/network/src/service/traits.rs @@ -32,12 +32,11 @@ use crate::{ }; use futures::{channel::oneshot, Stream}; -use libp2p::kad::Record; use prometheus_endpoint::Registry; use sc_client_api::BlockBackend; use sc_network_common::{role::ObservedRole, ExHashT}; -pub use sc_network_types::{multiaddr::Multiaddr, PeerId, rec::Key as KademliaKey}; +pub use sc_network_types::{multiaddr::Multiaddr, PeerId, rec::{Record, Key as KademliaKey}}; use sp_runtime::traits::Block as BlockT; use std::{ diff --git a/substrate/client/network/types/src/rec.rs b/substrate/client/network/types/src/rec.rs index 76e620c0ca83..90731b436edb 100644 --- a/substrate/client/network/types/src/rec.rs +++ b/substrate/client/network/types/src/rec.rs @@ -23,6 +23,7 @@ use std::{ time:: Instant, }; use bytes::Bytes; +use litep2p::protocol::libp2p::kademlia::{RecordKey, Record as LiteRecord}; use crate::{PeerId, multihash::Multihash}; /// The (opaque) key of a record. @@ -109,6 +110,19 @@ impl From for Record { Record {key, value: out.value, publisher, expires: out.expires} } } + +impl Into for Record { + fn into(self) -> LiteRecord { + let vec: Vec = self.key.to_vec(); + let key: RecordKey = vec.into(); + let mut publisher: Option = None; + if let Some(x) = self.publisher{ + publisher = Some(x.into()); + } + LiteRecord {key, value: self.value, publisher, expires: self.expires} + } +} + impl From for libp2p_kad::Record { fn from(a:Record) -> libp2p_kad::Record { //let key: KademliaKey = a.key.to_vec().into(); @@ -120,6 +134,10 @@ impl From for libp2p_kad::Record { } } +/*impl From for SigningError { + fn from(a: ) +}*/ + /// A record either received by the given peer or retrieved from the local /// record store. #[derive(Debug, Clone, PartialEq, Eq)] From 128ae4820b5dc3ed868696d18fa73d17c1949213 Mon Sep 17 00:00:00 2001 From: ndkazu Date: Tue, 1 Oct 2024 16:47:16 +0900 Subject: [PATCH 53/80] clippy --- substrate/client/network/types/src/rec.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/substrate/client/network/types/src/rec.rs b/substrate/client/network/types/src/rec.rs index 90731b436edb..92b84ed9e291 100644 --- a/substrate/client/network/types/src/rec.rs +++ b/substrate/client/network/types/src/rec.rs @@ -111,15 +111,15 @@ impl From for Record { } } -impl Into for Record { - fn into(self) -> LiteRecord { - let vec: Vec = self.key.to_vec(); +impl From for LiteRecord { + fn from(val: Record) -> Self { + let vec: Vec = val.key.to_vec(); let key: RecordKey = vec.into(); let mut publisher: Option = None; - if let Some(x) = self.publisher{ + if let Some(x) = val.publisher{ publisher = Some(x.into()); } - LiteRecord {key, value: self.value, publisher, expires: self.expires} + LiteRecord {key, value: val.value, publisher, expires: val.expires} } } From 75cdda471830ac0ca899a91161122fe0fa4bfc27 Mon Sep 17 00:00:00 2001 From: ndkazu Date: Tue, 1 Oct 2024 17:15:43 +0900 Subject: [PATCH 54/80] Fix tests in sc-network --- substrate/client/network/src/discovery.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/substrate/client/network/src/discovery.rs b/substrate/client/network/src/discovery.rs index ca3641e76716..86c66c22701c 100644 --- a/substrate/client/network/src/discovery.rs +++ b/substrate/client/network/src/discovery.rs @@ -1130,7 +1130,7 @@ mod tests { // the first swarm via `with_permanent_addresses`. let mut swarms = (0..25) .map(|i| { - let keypair = Keypair::generate(); + let keypair = Keypair::generate_ed25519(); let transport = MemoryTransport::new() .upgrade(upgrade::Version::V1) @@ -1263,7 +1263,7 @@ mod tests { let unsupported_protocol_id = ProtocolId::from("b"); let mut discovery = { - let keypair = Keypair::generate(); + let keypair = Keypair::generate_ed25519(); let mut config = DiscoveryConfig::new(keypair.public().to_peer_id()); config .allow_private_ip(true) From 008674c40b72061640c2482c39c4fdef6745869d Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Tue, 1 Oct 2024 10:32:56 +0000 Subject: [PATCH 55/80] ".git/.scripts/commands/fmt/fmt.sh" --- .../client/authority-discovery/src/worker.rs | 40 ++-- .../src/worker/schema/tests.rs | 2 +- .../authority-discovery/src/worker/tests.rs | 12 +- substrate/client/network/src/behaviour.rs | 7 +- substrate/client/network/src/event.rs | 5 +- .../client/network/src/litep2p/service.rs | 12 +- substrate/client/network/src/service.rs | 2 +- .../client/network/src/service/traits.rs | 8 +- substrate/client/network/types/Cargo.toml | 2 +- substrate/client/network/types/src/lib.rs | 2 +- substrate/client/network/types/src/rec.rs | 225 +++++++++--------- 11 files changed, 162 insertions(+), 155 deletions(-) diff --git a/substrate/client/authority-discovery/src/worker.rs b/substrate/client/authority-discovery/src/worker.rs index 9512441efe00..13e860463c2d 100644 --- a/substrate/client/authority-discovery/src/worker.rs +++ b/substrate/client/authority-discovery/src/worker.rs @@ -34,8 +34,8 @@ use futures::{channel::mpsc, future, stream::Fuse, FutureExt, Stream, StreamExt} use addr_cache::AddrCache; use codec::{Decode, Encode}; use ip_network::IpNetwork; -use sc_network_types::rec::{PeerRecord, Record, Key}; use linked_hash_set::LinkedHashSet; +use sc_network_types::rec::{Key, PeerRecord, Record}; use log::{debug, error, trace}; use prometheus_endpoint::{register, Counter, CounterVec, Gauge, Opts, U64}; @@ -677,8 +677,10 @@ where self.authorities_queried_at = Some(best_hash); } - let authority_id = - self.known_authorities.get::(&record_key.to_vec().into()).ok_or(Error::UnknownAuthority)?; + let authority_id = self + .known_authorities + .get::(&record_key.to_vec().into()) + .ok_or(Error::UnknownAuthority)?; let signed_record = Self::check_record_signed_with_authority_id(record_value.as_slice(), authority_id)?; self.check_record_signed_with_network_key( @@ -697,7 +699,8 @@ where }) .unwrap_or_default(); // 0 is a sane default for records that do not have creation time present. - let current_record_info = self.last_known_records.get::(&record_key.to_vec().into()); + let current_record_info = + self.last_known_records.get::(&record_key.to_vec().into()); // If record creation time is older than the current record creation time, // we don't store it since we want to give higher priority to newer records. if let Some(current_record_info) = current_record_info { @@ -712,7 +715,12 @@ where } } - self.network.store_record(record_key.to_vec().into(), record_value, Some(publisher), expires); + self.network.store_record( + record_key.to_vec().into(), + record_value, + Some(publisher), + expires, + ); Ok(()) } @@ -766,15 +774,19 @@ where // Ensure `values` is not empty and all its keys equal. let remote_key = peer_record.record.key.clone(); - let authority_id: AuthorityId = - if let Some(authority_id) = self.in_flight_lookups.remove::(&remote_key.to_vec().into()) { - self.known_lookups.insert(remote_key.clone().to_vec().into(), authority_id.clone()); - authority_id - } else if let Some(authority_id) = self.known_lookups.get::(&remote_key.to_vec().into()) { - authority_id.clone() - } else { - return Err(Error::ReceivingUnexpectedRecord); - }; + let authority_id: AuthorityId = if let Some(authority_id) = + self.in_flight_lookups.remove::(&remote_key.to_vec().into()) + { + self.known_lookups + .insert(remote_key.clone().to_vec().into(), authority_id.clone()); + authority_id + } else if let Some(authority_id) = + self.known_lookups.get::(&remote_key.to_vec().into()) + { + authority_id.clone() + } else { + return Err(Error::ReceivingUnexpectedRecord); + }; let local_peer_id = self.network.local_peer_id(); diff --git a/substrate/client/authority-discovery/src/worker/schema/tests.rs b/substrate/client/authority-discovery/src/worker/schema/tests.rs index f3bb67f5fb34..1dff1b93e06d 100644 --- a/substrate/client/authority-discovery/src/worker/schema/tests.rs +++ b/substrate/client/authority-discovery/src/worker/schema/tests.rs @@ -26,9 +26,9 @@ mod schema_v2 { use super::*; use codec::Encode; -use sc_network_types::ed25519::Keypair; use prost::Message; use sc_network::{Multiaddr, PeerId}; +use sc_network_types::ed25519::Keypair; #[test] fn v2_decodes_v1() { diff --git a/substrate/client/authority-discovery/src/worker/tests.rs b/substrate/client/authority-discovery/src/worker/tests.rs index 55cd1f8a5ae1..a594e405a4dc 100644 --- a/substrate/client/authority-discovery/src/worker/tests.rs +++ b/substrate/client/authority-discovery/src/worker/tests.rs @@ -30,13 +30,15 @@ use futures::{ sink::SinkExt, task::LocalSpawn, }; -use sc_network_types::rec:: Key as KademliaKey; use prometheus_endpoint::prometheus::default_registry; -use sc_network::service::signature::SigningError; use sc_client_api::HeaderBackend; -use sc_network::{PublicKey, service::signature::Keypair, Signature}; +use sc_network::{ + service::signature::{Keypair, SigningError}, + PublicKey, Signature, +}; use sc_network_types::{ multiaddr::{Multiaddr, Protocol}, + rec::Key as KademliaKey, PeerId, }; use sp_api::{ApiRef, ProvideRuntimeApi}; @@ -178,8 +180,8 @@ impl NetworkSigner for TestNetwork { signature: &Vec, message: &Vec, ) -> std::result::Result { - let public_key = PublicKey::try_decode_protobuf(&public_key) - .map_err(|error| error.to_string())?; + let public_key = + PublicKey::try_decode_protobuf(&public_key).map_err(|error| error.to_string())?; let peer_id: PeerId = peer_id.into(); let remote: PeerId = public_key.to_peer_id().into(); diff --git a/substrate/client/network/src/behaviour.rs b/substrate/client/network/src/behaviour.rs index 53defd080374..f4551213a7a5 100644 --- a/substrate/client/network/src/behaviour.rs +++ b/substrate/client/network/src/behaviour.rs @@ -382,7 +382,12 @@ impl From for BehaviourOut { BehaviourOut::Dht(DhtEvent::ValuePut(key.to_vec().into()), Some(duration)), DiscoveryOut::PutRecordRequest(record_key, record_value, publisher, expires) => BehaviourOut::Dht( - DhtEvent::PutRecordRequest(record_key.to_vec().into(), record_value, publisher, expires), + DhtEvent::PutRecordRequest( + record_key.to_vec().into(), + record_value, + publisher, + expires, + ), None, ), DiscoveryOut::ValuePutFailed(key, duration) => diff --git a/substrate/client/network/src/event.rs b/substrate/client/network/src/event.rs index 9d0354de1be3..d441b7e47ba7 100644 --- a/substrate/client/network/src/event.rs +++ b/substrate/client/network/src/event.rs @@ -23,8 +23,11 @@ use crate::types::ProtocolName; use bytes::Bytes; -use sc_network_types::{PeerId, rec::{Key,PeerRecord}}; use sc_network_common::role::ObservedRole; +use sc_network_types::{ + rec::{Key, PeerRecord}, + PeerId, +}; /// Events generated by DHT as a response to get_value and put_value requests. #[derive(Debug, Clone)] diff --git a/substrate/client/network/src/litep2p/service.rs b/substrate/client/network/src/litep2p/service.rs index 00fcf3eb19ae..e1823b32d312 100644 --- a/substrate/client/network/src/litep2p/service.rs +++ b/substrate/client/network/src/litep2p/service.rs @@ -32,16 +32,15 @@ use crate::{ RequestFailure, Signature, }; -use sc_network_types::rec::Record; use codec::DecodeAll; use futures::{channel::oneshot, stream::BoxStream}; -use libp2p::{identity::SigningError}; -use sc_network_types::rec::Key as KademliaKey; +use libp2p::identity::SigningError; use litep2p::{ addresses::PublicAddresses, crypto::ed25519::Keypair, types::multiaddr::Multiaddr as LiteP2pMultiaddr, }; use parking_lot::RwLock; +use sc_network_types::rec::{Key as KademliaKey, Record}; use sc_network_common::{ role::{ObservedRole, Roles}, @@ -267,12 +266,7 @@ impl NetworkDHTProvider for Litep2pNetworkService { let _ = self.cmd_tx.unbounded_send(NetworkServiceCommand::PutValue { key, value }); } - fn put_record_to( - &self, - record: Record, - peers: HashSet, - update_local_storage: bool, - ) { + fn put_record_to(&self, record: Record, peers: HashSet, update_local_storage: bool) { let _ = self.cmd_tx.unbounded_send(NetworkServiceCommand::PutValueTo { record: Record { key: record.key.to_vec().into(), diff --git a/substrate/client/network/src/service.rs b/substrate/client/network/src/service.rs index 17879698b343..96f8893d3354 100644 --- a/substrate/client/network/src/service.rs +++ b/substrate/client/network/src/service.rs @@ -75,11 +75,11 @@ use libp2p::{ }, PeerId, }; -use sc_network_types::rec::{Record, Key as KademliaKey}; use log::{debug, error, info, trace, warn}; use metrics::{Histogram, MetricSources, Metrics}; use parking_lot::Mutex; use prometheus_endpoint::Registry; +use sc_network_types::rec::{Key as KademliaKey, Record}; use sc_client_api::BlockBackend; use sc_network_common::{ diff --git a/substrate/client/network/src/service/traits.rs b/substrate/client/network/src/service/traits.rs index 6242e609c801..500d3fe6aeda 100644 --- a/substrate/client/network/src/service/traits.rs +++ b/substrate/client/network/src/service/traits.rs @@ -36,7 +36,11 @@ use prometheus_endpoint::Registry; use sc_client_api::BlockBackend; use sc_network_common::{role::ObservedRole, ExHashT}; -pub use sc_network_types::{multiaddr::Multiaddr, PeerId, rec::{Record, Key as KademliaKey}}; +pub use sc_network_types::{ + multiaddr::Multiaddr, + rec::{Key as KademliaKey, Record}, + PeerId, +}; use sp_runtime::traits::Block as BlockT; use std::{ @@ -48,7 +52,7 @@ use std::{ time::{Duration, Instant}, }; -pub use libp2p::{identity::SigningError}; +pub use libp2p::identity::SigningError; /// Supertrait defining the services provided by [`NetworkBackend`] service handle. pub trait NetworkService: diff --git a/substrate/client/network/types/Cargo.toml b/substrate/client/network/types/Cargo.toml index 0cbb43bd4232..7438eaeffcd2 100644 --- a/substrate/client/network/types/Cargo.toml +++ b/substrate/client/network/types/Cargo.toml @@ -14,7 +14,7 @@ bs58 = { workspace = true, default-features = true } bytes = { version = "1.4.0", default-features = false } ed25519-dalek = { workspace = true, default-features = true } libp2p-identity = { features = ["ed25519", "peerid", "rand"], workspace = true } -libp2p-kad = { version = "0.44.6", default-features = false } +libp2p-kad = { version = "0.44.6", default-features = false } litep2p = { workspace = true } log = { workspace = true, default-features = true } multiaddr = { workspace = true } diff --git a/substrate/client/network/types/src/lib.rs b/substrate/client/network/types/src/lib.rs index 89422a95efd1..ba9bb739efdb 100644 --- a/substrate/client/network/types/src/lib.rs +++ b/substrate/client/network/types/src/lib.rs @@ -19,6 +19,6 @@ pub mod ed25519; pub mod multiaddr; pub mod multihash; -pub mod rec; mod peer_id; +pub mod rec; pub use peer_id::PeerId; diff --git a/substrate/client/network/types/src/rec.rs b/substrate/client/network/types/src/rec.rs index 92b84ed9e291..11b05e7c7a5b 100644 --- a/substrate/client/network/types/src/rec.rs +++ b/substrate/client/network/types/src/rec.rs @@ -16,186 +16,173 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use std::{ - borrow::Borrow, - error::Error, - fmt, - time:: Instant, -}; +use crate::{multihash::Multihash, PeerId}; use bytes::Bytes; -use litep2p::protocol::libp2p::kademlia::{RecordKey, Record as LiteRecord}; -use crate::{PeerId, multihash::Multihash}; +use litep2p::protocol::libp2p::kademlia::{Record as LiteRecord, RecordKey}; +use std::{borrow::Borrow, error::Error, fmt, time::Instant}; /// The (opaque) key of a record. #[derive(Clone, Debug, PartialEq, Eq, Hash)] pub struct Key(Bytes); impl Key { - /// Creates a new key from the bytes of the input. - pub fn new>(key: &K) -> Self { - Key(Bytes::copy_from_slice(key.as_ref())) - } - - /// Copies the bytes of the key into a new vector. - pub fn to_vec(&self) -> Vec { - Vec::from(&self.0[..]) - } + /// Creates a new key from the bytes of the input. + pub fn new>(key: &K) -> Self { + Key(Bytes::copy_from_slice(key.as_ref())) + } + + /// Copies the bytes of the key into a new vector. + pub fn to_vec(&self) -> Vec { + Vec::from(&self.0[..]) + } } impl Borrow<[u8]> for Key { - fn borrow(&self) -> &[u8] { - &self.0[..] - } + fn borrow(&self) -> &[u8] { + &self.0[..] + } } impl AsRef<[u8]> for Key { - fn as_ref(&self) -> &[u8] { - &self.0[..] - } + fn as_ref(&self) -> &[u8] { + &self.0[..] + } } impl From> for Key { - fn from(v: Vec) -> Key { - Key(Bytes::from(v)) - } + fn from(v: Vec) -> Key { + Key(Bytes::from(v)) + } } impl From for Key { - fn from(m: Multihash) -> Key { - Key::from(m.to_bytes()) - } + fn from(m: Multihash) -> Key { + Key::from(m.to_bytes()) + } } /// A record stored in the DHT. #[derive(Clone, Debug, Eq, PartialEq)] pub struct Record { - /// Key of the record. - pub key: Key, - /// Value of the record. - pub value: Vec, - /// The (original) publisher of the record. - pub publisher: Option, - /// The expiration time as measured by a local, monotonic clock. - pub expires: Option, + /// Key of the record. + pub key: Key, + /// Value of the record. + pub value: Vec, + /// The (original) publisher of the record. + pub publisher: Option, + /// The expiration time as measured by a local, monotonic clock. + pub expires: Option, } impl Record { - /// Creates a new record for insertion into the DHT. - pub fn new(key: K, value: Vec) -> Self - where - K: Into, - { - Record { - key: key.into(), - value, - publisher: None, - expires: None, - } - } - - /// Checks whether the record is expired w.r.t. the given `Instant`. - pub fn is_expired(&self, now: Instant) -> bool { - self.expires.map_or(false, |t| now >= t) - } + /// Creates a new record for insertion into the DHT. + pub fn new(key: K, value: Vec) -> Self + where + K: Into, + { + Record { key: key.into(), value, publisher: None, expires: None } + } + + /// Checks whether the record is expired w.r.t. the given `Instant`. + pub fn is_expired(&self, now: Instant) -> bool { + self.expires.map_or(false, |t| now >= t) + } } impl From for Record { - fn from(out: libp2p_kad::Record) -> Self { - let vec: Vec = out.key.to_vec(); - let key: Key = vec.into(); - let mut publisher: Option = None; - if let Some(x) = out.publisher{ - publisher = Some(x.into()); - } - Record {key, value: out.value, publisher, expires: out.expires} - } + fn from(out: libp2p_kad::Record) -> Self { + let vec: Vec = out.key.to_vec(); + let key: Key = vec.into(); + let mut publisher: Option = None; + if let Some(x) = out.publisher { + publisher = Some(x.into()); + } + Record { key, value: out.value, publisher, expires: out.expires } + } } impl From for LiteRecord { - fn from(val: Record) -> Self { - let vec: Vec = val.key.to_vec(); - let key: RecordKey = vec.into(); - let mut publisher: Option = None; - if let Some(x) = val.publisher{ - publisher = Some(x.into()); - } - LiteRecord {key, value: val.value, publisher, expires: val.expires} - } + fn from(val: Record) -> Self { + let vec: Vec = val.key.to_vec(); + let key: RecordKey = vec.into(); + let mut publisher: Option = None; + if let Some(x) = val.publisher { + publisher = Some(x.into()); + } + LiteRecord { key, value: val.value, publisher, expires: val.expires } + } } impl From for libp2p_kad::Record { - fn from(a:Record) -> libp2p_kad::Record { - //let key: KademliaKey = a.key.to_vec().into(); - let mut peer: Option = None; - if let Some(x) = a.publisher { - peer = Some(x.into()); - } - libp2p_kad::Record {key: a.key.to_vec().into(), value: a.value, publisher: peer, expires: a.expires} - } + fn from(a: Record) -> libp2p_kad::Record { + //let key: KademliaKey = a.key.to_vec().into(); + let mut peer: Option = None; + if let Some(x) = a.publisher { + peer = Some(x.into()); + } + libp2p_kad::Record { + key: a.key.to_vec().into(), + value: a.value, + publisher: peer, + expires: a.expires, + } + } } /*impl From for SigningError { - fn from(a: ) + fn from(a: ) }*/ /// A record either received by the given peer or retrieved from the local /// record store. #[derive(Debug, Clone, PartialEq, Eq)] pub struct PeerRecord { - /// The peer from whom the record was received. `None` if the record was - /// retrieved from local storage. - pub peer: Option, - pub record: Record, + /// The peer from whom the record was received. `None` if the record was + /// retrieved from local storage. + pub peer: Option, + pub record: Record, } impl From for PeerRecord { - fn from(out: libp2p_kad::PeerRecord) -> Self { - let mut peer: Option = None; - if let Some(x) = out.peer{ - peer = Some(x.into()); - } - let record = out.record.into(); - PeerRecord {peer, record} - - - } + fn from(out: libp2p_kad::PeerRecord) -> Self { + let mut peer: Option = None; + if let Some(x) = out.peer { + peer = Some(x.into()); + } + let record = out.record.into(); + PeerRecord { peer, record } + } } /// An error during signing of a message. #[derive(Debug)] pub struct SigningError { - msg: String, - source: Option>, + msg: String, + source: Option>, } /// An error during encoding of key material. #[allow(dead_code)] impl SigningError { - #[cfg(not(target_arch = "wasm32"))] - pub(crate) fn new(msg: S) -> Self { - Self { - msg: msg.to_string(), - source: None, - } - } - - #[cfg(not(target_arch = "wasm32"))] - pub(crate) fn source(self, source: impl Error + Send + Sync + 'static) -> Self { - Self { - source: Some(Box::new(source)), - ..self - } - } + #[cfg(not(target_arch = "wasm32"))] + pub(crate) fn new(msg: S) -> Self { + Self { msg: msg.to_string(), source: None } + } + + #[cfg(not(target_arch = "wasm32"))] + pub(crate) fn source(self, source: impl Error + Send + Sync + 'static) -> Self { + Self { source: Some(Box::new(source)), ..self } + } } impl fmt::Display for SigningError { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "Key signing error: {}", self.msg) - } + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "Key signing error: {}", self.msg) + } } impl Error for SigningError { - fn source(&self) -> Option<&(dyn Error + 'static)> { - self.source.as_ref().map(|s| &**s as &dyn Error) - } -} \ No newline at end of file + fn source(&self) -> Option<&(dyn Error + 'static)> { + self.source.as_ref().map(|s| &**s as &dyn Error) + } +} From 5f72326505856524f57b9c09736ec3aa613bccf5 Mon Sep 17 00:00:00 2001 From: ndkazu Date: Tue, 1 Oct 2024 23:22:51 +0900 Subject: [PATCH 56/80] Fixed prdoc --- prdoc/pr_5842.prdoc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/prdoc/pr_5842.prdoc b/prdoc/pr_5842.prdoc index e38de38e718f..0175c7583419 100644 --- a/prdoc/pr_5842.prdoc +++ b/prdoc/pr_5842.prdoc @@ -12,5 +12,7 @@ doc: crates: - name: sc-network bump: patch + - name: sc-network-types + bump: patch - name: sc-authority-discovery bump: patch From c96ace58c430cd9ccefcd00cbced87aed0fa8635 Mon Sep 17 00:00:00 2001 From: Kazunobu Ndong <33208377+ndkazu@users.noreply.github.com> Date: Tue, 8 Oct 2024 07:38:03 +0900 Subject: [PATCH 57/80] Update substrate/client/network/types/src/rec.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/types/src/rec.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/substrate/client/network/types/src/rec.rs b/substrate/client/network/types/src/rec.rs index 11b05e7c7a5b..4f1e42eff231 100644 --- a/substrate/client/network/types/src/rec.rs +++ b/substrate/client/network/types/src/rec.rs @@ -129,10 +129,6 @@ impl From for libp2p_kad::Record { } } -/*impl From for SigningError { - fn from(a: ) -}*/ - /// A record either received by the given peer or retrieved from the local /// record store. #[derive(Debug, Clone, PartialEq, Eq)] From a3210f5ce6387ae76d9c506376bc0881072def91 Mon Sep 17 00:00:00 2001 From: ndkazu Date: Tue, 8 Oct 2024 08:01:24 +0900 Subject: [PATCH 58/80] Applied review corrections --- substrate/client/network/types/src/rec.rs | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/substrate/client/network/types/src/rec.rs b/substrate/client/network/types/src/rec.rs index 4f1e42eff231..5180e4dac98f 100644 --- a/substrate/client/network/types/src/rec.rs +++ b/substrate/client/network/types/src/rec.rs @@ -93,10 +93,7 @@ impl From for Record { fn from(out: libp2p_kad::Record) -> Self { let vec: Vec = out.key.to_vec(); let key: Key = vec.into(); - let mut publisher: Option = None; - if let Some(x) = out.publisher { - publisher = Some(x.into()); - } + let publisher = out.publisher.map(Into::into); Record { key, value: out.value, publisher, expires: out.expires } } } @@ -105,21 +102,14 @@ impl From for LiteRecord { fn from(val: Record) -> Self { let vec: Vec = val.key.to_vec(); let key: RecordKey = vec.into(); - let mut publisher: Option = None; - if let Some(x) = val.publisher { - publisher = Some(x.into()); - } + let publisher = val.publisher.map(Into::into); LiteRecord { key, value: val.value, publisher, expires: val.expires } } } impl From for libp2p_kad::Record { fn from(a: Record) -> libp2p_kad::Record { - //let key: KademliaKey = a.key.to_vec().into(); - let mut peer: Option = None; - if let Some(x) = a.publisher { - peer = Some(x.into()); - } + let peer = a.publisher.map(Into::into); libp2p_kad::Record { key: a.key.to_vec().into(), value: a.value, @@ -141,10 +131,7 @@ pub struct PeerRecord { impl From for PeerRecord { fn from(out: libp2p_kad::PeerRecord) -> Self { - let mut peer: Option = None; - if let Some(x) = out.peer { - peer = Some(x.into()); - } + let peer = out.peer.map(Into::into); let record = out.record.into(); PeerRecord { peer, record } } From 0df8b33097c5149266ac85c9c75e44e9761e054a Mon Sep 17 00:00:00 2001 From: ndkazu Date: Sat, 2 Nov 2024 15:24:23 +0900 Subject: [PATCH 59/80] changed file name from rec.rs to kad.rs --- substrate/client/authority-discovery/src/worker.rs | 2 +- substrate/client/authority-discovery/src/worker/tests.rs | 2 +- substrate/client/network/src/event.rs | 2 +- substrate/client/network/src/litep2p/mod.rs | 8 ++++---- substrate/client/network/src/litep2p/service.rs | 2 +- substrate/client/network/src/service.rs | 2 +- substrate/client/network/src/service/traits.rs | 2 +- substrate/client/network/types/src/{rec.rs => kad.rs} | 0 substrate/client/network/types/src/lib.rs | 2 +- 9 files changed, 11 insertions(+), 11 deletions(-) rename substrate/client/network/types/src/{rec.rs => kad.rs} (100%) diff --git a/substrate/client/authority-discovery/src/worker.rs b/substrate/client/authority-discovery/src/worker.rs index 13e860463c2d..2d2e6294f80e 100644 --- a/substrate/client/authority-discovery/src/worker.rs +++ b/substrate/client/authority-discovery/src/worker.rs @@ -35,7 +35,7 @@ use addr_cache::AddrCache; use codec::{Decode, Encode}; use ip_network::IpNetwork; use linked_hash_set::LinkedHashSet; -use sc_network_types::rec::{Key, PeerRecord, Record}; +use sc_network_types::kad::{Key, PeerRecord, Record}; use log::{debug, error, trace}; use prometheus_endpoint::{register, Counter, CounterVec, Gauge, Opts, U64}; diff --git a/substrate/client/authority-discovery/src/worker/tests.rs b/substrate/client/authority-discovery/src/worker/tests.rs index a594e405a4dc..29d355b5ee15 100644 --- a/substrate/client/authority-discovery/src/worker/tests.rs +++ b/substrate/client/authority-discovery/src/worker/tests.rs @@ -38,7 +38,7 @@ use sc_network::{ }; use sc_network_types::{ multiaddr::{Multiaddr, Protocol}, - rec::Key as KademliaKey, + kad::Key as KademliaKey, PeerId, }; use sp_api::{ApiRef, ProvideRuntimeApi}; diff --git a/substrate/client/network/src/event.rs b/substrate/client/network/src/event.rs index d441b7e47ba7..626cf516a7ec 100644 --- a/substrate/client/network/src/event.rs +++ b/substrate/client/network/src/event.rs @@ -25,7 +25,7 @@ use bytes::Bytes; use sc_network_common::role::ObservedRole; use sc_network_types::{ - rec::{Key, PeerRecord}, + kad::{Key, PeerRecord}, PeerId, }; diff --git a/substrate/client/network/src/litep2p/mod.rs b/substrate/client/network/src/litep2p/mod.rs index 0f75ac0c32f6..a80cb64cc814 100644 --- a/substrate/client/network/src/litep2p/mod.rs +++ b/substrate/client/network/src/litep2p/mod.rs @@ -863,7 +863,7 @@ impl NetworkBackend for Litep2pNetworkBac ); self.event_streams.send(Event::Dht( - DhtEvent::ValuePut(sc_network_types::rec::Key::new::(&key.to_vec().into())) + DhtEvent::ValuePut(sc_network_types::kad::Key::new::(&key.to_vec().into())) )); if let Some(ref metrics) = self.metrics { @@ -889,7 +889,7 @@ impl NetworkBackend for Litep2pNetworkBac ); self.event_streams.send(Event::Dht( - DhtEvent::ValuePutFailed(sc_network_types::rec::Key::new::(&key.to_vec().into())) + DhtEvent::ValuePutFailed(sc_network_types::kad::Key::new::(&key.to_vec().into())) )); if let Some(ref metrics) = self.metrics { @@ -907,7 +907,7 @@ impl NetworkBackend for Litep2pNetworkBac ); self.event_streams.send(Event::Dht( - DhtEvent::ValueNotFound(sc_network_types::rec::Key::new::(&key.to_vec().into())) + DhtEvent::ValueNotFound(sc_network_types::kad::Key::new::(&key.to_vec().into())) )); if let Some(ref metrics) = self.metrics { @@ -963,7 +963,7 @@ impl NetworkBackend for Litep2pNetworkBac Some(DiscoveryEvent::IncomingRecord { record: Record { key, value, publisher, expires }} ) => { self.event_streams.send(Event::Dht( DhtEvent::PutRecordRequest( - sc_network_types::rec::Key::new::(&key.to_vec().into()), + sc_network_types::kad::Key::new::(&key.to_vec().into()), value, publisher.map(Into::into), expires, diff --git a/substrate/client/network/src/litep2p/service.rs b/substrate/client/network/src/litep2p/service.rs index e1823b32d312..fa1d47e5a1b7 100644 --- a/substrate/client/network/src/litep2p/service.rs +++ b/substrate/client/network/src/litep2p/service.rs @@ -40,7 +40,7 @@ use litep2p::{ types::multiaddr::Multiaddr as LiteP2pMultiaddr, }; use parking_lot::RwLock; -use sc_network_types::rec::{Key as KademliaKey, Record}; +use sc_network_types::kad::{Key as KademliaKey, Record}; use sc_network_common::{ role::{ObservedRole, Roles}, diff --git a/substrate/client/network/src/service.rs b/substrate/client/network/src/service.rs index 96f8893d3354..438ef1ff7421 100644 --- a/substrate/client/network/src/service.rs +++ b/substrate/client/network/src/service.rs @@ -79,7 +79,7 @@ use log::{debug, error, info, trace, warn}; use metrics::{Histogram, MetricSources, Metrics}; use parking_lot::Mutex; use prometheus_endpoint::Registry; -use sc_network_types::rec::{Key as KademliaKey, Record}; +use sc_network_types::kad::{Key as KademliaKey, Record}; use sc_client_api::BlockBackend; use sc_network_common::{ diff --git a/substrate/client/network/src/service/traits.rs b/substrate/client/network/src/service/traits.rs index 500d3fe6aeda..8fa430adfd9c 100644 --- a/substrate/client/network/src/service/traits.rs +++ b/substrate/client/network/src/service/traits.rs @@ -38,7 +38,7 @@ use sc_client_api::BlockBackend; use sc_network_common::{role::ObservedRole, ExHashT}; pub use sc_network_types::{ multiaddr::Multiaddr, - rec::{Key as KademliaKey, Record}, + kad::{Key as KademliaKey, Record}, PeerId, }; use sp_runtime::traits::Block as BlockT; diff --git a/substrate/client/network/types/src/rec.rs b/substrate/client/network/types/src/kad.rs similarity index 100% rename from substrate/client/network/types/src/rec.rs rename to substrate/client/network/types/src/kad.rs diff --git a/substrate/client/network/types/src/lib.rs b/substrate/client/network/types/src/lib.rs index ba9bb739efdb..299b93d10355 100644 --- a/substrate/client/network/types/src/lib.rs +++ b/substrate/client/network/types/src/lib.rs @@ -20,5 +20,5 @@ pub mod ed25519; pub mod multiaddr; pub mod multihash; mod peer_id; -pub mod rec; +pub mod kad; pub use peer_id::PeerId; From 596fcf943f5adf46aad430ac4da159930f1ae40c Mon Sep 17 00:00:00 2001 From: ndkazu Date: Sat, 2 Nov 2024 16:42:17 +0900 Subject: [PATCH 60/80] Removed unnecessary into() and libp2p --- substrate/client/authority-discovery/src/worker.rs | 2 +- substrate/client/network/src/types.rs | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/substrate/client/authority-discovery/src/worker.rs b/substrate/client/authority-discovery/src/worker.rs index 2d2e6294f80e..14b071727191 100644 --- a/substrate/client/authority-discovery/src/worker.rs +++ b/substrate/client/authority-discovery/src/worker.rs @@ -580,7 +580,7 @@ where debug!(target: LOG_TARGET, "Value for hash '{:?}' found on Dht.", v.record.key); - if let Err(e) = self.handle_dht_value_found_event(v.into()) { + if let Err(e) = self.handle_dht_value_found_event(v) { if let Some(metrics) = &self.metrics { metrics.handle_value_found_event_failure.inc(); } diff --git a/substrate/client/network/src/types.rs b/substrate/client/network/src/types.rs index 0652bbcdddec..5289389de381 100644 --- a/substrate/client/network/src/types.rs +++ b/substrate/client/network/src/types.rs @@ -26,8 +26,6 @@ use std::{ sync::Arc, }; -pub use libp2p::{multiaddr, Multiaddr, PeerId}; - /// The protocol name transmitted on the wire. #[derive(Debug, Clone)] pub enum ProtocolName { From 3ab346059fafd3c87cb0ee229cb500c0f9e06175 Mon Sep 17 00:00:00 2001 From: ndkazu Date: Mon, 4 Nov 2024 21:38:47 +0900 Subject: [PATCH 61/80] Removed unneeded conversions --- .../client/authority-discovery/src/worker.rs | 22 +++++++++---------- substrate/client/network/src/litep2p/mod.rs | 6 ++--- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/substrate/client/authority-discovery/src/worker.rs b/substrate/client/authority-discovery/src/worker.rs index 14b071727191..c9bfa46a8dfd 100644 --- a/substrate/client/authority-discovery/src/worker.rs +++ b/substrate/client/authority-discovery/src/worker.rs @@ -592,7 +592,7 @@ where metrics.dht_event_received.with_label_values(&["value_not_found"]).inc(); } - if self.in_flight_lookups.remove::(&hash.to_vec().into()).is_some() { + if self.in_flight_lookups.remove(&hash).is_some() { debug!(target: LOG_TARGET, "Value for hash '{:?}' not found on Dht.", hash) } else { debug!( @@ -602,7 +602,7 @@ where } }, DhtEvent::ValuePut(hash) => { - if !self.latest_published_kad_keys.contains::(&hash.to_vec().into()) { + if !self.latest_published_kad_keys.contains(&hash) { return; } @@ -618,7 +618,7 @@ where debug!(target: LOG_TARGET, "Successfully put hash '{:?}' on Dht.", hash) }, DhtEvent::ValuePutFailed(hash) => { - if !self.latest_published_kad_keys.contains::(&hash.to_vec().into()) { + if !self.latest_published_kad_keys.contains(&hash) { // Not a value we have published or received multiple times. return; } @@ -656,7 +656,7 @@ where // Make sure we don't ever work with an outdated set of authorities // and that we do not update known_authorithies too often. let best_hash = self.client.best_hash().await?; - if !self.known_authorities.contains_key::(&record_key.to_vec().into()) && + if !self.known_authorities.contains_key(&record_key) && self.authorities_queried_at .map(|authorities_queried_at| authorities_queried_at != best_hash) .unwrap_or(true) @@ -679,7 +679,7 @@ where let authority_id = self .known_authorities - .get::(&record_key.to_vec().into()) + .get(&record_key) .ok_or(Error::UnknownAuthority)?; let signed_record = Self::check_record_signed_with_authority_id(record_value.as_slice(), authority_id)?; @@ -700,7 +700,7 @@ where .unwrap_or_default(); // 0 is a sane default for records that do not have creation time present. let current_record_info = - self.last_known_records.get::(&record_key.to_vec().into()); + self.last_known_records.get(&record_key); // If record creation time is older than the current record creation time, // we don't store it since we want to give higher priority to newer records. if let Some(current_record_info) = current_record_info { @@ -716,7 +716,7 @@ where } self.network.store_record( - record_key.to_vec().into(), + record_key, record_value, Some(publisher), expires, @@ -775,13 +775,13 @@ where let remote_key = peer_record.record.key.clone(); let authority_id: AuthorityId = if let Some(authority_id) = - self.in_flight_lookups.remove::(&remote_key.to_vec().into()) + self.in_flight_lookups.remove(&remote_key) { self.known_lookups - .insert(remote_key.clone().to_vec().into(), authority_id.clone()); + .insert(remote_key.clone(), authority_id.clone()); authority_id } else if let Some(authority_id) = - self.known_lookups.get::(&remote_key.to_vec().into()) + self.known_lookups.get(&remote_key) { authority_id.clone() } else { @@ -847,7 +847,7 @@ where let addr_cache_needs_update = self.handle_new_record( &authority_id, - remote_key.clone().to_vec().into(), + remote_key.clone(), RecordInfo { creation_time: records_creation_time, peers_with_record: answering_peer_id.into_iter().collect(), diff --git a/substrate/client/network/src/litep2p/mod.rs b/substrate/client/network/src/litep2p/mod.rs index a80cb64cc814..e51e4c93574c 100644 --- a/substrate/client/network/src/litep2p/mod.rs +++ b/substrate/client/network/src/litep2p/mod.rs @@ -863,7 +863,7 @@ impl NetworkBackend for Litep2pNetworkBac ); self.event_streams.send(Event::Dht( - DhtEvent::ValuePut(sc_network_types::kad::Key::new::(&key.to_vec().into())) + DhtEvent::ValuePut(sc_network_types::kad::Key::new(&key.to_vec())) )); if let Some(ref metrics) = self.metrics { @@ -889,7 +889,7 @@ impl NetworkBackend for Litep2pNetworkBac ); self.event_streams.send(Event::Dht( - DhtEvent::ValuePutFailed(sc_network_types::kad::Key::new::(&key.to_vec().into())) + DhtEvent::ValuePutFailed(sc_network_types::kad::Key::new(&key.to_vec())) )); if let Some(ref metrics) = self.metrics { @@ -907,7 +907,7 @@ impl NetworkBackend for Litep2pNetworkBac ); self.event_streams.send(Event::Dht( - DhtEvent::ValueNotFound(sc_network_types::kad::Key::new::(&key.to_vec().into())) + DhtEvent::ValueNotFound(sc_network_types::kad::Key::new(&key.to_vec())) )); if let Some(ref metrics) = self.metrics { From e7e5ccd48426c4de72e85446676357307ff7ac6f Mon Sep 17 00:00:00 2001 From: ndkazu Date: Mon, 4 Nov 2024 22:39:47 +0900 Subject: [PATCH 62/80] Started work on litep2p/mod.rs --- substrate/client/network/src/litep2p/mod.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/substrate/client/network/src/litep2p/mod.rs b/substrate/client/network/src/litep2p/mod.rs index e51e4c93574c..4d85b33861e4 100644 --- a/substrate/client/network/src/litep2p/mod.rs +++ b/substrate/client/network/src/litep2p/mod.rs @@ -50,7 +50,8 @@ use crate::{ use codec::Encode; use futures::StreamExt; -use libp2p::kad::{PeerRecord, Record as P2PRecord, RecordKey}; +use sc_network_types::kad::{PeerRecord, Record as P2PRecord}; +use sc_network_types::kad::Key as RecordKey; use litep2p::{ config::ConfigBuilder, crypto::ed25519::Keypair, From 04e74ffe5b515f98271eaa8735f80720d62c8719 Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Fri, 8 Nov 2024 12:22:27 +0000 Subject: [PATCH 63/80] ".git/.scripts/commands/fmt/fmt.sh" --- .../client/authority-discovery/src/worker.rs | 38 +++++++------------ .../authority-discovery/src/worker/tests.rs | 2 +- substrate/client/network/src/litep2p/mod.rs | 3 +- .../client/network/src/service/traits.rs | 2 +- substrate/client/network/types/src/lib.rs | 2 +- 5 files changed, 17 insertions(+), 30 deletions(-) diff --git a/substrate/client/authority-discovery/src/worker.rs b/substrate/client/authority-discovery/src/worker.rs index 11e4bb631a0c..4f370bc760c5 100644 --- a/substrate/client/authority-discovery/src/worker.rs +++ b/substrate/client/authority-discovery/src/worker.rs @@ -713,10 +713,8 @@ where self.authorities_queried_at = Some(best_hash); } - let authority_id = self - .known_authorities - .get(&record_key) - .ok_or(Error::UnknownAuthority)?; + let authority_id = + self.known_authorities.get(&record_key).ok_or(Error::UnknownAuthority)?; let signed_record = Self::check_record_signed_with_authority_id(record_value.as_slice(), authority_id)?; self.check_record_signed_with_network_key( @@ -735,8 +733,7 @@ where }) .unwrap_or_default(); // 0 is a sane default for records that do not have creation time present. - let current_record_info = - self.last_known_records.get(&record_key); + let current_record_info = self.last_known_records.get(&record_key); // If record creation time is older than the current record creation time, // we don't store it since we want to give higher priority to newer records. if let Some(current_record_info) = current_record_info { @@ -751,12 +748,7 @@ where } } - self.network.store_record( - record_key, - record_value, - Some(publisher), - expires, - ); + self.network.store_record(record_key, record_value, Some(publisher), expires); Ok(()) } @@ -810,19 +802,15 @@ where // Ensure `values` is not empty and all its keys equal. let remote_key = peer_record.record.key.clone(); - let authority_id: AuthorityId = if let Some(authority_id) = - self.in_flight_lookups.remove(&remote_key) - { - self.known_lookups - .insert(remote_key.clone(), authority_id.clone()); - authority_id - } else if let Some(authority_id) = - self.known_lookups.get(&remote_key) - { - authority_id.clone() - } else { - return Err(Error::ReceivingUnexpectedRecord); - }; + let authority_id: AuthorityId = + if let Some(authority_id) = self.in_flight_lookups.remove(&remote_key) { + self.known_lookups.insert(remote_key.clone(), authority_id.clone()); + authority_id + } else if let Some(authority_id) = self.known_lookups.get(&remote_key) { + authority_id.clone() + } else { + return Err(Error::ReceivingUnexpectedRecord); + }; let local_peer_id = self.network.local_peer_id(); diff --git a/substrate/client/authority-discovery/src/worker/tests.rs b/substrate/client/authority-discovery/src/worker/tests.rs index 0f772d5dea5a..c40da5ae7c7a 100644 --- a/substrate/client/authority-discovery/src/worker/tests.rs +++ b/substrate/client/authority-discovery/src/worker/tests.rs @@ -37,8 +37,8 @@ use sc_network::{ PublicKey, Signature, }; use sc_network_types::{ - multiaddr::{Multiaddr, Protocol}, kad::Key as KademliaKey, + multiaddr::{Multiaddr, Protocol}, PeerId, }; use sp_api::{ApiRef, ProvideRuntimeApi}; diff --git a/substrate/client/network/src/litep2p/mod.rs b/substrate/client/network/src/litep2p/mod.rs index cafe1098a752..6df3b15eb6cb 100644 --- a/substrate/client/network/src/litep2p/mod.rs +++ b/substrate/client/network/src/litep2p/mod.rs @@ -50,8 +50,6 @@ use crate::{ use codec::Encode; use futures::StreamExt; -use sc_network_types::kad::{PeerRecord, Record as P2PRecord}; -use sc_network_types::kad::Key as RecordKey; use litep2p::{ config::ConfigBuilder, crypto::ed25519::Keypair, @@ -75,6 +73,7 @@ use litep2p::{ Litep2p, Litep2pEvent, ProtocolName as Litep2pProtocolName, }; use prometheus_endpoint::Registry; +use sc_network_types::kad::{Key as RecordKey, PeerRecord, Record as P2PRecord}; use sc_client_api::BlockBackend; use sc_network_common::{role::Roles, ExHashT}; diff --git a/substrate/client/network/src/service/traits.rs b/substrate/client/network/src/service/traits.rs index 8fa430adfd9c..f5dd2995acb1 100644 --- a/substrate/client/network/src/service/traits.rs +++ b/substrate/client/network/src/service/traits.rs @@ -37,8 +37,8 @@ use prometheus_endpoint::Registry; use sc_client_api::BlockBackend; use sc_network_common::{role::ObservedRole, ExHashT}; pub use sc_network_types::{ - multiaddr::Multiaddr, kad::{Key as KademliaKey, Record}, + multiaddr::Multiaddr, PeerId, }; use sp_runtime::traits::Block as BlockT; diff --git a/substrate/client/network/types/src/lib.rs b/substrate/client/network/types/src/lib.rs index 299b93d10355..093d81533f60 100644 --- a/substrate/client/network/types/src/lib.rs +++ b/substrate/client/network/types/src/lib.rs @@ -17,8 +17,8 @@ // along with this program. If not, see . pub mod ed25519; +pub mod kad; pub mod multiaddr; pub mod multihash; mod peer_id; -pub mod kad; pub use peer_id::PeerId; From d1a7df4989984a6265071e03f413e569343b9faa Mon Sep 17 00:00:00 2001 From: Kazunobu Ndong <33208377+ndkazu@users.noreply.github.com> Date: Sat, 9 Nov 2024 20:50:16 +0900 Subject: [PATCH 64/80] Update substrate/client/network/types/src/kad.rs Co-authored-by: Dmitry Markin --- substrate/client/network/types/src/kad.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/substrate/client/network/types/src/kad.rs b/substrate/client/network/types/src/kad.rs index 5180e4dac98f..325db870a3c7 100644 --- a/substrate/client/network/types/src/kad.rs +++ b/substrate/client/network/types/src/kad.rs @@ -152,7 +152,6 @@ impl SigningError { Self { msg: msg.to_string(), source: None } } - #[cfg(not(target_arch = "wasm32"))] pub(crate) fn source(self, source: impl Error + Send + Sync + 'static) -> Self { Self { source: Some(Box::new(source)), ..self } } From 35fc773f82cdf1d6c8c6d587255ea8500c88ee40 Mon Sep 17 00:00:00 2001 From: ndkazu Date: Sat, 9 Nov 2024 21:27:34 +0900 Subject: [PATCH 65/80] First round of corrections --- .../client/authority-discovery/src/worker.rs | 2 +- .../authority-discovery/src/worker/tests.rs | 2 +- substrate/client/network/src/litep2p/mod.rs | 2 +- substrate/client/network/types/src/kad.rs | 15 +++------------ 4 files changed, 6 insertions(+), 15 deletions(-) diff --git a/substrate/client/authority-discovery/src/worker.rs b/substrate/client/authority-discovery/src/worker.rs index 4f370bc760c5..ba82910efcdf 100644 --- a/substrate/client/authority-discovery/src/worker.rs +++ b/substrate/client/authority-discovery/src/worker.rs @@ -906,7 +906,7 @@ where if new_record.creation_time > current_record_info.creation_time { let peers_that_need_updating = current_record_info.peers_with_record.clone(); self.network.put_record_to( - new_record.record.clone().into(), + new_record.record.clone(), peers_that_need_updating.clone(), // If this is empty it means we received the answer from our node local // storage, so we need to update that as well. diff --git a/substrate/client/authority-discovery/src/worker/tests.rs b/substrate/client/authority-discovery/src/worker/tests.rs index c40da5ae7c7a..6c3a3b56b1cb 100644 --- a/substrate/client/authority-discovery/src/worker/tests.rs +++ b/substrate/client/authority-discovery/src/worker/tests.rs @@ -169,7 +169,7 @@ impl NetworkSigner for TestNetwork { fn sign_with_local_identity( &self, msg: Vec, - ) -> std::result::Result { + ) -> std::result::Result { Signature::sign_message(msg, &self.identity) } diff --git a/substrate/client/network/src/litep2p/mod.rs b/substrate/client/network/src/litep2p/mod.rs index 6df3b15eb6cb..5dadc82ec19c 100644 --- a/substrate/client/network/src/litep2p/mod.rs +++ b/substrate/client/network/src/litep2p/mod.rs @@ -964,7 +964,7 @@ impl NetworkBackend for Litep2pNetworkBac Some(DiscoveryEvent::IncomingRecord { record: Record { key, value, publisher, expires }} ) => { self.event_streams.send(Event::Dht( DhtEvent::PutRecordRequest( - sc_network_types::kad::Key::new::(&key.to_vec().into()), + sc_network_types::kad::Key::new(&key.to_vec()), value, publisher.map(Into::into), expires, diff --git a/substrate/client/network/types/src/kad.rs b/substrate/client/network/types/src/kad.rs index 325db870a3c7..12eddb9436d4 100644 --- a/substrate/client/network/types/src/kad.rs +++ b/substrate/client/network/types/src/kad.rs @@ -19,7 +19,7 @@ use crate::{multihash::Multihash, PeerId}; use bytes::Bytes; use litep2p::protocol::libp2p::kademlia::{Record as LiteRecord, RecordKey}; -use std::{borrow::Borrow, error::Error, fmt, time::Instant}; +use std::{error::Error, fmt, time::Instant}; /// The (opaque) key of a record. #[derive(Clone, Debug, PartialEq, Eq, Hash)] @@ -37,12 +37,6 @@ impl Key { } } -impl Borrow<[u8]> for Key { - fn borrow(&self) -> &[u8] { - &self.0[..] - } -} - impl AsRef<[u8]> for Key { fn as_ref(&self) -> &[u8] { &self.0[..] @@ -76,11 +70,9 @@ pub struct Record { impl Record { /// Creates a new record for insertion into the DHT. - pub fn new(key: K, value: Vec) -> Self - where - K: Into, + pub fn new(key: Key, value: Vec) -> Self { - Record { key: key.into(), value, publisher: None, expires: None } + Record { key: key, value, publisher: None, expires: None } } /// Checks whether the record is expired w.r.t. the given `Instant`. @@ -147,7 +139,6 @@ pub struct SigningError { /// An error during encoding of key material. #[allow(dead_code)] impl SigningError { - #[cfg(not(target_arch = "wasm32"))] pub(crate) fn new(msg: S) -> Self { Self { msg: msg.to_string(), source: None } } From 37d217afb6b2bce5cb78fdb4829b3cc1804b2d87 Mon Sep 17 00:00:00 2001 From: ndkazu Date: Sat, 9 Nov 2024 21:36:01 +0900 Subject: [PATCH 66/80] 2nd round of corrections --- substrate/client/network/types/src/kad.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/substrate/client/network/types/src/kad.rs b/substrate/client/network/types/src/kad.rs index 12eddb9436d4..31b7c126e7f2 100644 --- a/substrate/client/network/types/src/kad.rs +++ b/substrate/client/network/types/src/kad.rs @@ -18,7 +18,7 @@ use crate::{multihash::Multihash, PeerId}; use bytes::Bytes; -use litep2p::protocol::libp2p::kademlia::{Record as LiteRecord, RecordKey}; +use litep2p::protocol::libp2p::kademlia::{Record as Litep2pRecord, RecordKey as Litep2pKey}; use std::{error::Error, fmt, time::Instant}; /// The (opaque) key of a record. @@ -90,12 +90,12 @@ impl From for Record { } } -impl From for LiteRecord { +impl From for Litep2pRecord { fn from(val: Record) -> Self { let vec: Vec = val.key.to_vec(); - let key: RecordKey = vec.into(); + let key: Litep2pKey = vec.into(); let publisher = val.publisher.map(Into::into); - LiteRecord { key, value: val.value, publisher, expires: val.expires } + Litep2pRecord { key, value: val.value, publisher, expires: val.expires } } } From 0e60ca0afab8850931790fc5415ddcad18f011c2 Mon Sep 17 00:00:00 2001 From: ndkazu Date: Sat, 9 Nov 2024 21:42:34 +0900 Subject: [PATCH 67/80] Corrected format --- substrate/client/network/types/src/kad.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/substrate/client/network/types/src/kad.rs b/substrate/client/network/types/src/kad.rs index 31b7c126e7f2..94c50fc9975a 100644 --- a/substrate/client/network/types/src/kad.rs +++ b/substrate/client/network/types/src/kad.rs @@ -70,9 +70,8 @@ pub struct Record { impl Record { /// Creates a new record for insertion into the DHT. - pub fn new(key: Key, value: Vec) -> Self - { - Record { key: key, value, publisher: None, expires: None } + pub fn new(key: Key, value: Vec) -> Self { + Record { key, value, publisher: None, expires: None } } /// Checks whether the record is expired w.r.t. the given `Instant`. From 349906a08f7f206af010f5179d8910f0c5708de8 Mon Sep 17 00:00:00 2001 From: ndkazu Date: Sat, 9 Nov 2024 22:00:50 +0900 Subject: [PATCH 68/80] Simplified function --- substrate/client/network/types/src/kad.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/client/network/types/src/kad.rs b/substrate/client/network/types/src/kad.rs index 94c50fc9975a..8d2d50522d22 100644 --- a/substrate/client/network/types/src/kad.rs +++ b/substrate/client/network/types/src/kad.rs @@ -33,7 +33,7 @@ impl Key { /// Copies the bytes of the key into a new vector. pub fn to_vec(&self) -> Vec { - Vec::from(&self.0[..]) + self.0.to_vec() } } From 65f0af4c497877cf5c48ac8d1dca466c70efa242 Mon Sep 17 00:00:00 2001 From: ndkazu Date: Mon, 11 Nov 2024 23:44:46 +0900 Subject: [PATCH 69/80] Simplified syntax --- substrate/client/network/src/litep2p/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/substrate/client/network/src/litep2p/mod.rs b/substrate/client/network/src/litep2p/mod.rs index 5dadc82ec19c..c6d6bf5b4165 100644 --- a/substrate/client/network/src/litep2p/mod.rs +++ b/substrate/client/network/src/litep2p/mod.rs @@ -864,7 +864,7 @@ impl NetworkBackend for Litep2pNetworkBac ); self.event_streams.send(Event::Dht( - DhtEvent::ValuePut(sc_network_types::kad::Key::new(&key.to_vec())) + DhtEvent::ValuePut(key.into()) )); if let Some(ref metrics) = self.metrics { @@ -890,7 +890,7 @@ impl NetworkBackend for Litep2pNetworkBac ); self.event_streams.send(Event::Dht( - DhtEvent::ValuePutFailed(sc_network_types::kad::Key::new(&key.to_vec())) + DhtEvent::ValuePutFailed(key.into()) )); if let Some(ref metrics) = self.metrics { From e0bc0b6c93d437fd8494eba6e403a02e09d3d018 Mon Sep 17 00:00:00 2001 From: Dmitry Markin Date: Tue, 12 Nov 2024 14:08:56 +0200 Subject: [PATCH 70/80] minor: use `into()` to convert kad key --- substrate/client/network/src/litep2p/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/substrate/client/network/src/litep2p/mod.rs b/substrate/client/network/src/litep2p/mod.rs index c6d6bf5b4165..bce7f57272ba 100644 --- a/substrate/client/network/src/litep2p/mod.rs +++ b/substrate/client/network/src/litep2p/mod.rs @@ -908,7 +908,7 @@ impl NetworkBackend for Litep2pNetworkBac ); self.event_streams.send(Event::Dht( - DhtEvent::ValueNotFound(sc_network_types::kad::Key::new(&key.to_vec())) + DhtEvent::ValueNotFound(key.into()) )); if let Some(ref metrics) = self.metrics { @@ -964,7 +964,7 @@ impl NetworkBackend for Litep2pNetworkBac Some(DiscoveryEvent::IncomingRecord { record: Record { key, value, publisher, expires }} ) => { self.event_streams.send(Event::Dht( DhtEvent::PutRecordRequest( - sc_network_types::kad::Key::new(&key.to_vec()), + key.into(), value, publisher.map(Into::into), expires, From 7fafdd044619604666ad089b1bdf29f275e1c659 Mon Sep 17 00:00:00 2001 From: Dmitry Markin Date: Tue, 12 Nov 2024 15:43:10 +0000 Subject: [PATCH 71/80] minor: simplify conversions --- .../client/network/src/litep2p/discovery.rs | 2 +- substrate/client/network/src/litep2p/mod.rs | 18 ++++++------- substrate/client/network/types/src/kad.rs | 25 +++++++++++++++++++ 3 files changed, 35 insertions(+), 10 deletions(-) diff --git a/substrate/client/network/src/litep2p/discovery.rs b/substrate/client/network/src/litep2p/discovery.rs index 9043f9420e8d..3a9454e317cc 100644 --- a/substrate/client/network/src/litep2p/discovery.rs +++ b/substrate/client/network/src/litep2p/discovery.rs @@ -27,7 +27,6 @@ use array_bytes::bytes2hex; use futures::{FutureExt, Stream}; use futures_timer::Delay; use ip_network::IpNetwork; -use libp2p::kad::record::Key as KademliaKey; use litep2p::{ protocol::{ libp2p::{ @@ -45,6 +44,7 @@ use litep2p::{ PeerId, ProtocolName, }; use parking_lot::RwLock; +use sc_network_types::kad::Key as KademliaKey; use schnellru::{ByLength, LruMap}; use std::{ diff --git a/substrate/client/network/src/litep2p/mod.rs b/substrate/client/network/src/litep2p/mod.rs index bce7f57272ba..15501dab688b 100644 --- a/substrate/client/network/src/litep2p/mod.rs +++ b/substrate/client/network/src/litep2p/mod.rs @@ -703,21 +703,21 @@ impl NetworkBackend for Litep2pNetworkBac None => return, Some(command) => match command { NetworkServiceCommand::GetValue{ key } => { - let query_id = self.discovery.get_value(key.to_vec().into()).await; - self.pending_get_values.insert(query_id, (key.to_vec().into(), Instant::now())); + let query_id = self.discovery.get_value(key.clone()).await; + self.pending_get_values.insert(query_id, (key, Instant::now())); } NetworkServiceCommand::PutValue { key, value } => { - let query_id = self.discovery.put_value(key.to_vec().into(), value).await; - self.pending_put_values.insert(query_id, (key.to_vec().into(), Instant::now())); + let query_id = self.discovery.put_value(key.clone(), value).await; + self.pending_put_values.insert(query_id, (key, Instant::now())); } NetworkServiceCommand::PutValueTo { record, peers, update_local_storage} => { - let kademlia_key = record.key.to_vec().into(); + let kademlia_key = record.key.clone(); let query_id = self.discovery.put_value_to_peers(record.into(), peers, update_local_storage).await; self.pending_put_values.insert(query_id, (kademlia_key, Instant::now())); } NetworkServiceCommand::StoreRecord { key, value, publisher, expires } => { - self.discovery.store_record(key.to_vec().into(), value, publisher.map(Into::into), expires).await; + self.discovery.store_record(key, value, publisher.map(Into::into), expires).await; } NetworkServiceCommand::EventStream { tx } => { self.event_streams.push(tx); @@ -864,7 +864,7 @@ impl NetworkBackend for Litep2pNetworkBac ); self.event_streams.send(Event::Dht( - DhtEvent::ValuePut(key.into()) + DhtEvent::ValuePut(key) )); if let Some(ref metrics) = self.metrics { @@ -890,7 +890,7 @@ impl NetworkBackend for Litep2pNetworkBac ); self.event_streams.send(Event::Dht( - DhtEvent::ValuePutFailed(key.into()) + DhtEvent::ValuePutFailed(key) )); if let Some(ref metrics) = self.metrics { @@ -908,7 +908,7 @@ impl NetworkBackend for Litep2pNetworkBac ); self.event_streams.send(Event::Dht( - DhtEvent::ValueNotFound(key.into()) + DhtEvent::ValueNotFound(key) )); if let Some(ref metrics) = self.metrics { diff --git a/substrate/client/network/types/src/kad.rs b/substrate/client/network/types/src/kad.rs index 8d2d50522d22..72028d356dc7 100644 --- a/substrate/client/network/types/src/kad.rs +++ b/substrate/client/network/types/src/kad.rs @@ -18,6 +18,7 @@ use crate::{multihash::Multihash, PeerId}; use bytes::Bytes; +use libp2p_kad::RecordKey as Libp2pKey; use litep2p::protocol::libp2p::kademlia::{Record as Litep2pRecord, RecordKey as Litep2pKey}; use std::{error::Error, fmt, time::Instant}; @@ -55,6 +56,30 @@ impl From for Key { } } +impl From for Key { + fn from(key: Litep2pKey) -> Self { + Self::from(key.to_vec()) + } +} + +impl From for Litep2pKey { + fn from(key: Key) -> Self { + Self::from(key.to_vec()) + } +} + +impl From for Key { + fn from(key: Libp2pKey) -> Self { + Self::from(key.to_vec()) + } +} + +impl From for Libp2pKey { + fn from(key: Key) -> Self { + Self::from(key.to_vec()) + } +} + /// A record stored in the DHT. #[derive(Clone, Debug, Eq, PartialEq)] pub struct Record { From 91d2836628532dfb258bd6a52a94d980a5eb1cf3 Mon Sep 17 00:00:00 2001 From: Dmitry Markin Date: Tue, 12 Nov 2024 15:48:47 +0000 Subject: [PATCH 72/80] minor: simplify conversions (libp2p backend) --- substrate/client/network/src/behaviour.rs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/substrate/client/network/src/behaviour.rs b/substrate/client/network/src/behaviour.rs index f4551213a7a5..dbb72381b660 100644 --- a/substrate/client/network/src/behaviour.rs +++ b/substrate/client/network/src/behaviour.rs @@ -377,21 +377,16 @@ impl From for BehaviourOut { DiscoveryOut::ValueFound(results, duration) => BehaviourOut::Dht(DhtEvent::ValueFound(results.into()), Some(duration)), DiscoveryOut::ValueNotFound(key, duration) => - BehaviourOut::Dht(DhtEvent::ValueNotFound(key.to_vec().into()), Some(duration)), + BehaviourOut::Dht(DhtEvent::ValueNotFound(key.into()), Some(duration)), DiscoveryOut::ValuePut(key, duration) => - BehaviourOut::Dht(DhtEvent::ValuePut(key.to_vec().into()), Some(duration)), + BehaviourOut::Dht(DhtEvent::ValuePut(key.into()), Some(duration)), DiscoveryOut::PutRecordRequest(record_key, record_value, publisher, expires) => BehaviourOut::Dht( - DhtEvent::PutRecordRequest( - record_key.to_vec().into(), - record_value, - publisher, - expires, - ), + DhtEvent::PutRecordRequest(record_key.into(), record_value, publisher, expires), None, ), DiscoveryOut::ValuePutFailed(key, duration) => - BehaviourOut::Dht(DhtEvent::ValuePutFailed(key.to_vec().into()), Some(duration)), + BehaviourOut::Dht(DhtEvent::ValuePutFailed(key.into()), Some(duration)), DiscoveryOut::RandomKademliaStarted => BehaviourOut::RandomKademliaStarted, } } From c3b039fa927fce32e06dd02cdeb1b1a403b59149 Mon Sep 17 00:00:00 2001 From: Dmitry Markin Date: Wed, 13 Nov 2024 11:00:42 +0000 Subject: [PATCH 73/80] empty, kick GitHub From 391047dde08bb621e23246d372e278aa0674b586 Mon Sep 17 00:00:00 2001 From: Dmitry Markin Date: Wed, 13 Nov 2024 12:18:01 +0000 Subject: [PATCH 74/80] minor: more direct conversions in `NetworkWorker` --- substrate/client/network/src/service.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/substrate/client/network/src/service.rs b/substrate/client/network/src/service.rs index 438ef1ff7421..5e5e4ee28589 100644 --- a/substrate/client/network/src/service.rs +++ b/substrate/client/network/src/service.rs @@ -1455,9 +1455,9 @@ where fn handle_worker_message(&mut self, msg: ServiceToWorkerMsg) { match msg { ServiceToWorkerMsg::GetValue(key) => - self.network_service.behaviour_mut().get_value(key.to_vec().into()), + self.network_service.behaviour_mut().get_value(key.into()), ServiceToWorkerMsg::PutValue(key, value) => - self.network_service.behaviour_mut().put_value(key.to_vec().into(), value), + self.network_service.behaviour_mut().put_value(key.into(), value), ServiceToWorkerMsg::PutRecordTo { record, peers, update_local_storage } => self .network_service .behaviour_mut() @@ -1465,7 +1465,7 @@ where ServiceToWorkerMsg::StoreRecord(key, value, publisher, expires) => self .network_service .behaviour_mut() - .store_record(key.to_vec().into(), value, publisher, expires), + .store_record(key.into(), value, publisher, expires), ServiceToWorkerMsg::AddKnownAddress(peer_id, addr) => self.network_service.behaviour_mut().add_known_address(peer_id, addr), ServiceToWorkerMsg::EventStream(sender) => self.event_streams.push(sender), From 86cccce1ef4a984b1370ea6f1b812675da0d1135 Mon Sep 17 00:00:00 2001 From: ndkazu Date: Sat, 16 Nov 2024 23:34:02 +0900 Subject: [PATCH 75/80] Start migration to benchmarking V2 --- substrate/frame/democracy/src/benchmarking.rs | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/substrate/frame/democracy/src/benchmarking.rs b/substrate/frame/democracy/src/benchmarking.rs index ee36e9212f52..23f0c958b021 100644 --- a/substrate/frame/democracy/src/benchmarking.rs +++ b/substrate/frame/democracy/src/benchmarking.rs @@ -17,9 +17,11 @@ //! Democracy pallet benchmarking. +#![cfg(feature = "runtime-benchmarks")] + use super::*; -use frame_benchmarking::v1::{account, benchmarks, whitelist_account, BenchmarkError}; +use frame_benchmarking::v2::*; use frame_support::{ assert_noop, assert_ok, traits::{Currency, EnsureOrigin, Get, OnInitialize, UnfilteredDispatchable}, @@ -94,8 +96,12 @@ fn note_preimage() -> T::Hash { hash } -benchmarks! { - propose { +#[benchmarks] +mod benchmarks { + use super::*; + + #[benchmark] + fn propose() -> Result<(), BenchmarkError> { let p = T::MaxProposals::get(); for i in 0 .. (p - 1) { @@ -106,11 +112,14 @@ benchmarks! { let proposal = make_proposal::(0); let value = T::MinimumDeposit::get(); whitelist_account!(caller); - }: _(RawOrigin::Signed(caller), proposal, value) - verify { + + #[extrinsic_call] + _(RawOrigin::Signed(caller), proposal, value); + assert_eq!(PublicProps::::get().len(), p as usize, "Proposals not created."); + Ok(()) } - +/* second { let caller = funded_account::("caller", 0); add_proposal::(0)?; @@ -845,7 +854,7 @@ benchmarks! { hash, }.into()); } - +*/ impl_benchmark_test_suite!( Democracy, crate::tests::new_test_ext(), From 6a8f452e34b89d2184f80f40d4c0dabac399d427 Mon Sep 17 00:00:00 2001 From: ndkazu Date: Sun, 17 Nov 2024 12:41:28 +0900 Subject: [PATCH 76/80] Changing to V2 --- substrate/frame/democracy/src/benchmarking.rs | 36 +++++++++++++------ 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/substrate/frame/democracy/src/benchmarking.rs b/substrate/frame/democracy/src/benchmarking.rs index 23f0c958b021..5f2fd63b4bf0 100644 --- a/substrate/frame/democracy/src/benchmarking.rs +++ b/substrate/frame/democracy/src/benchmarking.rs @@ -119,8 +119,9 @@ mod benchmarks { assert_eq!(PublicProps::::get().len(), p as usize, "Proposals not created."); Ok(()) } -/* - second { + + #[benchmark] + fn second() -> Result<(), BenchmarkError> { let caller = funded_account::("caller", 0); add_proposal::(0)?; @@ -134,13 +135,18 @@ mod benchmarks { let deposits = DepositOf::::get(0).ok_or("Proposal not created")?; assert_eq!(deposits.0.len(), (T::MaxDeposits::get() - 1) as usize, "Seconds not recorded"); whitelist_account!(caller); - }: _(RawOrigin::Signed(caller), 0) - verify { + + #[extrinsic_call] + _(RawOrigin::Signed(caller), 0); + + let deposits = DepositOf::::get(0).ok_or("Proposal not created")?; assert_eq!(deposits.0.len(), (T::MaxDeposits::get()) as usize, "`second` benchmark did not work"); + Ok(()) } - vote_new { + #[benchmark] + fn vote_new() -> Result<(), BenchmarkError> { let caller = funded_account::("caller", 0); let account_vote = account_vote::(100u32.into()); @@ -157,16 +163,21 @@ mod benchmarks { let ref_index = add_referendum::(T::MaxVotes::get() - 1).0; whitelist_account!(caller); - }: vote(RawOrigin::Signed(caller.clone()), ref_index, account_vote) - verify { + + #[extrinsic_call] + vote(RawOrigin::Signed(caller.clone()), ref_index, account_vote); + let votes = match VotingOf::::get(&caller) { Voting::Direct { votes, .. } => votes, _ => return Err("Votes are not direct".into()), }; + assert_eq!(votes.len(), T::MaxVotes::get() as usize, "Vote was not recorded."); + Ok(()) } - vote_existing { + #[benchmark] + fn vote_existing() -> Result<(), BenchmarkError> { let caller = funded_account::("caller", 0); let account_vote = account_vote::(100u32.into()); @@ -188,8 +199,10 @@ mod benchmarks { // This tests when a user changes a vote whitelist_account!(caller); - }: vote(RawOrigin::Signed(caller.clone()), ref_index, new_vote) - verify { + + #[extrinsic_call] + vote(RawOrigin::Signed(caller.clone()), ref_index, new_vote); + let votes = match VotingOf::::get(&caller) { Voting::Direct { votes, .. } => votes, _ => return Err("Votes are not direct".into()), @@ -202,8 +215,9 @@ mod benchmarks { _ => return Err("referendum not ongoing".into()), }; assert_eq!(tally.nays, 1000u32.into(), "changed vote was not recorded"); + Ok(()) } - +/* emergency_cancel { let origin = T::CancellationOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?; From 0e907c4e08d5a2e8e1a854c6acbc16505f4775de Mon Sep 17 00:00:00 2001 From: ndkazu Date: Sun, 17 Nov 2024 20:44:22 +0900 Subject: [PATCH 77/80] Migrated benchmarking --- substrate/frame/democracy/src/benchmarking.rs | 509 +++++++++++------- 1 file changed, 305 insertions(+), 204 deletions(-) diff --git a/substrate/frame/democracy/src/benchmarking.rs b/substrate/frame/democracy/src/benchmarking.rs index 5f2fd63b4bf0..bdbc88aca533 100644 --- a/substrate/frame/democracy/src/benchmarking.rs +++ b/substrate/frame/democracy/src/benchmarking.rs @@ -104,7 +104,7 @@ mod benchmarks { fn propose() -> Result<(), BenchmarkError> { let p = T::MaxProposals::get(); - for i in 0 .. (p - 1) { + for i in 0..(p - 1) { add_proposal::(i)?; } @@ -115,7 +115,7 @@ mod benchmarks { #[extrinsic_call] _(RawOrigin::Signed(caller), proposal, value); - + assert_eq!(PublicProps::::get().len(), p as usize, "Proposals not created."); Ok(()) } @@ -127,7 +127,7 @@ mod benchmarks { // Create s existing "seconds" // we must reserve one deposit for the `proposal` and one for our benchmarked `second` call. - for i in 0 .. T::MaxDeposits::get() - 2 { + for i in 0..T::MaxDeposits::get() - 2 { let seconder = funded_account::("seconder", i); Democracy::::second(RawOrigin::Signed(seconder).into(), 0)?; } @@ -135,13 +135,16 @@ mod benchmarks { let deposits = DepositOf::::get(0).ok_or("Proposal not created")?; assert_eq!(deposits.0.len(), (T::MaxDeposits::get() - 1) as usize, "Seconds not recorded"); whitelist_account!(caller); - + #[extrinsic_call] _(RawOrigin::Signed(caller), 0); - - + let deposits = DepositOf::::get(0).ok_or("Proposal not created")?; - assert_eq!(deposits.0.len(), (T::MaxDeposits::get()) as usize, "`second` benchmark did not work"); + assert_eq!( + deposits.0.len(), + (T::MaxDeposits::get()) as usize, + "`second` benchmark did not work" + ); Ok(()) } @@ -151,9 +154,13 @@ mod benchmarks { let account_vote = account_vote::(100u32.into()); // We need to create existing direct votes - for i in 0 .. T::MaxVotes::get() - 1 { + for i in 0..T::MaxVotes::get() - 1 { let ref_index = add_referendum::(i).0; - Democracy::::vote(RawOrigin::Signed(caller.clone()).into(), ref_index, account_vote)?; + Democracy::::vote( + RawOrigin::Signed(caller.clone()).into(), + ref_index, + account_vote, + )?; } let votes = match VotingOf::::get(&caller) { Voting::Direct { votes, .. } => votes, @@ -184,7 +191,11 @@ mod benchmarks { // We need to create existing direct votes for i in 0..T::MaxVotes::get() { let ref_index = add_referendum::(i).0; - Democracy::::vote(RawOrigin::Signed(caller.clone()).into(), ref_index, account_vote)?; + Democracy::::vote( + RawOrigin::Signed(caller.clone()).into(), + ref_index, + account_vote, + )?; } let votes = match VotingOf::::get(&caller) { Voting::Direct { votes, .. } => votes, @@ -199,7 +210,7 @@ mod benchmarks { // This tests when a user changes a vote whitelist_account!(caller); - + #[extrinsic_call] vote(RawOrigin::Signed(caller.clone()), ref_index, new_vote); @@ -208,37 +219,41 @@ mod benchmarks { _ => return Err("Votes are not direct".into()), }; assert_eq!(votes.len(), T::MaxVotes::get() as usize, "Vote was incorrectly added"); - let referendum_info = ReferendumInfoOf::::get(ref_index) - .ok_or("referendum doesn't exist")?; - let tally = match referendum_info { + let referendum_info = + ReferendumInfoOf::::get(ref_index).ok_or("referendum doesn't exist")?; + let tally = match referendum_info { ReferendumInfo::Ongoing(r) => r.tally, _ => return Err("referendum not ongoing".into()), }; assert_eq!(tally.nays, 1000u32.into(), "changed vote was not recorded"); Ok(()) } -/* - emergency_cancel { - let origin = - T::CancellationOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?; + + #[benchmark] + fn emergency_cancel() -> Result<(), BenchmarkError> { + let origin = T::CancellationOrigin::try_successful_origin() + .map_err(|_| BenchmarkError::Weightless)?; let (ref_index, _, preimage_hash) = add_referendum::(0); assert_ok!(Democracy::::referendum_status(ref_index)); - }: _(origin, ref_index) - verify { + + #[extrinsic_call] + _(origin as T::RuntimeOrigin, ref_index); // Referendum has been canceled - assert_noop!( - Democracy::::referendum_status(ref_index), - Error::::ReferendumInvalid, + assert_noop!(Democracy::::referendum_status(ref_index), Error::::ReferendumInvalid,); + assert_last_event::( + crate::Event::MetadataCleared { + owner: MetadataOwner::Referendum(ref_index), + hash: preimage_hash, + } + .into(), ); - assert_last_event::(crate::Event::MetadataCleared { - owner: MetadataOwner::Referendum(ref_index), - hash: preimage_hash, - }.into()); + Ok(()) } - blacklist { + #[benchmark] + fn blacklist() -> Result<(), BenchmarkError> { // Place our proposal at the end to make sure it's worst case. - for i in 0 .. T::MaxProposals::get() - 1 { + for i in 0..T::MaxProposals::get() - 1 { add_proposal::(i)?; } // We should really add a lot of seconds here, but we're not doing it elsewhere. @@ -254,21 +269,24 @@ mod benchmarks { )); let origin = T::BlacklistOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?; - }: _(origin, hash, Some(ref_index)) - verify { + #[extrinsic_call] + _(origin as T::RuntimeOrigin, hash, Some(ref_index)); + // Referendum has been canceled - assert_noop!( - Democracy::::referendum_status(ref_index), - Error::::ReferendumInvalid + assert_noop!(Democracy::::referendum_status(ref_index), Error::::ReferendumInvalid); + assert_has_event::( + crate::Event::MetadataCleared { + owner: MetadataOwner::Referendum(ref_index), + hash: preimage_hash, + } + .into(), ); - assert_has_event::(crate::Event::MetadataCleared { - owner: MetadataOwner::Referendum(ref_index), - hash: preimage_hash, - }.into()); + Ok(()) } // Worst case scenario, we external propose a previously blacklisted proposal - external_propose { + #[benchmark] + fn external_propose() -> Result<(), BenchmarkError> { let origin = T::ExternalOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?; let proposal = make_proposal::(0); @@ -281,33 +299,42 @@ mod benchmarks { .try_into() .unwrap(); Blacklist::::insert(proposal.hash(), (BlockNumberFor::::zero(), addresses)); - }: _(origin, proposal) - verify { + #[extrinsic_call] + _(origin as T::RuntimeOrigin, proposal); + // External proposal created ensure!(NextExternal::::exists(), "External proposal didn't work"); + Ok(()) } - external_propose_majority { + #[benchmark] + fn external_propose_majority() -> Result<(), BenchmarkError> { let origin = T::ExternalMajorityOrigin::try_successful_origin() .map_err(|_| BenchmarkError::Weightless)?; let proposal = make_proposal::(0); - }: _(origin, proposal) - verify { + #[extrinsic_call] + _(origin as T::RuntimeOrigin, proposal); + // External proposal created ensure!(NextExternal::::exists(), "External proposal didn't work"); + Ok(()) } - external_propose_default { + #[benchmark] + fn external_propose_default() -> Result<(), BenchmarkError> { let origin = T::ExternalDefaultOrigin::try_successful_origin() .map_err(|_| BenchmarkError::Weightless)?; let proposal = make_proposal::(0); - }: _(origin, proposal) - verify { + #[extrinsic_call] + _(origin as T::RuntimeOrigin, proposal); + // External proposal created ensure!(NextExternal::::exists(), "External proposal didn't work"); + Ok(()) } - fast_track { + #[benchmark] + fn fast_track() -> Result<(), BenchmarkError> { let origin_propose = T::ExternalDefaultOrigin::try_successful_origin() .expect("ExternalDefaultOrigin has no successful origin required for the benchmark"); let proposal = make_proposal::(0); @@ -318,23 +345,30 @@ mod benchmarks { assert_ok!(Democracy::::set_metadata( origin_propose, MetadataOwner::External, - Some(preimage_hash))); + Some(preimage_hash) + )); // NOTE: Instant origin may invoke a little bit more logic, but may not always succeed. let origin_fast_track = T::FastTrackOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?; let voting_period = T::FastTrackVotingPeriod::get(); let delay = 0u32; - }: _(origin_fast_track, proposal_hash, voting_period, delay.into()) - verify { + #[extrinsic_call] + _(origin_fast_track as T::RuntimeOrigin, proposal_hash, voting_period, delay.into()); + assert_eq!(ReferendumCount::::get(), 1, "referendum not created"); - assert_last_event::(crate::Event::MetadataTransferred { - prev_owner: MetadataOwner::External, - owner: MetadataOwner::Referendum(0), - hash: preimage_hash, - }.into()); + assert_last_event::( + crate::Event::MetadataTransferred { + prev_owner: MetadataOwner::External, + owner: MetadataOwner::Referendum(0), + hash: preimage_hash, + } + .into(), + ); + Ok(()) } - veto_external { + #[benchmark] + fn veto_external() -> Result<(), BenchmarkError> { let proposal = make_proposal::(0); let proposal_hash = proposal.hash(); @@ -346,28 +380,32 @@ mod benchmarks { assert_ok!(Democracy::::set_metadata( origin_propose, MetadataOwner::External, - Some(preimage_hash)) - ); + Some(preimage_hash) + )); let mut vetoers: BoundedVec = Default::default(); - for i in 0 .. (T::MaxBlacklisted::get() - 1) { + for i in 0..(T::MaxBlacklisted::get() - 1) { vetoers.try_push(account::("vetoer", i, SEED)).unwrap(); } vetoers.sort(); Blacklist::::insert(proposal_hash, (BlockNumberFor::::zero(), vetoers)); - let origin = T::VetoOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?; + let origin = + T::VetoOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?; ensure!(NextExternal::::get().is_some(), "no external proposal"); - }: _(origin, proposal_hash) - verify { + #[extrinsic_call] + _(origin as T::RuntimeOrigin, proposal_hash); + assert!(NextExternal::::get().is_none()); let (_, new_vetoers) = Blacklist::::get(&proposal_hash).ok_or("no blacklist")?; assert_eq!(new_vetoers.len(), T::MaxBlacklisted::get() as usize, "vetoers not added"); + Ok(()) } - cancel_proposal { + #[benchmark] + fn cancel_proposal() -> Result<(), BenchmarkError> { // Place our proposal at the end to make sure it's worst case. - for i in 0 .. T::MaxProposals::get() { + for i in 0..T::MaxProposals::get() { add_proposal::(i)?; } // Add metadata to the first proposal. @@ -376,31 +414,41 @@ mod benchmarks { assert_ok!(Democracy::::set_metadata( RawOrigin::Signed(proposer).into(), MetadataOwner::Proposal(0), - Some(preimage_hash))); + Some(preimage_hash) + )); let cancel_origin = T::CancelProposalOrigin::try_successful_origin() .map_err(|_| BenchmarkError::Weightless)?; - }: _(cancel_origin, 0) - verify { - assert_last_event::(crate::Event::MetadataCleared { - owner: MetadataOwner::Proposal(0), - hash: preimage_hash, - }.into()); + #[extrinsic_call] + _(cancel_origin as T::RuntimeOrigin, 0); + + assert_last_event::( + crate::Event::MetadataCleared { + owner: MetadataOwner::Proposal(0), + hash: preimage_hash, + } + .into(), + ); + Ok(()) } - cancel_referendum { + #[benchmark] + fn cancel_referendum() -> Result<(), BenchmarkError> { let (ref_index, _, preimage_hash) = add_referendum::(0); - }: _(RawOrigin::Root, ref_index) - verify { - assert_last_event::(crate::Event::MetadataCleared { - owner: MetadataOwner::Referendum(0), - hash: preimage_hash, - }.into()); - } + #[extrinsic_call] + _(RawOrigin::Root, ref_index); - #[extra] - on_initialize_external { - let r in 0 .. REFERENDUM_COUNT_HINT; + assert_last_event::( + crate::Event::MetadataCleared { + owner: MetadataOwner::Referendum(0), + hash: preimage_hash, + } + .into(), + ); + Ok(()) + } + #[benchmark(extra)] + fn on_initialize_external(r: Linear<0, REFERENDUM_COUNT_HINT>) -> Result<(), BenchmarkError> { for i in 0..r { add_referendum::(i); } @@ -420,14 +468,17 @@ mod benchmarks { let block_number = T::LaunchPeriod::get(); - }: { Democracy::::on_initialize(block_number) } - verify { + #[block] + { + Democracy::::on_initialize(block_number); + } + // One extra because of next external assert_eq!(ReferendumCount::::get(), r + 1, "referenda not created"); ensure!(!NextExternal::::exists(), "External wasn't taken"); // All but the new next external should be finished - for i in 0 .. r { + for i in 0..r { if let Some(value) = ReferendumInfoOf::::get(i) { match value { ReferendumInfo::Finished { .. } => (), @@ -435,12 +486,13 @@ mod benchmarks { } } } + Ok(()) } - #[extra] - on_initialize_public { - let r in 0 .. (T::MaxVotes::get() - 1); - + #[benchmark(extra)] + fn on_initialize_public( + r: Linear<0, { T::MaxVotes::get() - 1 }>, + ) -> Result<(), BenchmarkError> { for i in 0..r { add_referendum::(i); } @@ -453,13 +505,16 @@ mod benchmarks { let block_number = T::LaunchPeriod::get(); - }: { Democracy::::on_initialize(block_number) } - verify { + #[block] + { + Democracy::::on_initialize(block_number); + } + // One extra because of next public assert_eq!(ReferendumCount::::get(), r + 1, "proposal not accepted"); // All should be finished - for i in 0 .. r { + for i in 0..r { if let Some(value) = ReferendumInfoOf::::get(i) { match value { ReferendumInfo::Finished { .. } => (), @@ -467,12 +522,12 @@ mod benchmarks { } } } + Ok(()) } // No launch no maturing referenda. - on_initialize_base { - let r in 0 .. (T::MaxVotes::get() - 1); - + #[benchmark] + fn on_initialize_base(r: Linear<0, { T::MaxVotes::get() - 1 }>) -> Result<(), BenchmarkError> { for i in 0..r { add_referendum::(i); } @@ -487,22 +542,29 @@ mod benchmarks { assert_eq!(ReferendumCount::::get(), r, "referenda not created"); assert_eq!(LowestUnbaked::::get(), 0, "invalid referenda init"); - }: { Democracy::::on_initialize(1u32.into()) } - verify { + #[block] + { + Democracy::::on_initialize(1u32.into()); + } + // All should be on going - for i in 0 .. r { + for i in 0..r { if let Some(value) = ReferendumInfoOf::::get(i) { match value { - ReferendumInfo::Finished { .. } => return Err("Referendum has been finished".into()), + ReferendumInfo::Finished { .. } => { + return Err("Referendum has been finished".into()) + }, ReferendumInfo::Ongoing(_) => (), } } } + Ok(()) } - on_initialize_base_with_launch_period { - let r in 0 .. (T::MaxVotes::get() - 1); - + #[benchmark] + fn on_initialize_base_with_launch_period( + r: Linear<0, { T::MaxVotes::get() - 1 }>, + ) -> Result<(), BenchmarkError> { for i in 0..r { add_referendum::(i); } @@ -519,22 +581,27 @@ mod benchmarks { let block_number = T::LaunchPeriod::get(); - }: { Democracy::::on_initialize(block_number) } - verify { + #[block] + { + Democracy::::on_initialize(block_number); + } + // All should be on going - for i in 0 .. r { + for i in 0..r { if let Some(value) = ReferendumInfoOf::::get(i) { match value { - ReferendumInfo::Finished { .. } => return Err("Referendum has been finished".into()), + ReferendumInfo::Finished { .. } => { + return Err("Referendum has been finished".into()) + }, ReferendumInfo::Ongoing(_) => (), } } } + Ok(()) } - delegate { - let r in 0 .. (T::MaxVotes::get() - 1); - + #[benchmark] + fn delegate(r: Linear<0, { T::MaxVotes::get() - 1 }>) -> Result<(), BenchmarkError> { let initial_balance: BalanceOf = 100u32.into(); let delegated_balance: BalanceOf = 1000u32.into(); @@ -561,7 +628,11 @@ mod benchmarks { // We need to create existing direct votes for the `new_delegate` for i in 0..r { let ref_index = add_referendum::(i).0; - Democracy::::vote(RawOrigin::Signed(new_delegate.clone()).into(), ref_index, account_vote)?; + Democracy::::vote( + RawOrigin::Signed(new_delegate.clone()).into(), + ref_index, + account_vote, + )?; } let votes = match VotingOf::::get(&new_delegate) { Voting::Direct { votes, .. } => votes, @@ -569,8 +640,15 @@ mod benchmarks { }; assert_eq!(votes.len(), r as usize, "Votes were not recorded."); whitelist_account!(caller); - }: _(RawOrigin::Signed(caller.clone()), new_delegate_lookup, Conviction::Locked1x, delegated_balance) - verify { + + #[extrinsic_call] + _( + RawOrigin::Signed(caller.clone()), + new_delegate_lookup, + Conviction::Locked1x, + delegated_balance, + ); + let (target, balance) = match VotingOf::::get(&caller) { Voting::Delegating { target, balance, .. } => (target, balance), _ => return Err("Votes are not direct".into()), @@ -582,11 +660,11 @@ mod benchmarks { _ => return Err("Votes are not direct".into()), }; assert_eq!(delegations.capital, delegated_balance, "delegation was not recorded."); + Ok(()) } - undelegate { - let r in 0 .. (T::MaxVotes::get() - 1); - + #[benchmark] + fn undelegate(r: Linear<0, { T::MaxVotes::get() - 1 }>) -> Result<(), BenchmarkError> { let initial_balance: BalanceOf = 100u32.into(); let delegated_balance: BalanceOf = 1000u32.into(); @@ -613,7 +691,7 @@ mod benchmarks { Democracy::::vote( RawOrigin::Signed(the_delegate.clone()).into(), ref_index, - account_vote + account_vote, )?; } let votes = match VotingOf::::get(&the_delegate) { @@ -622,31 +700,38 @@ mod benchmarks { }; assert_eq!(votes.len(), r as usize, "Votes were not recorded."); whitelist_account!(caller); - }: _(RawOrigin::Signed(caller.clone())) - verify { + + #[extrinsic_call] + _(RawOrigin::Signed(caller.clone())); + // Voting should now be direct match VotingOf::::get(&caller) { Voting::Direct { .. } => (), _ => return Err("undelegation failed".into()), } + Ok(()) } - clear_public_proposals { + #[benchmark] + fn clear_public_proposals() -> Result<(), BenchmarkError> { add_proposal::(0)?; - }: _(RawOrigin::Root) + #[extrinsic_call] + _(RawOrigin::Root); - // Test when unlock will remove locks - unlock_remove { - let r in 0 .. (T::MaxVotes::get() - 1); + Ok(()) + } + // Test when unlock will remove locks + #[benchmark] + fn unlock_remove(r: Linear<0, { T::MaxVotes::get() - 1 }>) -> Result<(), BenchmarkError> { let locker = funded_account::("locker", 0); let locker_lookup = T::Lookup::unlookup(locker.clone()); // Populate votes so things are locked let base_balance: BalanceOf = 100u32.into(); let small_vote = account_vote::(base_balance); // Vote and immediately unvote - for i in 0 .. r { + for i in 0..r { let ref_index = add_referendum::(i).0; Democracy::::vote(RawOrigin::Signed(locker.clone()).into(), ref_index, small_vote)?; Democracy::::remove_vote(RawOrigin::Signed(locker.clone()).into(), ref_index)?; @@ -654,23 +739,25 @@ mod benchmarks { let caller = funded_account::("caller", 0); whitelist_account!(caller); - }: unlock(RawOrigin::Signed(caller), locker_lookup) - verify { + + #[extrinsic_call] + unlock(RawOrigin::Signed(caller), locker_lookup); + // Note that we may want to add a `get_lock` api to actually verify let voting = VotingOf::::get(&locker); assert_eq!(voting.locked_balance(), BalanceOf::::zero()); + Ok(()) } // Test when unlock will set a new value - unlock_set { - let r in 0 .. (T::MaxVotes::get() - 1); - + #[benchmark] + fn unlock_set(r: Linear<0, { T::MaxVotes::get() - 1 }>) -> Result<(), BenchmarkError> { let locker = funded_account::("locker", 0); let locker_lookup = T::Lookup::unlookup(locker.clone()); // Populate votes so things are locked let base_balance: BalanceOf = 100u32.into(); let small_vote = account_vote::(base_balance); - for i in 0 .. r { + for i in 0..r { let ref_index = add_referendum::(i).0; Democracy::::vote(RawOrigin::Signed(locker.clone()).into(), ref_index, small_vote)?; } @@ -693,8 +780,10 @@ mod benchmarks { let caller = funded_account::("caller", 0); whitelist_account!(caller); - }: unlock(RawOrigin::Signed(caller), locker_lookup) - verify { + + #[extrinsic_call] + unlock(RawOrigin::Signed(caller), locker_lookup); + let votes = match VotingOf::::get(&locker) { Voting::Direct { votes, .. } => votes, _ => return Err("Votes are not direct".into()), @@ -704,17 +793,21 @@ mod benchmarks { let voting = VotingOf::::get(&locker); // Note that we may want to add a `get_lock` api to actually verify assert_eq!(voting.locked_balance(), if r > 0 { base_balance } else { 0u32.into() }); + Ok(()) } - remove_vote { - let r in 1 .. T::MaxVotes::get(); - + #[benchmark] + fn remove_vote(r: Linear<1, { T::MaxVotes::get() }>) -> Result<(), BenchmarkError> { let caller = funded_account::("caller", 0); let account_vote = account_vote::(100u32.into()); - for i in 0 .. r { + for i in 0..r { let ref_index = add_referendum::(i).0; - Democracy::::vote(RawOrigin::Signed(caller.clone()).into(), ref_index, account_vote)?; + Democracy::::vote( + RawOrigin::Signed(caller.clone()).into(), + ref_index, + account_vote, + )?; } let votes = match VotingOf::::get(&caller) { @@ -725,26 +818,32 @@ mod benchmarks { let ref_index = r - 1; whitelist_account!(caller); - }: _(RawOrigin::Signed(caller.clone()), ref_index) - verify { + + #[extrinsic_call] + _(RawOrigin::Signed(caller.clone()), ref_index); + let votes = match VotingOf::::get(&caller) { Voting::Direct { votes, .. } => votes, _ => return Err("Votes are not direct".into()), }; assert_eq!(votes.len(), (r - 1) as usize, "Vote was not removed"); + Ok(()) } // Worst case is when target == caller and referendum is ongoing - remove_other_vote { - let r in 1 .. T::MaxVotes::get(); - + #[benchmark] + fn remove_other_vote(r: Linear<1, { T::MaxVotes::get() }>) -> Result<(), BenchmarkError> { let caller = funded_account::("caller", r); let caller_lookup = T::Lookup::unlookup(caller.clone()); let account_vote = account_vote::(100u32.into()); - for i in 0 .. r { + for i in 0..r { let ref_index = add_referendum::(i).0; - Democracy::::vote(RawOrigin::Signed(caller.clone()).into(), ref_index, account_vote)?; + Democracy::::vote( + RawOrigin::Signed(caller.clone()).into(), + ref_index, + account_vote, + )?; } let votes = match VotingOf::::get(&caller) { @@ -755,68 +854,71 @@ mod benchmarks { let ref_index = r - 1; whitelist_account!(caller); - }: _(RawOrigin::Signed(caller.clone()), caller_lookup, ref_index) - verify { + + #[extrinsic_call] + _(RawOrigin::Signed(caller.clone()), caller_lookup, ref_index); + let votes = match VotingOf::::get(&caller) { Voting::Direct { votes, .. } => votes, _ => return Err("Votes are not direct".into()), }; assert_eq!(votes.len(), (r - 1) as usize, "Vote was not removed"); + Ok(()) } - set_external_metadata { + #[benchmark] + fn set_external_metadata() -> Result<(), BenchmarkError> { let origin = T::ExternalOrigin::try_successful_origin() .expect("ExternalOrigin has no successful origin required for the benchmark"); - assert_ok!( - Democracy::::external_propose(origin.clone(), make_proposal::(0)) - ); + assert_ok!(Democracy::::external_propose(origin.clone(), make_proposal::(0))); let owner = MetadataOwner::External; let hash = note_preimage::(); - }: set_metadata(origin, owner.clone(), Some(hash)) - verify { - assert_last_event::(crate::Event::MetadataSet { - owner, - hash, - }.into()); + + #[extrinsic_call] + set_metadata(origin as T::RuntimeOrigin, owner.clone(), Some(hash)); + + assert_last_event::(crate::Event::MetadataSet { owner, hash }.into()); + Ok(()) } - clear_external_metadata { + #[benchmark] + fn clear_external_metadata() -> Result<(), BenchmarkError> { let origin = T::ExternalOrigin::try_successful_origin() .expect("ExternalOrigin has no successful origin required for the benchmark"); - assert_ok!( - Democracy::::external_propose(origin.clone(), make_proposal::(0)) - ); + assert_ok!(Democracy::::external_propose(origin.clone(), make_proposal::(0))); let owner = MetadataOwner::External; let proposer = funded_account::("proposer", 0); let hash = note_preimage::(); assert_ok!(Democracy::::set_metadata(origin.clone(), owner.clone(), Some(hash))); - }: set_metadata(origin, owner.clone(), None) - verify { - assert_last_event::(crate::Event::MetadataCleared { - owner, - hash, - }.into()); + + #[extrinsic_call] + set_metadata(origin as T::RuntimeOrigin, owner.clone(), None); + + assert_last_event::(crate::Event::MetadataCleared { owner, hash }.into()); + Ok(()) } - set_proposal_metadata { + #[benchmark] + fn set_proposal_metadata() -> Result<(), BenchmarkError> { // Place our proposal at the end to make sure it's worst case. - for i in 0 .. T::MaxProposals::get() { + for i in 0..T::MaxProposals::get() { add_proposal::(i)?; } let owner = MetadataOwner::Proposal(0); let proposer = funded_account::("proposer", 0); let hash = note_preimage::(); - }: set_metadata(RawOrigin::Signed(proposer).into(), owner.clone(), Some(hash)) - verify { - assert_last_event::(crate::Event::MetadataSet { - owner, - hash, - }.into()); + + #[extrinsic_call] + set_metadata(RawOrigin::Signed(proposer), owner.clone(), Some(hash)); + + assert_last_event::(crate::Event::MetadataSet { owner, hash }.into()); + Ok(()) } - clear_proposal_metadata { + #[benchmark] + fn clear_proposal_metadata() -> Result<(), BenchmarkError> { // Place our proposal at the end to make sure it's worst case. - for i in 0 .. T::MaxProposals::get() { + for i in 0..T::MaxProposals::get() { add_proposal::(i)?; } let proposer = funded_account::("proposer", 0); @@ -825,16 +927,18 @@ mod benchmarks { assert_ok!(Democracy::::set_metadata( RawOrigin::Signed(proposer.clone()).into(), owner.clone(), - Some(hash))); - }: set_metadata(RawOrigin::Signed(proposer).into(), owner.clone(), None) - verify { - assert_last_event::(crate::Event::MetadataCleared { - owner, - hash, - }.into()); + Some(hash) + )); + + #[extrinsic_call] + set_metadata::(RawOrigin::Signed(proposer), owner.clone(), None); + + assert_last_event::(crate::Event::MetadataCleared { owner, hash }.into()); + Ok(()) } - set_referendum_metadata { + #[benchmark] + fn set_referendum_metadata() -> Result<(), BenchmarkError> { // create not ongoing referendum. ReferendumInfoOf::::insert( 0, @@ -843,15 +947,16 @@ mod benchmarks { let owner = MetadataOwner::Referendum(0); let caller = funded_account::("caller", 0); let hash = note_preimage::(); - }: set_metadata(RawOrigin::Root.into(), owner.clone(), Some(hash)) - verify { - assert_last_event::(crate::Event::MetadataSet { - owner, - hash, - }.into()); + + #[extrinsic_call] + set_metadata::(RawOrigin::Root, owner.clone(), Some(hash)); + + assert_last_event::(crate::Event::MetadataSet { owner, hash }.into()); + Ok(()) } - clear_referendum_metadata { + #[benchmark] + fn clear_referendum_metadata() -> Result<(), BenchmarkError> { // create not ongoing referendum. ReferendumInfoOf::::insert( 0, @@ -861,17 +966,13 @@ mod benchmarks { let hash = note_preimage::(); MetadataOf::::insert(owner.clone(), hash); let caller = funded_account::("caller", 0); - }: set_metadata(RawOrigin::Signed(caller).into(), owner.clone(), None) - verify { - assert_last_event::(crate::Event::MetadataCleared { - owner, - hash, - }.into()); + + #[extrinsic_call] + set_metadata::(RawOrigin::Signed(caller), owner.clone(), None); + + assert_last_event::(crate::Event::MetadataCleared { owner, hash }.into()); + Ok(()) } -*/ - impl_benchmark_test_suite!( - Democracy, - crate::tests::new_test_ext(), - crate::tests::Test - ); + + impl_benchmark_test_suite!(Democracy, crate::tests::new_test_ext(), crate::tests::Test); } From ab0b870e6385131c4249c14e7eada70296c82c9e Mon Sep 17 00:00:00 2001 From: ndkazu Date: Sun, 17 Nov 2024 21:03:41 +0900 Subject: [PATCH 78/80] prdoc and some formating --- prdoc/pr_6509.prdoc | 15 +++++++++++++++ substrate/frame/democracy/src/benchmarking.rs | 4 ++-- 2 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 prdoc/pr_6509.prdoc diff --git a/prdoc/pr_6509.prdoc b/prdoc/pr_6509.prdoc new file mode 100644 index 000000000000..f3783aa2fcca --- /dev/null +++ b/prdoc/pr_6509.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: Migrate pallet-democracy benchmark to v2 + +doc: + - audience: Runtime Dev + description: |- + Part of: + + - #6202. + +crates: +- name: pallet-democracy + bump: patch diff --git a/substrate/frame/democracy/src/benchmarking.rs b/substrate/frame/democracy/src/benchmarking.rs index bdbc88aca533..95bdb9e2b195 100644 --- a/substrate/frame/democracy/src/benchmarking.rs +++ b/substrate/frame/democracy/src/benchmarking.rs @@ -887,7 +887,7 @@ mod benchmarks { .expect("ExternalOrigin has no successful origin required for the benchmark"); assert_ok!(Democracy::::external_propose(origin.clone(), make_proposal::(0))); let owner = MetadataOwner::External; - let proposer = funded_account::("proposer", 0); + let _proposer = funded_account::("proposer", 0); let hash = note_preimage::(); assert_ok!(Democracy::::set_metadata(origin.clone(), owner.clone(), Some(hash))); @@ -945,7 +945,7 @@ mod benchmarks { ReferendumInfo::Finished { end: BlockNumberFor::::zero(), approved: true }, ); let owner = MetadataOwner::Referendum(0); - let caller = funded_account::("caller", 0); + let _caller = funded_account::("caller", 0); let hash = note_preimage::(); #[extrinsic_call] From dae7a6e5f7a4ea70b0dfa04b2a042a9ee2e8111d Mon Sep 17 00:00:00 2001 From: ndkazu Date: Sun, 17 Nov 2024 21:17:19 +0900 Subject: [PATCH 79/80] prdoc --- prdoc/pr_6509.prdoc | 6 ++---- substrate/frame/democracy/src/benchmarking.rs | 10 ++++------ 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/prdoc/pr_6509.prdoc b/prdoc/pr_6509.prdoc index f3783aa2fcca..74215fe0084c 100644 --- a/prdoc/pr_6509.prdoc +++ b/prdoc/pr_6509.prdoc @@ -5,10 +5,8 @@ title: Migrate pallet-democracy benchmark to v2 doc: - audience: Runtime Dev - description: |- - Part of: - - - #6202. + description: | + "Part of issue #6202." crates: - name: pallet-democracy diff --git a/substrate/frame/democracy/src/benchmarking.rs b/substrate/frame/democracy/src/benchmarking.rs index 95bdb9e2b195..f9c810e56192 100644 --- a/substrate/frame/democracy/src/benchmarking.rs +++ b/substrate/frame/democracy/src/benchmarking.rs @@ -551,9 +551,8 @@ mod benchmarks { for i in 0..r { if let Some(value) = ReferendumInfoOf::::get(i) { match value { - ReferendumInfo::Finished { .. } => { - return Err("Referendum has been finished".into()) - }, + ReferendumInfo::Finished { .. } => + return Err("Referendum has been finished".into()), ReferendumInfo::Ongoing(_) => (), } } @@ -590,9 +589,8 @@ mod benchmarks { for i in 0..r { if let Some(value) = ReferendumInfoOf::::get(i) { match value { - ReferendumInfo::Finished { .. } => { - return Err("Referendum has been finished".into()) - }, + ReferendumInfo::Finished { .. } => + return Err("Referendum has been finished".into()), ReferendumInfo::Ongoing(_) => (), } } From d2916dd6143556b128c1a85912b4d98f2f9d9244 Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Tue, 19 Nov 2024 17:25:15 +0000 Subject: [PATCH 80/80] ".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime=dev --target_dir=substrate --features=runtime-benchmarks --pallet=pallet_democracy --- substrate/frame/democracy/src/weights.rs | 302 +++++++++++------------ 1 file changed, 150 insertions(+), 152 deletions(-) diff --git a/substrate/frame/democracy/src/weights.rs b/substrate/frame/democracy/src/weights.rs index 0a2200a78b5d..765ee57f0eb3 100644 --- a/substrate/frame/democracy/src/weights.rs +++ b/substrate/frame/democracy/src/weights.rs @@ -18,27 +18,25 @@ //! Autogenerated weights for `pallet_democracy` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 -//! DATE: 2024-11-08, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-11-19, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `runner-wiukf8gn-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` //! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: `1024` // Executed Command: -// ./target/production/substrate-node +// target/production/substrate-node // benchmark // pallet -// --chain=dev // --steps=50 // --repeat=20 -// --pallet=pallet_democracy -// --no-storage-info -// --no-median-slopes -// --no-min-squares // --extrinsic=* // --wasm-execution=compiled // --heap-pages=4096 -// --output=./substrate/frame/democracy/src/weights.rs +// --json-file=/builds/parity/mirrors/polkadot-sdk/.git/.artifacts/bench.json +// --pallet=pallet_democracy +// --chain=dev // --header=./substrate/HEADER-APACHE2 +// --output=./substrate/frame/democracy/src/weights.rs // --template=./substrate/.maintain/frame-weight-template.hbs #![cfg_attr(rustfmt, rustfmt_skip)] @@ -96,8 +94,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `4834` // Estimated: `18187` - // Minimum execution time: 48_991_000 picoseconds. - Weight::from_parts(50_476_000, 18187) + // Minimum execution time: 49_681_000 picoseconds. + Weight::from_parts(51_578_000, 18187) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -107,8 +105,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `3589` // Estimated: `6695` - // Minimum execution time: 43_129_000 picoseconds. - Weight::from_parts(45_076_000, 6695) + // Minimum execution time: 45_001_000 picoseconds. + Weight::from_parts(45_990_000, 6695) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -124,8 +122,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `3503` // Estimated: `7260` - // Minimum execution time: 63_761_000 picoseconds. - Weight::from_parts(65_424_000, 7260) + // Minimum execution time: 65_095_000 picoseconds. + Weight::from_parts(67_484_000, 7260) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -141,8 +139,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `3525` // Estimated: `7260` - // Minimum execution time: 66_543_000 picoseconds. - Weight::from_parts(69_537_000, 7260) + // Minimum execution time: 66_877_000 picoseconds. + Weight::from_parts(68_910_000, 7260) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -156,8 +154,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `399` // Estimated: `3666` - // Minimum execution time: 28_934_000 picoseconds. - Weight::from_parts(29_982_000, 3666) + // Minimum execution time: 29_312_000 picoseconds. + Weight::from_parts(30_040_000, 3666) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -179,8 +177,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `5943` // Estimated: `18187` - // Minimum execution time: 108_004_000 picoseconds. - Weight::from_parts(110_779_000, 18187) + // Minimum execution time: 107_932_000 picoseconds. + Weight::from_parts(108_940_000, 18187) .saturating_add(T::DbWeight::get().reads(8_u64)) .saturating_add(T::DbWeight::get().writes(7_u64)) } @@ -192,8 +190,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `3449` // Estimated: `6703` - // Minimum execution time: 17_630_000 picoseconds. - Weight::from_parts(18_419_000, 6703) + // Minimum execution time: 17_703_000 picoseconds. + Weight::from_parts(18_188_000, 6703) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -203,8 +201,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 2_572_000 picoseconds. - Weight::from_parts(2_810_000, 0) + // Minimum execution time: 2_672_000 picoseconds. + Weight::from_parts(2_814_000, 0) .saturating_add(T::DbWeight::get().writes(1_u64)) } /// Storage: `Democracy::NextExternal` (r:0 w:1) @@ -213,8 +211,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 2_628_000 picoseconds. - Weight::from_parts(2_724_000, 0) + // Minimum execution time: 2_584_000 picoseconds. + Weight::from_parts(2_846_000, 0) .saturating_add(T::DbWeight::get().writes(1_u64)) } /// Storage: `Democracy::NextExternal` (r:1 w:1) @@ -229,8 +227,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `319` // Estimated: `3518` - // Minimum execution time: 24_624_000 picoseconds. - Weight::from_parts(25_518_000, 3518) + // Minimum execution time: 24_603_000 picoseconds. + Weight::from_parts(25_407_000, 3518) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(5_u64)) } @@ -244,8 +242,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `3552` // Estimated: `6703` - // Minimum execution time: 31_786_000 picoseconds. - Weight::from_parts(32_786_000, 6703) + // Minimum execution time: 31_721_000 picoseconds. + Weight::from_parts(32_785_000, 6703) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -261,8 +259,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `5854` // Estimated: `18187` - // Minimum execution time: 87_352_000 picoseconds. - Weight::from_parts(89_670_000, 18187) + // Minimum execution time: 86_981_000 picoseconds. + Weight::from_parts(89_140_000, 18187) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(4_u64)) } @@ -274,8 +272,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `304` // Estimated: `3518` - // Minimum execution time: 17_561_000 picoseconds. - Weight::from_parts(18_345_000, 3518) + // Minimum execution time: 17_465_000 picoseconds. + Weight::from_parts(18_018_000, 3518) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -290,10 +288,10 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `277 + r * (86 ±0)` // Estimated: `1489 + r * (2676 ±0)` - // Minimum execution time: 6_801_000 picoseconds. - Weight::from_parts(8_524_132, 1489) - // Standard Error: 10_028 - .saturating_add(Weight::from_parts(4_073_619, 0).saturating_mul(r.into())) + // Minimum execution time: 6_746_000 picoseconds. + Weight::from_parts(7_381_932, 1489) + // Standard Error: 10_311 + .saturating_add(Weight::from_parts(4_107_935, 0).saturating_mul(r.into())) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(r.into()))) .saturating_add(T::DbWeight::get().writes(1_u64)) @@ -316,10 +314,10 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `277 + r * (86 ±0)` // Estimated: `18187 + r * (2676 ±0)` - // Minimum execution time: 10_160_000 picoseconds. - Weight::from_parts(11_472_067, 18187) - // Standard Error: 10_730 - .saturating_add(Weight::from_parts(4_104_654, 0).saturating_mul(r.into())) + // Minimum execution time: 9_766_000 picoseconds. + Weight::from_parts(9_788_895, 18187) + // Standard Error: 11_913 + .saturating_add(Weight::from_parts(4_130_441, 0).saturating_mul(r.into())) .saturating_add(T::DbWeight::get().reads(5_u64)) .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(r.into()))) .saturating_add(T::DbWeight::get().writes(1_u64)) @@ -338,10 +336,10 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `863 + r * (108 ±0)` // Estimated: `19800 + r * (2676 ±0)` - // Minimum execution time: 49_741_000 picoseconds. - Weight::from_parts(53_544_421, 19800) - // Standard Error: 11_984 - .saturating_add(Weight::from_parts(5_123_946, 0).saturating_mul(r.into())) + // Minimum execution time: 48_992_000 picoseconds. + Weight::from_parts(55_524_560, 19800) + // Standard Error: 11_278 + .saturating_add(Weight::from_parts(4_987_109, 0).saturating_mul(r.into())) .saturating_add(T::DbWeight::get().reads(5_u64)) .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(r.into()))) .saturating_add(T::DbWeight::get().writes(4_u64)) @@ -357,10 +355,10 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `526 + r * (108 ±0)` // Estimated: `13530 + r * (2676 ±0)` - // Minimum execution time: 24_977_000 picoseconds. - Weight::from_parts(22_449_729, 13530) - // Standard Error: 10_846 - .saturating_add(Weight::from_parts(5_058_209, 0).saturating_mul(r.into())) + // Minimum execution time: 23_828_000 picoseconds. + Weight::from_parts(23_638_577, 13530) + // Standard Error: 10_946 + .saturating_add(Weight::from_parts(4_971_245, 0).saturating_mul(r.into())) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(r.into()))) .saturating_add(T::DbWeight::get().writes(2_u64)) @@ -373,8 +371,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 2_700_000 picoseconds. - Weight::from_parts(3_028_000, 0) + // Minimum execution time: 2_759_000 picoseconds. + Weight::from_parts(2_850_000, 0) .saturating_add(T::DbWeight::get().writes(1_u64)) } /// Storage: `Democracy::VotingOf` (r:1 w:1) @@ -390,10 +388,10 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `596` // Estimated: `7260` - // Minimum execution time: 31_183_000 picoseconds. - Weight::from_parts(43_105_470, 7260) - // Standard Error: 3_096 - .saturating_add(Weight::from_parts(98_571, 0).saturating_mul(r.into())) + // Minimum execution time: 30_804_000 picoseconds. + Weight::from_parts(42_750_018, 7260) + // Standard Error: 3_300 + .saturating_add(Weight::from_parts(99_997, 0).saturating_mul(r.into())) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -410,10 +408,10 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `597 + r * (22 ±0)` // Estimated: `7260` - // Minimum execution time: 39_672_000 picoseconds. - Weight::from_parts(44_120_387, 7260) - // Standard Error: 1_890 - .saturating_add(Weight::from_parts(130_089, 0).saturating_mul(r.into())) + // Minimum execution time: 39_946_000 picoseconds. + Weight::from_parts(44_500_306, 7260) + // Standard Error: 1_914 + .saturating_add(Weight::from_parts(116_987, 0).saturating_mul(r.into())) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -426,10 +424,10 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `761 + r * (26 ±0)` // Estimated: `7260` - // Minimum execution time: 21_396_000 picoseconds. - Weight::from_parts(26_151_983, 7260) - // Standard Error: 2_052 - .saturating_add(Weight::from_parts(131_709, 0).saturating_mul(r.into())) + // Minimum execution time: 21_677_000 picoseconds. + Weight::from_parts(25_329_290, 7260) + // Standard Error: 1_998 + .saturating_add(Weight::from_parts(157_800, 0).saturating_mul(r.into())) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -442,10 +440,10 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `761 + r * (26 ±0)` // Estimated: `7260` - // Minimum execution time: 21_425_000 picoseconds. - Weight::from_parts(26_335_367, 7260) - // Standard Error: 2_170 - .saturating_add(Weight::from_parts(130_502, 0).saturating_mul(r.into())) + // Minimum execution time: 21_777_000 picoseconds. + Weight::from_parts(26_635_600, 7260) + // Standard Error: 2_697 + .saturating_add(Weight::from_parts(135_641, 0).saturating_mul(r.into())) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -461,8 +459,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `351` // Estimated: `3556` - // Minimum execution time: 19_765_000 picoseconds. - Weight::from_parts(20_266_000, 3556) + // Minimum execution time: 19_914_000 picoseconds. + Weight::from_parts(20_450_000, 3556) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -474,8 +472,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `319` // Estimated: `3518` - // Minimum execution time: 16_560_000 picoseconds. - Weight::from_parts(17_277_000, 3518) + // Minimum execution time: 16_212_000 picoseconds. + Weight::from_parts(16_745_000, 3518) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -491,8 +489,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `4883` // Estimated: `18187` - // Minimum execution time: 47_711_000 picoseconds. - Weight::from_parts(48_669_000, 18187) + // Minimum execution time: 47_225_000 picoseconds. + Weight::from_parts(47_976_000, 18187) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -504,8 +502,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `4855` // Estimated: `18187` - // Minimum execution time: 43_809_000 picoseconds. - Weight::from_parts(45_698_000, 18187) + // Minimum execution time: 43_140_000 picoseconds. + Weight::from_parts(43_924_000, 18187) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -519,8 +517,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `106` // Estimated: `3556` - // Minimum execution time: 14_736_000 picoseconds. - Weight::from_parts(15_191_000, 3556) + // Minimum execution time: 14_614_000 picoseconds. + Weight::from_parts(15_376_000, 3556) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -532,8 +530,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `335` // Estimated: `3666` - // Minimum execution time: 22_803_000 picoseconds. - Weight::from_parts(23_732_000, 3666) + // Minimum execution time: 22_588_000 picoseconds. + Weight::from_parts(23_267_000, 3666) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -553,8 +551,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `4834` // Estimated: `18187` - // Minimum execution time: 48_991_000 picoseconds. - Weight::from_parts(50_476_000, 18187) + // Minimum execution time: 49_681_000 picoseconds. + Weight::from_parts(51_578_000, 18187) .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } @@ -564,8 +562,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `3589` // Estimated: `6695` - // Minimum execution time: 43_129_000 picoseconds. - Weight::from_parts(45_076_000, 6695) + // Minimum execution time: 45_001_000 picoseconds. + Weight::from_parts(45_990_000, 6695) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -581,8 +579,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `3503` // Estimated: `7260` - // Minimum execution time: 63_761_000 picoseconds. - Weight::from_parts(65_424_000, 7260) + // Minimum execution time: 65_095_000 picoseconds. + Weight::from_parts(67_484_000, 7260) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } @@ -598,8 +596,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `3525` // Estimated: `7260` - // Minimum execution time: 66_543_000 picoseconds. - Weight::from_parts(69_537_000, 7260) + // Minimum execution time: 66_877_000 picoseconds. + Weight::from_parts(68_910_000, 7260) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } @@ -613,8 +611,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `399` // Estimated: `3666` - // Minimum execution time: 28_934_000 picoseconds. - Weight::from_parts(29_982_000, 3666) + // Minimum execution time: 29_312_000 picoseconds. + Weight::from_parts(30_040_000, 3666) .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } @@ -636,8 +634,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `5943` // Estimated: `18187` - // Minimum execution time: 108_004_000 picoseconds. - Weight::from_parts(110_779_000, 18187) + // Minimum execution time: 107_932_000 picoseconds. + Weight::from_parts(108_940_000, 18187) .saturating_add(RocksDbWeight::get().reads(8_u64)) .saturating_add(RocksDbWeight::get().writes(7_u64)) } @@ -649,8 +647,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `3449` // Estimated: `6703` - // Minimum execution time: 17_630_000 picoseconds. - Weight::from_parts(18_419_000, 6703) + // Minimum execution time: 17_703_000 picoseconds. + Weight::from_parts(18_188_000, 6703) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -660,8 +658,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 2_572_000 picoseconds. - Weight::from_parts(2_810_000, 0) + // Minimum execution time: 2_672_000 picoseconds. + Weight::from_parts(2_814_000, 0) .saturating_add(RocksDbWeight::get().writes(1_u64)) } /// Storage: `Democracy::NextExternal` (r:0 w:1) @@ -670,8 +668,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 2_628_000 picoseconds. - Weight::from_parts(2_724_000, 0) + // Minimum execution time: 2_584_000 picoseconds. + Weight::from_parts(2_846_000, 0) .saturating_add(RocksDbWeight::get().writes(1_u64)) } /// Storage: `Democracy::NextExternal` (r:1 w:1) @@ -686,8 +684,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `319` // Estimated: `3518` - // Minimum execution time: 24_624_000 picoseconds. - Weight::from_parts(25_518_000, 3518) + // Minimum execution time: 24_603_000 picoseconds. + Weight::from_parts(25_407_000, 3518) .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(5_u64)) } @@ -701,8 +699,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `3552` // Estimated: `6703` - // Minimum execution time: 31_786_000 picoseconds. - Weight::from_parts(32_786_000, 6703) + // Minimum execution time: 31_721_000 picoseconds. + Weight::from_parts(32_785_000, 6703) .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } @@ -718,8 +716,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `5854` // Estimated: `18187` - // Minimum execution time: 87_352_000 picoseconds. - Weight::from_parts(89_670_000, 18187) + // Minimum execution time: 86_981_000 picoseconds. + Weight::from_parts(89_140_000, 18187) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(4_u64)) } @@ -731,8 +729,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `304` // Estimated: `3518` - // Minimum execution time: 17_561_000 picoseconds. - Weight::from_parts(18_345_000, 3518) + // Minimum execution time: 17_465_000 picoseconds. + Weight::from_parts(18_018_000, 3518) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } @@ -747,10 +745,10 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `277 + r * (86 ±0)` // Estimated: `1489 + r * (2676 ±0)` - // Minimum execution time: 6_801_000 picoseconds. - Weight::from_parts(8_524_132, 1489) - // Standard Error: 10_028 - .saturating_add(Weight::from_parts(4_073_619, 0).saturating_mul(r.into())) + // Minimum execution time: 6_746_000 picoseconds. + Weight::from_parts(7_381_932, 1489) + // Standard Error: 10_311 + .saturating_add(Weight::from_parts(4_107_935, 0).saturating_mul(r.into())) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(r.into()))) .saturating_add(RocksDbWeight::get().writes(1_u64)) @@ -773,10 +771,10 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `277 + r * (86 ±0)` // Estimated: `18187 + r * (2676 ±0)` - // Minimum execution time: 10_160_000 picoseconds. - Weight::from_parts(11_472_067, 18187) - // Standard Error: 10_730 - .saturating_add(Weight::from_parts(4_104_654, 0).saturating_mul(r.into())) + // Minimum execution time: 9_766_000 picoseconds. + Weight::from_parts(9_788_895, 18187) + // Standard Error: 11_913 + .saturating_add(Weight::from_parts(4_130_441, 0).saturating_mul(r.into())) .saturating_add(RocksDbWeight::get().reads(5_u64)) .saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(r.into()))) .saturating_add(RocksDbWeight::get().writes(1_u64)) @@ -795,10 +793,10 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `863 + r * (108 ±0)` // Estimated: `19800 + r * (2676 ±0)` - // Minimum execution time: 49_741_000 picoseconds. - Weight::from_parts(53_544_421, 19800) - // Standard Error: 11_984 - .saturating_add(Weight::from_parts(5_123_946, 0).saturating_mul(r.into())) + // Minimum execution time: 48_992_000 picoseconds. + Weight::from_parts(55_524_560, 19800) + // Standard Error: 11_278 + .saturating_add(Weight::from_parts(4_987_109, 0).saturating_mul(r.into())) .saturating_add(RocksDbWeight::get().reads(5_u64)) .saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(r.into()))) .saturating_add(RocksDbWeight::get().writes(4_u64)) @@ -814,10 +812,10 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `526 + r * (108 ±0)` // Estimated: `13530 + r * (2676 ±0)` - // Minimum execution time: 24_977_000 picoseconds. - Weight::from_parts(22_449_729, 13530) - // Standard Error: 10_846 - .saturating_add(Weight::from_parts(5_058_209, 0).saturating_mul(r.into())) + // Minimum execution time: 23_828_000 picoseconds. + Weight::from_parts(23_638_577, 13530) + // Standard Error: 10_946 + .saturating_add(Weight::from_parts(4_971_245, 0).saturating_mul(r.into())) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(r.into()))) .saturating_add(RocksDbWeight::get().writes(2_u64)) @@ -830,8 +828,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 2_700_000 picoseconds. - Weight::from_parts(3_028_000, 0) + // Minimum execution time: 2_759_000 picoseconds. + Weight::from_parts(2_850_000, 0) .saturating_add(RocksDbWeight::get().writes(1_u64)) } /// Storage: `Democracy::VotingOf` (r:1 w:1) @@ -847,10 +845,10 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `596` // Estimated: `7260` - // Minimum execution time: 31_183_000 picoseconds. - Weight::from_parts(43_105_470, 7260) - // Standard Error: 3_096 - .saturating_add(Weight::from_parts(98_571, 0).saturating_mul(r.into())) + // Minimum execution time: 30_804_000 picoseconds. + Weight::from_parts(42_750_018, 7260) + // Standard Error: 3_300 + .saturating_add(Weight::from_parts(99_997, 0).saturating_mul(r.into())) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } @@ -867,10 +865,10 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `597 + r * (22 ±0)` // Estimated: `7260` - // Minimum execution time: 39_672_000 picoseconds. - Weight::from_parts(44_120_387, 7260) - // Standard Error: 1_890 - .saturating_add(Weight::from_parts(130_089, 0).saturating_mul(r.into())) + // Minimum execution time: 39_946_000 picoseconds. + Weight::from_parts(44_500_306, 7260) + // Standard Error: 1_914 + .saturating_add(Weight::from_parts(116_987, 0).saturating_mul(r.into())) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } @@ -883,10 +881,10 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `761 + r * (26 ±0)` // Estimated: `7260` - // Minimum execution time: 21_396_000 picoseconds. - Weight::from_parts(26_151_983, 7260) - // Standard Error: 2_052 - .saturating_add(Weight::from_parts(131_709, 0).saturating_mul(r.into())) + // Minimum execution time: 21_677_000 picoseconds. + Weight::from_parts(25_329_290, 7260) + // Standard Error: 1_998 + .saturating_add(Weight::from_parts(157_800, 0).saturating_mul(r.into())) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } @@ -899,10 +897,10 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `761 + r * (26 ±0)` // Estimated: `7260` - // Minimum execution time: 21_425_000 picoseconds. - Weight::from_parts(26_335_367, 7260) - // Standard Error: 2_170 - .saturating_add(Weight::from_parts(130_502, 0).saturating_mul(r.into())) + // Minimum execution time: 21_777_000 picoseconds. + Weight::from_parts(26_635_600, 7260) + // Standard Error: 2_697 + .saturating_add(Weight::from_parts(135_641, 0).saturating_mul(r.into())) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } @@ -918,8 +916,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `351` // Estimated: `3556` - // Minimum execution time: 19_765_000 picoseconds. - Weight::from_parts(20_266_000, 3556) + // Minimum execution time: 19_914_000 picoseconds. + Weight::from_parts(20_450_000, 3556) .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -931,8 +929,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `319` // Estimated: `3518` - // Minimum execution time: 16_560_000 picoseconds. - Weight::from_parts(17_277_000, 3518) + // Minimum execution time: 16_212_000 picoseconds. + Weight::from_parts(16_745_000, 3518) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -948,8 +946,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `4883` // Estimated: `18187` - // Minimum execution time: 47_711_000 picoseconds. - Weight::from_parts(48_669_000, 18187) + // Minimum execution time: 47_225_000 picoseconds. + Weight::from_parts(47_976_000, 18187) .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -961,8 +959,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `4855` // Estimated: `18187` - // Minimum execution time: 43_809_000 picoseconds. - Weight::from_parts(45_698_000, 18187) + // Minimum execution time: 43_140_000 picoseconds. + Weight::from_parts(43_924_000, 18187) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -976,8 +974,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `106` // Estimated: `3556` - // Minimum execution time: 14_736_000 picoseconds. - Weight::from_parts(15_191_000, 3556) + // Minimum execution time: 14_614_000 picoseconds. + Weight::from_parts(15_376_000, 3556) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -989,8 +987,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `335` // Estimated: `3666` - // Minimum execution time: 22_803_000 picoseconds. - Weight::from_parts(23_732_000, 3666) + // Minimum execution time: 22_588_000 picoseconds. + Weight::from_parts(23_267_000, 3666) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) }