Fix timer panics in the wasm light client (#4561)

* Make WASM browser thing compile

* Fix

* updated exit-future (github repo)

* Switch to broadcast crate

* Migrate client/cli

* Switch exit-future to modernize branch

* Small changes

* Switch to cargo version and fix fg tests

* fix basic-authorship

* Fix crash on grafana macro

* Fix grafana macro

* Switch node python version

* Disable record_metrics_slice in grafana macro on wasm

* Update client/grafana-data-source/src/lib.rs

* Revert "Update client/grafana-data-source/src/lib.rs"

This reverts commit 888009a8e0b7051bd4bfbbfdb0448bcf2e2aae93.

* Add wasm support for state machine

* Switch to my own libp2p version

* Revert "Switch to my own libp2p version"

This reverts commit ce613871b59264b3165b45c37943e6560240daa7.

* Revert "Add wasm support for state machine"

This reverts commit de7eaa0694d9534fc3b164621737968e9a6a7c5f.

* Add sc-browser

* Squash

* remove sc-browser

* Fix keystore on wasm

* stubs for removed functions to make env compatible with old runtimes

* Add test (that doesn't work)

* Fix build scripts

* Revert basic-authorship due to no panics

* Revert cli/informant

* Revert consensus

* revert offchain

* Update utils/browser/Cargo.toml

Co-Authored-By: Benjamin Kampmann <ben@gnunicorn.org>

* export console functions

* Add new chainspec

* Fix ws in chain spec

* revert chainspec

* Fix chainspec

* Use an Option<PathBuf> in keystore instead of cfg flags

* Remove crud

* Only use wasm-timer for instant and systemtime

* Remove telemetry changes

* Assuming this is ok

* Add a KeystoreConfig

* Add stubs back in

* Update libp2p

* Revert "Add stubs back in"

This reverts commit 4690cf1882aa0f99f7f00a58c4080c8aa9b77c36.

* Remove commented js again

* Bump kvdb-web version

* Fix cli

* Switch branch on futures-timer

* Fix tests

* Remove sc-client test build in check-web-wasm because there isn't a good way to build futures-timer with wasm-bindgen support in the build

* Remove more things ^^

* Switch branch on futures-timer back

* Put DB io stats behind a cfg flag

* Fix things

* Don't timeout transports on wasm

* Update branch of futures-timer and fix bad merge

* Spawn informant

* Fix network test

* Fix delay resets

* Changes

* Fix tests

* use wasm_timer for transaction pool

* Fixes

* Switch futures-timer to crates

* Only diagnose futures on native

* Fix sc-network-test tests

* Select log level in js

* Fix syncing ;^)

* Allow disabling colours in the informant

* Use OutputFormat enum for informant

* MallocSizeOf impl on transaction pool broke stuff because wasm_timer::Instant doesnt impl it so just revert the transaction pool to master

* Update futures-diagnose

* Revert "MallocSizeOf impl on transaction pool broke stuff because wasm_timer::Instant doesnt impl it so just revert the transaction pool to master"

This reverts commit baa4ffc94fd968b6660a2c17ba8113e06af15548.

* Pass whole chain spec in start_client

* Get Instant::now to work in transaction pool again

* Informant dep reordering

Co-authored-by: Pierre Krieger <pierre.krieger1708@gmail.com>
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
Co-authored-by: Svyatoslav Nikolsky <svyatonik@gmail.com>
Co-authored-by: Benjamin Kampmann <ben.kampmann@googlemail.com>
Co-authored-by: Demi Obenour <48690212+DemiMarie-parity@users.noreply.github.com>
This commit is contained in:
Ashley
2020-02-10 12:23:55 +01:00
committed by GitHub
parent 34bf0caa05
commit ead6815ae4
54 changed files with 299 additions and 155 deletions
+73 -25
View File
@@ -425,11 +425,13 @@ dependencies = [
name = "browser-utils" name = "browser-utils"
version = "0.8.0" version = "0.8.0"
dependencies = [ dependencies = [
"chrono",
"clear_on_drop", "clear_on_drop",
"console_error_panic_hook", "console_error_panic_hook",
"console_log", "console_log",
"futures 0.1.29", "futures 0.1.29",
"futures 0.3.4", "futures 0.3.4",
"futures-timer 3.0.1",
"js-sys", "js-sys",
"kvdb-web", "kvdb-web",
"libp2p", "libp2p",
@@ -437,6 +439,7 @@ dependencies = [
"rand 0.6.5", "rand 0.6.5",
"rand 0.7.3", "rand 0.7.3",
"sc-chain-spec", "sc-chain-spec",
"sc-informant",
"sc-network", "sc-network",
"sc-service", "sc-service",
"wasm-bindgen", "wasm-bindgen",
@@ -595,10 +598,12 @@ version = "0.4.10"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "31850b4a4d6bae316f7a09e691c944c28299298837edc0a03f755618c23cbc01" checksum = "31850b4a4d6bae316f7a09e691c944c28299298837edc0a03f755618c23cbc01"
dependencies = [ dependencies = [
"js-sys",
"num-integer", "num-integer",
"num-traits", "num-traits",
"serde", "serde",
"time", "time",
"wasm-bindgen",
] ]
[[package]] [[package]]
@@ -1715,23 +1720,22 @@ version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b0a34e53cf6cdcd0178aa573aed466b646eb3db769570841fda0c7ede375a27" checksum = "7b0a34e53cf6cdcd0178aa573aed466b646eb3db769570841fda0c7ede375a27"
[[package]]
name = "futures-timer"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "878f1d2fc31355fa02ed2372e741b0c17e58373341e6a122569b4623a14a7d33"
dependencies = [
"futures-core-preview",
"futures-util-preview",
"pin-utils",
]
[[package]] [[package]]
name = "futures-timer" name = "futures-timer"
version = "2.0.2" version = "2.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1de7508b218029b0f01662ed8f61b1c964b3ae99d6f25462d0f55a595109df6" checksum = "a1de7508b218029b0f01662ed8f61b1c964b3ae99d6f25462d0f55a595109df6"
[[package]]
name = "futures-timer"
version = "3.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3de1a2b2a2a33d9e60e17980b60ee061eeaae96a5abe9121db0fdb9af167a1c5"
dependencies = [
"gloo-timers",
"send_wrapper 0.4.0",
]
[[package]] [[package]]
name = "futures-util" name = "futures-util"
version = "0.3.4" version = "0.3.4"
@@ -1873,6 +1877,19 @@ dependencies = [
"regex", "regex",
] ]
[[package]]
name = "gloo-timers"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b2d17dbd803c2fc86cb1b613adf63192046a7176f383a8302594654752c4c4a"
dependencies = [
"futures-channel",
"futures-core",
"js-sys",
"wasm-bindgen",
"web-sys",
]
[[package]] [[package]]
name = "goblin" name = "goblin"
version = "0.1.3" version = "0.1.3"
@@ -1891,7 +1908,7 @@ dependencies = [
"async-std", "async-std",
"chrono", "chrono",
"derive_more", "derive_more",
"futures-timer 2.0.2", "futures-timer 3.0.1",
"futures-util", "futures-util",
"hyper 0.13.2", "hyper 0.13.2",
"lazy_static", "lazy_static",
@@ -1907,7 +1924,7 @@ name = "grafana-data-source-test"
version = "2.0.0" version = "2.0.0"
dependencies = [ dependencies = [
"futures 0.3.4", "futures 0.3.4",
"futures-timer 2.0.2", "futures-timer 3.0.1",
"grafana-data-source", "grafana-data-source",
"rand 0.7.3", "rand 0.7.3",
] ]
@@ -5450,7 +5467,7 @@ dependencies = [
"derive_more", "derive_more",
"env_logger 0.7.1", "env_logger 0.7.1",
"futures 0.3.4", "futures 0.3.4",
"futures-timer 2.0.2", "futures-timer 3.0.1",
"libp2p", "libp2p",
"log 0.4.8", "log 0.4.8",
"parity-scale-codec", "parity-scale-codec",
@@ -5554,6 +5571,7 @@ dependencies = [
"regex", "regex",
"rpassword", "rpassword",
"sc-client-api", "sc-client-api",
"sc-informant",
"sc-network", "sc-network",
"sc-service", "sc-service",
"sc-telemetry", "sc-telemetry",
@@ -5678,7 +5696,7 @@ dependencies = [
"env_logger 0.7.1", "env_logger 0.7.1",
"futures 0.1.29", "futures 0.1.29",
"futures 0.3.4", "futures 0.3.4",
"futures-timer 0.4.0", "futures-timer 3.0.1",
"log 0.4.8", "log 0.4.8",
"parity-scale-codec", "parity-scale-codec",
"parking_lot 0.10.0", "parking_lot 0.10.0",
@@ -5718,7 +5736,7 @@ dependencies = [
"fork-tree", "fork-tree",
"futures 0.1.29", "futures 0.1.29",
"futures 0.3.4", "futures 0.3.4",
"futures-timer 0.4.0", "futures-timer 3.0.1",
"log 0.4.8", "log 0.4.8",
"merlin", "merlin",
"num-bigint", "num-bigint",
@@ -5824,7 +5842,7 @@ name = "sc-consensus-slots"
version = "0.8.0" version = "0.8.0"
dependencies = [ dependencies = [
"futures 0.3.4", "futures 0.3.4",
"futures-timer 2.0.2", "futures-timer 3.0.1",
"log 0.4.8", "log 0.4.8",
"parity-scale-codec", "parity-scale-codec",
"parking_lot 0.10.0", "parking_lot 0.10.0",
@@ -5950,7 +5968,7 @@ dependencies = [
"fork-tree", "fork-tree",
"futures 0.1.29", "futures 0.1.29",
"futures 0.3.4", "futures 0.3.4",
"futures-timer 2.0.2", "futures-timer 3.0.1",
"log 0.4.8", "log 0.4.8",
"parity-scale-codec", "parity-scale-codec",
"parking_lot 0.10.0", "parking_lot 0.10.0",
@@ -5981,6 +5999,22 @@ dependencies = [
"tokio 0.1.22", "tokio 0.1.22",
] ]
[[package]]
name = "sc-informant"
version = "0.8.0"
dependencies = [
"ansi_term 0.12.1",
"futures 0.3.4",
"log 0.4.8",
"parity-util-mem",
"sc-client-api",
"sc-network",
"sc-service",
"sp-blockchain",
"sp-runtime",
"wasm-timer",
]
[[package]] [[package]]
name = "sc-keystore" name = "sc-keystore"
version = "2.0.0" version = "2.0.0"
@@ -6009,7 +6043,7 @@ dependencies = [
"fnv", "fnv",
"fork-tree", "fork-tree",
"futures 0.3.4", "futures 0.3.4",
"futures-timer 0.4.0", "futures-timer 3.0.1",
"futures_codec", "futures_codec",
"libp2p", "libp2p",
"linked-hash-map", "linked-hash-map",
@@ -6043,6 +6077,7 @@ dependencies = [
"tempfile", "tempfile",
"unsigned-varint", "unsigned-varint",
"void", "void",
"wasm-timer",
"zeroize 1.1.0", "zeroize 1.1.0",
] ]
@@ -6052,13 +6087,14 @@ version = "0.8.0"
dependencies = [ dependencies = [
"futures 0.1.29", "futures 0.1.29",
"futures 0.3.4", "futures 0.3.4",
"futures-timer 0.4.0", "futures-timer 3.0.1",
"libp2p", "libp2p",
"log 0.4.8", "log 0.4.8",
"lru 0.1.17", "lru 0.1.17",
"parking_lot 0.10.0", "parking_lot 0.10.0",
"sc-network", "sc-network",
"sp-runtime", "sp-runtime",
"wasm-timer",
] ]
[[package]] [[package]]
@@ -6068,7 +6104,7 @@ dependencies = [
"env_logger 0.7.1", "env_logger 0.7.1",
"futures 0.1.29", "futures 0.1.29",
"futures 0.3.4", "futures 0.3.4",
"futures-timer 0.4.0", "futures-timer 3.0.1",
"libp2p", "libp2p",
"log 0.4.8", "log 0.4.8",
"parking_lot 0.10.0", "parking_lot 0.10.0",
@@ -6097,7 +6133,7 @@ dependencies = [
"fnv", "fnv",
"futures 0.1.29", "futures 0.1.29",
"futures 0.3.4", "futures 0.3.4",
"futures-timer 2.0.2", "futures-timer 3.0.1",
"hyper 0.12.35", "hyper 0.12.35",
"hyper-rustls", "hyper-rustls",
"log 0.4.8", "log 0.4.8",
@@ -6129,6 +6165,7 @@ dependencies = [
"log 0.4.8", "log 0.4.8",
"rand 0.7.3", "rand 0.7.3",
"serde_json", "serde_json",
"wasm-timer",
] ]
[[package]] [[package]]
@@ -6225,7 +6262,7 @@ dependencies = [
"futures 0.1.29", "futures 0.1.29",
"futures 0.3.4", "futures 0.3.4",
"futures-diagnose", "futures-diagnose",
"futures-timer 2.0.2", "futures-timer 3.0.1",
"grafana-data-source", "grafana-data-source",
"lazy_static", "lazy_static",
"log 0.4.8", "log 0.4.8",
@@ -6267,6 +6304,7 @@ dependencies = [
"tokio 0.2.11", "tokio 0.2.11",
"tokio-executor 0.1.10", "tokio-executor 0.1.10",
"tracing", "tracing",
"wasm-timer",
] ]
[[package]] [[package]]
@@ -6306,7 +6344,7 @@ version = "2.0.0"
dependencies = [ dependencies = [
"bytes 0.5.4", "bytes 0.5.4",
"futures 0.3.4", "futures 0.3.4",
"futures-timer 2.0.2", "futures-timer 3.0.1",
"libp2p", "libp2p",
"log 0.4.8", "log 0.4.8",
"parking_lot 0.10.0", "parking_lot 0.10.0",
@@ -6318,6 +6356,7 @@ dependencies = [
"slog-scope", "slog-scope",
"take_mut", "take_mut",
"void", "void",
"wasm-timer",
] ]
[[package]] [[package]]
@@ -6353,6 +6392,7 @@ dependencies = [
"sp-runtime", "sp-runtime",
"sp-transaction-pool", "sp-transaction-pool",
"substrate-test-runtime", "substrate-test-runtime",
"wasm-timer",
] ]
[[package]] [[package]]
@@ -6376,6 +6416,7 @@ dependencies = [
"sp-transaction-pool", "sp-transaction-pool",
"substrate-test-runtime-client", "substrate-test-runtime-client",
"substrate-test-runtime-transaction-pool", "substrate-test-runtime-transaction-pool",
"wasm-timer",
] ]
[[package]] [[package]]
@@ -6505,6 +6546,12 @@ version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "686ef91cf020ad8d4aca9a7047641fd6add626b7b89e14546c2b6a76781cf822" checksum = "686ef91cf020ad8d4aca9a7047641fd6add626b7b89e14546c2b6a76781cf822"
[[package]]
name = "send_wrapper"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f638d531eccd6e23b980caf34876660d38e265409d8e99b397ab71eb3612fad0"
[[package]] [[package]]
name = "serde" name = "serde"
version = "1.0.104" version = "1.0.104"
@@ -6854,7 +6901,7 @@ dependencies = [
"derive_more", "derive_more",
"futures 0.3.4", "futures 0.3.4",
"futures-diagnose", "futures-diagnose",
"futures-timer 0.4.0", "futures-timer 3.0.1",
"libp2p", "libp2p",
"log 0.4.8", "log 0.4.8",
"parity-scale-codec", "parity-scale-codec",
@@ -7235,6 +7282,7 @@ dependencies = [
"sp-inherents", "sp-inherents",
"sp-runtime", "sp-runtime",
"sp-std", "sp-std",
"wasm-timer",
] ]
[[package]] [[package]]
+1
View File
@@ -35,6 +35,7 @@ members = [
"client/executor/wasmtime", "client/executor/wasmtime",
"client/executor/runtime-test", "client/executor/runtime-test",
"client/finality-grandpa", "client/finality-grandpa",
"client/informant",
"client/tracing", "client/tracing",
"client/keystore", "client/keystore",
"client/network", "client/network",
@@ -15,11 +15,12 @@ function log(msg) {
async function start() { async function start() {
log('Loading WASM'); log('Loading WASM');
await init('./pkg/node_cli_bg.wasm'); await init('./pkg/node_cli_bg.wasm');
log('Successfully loaded WASM'); log('Fetching chain spec');
const chain_spec_response = await fetch("https://raw.githubusercontent.com/paritytech/substrate/master/bin/node/cli/res/flaming-fir.json");
const chain_spec_text = await chain_spec_response.text();
// Build our client. // Build our client.
log('Starting client'); let client = await start_client(chain_spec_text, 'info', ws());
let client = await start_client(ws());
log('Client started'); log('Client started');
client.rpcSubscribe('{"method":"chain_subscribeNewHead","params":[],"id":1,"jsonrpc":"2.0"}', client.rpcSubscribe('{"method":"chain_subscribeNewHead","params":[],"id":1,"jsonrpc":"2.0"}',
+7 -7
View File
@@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Substrate. If not, see <http://www.gnu.org/licenses/>. // along with Substrate. If not, see <http://www.gnu.org/licenses/>.
use crate::ChainSpec; use crate::chain_spec::ChainSpec;
use log::info; use log::info;
use wasm_bindgen::prelude::*; use wasm_bindgen::prelude::*;
use sc_service::Configuration; use sc_service::Configuration;
@@ -22,20 +22,20 @@ use browser_utils::{
Transport, Client, Transport, Client,
browser_configuration, set_console_error_panic_hook, init_console_log, browser_configuration, set_console_error_panic_hook, init_console_log,
}; };
use std::str::FromStr;
/// Starts the client. /// Starts the client.
#[wasm_bindgen] #[wasm_bindgen]
pub async fn start_client(wasm_ext: Transport) -> Result<Client, JsValue> { pub async fn start_client(chain_spec: String, log_level: String, wasm_ext: Transport) -> Result<Client, JsValue> {
start_inner(wasm_ext) start_inner(chain_spec, log_level, wasm_ext)
.await .await
.map_err(|err| JsValue::from_str(&err.to_string())) .map_err(|err| JsValue::from_str(&err.to_string()))
} }
async fn start_inner(wasm_ext: Transport) -> Result<Client, Box<dyn std::error::Error>> { async fn start_inner(chain_spec: String, log_level: String, wasm_ext: Transport) -> Result<Client, Box<dyn std::error::Error>> {
set_console_error_panic_hook(); set_console_error_panic_hook();
init_console_log(log::Level::Info)?; init_console_log(log::Level::from_str(&log_level)?)?;
let chain_spec = ChainSpec::from_json_bytes(chain_spec.as_bytes().to_vec())
let chain_spec = ChainSpec::FlamingFir.load()
.map_err(|e| format!("{:?}", e))?; .map_err(|e| format!("{:?}", e))?;
let config: Configuration<_, _> = browser_configuration(wasm_ext, chain_spec) let config: Configuration<_, _> = browser_configuration(wasm_ext, chain_spec)
@@ -14,7 +14,7 @@ bytes = "0.4.12"
codec = { package = "parity-scale-codec", default-features = false, version = "1.0.3" } codec = { package = "parity-scale-codec", default-features = false, version = "1.0.3" }
derive_more = "0.99.2" derive_more = "0.99.2"
futures = "0.3.1" futures = "0.3.1"
futures-timer = "2.0" futures-timer = "3.0.1"
libp2p = { version = "0.15.0", default-features = false, features = ["secp256k1", "libp2p-websocket"] } libp2p = { version = "0.15.0", default-features = false, features = ["secp256k1", "libp2p-websocket"] }
log = "0.4.8" log = "0.4.8"
prost = "0.6.1" prost = "0.6.1"
+1
View File
@@ -21,6 +21,7 @@ tokio = { version = "0.2.9", features = [ "signal", "rt-core", "rt-threaded" ] }
futures = "0.3.1" futures = "0.3.1"
fdlimit = "0.1.1" fdlimit = "0.1.1"
serde_json = "1.0.41" serde_json = "1.0.41"
sc-informant = { version = "0.8", path = "../informant" }
sp-panic-handler = { version = "2.0.0", path = "../../primitives/panic-handler" } sp-panic-handler = { version = "2.0.0", path = "../../primitives/panic-handler" }
sc-client-api = { version = "2.0.0", path = "../api" } sc-client-api = { version = "2.0.0", path = "../api" }
sp-blockchain = { version = "2.0.0", path = "../../primitives/blockchain" } sp-blockchain = { version = "2.0.0", path = "../../primitives/blockchain" }
-1
View File
@@ -24,7 +24,6 @@ mod traits;
mod params; mod params;
mod execution_strategy; mod execution_strategy;
pub mod error; pub mod error;
pub mod informant;
mod runtime; mod runtime;
mod node_key; mod node_key;
+1 -2
View File
@@ -21,7 +21,6 @@ use futures::select;
use futures::pin_mut; use futures::pin_mut;
use sc_service::{AbstractService, Configuration}; use sc_service::{AbstractService, Configuration};
use crate::error; use crate::error;
use crate::informant;
#[cfg(target_family = "unix")] #[cfg(target_family = "unix")]
async fn main<F, E>(func: F) -> Result<(), Box<dyn std::error::Error>> async fn main<F, E>(func: F) -> Result<(), Box<dyn std::error::Error>>
@@ -124,7 +123,7 @@ where
let service = service_builder(config)?; let service = service_builder(config)?;
let informant_future = informant::build(&service); let informant_future = sc_informant::build(&service, sc_informant::OutputFormat::Coloured);
let _informant_handle = runtime.spawn(informant_future); let _informant_handle = runtime.spawn(informant_future);
// we eagerly drop the service so that the internal exit future is fired, // we eagerly drop the service so that the internal exit future is fired,
+1 -1
View File
@@ -16,7 +16,7 @@ codec = { package = "parity-scale-codec", version = "1.0.0" }
sp-consensus = { version = "0.8", path = "../../../primitives/consensus/common" } sp-consensus = { version = "0.8", path = "../../../primitives/consensus/common" }
derive_more = "0.99.2" derive_more = "0.99.2"
futures = "0.3.1" futures = "0.3.1"
futures-timer = "0.4.0" futures-timer = "3.0.1"
sp-inherents = { version = "2.0.0", path = "../../../primitives/inherents" } sp-inherents = { version = "2.0.0", path = "../../../primitives/inherents" }
sc-keystore = { version = "2.0.0", path = "../../keystore" } sc-keystore = { version = "2.0.0", path = "../../keystore" }
log = "0.4.8" log = "0.4.8"
+1 -1
View File
@@ -32,7 +32,7 @@ sc-consensus-slots = { version = "0.8", path = "../slots" }
sp-runtime = { version = "2.0.0", path = "../../../primitives/runtime" } sp-runtime = { version = "2.0.0", path = "../../../primitives/runtime" }
fork-tree = { version = "2.0.0", path = "../../../utils/fork-tree" } fork-tree = { version = "2.0.0", path = "../../../utils/fork-tree" }
futures = "0.3.1" futures = "0.3.1"
futures-timer = "0.4.0" futures-timer = "3.0.1"
parking_lot = "0.10.0" parking_lot = "0.10.0"
log = "0.4.8" log = "0.4.8"
schnorrkel = { version = "0.8.5", features = ["preaudit_deprecated"] } schnorrkel = { version = "0.8.5", features = ["preaudit_deprecated"] }
+1 -1
View File
@@ -19,7 +19,7 @@ sc-telemetry = { version = "2.0.0", path = "../../telemetry" }
sp-consensus = { version = "0.8", path = "../../../primitives/consensus/common" } sp-consensus = { version = "0.8", path = "../../../primitives/consensus/common" }
sp-inherents = { version = "2.0.0", path = "../../../primitives/inherents" } sp-inherents = { version = "2.0.0", path = "../../../primitives/inherents" }
futures = "0.3.1" futures = "0.3.1"
futures-timer = "2.0" futures-timer = "3.0.1"
parking_lot = "0.10.0" parking_lot = "0.10.0"
log = "0.4.8" log = "0.4.8"
+1 -1
View File
@@ -8,7 +8,7 @@ license = "GPL-3.0"
[dependencies] [dependencies]
fork-tree = { version = "2.0.0", path = "../../utils/fork-tree" } fork-tree = { version = "2.0.0", path = "../../utils/fork-tree" }
futures = "0.3.1" futures = "0.3.1"
futures-timer = "2.0.2" futures-timer = "3.0.1"
log = "0.4.8" log = "0.4.8"
parking_lot = "0.10.0" parking_lot = "0.10.0"
rand = "0.7.2" rand = "0.7.2"
@@ -19,7 +19,7 @@
use futures_timer::Delay; use futures_timer::Delay;
use futures::{channel::mpsc, future::{FutureExt as _}, prelude::*, ready, stream::Stream}; use futures::{channel::mpsc, future::{FutureExt as _}, prelude::*, ready, stream::Stream};
use log::debug; use log::debug;
use std::{pin::Pin, task::{Context, Poll}, time::{Instant, Duration}}; use std::{pin::Pin, task::{Context, Poll}, time::Duration};
use sc_network::PeerId; use sc_network::PeerId;
use sp_runtime::traits::{NumberFor, Block as BlockT}; use sp_runtime::traits::{NumberFor, Block as BlockT};
@@ -28,10 +28,6 @@ use super::gossip::{NeighborPacket, GossipMessage};
// How often to rebroadcast, in cases where no new packets are created. // How often to rebroadcast, in cases where no new packets are created.
const REBROADCAST_AFTER: Duration = Duration::from_secs(2 * 60); const REBROADCAST_AFTER: Duration = Duration::from_secs(2 * 60);
fn rebroadcast_instant() -> Instant {
Instant::now() + REBROADCAST_AFTER
}
/// A sender used to send neighbor packets to a background job. /// A sender used to send neighbor packets to a background job.
#[derive(Clone)] #[derive(Clone)]
pub(super) struct NeighborPacketSender<B: BlockT>( pub(super) struct NeighborPacketSender<B: BlockT>(
@@ -85,7 +81,7 @@ impl <B: BlockT> Stream for NeighborPacketWorker<B> {
match this.rx.poll_next_unpin(cx) { match this.rx.poll_next_unpin(cx) {
Poll::Ready(None) => return Poll::Ready(None), Poll::Ready(None) => return Poll::Ready(None),
Poll::Ready(Some((to, packet))) => { Poll::Ready(Some((to, packet))) => {
this.delay.reset(rebroadcast_instant()); this.delay.reset(REBROADCAST_AFTER);
this.last = Some((to.clone(), packet.clone())); this.last = Some((to.clone(), packet.clone()));
return Poll::Ready(Some((to, GossipMessage::<B>::from(packet.clone())))); return Poll::Ready(Some((to, GossipMessage::<B>::from(packet.clone()))));
@@ -98,7 +94,7 @@ impl <B: BlockT> Stream for NeighborPacketWorker<B> {
// Getting this far here implies that the timer fired. // Getting this far here implies that the timer fired.
this.delay.reset(rebroadcast_instant()); this.delay.reset(REBROADCAST_AFTER);
// Make sure the underlying task is scheduled for wake-up. // Make sure the underlying task is scheduled for wake-up.
// //
+19
View File
@@ -0,0 +1,19 @@
[package]
name = "sc-informant"
version = "0.8.0"
authors = ["Parity Technologies <admin@parity.io>"]
description = "Substrate informant."
edition = "2018"
license = "GPL-3.0"
[dependencies]
ansi_term = "0.12.1"
futures = "0.3.1"
log = "0.4.8"
parity-util-mem = { version = "0.5.1", default-features = false, features = ["primitive-types"] }
wasm-timer = "0.2"
sc-client-api = { version = "2.0.0", path = "../api" }
sc-network = { version = "0.8", path = "../network" }
sc-service = { version = "0.8", default-features = false, path = "../service" }
sp-blockchain = { version = "2.0.0", path = "../../primitives/blockchain" }
sp-runtime = { version = "2.0.0", path = "../../primitives/runtime" }
@@ -20,7 +20,9 @@ use log::info;
use sc_network::SyncState; use sc_network::SyncState;
use sp_runtime::traits::{Block as BlockT, CheckedDiv, NumberFor, Zero, Saturating}; use sp_runtime::traits::{Block as BlockT, CheckedDiv, NumberFor, Zero, Saturating};
use sc_service::NetworkStatus; use sc_service::NetworkStatus;
use std::{convert::{TryFrom, TryInto}, fmt, time}; use std::{convert::{TryFrom, TryInto}, fmt};
use wasm_timer::Instant;
use crate::OutputFormat;
/// State of the informant display system. /// State of the informant display system.
/// ///
@@ -40,15 +42,18 @@ pub struct InformantDisplay<B: BlockT> {
/// `None` if `display` has never been called. /// `None` if `display` has never been called.
last_number: Option<NumberFor<B>>, last_number: Option<NumberFor<B>>,
/// The last time `display` or `new` has been called. /// The last time `display` or `new` has been called.
last_update: time::Instant, last_update: Instant,
/// The format to print output in.
format: OutputFormat,
} }
impl<B: BlockT> InformantDisplay<B> { impl<B: BlockT> InformantDisplay<B> {
/// Builds a new informant display system. /// Builds a new informant display system.
pub fn new() -> InformantDisplay<B> { pub fn new(format: OutputFormat) -> InformantDisplay<B> {
InformantDisplay { InformantDisplay {
last_number: None, last_number: None,
last_update: time::Instant::now(), last_update: Instant::now(),
format,
} }
} }
@@ -56,8 +61,10 @@ impl<B: BlockT> InformantDisplay<B> {
pub fn display(&mut self, info: &ClientInfo<B>, net_status: NetworkStatus<B>) { pub fn display(&mut self, info: &ClientInfo<B>, net_status: NetworkStatus<B>) {
let best_number = info.chain.best_number; let best_number = info.chain.best_number;
let best_hash = info.chain.best_hash; let best_hash = info.chain.best_hash;
let finalized_number = info.chain.finalized_number;
let num_connected_peers = net_status.num_connected_peers;
let speed = speed::<B>(best_number, self.last_number, self.last_update); let speed = speed::<B>(best_number, self.last_number, self.last_update);
self.last_update = time::Instant::now(); self.last_update = Instant::now();
self.last_number = Some(best_number); self.last_number = Some(best_number);
let (status, target) = match (net_status.sync_state, net_status.best_seen_block) { let (status, target) = match (net_status.sync_state, net_status.best_seen_block) {
@@ -66,19 +73,35 @@ impl<B: BlockT> InformantDisplay<B> {
(SyncState::Downloading, Some(n)) => (format!("Syncing{}", speed), format!(", target=#{}", n)), (SyncState::Downloading, Some(n)) => (format!("Syncing{}", speed), format!(", target=#{}", n)),
}; };
info!( if self.format == OutputFormat::Coloured {
target: "substrate", info!(
"{}{} ({} peers), best: #{} ({}), finalized #{} ({}), ⬇ {} ⬆ {}", target: "substrate",
Colour::White.bold().paint(&status), "{}{} ({} peers), best: #{} ({}), finalized #{} ({}), ⬇ {} ⬆ {}",
target, Colour::White.bold().paint(&status),
Colour::White.bold().paint(format!("{}", net_status.num_connected_peers)), target,
Colour::White.paint(format!("{}", best_number)), Colour::White.bold().paint(format!("{}", num_connected_peers)),
best_hash, Colour::White.paint(format!("{}", best_number)),
Colour::White.paint(format!("{}", info.chain.finalized_number)), best_hash,
info.chain.finalized_hash, Colour::White.paint(format!("{}", finalized_number)),
TransferRateFormat(net_status.average_download_per_sec), info.chain.finalized_hash,
TransferRateFormat(net_status.average_upload_per_sec), TransferRateFormat(net_status.average_download_per_sec),
); TransferRateFormat(net_status.average_upload_per_sec),
);
} else {
info!(
target: "substrate",
"{}{} ({} peers), best: #{} ({}), finalized #{} ({}), ⬇ {} ⬆ {}",
status,
target,
num_connected_peers,
best_number,
best_hash,
finalized_number,
info.chain.finalized_hash,
TransferRateFormat(net_status.average_download_per_sec),
TransferRateFormat(net_status.average_upload_per_sec),
);
}
} }
} }
@@ -87,7 +110,7 @@ impl<B: BlockT> InformantDisplay<B> {
fn speed<B: BlockT>( fn speed<B: BlockT>(
best_number: NumberFor<B>, best_number: NumberFor<B>,
last_number: Option<NumberFor<B>>, last_number: Option<NumberFor<B>>,
last_update: time::Instant last_update: Instant
) -> String { ) -> String {
// Number of milliseconds elapsed since last time. // Number of milliseconds elapsed since last time.
let elapsed_ms = { let elapsed_ms = {
@@ -25,12 +25,19 @@ use std::time::Duration;
mod display; mod display;
/// The format to print telemetry output in.
#[derive(PartialEq)]
pub enum OutputFormat {
Coloured,
Plain,
}
/// Creates an informant in the form of a `Future` that must be polled regularly. /// Creates an informant in the form of a `Future` that must be polled regularly.
pub fn build(service: &impl AbstractService) -> impl futures::Future<Output = ()> { pub fn build(service: &impl AbstractService, format: OutputFormat) -> impl futures::Future<Output = ()> {
let client = service.client(); let client = service.client();
let pool = service.transaction_pool(); let pool = service.transaction_pool();
let mut display = display::InformantDisplay::new(); let mut display = display::InformantDisplay::new(format);
let display_notifications = service let display_notifications = service
.network_status(Duration::from_millis(5000)) .network_status(Duration::from_millis(5000))
@@ -41,6 +48,7 @@ pub fn build(service: &impl AbstractService) -> impl futures::Future<Output = ()
} else { } else {
trace!(target: "usage", "Usage statistics not displayed as backend does not provide it") trace!(target: "usage", "Usage statistics not displayed as backend does not provide it")
} }
#[cfg(not(target_os = "unknown"))]
trace!( trace!(
target: "usage", target: "usage",
"Subsystems memory [txpool: {} kB]", "Subsystems memory [txpool: {} kB]",
+2 -1
View File
@@ -9,8 +9,9 @@ edition = "2018"
[dependencies] [dependencies]
log = "0.4.8" log = "0.4.8"
futures = { version = "0.3.1", features = ["compat"] } futures = { version = "0.3.1", features = ["compat"] }
wasm-timer = "0.2"
futures-timer = "3.0.1"
futures01 = { package = "futures", version = "0.1.29" } futures01 = { package = "futures", version = "0.1.29" }
futures-timer = "0.4.0"
libp2p = { version = "0.15.0", default-features = false, features = ["libp2p-websocket"] } libp2p = { version = "0.15.0", default-features = false, features = ["libp2p-websocket"] }
lru = "0.1.2" lru = "0.1.2"
parking_lot = "0.10.0" parking_lot = "0.10.0"
@@ -28,6 +28,7 @@ use sp_runtime::traits::{Block as BlockT, Hash, HashFor};
use sp_runtime::ConsensusEngineId; use sp_runtime::ConsensusEngineId;
pub use sc_network::message::generic::{Message, ConsensusMessage}; pub use sc_network::message::generic::{Message, ConsensusMessage};
use sc_network::config::Roles; use sc_network::config::Roles;
use wasm_timer::Instant;
// FIXME: Add additional spam/DoS attack protection: https://github.com/paritytech/substrate/issues/1115 // FIXME: Add additional spam/DoS attack protection: https://github.com/paritytech/substrate/issues/1115
const KNOWN_MESSAGES_CACHE_SIZE: usize = 4096; const KNOWN_MESSAGES_CACHE_SIZE: usize = 4096;
@@ -165,7 +166,7 @@ pub struct ConsensusGossip<B: BlockT> {
messages: Vec<MessageEntry<B>>, messages: Vec<MessageEntry<B>>,
known_messages: LruCache<B::Hash, ()>, known_messages: LruCache<B::Hash, ()>,
validators: HashMap<ConsensusEngineId, Arc<dyn Validator<B>>>, validators: HashMap<ConsensusEngineId, Arc<dyn Validator<B>>>,
next_broadcast: time::Instant, next_broadcast: Instant,
} }
impl<B: BlockT> ConsensusGossip<B> { impl<B: BlockT> ConsensusGossip<B> {
@@ -177,7 +178,7 @@ impl<B: BlockT> ConsensusGossip<B> {
messages: Default::default(), messages: Default::default(),
known_messages: LruCache::new(KNOWN_MESSAGES_CACHE_SIZE), known_messages: LruCache::new(KNOWN_MESSAGES_CACHE_SIZE),
validators: Default::default(), validators: Default::default(),
next_broadcast: time::Instant::now() + REBROADCAST_INTERVAL, next_broadcast: Instant::now() + REBROADCAST_INTERVAL,
} }
} }
@@ -260,9 +261,9 @@ impl<B: BlockT> ConsensusGossip<B> {
/// Perform periodic maintenance /// Perform periodic maintenance
pub fn tick(&mut self, network: &mut dyn Network<B>) { pub fn tick(&mut self, network: &mut dyn Network<B>) {
self.collect_garbage(); self.collect_garbage();
if time::Instant::now() >= self.next_broadcast { if Instant::now() >= self.next_broadcast {
self.rebroadcast(network); self.rebroadcast(network);
self.next_broadcast = time::Instant::now() + REBROADCAST_INTERVAL; self.next_broadcast = Instant::now() + REBROADCAST_INTERVAL;
} }
} }
+2 -1
View File
@@ -17,7 +17,8 @@ fnv = "1.0.6"
fork-tree = { version = "2.0.0", path = "../../utils/fork-tree" } fork-tree = { version = "2.0.0", path = "../../utils/fork-tree" }
futures = "0.3.1" futures = "0.3.1"
futures_codec = "0.3.3" futures_codec = "0.3.3"
futures-timer = "0.4.0" futures-timer = "3.0.1"
wasm-timer = "0.2"
libp2p = { version = "0.15.0", default-features = false, features = ["libp2p-websocket"] } libp2p = { version = "0.15.0", default-features = false, features = ["libp2p-websocket"] }
linked-hash-map = "0.5.2" linked-hash-map = "0.5.2"
linked_hash_set = "0.1.3" linked_hash_set = "0.1.3"
+2 -1
View File
@@ -28,7 +28,8 @@ use std::error;
use std::collections::hash_map::Entry; use std::collections::hash_map::Entry;
use std::pin::Pin; use std::pin::Pin;
use std::task::{Context, Poll}; use std::task::{Context, Poll};
use std::time::{Duration, Instant}; use std::time::Duration;
use wasm_timer::Instant;
use crate::utils::interval; use crate::utils::interval;
/// Time after we disconnect from a node before we purge its information from the cache. /// Time after we disconnect from a node before we purge its information from the cache.
+7 -6
View File
@@ -52,6 +52,7 @@ use crate::chain::{Client, FinalityProofProvider};
use sc_client_api::{FetchChecker, ChangesProof, StorageProof}; use sc_client_api::{FetchChecker, ChangesProof, StorageProof};
use crate::error; use crate::error;
use util::LruHashSet; use util::LruHashSet;
use wasm_timer::Instant;
mod legacy_proto; mod legacy_proto;
mod util; mod util;
@@ -158,7 +159,7 @@ struct PacketStats {
/// A peer that we are connected to /// A peer that we are connected to
/// and from whom we have not yet received a Status message. /// and from whom we have not yet received a Status message.
struct HandshakingPeer { struct HandshakingPeer {
timestamp: time::Instant, timestamp: Instant,
} }
/// Peer information /// Peer information
@@ -166,9 +167,9 @@ struct HandshakingPeer {
struct Peer<B: BlockT, H: ExHashT> { struct Peer<B: BlockT, H: ExHashT> {
info: PeerInfo<B>, info: PeerInfo<B>,
/// Current block request, if any. /// Current block request, if any.
block_request: Option<(time::Instant, message::BlockRequest<B>)>, block_request: Option<(Instant, message::BlockRequest<B>)>,
/// Requests we are no longer insterested in. /// Requests we are no longer insterested in.
obsolete_requests: HashMap<message::RequestId, time::Instant>, obsolete_requests: HashMap<message::RequestId, Instant>,
/// Holds a set of transactions known to this peer. /// Holds a set of transactions known to this peer.
known_extrinsics: LruHashSet<H>, known_extrinsics: LruHashSet<H>,
/// Holds a set of blocks known to this peer. /// Holds a set of blocks known to this peer.
@@ -701,7 +702,7 @@ impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> Protocol<B, S, H> {
/// Called when a new peer is connected /// Called when a new peer is connected
pub fn on_peer_connected(&mut self, who: PeerId) { pub fn on_peer_connected(&mut self, who: PeerId) {
trace!(target: "sync", "Connecting {}", who); trace!(target: "sync", "Connecting {}", who);
self.handshaking_peers.insert(who.clone(), HandshakingPeer { timestamp: time::Instant::now() }); self.handshaking_peers.insert(who.clone(), HandshakingPeer { timestamp: Instant::now() });
self.send_status(who); self.send_status(who);
} }
@@ -890,7 +891,7 @@ impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> Protocol<B, S, H> {
} }
fn maintain_peers(&mut self) { fn maintain_peers(&mut self) {
let tick = time::Instant::now(); let tick = Instant::now();
let mut aborting = Vec::new(); let mut aborting = Vec::new();
{ {
for (who, peer) in self.context_data.peers.iter() { for (who, peer) in self.context_data.peers.iter() {
@@ -1833,7 +1834,7 @@ fn send_request<B: BlockT, H: ExHashT>(
trace!(target: "sync", "Request {} for {} is now obsolete.", request.id, who); trace!(target: "sync", "Request {} for {} is now obsolete.", request.id, who);
peer.obsolete_requests.insert(request.id, timestamp); peer.obsolete_requests.insert(request.id, timestamp);
} }
peer.block_request = Some((time::Instant::now(), r.clone())); peer.block_request = Some((Instant::now(), r.clone()));
} }
} }
send_message::<B>(behaviour, stats, who, message) send_message::<B>(behaviour, stats, who, message)
@@ -26,7 +26,8 @@ use log::{debug, error, trace, warn};
use rand::distributions::{Distribution as _, Uniform}; use rand::distributions::{Distribution as _, Uniform};
use smallvec::SmallVec; use smallvec::SmallVec;
use std::{borrow::Cow, collections::hash_map::Entry, cmp, error, marker::PhantomData, mem, pin::Pin}; use std::{borrow::Cow, collections::hash_map::Entry, cmp, error, marker::PhantomData, mem, pin::Pin};
use std::time::{Duration, Instant}; use std::time::Duration;
use wasm_timer::Instant;
use std::task::{Context, Poll}; use std::task::{Context, Poll};
/// Network behaviour that handles opening substreams for custom protocols with other nodes. /// Network behaviour that handles opening substreams for custom protocols with other nodes.
@@ -387,7 +388,7 @@ impl<TSubstream> LegacyProto<TSubstream> {
debug!(target: "sub-libp2p", "PSM => Connect({:?}): Will start to connect at \ debug!(target: "sub-libp2p", "PSM => Connect({:?}): Will start to connect at \
until {:?}", occ_entry.key(), until); until {:?}", occ_entry.key(), until);
*occ_entry.into_mut() = PeerState::PendingRequest { *occ_entry.into_mut() = PeerState::PendingRequest {
timer: futures_timer::Delay::new_at(until.clone()), timer: futures_timer::Delay::new(until.clone() - Instant::now()),
timer_deadline: until.clone(), timer_deadline: until.clone(),
}; };
}, },
@@ -406,7 +407,7 @@ impl<TSubstream> LegacyProto<TSubstream> {
*occ_entry.into_mut() = PeerState::DisabledPendingEnable { *occ_entry.into_mut() = PeerState::DisabledPendingEnable {
connected_point: connected_point.clone(), connected_point: connected_point.clone(),
open, open,
timer: futures_timer::Delay::new_at(banned.clone()), timer: futures_timer::Delay::new(banned.clone() - Instant::now()),
timer_deadline: banned.clone(), timer_deadline: banned.clone(),
}; };
}, },
@@ -348,13 +348,12 @@ where
ProtocolState::Init { substreams, mut init_deadline } => { ProtocolState::Init { substreams, mut init_deadline } => {
match Pin::new(&mut init_deadline).poll(cx) { match Pin::new(&mut init_deadline).poll(cx) {
Poll::Ready(Ok(())) => { Poll::Ready(()) => {
init_deadline = Delay::new(Duration::from_secs(60)); init_deadline = Delay::new(Duration::from_secs(60));
error!(target: "sub-libp2p", "Handler initialization process is too long \ error!(target: "sub-libp2p", "Handler initialization process is too long \
with {:?}", self.remote_peer_id) with {:?}", self.remote_peer_id)
}, },
Poll::Pending => {} Poll::Pending => {}
Poll::Ready(Err(_)) => error!(target: "sub-libp2p", "Tokio timer has errored")
} }
self.state = ProtocolState::Init { substreams, init_deadline }; self.state = ProtocolState::Init { substreams, init_deadline };
@@ -363,7 +362,7 @@ where
ProtocolState::Opening { mut deadline } => { ProtocolState::Opening { mut deadline } => {
match Pin::new(&mut deadline).poll(cx) { match Pin::new(&mut deadline).poll(cx) {
Poll::Ready(Ok(())) => { Poll::Ready(()) => {
deadline = Delay::new(Duration::from_secs(60)); deadline = Delay::new(Duration::from_secs(60));
let event = CustomProtoHandlerOut::ProtocolError { let event = CustomProtoHandlerOut::ProtocolError {
is_severe: true, is_severe: true,
@@ -376,12 +375,6 @@ where
self.state = ProtocolState::Opening { deadline }; self.state = ProtocolState::Opening { deadline };
None None
}, },
Poll::Ready(Err(_)) => {
error!(target: "sub-libp2p", "Tokio timer has errored");
deadline = Delay::new(Duration::from_secs(60));
self.state = ProtocolState::Opening { deadline };
None
},
} }
} }
@@ -409,7 +409,7 @@ fn reconnect_after_disconnect() {
_ => panic!() _ => panic!()
} }
if let Poll::Ready(Ok(_)) = delay.poll_unpin(cx) { if let Poll::Ready(()) = delay.poll_unpin(cx) {
Poll::Ready(Ok(())) Poll::Ready(Ok(()))
} else { } else {
Poll::Pending Poll::Pending
@@ -21,7 +21,8 @@
use std::collections::{HashMap, VecDeque}; use std::collections::{HashMap, VecDeque};
use std::sync::Arc; use std::sync::Arc;
use std::time::{Instant, Duration}; use std::time::Duration;
use wasm_timer::Instant;
use log::{trace, info}; use log::{trace, info};
use futures::channel::oneshot::{Sender as OneShotSender}; use futures::channel::oneshot::{Sender as OneShotSender};
use linked_hash_map::{Entry, LinkedHashMap}; use linked_hash_map::{Entry, LinkedHashMap};
@@ -21,7 +21,8 @@ use libp2p::PeerId;
use log::{debug, trace, warn}; use log::{debug, trace, warn};
use sp_runtime::traits::{Block as BlockT, NumberFor, Zero}; use sp_runtime::traits::{Block as BlockT, NumberFor, Zero};
use std::collections::{HashMap, HashSet, VecDeque}; use std::collections::{HashMap, HashSet, VecDeque};
use std::time::{Duration, Instant}; use std::time::Duration;
use wasm_timer::Instant;
// Time to wait before trying to get the same extra data from the same peer. // Time to wait before trying to get the same extra data from the same peer.
const EXTRA_RETRY_WAIT: Duration = Duration::from_secs(10); const EXTRA_RETRY_WAIT: Duration = Duration::from_secs(10);
+11 -4
View File
@@ -118,11 +118,18 @@ pub fn build_transport(
core::upgrade::apply(stream, upgrade, endpoint, upgrade::Version::V1) core::upgrade::apply(stream, upgrade, endpoint, upgrade::Version::V1)
.map_ok(|(id, muxer)| (id, core::muxing::StreamMuxerBox::new(muxer))) .map_ok(|(id, muxer)| (id, core::muxing::StreamMuxerBox::new(muxer)))
}) });
.timeout(Duration::from_secs(20)) let transport = if cfg!(not(target_os = "unknown")) {
.map_err(|err| io::Error::new(io::ErrorKind::Other, err)) transport
.boxed(); .timeout(Duration::from_secs(20))
.map_err(|err| io::Error::new(io::ErrorKind::Other, err))
.boxed()
} else {
transport
.map_err(|err| io::Error::new(io::ErrorKind::Other, err))
.boxed()
};
(transport, sinks) (transport, sinks)
} }
+1 -1
View File
@@ -12,7 +12,7 @@ log = "0.4.8"
parking_lot = "0.10.0" parking_lot = "0.10.0"
futures = "0.1.29" futures = "0.1.29"
futures03 = { package = "futures", version = "0.3.1", features = ["compat"] } futures03 = { package = "futures", version = "0.3.1", features = ["compat"] }
futures-timer = "0.4.0" futures-timer = "3.0.1"
rand = "0.7.2" rand = "0.7.2"
libp2p = { version = "0.15.0", default-features = false, features = ["libp2p-websocket"] } libp2p = { version = "0.15.0", default-features = false, features = ["libp2p-websocket"] }
sp-consensus = { version = "0.8", path = "../../../primitives/consensus/common" } sp-consensus = { version = "0.8", path = "../../../primitives/consensus/common" }
+2 -2
View File
@@ -405,7 +405,7 @@ fn blocks_are_not_announced_by_light_nodes() {
net.peers.remove(0); net.peers.remove(0);
// Poll for a few seconds and make sure 1 and 2 (now 0 and 1) don't sync together. // Poll for a few seconds and make sure 1 and 2 (now 0 and 1) don't sync together.
let mut delay = futures_timer::Delay::new(Duration::from_secs(5)).compat(); let mut delay = futures_timer::Delay::new(Duration::from_secs(5)).unit_error().compat();
runtime.block_on(futures::future::poll_fn::<(), (), _>(|| { runtime.block_on(futures::future::poll_fn::<(), (), _>(|| {
net.poll(); net.poll();
delay.poll().map_err(|_| ()) delay.poll().map_err(|_| ())
@@ -504,7 +504,7 @@ fn can_not_sync_from_light_peer() {
net.peers.remove(0); net.peers.remove(0);
// ensure that the #2 (now #1) fails to sync block #1 even after 5 seconds // ensure that the #2 (now #1) fails to sync block #1 even after 5 seconds
let mut test_finished = futures_timer::Delay::new(Duration::from_secs(5)).compat(); let mut test_finished = futures_timer::Delay::new(Duration::from_secs(5)).unit_error().compat();
runtime.block_on(futures::future::poll_fn::<(), (), _>(|| -> Result<_, ()> { runtime.block_on(futures::future::poll_fn::<(), (), _>(|| -> Result<_, ()> {
net.poll(); net.poll();
test_finished.poll().map_err(|_| ()) test_finished.poll().map_err(|_| ())
+1 -1
View File
@@ -13,7 +13,7 @@ sp-api = { version = "2.0.0", path = "../../primitives/api" }
fnv = "1.0.6" fnv = "1.0.6"
futures01 = { package = "futures", version = "0.1" } futures01 = { package = "futures", version = "0.1" }
futures = "0.3.1" futures = "0.3.1"
futures-timer = "2.0" futures-timer = "3.0.1"
log = "0.4.8" log = "0.4.8"
threadpool = "1.7" threadpool = "1.7"
num_cpus = "1.10" num_cpus = "1.10"
+1
View File
@@ -12,6 +12,7 @@ futures = "0.3.1"
libp2p = { version = "0.15.0", default-features = false } libp2p = { version = "0.15.0", default-features = false }
log = "0.4.8" log = "0.4.8"
serde_json = "1.0.41" serde_json = "1.0.41"
wasm-timer = "0.2"
[dev-dependencies] [dev-dependencies]
rand = "0.7.2" rand = "0.7.2"
+2 -1
View File
@@ -19,12 +19,13 @@
mod peersstate; mod peersstate;
use std::{collections::{HashSet, HashMap}, collections::VecDeque, time::Instant}; use std::{collections::{HashSet, HashMap}, collections::VecDeque};
use futures::{prelude::*, channel::mpsc}; use futures::{prelude::*, channel::mpsc};
use libp2p::PeerId; use libp2p::PeerId;
use log::{debug, error, trace}; use log::{debug, error, trace};
use serde_json::json; use serde_json::json;
use std::{pin::Pin, task::Context, task::Poll}; use std::{pin::Pin, task::Context, task::Poll};
use wasm_timer::Instant;
/// We don't accept nodes whose reputation is under this value. /// We don't accept nodes whose reputation is under this value.
const BANNED_THRESHOLD: i32 = 82 * (i32::min_value() / 100); const BANNED_THRESHOLD: i32 = 82 * (i32::min_value() / 100);
+2 -1
View File
@@ -24,7 +24,8 @@ lazy_static = "1.4.0"
log = "0.4.8" log = "0.4.8"
slog = { version = "2.5.2", features = ["nested-values"] } slog = { version = "2.5.2", features = ["nested-values"] }
tokio-executor = "0.1.8" tokio-executor = "0.1.8"
futures-timer = "2" futures-timer = "3.0.1"
wasm-timer = "0.2"
exit-future = "0.2.0" exit-future = "0.2.0"
serde = "1.0.101" serde = "1.0.101"
serde_json = "1.0.41" serde_json = "1.0.41"
+9 -4
View File
@@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Substrate. If not, see <http://www.gnu.org/licenses/>. // along with Substrate. If not, see <http://www.gnu.org/licenses/>.
use crate::{Service, NetworkStatus, NetworkState, error::Error, DEFAULT_PROTOCOL_ID}; use crate::{Service, NetworkStatus, NetworkState, error::Error, DEFAULT_PROTOCOL_ID, MallocSizeOfWasm};
use crate::{SpawnTaskHandle, start_rpc_servers, build_network_future, TransactionPoolAdapter}; use crate::{SpawnTaskHandle, start_rpc_servers, build_network_future, TransactionPoolAdapter};
use crate::status_sinks; use crate::status_sinks;
use crate::config::{Configuration, DatabaseConfig, KeystoreConfig}; use crate::config::{Configuration, DatabaseConfig, KeystoreConfig};
@@ -46,8 +46,9 @@ use sc_executor::{NativeExecutor, NativeExecutionDispatch};
use std::{ use std::{
borrow::Cow, borrow::Cow,
io::{Read, Write, Seek}, io::{Read, Write, Seek},
marker::PhantomData, sync::Arc, time::SystemTime, pin::Pin marker::PhantomData, sync::Arc, pin::Pin
}; };
use wasm_timer::SystemTime;
use sysinfo::{get_current_pid, ProcessExt, System, SystemExt}; use sysinfo::{get_current_pid, ProcessExt, System, SystemExt};
use sc_telemetry::{telemetry, SUBSTRATE_INFO}; use sc_telemetry::{telemetry, SUBSTRATE_INFO};
use sp_transaction_pool::MaintainedTransactionPool; use sp_transaction_pool::MaintainedTransactionPool;
@@ -738,7 +739,7 @@ ServiceBuilder<
TSc: Clone, TSc: Clone,
TImpQu: 'static + ImportQueue<TBl>, TImpQu: 'static + ImportQueue<TBl>,
TNetP: NetworkSpecialization<TBl>, TNetP: NetworkSpecialization<TBl>,
TExPool: MaintainedTransactionPool<Block=TBl, Hash = <TBl as BlockT>::Hash> + 'static, TExPool: MaintainedTransactionPool<Block=TBl, Hash = <TBl as BlockT>::Hash> + MallocSizeOfWasm + 'static,
TRpc: sc_rpc::RpcExtension<sc_rpc::Metadata> + Clone, TRpc: sc_rpc::RpcExtension<sc_rpc::Metadata> + Clone,
{ {
@@ -984,6 +985,10 @@ ServiceBuilder<
"disk_read_per_sec" => info.usage.as_ref().map(|usage| usage.io.bytes_read).unwrap_or(0), "disk_read_per_sec" => info.usage.as_ref().map(|usage| usage.io.bytes_read).unwrap_or(0),
"disk_write_per_sec" => info.usage.as_ref().map(|usage| usage.io.bytes_written).unwrap_or(0), "disk_write_per_sec" => info.usage.as_ref().map(|usage| usage.io.bytes_written).unwrap_or(0),
); );
#[cfg(not(target_os = "unknown"))]
let memory_transaction_pool = parity_util_mem::malloc_size(&*transaction_pool_);
#[cfg(target_os = "unknown")]
let memory_transaction_pool = 0;
let _ = record_metrics!( let _ = record_metrics!(
"peers" => num_peers, "peers" => num_peers,
"height" => best_number, "height" => best_number,
@@ -997,7 +1002,7 @@ ServiceBuilder<
"used_db_cache_size" => info.usage.as_ref().map(|usage| usage.memory.database_cache).unwrap_or(0), "used_db_cache_size" => info.usage.as_ref().map(|usage| usage.memory.database_cache).unwrap_or(0),
"disk_read_per_sec" => info.usage.as_ref().map(|usage| usage.io.bytes_read).unwrap_or(0), "disk_read_per_sec" => info.usage.as_ref().map(|usage| usage.io.bytes_read).unwrap_or(0),
"disk_write_per_sec" => info.usage.as_ref().map(|usage| usage.io.bytes_written).unwrap_or(0), "disk_write_per_sec" => info.usage.as_ref().map(|usage| usage.io.bytes_written).unwrap_or(0),
"memory_transaction_pool" => parity_util_mem::malloc_size(&*transaction_pool_), "memory_transaction_pool" => memory_transaction_pool,
); );
ready(()) ready(())
+15 -3
View File
@@ -31,7 +31,8 @@ use std::{borrow::Cow, io, pin::Pin};
use std::marker::PhantomData; use std::marker::PhantomData;
use std::net::SocketAddr; use std::net::SocketAddr;
use std::collections::HashMap; use std::collections::HashMap;
use std::time::{Duration, Instant}; use std::time::Duration;
use wasm_timer::Instant;
use std::task::{Poll, Context}; use std::task::{Poll, Context};
use parking_lot::Mutex; use parking_lot::Mutex;
@@ -52,6 +53,7 @@ use log::{log, warn, debug, error, Level};
use codec::{Encode, Decode}; use codec::{Encode, Decode};
use sp_runtime::generic::BlockId; use sp_runtime::generic::BlockId;
use sp_runtime::traits::{NumberFor, Block as BlockT}; use sp_runtime::traits::{NumberFor, Block as BlockT};
use parity_util_mem::MallocSizeOf;
pub use self::error::Error; pub use self::error::Error;
pub use self::builder::{ pub use self::builder::{
@@ -73,6 +75,16 @@ pub use sc_network::{FinalityProofProvider, OnDemand, config::BoxFinalityProofRe
const DEFAULT_PROTOCOL_ID: &str = "sup"; 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<T: MallocSizeOf> MallocSizeOfWasm for T {}
#[cfg(target_os = "unknown")]
impl<T> MallocSizeOfWasm for T {}
/// Substrate service. /// Substrate service.
pub struct Service<TBl, TCl, TSc, TNetStatus, TNet, TTxPool, TOc> { pub struct Service<TBl, TCl, TSc, TNetStatus, TNet, TTxPool, TOc> {
client: Arc<TCl>, client: Arc<TCl>,
@@ -163,7 +175,7 @@ pub trait AbstractService: 'static + Future<Output = Result<(), Error>> +
/// Chain selection algorithm. /// Chain selection algorithm.
type SelectChain: sp_consensus::SelectChain<Self::Block>; type SelectChain: sp_consensus::SelectChain<Self::Block>;
/// Transaction pool. /// Transaction pool.
type TransactionPool: TransactionPool<Block = Self::Block>; type TransactionPool: TransactionPool<Block = Self::Block> + MallocSizeOfWasm;
/// Network specialization. /// Network specialization.
type NetworkSpecialization: NetworkSpecialization<Self::Block>; type NetworkSpecialization: NetworkSpecialization<Self::Block>;
@@ -227,7 +239,7 @@ where
TExec: 'static + sc_client::CallExecutor<TBl> + Send + Sync + Clone, TExec: 'static + sc_client::CallExecutor<TBl> + Send + Sync + Clone,
TRtApi: 'static + Send + Sync, TRtApi: 'static + Send + Sync,
TSc: sp_consensus::SelectChain<TBl> + 'static + Clone + Send + Unpin, TSc: sp_consensus::SelectChain<TBl> + 'static + Clone + Send + Unpin,
TExPool: 'static + TransactionPool<Block = TBl>, TExPool: 'static + TransactionPool<Block = TBl> + MallocSizeOfWasm,
TOc: 'static + Send + Sync, TOc: 'static + Send + Sync,
TNetSpec: NetworkSpecialization<TBl>, TNetSpec: NetworkSpecialization<TBl>,
{ {
+2 -1
View File
@@ -10,7 +10,8 @@ license = "GPL-3.0"
bytes = "0.5" bytes = "0.5"
parking_lot = "0.10.0" parking_lot = "0.10.0"
futures = "0.3.1" futures = "0.3.1"
futures-timer = "2.0.0" futures-timer = "3.0.1"
wasm-timer = "0.2.0"
libp2p = { version = "0.15.0", default-features = false, features = ["libp2p-websocket"] } libp2p = { version = "0.15.0", default-features = false, features = ["libp2p-websocket"] }
log = "0.4.8" log = "0.4.8"
pin-project = "0.4.6" pin-project = "0.4.6"
+2 -1
View File
@@ -63,7 +63,8 @@ use libp2p::{Multiaddr, wasm_ext};
use log::{error, warn}; use log::{error, warn};
use parking_lot::Mutex; use parking_lot::Mutex;
use serde::{Serialize, Deserialize}; use serde::{Serialize, Deserialize};
use std::{pin::Pin, sync::Arc, task::{Context, Poll}, time::{Duration, Instant}}; use std::{pin::Pin, sync::Arc, task::{Context, Poll}, time::Duration};
use wasm_timer::Instant;
pub use libp2p::wasm_ext::ExtTransport; pub use libp2p::wasm_ext::ExtTransport;
pub use slog_scope::with_logger; pub use slog_scope::with_logger;
+2 -2
View File
@@ -98,10 +98,10 @@ impl TelemetryWorker {
.map_ok(|data| BytesMut::from(data.as_ref())); .map_ok(|data| BytesMut::from(data.as_ref()));
future::ready(Ok::<_, io::Error>(connec)) future::ready(Ok::<_, io::Error>(connec))
}) })
}); })
.timeout(CONNECT_TIMEOUT);
let transport = transport let transport = transport
.timeout(CONNECT_TIMEOUT)
.map_err(|err| io::Error::new(io::ErrorKind::Other, err)) .map_err(|err| io::Error::new(io::ErrorKind::Other, err))
.map(|out, _| { .map(|out, _| {
let out = out let out = out
@@ -12,6 +12,7 @@ futures = { version = "0.3.1", features = ["compat"] }
futures-diagnose = "1.0" futures-diagnose = "1.0"
log = "0.4.8" log = "0.4.8"
parking_lot = "0.10.0" parking_lot = "0.10.0"
wasm-timer = "0.2"
sp-core = { version = "2.0.0", path = "../../primitives/core" } sp-core = { version = "2.0.0", path = "../../primitives/core" }
sp-api = { version = "2.0.0", path = "../../primitives/api" } sp-api = { version = "2.0.0", path = "../../primitives/api" }
sp-runtime = { version = "2.0.0", path = "../../primitives/runtime" } sp-runtime = { version = "2.0.0", path = "../../primitives/runtime" }
@@ -11,6 +11,7 @@ futures = "0.3.1"
log = "0.4.8" log = "0.4.8"
parking_lot = "0.10.0" parking_lot = "0.10.0"
serde = { version = "1.0.101", features = ["derive"] } serde = { version = "1.0.101", features = ["derive"] }
wasm-timer = "0.2"
sp-core = { version = "2.0.0", path = "../../../primitives/core" } sp-core = { version = "2.0.0", path = "../../../primitives/core" }
sp-runtime = { version = "2.0.0", path = "../../../primitives/runtime" } sp-runtime = { version = "2.0.0", path = "../../../primitives/runtime" }
sp-transaction-pool = { version = "2.0.0", path = "../../../primitives/transaction-pool" } sp-transaction-pool = { version = "2.0.0", path = "../../../primitives/transaction-pool" }
@@ -209,7 +209,8 @@ const RECENTLY_PRUNED_TAGS: usize = 2;
/// as-is for the second time will fail or produce unwanted results. /// as-is for the second time will fail or produce unwanted results.
/// Most likely it is required to revalidate them and recompute set of /// Most likely it is required to revalidate them and recompute set of
/// required tags. /// required tags.
#[derive(Debug, parity_util_mem::MallocSizeOf)] #[derive(Debug)]
#[cfg_attr(not(target_os = "unknown"), derive(parity_util_mem::MallocSizeOf))]
pub struct BasePool<Hash: hash::Hash + Eq, Ex> { pub struct BasePool<Hash: hash::Hash + Eq, Ex> {
reject_future_transactions: bool, reject_future_transactions: bool,
future: FutureTransactions<Hash, Ex>, future: FutureTransactions<Hash, Ex>,
@@ -19,17 +19,17 @@ use std::{
fmt, fmt,
hash, hash,
sync::Arc, sync::Arc,
time,
}; };
use sp_core::hexdisplay::HexDisplay; use sp_core::hexdisplay::HexDisplay;
use sp_runtime::transaction_validity::{ use sp_runtime::transaction_validity::{
TransactionTag as Tag, TransactionTag as Tag,
}; };
use wasm_timer::Instant;
use crate::base_pool::Transaction; use crate::base_pool::Transaction;
#[derive(parity_util_mem::MallocSizeOf)] #[cfg_attr(not(target_os = "unknown"), derive(parity_util_mem::MallocSizeOf))]
/// Transaction with partially satisfied dependencies. /// Transaction with partially satisfied dependencies.
pub struct WaitingTransaction<Hash, Ex> { pub struct WaitingTransaction<Hash, Ex> {
/// Transaction details. /// Transaction details.
@@ -37,7 +37,7 @@ pub struct WaitingTransaction<Hash, Ex> {
/// Tags that are required and have not been satisfied yet by other transactions in the pool. /// Tags that are required and have not been satisfied yet by other transactions in the pool.
pub missing_tags: HashSet<Tag>, pub missing_tags: HashSet<Tag>,
/// Time of import to the Future Queue. /// Time of import to the Future Queue.
pub imported_at: time::Instant, pub imported_at: Instant,
} }
impl<Hash: fmt::Debug, Ex: fmt::Debug> fmt::Debug for WaitingTransaction<Hash, Ex> { impl<Hash: fmt::Debug, Ex: fmt::Debug> fmt::Debug for WaitingTransaction<Hash, Ex> {
@@ -91,7 +91,7 @@ impl<Hash, Ex> WaitingTransaction<Hash, Ex> {
WaitingTransaction { WaitingTransaction {
transaction: Arc::new(transaction), transaction: Arc::new(transaction),
missing_tags, missing_tags,
imported_at: time::Instant::now(), imported_at: Instant::now(),
} }
} }
@@ -110,7 +110,8 @@ impl<Hash, Ex> WaitingTransaction<Hash, Ex> {
/// ///
/// Contains transactions that are still awaiting for some other transactions that /// Contains transactions that are still awaiting for some other transactions that
/// could provide a tag that they require. /// could provide a tag that they require.
#[derive(Debug, parity_util_mem::MallocSizeOf)] #[derive(Debug)]
#[cfg_attr(not(target_os = "unknown"), derive(parity_util_mem::MallocSizeOf))]
pub struct FutureTransactions<Hash: hash::Hash + Eq, Ex> { pub struct FutureTransactions<Hash: hash::Hash + Eq, Ex> {
/// tags that are not yet provided by any transaction and we await for them /// tags that are not yet provided by any transaction and we await for them
wanted_tags: HashMap<Tag, HashSet<Hash>>, wanted_tags: HashMap<Tag, HashSet<Hash>>,
@@ -34,6 +34,7 @@ use sp_runtime::{
transaction_validity::{TransactionValidity, TransactionTag as Tag, TransactionValidityError}, transaction_validity::{TransactionValidity, TransactionTag as Tag, TransactionValidityError},
}; };
use sp_transaction_pool::{error, PoolStatus}; use sp_transaction_pool::{error, PoolStatus};
use wasm_timer::Instant;
use crate::validated_pool::{ValidatedPool, ValidatedTransaction}; use crate::validated_pool::{ValidatedPool, ValidatedTransaction};
@@ -122,6 +123,7 @@ pub struct Pool<B: ChainApi> {
validated_pool: Arc<ValidatedPool<B>>, validated_pool: Arc<ValidatedPool<B>>,
} }
#[cfg(not(target_os = "unknown"))]
impl<B: ChainApi> parity_util_mem::MallocSizeOf for Pool<B> impl<B: ChainApi> parity_util_mem::MallocSizeOf for Pool<B>
where where
B::Hash: parity_util_mem::MallocSizeOf, B::Hash: parity_util_mem::MallocSizeOf,
@@ -189,7 +191,6 @@ impl<B: ChainApi> Pool<B> {
at: &BlockId<B::Block>, at: &BlockId<B::Block>,
max: Option<usize>, max: Option<usize>,
) -> Result<(), B::Error> { ) -> Result<(), B::Error> {
use std::time::Instant;
log::debug!(target: "txpool", log::debug!(target: "txpool",
"Fetching ready transactions (up to: {})", "Fetching ready transactions (up to: {})",
max.map(|x| format!("{}", x)).unwrap_or_else(|| "all".into()) max.map(|x| format!("{}", x)).unwrap_or_else(|| "all".into())
@@ -317,7 +318,7 @@ impl<B: ChainApi> Pool<B> {
// Make sure that we don't revalidate extrinsics that were part of the recently // Make sure that we don't revalidate extrinsics that were part of the recently
// imported block. This is especially important for UTXO-like chains cause the // imported block. This is especially important for UTXO-like chains cause the
// inputs are pruned so such transaction would go to future again. // inputs are pruned so such transaction would go to future again.
self.validated_pool.ban(&std::time::Instant::now(), known_imported_hashes.clone().into_iter()); self.validated_pool.ban(&Instant::now(), known_imported_hashes.clone().into_iter());
// Try to re-validate pruned transactions since some of them might be still valid. // Try to re-validate pruned transactions since some of them might be still valid.
// note that `known_imported_hashes` will be rejected here due to temporary ban. // note that `known_imported_hashes` will be rejected here due to temporary ban.
@@ -469,10 +470,7 @@ impl<B: ChainApi> Clone for Pool<B> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use std::{ use std::collections::{HashMap, HashSet};
collections::{HashMap, HashSet},
time::Instant,
};
use parking_lot::Mutex; use parking_lot::Mutex;
use futures::executor::block_on; use futures::executor::block_on;
use super::*; use super::*;
@@ -481,6 +479,7 @@ mod tests {
use codec::Encode; use codec::Encode;
use substrate_test_runtime::{Block, Extrinsic, Transfer, H256, AccountId}; use substrate_test_runtime::{Block, Extrinsic, Transfer, H256, AccountId};
use assert_matches::assert_matches; use assert_matches::assert_matches;
use wasm_timer::Instant;
use crate::base_pool::Limit; use crate::base_pool::Limit;
const INVALID_NONCE: u64 = 254; const INVALID_NONCE: u64 = 254;
@@ -23,9 +23,10 @@ use std::{
collections::HashMap, collections::HashMap,
hash, hash,
iter, iter,
time::{Duration, Instant}, time::Duration,
}; };
use parking_lot::RwLock; use parking_lot::RwLock;
use wasm_timer::Instant;
use crate::base_pool::Transaction; use crate::base_pool::Transaction;
@@ -19,7 +19,6 @@ use std::{
fmt, fmt,
hash, hash,
sync::Arc, sync::Arc,
time,
}; };
use crate::base_pool as base; use crate::base_pool as base;
@@ -37,6 +36,7 @@ use sp_runtime::{
transaction_validity::TransactionTag as Tag, transaction_validity::TransactionTag as Tag,
}; };
use sp_transaction_pool::{error, PoolStatus}; use sp_transaction_pool::{error, PoolStatus};
use wasm_timer::Instant;
use crate::base_pool::PruneStatus; use crate::base_pool::PruneStatus;
use crate::pool::{EventStream, Options, ChainApi, BlockHash, ExHash, ExtrinsicFor, TransactionFor}; use crate::pool::{EventStream, Options, ChainApi, BlockHash, ExHash, ExtrinsicFor, TransactionFor};
@@ -74,6 +74,7 @@ pub(crate) struct ValidatedPool<B: ChainApi> {
rotator: PoolRotator<ExHash<B>>, rotator: PoolRotator<ExHash<B>>,
} }
#[cfg(not(target_os = "unknown"))]
impl<B: ChainApi> parity_util_mem::MallocSizeOf for ValidatedPool<B> impl<B: ChainApi> parity_util_mem::MallocSizeOf for ValidatedPool<B>
where where
B::Hash: parity_util_mem::MallocSizeOf, B::Hash: parity_util_mem::MallocSizeOf,
@@ -100,7 +101,7 @@ impl<B: ChainApi> ValidatedPool<B> {
} }
/// Bans given set of hashes. /// Bans given set of hashes.
pub fn ban(&self, now: &std::time::Instant, hashes: impl IntoIterator<Item=ExHash<B>>) { pub fn ban(&self, now: &Instant, hashes: impl IntoIterator<Item=ExHash<B>>) {
self.rotator.ban(now, hashes) self.rotator.ban(now, hashes)
} }
@@ -145,7 +146,7 @@ impl<B: ChainApi> ValidatedPool<B> {
Ok(imported.hash().clone()) Ok(imported.hash().clone())
} }
ValidatedTransaction::Invalid(hash, err) => { ValidatedTransaction::Invalid(hash, err) => {
self.rotator.ban(&std::time::Instant::now(), std::iter::once(hash)); self.rotator.ban(&Instant::now(), std::iter::once(hash));
Err(err.into()) Err(err.into())
}, },
ValidatedTransaction::Unknown(hash, err) => { ValidatedTransaction::Unknown(hash, err) => {
@@ -177,7 +178,7 @@ impl<B: ChainApi> ValidatedPool<B> {
let removed = pool.enforce_limits(ready_limit, future_limit) let removed = pool.enforce_limits(ready_limit, future_limit)
.into_iter().map(|x| x.hash.clone()).collect::<HashSet<_>>(); .into_iter().map(|x| x.hash.clone()).collect::<HashSet<_>>();
// ban all removed transactions // ban all removed transactions
self.rotator.ban(&std::time::Instant::now(), removed.iter().map(|x| x.clone())); self.rotator.ban(&Instant::now(), removed.iter().map(|x| x.clone()));
removed removed
}; };
// run notifications // run notifications
@@ -208,7 +209,7 @@ impl<B: ChainApi> ValidatedPool<B> {
.map(|_| watcher) .map(|_| watcher)
}, },
ValidatedTransaction::Invalid(hash, err) => { ValidatedTransaction::Invalid(hash, err) => {
self.rotator.ban(&std::time::Instant::now(), std::iter::once(hash)); self.rotator.ban(&Instant::now(), std::iter::once(hash));
Err(err.into()) Err(err.into())
}, },
ValidatedTransaction::Unknown(_, err) => Err(err.into()), ValidatedTransaction::Unknown(_, err) => Err(err.into()),
@@ -430,7 +431,7 @@ impl<B: ChainApi> ValidatedPool<B> {
let block_number = self.api.block_id_to_number(at)? let block_number = self.api.block_id_to_number(at)?
.ok_or_else(|| error::Error::InvalidBlockId(format!("{:?}", at)).into())? .ok_or_else(|| error::Error::InvalidBlockId(format!("{:?}", at)).into())?
.saturated_into::<u64>(); .saturated_into::<u64>();
let now = time::Instant::now(); let now = Instant::now();
let to_remove = { let to_remove = {
self.ready() self.ready()
.filter(|tx| self.rotator.ban_if_stale(&now, block_number, &tx)) .filter(|tx| self.rotator.ban_if_stale(&now, block_number, &tx))
@@ -497,7 +498,7 @@ impl<B: ChainApi> ValidatedPool<B> {
debug!(target: "txpool", "Removing invalid transactions: {:?}", hashes); debug!(target: "txpool", "Removing invalid transactions: {:?}", hashes);
// temporarily ban invalid transactions // temporarily ban invalid transactions
self.rotator.ban(&time::Instant::now(), hashes.iter().cloned()); self.rotator.ban(&Instant::now(), hashes.iter().cloned());
let invalid = self.pool.write().remove_subtree(hashes); let invalid = self.pool.write().remove_subtree(hashes);
+4 -2
View File
@@ -28,7 +28,7 @@ pub mod testing;
pub use sc_transaction_graph as txpool; pub use sc_transaction_graph as txpool;
pub use crate::api::{FullChainApi, LightChainApi}; pub use crate::api::{FullChainApi, LightChainApi};
use std::{collections::HashMap, sync::Arc, pin::Pin, time::Instant}; use std::{collections::HashMap, sync::Arc, pin::Pin};
use futures::{Future, FutureExt, future::ready}; use futures::{Future, FutureExt, future::ready};
use parking_lot::Mutex; use parking_lot::Mutex;
@@ -41,6 +41,7 @@ use sp_transaction_pool::{
TxHash, TransactionFor, TransactionStatusStreamFor, BlockHash, TxHash, TransactionFor, TransactionStatusStreamFor, BlockHash,
MaintainedTransactionPool, PoolFuture, MaintainedTransactionPool, PoolFuture,
}; };
use wasm_timer::Instant;
/// Basic implementation of transaction pool that can be customized by providing PoolApi. /// Basic implementation of transaction pool that can be customized by providing PoolApi.
pub struct BasicPool<PoolApi, Block> pub struct BasicPool<PoolApi, Block>
@@ -53,6 +54,7 @@ pub struct BasicPool<PoolApi, Block>
revalidation_strategy: Arc<Mutex<RevalidationStrategy<NumberFor<Block>>>>, revalidation_strategy: Arc<Mutex<RevalidationStrategy<NumberFor<Block>>>>,
} }
#[cfg(not(target_os = "unknown"))]
impl<PoolApi, Block> parity_util_mem::MallocSizeOf for BasicPool<PoolApi, Block> impl<PoolApi, Block> parity_util_mem::MallocSizeOf for BasicPool<PoolApi, Block>
where where
PoolApi: sc_transaction_graph::ChainApi<Block=Block, Hash=Block::Hash>, PoolApi: sc_transaction_graph::ChainApi<Block=Block, Hash=Block::Hash>,
@@ -205,7 +207,7 @@ enum RevalidationStatus<N> {
/// The revalidation has never been completed. /// The revalidation has never been completed.
NotScheduled, NotScheduled,
/// The revalidation is scheduled. /// The revalidation is scheduled.
Scheduled(Option<std::time::Instant>, Option<N>), Scheduled(Option<Instant>, Option<N>),
/// The revalidation is in progress. /// The revalidation is in progress.
InProgress, InProgress,
} }
@@ -14,7 +14,7 @@ sp-core = { path= "../../core" }
sp-inherents = { version = "2.0.0", path = "../../inherents" } sp-inherents = { version = "2.0.0", path = "../../inherents" }
sp-state-machine = { version = "0.8.0", path = "../../../primitives/state-machine" } sp-state-machine = { version = "0.8.0", path = "../../../primitives/state-machine" }
futures = { version = "0.3.1", features = ["thread-pool"] } futures = { version = "0.3.1", features = ["thread-pool"] }
futures-timer = "0.4.0" futures-timer = "3.0.1"
futures-diagnose = "1.0" futures-diagnose = "1.0"
sp-std = { version = "2.0.0", path = "../../std" } sp-std = { version = "2.0.0", path = "../../std" }
sp-version = { version = "2.0.0", path = "../../version" } sp-version = { version = "2.0.0", path = "../../version" }
@@ -12,6 +12,7 @@ sp-runtime = { version = "2.0.0", default-features = false, path = "../runtime"
codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] } codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] }
sp-inherents = { version = "2.0.0", default-features = false, path = "../inherents" } sp-inherents = { version = "2.0.0", default-features = false, path = "../inherents" }
impl-trait-for-tuples = "0.1.3" impl-trait-for-tuples = "0.1.3"
wasm-timer = "0.2"
[features] [features]
default = [ "std" ] default = [ "std" ]
+1 -1
View File
@@ -90,7 +90,7 @@ impl ProvideInherentData for InherentDataProvider {
&self, &self,
inherent_data: &mut InherentData, inherent_data: &mut InherentData,
) -> Result<(), sp_inherents::Error> { ) -> Result<(), sp_inherents::Error> {
use std::time::SystemTime; use wasm_timer::SystemTime;
let now = SystemTime::now(); let now = SystemTime::now();
now.duration_since(SystemTime::UNIX_EPOCH) now.duration_since(SystemTime::UNIX_EPOCH)
@@ -29,7 +29,7 @@ use futures::{
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use sp_runtime::{ use sp_runtime::{
generic::BlockId, generic::BlockId,
traits::{Block as BlockT, Member, MaybeMallocSizeOf}, traits::{Block as BlockT, Member},
transaction_validity::{ transaction_validity::{
TransactionLongevity, TransactionPriority, TransactionTag, TransactionLongevity, TransactionPriority, TransactionTag,
}, },
@@ -154,7 +154,7 @@ pub trait InPoolTransaction {
} }
/// Transaction pool interface. /// Transaction pool interface.
pub trait TransactionPool: Send + Sync + MaybeMallocSizeOf { pub trait TransactionPool: Send + Sync {
/// Block type. /// Block type.
type Block: BlockT; type Block: BlockT;
/// Transaction hash type. /// Transaction hash type.
+6 -3
View File
@@ -17,12 +17,15 @@ js-sys = "0.3.34"
wasm-bindgen = "0.2.57" wasm-bindgen = "0.2.57"
wasm-bindgen-futures = "0.4.7" wasm-bindgen-futures = "0.4.7"
kvdb-web = "0.4" kvdb-web = "0.4"
service = { version = "0.8", package = "sc-service", path = "../../client/service", default-features = false } sc-informant = { version = "0.8", path = "../../client/informant" }
network = { package = "sc-network", path = "../../client/network" } sc-service = { version = "0.8", path = "../../client/service", default-features = false }
chain-spec = { package = "sc-chain-spec", path = "../../client/chain-spec" } sc-network = { path = "../../client/network" }
sc-chain-spec = { path = "../../client/chain-spec" }
# Imported just for the `no_cc` feature # Imported just for the `no_cc` feature
clear_on_drop = { version = "0.2.3", features = ["no_cc"] } clear_on_drop = { version = "0.2.3", features = ["no_cc"] }
# Imported just for the `wasm-bindgen` feature # Imported just for the `wasm-bindgen` feature
rand6 = { package = "rand", version = "0.6", features = ["wasm-bindgen"] } rand6 = { package = "rand", version = "0.6", features = ["wasm-bindgen"] }
rand = { version = "0.7", features = ["wasm-bindgen"] } rand = { version = "0.7", features = ["wasm-bindgen"] }
futures-timer = { version = "3.0.1", features = ["wasm-bindgen"]}
chrono = { version = "0.4", features = ["wasmbind"] }
+11 -3
View File
@@ -17,7 +17,7 @@
use futures01::sync::mpsc as mpsc01; use futures01::sync::mpsc as mpsc01;
use log::{debug, info}; use log::{debug, info};
use std::sync::Arc; use std::sync::Arc;
use service::{ use sc_service::{
AbstractService, RpcSession, Roles, Configuration, config::{DatabaseConfig, KeystoreConfig}, AbstractService, RpcSession, Roles, Configuration, config::{DatabaseConfig, KeystoreConfig},
ChainSpec, RuntimeGenesis ChainSpec, RuntimeGenesis
}; };
@@ -25,7 +25,7 @@ use wasm_bindgen::prelude::*;
use futures::{prelude::*, channel::{oneshot, mpsc}, future::{poll_fn, ok}, compat::*}; use futures::{prelude::*, channel::{oneshot, mpsc}, future::{poll_fn, ok}, compat::*};
use std::task::Poll; use std::task::Poll;
use std::pin::Pin; use std::pin::Pin;
use chain_spec::Extension; use sc_chain_spec::Extension;
pub use libp2p::wasm_ext::{ExtTransport, ffi::Transport}; pub use libp2p::wasm_ext::{ExtTransport, ffi::Transport};
pub use console_error_panic_hook::set_once as set_console_error_panic_hook; pub use console_error_panic_hook::set_once as set_console_error_panic_hook;
@@ -46,7 +46,10 @@ where
let transport = ExtTransport::new(transport); let transport = ExtTransport::new(transport);
let mut config = Configuration::default(); let mut config = Configuration::default();
config.network.transport = network::config::TransportConfig::Normal { config.network.boot_nodes = chain_spec.boot_nodes().to_vec();
config.telemetry_endpoints = chain_spec.telemetry_endpoints().clone();
config.chain_spec = Some(chain_spec);
config.network.transport = sc_network::config::TransportConfig::Normal {
wasm_external_transport: Some(transport.clone()), wasm_external_transport: Some(transport.clone()),
allow_private_ipv4: true, allow_private_ipv4: true,
enable_mdns: false, enable_mdns: false,
@@ -82,6 +85,11 @@ struct RpcMessage {
/// Create a Client object that connects to a service. /// Create a Client object that connects to a service.
pub fn start_client(mut service: impl AbstractService) -> Client { pub fn start_client(mut service: impl AbstractService) -> Client {
// Spawn informant
wasm_bindgen_futures::spawn_local(
sc_informant::build(&service, sc_informant::OutputFormat::Plain).map(drop)
);
// We dispatch a background task responsible for processing the service. // We dispatch a background task responsible for processing the service.
// //
// The main action performed by the code below consists in polling the service with // The main action performed by the code below consists in polling the service with
@@ -16,7 +16,7 @@ serde = { version = "1", features = ["derive"] }
chrono = { version = "0.4", features = ["serde"] } chrono = { version = "0.4", features = ["serde"] }
lazy_static = "1.4" lazy_static = "1.4"
parking_lot = "0.10.0" parking_lot = "0.10.0"
futures-timer = "2.0" futures-timer = "3.0.1"
derive_more = "0.99" derive_more = "0.99"
[target.'cfg(not(target_os = "unknown"))'.dependencies] [target.'cfg(not(target_os = "unknown"))'.dependencies]
@@ -9,5 +9,5 @@ edition = "2018"
[dependencies] [dependencies]
grafana-data-source = { version = "0.8", path = ".." } grafana-data-source = { version = "0.8", path = ".." }
futures = "0.3" futures = "0.3"
futures-timer = "2.0" futures-timer = "3.0.1"
rand = "0.7" rand = "0.7"