From 2be524b09ee747b901842ebf817422dba618a05e Mon Sep 17 00:00:00 2001 From: Ashley Ruglys Date: Thu, 9 Jul 2020 08:52:14 +0200 Subject: [PATCH 1/6] Simplify a few chain components creation APIs related to the service --- Cargo.lock | 1 + bin/node-template/node/src/service.rs | 10 ++- bin/node/cli/src/service.rs | 14 +-- client/api/src/execution_extensions.rs | 6 +- client/api/src/in_mem.rs | 6 ++ .../basic-authorship/src/basic_authorship.rs | 52 ++++++----- client/consensus/manual-seal/src/lib.rs | 20 +++-- client/finality-grandpa/src/lib.rs | 5 +- client/offchain/src/lib.rs | 12 +-- client/rpc/src/author/tests.rs | 7 +- client/service/src/builder.rs | 28 ++---- client/service/src/config.rs | 5 ++ client/service/src/lib.rs | 7 +- client/service/src/metrics.rs | 8 +- client/transaction-pool/src/lib.rs | 90 +++++++++++++------ primitives/consensus/common/Cargo.toml | 1 + .../consensus/common/src/import_queue.rs | 4 +- primitives/core/src/tasks.rs | 2 +- utils/frame/rpc/system/src/lib.rs | 52 ++++++----- 19 files changed, 196 insertions(+), 134 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c0c734533d591..906d3526ec0e7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7639,6 +7639,7 @@ dependencies = [ "sp-state-machine", "sp-std", "sp-test-primitives", + "sp-trie", "sp-utils", "sp-version", "substrate-prometheus-endpoint", diff --git a/bin/node-template/node/src/service.rs b/bin/node-template/node/src/service.rs index 89bf159927fc6..0a5d3c0f4a278 100644 --- a/bin/node-template/node/src/service.rs +++ b/bin/node-template/node/src/service.rs @@ -48,10 +48,12 @@ macro_rules! new_full_start { let pool_api = sc_transaction_pool::FullChainApi::new( builder.client().clone(), ); - Ok(sc_transaction_pool::BasicPool::new( + Ok(sc_transaction_pool::BasicPool::new_full( builder.config().transaction_pool.clone(), std::sync::Arc::new(pool_api), builder.prometheus_registry(), + builder.spawn_handle(), + builder.client().clone(), )) })? .with_import_queue(| @@ -220,12 +222,12 @@ pub fn new_light(config: Configuration) -> Result { builder.client().clone(), fetcher.clone(), ); - let pool = sc_transaction_pool::BasicPool::with_revalidation_type( + let pool = Arc::new(sc_transaction_pool::BasicPool::new_light( builder.config().transaction_pool.clone(), Arc::new(pool_api), builder.prometheus_registry(), - sc_transaction_pool::RevalidationType::Light, - ); + builder.spawn_handle(), + )); Ok(pool) })? .with_import_queue_and_fprb(| diff --git a/bin/node/cli/src/service.rs b/bin/node/cli/src/service.rs index 632092cdaa188..718b794a26111 100644 --- a/bin/node/cli/src/service.rs +++ b/bin/node/cli/src/service.rs @@ -62,12 +62,12 @@ macro_rules! new_full_start { let pool_api = sc_transaction_pool::FullChainApi::new( builder.client().clone(), ); - let config = builder.config(); - - Ok(sc_transaction_pool::BasicPool::new( - config.transaction_pool.clone(), + Ok(sc_transaction_pool::BasicPool::new_full( + builder.config().transaction_pool.clone(), std::sync::Arc::new(pool_api), builder.prometheus_registry(), + builder.spawn_handle(), + builder.client().clone(), )) })? .with_import_queue(| @@ -355,12 +355,12 @@ pub fn new_light_base(config: Configuration) -> Result<( builder.client().clone(), fetcher, ); - let pool = sc_transaction_pool::BasicPool::with_revalidation_type( + let pool = Arc::new(sc_transaction_pool::BasicPool::new_light( builder.config().transaction_pool.clone(), Arc::new(pool_api), builder.prometheus_registry(), - sc_transaction_pool::RevalidationType::Light, - ); + builder.spawn_handle(), + )); Ok(pool) })? .with_import_queue_and_fprb(| diff --git a/client/api/src/execution_extensions.rs b/client/api/src/execution_extensions.rs index 55ffc3794c4ea..b89885cc5c4dc 100644 --- a/client/api/src/execution_extensions.rs +++ b/client/api/src/execution_extensions.rs @@ -126,8 +126,10 @@ impl ExecutionExtensions { /// extension to be a `Weak` reference. /// That's also the reason why it's being registered lazily instead of /// during initialization. - pub fn register_transaction_pool(&self, pool: Weak>) { - *self.transaction_pool.write() = Some(pool); + pub fn register_transaction_pool(&self, pool: &Arc) + where T: sp_transaction_pool::OffchainSubmitTransaction + 'static + { + *self.transaction_pool.write() = Some(Arc::downgrade(&pool) as _); } /// Create `ExecutionManager` and `Extensions` for given offchain call. diff --git a/client/api/src/in_mem.rs b/client/api/src/in_mem.rs index 1de2747eb4c76..9bfdcdd4d5aea 100644 --- a/client/api/src/in_mem.rs +++ b/client/api/src/in_mem.rs @@ -114,6 +114,12 @@ pub struct Blockchain { storage: Arc>>, } +impl Default for Blockchain { + fn default() -> Self { + Self::new() + } +} + impl Clone for Blockchain { fn clone(&self) -> Self { let storage = Arc::new(RwLock::new(self.storage.read().clone())); diff --git a/client/basic-authorship/src/basic_authorship.rs b/client/basic-authorship/src/basic_authorship.rs index 7343b13c04031..6fc72448a89f4 100644 --- a/client/basic-authorship/src/basic_authorship.rs +++ b/client/basic-authorship/src/basic_authorship.rs @@ -358,12 +358,13 @@ mod tests { fn should_cease_building_block_when_deadline_is_reached() { // given let client = Arc::new(substrate_test_runtime_client::new()); - let txpool = Arc::new( - BasicPool::new( - Default::default(), - Arc::new(FullChainApi::new(client.clone())), - None, - ).0 + let spawner = sp_core::testing::SpawnBlockingExecutor::new(); + let txpool = BasicPool::new_full( + Default::default(), + Arc::new(FullChainApi::new(client.clone())), + None, + spawner, + client.clone(), ); futures::executor::block_on( @@ -411,12 +412,13 @@ mod tests { #[test] fn should_not_panic_when_deadline_is_reached() { let client = Arc::new(substrate_test_runtime_client::new()); - let txpool = Arc::new( - BasicPool::new( - Default::default(), - Arc::new(FullChainApi::new(client.clone())), - None, - ).0 + let spawner = sp_core::testing::SpawnBlockingExecutor::new(); + let txpool = BasicPool::new_full( + Default::default(), + Arc::new(FullChainApi::new(client.clone())), + None, + spawner, + client.clone(), ); let mut proposer_factory = ProposerFactory::new(client.clone(), txpool.clone(), None); @@ -446,12 +448,13 @@ mod tests { fn proposed_storage_changes_should_match_execute_block_storage_changes() { let (client, backend) = TestClientBuilder::new().build_with_backend(); let client = Arc::new(client); - let txpool = Arc::new( - BasicPool::new( - Default::default(), - Arc::new(FullChainApi::new(client.clone())), - None, - ).0 + let spawner = sp_core::testing::SpawnBlockingExecutor::new(); + let txpool = BasicPool::new_full( + Default::default(), + Arc::new(FullChainApi::new(client.clone())), + None, + spawner, + client.clone(), ); let genesis_hash = client.info().best_hash; @@ -508,12 +511,13 @@ mod tests { fn should_not_remove_invalid_transactions_when_skipping() { // given let mut client = Arc::new(substrate_test_runtime_client::new()); - let txpool = Arc::new( - BasicPool::new( - Default::default(), - Arc::new(FullChainApi::new(client.clone())), - None, - ).0 + let spawner = sp_core::testing::SpawnBlockingExecutor::new(); + let txpool = BasicPool::new_full( + Default::default(), + Arc::new(FullChainApi::new(client.clone())), + None, + spawner, + client.clone(), ); futures::executor::block_on( diff --git a/client/consensus/manual-seal/src/lib.rs b/client/consensus/manual-seal/src/lib.rs index 53cc57ba6e8f2..77fb5043c5dd6 100644 --- a/client/consensus/manual-seal/src/lib.rs +++ b/client/consensus/manual-seal/src/lib.rs @@ -200,10 +200,7 @@ mod tests { AccountKeyring::*, TestClientBuilder, }; - use sc_transaction_pool::{ - BasicPool, - txpool::Options, - }; + use sc_transaction_pool::{BasicPool, RevalidationType, txpool::Options}; use substrate_test_runtime_transaction_pool::{TestApi, uxt}; use sp_transaction_pool::{TransactionPool, MaintainedTransactionPool, TransactionSource}; use sp_runtime::generic::BlockId; @@ -223,7 +220,10 @@ mod tests { let (client, select_chain) = builder.build_with_longest_chain(); let client = Arc::new(client); let inherent_data_providers = InherentDataProviders::new(); - let pool = Arc::new(BasicPool::new(Options::default(), api(), None).0); + let spawner = sp_core::testing::SpawnBlockingExecutor::new(); + let pool = Arc::new(BasicPool::with_revalidation_type( + Options::default(), api(), None, RevalidationType::Full, spawner, + )); let env = ProposerFactory::new( client.clone(), pool.clone(), @@ -288,7 +288,10 @@ mod tests { let (client, select_chain) = builder.build_with_longest_chain(); let client = Arc::new(client); let inherent_data_providers = InherentDataProviders::new(); - let pool = Arc::new(BasicPool::new(Options::default(), api(), None).0); + let spawner = sp_core::testing::SpawnBlockingExecutor::new(); + let pool = Arc::new(BasicPool::with_revalidation_type( + Options::default(), api(), None, RevalidationType::Full, spawner, + )); let env = ProposerFactory::new( client.clone(), pool.clone(), @@ -357,7 +360,10 @@ mod tests { let client = Arc::new(client); let inherent_data_providers = InherentDataProviders::new(); let pool_api = api(); - let pool = Arc::new(BasicPool::new(Options::default(), pool_api.clone(), None).0); + let spawner = sp_core::testing::SpawnBlockingExecutor::new(); + let pool = Arc::new(BasicPool::with_revalidation_type( + Options::default(), pool_api.clone(), None, RevalidationType::Full, spawner, + )); let env = ProposerFactory::new( client.clone(), pool.clone(), diff --git a/client/finality-grandpa/src/lib.rs b/client/finality-grandpa/src/lib.rs index fa2a6fedd8b05..7d74d0eebfc48 100644 --- a/client/finality-grandpa/src/lib.rs +++ b/client/finality-grandpa/src/lib.rs @@ -84,7 +84,8 @@ use sc_telemetry::{telemetry, CONSENSUS_INFO, CONSENSUS_DEBUG}; use parking_lot::RwLock; use finality_grandpa::Error as GrandpaError; -use finality_grandpa::{voter, BlockNumberOps, voter_set::VoterSet}; +use finality_grandpa::{voter, voter_set::VoterSet}; +pub use finality_grandpa::BlockNumberOps; use std::{fmt, io}; use std::sync::Arc; @@ -126,7 +127,7 @@ pub use authorities::SharedAuthoritySet; pub use finality_proof::{FinalityProofProvider, StorageAndProofProvider}; pub use import::GrandpaBlockImport; pub use justification::GrandpaJustification; -pub use light_import::light_block_import; +pub use light_import::{light_block_import, GrandpaLightBlockImport}; pub use voting_rule::{ BeforeBestBlockBy, ThreeQuartersOfTheUnfinalizedChain, VotingRule, VotingRulesBuilder }; diff --git a/client/offchain/src/lib.rs b/client/offchain/src/lib.rs index 7c90065746aa3..dcf142c005edb 100644 --- a/client/offchain/src/lib.rs +++ b/client/offchain/src/lib.rs @@ -212,7 +212,6 @@ mod tests { use substrate_test_runtime_client::{TestClient, runtime::Block}; use sc_transaction_pool::{BasicPool, FullChainApi}; use sp_transaction_pool::{TransactionPool, InPoolTransaction}; - use sc_client_api::ExecutorProvider; struct MockNetworkStateInfo(); @@ -227,7 +226,7 @@ mod tests { } struct TestPool( - BasicPool, Block> + Arc, Block>> ); impl sp_transaction_pool::OffchainSubmitTransaction for TestPool { @@ -248,13 +247,14 @@ mod tests { let _ = env_logger::try_init(); let client = Arc::new(substrate_test_runtime_client::new()); - let pool = Arc::new(TestPool(BasicPool::new( + let spawner = sp_core::testing::SpawnBlockingExecutor::new(); + let pool = TestPool(BasicPool::new_full( Default::default(), Arc::new(FullChainApi::new(client.clone())), None, - ).0)); - client.execution_extensions() - .register_transaction_pool(Arc::downgrade(&pool.clone()) as _); + spawner, + client.clone(), + )); let db = sc_client_db::offchain::LocalStorage::new_test(); let network_state = Arc::new(MockNetworkStateInfo()); let header = client.header(&BlockId::number(0)).unwrap().unwrap(); diff --git a/client/rpc/src/author/tests.rs b/client/rpc/src/author/tests.rs index f2f4ddebb2f1d..06fede952b5be 100644 --- a/client/rpc/src/author/tests.rs +++ b/client/rpc/src/author/tests.rs @@ -61,11 +61,14 @@ impl Default for TestSetup { let client_builder = substrate_test_runtime_client::TestClientBuilder::new(); let client = Arc::new(client_builder.set_keystore(keystore.clone()).build()); - let pool = Arc::new(BasicPool::new( + let spawner = sp_core::testing::SpawnBlockingExecutor::new(); + let pool = BasicPool::new_full( Default::default(), Arc::new(FullChainApi::new(client.clone())), None, - ).0); + spawner, + client.clone(), + ); TestSetup { client, keystore, diff --git a/client/service/src/builder.rs b/client/service/src/builder.rs index 1585298d98bd6..356162d863a76 100644 --- a/client/service/src/builder.rs +++ b/client/service/src/builder.rs @@ -66,8 +66,6 @@ use sc_client_api::{ use sp_blockchain::{HeaderMetadata, HeaderBackend}; use crate::{ServiceComponents, TelemetryOnConnectSinks, RpcHandlers, NetworkStatusSinks}; -pub type BackgroundTask = Pin + Send>>; - /// Aggregator for the components required to build a service. /// /// # Usage @@ -518,6 +516,11 @@ impl self.remote_backend.clone() } + /// Returns a spawn handle created by the task manager. + pub fn spawn_handle(&self) -> SpawnTaskHandle { + self.task_manager.spawn_handle() + } + /// Consume the builder and return the parts needed for chain operations. pub fn to_chain_ops_parts(self) -> (Arc, Arc, TImpQu, TaskManager) { (self.client, self.backend, self.import_queue, self.task_manager) @@ -728,15 +731,11 @@ impl self, transaction_pool_builder: impl FnOnce( &Self, - ) -> Result<(UExPool, Option), Error>, + ) -> Result, Error>, ) -> Result, Error> where TSc: Clone, TFchr: Clone { - let (transaction_pool, background_task) = transaction_pool_builder(&self)?; - - if let Some(background_task) = background_task{ - self.task_manager.spawn_handle().spawn("txpool-background", background_task); - } + let transaction_pool = transaction_pool_builder(&self)?; Ok(ServiceBuilder { config: self.config, @@ -749,7 +748,7 @@ impl import_queue: self.import_queue, finality_proof_request_builder: self.finality_proof_request_builder, finality_proof_provider: self.finality_proof_provider, - transaction_pool: Arc::new(transaction_pool), + transaction_pool: transaction_pool, rpc_extensions_builder: self.rpc_extensions_builder, remote_backend: self.remote_backend, block_announce_validator_builder: self.block_announce_validator_builder, @@ -978,12 +977,7 @@ ServiceBuilder< // Prometheus metrics. let metrics_service = if let Some(PrometheusConfig { port, registry }) = config.prometheus_config.clone() { // Set static metrics. - let metrics = MetricsService::with_prometheus( - ®istry, - &config.network.node_name, - &config.impl_version, - &config.role, - )?; + let metrics = MetricsService::with_prometheus(®istry, &config)?; spawn_handle.spawn( "prometheus-endpoint", prometheus_endpoint::init_prometheus(port, registry).map(drop) @@ -1122,10 +1116,6 @@ ServiceBuilder< /// Builds the full service. pub fn build_full(self) -> Result, Error> { - // make transaction pool available for off-chain runtime calls. - self.client.execution_extensions() - .register_transaction_pool(Arc::downgrade(&self.transaction_pool) as _); - self.build_common() } } diff --git a/client/service/src/config.rs b/client/service/src/config.rs index f3080005a6cf3..397dacd747b14 100644 --- a/client/service/src/config.rs +++ b/client/service/src/config.rs @@ -181,6 +181,11 @@ impl Configuration { pub fn display_role(&self) -> String { self.role.to_string() } + + /// Returns the prometheus metrics registry, if available. + pub fn prometheus_registry<'a>(&'a self) -> Option<&'a Registry> { + self.prometheus_config.as_ref().map(|config| &config.registry) + } } /// Available RPC methods. diff --git a/client/service/src/lib.rs b/client/service/src/lib.rs index 2c09591fc7d65..b26f036907096 100644 --- a/client/service/src/lib.rs +++ b/client/service/src/lib.rs @@ -577,11 +577,14 @@ mod tests { // given let (client, longest_chain) = TestClientBuilder::new().build_with_longest_chain(); let client = Arc::new(client); - let pool = Arc::new(BasicPool::new( + let spawner = sp_core::testing::SpawnBlockingExecutor::new(); + let pool = BasicPool::new_full( Default::default(), Arc::new(FullChainApi::new(client.clone())), None, - ).0); + spawner, + client.clone(), + ); let source = sp_runtime::transaction_validity::TransactionSource::External; let best = longest_chain.best_chain().unwrap(); let transaction = Transfer { diff --git a/client/service/src/metrics.rs b/client/service/src/metrics.rs index 232e9abdc1c97..1727aaae743aa 100644 --- a/client/service/src/metrics.rs +++ b/client/service/src/metrics.rs @@ -18,7 +18,7 @@ use std::{convert::TryFrom, time::SystemTime}; -use crate::NetworkStatus; +use crate::{NetworkStatus, config::Configuration}; use prometheus_endpoint::{register, Gauge, U64, F64, Registry, PrometheusError, Opts, GaugeVec}; use sc_telemetry::{telemetry, SUBSTRATE_INFO}; use sp_runtime::traits::{NumberFor, Block, SaturatedConversion, UniqueSaturatedInto}; @@ -261,17 +261,17 @@ impl MetricsService { impl MetricsService { - pub fn with_prometheus(registry: &Registry, name: &str, version: &str, role: &Role) + pub fn with_prometheus(registry: &Registry, config: &Configuration) -> Result { - let role_bits = match role { + let role_bits = match config.role { Role::Full => 1u64, Role::Light => 2u64, Role::Sentry { .. } => 3u64, Role::Authority { .. } => 4u64, }; - PrometheusMetrics::setup(registry, name, version, role_bits).map(|p| { + PrometheusMetrics::setup(registry, &config.network.node_name, &config.impl_version, role_bits).map(|p| { Self::inner_new(Some(p)) }) } diff --git a/client/transaction-pool/src/lib.rs b/client/transaction-pool/src/lib.rs index ea8b4bf9dec81..6cd0b3e7cc9c4 100644 --- a/client/transaction-pool/src/lib.rs +++ b/client/transaction-pool/src/lib.rs @@ -42,6 +42,7 @@ use sp_runtime::{ generic::BlockId, traits::{Block as BlockT, NumberFor, AtLeast32Bit, Extrinsic, Zero}, }; +use sp_core::traits::SpawnNamed; use sp_transaction_pool::{ TransactionPool, PoolStatus, ImportNotificationStream, TxHash, TransactionFor, TransactionStatusStreamFor, MaintainedTransactionPool, PoolFuture, ChainEvent, @@ -152,18 +153,6 @@ impl BasicPool Block: BlockT, PoolApi: ChainApi + 'static, { - /// Create new basic transaction pool with provided api. - /// - /// It will also optionally return background task that might be started by the - /// caller. - pub fn new( - options: sc_transaction_graph::Options, - pool_api: Arc, - prometheus: Option<&PrometheusRegistry>, - ) -> (Self, Option + Send>>>) { - Self::with_revalidation_type(options, pool_api, prometheus, RevalidationType::Full) - } - /// Create new basic transaction pool with provided api, for tests. #[cfg(test)] pub fn new_test( @@ -186,6 +175,18 @@ impl BasicPool ) } + /// Create new basic transaction pool for a light node with the provided api. + pub fn new_light( + options: sc_transaction_graph::Options, + pool_api: Arc, + prometheus: Option<&PrometheusRegistry>, + spawner: impl SpawnNamed, + ) -> Self { + Self::with_revalidation_type( + options, pool_api, prometheus, RevalidationType::Light, spawner, + ) + } + /// Create new basic transaction pool with provided api and custom /// revalidation type. pub fn with_revalidation_type( @@ -193,7 +194,8 @@ impl BasicPool pool_api: Arc, prometheus: Option<&PrometheusRegistry>, revalidation_type: RevalidationType, - ) -> (Self, Option + Send>>>) { + spawner: impl SpawnNamed, + ) -> Self { let pool = Arc::new(sc_transaction_graph::Pool::new(options, pool_api.clone())); let (revalidation_queue, background_task) = match revalidation_type { RevalidationType::Light => (revalidation::RevalidationQueue::new(pool_api.clone(), pool.clone()), None), @@ -203,22 +205,23 @@ impl BasicPool }, }; - ( - BasicPool { - api: pool_api, - pool, - revalidation_queue: Arc::new(revalidation_queue), - revalidation_strategy: Arc::new(Mutex::new( - match revalidation_type { - RevalidationType::Light => RevalidationStrategy::Light(RevalidationStatus::NotScheduled), - RevalidationType::Full => RevalidationStrategy::Always, - } - )), - ready_poll: Default::default(), - metrics: PrometheusMetrics::new(prometheus), - }, - background_task, - ) + if let Some(background_task) = background_task { + spawner.spawn("txpool-background", background_task); + } + + BasicPool { + api: pool_api, + pool, + revalidation_queue: Arc::new(revalidation_queue), + revalidation_strategy: Arc::new(Mutex::new( + match revalidation_type { + RevalidationType::Light => RevalidationStrategy::Light(RevalidationStatus::NotScheduled), + RevalidationType::Full => RevalidationStrategy::Always, + } + )), + ready_poll: Default::default(), + metrics: PrometheusMetrics::new(prometheus), + } } /// Gets shared reference to the underlying pool. @@ -352,6 +355,35 @@ impl TransactionPool for BasicPool } } +impl BasicPool, Block> +where + Block: BlockT, + Client: sp_api::ProvideRuntimeApi + + sc_client_api::BlockBackend + + sp_runtime::traits::BlockIdTo, + Client: sc_client_api::ExecutorProvider + Send + Sync + 'static, + Client::Api: sp_transaction_pool::runtime_api::TaggedTransactionQueue, + sp_api::ApiErrorFor: Send + std::fmt::Display, +{ + /// Create new basic transaction pool for a full node with the provided api. + pub fn new_full( + options: sc_transaction_graph::Options, + pool_api: Arc>, + prometheus: Option<&PrometheusRegistry>, + spawner: impl SpawnNamed, + client: Arc, + ) -> Arc { + let pool = Arc::new(Self::with_revalidation_type( + options, pool_api, prometheus, RevalidationType::Full, spawner + )); + + // make transaction pool available for off-chain runtime calls. + client.execution_extensions().register_transaction_pool(&pool); + + pool + } +} + impl sp_transaction_pool::LocalTransactionPool for BasicPool, Block> where diff --git a/primitives/consensus/common/Cargo.toml b/primitives/consensus/common/Cargo.toml index 39c47545c2b08..1c41d25ec70e4 100644 --- a/primitives/consensus/common/Cargo.toml +++ b/primitives/consensus/common/Cargo.toml @@ -26,6 +26,7 @@ sp-std = { version = "2.0.0-rc4", path = "../../std" } sp-version = { version = "2.0.0-rc4", path = "../../version" } sp-runtime = { version = "2.0.0-rc4", path = "../../runtime" } sp-utils = { version = "2.0.0-rc4", path = "../../utils" } +sp-trie = { version = "2.0.0-rc4", path = "../../trie" } 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..ae8880e809ff6 100644 --- a/primitives/consensus/common/src/import_queue.rs +++ b/primitives/consensus/common/src/import_queue.rs @@ -28,7 +28,7 @@ use std::collections::HashMap; -use sp_runtime::{Justification, traits::{Block as BlockT, Header as _, NumberFor}}; +use sp_runtime::{Justification, traits::{Block as BlockT, Header as _, NumberFor, BlakeTwo256}}; use crate::{ error::Error as ConsensusError, @@ -43,6 +43,8 @@ pub use basic_queue::BasicQueue; mod basic_queue; pub mod buffered_link; +pub type DefaultQueue = BasicQueue>; + /// Shared block import struct used by the queue. pub type BoxBlockImport = Box< dyn BlockImport + Send + Sync diff --git a/primitives/core/src/tasks.rs b/primitives/core/src/tasks.rs index 9a181255ec4e0..731e51d2470c0 100644 --- a/primitives/core/src/tasks.rs +++ b/primitives/core/src/tasks.rs @@ -54,4 +54,4 @@ impl CloneableSpawn for Executor { /// Create tasks executor. pub fn executor() -> Box { Box::new(Executor::new()) -} \ No newline at end of file +} diff --git a/utils/frame/rpc/system/src/lib.rs b/utils/frame/rpc/system/src/lib.rs index 6927f05b4f05b..4a0dfca8b51e8 100644 --- a/utils/frame/rpc/system/src/lib.rs +++ b/utils/frame/rpc/system/src/lib.rs @@ -298,12 +298,13 @@ mod tests { // given let client = Arc::new(substrate_test_runtime_client::new()); - let pool = Arc::new( - BasicPool::new( - Default::default(), - Arc::new(FullChainApi::new(client.clone())), - None, - ).0 + let spawner = sp_core::testing::SpawnBlockingExecutor::new(); + let pool = BasicPool::new_full( + Default::default(), + Arc::new(FullChainApi::new(client.clone())), + None, + spawner, + client.clone(), ); let source = sp_runtime::transaction_validity::TransactionSource::External; @@ -337,12 +338,13 @@ mod tests { // given let client = Arc::new(substrate_test_runtime_client::new()); - let pool = Arc::new( - BasicPool::new( - Default::default(), - Arc::new(FullChainApi::new(client.clone())), - None, - ).0 + let spawner = sp_core::testing::SpawnBlockingExecutor::new(); + let pool = BasicPool::new_full( + Default::default(), + Arc::new(FullChainApi::new(client.clone())), + None, + spawner, + client.clone(), ); let accounts = FullSystem::new(client, pool, DenyUnsafe::Yes); @@ -360,12 +362,13 @@ mod tests { // given let client = Arc::new(substrate_test_runtime_client::new()); - let pool = Arc::new( - BasicPool::new( - Default::default(), - Arc::new(FullChainApi::new(client.clone())), - None, - ).0 + let spawner = sp_core::testing::SpawnBlockingExecutor::new(); + let pool = BasicPool::new_full( + Default::default(), + Arc::new(FullChainApi::new(client.clone())), + None, + spawner, + client.clone(), ); let accounts = FullSystem::new(client, pool, DenyUnsafe::No); @@ -392,12 +395,13 @@ mod tests { // given let client = Arc::new(substrate_test_runtime_client::new()); - let pool = Arc::new( - BasicPool::new( - Default::default(), - Arc::new(FullChainApi::new(client.clone())), - None, - ).0 + let spawner = sp_core::testing::SpawnBlockingExecutor::new(); + let pool = BasicPool::new_full( + Default::default(), + Arc::new(FullChainApi::new(client.clone())), + None, + spawner, + client.clone(), ); let accounts = FullSystem::new(client, pool, DenyUnsafe::No); From b452e1710e9db93cd75a5a788068e816784637b5 Mon Sep 17 00:00:00 2001 From: Ashley Ruglys Date: Thu, 9 Jul 2020 11:55:47 +0200 Subject: [PATCH 2/6] Fix basic-authorship doc tests --- client/basic-authorship/src/lib.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/client/basic-authorship/src/lib.rs b/client/basic-authorship/src/lib.rs index bc51037277612..68356d0a28ff8 100644 --- a/client/basic-authorship/src/lib.rs +++ b/client/basic-authorship/src/lib.rs @@ -31,10 +31,13 @@ //! # }; //! # use sc_transaction_pool::{BasicPool, FullChainApi}; //! # let client = Arc::new(substrate_test_runtime_client::new()); -//! # let txpool = Arc::new(BasicPool::new( +//! # let spawner = sp_core::testing::SpawnBlockingExecutor::new(); +//! # let txpool = BasicPool::new_full( //! # Default::default(), //! # Arc::new(FullChainApi::new(client.clone(), None)), -//! # None).0, +//! # None, +//! # spawner, +//! # client.clone(), //! # ); //! // The first step is to create a `ProposerFactory`. //! let mut proposer_factory = ProposerFactory::new(client.clone(), txpool.clone(), None); From cf49f81194c30c6c4ecb3eb14787e87c2ce3883b Mon Sep 17 00:00:00 2001 From: Ashley Ruglys Date: Thu, 9 Jul 2020 12:19:04 +0200 Subject: [PATCH 3/6] Remove DefaultQueue --- primitives/consensus/common/src/import_queue.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/primitives/consensus/common/src/import_queue.rs b/primitives/consensus/common/src/import_queue.rs index ae8880e809ff6..21e8d976e0449 100644 --- a/primitives/consensus/common/src/import_queue.rs +++ b/primitives/consensus/common/src/import_queue.rs @@ -43,8 +43,6 @@ pub use basic_queue::BasicQueue; mod basic_queue; pub mod buffered_link; -pub type DefaultQueue = BasicQueue>; - /// Shared block import struct used by the queue. pub type BoxBlockImport = Box< dyn BlockImport + Send + Sync From 6c3b9ce4e362b0e594ca0c9e52c6f97971ad83ba Mon Sep 17 00:00:00 2001 From: Ashley Date: Thu, 9 Jul 2020 12:23:34 +0200 Subject: [PATCH 4/6] Update client/service/src/builder.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: AndrĂ© Silva <123550+andresilva@users.noreply.github.com> --- client/service/src/builder.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/service/src/builder.rs b/client/service/src/builder.rs index 356162d863a76..49d2d61f9c2bb 100644 --- a/client/service/src/builder.rs +++ b/client/service/src/builder.rs @@ -516,7 +516,7 @@ impl self.remote_backend.clone() } - /// Returns a spawn handle created by the task manager. + /// Returns a spawn handle created by the task manager. pub fn spawn_handle(&self) -> SpawnTaskHandle { self.task_manager.spawn_handle() } From fbb48b95143a220892176e447ad56c9d090d0b3b Mon Sep 17 00:00:00 2001 From: Ashley Ruglys Date: Thu, 9 Jul 2020 12:25:45 +0200 Subject: [PATCH 5/6] Move ExecutionExtensions comment around --- client/api/src/execution_extensions.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/client/api/src/execution_extensions.rs b/client/api/src/execution_extensions.rs index b89885cc5c4dc..4f2ddb77e6653 100644 --- a/client/api/src/execution_extensions.rs +++ b/client/api/src/execution_extensions.rs @@ -84,6 +84,10 @@ pub struct ExecutionExtensions { keystore: Option, // FIXME: these two are only RwLock because of https://github.com/paritytech/substrate/issues/4587 // remove when fixed. + // To break retain cycle between `Client` and `TransactionPool` we require this + // extension to be a `Weak` reference. + // That's also the reason why it's being registered lazily instead of + // during initialization. transaction_pool: RwLock>>>, extensions_factory: RwLock>, } @@ -121,11 +125,6 @@ impl ExecutionExtensions { } /// Register transaction pool extension. - /// - /// To break retain cycle between `Client` and `TransactionPool` we require this - /// extension to be a `Weak` reference. - /// That's also the reason why it's being registered lazily instead of - /// during initialization. pub fn register_transaction_pool(&self, pool: &Arc) where T: sp_transaction_pool::OffchainSubmitTransaction + 'static { From 6f170f07dc370d20aa9324b653deca9bafe3a54e Mon Sep 17 00:00:00 2001 From: Ashley Ruglys Date: Thu, 9 Jul 2020 12:49:20 +0200 Subject: [PATCH 6/6] Remove unused BlakeTwo256 --- primitives/consensus/common/src/import_queue.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/primitives/consensus/common/src/import_queue.rs b/primitives/consensus/common/src/import_queue.rs index 21e8d976e0449..94228a266385f 100644 --- a/primitives/consensus/common/src/import_queue.rs +++ b/primitives/consensus/common/src/import_queue.rs @@ -28,7 +28,7 @@ use std::collections::HashMap; -use sp_runtime::{Justification, traits::{Block as BlockT, Header as _, NumberFor, BlakeTwo256}}; +use sp_runtime::{Justification, traits::{Block as BlockT, Header as _, NumberFor}}; use crate::{ error::Error as ConsensusError,