diff --git a/substrate/core/transaction-pool/Cargo.toml b/substrate/core/transaction-pool/Cargo.toml index 8d16144f90..aa31092659 100644 --- a/substrate/core/transaction-pool/Cargo.toml +++ b/substrate/core/transaction-pool/Cargo.toml @@ -2,6 +2,7 @@ name = "substrate-transaction-pool" version = "0.1.0" authors = ["Parity Technologies "] +edition = "2018" [dependencies] error-chain = "0.12" @@ -10,10 +11,10 @@ log = "0.4" parity-codec = "3.0" parking_lot = "0.7.1" sr-primitives = { path = "../sr-primitives" } -substrate-client = { path = "../client" } +client = { package = "substrate-client", path = "../client" } substrate-primitives = { path = "../primitives" } -substrate-transaction-graph = { path = "./graph" } +txpool = { package = "substrate-transaction-graph", path = "./graph" } [dev-dependencies] -substrate-test-client = { path = "../../core/test-client" } -substrate-keyring = { path = "../../core/keyring" } +test_client = { package = "substrate-test-client", path = "../../core/test-client" } +keyring = { package = "substrate-keyring", path = "../../core/keyring" } diff --git a/substrate/core/transaction-pool/graph/Cargo.toml b/substrate/core/transaction-pool/graph/Cargo.toml index 7910e10d9f..05601ae719 100644 --- a/substrate/core/transaction-pool/graph/Cargo.toml +++ b/substrate/core/transaction-pool/graph/Cargo.toml @@ -2,6 +2,7 @@ name = "substrate-transaction-graph" version = "0.1.0" authors = ["Parity Technologies "] +edition = "2018" [dependencies] error-chain = "0.12" @@ -14,4 +15,4 @@ sr-primitives = { path = "../../sr-primitives" } [dev-dependencies] assert_matches = "1.1" -substrate-test-runtime = { path = "../../test-runtime" } +test_runtime = { package = "substrate-test-runtime", path = "../../test-runtime" } diff --git a/substrate/core/transaction-pool/graph/src/base_pool.rs b/substrate/core/transaction-pool/graph/src/base_pool.rs index 9ec334fb8d..6b63e22b17 100644 --- a/substrate/core/transaction-pool/graph/src/base_pool.rs +++ b/substrate/core/transaction-pool/graph/src/base_pool.rs @@ -24,6 +24,8 @@ use std::{ }; use serde::Serialize; +use error_chain::bail; +use log::{trace, debug, warn}; use sr_primitives::traits::Member; use sr_primitives::transaction_validity::{ TransactionTag as Tag, @@ -31,9 +33,9 @@ use sr_primitives::transaction_validity::{ TransactionPriority as Priority, }; -use error; -use future::{FutureTransactions, WaitingTransaction}; -use ready::ReadyTransactions; +use crate::error; +use crate::future::{FutureTransactions, WaitingTransaction}; +use crate::ready::ReadyTransactions; /// Successful import result. #[derive(Debug, PartialEq, Eq)] diff --git a/substrate/core/transaction-pool/graph/src/error.rs b/substrate/core/transaction-pool/graph/src/error.rs index 308d575a2c..63f9c4a185 100644 --- a/substrate/core/transaction-pool/graph/src/error.rs +++ b/substrate/core/transaction-pool/graph/src/error.rs @@ -17,6 +17,9 @@ //! Transaction pool errors. use sr_primitives::transaction_validity::TransactionPriority as Priority; +use error_chain::{ + error_chain, error_chain_processing, impl_error_chain_processed, impl_extract_backtrace, impl_error_chain_kind +}; error_chain! { errors { diff --git a/substrate/core/transaction-pool/graph/src/future.rs b/substrate/core/transaction-pool/graph/src/future.rs index 0bab6bc2e0..43fe513f9a 100644 --- a/substrate/core/transaction-pool/graph/src/future.rs +++ b/substrate/core/transaction-pool/graph/src/future.rs @@ -24,7 +24,7 @@ use sr_primitives::transaction_validity::{ TransactionTag as Tag, }; -use base_pool::Transaction; +use crate::base_pool::Transaction; /// Transaction with partially satisfied dependencies. #[derive(Debug)] @@ -105,7 +105,7 @@ impl FutureTransactions { // Add all tags that are missing for tag in &tx.missing_tags { - let mut entry = self.wanted_tags.entry(tag.clone()).or_insert_with(HashSet::new); + let entry = self.wanted_tags.entry(tag.clone()).or_insert_with(HashSet::new); entry.insert(tx.transaction.hash.clone()); } @@ -134,8 +134,7 @@ impl FutureTransactions { if let Some(hashes) = self.wanted_tags.remove(tag.as_ref()) { for hash in hashes { let is_ready = { - let mut tx = self.waiting.get_mut(&hash) - .expect(WAITING_PROOF); + let tx = self.waiting.get_mut(&hash).expect(WAITING_PROOF); tx.satisfy_tag(tag.as_ref()); tx.is_ready() }; @@ -160,7 +159,7 @@ impl FutureTransactions { if let Some(waiting_tx) = self.waiting.remove(hash) { // remove from wanted_tags as well for tag in waiting_tx.missing_tags { - let remove = if let Some(mut wanted) = self.wanted_tags.get_mut(&tag) { + let remove = if let Some(wanted) = self.wanted_tags.get_mut(&tag) { wanted.remove(hash); wanted.is_empty() } else { false }; diff --git a/substrate/core/transaction-pool/graph/src/lib.rs b/substrate/core/transaction-pool/graph/src/lib.rs index a4879f3cb0..a11be3690b 100644 --- a/substrate/core/transaction-pool/graph/src/lib.rs +++ b/substrate/core/transaction-pool/graph/src/lib.rs @@ -27,21 +27,6 @@ #![warn(missing_docs)] #![warn(unused_extern_crates)] -extern crate futures; -extern crate parking_lot; -extern crate sr_primitives; - -extern crate serde; -#[macro_use] extern crate error_chain; -#[macro_use] extern crate log; -#[macro_use] extern crate serde_derive; - -#[cfg(test)] -extern crate substrate_test_runtime as test_runtime; -#[cfg(test)] -#[macro_use] -extern crate assert_matches; - mod future; mod listener; mod pool; diff --git a/substrate/core/transaction-pool/graph/src/listener.rs b/substrate/core/transaction-pool/graph/src/listener.rs index d4645eb2c5..e2dfaef915 100644 --- a/substrate/core/transaction-pool/graph/src/listener.rs +++ b/substrate/core/transaction-pool/graph/src/listener.rs @@ -20,8 +20,9 @@ use std::{ hash, }; use serde::Serialize; -use watcher; +use crate::watcher; use sr_primitives::traits; +use log::warn; /// Extrinsic pool default listener. pub struct Listener { diff --git a/substrate/core/transaction-pool/graph/src/pool.rs b/substrate/core/transaction-pool/graph/src/pool.rs index fca9d6a5d6..4c2f460da0 100644 --- a/substrate/core/transaction-pool/graph/src/pool.rs +++ b/substrate/core/transaction-pool/graph/src/pool.rs @@ -21,12 +21,14 @@ use std::{ time, }; -use base_pool as base; -use error; -use listener::Listener; -use rotator::PoolRotator; -use watcher::Watcher; +use crate::base_pool as base; +use crate::error; +use crate::listener::Listener; +use crate::rotator::PoolRotator; +use crate::watcher::Watcher; use serde::Serialize; +use error_chain::bail; +use log::debug; use futures::sync::mpsc; use parking_lot::{Mutex, RwLock}; @@ -394,6 +396,8 @@ mod tests { use super::*; use futures::Stream; use test_runtime::{Block, Extrinsic, Transfer, H256}; + use assert_matches::assert_matches; + use crate::watcher; #[derive(Debug, Default)] struct TestApi; @@ -606,8 +610,8 @@ mod tests { // then let mut stream = watcher.into_stream().wait(); - assert_eq!(stream.next(), Some(Ok(::watcher::Status::Ready))); - assert_eq!(stream.next(), Some(Ok(::watcher::Status::Finalised(H256::from_low_u64_be(2))))); + assert_eq!(stream.next(), Some(Ok(watcher::Status::Ready))); + assert_eq!(stream.next(), Some(Ok(watcher::Status::Finalised(H256::from_low_u64_be(2))))); assert_eq!(stream.next(), None); } @@ -631,8 +635,8 @@ mod tests { // then let mut stream = watcher.into_stream().wait(); - assert_eq!(stream.next(), Some(Ok(::watcher::Status::Ready))); - assert_eq!(stream.next(), Some(Ok(::watcher::Status::Finalised(H256::from_low_u64_be(2))))); + assert_eq!(stream.next(), Some(Ok(watcher::Status::Ready))); + assert_eq!(stream.next(), Some(Ok(watcher::Status::Finalised(H256::from_low_u64_be(2))))); assert_eq!(stream.next(), None); } @@ -660,8 +664,8 @@ mod tests { // then let mut stream = watcher.into_stream().wait(); - assert_eq!(stream.next(), Some(Ok(::watcher::Status::Future))); - assert_eq!(stream.next(), Some(Ok(::watcher::Status::Ready))); + assert_eq!(stream.next(), Some(Ok(watcher::Status::Future))); + assert_eq!(stream.next(), Some(Ok(watcher::Status::Ready))); } #[test] @@ -683,8 +687,8 @@ mod tests { // then let mut stream = watcher.into_stream().wait(); - assert_eq!(stream.next(), Some(Ok(::watcher::Status::Ready))); - assert_eq!(stream.next(), Some(Ok(::watcher::Status::Invalid))); + assert_eq!(stream.next(), Some(Ok(watcher::Status::Ready))); + assert_eq!(stream.next(), Some(Ok(watcher::Status::Invalid))); assert_eq!(stream.next(), None); } @@ -710,8 +714,8 @@ mod tests { // then let mut stream = watcher.into_stream().wait(); - assert_eq!(stream.next(), Some(Ok(::watcher::Status::Ready))); - assert_eq!(stream.next(), Some(Ok(::watcher::Status::Broadcast(peers)))); + assert_eq!(stream.next(), Some(Ok(watcher::Status::Ready))); + assert_eq!(stream.next(), Some(Ok(watcher::Status::Broadcast(peers)))); } } } diff --git a/substrate/core/transaction-pool/graph/src/ready.rs b/substrate/core/transaction-pool/graph/src/ready.rs index ca2aa06d50..eb3d61f397 100644 --- a/substrate/core/transaction-pool/graph/src/ready.rs +++ b/substrate/core/transaction-pool/graph/src/ready.rs @@ -22,15 +22,17 @@ use std::{ }; use serde::Serialize; +use log::debug; +use error_chain::bail; use parking_lot::RwLock; use sr_primitives::traits::Member; use sr_primitives::transaction_validity::{ TransactionTag as Tag, }; -use error; -use future::WaitingTransaction; -use base_pool::Transaction; +use crate::error; +use crate::future::WaitingTransaction; +use crate::base_pool::Transaction; #[derive(Debug)] struct TransactionRef { @@ -170,7 +172,7 @@ impl ReadyTransactions { for tag in &transaction.requires { // Check if the transaction that satisfies the tag is still in the queue. if let Some(other) = self.provided_tags.get(tag) { - let mut tx = ready.get_mut(other).expect(HASH_READY); + let tx = ready.get_mut(other).expect(HASH_READY); tx.unlocks.push(hash.clone()); // this transaction depends on some other, so it doesn't go to best directly. goes_to_best = false; diff --git a/substrate/core/transaction-pool/graph/src/rotator.rs b/substrate/core/transaction-pool/graph/src/rotator.rs index 2d7532c7a9..6ca10a9005 100644 --- a/substrate/core/transaction-pool/graph/src/rotator.rs +++ b/substrate/core/transaction-pool/graph/src/rotator.rs @@ -27,7 +27,7 @@ use std::{ }; use parking_lot::RwLock; -use base_pool::Transaction; +use crate::base_pool::Transaction; /// Expected size of the banned extrinsics cache. const EXPECTED_SIZE: usize = 2048; diff --git a/substrate/core/transaction-pool/graph/src/watcher.rs b/substrate/core/transaction-pool/graph/src/watcher.rs index 7ca4a66283..bb73a4b0e9 100644 --- a/substrate/core/transaction-pool/graph/src/watcher.rs +++ b/substrate/core/transaction-pool/graph/src/watcher.rs @@ -20,6 +20,7 @@ use futures::{ Stream, sync::mpsc, }; +use serde_derive::{Serialize, Deserialize}; /// Possible extrinsic status events #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] diff --git a/substrate/core/transaction-pool/src/api.rs b/substrate/core/transaction-pool/src/api.rs index 382f4f6ed8..d8bfe66924 100644 --- a/substrate/core/transaction-pool/src/api.rs +++ b/substrate/core/transaction-pool/src/api.rs @@ -34,7 +34,7 @@ use sr_primitives::{ transaction_validity::TransactionValidity, }; -use error; +use crate::error; /// The transaction pool logic pub struct ChainApi { diff --git a/substrate/core/transaction-pool/src/error.rs b/substrate/core/transaction-pool/src/error.rs index 009c80a315..9f191b8545 100644 --- a/substrate/core/transaction-pool/src/error.rs +++ b/substrate/core/transaction-pool/src/error.rs @@ -18,6 +18,9 @@ use client; use txpool; +use error_chain::{ + error_chain, error_chain_processing, impl_error_chain_processed, impl_extract_backtrace, impl_error_chain_kind +}; error_chain! { links { diff --git a/substrate/core/transaction-pool/src/lib.rs b/substrate/core/transaction-pool/src/lib.rs index 44f63ed37d..ee9d8d8cbb 100644 --- a/substrate/core/transaction-pool/src/lib.rs +++ b/substrate/core/transaction-pool/src/lib.rs @@ -19,21 +19,6 @@ #![warn(missing_docs)] #![warn(unused_extern_crates)] -extern crate parity_codec; -extern crate sr_primitives; -extern crate substrate_client as client; -extern crate substrate_primitives; - -pub extern crate substrate_transaction_graph as txpool; - -#[macro_use] -extern crate error_chain; - -#[cfg(test)] -extern crate substrate_test_client as test_client; -#[cfg(test)] -extern crate substrate_keyring as keyring; - mod api; #[cfg(test)] mod tests; @@ -41,3 +26,4 @@ mod tests; pub mod error; pub use api::ChainApi; +pub use txpool; diff --git a/substrate/core/trie/Cargo.toml b/substrate/core/trie/Cargo.toml index 44ad3a075c..a9252764d5 100644 --- a/substrate/core/trie/Cargo.toml +++ b/substrate/core/trie/Cargo.toml @@ -5,13 +5,14 @@ authors = ["Parity Technologies "] description = "Patricia trie stuff using a parity-codec node format" repository = "https://github.com/paritytech/parity-common" license = "GPL-3.0" +edition = "2018" [[bench]] name = "bench" harness = false [dependencies] -parity-codec = { version = "3.0" } +codec = { package = "parity-codec", version = "3.0" } hash-db = { version = "0.9", default-features = false } trie-db = { version = "0.9", optional = true } trie-root = { version = "0.9", default-features = false } @@ -32,4 +33,4 @@ std = [ "memory-db", "trie-db", "trie-root/std" -] \ No newline at end of file +] diff --git a/substrate/core/trie/benches/bench.rs b/substrate/core/trie/benches/bench.rs index 75fe648b8f..f4100bff15 100644 --- a/substrate/core/trie/benches/bench.rs +++ b/substrate/core/trie/benches/bench.rs @@ -14,17 +14,10 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . -#[macro_use] -extern crate criterion; -use criterion::Criterion; +use criterion::{Criterion, criterion_group, criterion_main}; criterion_group!(benches, benchmark); criterion_main!(benches); -extern crate substrate_primitives; -extern crate keccak_hasher; -extern crate substrate_trie; -extern crate trie_bench; - fn benchmark(c: &mut Criterion) { trie_bench::standard_benchmark::< substrate_primitives::Blake2Hasher, diff --git a/substrate/core/trie/src/lib.rs b/substrate/core/trie/src/lib.rs index 60682df42c..f2f1183d4c 100644 --- a/substrate/core/trie/src/lib.rs +++ b/substrate/core/trie/src/lib.rs @@ -18,20 +18,6 @@ // TODO: no_std -extern crate trie_root; -extern crate parity_codec as codec; -extern crate trie_db; -extern crate hash_db; -extern crate memory_db; - -#[cfg(test)] -extern crate substrate_primitives; -#[cfg(test)] -extern crate trie_standardmap; -#[cfg(test)] -#[macro_use] -extern crate hex_literal; - mod error; mod node_header; mod node_codec; @@ -281,6 +267,7 @@ mod tests { use hash_db::{HashDB, Hasher}; use trie_db::{DBValue, TrieMut, Trie}; use trie_standardmap::{Alphabet, ValueMode, StandardMap}; + use hex_literal::{hex, hex_impl}; fn check_equivalent(input: &Vec<(&[u8], &[u8])>) { { diff --git a/substrate/core/trie/src/node_codec.rs b/substrate/core/trie/src/node_codec.rs index 7cc888be7c..bb8e146b16 100644 --- a/substrate/core/trie/src/node_codec.rs +++ b/substrate/core/trie/src/node_codec.rs @@ -20,7 +20,7 @@ use std::marker::PhantomData; use codec::{Encode, Decode, Compact}; use hash_db::Hasher; use trie_db::{self, DBValue, NibbleSlice, node::Node, ChildReference}; -use error::Error; +use crate::error::Error; use super::{EMPTY_TRIE, LEAF_NODE_OFFSET, LEAF_NODE_BIG, EXTENSION_NODE_OFFSET, EXTENSION_NODE_BIG, take, partial_to_key, node_header::NodeHeader, branch_node};