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
@@ -209,7 +209,8 @@ 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, 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> {
reject_future_transactions: bool,
future: FutureTransactions<Hash, Ex>,
@@ -19,17 +19,17 @@ use std::{
fmt,
hash,
sync::Arc,
time,
};
use sp_core::hexdisplay::HexDisplay;
use sp_runtime::transaction_validity::{
TransactionTag as Tag,
};
use wasm_timer::Instant;
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.
pub struct WaitingTransaction<Hash, Ex> {
/// 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.
pub missing_tags: HashSet<Tag>,
/// 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> {
@@ -91,7 +91,7 @@ impl<Hash, Ex> WaitingTransaction<Hash, Ex> {
WaitingTransaction {
transaction: Arc::new(transaction),
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
/// 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> {
/// tags that are not yet provided by any transaction and we await for them
wanted_tags: HashMap<Tag, HashSet<Hash>>,
@@ -34,6 +34,7 @@ use sp_runtime::{
transaction_validity::{TransactionValidity, TransactionTag as Tag, TransactionValidityError},
};
use sp_transaction_pool::{error, PoolStatus};
use wasm_timer::Instant;
use crate::validated_pool::{ValidatedPool, ValidatedTransaction};
@@ -122,6 +123,7 @@ pub struct Pool<B: ChainApi> {
validated_pool: Arc<ValidatedPool<B>>,
}
#[cfg(not(target_os = "unknown"))]
impl<B: ChainApi> parity_util_mem::MallocSizeOf for Pool<B>
where
B::Hash: parity_util_mem::MallocSizeOf,
@@ -189,7 +191,6 @@ impl<B: ChainApi> Pool<B> {
at: &BlockId<B::Block>,
max: Option<usize>,
) -> Result<(), B::Error> {
use std::time::Instant;
log::debug!(target: "txpool",
"Fetching ready transactions (up to: {})",
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
// imported block. This is especially important for UTXO-like chains cause the
// 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.
// 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)]
mod tests {
use std::{
collections::{HashMap, HashSet},
time::Instant,
};
use std::collections::{HashMap, HashSet};
use parking_lot::Mutex;
use futures::executor::block_on;
use super::*;
@@ -481,6 +479,7 @@ mod tests {
use codec::Encode;
use substrate_test_runtime::{Block, Extrinsic, Transfer, H256, AccountId};
use assert_matches::assert_matches;
use wasm_timer::Instant;
use crate::base_pool::Limit;
const INVALID_NONCE: u64 = 254;
@@ -23,9 +23,10 @@ use std::{
collections::HashMap,
hash,
iter,
time::{Duration, Instant},
time::Duration,
};
use parking_lot::RwLock;
use wasm_timer::Instant;
use crate::base_pool::Transaction;
@@ -19,7 +19,6 @@ use std::{
fmt,
hash,
sync::Arc,
time,
};
use crate::base_pool as base;
@@ -37,6 +36,7 @@ use sp_runtime::{
transaction_validity::TransactionTag as Tag,
};
use sp_transaction_pool::{error, PoolStatus};
use wasm_timer::Instant;
use crate::base_pool::PruneStatus;
use crate::pool::{EventStream, Options, ChainApi, BlockHash, ExHash, ExtrinsicFor, TransactionFor};
@@ -74,6 +74,7 @@ pub(crate) struct ValidatedPool<B: ChainApi> {
rotator: PoolRotator<ExHash<B>>,
}
#[cfg(not(target_os = "unknown"))]
impl<B: ChainApi> parity_util_mem::MallocSizeOf for ValidatedPool<B>
where
B::Hash: parity_util_mem::MallocSizeOf,
@@ -100,7 +101,7 @@ impl<B: ChainApi> ValidatedPool<B> {
}
/// 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)
}
@@ -145,7 +146,7 @@ impl<B: ChainApi> ValidatedPool<B> {
Ok(imported.hash().clone())
}
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())
},
ValidatedTransaction::Unknown(hash, err) => {
@@ -177,7 +178,7 @@ impl<B: ChainApi> ValidatedPool<B> {
let removed = pool.enforce_limits(ready_limit, future_limit)
.into_iter().map(|x| x.hash.clone()).collect::<HashSet<_>>();
// 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
};
// run notifications
@@ -208,7 +209,7 @@ impl<B: ChainApi> ValidatedPool<B> {
.map(|_| watcher)
},
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())
},
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)?
.ok_or_else(|| error::Error::InvalidBlockId(format!("{:?}", at)).into())?
.saturated_into::<u64>();
let now = time::Instant::now();
let now = Instant::now();
let to_remove = {
self.ready()
.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);
// 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);