[big refactor] Remove crate aliasing. (#4395)

* Rename: Phase 1.

* Unify codec.

* Fixing: Phase 2

* Fixing: Phase 3.

* Fixing: Phase 4.

* Fixing: Phase 5.

* Fixing: Phase 6.

* Fixing: Phase 7.

* Fixing: Phase 8. Tests

* Fixing: Phase 9. Tests!!!

* Fixing: Phase 10. Moar tests!

* Finally done!

* More fixes.

* Rename primitives:: to sp_core::

* Apply renames in finality-grandpa.

* Fix benches.

* Fix benches 2.

* Revert node-template.

* Fix frame-system in our modules.
This commit is contained in:
Tomasz Drwięga
2019-12-16 13:36:49 +01:00
committed by Gavin Wood
parent f14d98a439
commit 8778ca7dc8
485 changed files with 4023 additions and 4005 deletions
+13 -13
View File
@@ -20,13 +20,13 @@ use std::{marker::PhantomData, pin::Pin, sync::Arc};
use codec::{Decode, Encode};
use futures::{channel::oneshot, executor::{ThreadPool, ThreadPoolBuilder}, future::{Future, FutureExt, ready}};
use client_api::{
use sc_client_api::{
blockchain::HeaderBackend,
light::{Fetcher, RemoteCallRequest}
};
use primitives::{H256, Blake2Hasher, Hasher};
use sp_core::{H256, Blake2Hasher, Hasher};
use sp_runtime::{generic::BlockId, traits::{self, Block as BlockT}, transaction_validity::TransactionValidity};
use txpool_api::runtime_api::TaggedTransactionQueue;
use sp_transaction_pool::runtime_api::TaggedTransactionQueue;
use crate::error::{self, Error};
@@ -54,7 +54,7 @@ impl<T, Block> FullChainApi<T, Block> where
}
}
impl<T, Block> txpool::ChainApi for FullChainApi<T, Block> where
impl<T, Block> sc_transaction_graph::ChainApi for FullChainApi<T, Block> where
Block: BlockT<Hash = H256>,
T: traits::ProvideRuntimeApi + traits::BlockIdTo<Block> + 'static + Send + Sync,
T::Api: TaggedTransactionQueue<Block>,
@@ -68,7 +68,7 @@ impl<T, Block> txpool::ChainApi for FullChainApi<T, Block> where
fn validate_transaction(
&self,
at: &BlockId<Self::Block>,
uxt: txpool::ExtrinsicFor<Self>,
uxt: sc_transaction_graph::ExtrinsicFor<Self>,
) -> Self::ValidationFuture {
let (tx, rx) = oneshot::channel();
let client = self.client.clone();
@@ -93,18 +93,18 @@ impl<T, Block> txpool::ChainApi for FullChainApi<T, Block> where
fn block_id_to_number(
&self,
at: &BlockId<Self::Block>,
) -> error::Result<Option<txpool::NumberFor<Self>>> {
) -> error::Result<Option<sc_transaction_graph::NumberFor<Self>>> {
self.client.to_number(at).map_err(|e| Error::BlockIdConversion(format!("{:?}", e)))
}
fn block_id_to_hash(
&self,
at: &BlockId<Self::Block>,
) -> error::Result<Option<txpool::BlockHash<Self>>> {
) -> error::Result<Option<sc_transaction_graph::BlockHash<Self>>> {
self.client.to_hash(at).map_err(|e| Error::BlockIdConversion(format!("{:?}", e)))
}
fn hash_and_length(&self, ex: &txpool::ExtrinsicFor<Self>) -> (Self::Hash, usize) {
fn hash_and_length(&self, ex: &sc_transaction_graph::ExtrinsicFor<Self>) -> (Self::Hash, usize) {
ex.using_encoded(|x| {
(Blake2Hasher::hash(x), x.len())
})
@@ -133,7 +133,7 @@ impl<T, F, Block> LightChainApi<T, F, Block> where
}
}
impl<T, F, Block> txpool::ChainApi for LightChainApi<T, F, Block> where
impl<T, F, Block> sc_transaction_graph::ChainApi for LightChainApi<T, F, Block> where
Block: BlockT<Hash=H256>,
T: HeaderBackend<Block> + 'static,
F: Fetcher<Block> + 'static,
@@ -146,7 +146,7 @@ impl<T, F, Block> txpool::ChainApi for LightChainApi<T, F, Block> where
fn validate_transaction(
&self,
at: &BlockId<Self::Block>,
uxt: txpool::ExtrinsicFor<Self>,
uxt: sc_transaction_graph::ExtrinsicFor<Self>,
) -> Self::ValidationFuture {
let header_hash = self.client.expect_block_hash_from_id(at);
let header_and_hash = header_hash
@@ -177,15 +177,15 @@ impl<T, F, Block> txpool::ChainApi for LightChainApi<T, F, Block> where
Box::new(remote_validation_request)
}
fn block_id_to_number(&self, at: &BlockId<Self::Block>) -> error::Result<Option<txpool::NumberFor<Self>>> {
fn block_id_to_number(&self, at: &BlockId<Self::Block>) -> error::Result<Option<sc_transaction_graph::NumberFor<Self>>> {
Ok(self.client.block_number_from_id(at)?)
}
fn block_id_to_hash(&self, at: &BlockId<Self::Block>) -> error::Result<Option<txpool::BlockHash<Self>>> {
fn block_id_to_hash(&self, at: &BlockId<Self::Block>) -> error::Result<Option<sc_transaction_graph::BlockHash<Self>>> {
Ok(self.client.block_hash_from_id(at)?)
}
fn hash_and_length(&self, ex: &txpool::ExtrinsicFor<Self>) -> (Self::Hash, usize) {
fn hash_and_length(&self, ex: &sc_transaction_graph::ExtrinsicFor<Self>) -> (Self::Hash, usize) {
ex.using_encoded(|x| {
(Blake2Hasher::hash(x), x.len())
})
@@ -16,7 +16,7 @@
//! Transaction pool error.
use txpool_api::error::Error as TxPoolError;
use sp_transaction_pool::error::Error as TxPoolError;
/// Transaction pool result.
pub type Result<T> = std::result::Result<T, Error>;
@@ -47,7 +47,7 @@ impl std::error::Error for Error {
}
}
impl txpool_api::error::IntoPoolError for Error {
impl sp_transaction_pool::error::IntoPoolError for Error {
fn into_pool_error(self) -> std::result::Result<TxPoolError, Self> {
match self {
Error::Pool(e) => Ok(e),
+11 -11
View File
@@ -26,7 +26,7 @@ pub mod error;
#[cfg(test)]
mod tests;
pub use txpool;
pub use sc_transaction_graph as txpool;
pub use crate::api::{FullChainApi, LightChainApi};
pub use crate::maintainer::{FullBasicPoolMaintainer, LightBasicPoolMaintainer};
@@ -37,7 +37,7 @@ use sp_runtime::{
generic::BlockId,
traits::Block as BlockT,
};
use txpool_api::{
use sp_transaction_pool::{
TransactionPool, PoolStatus, ImportNotificationStream,
TxHash, TransactionFor, TransactionStatusStreamFor,
};
@@ -46,25 +46,25 @@ use txpool_api::{
pub struct BasicPool<PoolApi, Block>
where
Block: BlockT,
PoolApi: txpool::ChainApi<Block=Block, Hash=Block::Hash>,
PoolApi: sc_transaction_graph::ChainApi<Block=Block, Hash=Block::Hash>,
{
pool: Arc<txpool::Pool<PoolApi>>,
pool: Arc<sc_transaction_graph::Pool<PoolApi>>,
}
impl<PoolApi, Block> BasicPool<PoolApi, Block>
where
Block: BlockT,
PoolApi: txpool::ChainApi<Block=Block, Hash=Block::Hash>,
PoolApi: sc_transaction_graph::ChainApi<Block=Block, Hash=Block::Hash>,
{
/// Create new basic transaction pool with provided api.
pub fn new(options: txpool::Options, pool_api: PoolApi) -> Self {
pub fn new(options: sc_transaction_graph::Options, pool_api: PoolApi) -> Self {
BasicPool {
pool: Arc::new(txpool::Pool::new(options, pool_api)),
pool: Arc::new(sc_transaction_graph::Pool::new(options, pool_api)),
}
}
/// Gets shared reference to the underlying pool.
pub fn pool(&self) -> &Arc<txpool::Pool<PoolApi>> {
pub fn pool(&self) -> &Arc<sc_transaction_graph::Pool<PoolApi>> {
&self.pool
}
}
@@ -72,11 +72,11 @@ impl<PoolApi, Block> BasicPool<PoolApi, Block>
impl<PoolApi, Block> TransactionPool for BasicPool<PoolApi, Block>
where
Block: BlockT,
PoolApi: 'static + txpool::ChainApi<Block=Block, Hash=Block::Hash, Error=error::Error>,
PoolApi: 'static + sc_transaction_graph::ChainApi<Block=Block, Hash=Block::Hash, Error=error::Error>,
{
type Block = PoolApi::Block;
type Hash = txpool::ExHash<PoolApi>;
type InPoolTransaction = txpool::base_pool::Transaction<TxHash<Self>, TransactionFor<Self>>;
type Hash = sc_transaction_graph::ExHash<PoolApi>;
type InPoolTransaction = sc_transaction_graph::base_pool::Transaction<TxHash<Self>, TransactionFor<Self>>;
type Error = error::Error;
fn submit_at(
@@ -26,31 +26,31 @@ use futures::{
use log::{warn, debug, trace};
use parking_lot::Mutex;
use client_api::{
use sc_client_api::{
client::BlockBody,
light::{Fetcher, RemoteBodyRequest},
};
use primitives::{Blake2Hasher, H256};
use sp_core::{Blake2Hasher, H256};
use sp_runtime::{
generic::BlockId,
traits::{Block as BlockT, Extrinsic, Header, NumberFor, ProvideRuntimeApi, SimpleArithmetic},
};
use sp_blockchain::HeaderBackend;
use txpool_api::TransactionPoolMaintainer;
use txpool_api::runtime_api::TaggedTransactionQueue;
use sp_transaction_pool::TransactionPoolMaintainer;
use sp_transaction_pool::runtime_api::TaggedTransactionQueue;
use txpool::{self, ChainApi};
use sc_transaction_graph::{self, ChainApi};
/// Basic transaction pool maintainer for full clients.
pub struct FullBasicPoolMaintainer<Client, PoolApi: ChainApi> {
pool: Arc<txpool::Pool<PoolApi>>,
pool: Arc<sc_transaction_graph::Pool<PoolApi>>,
client: Arc<Client>,
}
impl<Client, PoolApi: ChainApi> FullBasicPoolMaintainer<Client, PoolApi> {
/// Create new basic full pool maintainer.
pub fn new(
pool: Arc<txpool::Pool<PoolApi>>,
pool: Arc<sc_transaction_graph::Pool<PoolApi>>,
client: Arc<Client>,
) -> Self {
FullBasicPoolMaintainer { pool, client }
@@ -61,7 +61,7 @@ impl<Block, Client, PoolApi> TransactionPoolMaintainer
for
FullBasicPoolMaintainer<Client, PoolApi>
where
Block: BlockT<Hash = <Blake2Hasher as primitives::Hasher>::Out>,
Block: BlockT<Hash = <Blake2Hasher as sp_core::Hasher>::Out>,
Client: ProvideRuntimeApi + HeaderBackend<Block> + BlockBody<Block> + 'static,
Client::Api: TaggedTransactionQueue<Block>,
PoolApi: ChainApi<Block = Block, Hash = H256> + 'static,
@@ -143,7 +143,7 @@ where
/// Basic transaction pool maintainer for light clients.
pub struct LightBasicPoolMaintainer<Block: BlockT, Client, PoolApi: ChainApi, F> {
pool: Arc<txpool::Pool<PoolApi>>,
pool: Arc<sc_transaction_graph::Pool<PoolApi>>,
client: Arc<Client>,
fetcher: Arc<F>,
revalidate_time_period: Option<std::time::Duration>,
@@ -154,7 +154,7 @@ pub struct LightBasicPoolMaintainer<Block: BlockT, Client, PoolApi: ChainApi, F>
impl<Block, Client, PoolApi, F> LightBasicPoolMaintainer<Block, Client, PoolApi, F>
where
Block: BlockT<Hash = <Blake2Hasher as primitives::Hasher>::Out>,
Block: BlockT<Hash = <Blake2Hasher as sp_core::Hasher>::Out>,
Client: ProvideRuntimeApi + HeaderBackend<Block> + BlockBody<Block> + 'static,
Client::Api: TaggedTransactionQueue<Block>,
PoolApi: ChainApi<Block = Block, Hash = H256> + 'static,
@@ -165,7 +165,7 @@ impl<Block, Client, PoolApi, F> LightBasicPoolMaintainer<Block, Client, PoolApi,
/// Default constants are: revalidate every 60 seconds or every 20 blocks
/// (whatever happens first).
pub fn with_defaults(
pool: Arc<txpool::Pool<PoolApi>>,
pool: Arc<sc_transaction_graph::Pool<PoolApi>>,
client: Arc<Client>,
fetcher: Arc<F>,
) -> Self {
@@ -180,7 +180,7 @@ impl<Block, Client, PoolApi, F> LightBasicPoolMaintainer<Block, Client, PoolApi,
/// Create light pool maintainer with passed constants.
pub fn new(
pool: Arc<txpool::Pool<PoolApi>>,
pool: Arc<sc_transaction_graph::Pool<PoolApi>>,
client: Arc<Client>,
fetcher: Arc<F>,
revalidate_time_period: Option<std::time::Duration>,
@@ -261,7 +261,7 @@ impl<Block, Client, PoolApi, F> TransactionPoolMaintainer
for
LightBasicPoolMaintainer<Block, Client, PoolApi, F>
where
Block: BlockT<Hash = <Blake2Hasher as primitives::Hasher>::Out>,
Block: BlockT<Hash = <Blake2Hasher as sp_core::Hasher>::Out>,
Client: ProvideRuntimeApi + HeaderBackend<Block> + BlockBody<Block> + 'static,
Client::Api: TaggedTransactionQueue<Block>,
PoolApi: ChainApi<Block = Block, Hash = H256> + 'static,
@@ -355,15 +355,15 @@ mod tests {
use super::*;
use futures::executor::block_on;
use codec::Encode;
use test_client::{prelude::*, runtime::{Block, Transfer}, consensus::{BlockOrigin, SelectChain}};
use txpool_api::PoolStatus;
use substrate_test_runtime_client::{prelude::*, runtime::{Block, Transfer}, sp_consensus::{BlockOrigin, SelectChain}};
use sp_transaction_pool::PoolStatus;
use crate::api::{FullChainApi, LightChainApi};
#[test]
fn should_remove_transactions_from_the_full_pool() {
let (client, longest_chain) = TestClientBuilder::new().build_with_longest_chain();
let client = Arc::new(client);
let pool = txpool::Pool::new(Default::default(), FullChainApi::new(client.clone()));
let pool = sc_transaction_graph::Pool::new(Default::default(), FullChainApi::new(client.clone()));
let pool = Arc::new(pool);
let transaction = Transfer {
amount: 5,
@@ -401,7 +401,7 @@ mod tests {
to: Default::default(),
}.into_signed_tx();
let fetcher_transaction = transaction.clone();
let fetcher = Arc::new(test_client::new_light_fetcher()
let fetcher = Arc::new(substrate_test_runtime_client::new_light_fetcher()
.with_remote_body(Some(Box::new(move |_| Ok(vec![fetcher_transaction.clone()]))))
.with_remote_call(Some(Box::new(move |_| {
let validity: sp_runtime::transaction_validity::TransactionValidity =
@@ -417,7 +417,7 @@ mod tests {
let (client, longest_chain) = TestClientBuilder::new().build_with_longest_chain();
let client = Arc::new(client);
let pool = txpool::Pool::new(Default::default(), LightChainApi::new(
let pool = sc_transaction_graph::Pool::new(Default::default(), LightChainApi::new(
client.clone(),
fetcher.clone(),
));
@@ -473,7 +473,7 @@ mod tests {
let build_fetcher = || {
let validated = Arc::new(atomic::AtomicBool::new(false));
Arc::new(test_client::new_light_fetcher()
Arc::new(substrate_test_runtime_client::new_light_fetcher()
.with_remote_body(Some(Box::new(move |_| Ok(vec![]))))
.with_remote_call(Some(Box::new(move |_| {
let is_inserted = validated.swap(true, atomic::Ordering::SeqCst);
@@ -504,7 +504,7 @@ mod tests {
let client = Arc::new(client);
// now let's prepare pool
let pool = txpool::Pool::new(Default::default(), LightChainApi::new(
let pool = sc_transaction_graph::Pool::new(Default::default(), LightChainApi::new(
client.clone(),
fetcher.clone(),
));
@@ -563,7 +563,7 @@ mod tests {
fn should_add_reverted_transactions_to_the_pool() {
let (client, longest_chain) = TestClientBuilder::new().build_with_longest_chain();
let client = Arc::new(client);
let pool = txpool::Pool::new(Default::default(), FullChainApi::new(client.clone()));
let pool = sc_transaction_graph::Pool::new(Default::default(), FullChainApi::new(client.clone()));
let pool = Arc::new(pool);
let transaction = Transfer {
amount: 5,
@@ -19,8 +19,8 @@ use super::*;
use codec::Encode;
use futures::executor::block_on;
use txpool::{self, Pool};
use test_client::{runtime::{AccountId, Block, Hash, Index, Extrinsic, Transfer}, AccountKeyring::{self, *}};
use sc_transaction_graph::{self, Pool};
use substrate_test_runtime_client::{runtime::{AccountId, Block, Hash, Index, Extrinsic, Transfer}, AccountKeyring::{self, *}};
use sp_runtime::{
generic::{self, BlockId},
traits::{Hash as HashT, BlakeTwo256},
@@ -39,7 +39,7 @@ impl TestApi {
}
}
impl txpool::ChainApi for TestApi {
impl sc_transaction_graph::ChainApi for TestApi {
type Block = Block;
type Hash = Hash;
type Error = error::Error;
@@ -48,7 +48,7 @@ impl txpool::ChainApi for TestApi {
fn validate_transaction(
&self,
at: &BlockId<Self::Block>,
uxt: txpool::ExtrinsicFor<Self>,
uxt: sc_transaction_graph::ExtrinsicFor<Self>,
) -> Self::ValidationFuture {
let expected = index(at);
let requires = if expected == uxt.transfer().nonce {
@@ -73,18 +73,18 @@ impl txpool::ChainApi for TestApi {
))
}
fn block_id_to_number(&self, at: &BlockId<Self::Block>) -> error::Result<Option<txpool::NumberFor<Self>>> {
fn block_id_to_number(&self, at: &BlockId<Self::Block>) -> error::Result<Option<sc_transaction_graph::NumberFor<Self>>> {
Ok(Some(number_of(at)))
}
fn block_id_to_hash(&self, at: &BlockId<Self::Block>) -> error::Result<Option<txpool::BlockHash<Self>>> {
fn block_id_to_hash(&self, at: &BlockId<Self::Block>) -> error::Result<Option<sc_transaction_graph::BlockHash<Self>>> {
Ok(match at {
generic::BlockId::Hash(x) => Some(x.clone()),
_ => Some(Default::default()),
})
}
fn hash_and_length(&self, ex: &txpool::ExtrinsicFor<Self>) -> (Self::Hash, usize) {
fn hash_and_length(&self, ex: &sc_transaction_graph::ExtrinsicFor<Self>) -> (Self::Hash, usize) {
let encoded = ex.encode();
(BlakeTwo256::hash(&encoded), encoded.len())
}