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
@@ -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)]