Migrate tx-graph, tx-pool and trie to the 2018 edition (#1611)

This commit is contained in:
Stanislav Tkach
2019-01-29 17:25:03 +02:00
committed by Gav Wood
parent e6839d2d41
commit d796e09f02
18 changed files with 59 additions and 90 deletions
+5 -4
View File
@@ -2,6 +2,7 @@
name = "substrate-transaction-pool"
version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>"]
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" }
@@ -2,6 +2,7 @@
name = "substrate-transaction-graph"
version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>"]
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" }
@@ -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)]
@@ -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 {
@@ -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<Hash: hash::Hash + Eq + Clone, Ex> FutureTransactions<Hash, Ex> {
// 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<Hash: hash::Hash + Eq + Clone, Ex> FutureTransactions<Hash, Ex> {
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<Hash: hash::Hash + Eq + Clone, Ex> FutureTransactions<Hash, Ex> {
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 };
@@ -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;
@@ -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<H: hash::Hash + Eq, H2> {
@@ -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))));
}
}
}
@@ -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<Hash, Ex> {
@@ -170,7 +172,7 @@ impl<Hash: hash::Hash + Member + Serialize, Ex> ReadyTransactions<Hash, Ex> {
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;
@@ -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;
@@ -20,6 +20,7 @@ use futures::{
Stream,
sync::mpsc,
};
use serde_derive::{Serialize, Deserialize};
/// Possible extrinsic status events
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
+1 -1
View File
@@ -34,7 +34,7 @@ use sr_primitives::{
transaction_validity::TransactionValidity,
};
use error;
use crate::error;
/// The transaction pool logic
pub struct ChainApi<T, Block> {
@@ -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 {
+1 -15
View File
@@ -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;
+3 -2
View File
@@ -5,13 +5,14 @@ authors = ["Parity Technologies <admin@parity.io>"]
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"
]
]
+1 -8
View File
@@ -14,17 +14,10 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
#[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,
+1 -14
View File
@@ -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])>) {
{
+1 -1
View File
@@ -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};