diff --git a/Cargo.lock b/Cargo.lock index 529fbfc17315f..a0db7d4b34a24 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7125,16 +7125,6 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb5d2a036dc6d2d8fd16fde3498b04306e29bd193bf306a57427019b823d5acd" -[[package]] -name = "ruzstd" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d425143485a37727c7a46e689bbe3b883a00f42b4a52c4ac0f44855c1009b00" -dependencies = [ - "byteorder", - "twox-hash", -] - [[package]] name = "rw-stream-sink" version = "0.2.1" @@ -9137,7 +9127,6 @@ dependencies = [ name = "sp-maybe-compressed-blob" version = "4.0.0-dev" dependencies = [ - "ruzstd", "zstd", ] diff --git a/client/cli/Cargo.toml b/client/cli/Cargo.toml index 7798507e529f4..c3564e3e3a18d 100644 --- a/client/cli/Cargo.toml +++ b/client/cli/Cargo.toml @@ -43,8 +43,6 @@ sc-tracing = { version = "4.0.0-dev", path = "../tracing" } chrono = "0.4.10" serde = "1.0.126" thiserror = "1.0.21" - -[target.'cfg(not(target_os = "unknown"))'.dependencies] rpassword = "5.0.0" [dev-dependencies] diff --git a/client/cli/src/params/keystore_params.rs b/client/cli/src/params/keystore_params.rs index 99da21a12f768..951f61bd1bc5f 100644 --- a/client/cli/src/params/keystore_params.rs +++ b/client/cli/src/params/keystore_params.rs @@ -76,13 +76,7 @@ impl KeystoreParams { /// Returns a vector of remote-urls and the local Keystore configuration pub fn keystore_config(&self, config_dir: &Path) -> Result<(Option, KeystoreConfig)> { let password = if self.password_interactive { - #[cfg(not(target_os = "unknown"))] - { - let password = input_keystore_password()?; - Some(SecretString::new(password)) - } - #[cfg(target_os = "unknown")] - None + Some(SecretString::new(input_keystore_password()?)) } else if let Some(ref file) = self.password_filename { let password = fs::read_to_string(file).map_err(|e| format!("{}", e))?; Some(SecretString::new(password)) @@ -113,7 +107,6 @@ impl KeystoreParams { } } -#[cfg(not(target_os = "unknown"))] fn input_keystore_password() -> Result { rpassword::read_password_from_tty(Some("Keystore password: ")) .map_err(|e| format!("{:?}", e).into()) diff --git a/client/db/src/light.rs b/client/db/src/light.rs index d56188b70fcba..bf2da5c61d058 100644 --- a/client/db/src/light.rs +++ b/client/db/src/light.rs @@ -65,8 +65,6 @@ pub struct LightStorage { meta: RwLock, Block::Hash>>, cache: Arc>, header_metadata_cache: Arc>, - - #[cfg(not(target_os = "unknown"))] io_stats: FrozenForDuration, } @@ -102,7 +100,6 @@ impl LightStorage { meta: RwLock::new(meta), cache: Arc::new(DbCacheSync(RwLock::new(cache))), header_metadata_cache, - #[cfg(not(target_os = "unknown"))] io_stats: FrozenForDuration::new(std::time::Duration::from_secs(1)), }) } @@ -589,7 +586,6 @@ where Some(self.cache.clone()) } - #[cfg(not(target_os = "unknown"))] fn usage_info(&self) -> Option { use sc_client_api::{IoInfo, MemoryInfo, MemorySize}; @@ -619,11 +615,6 @@ where }, }) } - - #[cfg(target_os = "unknown")] - fn usage_info(&self) -> Option { - None - } } impl ProvideChtRoots for LightStorage diff --git a/client/executor/src/wasm_runtime.rs b/client/executor/src/wasm_runtime.rs index 892c3681c7ce4..b11e3958dbc81 100644 --- a/client/executor/src/wasm_runtime.rs +++ b/client/executor/src/wasm_runtime.rs @@ -237,7 +237,6 @@ impl RuntimeCache { None => { let code = runtime_code.fetch_runtime_code().ok_or(WasmError::CodeNotFound)?; - #[cfg(not(target_os = "unknown"))] let time = std::time::Instant::now(); let result = create_versioned_wasm_runtime( @@ -254,7 +253,6 @@ impl RuntimeCache { match result { Ok(ref result) => { - #[cfg(not(target_os = "unknown"))] log::debug!( target: "wasm-runtime", "Prepared new runtime version {:?} in {} ms.", diff --git a/client/informant/src/lib.rs b/client/informant/src/lib.rs index 4f6aa2b7a3fef..f421dbbb7e564 100644 --- a/client/informant/src/lib.rs +++ b/client/informant/src/lib.rs @@ -52,31 +52,16 @@ impl Default for OutputFormat { } } -/// Marker trait for a type that implements `TransactionPool` and `MallocSizeOf` on `not(target_os = -/// "unknown")`. -#[cfg(target_os = "unknown")] -pub trait TransactionPoolAndMaybeMallogSizeOf: TransactionPool {} - -/// Marker trait for a type that implements `TransactionPool` and `MallocSizeOf` on `not(target_os = -/// "unknown")`. -#[cfg(not(target_os = "unknown"))] -pub trait TransactionPoolAndMaybeMallogSizeOf: TransactionPool + MallocSizeOf {} - -#[cfg(target_os = "unknown")] -impl TransactionPoolAndMaybeMallogSizeOf for T {} - -#[cfg(not(target_os = "unknown"))] -impl TransactionPoolAndMaybeMallogSizeOf for T {} - /// Builds the informant and returns a `Future` that drives the informant. -pub async fn build( +pub async fn build( client: Arc, network: Arc::Hash>>, - pool: Arc, + pool: Arc

, format: OutputFormat, ) where C: UsageProvider + HeaderMetadata + BlockchainEvents, >::Error: Display, + P: TransactionPool + MallocSizeOf, { let mut display = display::InformantDisplay::new(format.clone()); @@ -97,7 +82,6 @@ pub async fn build( "Usage statistics not displayed as backend does not provide it", ) } - #[cfg(not(target_os = "unknown"))] trace!( target: "usage", "Subsystems memory [txpool: {} kB]", diff --git a/client/network/Cargo.toml b/client/network/Cargo.toml index de62a534f8662..196bd419aaae9 100644 --- a/client/network/Cargo.toml +++ b/client/network/Cargo.toml @@ -64,26 +64,7 @@ unsigned-varint = { version = "0.6.0", features = [ ] } void = "1.0.2" zeroize = "1.2.0" - -[dependencies.libp2p] -version = "0.39.1" - -[target.'cfg(target_os = "unknown")'.dependencies.libp2p] -version = "0.39.1" -default-features = false -features = [ - "identify", - "kad", - "mdns", - "mplex", - "noise", - "ping", - "request-response", - "tcp-async-io", - "websocket", - "yamux", -] - +libp2p = "0.39.1" [dev-dependencies] assert_matches = "1.3" diff --git a/client/network/src/discovery.rs b/client/network/src/discovery.rs index f8edd0203342d..3be00a52e98b7 100644 --- a/client/network/src/discovery.rs +++ b/client/network/src/discovery.rs @@ -50,8 +50,6 @@ use crate::{config::ProtocolId, utils::LruHashSet}; use futures::prelude::*; use futures_timer::Delay; use ip_network::IpNetwork; -#[cfg(not(target_os = "unknown"))] -use libp2p::mdns::{Mdns, MdnsConfig, MdnsEvent}; use libp2p::{ core::{ connection::{ConnectionId, ListenerId}, @@ -66,6 +64,7 @@ use libp2p::{ GetClosestPeersError, Kademlia, KademliaBucketInserts, KademliaConfig, KademliaEvent, QueryId, QueryResult, Quorum, Record, }, + mdns::{Mdns, MdnsConfig, MdnsEvent}, multiaddr::Protocol, swarm::{ protocols_handler::multi::IntoMultiHandler, IntoProtocolsHandler, NetworkBehaviour, @@ -156,9 +155,6 @@ impl DiscoveryConfig { /// Should MDNS discovery be supported? pub fn with_mdns(&mut self, value: bool) -> &mut Self { - if value && cfg!(target_os = "unknown") { - log::warn!(target: "sub-libp2p", "mDNS is not available on this platform") - } self.enable_mdns = value; self } @@ -234,7 +230,6 @@ impl DiscoveryConfig { num_connections: 0, allow_private_ipv4, discovery_only_if_under_num, - #[cfg(not(target_os = "unknown"))] mdns: if enable_mdns { MdnsWrapper::Instantiating(Mdns::new(MdnsConfig::default()).boxed()) } else { @@ -257,7 +252,6 @@ pub struct DiscoveryBehaviour { /// Kademlia requests and answers. kademlias: HashMap>, /// Discovers nodes on the local network. - #[cfg(not(target_os = "unknown"))] mdns: MdnsWrapper, /// Stream that fires when we need to perform the next random Kademlia query. `None` if /// random walking is disabled. @@ -505,7 +499,6 @@ impl NetworkBehaviour for DiscoveryBehaviour { list_to_filter.extend(k.addresses_of_peer(peer_id)) } - #[cfg(not(target_os = "unknown"))] list_to_filter.extend(self.mdns.addresses_of_peer(peer_id)); if !self.allow_private_ipv4 { @@ -840,7 +833,6 @@ impl NetworkBehaviour for DiscoveryBehaviour { } // Poll mDNS. - #[cfg(not(target_os = "unknown"))] while let Poll::Ready(ev) = self.mdns.poll(cx, params) { match ev { NetworkBehaviourAction::GenerateEvent(event) => match event { @@ -890,14 +882,12 @@ fn protocol_name_from_protocol_id(id: &ProtocolId) -> Vec { /// [`Mdns::new`] returns a future. Instead of forcing [`DiscoveryConfig::finish`] and all its /// callers to be async, lazily instantiate [`Mdns`]. -#[cfg(not(target_os = "unknown"))] enum MdnsWrapper { Instantiating(futures::future::BoxFuture<'static, std::io::Result>), Ready(Mdns), Disabled, } -#[cfg(not(target_os = "unknown"))] impl MdnsWrapper { fn addresses_of_peer(&mut self, peer_id: &PeerId) -> Vec { match self { diff --git a/client/network/src/transport.rs b/client/network/src/transport.rs index 47382fa3b1353..04223c6d6846f 100644 --- a/client/network/src/transport.rs +++ b/client/network/src/transport.rs @@ -25,10 +25,8 @@ use libp2p::{ transport::{Boxed, OptionalTransport}, upgrade, }, - identity, mplex, noise, PeerId, Transport, + dns, identity, mplex, noise, tcp, websocket, PeerId, Transport, }; -#[cfg(not(target_os = "unknown"))] -use libp2p::{dns, tcp, websocket}; use std::{sync::Arc, time::Duration}; pub use self::bandwidth::BandwidthSinks; diff --git a/client/offchain/Cargo.toml b/client/offchain/Cargo.toml index a7ff572e9b0b7..641a1e55063d0 100644 --- a/client/offchain/Cargo.toml +++ b/client/offchain/Cargo.toml @@ -31,8 +31,6 @@ sp-offchain = { version = "4.0.0-dev", path = "../../primitives/offchain" } sp-runtime = { version = "4.0.0-dev", path = "../../primitives/runtime" } sc-utils = { version = "4.0.0-dev", path = "../utils" } threadpool = "1.7" - -[target.'cfg(not(target_os = "unknown"))'.dependencies] hyper = "0.14.11" hyper-rustls = "0.22.1" diff --git a/client/offchain/src/api.rs b/client/offchain/src/api.rs index 46ba1a0f3cbc6..b2276a852372f 100644 --- a/client/offchain/src/api.rs +++ b/client/offchain/src/api.rs @@ -32,14 +32,8 @@ use sp_core::{ }; pub use sp_offchain::STORAGE_PREFIX; -#[cfg(not(target_os = "unknown"))] mod http; -#[cfg(target_os = "unknown")] -use http_dummy as http; -#[cfg(target_os = "unknown")] -mod http_dummy; - mod timestamp; fn unavailable_yet(name: &str) -> R { diff --git a/client/offchain/src/api/http_dummy.rs b/client/offchain/src/api/http_dummy.rs deleted file mode 100644 index 73d30396ab1cb..0000000000000 --- a/client/offchain/src/api/http_dummy.rs +++ /dev/null @@ -1,124 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) 2019-2021 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 . - -//! Contains the same API as the `http` module, except that everything returns an error. - -use sp_core::offchain::{HttpError, HttpRequestId, HttpRequestStatus, Timestamp}; -use std::{ - future::Future, - pin::Pin, - task::{Context, Poll}, -}; - -/// Wrapper struct (wrapping nothing in case of http_dummy) used for keeping the hyper_rustls client -/// running. -#[derive(Clone)] -pub struct SharedClient; - -impl SharedClient { - pub fn new() -> Self { - Self - } -} - -/// Creates a pair of [`HttpApi`] and [`HttpWorker`]. -pub fn http(_: SharedClient) -> (HttpApi, HttpWorker) { - (HttpApi, HttpWorker) -} - -/// Dummy implementation of HTTP capabilities. -#[derive(Debug)] -pub struct HttpApi; - -/// Dummy implementation of HTTP capabilities. -#[derive(Debug)] -pub struct HttpWorker; - -impl HttpApi { - /// Mimics the corresponding method in the offchain API. - pub fn request_start(&mut self, _: &str, _: &str) -> Result { - /// Because this always returns an error, none of the other methods should ever be called. - Err(()) - } - - /// Mimics the corresponding method in the offchain API. - pub fn request_add_header(&mut self, _: HttpRequestId, _: &str, _: &str) -> Result<(), ()> { - unreachable!( - "Creating a request always fails, thus this function will \ - never be called; qed" - ) - } - - /// Mimics the corresponding method in the offchain API. - pub fn request_write_body( - &mut self, - _: HttpRequestId, - _: &[u8], - _: Option, - ) -> Result<(), HttpError> { - unreachable!( - "Creating a request always fails, thus this function will \ - never be called; qed" - ) - } - - /// Mimics the corresponding method in the offchain API. - pub fn response_wait( - &mut self, - requests: &[HttpRequestId], - _: Option, - ) -> Vec { - if requests.is_empty() { - Vec::new() - } else { - unreachable!( - "Creating a request always fails, thus the list of requests should \ - always be empty; qed" - ) - } - } - - /// Mimics the corresponding method in the offchain API. - pub fn response_headers(&mut self, _: HttpRequestId) -> Vec<(Vec, Vec)> { - unreachable!( - "Creating a request always fails, thus this function will \ - never be called; qed" - ) - } - - /// Mimics the corresponding method in the offchain API. - pub fn response_read_body( - &mut self, - _: HttpRequestId, - _: &mut [u8], - _: Option, - ) -> Result { - unreachable!( - "Creating a request always fails, thus this function will \ - never be called; qed" - ) - } -} - -impl Future for HttpWorker { - type Output = (); - - fn poll(self: Pin<&mut Self>, _: &mut Context) -> Poll { - Poll::Ready(()) - } -} diff --git a/client/rpc-servers/Cargo.toml b/client/rpc-servers/Cargo.toml index ebb8c620193f2..fede65fa7a054 100644 --- a/client/rpc-servers/Cargo.toml +++ b/client/rpc-servers/Cargo.toml @@ -19,8 +19,6 @@ pubsub = { package = "jsonrpc-pubsub", version = "18.0.0" } log = "0.4.8" prometheus-endpoint = { package = "substrate-prometheus-endpoint", path = "../../utils/prometheus", version = "0.9.0"} serde_json = "1.0.41" - -[target.'cfg(not(target_os = "unknown"))'.dependencies] http = { package = "jsonrpc-http-server", version = "18.0.0" } ipc = { package = "jsonrpc-ipc-server", version = "18.0.0" } ws = { package = "jsonrpc-ws-server", version = "18.0.0" } diff --git a/client/rpc-servers/src/lib.rs b/client/rpc-servers/src/lib.rs index 6e09a0ea36ac0..d60e561ed7751 100644 --- a/client/rpc-servers/src/lib.rs +++ b/client/rpc-servers/src/lib.rs @@ -42,7 +42,6 @@ const HTTP_THREADS: usize = 4; /// The RPC IoHandler containing all requested APIs. pub type RpcHandler = pubsub::PubSubHandler; -pub use self::inner::*; pub use middleware::{method_names, RpcMetrics, RpcMiddleware}; /// Construct rpc `IoHandler` @@ -111,122 +110,106 @@ impl ServerMetrics { } } -#[cfg(not(target_os = "unknown"))] -mod inner { - use super::*; +/// Type alias for ipc server +pub type IpcServer = ipc::Server; +/// Type alias for http server +pub type HttpServer = http::Server; +/// Type alias for ws server +pub type WsServer = ws::Server; - /// Type alias for ipc server - pub type IpcServer = ipc::Server; - /// Type alias for http server - pub type HttpServer = http::Server; - /// Type alias for ws server - pub type WsServer = ws::Server; - - impl ws::SessionStats for ServerMetrics { - fn open_session(&self, _id: ws::SessionId) { - self.session_opened.as_ref().map(|m| m.inc()); - } - - fn close_session(&self, _id: ws::SessionId) { - self.session_closed.as_ref().map(|m| m.inc()); - } +impl ws::SessionStats for ServerMetrics { + fn open_session(&self, _id: ws::SessionId) { + self.session_opened.as_ref().map(|m| m.inc()); } - /// Start HTTP server listening on given address. - /// - /// **Note**: Only available if `not(target_os = "unknown")`. - pub fn start_http( - addr: &std::net::SocketAddr, - thread_pool_size: Option, - cors: Option<&Vec>, - io: RpcHandler, - maybe_max_payload_mb: Option, - ) -> io::Result { - let max_request_body_size = maybe_max_payload_mb - .map(|mb| mb.saturating_mul(MEGABYTE)) - .unwrap_or(RPC_MAX_PAYLOAD_DEFAULT); - - http::ServerBuilder::new(io) - .threads(thread_pool_size.unwrap_or(HTTP_THREADS)) - .health_api(("/health", "system_health")) - .allowed_hosts(hosts_filtering(cors.is_some())) - .rest_api(if cors.is_some() { http::RestApi::Secure } else { http::RestApi::Unsecure }) - .cors(map_cors::(cors)) - .max_request_body_size(max_request_body_size) - .start_http(addr) - } - - /// Start IPC server listening on given path. - /// - /// **Note**: Only available if `not(target_os = "unknown")`. - pub fn start_ipc( - addr: &str, - io: RpcHandler, - server_metrics: ServerMetrics, - ) -> io::Result { - let builder = ipc::ServerBuilder::new(io); - #[cfg(target_os = "unix")] - builder.set_security_attributes({ - let security_attributes = ipc::SecurityAttributes::empty(); - security_attributes.set_mode(0o600)?; - security_attributes - }); - builder.session_stats(server_metrics).start(addr) + fn close_session(&self, _id: ws::SessionId) { + self.session_closed.as_ref().map(|m| m.inc()); } +} - /// Start WS server listening on given address. - /// - /// **Note**: Only available if `not(target_os = "unknown")`. - pub fn start_ws< - M: pubsub::PubSubMetadata + From>, - >( - addr: &std::net::SocketAddr, - max_connections: Option, - cors: Option<&Vec>, - io: RpcHandler, - maybe_max_payload_mb: Option, - server_metrics: ServerMetrics, - ) -> io::Result { - let rpc_max_payload = maybe_max_payload_mb - .map(|mb| mb.saturating_mul(MEGABYTE)) - .unwrap_or(RPC_MAX_PAYLOAD_DEFAULT); - ws::ServerBuilder::with_meta_extractor(io, |context: &ws::RequestContext| { - context.sender().into() - }) - .max_payload(rpc_max_payload) - .max_connections(max_connections.unwrap_or(WS_MAX_CONNECTIONS)) - .allowed_origins(map_cors(cors)) +/// Start HTTP server listening on given address. +pub fn start_http( + addr: &std::net::SocketAddr, + thread_pool_size: Option, + cors: Option<&Vec>, + io: RpcHandler, + maybe_max_payload_mb: Option, +) -> io::Result { + let max_request_body_size = maybe_max_payload_mb + .map(|mb| mb.saturating_mul(MEGABYTE)) + .unwrap_or(RPC_MAX_PAYLOAD_DEFAULT); + + http::ServerBuilder::new(io) + .threads(thread_pool_size.unwrap_or(HTTP_THREADS)) + .health_api(("/health", "system_health")) .allowed_hosts(hosts_filtering(cors.is_some())) - .session_stats(server_metrics) - .start(addr) - .map_err(|err| match err { - ws::Error::Io(io) => io, - ws::Error::ConnectionClosed => io::ErrorKind::BrokenPipe.into(), - e => { - error!("{}", e); - io::ErrorKind::Other.into() - }, - }) - } + .rest_api(if cors.is_some() { http::RestApi::Secure } else { http::RestApi::Unsecure }) + .cors(map_cors::(cors)) + .max_request_body_size(max_request_body_size) + .start_http(addr) +} - fn map_cors From<&'a str>>( - cors: Option<&Vec>, - ) -> http::DomainsValidation { - cors.map(|x| x.iter().map(AsRef::as_ref).map(Into::into).collect::>()) - .into() - } +/// Start IPC server listening on given path. +pub fn start_ipc( + addr: &str, + io: RpcHandler, + server_metrics: ServerMetrics, +) -> io::Result { + let builder = ipc::ServerBuilder::new(io); + #[cfg(target_os = "unix")] + builder.set_security_attributes({ + let security_attributes = ipc::SecurityAttributes::empty(); + security_attributes.set_mode(0o600)?; + security_attributes + }); + builder.session_stats(server_metrics).start(addr) +} - fn hosts_filtering(enable: bool) -> http::DomainsValidation { - if enable { - // NOTE The listening address is whitelisted by default. - // Setting an empty vector here enables the validation - // and allows only the listening address. - http::DomainsValidation::AllowOnly(vec![]) - } else { - http::DomainsValidation::Disabled - } - } +/// Start WS server listening on given address. +pub fn start_ws< + M: pubsub::PubSubMetadata + From>, +>( + addr: &std::net::SocketAddr, + max_connections: Option, + cors: Option<&Vec>, + io: RpcHandler, + maybe_max_payload_mb: Option, + server_metrics: ServerMetrics, +) -> io::Result { + let rpc_max_payload = maybe_max_payload_mb + .map(|mb| mb.saturating_mul(MEGABYTE)) + .unwrap_or(RPC_MAX_PAYLOAD_DEFAULT); + ws::ServerBuilder::with_meta_extractor(io, |context: &ws::RequestContext| { + context.sender().into() + }) + .max_payload(rpc_max_payload) + .max_connections(max_connections.unwrap_or(WS_MAX_CONNECTIONS)) + .allowed_origins(map_cors(cors)) + .allowed_hosts(hosts_filtering(cors.is_some())) + .session_stats(server_metrics) + .start(addr) + .map_err(|err| match err { + ws::Error::Io(io) => io, + ws::Error::ConnectionClosed => io::ErrorKind::BrokenPipe.into(), + e => { + error!("{}", e); + io::ErrorKind::Other.into() + }, + }) } -#[cfg(target_os = "unknown")] -mod inner {} +fn map_cors From<&'a str>>(cors: Option<&Vec>) -> http::DomainsValidation { + cors.map(|x| x.iter().map(AsRef::as_ref).map(Into::into).collect::>()) + .into() +} + +fn hosts_filtering(enable: bool) -> http::DomainsValidation { + if enable { + // NOTE The listening address is whitelisted by default. + // Setting an empty vector here enables the validation + // and allows only the listening address. + http::DomainsValidation::AllowOnly(vec![]) + } else { + http::DomainsValidation::Disabled + } +} diff --git a/client/rpc-servers/src/middleware.rs b/client/rpc-servers/src/middleware.rs index 43380977455df..00532b0e8d661 100644 --- a/client/rpc-servers/src/middleware.rs +++ b/client/rpc-servers/src/middleware.rs @@ -175,7 +175,6 @@ impl RequestMiddleware for RpcMiddleware { F: Fn(jsonrpc_core::Call, M) -> X + Send + Sync, X: Future> + Send + 'static, { - #[cfg(not(target_os = "unknown"))] let start = std::time::Instant::now(); let name = call_name(&call, &self.known_rpc_method_names).to_owned(); let metrics = self.metrics.clone(); @@ -191,11 +190,7 @@ impl RequestMiddleware for RpcMiddleware { Either::Left( async move { let r = r.await; - #[cfg(not(target_os = "unknown"))] let micros = start.elapsed().as_micros(); - // seems that std::time is not implemented for browser target - #[cfg(target_os = "unknown")] - let micros = 1; if let Some(ref metrics) = metrics { metrics .calls_time diff --git a/client/service/Cargo.toml b/client/service/Cargo.toml index b79e95fbb0912..6832ed44d5925 100644 --- a/client/service/Cargo.toml +++ b/client/service/Cargo.toml @@ -79,8 +79,6 @@ parity-util-mem = { version = "0.10.0", default-features = false, features = [ "primitive-types", ] } async-trait = "0.1.50" - -[target.'cfg(not(target_os = "unknown"))'.dependencies] tempfile = "3.1.0" directories = "3.0.2" diff --git a/client/service/src/builder.rs b/client/service/src/builder.rs index f0c037aee232f..7b0e2203dffd1 100644 --- a/client/service/src/builder.rs +++ b/client/service/src/builder.rs @@ -22,8 +22,7 @@ use crate::{ config::{Configuration, KeystoreConfig, PrometheusConfig, TransactionStorageMode}, error::Error, metrics::MetricsService, - start_rpc_servers, MallocSizeOfWasm, RpcHandlers, SpawnTaskHandle, TaskManager, - TransactionPoolAdapter, + start_rpc_servers, RpcHandlers, SpawnTaskHandle, TaskManager, TransactionPoolAdapter, }; use futures::{channel::oneshot, future::ready, FutureExt, StreamExt}; use jsonrpc_pubsub::manager::SubscriptionManager; @@ -552,7 +551,7 @@ where TBl::Header: Unpin, TBackend: 'static + sc_client_api::backend::Backend + Send, TExPool: MaintainedTransactionPool::Hash> - + MallocSizeOfWasm + + parity_util_mem::MallocSizeOf + 'static, TRpc: sc_rpc::RpcExtension, { diff --git a/client/service/src/config.rs b/client/service/src/config.rs index 4223a1812204e..20a9f58d21fd0 100644 --- a/client/service/src/config.rs +++ b/client/service/src/config.rs @@ -43,7 +43,6 @@ use std::{ pin::Pin, sync::Arc, }; -#[cfg(not(target_os = "unknown"))] use tempfile::TempDir; /// Service configuration. @@ -253,7 +252,6 @@ impl Default for RpcMethods { #[derive(Debug)] pub enum BasePath { /// A temporary directory is used as base path and will be deleted when dropped. - #[cfg(not(target_os = "unknown"))] Temporary(TempDir), /// A path on the disk. Permanenent(PathBuf), @@ -265,7 +263,6 @@ impl BasePath { /// /// Note: the temporary directory will be created automatically and deleted when the `BasePath` /// instance is dropped. - #[cfg(not(target_os = "unknown"))] pub fn new_temp_dir() -> io::Result { Ok(BasePath::Temporary(tempfile::Builder::new().prefix("substrate").tempdir()?)) } @@ -279,7 +276,6 @@ impl BasePath { } /// Create a base path from values describing the project. - #[cfg(not(target_os = "unknown"))] pub fn from_project(qualifier: &str, organization: &str, application: &str) -> BasePath { BasePath::new( directories::ProjectDirs::from(qualifier, organization, application) @@ -291,7 +287,6 @@ impl BasePath { /// Retrieve the base path. pub fn path(&self) -> &Path { match self { - #[cfg(not(target_os = "unknown"))] BasePath::Temporary(temp_dir) => temp_dir.path(), BasePath::Permanenent(path) => path.as_path(), } diff --git a/client/service/src/lib.rs b/client/service/src/lib.rs index ede6f01a4539e..6e4208138a3bd 100644 --- a/client/service/src/lib.rs +++ b/client/service/src/lib.rs @@ -39,7 +39,6 @@ use std::{collections::HashMap, io, net::SocketAddr, pin::Pin, task::Poll}; use codec::{Decode, Encode}; use futures::{stream, Future, FutureExt, Stream, StreamExt}; use log::{debug, error, warn}; -use parity_util_mem::MallocSizeOf; use sc_network::PeerId; use sc_utils::mpsc::TracingUnboundedReceiver; use sp_runtime::{ @@ -81,16 +80,6 @@ pub use task_manager::{SpawnTaskHandle, TaskManager}; const DEFAULT_PROTOCOL_ID: &str = "sup"; -/// A type that implements `MallocSizeOf` on native but not wasm. -#[cfg(not(target_os = "unknown"))] -pub trait MallocSizeOfWasm: MallocSizeOf {} -#[cfg(target_os = "unknown")] -pub trait MallocSizeOfWasm {} -#[cfg(not(target_os = "unknown"))] -impl MallocSizeOfWasm for T {} -#[cfg(target_os = "unknown")] -impl MallocSizeOfWasm for T {} - /// RPC handlers that can perform RPC queries. #[derive(Clone)] pub struct RpcHandlers( @@ -305,7 +294,6 @@ async fn build_network_future< } // Wrapper for HTTP and WS servers that makes sure they are properly shut down. -#[cfg(not(target_os = "unknown"))] mod waiting { pub struct HttpServer(pub Option); impl Drop for HttpServer { @@ -340,7 +328,6 @@ mod waiting { /// Starts RPC servers that run in their own thread, and returns an opaque object that keeps them /// alive. -#[cfg(not(target_os = "unknown"))] fn start_rpc_servers< H: FnMut( sc_rpc::DenyUnsafe, @@ -445,23 +432,6 @@ fn start_rpc_servers< ))) } -/// Starts RPC servers that run in their own thread, and returns an opaque object that keeps them -/// alive. -#[cfg(target_os = "unknown")] -fn start_rpc_servers< - H: FnMut( - sc_rpc::DenyUnsafe, - sc_rpc_server::RpcMiddleware, - ) -> Result, Error>, ->( - _: &Configuration, - _: H, - _: Option, - _: sc_rpc_server::ServerMetrics, -) -> Result, error::Error> { - Ok(Box::new(())) -} - /// An RPC session. Used to perform in-memory RPC queries (ie. RPC queries that don't go through /// the HTTP or WebSockets server). #[derive(Clone)] diff --git a/client/transaction-pool/src/graph/base_pool.rs b/client/transaction-pool/src/graph/base_pool.rs index b5ff036c0139e..890a87e82929d 100644 --- a/client/transaction-pool/src/graph/base_pool.rs +++ b/client/transaction-pool/src/graph/base_pool.rs @@ -207,8 +207,7 @@ const RECENTLY_PRUNED_TAGS: usize = 2; /// as-is for the second time will fail or produce unwanted results. /// Most likely it is required to revalidate them and recompute set of /// required tags. -#[derive(Debug)] -#[cfg_attr(not(target_os = "unknown"), derive(parity_util_mem::MallocSizeOf))] +#[derive(Debug, parity_util_mem::MallocSizeOf)] pub struct BasePool { reject_future_transactions: bool, future: FutureTransactions, diff --git a/client/transaction-pool/src/graph/future.rs b/client/transaction-pool/src/graph/future.rs index 201d6f40e8b19..6ed1f1014304f 100644 --- a/client/transaction-pool/src/graph/future.rs +++ b/client/transaction-pool/src/graph/future.rs @@ -28,7 +28,7 @@ use std::time::Instant; use super::base_pool::Transaction; -#[cfg_attr(not(target_os = "unknown"), derive(parity_util_mem::MallocSizeOf))] +#[derive(parity_util_mem::MallocSizeOf)] /// Transaction with partially satisfied dependencies. pub struct WaitingTransaction { /// Transaction details. @@ -108,8 +108,7 @@ impl WaitingTransaction { /// /// Contains transactions that are still awaiting for some other transactions that /// could provide a tag that they require. -#[derive(Debug)] -#[cfg_attr(not(target_os = "unknown"), derive(parity_util_mem::MallocSizeOf))] +#[derive(Debug, parity_util_mem::MallocSizeOf)] pub struct FutureTransactions { /// tags that are not yet provided by any transaction and we await for them wanted_tags: HashMap>, diff --git a/client/transaction-pool/src/graph/pool.rs b/client/transaction-pool/src/graph/pool.rs index 70de9b2356689..2af5a8a19a5a9 100644 --- a/client/transaction-pool/src/graph/pool.rs +++ b/client/transaction-pool/src/graph/pool.rs @@ -133,7 +133,6 @@ pub struct Pool { validated_pool: Arc>, } -#[cfg(not(target_os = "unknown"))] impl parity_util_mem::MallocSizeOf for Pool where ExtrinsicFor: parity_util_mem::MallocSizeOf, diff --git a/client/transaction-pool/src/graph/validated_pool.rs b/client/transaction-pool/src/graph/validated_pool.rs index 4dd5ea3b67e7e..e4aad7f342b5b 100644 --- a/client/transaction-pool/src/graph/validated_pool.rs +++ b/client/transaction-pool/src/graph/validated_pool.rs @@ -111,7 +111,6 @@ pub struct ValidatedPool { rotator: PoolRotator>, } -#[cfg(not(target_os = "unknown"))] impl parity_util_mem::MallocSizeOf for ValidatedPool where ExtrinsicFor: parity_util_mem::MallocSizeOf, diff --git a/client/transaction-pool/src/lib.rs b/client/transaction-pool/src/lib.rs index cd97abab933f0..6f59184230f60 100644 --- a/client/transaction-pool/src/lib.rs +++ b/client/transaction-pool/src/lib.rs @@ -138,7 +138,6 @@ impl ReadyPoll { } } -#[cfg(not(target_os = "unknown"))] impl parity_util_mem::MallocSizeOf for BasicPool where PoolApi: graph::ChainApi, diff --git a/client/utils/src/metrics.rs b/client/utils/src/metrics.rs index 8df8e65962474..85ccce626bc25 100644 --- a/client/utils/src/metrics.rs +++ b/client/utils/src/metrics.rs @@ -16,7 +16,6 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . - //! Metering primitives and globals use lazy_static::lazy_static; diff --git a/primitives/maybe-compressed-blob/Cargo.toml b/primitives/maybe-compressed-blob/Cargo.toml index 720fc4281ca7b..8d47c89ea8ebe 100644 --- a/primitives/maybe-compressed-blob/Cargo.toml +++ b/primitives/maybe-compressed-blob/Cargo.toml @@ -10,8 +10,5 @@ description = "Handling of blobs, usually Wasm code, which may be compresed" documentation = "https://docs.rs/sp-maybe-compressed-blob" readme = "README.md" -[target.'cfg(not(target_os = "unknown"))'.dependencies] +[dependencies] zstd = { version = "0.6.0", default-features = false } - -[target.'cfg(target_os = "unknown")'.dependencies] -ruzstd = { version = "0.2.2" } diff --git a/primitives/maybe-compressed-blob/src/lib.rs b/primitives/maybe-compressed-blob/src/lib.rs index 4e4a3da0a82c6..e8a7e42b4eace 100644 --- a/primitives/maybe-compressed-blob/src/lib.rs +++ b/primitives/maybe-compressed-blob/src/lib.rs @@ -70,22 +70,12 @@ fn read_from_decoder( } } -#[cfg(not(target_os = "unknown"))] fn decompress_zstd(blob: &[u8], bomb_limit: usize) -> Result, Error> { let decoder = zstd::Decoder::new(blob).map_err(|_| Error::Invalid)?; read_from_decoder(decoder, blob.len(), bomb_limit) } -#[cfg(target_os = "unknown")] -fn decompress_zstd(mut blob: &[u8], bomb_limit: usize) -> Result, Error> { - let blob_len = blob.len(); - let decoder = - ruzstd::streaming_decoder::StreamingDecoder::new(&mut blob).map_err(|_| Error::Invalid)?; - - read_from_decoder(decoder, blob_len, bomb_limit) -} - /// Decode a blob, if it indicates that it is compressed. Provide a `bomb_limit`, which /// is the limit of bytes which should be decompressed from the blob. pub fn decompress(blob: &[u8], bomb_limit: usize) -> Result, Error> { @@ -99,7 +89,6 @@ pub fn decompress(blob: &[u8], bomb_limit: usize) -> Result, Error> { /// Encode a blob as compressed. If the blob's size is over the bomb limit, /// this will not compress the blob, as the decoder will not be able to be /// able to differentiate it from a compression bomb. -#[cfg(not(target_os = "unknown"))] pub fn compress(blob: &[u8], bomb_limit: usize) -> Option> { use std::io::Write; diff --git a/utils/prometheus/Cargo.toml b/utils/prometheus/Cargo.toml index 16feedb2b5bd2..062054801da80 100644 --- a/utils/prometheus/Cargo.toml +++ b/utils/prometheus/Cargo.toml @@ -17,8 +17,6 @@ log = "0.4.8" prometheus = { version = "0.11.0", default-features = false } futures-util = { version = "0.3.1", default-features = false, features = ["io"] } derive_more = "0.99" - -[target.'cfg(not(target_os = "unknown"))'.dependencies] async-std = { version = "1.6.5", features = ["unstable"] } tokio = "1.10" hyper = { version = "0.14.11", default-features = false, features = ["http1", "server", "tcp"] } diff --git a/utils/prometheus/src/lib.rs b/utils/prometheus/src/lib.rs index 5771b65567575..f81b82cb17646 100644 --- a/utils/prometheus/src/lib.rs +++ b/utils/prometheus/src/lib.rs @@ -15,9 +15,13 @@ // See the License for the specific language governing permissions and // limitations under the License. -#[cfg(not(target_os = "unknown"))] use futures_util::future::Future; -use prometheus::core::Collector; +use hyper::{ + http::StatusCode, + server::Server, + service::{make_service_fn, service_fn}, + Body, Request, Response, +}; pub use prometheus::{ self, core::{ @@ -27,21 +31,14 @@ pub use prometheus::{ exponential_buckets, Error as PrometheusError, Histogram, HistogramOpts, HistogramVec, Opts, Registry, }; -#[cfg(not(target_os = "unknown"))] -use prometheus::{Encoder, TextEncoder}; +use prometheus::{core::Collector, Encoder, TextEncoder}; use std::net::SocketAddr; -#[cfg(not(target_os = "unknown"))] mod networking; mod sourced; pub use sourced::{MetricSource, SourcedCounter, SourcedGauge, SourcedMetric}; -#[cfg(not(target_os = "unknown"))] -pub use known_os::init_prometheus; -#[cfg(target_os = "unknown")] -pub use unknown_os::init_prometheus; - pub fn register( metric: T, registry: &Registry, @@ -50,126 +47,96 @@ pub fn register( Ok(metric) } -// On WASM `init_prometheus` becomes a no-op. -#[cfg(target_os = "unknown")] -mod unknown_os { - use super::*; - - pub enum Error {} - - pub async fn init_prometheus(_: SocketAddr, _registry: Registry) -> Result<(), Error> { - Ok(()) - } +#[derive(Debug, derive_more::Display, derive_more::From)] +pub enum Error { + /// Hyper internal error. + Hyper(hyper::Error), + /// Http request error. + Http(hyper::http::Error), + /// i/o error. + Io(std::io::Error), + #[display(fmt = "Prometheus port {} already in use.", _0)] + PortInUse(SocketAddr), } -#[cfg(not(target_os = "unknown"))] -mod known_os { - use super::*; - use hyper::{ - http::StatusCode, - server::Server, - service::{make_service_fn, service_fn}, - Body, Request, Response, - }; - - #[derive(Debug, derive_more::Display, derive_more::From)] - pub enum Error { - /// Hyper internal error. - Hyper(hyper::Error), - /// Http request error. - Http(hyper::http::Error), - /// i/o error. - Io(std::io::Error), - #[display(fmt = "Prometheus port {} already in use.", _0)] - PortInUse(SocketAddr), - } - - impl std::error::Error for Error { - fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - match self { - Error::Hyper(error) => Some(error), - Error::Http(error) => Some(error), - Error::Io(error) => Some(error), - Error::PortInUse(_) => None, - } +impl std::error::Error for Error { + fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { + match self { + Error::Hyper(error) => Some(error), + Error::Http(error) => Some(error), + Error::Io(error) => Some(error), + Error::PortInUse(_) => None, } } +} - async fn request_metrics( - req: Request, - registry: Registry, - ) -> Result, Error> { - if req.uri().path() == "/metrics" { - let metric_families = registry.gather(); - let mut buffer = vec![]; - let encoder = TextEncoder::new(); - encoder.encode(&metric_families, &mut buffer).unwrap(); - - Response::builder() - .status(StatusCode::OK) - .header("Content-Type", encoder.format_type()) - .body(Body::from(buffer)) - .map_err(Error::Http) - } else { - Response::builder() - .status(StatusCode::NOT_FOUND) - .body(Body::from("Not found.")) - .map_err(Error::Http) - } +async fn request_metrics(req: Request, registry: Registry) -> Result, Error> { + if req.uri().path() == "/metrics" { + let metric_families = registry.gather(); + let mut buffer = vec![]; + let encoder = TextEncoder::new(); + encoder.encode(&metric_families, &mut buffer).unwrap(); + + Response::builder() + .status(StatusCode::OK) + .header("Content-Type", encoder.format_type()) + .body(Body::from(buffer)) + .map_err(Error::Http) + } else { + Response::builder() + .status(StatusCode::NOT_FOUND) + .body(Body::from("Not found.")) + .map_err(Error::Http) } +} - #[derive(Clone)] - pub struct Executor; +#[derive(Clone)] +pub struct Executor; - impl hyper::rt::Executor for Executor - where - T: Future + Send + 'static, - T::Output: Send + 'static, - { - fn execute(&self, future: T) { - async_std::task::spawn(future); - } +impl hyper::rt::Executor for Executor +where + T: Future + Send + 'static, + T::Output: Send + 'static, +{ + fn execute(&self, future: T) { + async_std::task::spawn(future); } +} - /// Initializes the metrics context, and starts an HTTP server - /// to serve metrics. - pub async fn init_prometheus( - prometheus_addr: SocketAddr, - registry: Registry, - ) -> Result<(), Error> { - let listener = async_std::net::TcpListener::bind(&prometheus_addr) - .await - .map_err(|_| Error::PortInUse(prometheus_addr))?; - - init_prometheus_with_listener(listener, registry).await - } +/// Initializes the metrics context, and starts an HTTP server +/// to serve metrics. +pub async fn init_prometheus(prometheus_addr: SocketAddr, registry: Registry) -> Result<(), Error> { + let listener = async_std::net::TcpListener::bind(&prometheus_addr) + .await + .map_err(|_| Error::PortInUse(prometheus_addr))?; - /// Init prometheus using the given listener. - pub(crate) async fn init_prometheus_with_listener( - listener: async_std::net::TcpListener, - registry: Registry, - ) -> Result<(), Error> { - use networking::Incoming; + init_prometheus_with_listener(listener, registry).await +} - log::info!("〽️ Prometheus exporter started at {}", listener.local_addr()?); +/// Init prometheus using the given listener. +async fn init_prometheus_with_listener( + listener: async_std::net::TcpListener, + registry: Registry, +) -> Result<(), Error> { + use networking::Incoming; - let service = make_service_fn(move |_| { - let registry = registry.clone(); + log::info!("〽️ Prometheus exporter started at {}", listener.local_addr()?); - async move { - Ok::<_, hyper::Error>(service_fn(move |req: Request| { - request_metrics(req, registry.clone()) - })) - } - }); + let service = make_service_fn(move |_| { + let registry = registry.clone(); - let server = - Server::builder(Incoming(listener.incoming())).executor(Executor).serve(service); + async move { + Ok::<_, hyper::Error>(service_fn(move |req: Request| { + request_metrics(req, registry.clone()) + })) + } + }); - let result = server.await.map_err(Into::into); + let server = Server::builder(Incoming(listener.incoming())).executor(Executor).serve(service); - result - } + let result = server.await.map_err(Into::into); + + result } #[cfg(test)] @@ -197,7 +164,7 @@ mod tests { ) .expect("Registers the test metric"); - runtime.spawn(known_os::init_prometheus_with_listener(listener, registry)); + runtime.spawn(init_prometheus_with_listener(listener, registry)); runtime.block_on(async { let client = Client::new();