From 19c1d9028d8d6eabef41693433b56e14da025247 Mon Sep 17 00:00:00 2001 From: Ashley Date: Thu, 30 Jul 2020 11:02:12 +0200 Subject: [PATCH] Add a `DefaultQueue` type alias to remove the need to use `sp_api::TransactionFor` (#6761) * Add DefaultQueue * Add DefaultImportQueue to the top level of sp-consensus --- Cargo.lock | 1 + bin/node-template/node/src/service.rs | 2 +- bin/node/cli/src/service.rs | 2 +- client/consensus/aura/src/lib.rs | 7 ++----- client/consensus/babe/src/lib.rs | 7 ++----- primitives/consensus/common/Cargo.toml | 1 + primitives/consensus/common/src/import_queue.rs | 5 +++++ primitives/consensus/common/src/lib.rs | 1 + 8 files changed, 14 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 93aa1d393fbc8..574e4f4802550 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7750,6 +7750,7 @@ dependencies = [ "parity-scale-codec", "parking_lot 0.10.2", "serde", + "sp-api", "sp-core", "sp-inherents", "sp-runtime", diff --git a/bin/node-template/node/src/service.rs b/bin/node-template/node/src/service.rs index 599560355ecb9..0de17103b05a4 100644 --- a/bin/node-template/node/src/service.rs +++ b/bin/node-template/node/src/service.rs @@ -24,7 +24,7 @@ type FullSelectChain = sc_consensus::LongestChain; pub fn new_partial(config: &Configuration) -> Result, + sp_consensus::DefaultImportQueue, sc_transaction_pool::FullPool, ( sc_finality_grandpa::GrandpaBlockImport, diff --git a/bin/node/cli/src/service.rs b/bin/node/cli/src/service.rs index 322e9bf1d8ab5..a47869ed83232 100644 --- a/bin/node/cli/src/service.rs +++ b/bin/node/cli/src/service.rs @@ -46,7 +46,7 @@ type LightClient = sc_service::TLightClient; pub fn new_partial(config: &Configuration) -> Result, + sp_consensus::DefaultImportQueue, sc_transaction_pool::FullPool, ( impl Fn(node_rpc::DenyUnsafe) -> node_rpc::IoHandler, diff --git a/client/consensus/aura/src/lib.rs b/client/consensus/aura/src/lib.rs index 244b7e929ef95..4e6cb49f1129d 100644 --- a/client/consensus/aura/src/lib.rs +++ b/client/consensus/aura/src/lib.rs @@ -47,7 +47,7 @@ use sp_consensus::{ BlockOrigin, Error as ConsensusError, SelectChain, SlotData, BlockCheckParams, ImportResult }; use sp_consensus::import_queue::{ - Verifier, BasicQueue, BoxJustificationImport, BoxFinalityProofImport, + Verifier, BasicQueue, DefaultImportQueue, BoxJustificationImport, BoxFinalityProofImport, }; use sc_client_api::{backend::AuxStore, BlockOf}; use sp_blockchain::{ @@ -713,9 +713,6 @@ fn authorities(client: &C, at: &BlockId) -> Result, Consensus .ok_or_else(|| sp_consensus::Error::InvalidAuthoritiesSet.into()) } -/// The Aura import queue type. -pub type AuraImportQueue = BasicQueue>; - /// Register the aura inherent data provider, if not registered already. fn register_aura_inherent_data_provider( inherent_data_providers: &InherentDataProviders, @@ -824,7 +821,7 @@ pub fn import_queue( inherent_data_providers: InherentDataProviders, spawner: &S, registry: Option<&Registry>, -) -> Result, sp_consensus::Error> where +) -> Result, sp_consensus::Error> where B: BlockT, C::Api: BlockBuilderApi + AuraApi> + ApiExt, C: 'static + ProvideRuntimeApi + BlockOf + ProvideCache + Send + Sync + AuxStore + HeaderBackend, diff --git a/client/consensus/babe/src/lib.rs b/client/consensus/babe/src/lib.rs index f09e9b063c255..e6f880fe345a1 100644 --- a/client/consensus/babe/src/lib.rs +++ b/client/consensus/babe/src/lib.rs @@ -100,7 +100,7 @@ use sp_consensus::{ }; use sp_consensus_babe::inherents::BabeInherentData; use sp_timestamp::{TimestampInherentData, InherentType as TimestampInherent}; -use sp_consensus::import_queue::{Verifier, BasicQueue, CacheKeyId}; +use sp_consensus::import_queue::{Verifier, BasicQueue, DefaultImportQueue, CacheKeyId}; use sc_client_api::{ backend::AuxStore, BlockchainEvents, ProvideUncles, @@ -967,9 +967,6 @@ where } } -/// The BABE import queue type. -pub type BabeImportQueue = BasicQueue>; - /// Register the babe inherent data provider, if not registered already. fn register_babe_inherent_data_provider( inherent_data_providers: &InherentDataProviders, @@ -1368,7 +1365,7 @@ pub fn import_queue( inherent_data_providers: InherentDataProviders, spawner: &impl sp_core::traits::SpawnNamed, registry: Option<&Registry>, -) -> ClientResult> where +) -> ClientResult> where Inner: BlockImport> + Send + Sync + 'static, Client: ProvideRuntimeApi + ProvideCache + Send + Sync + AuxStore + 'static, diff --git a/primitives/consensus/common/Cargo.toml b/primitives/consensus/common/Cargo.toml index 583fb088060cb..67d5603fdc5f8 100644 --- a/primitives/consensus/common/Cargo.toml +++ b/primitives/consensus/common/Cargo.toml @@ -27,6 +27,7 @@ sp-version = { version = "2.0.0-rc5", path = "../../version" } sp-runtime = { version = "2.0.0-rc5", path = "../../runtime" } sp-utils = { version = "2.0.0-rc5", path = "../../utils" } sp-trie = { version = "2.0.0-rc5", path = "../../trie" } +sp-api = { version = "2.0.0-rc5", path = "../../api" } codec = { package = "parity-scale-codec", version = "1.3.1", features = ["derive"] } parking_lot = "0.10.0" serde = { version = "1.0", features = ["derive"] } diff --git a/primitives/consensus/common/src/import_queue.rs b/primitives/consensus/common/src/import_queue.rs index 94228a266385f..9d25786441ac9 100644 --- a/primitives/consensus/common/src/import_queue.rs +++ b/primitives/consensus/common/src/import_queue.rs @@ -40,6 +40,11 @@ use crate::{ }; pub use basic_queue::BasicQueue; +/// A commonly-used Import Queue type. +/// +/// This defines the transaction type of the `BasicQueue` to be the transaction type for a client. +pub type DefaultImportQueue = BasicQueue>; + mod basic_queue; pub mod buffered_link; diff --git a/primitives/consensus/common/src/lib.rs b/primitives/consensus/common/src/lib.rs index da23172783cdc..04b65a723e4a8 100644 --- a/primitives/consensus/common/src/lib.rs +++ b/primitives/consensus/common/src/lib.rs @@ -56,6 +56,7 @@ pub use block_import::{ }; pub use select_chain::SelectChain; pub use sp_state_machine::Backend as StateBackend; +pub use import_queue::DefaultImportQueue; /// Block status. #[derive(Debug, PartialEq, Eq)]